1826
|
1 |
#!/usr/local/dist/DIR/perl4/bin/perl
|
|
2 |
#
|
|
3 |
# gen-isaaxe
|
|
4 |
# Franz Regensburger <regensbu@informatik.tu-muenchen.de>
|
|
5 |
# 21.3.95
|
|
6 |
#
|
|
7 |
# last changed:
|
|
8 |
#
|
|
9 |
# configures the script `isaaxe'
|
|
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 |
|
|
43 |
# complain if no configuration file is found
|
|
44 |
|
|
45 |
if ($config_file eq "") {
|
|
46 |
print "\nno configuration file suplied or argument is not a text file\n\n";
|
|
47 |
print "usage gen-isaaxe [-d -dd] configfile\n",
|
|
48 |
"options must be seperated by blanks!";
|
|
49 |
die "\n";
|
|
50 |
}
|
|
51 |
|
|
52 |
print "debug mode is on\n" if $do_debug;
|
|
53 |
print "double debug mode is on\n" if $do_ddebug;
|
|
54 |
print "name of configuration file is $config_file\n" if $do_debug;
|
|
55 |
|
|
56 |
########################
|
|
57 |
# open the configuration file
|
|
58 |
|
|
59 |
open(INFILE,$config_file) || die "can't open $config_file: $!\n";
|
|
60 |
print "opened configuration file,\nprocessing\n" if $do_debug;
|
|
61 |
|
|
62 |
########################
|
|
63 |
# search for general setup variables
|
|
64 |
|
|
65 |
print "\ngeneral setup\n" if $do_debug;
|
|
66 |
|
|
67 |
########################
|
|
68 |
# search for PACK
|
|
69 |
|
|
70 |
$pack = $ENV{'ISABELLE8BIT'};
|
|
71 |
|
|
72 |
if ($pack eq "") {
|
|
73 |
die "\ncan't find label PACK in configuration file\n";}
|
|
74 |
|
|
75 |
if (! (-d $pack)){
|
|
76 |
die "\nPACK is not a directory\n";}
|
|
77 |
|
|
78 |
########################
|
|
79 |
# search for AXE_DIR
|
|
80 |
|
|
81 |
#$axe_dir = &look_for_value('^\s*AXE_DIR\s*"(.*)"',"AXE_DIR");
|
|
82 |
|
|
83 |
#if ($axe_dir eq "") {
|
|
84 |
# die "\ncan't find AXE_DIR in configuration file\n";}
|
|
85 |
|
|
86 |
|
|
87 |
#if (!(-r $pack."/".$axe_dir && -w $pack."/".$axe_dir && -x $pack."/".$axe_dir)){
|
|
88 |
# die "\nneed read, write and execute permission for directory AXE_DIR\n";}
|
|
89 |
|
|
90 |
$axe_dir = "axe";
|
|
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 AXE_DIR and open the file `isaaxe'
|
|
152 |
|
|
153 |
chdir $pack."/".$axe_dir || die "can't cd to $axe_dir: $!\n";
|
|
154 |
|
|
155 |
########################
|
|
156 |
# configure isaaxe
|
|
157 |
#
|
|
158 |
|
|
159 |
$filename = "isaaxe";
|
|
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*\x2aAxe\x2aed\x2e(translations)',
|
|
168 |
'*Axe*ed.translations');
|
|
169 |
|
|
170 |
if ( $found eq "") {
|
|
171 |
die "\ncan't find `*Axe*ed.translations'\n";}
|
|
172 |
|
|
173 |
# print header of table
|
|
174 |
printf(OUTFILE "*Axe*ed.translations: #override\\\n");
|
|
175 |
|
|
176 |
#print the table
|
|
177 |
$index = 0;
|
|
178 |
while ($index < $end_key_map) {
|
|
179 |
$entry = &translate_entry(split(/:/,$key_map[$index]));
|
|
180 |
printf(OUTFILE "\t%s \\n\\\n", $entry);
|
|
181 |
$index += 1;
|
|
182 |
}
|
|
183 |
# print the last item
|
|
184 |
$entry = &translate_entry(split(/:/,$key_map[$index]));
|
|
185 |
printf(OUTFILE "\t%s \\\n", $entry);
|
|
186 |
|
|
187 |
# print footer of table
|
|
188 |
printf(OUTFILE "\" \$*\n");
|
|
189 |
|
|
190 |
close(INFILE);
|
|
191 |
close(OUTFILE);
|
|
192 |
print "closed $filename and tmp.txt\n" if $do_ddebug;
|
|
193 |
|
|
194 |
$status = system("cp tmp.txt $filename") ;
|
|
195 |
if ($status) { die "can't copy tmp.txt to $filename: $!\n";}
|
|
196 |
|
|
197 |
print "copied tmp.txt to $filename\n" if $do_ddebug;
|
|
198 |
|
|
199 |
$status = system("rm -f tmp.txt");
|
|
200 |
if ($status) {die "can't remove file tmp.txt: $!\n";}
|
|
201 |
|
|
202 |
print "removed tmp.txt to $filename\n" if $do_ddebug;
|
|
203 |
|
|
204 |
########################
|
|
205 |
# END of script
|
|
206 |
#
|
|
207 |
print "\nconfiguration of isaaxe properly terminated\n\n";
|
|
208 |
exit(0);
|
|
209 |
|
|
210 |
#######################################################################
|
|
211 |
# subroutines
|
|
212 |
#######################################################################
|
|
213 |
|
|
214 |
sub look_for_value {
|
|
215 |
local ($pattern,$label) = @_;
|
|
216 |
local ($temp) = "";
|
|
217 |
|
|
218 |
while (<INFILE> ){
|
|
219 |
if (($temp) = /$pattern/){
|
|
220 |
print "line $.: $label is $temp\n" if $do_debug;
|
|
221 |
last;}
|
|
222 |
}
|
|
223 |
return $temp;
|
|
224 |
}
|
|
225 |
|
|
226 |
|
|
227 |
sub look_for_label {
|
|
228 |
local ($pattern,$label) = @_;
|
|
229 |
local ($temp) = "";
|
|
230 |
|
|
231 |
while (<INFILE> ){
|
|
232 |
if (($temp) = /$pattern/){
|
|
233 |
print "line $.: $label found\n" if $do_debug;
|
|
234 |
last;}
|
|
235 |
}
|
|
236 |
return $temp;
|
|
237 |
}
|
|
238 |
|
|
239 |
sub replicate_until {
|
|
240 |
local ($pattern,$label) = @_;
|
|
241 |
local ($temp) = "";
|
|
242 |
|
|
243 |
while (<INFILE> ){
|
|
244 |
if (($temp) = /$pattern/){
|
|
245 |
print "line $.: $label found\n" if $do_debug;
|
|
246 |
last;}
|
|
247 |
else {printf(OUTFILE "%s",$_);}
|
|
248 |
}
|
|
249 |
return $temp;
|
|
250 |
}
|
|
251 |
|
|
252 |
sub skip_until {
|
|
253 |
local ($pattern,$label) = @_;
|
|
254 |
local ($temp) = "";
|
|
255 |
|
|
256 |
while (<INFILE> ){
|
|
257 |
if (($temp) = /$pattern/){
|
|
258 |
print "line $.: $label found\n" if $do_debug;
|
|
259 |
last;}
|
|
260 |
}
|
|
261 |
return $temp;
|
|
262 |
}
|
|
263 |
|
|
264 |
sub double_bs {
|
|
265 |
local ($string) = @_;
|
|
266 |
local ($element);
|
|
267 |
local (@temp1);
|
|
268 |
local (@temp2) = ();
|
|
269 |
|
|
270 |
# find the hex-numbers
|
|
271 |
@temp1 = split(/(\\x[0-9a-fA-F][0-9a-fA-F])/,$string);
|
|
272 |
|
|
273 |
#duplicate all backslashes in elements which are not hexnumbers
|
|
274 |
while(@temp1) {
|
|
275 |
$element = shift(@temp1);
|
|
276 |
if ($element =~ /\\x[0-9a-fA-F][0-9a-fA-F]/){
|
|
277 |
push(@temp2,$element);}
|
|
278 |
else{
|
|
279 |
$element =~ s/\\/\\\\/g;
|
|
280 |
push(@temp2,$element);}
|
|
281 |
}
|
|
282 |
return (join('',@temp2));
|
|
283 |
}
|
|
284 |
|
|
285 |
# strip leading and trailing blanks
|
|
286 |
sub strip_blanks{
|
|
287 |
local ($string) = @_;
|
|
288 |
$string =~ s/^\s*((\S+)|(\S.*\S))\s*$/$1/g;
|
|
289 |
return $string;
|
|
290 |
}
|
|
291 |
|
|
292 |
# translate an entry for `isaaxe' script
|
|
293 |
sub translate_entry{
|
|
294 |
local ($mod,$key,$code) = @_;
|
|
295 |
local (@codelist);
|
|
296 |
local ($string);
|
|
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 .= "insert-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 |
|