4 | Ulinkgoto
of (int * int)
6 and facename
= string;;
8 let dolog fmt
= Printf.kprintf prerr_endline fmt
;;
10 type params
= angle
* proportional
* texcount
* sliceheight
19 and proportional
= bool
20 and interpagespace
= int
27 external init
: Unix.file_descr
-> params
-> unit = "ml_init";;
28 external draw
: (int * int * int * int * bool) -> string -> unit = "ml_draw";;
29 external seltext
: string -> (int * int * int * int) -> int -> unit =
31 external copysel
: string -> unit = "ml_copysel";;
32 external getpdimrect
: int -> float array
= "ml_getpdimrect";;
33 external whatsunder
: string -> int -> int -> under
= "ml_whatsunder";;
34 external zoomforh
: int -> int -> int -> float = "ml_zoom_for_height";;
38 | Msel
of (mpos
* mpos
)
44 type textentry
= (char
* string * onhist
* onkey
* ondone
)
45 and onkey
= string -> int -> te
46 and ondone
= string -> unit
47 and histcancel
= unit -> unit
48 and onhist
= ((histcmd
-> string) * histcancel
) option
49 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
54 | TEswitch
of textentry
66 { store
= Array.create n v
73 let cbcap b
= Array.length b
.store
;;
78 b
.wc
<- (b
.wc
+ 1) mod cap;
80 b
.len
<- min
(b
.len
+ 1) cap;
83 let cbempty b
= b
.len
= 0;;
85 let cbgetg b circular dir
=
89 let rc = b
.rc + dir
in
101 else max
0 (min
rc (b
.len
-1))
107 let cbget b
= cbgetg b
false;;
108 let cbgetc b
= cbgetg b
true;;
111 let rc = b
.wc
- b
.len
in
112 let rc = if rc < 0 then cbcap b
+ rc else rc in
116 let cbdecr b
= b
.len
<- b
.len
- 1;;
131 { mutable scrollw
: int
132 ; mutable scrollh
: int
133 ; mutable icase
: bool
134 ; mutable preload
: bool
135 ; mutable pagebias
: int
136 ; mutable verbose
: bool
137 ; mutable scrollstep
: int
138 ; mutable maxhfit
: bool
139 ; mutable crophack
: bool
140 ; mutable autoscrollstep
: int
141 ; mutable showall
: bool
142 ; mutable hlinks
: bool
143 ; mutable underinfo
: bool
144 ; mutable interpagespace
: interpagespace
145 ; mutable zoom
: float
146 ; mutable presentation
: bool
147 ; mutable angle
: angle
150 ; mutable savebmarks
: bool
151 ; mutable proportional
: proportional
152 ; mutable memlimit
: int
153 ; mutable texcount
: texcount
154 ; mutable sliceheight
: sliceheight
155 ; mutable thumbw
: width
159 type outline
= string * int * int * float;;
161 | Oarray
of outline array
162 | Olist
of outline list
163 | Onarrow
of string * outline array
* outline array
166 type rect
= (float * float * float * float * float * float * float * float);;
168 type pagemapkey
= (pageno
* width
* angle
* proportional
* gen
);;
170 type anchor
= pageno
* top
;;
173 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
174 | Outline
of (bool * int * int * outline array
* string)
175 | Textentry
of (textentry
* mode
)
179 let isbirdseye = function Birdseye _
-> true | _
-> false;;
180 let istextentry = function Textentry _
-> true | _
-> false;;
183 { mutable csock
: Unix.file_descr
184 ; mutable ssock
: Unix.file_descr
188 ; mutable anchor
: anchor
190 ; mutable layout
: layout list
191 ; pagemap
: (pagemapkey
, (opaque
* pixmapsize
)) Hashtbl.t
192 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
193 ; mutable pagecount
: int
194 ; pagecache
: string circbuf
195 ; mutable rendering
: bool
196 ; mutable mstate
: mstate
197 ; mutable searchpattern
: string
198 ; mutable rects
: (pageno
* recttype
* rect
) list
199 ; mutable rects1
: (pageno
* recttype
* rect
) list
200 ; mutable text
: string
201 ; mutable fullscreen
: (width
* height
) option
202 ; mutable mode
: mode
203 ; mutable outlines
: outlines
204 ; mutable bookmarks
: outline list
205 ; mutable path
: string
206 ; mutable password
: string
207 ; mutable invalidated
: int
208 ; mutable colorscale
: float
209 ; mutable memused
: int
211 ; mutable throttle
: layout list
option
212 ; mutable ascrollstep
: int
216 { pat
: string circbuf
217 ; pag
: string circbuf
218 ; nav
: anchor circbuf
232 ; autoscrollstep
= 24
238 ; presentation
= false
243 ; proportional
= true
244 ; memlimit
= 32*1024*1024
251 let conf = { defconf with angle
= defconf.angle
};;
262 ; pagemap
= Hashtbl.create
10
263 ; pagecache
= cbnew 100 ""
274 ; outlines
= Olist
[]
280 { nav
= cbnew 100 (0, 0.0)
295 Printf.kprintf prerr_endline fmt
297 Printf.kprintf ignore fmt
301 let len = String.length s
in
303 let b = Buffer.create
n in
304 Buffer.add_char
b (Char.chr
((len lsr 24) land 0xff));
305 Buffer.add_char
b (Char.chr
((len lsr 16) land 0xff));
306 Buffer.add_char
b (Char.chr
((len lsr 8) land 0xff));
307 Buffer.add_char
b (Char.chr
((len lsr 0) land 0xff));
308 Buffer.add_string
b s
;
309 let s'
= Buffer.contents
b in
310 let n'
= Unix.write fd
s'
0 n in
311 if n'
!= n then failwith
"write failed";
316 let n = Unix.read fd
s 0 4 in
317 if n != 4 then failwith
"incomplete read(len)";
319 lor (Char.code
s.[0] lsl 24)
320 lor (Char.code
s.[1] lsl 16)
321 lor (Char.code
s.[2] lsl 8)
322 lor (Char.code
s.[3] lsl 0)
324 let s = String.create
len in
325 let n = Unix.read fd
s 0 len in
326 if n != len then failwith
"incomplete read(data)";
331 let b = Buffer.create
10 in
332 Buffer.add_string
b s;
333 let rec combine = function
336 Buffer.add_char
b ' '
;
339 | `
b b -> if b then "1" else "0"
341 | `i i
-> string_of_int i
342 | `f f
-> string_of_float f
343 | `I f
-> string_of_int
(truncate f
)
345 Buffer.add_string
b s;
352 let cmd = Buffer.contents
(makecmd s l
) in
353 writecmd state.csock
cmd;
359 let d = conf.winh
- h
in
366 let rec f pn ph pi fh l
=
368 | (n, _
, h
, _
) :: rest
->
369 let ips = calcips h
in
374 if isbirdseye state.mode
&& pn
= 0
379 let fh = fh + ((n - pn
) * (ph
+ pi
)) in
384 if conf.presentation
|| (isbirdseye state.mode
&& pn
= 0)
388 let fh = fh + ((state.pagecount
- pn
) * (ph
+ pi
)) + inc in
391 let fh = f 0 0 0 0 state.pdims
in
395 let getpageyh pageno
=
396 let rec f pn ph pi y l
=
398 | (n, _
, h
, _
) :: rest
->
399 let ips = calcips h
in
402 let h = if n = pageno
then h else ph
in
403 if conf.presentation
&& n = pageno
405 y
+ (pageno
- pn
) * (ph
+ pi
) + pi
, h
407 y
+ (pageno
- pn
) * (ph
+ pi
), h
409 let y = y + (if conf.presentation
then pi
else 0) in
410 let y = y + (n - pn
) * (ph
+ pi
) in
414 y + (pageno
- pn
) * (ph
+ pi
), ph
416 f 0 0 0 0 state.pdims
419 let getpagey pageno
= fst
(getpageyh pageno
);;
422 let rec f ~pageno ~pdimno ~prev ~py ~dy ~pdims ~cacheleft ~accu
=
423 let ((w
, h, ips, x
) as curr
), rest
, pdimno
, yinc
=
425 | (pageno'
, w
, h, x
) :: rest
when pageno'
= pageno
->
426 let ips = calcips h in
428 if conf.presentation
|| (isbirdseye state.mode
&& pageno
= 0)
432 (w
, h, ips, x
), rest
, pdimno
+ 1, yinc
434 prev
, pdims
, pdimno
, 0
436 let dy = dy + yinc in
437 let py = py + yinc in
438 if pageno
= state.pagecount
|| cacheleft
= 0 || dy >= sh
443 if py + h <= vy - yinc
445 let py = py + h + ips in
446 let dy = max
0 (py - y) in
456 let pagey = vy - py in
457 let pagevh = h - pagey in
458 let pagevh = min
(sh
- dy) pagevh in
459 let off = if yinc > 0 then py - vy else 0 in
460 let py = py + h + ips in
466 ; pagedispy
= dy + off
467 ; pagey = pagey + off
468 ; pagevh = pagevh - off
472 let accu = e :: accu in
479 ~cacheleft
:(cacheleft
-1)
482 if state.invalidated
= 0
492 ~cacheleft
:(cbcap state.pagecache
)
502 let y = state.y + incr
in
504 let y = min
y (state.maxy
- (if conf.maxhfit
then conf.winh
else 0)) in
508 let getopaque pageno
=
509 try Some
(Hashtbl.find
state.pagemap
510 (pageno
, state.w
, conf.angle
, conf.proportional
, state.gen
))
511 with Not_found
-> None
514 let cache pageno opaque
=
515 Hashtbl.replace
state.pagemap
516 (pageno
, state.w
, conf.angle
, conf.proportional
, state.gen
) opaque
519 let validopaque opaque
= String.length opaque
> 0;;
522 match getopaque l
.pageno
with
523 | None
when not
state.rendering
->
524 state.rendering
<- true;
525 cache l
.pageno
("", -1);
526 wcmd "render" [`i
(l
.pageno
+ 1)
533 let loadlayout layout =
534 let rec f all
= function
536 begin match getopaque l
.pageno
with
537 | None
-> render l
; f false ls
538 | Some
(opaque
, _
) -> f (all
&& validopaque opaque
) ls
542 f (layout <> []) layout;
545 let findpageforopaque opaque
=
547 (fun k
(v
, s) a
-> if v
= opaque
then Some
(k
, s) else a
)
551 let pagevisible layout n = List.exists
(fun l
-> l
.pageno
= n) layout;;
557 let memleft = conf.memlimit
- state.memused
in
560 let opaque = cbpeek state.pagecache
in
561 match findpageforopaque opaque with
562 | Some
((n, _
, _
, _
, _
), size
) ->
563 memleft + size
>= 0 && not
(pagevisible state.layout n)
570 let presentation = conf.presentation in
571 let interpagespace = conf.interpagespace in
572 let maxy = state.maxy in
573 conf.presentation <- false;
574 conf.interpagespace <- 0;
575 state.maxy <- calcheight ();
577 match state.layout with
579 | l
:: _
-> getpagey l
.pageno
+ l
.pagey
581 let y = if y < conf.winh
then 0 else y - conf.winh
in
582 let pages = layout y (conf.winh
*3) in
583 List.iter
render pages;
584 conf.presentation <- presentation;
585 conf.interpagespace <- interpagespace;
591 let y = min
state.maxy y in
592 let pages = layout y conf.winh
in
593 let ready = loadlayout pages in
599 state.layout <- pages;
600 state.throttle
<- None
;
601 Glut.postRedisplay
();
604 state.throttle
<- Some
pages;
609 state.layout <- pages;
610 state.throttle
<- None
;
611 Glut.postRedisplay
();
613 begin match state.mode
with
614 | Birdseye
(conf, leftx
, pageno
, hooverpageno
, anchor
) ->
615 if not
(pagevisible pages pageno
)
617 match state.layout with
620 state.mode
<- Birdseye
(conf, leftx
, l
.pageno
, hooverpageno
, anchor
)
627 let gotoy_and_clear_text y =
629 if not
conf.verbose
then state.text
<- "";
632 let emptyanchor = (0, 0.0);;
635 match state.layout with
637 | l
:: _
-> (l
.pageno
, float l
.pagey /. float l
.pageh
)
640 let getanchory (n, top
) =
641 let y, h = getpageyh n in
642 y + (truncate
(top
*. float h));
645 let gotoanchor anchor
=
646 gotoy (getanchory anchor
);
650 cbput state.hists
.nav
(getanchor ());
654 let anchor = cbgetc state.hists
.nav ~
-1 in
659 let y, h = getpageyh n in
660 gotoy_and_clear_text (y + (truncate
(top
*. float h)));
663 let gotopage1 n top
=
664 let y = getpagey n in
665 gotoy_and_clear_text (y + top
);
673 state.invalidated
<- state.invalidated
+ 1;
677 let c = c *. state.colorscale
in
682 state.maxy <- calcheight ();
683 match state.mode
with
684 | Birdseye
(_
, _
, pageno
, _
, _
) ->
685 let y, h = getpageyh pageno
in
686 let top = (conf.winh
- h) / 2 in
687 gotoy (max
0 (y - top))
688 | _
-> gotoanchor state.anchor
692 GlMat.mode `projection
;
693 GlMat.load_identity
();
694 GlMat.rotate ~x
:1.0 ~angle
:180.0 ();
695 GlMat.translate ~x
:~
-.1.0 ~
y:~
-.1.0 ();
696 GlMat.scale3
(2.0 /. float state.w
, 2.0 /. float conf.winh
, 1.0);
699 GlMat.translate ~x
:(float state.x
) ();
704 GlMat.mode `projection
;
705 GlMat.load_identity
();
706 GlMat.rotate ~x
:1.0 ~angle
:180.0 ();
707 GlMat.translate ~x
:~
-.1.0 ~
y:~
-.1.0 ();
708 GlMat.scale3
(2.0 /. float conf.winw
, 2.0 /. float conf.winh
, 1.0);
712 if state.invalidated
= 0
713 then state.anchor <- getanchor ();
716 let w = truncate
(float w *. conf.zoom
) - conf.scrollw
in
720 GlMat.mode `modelview
;
721 GlMat.load_identity
();
722 GlClear.color
(scalecolor 1.0);
723 GlClear.clear
[`color
];
726 wcmd "geometry" [`i
w; `i
h];
730 GlDraw.color
(0.0, 0.0, 0.0);
732 (0.0, float (conf.winh
- 18))
733 (float (conf.winw
- conf.scrollw
- 1), float conf.winh
)
735 let font = Glut.BITMAP_8_BY_13
in
736 GlDraw.color
(1.0, 1.0, 1.0);
737 GlPix.raster_pos ~x
:0.0 ~
y:(float (conf.winh
- 5)) ();
738 Glut.bitmapCharacter ~
font ~
c:(Char.code
c);
739 String.iter
(fun c -> Glut.bitmapCharacter ~
font ~
c:(Char.code
c)) s;
743 let len = String.length
state.text
in
744 match state.mode
with
745 | Textentry
((c, text
, _
, _
, _
), _
) ->
749 text ^
" [" ^
state.text ^
"]"
756 if len > 0 then showtext ' '
state.text
760 state.text
<- Printf.sprintf
"%c%s" c s;
761 Glut.postRedisplay
();
770 state.rects
<- state.rects1
;
771 Glut.postRedisplay
()
774 let n = Scanf.sscanf
cmd "C %u" (fun n -> n) in
775 state.pagecount
<- n;
776 state.invalidated
<- state.invalidated
- 1;
777 if state.invalidated
= 0
781 let s = Scanf.sscanf
cmd "t %n"
782 (fun n -> String.sub
cmd n (String.length
cmd - n))
784 Glut.setWindowTitle
s
787 let s = Scanf.sscanf
cmd "T %n"
788 (fun n -> String.sub
cmd n (String.length
cmd - n))
790 if istextentry state.mode
797 Glut.postRedisplay
();
803 let s = Scanf.sscanf
cmd "V %n"
804 (fun n -> String.sub
cmd n (String.length
cmd - n))
810 let pageno, c, x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
=
811 Scanf.sscanf
cmd "F %u %d %f %f %f %f %f %f %f %f"
812 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
813 (p
, c, x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
))
815 let y = (getpagey pageno) + truncate y0
in
818 state.rects1
<- [pageno, c, (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
)]
821 let pageno, c, x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
=
822 Scanf.sscanf
cmd "R %u %d %f %f %f %f %f %f %f %f"
823 (fun p
c x0 y0 x1 y1 x2 y2 x3 y3
->
824 (p
, c, x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
))
827 (pageno, c, (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) :: state.rects1
830 let n, w, h, r
, l
, s, p
=
831 Scanf.sscanf
cmd "r %u %u %u %u %d %u %s"
832 (fun n w h r l
s p
->
833 (n-1, w, h, r
, l
!= 0, s, p
))
836 Hashtbl.replace
state.pagemap
(n, w, r
, l
, state.gen
) (p
, s);
837 state.memused
<- state.memused
+ s;
840 match state.throttle
with
841 | None
-> state.layout
842 | Some
layout -> layout
846 if (state.memused
<= conf.memlimit
) || cbempty state.pagecache
849 let evictedopaque = cbpeek state.pagecache
in
850 match findpageforopaque evictedopaque with
851 | None
-> failwith
"bug in gc"
852 | Some
((evictedn
, _
, _
, _
, gen
) as k
, evictedsize
) ->
853 if state.gen
!= gen
|| not
(pagevisible layout evictedn
)
855 wcmd "free" [`
s evictedopaque];
856 state.memused
<- state.memused
- evictedsize
;
857 Hashtbl.remove
state.pagemap k
;
858 cbdecr state.pagecache
;
865 cbput state.pagecache p
;
866 state.rendering
<- false;
868 begin match state.throttle
with
870 if pagevisible state.layout n
873 let allvisible = loadlayout state.layout in
874 if allvisible then preload ();
881 let y = getpagey l
.pageno + l
.pagey in
886 let (n, w, h, x
) as pdim
=
887 Scanf.sscanf
cmd "l %u %u %u %u" (fun n w h x
-> n, w, h, x
)
889 state.pdims
<- pdim
:: state.pdims
892 let (l
, n, t
, h, pos
) =
893 Scanf.sscanf
cmd "o %u %u %d %u %n" (fun l
n t
h pos
-> l
, n, t
, h, pos
)
895 let s = String.sub
cmd pos
(String.length
cmd - pos
) in
897 let l = String.length
s in
898 let b = Buffer.create
(String.length
s) in
905 | '
\xa0'
when pc2 -> Buffer.add_char
b ' '
; false
908 let c = if Char.code
c land 0x80 = 0 then c else '?'
in
917 let outline = (s, l, n, float t
/. float h) in
919 match state.outlines with
920 | Olist
outlines -> Olist
(outline :: outlines)
921 | Oarray _
-> Olist
[outline]
922 | Onarrow _
-> Olist
[outline]
924 state.outlines <- outlines
927 dolog "unknown cmd `%S'" cmd
930 let now = Unix.gettimeofday
;;
934 let r, _
, _
= Unix.select
[state.csock
] [] [] delay
in
937 if state.ascrollstep
> 0
939 let y = state.y + state.ascrollstep
in
940 let y = if y >= state.maxy then 0 else y in
946 let cmd = readcmd state.csock
in
955 let action = function
956 | HCprev
-> cbget cb ~
-1
957 | HCnext
-> cbget cb
1
958 | HCfirst
-> cbget cb ~
-(cb
.rc)
959 | HClast
-> cbget cb
(cb
.len - 1 - cb
.rc)
960 and cancel
() = cb
.rc <- rc
964 let search pattern forward
=
965 if String.length pattern
> 0
968 match state.layout with
971 l.pageno, (l.pagey + if forward
then 0 else 0*l.pagevh)
974 let b = makecmd "search"
975 [`
b conf.icase
; `i
pn; `i
py; `i
(if forward
then 1 else 0)]
977 Buffer.add_char
b '
,'
;
978 Buffer.add_string
b pattern
;
979 Buffer.add_char
b '
\000'
;
982 writecmd state.csock
cmd;
985 let intentry text key
=
986 let c = Char.unsafe_chr key
in
989 let s = "x" in s.[0] <- c;
990 let text = text ^
s in
994 state.text <- Printf.sprintf
"invalid char (%d, `%c')" key
c;
999 let b = Buffer.create
(String.length
s + 1) in
1000 Buffer.add_string
b s;
1001 Buffer.add_char
b c;
1005 let textentry text key
=
1006 let c = Char.unsafe_chr key
in
1008 | _
when key
>= 32 && key
< 127 ->
1009 let text = addchar text c in
1013 dolog "unhandled key %d char `%c'" key
(Char.unsafe_chr key
);
1017 let reinit angle proportional
=
1018 conf.angle
<- angle
;
1019 conf.proportional
<- proportional
;
1021 wcmd "reinit" [`i angle
; `
b proportional
];
1024 let optentry text key
=
1025 let btos b = if b then "on" else "off" in
1026 let c = Char.unsafe_chr key
in
1030 try conf.scrollstep
<- int_of_string
s with exc
->
1031 state.text <- Printf.sprintf
"bad integer `%s': %s"
1032 s (Printexc.to_string exc
)
1034 TEswitch
('#'
, "", None
, intentry, ondone)
1039 conf.autoscrollstep
<- int_of_string
s;
1040 if state.ascrollstep
> 0
1041 then state.ascrollstep
<- conf.autoscrollstep
;
1043 state.text <- Printf.sprintf
"bad integer `%s': %s"
1044 s (Printexc.to_string exc
)
1046 TEswitch
('
*'
, "", None
, intentry, ondone)
1051 let zoom = float (int_of_string
s) /. 100.0 in
1052 let zoom = max
0.01 (min
2.2 zoom) in
1056 reshape conf.winh
conf.winw
;
1057 state.text <- Printf.sprintf
"zoom is now %f" (zoom *. 100.0);
1059 state.text <- Printf.sprintf
"bad integer `%s': %s"
1060 s (Printexc.to_string exc
)
1062 TEswitch
('
@'
, "", None
, intentry, ondone)
1067 Some
(int_of_string
s)
1069 state.text <- Printf.sprintf
"bad integer `%s': %s"
1070 s (Printexc.to_string exc
);
1073 | Some angle
-> reinit angle
conf.proportional
1076 TEswitch
('^'
, "", None
, intentry, ondone)
1079 conf.icase
<- not
conf.icase
;
1080 TEdone
("case insensitive search " ^
(btos conf.icase
))
1083 conf.preload <- not
conf.preload;
1085 TEdone
("preload " ^
(btos conf.preload))
1088 conf.verbose
<- not
conf.verbose
;
1089 TEdone
("verbose " ^
(btos conf.verbose
))
1092 conf.maxhfit
<- not
conf.maxhfit
;
1093 state.maxy <- state.maxy + (if conf.maxhfit
then -conf.winh
else conf.winh
);
1094 TEdone
("maxhfit " ^
(btos conf.maxhfit
))
1097 conf.crophack
<- not
conf.crophack
;
1098 TEdone
("crophack " ^
btos conf.crophack
)
1101 conf.showall
<- not
conf.showall
;
1102 TEdone
("showall " ^
btos conf.showall
)
1105 conf.underinfo
<- not
conf.underinfo
;
1106 TEdone
("underinfo " ^
btos conf.underinfo
)
1109 conf.savebmarks
<- not
conf.savebmarks
;
1110 TEdone
("persistent bookmarks " ^
btos conf.savebmarks
)
1116 match state.layout with
1121 conf.interpagespace <- int_of_string
s;
1122 state.maxy <- calcheight ();
1123 let y = getpagey pageno in
1126 state.text <- Printf.sprintf
"bad integer `%s': %s"
1127 s (Printexc.to_string exc
)
1129 TEswitch
('
%'
, "", None
, intentry, ondone)
1132 reinit conf.angle
(not
conf.proportional
);
1133 TEdone
("proprortional display " ^
btos conf.proportional
)
1136 state.text <- Printf.sprintf
"bad option %d `%c'" key
c;
1140 let maxoutlinerows () = (conf.winh
- 31) / 16;;
1142 let enterselector allowdel
outlines errmsg msg
=
1143 if Array.length
outlines = 0
1145 showtext ' ' errmsg
;
1149 Glut.setCursor
Glut.CURSOR_INHERIT
;
1151 match state.layout with
1153 | {pageno=pageno} :: rest
-> pageno
1157 if n = Array.length
outlines
1160 let (_
, _
, outlinepageno
, _
) = outlines.(n) in
1161 if outlinepageno
>= pageno then n else loop (n+1)
1165 state.mode
<- Outline
1166 (allowdel
, active, max
0 (active - maxoutlinerows () / 2), outlines, "");
1167 Glut.postRedisplay
();
1171 let enteroutlinemode () =
1173 match state.outlines with
1176 let a = Array.of_list
(List.rev
l) in
1177 state.outlines <- Oarray
a;
1179 | Onarrow
(pat
, a, b) ->
1180 a, "Outline was narrowed to `" ^ pat ^
"' (Ctrl-u to restore)"
1182 enterselector false outlines "Document has no outline" msg
;
1185 let enterbookmarkmode () =
1186 let bookmarks = Array.of_list
state.bookmarks in
1187 enterselector true bookmarks "Document has no bookmarks (yet)" "";
1190 let quickbookmark ?title
() =
1191 match state.layout with
1197 let sec = Unix.gettimeofday
() in
1198 let tm = Unix.localtime
sec in
1199 Printf.sprintf
"Quick (page %d) (bookmarked at %d/%d/%d %d:%d)"
1203 (tm.Unix.tm_year
+ 1900)
1206 | Some
title -> title
1209 (title, 0, l.pageno, float l.pagey /. float l.pageh
) :: state.bookmarks
1213 state.fullscreen
<- None
;
1214 Glut.reshapeWindow
w h;
1217 let writeopen path password
=
1218 writecmd state.csock
("open " ^ path ^
"\000" ^
state.password ^
"\000");
1221 let opendoc path password
=
1224 state.password
<- password
;
1225 state.gen
<- state.gen
+ 1;
1227 writeopen path password
;
1228 Glut.setWindowTitle
("llpp " ^
Filename.basename path
);
1229 wcmd "geometry" [`i
state.w; `i
conf.winh
];
1233 let zoom = float conf.thumbw
/. float conf.winw
in
1234 let birdseyepageno =
1235 let rec fold = function
1237 | l :: _
when l.pagey = 0 -> l.pageno
1238 | _
:: rest
-> fold rest
1242 state.mode
<- Birdseye
(
1243 { conf with zoom = conf.zoom }, state.x
, birdseyepageno, -1, getanchor ()
1246 conf.presentation <- false;
1247 conf.interpagespace <- 10;
1248 conf.hlinks
<- false;
1250 state.mstate
<- Mnone
;
1251 conf.showall
<- false;
1252 Glut.setCursor
Glut.CURSOR_INHERIT
;
1255 state.text <- Printf.sprintf
"birds eye mode on (zoom %3.1f%%)"
1260 reshape conf.winw
conf.winh
;
1263 let birdseyeoff (c, leftx
, pageno, _
, anchor) goback
=
1265 conf.zoom <- c.zoom;
1266 conf.presentation <- c.presentation;
1267 conf.interpagespace <- c.interpagespace;
1268 conf.showall
<- c.showall
;
1269 conf.hlinks
<- c.hlinks
;
1273 state.text <- Printf.sprintf
"birds eye mode off (zoom %3.1f%%)"
1276 reshape conf.winw
conf.winh
;
1277 state.anchor <- if goback
then anchor else (pageno, 0.0);
1280 let togglebirdseye () =
1281 match state.mode
with
1282 | Birdseye vals
-> birdseyeoff vals
true
1283 | View
| Outline _
-> birdseyeon ()
1287 let viewkeyboard ~key ~x ~
y =
1289 state.mode
<- Textentry
(te
, state.mode
);
1292 Glut.postRedisplay
()
1294 let c = Char.chr key
in
1300 let y = getnav () in
1301 gotoy_and_clear_text y
1309 Glut.postRedisplay
()
1312 let ondone isforw
s =
1313 cbput state.hists
.pat
s;
1314 state.searchpattern
<- s;
1317 enttext (c, "", Some
(onhist state.hists
.pat
),
1318 textentry, ondone (c ='
/'
))
1320 | '
+'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
1321 let incr = if conf.zoom +. 0.01 > 0.1 then 0.1 else 0.01 in
1322 conf.zoom <- min
2.2 (conf.zoom +. incr);
1323 state.text <- Printf.sprintf
"zoom is %3.1f%%" (100.0*.conf.zoom);
1324 reshape conf.winw
conf.winh
1329 try int_of_string
s with exc
->
1330 state.text <- Printf.sprintf
"bad integer `%s': %s"
1331 s (Printexc.to_string exc
);
1337 state.text <- "page bias is now " ^ string_of_int
n;
1340 enttext ('
+'
, "", None
, intentry, ondone)
1342 | '
-'
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
1343 let decr = if conf.zoom -. 0.1 < 0.1 then 0.01 else 0.1 in
1344 conf.zoom <- max
0.01 (conf.zoom -. decr);
1345 if conf.zoom <= 1.0 then state.x
<- 0;
1346 state.text <- Printf.sprintf
"zoom is %3.1f%%" (100.0*.conf.zoom);
1347 reshape conf.winw
conf.winh
;
1353 enttext ('
-'
, "", None
, optentry, ondone)
1355 | '
0'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
1358 state.text <- "zoom is 100%";
1359 reshape conf.winw
conf.winh
1361 | '
1'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
1362 let zoom = zoomforh
conf.winw
conf.winh
conf.scrollw
in
1367 state.text <- Printf.sprintf
"zoom is %3.1f%%" (100.0*.conf.zoom);
1368 reshape conf.winw
conf.winh
;
1371 | '
9'
when (Glut.getModifiers
() land Glut.active_ctrl
!= 0) ->
1377 try int_of_string
s with exc
->
1378 state.text <- Printf.sprintf
"bad integer `%s': %s"
1379 s (Printexc.to_string exc
);
1385 cbput state.hists
.pag
(string_of_int
n);
1386 gotoy_and_clear_text (getpagey (n + conf.pagebias
- 1))
1389 let pageentry text key
=
1390 match Char.unsafe_chr key
with
1391 | 'g'
-> TEdone
text
1392 | _
-> intentry text key
1394 let text = "x" in text.[0] <- c;
1395 enttext ('
:'
, text, Some
(onhist state.hists
.pag
), pageentry, ondone)
1398 conf.scrollw
<- if conf.scrollw
> 0 then 0 else defconf.scrollw
;
1399 reshape conf.winw
conf.winh
;
1402 conf.hlinks
<- not
conf.hlinks
;
1403 state.text <- "highlightlinks " ^
if conf.hlinks
then "on" else "off";
1404 Glut.postRedisplay
()
1407 if state.ascrollstep
= 0
1408 then state.ascrollstep
<- conf.autoscrollstep
1410 conf.autoscrollstep
<- state.ascrollstep
;
1411 state.ascrollstep
<- 0;
1415 conf.presentation <- not
conf.presentation;
1416 showtext ' '
("presentation mode " ^
1417 if conf.presentation then "on" else "off");
1421 begin match state.fullscreen
with
1423 state.fullscreen
<- Some
(conf.winw
, conf.winh
);
1426 state.fullscreen
<- None
;
1431 gotoy_and_clear_text 0
1434 search state.searchpattern
true
1437 search state.searchpattern
false
1440 begin match state.layout with
1443 gotoy_and_clear_text (getpagey l.pageno)
1447 begin match List.rev
state.layout with
1450 let pageno = min
(l.pageno+1) (state.pagecount
-1) in
1451 gotoy_and_clear_text (getpagey pageno)
1455 begin match state.layout with
1458 let pageno = max
0 (l.pageno-1) in
1459 gotoy_and_clear_text (getpagey pageno)
1464 if fn
= -1 then l.pageno, l.pageno else fn
, l.pageno
1466 let fn, ln
= List.fold_left
f (-1, -1) state.layout in
1468 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
1472 else (100. *. (float state.y /. float maxy)) in
1475 Printf.sprintf
"Page %d of %d %.2f%%"
1476 (fn+1) state.pagecount
percent
1479 "Pages %d-%d of %d %.2f%%"
1480 (fn+1) (ln
+1) state.pagecount
percent
1485 begin match state.layout with
1488 doreshape (l.pagew
+ conf.scrollw
) l.pageh
;
1489 Glut.postRedisplay
();
1493 enterbookmarkmode ()
1497 match state.layout with
1500 (s, 0, l.pageno, float l.pagey /. float l.pageh
)
1504 enttext ('~'
, "", None
, textentry, ondone)
1508 showtext ' '
"Quick bookmark added";
1511 begin match state.layout with
1513 let rect = getpdimrect
l.pagedimno
in
1517 (truncate
(1.8 *. (rect.(1) -. rect.(0))),
1518 truncate
(1.2 *. (rect.(3) -. rect.(0))))
1520 (truncate
(rect.(1) -. rect.(0)),
1521 truncate
(rect.(3) -. rect.(0)))
1525 doreshape (w + conf.scrollw
) (h + conf.interpagespace)
1527 Glut.postRedisplay
();
1533 reinit (conf.angle
+ (if c = '
>'
then 30 else -30)) conf.proportional
1538 (min
(state.colorscale
+. (if c = '
]'
then 0.1 else -0.1)) 1.0);
1539 Glut.postRedisplay
()
1541 | 'k'
-> gotoy (clamp (-conf.scrollstep
))
1542 | 'j'
-> gotoy (clamp conf.scrollstep
)
1544 | '
r'
-> opendoc state.path
state.password
1547 vlog "huh? %d %c" key
(Char.chr key
);
1550 let textentrykeyboard ~key ~x ~
y ((c, text, opthist
, onkey
, ondone), mode
) =
1552 state.mode
<- Textentry
(te
, mode
);
1555 Glut.postRedisplay
()
1557 match Char.unsafe_chr key
with
1559 let len = String.length
text in
1563 Glut.postRedisplay
();
1566 let s = String.sub
text 0 (len - 1) in
1567 enttext (c, s, opthist
, onkey
, ondone)
1573 Glut.postRedisplay
()
1576 begin match opthist
with
1578 | Some
(_
, onhistcancel
) -> onhistcancel
()
1581 Glut.postRedisplay
()
1584 begin match onkey
text key
with
1588 Glut.postRedisplay
()
1591 enttext (c, text, opthist
, onkey
, ondone);
1595 Glut.postRedisplay
()
1598 state.mode
<- Textentry
(te
, mode
);
1599 Glut.postRedisplay
()
1603 let birdseyekeyboard ~key ~x ~
y ((_
, _
, pageno, _
, anchor) as beye
) =
1606 birdseyeoff beye
true
1609 let y, h = getpageyh pageno in
1610 let top = (conf.winh
- h) / 2 in
1611 gotoy (max
0 (y - top))
1614 birdseyeoff beye
false
1617 viewkeyboard ~key ~x ~
y
1620 let outlinekeyboard ~key ~x ~
y (allowdel
, active, first
, outlines, qsearch
) =
1621 let narrow outlines pattern
=
1622 let reopt = try Some
(Str.regexp_case_fold pattern
) with _
-> None
in
1626 let rec fold accu n =
1630 let (s, _
, _
, _
) as o
= outlines.(n) in
1632 if (try ignore
(Str.search_forward re
s 0); true
1633 with Not_found
-> false)
1639 let matched = fold [] (Array.length
outlines - 1) in
1640 if matched = [] then None
else Some
(Array.of_list
matched)
1642 let search active pattern
incr =
1645 if n = Array.length
outlines || n = -1
1648 let (s, _
, _
, _
) = outlines.(n) in
1650 (try ignore
(Str.search_forward re
s 0); true
1651 with Not_found
-> false)
1653 else loop (n + incr)
1658 let re = Str.regexp_case_fold pattern
in
1664 let firstof active = max
0 (active - maxoutlinerows () / 2) in
1667 if String.length qsearch
= 0
1671 Glut.postRedisplay
();
1675 state.mode
<- Outline
(allowdel
, active, first
, outlines, "");
1676 Glut.postRedisplay
();
1680 let incr = if key
= 18 then -1 else 1 in
1682 match search (active + incr) qsearch
incr with
1684 state.text <- qsearch ^
" [not found]";
1687 state.text <- qsearch
;
1688 active, firstof active
1690 state.mode
<- Outline
(allowdel
, active, first
, outlines, qsearch
);
1691 Glut.postRedisplay
();
1694 let len = String.length qsearch
in
1701 state.mode
<- Outline
(allowdel
, active, first
, outlines, "");
1704 let qsearch = String.sub
qsearch 0 (len - 1) in
1706 match search active qsearch ~
-1 with
1708 state.text <- qsearch ^
" [not found]";
1711 state.text <- qsearch;
1712 active, firstof active
1714 state.mode
<- Outline
(allowdel
, active, first
, outlines, qsearch);
1716 Glut.postRedisplay
()
1719 if active < Array.length
outlines
1721 let (_
, _
, n, t
) = outlines.(active) in
1726 if allowdel
then state.bookmarks <- Array.to_list
outlines;
1728 Glut.postRedisplay
();
1730 | _
when key
>= 32 && key
< 127 ->
1731 let pattern = addchar qsearch (Char.chr key
) in
1733 match search active pattern 1 with
1735 state.text <- pattern ^
" [not found]";
1738 state.text <- pattern;
1739 active, firstof active
1741 state.mode
<- Outline
(allowdel
, active, first
, outlines, pattern);
1742 Glut.postRedisplay
()
1744 | 14 when not allowdel
-> (* ctrl-n *)
1745 if String.length
qsearch > 0
1747 let optoutlines = narrow outlines qsearch in
1748 begin match optoutlines with
1749 | None
-> state.text <- "can't narrow"
1751 state.mode
<- Outline
(allowdel
, 0, 0, outlines, qsearch);
1752 match state.outlines with
1755 state.outlines <- Onarrow
(qsearch, outlines, a)
1756 | Onarrow
(pat
, a, b) ->
1757 state.outlines <- Onarrow
(qsearch, outlines, b)
1760 Glut.postRedisplay
()
1762 | 21 when not allowdel
-> (* ctrl-u *)
1764 match state.outlines with
1767 let a = Array.of_list
(List.rev
l) in
1768 state.outlines <- Oarray
a;
1770 | Onarrow
(pat
, a, b) ->
1771 state.outlines <- Oarray
b;
1775 state.mode
<- Outline
(allowdel
, 0, 0, outline, qsearch);
1776 Glut.postRedisplay
()
1779 state.mode
<- Outline
1780 (allowdel
, active, firstof active, outlines, qsearch);
1781 Glut.postRedisplay
()
1783 | 127 when allowdel
->
1784 let len = Array.length
outlines - 1 in
1788 state.bookmarks <- [];
1791 let bookmarks = Array.init
len
1793 let i = if i >= active then i + 1 else i in
1805 Glut.postRedisplay
()
1807 | _
-> dolog "unknown key %d" key
1810 let keyboard ~key ~x ~
y =
1815 match state.mode
with
1816 | Outline
outline -> outlinekeyboard ~key ~x ~
y outline
1817 | Textentry
textentry -> textentrykeyboard ~key ~x ~
y textentry
1818 | Birdseye birdseye
-> birdseyekeyboard ~key ~x ~
y birdseye
1819 | View
-> viewkeyboard ~key ~x ~
y
1822 let birdseyespecial key x
y (conf, leftx
, pageno, hooverpageno
, anchor) =
1825 let pageno = max
0 (pageno - 1) in
1826 let rec loop = function
1827 | [] -> gotopage1 pageno 0
1828 | l :: _
when l.pageno = pageno ->
1829 if l.pagedispy
>= 0 && l.pagey = 0
1830 then Glut.postRedisplay
()
1831 else gotopage1 pageno 0
1832 | _
:: rest
-> loop rest
1835 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor)
1838 let pageno = min
(state.pagecount
- 1) (pageno + 1) in
1839 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
1840 let rec loop = function
1842 let y, h = getpageyh pageno in
1843 let dy = (y - state.y) - (conf.winh
- h - conf.interpagespace) in
1845 | l :: rest
when l.pageno = pageno ->
1846 if l.pagevh != l.pageh
1847 then gotoy (clamp (l.pageh
- l.pagevh + conf.interpagespace))
1848 else Glut.postRedisplay
()
1849 | l :: rest
-> loop rest
1853 | Glut.KEY_PAGE_UP
->
1854 begin match state.layout with
1858 state.mode
<- Birdseye
(
1859 conf, leftx
, l.pageno, hooverpageno
, anchor
1861 gotopage1 l.pageno 0;
1864 let layout = layout (state.y-conf.winh
) conf.winh
in
1866 | [] -> gotoy (clamp (-conf.winh
))
1868 state.mode
<- Birdseye
(
1869 conf, leftx
, l.pageno, hooverpageno
, anchor
1871 gotopage1 l.pageno 0
1874 | [] -> gotoy (clamp (-conf.winh
))
1877 | Glut.KEY_PAGE_DOWN
->
1878 begin match List.rev
state.layout with
1880 let layout = layout (state.y + conf.winh
) conf.winh
in
1881 begin match layout with
1883 let incr = l.pageh
- l.pagevh in
1888 conf, leftx
, state.pagecount
- 1, hooverpageno
, anchor
1890 Glut.postRedisplay
();
1892 else gotoy (clamp (incr + conf.interpagespace*2));
1896 Birdseye
(conf, leftx
, l.pageno, hooverpageno
, anchor);
1897 gotopage1 l.pageno 0;
1900 | [] -> gotoy (clamp conf.winh
)
1904 state.mode
<- Birdseye
(conf, leftx
, 0, hooverpageno
, anchor);
1908 let pageno = state.pagecount
- 1 in
1909 state.mode
<- Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor);
1910 if not
(pagevisible state.layout pageno)
1913 match List.rev
state.pdims
with
1915 | (_
, _
, h, _
) :: _
-> h
1917 gotoy (max
0 (getpagey pageno - (conf.winh
- h - conf.interpagespace)))
1918 else Glut.postRedisplay
();
1922 let setautoscrollspeed goingdown
=
1923 let incr = max
1 (state.ascrollstep
/ 2) in
1924 let astep = max
1 (state.ascrollstep
+ (if goingdown
then incr else -incr)) in
1925 state.ascrollstep
<- astep;
1928 let special ~key ~x ~
y =
1929 match state.mode
with
1930 | View
| (Birdseye _
) when key
= Glut.KEY_F9
->
1934 birdseyespecial key x
y vals
1937 if state.ascrollstep
> 0 && (key
= Glut.KEY_DOWN
|| key
= Glut.KEY_UP
)
1938 then setautoscrollspeed (key
= Glut.KEY_DOWN
)
1942 | Glut.KEY_F3
-> search state.searchpattern
true; state.y
1943 | Glut.KEY_UP
-> clamp (-conf.scrollstep
)
1944 | Glut.KEY_DOWN
-> clamp conf.scrollstep
1945 | Glut.KEY_PAGE_UP
->
1946 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
1948 match state.layout with
1950 | l :: _
-> state.y - l.pagey
1953 | Glut.KEY_PAGE_DOWN
->
1954 if Glut.getModifiers
() land Glut.active_ctrl
!= 0
1956 match List.rev
state.layout with
1958 | l :: _
-> getpagey l.pageno
1961 | Glut.KEY_HOME
-> addnav (); 0
1964 state.maxy - (if conf.maxhfit
then conf.winh
else 0)
1966 | Glut.KEY_RIGHT
when conf.zoom > 1.0 ->
1967 state.x
<- state.x
- 10;
1969 | Glut.KEY_LEFT
when conf.zoom > 1.0 ->
1970 state.x
<- state.x
+ 10;
1975 gotoy_and_clear_text y
1978 ((c, s, (Some
(action, _
) as onhist), onkey
, ondone), mode
) ->
1981 | Glut.KEY_UP
-> action HCprev
1982 | Glut.KEY_DOWN
-> action HCnext
1983 | Glut.KEY_HOME
-> action HCfirst
1984 | Glut.KEY_END
-> action HClast
1987 state.mode
<- Textentry
((c, s, onhist, onkey
, ondone), mode
);
1988 Glut.postRedisplay
()
1992 | Outline
(allowdel
, active, first
, outlines, qsearch) ->
1993 let maxrows = maxoutlinerows () in
1994 let calcfirst first
active =
1997 let rows = active - first
in
1998 if rows > maxrows then active - maxrows else first
2002 let active = active + incr in
2003 let active = max
0 (min
active (Array.length
outlines - 1)) in
2004 let first = calcfirst first active in
2005 state.mode
<- Outline
(allowdel
, active, first, outlines, qsearch);
2006 Glut.postRedisplay
()
2008 let updownlevel incr =
2009 let len = Array.length
outlines in
2010 let (_
, curlevel
, _
, _
) = outlines.(active) in
2012 if i = len then i-1 else if i = -1 then 0 else
2013 let (_
, l, _
, _
) = outlines.(i) in
2014 if l != curlevel
then i else flow (i+incr)
2016 let active = flow active in
2017 let first = calcfirst first active in
2018 state.mode
<- Outline
(allowdel
, active, first, outlines, qsearch);
2019 Glut.postRedisplay
()
2022 | Glut.KEY_UP
-> navigate ~
-1
2023 | Glut.KEY_DOWN
-> navigate 1
2024 | Glut.KEY_PAGE_UP
-> navigate ~
-maxrows
2025 | Glut.KEY_PAGE_DOWN
-> navigate maxrows
2027 | Glut.KEY_RIGHT
when not allowdel
-> updownlevel 1
2028 | Glut.KEY_LEFT
when not allowdel
-> updownlevel ~
-1
2031 state.mode
<- Outline
(allowdel
, 0, 0, outlines, qsearch);
2032 Glut.postRedisplay
()
2035 let active = Array.length
outlines - 1 in
2036 let first = max
0 (active - maxrows) in
2037 state.mode
<- Outline
(allowdel
, active, first, outlines, qsearch);
2038 Glut.postRedisplay
()
2043 let drawplaceholder l =
2044 let margin = state.x
+ (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2046 (float l.pagex
, float l.pagedispy
)
2047 (float (l.pagew
+ l.pagex
), float (l.pagedispy
+ l.pagevh))
2049 let x = float (if margin < 0 then -margin else l.pagex
)
2050 and y = float (l.pagedispy
+ 13) in
2051 let font = Glut.BITMAP_8_BY_13
in
2052 GlDraw.color
(0.0, 0.0, 0.0);
2053 GlPix.raster_pos ~
x ~
y ();
2054 String.iter
(fun c -> Glut.bitmapCharacter ~
font ~
c:(Char.code
c))
2055 ("Loading " ^ string_of_int
(l.pageno + 1));
2058 let now () = Unix.gettimeofday
();;
2062 match state.mode
with
2063 | Textentry _
-> scalecolor 0.4
2064 | View
| Outline _
-> scalecolor 1.0
2065 | Birdseye
(_
, _
, pageno, hooverpageno
, _
) ->
2066 if l.pageno = pageno
2069 if l.pageno = hooverpageno
2075 begin match getopaque l.pageno with
2076 | Some
(opaque, _
) when validopaque opaque ->
2078 draw
(l.pagedispy
, l.pagew
, l.pagevh, l.pagey, conf.hlinks
)
2082 vlog "draw %d %f sec" l.pageno d;
2090 let maxy = state.maxy - (if conf.maxhfit
then conf.winh
else 0) in
2091 let sh = (float (maxy + conf.winh
) /. float conf.winh
) in
2092 let sh = float conf.winh
/. sh in
2093 let sh = max
sh (float conf.scrollh
) in
2096 if state.y = state.maxy
2098 else float y /. float maxy
2100 let position = (float conf.winh
-. sh) *. percent in
2103 if position +. sh > float conf.winh
2104 then float conf.winh
-. sh
2110 let scrollindicator () =
2111 GlDraw.color (0.64 , 0.64, 0.64);
2113 (float (conf.winw
- conf.scrollw
), 0.)
2114 (float conf.winw
, float conf.winh
)
2116 GlDraw.color (0.0, 0.0, 0.0);
2118 let position, sh = scrollph state.y in
2120 (float (conf.winw
- conf.scrollw
), position)
2121 (float conf.winw
, position +. sh)
2125 let showsel margin =
2126 match state.mstate
with
2127 | Mnone
| Mscroll _
| Mpan _
->
2130 | Msel
((x0
, y0
), (x1
, y1
)) ->
2131 let rec loop = function
2133 if (y0
>= l.pagedispy
&& y0
<= (l.pagedispy
+ l.pagevh))
2134 || ((y1
>= l.pagedispy
&& y1
<= (l.pagedispy
+ l.pagevh)))
2136 match getopaque l.pageno with
2137 | Some
(opaque, _
) when validopaque opaque ->
2138 let oy = -l.pagey + l.pagedispy
in
2140 (x0
- margin - state.x, y0
,
2141 x1
- margin - state.x, y1
) oy;
2151 let panx = float state.x in
2153 GlDraw.color (0.0, 0.0, 1.0) ~alpha
:0.5;
2154 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2156 (fun (pageno, c, (x0
, y0
, x1
, y1
, x2
, y2
, x3
, y3
)) ->
2158 if l.pageno = pageno
2160 let d = float (l.pagedispy
- l.pagey) in
2161 GlDraw.color (0.0, 0.0, 1.0 /. float c) ~alpha
:0.5;
2162 GlDraw.begins `quads
;
2164 GlDraw.vertex2
(x0
+.panx, y0
+.d);
2165 GlDraw.vertex2
(x1
+.panx, y1
+.d);
2166 GlDraw.vertex2
(x2
+.panx, y2
+.d);
2167 GlDraw.vertex2
(x3
+.panx, y3
+.d);
2177 let showoutline () =
2178 match state.mode
with
2179 | Outline
(allowdel
, active, first, outlines, qsearch) ->
2181 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2182 GlDraw.color (0., 0., 0.) ~alpha
:0.85;
2183 GlDraw.rect (0., 0.) (float conf.winw
, float conf.winh
);
2186 GlDraw.color (1., 1., 1.);
2187 let font = Glut.BITMAP_9_BY_15
in
2188 let draw_string x y s =
2189 GlPix.raster_pos ~
x ~
y ();
2190 String.iter
(fun c -> Glut.bitmapCharacter ~
font ~
c:(Char.code
c)) s
2193 if row
= Array.length
outlines || (row
- first) * 16 > conf.winh
2196 let (s, l, _
, _
) = outlines.(row
) in
2197 let y = (row
- first) * 16 in
2202 GlDraw.polygon_mode `both `line
;
2203 GlFunc.blend_func `src_alpha `one_minus_src_alpha
;
2204 GlDraw.color (1., 1., 1.) ~alpha
:0.9;
2205 GlDraw.rect (0., float (y + 1))
2206 (float (conf.winw
- 1), float (y + 18));
2207 GlDraw.polygon_mode `both `fill
;
2209 GlDraw.color (1., 1., 1.);
2211 draw_string (float x) (float (y + 16)) s;
2221 let margin = (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2222 GlDraw.viewport
margin 0 state.w conf.winh
;
2224 GlClear.color (scalecolor 0.5);
2225 GlClear.clear
[`
color];
2228 Gl.enable `scissor_test
;
2229 GlMisc.scissor
0 0 (conf.winw
- conf.scrollw
) conf.winh
;
2231 List.iter
drawpage state.layout;
2234 Gl.disable `scissor_test
2238 let x = -.float state.x in
2239 GlMat.translate ~
x ();
2243 GlDraw.viewport
0 0 conf.winw
conf.winh
;
2248 Glut.swapBuffers
();
2252 let margin = (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2253 let x = x - margin - state.x in
2254 let rec f = function
2256 begin match getopaque l.pageno with
2257 | Some
(opaque, _
) when validopaque opaque ->
2258 let y = y - l.pagedispy
in
2261 let y = l.pagey + y in
2262 let x = x - l.pagex
in
2263 match whatsunder
opaque x y with
2276 let viewmouse button bstate
x y =
2278 | Glut.OTHER_BUTTON
n when (n == 3 || n == 4) && bstate
= Glut.UP
->
2279 if state.ascrollstep
> 0
2281 setautoscrollspeed (n=4)
2285 then -conf.scrollstep
2286 else conf.scrollstep
2288 let incr = incr * 2 in
2289 let y = clamp incr in
2290 gotoy_and_clear_text y
2292 | Glut.LEFT_BUTTON
when Glut.getModifiers
() land Glut.active_ctrl
!= 0 ->
2293 if bstate
= Glut.DOWN
2295 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
2296 state.mstate
<- Mpan
(x, y)
2299 state.mstate
<- Mnone
2301 | Glut.LEFT_BUTTON
when x > conf.winw
- conf.scrollw
->
2302 if bstate
= Glut.DOWN
2304 let position, sh = scrollph state.y in
2305 if y > truncate
position && y < truncate
(position +. sh)
2307 state.mstate
<- Mscroll
2309 let percent = float y /. float conf.winh
in
2310 let desty = truncate
(float (state.maxy - conf.winh
) *. percent) in
2312 state.mstate
<- Mscroll
2314 state.mstate
<- Mnone
2316 | Glut.LEFT_BUTTON
->
2317 let dest = if bstate
= Glut.DOWN
then getunder x y else Unone
in
2318 begin match dest with
2319 | Ulinkgoto
(pageno, top) ->
2323 gotopage1 pageno top;
2329 | Unone
when bstate
= Glut.DOWN
->
2330 Glut.setCursor
Glut.CURSOR_CROSSHAIR
;
2331 state.mstate
<- Mpan
(x, y);
2333 | Unone
| Utext _
->
2334 if bstate
= Glut.DOWN
2336 if conf.angle
mod 360 = 0
2338 state.mstate
<- Msel
((x, y), (x, y));
2339 Glut.postRedisplay
()
2343 match state.mstate
with
2347 state.mstate
<- Mnone
2350 Glut.setCursor
Glut.CURSOR_INHERIT
;
2351 state.mstate
<- Mnone
2353 | Msel
((x0
, y0
), (x1
, y1
)) ->
2355 if (y0
>= l.pagedispy
&& y0
<= (l.pagedispy
+ l.pagevh))
2356 || ((y1
>= l.pagedispy
&& y1
<= (l.pagedispy
+ l.pagevh)))
2358 match getopaque l.pageno with
2359 | Some
(opaque, _
) when validopaque opaque ->
2363 List.iter
f state.layout;
2364 copysel
""; (* ugly *)
2365 Glut.setCursor
Glut.CURSOR_INHERIT
;
2366 state.mstate
<- Mnone
;
2373 let birdseyemouse button bstate
x y
2374 (conf, leftx
, pageno, hooverpageno
, anchor) =
2376 | Glut.LEFT_BUTTON
when bstate
= Glut.UP
->
2377 let margin = (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2378 let rec loop = function
2381 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
2382 && x > margin && x < margin + l.pagew
2384 birdseyeoff (conf, leftx
, l.pageno, hooverpageno
, anchor) false;
2389 | Glut.OTHER_BUTTON _
-> viewmouse button bstate
x y
2393 let mouse bstate button
x y =
2394 match state.mode
with
2395 | View
-> viewmouse button bstate
x y
2396 | Birdseye beye
-> birdseyemouse button bstate
x y beye
2401 let mouse ~button ~
state ~
x ~
y = mouse state button
x y;;
2404 match state.mode
with
2407 match state.mstate
with
2413 state.mstate
<- Mpan
(x, y);
2414 if conf.zoom > 1.0 then state.x <- state.x + dx;
2416 gotoy_and_clear_text y
2419 state.mstate
<- Msel
(a, (x, y));
2420 Glut.postRedisplay
()
2423 let y = min
conf.winh
(max
0 y) in
2424 let percent = float y /. float conf.winh
in
2425 let y = truncate
(float (state.maxy - conf.winh
) *. percent) in
2426 gotoy_and_clear_text y
2430 match state.mode
with
2431 | Birdseye
(conf, leftx
, pageno, hooverpageno
, anchor) ->
2432 let margin = (conf.winw
- (state.w + conf.scrollw
)) / 2 in
2433 let rec loop = function
2435 if hooverpageno
!= -1
2437 state.mode
<- Birdseye
(conf, leftx
, pageno, -1, anchor);
2438 Glut.postRedisplay
();
2441 if y > l.pagedispy
&& y < l.pagedispy
+ l.pagevh
2442 && x > margin && x < margin + l.pagew
2444 state.mode
<- Birdseye
(conf, leftx
, pageno, l.pageno, anchor);
2445 Glut.postRedisplay
();
2453 match state.mstate
with
2455 begin match getunder x y with
2456 | Unone
-> Glut.setCursor
Glut.CURSOR_INHERIT
2458 if conf.underinfo
then showtext 'u'
("ri: " ^ uri
);
2459 Glut.setCursor
Glut.CURSOR_INFO
2460 | Ulinkgoto
(page
, y) ->
2462 then showtext 'p'
("age: " ^ string_of_int page
);
2463 Glut.setCursor
Glut.CURSOR_INFO
2465 if conf.underinfo
then showtext '
f'
("ont: " ^
s);
2466 Glut.setCursor
Glut.CURSOR_TEXT
2469 | Mpan _
| Msel _
| Mscroll
->
2480 match Sys.os_type
with
2481 | "Win32" -> Sys.getenv
"HOMEPATH"
2482 | _
-> Sys.getenv
"HOME"
2485 ("Can not determine home directory location: " ^
2486 Printexc.to_string exn
);
2490 let config_of c attrs
=
2494 | "scroll-bar-width" -> { c with scrollw
= max
0 (int_of_string v
) }
2495 | "scroll-handle-height" -> { c with scrollh
= max
0 (int_of_string v
) }
2496 | "case-insensitive-search" -> { c with icase
= bool_of_string v
}
2497 | "preload" -> { c with preload = bool_of_string v
}
2498 | "page-bias" -> { c with pagebias
= int_of_string v
}
2499 | "scroll-step" -> { c with scrollstep
= max
1 (int_of_string v
) }
2500 | "auto-scroll-step" ->
2501 { c with autoscrollstep
= max
0 (int_of_string v
) }
2502 | "max-height-fit" -> { c with maxhfit
= bool_of_string v
}
2503 | "crop-hack" -> { c with crophack
= bool_of_string v
}
2504 | "throttle" -> { c with showall
= bool_of_string v
}
2505 | "highlight-links" -> { c with hlinks
= bool_of_string v
}
2506 | "under-cursor-info" -> { c with underinfo
= bool_of_string v
}
2507 | "vertical-margin" ->
2508 { c with interpagespace = max
0 (int_of_string v
) }
2510 let zoom = float_of_string v
/. 100. in
2511 let zoom = max
0.01 (min
2.2 zoom) in
2512 { c with zoom = zoom }
2513 | "presentation" -> { c with presentation = bool_of_string v
}
2514 | "rotation-angle" -> { c with angle
= int_of_string v
}
2515 | "width" -> { c with winw
= max
20 (int_of_string v
) }
2516 | "height" -> { c with winh
= max
20 (int_of_string v
) }
2517 | "persistent-bookmarks" -> { c with savebmarks
= bool_of_string v
}
2518 | "proportional-display" -> { c with proportional
= bool_of_string v
}
2519 | "pixmap-cache-size" -> { c with memlimit
= max
2 (int_of_string v
) }
2520 | "tex-count" -> { c with texcount
= max
1 (int_of_string v
) }
2521 | "slice-height" -> { c with sliceheight
= max
2 (int_of_string v
) }
2522 | "thumbnail-width" -> { c with thumbw
= max
2 (int_of_string v
) }
2525 prerr_endline
("Error processing attribute (`" ^
2526 k ^
"'=`" ^ v ^
"'): " ^
Printexc.to_string exn
);
2529 let rec fold c = function
2532 let c = apply c k v
in
2538 let fromstring f pos
n v
d =
2541 dolog "Error processing attribute (%S=%S) at %d\n%s"
2542 n v pos
(Printexc.to_string exn
)
2547 let bookmark_of attrs
=
2548 let rec fold title page rely
= function
2549 | ("title", v
) :: rest
-> fold v page rely rest
2550 | ("page", v
) :: rest
-> fold title v rely rest
2551 | ("rely", v
) :: rest
-> fold title page v rest
2552 | _
:: rest
-> fold title page rely rest
2553 | [] -> title, page
, rely
2555 fold "invalid" "0" "0" attrs
2559 let rec fold path page rely pan
= function
2560 | ("path", v
) :: rest
-> fold v page rely pan rest
2561 | ("page", v
) :: rest
-> fold path v rely pan rest
2562 | ("rely", v
) :: rest
-> fold path page v pan rest
2563 | ("pan", v
) :: rest
-> fold path page rely v rest
2564 | _
:: rest
-> fold path page rely pan rest
2565 | [] -> path
, page
, rely
, pan
2567 fold "" "0" "0" "0" attrs
2570 let setconf dst src
=
2571 dst
.scrollw
<- src
.scrollw
;
2572 dst
.scrollh
<- src
.scrollh
;
2573 dst
.icase
<- src
.icase
;
2574 dst
.preload <- src
.preload;
2575 dst
.pagebias
<- src
.pagebias
;
2576 dst
.verbose
<- src
.verbose
;
2577 dst
.scrollstep
<- src
.scrollstep
;
2578 dst
.maxhfit
<- src
.maxhfit
;
2579 dst
.crophack
<- src
.crophack
;
2580 dst
.autoscrollstep
<- src
.autoscrollstep
;
2581 dst
.showall
<- src
.showall
;
2582 dst
.hlinks
<- src
.hlinks
;
2583 dst
.underinfo
<- src
.underinfo
;
2584 dst
.interpagespace <- src
.interpagespace;
2585 dst
.zoom <- src
.zoom;
2586 dst
.presentation <- src
.presentation;
2587 dst
.angle
<- src
.angle
;
2588 dst
.winw
<- src
.winw
;
2589 dst
.winh
<- src
.winh
;
2590 dst
.savebmarks
<- src
.savebmarks
;
2591 dst
.memlimit
<- src
.memlimit
;
2592 dst
.proportional
<- src
.proportional
;
2593 dst
.texcount
<- src
.texcount
;
2594 dst
.sliceheight
<- src
.sliceheight
;
2595 dst
.thumbw
<- src
.thumbw
;
2599 let l = String.length
s in
2600 let b = Buffer.create
l in
2606 let h = Hashtbl.create
10 in
2607 let dc = { defconf with angle
= defconf.angle
} in
2608 let rec toplevel v t spos epos
=
2610 | Vdata
| Vcdata
| Vend
-> v
2611 | Vopen
("llppconfig", attrs
, closed
) ->
2614 else { v
with f = llppconfig
}
2616 error
"unexpected subelement at top level" s spos
2617 | Vclose tag
-> error
"unexpected close at top level" s spos
2619 and llppconfig v t spos epos
=
2621 | Vdata
| Vcdata
| Vend
-> v
2622 | Vopen
("defaults", attrs
, closed
) ->
2623 let c = config_of dc attrs
in
2627 else { v
with f = skip
"defaults" (fun () -> v
) }
2629 | Vopen
("doc", attrs
, closed
) ->
2630 let pathent, spage
, srely
, span
= doc_of attrs
in
2631 let path = unent pathent
2632 and pageno = fromstring int_of_string spos
"page" spage
0
2633 and rely
= fromstring float_of_string spos
"rely" srely
0.0
2634 and pan
= fromstring int_of_string spos
"pan" span
0 in
2635 let c = config_of dc attrs
in
2636 let anchor = (pageno, rely
) in
2638 then (Hashtbl.add
h path (c, [], pan
, anchor); v
)
2639 else { v
with f = doc
path pan
anchor c [] }
2641 | Vopen
(tag
, _
, closed
) ->
2642 error
"unexpected subelement in llppconfig" s spos
2644 | Vclose
"llppconfig" -> { v
with f = toplevel }
2645 | Vclose tag
-> error
"unexpected close in llppconfig" s spos
2647 and doc
path pan
anchor c bookmarks v t spos epos
=
2649 | Vdata
| Vcdata
-> v
2650 | Vend
-> error
"unexpected end of input in doc" s spos
2651 | Vopen
("bookmarks", attrs
, closed
) ->
2652 { v
with f = pbookmarks
path pan
anchor c bookmarks }
2654 | Vopen
(tag
, _
, _
) ->
2655 error
"unexpected subelement in doc" s spos
2658 Hashtbl.add
h path (c, List.rev
bookmarks, pan
, anchor);
2659 { v
with f = llppconfig
}
2661 | Vclose tag
-> error
"unexpected close in doc" s spos
2663 and pbookmarks
path pan
anchor c bookmarks v t spos epos
=
2665 | Vdata
| Vcdata
-> v
2666 | Vend
-> error
"unexpected end of input in bookmarks" s spos
2667 | Vopen
("item", attrs
, closed
) ->
2668 let titleent, spage
, srely
= bookmark_of attrs
in
2669 let page = fromstring int_of_string spos
"page" spage
0
2670 and rely
= fromstring float_of_string spos
"rely" srely
0.0 in
2671 let bookmarks = (unent titleent, 0, page, rely
) :: bookmarks in
2673 then { v
with f = pbookmarks
path pan
anchor c bookmarks }
2676 { v
with f = skip
"item" f }
2679 error
"unexpected subelement in bookmarks" s spos
2681 | Vclose
"bookmarks" ->
2682 { v
with f = doc
path pan
anchor c bookmarks }
2684 | Vclose tag
-> error
"unexpected close in bookmarks" s spos
2686 and skip tag
f v t spos epos
=
2688 | Vdata
| Vcdata
-> v
2690 error
("unexpected end of input in skipped " ^ tag
) s spos
2691 | Vopen
(tag'
, _
, closed
) ->
2695 let f'
() = { v
with f = skip tag
f } in
2696 { v
with f = skip tag'
f'
}
2700 else error
("unexpected close in skipped " ^ tag
) s spos
2703 parse
{ f = toplevel; accu = () } s;
2709 let len = in_channel_length ic
in
2710 let s = String.create
len in
2711 really_input ic
s 0 len;
2714 | Parse_error
(msg
, s, pos
) ->
2715 let subs = subs s pos
in
2716 let s = Printf.sprintf
"%s: at %d [..%s..]" msg pos
subs in
2717 failwith
("parse error: " ^
s)
2720 failwith
("config load error: " ^
Printexc.to_string exn
)
2726 let dir = Filename.concat
home ".config" in
2727 if Sys.is_directory
dir then dir else home
2730 Filename.concat
dir "llpp.conf"
2734 if Sys.file_exists
path
2737 (try Some
(open_in_bin
path)
2740 ("Error opening configuation file `" ^
path ^
"': " ^
2741 Printexc.to_string exn
);
2750 ("Error loading configuation from `" ^
path ^
"': " ^
2751 Printexc.to_string exn
);
2757 f (Hashtbl.create
0, defconf)
2762 let pc, pb
, px
, pa
=
2764 Hashtbl.find
h (Filename.basename
state.path)
2765 with Not_found
-> dc, [], 0, (0, 0.0)
2769 state.bookmarks <- pb
;
2771 cbput state.hists
.nav pa
;
2776 let add_attrs bb always
dc c =
2779 then Printf.bprintf bb
"\n %s='%b'" s a
2782 then Printf.bprintf bb
"\n %s='%d'" s a
2785 then Printf.bprintf bb
"\n %s='%f'" s (a*.100.)
2789 then dc.winw
, dc.winh
2791 match state.fullscreen
with
2793 | None
-> c.winw
, c.winh
2795 let zoom, presentation, interpagespace, showall
=
2797 then dc.zoom, dc.presentation, dc.interpagespace, dc.showall
2799 match state.mode
with
2800 | Birdseye
(bc
, _
, _
, _
, _
) ->
2801 bc
.zoom, bc
.presentation, bc
.interpagespace, bc
.showall
2802 | _
-> c.zoom, c.presentation, c.interpagespace, c.showall
2804 oi
"width" w dc.winw
;
2805 oi
"height" h dc.winh
;
2806 oi
"scroll-bar-width" c.scrollw
dc.scrollw
;
2807 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
2808 ob "case-insensitive-search" c.icase
dc.icase
;
2809 ob "preload" c.preload dc.preload;
2810 oi
"page-bias" c.pagebias
dc.pagebias
;
2811 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
2812 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
2813 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
2814 ob "crop-hack" c.crophack
dc.crophack
;
2815 ob "throttle" showall
dc.showall
;
2816 ob "highlight-links" c.hlinks
dc.hlinks
;
2817 ob "under-cursor-info" c.underinfo
dc.underinfo
;
2818 oi
"vertical-margin" interpagespace dc.interpagespace;
2819 oz
"zoom" zoom dc.zoom;
2820 ob "presentation" presentation dc.presentation;
2821 oi
"rotation-angle" c.angle
dc.angle
;
2822 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
2823 ob "proportional-display" c.proportional
dc.proportional
;
2824 oi
"pixmap-cache-size" c.memlimit
dc.memlimit
;
2825 oi
"texcount" c.texcount
dc.texcount
;
2826 oi
"slice-height" c.sliceheight
dc.sliceheight
;
2827 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
2831 let bb = Buffer.create
32768 in
2833 Buffer.add_string
bb "<llppconfig>\n<defaults ";
2834 add_attrs bb true dc dc;
2835 Buffer.add_string
bb "/>\n";
2837 let adddoc path pan
anchor c bookmarks =
2838 if bookmarks == [] && c = dc && anchor = emptyanchor
2841 Printf.bprintf
bb "<doc path='%s'"
2842 (enent
path 0 (String.length
path));
2844 if anchor <> emptyanchor
2846 let n, y = anchor in
2847 Printf.bprintf
bb " page='%d'" n;
2848 Printf.bprintf
bb " rely='%f'" y;
2852 then Printf.bprintf
bb " pan='%d'" pan
;
2854 add_attrs bb false dc c;
2856 begin match bookmarks with
2857 | [] -> Buffer.add_string
bb "/>\n"
2859 Buffer.add_string
bb ">\n<bookmarks>\n";
2860 List.iter
(fun (title, _level
, page, rely
) ->
2862 "<item title='%s' page='%d' rely='%f'/>\n"
2863 (enent
title 0 (String.length
title))
2867 Buffer.add_string
bb "</bookmarks>\n</doc>\n";
2873 match state.mode
with
2874 | Birdseye
(_
, pan, _
, _
, _
) -> pan
2877 let basename = Filename.basename state.path in
2878 adddoc basename pan (getanchor ())
2881 if state.ascrollstep
> 0
2882 then state.ascrollstep
2883 else conf.autoscrollstep
}
2884 (if conf.savebmarks
then state.bookmarks else []);
2886 Hashtbl.iter
(fun path (c, bookmarks, x, y) ->
2888 then adddoc path x y c bookmarks
2890 Buffer.add_string
bb "</llppconfig>";
2893 if Buffer.length
bb > 0
2896 let tmp = path ^
".tmp" in
2897 let oc = open_out_bin
tmp in
2898 Buffer.output_buffer
oc bb;
2900 Sys.rename
tmp path;
2903 ("error while saving configuration: " ^
Printexc.to_string exn
)
2909 ["-p", Arg.String
(fun s -> state.password
<- s) , "password"]
2910 (fun s -> state.path <- s)
2911 ("Usage: " ^
Sys.argv
.(0) ^
" [options] some.pdf\noptions:")
2913 if String.length
state.path = 0
2914 then (prerr_endline
"filename missing"; exit
1);
2918 let _ = Glut.init
Sys.argv
in
2919 let () = Glut.initDisplayMode ~depth
:false ~double_buffer
:true () in
2920 let () = Glut.initWindowSize
conf.winw
conf.winh
in
2921 let _ = Glut.createWindow
("llpp " ^
Filename.basename state.path) in
2924 if Sys.os_type
= "Unix"
2926 Unix.socketpair
Unix.PF_UNIX
Unix.SOCK_STREAM
0
2928 let addr = Unix.ADDR_INET
(Unix.inet_addr_loopback
, 1337) in
2929 let sock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
2930 Unix.setsockopt
sock Unix.SO_REUSEADDR
true;
2931 Unix.bind
sock addr;
2933 let csock = Unix.socket
Unix.PF_INET
Unix.SOCK_STREAM
0 in
2934 Unix.connect
csock addr;
2935 let ssock, _ = Unix.accept
sock in
2938 Unix.setsockopt
sock Unix.TCP_NODELAY
true;
2939 Unix.setsockopt_optint
sock Unix.SO_LINGER None
;
2943 at_exit
(fun () -> Unix.shutdown
ssock Unix.SHUTDOWN_ALL
);
2947 let () = Glut.displayFunc
display in
2948 let () = Glut.reshapeFunc
reshape in
2949 let () = Glut.keyboardFunc
keyboard in
2950 let () = Glut.specialFunc
special in
2951 let () = Glut.idleFunc
(Some
idle) in
2952 let () = Glut.mouseFunc
mouse in
2953 let () = Glut.motionFunc
motion in
2954 let () = Glut.passiveMotionFunc
pmotion in
2956 init
ssock (conf.angle
, conf.proportional
, conf.texcount
, conf.sliceheight
);
2957 state.csock <- csock;
2958 state.ssock <- ssock;
2959 state.text <- "Opening " ^
state.path;
2960 writeopen state.path state.password
;
2964 let rec handlelablglutbug () =
2967 with Glut.BadEnum
"key in special_of_int" ->
2968 showtext '
!'
" LablGlut bug: special key not recognized";
2969 handlelablglutbug ()
2971 handlelablglutbug ();