Print header in head(1)
This commit is contained in:
parent
2a84dd5076
commit
93c8aaf925
8
head.c
8
head.c
|
@ -21,6 +21,7 @@ main(int argc, char *argv[])
|
||||||
long n = 10;
|
long n = 10;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
int newline, many;
|
||||||
|
|
||||||
ARGBEGIN {
|
ARGBEGIN {
|
||||||
case 'n':
|
case 'n':
|
||||||
|
@ -36,12 +37,17 @@ main(int argc, char *argv[])
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
head(stdin, "<stdin>", n);
|
head(stdin, "<stdin>", n);
|
||||||
} else {
|
} else {
|
||||||
for (; argc > 0; argc--, argv++) {
|
many = argc > 1;
|
||||||
|
for (newline = 0; argc > 0; argc--, argv++) {
|
||||||
if (!(fp = fopen(argv[0], "r"))) {
|
if (!(fp = fopen(argv[0], "r"))) {
|
||||||
weprintf("fopen %s:", argv[0]);
|
weprintf("fopen %s:", argv[0]);
|
||||||
ret = 1;
|
ret = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (many)
|
||||||
|
printf("%s==> %s <==\n",
|
||||||
|
newline ? "\n" : "", argv[0]);
|
||||||
|
newline = 1;
|
||||||
head(fp, argv[0], n);
|
head(fp, argv[0], n);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user