Changeset 11309 for trunk


Ignore:
Timestamp:
2006-03-08T11:40:01+13:00 (18 years ago)
Author:
kjdon
Message:

now uses new parse2 parsing instead of old parsargv, and creator no longer checked for syntax

File:
1 edited

Legend:

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

    r9060 r11309  
    3939}
    4040
    41 use parsargv;
     41use parse2;
    4242use util;
    4343use cfgread;
    44 use gsprintf;
     44use gsprintf 'gsprintf';
    4545use printusage;
     46
     47use strict;
     48no strict 'subs'; # allow barewords (eg STDERR) as function arguments
     49
     50my $public_list =
     51    [ { 'name' => "true",
     52    'desc' => "{mkcol.public.true}"},
     53      { 'name' => "false",
     54    'desc' => "{mkcol.public.false}"}
     55      ];
     56
     57my $win31compat_list =
     58    [ { 'name' => "true",
     59    'desc' => "{mkcol.win31compat.true}"},
     60      { 'name' => "false",
     61    'desc' => "{mkcol.win31compat.false}"}
     62      ];
    4663
    4764my $arguments =
     
    6582      { 'name' => "public",
    6683    'desc' => "{mkcol.public}",
    67     'type' => "string",
     84    'type' => "enum",
    6885    'deft' => "true",
     86    'list' => $public_list,
    6987    'reqd' => "no" },
    7088      { 'name' => "title",
     
    90108      { 'name' => "win31compat",
    91109    'desc' => "{mkcol.win31compat}",
    92     'type' => "string",
     110    'type' => "enum",
    93111    'deft' => "true",
    94     'reqd' => "no" } ];
     112    'list' => $win31compat_list,
     113    'reqd' => "no" },
     114      { 'name' => "gli",
     115    'desc' => "",
     116    'type' => "flag",
     117    'reqd' => "no",
     118    'hiddengli' => "yes" },
     119      { 'name' => "xml",
     120    'desc' => "{scripts.xml}",
     121    'type' => "flag",
     122    'reqd' => "no",
     123    'hiddengli' => "yes" }
     124      ];
    95125
    96126my $options = { 'name' => "mkcol.pl",
     
    98128        'args' => $arguments };
    99129
    100 sub gsprintf
    101 {
    102     return &gsprintf::gsprintf(@_);
    103 }
     130# options
     131my ($creator, $optionfile, $maintainer, $collectdir, $public,
     132    $title, $about, $plugin, $quiet, $language, $win31compat, $gli);
     133
     134#other variables
     135my ($collection, $capcollection, $pluginstring, @plugin);
     136
     137&main();
    104138
    105139
     
    126160    closedir(DIR);
    127161
    128     foreach $file (@files)
     162    foreach my $file (@files)
    129163    {
    130164    my $thisfile = &util::filename_cat ($modeldir, $file);
     
    146180        (&gsprintf(STDERR, "{common.cannot_create_file}\n", $destfile) && die);
    147181
    148         while (defined ($line = <INFILE>)) {
     182        while (defined (my $line = <INFILE>)) {
    149183        $line =~ s/\*\*collection\*\*/$collection/g;
    150184        $line =~ s/\*\*COLLECTION\*\*/$capcollection/g;
     
    165199}
    166200
    167 # get and check options
    168 sub parse_args {
    169     my ($argref) = @_;
    170     if (!&parsargv::parse($argref,
    171               'language/.*/', \$language,
    172               'optionfile/.*/', \$optionfile,
    173               'collectdir/.*/', \$collectdir,
    174               'creator/\w+\@[\w\.]+/', \$creator,
    175               'maintainer/\w+\@[\w\.]+/', \$maintainer,
    176               'public/true|false/true', \$public,
    177               'title/.+/', \$title,
    178               'about/.+/', \$about,
    179               'plugin/.+', \@plugin,
    180               'quiet', \$quiet,
    181               'win31compat/true|false/true', \$win31compat,
    182               'gli', \$gli,
    183               q^xml^, \$xml
    184               )) {
     201
     202sub main {
     203   
     204    my $xml = 0;
     205   
     206    my $hashParsingResult = {};
     207    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)
     210    {
    185211    &PrintUsage::print_txt_usage($options, "{mkcol.params}");
    186212    die "\n";
    187213    }
    188 }
    189 
    190 sub main {
    191 
    192     &parse_args (\@ARGV);
     214   
     215    foreach my $strVariable (keys %$hashParsingResult)
     216    {
     217    eval "\$$strVariable = \$hashParsingResult->{\"\$strVariable\"}";
     218    }
     219
    193220
    194221    # If $language has been specified, load the appropriate resource bundle
    195222    # (Otherwise, the default resource bundle will be loaded automatically)
    196     if ($language) {
     223    if ($language && $language =~ /\S/) {
    197224    &gsprintf::load_language_specific_resource_bundle($language);
    198225    }
     
    200227    if ($xml) {
    201228    &PrintUsage::print_xml_usage($options);
    202     die "\n";
     229    print "\n";
     230    return;
    203231    }
    204232
     
    216244    }
    217245    close OPTIONS;
    218     &parse_args ($options);
    219     }
    220 
     246    my $optionsParsingResult = {};
     247    my $optionsParseFailed = "false";
     248    if (!parse2::parse($options,$arguments,$optionsParsingResult)) {
     249        &PrintUsage::print_txt_usage($options, "{mkcol.params}");
     250        die "\n";
     251    }
     252       
     253    foreach my $strVariable (keys %$optionsParsingResult)
     254    {
     255        eval "\$$strVariable = \$optionsParsingResult->{\"\$strVariable\"}";
     256    }
     257    }
     258   
    221259    # load default plugins if none were on command line
    222260    if (!scalar(@plugin)) {
     
    248286    }
    249287
    250     # We don't want creator to be required anymore - John Thompson 28-11-2003
    251     #if (!defined($creator) || $creator eq "") {
    252     #   &gsprintf(STDOUT, "{mkcol.creator_undefined}\n");
    253     #   die "\n";
    254     #}
    255 
    256     #Of course thats means we don't want to default maintainer unless a creator is provided
    257288    if (defined($creator) && (!defined($maintainer) || $maintainer eq "")) {
    258289    $maintainer = $creator;
     
    271302    # get the strings to include.
    272303    $pluginstring = "";
    273     foreach $plugin (@plugin) {
    274     $pluginstring .= "plugin         $plugin\n";
    275     }
    276 
    277     $mdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", "modelcol");
     304    foreach my $plug (@plugin) {
     305    $pluginstring .= "plugin         $plug\n";
     306    }
     307
     308    my $mdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", "modelcol");
     309    my $cdir;
    278310    if (defined $collectdir && $collectdir =~ /\w/) {
    279311    if (!-d $collectdir) {
     
    303335}
    304336
    305 &main ();
     337
Note: See TracChangeset for help on using the changeset viewer.