1 /* head - print the first few lines of a file Author: Andy Tanenbaum */
10 _PROTOTYPE(int main
, (int argc
, char **argv
));
11 _PROTOTYPE(void do_file
, (int n
, FILE *f
));
12 _PROTOTYPE(void usage
, (void));
22 /* Check for flag. Only flag is -n, to say how many lines to print. */
26 if (argc
> 1 && *ptr
++ == '-') {
34 /* Print standard input only. */
39 /* One or more files have been listed explicitly. */
41 if (nfiles
> 1) printf("==> %s <==\n", argv
[k
]);
42 if ((f
= fopen(argv
[k
], "r")) == NULL
)
43 fprintf(stderr
, "%s: cannot open %s: %s\n",
44 argv
[0], argv
[k
], strerror(errno
));
50 if (k
< argc
) printf("\n");
63 /* Print the first 'n' lines of a file. */
64 while (n
) switch (c
= getc(f
)) {
69 default: putc((char) c
, stdout
);
76 fprintf(stderr
, "Usage: head [-n] [file ...]\n");