public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/569] New: getopt_long option parsing
@ 2004-11-23  7:12 alain.bonnefoy@rieter.com
  2004-11-23  7:15 ` [Bug libc/569] " alain.bonnefoy@rieter.com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: alain.bonnefoy@rieter.com @ 2004-11-23  7:12 UTC (permalink / raw)
  To: glibc-bugs

According to what I saw in the getopt_long source code, the optional argument 
parsing test is: 

                if (o->has_arg>0) { 
                    if (*max=='=') 
                        optarg=max+1; 
                    else { 
                        optarg=argv[optind+1]; 
                        ++optind; 
                        // These two 'if' code blocks fix a bug about optional 
argument missing. 
                        // More, I added two additional test with (optarg[0] 
== '-') as I consider that dash 
                        // specify an option only if it's followed by a 
character different from space or end of string 
                        if ((o->has_arg==1) && (!optarg || ((optarg[0] == '-') 
&& (optarg[1] != ' ') && (optarg[1] != '\0')))) { /* no mandatory argument 
there */ 
                            if (*optstring==':') return ':'; 
                            write(2,"argument required: `",20); 
                            write(2,arg,max-arg); 
                            write(2,"'.\n",3); 
                            return '?'; 
                        } 
                        if ((o->has_arg==2) && (!optarg || ((optarg[0] == '-') 
&& (optarg[1] != ' ') && (optarg[1] != '\0')))) { /* no optional argument 
there */ 
                            optarg = NULL; 
                            if (!o->flag) return o->val; 
                            return 0; 
                        } 
                    } 
                } 

The problem of this code is that it doesn't allow to specify negative values 
as optional parameters such as: 

# my_cmd --setmin -100 --setmax 100 

What I propose is to add an additional test to accept a dash character as 
optional argument if it is followed by a digit: 

                if (o->has_arg>0) { 
                    if (*max=='=') 
                        optarg=max+1; 
                    else { 
                        optarg=argv[optind+1]; 
                        ++optind; 
                        // These two 'if' code blocks fix a bug about optional 
argument missing. 
                        // More, I added two additional test with (optarg[0] 
== '-') as I consider that dash 
                        // specify an option only if it's followed by a 
character different from space or end of string AND it's not a digit like a 
negative value 
                        if ((o->has_arg==1) && (!optarg || ((optarg[0] == '-') 
&& (!isdigit(optarg[1])) && (optarg[1] != ' ') && (optarg[1] != '\0')))) { /* 
no mandatory argument there */ 
                            if (*optstring==':') return ':'; 
                            write(2,"argument required: `",20); 
                            write(2,arg,max-arg); 
                            write(2,"'.\n",3); 
                            return '?'; 
                        } 
                        if ((o->has_arg==2) && (!optarg || ((optarg[0] == '-') 
&& (!isdigit(optarg[1])) && (optarg[1] != ' ') && (optarg[1] != '\0')))) { /* 
no optional argument there */ 
                            optarg = NULL; 
                            if (!o->flag) return o->val; 
                            return 0; 
                        } 
                    } 
                } 


Kind regards, 
A.Bonnefoy

-- 
           Summary: getopt_long option parsing
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: gotom at debian dot or dot jp
        ReportedBy: alain dot bonnefoy at rieter dot com
                CC: glibc-bugs at sources dot redhat dot com
 GCC build triplet: any
  GCC host triplet: any
GCC target triplet: any


http://sources.redhat.com/bugzilla/show_bug.cgi?id=569

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug libc/569] getopt_long option parsing
  2004-11-23  7:12 [Bug libc/569] New: getopt_long option parsing alain.bonnefoy@rieter.com
@ 2004-11-23  7:15 ` alain.bonnefoy@rieter.com
  2004-11-23 10:50 ` schwab@suse.de
  2004-11-25 12:58 ` alain.bonnefoy@rieter.com
  2 siblings, 0 replies; 4+ messages in thread
From: alain.bonnefoy@rieter.com @ 2004-11-23  7:15 UTC (permalink / raw)
  To: glibc-bugs

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
              Alias|                            |getopt_long_neg_pars


http://sources.redhat.com/bugzilla/show_bug.cgi?id=569

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug libc/569] getopt_long option parsing
  2004-11-23  7:12 [Bug libc/569] New: getopt_long option parsing alain.bonnefoy@rieter.com
  2004-11-23  7:15 ` [Bug libc/569] " alain.bonnefoy@rieter.com
@ 2004-11-23 10:50 ` schwab@suse.de
  2004-11-25 12:58 ` alain.bonnefoy@rieter.com
  2 siblings, 0 replies; 4+ messages in thread
From: schwab@suse.de @ 2004-11-23 10:50 UTC (permalink / raw)
  To: glibc-bugs

------- Additional Comments From schwab at suse dot de  2004-11-23 10:50 -------
Use --foo=-100 instead. 

-- 


http://sources.redhat.com/bugzilla/show_bug.cgi?id=569

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug libc/569] getopt_long option parsing
  2004-11-23  7:12 [Bug libc/569] New: getopt_long option parsing alain.bonnefoy@rieter.com
  2004-11-23  7:15 ` [Bug libc/569] " alain.bonnefoy@rieter.com
  2004-11-23 10:50 ` schwab@suse.de
@ 2004-11-25 12:58 ` alain.bonnefoy@rieter.com
  2 siblings, 0 replies; 4+ messages in thread
From: alain.bonnefoy@rieter.com @ 2004-11-25 12:58 UTC (permalink / raw)
  To: glibc-bugs

------- Additional Comments From alain dot bonnefoy at rieter dot com  2004-11-25 12:58 -------
should use --foo=-10 instead

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


http://sources.redhat.com/bugzilla/show_bug.cgi?id=569

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-11-25 12:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-23  7:12 [Bug libc/569] New: getopt_long option parsing alain.bonnefoy@rieter.com
2004-11-23  7:15 ` [Bug libc/569] " alain.bonnefoy@rieter.com
2004-11-23 10:50 ` schwab@suse.de
2004-11-25 12:58 ` alain.bonnefoy@rieter.com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).