Reorganise, make it just one function, remove -v option it didnt work properly anyway...
[oweals/busybox.git] / coreutils / wc.c
index 9f818ea72deec9fe430a2181c661047ac5d0a8ae..8e3b5bbf438070cfab3b7d892b723c2363fc63c8 100644 (file)
@@ -42,20 +42,29 @@ static char print_type = 0;
 static void print_counts(const unsigned int lines, const unsigned int words,
        const unsigned int chars, const unsigned int length, const char *name)
 {
+       int output = 0;
+
        if (print_type & print_lines) {
-               printf("%7d ", lines);
+               printf("%7d", lines);
+               output++;
        }
        if (print_type & print_words) {
-               printf("%7d ", words);
+               if (output++)
+                       putchar(' ');
+               printf("%7d", words);
        }
        if (print_type & print_chars) {
-               printf("%7d ", chars);
+               if (output++)
+                       putchar(' ');
+               printf("%7d", chars);
        }
        if (print_type & print_length) {
-               printf("%7d ", length);
+               if (output++)
+                       putchar(' ');
+               printf("%7d", length);
        }
        if (*name) {
-               printf("%s", name);
+               printf(" %s", name);
        }
        putchar('\n');
 }
@@ -68,7 +77,7 @@ static void wc_file(FILE * file, const char *name)
        unsigned int length = 0;
        unsigned int linepos = 0;
        char in_word = 0;
-       char c;
+       int c;
 
        while ((c = getc(file)) != EOF) {
                chars++;