Changeset 12545


Ignore:
Timestamp:
2006-08-24T16:17:35+12:00 (18 years ago)
Author:
kjdon
Message:

changed parse2::parse so that it returns -1 on error, 0 on success, or if allow_extra_options is specified, then on success returns the number of args left over. allowed the use of -h to print the usage for all scripts

Location:
trunk/gsdl/bin/script
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/bin/script/buildcol.pl

    r12500 r12545  
    227227
    228228    my $hashParsingResult = {};
    229     my $blnParseFailed = "false";
    230229    # general options available to all plugins
    231230    my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
    232231
    233     # If there are more than one argument left after parsing, it mean user input too many arguments.
    234     # Error occoured  will return 0
    235     if ($intArgLeftinAfterParsing != 1)
     232    # If parse returns -1 then something has gone wrong
     233    if ($intArgLeftinAfterParsing == -1)
    236234    {
    237     $blnParseFailed = "true";
    238     }
    239     if($blnParseFailed eq "true")
    240     {
    241     print "";
    242235    &PrintUsage::print_txt_usage($options, "{buildcol.params}");
    243236    die "\n";
    244237    }
     238   
    245239    foreach my $strVariable (keys %$hashParsingResult)
    246240    {
     
    264258    }
    265259
     260    # now check that we had exactly one leftover arg, which should be
     261    # the collection name. We don't want to do this earlier, cos
     262    # -xml arg doesn't need a collection name
     263    # Or if the user specified -h, then we output the usage also
     264    if ($intArgLeftinAfterParsing != 1 || (@ARGV && $ARGV[0] =~ /^\-+h/))
     265    {
     266    &PrintUsage::print_txt_usage($options, "{buildcol.params}");
     267    die "\n";
     268    }
     269   
    266270    $textindex = "";
    267271    my $close_out = 0;
  • trunk/gsdl/bin/script/classinfo.pl

    r11683 r12545  
    8585
    8686    my $hashParsingResult = {};
    87     my $blnParseFailed = "false";
    88     # general options available to all plugins
     87    # general options available to all classifiers
    8988    my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
    90     # If there are more than one argument left after parsing, it mean user input too many arguments.
    91     # Error occoured  will return 0
    92     if($intArgLeftinAfterParsing > 1)
     89    # parse returns -1 if an error occurred
     90    if($intArgLeftinAfterParsing == -1)
    9391    {
    9492    &PrintUsage::print_txt_usage($options, "{classinfo.params}");
     
    104102    if ($language) {
    105103    &gsprintf::load_language_specific_resource_bundle($language);
     104    }
     105   
     106    # If there is not exactly 1 argument left (classifier name), then the arguments were wrong
     107    # Or if the user specified -h, then we output the usage also
     108    if( $intArgLeftinAfterParsing != 1 || (@ARGV && $ARGV[0] =~ /^\-+h/) )
     109    {
     110    PrintUsage::print_txt_usage($options, "{classinfo.params}"); 
     111        die "\n";
    106112    }
    107113
  • trunk/gsdl/bin/script/downloadinfo.pl

    r11786 r12545  
    8686    my $unparsed_args = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
    8787
     88    # parse returns -1 on error
     89    if ($unparsed_args == -1) {
     90    PrintUsage::print_txt_usage($options, "{pluginfo.params}");
     91    die "\n";
     92    }
     93
    8894    foreach my $strVariable (keys %$hashParsingResult)
    8995    {
     
    118124    }
    119125   
    120     # If there are more than one argument left after parsing, it mean user input too many arguments.
    121     # Error occoured  will return 0
    122     if( $unparsed_args > 1 or (@ARGV && $ARGV[0] =~ /^\-+h/) )
     126    # If there is not exactly one argument left (download name), then the arguments were wrong
     127    # Or if the user specified -h, then we output the usage also
     128
     129    if( $unparsed_args != 1 || (@ARGV && $ARGV[0] =~ /^\-+h/) )
    123130    {
    124     PrintUsage::print_txt_usage($options, "{pluginfo.params}");
     131    PrintUsage::print_txt_usage($options, "{downloadinfo.params}");
    125132    die "\n";
    126133    }
  • trunk/gsdl/bin/script/explode_metadata_database.pl

    r12290 r12545  
    9898
    9999    my $hashParsingResult = {};
    100     my $blnParseFailed = "false";
    101100    # parse the options
    102101    my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
     102
     103    # If parse returns -1 then something has gone wrong
     104    if ($intArgLeftinAfterParsing == -1)
     105    {
     106    &PrintUsage::print_txt_usage($options, "{explode.params}");
     107    die "\n";
     108    }
    103109
    104110    foreach my $strVariable (keys %$hashParsingResult)
     
    119125    }
    120126
    121     # There should one arg left after parsing
    122     if($intArgLeftinAfterParsing > 1)
     127    # There should one arg left after parsing (the filename)
     128    # Or the user may have specified -h, in which case we output the usage
     129    if($intArgLeftinAfterParsing != 1 || (@ARGV && $ARGV[0] =~ /^\-+h/))
    123130    {
    124131    &PrintUsage::print_txt_usage($options, "{explode.params}");
  • trunk/gsdl/bin/script/export.pl

    r12361 r12545  
    235235
    236236    my $hashParsingResult = {};
    237     my $blnParseFailed = "false";
    238237    # general options available to all plugins
    239238    my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
    240     # can have more than one collection name, so don't check num args left   
     239   
     240    # If parse returns -1 then something has gone wrong
     241    if ($intArgLeftinAfterParsing == -1)
     242    {
     243    &PrintUsage::print_txt_usage($options, "{export.params}");
     244    die "\n";
     245    }
     246
    241247    foreach my $strVariable (keys %$hashParsingResult)
    242248    {
     
    280286    }
    281287
    282     if (scalar(@ARGV) == 0) {
     288    # can have more than one collection name, 
     289    # if the first extra option is -h, then output the help
     290    if (scalar(@ARGV) == 0 || (@ARGV && $ARGV[0] =~ /^\-+h/)) {
    283291    &PrintUsage::print_txt_usage($options, "{export.params}");
    284292    die "\n";
  • trunk/gsdl/bin/script/exportcol.pl

    r11944 r12545  
    9797
    9898    my $hashParsingResult = {};
    99     my $blnParseFailed = "false";
     99
    100100    # parse options
    101101    my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
    102     # don't care how many args are left - can have multiple collection names
     102
     103    # If parse returns -1 then something has gone wrong
     104    if ($intArgLeftinAfterParsing == -1)
     105    {
     106    &PrintUsage::print_txt_usage($options, "{exportcol.params}");
     107    die "\n";
     108    }
     109   
    103110    foreach my $strVariable (keys %$hashParsingResult)
    104111    {
     
    122129    }
    123130   
     131    # can have more than one collection name, 
     132    # if the first extra option is -h, then output the help
     133    if (scalar(@ARGV) == 0 || (@ARGV && $ARGV[0] =~ /^\-+h/)) {
     134    &PrintUsage::print_txt_usage($options, "{exportcol.params}");
     135    die "\n";
     136    }
     137
    124138    my @coll_list = @ARGV;
    125    
    126     if (not @coll_list) { # empty list
    127     &PrintUsage::print_txt_usage($options, "{exportcol.params}");
    128     exit(1);
    129     }
    130139
    131140    my $close_out = 0;
  • trunk/gsdl/bin/script/import.pl

    r12500 r12545  
    251251
    252252    my $hashParsingResult = {};
    253     my $blnParseFailed = "false";
    254253    # general options available to all plugins
    255254    my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
    256     # If there is more than one argument left after parsing, it mean user input too many arguments.
    257     if($intArgLeftinAfterParsing > 1)
     255    # Parse returns -1 if something has gone wrong
     256    if($intArgLeftinAfterParsing == -1)
    258257    {
    259258    &PrintUsage::print_txt_usage($options, "{import.params}");
     
    280279    if ($gli) { # the gli wants strings to be in UTF-8
    281280    &gsprintf::output_strings_in_UTF8;
     281    }
     282   
     283    # now check that we had exactly one leftover arg, which should be
     284    # the collection name. We don't want to do this earlier, cos
     285    # -xml arg doesn't need a collection name
     286    # Or if the user specified -h, then we output the usage also
     287    if ($intArgLeftinAfterParsing != 1 || (@ARGV && $ARGV[0] =~ /^\-+h/))
     288    {
     289    &PrintUsage::print_txt_usage($options, "{buildcol.params}");
     290    die "\n";
    282291    }
    283292
  • trunk/gsdl/bin/script/mkcol.pl

    r11330 r12545  
    206206    my $hashParsingResult = {};
    207207    my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
    208     # If there is more than one argument left after parsing, it mean user input too many arguments.
    209     if($intArgLeftinAfterParsing > 1)
     208   
     209    # If parse returns -1 then something has gone wrong
     210    if ($intArgLeftinAfterParsing == -1)
    210211    {
    211212    &PrintUsage::print_txt_usage($options, "{mkcol.params}");
     
    217218    eval "\$$strVariable = \$hashParsingResult->{\"\$strVariable\"}";
    218219    }
    219 
    220220
    221221    # If $language has been specified, load the appropriate resource bundle
     
    234234    &gsprintf::output_strings_in_UTF8;
    235235    }
    236    
     236
     237    # now check that we had exactly one leftover arg, which should be
     238    # the collection name. We don't want to do this earlier, cos
     239    # -xml arg doesn't need a collection name
     240    # Or if the user specified -h, then we output the usage also
     241    if ($intArgLeftinAfterParsing != 1 || (@ARGV && $ARGV[0] =~ /^\-+h/))
     242    {
     243    &PrintUsage::print_txt_usage($options, "{mkcol.params}");
     244    die "\n";
     245    }
     246
    237247    if ($optionfile =~ /\w/) {
    238248    open (OPTIONS, $optionfile) ||
     
    245255    close OPTIONS;
    246256    my $optionsParsingResult = {};
    247     my $optionsParseFailed = "false";
    248     if (!parse2::parse($options,$arguments,$optionsParsingResult)) {
     257    if (parse2::parse($options,$arguments,$optionsParsingResult) == -1) {
    249258        &PrintUsage::print_txt_usage($options, "{mkcol.params}");
    250259        die "\n";
  • trunk/gsdl/bin/script/pluginfo.pl

    r11683 r12545  
    8585
    8686    my $hashParsingResult = {};
    87     my $blnParseFailed = "false";
    8887    # general options available to all plugins
    8988    my $unparsed_args = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
    90 
     89    # parse returns -1 if an error occurred
     90    if ($unparsed_args == -1) {
     91   
     92    PrintUsage::print_txt_usage($options, "{pluginfo.params}");
     93    die "\n";
     94    }
     95   
    9196    foreach my $strVariable (keys %$hashParsingResult)
    9297    {
     
    121126    }
    122127
    123     # If there are more than one argument left after parsing, it mean user input too many arguments.
    124     # Error occoured  will return 0
    125     if( $unparsed_args > 1 or (@ARGV && $ARGV[0] =~ /^\-+h/) )
     128    # If there is not exactly 1 argument left (plugin name), then the arguments were wrong
     129    # Or if the user specified -h, then we output the usage also
     130    if( $unparsed_args != 1 || (@ARGV && $ARGV[0] =~ /^\-+h/) )
    126131    {
    127     PrintUsage::print_txt_usage($options, "{pluginfo.params}");
    128     die "\n";
    129     }
    130 
     132    PrintUsage::print_txt_usage($options, "{pluginfo.params}"); 
     133        die "\n";
     134    }
     135   
    131136    my $plugin = shift (@ARGV);
    132137    if (defined $plugin) {
  • trunk/gsdl/bin/script/plugoutinfo.pl

    r12334 r12545  
    8585
    8686    my $hashParsingResult = {};
    87     my $blnParseFailed = "false";
    88     # general options available to all plugins
     87    # general options available to all plugouts
    8988    my $unparsed_args = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
    9089
     90    # parse returns -1 if an error occurred
     91    if ($unparsed_args == -1) {
     92   
     93    PrintUsage::print_txt_usage($options, "{plugoutinfo.params}");
     94    die "\n";
     95    }
     96   
    9197    foreach my $strVariable (keys %$hashParsingResult)
    9298    {
     
    100106    }
    101107 
    102 
    103108    # if language wasn't specified, see if it is set in the environment
    104109    # (LC_ALL or LANG)
     
    123128    }
    124129
    125     # If there are more than one argument left after parsing, it mean user input too many arguments.
    126     # Error occoured  will return 0
    127     if( $unparsed_args > 1 or (@ARGV && $ARGV[0] =~ /^\-+h/) )
     130    # If there is not exactly 1 argument left (plugout name), then the arguments were wrong
     131    # Or if the user specified -h, then we output the usage also
     132    if( $unparsed_args != 1 || (@ARGV && $ARGV[0] =~ /^\-+h/) )
    128133    {
    129     PrintUsage::print_txt_usage($options, "{plugoutinfo.params}");
    130     die "\n";
     134    PrintUsage::print_txt_usage($options, "{plugoutinfo.params}"); 
     135        die "\n";
    131136    }
    132137
Note: See TracChangeset for help on using the changeset viewer.