[hackers] [sbase] Print header in head(1) || sin

From: <git_AT_suckless.org>
Date: Thu, 20 Nov 2014 23:52:11 +0100

commit 93c8aaf925bfc6f5275baab35092c35ea19af5fb
Author: sin <sin_AT_2f30.org>
Date: Thu Nov 20 22:51:18 2014 +0000

    Print header in head(1)

diff --git a/head.c b/head.c
index ec40446..f4f6d67 100644
--- a/head.c
+++ b/head.c
_AT_@ -21,6 +21,7 @@ main(int argc, char *argv[])
         long n = 10;
         FILE *fp;
         int ret = 0;
+ int newline, many;
 
         ARGBEGIN {
         case 'n':
_AT_@ -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);
                 }
Received on Thu Nov 20 2014 - 23:52:11 CET

This archive was generated by hypermail 2.3.0 : Fri Nov 21 2014 - 00:00:31 CET