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