[71e7014] | 1 | #!/usr/local/bin/perl |
---|
[a70441f] | 2 | # $Id: doc2idx.pl,v 1.2 2000-04-27 10:07:19 obachman Exp $ |
---|
[71e7014] | 3 | ################################################################### |
---|
| 4 | # Computer Algebra System SINGULAR |
---|
| 5 | # |
---|
| 6 | # doc2idx.pl: utility to index file for singular manual |
---|
| 7 | # |
---|
| 8 | # Prints to stdout lines of the following form |
---|
| 9 | # |
---|
| 10 | # $indexentry\t$nodename\t$url\t$chksum |
---|
| 11 | # |
---|
| 12 | # where $indexentry: entries of index (all lower case) |
---|
| 13 | # $nodename : name of node where index entry occured |
---|
| 14 | # $url : url of node |
---|
| 15 | # $chksum : checksum of help text, if library proc node |
---|
| 16 | # lines are sorted alphabetically w.r.t. $indexentry |
---|
| 17 | |
---|
| 18 | #### |
---|
| 19 | $Usage = <<EOT; |
---|
| 20 | Usage: |
---|
| 21 | $0 singular-index-file html-index-file chksum-db |
---|
| 22 | Outputs sorted lines of the form $indexentry\t$nodename\t$url\t$chksum |
---|
| 23 | EOT |
---|
| 24 | |
---|
| 25 | ################################################################### |
---|
| 26 | # parse command line options |
---|
| 27 | # |
---|
| 28 | die "Need 3 arguments:\n $Usage" unless (scalar(@ARGV) == 3); |
---|
| 29 | |
---|
| 30 | # open files |
---|
| 31 | open (HLP, "<$ARGV[0]") || die "Can't open $ARGV[0]: $!\n"; |
---|
| 32 | open (URL, "<$ARGV[1]") || die "Can't open $ARGV[1]: $!\n"; |
---|
| 33 | $db_file = $ARGV[2]; |
---|
[a70441f] | 34 | unless ($return = do $db_file) |
---|
| 35 | { |
---|
| 36 | die "couldn't parse $db_file: $@" if $@; |
---|
| 37 | die "couldn't do $db_file: $!" unless defined $return; |
---|
| 38 | die "couldn't run $db_file" unless $return; |
---|
| 39 | } |
---|
[71e7014] | 40 | |
---|
| 41 | # fill hashes |
---|
| 42 | # first: HLP |
---|
| 43 | while (<HLP>) |
---|
| 44 | { |
---|
| 45 | if (/Node: Index/) |
---|
| 46 | { |
---|
| 47 | while (<HLP>) |
---|
| 48 | { |
---|
| 49 | last if /\* Menu:/; |
---|
| 50 | } |
---|
| 51 | <HLP>; |
---|
| 52 | while (<HLP>) |
---|
| 53 | { |
---|
| 54 | last if /^\s*$/; |
---|
| 55 | if (/^\* (.*?): (.*)\.$/) |
---|
| 56 | { |
---|
| 57 | $entry = $1; |
---|
| 58 | $node = $2; |
---|
| 59 | } |
---|
| 60 | $entry =~ s/\s*(.*) <\d+>\s*$/$1/; |
---|
| 61 | $node =~ s/^\s*(.*)\s*$/$1/; |
---|
| 62 | $index->{$entry}->{Node} = $node unless $entry eq $prev; |
---|
| 63 | $prev = $entry; |
---|
| 64 | } |
---|
| 65 | last; |
---|
| 66 | } |
---|
| 67 | } |
---|
| 68 | close(HLP); |
---|
| 69 | |
---|
| 70 | while (<URL>) |
---|
| 71 | { |
---|
| 72 | ($entry, $url) = split(/\t/); |
---|
| 73 | $url =~ s/^\s*(.*)\s*$/$1/; |
---|
| 74 | $index->{$entry}->{Url} = $url; |
---|
| 75 | } |
---|
| 76 | close(URL); |
---|
| 77 | |
---|
| 78 | for $entry (sort keys %$index) |
---|
| 79 | { |
---|
[a70441f] | 80 | print "$entry\t$index->{$entry}->{Node}\t$index->{$entry}->{Url}\t$CHECKSUMS{$entry}\n"; |
---|
[71e7014] | 81 | } |
---|
| 82 | |
---|
| 83 | |
---|