diff options
Diffstat (limited to 'cat.c')
-rw-r--r-- | cat.c | 28 |
1 files changed, 18 insertions, 10 deletions
@@ -22,15 +22,27 @@ | |||
22 | #include "internal.h" | 22 | #include "internal.h" |
23 | #include <stdio.h> | 23 | #include <stdio.h> |
24 | 24 | ||
25 | const char cat_usage[] = "[file ...]"; | ||
26 | 25 | ||
27 | extern int cat_more_main(int argc, char **argv) | 26 | static void print_file( FILE *file) |
28 | { | 27 | { |
29 | int c; | 28 | int c; |
30 | FILE *file = stdin; | 29 | while ((c = getc(file)) != EOF) |
30 | putc(c, stdout); | ||
31 | fclose(file); | ||
32 | fflush(stdout); | ||
33 | } | ||
34 | |||
35 | extern int cat_more_main(int argc, char **argv) | ||
36 | { | ||
37 | FILE *file; | ||
38 | |||
39 | if (argc==1) { | ||
40 | print_file( stdin); | ||
41 | exit( TRUE); | ||
42 | } | ||
31 | 43 | ||
32 | if ( (argc < 2) || (**(argv+1) == '-') ) { | 44 | if ( **(argv+1) == '-' ) { |
33 | fprintf(stderr, "Usage: %s %s", *argv, cat_usage); | 45 | fprintf(stderr, "Usage: cat [file ...]\n"); |
34 | exit(FALSE); | 46 | exit(FALSE); |
35 | } | 47 | } |
36 | argc--; | 48 | argc--; |
@@ -42,11 +54,7 @@ extern int cat_more_main(int argc, char **argv) | |||
42 | perror(*argv); | 54 | perror(*argv); |
43 | exit(FALSE); | 55 | exit(FALSE); |
44 | } | 56 | } |
45 | while ((c = getc(file)) != EOF) | 57 | print_file( file); |
46 | putc(c, stdout); | ||
47 | fclose(file); | ||
48 | fflush(stdout); | ||
49 | |||
50 | argc--; | 58 | argc--; |
51 | argv++; | 59 | argv++; |
52 | } | 60 | } |