Changeset 2450

Show
Ignore:
Timestamp:
21.05.2001 18:00:29 (19 years ago)
Author:
jrm21
Message:

now accepts the "-title_sub" option, a regexp to remove when automatically
extracting title from text.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/perllib/plugins/TEXTPlug.pm

    r2219 r2450  
    3030 
    3131use BasPlug; 
     32use parsargv; 
     33 
    3234 
    3335sub BEGIN { 
     
    3537} 
    3638 
     39sub print_usage { 
     40    print STDERR "\n  usage: plugin TEXTPlug [options]\n\n"; 
     41    print STDERR "  options:\n"; 
     42    print STDERR "   -title_sub\t     Substitution expression to modify string stored as Title.\n"; 
     43    print STDERR "\t\t     Used by, for example, PSPlug to remove \"Page 1\" etc from\n"; 
     44    print STDERR "\t\t     text used as the title.\n"; 
     45 
     46    print STDERR "\n"; 
     47} 
     48 
    3749sub new { 
    3850    my ($class) = @_; 
    3951    my $self = new BasPlug ($class, @_); 
     52 
     53    if (!parsargv::parse(\@_,  
     54             q^title_sub/.*/^, \$self->{'title_sub'}, 
     55             "allow_extra_options")) { 
     56    print STDERR "\nIncorrect options passed to TEXTPlug, check your collect.cfg configuration file\n"; 
     57    &print_usage(); 
     58        die "\n"; 
     59    } 
     60 
    4061 
    4162    return bless $self, $class; 
     
    6384    # in from another plugin) 
    6485    if (!defined $metadata->{'Title'}) { 
    65     my ($title) = $$textref =~ /^\s*([^\n]*)/; 
     86    my ($title) = $$textref; 
     87    $title =~ /^\s+/s; 
     88    if (defined $self->{'title_sub'}) {$title =~ s/$self->{'title_sub'}//;} 
     89    $title =~ /^\s*([^\n]*)/s; $title=$1; 
    6690    if (length($title) > 100) { 
    67         $title = substr ($title, 0, 100); 
     91        $title = substr ($title, 0, 100) . "..."; 
    6892    } 
    6993    $doc_obj->add_utf8_metadata ($cursection, "Title", $title);