author | wenzelm |
Fri, 06 Oct 2000 17:35:58 +0200 | |
changeset 10168 | 50be659d4222 |
parent 4637 | bac998af6ea2 |
permissions | -rwxr-xr-x |
2795 | 1 |
#!/usr/local/dist/bin/perl |
1826 | 2 |
# |
3 |
# gen-isa_xemacs |
|
4 |
# Franz Regensburger <regensbu@informatik.tu-muenchen.de> |
|
5 |
# 21.3.95 |
|
6 |
# |
|
7 |
# last changed: |
|
8 |
# |
|
9 |
# configures the script `isa_xemacs' |
|
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-isa_xemacs [-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 XEMACS_DIR |
|
79 |
||
80 |
#$xemacs_dir = &look_for_value('^\s*XEMACS_DIR\s*"(.*)"',"XEMACS_DIR"); |
|
81 |
||
82 |
#if ($xemacs_dir eq "") { |
|
83 |
# die "\ncan't find XEMACS_DIR in configuration file\n";} |
|
84 |
||
85 |
||
86 |
#if (!(-r $pack."/".$xemacs_dir && -w $pack."/".$xemacs_dir && -x $pack."/".$xemacs_dir)){ |
|
87 |
# die "\nneed read, write and execute permission for directory XEMACS_DIR\n";} |
|
88 |
||
89 |
$xemacs_dir = "xemacs"; |
|
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 = |
|
4637
bac998af6ea2
extended input syntax to handle names of special keys
oheimb
parents:
2795
diff
changeset
|
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*$'; |
1826 | 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 XEMACS_DIR and open the file `isa_xemacs' |
|
152 |
||
153 |
chdir $pack."/".$xemacs_dir || die "can't cd to $xemacs_dir: $!\n"; |
|
154 |
||
155 |
######################## |
|
156 |
# configure isa_xemacs |
|
157 |
# |
|
158 |
||
159 |
$filename = "isa_xemacs.emacs"; |
|
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*;;\s*BEGIN-KEY-(MAP)', |
|
168 |
'BEGIN-KEY-MAP'); |
|
169 |
||
170 |
if ( $found eq "") { |
|
171 |
die "\ncan't find `BEGIN-KEY-MAP'\n";} |
|
172 |
||
173 |
# print header of table |
|
174 |
printf(OUTFILE ";; BEGIN-KEY-MAP\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 "%s\n", $entry); |
|
181 |
$index += 1; |
|
182 |
} |
|
183 |
# print the last item |
|
184 |
$entry = &translate_entry(split(/:/,$key_map[$index])); |
|
185 |
printf(OUTFILE "%s\n", $entry); |
|
186 |
||
187 |
# print footer of table |
|
188 |
printf(OUTFILE ";; END-KEY-MAP\n"); |
|
189 |
||
190 |
# skip the table in the input file |
|
191 |
$found = &skip_until('^\s*;;\s*END-KEY-(MAP)','END-KEY-MAP'); |
|
192 |
if ($found eq "") { |
|
193 |
die "\ncan't find END-KEY-MAP in file $filename\n";} |
|
194 |
||
195 |
## replicate the rest of the input file |
|
196 |
while (<INFILE> ){printf(OUTFILE "%s",$_);} |
|
197 |
||
198 |
close(INFILE); |
|
199 |
close(OUTFILE); |
|
200 |
print "closed $filename and tmp.txt\n" if $do_ddebug; |
|
201 |
||
202 |
$status = system("cp tmp.txt $filename") ; |
|
203 |
if ($status) { die "can't copy tmp.txt to $filename: $!\n";} |
|
204 |
||
205 |
print "copied tmp.txt to $filename\n" if $do_ddebug; |
|
206 |
||
207 |
$status = system("rm -f tmp.txt"); |
|
208 |
if ($status) {die "can't remove file tmp.txt: $!\n";} |
|
209 |
||
210 |
print "removed tmp.txt to $filename\n" if $do_ddebug; |
|
211 |
||
212 |
######################## |
|
213 |
# END of script |
|
214 |
# |
|
215 |
print "\nconfiguration of isa_xemacs properly terminated\n\n"; |
|
216 |
exit(0); |
|
217 |
||
218 |
####################################################################### |
|
219 |
# subroutines |
|
220 |
####################################################################### |
|
221 |
||
222 |
sub look_for_value { |
|
223 |
local ($pattern,$label) = @_; |
|
224 |
local ($temp) = ""; |
|
225 |
||
226 |
while (<INFILE> ){ |
|
227 |
if (($temp) = /$pattern/){ |
|
228 |
print "line $.: $label is $temp\n" if $do_debug; |
|
229 |
last;} |
|
230 |
} |
|
231 |
return $temp; |
|
232 |
} |
|
233 |
||
234 |
||
235 |
sub look_for_label { |
|
236 |
local ($pattern,$label) = @_; |
|
237 |
local ($temp) = ""; |
|
238 |
||
239 |
while (<INFILE> ){ |
|
240 |
if (($temp) = /$pattern/){ |
|
241 |
print "line $.: $label found\n" if $do_debug; |
|
242 |
last;} |
|
243 |
} |
|
244 |
return $temp; |
|
245 |
} |
|
246 |
||
247 |
sub replicate_until { |
|
248 |
local ($pattern,$label) = @_; |
|
249 |
local ($temp) = ""; |
|
250 |
||
251 |
while (<INFILE> ){ |
|
252 |
if (($temp) = /$pattern/){ |
|
253 |
print "line $.: $label found\n" if $do_debug; |
|
254 |
last;} |
|
255 |
else {printf(OUTFILE "%s",$_);} |
|
256 |
} |
|
257 |
return $temp; |
|
258 |
} |
|
259 |
||
260 |
sub skip_until { |
|
261 |
local ($pattern,$label) = @_; |
|
262 |
local ($temp) = ""; |
|
263 |
||
264 |
while (<INFILE> ){ |
|
265 |
if (($temp) = /$pattern/){ |
|
266 |
print "line $.: $label found\n" if $do_debug; |
|
267 |
last;} |
|
268 |
} |
|
269 |
return $temp; |
|
270 |
} |
|
271 |
||
272 |
sub double_bs { |
|
273 |
local ($string) = @_; |
|
274 |
local ($element); |
|
275 |
local (@temp1); |
|
276 |
local (@temp2) = (); |
|
277 |
||
278 |
# find the hex-numbers |
|
279 |
@temp1 = split(/(\\x[0-9a-fA-F][0-9a-fA-F])/,$string); |
|
280 |
||
281 |
#duplicate all backslashes in elements which are not hexnumbers |
|
282 |
while(@temp1) { |
|
283 |
$element = shift(@temp1); |
|
284 |
if ($element =~ /\\x[0-9a-fA-F][0-9a-fA-F]/){ |
|
285 |
push(@temp2,$element);} |
|
286 |
else{ |
|
287 |
$element =~ s/\\/\\\\/g; |
|
288 |
push(@temp2,$element);} |
|
289 |
} |
|
290 |
return (join('',@temp2)); |
|
291 |
} |
|
292 |
||
293 |
# strip leading and trailing blanks |
|
294 |
sub strip_blanks{ |
|
295 |
local ($string) = @_; |
|
296 |
$string =~ s/^\s*((\S+)|(\S.*\S))\s*$/$1/g; |
|
297 |
return $string; |
|
298 |
} |
|
299 |
||
300 |
# translate an entry for `isa_xemacs' script |
|
301 |
sub translate_entry{ |
|
302 |
local ($mod,$key,$code) = @_; |
|
303 |
local (@codelist); |
|
304 |
local ($string); |
|
305 |
local ($emacs_mod); |
|
306 |
||
307 |
# we have to construct an emacs modifier |
|
308 |
if ($mod eq "None") { # No Modifier |
|
309 |
if ($key =~ /^[a-zA-Z]$/) { # key is not a function key |
|
310 |
$emacs_mod = "\"$key\"";} |
|
311 |
else { # key must be a function key, we translate the F to lowercase |
|
312 |
$key =~ tr/F/f/; |
|
313 |
$emacs_mod = "'(".$key.")";}} |
|
314 |
elsif ($mod eq "Mod1") { # Mod2 is Meta key in emacs |
|
315 |
if ($key =~ /^[a-zA-Z]$/) { # key is not a function key |
|
316 |
$emacs_mod = "'(meta ".$key.")";} |
|
317 |
else { # key must be a function key, we translate the F to lowercase |
|
318 |
$key =~ tr/F/f/; |
|
319 |
$emacs_mod = "'(meta ".$key.")";}} |
|
320 |
elsif ($mod eq "Mod2") { # Mod2 is Super key in emacs |
|
321 |
if ($key =~ /^[a-zA-Z]$/) { # key is not a function key |
|
322 |
$emacs_mod = "'(super ".$key.")";} |
|
323 |
else { # key must be a function key, we translate the F to lowercase |
|
324 |
$key =~ tr/F/f/; |
|
325 |
$emacs_mod = "'(super ".$key.")";}} |
|
326 |
elsif ($mod eq "Mod4") { # Mod4 is Hyper key in emacs |
|
327 |
if ($key =~ /^[a-zA-Z]$/) { # key is not a function key |
|
328 |
$emacs_mod = "'(hyper ".$key.")";} |
|
329 |
else { # key must be a function key, we translate the F to lowercase |
|
330 |
$key =~ tr/F/f/; |
|
331 |
$emacs_mod = "'(hyper ".$key.")";}} |
|
332 |
elsif ($mod eq "Ctrl") { # Ctrl is Control key in emacs |
|
333 |
if ($key =~ /^[a-zA-Z]$/) { # key is not a function key |
|
334 |
$emacs_mod = "'(control ".$key.")";} |
|
335 |
else { # key must be a function key, we translate the F to lowercase |
|
336 |
$key =~ tr/F/f/; |
|
337 |
$emacs_mod = "'(control ".$key.")";}} |
|
338 |
else { # modifier must be Shift |
|
339 |
if ($key =~ /^[a-zA-Z]$/) { # key is not a function key |
|
340 |
$key =~ tr/a-z/A-Z/; # we translate to uppercase |
|
341 |
$emacs_mod = "\"$key\"";} |
|
342 |
else { # key must be a function key, we translate the F to lowercase |
|
343 |
$key =~ tr/F/f/; |
|
344 |
$emacs_mod = "'(shift ".$key.")";}} |
|
345 |
||
346 |
# split the sequence of key codes |
|
347 |
@codelist = split(/\s*,\s*/,$code); |
|
348 |
||
349 |
# generate key codes |
|
350 |
$code=""; |
|
351 |
foreach $string (@codelist){ |
|
352 |
$code .= "(insert \"". sprintf("\\%o",hex($string)) ."\")";} |
|
353 |
||
354 |
# assemble the whole line |
|
355 |
$string = |
|
356 |
"(global-set-key ".$emacs_mod." '(lambda () (interactive) " . |
|
357 |
$code. "))"; |
|
358 |
||
359 |
return $string; |
|
360 |
} |
|
361 |
||
362 |
||
363 |
||
364 |