aboutsummaryrefslogtreecommitdiff
path: root/coreutils/head.c
diff options
context:
space:
mode:
authorErik Andersen <andersen@codepoet.org>2000-01-23 18:19:02 +0000
committerErik Andersen <andersen@codepoet.org>2000-01-23 18:19:02 +0000
commit5509af7073ffff75d86ff8c67a2075169a859efd (patch)
tree2728cbb296484026cb657f92f78e1bb0806ba6f4 /coreutils/head.c
parent9bc7e89fc1eb493c06494ad86781ab49fc28c509 (diff)
downloadbusybox-w32-5509af7073ffff75d86ff8c67a2075169a859efd.tar.gz
busybox-w32-5509af7073ffff75d86ff8c67a2075169a859efd.tar.bz2
busybox-w32-5509af7073ffff75d86ff8c67a2075169a859efd.zip
* added (and documented) "-n" option for head -
contributed Friedrich Vedder <fwv@myrtle.lahn.de> * Cleanup for a number of usage messages -- also contributed Friedrich Vedder <fwv@myrtle.lahn.de> -Erik
Diffstat (limited to 'coreutils/head.c')
-rw-r--r--coreutils/head.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/coreutils/head.c b/coreutils/head.c
index 7f08a8041..4e58bdcd7 100644
--- a/coreutils/head.c
+++ b/coreutils/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 $ */