2795
|
1 |
#!/usr/local/dist/bin/perl
|
1826
|
2 |
'di';
|
|
3 |
'ig00';
|
|
4 |
#
|
|
5 |
# $Header$
|
|
6 |
#
|
|
7 |
# $Log$
|
5674
|
8 |
# Revision 1.3 1998/10/19 13:37:03 oheimb
|
|
9 |
# corrected Header
|
|
10 |
#
|
|
11 |
# Revision 1.2 1997/03/17 11:25:53 wenzelm
|
2795
|
12 |
# fixed perl path;
|
|
13 |
#
|
|
14 |
# Revision 1.1.1.1 1996/06/25 15:44:59 oheimb
|
|
15 |
# Graphical 8bit Font Packet, see isabelle/Tools/8bit/doc/manual.dvi
|
|
16 |
# Author: Franz Regensburger; improvements by David von Oheimb
|
1826
|
17 |
#
|
|
18 |
# Revision 1.1.1.1 1996/06/25 13:58:24 oheimb
|
|
19 |
# Graphical 8bit Font Package imported, second attempt
|
|
20 |
#
|
|
21 |
#
|
|
22 |
# patcher
|
|
23 |
# Franz Regensburger <regensbu@informatik.tu-muenchen.de>
|
|
24 |
# 10.2.8.95
|
|
25 |
#
|
|
26 |
# last changed:
|
|
27 |
#
|
|
28 |
# a universal patcher for text files
|
|
29 |
#
|
|
30 |
# don't use character @ in configfile
|
|
31 |
|
|
32 |
# I like to see the output as it happens (flushed output)
|
|
33 |
|
|
34 |
$| = 1;
|
|
35 |
|
|
36 |
# cash current working directory
|
|
37 |
require "pwd.pl";
|
|
38 |
&initpwd;
|
|
39 |
|
|
40 |
########################
|
|
41 |
# comand line processing
|
|
42 |
# processes all known switches and ingnores others.
|
|
43 |
# first non-switch which is the name of a text file is
|
|
44 |
# interpreted as name of the configuration file
|
|
45 |
#
|
|
46 |
|
|
47 |
# initialize
|
|
48 |
$config_file="";
|
|
49 |
|
|
50 |
$do_debug = 0;
|
|
51 |
$do_ddebug = 0;
|
|
52 |
|
|
53 |
while (@ARGV){
|
|
54 |
$cur_arg = shift @ARGV;
|
|
55 |
if ($cur_arg eq '-d') {$do_debug = 1;}
|
|
56 |
elsif ($cur_arg eq '-dd') {$do_debug = 1; $do_ddebug = 1;}
|
|
57 |
elsif ((-T $cur_arg) && !$config_file) {$config_file = $cur_arg;}
|
|
58 |
}
|
|
59 |
|
|
60 |
# complain if no config file is found
|
|
61 |
|
|
62 |
if ($config_file eq "") {
|
|
63 |
print "\nno config file suplied or argument is not a text file\n\n";
|
|
64 |
print "usage patcher [-d -dd ] config-file \n",
|
|
65 |
"options must be seperated by blanks!";
|
|
66 |
die "\n";
|
|
67 |
}
|
|
68 |
|
|
69 |
print "debug mode is on\n" if $do_debug;
|
|
70 |
print "double debug mode is on\n" if $do_ddebug;
|
|
71 |
print "name of config file is $config_file\n" if $do_debug;
|
|
72 |
|
|
73 |
########################
|
|
74 |
# open the config file
|
|
75 |
|
|
76 |
open(INFILE,$config_file) || die "can't open $config_file: $!\n";
|
|
77 |
print "opened config file,\nprocessing\n" if $do_ddebug;
|
|
78 |
|
|
79 |
########################
|
|
80 |
# look for stem of filenames
|
|
81 |
$stem = &look_for_value('^\s*STEM\s*"(.*)"',"STEM");
|
|
82 |
|
|
83 |
if ($stem eq "") {
|
|
84 |
die "\ncan't find STEM in configuration file\n";}
|
|
85 |
|
|
86 |
if (! (-d $stem)){
|
|
87 |
die "\nSTEM is not a directory\n";}
|
|
88 |
|
|
89 |
if (! (-r $stem)){
|
|
90 |
die "\nno read permission for directory STEM \n";}
|
|
91 |
|
|
92 |
|
|
93 |
########################
|
|
94 |
# read in the configuration commands
|
|
95 |
print "\nreading commands\n" if $do_debug;
|
|
96 |
|
|
97 |
$index = 0;
|
|
98 |
$end_config = 0;
|
|
99 |
$pattern1 = '^\s*(ADD|EXTRACT)\s*([^\s]*)\s*IN\s*([^\s]*)\s*BETWEEN\s*"([^"]*)"\s*"([^"]*)"';
|
|
100 |
$pattern2 = '^\s*(CLEAN)\s*IN\s*([^\s]*)\s*BETWEEN\s*"([^"]*)"\s*"([^"]*)"';
|
|
101 |
|
|
102 |
#$pattern = '^#\s*([^#]*)#\s*([^#]*)#\s*([^#]*)#\s*([^#]*)#\s*([^#]*)';
|
|
103 |
|
|
104 |
while (<INFILE> ){
|
|
105 |
if (($cmd,$patchfile,$infile,$pragma1,$pragma2) = /$pattern1/){
|
|
106 |
$config_table[$index]= join('@',$cmd,$patchfile,$infile,$pragma1,$pragma2);
|
|
107 |
# the @ is used as seperator
|
|
108 |
printf "line $.: %s %s %s %s %s\n",
|
|
109 |
$cmd,$patchfile,$infile,$pragma1,$pragma2 if $do_ddebug;
|
|
110 |
$index +=1;
|
|
111 |
}
|
|
112 |
elsif (($cmd,$infile,$pragma1,$pragma2) = /$pattern2/){
|
|
113 |
$config_table[$index]= join('@',$cmd,"",$infile,$pragma1,$pragma2);
|
|
114 |
# the @ is used as seperator
|
|
115 |
printf "line $.: %s %s %s %s\n",
|
|
116 |
$cmd,$infile,$pragma1,$pragma2 if $do_ddebug;
|
|
117 |
$index +=1;
|
|
118 |
}
|
|
119 |
} #while
|
|
120 |
|
|
121 |
if ($index > 0) {
|
|
122 |
$end_config = $index - 1;}
|
|
123 |
else {$end_config = -1;}
|
|
124 |
|
|
125 |
print "there were $index commands found\n" if $do_debug;
|
|
126 |
|
|
127 |
########################
|
|
128 |
# close the handle for the config file
|
|
129 |
close(INFILE);
|
|
130 |
print "closed config file\n\n" if $do_debug;
|
|
131 |
|
|
132 |
|
|
133 |
########################
|
|
134 |
# do all the commands
|
|
135 |
print "processing all the commands\n" if $do_debug;
|
|
136 |
|
|
137 |
$index = 0;
|
|
138 |
while ($index <= $end_config) {
|
|
139 |
($cmd,$patchfile,$infile,$pragma1,$pragma2) =
|
|
140 |
split(/@/,$config_table[$index]);
|
|
141 |
print "current command is:\n" if $do_debug;
|
|
142 |
printf " %s %s %s %s %s\n",
|
|
143 |
$cmd,$patchfile,$infile,$pragma1,$pragma2 if $do_debug;
|
|
144 |
|
|
145 |
$filename = $stem.$infile;
|
|
146 |
$tempfile = $stem."patcher.tmp";
|
|
147 |
$thepatchfile = $stem.$patchfile;
|
|
148 |
|
|
149 |
open(INFILE ,$filename) || die "can't open $filename: $!\n";
|
|
150 |
print "opened $filename for reading\n" if $do_ddebug;
|
|
151 |
|
|
152 |
if ( $cmd eq "ADD" ){
|
|
153 |
open(PATCHFILE,$thepatchfile) || die "can't open $thepatchfile: $!\n";
|
|
154 |
print "opened $thepatchfile for reading\n" if $do_ddebug;
|
|
155 |
}
|
|
156 |
|
|
157 |
if ( $cmd eq "EXTRACT" ){
|
|
158 |
open(PATCHFILE,">".$thepatchfile) || die "can't open $thepatchfile: $!\n";
|
|
159 |
print "opened $thepatchfile for writing\n" if $do_ddebug;
|
|
160 |
}
|
|
161 |
|
|
162 |
open(OUTFILE,">".$tempfile) || die "can't open temporary file $tempfile: $!\n";
|
|
163 |
print "opened $tempfile for writing\n" if $do_ddebug;
|
|
164 |
|
|
165 |
$found = &replicate_until($pragma1);
|
|
166 |
if ($found eq "") {die "\ncan't find $pragma1\n";}
|
|
167 |
|
|
168 |
if ( $cmd eq "ADD" ){
|
|
169 |
while (<PATCHFILE> ){
|
|
170 |
printf(OUTFILE "%s",$_);
|
|
171 |
}
|
|
172 |
}
|
|
173 |
if ( $cmd eq "EXTRACT" ){
|
|
174 |
while (<INFILE> ){
|
|
175 |
printf(OUTFILE "%s",$_);
|
|
176 |
if (/$pragma2/){
|
|
177 |
last;}
|
|
178 |
printf(PATCHFILE "%s",$_);
|
|
179 |
}
|
|
180 |
}
|
|
181 |
else {
|
|
182 |
$found = &skip_until($pragma2);
|
|
183 |
if ($found eq "") {die "\ncan't find $pragma2\n";}
|
|
184 |
}
|
|
185 |
|
|
186 |
# print the rest
|
|
187 |
while (<INFILE> ){
|
|
188 |
printf(OUTFILE "%s",$_);
|
|
189 |
}
|
|
190 |
|
|
191 |
close(INFILE);
|
|
192 |
close(PATCHFILE) if $cmd eq "ADD" | $cmd eq "EXTRACT";
|
|
193 |
close(OUTFILE);
|
|
194 |
print "closed the files\n" if $do_ddebug;
|
|
195 |
|
|
196 |
$status = system("cp $tempfile $filename") ;
|
|
197 |
if ($status) { die "can't copy $tempfile to $filename: $!\n";}
|
|
198 |
|
|
199 |
|
|
200 |
$index += 1;
|
|
201 |
}
|
|
202 |
|
|
203 |
# erase the patcher.tmp file
|
|
204 |
|
|
205 |
$status = system("rm $tempfile") ;
|
|
206 |
if ($status) { die "can't erase $tempfile: $!\n";}
|
|
207 |
|
|
208 |
|
|
209 |
########################
|
|
210 |
# END of script
|
|
211 |
#
|
|
212 |
|
|
213 |
print "\nprogram patcher properly terminated\n\n";
|
|
214 |
exit(0);
|
|
215 |
|
|
216 |
#######################################################################
|
|
217 |
# subroutines
|
|
218 |
#######################################################################
|
|
219 |
|
|
220 |
sub look_for_value {
|
|
221 |
local ($pattern,$label) = @_;
|
|
222 |
local ($temp) = "";
|
|
223 |
|
|
224 |
while (<INFILE> ){
|
|
225 |
if (($temp) = /$pattern/){
|
|
226 |
print "line $.: $label is $temp\n" if $do_debug;
|
|
227 |
last;}
|
|
228 |
}
|
|
229 |
return $temp;
|
|
230 |
}
|
|
231 |
|
|
232 |
|
|
233 |
sub look_for_label {
|
|
234 |
local ($pattern,$label) = @_;
|
|
235 |
local ($temp) = "";
|
|
236 |
|
|
237 |
while (<INFILE> ){
|
|
238 |
if (/$pattern/){
|
|
239 |
$temp=true;
|
|
240 |
last;}
|
|
241 |
}
|
|
242 |
return $temp;
|
|
243 |
}
|
|
244 |
|
|
245 |
sub replicate_until {
|
|
246 |
local ($pattern) = @_;
|
|
247 |
local ($temp) = "";
|
|
248 |
|
|
249 |
while (<INFILE> ){
|
|
250 |
printf(OUTFILE "%s",$_);
|
|
251 |
if (/$pattern/){
|
|
252 |
$temp = "true";
|
|
253 |
last;}
|
|
254 |
}
|
|
255 |
return $temp;
|
|
256 |
}
|
|
257 |
|
|
258 |
sub skip_until {
|
|
259 |
local ($pattern) = @_;
|
|
260 |
local ($temp) = "";
|
|
261 |
|
|
262 |
while (<INFILE> ){
|
|
263 |
if (/$pattern/){
|
|
264 |
printf(OUTFILE "%s",$_); #restore last line
|
|
265 |
$temp = "true";
|
|
266 |
last;}
|
|
267 |
}
|
|
268 |
return $temp;
|
|
269 |
}
|
|
270 |
###############################################################
|
|
271 |
|
|
272 |
# These next few lines are legal in both Perl and nroff.
|
|
273 |
|
|
274 |
.00; # finish .ig
|
|
275 |
|
|
276 |
'di \" finish diversion--previous line must be blank
|
|
277 |
.nr nl 0-1 \" fake up transition to first page again
|
|
278 |
.nr % 0 \" start at page 1
|
|
279 |
'; __END__ ##### From here on it's a standard manual page #####
|