D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 2142 - getopt() incorrectly processes bundled comman-line options
Summary: getopt() incorrectly processes bundled comman-line options
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: Andrei Alexandrescu
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-06-06 05:08 UTC by Artem Borisovskiy
Modified: 2015-06-09 01:19 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Artem Borisovskiy 2008-06-06 05:08:28 UTC
getopt() sees only one short option in bundled options - the one that is given to getopt() first.

Example:
 boo f_linenum, f_filename;
 getopt
  (
    args,
    std.getopt.config.bundling,
    //std.getopt.config.caseSensitive,
    "linenum|l", &f_linenum,
    "filename|n", &f_filename
  );
In `-ln' and `-nl' options only `l' will be recognized in this case.
And if  we will change the order like this:
  ...
  "filename|n", &f_filename,
  "linenum|l", &f_linenum
  ...
`n' will be recognized, but `l' will be skipped

I think, it's from line 538 of getopt.d:
536  if (cfg.bundling && !isLong && v.length == 1
537    && std.string.find(arg, v) >= 0)
538  return true;    <--- this is wrong

P.S. I cannot check my solution, because phobos doesn't compile:
Error: multiple definition of object-2: _D8object.212__ModuleInfoZ and object: _
D8object.212__ModuleInfoZ
Comment 1 Artem Borisovskiy 2008-06-26 02:23:28 UTC
I found that if short option is recognized, then the whole argument containing it is removed from <args>, leaving all remaining bundled options unprocessed.
Comment 2 Andrei Alexandrescu 2010-09-26 08:25:34 UTC
http://www.dsource.org/projects/phobos/changeset/2050