source: git/doc/doc2idx.pl

spielwiese
Last change on this file was cc0709a, checked in by Frédéric Chapoton <chapoton@…>, 9 months ago
fix some file encodings (to utf8) and some typos in doc/ folder
  • Property mode set to 100644
File size: 1.9 KB
Line 
1#!/usr/local/bin/perl
2###################################################################
3#  Computer Algebra System SINGULAR
4#
5#  doc2idx.pl: utility to index file for singular manual
6#
7#  Prints to stdout lines of the following form
8#
9#  $indexentry\t$nodename\t$url\t$chksum
10#
11#  where $indexentry: entries of index (all lower case)
12#        $nodename  : name of node where index entry occurred
13#        $url       : url of node
14#        $chksum    : checksum of help text, if library proc node
15# lines are sorted alphabetically w.r.t. $indexentry
16
17####
18$Usage = <<EOT;
19Usage:
20$0 singular-index-file html-index-file chksum-db
21Outputs sorted lines of the form $indexentry\t$nodename\t$url\t$chksum
22EOT
23
24###################################################################
25# parse command line options
26#
27die "Need 3 arguments:\n $Usage" unless (scalar(@ARGV) == 3);
28
29# open files
30open (HLP, "<$ARGV[0]") || die "Can't open $ARGV[0]: $!\n";
31open (URL, "<$ARGV[1]") || die "Can't open $ARGV[1]: $!\n";
32$db_file = $ARGV[2];
33unless ($return = do $db_file)
34{
35  die "couldn't parse $db_file: $@" if $@;
36  die "couldn't do $db_file: $!"    unless defined $return;
37  die "couldn't run $db_file"       unless $return;
38}
39
40# fill hashes
41# first: HLP
42while (<HLP>)
43{
44  if (/Node: Index/)
45  {
46    while (<HLP>)
47    {
48      last if /\* Menu:/;
49    }
50    <HLP>;
51    while (<HLP>)
52    {
53      last if /^\s*$/;
54      if (/^\* (.*?): (.*)\.$/)
55      {
56        $entry = $1;
57        $node = $2;
58      }
59      $entry =~ s/\s*(.*) <\d+>\s*$/$1/;
60      $node =~ s/^\s*(.*)\s*$/$1/;
61      $index->{$entry}->{Node} = $node unless $entry eq $prev;
62      $prev = $entry;
63    }
64    last;
65  }
66}
67close(HLP);
68
69while (<URL>)
70{
71  ($entry, $url) = split(/\t/);
72  $url =~ s/^\s*(.*)\s*$/$1/;
73  $index->{$entry}->{Url} = $url;
74}
75close(URL);
76
77for $entry (sort keys %$index)
78{
79  print "$entry\t$index->{$entry}->{Node}\t$index->{$entry}->{Url}\t$CHECKSUMS{$entry}\n";
80}
81
82
Note: See TracBrowser for help on using the repository browser.