Debian Codegraph @

texk/chktex/chktex-src/MakeChkTeXRC.pl

raw
1 # Used to convert chktexrc.in (which see) into chktexrc and ChkTeXRC.tex
2
3 use strict;
4 use warnings;
5
6 my $chktexrc_output;
7 if ( $ARGV[0] eq '--chktexrc' ) {
8 $chktexrc_output = 1;
9 } elsif ( $ARGV[0] eq '--latex' ) {
10 $chktexrc_output = 0;
11 } else {
12 exit 1;
13 }
14
15
16 # Filter the lines of the file
17 open(my $fh, '<:encoding(UTF-8)', $ARGV[1])
18 or die "Could not open file '$ARGV[1]' $!";
19
20 while ( <$fh> ) {
21 if (/^#### END$/) {
22 exit 0;
23 }
24
25 if ($chktexrc_output) {
26 # chktexrc output, so discard all lines over 2
27 next if /^#{3,}/;
28
29 s/\@verb\@/`/g;
30 s/\@endverb\@/'/g;
31 s/\@emph\@/*/g;
32 s/\@endemph\@/*/g;
33 s/\@ref\@/ /g;
34 s/\@endref\@//g;
35
36 s/\@TeX@/TeX/g;
37 s/\@LaTeX@/LaTeX/g;
38 s/\@ChkTeX@/ChkTeX/g;
39 s/\@\\{2}\@//g; # \\ in LaTeX
40 s/\\\@ */ /g; # \@ in LaTeX
41 s/\@bf //g;
42 s/\@\&\@//g;
43 print;
44
45 } else {
46
47 # LaTeX output, so discard lines except with 1,3
48 next if /^#{4,}/;
49 next if /^#{2} /;
50 # next unless /^#/;
51 s/^#+[ ]*//;
52
53 s/\@emph\@/\\emph{/g;
54 s/\@endemph\@/}/g;
55 s/\@ref\@(.*)\@endref\@/~\\hyperref[rc:$1]{$1}/g;
56
57
58 s/\@TeX@/\\TeX{}/g;
59 s/\@LaTeX@/\\LaTeX{}/g;
60 s/\@ChkTeX@/\\chktex{}/g;
61 s/\@verb\@/\\verb@/g;
62 s/\@endverb\@/@/g;
63 s/\@\\{2}\@/\\\\/g;
64 s/\@bf/\\bf/g;
65 s/\@\&\@/&/g;
66
67 print;
68 }
69 }
70 # TODO:
71 # \ChkTeX