author | wenzelm |
Mon, 29 Nov 1999 15:52:49 +0100 | |
changeset 8039 | a901bafe4578 |
parent 4637 | bac998af6ea2 |
permissions | -rwxr-xr-x |
2795 | 1 |
#!/usr/local/dist/bin/perl |
1826 | 2 |
# |
3 |
# gen-isa_gnu_emacs |
|
4 |
# Franz Regensburger <regensbu@informatik.tu-muenchen.de> |
|
5 |
# 21.3.95 |
|
6 |
# |
|
7 |
# last changed: |
|
8 |
# |
|
9 |
# configures the script `isa_gnu_emacs' |
|
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_gnu_emacs [-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 GNU_EMACS_DIR |
|
79 |
||
80 |
#$gnu_emacs_dir = &look_for_value('^\s*GNU_EMACS_DIR\s*"(.*)"',"GNU_EMACS_DIR"); |
|
81 |
||
82 |
#if ($gnu_emacs_dir eq "") { |
|
83 |
# die "\ncan't find GNU_EMACS_DIR in configuration file\n";} |
|
84 |
||
85 |
||
86 |
#if (!(-r $pack."/".$gnu_emacs_dir && -w $pack."/".$gnu_emacs_dir && -x $pack."/".$gnu_emacs_dir)){ |
|
87 |
# die "\nneed read, write and execute permission for directory GNU_EMACS_DIR\n";} |
|
88 |
||
89 |
$gnu_emacs_dir = "gnu_emacs"; |
|
90 |
||
91 |
######################## |
|
92 |
# configuration of KEY_MAP |
|
93 |
print "\nsetup for KEY_MAP\n" if $do_debug; |
|
94 |
||
95 |
######################## |
|
96 |
# search for BEGIN_KEY_MAP |
|
97 |
||
98 |
$found = &look_for_label('^\s*BEGIN_KEY_MA(P)',"BEGIN_KEY_MAP"); |
|
99 |
||
100 |
if ($found eq "") { |
|
101 |
die "\ncan't find BEGIN_KEY_MAP in configuration file\n";} |
|
102 |
||
103 |
######################## |
|
104 |
# read the KEY_MAP |
|
105 |
||
106 |
$index = 0; |
|
107 |
$found = 0; |
|
108 |
$end_key_map = 0; |
|
109 |
$pattern = |
|
4637
bac998af6ea2
extended input syntax to handle names of special keys
oheimb
parents:
2795
diff
changeset
|
110 |
'^\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 | 111 |
|
112 |
while (<INFILE> ){ |
|
113 |
if (/^\s*END_KEY_MAP/){ |
|
114 |
print "line $.: END_KEY_MAP found\n" if $do_debug; |
|
115 |
$found = 1; |
|
116 |
$end_key_map = $index - 1; |
|
117 |
last;} |
|
118 |
elsif (($modifiers,$key,$codeseq) = /$pattern/){ |
|
119 |
$key_map[$index]= join(':',$modifiers,$key,$codeseq); |
|
120 |
print "line $.: \"$key_map[$index]\"\n" if $do_ddebug; |
|
121 |
$index +=1; |
|
122 |
} |
|
123 |
else { |
|
124 |
print "Is this a comment? line $.: $_\n" ;} |
|
125 |
} |
|
126 |
if (!$found){ |
|
127 |
die "\ncan't find END_KEY_MAP in configuration file\n";} |
|
128 |
||
129 |
if ($end_low_table < $start_low_table){ |
|
130 |
die "\nNo entries in KEY_MAP\n";} |
|
131 |
else {print |
|
132 |
"computed index for END_KEY_MAP is $end_key_map\n" if $do_debug;} |
|
133 |
||
134 |
######################## |
|
135 |
# we reached the end of the configuration file |
|
136 |
||
137 |
print "\nprocessing of configuration file completed\n" if $do_debug; |
|
138 |
||
139 |
######################## |
|
140 |
# close the handle for config file |
|
141 |
close(INFILE); |
|
142 |
print "closed configuration file\n" if $do_debug; |
|
143 |
||
144 |
||
145 |
####################################################################### |
|
146 |
# modify the sources |
|
147 |
####################################################################### |
|
148 |
||
149 |
######################## |
|
150 |
# change to directory GNU_EMACS_DIR and open the file `isa_gnu_emacs' |
|
151 |
||
152 |
chdir $pack."/".$gnu_emacs_dir || die "can't cd to $gnu_emacs_dir: $!\n"; |
|
153 |
||
154 |
######################## |
|
155 |
# configure isa_gnu_emacs |
|
156 |
# |
|
157 |
||
158 |
$filename = "isa_gnu_emacs.emacs"; |
|
159 |
print "\nconfiguring $filename\n" if $do_debug; |
|
160 |
||
161 |
open(INFILE ,$filename) || die "can't open $filename: $!\n"; |
|
162 |
print "opened $filename for reading\n" if $do_ddebug; |
|
163 |
open(OUTFILE,">tmp.txt") || die "can't open temporary file tmp.txt: $!\n"; |
|
164 |
print "opened tmp.txt for writing\n" if $do_ddebug; |
|
165 |
||
166 |
$found = &replicate_until('^\s*;;\s*BEGIN-KEY-(MAP)', |
|
167 |
'BEGIN-KEY-MAP'); |
|
168 |
||
169 |
if ( $found eq "") { |
|
170 |
die "\ncan't find `BEGIN-KEY-MAP'\n";} |
|
171 |
||
172 |
# print header of table |
|
173 |
printf(OUTFILE ";; BEGIN-KEY-MAP\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 "%s\n", $entry); |
|
180 |
$index += 1; |
|
181 |
} |
|
182 |
# print the last item |
|
183 |
$entry = &translate_entry(split(/:/,$key_map[$index])); |
|
184 |
printf(OUTFILE "%s\n", $entry); |
|
185 |
||
186 |
# print footer of table |
|
187 |
printf(OUTFILE ";; END-KEY-MAP\n"); |
|
188 |
||
189 |
# skip the table in the input file |
|
190 |
$found = &skip_until('^\s*;;\s*END-KEY-(MAP)','END-KEY-MAP'); |
|
191 |
if ($found eq "") { |
|
192 |
die "\ncan't find END-KEY-MAP in file $filename\n";} |
|
193 |
||
194 |
## replicate the rest of the input file |
|
195 |
while (<INFILE> ){printf(OUTFILE "%s",$_);} |
|
196 |
||
197 |
close(INFILE); |
|
198 |
close(OUTFILE); |
|
199 |
print "closed $filename and tmp.txt\n" if $do_ddebug; |
|
200 |
||
201 |
$status = system("cp tmp.txt $filename") ; |
|
202 |
if ($status) { die "can't copy tmp.txt to $filename: $!\n";} |
|
203 |
||
204 |
print "copied tmp.txt to $filename\n" if $do_ddebug; |
|
205 |
||
206 |
$status = system("rm -f tmp.txt"); |
|
207 |
if ($status) {die "can't remove file tmp.txt: $!\n";} |
|
208 |
||
209 |
print "removed tmp.txt to $filename\n" if $do_ddebug; |
|
210 |
||
211 |
######################## |
|
212 |
# END of script |
|
213 |
# |
|
214 |
print "\nconfiguration of isa_gnu_emacs properly terminated\n\n"; |
|
215 |
exit(0); |
|
216 |
||
217 |
####################################################################### |
|
218 |
# subroutines |
|
219 |
####################################################################### |
|
220 |
||
221 |
sub look_for_value { |
|
222 |
local ($pattern,$label) = @_; |
|
223 |
local ($temp) = ""; |
|
224 |
||
225 |
while (<INFILE> ){ |
|
226 |
if (($temp) = /$pattern/){ |
|
227 |
print "line $.: $label is $temp\n" if $do_debug; |
|
228 |
last;} |
|
229 |
} |
|
230 |
return $temp; |
|
231 |
} |
|
232 |
||
233 |
||
234 |
sub look_for_label { |
|
235 |
local ($pattern,$label) = @_; |
|
236 |
local ($temp) = ""; |
|
237 |
||
238 |
while (<INFILE> ){ |
|
239 |
if (($temp) = /$pattern/){ |
|
240 |
print "line $.: $label found\n" if $do_debug; |
|
241 |
last;} |
|
242 |
} |
|
243 |
return $temp; |
|
244 |
} |
|
245 |
||
246 |
sub replicate_until { |
|
247 |
local ($pattern,$label) = @_; |
|
248 |
local ($temp) = ""; |
|
249 |
||
250 |
while (<INFILE> ){ |
|
251 |
if (($temp) = /$pattern/){ |
|
252 |
print "line $.: $label found\n" if $do_debug; |
|
253 |
last;} |
|
254 |
else {printf(OUTFILE "%s",$_);} |
|
255 |
} |
|
256 |
return $temp; |
|
257 |
} |
|
258 |
||
259 |
sub skip_until { |
|
260 |
local ($pattern,$label) = @_; |
|
261 |
local ($temp) = ""; |
|
262 |
||
263 |
while (<INFILE> ){ |
|
264 |
if (($temp) = /$pattern/){ |
|
265 |
print "line $.: $label found\n" if $do_debug; |
|
266 |
last;} |
|
267 |
} |
|
268 |
return $temp; |
|
269 |
} |
|
270 |
||
271 |
sub double_bs { |
|
272 |
local ($string) = @_; |
|
273 |
local ($element); |
|
274 |
local (@temp1); |
|
275 |
local (@temp2) = (); |
|
276 |
||
277 |
# find the hex-numbers |
|
278 |
@temp1 = split(/(\\x[0-9a-fA-F][0-9a-fA-F])/,$string); |
|
279 |
||
280 |
#duplicate all backslashes in elements which are not hexnumbers |
|
281 |
while(@temp1) { |
|
282 |
$element = shift(@temp1); |
|
283 |
if ($element =~ /\\x[0-9a-fA-F][0-9a-fA-F]/){ |
|
284 |
push(@temp2,$element);} |
|
285 |
else{ |
|
286 |
$element =~ s/\\/\\\\/g; |
|
287 |
push(@temp2,$element);} |
|
288 |
} |
|
289 |
return (join('',@temp2)); |
|
290 |
} |
|
291 |
||
292 |
# strip leading and trailing blanks |
|
293 |
sub strip_blanks{ |
|
294 |
local ($string) = @_; |
|
295 |
$string =~ s/^\s*((\S+)|(\S.*\S))\s*$/$1/g; |
|
296 |
return $string; |
|
297 |
} |
|
298 |
||
299 |
# translate an entry for `isa_gnu_emacs' script |
|
300 |
sub translate_entry{ |
|
301 |
local ($mod,$key,$code) = @_; |
|
302 |
local (@codelist); |
|
303 |
local ($string); |
|
304 |
local ($emacs_mod); |
|
305 |
||
306 |
# we have to construct an emacs modifier |
|
307 |
if ($mod eq "None") { # No Modifier |
|
308 |
if ($key =~ /^[a-zA-Z]$/) { # key is not a function key |
|
309 |
$emacs_mod = "\"$key\"";} |
|
310 |
else { # key must be a function key, we translate the F to lowercase |
|
311 |
$key =~ tr/F/f/; |
|
312 |
$emacs_mod = "[".$key."]";}} |
|
313 |
elsif ($mod eq "Mod1") { # Mod2 is Meta key in emacs |
|
314 |
if ($key =~ /^[a-zA-Z]$/) { # key is not a function key |
|
315 |
$emacs_mod = "[?\\M-".$key."]";} |
|
316 |
else { # key must be a function key, we translate the F to lowercase |
|
317 |
$key =~ tr/F/f/; |
|
318 |
$emacs_mod = "[M-".$key."]";}} |
|
319 |
elsif ($mod eq "Mod2") { # Mod2 is Super key in emacs |
|
320 |
if ($key =~ /^[a-zA-Z]$/) { # key is not a function key |
|
321 |
$emacs_mod = "[?\\s-".$key."]";} |
|
322 |
else { # key must be a function key, we translate the F to lowercase |
|
323 |
$key =~ tr/F/f/; |
|
324 |
$emacs_mod = "[s-".$key."]";}} |
|
325 |
elsif ($mod eq "Mod4") { # Mod4 is Hyper key in emacs |
|
326 |
if ($key =~ /^[a-zA-Z]$/) { # key is not a function key |
|
327 |
$emacs_mod = "[?\\H-".$key."]";} |
|
328 |
else { # key must be a function key, we translate the F to lowercase |
|
329 |
$key =~ tr/F/f/; |
|
330 |
$emacs_mod = "[H-".$key."]";}} |
|
331 |
elsif ($mod eq "Ctrl") { # Ctrl is Control key in emacs |
|
332 |
if ($key =~ /^[a-zA-Z]$/) { # key is not a function key |
|
333 |
$emacs_mod = "[?\\C-".$key."]";} |
|
334 |
else { # key must be a function key, we translate the F to lowercase |
|
335 |
$key =~ tr/F/f/; |
|
336 |
$emacs_mod = "[C-".$key."]";}} |
|
337 |
else { # modifier must be Shift |
|
338 |
if ($key =~ /^[a-zA-Z]$/) { # key is not a function key |
|
339 |
$key =~ tr/a-z/A-Z/; # we translate to uppercase |
|
340 |
$emacs_mod = "\"$key\"";} |
|
341 |
else { # key must be a function key, we translate the F to lowercase |
|
342 |
$key =~ tr/F/f/; |
|
343 |
$emacs_mod = "[S-".$key."]";}} |
|
344 |
||
345 |
# split the sequence of key codes |
|
346 |
@codelist = split(/\s*,\s*/,$code); |
|
347 |
||
348 |
# generate key codes |
|
349 |
$code=""; |
|
350 |
foreach $string (@codelist){ |
|
351 |
$code .= "(insert \"". sprintf("\\%o",hex($string)) ."\")";} |
|
352 |
||
353 |
# assemble the whole line |
|
354 |
$string = |
|
355 |
"(global-set-key ".$emacs_mod." '(lambda () (interactive) " . |
|
356 |
$code. "))"; |
|
357 |
||
358 |
return $string; |
|
359 |
} |
|
360 |
||
361 |
||
362 |
||
363 |