home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / perl501m.zip / lib / Getopt / Long.pm next >
Text File  |  1995-07-03  |  20KB  |  653 lines

  1. package Getopt::Long;
  2. require 5.000;
  3. require Exporter;
  4.  
  5. @ISA = qw(Exporter);
  6. @EXPORT = qw(GetOptions);
  7.  
  8. =head1 NAME
  9.  
  10. GetOptions - extended getopt processing
  11.  
  12. =head1 SYNOPSIS
  13.  
  14.     use Getopt::Long;
  15.     $result = GetOptions (...option-descriptions...);
  16.  
  17. =head1 DESCRIPTION
  18.  
  19. The Getopt::Long module implements an extended getopt function called
  20. GetOptions(). This function adheres to the new syntax (long option names,
  21. no bundling).  It tries to implement the better functionality of
  22. traditional, GNU and POSIX getopt() functions.
  23.  
  24. Each description should designate a valid Perl identifier, optionally
  25. followed by an argument specifier.
  26.  
  27. Values for argument specifiers are:
  28.  
  29.   <none>   option does not take an argument
  30.   !        option does not take an argument and may be negated
  31.   =s :s    option takes a mandatory (=) or optional (:) string argument
  32.   =i :i    option takes a mandatory (=) or optional (:) integer argument
  33.   =f :f    option takes a mandatory (=) or optional (:) real number argument
  34.  
  35. If option "name" is set, it will cause the Perl variable $opt_name to
  36. be set to the specified value. The calling program can use this
  37. variable to detect whether the option has been set. Options that do
  38. not take an argument will be set to 1 (one).
  39.  
  40. Options that take an optional argument will be defined, but set to ''
  41. if no actual argument has been supplied.
  42.  
  43. If an "@" sign is appended to the argument specifier, the option is
  44. treated as an array.  Value(s) are not set, but pushed into array
  45. @opt_name.
  46.  
  47. Options that do not take a value may have an "!" argument specifier to
  48. indicate that they may be negated. E.g. "foo!" will allow B<-foo> (which
  49. sets $opt_foo to 1) and B<-nofoo> (which will set $opt_foo to 0).
  50.  
  51. The option name may actually be a list of option names, separated by
  52. '|'s, e.g. B<"foo|bar|blech=s". In this example, options 'bar' and
  53. 'blech' will set $opt_foo instead.
  54.  
  55. Option names may be abbreviated to uniqueness, depending on
  56. configuration variable $autoabbrev.
  57.  
  58. Dashes in option names are allowed (e.g. pcc-struct-return) and will
  59. be translated to underscores in the corresponding Perl variable (e.g.
  60. $opt_pcc_struct_return).  Note that a lone dash "-" is considered an
  61. option, corresponding Perl identifier is $opt_ .
  62.  
  63. A double dash "--" signals end of the options list.
  64.  
  65. If the first option of the list consists of non-alphanumeric
  66. characters only, it is interpreted as a generic option starter.
  67. Everything starting with one of the characters from the starter will
  68. be considered an option.
  69.  
  70. The default values for the option starters are "-" (traditional), "--"
  71. (POSIX) and "+" (GNU, being phased out).
  72.  
  73. Options that start with "--" may have an argument appended, separated
  74. with an "=", e.g. "--foo=bar".
  75.  
  76. If configuration variable $getopt_compat is set to a non-zero value,
  77. options that start with "+" may also include their arguments,
  78. e.g. "+foo=bar".
  79.  
  80. A return status of 0 (false) indicates that the function detected
  81. one or more errors.
  82.  
  83. =head1 EXAMPLES
  84.  
  85. If option "one:i" (i.e. takes an optional integer argument), then
  86. the following situations are handled:
  87.  
  88.    -one -two        -> $opt_one = '', -two is next option
  89.    -one -2        -> $opt_one = -2
  90.  
  91. Also, assume "foo=s" and "bar:s" :
  92.  
  93.    -bar -xxx        -> $opt_bar = '', '-xxx' is next option
  94.    -foo -bar        -> $opt_foo = '-bar'
  95.    -foo --        -> $opt_foo = '--'
  96.  
  97. In GNU or POSIX format, option names and values can be combined:
  98.  
  99.    +foo=blech        -> $opt_foo = 'blech'
  100.    --bar=        -> $opt_bar = ''
  101.    --bar=--        -> $opt_bar = '--'
  102.  
  103. =over 12
  104.  
  105. =item $autoabbrev      
  106.  
  107. Allow option names to be abbreviated to uniqueness.
  108. Default is 1 unless environment variable
  109. POSIXLY_CORRECT has been set.
  110.  
  111. =item $getopt_compat   
  112.  
  113. Allow '+' to start options.
  114. Default is 1 unless environment variable
  115. POSIXLY_CORRECT has been set.
  116.  
  117. =item $option_start    
  118.  
  119. Regexp with option starters.
  120. Default is (--|-) if environment variable
  121. POSIXLY_CORRECT has been set, (--|-|\+) otherwise.
  122.  
  123. =item $order           
  124.  
  125. Whether non-options are allowed to be mixed with
  126. options.
  127. Default is $REQUIRE_ORDER if environment variable
  128. POSIXLY_CORRECT has been set, $PERMUTE otherwise.
  129.  
  130. =item $ignorecase      
  131.  
  132. Ignore case when matching options. Default is 1.
  133.  
  134. =item $debug           
  135.  
  136. Enable debugging output. Default is 0.
  137.  
  138. =back
  139.  
  140. =head1 NOTE
  141.  
  142. Does not yet use the Exporter--or even packages!!
  143. Thus, it's not a real module.
  144.  
  145. =cut
  146.  
  147. # newgetopt.pl -- new options parsing
  148.  
  149. # SCCS Status     : @(#)@ newgetopt.pl    1.14
  150. # Author          : Johan Vromans
  151. # Created On      : Tue Sep 11 15:00:12 1990
  152. # Last Modified By: Johan Vromans
  153. # Last Modified On: Sat Feb 12 18:24:02 1994
  154. # Update Count    : 138
  155. # Status          : Okay
  156.  
  157. ################ Introduction ################
  158. #
  159. # This package implements an extended getopt function. This function adheres
  160. # to the new syntax (long option names, no bundling).
  161. # It tries to implement the better functionality of traditional, GNU and
  162. # POSIX getopt functions.
  163. # This program is Copyright 1990,1994 by Johan Vromans.
  164. # This program is free software; you can redistribute it and/or
  165. # modify it under the terms of the GNU General Public License
  166. # as published by the Free Software Foundation; either version 2
  167. # of the License, or (at your option) any later version.
  168. # This program is distributed in the hope that it will be useful,
  169. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  170. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  171. # GNU General Public License for more details.
  172. # If you do not have a copy of the GNU General Public License write to
  173. # the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, 
  174. # MA 02139, USA.
  175.  
  176. ################ Description ################
  177. #
  178. # Usage:
  179. #    require "newgetopt.pl";
  180. #    ...change configuration values, if needed...
  181. #    $result = &NGetOpt (...option-descriptions...);
  182. # Each description should designate a valid perl identifier, optionally
  183. # followed by an argument specifier.
  184. # Values for argument specifiers are:
  185. #   <none>   option does not take an argument
  186. #   !        option does not take an argument and may be negated
  187. #   =s :s    option takes a mandatory (=) or optional (:) string argument
  188. #   =i :i    option takes a mandatory (=) or optional (:) integer argument
  189. #   =f :f    option takes a mandatory (=) or optional (:) real number argument
  190. # If option "name" is set, it will cause the perl variable $opt_name to
  191. # be set to the specified value. The calling program can use this
  192. # variable to detect whether the option has been set. Options that do
  193. # not take an argument will be set to 1 (one).
  194. # Options that take an optional argument will be defined, but set to ''
  195. # if no actual argument has been supplied.
  196. # If an "@" sign is appended to the argument specifier, the option is
  197. # treated as an array. Value(s) are not set, but pushed into array
  198. # @opt_name.
  199. # Options that do not take a value may have an "!" argument spacifier to
  200. # indicate that they may be negated. E.g. "foo!" will allow -foo (which
  201. # sets $opt_foo to 1) and -nofoo (which will set $opt_foo to 0).
  202. # The option name may actually be a list of option names, separated by
  203. # '|'s, e.g. "foo|bar|blech=s". In this example, options 'bar' and
  204. # 'blech' will set $opt_foo instead.
  205. # Option names may be abbreviated to uniqueness, depending on
  206. # configuration variable $autoabbrev.
  207. # Dashes in option names are allowed (e.g. pcc-struct-return) and will
  208. # be translated to underscores in the corresponding perl variable (e.g.
  209. # $opt_pcc_struct_return).  Note that a lone dash "-" is considered an
  210. # option, corresponding perl identifier is $opt_ .
  211. # A double dash "--" signals end of the options list.
  212. # If the first option of the list consists of non-alphanumeric
  213. # characters only, it is interpreted as a generic option starter.
  214. # Everything starting with one of the characters from the starter will
  215. # be considered an option.
  216. # The default values for the option starters are "-" (traditional), "--"
  217. # (POSIX) and "+" (GNU, being phased out).
  218. # Options that start with "--" may have an argument appended, separated
  219. # with an "=", e.g. "--foo=bar".
  220. # If configuration varaible $getopt_compat is set to a non-zero value,
  221. # options that start with "+" may also include their arguments,
  222. # e.g. "+foo=bar".
  223. # A return status of 0 (false) indicates that the function detected
  224. # one or more errors.
  225. #
  226. ################ Some examples ################
  227. # If option "one:i" (i.e. takes an optional integer argument), then
  228. # the following situations are handled:
  229. #    -one -two        -> $opt_one = '', -two is next option
  230. #    -one -2        -> $opt_one = -2
  231. # Also, assume "foo=s" and "bar:s" :
  232. #    -bar -xxx        -> $opt_bar = '', '-xxx' is next option
  233. #    -foo -bar        -> $opt_foo = '-bar'
  234. #    -foo --        -> $opt_foo = '--'
  235. # In GNU or POSIX format, option names and values can be combined:
  236. #    +foo=blech        -> $opt_foo = 'blech'
  237. #    --bar=        -> $opt_bar = ''
  238. #    --bar=--        -> $opt_bar = '--'
  239. ################ Configuration values ################
  240. #   $autoabbrev      Allow option names to be abbreviated to uniqueness.
  241. #                    Default is 1 unless environment variable
  242. #                    POSIXLY_CORRECT has been set.
  243. #   $getopt_compat   Allow '+' to start options.
  244. #                    Default is 1 unless environment variable
  245. #                    POSIXLY_CORRECT has been set.
  246. #   $option_start    Regexp with option starters.
  247. #                    Default is (--|-) if environment variable
  248. #                    POSIXLY_CORRECT has been set, (--|-|\+) otherwise.
  249. #   $order           Whether non-options are allowed to be mixed with
  250. #                    options.
  251. #                    Default is $REQUIRE_ORDER if environment variable
  252. #                    POSIXLY_CORRECT has been set, $PERMUTE otherwise.
  253. #   $ignorecase      Ignore case when matching options. Default is 1.
  254. #   $debug           Enable debugging output. Default is 0.
  255.  
  256. ################ History ################
  257. # 12-Feb-1994        Johan Vromans    
  258. #    Added "!" for negation.
  259. #    Released to the net.
  260. #
  261. # 26-Aug-1992        Johan Vromans    
  262. #    More POSIX/GNU compliance.
  263. #    Lone dash and double-dash are now independent of the option prefix
  264. #      that is used.
  265. #    Make errors in NGetOpt parameters fatal.
  266. #    Allow options to be mixed with arguments.
  267. #      Check $ENV{"POSIXLY_CORRECT"} to suppress this.
  268. #    Allow --foo=bar and +foo=bar (but not -foo=bar).
  269. #    Allow options to be abbreviated to minimum needed for uniqueness.
  270. #      (Controlled by configuration variable $autoabbrev.)
  271. #    Allow alias names for options (e.g. "foo|bar=s").
  272. #    Allow "-" in option names (e.g. --pcc-struct-return). Dashes are
  273. #      translated to "_" to form valid perl identifiers
  274. #      (e.g. $opt_pcc_struct_return). 
  275. #
  276. # 2-Jun-1992        Johan Vromans    
  277. #    Do not use //o to allow multiple NGetOpt calls with different delimeters.
  278. #    Prevent typeless option from using previous $array state.
  279. #    Prevent empty option from being eaten as a (negative) number.
  280. #
  281. # 25-May-1992        Johan Vromans    
  282. #    Add array options. "foo=s@" will return an array @opt_foo that
  283. #    contains all values that were supplied. E.g. "-foo one -foo -two" will
  284. #    return @opt_foo = ("one", "-two");
  285. #    Correct bug in handling options that allow for a argument when followed
  286. #    by another option.
  287. #
  288. # 4-May-1992        Johan Vromans    
  289. #    Add $ignorecase to match options in either case.
  290. #    Allow '' option.
  291. #
  292. # 19-Mar-1992        Johan Vromans    
  293. #    Allow require from packages.
  294. #    NGetOpt is now defined in the package that requires it.
  295. #    @ARGV and $opt_... are taken from the package that calls it.
  296. #    Use standard (?) option prefixes: -, -- and +.
  297. #
  298. # 20-Sep-1990        Johan Vromans    
  299. #    Set options w/o argument to 1.
  300. #    Correct the dreadful semicolon/require bug.
  301.  
  302. ################ Configuration Section ################
  303.  
  304.  
  305.     # Values for $order. See GNU getopt.c for details.
  306.     $REQUIRE_ORDER = 0;
  307.     $PERMUTE = 1;
  308.     $RETURN_IN_ORDER = 2;
  309.     $RETURN_IN_ORDER = 2; # avoid typo warning with -w
  310.  
  311.     # Handle POSIX compliancy.
  312.     if ( defined $ENV{"POSIXLY_CORRECT"} ) {
  313.     $autoabbrev = 0;    # no automatic abbrev of options (???)
  314.     $getopt_compat = 0;    # disallow '+' to start options
  315.     $option_start = "(--|-)";
  316.     $order = $REQUIRE_ORDER;
  317.     }
  318.     else {
  319.     $autoabbrev = 1;    # automatic abbrev of options
  320.     $getopt_compat = 1;    # allow '+' to start options
  321.     $option_start = "(--|-|\\+)";
  322.     $order = $PERMUTE;
  323.     }
  324.  
  325.     # Other configurable settings.
  326.     $debug = 0;            # for debugging
  327.     $ignorecase = 1;        # ignore case when matching options
  328.     $argv_end = "--";        # don't change this!
  329. }
  330.  
  331. ################ Subroutines ################
  332.  
  333. sub GetOptions {
  334.  
  335.     @optionlist = @_;    #';
  336.  
  337.     local ($[) = 0;
  338.     local ($genprefix) = $option_start;
  339.     local ($argend) = $argv_end;
  340.     local ($error) = 0;
  341.     local ($opt, $arg, $type, $mand, %opctl);
  342.     local ($pkg) = (caller)[0];
  343.     local ($optarg);
  344.     local (%aliases);
  345.     local (@ret) = ();
  346.  
  347.     print STDERR "NGetOpt 1.14 -- called from $pkg\n" if $debug;
  348.  
  349.     # See if the first element of the optionlist contains option
  350.     # starter characters.
  351.     if ( $optionlist[0] =~ /^\W+$/ ) {
  352.     $genprefix = shift (@optionlist);
  353.     # Turn into regexp.
  354.     $genprefix =~ s/(\W)/\\$1/g;
  355.     $genprefix = "[" . $genprefix . "]";
  356.     }
  357.  
  358.     # Verify correctness of optionlist.
  359.     %opctl = ();
  360.     foreach $opt ( @optionlist ) {
  361.     $opt =~ tr/A-Z/a-z/ if $ignorecase;
  362.     if ( $opt !~ /^(\w+[-\w|]*)?(!|[=:][infse]@?)?$/ ) {
  363.         die ("Error in option spec: \"", $opt, "\"\n");
  364.         $error++;
  365.         next;
  366.     }
  367.     local ($o, $c, $a) = ($1, $2);
  368.  
  369.     if ( ! defined $o ) {
  370.         $opctl{''} = defined $c ? $c : '';
  371.     }
  372.     else {
  373.         # Handle alias names
  374.         foreach ( split (/\|/, $o)) {
  375.         if ( defined $c && $c eq '!' ) {
  376.             $opctl{"no$_"} = $c;
  377.             $c = '';
  378.         }
  379.         $opctl{$_} = defined $c ? $c : '';
  380.         if ( defined $a ) {
  381.             # Note alias.
  382.             $aliases{$_} = $a;
  383.         }
  384.         else {
  385.             # Set primary name.
  386.             $a = $_;
  387.         }
  388.         }
  389.     }
  390.     }
  391.     @opctl = sort(keys (%opctl)) if $autoabbrev;
  392.  
  393.     return 0 if $error;
  394.  
  395.     if ( $debug ) {
  396.     local ($arrow, $k, $v);
  397.     $arrow = "=> ";
  398.     while ( ($k,$v) = each(%opctl) ) {
  399.         print STDERR ($arrow, "\$opctl{\"$k\"} = \"$v\"\n");
  400.         $arrow = "   ";
  401.     }
  402.     }
  403.  
  404.     # Process argument list
  405.  
  406.     while ( $#ARGV >= 0 ) {
  407.  
  408.     # >>> See also the continue block <<<
  409.  
  410.     #### Get next argument ####
  411.  
  412.     $opt = shift (@ARGV);
  413.     print STDERR ("=> option \"", $opt, "\"\n") if $debug;
  414.     $arg = undef;
  415.     $optarg = undef;
  416.     $array = 0;
  417.  
  418.     #### Determine what we have ####
  419.  
  420.     # Double dash is option list terminator.
  421.     if ( $opt eq $argend ) {
  422.         unshift (@ARGV, @ret) if $order == $PERMUTE;
  423.         return ($error == 0);
  424.     }
  425.     elsif ( $opt =~ /^$genprefix/ ) {
  426.         # Looks like an option.
  427.         $opt = $';        # option name (w/o prefix)
  428.         # If it is a long opt, it may include the value.
  429.         if (($+ eq "--" || ($getopt_compat && $+ eq "+")) && 
  430.         $opt =~ /^([^=]+)=/ ) {
  431.         $opt = $1;
  432.         $optarg = $';
  433.         print STDERR ("=> option \"", $opt, 
  434.                   "\", optarg = \"$optarg\"\n")
  435.             if $debug;
  436.         }
  437.  
  438.     }
  439.     # Not an option. Save it if we may permute...
  440.     elsif ( $order == $PERMUTE ) {
  441.         push (@ret, $opt);
  442.         next;
  443.     }
  444.     # ...otherwise, terminate.
  445.     else {
  446.         # Push back and exit.
  447.         unshift (@ARGV, $opt);
  448.         return ($error == 0);
  449.     }
  450.  
  451.     #### Look it up ###
  452.  
  453.     $opt =~ tr/A-Z/a-z/ if $ignorecase;
  454.  
  455.     local ($tryopt) = $opt;
  456.     if ( $autoabbrev ) {
  457.         local ($pat, @hits);
  458.  
  459.         # Turn option name into pattern.
  460.         ($pat = $opt) =~ s/(\W)/\\$1/g;
  461.         # Look up in option names.
  462.         @hits = grep (/^$pat/, @opctl);
  463.         print STDERR ("=> ", 0+@hits, " hits (@hits) with \"$pat\" ",
  464.               "out of ", 0+@opctl, "\n")
  465.         if $debug;
  466.  
  467.         # Check for ambiguous results.
  468.         unless ( (@hits <= 1) || (grep ($_ eq $opt, @hits) == 1) ) {
  469.         print STDERR ("Option ", $opt, " is ambiguous (",
  470.                   join(", ", @hits), ")\n");
  471.         $error++;
  472.         next;
  473.         }
  474.  
  475.         # Complete the option name, if appropriate.
  476.         if ( @hits == 1 && $hits[0] ne $opt ) {
  477.         $tryopt = $hits[0];
  478.         print STDERR ("=> option \"$opt\" -> \"$tryopt\"\n")
  479.             if $debug;
  480.         }
  481.     }
  482.  
  483.     unless  ( defined ( $type = $opctl{$tryopt} ) ) {
  484.         print STDERR ("Unknown option: ", $opt, "\n");
  485.         $error++;
  486.         next;
  487.     }
  488.     $opt = $tryopt;
  489.     print STDERR ("=> found \"$type\" for ", $opt, "\n") if $debug;
  490.  
  491.     #### Determine argument status ####
  492.  
  493.     # If it is an option w/o argument, we're almost finished with it.
  494.     if ( $type eq '' || $type eq '!' ) {
  495.         if ( defined $optarg ) {
  496.         print STDERR ("Option ", $opt, " does not take an argument\n");
  497.         $error++;
  498.         }
  499.         elsif ( $type eq '' ) {
  500.         $arg = 1;        # supply explicit value
  501.         }
  502.         else {
  503.         substr ($opt, 0, 2) = ''; # strip NO prefix
  504.         $arg = 0;        # supply explicit value
  505.         }
  506.         next;
  507.     }
  508.  
  509.     # Get mandatory status and type info.
  510.     ($mand, $type, $array) = $type =~ /^(.)(.)(@?)$/;
  511.  
  512.     # Check if there is an option argument available.
  513.     if ( defined $optarg ? ($optarg eq '') : ($#ARGV < 0) ) {
  514.  
  515.         # Complain if this option needs an argument.
  516.         if ( $mand eq "=" ) {
  517.         print STDERR ("Option ", $opt, " requires an argument\n");
  518.         $error++;
  519.         }
  520.         if ( $mand eq ":" ) {
  521.         $arg = $type eq "s" ? '' : 0;
  522.         }
  523.         next;
  524.     }
  525.  
  526.     # Get (possibly optional) argument.
  527.     $arg = defined $optarg ? $optarg : shift (@ARGV);
  528.  
  529.     #### Check if the argument is valid for this option ####
  530.  
  531.     if ( $type eq "s" ) {    # string
  532.         # A mandatory string takes anything. 
  533.         next if $mand eq "=";
  534.  
  535.         # An optional string takes almost anything. 
  536.         next if defined $optarg;
  537.         next if $arg eq "-";
  538.  
  539.         # Check for option or option list terminator.
  540.         if ($arg eq $argend ||
  541.         $arg =~ /^$genprefix.+/) {
  542.         # Push back.
  543.         unshift (@ARGV, $arg);
  544.         # Supply empty value.
  545.         $arg = '';
  546.         }
  547.         next;
  548.     }
  549.  
  550.     if ( $type eq "n" || $type eq "i" ) { # numeric/integer
  551.         if ( $arg !~ /^-?[0-9]+$/ ) {
  552.         if ( defined $optarg || $mand eq "=" ) {
  553.             print STDERR ("Value \"", $arg, "\" invalid for option ",
  554.                   $opt, " (number expected)\n");
  555.             $error++;
  556.             undef $arg;    # don't assign it
  557.         }
  558.         else {
  559.             # Push back.
  560.             unshift (@ARGV, $arg);
  561.             # Supply default value.
  562.             $arg = 0;
  563.         }
  564.         }
  565.         next;
  566.     }
  567.  
  568.     if ( $type eq "f" ) { # fixed real number, int is also ok
  569.         if ( $arg !~ /^-?[0-9.]+$/ ) {
  570.         if ( defined $optarg || $mand eq "=" ) {
  571.             print STDERR ("Value \"", $arg, "\" invalid for option ",
  572.                   $opt, " (real number expected)\n");
  573.             $error++;
  574.             undef $arg;    # don't assign it
  575.         }
  576.         else {
  577.             # Push back.
  578.             unshift (@ARGV, $arg);
  579.             # Supply default value.
  580.             $arg = 0.0;
  581.         }
  582.         }
  583.         next;
  584.     }
  585.  
  586.     die ("NGetOpt internal error (Can't happen)\n");
  587.     }
  588.  
  589.     continue {
  590.     if ( defined $arg ) {
  591.         $opt = $aliases{$opt} if defined $aliases{$opt};
  592.         # Make sure a valid perl identifier results.
  593.         $opt =~ s/\W/_/g;
  594.         if ( $array ) {
  595.         print STDERR ('=> push (@', $pkg, '\'opt_', $opt, ", \"$arg\")\n")
  596.             if $debug;
  597.             eval ('push(@' . $pkg . '\'opt_' . $opt . ", \$arg);");
  598.         }
  599.         else {
  600.         print STDERR ('=> $', $pkg, '\'opt_', $opt, " = \"$arg\"\n")
  601.             if $debug;
  602.             eval ('$' . $pkg . '\'opt_' . $opt . " = \$arg;");
  603.         }
  604.     }
  605.     }
  606.  
  607.     if ( $order == $PERMUTE && @ret > 0 ) {
  608.     unshift (@ARGV, @ret);
  609.     }
  610.     return ($error == 0);
  611. }
  612.  
  613. ################ Package return ################
  614.  
  615. 1;
  616.  
  617.  
  618.