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

No subject provided #1082

Closed
p5pRT opened this issue Jan 25, 2000 · 4 comments
Closed

No subject provided #1082

p5pRT opened this issue Jan 25, 2000 · 4 comments

Comments

@p5pRT
Copy link

p5pRT commented Jan 25, 2000

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

Searchable as RT2035$

@p5pRT
Copy link
Author

p5pRT commented Jan 25, 2000

From espie@schutzenberger.liafa.jussieu.fr

Getopt​::Std does not stop processing options when it encounters
`--', as is traditional under Unix.
Since there is no escape mechanism, this makes Getopt​::Std useless
for real programs.

The following patch makes it recognize --.

Inline Patch
--- Std.pm.orig	Tue Jan 25 22:08:42 2000
+++ Std.pm	Tue Jan 25 22:15:12 2000
@@ -60,6 +60,10 @@ sub getopt ($;$) {
 
     while (@ARGV && ($_ = $ARGV[0]) =~ /^-(.)(.*)/) {
 	($first,$rest) = ($1,$2);
+	if (/^--$/) { 	# early exit if --
+		shift(@ARGV);
+		last;
+	}
 	if (index($argumentative,$first) >= 0) {
 	    if ($rest ne '') {
 		shift(@ARGV);
@@ -111,6 +115,10 @@ sub getopts ($;$) {
     @args = split( / */, $argumentative );
     while(@ARGV && ($_ = $ARGV[0]) =~ /^-(.)(.*)/) {
 	($first,$rest) = ($1,$2);
+	if (/^--$/) { 	# early exit if --
+		shift(@ARGV);
+		last;
+	}
 	$pos = index($argumentative,$first);
 	if($pos >= 0) {
 	    if(defined($args[$pos+1]) and ($args[$pos+1] eq ':')) {
Perl Info


Site configuration information for perl 5.00503:

Configured by root at Fri Oct 22 00:01:19 MDT 1999.

Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration:
  Platform:
    osname=openbsd, osvers=2.6, archname=i386-openbsd
    uname='openbsd'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef useperlio=undef d_sfio=undef
  Compiler:
    cc='cc', optimize='-O2', gccversion=2.95.1 19990816 (release)
    cppflags=''
    ccflags =''
    stdchar='char', d_stdstdio=undef, usevfork=true
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    alignbytes=4, usemymalloc=n, prototype=define
  Linker and Libraries:
    ld='ld', ldflags =''
    libpth=/usr/lib
    libs=-lm -lc
    libc=/usr/lib/libc.a, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=define, ccdlflags=' '
    cccdlflags='-DPIC -fPIC ', lddlflags='-Bforcearchive -Bshareable '

Locally applied patches:
    


@INC for perl 5.00503:
    /usr/libdata/perl5/i386-openbsd/5.00503
    /usr/local/libdata/perl5/i386-openbsd/5.00503
    /usr/libdata/perl5
    /usr/local/libdata/perl5
    /usr/local/libdata/perl5/site_perl/i386-openbsd
    /usr/libdata/perl5/site_perl/i386-openbsd
    /usr/local/libdata/perl5/site_perl
    /usr/libdata/perl5/site_perl
    .


Environment for perl 5.00503:
    HOME=/home/espie
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/espie/bin:/usr/local/egcs/bin:/usr/games:/usr/local/bin:/usr/local/maple/bin:/bin:/usr/bin:/usr/X11R6/bin:/usr/sbin:/sbin:/emul/linux/usr/local/bin:/emul/linux/usr/bin:/emul/linux/usr/X11R6/bin:/emul/linux/bin
    PERL_BADLANG (unset)
    SHELL=/bin/zsh

@p5pRT
Copy link
Author

p5pRT commented Jan 25, 2000

From [Unknown Contact. See original ticket]

Getopt​::Std does not stop processing options when it encounters
`--', as is traditional under Unix.
Since there is no escape mechanism, this makes Getopt​::Std useless
for real programs.

"Real" programs don't use getopts.

I don't see this an particularly onerous. It's not as though
you can't remove a file name "--", you know.

--tom

@p5pRT
Copy link
Author

p5pRT commented Jan 26, 2000

From @TimToady

