|
1 #!/usr/local/dist/DIR/perl4/bin/perl |
|
2 # |
|
3 # gen-isaterm |
|
4 # Franz Regensburger <regensbu@informatik.tu-muenchen.de> |
|
5 # 21.3.95 |
|
6 # |
|
7 # last changed: |
|
8 # |
|
9 # configures the script `isaterm' |
|
10 # |
|
11 # |
|
12 |
|
13 # I like to see the output as it happens (flushed output) |
|
14 |
|
15 $| = 1; |
|
16 |
|
17 # cash current working directory |
|
18 require "pwd.pl"; |
|
19 &initpwd; |
|
20 |
|
21 $initial_dir = $ENV{'PWD'}; |
|
22 |
|
23 ######################## |
|
24 # comand line processing |
|
25 # processes all known switches and ingnores others. |
|
26 # first non-switch which is the name of a text file is |
|
27 # interpreted as name of configuration file. |
|
28 # |
|
29 |
|
30 # initialize |
|
31 $config_file=""; |
|
32 $do_debug = 0; |
|
33 $do_ddebug = 0; |
|
34 |
|
35 while (@ARGV){ |
|
36 $cur_arg = shift @ARGV; |
|
37 if ($cur_arg eq '-d') {$do_debug = 1;} |
|
38 elsif ($cur_arg eq '-dd') {$do_debug = 1; $do_ddebug = 1;} |
|
39 elsif ((-T $cur_arg) && !$config_file) {$config_file = $cur_arg;} |
|
40 } |
|
41 |
|
42 # complain if no configuration file is found |
|
43 |
|
44 if ($config_file eq "") { |
|
45 print "\nno configuration file suplied or argument is not a text file\n\n"; |
|
46 print "usage gen-isaterm [-d -dd] configfile\n", |
|
47 "options must be seperated by blanks!"; |
|
48 die "\n"; |
|
49 } |
|
50 |
|
51 print "debug mode is on\n" if $do_debug; |
|
52 print "double debug mode is on\n" if $do_ddebug; |
|
53 print "name of configuration file is $config_file\n" if $do_debug; |
|
54 |
|
55 ######################## |
|
56 # open the configuration file |
|
57 |
|
58 open(INFILE,$config_file) || die "can't open $config_file: $!\n"; |
|
59 print "opened configuration file,\nprocessing\n" if $do_debug; |
|
60 |
|
61 ######################## |
|
62 # search for general setup variables |
|
63 |
|
64 print "\ngeneral setup\n" if $do_debug; |
|
65 |
|
66 ######################## |
|
67 # search for PACK |
|
68 |
|
69 $pack = $ENV{'ISABELLE8BIT'}; |
|
70 |
|
71 if ($pack eq "") { |
|
72 die "\ncan't find label PACK in configuration file\n";} |
|
73 |
|
74 if (! (-d $pack)){ |
|
75 die "\nPACK is not a directory\n";} |
|
76 |
|
77 ######################## |
|
78 # search for TERM_DIR |
|
79 |
|
80 #$term_dir = &look_for_value('^\s*TERM_DIR\s*"(.*)"',"TERM_DIR"); |
|
81 |
|
82 #if ($term_dir eq "") { |
|
83 # die "\ncan't find TERM_DIR in configuration file\n";} |
|
84 |
|
85 |
|
86 #if (!(-r $pack."/".$term_dir && -w $pack."/".$term_dir && -x $pack."/".$term_dir)){ |
|
87 # die "\nneed read, write and execute permission for directory TERM_DIR\n";} |
|
88 |
|
89 $term_dir = "term"; |
|
90 |
|
91 |
|
92 ######################## |
|
93 # configuration of KEY_MAP |
|
94 print "\nsetup for KEY_MAP\n" if $do_debug; |
|
95 |
|
96 ######################## |
|
97 # search for BEGIN_KEY_MAP |
|
98 |
|
99 $found = &look_for_label('^\s*BEGIN_KEY_MA(P)',"BEGIN_KEY_MAP"); |
|
100 |
|
101 if ($found eq "") { |
|
102 die "\ncan't find BEGIN_KEY_MAP in configuration file\n";} |
|
103 |
|
104 ######################## |
|
105 # read the KEY_MAP |
|
106 |
|
107 $index = 0; |
|
108 $found = 0; |
|
109 $end_key_map = 0; |
|
110 $pattern = |
|
111 '^\s*MOD\s*(None|Mod1|Mod2|Mod4|Shift|Ctrl)\s*KEY\s*([a-zA-Z]|F\d{1,2})\s*CODE\s*([0-9a-fA-F][0-9a-fA-F](\s*,\s*[0-9a-fA-F][0-9a-fA-F])*)\s*$'; |
|
112 |
|
113 while (<INFILE> ){ |
|
114 if (/^\s*END_KEY_MAP/){ |
|
115 print "line $.: END_KEY_MAP found\n" if $do_debug; |
|
116 $found = 1; |
|
117 $end_key_map = $index - 1; |
|
118 last;} |
|
119 elsif (($modifiers,$key,$codeseq) = /$pattern/){ |
|
120 $key_map[$index]= join(':',$modifiers,$key,$codeseq); |
|
121 print "line $.: \"$key_map[$index]\"\n" if $do_ddebug; |
|
122 $index +=1; |
|
123 } |
|
124 else { |
|
125 print "Is this a comment? line $.: $_\n" ;} |
|
126 } |
|
127 if (!$found){ |
|
128 die "\ncan't find END_KEY_MAP in configuration file\n";} |
|
129 |
|
130 if ($end_low_table < $start_low_table){ |
|
131 die "\nNo entries in KEY_MAP\n";} |
|
132 else {print |
|
133 "computed index for END_KEY_MAP is $end_key_map\n" if $do_debug;} |
|
134 |
|
135 ######################## |
|
136 # we reached the end of the configuration file |
|
137 |
|
138 print "\nprocessing of configuration file completed\n" if $do_debug; |
|
139 |
|
140 ######################## |
|
141 # close the handle for config file |
|
142 close(INFILE); |
|
143 print "closed configuration file\n" if $do_debug; |
|
144 |
|
145 |
|
146 ####################################################################### |
|
147 # modify the sources |
|
148 ####################################################################### |
|
149 |
|
150 ######################## |
|
151 # change to directory TERM_DIR and open the file `isaterm' |
|
152 |
|
153 chdir $pack."/".$term_dir || die "can't cd to $term_dir: $!\n"; |
|
154 |
|
155 ######################## |
|
156 # configure isaterm |
|
157 # |
|
158 |
|
159 $filename = "isaterm"; |
|
160 print "\nconfiguring $filename\n" if $do_debug; |
|
161 |
|
162 open(INFILE ,$filename) || die "can't open $filename: $!\n"; |
|
163 print "opened $filename for reading\n" if $do_ddebug; |
|
164 open(OUTFILE,">tmp.txt") || die "can't open temporary file tmp.txt: $!\n"; |
|
165 print "opened tmp.txt for writing\n" if $do_ddebug; |
|
166 |
|
167 $found = &replicate_until('^\s*\x2axterm\x2avt100\x2e(translations)','xterm*vt100.translations'); |
|
168 |
|
169 if ( $found eq "") { |
|
170 die "\ncan't find `xterm*vt100.translations'\n";} |
|
171 |
|
172 # print header of table |
|
173 printf(OUTFILE "*xterm*vt100.translations: #override\\\n"); |
|
174 |
|
175 #print the table |
|
176 $index = 0; |
|
177 while ($index < $end_key_map) { |
|
178 $entry = &translate_entry(split(/:/,$key_map[$index])); |
|
179 printf(OUTFILE "\t%s \\n\\\n", $entry); |
|
180 $index += 1; |
|
181 } |
|
182 # print the last item |
|
183 $entry = &translate_entry(split(/:/,$key_map[$index])); |
|
184 printf(OUTFILE "\t%s \\\n", $entry); |
|
185 |
|
186 # print footer of table |
|
187 printf(OUTFILE "\" \$* -e \$ISATERMDIR/initisaterm \n"); |
|
188 |
|
189 close(INFILE); |
|
190 close(OUTFILE); |
|
191 print "closed $filename and tmp.txt\n" if $do_ddebug; |
|
192 |
|
193 $status = system("cp tmp.txt $filename") ; |
|
194 if ($status) { die "can't copy tmp.txt to $filename: $!\n";} |
|
195 |
|
196 print "copied tmp.txt to $filename\n" if $do_ddebug; |
|
197 |
|
198 $status = system("rm -f tmp.txt"); |
|
199 if ($status) {die "can't remove file tmp.txt: $!\n";} |
|
200 |
|
201 print "removed tmp.txt to $filename\n" if $do_ddebug; |
|
202 |
|
203 ######################## |
|
204 # END of script |
|
205 # |
|
206 print "\nconfiguration of isaterm properly terminated\n\n"; |
|
207 exit(0); |
|
208 |
|
209 ####################################################################### |
|
210 # subroutines |
|
211 ####################################################################### |
|
212 |
|
213 sub look_for_value { |
|
214 local ($pattern,$label) = @_; |
|
215 local ($temp) = ""; |
|
216 |
|
217 while (<INFILE> ){ |
|
218 if (($temp) = /$pattern/){ |
|
219 print "line $.: $label is $temp\n" if $do_debug; |
|
220 last;} |
|
221 } |
|
222 return $temp; |
|
223 } |
|
224 |
|
225 |
|
226 sub look_for_label { |
|
227 local ($pattern,$label) = @_; |
|
228 local ($temp) = ""; |
|
229 |
|
230 while (<INFILE> ){ |
|
231 if (($temp) = /$pattern/){ |
|
232 print "line $.: $label found\n" if $do_debug; |
|
233 last;} |
|
234 } |
|
235 return $temp; |
|
236 } |
|
237 |
|
238 sub replicate_until { |
|
239 local ($pattern,$label) = @_; |
|
240 local ($temp) = ""; |
|
241 |
|
242 while (<INFILE> ){ |
|
243 if (($temp) = /$pattern/){ |
|
244 print "line $.: $label found\n" if $do_debug; |
|
245 last;} |
|
246 else {printf(OUTFILE "%s",$_);} |
|
247 } |
|
248 return $temp; |
|
249 } |
|
250 |
|
251 sub skip_until { |
|
252 local ($pattern,$label) = @_; |
|
253 local ($temp) = ""; |
|
254 |
|
255 while (<INFILE> ){ |
|
256 if (($temp) = /$pattern/){ |
|
257 print "line $.: $label found\n" if $do_debug; |
|
258 last;} |
|
259 } |
|
260 return $temp; |
|
261 } |
|
262 |
|
263 sub double_bs { |
|
264 local ($string) = @_; |
|
265 local ($element); |
|
266 local (@temp1); |
|
267 local (@temp2) = (); |
|
268 |
|
269 # find the hex-numbers |
|
270 @temp1 = split(/(\\x[0-9a-fA-F][0-9a-fA-F])/,$string); |
|
271 |
|
272 #duplicate all backslashes in elements which are not hexnumbers |
|
273 while(@temp1) { |
|
274 $element = shift(@temp1); |
|
275 if ($element =~ /\\x[0-9a-fA-F][0-9a-fA-F]/){ |
|
276 push(@temp2,$element);} |
|
277 else{ |
|
278 $element =~ s/\\/\\\\/g; |
|
279 push(@temp2,$element);} |
|
280 } |
|
281 return (join('',@temp2)); |
|
282 } |
|
283 |
|
284 # strip leading and trailing blanks |
|
285 sub strip_blanks{ |
|
286 local ($string) = @_; |
|
287 $string =~ s/^\s*((\S+)|(\S.*\S))\s*$/$1/g; |
|
288 return $string; |
|
289 } |
|
290 |
|
291 # translate an entry for `isaterm' script |
|
292 sub translate_entry{ |
|
293 local ($mod,$key,$code) = @_; |
|
294 local (@codelist); |
|
295 local ($string); |
|
296 |
|
297 # if mod is None, delete it |
|
298 if ($mod eq "None"){$mod = "";} |
|
299 |
|
300 # if key is an uppercase letter, add Shift to modifier |
|
301 # although conversion to lowercase is not necessary, we do it |
|
302 |
|
303 if ($key =~ /^[A-Z]$/){ |
|
304 $mod = $mod." Shift" if !($mod eq "Shift"); |
|
305 $key =~ tr/A-Z/a-z/;} |
|
306 |
|
307 # split the sequence of key codes |
|
308 @codelist = split(/\s*,\s*/,$code); |
|
309 |
|
310 # generate key codes |
|
311 $code=""; |
|
312 foreach $string (@codelist){ |
|
313 $code .= "string(0x". $string .") ";} |
|
314 |
|
315 # assemble the whole line |
|
316 $string = "!". #exclusive binding |
|
317 $mod." <Key>".$key.":\t\t".$code; |
|
318 |
|
319 return $string; |
|
320 } |
|
321 |
|
322 |
|
323 |
|
324 |