17 external glx
: int -> unit = "ml_glx";;
18 external glxsync
: unit -> unit = "ml_glxsync";;
19 external swapb
: unit -> unit = "ml_swapb";;
21 let vlog fmt
= Format.kprintf ignore fmt
;;
27 method reshape _ _
= ()
28 method mouse _ _ _ _ _
= ()
29 method motion _ _
= ()
30 method pmotion _ _
= ()
34 method winstate _
= ()
42 method reshape
: int -> int -> unit
43 method mouse
: int -> bool -> int -> int -> int -> unit
44 method motion
: int -> int -> unit
45 method pmotion
: int -> int -> unit
46 method key
: int -> int -> unit
47 method enter
: int -> int -> unit
49 method winstate
: winstate list
-> unit
56 ; mutable keymap
: int array array
57 ; fifo
: (string -> unit) Queue.t
59 ; mutable protoatom
: int
60 ; mutable deleatom
: int
61 ; mutable nwmsatom
: int
62 ; mutable maxvatom
: int
63 ; mutable maxhatom
: int
64 ; mutable fulsatom
: int
65 ; mutable idbase
: int
66 ; mutable fullscreen
: (int -> unit)
67 ; mutable setwmname
: (string -> unit)
68 ; mutable actwin
: (unit -> unit)
69 ; mutable stringatom
: int
71 ; mutable sock
: Unix.file_descr
77 ; mutable curcurs
: cursor
78 ; mutable capslmask
: int
79 ; mutable numlmask
: int
80 ; mutable levl3mask
: int
81 ; mutable levl5mask
: int
85 | Fs
of (int * int * int * int)
92 ; fifo
= Queue.create
()
101 ; fullscreen
= (fun _
-> ())
102 ; setwmname
= (fun _
-> ())
103 ; actwin
= (fun _
-> ())
112 ; curcurs
= CURSOR_INHERIT
120 let w8 s pos i
= String.set s pos
(Char.chr
(i
land 0xff));;
124 w8 s
(pos
+1) (i
lsr 8);
129 w16 s
(pos
+2) (i
lsr 16);
133 let rb pos1
= Char.code
(String.get s
(pos
+ pos1
)) in
134 (rb 0) lor ((rb 1) lsl 8)
139 i - ((i land 0x8000) lsl 1);
142 let r8 s pos
= Char.code
(String.get s pos
);;
145 let rb pos1
= Char.code
(String.get s
(pos
+ pos1
)) in
146 let l = (rb 0) lor ((rb 1) lsl 8)
147 and u
= (rb 2) lor ((rb 3) lsl 8) in
152 let s = String.create n
in
154 let m = tempfailureretry
(Unix.read sock
s pos
) n
in
159 ignore
(tempfailureretry
(Unix.select
[sock
] [] []) 0.01);
160 loop (pos
+ m) (n
- m)
167 let sendstr1 s pos len sock
=
168 vlog "%d => %S" state.seq
s;
169 state.seq
<- state.seq
+ 1;
170 let n = tempfailureretry
(Unix.send sock
s pos len
) [] in
172 then error
"send %d returned %d" len
n;
175 let updkmap sock resp
=
176 let syms = r8 resp
1 in
177 let len = r32 resp
4 in
180 then readstr sock
(4*len)
183 let m = len / syms in
184 state.keymap
<- Array.make_matrix
185 (state.maxk
- state.mink
) syms 0xffffff;
186 let rec loop i = if i = m then () else
188 let rec loop2 k l = if l = syms then () else
189 let v = r32 data k in
190 state.keymap
.(i).(l) <- v;
199 let updmodmap sock resp
=
201 let len = r16 resp
4 in
204 then readstr sock
(len*4)
207 let modmap = Array.make_matrix
8 n 0xffffff in
208 let rec loop l = if l = 8 then () else
210 let rec loop1 m = if m = n then () else
212 let code = r8 data p in
213 modmap.(l).(m) <- code;
216 let ki = code - state.mink
in
219 let a = state.keymap
.(ki) in
220 let rec capsloop i = if i = Array.length
a || i > 3 then () else
223 then state.capslmask
<- 2
231 let ki = code - state.mink
in
234 let a = state.keymap
.(ki) in
235 let rec lloop i = if i = Array.length
a || i > 3 then () else
238 | 0xfe03 -> state.levl3mask
<- 1 lsl l
239 | 0xfe11 -> state.levl5mask
<- 1 lsl l
240 | 0xff7f -> state.numlmask
<- 1 lsl l
254 let sendwithrep sock
s f
=
255 Queue.push f
state.fifo
;
256 sendstr1 s 0 (String.length
s) sock
;
260 let b = Buffer.create
16 in
261 List.iter
(Buffer.add_string
b) ss
;
262 let bl = Buffer.length
b in
263 let pl = bl land 3 in
267 Buffer.add_substring
b pad 0 (4 - pl);
272 let padcat s1 s2
= padcatl [s1
; s2
];;
274 let internreq name onlyifexists
=
275 let s = "\016\000\000\000\000\000\000\000" in
276 let s = padcat s name
in
277 if onlyifexists
then w8 s 1 1;
278 w16 s 2 (String.length
s / 4);
279 w16 s 4 (String.length name
);
283 let sendintern sock
s onlyifexists f
=
284 let s = internreq s onlyifexists
in
285 sendwithrep sock
s f
;
288 let createwindowreq wid parent x y w h bw mask
=
289 let s = "\001\000\009\000wwwwppppxxyywwhhbwccvvvvmmmmeeee" in
299 w32 s 28 0x800; (* eventmask *)
304 let getgeometryreq wid
=
305 let s = "\014u\002\000dddd" in
311 let s = "\008u\002\000wwww" in
316 let getkeymapreq first count
=
317 let s = "\101u\002\000fcuu" in
323 let changepropreq wid prop typ format props
=
324 let s = "\018\000llwwwwppppttttfuuuLLLL" in
325 let s = padcat s props
in
326 w16 s 2 (String.length
s / 4);
331 let ful = String.length props
/ (match format
with
335 | n -> error
"no idea what %d means" n)
341 let getpropreq delete wid prop typ
=
342 let s = "\020\000\006\000wwwwppppttttooooLLLL" in
343 if delete
then w8 s 1 1;
352 let openfontreq fid name
=
353 let s = "\045ullffffnnuu" in
354 let s = padcat s name
in
355 w16 s 2 (String.length
s / 4);
357 w16 s 8 (String.length name
);
361 let createglyphcursorreq fid cid cindex
=
362 let s = "\094u\008\000ccccffffffffssmmrrggbbRRGGBB" in
377 let changewindowattributesreq wid mask attrs
=
378 let s = "\002ullwwwwmmmm" in
379 let s = padcat s attrs
in
380 w16 s 2 (String.length
s / 4);
386 let configurewindowreq wid mask values
=
387 let s = "\012ullwwwwmmuu" in
388 let s = padcat s values
in
389 w16 s 2 (String.length
s / 4);
401 let clientmessage format seq wid typ
data =
402 let s = "\033fsswwwwtttt" in
403 let s = padcat s data in
411 let sendeventreq propagate destwid mask
data =
412 let s = "\025p\011\000wwwwmmmm" in
413 let s = padcat s data in
420 let getmodifiermappingreq () =
421 let s = "\119u\001\000" in
425 let getkeysym code mask
=
426 let pkpk = state.keymap
.(code-state.mink
).(0) in
427 if (pkpk >= 0xff80 && pkpk <= 0xffbd)
428 || (pkpk >= 0x11000000 && pkpk <= 0x1100ffff)
430 if mask
land state.numlmask
!= 0
432 let keysym = state.keymap
.(code-state.mink
).(1) in
433 if keysym = 0 then pkpk else keysym
438 if pkpk land 0xf000 = 0xf000
440 else (mask
land 1) lxor ((mask
land state.capslmask
) lsr 1)
443 let l3 = (mask
land state.levl3mask
) != 0 in
444 let l4 = (mask
land state.levl5mask
) != 0 in
446 if l3 then (if l4 then 8 else 4) else (if l4 then 6 else 0)
448 let keysym = state.keymap
.(code-state.mink
).(index) in
449 if index land 1 = 1 && keysym = 0
450 then state.keymap
.(code-state.mink
).(index - 1)
456 let resp = readstr sock
32 in
457 let opcode = r8 resp 0 in
458 match opcode land lnot
0x80 with
463 and resid
= r32 resp 4
466 error
"code=%d serial=%d resid=%#x min=%d maj=%d\n%S"
467 code serial resid min maj
resp;
469 | 1 -> (* response *)
470 let rep = Queue.pop
state.fifo
in
473 | 2 -> (* key press *)
474 if Array.length
state.keymap
> 0
476 let code = r8 resp 1 in
477 let mask = r16 resp 28 in
478 let keysym = getkeysym code mask in
479 vlog "keysym = %x %c mask %#x code %d"
480 keysym (Char.unsafe_chr
keysym) mask code;
481 state.t#key
keysym mask;
483 | 3 -> (* key release *)
484 if Array.length
state.keymap
> 0
486 let code = r8 resp 1 in
487 let mask = r16 resp 28 in
488 let keysym = getkeysym code mask in
489 vlog "release keysym = %x %c mask %#x code %#d"
490 keysym (Char.unsafe_chr
keysym) mask code
492 | 4 -> (* buttonpress *)
496 and m = r16 resp 28 in
497 state.t#mouse
n true x y
m;
500 | 5 -> (* buttonrelease *)
504 and m = r16 resp 28 in
505 state.t#mouse
n false x y
m;
506 vlog "release %d %d %d" n x y
509 let x = r16s resp 24 in
510 let y = r16s resp 26 in
511 let m = r16 resp 28 in
513 then state.t#pmotion
x y
514 else state.t#motion
x y;
515 vlog "move %dx%d => %d" x y m
519 and y = r16s resp 26 in
521 vlog "enter %d %d" x y
526 | 18 -> vlog "unmap";
531 | 12 -> (* exposure *)
535 | 15 -> (* visibility *)
536 let vis = r8 resp 8 in
537 if vis != 2 then state.t#visible
;
538 vlog "visibility %d" vis;
540 | 34 -> (* mapping *)
541 state.keymap
<- [||];
542 let s = getkeymapreq state.mink
(state.maxk
-state.mink
-1) in
543 sendwithrep sock
s (updkmap sock
);
544 state.capslmask
<- 0;
545 state.levl3mask
<- 0;
546 state.levl5mask
<- 0;
548 let s = getmodifiermappingreq () in
549 sendwithrep sock
s (updmodmap sock
);
551 | 33 -> (* clientmessage *)
552 let atom = r32 resp 8 in
553 if atom = state.protoatom
555 let atom = r32 resp 12 in
556 if atom = state.deleatom
561 | 21 -> (* reparent *)
564 | 22 -> (* configure *)
568 and h
= r16 resp 22 in
569 vlog "configure cur [%d %d %d %d] conf [%d %d %d %d]"
570 state.x state.y state.w
state.h
574 if w
!= state.w
|| h
!= state.h
585 let atom = r32 resp 8 in
586 if atom = state.nwmsatom
588 let s = getpropreq false state.idbase
atom 4 in
589 sendwithrep sock
s (fun resp ->
590 let len = r32 resp 4 in
591 let nitems = r32 resp 16 in
596 let s = readstr sock
(len*4) in
597 let rec loop wsl i = if i = nitems then wsl else
598 let atom = r32 s (i*4) in
600 if atom = state.maxhatom
603 if atom = state.maxvatom
606 if atom = state.fulsatom
608 state.fs
<- Fs
(state.x, state.y, state.w
, state.h
);
618 state.t#winstate
(List.sort compare
wsl)
622 dolog
"event %d %S" n resp
628 if hasdata sock
then loop ();
633 let sendstr s ?
(pos
=0) ?
(len=String.length
s) sock
=
634 sendstr1 s pos
len sock
;
635 if hasdata sock
then readresp sock
;
641 let s = "wwuuhhuu" in
644 let s = configurewindowreq state.idbase
0x000c s in
645 sendstr s state.sock
;
646 else state.fullscreen
state.idbase
653 let syncsendwithrep sock secstowait
s f
=
654 let completed = ref false in
655 sendwithrep sock
s (fun resp -> f
resp; completed := true);
656 let now = Unix.gettimeofday
in
657 let deadline = now () +. secstowait
in
658 let rec readtillcompletion () =
660 let timeout = deadline -. now () in
663 else Unix.select
[sock
] [] [] timeout
665 let r, _
, _
= tempfailureretry
sf deadline in
667 | [] -> error
"didn't get X response in %f seconds, aborting" secstowait
671 then readtillcompletion ()
673 readtillcompletion ();
677 let s = mapreq state.idbase
in
678 sendstr s state.sock
;
681 let syncsendintern sock secstowait
s onlyifexists f
=
682 let s = internreq s onlyifexists
in
683 syncsendwithrep sock secstowait
s f
;
686 let setup sock screennum w h
=
687 let s = readstr sock
2 in
688 let n = String.length
s in
690 then error
"failed to read X connection setup response n=%d" n;
693 let reasonlen = r8 s 1 in
694 let s = readstr sock
6 in
699 let data = readstr sock
len in
700 let reason = String.sub
data 0 reasonlen in
701 error
"X connection failed maj=%d min=%d reason=%S"
704 | '
\002'
-> failwith
"X connection setup failed: authentication required";
707 let s = readstr sock
38 in
711 and idbase
= r32 s 10
712 and idmask
= r32 s 14
714 and screens
= r8 s 26
715 and formats
= r8 s 27
717 and maxkk
= r8 s 33 in
718 let data = readstr sock
(4*add
-32) in
719 let vendor = String.sub
data 0 vlen
in
720 let pos = ((vlen
+3) land lnot
3) + formats
*8 in
722 if screennum
>= screens
723 then error
"invalid screen %d, max %d" screennum
(screens
-1);
727 let rec findscreen n pos = if n = screennum
then pos else
729 let ndepths = r8 s (pos+39) in
730 let rec skipdepths n pos = if n = ndepths then pos else
732 let nvisiuals = r16 s (pos+2) in
733 pos + nvisiuals*24 + 8
737 skipdepths n (pos+40)
743 let root = r32 data pos in
744 let rootw = r16 data (pos+20)
745 and rooth
= r16 data (pos+22) in
748 state.idbase
<- idbase
;
749 vlog "vendor = %S, maj=%d min=%d" vendor maj min
;
750 vlog "screens = %d formats = %d" screens formats
;
751 vlog "minkk = %d maxkk = %d" minkk maxkk
;
752 vlog "idbase = %#x idmask = %#x" idbase idmask
;
753 vlog "root=%#x %dx%d" root rootw rooth
;
756 + 0x00000001 (* KeyPress *)
757 (* + 0x00000002 *) (* KeyRelease *)
758 + 0x00000004 (* ButtonPress *)
759 + 0x00000008 (* ButtonRelease *)
760 + 0x00000010 (* EnterWindow *)
761 + 0x00000020 (* LeaveWindow *)
762 + 0x00000040 (* PointerMotion *)
763 (* + 0x00000080 *) (* PointerMotionHint *)
764 (* + 0x00000100 *) (* Button1Motion *)
765 (* + 0x00000200 *) (* Button2Motion *)
766 (* + 0x00000400 *) (* Button3Motion *)
767 (* + 0x00000800 *) (* Button4Motion *)
768 (* + 0x00001000 *) (* Button5Motion *)
769 + 0x00002000 (* ButtonMotion *)
770 (* + 0x00004000 *) (* KeymapState *)
771 + 0x00008000 (* Exposure *)
772 + 0x00010000 (* VisibilityChange *)
773 + 0x00020000 (* StructureNotify *)
774 (* + 0x00040000 *) (* ResizeRedirect *)
775 (* + 0x00080000 *) (* SubstructureNotify *)
776 (* + 0x00100000 *) (* SubstructureRedirect *)
777 (* + 0x00200000 *) (* FocusChange *)
778 + 0x00400000 (* PropertyChange *)
779 (* + 0x00800000 *) (* ColormapChange *)
780 (* + 0x01000000 *) (* OwnerGrabButton *)
782 let wid = state.idbase
in
783 let s = createwindowreq wid root 0 0 w h
0 mask in
786 sendintern sock
"WM_PROTOCOLS" false (fun resp ->
787 state.protoatom
<- r32 resp 8;
788 sendintern sock
"WM_DELETE_WINDOW" false (fun resp ->
789 state.deleatom
<- r32 resp 8;
790 let s = s32 state.deleatom
in
791 let s = changepropreq wid state.protoatom
4 32 s in
796 sendintern sock
"WM_CLIENT_MACHINE" false (fun resp ->
797 let atom = r32 resp 8 in
800 try Unix.gethostname
()
802 dolog
"error getting host name: %s" (exntos exn
);
807 let s = changepropreq wid atom state.stringatom
8 hostname in
809 sendintern sock
"_NET_WM_PID" false (fun resp ->
810 let atom = r32 resp 8 in
811 let pid = Unix.getpid
() in
813 let s = changepropreq wid atom (* cardinal *)6 32 s in
818 state.actwin
<- (fun () ->
820 let s = configurewindowreq state.idbase
0x40 s in
821 sendstr s state.sock
;
822 let s = mapreq state.idbase
in
823 sendstr s state.sock
;
826 sendintern sock
"_NET_ACTIVE_WINDOW" true (fun resp ->
827 let atom = r32 resp 8 in
828 state.actwin
<- (fun () ->
829 let data = String.make
20 '
\000'
in
830 let cm = clientmessage 32 0 wid atom data in
831 let s = sendeventreq 0 root 0x180000 cm in
832 sendstr s state.sock
;
836 syncsendintern sock
2.0 "WM_CLASS" false (fun resp ->
837 let atom = r32 resp 8 in
838 let llpp = "llpp\000llpp\000" in
839 let s = changepropreq wid atom 31 8 llpp in
843 let s = getkeymapreq state.mink
(state.maxk
-state.mink
) in
844 sendwithrep sock
s (updkmap sock
);
846 let s = getmodifiermappingreq () in
847 sendwithrep sock
s (updmodmap sock
);
849 let s = openfontreq (wid+1) "cursor" in
852 Array.iteri
(fun i glyphindex
->
853 let s = createglyphcursorreq (wid+1) (wid+2+i) glyphindex
in
855 ) [|34;48;50;58;128;152|];
857 sendintern sock
"UTF8_STRING" true (fun resp ->
858 let atom = r32 resp 8 in
860 then state.stringatom
<- atom;
864 let s = changepropreq state.idbase
39 state.stringatom
8 s in
865 sendstr s state.sock
;
867 state.setwmname <- setwmname;
868 sendintern sock
"_NET_WM_NAME" true (fun resp ->
869 let atom = r32 resp 8 in
871 then state.setwmname <- (fun s ->
873 let s = changepropreq state.idbase
atom state.stringatom
8 s in
874 sendstr s state.sock
;
878 state.fullscreen
<- (fun wid ->
879 let s = "xxuuyyuuwwuuhhuu" in
886 let s = configurewindowreq wid 0x000f s in
887 sendstr s state.sock
;
888 state.fs
<- Fs
(state.x, state.y, state.w
, state.h
);
895 let s = configurewindowreq wid 0x000f s in
896 sendstr s state.sock
;
900 sendintern sock
"_NET_WM_STATE" true (fun resp ->
901 state.nwmsatom
<- r32 resp 8;
902 if state.nwmsatom
!= 0
904 sendintern sock
"_NET_WM_STATE_MAXIMIZED_VERT" true (fun resp ->
905 state.maxvatom
<- r32 resp 8;
907 sendintern sock
"_NET_WM_STATE_MAXIMIZED_HORZ" true (fun resp ->
908 state.maxhatom
<- r32 resp 8;
910 sendintern sock
"_NET_WM_STATE_FULLSCREEN" true (fun resp ->
911 state.fulsatom
<- r32 resp 8;
912 if state.fulsatom
!= 0
916 let data = String.make
20 '
\000'
in
919 | NoFs
-> Fs
(-1, -1, -1, -1), 1
923 w32 data 4 state.fulsatom
;
925 let cm = clientmessage 32 0 wid state.nwmsatom
data in
926 let s = sendeventreq 0 root 0x180000 cm in
933 let s = getgeometryreq wid in
934 syncsendwithrep sock
2.0 s (fun resp ->
937 and h
= r16 resp 18 in
943 error
"unknown conection setup response %d" (Char.code c
)
946 let getauth haddr dnum
=
948 if haddr = "localhost" || String.length
haddr = 0
950 try Unix.gethostname
()
952 dolog
"failed to resolve `%S': %s" haddr (exntos exn
);
957 try Sys.getenv
"XAUTHORITY"
959 try Filename.concat
(Sys.getenv
"HOME") ".Xauthority"
963 let input_string ic
len =
964 let s = String.create
len in
965 really_input ic
s 0 len;
969 let rb pos = Char.code (String.get
s pos) in
970 (rb 1) lor ((rb 0) lsl 8)
974 let s = input_string ic
2 in
978 let family = input_string ic
2 in
982 try Some
(int_of_string
nums)
985 "display number(%S) is not an integer (corrupt %S?): %s"
986 nums path (exntos exn
);
992 vlog "family %S addr %S(%S) num %S(%d) name %S data %S"
993 family addr haddr nums dnum
name data;
995 | Some num
when addr = haddr && num
= dnum
->
1002 | End_of_file
-> "", ""
1004 dolog
"exception while reading X authority data (%S): %s"
1013 if String.length
path = 0
1015 else Some
(open_in_bin
path)
1017 if Sys.file_exists
path
1019 dolog
"failed to open X authority file `%S' : %s"
1025 | Some ic
-> readauth ic
1028 let init t
w h osx
=
1030 try Sys.getenv
"DISPLAY"
1032 error
"could not get DISPLAY evironment variable: %s"
1037 then error
"invalid DISPLAY(%s) %S" w d
1039 let s = String.sub
d b (e
- b) in
1042 error
"invalid DISPLAY %S can not parse %s(%S): %s"
1046 if pos = String.length
d
1047 then error
"invalid DISPLAY %S no display number specified" d
1051 let rec pdispnum pos1
=
1052 if pos1
= String.length
d
1053 then getnum "display number" (pos+1) pos1
, 0
1057 let dispnum = getnum "display number" (pos+1) pos1
in
1058 let rec pscreennum pos2
=
1059 if pos2
= String.length
d
1060 then getnum "screen number" (pos1
+1) pos2
1063 | '
0'
.. '
9'
-> pscreennum (pos2
+1)
1065 error
"invalid DISPLAY %S, cannot parse screen number" d
1067 dispnum, pscreennum (pos1
+1)
1068 | '
0'
.. '
9'
-> pdispnum (pos1
+1)
1070 error
"invalid DISPLAY %S, cannot parse display number" d
1072 String.sub
d 0 pos, pdispnum (pos+1)
1076 let host, (dispnum, screennum
) = phost 0 in
1077 let aname, adata
= getauth host dispnum in
1080 if osx
|| String.length
host = 0 || host = "unix"
1084 then Unix.ADDR_UNIX
d
1085 else Unix.ADDR_UNIX
("/tmp/.X11-unix/X" ^ string_of_int
dispnum)
1087 let fd = Unix.socket
Unix.PF_UNIX
Unix.SOCK_STREAM
0 in
1091 try Unix.gethostbyname
host
1093 error
"cannot resolve %S: %s" host (exntos exn
)
1095 let addr = h.Unix.h_addr_list
.(0) in
1096 let port = 6000 + dispnum in
1097 let fd = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
1098 fd, (Unix.ADDR_INET
(addr, port))
1100 try Unix.connect
fd addr; fd
1102 error
"failed to connect to X: %s" (exntos exn
)
1105 let s = "luMMmmnndduu" in
1106 let s = padcat s aname in
1107 let s = padcat s adata
in
1110 w16 s 6 (String.length
aname);
1111 w16 s 8 (String.length adata
);
1112 sendstr1 s 0 (String.length
s) fd;
1114 setup fd screennum
w h;
1116 fd, state.w, state.h;
1123 let setcursor cursor
=
1124 if cursor
!= state.curcurs
1128 | CURSOR_INHERIT
-> -1
1131 | CURSOR_CROSSHAIR
-> 0
1134 let s = s32 (if n = -1 then 0 else state.idbase
+2+n) in
1135 let s = changewindowattributesreq state.idbase
(*cursor*)0x4000 s in
1136 sendstr s state.sock
;
1137 state.curcurs
<- cursor
;
1141 state.fullscreen state.idbase
;
1144 let metamask = 0x40;;
1149 let withalt mask = mask land altmask != 0;;
1150 let withctrl mask = mask land ctrlmask != 0;;
1151 let withshift mask = mask land shiftmask != 0;;
1152 let withmeta mask = mask land metamask != 0;;
1153 let withnone mask = mask land (altmask + ctrlmask + shiftmask + metamask) = 0;;
1156 let t = Hashtbl.create
20
1157 and f
= Hashtbl.create
20 in
1159 List.iter
(fun s -> Hashtbl.add t s k) (n::nl
);
1163 let s = String.create
1 in
1165 add s [] (Char.code c
)
1168 let an = Char.code a and bn
= Char.code b in
1169 for i = an to bn
do addc (Char.chr
i) done;
1174 String.iter
addc "`~!@#$%^&*()-_=+\\|[{]};:,./<>?";
1175 for i = 0 to 29 do add ("f" ^ string_of_int
(i+1)) [] (0xffbe + i) done;
1176 add "space" [] 0x20;
1177 add "ret" ["return"; "enter"] 0xff0d;
1178 add "tab" [] 0xff09;
1179 add "left" [] 0xff51;
1180 add "right" [] 0xff53;
1181 add "home" [] 0xff50;
1182 add "end" [] 0xff57;
1183 add "ins" ["insert"] 0xff63;
1184 add "del" ["delete"] 0xffff;
1185 add "esc" ["escape"] 0xff1b;
1186 add "pgup" ["pageup"] 0xff55;
1187 add "pgdown" ["pagedown"] 0xff56;
1188 add "backspace" [] 0xff08;
1190 add "down" [] 0xff54;
1195 try Hashtbl.find xlatf
k
1196 with Not_found
-> Printf.sprintf
"%#x" k;
1200 try Hashtbl.find xlatt name
1202 if String.length
name = 1
1203 then Char.code name.[0]
1204 else int_of_string
name;