Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1382 lines
39 KiB

  1. # GetOpt::Long.pm -- Universal options parsing
  2. package Getopt::Long;
  3. # RCS Status : $Id: GetoptLong.pl,v 2.18 1998-06-14 15:02:19+02 jv Exp $
  4. # Author : Johan Vromans
  5. # Created On : Tue Sep 11 15:00:12 1990
  6. # Last Modified By: Johan Vromans
  7. # Last Modified On: Fri Jan 8 14:48:43 1999
  8. # Update Count : 707
  9. # Status : Released
  10. ################ Copyright ################
  11. # This program is Copyright 1990,1999 by Johan Vromans.
  12. # This program is free software; you can redistribute it and/or
  13. # modify it under the terms of the GNU General Public License
  14. # as published by the Free Software Foundation; either version 2
  15. # of the License, or (at your option) any later version.
  16. #
  17. # This program is distributed in the hope that it will be useful,
  18. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. # GNU General Public License for more details.
  21. #
  22. # If you do not have a copy of the GNU General Public License write to
  23. # the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
  24. # MA 02139, USA.
  25. ################ Module Preamble ################
  26. use strict;
  27. BEGIN {
  28. require 5.004;
  29. use Exporter ();
  30. use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
  31. $VERSION = "2.19";
  32. @ISA = qw(Exporter);
  33. @EXPORT = qw(&GetOptions $REQUIRE_ORDER $PERMUTE $RETURN_IN_ORDER);
  34. %EXPORT_TAGS = qw();
  35. @EXPORT_OK = qw();
  36. use AutoLoader qw(AUTOLOAD);
  37. }
  38. # User visible variables.
  39. use vars @EXPORT, @EXPORT_OK;
  40. use vars qw($error $debug $major_version $minor_version);
  41. # Deprecated visible variables.
  42. use vars qw($autoabbrev $getopt_compat $ignorecase $bundling $order
  43. $passthrough);
  44. # Official invisible variables.
  45. use vars qw($genprefix);
  46. # Public subroutines.
  47. sub Configure (@);
  48. sub config (@); # deprecated name
  49. sub GetOptions;
  50. # Private subroutines.
  51. sub ConfigDefaults ();
  52. sub FindOption ($$$$$$$);
  53. sub Croak (@); # demand loading the real Croak
  54. ################ Local Variables ################
  55. ################ Resident subroutines ################
  56. sub ConfigDefaults () {
  57. # Handle POSIX compliancy.
  58. if ( defined $ENV{"POSIXLY_CORRECT"} ) {
  59. $genprefix = "(--|-)";
  60. $autoabbrev = 0; # no automatic abbrev of options
  61. $bundling = 0; # no bundling of single letter switches
  62. $getopt_compat = 0; # disallow '+' to start options
  63. $order = $REQUIRE_ORDER;
  64. }
  65. else {
  66. $genprefix = "(--|-|\\+)";
  67. $autoabbrev = 1; # automatic abbrev of options
  68. $bundling = 0; # bundling off by default
  69. $getopt_compat = 1; # allow '+' to start options
  70. $order = $PERMUTE;
  71. }
  72. # Other configurable settings.
  73. $debug = 0; # for debugging
  74. $error = 0; # error tally
  75. $ignorecase = 1; # ignore case when matching options
  76. $passthrough = 0; # leave unrecognized options alone
  77. }
  78. ################ Initialization ################
  79. # Values for $order. See GNU getopt.c for details.
  80. ($REQUIRE_ORDER, $PERMUTE, $RETURN_IN_ORDER) = (0..2);
  81. # Version major/minor numbers.
  82. ($major_version, $minor_version) = $VERSION =~ /^(\d+)\.(\d+)/;
  83. # Set defaults.
  84. ConfigDefaults ();
  85. ################ Package return ################
  86. 1;
  87. __END__
  88. ################ AutoLoading subroutines ################
  89. # RCS Status : $Id: GetoptLongAl.pl,v 2.20 1998-06-14 15:02:19+02 jv Exp $
  90. # Author : Johan Vromans
  91. # Created On : Fri Mar 27 11:50:30 1998
  92. # Last Modified By: Johan Vromans
  93. # Last Modified On: Sun Jun 14 13:54:35 1998
  94. # Update Count : 24
  95. # Status : Released
  96. sub GetOptions {
  97. my @optionlist = @_; # local copy of the option descriptions
  98. my $argend = '--'; # option list terminator
  99. my %opctl = (); # table of arg.specs (long and abbrevs)
  100. my %bopctl = (); # table of arg.specs (bundles)
  101. my $pkg = (caller)[0]; # current context
  102. # Needed if linkage is omitted.
  103. my %aliases= (); # alias table
  104. my @ret = (); # accum for non-options
  105. my %linkage; # linkage
  106. my $userlinkage; # user supplied HASH
  107. my $opt; # current option
  108. my $genprefix = $genprefix; # so we can call the same module many times
  109. my @opctl; # the possible long option names
  110. $error = '';
  111. print STDERR ("GetOpt::Long $Getopt::Long::VERSION ",
  112. "called from package \"$pkg\".",
  113. "\n ",
  114. 'GetOptionsAl $Revision: 2.20 $ ',
  115. "\n ",
  116. "ARGV: (@ARGV)",
  117. "\n ",
  118. "autoabbrev=$autoabbrev,".
  119. "bundling=$bundling,",
  120. "getopt_compat=$getopt_compat,",
  121. "order=$order,",
  122. "\n ",
  123. "ignorecase=$ignorecase,",
  124. "passthrough=$passthrough,",
  125. "genprefix=\"$genprefix\".",
  126. "\n")
  127. if $debug;
  128. # Check for ref HASH as first argument.
  129. # First argument may be an object. It's OK to use this as long
  130. # as it is really a hash underneath.
  131. $userlinkage = undef;
  132. if ( ref($optionlist[0]) and
  133. "$optionlist[0]" =~ /^(?:.*\=)?HASH\([^\(]*\)$/ ) {
  134. $userlinkage = shift (@optionlist);
  135. print STDERR ("=> user linkage: $userlinkage\n") if $debug;
  136. }
  137. # See if the first element of the optionlist contains option
  138. # starter characters.
  139. if ( $optionlist[0] =~ /^\W+$/ ) {
  140. $genprefix = shift (@optionlist);
  141. # Turn into regexp. Needs to be parenthesized!
  142. $genprefix =~ s/(\W)/\\$1/g;
  143. $genprefix = "([" . $genprefix . "])";
  144. }
  145. # Verify correctness of optionlist.
  146. %opctl = ();
  147. %bopctl = ();
  148. while ( @optionlist > 0 ) {
  149. my $opt = shift (@optionlist);
  150. # Strip leading prefix so people can specify "--foo=i" if they like.
  151. $opt = $+ if $opt =~ /^$genprefix+(.*)$/s;
  152. if ( $opt eq '<>' ) {
  153. if ( (defined $userlinkage)
  154. && !(@optionlist > 0 && ref($optionlist[0]))
  155. && (exists $userlinkage->{$opt})
  156. && ref($userlinkage->{$opt}) ) {
  157. unshift (@optionlist, $userlinkage->{$opt});
  158. }
  159. unless ( @optionlist > 0
  160. && ref($optionlist[0]) && ref($optionlist[0]) eq 'CODE' ) {
  161. $error .= "Option spec <> requires a reference to a subroutine\n";
  162. next;
  163. }
  164. $linkage{'<>'} = shift (@optionlist);
  165. next;
  166. }
  167. # Match option spec. Allow '?' as an alias.
  168. if ( $opt !~ /^((\w+[-\w]*)(\|(\?|\w[-\w]*)?)*)?([!~+]|[=:][infse][@%]?)?$/ ) {
  169. $error .= "Error in option spec: \"$opt\"\n";
  170. next;
  171. }
  172. my ($o, $c, $a) = ($1, $5);
  173. $c = '' unless defined $c;
  174. if ( ! defined $o ) {
  175. # empty -> '-' option
  176. $opctl{$o = ''} = $c;
  177. }
  178. else {
  179. # Handle alias names
  180. my @o = split (/\|/, $o);
  181. my $linko = $o = $o[0];
  182. # Force an alias if the option name is not locase.
  183. $a = $o unless $o eq lc($o);
  184. $o = lc ($o)
  185. if $ignorecase > 1
  186. || ($ignorecase
  187. && ($bundling ? length($o) > 1 : 1));
  188. foreach ( @o ) {
  189. if ( $bundling && length($_) == 1 ) {
  190. $_ = lc ($_) if $ignorecase > 1;
  191. if ( $c eq '!' ) {
  192. $opctl{"no$_"} = $c;
  193. warn ("Ignoring '!' modifier for short option $_\n");
  194. $c = '';
  195. }
  196. $opctl{$_} = $bopctl{$_} = $c;
  197. }
  198. else {
  199. $_ = lc ($_) if $ignorecase;
  200. if ( $c eq '!' ) {
  201. $opctl{"no$_"} = $c;
  202. $c = '';
  203. }
  204. $opctl{$_} = $c;
  205. }
  206. if ( defined $a ) {
  207. # Note alias.
  208. $aliases{$_} = $a;
  209. }
  210. else {
  211. # Set primary name.
  212. $a = $_;
  213. }
  214. }
  215. $o = $linko;
  216. }
  217. # If no linkage is supplied in the @optionlist, copy it from
  218. # the userlinkage if available.
  219. if ( defined $userlinkage ) {
  220. unless ( @optionlist > 0 && ref($optionlist[0]) ) {
  221. if ( exists $userlinkage->{$o} && ref($userlinkage->{$o}) ) {
  222. print STDERR ("=> found userlinkage for \"$o\": ",
  223. "$userlinkage->{$o}\n")
  224. if $debug;
  225. unshift (@optionlist, $userlinkage->{$o});
  226. }
  227. else {
  228. # Do nothing. Being undefined will be handled later.
  229. next;
  230. }
  231. }
  232. }
  233. # Copy the linkage. If omitted, link to global variable.
  234. if ( @optionlist > 0 && ref($optionlist[0]) ) {
  235. print STDERR ("=> link \"$o\" to $optionlist[0]\n")
  236. if $debug;
  237. if ( ref($optionlist[0]) =~ /^(SCALAR|CODE)$/ ) {
  238. $linkage{$o} = shift (@optionlist);
  239. }
  240. elsif ( ref($optionlist[0]) =~ /^(ARRAY)$/ ) {
  241. $linkage{$o} = shift (@optionlist);
  242. $opctl{$o} .= '@'
  243. if $opctl{$o} ne '' and $opctl{$o} !~ /\@$/;
  244. $bopctl{$o} .= '@'
  245. if $bundling and defined $bopctl{$o} and
  246. $bopctl{$o} ne '' and $bopctl{$o} !~ /\@$/;
  247. }
  248. elsif ( ref($optionlist[0]) =~ /^(HASH)$/ ) {
  249. $linkage{$o} = shift (@optionlist);
  250. $opctl{$o} .= '%'
  251. if $opctl{$o} ne '' and $opctl{$o} !~ /\%$/;
  252. $bopctl{$o} .= '%'
  253. if $bundling and defined $bopctl{$o} and
  254. $bopctl{$o} ne '' and $bopctl{$o} !~ /\%$/;
  255. }
  256. else {
  257. $error .= "Invalid option linkage for \"$opt\"\n";
  258. }
  259. }
  260. else {
  261. # Link to global $opt_XXX variable.
  262. # Make sure a valid perl identifier results.
  263. my $ov = $o;
  264. $ov =~ s/\W/_/g;
  265. if ( $c =~ /@/ ) {
  266. print STDERR ("=> link \"$o\" to \@$pkg","::opt_$ov\n")
  267. if $debug;
  268. eval ("\$linkage{\$o} = \\\@".$pkg."::opt_$ov;");
  269. }
  270. elsif ( $c =~ /%/ ) {
  271. print STDERR ("=> link \"$o\" to \%$pkg","::opt_$ov\n")
  272. if $debug;
  273. eval ("\$linkage{\$o} = \\\%".$pkg."::opt_$ov;");
  274. }
  275. else {
  276. print STDERR ("=> link \"$o\" to \$$pkg","::opt_$ov\n")
  277. if $debug;
  278. eval ("\$linkage{\$o} = \\\$".$pkg."::opt_$ov;");
  279. }
  280. }
  281. }
  282. # Bail out if errors found.
  283. die ($error) if $error;
  284. $error = 0;
  285. # Sort the possible long option names.
  286. @opctl = sort(keys (%opctl)) if $autoabbrev;
  287. # Show the options tables if debugging.
  288. if ( $debug ) {
  289. my ($arrow, $k, $v);
  290. $arrow = "=> ";
  291. while ( ($k,$v) = each(%opctl) ) {
  292. print STDERR ($arrow, "\$opctl{\"$k\"} = \"$v\"\n");
  293. $arrow = " ";
  294. }
  295. $arrow = "=> ";
  296. while ( ($k,$v) = each(%bopctl) ) {
  297. print STDERR ($arrow, "\$bopctl{\"$k\"} = \"$v\"\n");
  298. $arrow = " ";
  299. }
  300. }
  301. # Process argument list
  302. while ( @ARGV > 0 ) {
  303. #### Get next argument ####
  304. $opt = shift (@ARGV);
  305. print STDERR ("=> option \"", $opt, "\"\n") if $debug;
  306. #### Determine what we have ####
  307. # Double dash is option list terminator.
  308. if ( $opt eq $argend ) {
  309. # Finish. Push back accumulated arguments and return.
  310. unshift (@ARGV, @ret)
  311. if $order == $PERMUTE;
  312. return ($error == 0);
  313. }
  314. my $tryopt = $opt;
  315. my $found; # success status
  316. my $dsttype; # destination type ('@' or '%')
  317. my $incr; # destination increment
  318. my $key; # key (if hash type)
  319. my $arg; # option argument
  320. ($found, $opt, $arg, $dsttype, $incr, $key) =
  321. FindOption ($genprefix, $argend, $opt,
  322. \%opctl, \%bopctl, \@opctl, \%aliases);
  323. if ( $found ) {
  324. # FindOption undefines $opt in case of errors.
  325. next unless defined $opt;
  326. if ( defined $arg ) {
  327. $opt = $aliases{$opt} if defined $aliases{$opt};
  328. if ( defined $linkage{$opt} ) {
  329. print STDERR ("=> ref(\$L{$opt}) -> ",
  330. ref($linkage{$opt}), "\n") if $debug;
  331. if ( ref($linkage{$opt}) eq 'SCALAR' ) {
  332. if ( $incr ) {
  333. print STDERR ("=> \$\$L{$opt} += \"$arg\"\n")
  334. if $debug;
  335. if ( defined ${$linkage{$opt}} ) {
  336. ${$linkage{$opt}} += $arg;
  337. }
  338. else {
  339. ${$linkage{$opt}} = $arg;
  340. }
  341. }
  342. else {
  343. print STDERR ("=> \$\$L{$opt} = \"$arg\"\n")
  344. if $debug;
  345. ${$linkage{$opt}} = $arg;
  346. }
  347. }
  348. elsif ( ref($linkage{$opt}) eq 'ARRAY' ) {
  349. print STDERR ("=> push(\@{\$L{$opt}, \"$arg\")\n")
  350. if $debug;
  351. push (@{$linkage{$opt}}, $arg);
  352. }
  353. elsif ( ref($linkage{$opt}) eq 'HASH' ) {
  354. print STDERR ("=> \$\$L{$opt}->{$key} = \"$arg\"\n")
  355. if $debug;
  356. $linkage{$opt}->{$key} = $arg;
  357. }
  358. elsif ( ref($linkage{$opt}) eq 'CODE' ) {
  359. print STDERR ("=> &L{$opt}(\"$opt\", \"$arg\")\n")
  360. if $debug;
  361. &{$linkage{$opt}}($opt, $arg);
  362. }
  363. else {
  364. print STDERR ("Invalid REF type \"", ref($linkage{$opt}),
  365. "\" in linkage\n");
  366. Croak ("Getopt::Long -- internal error!\n");
  367. }
  368. }
  369. # No entry in linkage means entry in userlinkage.
  370. elsif ( $dsttype eq '@' ) {
  371. if ( defined $userlinkage->{$opt} ) {
  372. print STDERR ("=> push(\@{\$L{$opt}}, \"$arg\")\n")
  373. if $debug;
  374. push (@{$userlinkage->{$opt}}, $arg);
  375. }
  376. else {
  377. print STDERR ("=>\$L{$opt} = [\"$arg\"]\n")
  378. if $debug;
  379. $userlinkage->{$opt} = [$arg];
  380. }
  381. }
  382. elsif ( $dsttype eq '%' ) {
  383. if ( defined $userlinkage->{$opt} ) {
  384. print STDERR ("=> \$L{$opt}->{$key} = \"$arg\"\n")
  385. if $debug;
  386. $userlinkage->{$opt}->{$key} = $arg;
  387. }
  388. else {
  389. print STDERR ("=>\$L{$opt} = {$key => \"$arg\"}\n")
  390. if $debug;
  391. $userlinkage->{$opt} = {$key => $arg};
  392. }
  393. }
  394. else {
  395. if ( $incr ) {
  396. print STDERR ("=> \$L{$opt} += \"$arg\"\n")
  397. if $debug;
  398. if ( defined $userlinkage->{$opt} ) {
  399. $userlinkage->{$opt} += $arg;
  400. }
  401. else {
  402. $userlinkage->{$opt} = $arg;
  403. }
  404. }
  405. else {
  406. print STDERR ("=>\$L{$opt} = \"$arg\"\n") if $debug;
  407. $userlinkage->{$opt} = $arg;
  408. }
  409. }
  410. }
  411. }
  412. # Not an option. Save it if we $PERMUTE and don't have a <>.
  413. elsif ( $order == $PERMUTE ) {
  414. # Try non-options call-back.
  415. my $cb;
  416. if ( (defined ($cb = $linkage{'<>'})) ) {
  417. &$cb ($tryopt);
  418. }
  419. else {
  420. print STDERR ("=> saving \"$tryopt\" ",
  421. "(not an option, may permute)\n") if $debug;
  422. push (@ret, $tryopt);
  423. }
  424. next;
  425. }
  426. # ...otherwise, terminate.
  427. else {
  428. # Push this one back and exit.
  429. unshift (@ARGV, $tryopt);
  430. return ($error == 0);
  431. }
  432. }
  433. # Finish.
  434. if ( $order == $PERMUTE ) {
  435. # Push back accumulated arguments
  436. print STDERR ("=> restoring \"", join('" "', @ret), "\"\n")
  437. if $debug && @ret > 0;
  438. unshift (@ARGV, @ret) if @ret > 0;
  439. }
  440. return ($error == 0);
  441. }
  442. # Option lookup.
  443. sub FindOption ($$$$$$$) {
  444. # returns (1, $opt, $arg, $dsttype, $incr, $key) if okay,
  445. # returns (0) otherwise.
  446. my ($prefix, $argend, $opt, $opctl, $bopctl, $names, $aliases) = @_;
  447. my $key; # hash key for a hash option
  448. my $arg;
  449. print STDERR ("=> find \"$opt\", prefix=\"$prefix\"\n") if $debug;
  450. return (0) unless $opt =~ /^$prefix(.*)$/s;
  451. $opt = $+;
  452. my ($starter) = $1;
  453. print STDERR ("=> split \"$starter\"+\"$opt\"\n") if $debug;
  454. my $optarg = undef; # value supplied with --opt=value
  455. my $rest = undef; # remainder from unbundling
  456. # If it is a long option, it may include the value.
  457. if (($starter eq "--" || ($getopt_compat && !$bundling))
  458. && $opt =~ /^([^=]+)=(.*)$/s ) {
  459. $opt = $1;
  460. $optarg = $2;
  461. print STDERR ("=> option \"", $opt,
  462. "\", optarg = \"$optarg\"\n") if $debug;
  463. }
  464. #### Look it up ###
  465. my $tryopt = $opt; # option to try
  466. my $optbl = $opctl; # table to look it up (long names)
  467. my $type;
  468. my $dsttype = '';
  469. my $incr = 0;
  470. if ( $bundling && $starter eq '-' ) {
  471. # Unbundle single letter option.
  472. $rest = substr ($tryopt, 1);
  473. $tryopt = substr ($tryopt, 0, 1);
  474. $tryopt = lc ($tryopt) if $ignorecase > 1;
  475. print STDERR ("=> $starter$tryopt unbundled from ",
  476. "$starter$tryopt$rest\n") if $debug;
  477. $rest = undef unless $rest ne '';
  478. $optbl = $bopctl; # look it up in the short names table
  479. # If bundling == 2, long options can override bundles.
  480. if ( $bundling == 2 and
  481. defined ($rest) and
  482. defined ($type = $opctl->{$tryopt.$rest}) ) {
  483. print STDERR ("=> $starter$tryopt rebundled to ",
  484. "$starter$tryopt$rest\n") if $debug;
  485. $tryopt .= $rest;
  486. undef $rest;
  487. }
  488. }
  489. # Try auto-abbreviation.
  490. elsif ( $autoabbrev ) {
  491. # Downcase if allowed.
  492. $tryopt = $opt = lc ($opt) if $ignorecase;
  493. # Turn option name into pattern.
  494. my $pat = quotemeta ($opt);
  495. # Look up in option names.
  496. my @hits = grep (/^$pat/, @{$names});
  497. print STDERR ("=> ", scalar(@hits), " hits (@hits) with \"$pat\" ",
  498. "out of ", scalar(@{$names}), "\n") if $debug;
  499. # Check for ambiguous results.
  500. unless ( (@hits <= 1) || (grep ($_ eq $opt, @hits) == 1) ) {
  501. # See if all matches are for the same option.
  502. my %hit;
  503. foreach ( @hits ) {
  504. $_ = $aliases->{$_} if defined $aliases->{$_};
  505. $hit{$_} = 1;
  506. }
  507. # Now see if it really is ambiguous.
  508. unless ( keys(%hit) == 1 ) {
  509. return (0) if $passthrough;
  510. warn ("Option ", $opt, " is ambiguous (",
  511. join(", ", @hits), ")\n");
  512. $error++;
  513. undef $opt;
  514. return (1, $opt,$arg,$dsttype,$incr,$key);
  515. }
  516. @hits = keys(%hit);
  517. }
  518. # Complete the option name, if appropriate.
  519. if ( @hits == 1 && $hits[0] ne $opt ) {
  520. $tryopt = $hits[0];
  521. $tryopt = lc ($tryopt) if $ignorecase;
  522. print STDERR ("=> option \"$opt\" -> \"$tryopt\"\n")
  523. if $debug;
  524. }
  525. }
  526. # Map to all lowercase if ignoring case.
  527. elsif ( $ignorecase ) {
  528. $tryopt = lc ($opt);
  529. }
  530. # Check validity by fetching the info.
  531. $type = $optbl->{$tryopt} unless defined $type;
  532. unless ( defined $type ) {
  533. return (0) if $passthrough;
  534. warn ("Unknown option: ", $opt, "\n");
  535. $error++;
  536. return (1, $opt,$arg,$dsttype,$incr,$key);
  537. }
  538. # Apparently valid.
  539. $opt = $tryopt;
  540. print STDERR ("=> found \"$type\" for ", $opt, "\n") if $debug;
  541. #### Determine argument status ####
  542. # If it is an option w/o argument, we're almost finished with it.
  543. if ( $type eq '' || $type eq '!' || $type eq '+' ) {
  544. if ( defined $optarg ) {
  545. return (0) if $passthrough;
  546. warn ("Option ", $opt, " does not take an argument\n");
  547. $error++;
  548. undef $opt;
  549. }
  550. elsif ( $type eq '' || $type eq '+' ) {
  551. $arg = 1; # supply explicit value
  552. $incr = $type eq '+';
  553. }
  554. else {
  555. substr ($opt, 0, 2) = ''; # strip NO prefix
  556. $arg = 0; # supply explicit value
  557. }
  558. unshift (@ARGV, $starter.$rest) if defined $rest;
  559. return (1, $opt,$arg,$dsttype,$incr,$key);
  560. }
  561. # Get mandatory status and type info.
  562. my $mand;
  563. ($mand, $type, $dsttype, $key) = $type =~ /^(.)(.)([@%]?)$/;
  564. # Check if there is an option argument available.
  565. if ( defined $optarg ? ($optarg eq '')
  566. : !(defined $rest || @ARGV > 0) ) {
  567. # Complain if this option needs an argument.
  568. if ( $mand eq "=" ) {
  569. return (0) if $passthrough;
  570. warn ("Option ", $opt, " requires an argument\n");
  571. $error++;
  572. undef $opt;
  573. }
  574. if ( $mand eq ":" ) {
  575. $arg = $type eq "s" ? '' : 0;
  576. }
  577. return (1, $opt,$arg,$dsttype,$incr,$key);
  578. }
  579. # Get (possibly optional) argument.
  580. $arg = (defined $rest ? $rest
  581. : (defined $optarg ? $optarg : shift (@ARGV)));
  582. # Get key if this is a "name=value" pair for a hash option.
  583. $key = undef;
  584. if ($dsttype eq '%' && defined $arg) {
  585. ($key, $arg) = ($arg =~ /^(.*)=(.*)$/s) ? ($1, $2) : ($arg, 1);
  586. }
  587. #### Check if the argument is valid for this option ####
  588. if ( $type eq "s" ) { # string
  589. # A mandatory string takes anything.
  590. return (1, $opt,$arg,$dsttype,$incr,$key) if $mand eq "=";
  591. # An optional string takes almost anything.
  592. return (1, $opt,$arg,$dsttype,$incr,$key)
  593. if defined $optarg || defined $rest;
  594. return (1, $opt,$arg,$dsttype,$incr,$key) if $arg eq "-"; # ??
  595. # Check for option or option list terminator.
  596. if ($arg eq $argend ||
  597. $arg =~ /^$prefix.+/) {
  598. # Push back.
  599. unshift (@ARGV, $arg);
  600. # Supply empty value.
  601. $arg = '';
  602. }
  603. }
  604. elsif ( $type eq "n" || $type eq "i" ) { # numeric/integer
  605. if ( $bundling && defined $rest && $rest =~ /^(-?[0-9]+)(.*)$/s ) {
  606. $arg = $1;
  607. $rest = $2;
  608. unshift (@ARGV, $starter.$rest) if defined $rest && $rest ne '';
  609. }
  610. elsif ( $arg !~ /^-?[0-9]+$/ ) {
  611. if ( defined $optarg || $mand eq "=" ) {
  612. if ( $passthrough ) {
  613. unshift (@ARGV, defined $rest ? $starter.$rest : $arg)
  614. unless defined $optarg;
  615. return (0);
  616. }
  617. warn ("Value \"", $arg, "\" invalid for option ",
  618. $opt, " (number expected)\n");
  619. $error++;
  620. undef $opt;
  621. # Push back.
  622. unshift (@ARGV, $starter.$rest) if defined $rest;
  623. }
  624. else {
  625. # Push back.
  626. unshift (@ARGV, defined $rest ? $starter.$rest : $arg);
  627. # Supply default value.
  628. $arg = 0;
  629. }
  630. }
  631. }
  632. elsif ( $type eq "f" ) { # real number, int is also ok
  633. # We require at least one digit before a point or 'e',
  634. # and at least one digit following the point and 'e'.
  635. # [-]NN[.NN][eNN]
  636. if ( $bundling && defined $rest &&
  637. $rest =~ /^(-?[0-9]+(\.[0-9]+)?([eE]-?[0-9]+)?)(.*)$/s ) {
  638. $arg = $1;
  639. $rest = $+;
  640. unshift (@ARGV, $starter.$rest) if defined $rest && $rest ne '';
  641. }
  642. elsif ( $arg !~ /^-?[0-9.]+(\.[0-9]+)?([eE]-?[0-9]+)?$/ ) {
  643. if ( defined $optarg || $mand eq "=" ) {
  644. if ( $passthrough ) {
  645. unshift (@ARGV, defined $rest ? $starter.$rest : $arg)
  646. unless defined $optarg;
  647. return (0);
  648. }
  649. warn ("Value \"", $arg, "\" invalid for option ",
  650. $opt, " (real number expected)\n");
  651. $error++;
  652. undef $opt;
  653. # Push back.
  654. unshift (@ARGV, $starter.$rest) if defined $rest;
  655. }
  656. else {
  657. # Push back.
  658. unshift (@ARGV, defined $rest ? $starter.$rest : $arg);
  659. # Supply default value.
  660. $arg = 0.0;
  661. }
  662. }
  663. }
  664. else {
  665. Croak ("GetOpt::Long internal error (Can't happen)\n");
  666. }
  667. return (1, $opt, $arg, $dsttype, $incr, $key);
  668. }
  669. # Getopt::Long Configuration.
  670. sub Configure (@) {
  671. my (@options) = @_;
  672. my $opt;
  673. foreach $opt ( @options ) {
  674. my $try = lc ($opt);
  675. my $action = 1;
  676. if ( $try =~ /^no_?(.*)$/s ) {
  677. $action = 0;
  678. $try = $+;
  679. }
  680. if ( $try eq 'default' or $try eq 'defaults' ) {
  681. ConfigDefaults () if $action;
  682. }
  683. elsif ( $try eq 'auto_abbrev' or $try eq 'autoabbrev' ) {
  684. $autoabbrev = $action;
  685. }
  686. elsif ( $try eq 'getopt_compat' ) {
  687. $getopt_compat = $action;
  688. }
  689. elsif ( $try eq 'ignorecase' or $try eq 'ignore_case' ) {
  690. $ignorecase = $action;
  691. }
  692. elsif ( $try eq 'ignore_case_always' ) {
  693. $ignorecase = $action ? 2 : 0;
  694. }
  695. elsif ( $try eq 'bundling' ) {
  696. $bundling = $action;
  697. }
  698. elsif ( $try eq 'bundling_override' ) {
  699. $bundling = $action ? 2 : 0;
  700. }
  701. elsif ( $try eq 'require_order' ) {
  702. $order = $action ? $REQUIRE_ORDER : $PERMUTE;
  703. }
  704. elsif ( $try eq 'permute' ) {
  705. $order = $action ? $PERMUTE : $REQUIRE_ORDER;
  706. }
  707. elsif ( $try eq 'pass_through' or $try eq 'passthrough' ) {
  708. $passthrough = $action;
  709. }
  710. elsif ( $try =~ /^prefix=(.+)$/ ) {
  711. $genprefix = $1;
  712. # Turn into regexp. Needs to be parenthesized!
  713. $genprefix = "(" . quotemeta($genprefix) . ")";
  714. eval { '' =~ /$genprefix/; };
  715. Croak ("Getopt::Long: invalid pattern \"$genprefix\"") if $@;
  716. }
  717. elsif ( $try =~ /^prefix_pattern=(.+)$/ ) {
  718. $genprefix = $1;
  719. # Parenthesize if needed.
  720. $genprefix = "(" . $genprefix . ")"
  721. unless $genprefix =~ /^\(.*\)$/;
  722. eval { '' =~ /$genprefix/; };
  723. Croak ("Getopt::Long: invalid pattern \"$genprefix\"") if $@;
  724. }
  725. elsif ( $try eq 'debug' ) {
  726. $debug = $action;
  727. }
  728. else {
  729. Croak ("Getopt::Long: unknown config parameter \"$opt\"")
  730. }
  731. }
  732. }
  733. # Deprecated name.
  734. sub config (@) {
  735. Configure (@_);
  736. }
  737. # To prevent Carp from being loaded unnecessarily.
  738. sub Croak (@) {
  739. require 'Carp.pm';
  740. $Carp::CarpLevel = 1;
  741. Carp::croak(@_);
  742. };
  743. ################ Documentation ################
  744. =head1 NAME
  745. GetOptions - extended processing of command line options
  746. =head1 SYNOPSIS
  747. use Getopt::Long;
  748. $result = GetOptions (...option-descriptions...);
  749. =head1 DESCRIPTION
  750. The Getopt::Long module implements an extended getopt function called
  751. GetOptions(). This function adheres to the POSIX syntax for command
  752. line options, with GNU extensions. In general, this means that options
  753. have long names instead of single letters, and are introduced with a
  754. double dash "--". Support for bundling of command line options, as was
  755. the case with the more traditional single-letter approach, is provided
  756. but not enabled by default. For example, the UNIX "ps" command can be
  757. given the command line "option"
  758. -vax
  759. which means the combination of B<-v>, B<-a> and B<-x>. With the new
  760. syntax B<--vax> would be a single option, probably indicating a
  761. computer architecture.
  762. Command line options can be used to set values. These values can be
  763. specified in one of two ways:
  764. --size 24
  765. --size=24
  766. GetOptions is called with a list of option-descriptions, each of which
  767. consists of two elements: the option specifier and the option linkage.
  768. The option specifier defines the name of the option and, optionally,
  769. the value it can take. The option linkage is usually a reference to a
  770. variable that will be set when the option is used. For example, the
  771. following call to GetOptions:
  772. GetOptions("size=i" => \$offset);
  773. will accept a command line option "size" that must have an integer
  774. value. With a command line of "--size 24" this will cause the variable
  775. $offset to get the value 24.
  776. Alternatively, the first argument to GetOptions may be a reference to
  777. a HASH describing the linkage for the options, or an object whose
  778. class is based on a HASH. The following call is equivalent to the
  779. example above:
  780. %optctl = ("size" => \$offset);
  781. GetOptions(\%optctl, "size=i");
  782. Linkage may be specified using either of the above methods, or both.
  783. Linkage specified in the argument list takes precedence over the
  784. linkage specified in the HASH.
  785. The command line options are taken from array @ARGV. Upon completion
  786. of GetOptions, @ARGV will contain the rest (i.e. the non-options) of
  787. the command line.
  788. Each option specifier designates the name of the option, optionally
  789. followed by an argument specifier.
  790. Options that do not take arguments will have no argument specifier.
  791. The option variable will be set to 1 if the option is used.
  792. For the other options, the values for argument specifiers are:
  793. =over 8
  794. =item !
  795. Option does not take an argument and may be negated, i.e. prefixed by
  796. "no". E.g. "foo!" will allow B<--foo> (with value 1) and B<-nofoo>
  797. (with value 0).
  798. The option variable will be set to 1, or 0 if negated.
  799. =item +
  800. Option does not take an argument and will be incremented by 1 every
  801. time it appears on the command line. E.g. "more+", when used with
  802. B<--more --more --more>, will set the option variable to 3 (provided
  803. it was 0 or undefined at first).
  804. The B<+> specifier is ignored if the option destination is not a SCALAR.
  805. =item =s
  806. Option takes a mandatory string argument.
  807. This string will be assigned to the option variable.
  808. Note that even if the string argument starts with B<-> or B<-->, it
  809. will not be considered an option on itself.
  810. =item :s
  811. Option takes an optional string argument.
  812. This string will be assigned to the option variable.
  813. If omitted, it will be assigned "" (an empty string).
  814. If the string argument starts with B<-> or B<-->, it
  815. will be considered an option on itself.
  816. =item =i
  817. Option takes a mandatory integer argument.
  818. This value will be assigned to the option variable.
  819. Note that the value may start with B<-> to indicate a negative
  820. value.
  821. =item :i
  822. Option takes an optional integer argument.
  823. This value will be assigned to the option variable.
  824. If omitted, the value 0 will be assigned.
  825. Note that the value may start with B<-> to indicate a negative
  826. value.
  827. =item =f
  828. Option takes a mandatory real number argument.
  829. This value will be assigned to the option variable.
  830. Note that the value may start with B<-> to indicate a negative
  831. value.
  832. =item :f
  833. Option takes an optional real number argument.
  834. This value will be assigned to the option variable.
  835. If omitted, the value 0 will be assigned.
  836. =back
  837. A lone dash B<-> is considered an option, the corresponding option
  838. name is the empty string.
  839. A double dash on itself B<--> signals end of the options list.
  840. =head2 Linkage specification
  841. The linkage specifier is optional. If no linkage is explicitly
  842. specified but a ref HASH is passed, GetOptions will place the value in
  843. the HASH. For example:
  844. %optctl = ();
  845. GetOptions (\%optctl, "size=i");
  846. will perform the equivalent of the assignment
  847. $optctl{"size"} = 24;
  848. For array options, a reference to an array is used, e.g.:
  849. %optctl = ();
  850. GetOptions (\%optctl, "sizes=i@");
  851. with command line "-sizes 24 -sizes 48" will perform the equivalent of
  852. the assignment
  853. $optctl{"sizes"} = [24, 48];
  854. For hash options (an option whose argument looks like "name=value"),
  855. a reference to a hash is used, e.g.:
  856. %optctl = ();
  857. GetOptions (\%optctl, "define=s%");
  858. with command line "--define foo=hello --define bar=world" will perform the
  859. equivalent of the assignment
  860. $optctl{"define"} = {foo=>'hello', bar=>'world')
  861. If no linkage is explicitly specified and no ref HASH is passed,
  862. GetOptions will put the value in a global variable named after the
  863. option, prefixed by "opt_". To yield a usable Perl variable,
  864. characters that are not part of the syntax for variables are
  865. translated to underscores. For example, "--fpp-struct-return" will set
  866. the variable $opt_fpp_struct_return. Note that this variable resides
  867. in the namespace of the calling program, not necessarily B<main>.
  868. For example:
  869. GetOptions ("size=i", "sizes=i@");
  870. with command line "-size 10 -sizes 24 -sizes 48" will perform the
  871. equivalent of the assignments
  872. $opt_size = 10;
  873. @opt_sizes = (24, 48);
  874. A lone dash B<-> is considered an option, the corresponding Perl
  875. identifier is $opt_ .
  876. The linkage specifier can be a reference to a scalar, a reference to
  877. an array, a reference to a hash or a reference to a subroutine.
  878. Note that, if your code is running under the recommended C<use strict
  879. 'vars'> pragma, it may be helpful to declare these package variables
  880. via C<use vars> perhaps something like this:
  881. use vars qw/ $opt_size @opt_sizes $opt_bar /;
  882. If a REF SCALAR is supplied, the new value is stored in the referenced
  883. variable. If the option occurs more than once, the previous value is
  884. overwritten.
  885. If a REF ARRAY is supplied, the new value is appended (pushed) to the
  886. referenced array.
  887. If a REF HASH is supplied, the option value should look like "key" or
  888. "key=value" (if the "=value" is omitted then a value of 1 is implied).
  889. In this case, the element of the referenced hash with the key "key"
  890. is assigned "value".
  891. If a REF CODE is supplied, the referenced subroutine is called with
  892. two arguments: the option name and the option value.
  893. The option name is always the true name, not an abbreviation or alias.
  894. =head2 Aliases and abbreviations
  895. The option name may actually be a list of option names, separated by
  896. "|"s, e.g. "foo|bar|blech=s". In this example, "foo" is the true name
  897. of this option. If no linkage is specified, options "foo", "bar" and
  898. "blech" all will set $opt_foo. For convenience, the single character
  899. "?" is allowed as an alias, e.g. "help|?".
  900. Option names may be abbreviated to uniqueness, depending on
  901. configuration option B<auto_abbrev>.
  902. =head2 Non-option call-back routine
  903. A special option specifier, E<lt>E<gt>, can be used to designate a subroutine
  904. to handle non-option arguments. GetOptions will immediately call this
  905. subroutine for every non-option it encounters in the options list.
  906. This subroutine gets the name of the non-option passed.
  907. This feature requires configuration option B<permute>, see section
  908. CONFIGURATION OPTIONS.
  909. See also the examples.
  910. =head2 Option starters
  911. On the command line, options can start with B<-> (traditional), B<-->
  912. (POSIX) and B<+> (GNU, now being phased out). The latter is not
  913. allowed if the environment variable B<POSIXLY_CORRECT> has been
  914. defined.
  915. Options that start with "--" may have an argument appended, separated
  916. with an "=", e.g. "--foo=bar".
  917. =head2 Return values and Errors
  918. Configuration errors and errors in the option definitions are
  919. signalled using C<die()> and will terminate the calling
  920. program unless the call to C<Getopt::Long::GetOptions()> was embedded
  921. in C<eval { ... }> or C<die()> was trapped using C<$SIG{__DIE__}>.
  922. A return value of 1 (true) indicates success.
  923. A return status of 0 (false) indicates that the function detected one
  924. or more errors during option parsing. These errors are signalled using
  925. C<warn()> and can be trapped with C<$SIG{__WARN__}>.
  926. Errors that can't happen are signalled using C<Carp::croak()>.
  927. =head1 COMPATIBILITY
  928. Getopt::Long::GetOptions() is the successor of
  929. B<newgetopt.pl> that came with Perl 4. It is fully upward compatible.
  930. In fact, the Perl 5 version of newgetopt.pl is just a wrapper around
  931. the module.
  932. If an "@" sign is appended to the argument specifier, the option is
  933. treated as an array. Value(s) are not set, but pushed into array
  934. @opt_name. If explicit linkage is supplied, this must be a reference
  935. to an ARRAY.
  936. If an "%" sign is appended to the argument specifier, the option is
  937. treated as a hash. Value(s) of the form "name=value" are set by
  938. setting the element of the hash %opt_name with key "name" to "value"
  939. (if the "=value" portion is omitted it defaults to 1). If explicit
  940. linkage is supplied, this must be a reference to a HASH.
  941. If configuration option B<getopt_compat> is set (see section
  942. CONFIGURATION OPTIONS), options that start with "+" or "-" may also
  943. include their arguments, e.g. "+foo=bar". This is for compatiblity
  944. with older implementations of the GNU "getopt" routine.
  945. If the first argument to GetOptions is a string consisting of only
  946. non-alphanumeric characters, it is taken to specify the option starter
  947. characters. Everything starting with one of these characters from the
  948. starter will be considered an option. B<Using a starter argument is
  949. strongly deprecated.>
  950. For convenience, option specifiers may have a leading B<-> or B<-->,
  951. so it is possible to write:
  952. GetOptions qw(-foo=s --bar=i --ar=s);
  953. =head1 EXAMPLES
  954. If the option specifier is "one:i" (i.e. takes an optional integer
  955. argument), then the following situations are handled:
  956. -one -two -> $opt_one = '', -two is next option
  957. -one -2 -> $opt_one = -2
  958. Also, assume specifiers "foo=s" and "bar:s" :
  959. -bar -xxx -> $opt_bar = '', '-xxx' is next option
  960. -foo -bar -> $opt_foo = '-bar'
  961. -foo -- -> $opt_foo = '--'
  962. In GNU or POSIX format, option names and values can be combined:
  963. +foo=blech -> $opt_foo = 'blech'
  964. --bar= -> $opt_bar = ''
  965. --bar=-- -> $opt_bar = '--'
  966. Example of using variable references:
  967. $ret = GetOptions ('foo=s', \$foo, 'bar=i', 'ar=s', \@ar);
  968. With command line options "-foo blech -bar 24 -ar xx -ar yy"
  969. this will result in:
  970. $foo = 'blech'
  971. $opt_bar = 24
  972. @ar = ('xx','yy')
  973. Example of using the E<lt>E<gt> option specifier:
  974. @ARGV = qw(-foo 1 bar -foo 2 blech);
  975. GetOptions("foo=i", \$myfoo, "<>", \&mysub);
  976. Results:
  977. mysub("bar") will be called (with $myfoo being 1)
  978. mysub("blech") will be called (with $myfoo being 2)
  979. Compare this with:
  980. @ARGV = qw(-foo 1 bar -foo 2 blech);
  981. GetOptions("foo=i", \$myfoo);
  982. This will leave the non-options in @ARGV:
  983. $myfoo -> 2
  984. @ARGV -> qw(bar blech)
  985. =head1 CONFIGURATION OPTIONS
  986. B<GetOptions> can be configured by calling subroutine
  987. B<Getopt::Long::Configure>. This subroutine takes a list of quoted
  988. strings, each specifying a configuration option to be set, e.g.
  989. B<ignore_case>. Options can be reset by prefixing with B<no_>, e.g.
  990. B<no_ignore_case>. Case does not matter. Multiple calls to B<config>
  991. are possible.
  992. Previous versions of Getopt::Long used variables for the purpose of
  993. configuring. Although manipulating these variables still work, it
  994. is strongly encouraged to use the new B<config> routine. Besides, it
  995. is much easier.
  996. The following options are available:
  997. =over 12
  998. =item default
  999. This option causes all configuration options to be reset to their
  1000. default values.
  1001. =item auto_abbrev
  1002. Allow option names to be abbreviated to uniqueness.
  1003. Default is set unless environment variable
  1004. POSIXLY_CORRECT has been set, in which case B<auto_abbrev> is reset.
  1005. =item getopt_compat
  1006. Allow '+' to start options.
  1007. Default is set unless environment variable
  1008. POSIXLY_CORRECT has been set, in which case B<getopt_compat> is reset.
  1009. =item require_order
  1010. Whether non-options are allowed to be mixed with
  1011. options.
  1012. Default is set unless environment variable
  1013. POSIXLY_CORRECT has been set, in which case b<require_order> is reset.
  1014. See also B<permute>, which is the opposite of B<require_order>.
  1015. =item permute
  1016. Whether non-options are allowed to be mixed with
  1017. options.
  1018. Default is set unless environment variable
  1019. POSIXLY_CORRECT has been set, in which case B<permute> is reset.
  1020. Note that B<permute> is the opposite of B<require_order>.
  1021. If B<permute> is set, this means that
  1022. -foo arg1 -bar arg2 arg3
  1023. is equivalent to
  1024. -foo -bar arg1 arg2 arg3
  1025. If a non-option call-back routine is specified, @ARGV will always be
  1026. empty upon succesful return of GetOptions since all options have been
  1027. processed, except when B<--> is used:
  1028. -foo arg1 -bar arg2 -- arg3
  1029. will call the call-back routine for arg1 and arg2, and terminate
  1030. leaving arg2 in @ARGV.
  1031. If B<require_order> is set, options processing
  1032. terminates when the first non-option is encountered.
  1033. -foo arg1 -bar arg2 arg3
  1034. is equivalent to
  1035. -foo -- arg1 -bar arg2 arg3
  1036. =item bundling (default: reset)
  1037. Setting this variable to a non-zero value will allow single-character
  1038. options to be bundled. To distinguish bundles from long option names,
  1039. long options must be introduced with B<--> and single-character
  1040. options (and bundles) with B<->. For example,
  1041. ps -vax --vax
  1042. would be equivalent to
  1043. ps -v -a -x --vax
  1044. provided "vax", "v", "a" and "x" have been defined to be valid
  1045. options.
  1046. Bundled options can also include a value in the bundle; for strings
  1047. this value is the rest of the bundle, but integer and floating values
  1048. may be combined in the bundle, e.g.
  1049. scale -h24w80
  1050. is equivalent to
  1051. scale -h 24 -w 80
  1052. Note: resetting B<bundling> also resets B<bundling_override>.
  1053. =item bundling_override (default: reset)
  1054. If B<bundling_override> is set, bundling is enabled as with
  1055. B<bundling> but now long option names override option bundles. In the
  1056. above example, B<-vax> would be interpreted as the option "vax", not
  1057. the bundle "v", "a", "x".
  1058. Note: resetting B<bundling_override> also resets B<bundling>.
  1059. B<Note:> Using option bundling can easily lead to unexpected results,
  1060. especially when mixing long options and bundles. Caveat emptor.
  1061. =item ignore_case (default: set)
  1062. If set, case is ignored when matching options.
  1063. Note: resetting B<ignore_case> also resets B<ignore_case_always>.
  1064. =item ignore_case_always (default: reset)
  1065. When bundling is in effect, case is ignored on single-character
  1066. options also.
  1067. Note: resetting B<ignore_case_always> also resets B<ignore_case>.
  1068. =item pass_through (default: reset)
  1069. Unknown options are passed through in @ARGV instead of being flagged
  1070. as errors. This makes it possible to write wrapper scripts that
  1071. process only part of the user supplied options, and passes the
  1072. remaining options to some other program.
  1073. This can be very confusing, especially when B<permute> is also set.
  1074. =item prefix
  1075. The string that starts options. See also B<prefix_pattern>.
  1076. =item prefix_pattern
  1077. A Perl pattern that identifies the strings that introduce options.
  1078. Default is C<(--|-|\+)> unless environment variable
  1079. POSIXLY_CORRECT has been set, in which case it is C<(--|-)>.
  1080. =item debug (default: reset)
  1081. Enable copious debugging output.
  1082. =back
  1083. =head1 OTHER USEFUL VARIABLES
  1084. =over 12
  1085. =item $Getopt::Long::VERSION
  1086. The version number of this Getopt::Long implementation in the format
  1087. C<major>.C<minor>. This can be used to have Exporter check the
  1088. version, e.g.
  1089. use Getopt::Long 3.00;
  1090. You can inspect $Getopt::Long::major_version and
  1091. $Getopt::Long::minor_version for the individual components.
  1092. =item $Getopt::Long::error
  1093. Internal error flag. May be incremented from a call-back routine to
  1094. cause options parsing to fail.
  1095. =back
  1096. =head1 AUTHOR
  1097. Johan Vromans E<lt>jvromans@squirrel.nlE<gt>
  1098. =head1 COPYRIGHT AND DISCLAIMER
  1099. This program is Copyright 1990,1999 by Johan Vromans.
  1100. This program is free software; you can redistribute it and/or
  1101. modify it under the terms of the GNU General Public License
  1102. as published by the Free Software Foundation; either version 2
  1103. of the License, or (at your option) any later version.
  1104. This program is distributed in the hope that it will be useful,
  1105. but WITHOUT ANY WARRANTY; without even the implied warranty of
  1106. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1107. GNU General Public License for more details.
  1108. If you do not have a copy of the GNU General Public License write to
  1109. the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
  1110. MA 02139, USA.
  1111. =cut