17 external glx1
: unit -> (int * int) = "ml_glx1";;
18 external glx2
: int -> unit = "ml_glx2";;
19 external glxsync
: unit -> unit = "ml_glxsync";;
20 external swapb
: unit -> unit = "ml_swapb";;
22 let vlog fmt
= Format.kprintf ignore fmt
;;
28 method reshape _ _
= ()
29 method mouse _ _ _ _ _
= ()
30 method motion _ _
= ()
31 method pmotion _ _
= ()
35 method winstate _
= ()
43 method reshape
: int -> int -> unit
44 method mouse
: int -> bool -> int -> int -> int -> unit
45 method motion
: int -> int -> unit
46 method pmotion
: int -> int -> unit
47 method key
: int -> int -> unit
48 method enter
: int -> int -> unit
50 method winstate
: winstate list
-> unit
57 ; mutable keymap
: int array array
58 ; fifo
: (string -> unit) Queue.t
60 ; mutable protoatom
: int
61 ; mutable deleatom
: int
62 ; mutable nwmsatom
: int
63 ; mutable maxvatom
: int
64 ; mutable maxhatom
: int
65 ; mutable fulsatom
: int
66 ; mutable idbase
: int
68 ; mutable fullscreen
: (int -> unit)
69 ; mutable setwmname
: (string -> unit)
70 ; mutable actwin
: (unit -> unit)
71 ; mutable stringatom
: int
73 ; mutable sock
: Unix.file_descr
79 ; mutable curcurs
: cursor
80 ; mutable capslmask
: int
81 ; mutable numlmask
: int
82 ; mutable levl3mask
: int
83 ; mutable levl5mask
: int
87 | Fs
of (int * int * int * int)
94 ; fifo
= Queue.create
()
104 ; fullscreen
= (fun _
-> ())
105 ; setwmname
= (fun _
-> ())
106 ; actwin
= (fun _
-> ())
115 ; curcurs
= CURSOR_INHERIT
125 let makereq opcode len reqlen
=
126 let s = String.make len '
\000'
in
132 let recv fd
s pos len
=
133 Unix.recv fd
s pos len
[];
137 let s = String.create n
in
139 let m = tempfailureretry
(recv sock
s pos
) n
in
144 ignore
(tempfailureretry
(Unix.select
[sock
] [] []) 0.01);
145 loop (pos
+ m) (n
- m)
152 let sendstr1 s pos len sock
=
153 vlog "%d <= %S" state.seq
s;
154 state.seq
<- state.seq
+ 1;
155 let n = tempfailureretry
(Unix.send sock
s pos len
) [] in
157 then error
"send %d returned %d" len
n;
160 let updkmap sock resp
=
161 let syms = r8 resp
1 in
162 let len = r32 resp
4 in
165 then readstr sock
(4*len)
168 let m = len / syms in
169 state.keymap
<- Array.make_matrix
170 (state.maxk
- state.mink
) syms 0xffffff;
171 let rec loop i
= if i
= m then () else
173 let rec loop2 k l
= if l
= syms then () else
174 let v = r32
data k in
175 state.keymap
.(i
).(l
) <- v;
184 let updmodmap sock resp
=
186 let len = r16 resp
4 in
189 then readstr sock
(len*4)
192 if len > 0 then (*???*)
193 let modmap = Array.make_matrix
8 n 0xffffff in
194 let rec loop l
= if l
= 8 then () else
196 let rec loop1 m = if m = n then () else
198 let code = r8
data p in
199 modmap.(l
).(m) <- code;
202 let ki = code - state.mink
in
205 let a = state.keymap
.(ki) in
206 let rec capsloop i
= if i
= Array.length
a || i
> 3 then () else
209 then state.capslmask
<- 2
217 let ki = code - state.mink
in
220 let a = state.keymap
.(ki) in
221 let rec lloop i
= if i
= Array.length
a || i
> 3 then () else
224 | 0xfe03 -> state.levl3mask
<- 1 lsl l
225 | 0xfe11 -> state.levl5mask
<- 1 lsl l
226 | 0xff7f -> state.numlmask
<- 1 lsl l
240 let sendwithrep sock
s f
=
241 Queue.push f
state.fifo
;
242 sendstr1 s 0 (String.length
s) sock
;
246 let b = Buffer.create
16 in
247 List.iter
(Buffer.add_string
b) ss
;
248 let bl = Buffer.length
b in
249 let pl = bl land 3 in
253 Buffer.add_substring
b pad 0 (4 - pl);
258 let padcat s1 s2
= padcatl [s1
; s2
];;
260 let internreq name onlyifexists
=
261 let s = makereq 16 8 8 in
262 let s = padcat s name
in
263 if onlyifexists
then w8
s 1 1;
264 w16
s 2 (String.length
s / 4);
265 w16
s 4 (String.length name
);
269 let sendintern sock
s onlyifexists f
=
270 let s = internreq s onlyifexists
in
271 sendwithrep sock
s f
;
274 let createwindowreq wid parent x y w h bw eventmask vid depth mid
=
275 let s = makereq 1 48 12 in
284 w16
s 22 0; (* inputoutput *)
285 w32
s 24 vid
; (* visual *)
286 w32
s 28 0x280a; (* eventmask*)
294 let createcolormapreq mid wid vid
=
295 let s = makereq 78 16 4 in
303 let getgeometryreq wid
=
304 let s = makereq 14 8 2 in
310 let s = makereq 8 8 2 in
315 let getkeymapreq first count
=
316 let s = makereq 101 8 2 in
322 let changepropreq wid prop typ format props
=
323 let s = makereq 18 24 0 in
324 let s = padcat s props
in
325 w16
s 2 (String.length
s / 4);
330 let ful = String.length props
/ (match format
with
334 | n -> error
"no idea what %d means" n)
340 let getpropreq delete wid prop typ
=
341 let s = makereq 20 24 6 in
342 if delete
then w8
s 1 1;
351 let openfontreq fid name
=
352 let s = makereq 45 12 0 in
353 let s = padcat s name
in
354 w16
s 2 (String.length
s / 4);
356 w16
s 8 (String.length name
);
360 let createglyphcursorreq fid cid cindex
=
361 let s = makereq 94 32 8 in
376 let changewindowattributesreq wid mask attrs
=
377 let s = makereq 2 12 0 in
378 let s = padcat s attrs
in
379 w16
s 2 (String.length
s / 4);
385 let configurewindowreq wid mask values
=
386 let s = makereq 2 12 0 in
387 let s = padcat s values
in
388 w16
s 2 (String.length
s / 4);
400 let clientmessage format seq wid typ
data =
401 let s = makereq 33 12 0 in
402 let s = padcat s data in
410 let sendeventreq propagate destwid mask
data =
411 let s = makereq 25 12 11 in
412 let s = padcat s data in
420 let getmodifiermappingreq () =
424 let getkeysym code mask
=
425 let pkpk = state.keymap
.(code-state.mink
).(0) in
426 if (pkpk >= 0xff80 && pkpk <= 0xffbd)
427 || (pkpk >= 0x11000000 && pkpk <= 0x1100ffff)
429 if mask
land state.numlmask
!= 0
431 let keysym = state.keymap
.(code-state.mink
).(1) in
432 if keysym = 0 then pkpk else keysym
437 if pkpk land 0xf000 = 0xf000
439 else (mask
land 1) lxor ((mask
land state.capslmask
) lsr 1)
442 let l3 = (mask
land state.levl3mask
) != 0 in
443 let l4 = (mask
land state.levl5mask
) != 0 in
445 if l3 then (if l4 then 8 else 4) else (if l4 then 6 else 0)
447 let keysym = state.keymap
.(code-state.mink
).(index) in
448 if index land 1 = 1 && keysym = 0
449 then state.keymap
.(code-state.mink
).(index - 1)
455 let resp = readstr sock
32 in
456 let opcode = r8
resp 0 in
457 match opcode land lnot
0x80 with
462 and resid
= r32
resp 4
465 error
"code=%d serial=%d resid=%#x min=%d maj=%d\n%S"
466 code serial resid min maj
resp;
468 | 1 -> (* response *)
469 let rep = Queue.pop
state.fifo
in
472 | 2 -> (* key press *)
473 if Array.length
state.keymap
> 0
475 let code = r8
resp 1 in
476 let mask = r16
resp 28 in
477 let keysym = getkeysym code mask in
478 vlog "keysym = %x %c mask %#x code %d"
479 keysym (Char.unsafe_chr
keysym) mask code;
480 state.t#key
keysym mask;
482 | 3 -> (* key release *)
483 if Array.length
state.keymap
> 0
485 let code = r8
resp 1 in
486 let mask = r16
resp 28 in
487 let keysym = getkeysym code mask in
488 vlog "release keysym = %x %c mask %#x code %#d"
489 keysym (Char.unsafe_chr
keysym) mask code
491 | 4 -> (* buttonpress *)
495 and m = r16
resp 28 in
496 state.t#mouse
n true x y
m;
499 | 5 -> (* buttonrelease *)
503 and m = r16
resp 28 in
504 state.t#mouse
n false x y
m;
505 vlog "release %d %d %d" n x y
508 let x = r16s
resp 24 in
509 let y = r16s
resp 26 in
510 let m = r16
resp 28 in
512 then state.t#pmotion
x y
513 else state.t#motion
x y;
514 vlog "move %dx%d => %d" x y m
518 and y = r16s
resp 26 in
520 vlog "enter %d %d" x y
525 | 18 -> vlog "unmap";
530 | 12 -> (* exposure *)
534 | 15 -> (* visibility *)
535 let vis = r8
resp 8 in
536 if vis != 2 then state.t#visible
;
537 vlog "visibility %d" vis;
539 | 34 -> (* mapping *)
541 let s = getkeymapreq state.mink
(state.maxk
-state.mink
-1) in
542 sendwithrep sock
s (updkmap sock
);
543 state.capslmask
<- 0;
544 state.levl3mask
<- 0;
545 state.levl5mask
<- 0;
547 let s = getmodifiermappingreq () in
548 sendwithrep sock
s (updmodmap sock
);
550 | 33 -> (* clientmessage *)
551 let atom = r32
resp 8 in
552 if atom = state.protoatom
554 let atom = r32
resp 12 in
555 if atom = state.deleatom
560 | 21 -> (* reparent *)
563 | 22 -> (* configure *)
567 and h
= r16
resp 22 in
568 vlog "configure cur [%d %d %d %d] conf [%d %d %d %d]"
569 state.x state.y state.w
state.h
573 if w
!= state.w
|| h
!= state.h
584 let atom = r32
resp 8 in
585 if atom = state.nwmsatom
587 let s = getpropreq false state.idbase
atom 4 in
588 sendwithrep sock
s (fun resp ->
589 let len = r32
resp 4 in
590 let nitems = r32
resp 16 in
595 let s = readstr sock
(len*4) in
596 let rec loop wsl i
= if i
= nitems then wsl else
597 let atom = r32
s (i
*4) in
599 if atom = state.maxhatom
602 if atom = state.maxvatom
605 if atom = state.fulsatom
607 state.fs
<- Fs
(state.x, state.y, state.w
, state.h
);
617 state.t#winstate
(List.sort compare
wsl)
621 dolog
"event %d %S" n resp
627 if hasdata sock
then loop ();
632 let sendstr s ?
(pos
=0) ?
(len=String.length
s) sock
=
633 sendstr1 s pos
len sock
;
634 if hasdata sock
then readresp sock
;
640 let s = "wwuuhhuu" in
643 let s = configurewindowreq state.idbase
0x000c s in
644 sendstr s state.sock
;
645 else state.fullscreen
state.idbase
652 let syncsendwithrep sock secstowait
s f
=
653 let completed = ref false in
654 sendwithrep sock
s (fun resp -> f
resp; completed := true);
655 let now = Unix.gettimeofday
in
656 let deadline = now () +. secstowait
in
657 let rec readtillcompletion () =
659 let timeout = deadline -. now () in
662 else Unix.select
[sock
] [] [] timeout
664 let r, _
, _
= tempfailureretry
sf deadline in
666 | [] -> error
"didn't get X response in %f seconds, aborting" secstowait
670 then readtillcompletion ()
672 readtillcompletion ();
676 let s = mapreq state.idbase
in
677 sendstr s state.sock
;
680 let syncsendintern sock secstowait
s onlyifexists f
=
681 let s = internreq s onlyifexists
in
682 syncsendwithrep sock secstowait
s f
;
685 let setup sock screennum w h
=
686 let s = readstr sock
2 in
687 let n = String.length
s in
689 then error
"failed to read X connection setup response n=%d" n;
692 let reasonlen = r8
s 1 in
693 let s = readstr sock
6 in
698 let data = readstr sock
len in
699 let reason = String.sub
data 0 reasonlen in
700 error
"X connection failed maj=%d min=%d reason=%S"
703 | '
\002'
-> failwith
"X connection setup failed: authentication required";
706 let s = readstr sock
38 in
710 and idbase
= r32
s 10
711 and idmask
= r32
s 14
713 and screens
= r8
s 26
714 and formats
= r8
s 27
716 and maxkk
= r8
s 33 in
717 let data = readstr sock
(4*add
-32) in
718 let vendor = String.sub
data 0 vlen
in
719 let pos = ((vlen
+3) land lnot
3) + formats
*8 in
721 if screennum
>= screens
722 then error
"invalid screen %d, max %d" screennum
(screens
-1);
726 let rec findscreen n pos = if n = screennum
then pos else
728 let ndepths = r8
s (pos+39) in
729 let rec skipdepths n pos = if n = ndepths then pos else
731 let nvisiuals = r16
s (pos+2) in
732 pos + nvisiuals*24 + 8
736 skipdepths n (pos+40)
742 let root = r32
data pos in
743 let rootw = r16
data (pos+20)
744 and rooth
= r16
data (pos+22) in
747 state.idbase
<- idbase
;
748 vlog "vendor = %S, maj=%d min=%d" vendor maj min
;
749 vlog "screens = %d formats = %d" screens formats
;
750 vlog "minkk = %d maxkk = %d" minkk maxkk
;
751 vlog "idbase = %#x idmask = %#x" idbase idmask
;
752 vlog "root=%#x %dx%d" root rootw rooth
;
753 vlog "wmm = %d, hmm = %d" (r16
data (pos+24)) (r16
data (pos+26));
754 vlog "visualid = %#x " (r32
data (pos+32));
756 let vid, depth
= glx1
() in
757 let wid = state.idbase
in
763 let s = createcolormapreq mid root vid in
767 + 0x00000001 (* KeyPress *)
768 (* + 0x00000002 *) (* KeyRelease *)
769 + 0x00000004 (* ButtonPress *)
770 + 0x00000008 (* ButtonRelease *)
771 + 0x00000010 (* EnterWindow *)
772 + 0x00000020 (* LeaveWindow *)
773 + 0x00000040 (* PointerMotion *)
774 (* + 0x00000080 *) (* PointerMotionHint *)
775 (* + 0x00000100 *) (* Button1Motion *)
776 (* + 0x00000200 *) (* Button2Motion *)
777 (* + 0x00000400 *) (* Button3Motion *)
778 (* + 0x00000800 *) (* Button4Motion *)
779 (* + 0x00001000 *) (* Button5Motion *)
780 + 0x00002000 (* ButtonMotion *)
781 (* + 0x00004000 *) (* KeymapState *)
782 + 0x00008000 (* Exposure *)
783 + 0x00010000 (* VisibilityChange *)
784 + 0x00020000 (* StructureNotify *)
785 (* + 0x00040000 *) (* ResizeRedirect *)
786 (* + 0x00080000 *) (* SubstructureNotify *)
787 (* + 0x00100000 *) (* SubstructureRedirect *)
788 (* + 0x00200000 *) (* FocusChange *)
789 + 0x00400000 (* PropertyChange *)
790 (* + 0x00800000 *) (* ColormapChange *)
791 (* + 0x01000000 *) (* OwnerGrabButton *)
793 let s = createwindowreq wid root 0 0 w h
0 mask vid depth
mid in
796 sendintern sock
"WM_PROTOCOLS" false (fun resp ->
797 state.protoatom
<- r32
resp 8;
798 sendintern sock
"WM_DELETE_WINDOW" false (fun resp ->
799 state.deleatom
<- r32
resp 8;
800 let s = s32 state.deleatom
in
801 let s = changepropreq wid state.protoatom
4 32 s in
806 sendintern sock
"WM_CLIENT_MACHINE" false (fun resp ->
807 let atom = r32
resp 8 in
810 try Unix.gethostname
()
812 dolog
"error getting host name: %s" (exntos exn
);
817 let s = changepropreq wid atom state.stringatom
8 hostname in
819 sendintern sock
"_NET_WM_PID" false (fun resp ->
820 let atom = r32
resp 8 in
821 let pid = Unix.getpid
() in
823 let s = changepropreq wid atom (* cardinal *)6 32 s in
828 state.actwin
<- (fun () ->
829 let s = String.create
4 in
830 let s = configurewindowreq wid 0x40 s in
831 sendstr s state.sock
;
832 let s = mapreq wid in
833 sendstr s state.sock
;
836 sendintern sock
"_NET_ACTIVE_WINDOW" true (fun resp ->
837 let atom = r32
resp 8 in
838 state.actwin
<- (fun () ->
839 let data = String.make
20 '
\000'
in
840 let cm = clientmessage 32 0 wid atom data in
841 let s = sendeventreq 0 root 0x180000 cm in
842 sendstr s state.sock
;
846 syncsendintern sock
2.0 "WM_CLASS" false (fun resp ->
847 let atom = r32
resp 8 in
848 let llpp = "llpp\000llpp\000" in
849 let s = changepropreq wid atom 31 8 llpp in
853 let s = getkeymapreq state.mink
(state.maxk
-state.mink
) in
854 sendwithrep sock
s (updkmap sock
);
856 let s = getmodifiermappingreq () in
857 sendwithrep sock
s (updmodmap sock
);
859 let s = openfontreq fid "cursor" in
862 Array.iteri
(fun i glyphindex
->
863 let s = createglyphcursorreq fid (fid+1+i
) glyphindex
in
865 ) [|34;48;50;58;128;152|];
867 sendintern sock
"UTF8_STRING" true (fun resp ->
868 let atom = r32
resp 8 in
870 then state.stringatom
<- atom;
874 let s = changepropreq wid 39 state.stringatom
8 s in
875 sendstr s state.sock
;
877 state.setwmname <- setwmname;
878 sendintern sock
"_NET_WM_NAME" true (fun resp ->
879 let atom = r32
resp 8 in
881 then state.setwmname <- (fun s ->
883 let s = changepropreq wid atom state.stringatom
8 s in
884 sendstr s state.sock
;
888 state.fullscreen
<- (fun wid ->
889 let s = "xxuuyyuuwwuuhhuu" in
896 let s = configurewindowreq wid 0x000f s in
897 sendstr s state.sock
;
898 state.fs
<- Fs
(state.x, state.y, state.w
, state.h
);
905 let s = configurewindowreq wid 0x000f s in
906 sendstr s state.sock
;
910 sendintern sock
"_NET_WM_STATE" true (fun resp ->
911 state.nwmsatom
<- r32
resp 8;
912 if state.nwmsatom
!= 0
914 sendintern sock
"_NET_WM_STATE_MAXIMIZED_VERT" true (fun resp ->
915 state.maxvatom
<- r32
resp 8;
917 sendintern sock
"_NET_WM_STATE_MAXIMIZED_HORZ" true (fun resp ->
918 state.maxhatom
<- r32
resp 8;
920 sendintern sock
"_NET_WM_STATE_FULLSCREEN" true (fun resp ->
921 state.fulsatom
<- r32
resp 8;
922 if state.fulsatom
!= 0
926 let data = String.make
20 '
\000'
in
929 | NoFs
-> Fs
(-1, -1, -1, -1), 1
933 w32
data 4 state.fulsatom
;
935 let cm = clientmessage 32 0 wid state.nwmsatom
data in
936 let s = sendeventreq 0 root 0x180000 cm in
943 let s = getgeometryreq wid in
944 syncsendwithrep sock
2.0 s (fun resp ->
947 and h
= r16
resp 18 in
953 error
"unknown conection setup response %d" (Char.code c
)
956 let getauth haddr dnum
=
958 if haddr = "localhost" || String.length
haddr = 0
960 try Unix.gethostname
()
962 dolog
"failed to resolve `%S': %s" haddr (exntos exn
);
967 try Sys.getenv
"XAUTHORITY"
969 try Filename.concat
(Sys.getenv
"HOME") ".Xauthority"
970 with Not_found
-> E.s
973 let input_string ic
len =
974 let s = String.create
len in
975 really_input ic
s 0 len;
979 let rb pos = Char.code (String.get
s pos) in
980 (rb 1) lor ((rb 0) lsl 8)
984 let s = input_string ic
2 in
988 let family = input_string ic
2 in
992 try Some
(int_of_string
nums)
995 "display number(%S) is not an integer (corrupt %S?): %s"
996 nums path (exntos exn
);
1002 vlog "family %S addr %S(%S) num %S(%d) name %S data %S"
1003 family addr haddr nums dnum
name data;
1005 | Some num
when addr = haddr && num
= dnum
->
1012 | End_of_file
-> E.s, E.s
1014 dolog
"exception while reading X authority data (%S): %s"
1023 if String.length
path = 0
1025 else Some
(open_in_bin
path)
1027 if Sys.file_exists
path
1029 dolog
"failed to open X authority file `%S' : %s"
1035 | Some ic
-> readauth ic
1038 let init t
w h osx
=
1040 try Sys.getenv
"DISPLAY"
1042 error
"could not get DISPLAY evironment variable: %s"
1047 then error
"invalid DISPLAY(%s) %S" w d
1049 let s = String.sub
d b (e
- b) in
1052 error
"invalid DISPLAY %S can not parse %s(%S): %s"
1056 if pos = String.length
d
1057 then error
"invalid DISPLAY %S no display number specified" d
1061 let rec pdispnum pos1
=
1062 if pos1
= String.length
d
1063 then getnum "display number" (pos+1) pos1
, 0
1067 let dispnum = getnum "display number" (pos+1) pos1
in
1068 let rec pscreennum pos2
=
1069 if pos2
= String.length
d
1070 then getnum "screen number" (pos1
+1) pos2
1073 | '
0'
.. '
9'
-> pscreennum (pos2
+1)
1075 error
"invalid DISPLAY %S, cannot parse screen number" d
1077 dispnum, pscreennum (pos1
+1)
1078 | '
0'
.. '
9'
-> pdispnum (pos1
+1)
1080 error
"invalid DISPLAY %S, cannot parse display number" d
1082 String.sub
d 0 pos, pdispnum (pos+1)
1086 let host, (dispnum, screennum
) = phost 0 in
1087 let aname, adata
= getauth host dispnum in
1090 if osx
|| String.length
host = 0 || host = "unix"
1094 then Unix.ADDR_UNIX
d
1095 else Unix.ADDR_UNIX
("/tmp/.X11-unix/X" ^ string_of_int
dispnum)
1097 let fd = Unix.socket
Unix.PF_UNIX
Unix.SOCK_STREAM
0 in
1101 try Unix.gethostbyname
host
1103 error
"cannot resolve %S: %s" host (exntos exn
)
1105 let addr = h.Unix.h_addr_list
.(0) in
1106 let port = 6000 + dispnum in
1107 let fd = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
1108 fd, (Unix.ADDR_INET
(addr, port))
1110 try Unix.connect
fd addr; fd
1112 error
"failed to connect to X: %s" (exntos exn
)
1115 let s = String.create
12 in
1116 let s = padcat s aname in
1117 let s = padcat s adata
in
1118 s.[0] <- ordermagic
;
1121 w16
s 6 (String.length
aname);
1122 w16
s 8 (String.length adata
);
1123 sendstr1 s 0 (String.length
s) fd;
1125 setup fd screennum
w h;
1127 fd, state.w, state.h;
1134 let setcursor cursor
=
1135 if cursor
!= state.curcurs
1139 | CURSOR_INHERIT
-> -1
1142 | CURSOR_CROSSHAIR
-> 0
1145 let s = s32 (if n = -1 then 0 else state.fid+1+n) in
1146 let s = changewindowattributesreq state.idbase
(*cursor*)0x4000 s in
1147 sendstr s state.sock
;
1148 state.curcurs
<- cursor
;
1152 state.fullscreen state.idbase
;
1155 let metamask = 0x40;;
1160 let withalt mask = mask land altmask != 0;;
1161 let withctrl mask = mask land ctrlmask != 0;;
1162 let withshift mask = mask land shiftmask != 0;;
1163 let withmeta mask = mask land metamask != 0;;
1164 let withnone mask = mask land (altmask + ctrlmask + shiftmask + metamask) = 0;;
1167 let t = Hashtbl.create
20
1168 and f
= Hashtbl.create
20 in
1170 List.iter
(fun s -> Hashtbl.add t s k) (n::nl
);
1174 let s = String.create
1 in
1176 add s [] (Char.code c
)
1179 let an = Char.code a and bn
= Char.code b in
1180 for i
= an to bn
do addc (Char.chr i
) done;
1185 String.iter
addc "`~!@#$%^&*()-_=+\\|[{]};:,./<>?";
1186 for i
= 0 to 29 do add ("f" ^ string_of_int
(i
+1)) [] (0xffbe + i
) done;
1187 add "space" [] 0x20;
1188 add "ret" ["return"; "enter"] 0xff0d;
1189 add "tab" [] 0xff09;
1190 add "left" [] 0xff51;
1191 add "right" [] 0xff53;
1192 add "home" [] 0xff50;
1193 add "end" [] 0xff57;
1194 add "ins" ["insert"] 0xff63;
1195 add "del" ["delete"] 0xffff;
1196 add "esc" ["escape"] 0xff1b;
1197 add "pgup" ["pageup"] 0xff55;
1198 add "pgdown" ["pagedown"] 0xff56;
1199 add "backspace" [] 0xff08;
1201 add "down" [] 0xff54;
1206 try Hashtbl.find xlatf
k
1207 with Not_found
-> Printf.sprintf
"%#x" k;
1211 try Hashtbl.find xlatt name
1213 if String.length
name = 1
1214 then Char.code name.[0]
1215 else int_of_string
name;