NetBSD Problem Report #32340

From mlelstv@henery.1st.de  Mon Dec 19 17:28:23 2005
Return-Path: <mlelstv@henery.1st.de>
Received: from serpens.de (serpens.de [62.208.181.200])
	by narn.netbsd.org (Postfix) with ESMTP id B31DA63B9D6
	for <gnats-bugs@gnats.NetBSD.org>; Mon, 19 Dec 2005 17:28:22 +0000 (UTC)
Message-Id: <200512191630.jBJGUE7q021911@henery.1st.de>
Date: Mon, 19 Dec 2005 17:30:14 +0100 (CET)
From: mlelstv@serpens.de
Reply-To: mlelstv@serpens.de
To: gnats-bugs@netbsd.org
Subject: rs doesn't parse options POSIXly
X-Send-Pr-Version: 3.95

>Number:         32340
>Category:       bin
>Synopsis:       rs doesn't parse options POSIXly
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Dec 19 17:30:01 +0000 2005
>Last-Modified:  Mon Dec 19 21:55:00 +0000 2005
>Originator:     mlelstv@serpens.de
>Release:        NetBSD 3.0_RC6
>Organization:

>Environment:


System: NetBSD henery 3.0_RC6 NetBSD 3.0_RC6 (HENERY) #9: Sun Dec 18 16:51:20 CET 2005 src@henery:/usr/obj/home/src/sys/arch/i386/compile/HENERY i386
Architecture: i386
Machine: i386
>Description:
rs doesn't accept options in a standard matter.

% echo 1 2 3 4 | rs -w 120
rs: Width must be a positive integer
usage:  rs [ -[csCS][x][kKgGw][N]tTeEnyjhHm ] [ rows [ cols ] ]

% echo 1 2 3 4 | rs -w120
1  2  3  4

The reason is that it does not use getopt but invents its own
command line parser that wants option arguments to be padded
directly to the option character.

The same is true for all the other options that accept an argument.

>How-To-Repeat:
See above.

>Fix:
Rewrite the option parser using getopt if the standard gods allow it.

>Audit-Trail:
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."

From: christos@zoulas.com (Christos Zoulas)
To: gnats-bugs@netbsd.org, gnats-admin@netbsd.org,
	netbsd-bugs@netbsd.org
Cc: 
Subject: Re: bin/32340: rs doesn't parse options POSIXly
Date: Mon, 19 Dec 2005 13:40:52 -0500

 On Dec 19,  5:30pm, mlelstv@serpens.de (mlelstv@serpens.de) wrote:
 -- Subject: bin/32340: rs doesn't parse options POSIXly

 | >Number:         32340
 | >Category:       bin
 | >Synopsis:       rs doesn't parse options POSIXly
 | >Confidential:   no
 | >Severity:       non-critical
 | >Priority:       low
 | >Responsible:    bin-bug-people
 | >State:          open
 | >Class:          sw-bug
 | >Submitter-Id:   net
 | >Arrival-Date:   Mon Dec 19 17:30:01 +0000 2005
 | >Originator:     mlelstv@serpens.de
 | >Release:        NetBSD 3.0_RC6
 | >Organization:
 | 	
 | >Environment:
 | 	
 | 	
 | System: NetBSD henery 3.0_RC6 NetBSD 3.0_RC6 (HENERY) #9: Sun Dec 18 16:51:20 CET 2005 src@henery:/usr/obj/home/src/sys/arch/i386/compile/HENERY i386
 | Architecture: i386
 | Machine: i386
 | >Description:
 | rs doesn't accept options in a standard matter.
 | 
 | % echo 1 2 3 4 | rs -w 120
 | rs: Width must be a positive integer
 | usage:  rs [ -[csCS][x][kKgGw][N]tTeEnyjhHm ] [ rows [ cols ] ]
 | 
 | % echo 1 2 3 4 | rs -w120
 | 1  2  3  4
 | 
 | The reason is that it does not use getopt but invents its own
 | command line parser that wants option arguments to be padded
 | directly to the option character.
 | 
 | The same is true for all the other options that accept an argument.

 Yes, but it needs to be able to parse both -s and -s <arg> for example
 which you cannot do with getopt. What does posix say about this?

 christos

From: David Laight <david@l8s.co.uk>
To: gnats-bugs@netbsd.org
Cc: 
Subject: Re: bin/32340: rs doesn't parse options POSIXly
Date: Mon, 19 Dec 2005 21:28:55 +0000

 On Mon, Dec 19, 2005 at 07:05:03PM +0000, Christos Zoulas wrote:
 >  
 >  Yes, but it needs to be able to parse both -s and -s <arg> for example
 >  which you cannot do with getopt. What does posix say about this?

 Posix doesn't allow options to have optional arguments.

 	David

 -- 
 David Laight: david@l8s.co.uk

From: Michael van Elst <mlelstv@serpens.de>
To: gnats-bugs@netbsd.org
Cc: gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Subject: Re: bin/32340: rs doesn't parse options POSIXly
Date: Mon, 19 Dec 2005 22:51:45 +0100

 On Mon, Dec 19, 2005 at 09:30:03PM +0000, David Laight wrote:
 > The following reply was made to PR bin/32340; it has been noted by GNATS.
 > 
 > From: David Laight <david@l8s.co.uk>
 > To: gnats-bugs@netbsd.org
 > Cc: 
 > Subject: Re: bin/32340: rs doesn't parse options POSIXly
 > Date: Mon, 19 Dec 2005 21:28:55 +0000
 > 
 >  On Mon, Dec 19, 2005 at 07:05:03PM +0000, Christos Zoulas wrote:
 >  >  
 >  >  Yes, but it needs to be able to parse both -s and -s <arg> for example
 >  >  which you cannot do with getopt. What does posix say about this?
 >  
 >  Posix doesn't allow options to have optional arguments.

 My patch allows that the mandatory arguments are separated from the
 option character. I.e. -w 120 and -w120 remain valid. On the other
 hand it may cause a subsequent 'rows' argument to be treated as
 the argument of an option.

 So I guess that 'rs' should remain as is and the documentation
 should be fixed.

 Saying this: what about the undocumented options? Is there
 a history?


 -- 
                                 Michael van Elst
 Internet: mlelstv@serpens.de
                                 "A potential Snark may lurk in every tree."

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.