diff options
author | sandman <sandman@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2002-05-17 22:18:04 +0000 |
---|---|---|
committer | sandman <sandman@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2002-05-17 22:18:04 +0000 |
commit | cc58e00131b21c0323133d3b414208273cdfb16f (patch) | |
tree | a948e20b6776ca384779aee363db04c02e541be7 | |
parent | 5e633dddba6664d30a4bb852ac57b0de9d4be924 (diff) | |
download | busybox-w32-cc58e00131b21c0323133d3b414208273cdfb16f.tar.gz busybox-w32-cc58e00131b21c0323133d3b414208273cdfb16f.tar.bz2 busybox-w32-cc58e00131b21c0323133d3b414208273cdfb16f.zip |
SUpport old style -[::digit::] options for head and tail
Also make head behave like GNU head (-0/-n 0 is valid)
git-svn-id: svn://busybox.net/trunk/busybox@4782 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | coreutils/head.c | 7 | ||||
-rw-r--r-- | coreutils/tail.c | 5 |
2 files changed, 11 insertions, 1 deletions
diff --git a/coreutils/head.c b/coreutils/head.c index 4a1677146..c5c11fc7b 100644 --- a/coreutils/head.c +++ b/coreutils/head.c | |||
@@ -47,12 +47,17 @@ int head_main(int argc, char **argv) | |||
47 | FILE *fp; | 47 | FILE *fp; |
48 | int need_headers, opt, len = 10, status = EXIT_SUCCESS; | 48 | int need_headers, opt, len = 10, status = EXIT_SUCCESS; |
49 | 49 | ||
50 | if (( argc >= 2 ) && ( strlen ( argv [1] ) >= 2 ) && ( argv [1][0] == '-' ) && isdigit ( argv [1][1] )) { | ||
51 | len = atoi ( &argv [1][1] ); | ||
52 | optind = 2; | ||
53 | } | ||
54 | |||
50 | /* parse argv[] */ | 55 | /* parse argv[] */ |
51 | while ((opt = getopt(argc, argv, "n:")) > 0) { | 56 | while ((opt = getopt(argc, argv, "n:")) > 0) { |
52 | switch (opt) { | 57 | switch (opt) { |
53 | case 'n': | 58 | case 'n': |
54 | len = atoi(optarg); | 59 | len = atoi(optarg); |
55 | if (len >= 1) | 60 | if (len >= 0) |
56 | break; | 61 | break; |
57 | /* fallthrough */ | 62 | /* fallthrough */ |
58 | default: | 63 | default: |
diff --git a/coreutils/tail.c b/coreutils/tail.c index 0c8dec26a..8201c80a0 100644 --- a/coreutils/tail.c +++ b/coreutils/tail.c | |||
@@ -68,6 +68,11 @@ int tail_main(int argc, char **argv) | |||
68 | char *s, *start, *end, buf[BUFSIZ]; | 68 | char *s, *start, *end, buf[BUFSIZ]; |
69 | int i, opt; | 69 | int i, opt; |
70 | 70 | ||
71 | if (( argc >= 2 ) && ( strlen ( argv [1] ) >= 2 ) && ( argv [1][0] == '-' ) && isdigit ( argv [1][1] )) { | ||
72 | count = atoi ( &argv [1][1] ); | ||
73 | optind = 2; | ||
74 | } | ||
75 | |||
71 | while ((opt = getopt(argc, argv, "c:fhn:q:s:v")) > 0) { | 76 | while ((opt = getopt(argc, argv, "c:fhn:q:s:v")) > 0) { |
72 | switch (opt) { | 77 | switch (opt) { |
73 | case 'f': | 78 | case 'f': |