commit 93c8aaf925bfc6f5275baab35092c35ea19af5fb
parent 2a84dd507611a461efbddffe8f8f6b2b518fed67
Author: sin <sin@2f30.org>
Date: Thu, 20 Nov 2014 22:51:18 +0000
Print header in head(1)
Diffstat:
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/head.c b/head.c
@@ -21,6 +21,7 @@ main(int argc, char *argv[])
long n = 10;
FILE *fp;
int ret = 0;
+ int newline, many;
ARGBEGIN {
case 'n':
@@ -36,12 +37,17 @@ main(int argc, char *argv[])
if (argc == 0) {
head(stdin, "<stdin>", n);
} else {
- for (; argc > 0; argc--, argv++) {
+ many = argc > 1;
+ for (newline = 0; argc > 0; argc--, argv++) {
if (!(fp = fopen(argv[0], "r"))) {
weprintf("fopen %s:", argv[0]);
ret = 1;
continue;
}
+ if (many)
+ printf("%s==> %s <==\n",
+ newline ? "\n" : "", argv[0]);
+ newline = 1;
head(fp, argv[0], n);
fclose(fp);
}