Subject: Re: bin/32340: rs doesn't parse options POSIXly
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org,>
From: Michael van Elst <mlelstv@serpens.de>
List: netbsd-bugs
Date: 12/19/2005 17:40:02
The following reply was made to PR bin/32340; it has been noted by GNATS.
From: Michael van Elst <mlelstv@serpens.de>
To: gnats-bugs@netbsd.org
Cc:
Subject: Re: bin/32340: rs doesn't parse options POSIXly
Date: Mon, 19 Dec 2005 18:38:09 +0100
Here is a patch that helps with the mandatory option arguments.
getopt is not applicable since options like -S and -C may
be used without argument.
N.B. the options -o, -B and -b are not documented in the manpage.
Index: rs.c
===================================================================
RCS file: /cvsroot/src/usr.bin/rs/rs.c,v
retrieving revision 1.11
diff -u -r1.11 rs.c
--- rs.c 1 Nov 2004 21:43:35 -0000 1.11
+++ rs.c 19 Dec 2005 17:19:18 -0000
@@ -101,6 +101,7 @@
char *getlist __P((short **, char *));
char *getnum __P((int *, char *, int));
char **getptrs __P((char **));
+char *getnextarg __P((char *, int *, char **[]));
int main __P((int, char **));
void prepfile __P((void));
void prints __P((char *, int));
@@ -393,6 +394,23 @@
return(sp);
}
+char *
+getnextarg(p,acp,avp)
+ char *p;
+ int *acp;
+ char **avp[];
+{
+ if (p[1])
+ return p;
+
+ if (*acp <= 1)
+ return p;
+
+ --(*acp);
+ ++(*avp);
+ return (*avp)[0]-1;
+}
+
void
getargs(ac, av)
int ac;
@@ -428,6 +446,7 @@
osep = '\t'; /* default is ^I */
break;
case 'w': /* window width, default 80 */
+ p = getnextarg(p, &ac, &av);
p = getnum(&owidth, p, 0);
if (owidth <= 0)
usage("Width must be a positive integer");
@@ -435,6 +454,7 @@
case 'K': /* skip N lines */
flags |= SKIPPRINT;
case 'k': /* skip, do not print */
+ p = getnextarg(p, &ac, &av);
p = getnum(&skip, p, 0);
if (!skip)
skip = 1;
@@ -443,9 +463,11 @@
flags |= NOTRIMENDCOL;
break;
case 'g': /* gutter space */
+ p = getnextarg(p, &ac, &av);
p = getnum(&gutter, p, 0);
break;
case 'G':
+ p = getnextarg(p, &ac, &av);
p = getnum(&propgutter, p, 0);
break;
case 'e': /* each line is an entry */
@@ -475,14 +497,17 @@
ipagespace = atoi(++p); (default is 1)
break;*/
case 'o': /* col order */
+ p = getnextarg(p, &ac, &av);
p = getlist(&cord, p);
break;
case 'b':
flags |= ICOLBOUNDS;
+ p = getnextarg(p, &ac, &av);
p = getlist(&icbd, p);
break;
case 'B':
flags |= OCOLBOUNDS;
+ p = getnextarg(p, &ac, &av);
p = getlist(&ocbd, p);
break;
default:
--
Michael van Elst
Internet: mlelstv@serpens.de
"A potential Snark may lurk in every tree."