3 external fz_version
: unit -> string = "ml_fz_version";;
6 { mutable fontsize
: int
7 ; mutable wwidth
: float
8 ; mutable maxrows
: int
21 let fastghyllscroll = (5,1,2);;
22 let neatghyllscroll = (10,1,9);;
24 let irect_of_string s
=
25 Scanf.sscanf s
"%d/%d/%d/%d" (fun x0 y0 x1 y1
-> (x0
,y0
,x1
,y1
))
28 let irect_to_string (x0
,y0
,x1
,y1
) =
29 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
32 let ghyllscroll_of_string s
=
34 | "fast" -> Some
fastghyllscroll
35 | "neat" -> Some
(10,1,9)
39 Scanf.sscanf s
"%u,%u,%u" (fun n a b
-> n
, a
, b
) in
40 if n
<= a
|| n
<= b
|| a
>= b
41 then error
"N(%d),A(%d),B(%d) (N <= A, A < B, N <= B)" n a b
;
45 let ghyllscroll_to_string ((n
, a
, b
) as nab
) =
46 if nab
= fastghyllscroll then "fast"
47 else if nab
= neatghyllscroll then "neat"
48 else Printf.sprintf
"%d,%d,%d" n a b
;
51 let multicolumns_to_string (n
, a
, b
) =
53 then Printf.sprintf
"%d" n
54 else Printf.sprintf
"%d,%d,%d" n a b
;
57 let multicolumns_of_string s
=
59 (int_of_string s
, 0, 0)
61 Scanf.sscanf s
"%u,%u,%u" (fun n a b
->
63 then failwith
"subtly broken";
71 | KMmulti
of key list
* key list
73 and keyhash
= (key
, keymap
) Hashtbl.t
76 | KSinto
of (key list
* key list
)
77 and interpagespace
= int
78 and multicolumns
= multicol
* pagegeom
79 and singlecolumn
= pagegeom
80 and splitcolumns
= columncount
* pagegeom
81 and pagegeom
= (pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
82 and multicol
= columncount
* covercount
* covercount
86 and fitmodel
= | FitWidth
| FitProportional
| FitPage
87 and trimmargins
= bool
88 and irect
= (int * int * int * int)
94 (angle
* fitmodel
* trimparams
* texcount
* sliceheight
* memsize
95 * colorspace
* fontpath
* trimcachepath
* haspbo
)
100 and rectcolor
= (float * float * float * float)
105 and fontpath
= string
106 and trimcachepath
= string
109 and trimparams
= (trimmargins
* irect
)
110 and colorspace
= | Rgb
| Bgr
| Gray
112 and usefontconfig
= bool
120 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
125 | Uannotation
of (opaque
* slinkindex
)
127 and facename
= string
128 and launchcommand
= string
129 and filename
= string
132 and destname
= string
144 | LDfirstvisible
of (int * int * int)
153 and anchor
= pageno
* top
* dtop
154 and rect
= float * float * float * float * float * float * float * float
155 and infochange
= | Memused
| Docinfo
| Pdim
160 method display
: unit
161 method key
: int -> int -> uioh
162 method button
: int -> bool -> int -> int -> int -> uioh
163 method multiclick
: int -> int -> int -> int -> uioh
164 method motion
: int -> int -> uioh
165 method pmotion
: int -> int -> uioh
166 method infochanged
: infochange
-> unit
167 method scrollpw
: (int * float * float)
168 method scrollph
: (int * float * float)
169 method modehash
: keyhash
170 method eformsgs
: bool
171 method alwaysscrolly
: bool
174 module type TextEnumType
=
178 val names
: string array
181 module TextEnumMake
(Ten
: TextEnumType
) =
183 let names = Ten.names;;
184 let to_int (t
: Ten.t
) = Obj.magic t
;;
185 let to_string t
= names.(to_int t
);;
186 let of_int n
: Ten.t
= Obj.magic n
;;
189 if i
= Array.length
names
190 then failwith
("invalid " ^
Ten.name ^
": " ^ s
)
199 module CSTE
= TextEnumMake
(struct
200 type t
= colorspace
;;
201 let name = "colorspace";;
202 let names = [|"rgb"; "bgr"; "gray"|];;
205 module MTE
= TextEnumMake
(struct
208 let names = [|"page"; "block"; "line"; "word"|];;
211 module FMTE
= TextEnumMake
(struct
213 let name = "fitmodel";;
214 let names = [|"width"; "proportional"; "page"|];;
218 { mutable scrollbw
: int
219 ; mutable scrollh
: int
220 ; mutable scrollb
: scrollb
221 ; mutable icase
: bool
222 ; mutable preload
: bool
223 ; mutable pagebias
: int
224 ; mutable verbose
: bool
225 ; mutable debug
: bool
226 ; mutable scrollstep
: int
227 ; mutable hscrollstep
: int
228 ; mutable maxhfit
: bool
229 ; mutable crophack
: bool
230 ; mutable autoscrollstep
: int
231 ; mutable maxwait
: float option
232 ; mutable hlinks
: bool
233 ; mutable underinfo
: bool
234 ; mutable interpagespace
: interpagespace
235 ; mutable zoom
: float
236 ; mutable presentation
: bool
237 ; mutable angle
: angle
238 ; mutable cwinw
: int
239 ; mutable cwinh
: int
240 ; mutable savebmarks
: bool
241 ; mutable fitmodel
: fitmodel
242 ; mutable trimmargins
: trimmargins
243 ; mutable trimfuzz
: irect
244 ; mutable memlimit
: memsize
245 ; mutable texcount
: texcount
246 ; mutable sliceheight
: sliceheight
247 ; mutable thumbw
: width
248 ; mutable jumpback
: bool
249 ; mutable bgcolor
: (float * float * float)
250 ; mutable bedefault
: bool
251 ; mutable tilew
: int
252 ; mutable tileh
: int
253 ; mutable mustoresize
: memsize
254 ; mutable checkers
: bool
255 ; mutable aalevel
: int
256 ; mutable urilauncher
: string
257 ; mutable pathlauncher
: string
258 ; mutable colorspace
: colorspace
259 ; mutable invert
: bool
260 ; mutable colorscale
: float
261 ; mutable ghyllscroll
: (int * int * int) option
262 ; mutable columns
: columns
263 ; mutable beyecolumns
: columncount
option
264 ; mutable selcmd
: string
265 ; mutable paxcmd
: string
266 ; mutable passcmd
: string
267 ; mutable savecmd
: string
268 ; mutable updatecurs
: bool
269 ; mutable keyhashes
: (string * keyhash
) list
270 ; mutable hfsize
: int
271 ; mutable pgscale
: float
272 ; mutable usepbo
: bool
273 ; mutable wheelbypage
: bool
274 ; mutable stcmd
: string
275 ; mutable riani
: bool
276 ; mutable pax
: (float * int * int) ref option
277 ; mutable paxmark
: mark
278 ; mutable leftscroll
: bool
279 ; mutable title
: string
280 ; mutable lastvisit
: float
281 ; mutable annotinline
: bool
282 ; mutable coarseprespos
: bool
284 ; mutable usedoccss
: usedoccss
287 | Csingle
of singlecolumn
288 | Cmulti
of multicolumns
289 | Csplit
of splitcolumns
294 | Olaunch
of launchcommand
295 | Oremote
of (filename
* pageno
)
296 | Oremotedest
of (filename
* destname
)
297 | Ohistory
of (filename
* conf
* outline list
* x
* anchor
* filename
)
298 and outline
= (caption
* outlinelevel
* outlinekind
)
299 and outlinelevel
= int
317 type tile
= opaque
* pixmapsize
* elapsed
318 and elapsed
= float;;
319 type pagemapkey
= pageno
* gen
;;
320 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
325 | Loading
of (page
* gen
)
327 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
329 | Outlining
of outline list
332 type mpos
= int * int
334 | Msel
of (mpos
* mpos
)
336 | Mscrolly
| Mscrollx
337 | Mzoom
of (buttonno
* step
* mpos
)
338 | Mzoomrect
of (mpos
* mpos
)
345 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
346 | Textentry
of (textentry
* onleave
)
348 | LinkNav
of linktarget
349 and onleave
= leavetextentrystatus
-> unit
350 and leavetextentrystatus
= | Cancel
| Confirm
351 and helpitem
= string * int * action
354 | Action
of (uioh
-> uioh
)
356 | Ltexact
of (pageno
* direction
)
357 | Ltgendir
of direction
358 | Ltnotready
of (pageno
* direction
)
359 and direction
= int (* -1, 0, 1 *)
360 and textentry
= string * string * onhist
option
361 * onkey
* ondone
* cancelonempty
362 and onkey
= string -> Keys.t
-> te
363 and ondone
= string -> unit
364 and histcancel
= unit -> unit
365 and onhist
= ((histcmd
-> string) * histcancel
)
366 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
367 and cancelonempty
= bool
372 | TEswitch
of textentry
384 { mutable ss
: Unix.file_descr
385 ; mutable wsfd
: Unix.file_descr
386 ; mutable stderr
: Unix.file_descr
387 ; mutable errmsgs
: Buffer.t
388 ; mutable newerrmsgs
: bool
392 ; mutable anchor
: anchor
393 ; mutable ranchors
: (string * string * anchor
* string) list
395 ; mutable layout
: page list
396 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
397 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
398 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
399 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
400 ; mutable pagecount
: int
401 ; mutable currently
: currently
402 ; mutable mstate
: mstate
403 ; mutable searchpattern
: string
404 ; mutable rects
: (pageno
* rectcolor
* rect
) list
405 ; mutable rects1
: (pageno
* rectcolor
* rect
) list
406 ; prects
: (pageno
, float array
) Hashtbl.t
407 ; mutable text
: string
408 ; mutable winstate
: Wsi.winstate list
409 ; mutable mode
: mode
410 ; mutable uioh
: uioh
411 ; mutable outlines
: outline array
412 ; mutable bookmarks
: outline list
413 ; mutable path
: string
414 ; mutable password
: string
415 ; mutable nameddest
: string
416 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
417 ; mutable memused
: memsize
419 ; mutable throttle
: (page list
* int * float) option
420 ; mutable autoscroll
: int option
421 ; mutable ghyll
: (int option -> unit)
422 ; mutable help
: helpitem array
423 ; mutable docinfo
: (int * string) list
424 ; mutable checkerstexid
: GlTex.texture_id
option
426 ; mutable prevzoom
: (float * int)
427 ; mutable progress
: float
428 ; mutable redisplay
: bool
429 ; mutable mpos
: mpos
430 ; mutable keystate
: keystate
431 ; mutable glinks
: bool
432 ; mutable prevcolumns
: (columns
* float) option
435 ; mutable reprf
: (unit -> unit)
436 ; mutable origin
: string
437 ; mutable roam
: (unit -> unit)
438 ; mutable bzoom
: bool
439 ; mutable traw
: [`
float] Raw.t
440 ; mutable vraw
: [`
float] Raw.t
441 ; mutable lnava
: (pageno
* linkno
) option
444 { pat
: string circbuf
445 ; pag
: string circbuf
446 ; nav
: anchor circbuf
447 ; sel
: string circbuf
451 let emptyanchor = (0, 0.0, 0.0);;
452 let emptykeyhash = Hashtbl.create
0;;
454 let noreprf () = ();;
457 let nouioh : uioh
= object (self
)
459 method key _ _
= self
460 method multiclick _ _ _ _
= self
461 method button _ _ _ _ _
= self
462 method motion _ _
= self
463 method pmotion _ _
= self
464 method infochanged _
= ()
465 method scrollpw
= (0, nan
, nan
)
466 method scrollph
= (0, nan
, nan
)
467 method modehash
= emptykeyhash
468 method eformsgs
= false
469 method alwaysscrolly
= false
472 let platform_to_string = function
473 | Punknown
-> "unknown"
478 | Pcygwin
-> "Cygwin"
482 Printf.sprintf
"llpp version %s, fitz %s, ocaml %s/%d bit"
483 Help.version (fz_version
()) Sys.ocaml_version
Sys.word_size
489 ; scrollb
= scrollbhv lor scrollbvv
505 ; presentation
= false
510 ; fitmodel
= FitProportional
511 ; trimmargins
= false
512 ; trimfuzz
= (0,0,0,0)
513 ; memlimit
= 32 lsl 20
518 ; bgcolor
= (0.5, 0.5, 0.5)
522 ; mustoresize
= 256 lsl 20
527 | Plinux
| Psun
| Pbsd
-> "xdg-open \"%s\""
528 | Posx
-> "open \"%s\""
529 | Pcygwin
-> "cygstart \"%s\""
530 | Punknown
-> "echo %s")
531 ; pathlauncher
= "lp \"%s\""
534 | Plinux
| Pbsd
| Psun
-> "xsel -i"
545 ; columns
= Csingle
[||]
551 ; wheelbypage
= false
552 ; stcmd
= "echo SyncTex"
555 ; paxmark
= Mark_word
560 ; coarseprespos
= false
564 let mk n
= (n
, Hashtbl.create
1) in
578 let conf = { defconf with angle
= defconf.angle
};;
581 let command = Str.global_replace percentsre url
conf.urilauncher
in
582 try ignore
@@ spawn
command []
583 with exn
-> dolog
"failed to execute `%s': %s" command @@ exntos exn
587 if emptystr
conf.urilauncher
590 match geturl uri
with
591 | "" -> dolog
"obtained empty url from uri %S" uri
598 :: "(searching in this text works just by typing (i.e. no initial '/'))"
603 | "" -> (s
, 0, Noaction
)
604 | url
-> (s
, 0, Action
(fun uioh
-> gotourl url
; uioh
))
609 { store
= Array.make n v
616 let cbcap b
= Array.length b
.store
;;
621 b
.wc
<- (b
.wc
+ 1) mod cap;
623 b
.len
<- min
(b
.len
+ 1) cap;
626 let cbempty b
= b
.len
= 0;;
628 let cbgetg b circular dir
=
632 let rc = b
.rc + dir
in
644 else bound
rc 0 (b
.len
-1)
650 let cbget b
= cbgetg b
false;;
651 let cbgetc b
= cbgetg b
true;;
656 ; stderr
= Unix.stderr
657 ; errmsgs
= Buffer.create
0
662 ; anchor
= emptyanchor
666 ; tilelru
= Queue.create
()
667 ; pagemap
= Hashtbl.create
10
668 ; tilemap
= Hashtbl.create
10
675 ; prects
= Hashtbl.create
1
679 ; searchpattern
= E.s
687 { nav
= cbnew 10 emptyanchor
699 ; checkerstexid
= None
700 ; prevzoom
= (1.0, 0)
714 ; traw
= Raw.create_static `
float ~len
:8
715 ; vraw
= Raw.create_static `
float ~len
:8
720 let copykeyhashes c
=
721 List.map
(fun (k
, v
) -> k
, Hashtbl.copy v
) c
.keyhashes
;
725 let d = state.winh
- h
in
726 max
conf.interpagespace
((d + 1) / 2)
729 let rowyh (c
, coverA
, coverB
) b n
=
730 if c
= 1 || (n
< coverA
|| n
>= state.pagecount
- coverB
)
732 let _, _, vy
, (_, _, h
, _) = b
.(n
) in
735 let n'
= n - coverA
in
738 let e = min
state.pagecount
(s + c
) in
739 let rec find m miny maxh
= if m
= e then miny
, maxh
else
740 let _, _, y
, (_, _, h
, _) = b
.(m
) in
741 let miny = min
miny y
in
742 let maxh = max
maxh h
in
748 let ((c
, coverA
, coverB
) as cl
), b
=
749 match conf.columns
with
750 | Csingle b
-> (1, 0, 0), b
751 | Cmulti
(c
, b
) -> c
, b
752 | Csplit
(_, b
) -> (1, 0, 0), b
754 if Array.length b
= 0
757 let rec bsearch nmin nmax
=
759 then bound nmin
0 (state.pagecount
-1)
761 let n = (nmax
+ nmin
) / 2 in
762 let vy, h
= rowyh cl b
n in
766 let ips = calcips h
in
768 let y1 = vy + h
+ ips in
772 then 0, vy + h
+ conf.interpagespace
774 let y0 = vy - conf.interpagespace
in
775 y0, y0 + h
+ conf.interpagespace
785 if n < state.pagecount
- coverB
786 then ((n-coverA
)/c
)*c
+ coverA
793 then bsearch (n+1) nmax
794 else bsearch nmin
(n-1)
797 bsearch 0 (state.pagecount
-1);
801 match conf.columns
with
802 | Cmulti
((_, _, _) as cl
, b
) ->
803 if Array.length b
> 0
805 let y, h
= rowyh cl b
(Array.length b
- 1) in
806 y + h
+ (if conf.presentation
then calcips h
else 0)
809 if Array.length b
> 0
811 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
812 y + h
+ (if conf.presentation
then calcips h
else 0)
815 if Array.length b
> 0
817 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
822 let getpageywh pageno
=
823 let pageno = bound
pageno 0 (state.pagecount
-1) in
824 match conf.columns
with
826 if Array.length b
= 0
829 let (_, _, y, (_, w
, h
, _)) = b
.(pageno) in
837 if Array.length b
= 0
840 let y, h
= rowyh cl b
pageno in
841 let (_, _, _, (_, w
, _, _)) = b
.(pageno) in
849 if Array.length b
= 0
853 let (_, _, y, (_, w
, h
, _)) = b
.(n) in
857 let getpageyh pageno =
858 let y,_,h
= getpageywh pageno in
862 let getpagedim pageno =
865 | (n, _, _, _) as pdim
:: rest
->
867 then (if n = pageno then pdim
else ppdim
)
872 f (-1, -1, -1, -1) state.pdims
875 let getpdimno pageno =
879 | (n, _, _, _) :: rest
->
881 then (if n = pageno then np else p
)
889 let getpagey pageno = fst
(getpageyh pageno);;
893 let coloff = l
.pagecol
* l
.pageh
in
894 float (l
.pagey
+ coloff) /. float l
.pageh
902 then float l
.pagedispy
/. float (calcips l
.pageh
)
903 else float l
.pagedispy
/. float conf.interpagespace
906 (l
.pageno, top, dtop)
910 match state.layout
with
911 | l
:: _ -> getanchor1 l
913 let n = page_of_y state.y in
917 let y, h
= getpageyh n in
918 let dy = y - state.y in
922 let ips = calcips h
in
923 float (dy + ips) /. float ips
925 float dy /. float conf.interpagespace
930 let fontpath = ref E.s;;
932 type historder
= [ `lastvisit
| `title
| `path
| `file
];;
935 Map.Make
(struct type t
= (int * int) let compare = compare end);;
938 let l = String.length
s in
939 let b = Buffer.create
l in
940 Parser.unent
b s 0 l;
945 try Sys.getenv
"HOME"
947 dolog
"cannot determine home directory location: %s" @@ exntos exn
;
951 let modifier_of_string = function
952 | "alt" -> Wsi.altmask
953 | "shift" -> Wsi.shiftmask
954 | "ctrl" | "control" -> Wsi.ctrlmask
955 | "meta" -> Wsi.metamask
959 let keys_of_string s =
960 let key_of_string r
s =
961 let elems = Str.full_split r
s in
964 let m1 = modifier_of_string s in
966 then (Wsi.namekey
s, m
)
969 | Str.Delim
s when n land 1 = 0 -> g s
971 | Str.Delim
_ -> (k
, m
)
973 let rec loop n k m
= function
976 let k, m
= f n k m x
in
981 let elems = Str.split whitere
s in
982 List.map
(key_of_string (Str.regexp
"-")) elems
985 let config_of c attrs
=
989 | "scroll-bar-width" -> { c
with scrollbw
= max
0 (int_of_string v
) }
990 | "scroll-handle-height" -> { c
with scrollh
= max
0 (int_of_string v
) }
991 | "case-insensitive-search" -> { c
with icase
= bool_of_string v
}
992 | "preload" -> { c
with preload
= bool_of_string v
}
993 | "page-bias" -> { c
with pagebias
= int_of_string v
}
994 | "scroll-step" -> { c
with scrollstep
= max
1 (int_of_string v
) }
995 | "horizontal-scroll-step" ->
996 { c
with hscrollstep
= max
(int_of_string v
) 1 }
997 | "auto-scroll-step" ->
998 { c
with autoscrollstep
= max
0 (int_of_string v
) }
999 | "max-height-fit" -> { c
with maxhfit
= bool_of_string v
}
1000 | "crop-hack" -> { c
with crophack
= bool_of_string v
}
1003 match String.map asciilower v
with
1004 | "true" -> Some infinity
1006 | f -> Some
(float_of_string
f)
1008 { c
with maxwait
= mw }
1009 | "highlight-links" -> { c
with hlinks
= bool_of_string v
}
1010 | "under-cursor-info" -> { c
with underinfo
= bool_of_string v
}
1011 | "vertical-margin" ->
1012 { c
with interpagespace
= max
0 (int_of_string v
) }
1014 let zoom = float_of_string v
/. 100. in
1015 let zoom = max
zoom 0.0 in
1016 { c
with zoom = zoom }
1017 | "presentation" -> { c
with presentation
= bool_of_string v
}
1018 | "rotation-angle" -> { c
with angle
= int_of_string v
}
1019 | "width" -> { c
with cwinw
= max
20 (int_of_string v
) }
1020 | "height" -> { c
with cwinh
= max
20 (int_of_string v
) }
1021 | "persistent-bookmarks" -> { c
with savebmarks
= bool_of_string v
}
1022 | "proportional-display" ->
1025 then FitProportional
1028 { c
with fitmodel
= fm }
1029 | "fit-model" -> { c
with fitmodel
= FMTE.of_string v
}
1030 | "pixmap-cache-size" ->
1031 { c
with memlimit
= max
2 (int_of_string_with_suffix v
) }
1032 | "tex-count" -> { c
with texcount
= max
1 (int_of_string v
) }
1033 | "slice-height" -> { c
with sliceheight
= max
2 (int_of_string v
) }
1034 | "thumbnail-width" -> { c
with thumbw
= max
2 (int_of_string v
) }
1035 | "persistent-location" -> { c
with jumpback
= bool_of_string v
}
1036 | "background-color" -> { c
with bgcolor
= color_of_string v
}
1037 | "tile-width" -> { c
with tilew
= max
2 (int_of_string v
) }
1038 | "tile-height" -> { c
with tileh
= max
2 (int_of_string v
) }
1039 | "mupdf-store-size" ->
1040 { c
with mustoresize
= max
1024 (int_of_string_with_suffix v
) }
1041 | "checkers" -> { c
with checkers
= bool_of_string v
}
1042 | "aalevel" -> { c
with aalevel
= max
0 (int_of_string v
) }
1043 | "trim-margins" -> { c
with trimmargins
= bool_of_string v
}
1044 | "trim-fuzz" -> { c
with trimfuzz
= irect_of_string v
}
1045 | "uri-launcher" -> { c
with urilauncher
= unentS v
}
1046 | "path-launcher" -> { c
with pathlauncher
= unentS v
}
1047 | "color-space" -> { c
with colorspace
= CSTE.of_string v
}
1048 | "invert-colors" -> { c
with invert
= bool_of_string v
}
1049 | "brightness" -> { c
with colorscale
= float_of_string v
}
1050 | "ghyllscroll" -> { c
with ghyllscroll
= ghyllscroll_of_string v
}
1052 let (n, _, _) as nab
= multicolumns_of_string v
in
1054 then { c
with columns
= Csplit
(-n, E.a
) }
1055 else { c
with columns
= Cmulti
(nab
, E.a
) }
1056 | "birds-eye-columns" ->
1057 { c
with beyecolumns
= Some
(max
(int_of_string v
) 2) }
1058 | "selection-command" -> { c
with selcmd
= unentS v
}
1059 | "synctex-command" -> { c
with stcmd
= unentS v
}
1060 | "pax-command" -> { c
with paxcmd
= unentS v
}
1061 | "askpass-command" -> { c
with passcmd
= unentS v
}
1062 | "savepath-command" -> { c
with savecmd
= unentS v
}
1063 | "update-cursor" -> { c
with updatecurs
= bool_of_string v
}
1064 | "hint-font-size" -> { c
with hfsize
= bound
(int_of_string v
) 5 100 }
1065 | "page-scroll-scale" -> { c
with pgscale
= float_of_string v
}
1066 | "use-pbo" -> { c
with usepbo
= bool_of_string v
}
1067 | "wheel-scrolls-pages" -> { c
with wheelbypage
= bool_of_string v
}
1068 | "horizontal-scrollbar-visible" ->
1071 then c
.scrollb
lor scrollbhv
1072 else c
.scrollb
land (lnot
scrollbhv)
1074 { c
with scrollb
= b }
1075 | "vertical-scrollbar-visible" ->
1078 then c
.scrollb
lor scrollbvv
1079 else c
.scrollb
land (lnot
scrollbvv)
1081 { c
with scrollb
= b }
1082 | "remote-in-a-new-instance" -> { c
with riani
= bool_of_string v
}
1086 then Some
(ref (0.0, 0, 0))
1088 | "point-and-x-mark" -> { c
with paxmark
= MTE.of_string v
}
1089 | "scroll-bar-on-the-left" -> { c
with leftscroll
= bool_of_string v
}
1090 | "title" -> { c
with title
= unentS v
}
1091 | "last-visit" -> { c
with lastvisit
= float_of_string v
}
1092 | "edit-annotations-inline" -> { c
with annotinline
= bool_of_string v
}
1093 | "coarse-presentation-positioning" ->
1094 { c
with coarseprespos
= bool_of_string v
}
1095 | "use-document-css" -> { c
with usedoccss
= bool_of_string v
}
1098 dolog
"error processing attribute (`%S' = `%S'): %s" k v
@@ exntos exn
;
1101 let rec fold c
= function
1104 let c = apply c k v
in
1107 fold { c with keyhashes
= copykeyhashes c } attrs
;
1110 let fromstring f pos
n v
d =
1113 dolog
"error processing attribute (%S=%S) at %d\n%s" n v pos
@@ exntos exn
;
1117 let bookmark_of attrs
=
1118 let rec fold title page rely visy
= function
1119 | ("title", v
) :: rest
-> fold v page rely visy rest
1120 | ("page", v
) :: rest
-> fold title v rely visy rest
1121 | ("rely", v
) :: rest
-> fold title page v visy rest
1122 | ("visy", v
) :: rest
-> fold title page rely v rest
1123 | _ :: rest
-> fold title page rely visy rest
1124 | [] -> title
, page
, rely
, visy
1126 fold "invalid" "0" "0" "0" attrs
1130 let rec fold path page rely pan visy origin
= function
1131 | ("path", v
) :: rest
-> fold v page rely pan visy origin rest
1132 | ("page", v
) :: rest
-> fold path v rely pan visy origin rest
1133 | ("rely", v
) :: rest
-> fold path page v pan visy origin rest
1134 | ("pan", v
) :: rest
-> fold path page rely v visy origin rest
1135 | ("visy", v
) :: rest
-> fold path page rely pan v origin rest
1136 | ("origin", v
) :: rest
-> fold path page rely pan visy v rest
1137 | _ :: rest
-> fold path page rely pan visy origin rest
1138 | [] -> path
, page
, rely
, pan
, visy
, origin
1140 fold E.s "0" "0" "0" "0" E.s attrs
1144 let rec fold rs ls
= function
1145 | ("out", v
) :: rest
-> fold v ls rest
1146 | ("in", v
) :: rest
-> fold rs v rest
1147 | _ :: rest
-> fold ls rs rest
1153 let setconf dst src
=
1154 dst
.scrollbw
<- src
.scrollbw
;
1155 dst
.scrollh
<- src
.scrollh
;
1156 dst
.icase
<- src
.icase
;
1157 dst
.preload
<- src
.preload
;
1158 dst
.pagebias
<- src
.pagebias
;
1159 dst
.verbose
<- src
.verbose
;
1160 dst
.scrollstep
<- src
.scrollstep
;
1161 dst
.maxhfit
<- src
.maxhfit
;
1162 dst
.crophack
<- src
.crophack
;
1163 dst
.autoscrollstep
<- src
.autoscrollstep
;
1164 dst
.maxwait
<- src
.maxwait
;
1165 dst
.hlinks
<- src
.hlinks
;
1166 dst
.underinfo
<- src
.underinfo
;
1167 dst
.interpagespace
<- src
.interpagespace
;
1168 dst
.zoom <- src
.zoom;
1169 dst
.presentation
<- src
.presentation
;
1170 dst
.angle
<- src
.angle
;
1171 dst
.cwinw
<- src
.cwinw
;
1172 dst
.cwinh
<- src
.cwinh
;
1173 dst
.savebmarks
<- src
.savebmarks
;
1174 dst
.memlimit
<- src
.memlimit
;
1175 dst
.fitmodel
<- src
.fitmodel
;
1176 dst
.texcount
<- src
.texcount
;
1177 dst
.sliceheight
<- src
.sliceheight
;
1178 dst
.thumbw
<- src
.thumbw
;
1179 dst
.jumpback
<- src
.jumpback
;
1180 dst
.bgcolor
<- src
.bgcolor
;
1181 dst
.tilew
<- src
.tilew
;
1182 dst
.tileh
<- src
.tileh
;
1183 dst
.mustoresize
<- src
.mustoresize
;
1184 dst
.checkers
<- src
.checkers
;
1185 dst
.aalevel
<- src
.aalevel
;
1186 dst
.trimmargins
<- src
.trimmargins
;
1187 dst
.trimfuzz
<- src
.trimfuzz
;
1188 dst
.urilauncher
<- src
.urilauncher
;
1189 dst
.colorspace
<- src
.colorspace
;
1190 dst
.invert
<- src
.invert
;
1191 dst
.colorscale
<- src
.colorscale
;
1192 dst
.ghyllscroll
<- src
.ghyllscroll
;
1193 dst
.columns
<- src
.columns
;
1194 dst
.beyecolumns
<- src
.beyecolumns
;
1195 dst
.selcmd
<- src
.selcmd
;
1196 dst
.updatecurs
<- src
.updatecurs
;
1197 dst
.pathlauncher
<- src
.pathlauncher
;
1198 dst
.keyhashes
<- copykeyhashes src
;
1199 dst
.hfsize
<- src
.hfsize
;
1200 dst
.hscrollstep
<- src
.hscrollstep
;
1201 dst
.pgscale
<- src
.pgscale
;
1202 dst
.usepbo
<- src
.usepbo
;
1203 dst
.wheelbypage
<- src
.wheelbypage
;
1204 dst
.stcmd
<- src
.stcmd
;
1205 dst
.paxcmd
<- src
.paxcmd
;
1206 dst
.passcmd
<- src
.passcmd
;
1207 dst
.savecmd
<- src
.savecmd
;
1208 dst
.scrollb
<- src
.scrollb
;
1209 dst
.riani
<- src
.riani
;
1210 dst
.paxmark
<- src
.paxmark
;
1211 dst
.leftscroll
<- src
.leftscroll
;
1212 dst
.title
<- src
.title
;
1213 dst
.annotinline
<- src
.annotinline
;
1214 dst
.coarseprespos
<- src
.coarseprespos
;
1216 dst
.usedoccss
<- src
.usedoccss
;
1220 else Some
((ref (0.0, 0, 0)));
1223 let findkeyhash c name =
1224 try List.assoc
name c.keyhashes
1225 with Not_found
-> failwith
("invalid mode name `" ^
name ^
"'")
1230 let h = Hashtbl.create
10 in
1231 let dc = { defconf with angle
= defconf.angle
} in
1232 let rec toplevel v t spos
_ =
1234 | Vdata
| Vcdata
| Vend
-> v
1235 | Vopen
("llppconfig", _, closed
) ->
1238 else { v
with f = llppconfig
}
1239 | Vopen
_ -> parse_error
"unexpected subelement at top level" s spos
1240 | Vclose
_ -> parse_error
"unexpected close at top level" s spos
1242 and llppconfig v t spos
_ =
1244 | Vdata
| Vcdata
-> v
1245 | Vend
-> parse_error
"unexpected end of input in llppconfig" s spos
1246 | Vopen
("defaults", attrs
, closed
) ->
1247 let c = config_of dc attrs
in
1251 else { v
with f = defaults
}
1253 | Vopen
("ui-font", attrs
, closed
) ->
1254 let rec getsize size
= function
1256 | ("size", v
) :: rest
->
1258 fromstring int_of_string spos
"size" v
fstate.fontsize
in
1260 | l -> getsize size l
1262 fstate.fontsize
<- getsize fstate.fontsize attrs
;
1265 else { v
with f = uifont
(Buffer.create
10) }
1267 | Vopen
("doc", attrs
, closed
) ->
1268 let pathent, spage
, srely
, span
, svisy
, origin
= doc_of attrs
in
1269 let path = unentS pathent
1270 and origin
= unentS origin
1271 and pageno = fromstring int_of_string spos
"page" spage
0
1272 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1273 and pan
= fromstring int_of_string spos
"pan" span
0
1274 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1275 let c = config_of dc attrs
in
1276 let anchor = (pageno, rely
, visy
) in
1278 then (Hashtbl.add
h path (c, [], pan
, anchor, origin
); v
)
1279 else { v
with f = doc
path origin pan
anchor c [] }
1282 parse_error
"unexpected subelement in llppconfig" s spos
1284 | Vclose
"llppconfig" -> { v
with f = toplevel }
1285 | Vclose
_ -> parse_error
"unexpected close in llppconfig" s spos
1287 and defaults v t spos
_ =
1289 | Vdata
| Vcdata
-> v
1290 | Vend
-> parse_error
"unexpected end of input in defaults" s spos
1291 | Vopen
("keymap", attrs
, closed
) ->
1293 try List.assoc
"mode" attrs
1294 with Not_found
-> "global" in
1299 let h = findkeyhash dc modename in
1300 KeyMap.iter
(Hashtbl.replace
h) keymap
;
1303 { v
with f = pkeymap
ret KeyMap.empty
}
1305 | Vopen
(_, _, _) ->
1306 parse_error
"unexpected subelement in defaults" s spos
1308 | Vclose
"defaults" ->
1309 { v
with f = llppconfig
}
1311 | Vclose
_ -> parse_error
"unexpected close in defaults" s spos
1313 and uifont
b v t spos epos
=
1316 Buffer.add_substring
b s spos
(epos
- spos
);
1318 | Vopen
(_, _, _) ->
1319 parse_error
"unexpected subelement in ui-font" s spos
1320 | Vclose
"ui-font" ->
1321 if emptystr
!fontpath
1322 then fontpath := Buffer.contents
b;
1323 { v
with f = llppconfig
}
1324 | Vclose
_ -> parse_error
"unexpected close in ui-font" s spos
1325 | Vend
-> parse_error
"unexpected end of input in ui-font" s spos
1327 and doc
path origin pan
anchor c bookmarks v t spos
_ =
1329 | Vdata
| Vcdata
-> v
1330 | Vend
-> parse_error
"unexpected end of input in doc" s spos
1331 | Vopen
("bookmarks", _, closed
) ->
1334 else { v
with f = pbookmarks
path origin pan
anchor c bookmarks
}
1336 | Vopen
("keymap", attrs
, closed
) ->
1338 try List.assoc
"mode" attrs
1339 with Not_found
-> "global"
1345 let h = findkeyhash c modename in
1346 KeyMap.iter
(Hashtbl.replace
h) keymap
;
1347 doc
path origin pan
anchor c bookmarks
1349 { v
with f = pkeymap
ret KeyMap.empty
}
1351 | Vopen
("css", [], false) ->
1352 { v
with f = pcss
path origin pan
anchor c bookmarks
}
1354 | Vopen
(_, _, _) ->
1355 parse_error
"unexpected subelement in doc" s spos
1358 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor, origin
);
1359 { v
with f = llppconfig
}
1361 | Vclose
_ -> parse_error
"unexpected close in doc" s spos
1363 and pcss
path origin pan
anchor c bookmarks v t spos epos
=
1366 let b = Buffer.create
10 in
1367 Buffer.add_substring
b s spos
(epos
- spos
);
1368 { v
with f = pcss
path origin pan
anchor
1369 { c with css
= Buffer.contents
b }
1371 | Vend
-> parse_error
"unexpected end of input in css" s spos
1372 | Vopen
_ -> parse_error
"unexpected subelement in css" s spos
1373 | Vclose
"css" -> { v
with f = doc
path origin pan
anchor c bookmarks
}
1374 | Vclose
_ -> parse_error
"unexpected close in css" s spos
1376 and pkeymap
ret keymap v t spos
_ =
1378 | Vdata
| Vcdata
-> v
1379 | Vend
-> parse_error
"unexpected end of input in keymap" s spos
1380 | Vopen
("map", attrs
, closed
) ->
1381 let r, l = map_of attrs
in
1382 let kss = fromstring keys_of_string spos
"in" r [] in
1383 let lss = fromstring keys_of_string spos
"out" l [] in
1387 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
1388 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
1391 then { v
with f = pkeymap
ret keymap }
1394 { v
with f = skip
"map" f }
1397 parse_error
"unexpected subelement in keymap" s spos
1399 | Vclose
"keymap" ->
1400 { v
with f = ret keymap }
1402 | Vclose
_ -> parse_error
"unexpected close in keymap" s spos
1404 and pbookmarks
path origin pan
anchor c bookmarks v t spos
_ =
1406 | Vdata
| Vcdata
-> v
1407 | Vend
-> parse_error
"unexpected end of input in bookmarks" s spos
1408 | Vopen
("item", attrs
, closed
) ->
1409 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
1410 let page = fromstring int_of_string spos
"page" spage
0
1411 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1412 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1414 (unentS titleent, 0, Oanchor
(page, rely
, visy
)) :: bookmarks
1417 then { v
with f = pbookmarks
path origin pan
anchor c bookmarks }
1420 { v
with f = skip
"item" f }
1423 parse_error
"unexpected subelement in bookmarks" s spos
1425 | Vclose
"bookmarks" ->
1426 { v
with f = doc
path origin pan
anchor c bookmarks }
1428 | Vclose
_ -> parse_error
"unexpected close in bookmarks" s spos
1430 and skip tag
f v t spos
_ =
1432 | Vdata
| Vcdata
-> v
1434 parse_error
("unexpected end of input in skipped " ^ tag
) s spos
1435 | Vopen
(tag'
, _, closed
) ->
1439 let f'
() = { v
with f = skip tag
f } in
1440 { v
with f = skip tag'
f'
}
1444 else parse_error
("unexpected close in skipped " ^ tag
) s spos
1447 parse
{ f = toplevel; accu
= () } s;
1451 let do_load f contents
=
1454 | Parser.Parse_error
(msg
, s, pos
) ->
1455 let subs = Parser.subs s pos
in
1456 Utils.error
"parse error: %s: at %d [..%S..]" msg pos
subs
1458 | exn
-> Utils.error
"parse error: %s" @@ exntos exn
1463 let xdgconfdir = Utils.getenvwithdef
"XDG_CONFIG_HOME" E.s in
1464 if emptystr
xdgconfdir
1467 let dir = Filename.concat
home ".config" in
1468 if Sys.is_directory
dir then dir else home
1472 Filename.concat
dir "llpp.conf"
1475 let confpath = ref defconfpath;;
1477 let load2 f default
=
1478 match filecontents
!confpath with
1479 | contents
-> f @@ do_load get contents
1480 | exception Unix.Unix_error
(Unix.ENOENT
, "open", _) ->
1481 f (Hashtbl.create
0, defconf)
1483 dolog
"error loading configuration from `%S': %s" !confpath @@ exntos exn
;
1487 let load1 f = load2 f false;;
1495 (fun path (conf, _, _, _, _) ((_, besttime
) as best
) ->
1496 if conf.lastvisit
> besttime
1497 then (path, conf.lastvisit
)
1500 (state.path, -.infinity
)
1504 let pc, pb
, px
, pa
, po
=
1506 let absname = abspath
state.path in
1507 Hashtbl.find h absname
1508 with Not_found
-> dc, [], 0, emptyanchor, state.origin
1512 state.bookmarks <- pb
;
1516 then state.anchor <- pa
;
1517 cbput state.hists
.nav pa
;
1525 Hashtbl.fold (fun path (pc, pb
, px
, pa
, po
) accu
->
1526 (path, pc, pb
, px
, pa
, po
) :: accu
)
1532 let add_attrs bb always
dc c time
=
1534 Buffer.add_string bb
"\n ";
1535 Printf.bprintf bb fmt
s
1537 let o c fmt
s = if c then o' fmt
s else ignore
in
1538 let ob s a
b = o (always
|| a
!= b) "%s='%b'" s a
1539 and op
s a
b = o (always
|| a
<> b) "%s='%b'" s (a
!= None
)
1540 and oi
s a
b = o (always
|| a
!= b) "%s='%d'" s a
1541 and oI
s a
b = o (always
|| a
!= b) "%s='%s'" s (string_with_suffix_of_int a
)
1542 and oz
s a
b = o (always
|| a
<> b) "%s='%g'" s (a
*.100.)
1543 and oF
s a
b = o (always
|| a
<> b) "%s='%f'" s a
1544 and oL
s a
b = o (always
|| a
<> b) "%s='%Ld'" s a
1545 and oc
s a
b = o (always
|| a
<> b) "%s='%s'" s (color_to_string a
)
1546 and oC
s a
b = o (always
|| a
<> b) "%s='%s'" s (CSTE.to_string a
)
1547 and oR
s a
b = o (always
|| a
<> b) "%s='%s'" s (irect_to_string a
)
1548 and oFm
s a
b = o (always
|| a
<> b) "%s='%s'" s (FMTE.to_string a
)
1549 and oSv
s a
b m
= o (always
|| a
<> b) "%s='%b'" s (a
land m
!= 0)
1550 and oPm
s a
b = o (always
|| a
<> b) "%s='%s'" s (MTE.to_string a
)
1552 o (always
|| a
<> b) "%s='%s'" s @@ Parser.enent a
0 (String.length a
)
1557 | Some
(_N
, _A
, _B
) -> o'
"%s='%u,%u,%u'" s _N _A _B
1561 | _ -> o'
"%s='none'" s
1571 else string_of_float
f
1578 | Cmulti
((n, a
, b), _) when n > 1 -> o'
"%s='%d,%d,%d'" s n a
b
1579 | Csplit
(n, _) when n > 1 -> o'
"%s='%d'" s ~
-n
1580 | Cmulti
_ | Csplit
_ | Csingle
_ -> ()
1585 | Some
c when c > 1 -> o'
"%s='%d'" s c
1588 oi
"width" c.cwinw
dc.cwinw
;
1589 oi
"height" c.cwinh
dc.cwinh
;
1590 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
1591 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
1592 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
1593 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
1594 ob "case-insensitive-search" c.icase
dc.icase
;
1595 ob "preload" c.preload
dc.preload
;
1596 oi
"page-bias" c.pagebias
dc.pagebias
;
1597 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
1598 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
1599 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
1600 ob "crop-hack" c.crophack
dc.crophack
;
1601 oW
"throttle" c.maxwait
dc.maxwait
;
1602 ob "highlight-links" c.hlinks
dc.hlinks
;
1603 ob "under-cursor-info" c.underinfo
dc.underinfo
;
1604 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
1605 oz
"zoom" c.zoom dc.zoom;
1606 ob "presentation" c.presentation
dc.presentation
;
1607 oi
"rotation-angle" c.angle
dc.angle
;
1608 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
1609 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
1610 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
1611 oi
"tex-count" c.texcount
dc.texcount
;
1612 oi
"slice-height" c.sliceheight
dc.sliceheight
;
1613 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
1614 ob "persistent-location" c.jumpback
dc.jumpback
;
1615 oc
"background-color" c.bgcolor
dc.bgcolor
;
1616 oi
"tile-width" c.tilew
dc.tilew
;
1617 oi
"tile-height" c.tileh
dc.tileh
;
1618 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
1619 ob "checkers" c.checkers
dc.checkers
;
1620 oi
"aalevel" c.aalevel
dc.aalevel
;
1621 ob "trim-margins" c.trimmargins
dc.trimmargins
;
1622 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
1623 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
1624 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
1625 oC
"color-space" c.colorspace
dc.colorspace
;
1626 ob "invert-colors" c.invert
dc.invert
;
1627 oF
"brightness" c.colorscale
dc.colorscale
;
1628 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
1629 oco
"columns" c.columns
dc.columns
;
1630 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
1631 os
"selection-command" c.selcmd
dc.selcmd
;
1632 os
"synctex-command" c.stcmd
dc.stcmd
;
1633 os
"pax-command" c.paxcmd
dc.paxcmd
;
1634 os
"askpass-command" c.passcmd
dc.passcmd
;
1635 os
"savepath-command" c.savecmd
dc.savecmd
;
1636 ob "update-cursor" c.updatecurs
dc.updatecurs
;
1637 oi
"hint-font-size" c.hfsize
dc.hfsize
;
1638 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
1639 oF
"page-scroll-scale" c.pgscale
dc.pgscale
;
1640 ob "use-pbo" c.usepbo
dc.usepbo
;
1641 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
1642 ob "remote-in-a-new-instance" c.riani
dc.riani
;
1643 op
"point-and-x" c.pax
dc.pax
;
1644 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
1645 ob "scroll-bar-on-the-left" c.leftscroll
dc.leftscroll
;
1647 then os
"title" c.title
dc.title
;
1648 oL
"last-visit" (Int64.of_float time
) 0L;
1649 ob "edit-annotations-inline" c.annotinline
dc.annotinline
;
1650 ob "coarse-presentation-positioning" c.coarseprespos
dc.coarseprespos
;
1651 ob "use-document-css" c.usedoccss
dc.usedoccss
;
1654 let keymapsbuf always
dc c =
1656 let bb = create
16 in
1657 let rec loop = function
1659 | (modename, h) :: rest
->
1660 let dh = findkeyhash dc modename in
1661 if always
|| h <> dh
1663 if Hashtbl.length
h > 0
1665 if length
bb > 0 then add_char
bb '
\n'
;
1666 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
1667 Hashtbl.iter
(fun i
o ->
1668 if always
|| match Hashtbl.find dh i
1669 with | dO
-> dO
<> o | exception Not_found
-> false
1672 if Wsi.withctrl m
then add_string
bb "ctrl-";
1673 if Wsi.withalt m
then add_string
bb "alt-";
1674 if Wsi.withshift m
then add_string
bb "shift-";
1675 if Wsi.withmeta m
then add_string
bb "meta-";
1676 add_string
bb (Wsi.keyname
k);
1679 let rec loop = function
1681 | km
:: [] -> addkm km
1682 | km
:: rest
-> addkm km
; add_char
bb ' '
; loop rest
1686 add_string
bb "<map in='";
1690 add_string
bb "' out='"; addkm km
; add_string
bb "'/>\n"
1693 add_string
bb "' out='"; addkms kms
; add_string
bb "'/>\n"
1695 | KMmulti
(ins
, kms
) ->
1696 add_char
bb ' '
; addkms ins
; add_string
bb "' out='";
1697 addkms kms
; add_string
bb "'/>\n"
1699 add_string
bb "</keymap>";
1708 let keystostrlist c =
1709 let rec loop accu
= function
1711 | (modename, h) :: rest
->
1713 if Hashtbl.length
h > 0
1715 let accu = Printf.sprintf
"\xc2\xb7Keys for %s" modename :: accu in
1716 Hashtbl.fold (fun i
o a
->
1717 let bb = Buffer.create
10 in
1719 if Wsi.withctrl m
then Buffer.add_string
bb "ctrl-";
1720 if Wsi.withalt m
then Buffer.add_string
bb "alt-";
1721 if Wsi.withshift m
then Buffer.add_string
bb "shift-";
1722 if Wsi.withmeta m
then Buffer.add_string
bb "meta-";
1723 Buffer.add_string
bb (Wsi.keyname
k);
1726 let rec loop = function
1728 | km
:: [] -> addkm km
1730 addkm km
; Buffer.add_char
bb ' '
;
1736 Buffer.add_char
bb '
\t'
;
1744 | KMmulti
(ins
, kms
) ->
1745 Buffer.add_char
bb ' '
;
1747 Buffer.add_string
bb "\t";
1750 Buffer.contents
bb :: a
1760 let save1 bb leavebirdseye x
h dc =
1761 let uifontsize = fstate.fontsize
in
1762 let dc = if conf.bedefault
then conf else dc in
1763 Buffer.add_string
bb "<llppconfig>\n";
1765 if nonemptystr
!fontpath
1767 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
1773 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
1776 Buffer.add_string
bb "<defaults";
1777 add_attrs bb true dc dc nan
;
1778 let kb = keymapsbuf true dc dc in
1779 if Buffer.length
kb > 0
1781 Buffer.add_string
bb ">\n";
1782 Buffer.add_buffer
bb kb;
1783 Buffer.add_string
bb "\n</defaults>\n";
1785 else Buffer.add_string
bb "/>\n";
1787 let adddoc path pan
anchor c bookmarks time origin
=
1788 if bookmarks == [] && c = dc && anchor = emptyanchor
1791 Printf.bprintf
bb "<doc path='%s'"
1792 (Parser.enent
path 0 (String.length
path));
1794 if nonemptystr origin
1795 then Printf.bprintf
bb "\n origin='%s'"
1796 (Parser.enent origin
0 (String.length origin
));
1798 if anchor <> emptyanchor
1800 let n, rely
, visy
= anchor in
1801 Printf.bprintf
bb "\n page='%d'" n;
1804 then Printf.bprintf
bb " rely='%f'" rely
;
1806 if abs_float visy
> 1e-6
1807 then Printf.bprintf
bb " visy='%f'" visy
;
1811 then Printf.bprintf
bb " pan='%d'" pan
;
1813 add_attrs bb false dc c time
;
1814 if nonemptystr
c.css
1815 then Printf.bprintf
bb ">\n <css><![CDATA[%s]]></css>" c.css
;
1816 let kb = keymapsbuf false dc c in
1818 begin match bookmarks with
1820 if Buffer.length
kb > 0
1822 Buffer.add_string
bb ">\n";
1823 Buffer.add_buffer
bb kb;
1824 Buffer.add_string
bb "\n</doc>\n";
1827 if nonemptystr
c.css
1828 then Buffer.add_string
bb "\n</doc>\n"
1829 else Buffer.add_string
bb "/>\n"
1831 Buffer.add_string
bb ">\n<bookmarks>\n";
1832 List.iter
(fun (title
, _, kind
) ->
1833 begin match kind
with
1834 | Oanchor
(page, rely
, visy
) ->
1836 "<item title='%s' page='%d'"
1837 (Parser.enent title
0 (String.length title
))
1842 Printf.bprintf
bb " rely='%f'" rely
1844 if abs_float visy
> 1e-6
1846 Printf.bprintf
bb " visy='%f'" visy
1848 | Ohistory
_ | Onone
| Ouri
_ | Oremote
_
1849 | Oremotedest
_ | Olaunch
_ ->
1850 failwith
"unexpected link in bookmarks"
1852 Buffer.add_string
bb "/>\n";
1854 Buffer.add_string
bb "</bookmarks>";
1855 if Buffer.length
kb > 0
1857 Buffer.add_string
bb "\n";
1858 Buffer.add_buffer
bb kb;
1860 Buffer.add_string
bb "\n</doc>\n";
1866 match state.mode
with
1867 | Birdseye
(c, pan, _, _, _) ->
1869 match conf.columns
with
1870 | Cmulti
((c, _, _), _) -> Some
c
1874 match c.columns
with
1875 | Cmulti
(c, _) -> Cmulti
(c, E.a
)
1876 | Csingle
_ -> Csingle
E.a
1877 | Csplit
_ -> failwith
"quit from bird's eye while split"
1879 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
1882 | LinkNav
_ -> x
, conf
1884 let docpath = if nonemptystr
state.path then abspath
state.path else E.s in
1885 if nonemptystr
docpath
1887 adddoc docpath pan (getanchor ())
1889 let autoscrollstep =
1890 match state.autoscroll
with
1892 | None
-> conf.autoscrollstep
1894 begin match state.mode
with
1895 | Birdseye beye
-> leavebirdseye beye
true
1900 { conf with autoscrollstep = autoscrollstep }
1902 (if conf.savebmarks
then state.bookmarks else [])
1906 Hashtbl.iter
(fun path (c, bookmarks, x
, anchor, origin
) ->
1907 if docpath <> abspath
path
1908 then adddoc path x
anchor c bookmarks c.lastvisit origin
1910 Buffer.add_string
bb "</llppconfig>\n";
1914 let save leavebirdseye
=
1915 let relx = float state.x
/. float state.winw
in
1917 let cx w = truncate
(relx *. float w) in
1919 (fun (w, h, x
) ws
->
1921 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
1922 | Wsi.MaxVert
-> (w, conf.cwinh
, x
)
1923 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
1925 (state.winw
, state.winh
, state.x
) state.winstate
1929 let bb = Buffer.create
32768 in
1931 save1 bb leavebirdseye x
h dc
1933 if load1 save2 && Buffer.length
bb > 0
1936 let tmp = !confpath ^
".tmp" in
1937 let oc = open_out_bin
tmp in
1938 Buffer.output_buffer
oc bb;
1940 Unix.rename
tmp !confpath;
1942 dolog
"error saving configuration: %s" @@ exntos exn
1947 (* This here has a potential of rising SIGPIPE, silently and
1948 seemingly harmlessly (when -gc was supplied an invalid
1949 executable for instance) probably needs revisiting *)
1950 let n'
= Unix.write fd
(Bytes.of_string s) 0 n in
1952 then Utils.error
"Unix.write %d = %d" n n'
1954 let href = ref (Hashtbl.create
0) in
1955 let cref = ref defconf in
1957 let f path (pc, _pb
, _px
, _pa
, _po
) =
1959 Printf.sprintf
"%s\000%ld\000" path (Int32.of_float
pc.lastvisit
)
1961 wr s (String.length
s)
1968 ignore
(load1 push);
1969 Unix.shutdown fd
Unix.SHUTDOWN_SEND
;
1970 let s = fdcontents fd
in
1972 match String.index_from
s ppos '
\000'
with
1973 | exception Not_found
-> ()
1975 match String.index_from
s (zpos1
+1) '
\000'
with
1976 | exception Not_found
-> error
"invalid gc input in (%S) at %d" s zpos1
1978 let okey = StringLabels.sub
s ~pos
:ppos ~len
:(zpos1
-ppos
) in
1979 let nkey = StringLabels.sub
s ~pos
:(zpos1
+1) ~len
:(zpos2
-zpos1
-1) in
1981 then (Hashtbl.remove
!href okey; f (zpos2
+1))
1983 match Hashtbl.find !href okey with
1984 | exception Not_found
-> Utils.error
"gc: cannot find %S" okey
1986 Hashtbl.remove
!href okey;
1987 Hashtbl.replace
!href nkey v;
1991 let bb = Buffer.create
32768 in
1992 let save2 (_h
, dc) = save1 bb (fun _ _ -> ()) 0 !href dc in
1993 if load1 save2 && Buffer.length
bb > 0
1996 let tmp = !confpath ^
".tmp" in
1997 let oc = open_out_bin
tmp in
1998 Buffer.output_buffer
oc bb;
2000 Unix.rename
tmp !confpath;
2002 dolog
"error saving configuration: %s" @@ exntos exn
2006 let logcurrently = function
2007 | Idle
-> dolog
"Idle"
2008 | Loading
(l, gen
) ->
2009 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
2010 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col
, row
, tilew
, tileh
) ->
2012 "Tiling %d[%d,%d] page=%s cs=%s angle=%d"
2013 l.pageno col row
(~
> pageopaque
)
2014 (CSTE.to_string colorspace
) angle
;
2015 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2016 angle gen
conf.angle
state.gen
2018 conf.tilew
conf.tileh
;