Debian Codegraph @

texk/chktex/chktex-src/deweb.in

raw
1 #! @PERL5@
2 # deweb v1.2, kills the C sections of a CWEB file, for passing to ChkTeX.
3 # Copyright (C) 1996 Jens T. Berger Thielemann
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 #
19 # Contact the author at:
20 # Jens Berger
21 # Spektrumvn. 4
22 # N-0666 Oslo
23 # Norway
24 # E-mail: <[email protected]>
25 #
26 #
27 #
28
29 print STDERR "DeWEB v1.3 - Copyright 1996 Jens T. Berger Thielemann\n";
30
31 undef $/;
32 my @FILES = @ARGV;
33 FILE:
34 while( my $file = shift @FILES ) {
35
36 my $success = open my $fh, '<', "$file";
37 if ( ! $success ) {
38 print STDERR "Couldn't open file '$file'\n";
39 next FILE;
40 }
41
42 $texmode = 1;
43 $_ = <$fh>;
44
45 while (/\@/) {
46 &out($`);
47 $_ = $';
48
49 if (/^@/) {
50 $_ = $';
51 &out('@');
52 next;
53 }
54
55 if (/^([\s\n])/) {
56 $_ = $';
57 print "\n" if $1 eq "\n";
58 $texmode = 1;
59 next;
60 }
61
62 if (/^[cpd]/i) {
63 $_ = $';
64 $texmode = 0;
65 next;
66 }
67
68 if (/^\,/i) {
69 $_ = $';
70 print '\,';
71 next;
72 }
73
74 if (m!^/!) {
75 $_ = $';
76 print '\\\\';
77 next;
78 }
79
80 if (/^[h\&\|\;\#\+]/i || /^i.*/i) {
81 $_ = $';
82 next;
83 }
84
85 if (/^\*[0-9\*]?((.|\n)*?\.)/) {
86 $_ = $';
87 print $1;
88 $texmode = 1;
89 next;
90 }
91
92 if (/^[<(^.t!]((.|\n)*?)\@\>/i) {
93 $_ = $';
94 print '{'.$1.'}';
95 $texmode = 0;
96 next;
97 }
98
99 if (/^[=]((.|\n)*?)\@\>/) {
100 $_ = $';
101 print &printnl($1);
102 next;
103 }
104
105 if (/^[fsl](\s+\S+\s+\S+)|^\'(.|\n)*?\'|^\[((.|\n)*?)\@\]/i) {
106 $_ = $';
107 print &printnl($+);
108 next;
109 }
110
111 @line = split(/\n/, $_, 2);
112 print STDERR "Unknown opcode, ignored. Buffer:\n$line[0]\n";
113
114 }
115
116 print $_;
117
118 }
119
120 sub printnl {
121 my($foo);
122 if (defined $_[0]) {
123 $foo = $_[0];
124 $foo =~ s/.//g;
125 } else {
126 $foo = "";
127 }
128 $foo;
129 }
130
131 sub out {
132 print $texmode? $_[0] : &printnl($_[0]);
133 }