[BusyBox] Support for old style options in head and tail
Robert Griebl
griebl at gmx.de
Wed May 15 18:23:03 UTC 2002
The following patches add support for the old style count options to both
head and tail. With these patches, converting GNU scripts to bb becomes much
more simple, since the "head -1 / tail -1" syntax is used very often.
Any objections against applying these to CVS head ?
--
cu
Robert
--
Real programmers dont write documentation -
leave that to the maintenance people.
Index: textutils/head.c
===================================================================
RCS file: /var/cvs/busybox/textutils/head.c,v
retrieving revision 1.26
diff -u -3 -p -r1.26 head.c
--- textutils/head.c 24 Oct 2001 05:00:26 -0000 1.26
+++ textutils/head.c 16 May 2002 00:17:47 -0000
@@ -47,12 +47,17 @@ int head_main(int argc, char **argv)
FILE *fp;
int need_headers, opt, len = 10, status = EXIT_SUCCESS;
+ if (( argc >= 2 ) && ( strlen ( argv [1] ) >= 2 ) && ( argv [1][0] == '-' )
&& isdigit ( argv [1][1] )) {
+ len = atoi ( &argv [1][1] );
+ optind = 2;
+ }
+
/* parse argv[] */
while ((opt = getopt(argc, argv, "n:")) > 0) {
switch (opt) {
Index: textutils/tail.c
===================================================================
RCS file: /var/cvs/busybox/textutils/tail.c,v
retrieving revision 1.40
diff -u -3 -p -r1.40 tail.c
--- textutils/tail.c 24 Oct 2001 05:00:27 -0000 1.40
+++ textutils/tail.c 16 May 2002 00:17:47 -0000
@@ -68,6 +68,11 @@ int tail_main(int argc, char **argv)
char *s, *start, *end, buf[BUFSIZ];
int i, opt;
+ if (( argc >= 2 ) && ( strlen ( argv [1] ) >= 2 ) && ( argv [1][0] == '-' )
&& isdigit ( argv [1][1] )) {
+ count = atoi ( &argv [1][1] );
+ optind = 2;
+ }
+
while ((opt = getopt(argc, argv, "c:fhn:q:s:v")) > 0) {
switch (opt) {
case 'f':
More information about the busybox
mailing list