API documentation updated
[chessclock] / www / html / installdox
1 #!/usr/bin/perl
2
3 %subst = ( );
4 $quiet   = 0;
5
6 if (open(F,"search.cfg"))
7 {
8   $_=<F> ; s/[ \t\n]*$//g ; $subst{"_doc"} = $_;
9   $_=<F> ; s/[ \t\n]*$//g ; $subst{"_cgi"} = $_;
10 }
11
12 while ( @ARGV ) {
13   $_ = shift @ARGV;
14   if ( s/^-// ) {
15     if ( /^l(.*)/ ) {
16       $v = ($1 eq "") ? shift @ARGV : $1;
17       ($v =~ /\/$/) || ($v .= "/");
18       $_ = $v;
19       if ( /(.+)\@(.+)/ ) {
20         if ( exists $subst{$1} ) {
21           $subst{$1} = $2;
22         } else {
23           print STDERR "Unknown tag file $1 given with option -l\n";
24           &usage();
25         }
26       } else {
27         print STDERR "Argument $_ is invalid for option -l\n";
28         &usage();
29       }
30     }
31     elsif ( /^q/ ) {
32       $quiet = 1;
33     }
34     elsif ( /^\?|^h/ ) {
35       &usage();
36     }
37     else {
38       print STDERR "Illegal option -$_\n";
39       &usage();
40     }
41   }
42   else {
43     push (@files, $_ );
44   }
45 }
46
47 foreach $sub (keys %subst)
48 {
49   if ( $subst{$sub} eq "" ) 
50   {
51     print STDERR "No substitute given for tag file `$sub'\n";
52     &usage();
53   }
54   elsif ( ! $quiet && $sub ne "_doc" && $sub ne "_cgi" )
55   {
56     print "Substituting $subst{$sub} for each occurence of tag file $sub\n"; 
57   }
58 }
59
60 if ( ! @files ) {
61   if (opendir(D,".")) {
62     foreach $file ( readdir(D) ) {
63       $match = ".html";
64       next if ( $file =~ /^\.\.?$/ );
65       ($file =~ /$match/) && (push @files, $file);
66       ($file =~ "tree.js") && (push @files, $file);
67     }
68     closedir(D);
69   }
70 }
71
72 if ( ! @files ) {
73   print STDERR "Warning: No input files given and none found!\n";
74 }
75
76 foreach $f (@files)
77 {
78   if ( ! $quiet ) {
79     print "Editing: $f...\n";
80   }
81   $oldf = $f;
82   $f   .= ".bak";
83   unless (rename $oldf,$f) {
84     print STDERR "Error: cannot rename file $oldf\n";
85     exit 1;
86   }
87   if (open(F,"<$f")) {
88     unless (open(G,">$oldf")) {
89       print STDERR "Error: opening file $oldf for writing\n";
90       exit 1;
91     }
92     if ($oldf ne "tree.js") {
93       while (<F>) {
94         s/doxygen\=\"([^ \"\:\t\>\<]*)\:([^ \"\t\>\<]*)\" (href|src)=\"\2/doxygen\=\"$1:$subst{$1}\" \3=\"$subst{$1}/g;
95         print G "$_";
96       }
97     }
98     else {
99       while (<F>) {
100         s/\"([^ \"\:\t\>\<]*)\:([^ \"\t\>\<]*)\", \"\2/\"$1:$subst{$1}\" ,\"$subst{$1}/g;
101         print G "$_";
102       }
103     }
104   } 
105   else {
106     print STDERR "Warning file $f does not exist\n";
107   }
108   unlink $f;
109 }
110
111 sub usage {
112   print STDERR "Usage: installdox [options] [html-file [html-file ...]]\n";
113   print STDERR "Options:\n";
114   print STDERR "     -l tagfile\@linkName   tag file + URL or directory \n";
115   print STDERR "     -q                    Quiet mode\n\n";
116   exit 1;
117 }