Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong interpretation of option in GetOptions() #4687

Closed
p5pRT opened this issue Dec 12, 2001 · 4 comments
Closed

Wrong interpretation of option in GetOptions() #4687

p5pRT opened this issue Dec 12, 2001 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Dec 12, 2001

Migrated from rt.perl.org#8044 (status was 'resolved')

Searchable as RT8044$

@p5pRT
Copy link
Author

p5pRT commented Dec 12, 2001

From welker@pdvp01.tfh-berlin.de

Created by welker@tfh-berlin.de

This is a bug report for perl from welker@​tfh-berlin.de,
generated with the help of perlbug 1.28 running under perl v5.6.0.

-----------------------------------------------------------------

#!/usr/bin/perl
#
# Calling program with option --a will not set $opt_all, but $opt_a !!!!!
# welker@​tfh-berlin.de

use File​::Basename;
use Getopt​::Long;

$prog=basename $0;
$syntax = "Syntax​: $prog [-al] [--all]\n";

Getopt​::Long​::Configure ("require_order", "bundling", "auto_abbrev", "debug");
GetOptions("l", "all", "a") or die $syntax;

print "Option -a : $opt_a\n";
print "Option -l : $opt_l\n";
print "Option --all : $opt_all\n";

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl v5.6.0:

Configured by root at Fri May 11 15:15:27 GMT 2001.

Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.4.3, archname=i586-linux
    uname='linux subbotin 2.4.3 #1 tue may 8 21:54:34 gmt 2001 i686 unknown '
    config_args='-ds -e -Dprefix=/usr -Di_db -Di_dbm -Di_ndbm -Di_gdbm'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define 
    use64bitint=undef use64bitall=undef uselongdouble=undef usesocks=undef
  Compiler:
    cc='cc', optimize='-O2 -pipe', gccversion=2.95.3 20010315 (SuSE)
    cppflags='-fno-strict-aliasing -I/usr/local/include'
    ccflags ='-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
    stdchar='char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lnsl -ldl -lm -lc -lcrypt
    libc=, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'

Locally applied patches:
    


@INC for perl v5.6.0:
    /usr/lib/perl5/5.6.0/i586-linux
    /usr/lib/perl5/5.6.0
    /usr/lib/perl5/site_perl/5.6.0/i586-linux
    /usr/lib/perl5/site_perl/5.6.0
    /usr/lib/perl5/site_perl
    .


Environment for perl v5.6.0:
    HOME=/usr1/doz/welker
    LANG=de_DE
    LANGUAGE (unset)
    LC_COLLATE=POSIX
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr1/doz/welker/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/bin:/usr/lib/java/bin:/usr/games/bin:/usr/games:/opt/gnome/bin:/opt/kde2/bin:.:/usr1/doz/welker/bin:.
    PERL_BADLANG (unset)
    SHELL=/bin/sh


@p5pRT
Copy link
Author

p5pRT commented Dec 12, 2001

From @sciurius

[Quoting Prof. Welker, on December 12 2001, 15​:45, in "[ID 20011212.002] Wr"]

# Calling program with option --a will not set $opt_all, but $opt_a !!!!!

Let's see...

Getopt​::Long​::Configure ("require_order", "bundling", "auto_abbrev", "debug");
You enable bundling, indicating that things like -al may be unbundled
in -a and -l.

GetOptions("l", "all", "a") or die $syntax;

I see three options​: 'l', 'a', and 'all'.

Calling with "--a" means​:

  A "--" starter, so no unbundling is done.
  "a" matches option 'a' completely, and 'all' partially, so option
  'a' takes precedence.

Hence, $opt_a is set. Surprising, maybe, but it behaves as it should.

If I change the documentation of the bundling setting as follows​:

  Enabling this option will allow single-character options to be
  bundled. To distinguish bundles from long option names, long options
  I<must> be introduced with C<--> and bundles with C<->.

  Note that, if you have options C<a>, C<l> and C<all>, and
  auto_abbrev enabled, C<-a> and C<--a> will both match the
  single-character option C<a>. C<-al> will be unbundled into C<-a>
  and C<-l>, while C<--al> will autocomplete to C<--all>.

Would that prevent the surprise?

-- Johan

@p5pRT
Copy link
Author

p5pRT commented Dec 12, 2001

From [Unknown Contact. See original ticket]

Prof. Welker <welker@​pdvp01.tfh&#45;berlin.de> wrote​:

# Calling program with option --a will not set $opt_all, but $opt_a!!!!!
# welker@​tfh-berlin.de

use File​::Basename;
use Getopt​::Long;

$prog=basename $0;
$syntax = "Syntax​: $prog [-al] [--all]\n";

Getopt​::Long​::Configure ("require_order", "bundling", "auto_abbrev", "debug");
GetOptions("l", "all", "a") or die $syntax;

print "Option -a : $opt_a\n";
print "Option -l : $opt_l\n";
print "Option --all : $opt_all\n";

Johan Vromans <jvromans@​squirrel.nl> wrote​:

If I change the documentation of the bundling setting as follows​:

Enabling this option will allow single-character options to be
bundled. To distinguish bundles from long option names, long options
I<must> be introduced with C<--> and bundles with C<->.

Note that, if you have options C<a>, C<l> and C<all>, and
auto_abbrev enabled, C<-a> and C<--a> will both match the
single-character option C<a>. C<-al> will be unbundled into C<-a>
and C<-l>, while C<--al> will autocomplete to C<--all>.

Would that prevent the surprise?

I had that figured out as​:
  Note that, if you have options C<a>, C<l> and C<all>, and
  auto_abbrev enabled, possible arguments and option settings are​:

  using argument sets option(s)
  ------------------------------------------
  -a, --a a
  -l, --l l
  -al, -la, -ala, -all,... a, l
  --al, --all all

(What actually caused me to look into the code is the (as I see it)
implementation decision of permitting options that are the initial
substring of another option and the resulting rule that a full
length match overrules the potential disambiguity. So, Johan, if
you're going to update, maybe this one as well?)

As I workaround to the initial problem, I'd consider

  Getopt​::Long​::Configure ( "auto_abbrev", "debug", "prefix_pattern=--"
);
  GetOptions( "all" ) or die $syntax;

  Getopt​::Long​::Configure ("require_order", "bundling",
"prefix_pattern=-");
  GetOptions("l", "a", ) or die $syntax;

which happens to handle --a as --all, but has to sacrifice require_order
in the first pass (or else --all wouldn't be found after -a/-l/-al etc.

HTH,
-Wolfgang

@p5pRT
Copy link
Author

p5pRT commented Dec 24, 2002

@sciurius - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant