Correct argument parsing and other minor cleanups.

This commit is contained in:
Matt Kraai 2000-07-13 06:33:12 +00:00
parent 37653aaf9c
commit ac48461da9
2 changed files with 22 additions and 22 deletions

22
cat.c
View File

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

View File

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