aboutsummaryrefslogtreecommitdiff
path: root/head.c
diff options
context:
space:
mode:
Diffstat (limited to 'head.c')
-rw-r--r--head.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/head.c b/head.c
index 7f08a8041..4e58bdcd7 100644
--- a/head.c
+++ b/head.c
@@ -26,10 +26,12 @@
26#include <stdio.h> 26#include <stdio.h>
27 27
28const char head_usage[] = 28const char head_usage[] =
29"Usage: head [FILE]...\n\n" 29"head [OPTION] [FILE]...\n\n"
30"Print first 10 lines of each FILE to standard output.\n" 30"Print first 10 lines of each FILE to standard output.\n"
31"With more than one FILE, precede each with a header giving the\n" 31"With more than one FILE, precede each with a header giving the\n"
32"file name. With no FILE, or when FILE is -, read standard input.\n"; 32"file name. With no FILE, or when FILE is -, read standard input.\n\n"
33"Options:\n"
34"\t-n NUM\t\tPrint first NUM lines instead of first 10\n";
33 35
34int 36int
35head(int len, FILE *src) 37head(int len, FILE *src)
@@ -49,22 +51,22 @@ head(int len, FILE *src)
49int 51int
50head_main(int argc, char **argv) 52head_main(int argc, char **argv)
51{ 53{
52 int i = 1;
53 char opt; 54 char opt;
54 int len = 10; 55 int len = 10, tmplen, i;
55
56 /* 1st option is potentially special */
57 if ((argc > 1) && (argv[1][0] == '-') && isDecimal(argv[1][1])) {
58 int tmplen = atoi(&argv[1][1]);
59 if (tmplen) { len = tmplen; }
60 i = 2;
61 }
62 56
63 /* parse argv[] */ 57 /* parse argv[] */
64 for ( ; i < argc; i++) { 58 for (i = 1; i < argc; i++) {
65 if (argv[i][0] == '-') { 59 if (argv[i][0] == '-') {
66 opt = argv[i][1]; 60 opt = argv[i][1];
67 switch (opt) { 61 switch (opt) {
62 case 'n':
63 tmplen = 0;
64 if (i++ < argc)
65 tmplen = atoi(argv[i]);
66 if (tmplen < 1)
67 usage(head_usage);
68 len = tmplen;
69 break;
68 case '-': 70 case '-':
69 case 'h': 71 case 'h':
70 usage(head_usage); 72 usage(head_usage);
@@ -103,4 +105,4 @@ head_main(int argc, char **argv)
103 exit(0); 105 exit(0);
104} 106}
105 107
106/* $Id: head.c,v 1.4 1999/12/17 18:52:06 erik Exp $ */ 108/* $Id: head.c,v 1.5 2000/01/23 18:19:02 erik Exp $ */