DyninstAPI defensive mode manual update.
[dyninst.git] / instructionAPI / doc / latex / manual-preproc.pl
1 #!/usr/bin/perl
2
3 use File::Temp "tempfile";
4
5 # Edit subsection numbering in the main document:
6 # 2 levels of subsection in the TOC, 2 levels numbered
7 # Reorder classes to match group ordering
8 open(CONFIG, "LatexConfig");
9 while(<CONFIG>)
10 {
11     s/\#.*$//;
12     chomp;
13     if(/CLASSLIST =(.*)/)
14     {
15         @classList = split /[\W|,]+/, $1;
16     }
17 }
18
19 sub reorderClasses
20 {
21     my($line, $class, $fh, $curfile) = @_;
22     my @tempClassList = @classList;
23     # keep going through this block of class includes, stuffing the class name and
24     # original line into a hash as key/value, respectively
25     do
26     {
27         $foundClasses{$class} = $line;
28         print "Found $class\n";
29         $line = <$curfile>;
30     }
31     while(($class) = ($line =~ /\\input\{(?:class|struct).*_\d+_\d+.*_\d+_\d+(.*)\}/));
32     # pull out all of the elements of the hash that appear in classlist, in order
33     while(defined($class = shift @tempClassList))
34     {
35         print $fh $foundClasses{$class};
36         print "Including $class: $foundClasses{$class}\n";
37         delete $foundClasses{$class};
38     }
39     # pull out any remaining elements, in alphabetical order
40     foreach $key (sort keys %foundClasses)
41     {
42         print "Including $key: $foundClasses{$key}\n";
43         print $fh $foundClasses{$key};
44     }
45     undef %foundclasses;
46     # Print the line that didn't match, so we can go back cleanly
47     print $fh $line;
48 }
49
50
51 while(@ARGV)
52 {
53     $file = shift @ARGV;
54     print "Preprocessing $file...\n";
55     open CURFILE, $file;
56     ($temp, $tempname) = tempfile();
57     while($line = <CURFILE>)
58     {
59         if($line =~ s/\{\\footrulewidth\}\{0.4pt\}/\{\\footrulewidth\}\{0pt\}/)
60         {
61             print $temp '\\renewcommand{\\headrulewidth}{0pt}';
62             print $temp "\n";
63             print $temp '\\setlength{\\headheight}{15pt}';
64             print $temp "\n";
65         }
66         if($line =~ /^Reimplemented/ || $line =~ /^Implemented/ || $line =~ /^Implements/ ||
67            $line =~ /^Inherits/ || $line =~ /^Inherited by/ || $line =~ /Namespace Documentation/ ||
68            $line =~ /namespaceDyninst/)
69         {
70             next;
71         }
72         $line =~ s/INSTRUCTION\\_\\\-EXPORT//g;
73         $line =~ s/Main Page/Introduction/;
74         $line =~ s/Module Documentation/Modules and Abstractions/;
75         $line =~ s/Class Documentation/Class Reference/;
76         $line =~ s/\\\w*section\{Detailed Description\}//;
77         $line =~ s/\\(\w*)section\{Constructor \\\& Destructor Documentation\}/\\$1section\{Constructors \\\& Destructors\}/;
78         $line =~ s/\\(\w*)section\{Member Function Documentation\}/\\$1section\{Member Functions\}/;
79         $line =~ s/\\(\w*)section\{Member Typedef Documentation\}/\\$1section\{Member Typedefs\}/;
80         $line =~ s/\\(\w*)section\{(.*)Documentation\}/\\$1section\{$2\}/;
81         $line =~ s/\\(\w*)subsection\{(.*)Class Reference\}/\\$1subsection\{$2Class\}/;
82         $line =~ s/\\(\w*)subsection\{(.*)Struct Reference\}/\\$1subsection\{$2Struct\}/;
83         $line =~ s/\\bf/\\textbf/g;
84
85         # remove section headers if they're tagged for removal
86         $line =~ s/\\\w*section\{REMOVE\}//;
87         if($line =~ /\\input\{(?:class|struct).*_\d+_\d+.*_\d+_\d+(.*)\}/)
88         {
89             # this will take over until we're done with the class includes
90             reorderClasses($line, $1, $temp, CURFILE);
91         }
92         else
93         {
94             print $temp $line;
95         }
96     };
97     close CURFILE;
98     close $temp;
99     `cp $tempname $file`;
100 };