Tom Christiansen writes​:
: >Getopt​::Std does not stop processing options when it encounters
: >`--', as is traditional under Unix.
: >Since there is no escape mechanism, this makes Getopt​::Std useless
: >for real programs.
:
: "Real" programs don't use getopts.

In which case it doesn't matter if people play with it.

Almost everyone has to play with getopts at some point in their
existence. I admit that I was an exception.

: I don't see this an particularly onerous. It's not as though
: you can't remove a file name "--", you know.

I don't see much reason to reject the patch other than to be the mud
around a stick.

Larry

@p5pRT
Copy link
Author

p5pRT commented Jan 26, 2000

From [Unknown Contact. See original ticket]

​: "Real" programs don't use getopts.
In which case it doesn't matter if people play with it.

I forgot the smiley! It was a joke.

Almost everyone has to play with getopts at some point in their
existence. I admit that I was an exception.

I often find I don't use it because I can't, because the program
has to treat arguments "differently". Here's the PPT fold opt
parser, which needs to treat -72 and -w 72 as equivalent. I don't
  know how to do that with getopts.
  # do this by hand, because we don't like $opt_80, $opt_132, etc.
  # and we want to check for dups. --tchrist
  OPTION​:
  while (@​ARGV && $ARGV[0] =~ /^-(.+)/ && (shift, ($_ = $1), 1)) {

  next OPTION unless length;

  if (s/^b//) {
  warn "-b flag already set" if $Byte_Only++;
  redo OPTION;
  }

  if (s/^s//) {
  warn "-s flag already set" if $Space_Break++;
  redo OPTION;
  }

  # historical practice makes -72 and -w 72 the same
  if (s/^(\d.*)// || s/^w(.*)//) {
  $Width = $1 || shift;
  next OPTION;
  }

  usage("unexpected option​: -$_");
  }

And here's the ppt awk front end for an awk-compatible call to a2p.
Here, I have to deal with var=val issues.

  while (@​ARGV) {
  $_ = $ARGV[0];
  if (s/^-//) {
  if (s/^F//) {
  unless (length) { shift; $_ = $ARGV[0]; }
  push(@​nargs, "-F$_");
  shift;
  next;
  }
  elsif (s/^v// || /^\w+=/) {
  unless (length) { shift; $_ = $ARGV[0]; }
  push(@​vargs, $_);
  shift;
  next;
  }
  elsif (s/^f//) {
  unless (length) { shift; $_ = shift; }
  push(@​nargs, $_);
  last;
  }
  elsif (s/^-//) {
  if (length) { usage("Long options not supported") }
  shift;
  next;
  }
  else {
  usage("unknown flag​: -$_");
  }
  } else {
  # XXX​: is it a program or an expression?
  if (/^\w+=/) {
  push(@​vargs, $_);
  shift;
  next;
  }
  else {
  print TMPIN "$_\n";
  shift;
  push @​nargs, $tmpin;
  last;
  }
  }
  }
  unshift @​ARGV, @​vargs; # put back var=val statements

I sometimes even do something like this​:

  @​opt{ qw/d f/ } = (0, 0);
  while ($ARGV[0] =~ /^-/) {
  $ARGV[0] =~ s/^-//;
  for my $flag (split(//,$ARGV[0])) {
  usage("unknown flag​: `$flag'") unless 'df' =~ /\Q$flag/;
  warn "$0​: `$flag' flag already set\n" if $opt{$flag}++;
  }
  shift;
  }

But then again, in tcgrep, I'd risk going crazy without

  $optstring = "incCwsxvhe​:f​:l1EHurtpP​:aqTF";
  $zeros = 'inCwxvhelut'; # init opts to 0 (prevent warnings)
  $nulls = 'pP'; # init opts to "" (prevent warnings)
  @​opt{ split //, $zeros } = ( 0 ) x length($zeros);
  @​opt{ split //, $nulls } = ( '' ) x length($nulls);
  getopts($optstring, \%opt) or usage();

Hm... maybe I should FMTEYEWTK on arg processing. :-)

I don't see much reason to reject the patch other than to be the mud
around a stick.

I corresponded with the author, who demonstrated some issues. I
agree that the patch should be accepted. Certainly people who
have other needs don't need to use getopts, and those who do use
it expect it to work as it does in getopts(3).

--tom

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