]> git.sur5r.net Git - bacula/docs/blob - docs/manual-fr/check_hyphens.pl
Add new French manual
[bacula/docs] / docs / manual-fr / check_hyphens.pl
1 #!/usr/bin/perl -w
2 # Finds multiple hyphens not inside a verbatim environment (or \verb).  
3 #   Places these inside a \verb{} contruct so they will not be converted
4 #   to single hyphen by latex or latex2html.
5
6 use strict;
7
8 # The following builds the test string to identify and change multiple
9 #   hyphens in the tex files.  Several constructs are identified but only
10 #   multiple hyphens are changed; the others are fed to the output 
11 #   unchanged.
12 my $b = '\\\\begin\\*?\\s*\\{\\s*';  # \begin{
13 my $e = '\\\\end\\*?\\s*\\{\\s*';    # \end{
14 my $c = '\\s*\\}';                   # closing curly brace
15
16 # This captures entire verbatim environments.  These are passed to the output
17 #   file unchanged.
18 my $verbatimenv = $b . "verbatim" . $c . ".*?" . $e . "verbatim" . $c;  
19
20 # This captures \verb{} constructs.  They are passed to the output unchanged.
21 my $verb = '\\\\verb\\*?(.).*?\\1';
22
23 # This identifies multiple hyphens.
24 my $hyphens = '\\-{2,}';
25
26 # This builds the actual test string from the above strings.
27 #my $teststr = "$verbatimenv|$verb|$tocentry|$hyphens";
28 my $teststr = "$verbatimenv|$verb|$hyphens";
29
30
31 sub get_includes {
32         # Get a list of include files from the top-level tex file.
33         my (@list,$file);
34         
35         while (my $filename = shift) {
36                 # Start with the top-level latex file so it gets checked too.
37                 push (@list,$filename);
38
39                 # Get a list of all the html files in the directory.
40                 open IF,"<$filename" or die "Cannot open input file $filename";
41                 while (<IF>) {
42                         chomp;
43                         push @list,"$1.tex" if (/\\include\{(.*?)\}/);
44                 }
45
46                 close IF;
47         }
48         return @list;
49 }
50
51 sub convert_hyphens {
52         my (@files) = @_;
53         my ($filedata,$out,$this,$thiscnt,$before,$verbenv,$cnt);
54         
55         # Build the test string to check for the various environments.
56         #   We only do the conversion if the multiple hyphens are outside of a 
57         #   verbatim environment (either \begin{verbatim}...\end{verbatim} or 
58         #   \verb{--}).  Capture those environments and pass them to the output
59         #   unchanged.
60
61         $cnt = 0;
62         foreach my $file (@files) {
63                 # Open the file and load the whole thing into $filedata. A bit wasteful but
64                 #   easier to deal with, and we don't have a problem with speed here.
65                 $filedata = "";
66                 open IF,"<$file" or die "Cannot open input file $file";
67                 while (<IF>) {
68                         $filedata .= $_;
69                 }
70                 close IF;
71                 
72                 # Set up to process the file data.
73                 $out = "";
74                 $verbenv = 0;
75                 $thiscnt = 0;
76
77                 # Go through the file data from beginning to end.  For each match, save what
78                 #   came before it and what matched.  $filedata now becomes only what came 
79                 #   after the match.
80                 #   Chech the match to see if it starts with a multiple-hyphen.  If so
81                 #     change it to \verb{--}. The other possible matches in the pattern
82                 #     won't start with a hyphen, so we're ok with matching that.
83                 while ($filedata =~ /$teststr/os) {
84                         $this = $&;
85                         $before = $`;
86                         $filedata = $';
87                         # This is where the actual conversion is done.
88
89                         # Use this contruct for putting something in between each hyphen
90                         #$thiscnt += ($this =~ s/^\-+/do {join('\\,',split('',$&));}/e);
91
92                         # Use this construct for putting something around each hyphen.
93                         $thiscnt += ($this =~ s/^\-+/\\verb\{$&\{/);
94                         
95                         # Put what came before and our (possibly) changed string into 
96                         #   the output buffer.
97                         $out .= $before . $this;
98                 }
99
100                 # If any hyphens were converted, save the file.
101                 if ($thiscnt) {
102                         open OF,">$file" or die "Cannot open output file $file";
103                         print OF $out . $filedata;
104                         close OF;
105                 }
106                 $cnt += $thiscnt;
107         }
108         return $cnt;
109 }
110 ##################################################################
111 #                       MAIN                                  ####
112 ##################################################################
113
114 my (@includes);
115 my $cnt;
116
117 # Examine the file pointed to by the first argument to get a list of 
118 #  includes to test.
119 @includes = get_includes(@ARGV);
120
121 $cnt = convert_hyphens(@includes);
122
123 print "$cnt Multiple hyphen", ($cnt == 1) ? "" : "s"," Found\n";