2795
|
1 |
#!/usr/local/dist/bin/perl
|
1826
|
2 |
'di';
|
|
3 |
'ig00';
|
|
4 |
###############################################
|
|
5 |
# Title: Tools/8bit/perl/generators/gen-isa2latex
|
|
6 |
# ID: $Id$
|
|
7 |
# Author: Franz Regensburger
|
|
8 |
# Copyright 1996 TU Muenchen
|
|
9 |
#
|
|
10 |
# configures the converter isa2latex with user provided settings
|
|
11 |
#
|
|
12 |
# Franz Regensburger <regensbu@informatik.tu-muenchen.de> 8.3.95
|
|
13 |
#
|
|
14 |
###############################################
|
|
15 |
|
|
16 |
# I like to see the output as it happens (flushed output)
|
|
17 |
|
|
18 |
$| = 1;
|
|
19 |
|
|
20 |
# cash current working directory
|
|
21 |
require "pwd.pl";
|
|
22 |
&initpwd;
|
|
23 |
|
|
24 |
$initial_dir = $ENV{'PWD'};
|
1907
|
25 |
$GMAKE= "gmake";
|
1826
|
26 |
|
|
27 |
########################
|
|
28 |
# comand line processing
|
|
29 |
# processes all known switches and ingnores others.
|
|
30 |
# first non-switch which is the name of a text file is
|
|
31 |
# interpreted as name of configuration file.
|
|
32 |
#
|
|
33 |
|
|
34 |
# initialize
|
|
35 |
$config_file="";
|
|
36 |
$do_debug = 0;
|
|
37 |
$do_ddebug = 0;
|
|
38 |
#$install_source = 0;
|
|
39 |
#$cleanup = 0;
|
|
40 |
|
|
41 |
while (@ARGV){
|
|
42 |
$cur_arg = shift @ARGV;
|
|
43 |
if ($cur_arg eq '-d') {$do_debug = 1;}
|
|
44 |
elsif ($cur_arg eq '-dd') {$do_debug = 1; $do_ddebug = 1;}
|
|
45 |
# elsif ($cur_arg eq '-c') {$cleanup = 1;}
|
|
46 |
# elsif ($cur_arg eq '-s') {$install_source = 1;}
|
|
47 |
elsif ((-T $cur_arg) && !$config_file) {$config_file = $cur_arg;}
|
|
48 |
}
|
|
49 |
|
|
50 |
# complain if no configuration file is found
|
|
51 |
|
|
52 |
if ($config_file eq "") {
|
|
53 |
print "\nno configuration file suplied or argument is not a text file\n\n";
|
|
54 |
print "usage gen-isa2latex [-d -dd ] configfile\n",
|
|
55 |
# print "usage gen-isa2latex [-d -dd -s -c ] configfile\n",
|
|
56 |
"options must be separated by blanks!";
|
|
57 |
die "\n";
|
|
58 |
}
|
|
59 |
|
|
60 |
print "debug mode is on\n" if $do_debug;
|
|
61 |
print "double debug mode is on\n" if $do_ddebug;
|
|
62 |
print "name of configuration file is $config_file\n" if $do_debug;
|
|
63 |
|
|
64 |
########################
|
|
65 |
# open the configuration file
|
|
66 |
|
|
67 |
open(CONFIG,$config_file) || die "can't open $config_file: $!\n";
|
|
68 |
print "opened configuration file,\nprocessing\n" if $do_debug;
|
|
69 |
|
|
70 |
########################
|
|
71 |
# search for general setup variables
|
|
72 |
|
|
73 |
print "\ngeneral setup\n" if $do_debug;
|
|
74 |
|
|
75 |
########################
|
|
76 |
# search for CONV_SOURCE_DIR
|
|
77 |
|
|
78 |
$conv_source_dir =
|
|
79 |
&look_for_value('^\s*CONV_SOURCE_DIR\s*"(.*)"',"CONV_SOURCE_DIR");
|
|
80 |
|
|
81 |
if ($conv_source_dir eq "") {
|
|
82 |
die "\ncan't find CONV_SOURCE_DIR in configuration file\n";}
|
|
83 |
|
|
84 |
if (! (-d $conv_source_dir)){
|
|
85 |
die "\nCONV_SOURCE_DIR is not a directory\n";}
|
|
86 |
|
|
87 |
if (! (-r $conv_source_dir)){
|
|
88 |
die "\nno read permission for directory CONV_SOURCE_DIR \n";}
|
|
89 |
|
|
90 |
#if ($install_source && !(-w $conv_source_dir)){
|
|
91 |
# die "\noption -s used but no write permission for directory CONV_SOURCE_DIR\n";}
|
|
92 |
|
|
93 |
|
|
94 |
########################
|
|
95 |
# search for CONV_TEMP_DIR
|
|
96 |
|
|
97 |
#$conv_temp_dir = &look_for_value('^\s*CONV_TEMP_DIR\s*"(.*)"',"CONV_TEMP_DIR");
|
|
98 |
|
|
99 |
#if ($conv_temp_dir eq "") {
|
|
100 |
# die "\ncan't find CONV_TEMP_DIR in configuration file\n";}
|
|
101 |
|
|
102 |
#if (! (-d $conv_temp_dir)){
|
|
103 |
# die "\nCONV_TEMP_DIR is not a directory\n";}
|
|
104 |
|
|
105 |
#if (!(-r $conv_temp_dir && -w $conv_temp_dir && -x $conv_temp_dir)){
|
|
106 |
# die "\nneed read, write and execute permission for directory CONV_TEMP_DIR\n";}
|
|
107 |
|
|
108 |
|
|
109 |
########################
|
|
110 |
# search for CONV_SUB_DIR
|
|
111 |
|
|
112 |
#$conv_sub_dir = &look_for_value('^\s*CONV_SUB_DIR\s*"(.*)"',"CONV_SUB_DIR");
|
|
113 |
|
|
114 |
#if ($conv_sub_dir eq "") {
|
|
115 |
# die "\ncan't find CONV_SUB_DIR in configuration file\n";}
|
|
116 |
|
|
117 |
########################
|
|
118 |
# process switsch -c for cleanup
|
|
119 |
|
|
120 |
#if ($cleanup) { # cleanup $conv_sub_dir
|
|
121 |
# chdir $conv_temp_dir || die "can't cd to $conv_temp_dir: $!\n";
|
|
122 |
# $status = system("rm -rf $conv_sub_dir/*; rmdir $conv_sub_dir");
|
|
123 |
# if ($status) {die "can't remove subdirectory $conv_sub_dir: $!\n";}
|
|
124 |
# print "cleanup done, exit configuration script\n";
|
|
125 |
# exit(0);
|
|
126 |
#}
|
|
127 |
|
|
128 |
|
|
129 |
########################
|
|
130 |
# configuration of LOW_TABLE
|
|
131 |
print "\nsetup for LOW_TABLE\n" if $do_debug;
|
|
132 |
|
|
133 |
########################
|
|
134 |
# search for START_LOW_TABLE
|
|
135 |
|
|
136 |
$start_low_table =
|
|
137 |
&look_for_value('^\s*START_LOW_TABLE\s*"(\d+)"',"START_LOW_TABLE");
|
|
138 |
|
|
139 |
if ($start_low_table eq "") {
|
|
140 |
die "\ncan't find START_LOW_TABLE in configuration file\n";}
|
|
141 |
|
|
142 |
if ($start_low_table < 32 || 127 < $start_low_table) {
|
|
143 |
die "\nSTART_LOW_TABLE not in range 32 .. 127\n";}
|
|
144 |
|
|
145 |
|
|
146 |
########################
|
|
147 |
# search for BEGIN_LOW_TABLE
|
|
148 |
|
|
149 |
$found = &look_for_label('^\s*BEGIN_LOW_TABL(E)',"BEGIN_LOW_TABLE");
|
|
150 |
|
|
151 |
if ($found eq "") {
|
|
152 |
die "\ncan't find BEGIN_LOW_TABLE in configuration file\n";}
|
|
153 |
|
|
154 |
########################
|
|
155 |
# read the LOW_TABLE
|
|
156 |
|
|
157 |
$index = 0;
|
|
158 |
$found = 0;
|
|
159 |
$end_low_table = 0;
|
|
160 |
$pattern = '^>\s*"([^"]*)"';
|
|
161 |
|
|
162 |
while (<CONFIG> ){
|
|
163 |
if (/^\s*END_LOW_TABLE/){
|
|
164 |
print "line $.: END_LOW_TABLE found\n" if $do_debug;
|
|
165 |
$found = 1;
|
|
166 |
$end_low_table = $start_low_table + $index - 1;
|
|
167 |
last;}
|
|
168 |
elsif (($temp) = /$pattern/){
|
|
169 |
$low_table[$index]= &double_bs($temp);
|
|
170 |
# backslashes are duplicated
|
|
171 |
print "line $.: \"$low_table[$index]\"\n" if $do_ddebug;
|
|
172 |
$index +=1;
|
|
173 |
}
|
|
174 |
}
|
|
175 |
if (!$found){
|
|
176 |
die "\ncan't find END_LOW_TABLE in configuration file\n";}
|
|
177 |
|
|
178 |
if ($end_low_table < $start_low_table || 127 < $end_low_table){
|
|
179 |
die "\nEND_LOW_TABLE $end_low_table not in range $start_low_table .. 127\n";}
|
|
180 |
else {print
|
|
181 |
"computed index for END_LOW_TABLE is $end_low_table\n" if $do_debug;}
|
|
182 |
|
|
183 |
########################
|
|
184 |
# configuration of HI_TABLE
|
|
185 |
print "\nsetup for HI_TABLE\n" if $do_debug;
|
|
186 |
|
|
187 |
########################
|
|
188 |
# search for START_HI_TABLE
|
|
189 |
#
|
|
190 |
$start_hi_table =
|
|
191 |
&look_for_value('^\s*START_HI_TABLE\s*"(\d+)"',"START_HI_TABLE");
|
|
192 |
|
|
193 |
if ($start_hi_table eq "") {
|
|
194 |
die "\ncan't find START_HI_TABLE in configuration file\n";}
|
|
195 |
|
|
196 |
if ($start_hi_table < 128 || 255 < $start_hi_table) {
|
|
197 |
die "\nSTART_HI_TABLE not in range 128 .. 255\n";}
|
|
198 |
|
|
199 |
########################
|
|
200 |
# search for BEGIN_HI_TABLE
|
|
201 |
|
|
202 |
$found = &look_for_label('^\s*BEGIN_HI_TABL(E)',"BEGIN_HI_TABLE");
|
|
203 |
|
|
204 |
if ($found eq "") {
|
|
205 |
die "\ncan't find BEGIN_HI_TABLE in configuration file\n";}
|
|
206 |
|
|
207 |
########################
|
|
208 |
# read the HI_TABLE
|
|
209 |
|
|
210 |
$index = 0;
|
|
211 |
$max_hi_len1 = 0; # for pretty printing
|
|
212 |
$max_hi_len2 = 0; # for pretty printing
|
|
213 |
$max_hi_len3 = 0; # for pretty printing
|
|
214 |
$found = 0;
|
|
215 |
$end_hi_table = 0;
|
|
216 |
$pattern = '^>\s*"([^"]*)"\s*"([^"]*)"\s*"([^"]*)"';
|
|
217 |
|
|
218 |
while (<CONFIG> ){
|
|
219 |
if (/^\s*END_HI_TABLE/){
|
|
220 |
print "line $.: END_HI_TABLE found\n" if $do_debug;
|
|
221 |
$found = 1;
|
|
222 |
$end_hi_table = $start_hi_table + $index - 1;
|
|
223 |
last;}
|
|
224 |
elsif (($temp_1,$temp_2,$temp_3) = /$pattern/){
|
|
225 |
$temp1 = $temp_1 ;
|
|
226 |
$temp2 = &double_bs($temp_2);
|
|
227 |
$temp3 = &double_bs($temp_3);
|
|
228 |
$max_hi_len1 = length($temp1) if $max_hi_len1 < length($temp1);
|
|
229 |
$max_hi_len2 = length($temp2) if $max_hi_len2 < length($temp2);
|
|
230 |
$max_hi_len3 = length($temp3) if $max_hi_len3 < length($temp3);
|
|
231 |
$hi_table[$index]= join('"',$temp1, $temp2, $temp3);
|
|
232 |
# the " as seperator is perfect since it cannot occur inside the strings
|
|
233 |
# backslashes are duplicated
|
|
234 |
printf "line $.: \"%s\" \t\t \"%s\" \t\t \"%s\"\n",
|
|
235 |
$temp1, $temp2, $temp3 if $do_ddebug;
|
|
236 |
$index +=1;
|
|
237 |
}
|
|
238 |
}
|
|
239 |
|
|
240 |
if (!$found){
|
|
241 |
die "\ncan't find END_HI_TABLE in configuration file\n";}
|
|
242 |
|
|
243 |
if ($end_hi_table < $start_hi_table || 255 < $end_hi_table ){
|
|
244 |
die "\nEND_HI_TABLE $end_hi_table not in range $start_low_table .. 255\n";}
|
|
245 |
else
|
|
246 |
{print "computed index for END_HI_TABLE is $end_hi_table\n" if $do_debug; }
|
|
247 |
|
|
248 |
|
|
249 |
|
|
250 |
########################
|
|
251 |
# configuration of SEQ_TABLE
|
|
252 |
print "\nsetup for SEQ_TABLE\n" if $do_debug;
|
|
253 |
|
|
254 |
########################
|
|
255 |
# search for BEGIN_SEQ_TABLE
|
|
256 |
|
|
257 |
$found = &look_for_label('^\s*BEGIN_SEQ_TABL(E)',"BEGIN_SEQ_TABLE");
|
|
258 |
|
|
259 |
if ($found eq "") {
|
|
260 |
die "\ncan't find BEGIN_SEQ_TABLE in configuration file\n";}
|
|
261 |
|
|
262 |
|
|
263 |
########################
|
|
264 |
# read the SEQ_TABLE
|
|
265 |
|
|
266 |
$index = 0;
|
|
267 |
$max_seq_len1 = 0; # for pretty printing
|
|
268 |
$max_seq_len2 = 0; # for pretty printing
|
|
269 |
$max_seq_len3 = 0; # for pretty printing
|
|
270 |
$max_seq_len4 = 0; # for pretty printing
|
|
271 |
$found = 0;
|
|
272 |
$seq_table = 0;
|
|
273 |
$pattern = '^>\s*"([^"]*)"\s*"([^"]*)"\s*"([^"]*)"\s*"([^"]*)"';
|
|
274 |
|
|
275 |
while (<CONFIG> ){
|
|
276 |
if (/^\s*END_SEQ_TABLE/){
|
|
277 |
print "line $.: END_SEQ_TABLE found\n" if $do_debug;
|
|
278 |
$found = 1;
|
|
279 |
$seq_table = $index;
|
|
280 |
last;}
|
|
281 |
elsif (($temp_1,$temp_2,$temp_3,$temp_4) = /$pattern/){
|
|
282 |
$temp1 = $temp_1 ;
|
|
283 |
$temp2 = $temp_2 ;
|
|
284 |
$temp3 = &double_bs($temp_3) ;
|
|
285 |
$temp4 = &double_bs($temp_4);
|
|
286 |
$max_seq_len1 = length($temp1) if $max_seq_len1 < length($temp1);
|
|
287 |
$max_seq_len2 = length($temp2) if $max_seq_len2 < length($temp2);
|
|
288 |
$max_seq_len3 = length($temp4) if $max_seq_len3 < length($temp3);
|
|
289 |
$max_seq_len4 = length($temp3) if $max_seq_len4 < length($temp4);
|
|
290 |
$seq_table[$index]= join('"',$temp1, $temp2, $temp3, $temp4);
|
|
291 |
# the " as seperator is perfect since it cannot occur inside the strings
|
|
292 |
# backslashes are only expanded in the latex replacement
|
|
293 |
printf "line $.: \"%s\" \t\t \"%s\" \t\t \"%s\" \t\t \"%s\"\n",
|
|
294 |
$temp1, $temp2, $temp3, $temp4 if $do_ddebug;
|
|
295 |
$index +=1;
|
|
296 |
}
|
|
297 |
}
|
|
298 |
|
|
299 |
if ($found == 0) {
|
|
300 |
die "\ncan't find END_SEQ_TABLE in configuration file\n";}
|
|
301 |
else {print "computed index for SEQ_TABLE is $seq_table\n" if $do_debug; }
|
|
302 |
|
|
303 |
|
|
304 |
########################
|
|
305 |
# we reached the end of the configuration file
|
|
306 |
|
|
307 |
print "\nprocessing of configuration file completed\n" if $do_debug;
|
|
308 |
|
|
309 |
########################
|
|
310 |
# close the handle for config file
|
|
311 |
close(CONFIG);
|
|
312 |
print "closed configuration file\n" if $do_debug;
|
|
313 |
|
|
314 |
#######################################################################
|
|
315 |
# copy sources and modify them
|
|
316 |
#######################################################################
|
|
317 |
|
|
318 |
########################
|
|
319 |
# change to temporary directory,
|
|
320 |
# make subdir and copy sources
|
|
321 |
# change to subdir
|
|
322 |
|
|
323 |
#print "\ncopying sources\n" if $do_debug;
|
|
324 |
|
|
325 |
#chdir $conv_temp_dir || die "can't cd to $conv_temp_dir: $!\n";
|
|
326 |
|
|
327 |
# cleanup if directory exists
|
|
328 |
|
|
329 |
#if (-d $conv_sub_dir){ # directory exists
|
|
330 |
# $status = system("rm -rf $conv_sub_dir/*; rmdir $conv_sub_dir");
|
|
331 |
# if ($status) {die "can't remove subdirectory $conv_sub_dir: $!\n";}
|
|
332 |
#}
|
|
333 |
|
|
334 |
# make the new sub dir
|
|
335 |
|
|
336 |
#mkdir($conv_sub_dir,0755) || die "can't create subdirectory $conv_sub_dir: $!\n";
|
|
337 |
|
|
338 |
#$status = system("cp -r $conv_source_dir/* $conv_sub_dir") ;
|
|
339 |
#if ($status) { die "can't copy files from CONV_SOURCE_DIR to CONV_SUB_DIR: $!\n";}
|
|
340 |
|
|
341 |
#chdir $conv_sub_dir || die "can't cd to $conv_sub_dir: $!\n";
|
|
342 |
chdir $conv_source_dir || die "can't cd to $conv_source_dir: $!\n";
|
|
343 |
|
|
344 |
print "\nconfiguring sources\n" if $do_debug;
|
|
345 |
|
|
346 |
########################
|
|
347 |
# configure conv-defs.h
|
|
348 |
#
|
|
349 |
|
|
350 |
$filename = "conv-defs.h";
|
|
351 |
|
|
352 |
print "\nconfiguring $filename\n" if $do_debug;
|
|
353 |
|
|
354 |
open(INFILE ,$filename) || die "can't open $filename in CONV_SOURCE_DIR: $!\n";
|
|
355 |
print "opened $filename for reading\n" if $do_ddebug;
|
|
356 |
open(OUTFILE,">tmp.txt") || die "can't open temporary file tmp.txt: $!\n";
|
|
357 |
print "opened tmp.txt for writing\n" if $do_ddebug;
|
|
358 |
|
|
359 |
$found = &replicate_until('^\s*\/\*\s*BEGIN\s*gen-isa2late(x)','BEGIN gen-isa2latex');
|
|
360 |
if ($found eq "") {
|
|
361 |
die "\ncan't find BEGIN gen-isa2latex\n";}
|
|
362 |
|
|
363 |
## replace
|
|
364 |
printf(OUTFILE "%s\n", "/* BEGIN gen-isa2latex */");
|
|
365 |
printf(OUTFILE "#define START_LOW_TABLE %s\n", $start_low_table);
|
|
366 |
printf(OUTFILE "#define END_LOW_TABLE %s\n", $end_low_table);
|
|
367 |
printf(OUTFILE "#define START_HI_TABLE %s\n", $start_hi_table);
|
|
368 |
printf(OUTFILE "#define END_HI_TABLE %s\n", $end_hi_table);
|
|
369 |
printf(OUTFILE "#define SEQ_TABLE %s\n", $seq_table);
|
|
370 |
printf(OUTFILE "%s\n", "/* END gen-isa2latex */");
|
|
371 |
|
|
372 |
$found = &skip_until('^\s*\/\*\s*END\s*gen-isa2late(x)','END gen-isa2latex');
|
|
373 |
if ($found eq "") {
|
|
374 |
die "\ncan't find END gen-isa2latex\n";}
|
|
375 |
|
|
376 |
## the rest
|
|
377 |
while (<INFILE> ){printf(OUTFILE "%s",$_);}
|
|
378 |
|
|
379 |
close(INFILE);
|
|
380 |
close(OUTFILE);
|
|
381 |
print "closed $filename and tmp.txt\n" if $do_ddebug;
|
|
382 |
|
|
383 |
$status = system("cp tmp.txt $filename") ;
|
|
384 |
if ($status) { die "can't copy tmp.txt to $filename: $!\n";}
|
|
385 |
|
|
386 |
########################
|
|
387 |
# configure conv-tables.h
|
|
388 |
#
|
|
389 |
|
|
390 |
$filename = "conv-tables.h";
|
|
391 |
|
|
392 |
print "\nconfiguring $filename\n" if $do_debug;
|
|
393 |
|
|
394 |
open(INFILE ,$filename) || die "can't open $filename in CONV_SOURCE_DIR: $!\n";
|
|
395 |
print "opened $filename for reading\n" if $do_ddebug;
|
|
396 |
open(OUTFILE,">tmp.txt") || die "can't open temporary file tmp.txt: $!\n";
|
|
397 |
print "opened tmp.txt for writing\n" if $do_ddebug;
|
|
398 |
|
|
399 |
### LOW TABLE
|
|
400 |
$found = &replicate_until('^\s*\/\*\s*BEGIN_OF_LOW_TABL(E)','BEGIN_OF_LOW_TABLE');
|
|
401 |
if ($found eq "") {
|
|
402 |
die "\ncan't find BEGIN_OF_LOW_TABLE\n";}
|
|
403 |
|
|
404 |
## replace
|
|
405 |
printf(OUTFILE "%s\n", "/* BEGIN_OF_LOW_TABLE */");
|
|
406 |
printf(OUTFILE "%s\n",
|
|
407 |
"char *translationTableLow[END_LOW_TABLE - START_LOW_TABLE + 1] = {");
|
|
408 |
$index = $start_low_table;
|
|
409 |
$sep = ",\n";
|
|
410 |
while ($index <= $end_low_table) {
|
|
411 |
$sep = "\n" if $index == $end_low_table;
|
|
412 |
printf(OUTFILE " \"%s\"".$sep, $low_table[$index - $start_low_table]);
|
|
413 |
$index++;
|
|
414 |
}
|
|
415 |
printf(OUTFILE "%s\n","};");
|
|
416 |
printf(OUTFILE "%s\n", "/* END_OF_LOW_TABLE */");
|
|
417 |
|
|
418 |
$found = &skip_until('^\s*\/\*\s*END_OF_LOW_TABL(E)','END_OF_LOW_TABLE');
|
|
419 |
if ($found eq "") {
|
|
420 |
die "\ncan't find END_OF_LOW_TABLE\n";}
|
|
421 |
|
|
422 |
### HI TABLE
|
|
423 |
$found = &replicate_until('^\s*\/\*\s*BEGIN_OF_HI_TABL(E)','BEGIN_OF_HI_TABLE');
|
|
424 |
if ($found eq "") {
|
|
425 |
die "\ncan't find BEGIN_OF_HI_TABLE\n";}
|
|
426 |
|
|
427 |
## replace
|
|
428 |
printf(OUTFILE "%s\n", "/* BEGIN_OF_HI_TABLE */");
|
|
429 |
printf(OUTFILE "%s\n",
|
|
430 |
"char *translationTableHi[END_HI_TABLE - START_HI_TABLE + 1][2] = {");
|
|
431 |
|
|
432 |
$index = $start_hi_table;
|
|
433 |
$sep = ",\n";
|
|
434 |
while ($index <= $end_hi_table) {
|
|
435 |
$sep = "\n" if $index == $end_hi_table;
|
|
436 |
($temp1,$temp2,$temp3) = split(/\"/,$hi_table[$index - $start_hi_table]);
|
|
437 |
printf(OUTFILE " {%-".($max_hi_len2+3)."s,%s}".$sep,
|
|
438 |
"\"".$temp2."\"","\"".$temp3."\"");
|
|
439 |
$index++;
|
|
440 |
}
|
|
441 |
printf(OUTFILE "%s\n","};");
|
|
442 |
printf(OUTFILE "%s\n", "/* END_OF_HI_TABLE */");
|
|
443 |
|
|
444 |
$found = &skip_until('^\s*\/\*\s*END_OF_HI_TABL(E)','END_OF_HI_TABLE');
|
|
445 |
if ($found eq "") {
|
|
446 |
die "\ncan't find END_OF_HI_TABLE\n";}
|
|
447 |
|
|
448 |
### SEQ TABLE
|
|
449 |
$found = &replicate_until('^\s*\/\*\s*BEGIN_OF_SEQ_TABL(E)','BEGIN_OF_SEQ_TABLE');
|
|
450 |
if ($found eq "") {
|
|
451 |
die "\ncan't find BEGIN_OF_SEQ_TABLE\n";}
|
|
452 |
|
|
453 |
## replace
|
|
454 |
printf(OUTFILE "%s\n", "/* BEGIN_OF_SEQ_TABLE */");
|
|
455 |
printf(OUTFILE "%s\n",
|
|
456 |
"char *translationTableSeq[SEQ_TABLE][2] = {");
|
|
457 |
|
|
458 |
$index = 0;
|
|
459 |
$sep = ",\n";
|
|
460 |
while ($index <= $seq_table - 1) {
|
|
461 |
$sep = "\n" if $index == $seq_table - 1;
|
|
462 |
($temp1,$temp2,$temp3,$temp4) = split(/\"/,$seq_table[$index]);
|
|
463 |
printf(OUTFILE " {%-".($max_seq_len3+3)."s,%s}".$sep,
|
|
464 |
"\"".$temp3."\"","\"".$temp4."\"");
|
|
465 |
$index++;
|
|
466 |
}
|
|
467 |
printf(OUTFILE "%s\n","};");
|
|
468 |
printf(OUTFILE "%s\n", "/* END_OF_SEQ_TABLE */");
|
|
469 |
|
|
470 |
$found = &skip_until('^\s*\/\*\s*END_OF_SEQ_TABL(E)','END_OF_SEQ_TABLE');
|
|
471 |
if ($found eq "") {
|
|
472 |
die "\ncan't find END_OF_SEQ_TABLE\n";}
|
|
473 |
## the rest
|
|
474 |
while (<INFILE> ){printf(OUTFILE "%s",$_);}
|
|
475 |
|
|
476 |
close(INFILE);
|
|
477 |
close(OUTFILE);
|
|
478 |
print "closed $filename and tmp.txt\n" if $do_ddebug;
|
|
479 |
|
|
480 |
$status = system("cp tmp.txt $filename") ;
|
|
481 |
if ($status) { die "can't copy tmp.txt to $filename: $!\n";}
|
|
482 |
|
|
483 |
########################
|
|
484 |
# configure conv-lex.x
|
|
485 |
#
|
|
486 |
|
|
487 |
$filename = "conv-lex.x";
|
|
488 |
|
|
489 |
print "\nconfiguring $filename\n" if $do_debug;
|
|
490 |
|
|
491 |
open(INFILE ,$filename) || die "can't open $filename in CONV_SOURCE_DIR: $!\n";
|
|
492 |
print "opened $filename for reading\n" if $do_ddebug;
|
|
493 |
open(OUTFILE,">tmp.txt") || die "can't open temporary file tmp.txt: $!\n";
|
|
494 |
print "opened tmp.txt for writing\n" if $do_ddebug;
|
|
495 |
|
|
496 |
|
|
497 |
### HI TABLE
|
|
498 |
$found = &replicate_until('^\s*\/\*\s*BEGIN_OF_HI_TABL(E)','BEGIN_OF_HI_TABLE');
|
|
499 |
if ($found eq "") {
|
|
500 |
die "\ncan't find BEGIN_OF_HI_TABLE\n";}
|
|
501 |
## replace
|
|
502 |
printf(OUTFILE "%s\n", " /* BEGIN_OF_HI_TABLE */");
|
|
503 |
$index = $start_hi_table;
|
|
504 |
while ($index <= $end_hi_table) {
|
|
505 |
($temp1,$temp2,$temp3) = split(/\"/,$hi_table[$index-$start_hi_table]);
|
|
506 |
printf(OUTFILE "<ISAA>%-".($max_hi_len1+3)."s\t"."put((char)%d,FALSE,0);\n",
|
|
507 |
$temp1,$index);
|
|
508 |
$index++;
|
|
509 |
}
|
|
510 |
printf(OUTFILE "%s\n", " /* END_OF_HI_TABLE */");
|
|
511 |
$found = &skip_until('^\s*\/\*\s*END_OF_HI_TABL(E)','END_OF_HI_TABLE');
|
|
512 |
if ($found eq "") {
|
|
513 |
die "\ncan't find END_OF_SEQ_TABLE\n";}
|
|
514 |
|
|
515 |
|
|
516 |
### SEQ TABLE
|
|
517 |
$found = &replicate_until('^\s*\/\*\s*BEGIN_OF_SEQ_TABL(E)','BEGIN_OF_SEQ_TABLE');
|
|
518 |
if ($found eq "") {
|
|
519 |
die "\ncan't find BEGIN_OF_SEQ_TABLE\n";}
|
|
520 |
## replace
|
|
521 |
printf(OUTFILE "%s\n", " /* BEGIN_OF_SEQ_TABLE */");
|
|
522 |
$index = 0;
|
|
523 |
while ($index < $seq_table ) {
|
|
524 |
($temp1,$temp2,$temp3,$temp4) = split(/\"/,$seq_table[$index]);
|
|
525 |
printf(OUTFILE "<ISA,ISAA>%-".($max_seq_len1+3)."s\t"."put((char)32,TRUE,%d);\n",
|
|
526 |
$temp1,$index);
|
|
527 |
printf(OUTFILE "<ISAA>%-".($max_seq_len2+3)."s \t"."put((char)32,TRUE,%d);\n",
|
|
528 |
$temp2,$index);
|
|
529 |
$index++;
|
|
530 |
}
|
|
531 |
printf(OUTFILE "%s\n", " /* END_OF_SEQ_TABLE */");
|
|
532 |
$found = &skip_until('^\s*\/\*\s*END_OF_SEQ_TABL(E)','END_OF_SEQ_TABLE');
|
|
533 |
if ($found eq "") {
|
|
534 |
die "\ncan't find END_OF_SEQ_TABLE\n";}
|
|
535 |
|
|
536 |
|
|
537 |
## the rest
|
|
538 |
while (<INFILE> ){printf(OUTFILE "%s",$_);}
|
|
539 |
|
|
540 |
close(INFILE);
|
|
541 |
close(OUTFILE);
|
|
542 |
print "closed $filename and tmp.txt\n" if $do_ddebug;
|
|
543 |
|
|
544 |
$status = system("cp tmp.txt $filename") ;
|
|
545 |
if ($status) { die "can't copy tmp.txt to $filename: $!\n";}
|
|
546 |
|
|
547 |
########################
|
|
548 |
# execute Makefile
|
|
549 |
#
|
|
550 |
print "\nexecuting Makefile\n" if $do_debug;
|
1907
|
551 |
$status = system($GMAKE) ;
|
|
552 |
if ($status) { die "\"".$GMAKE."\" executed abnormally: $!\n";}
|
1826
|
553 |
|
|
554 |
#$status = system("cp $conv_temp_dir/$conv_sub_dir/isa2latex $conv_source_dir");
|
|
555 |
# if ($status) { die "can't copy binary file to CONV_SOURCE_DIR: $!\n";}
|
|
556 |
|
|
557 |
#print "\nexecuting Makefile, cleaning up\n" if $do_debug;
|
1907
|
558 |
#$status = system($GMAKE." clean");
|
|
559 |
#if ($status) { die "\"".$GMAKE." clean\" executed abnormally: $!\n";}
|
1826
|
560 |
|
|
561 |
#######################################################################
|
|
562 |
# process -s option
|
|
563 |
#######################################################################
|
|
564 |
|
|
565 |
#if ($install_source){
|
|
566 |
# print "\ninstall new files in CONV_SOURCE_DIR due to -s option\n" if $do_debug;
|
|
567 |
# $status = system("cp -r $conv_temp_dir/$conv_sub_dir/* $conv_source_dir");
|
|
568 |
# if ($status) { die "can't copy new files to CONV_SOURCE_DIR: $!\n";}
|
|
569 |
|
|
570 |
# print "copied new files to CONV_SOURCE_DIR\n" if $do_debug;
|
|
571 |
|
|
572 |
# chdir $initial_dir || die "can't cd to initial dir $initial_dir: $!\n";
|
|
573 |
# $status = system("cp $config_file $conv_source_dir");
|
|
574 |
# if ($status) { die "can't copy configuration file to CONV_SOURCE_DIR: $!\n";}
|
|
575 |
#
|
|
576 |
# print "copied configuration file to CONV_SOURCE_DIR\n" if $do_debug;
|
|
577 |
|
|
578 |
#}
|
|
579 |
|
|
580 |
|
|
581 |
########################
|
|
582 |
# END of script
|
|
583 |
#
|
|
584 |
|
|
585 |
print "\nconfiguration and generation of isa2latex properly terminated\n".
|
|
586 |
"have fun with isa2latex!\n\n";
|
|
587 |
exit(0);
|
|
588 |
|
|
589 |
#######################################################################
|
|
590 |
# subroutines
|
|
591 |
#######################################################################
|
|
592 |
|
|
593 |
sub look_for_value {
|
|
594 |
local ($pattern,$label) = @_;
|
|
595 |
local ($temp) = "";
|
|
596 |
|
|
597 |
while (<CONFIG> ){
|
|
598 |
if (($temp) = /$pattern/){
|
|
599 |
print "line $.: $label is $temp\n" if $do_debug;
|
|
600 |
last;}
|
|
601 |
}
|
|
602 |
return $temp;
|
|
603 |
}
|
|
604 |
|
|
605 |
|
|
606 |
sub look_for_label {
|
|
607 |
local ($pattern,$label) = @_;
|
|
608 |
local ($temp) = "";
|
|
609 |
|
|
610 |
while (<CONFIG> ){
|
|
611 |
if (($temp) = /$pattern/){
|
|
612 |
print "line $.: $label found\n" if $do_debug;
|
|
613 |
last;}
|
|
614 |
}
|
|
615 |
return $temp;
|
|
616 |
}
|
|
617 |
|
|
618 |
sub replicate_until {
|
|
619 |
local ($pattern,$label) = @_;
|
|
620 |
local ($temp) = "";
|
|
621 |
|
|
622 |
while (<INFILE> ){
|
|
623 |
if (($temp) = /$pattern/){
|
|
624 |
print "line $.: $label found\n" if $do_debug;
|
|
625 |
last;}
|
|
626 |
else {printf(OUTFILE "%s",$_);}
|
|
627 |
}
|
|
628 |
return $temp;
|
|
629 |
}
|
|
630 |
|
|
631 |
sub skip_until {
|
|
632 |
local ($pattern,$label) = @_;
|
|
633 |
local ($temp) = "";
|
|
634 |
|
|
635 |
while (<INFILE> ){
|
|
636 |
if (($temp) = /$pattern/){
|
|
637 |
print "line $.: $label found\n" if $do_debug;
|
|
638 |
last;}
|
|
639 |
}
|
|
640 |
return $temp;
|
|
641 |
}
|
|
642 |
|
|
643 |
sub double_bs {
|
|
644 |
local ($string) = @_;
|
|
645 |
local ($element);
|
|
646 |
local (@temp1);
|
|
647 |
local (@temp2) = ();
|
|
648 |
|
|
649 |
# find the hex-numbers
|
|
650 |
@temp1 = split(/(\\x[0-9a-fA-F][0-9a-fA-F])/,$string);
|
|
651 |
|
|
652 |
#duplicate all backslashes in elements which are not hexnumbers
|
|
653 |
while(@temp1) {
|
|
654 |
$element = shift(@temp1);
|
|
655 |
if ($element =~ /\\x[0-9a-fA-F][0-9a-fA-F]/){
|
|
656 |
push(@temp2,$element);}
|
|
657 |
else{
|
|
658 |
$element =~ s/\\/\\\\/g;
|
|
659 |
push(@temp2,$element);}
|
|
660 |
}
|
|
661 |
return (join('',@temp2));
|
|
662 |
}
|
|
663 |
|
|
664 |
###############################################################
|
|
665 |
|
|
666 |
# These next few lines are legal in both Perl and nroff.
|
|
667 |
|
|
668 |
.00; # finish .ig
|
|
669 |
|
|
670 |
'di \" finish diversion--previous line must be blank
|
|
671 |
.nr nl 0-1 \" fake up transition to first page again
|
|
672 |
.nr % 0 \" start at page 1
|
|
673 |
'; __END__ ##### From here on it's a standard manual page #####
|