Discard implementation of %L and %U format specifiers, now never used.
[open-adventure.git] / misc.c
diff --git a/misc.c b/misc.c
index 4fa173d91f4d5b9ba457954cf136e408ef562600..2b6a58b212a7561eab784dad1a151566319cab4f 100644 (file)
--- a/misc.c
+++ b/misc.c
 #include "advent.h"
 #include "dungeon.h"
 
-static char* xstrdup(const char* s)
-{
-    char* ptr = strdup(s);
-    if (ptr == NULL) {
-        // LCOV_EXCL_START
-        // exclude from coverage analysis because we can't simulate an out of memory error in testing
-        fprintf(stderr, "Out of memory!\n");
-        exit(EXIT_FAILURE);
-    }
-    return (ptr);
-}
-
 static void* xmalloc(size_t size)
 {
     void* ptr = malloc(size);
@@ -202,20 +190,6 @@ void vspeak(const char* msg, bool blank, va_list ap)
                 size -= len;
             }
 
-            // All-lowercase specifier.
-            if (msg[i] == 'L' ||
-                msg[i] == 'C') {
-                packed_to_token(arg, renderp); /* unpack directly to destination */
-                int len = strlen(renderp);
-                for (int j = 0; j < len; ++j) {
-                    renderp[j] = tolower(renderp[j]);
-                }
-                if (msg[i] == 'C') // First char uppercase, rest lowercase.
-                    renderp[0] = toupper(renderp[0]);
-                renderp += len;
-                size -= len;
-            }
-
             previous_arg = arg;
         }
     }
@@ -293,19 +267,24 @@ void echo_input(FILE* destination, const char* input_prompt, const char* input)
     free(prompt_and_input);
 }
 
-int word_count(char* s)
+int word_count(char* str)
 {
-    char* copy = xstrdup(s);
     char delims[] = " \t";
     int count = 0;
-    char* word;
+    int inblanks = true;
+
+    for (char *s = str; *s; s++)
+       if (inblanks) {
+           if (strchr(delims, *s) == 0) {
+               ++count;
+               inblanks = false;
+           }
+       } else {
+           if (strchr(delims, *s) != 0) {
+               inblanks = true;
+           }
+       }
 
-    word = strtok(copy, delims);
-    while (word != NULL) {
-        word = strtok(NULL, delims);
-        ++count;
-    }
-    free(copy);
     return (count);
 }