Correct argument parsing and other minor cleanups.
authorMatt Kraai <kraai@debian.org>
Thu, 13 Jul 2000 06:33:12 +0000 (06:33 -0000)
committerMatt Kraai <kraai@debian.org>
Thu, 13 Jul 2000 06:33:12 +0000 (06:33 -0000)
cat.c
coreutils/cat.c

diff --git a/cat.c b/cat.c
index 80044346048acdbd8c76030976f823c1feef5dce..6c17ee620f728487cd0d3c3aef3aa74d1c4d1941 100644 (file)
--- a/cat.c
+++ b/cat.c
@@ -24,7 +24,6 @@
 #include "internal.h"
 #include <stdio.h>
 
-
 static void print_file(FILE * file)
 {
        int c;
@@ -35,6 +34,13 @@ static void print_file(FILE * file)
        fflush(stdout);
 }
 
+static const char cat_usage[] =
+       "cat [FILE]...\n"
+#ifndef BB_FEATURE_TRIVIAL_HELP
+       "\nConcatenates FILE(s) and prints them to stdout.\n"
+#endif
+       ;
+
 extern int cat_main(int argc, char **argv)
 {
        FILE *file;
@@ -44,17 +50,11 @@ extern int cat_main(int argc, char **argv)
                exit(TRUE);
        }
 
-       if (**(argv + 1) == '-') {
-               usage("cat [FILE ...]\n"
-#ifndef BB_FEATURE_TRIVIAL_HELP
-                               "\nConcatenates FILE(s) and prints them to the standard output.\n"
-#endif
-                               );
-       }
-       argc--;
+       if (**(argv + 1) == '-')
+               usage(cat_usage);
 
-       while (argc-- > 0 && *(argv++) != '\0' && strlen(*argv)) {
-               file = fopen(*argv, "r");
+       while (--argc > 0) {
+               file = fopen(*++argv, "r");
                if (file == NULL) {
                        perror(*argv);
                        exit(FALSE);
index 80044346048acdbd8c76030976f823c1feef5dce..6c17ee620f728487cd0d3c3aef3aa74d1c4d1941 100644 (file)
@@ -24,7 +24,6 @@
 #include "internal.h"
 #include <stdio.h>
 
-
 static void print_file(FILE * file)
 {
        int c;
@@ -35,6 +34,13 @@ static void print_file(FILE * file)
        fflush(stdout);
 }
 
+static const char cat_usage[] =
+       "cat [FILE]...\n"
+#ifndef BB_FEATURE_TRIVIAL_HELP
+       "\nConcatenates FILE(s) and prints them to stdout.\n"
+#endif
+       ;
+
 extern int cat_main(int argc, char **argv)
 {
        FILE *file;
@@ -44,17 +50,11 @@ extern int cat_main(int argc, char **argv)
                exit(TRUE);
        }
 
-       if (**(argv + 1) == '-') {
-               usage("cat [FILE ...]\n"
-#ifndef BB_FEATURE_TRIVIAL_HELP
-                               "\nConcatenates FILE(s) and prints them to the standard output.\n"
-#endif
-                               );
-       }
-       argc--;
+       if (**(argv + 1) == '-')
+               usage(cat_usage);
 
-       while (argc-- > 0 && *(argv++) != '\0' && strlen(*argv)) {
-               file = fopen(*argv, "r");
+       while (--argc > 0) {
+               file = fopen(*++argv, "r");
                if (file == NULL) {
                        perror(*argv);
                        exit(FALSE);