Ignore:
Timestamp:
2012-08-20T18:09:15+12:00 (12 years ago)
Author:
ak19
Message:

Now handles nested {If} and {Or} statements. Tested this on the only collect.cfg I know with a nested statement: the collect.cfg in the advanced beatles tutorial collection. These changes were to get the Looking at a Multimedia Collection to work for GS3.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/bin/script/convert_coll_from_gs2.pl

    r25731 r26124  
    716716}
    717717
     718sub format_if_or {
     719    my ($format, $node_type) = @_;
     720
     721    # while we find nested if/or statements, recurse to find more nested if/or statements,
     722    # and try to expand (process) these nested statements starting from innermost going to outermost
     723
     724    while($format =~ m/^.*\{(?:If|Or)\}\{[^\}\{]*\{/) { # contains nested if/or statement, expand it
     725
     726    my ($prefix, $nested_to_process, $suffix) = $format =~ m/^(.*\{(?:If|Or)\}\{[^\}\{]*)(\{[^\}]*\}\s*\{[^\}]*\})(.*)$/g; # recursion step
     727
     728    #print STDERR "prefix: |$prefix|\n\nnested: |$nested_to_process|\n\nsuffix: |$suffix|\n\n";
     729    $format = $prefix . &format_if_or($nested_to_process, $node_type) . $suffix;
     730    }
     731
     732    if($format =~ m/\{(If|Or)\}\{[^\}\{]*\}/g) { # base step: contains if/or statement(s), but none nested
     733    # expand them
     734    $format =~ s/\{If\}\{([^\}]*)\}/&format_if($1, $node_type)/eg;
     735    $format =~ s/\{Or\}\{([^\}]*)\}/&format_or($1)/eg;
     736    }
     737    return $format;
     738}
     739
    718740sub write_format {
    719741    my ($writer, $old_format, $node_type) = @_;
     
    723745    $old_format =~ s/\\\"/\"/g;
    724746    #convert [] to <gsf:...>
    725     # assume no nesting {If} or {Or} for now
    726     $old_format =~ s/\{If\}\{([^\}]*)\}/&format_if($1, $node_type)/eg;
    727     $old_format =~ s/\{Or\}\{([^\}]*)\}/&format_or($1)/eg;
     747    # now handles nested {If} and {Or}
     748    $old_format = &format_if_or($old_format, $node_type);
    728749    $old_format =~ s/\[Text\]/\<gsf:text\/\>/g;
    729750    $old_format =~ s/\[num\]/\<gsf:num\/\>/g;
Note: See TracChangeset for help on using the changeset viewer.