3 external fz_version
: unit -> string = "ml_fz_version";;
6 { mutable fontsize
: int
7 ; mutable wwidth
: float
8 ; mutable maxrows
: int
13 { fontsize
= 20 * Wsi.fontsizefactor
()
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
172 method scroll
: int -> int -> uioh
173 method zoom
: float -> int -> int -> unit
176 module type TextEnumType
=
180 val names
: string array
183 module TextEnumMake
(Ten
: TextEnumType
) =
185 let names = Ten.names;;
186 let to_int (t
: Ten.t
) = Obj.magic t
;;
187 let to_string t
= names.(to_int t
);;
188 let of_int n
: Ten.t
= Obj.magic n
;;
191 if i
= Array.length
names
192 then failwith
("invalid " ^
Ten.name ^
": " ^ s
)
201 module CSTE
= TextEnumMake
(struct
202 type t
= colorspace
;;
203 let name = "colorspace";;
204 let names = [|"rgb"; "bgr"; "gray"|];;
207 module MTE
= TextEnumMake
(struct
210 let names = [|"page"; "block"; "line"; "word"|];;
213 module FMTE
= TextEnumMake
(struct
215 let name = "fitmodel";;
216 let names = [|"width"; "proportional"; "page"|];;
220 { mutable scrollbw
: int
221 ; mutable scrollh
: int
222 ; mutable scrollb
: scrollb
223 ; mutable icase
: bool
224 ; mutable preload
: bool
225 ; mutable pagebias
: int
226 ; mutable verbose
: bool
227 ; mutable debug
: bool
228 ; mutable scrollstep
: int
229 ; mutable hscrollstep
: int
230 ; mutable maxhfit
: bool
231 ; mutable crophack
: bool
232 ; mutable autoscrollstep
: int
233 ; mutable maxwait
: float option
234 ; mutable hlinks
: bool
235 ; mutable underinfo
: bool
236 ; mutable interpagespace
: interpagespace
237 ; mutable zoom
: float
238 ; mutable presentation
: bool
239 ; mutable angle
: angle
240 ; mutable cwinw
: int
241 ; mutable cwinh
: int
242 ; mutable savebmarks
: bool
243 ; mutable fitmodel
: fitmodel
244 ; mutable trimmargins
: trimmargins
245 ; mutable trimfuzz
: irect
246 ; mutable memlimit
: memsize
247 ; mutable texcount
: texcount
248 ; mutable sliceheight
: sliceheight
249 ; mutable thumbw
: width
250 ; mutable jumpback
: bool
251 ; mutable bgcolor
: (float * float * float)
252 ; mutable bedefault
: bool
253 ; mutable tilew
: int
254 ; mutable tileh
: int
255 ; mutable mustoresize
: memsize
256 ; mutable checkers
: bool
257 ; mutable aalevel
: int
258 ; mutable urilauncher
: string
259 ; mutable pathlauncher
: string
260 ; mutable colorspace
: colorspace
261 ; mutable invert
: bool
262 ; mutable colorscale
: float
263 ; mutable ghyllscroll
: (int * int * int) option
264 ; mutable columns
: columns
265 ; mutable beyecolumns
: columncount
option
266 ; mutable selcmd
: string
267 ; mutable paxcmd
: string
268 ; mutable passcmd
: string
269 ; mutable savecmd
: string
270 ; mutable updatecurs
: bool
271 ; mutable keyhashes
: (string * keyhash
) list
272 ; mutable hfsize
: int
273 ; mutable pgscale
: float
274 ; mutable usepbo
: bool
275 ; mutable wheelbypage
: bool
276 ; mutable stcmd
: string
277 ; mutable riani
: bool
278 ; mutable pax
: (float * int * int) ref option
279 ; mutable paxmark
: mark
280 ; mutable leftscroll
: bool
281 ; mutable title
: string
282 ; mutable lastvisit
: float
283 ; mutable annotinline
: bool
284 ; mutable coarseprespos
: bool
286 ; mutable usedoccss
: usedoccss
289 | Csingle
of singlecolumn
290 | Cmulti
of multicolumns
291 | Csplit
of splitcolumns
296 | Olaunch
of launchcommand
297 | Oremote
of (filename
* pageno
)
298 | Oremotedest
of (filename
* destname
)
299 | Ohistory
of (filename
* conf
* outline list
* x
* anchor
* filename
)
300 and outline
= (caption
* outlinelevel
* outlinekind
)
301 and outlinelevel
= int
319 type tile
= opaque
* pixmapsize
* elapsed
320 and elapsed
= float;;
321 type pagemapkey
= pageno
* gen
;;
322 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
327 | Loading
of (page
* gen
)
329 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
331 | Outlining
of outline list
334 type mpos
= int * int
336 | Msel
of (mpos
* mpos
)
338 | Mscrolly
| Mscrollx
339 | Mzoom
of (buttonno
* step
* mpos
)
340 | Mzoomrect
of (mpos
* mpos
)
347 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
348 | Textentry
of (textentry
* onleave
)
350 | LinkNav
of linktarget
351 and onleave
= leavetextentrystatus
-> unit
352 and leavetextentrystatus
= | Cancel
| Confirm
353 and helpitem
= string * int * action
356 | Action
of (uioh
-> uioh
)
358 | Ltexact
of (pageno
* direction
)
359 | Ltgendir
of direction
360 | Ltnotready
of (pageno
* direction
)
361 and direction
= int (* -1, 0, 1 *)
362 and textentry
= string * string * onhist
option
363 * onkey
* ondone
* cancelonempty
364 and onkey
= string -> Keys.t
-> te
365 and ondone
= string -> unit
366 and histcancel
= unit -> unit
367 and onhist
= ((histcmd
-> string) * histcancel
)
368 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
369 and cancelonempty
= bool
374 | TEswitch
of textentry
386 { mutable ss
: Unix.file_descr
387 ; mutable wsfd
: Unix.file_descr
388 ; mutable stderr
: Unix.file_descr
389 ; mutable errmsgs
: Buffer.t
390 ; mutable newerrmsgs
: bool
394 ; mutable anchor
: anchor
395 ; mutable ranchors
: (string * string * anchor
* string) list
397 ; mutable layout
: page list
398 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
399 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
400 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
401 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
402 ; mutable pagecount
: int
403 ; mutable currently
: currently
404 ; mutable mstate
: mstate
405 ; mutable searchpattern
: string
406 ; mutable rects
: (pageno
* rectcolor
* rect
) list
407 ; mutable rects1
: (pageno
* rectcolor
* rect
) list
408 ; prects
: (pageno
, float array
) Hashtbl.t
409 ; mutable text
: string
410 ; mutable winstate
: Wsi.winstate list
411 ; mutable mode
: mode
412 ; mutable uioh
: uioh
413 ; mutable outlines
: outline array
414 ; mutable bookmarks
: outline list
415 ; mutable path
: string
416 ; mutable password
: string
417 ; mutable nameddest
: string
418 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
419 ; mutable memused
: memsize
421 ; mutable throttle
: (page list
* int * float) option
422 ; mutable autoscroll
: int option
423 ; mutable ghyll
: (int option -> unit)
424 ; mutable help
: helpitem array
425 ; mutable docinfo
: (int * string) list
426 ; mutable checkerstexid
: GlTex.texture_id
option
428 ; mutable prevzoom
: (float * int)
429 ; mutable progress
: float
430 ; mutable redisplay
: bool
431 ; mutable mpos
: mpos
432 ; mutable keystate
: keystate
433 ; mutable glinks
: bool
434 ; mutable prevcolumns
: (columns
* float) option
437 ; mutable reprf
: (unit -> unit)
438 ; mutable origin
: string
439 ; mutable roam
: (unit -> unit)
440 ; mutable bzoom
: bool
441 ; mutable traw
: [`
float] Raw.t
442 ; mutable vraw
: [`
float] Raw.t
443 ; mutable lnava
: (pageno
* linkno
) option
444 ; mutable slideshow
: int
447 { pat
: string circbuf
448 ; pag
: string circbuf
449 ; nav
: anchor circbuf
450 ; sel
: string circbuf
454 let emptyanchor = (0, 0.0, 0.0);;
455 let emptykeyhash = Hashtbl.create
0;;
457 let noreprf () = ();;
460 let nouioh : uioh
= object (self
)
462 method key _ _
= self
463 method multiclick _ _ _ _
= self
464 method button _ _ _ _ _
= self
465 method motion _ _
= self
466 method pmotion _ _
= self
467 method infochanged _
= ()
468 method scrollpw
= (0, nan
, nan
)
469 method scrollph
= (0, nan
, nan
)
470 method modehash
= emptykeyhash
471 method eformsgs
= false
472 method alwaysscrolly
= false
473 method scroll _ _
= self
474 method zoom _ _ _
= ()
477 let platform_to_string = function
478 | Punknown
-> "unknown"
483 | Pcygwin
-> "Cygwin"
487 Printf.sprintf
"llpp version %s, fitz %s, ocaml %s/%d bit"
488 Help.version (fz_version
()) Sys.ocaml_version
Sys.word_size
494 ; scrollb
= scrollbhv lor scrollbvv
510 ; presentation
= false
515 ; fitmodel
= FitProportional
516 ; trimmargins
= false
517 ; trimfuzz
= (0,0,0,0)
518 ; memlimit
= 32 lsl 20
523 ; bgcolor
= (0.5, 0.5, 0.5)
527 ; mustoresize
= 256 lsl 20
532 | Plinux
| Psun
| Pbsd
-> "xdg-open \"%s\""
533 | Posx
-> "open \"%s\""
534 | Pcygwin
-> "cygstart \"%s\""
535 | Punknown
-> "echo %s")
536 ; pathlauncher
= "lp \"%s\""
539 | Plinux
| Pbsd
| Psun
-> "xsel -i"
550 ; columns
= Csingle
[||]
553 ; hfsize
= 12 * Wsi.fontsizefactor
()
556 ; wheelbypage
= false
557 ; stcmd
= "echo SyncTex"
560 ; paxmark
= Mark_word
565 ; coarseprespos
= false
569 let mk n
= (n
, Hashtbl.create
1) in
583 let conf = { defconf with angle
= defconf.angle
};;
586 let command = Str.global_replace percentsre url
conf.urilauncher
in
587 try ignore
@@ spawn
command []
588 with exn
-> dolog
"failed to execute `%s': %s" command @@ exntos exn
592 if emptystr
conf.urilauncher
595 match geturl uri
with
596 | "" -> dolog
"obtained empty url from uri %S" uri
603 :: "(searching in this text works just by typing (i.e. no initial '/'))"
608 | "" -> (s
, 0, Noaction
)
609 | url
-> (s
, 0, Action
(fun uioh
-> gotourl url
; uioh
))
614 { store
= Array.make n v
621 let cbcap b
= Array.length b
.store
;;
626 b
.wc
<- (b
.wc
+ 1) mod cap;
628 b
.len
<- min
(b
.len
+ 1) cap;
631 let cbempty b
= b
.len
= 0;;
633 let cbgetg b circular dir
=
637 let rc = b
.rc + dir
in
649 else bound
rc 0 (b
.len
-1)
655 let cbget b
= cbgetg b
false;;
656 let cbgetc b
= cbgetg b
true;;
661 ; stderr
= Unix.stderr
662 ; errmsgs
= Buffer.create
0
667 ; anchor
= emptyanchor
671 ; tilelru
= Queue.create
()
672 ; pagemap
= Hashtbl.create
10
673 ; tilemap
= Hashtbl.create
10
680 ; prects
= Hashtbl.create
1
684 ; searchpattern
= E.s
692 { nav
= cbnew 10 emptyanchor
704 ; checkerstexid
= None
705 ; prevzoom
= (1.0, 0)
719 ; traw
= Raw.create_static `
float ~len
:8
720 ; vraw
= Raw.create_static `
float ~len
:8
726 let copykeyhashes c
=
727 List.map
(fun (k
, v
) -> k
, Hashtbl.copy v
) c
.keyhashes
;
731 let d = state.winh
- h
in
732 max
conf.interpagespace
((d + 1) / 2)
735 let rowyh (c
, coverA
, coverB
) b n
=
736 if c
= 1 || (n
< coverA
|| n
>= state.pagecount
- coverB
)
738 let _, _, vy
, (_, _, h
, _) = b
.(n
) in
741 let n'
= n - coverA
in
744 let e = min
state.pagecount
(s + c
) in
745 let rec find m miny maxh
= if m
= e then miny
, maxh
else
746 let _, _, y
, (_, _, h
, _) = b
.(m
) in
747 let miny = min
miny y
in
748 let maxh = max
maxh h
in
754 let ((c
, coverA
, coverB
) as cl
), b
=
755 match conf.columns
with
756 | Csingle b
-> (1, 0, 0), b
757 | Cmulti
(c
, b
) -> c
, b
758 | Csplit
(_, b
) -> (1, 0, 0), b
760 if Array.length b
= 0
763 let rec bsearch nmin nmax
=
765 then bound nmin
0 (state.pagecount
-1)
767 let n = (nmax
+ nmin
) / 2 in
768 let vy, h
= rowyh cl b
n in
772 let ips = calcips h
in
774 let y1 = vy + h
+ ips in
778 then 0, vy + h
+ conf.interpagespace
780 let y0 = vy - conf.interpagespace
in
781 y0, y0 + h
+ conf.interpagespace
791 if n < state.pagecount
- coverB
792 then ((n-coverA
)/c
)*c
+ coverA
799 then bsearch (n+1) nmax
800 else bsearch nmin
(n-1)
803 bsearch 0 (state.pagecount
-1);
807 match conf.columns
with
808 | Cmulti
((_, _, _) as cl
, b
) ->
809 if Array.length b
> 0
811 let y, h
= rowyh cl 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
818 y + h
+ (if conf.presentation
then calcips h
else 0)
821 if Array.length b
> 0
823 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
828 let getpageywh pageno
=
829 let pageno = bound
pageno 0 (state.pagecount
-1) in
830 match conf.columns
with
832 if Array.length b
= 0
835 let (_, _, y, (_, w
, h
, _)) = b
.(pageno) in
843 if Array.length b
= 0
846 let y, h
= rowyh cl b
pageno in
847 let (_, _, _, (_, w
, _, _)) = b
.(pageno) in
855 if Array.length b
= 0
859 let (_, _, y, (_, w
, h
, _)) = b
.(n) in
863 let getpageyh pageno =
864 let y,_,h
= getpageywh pageno in
868 let getpagedim pageno =
871 | (n, _, _, _) as pdim
:: rest
->
873 then (if n = pageno then pdim
else ppdim
)
878 f (-1, -1, -1, -1) state.pdims
881 let getpdimno pageno =
885 | (n, _, _, _) :: rest
->
887 then (if n = pageno then np else p
)
895 let getpagey pageno = fst
(getpageyh pageno);;
899 let coloff = l
.pagecol
* l
.pageh
in
900 float (l
.pagey
+ coloff) /. float l
.pageh
908 then float l
.pagedispy
/. float (calcips l
.pageh
)
909 else float l
.pagedispy
/. float conf.interpagespace
912 (l
.pageno, top, dtop)
916 match state.layout
with
917 | l
:: _ -> getanchor1 l
919 let n = page_of_y state.y in
923 let y, h
= getpageyh n in
924 let dy = y - state.y in
928 let ips = calcips h
in
929 float (dy + ips) /. float ips
931 float dy /. float conf.interpagespace
936 let fontpath = ref E.s;;
938 type historder
= [ `lastvisit
| `title
| `path
| `file
];;
941 Map.Make
(struct type t
= (int * int) let compare = compare end);;
944 let l = String.length
s in
945 let b = Buffer.create
l in
946 Parser.unent
b s 0 l;
951 try Sys.getenv
"HOME"
953 dolog
"cannot determine home directory location: %s" @@ exntos exn
;
957 let modifier_of_string = function
958 | "alt" -> Wsi.altmask
959 | "shift" -> Wsi.shiftmask
960 | "ctrl" | "control" -> Wsi.ctrlmask
961 | "meta" -> Wsi.metamask
965 let keys_of_string s =
966 let key_of_string r
s =
967 let elems = Str.full_split r
s in
970 let m1 = modifier_of_string s in
972 then (Wsi.namekey
s, m
)
975 | Str.Delim
s when n land 1 = 0 -> g s
977 | Str.Delim
_ -> (k
, m
)
979 let rec loop n k m
= function
982 let k, m
= f n k m x
in
987 let elems = Str.split whitere
s in
988 List.map
(key_of_string (Str.regexp
"-")) elems
991 let config_of c attrs
=
995 | "scroll-bar-width" -> { c
with scrollbw
= max
0 (int_of_string v
) }
996 | "scroll-handle-height" -> { c
with scrollh
= max
0 (int_of_string v
) }
997 | "case-insensitive-search" -> { c
with icase
= bool_of_string v
}
998 | "preload" -> { c
with preload
= bool_of_string v
}
999 | "page-bias" -> { c
with pagebias
= int_of_string v
}
1000 | "scroll-step" -> { c
with scrollstep
= max
1 (int_of_string v
) }
1001 | "horizontal-scroll-step" ->
1002 { c
with hscrollstep
= max
(int_of_string v
) 1 }
1003 | "auto-scroll-step" ->
1004 { c
with autoscrollstep
= max
0 (int_of_string v
) }
1005 | "max-height-fit" -> { c
with maxhfit
= bool_of_string v
}
1006 | "crop-hack" -> { c
with crophack
= bool_of_string v
}
1009 match String.map asciilower v
with
1010 | "true" -> Some infinity
1012 | f -> Some
(float_of_string
f)
1014 { c
with maxwait
= mw }
1015 | "highlight-links" -> { c
with hlinks
= bool_of_string v
}
1016 | "under-cursor-info" -> { c
with underinfo
= bool_of_string v
}
1017 | "vertical-margin" ->
1018 { c
with interpagespace
= max
0 (int_of_string v
) }
1020 let zoom = float_of_string v
/. 100. in
1021 let zoom = max
zoom 0.0 in
1022 { c
with zoom = zoom }
1023 | "presentation" -> { c
with presentation
= bool_of_string v
}
1024 | "rotation-angle" -> { c
with angle
= int_of_string v
}
1025 | "width" -> { c
with cwinw
= max
20 (int_of_string v
) }
1026 | "height" -> { c
with cwinh
= max
20 (int_of_string v
) }
1027 | "persistent-bookmarks" -> { c
with savebmarks
= bool_of_string v
}
1028 | "proportional-display" ->
1031 then FitProportional
1034 { c
with fitmodel
= fm }
1035 | "fit-model" -> { c
with fitmodel
= FMTE.of_string v
}
1036 | "pixmap-cache-size" ->
1037 { c
with memlimit
= max
2 (int_of_string_with_suffix v
) }
1038 | "tex-count" -> { c
with texcount
= max
1 (int_of_string v
) }
1039 | "slice-height" -> { c
with sliceheight
= max
2 (int_of_string v
) }
1040 | "thumbnail-width" -> { c
with thumbw
= max
2 (int_of_string v
) }
1041 | "persistent-location" -> { c
with jumpback
= bool_of_string v
}
1042 | "background-color" -> { c
with bgcolor
= color_of_string v
}
1043 | "tile-width" -> { c
with tilew
= max
2 (int_of_string v
) }
1044 | "tile-height" -> { c
with tileh
= max
2 (int_of_string v
) }
1045 | "mupdf-store-size" ->
1046 { c
with mustoresize
= max
1024 (int_of_string_with_suffix v
) }
1047 | "checkers" -> { c
with checkers
= bool_of_string v
}
1048 | "aalevel" -> { c
with aalevel
= max
0 (int_of_string v
) }
1049 | "trim-margins" -> { c
with trimmargins
= bool_of_string v
}
1050 | "trim-fuzz" -> { c
with trimfuzz
= irect_of_string v
}
1051 | "uri-launcher" -> { c
with urilauncher
= unentS v
}
1052 | "path-launcher" -> { c
with pathlauncher
= unentS v
}
1053 | "color-space" -> { c
with colorspace
= CSTE.of_string v
}
1054 | "invert-colors" -> { c
with invert
= bool_of_string v
}
1055 | "brightness" -> { c
with colorscale
= float_of_string v
}
1056 | "ghyllscroll" -> { c
with ghyllscroll
= ghyllscroll_of_string v
}
1058 let (n, _, _) as nab
= multicolumns_of_string v
in
1060 then { c
with columns
= Csplit
(-n, E.a
) }
1061 else { c
with columns
= Cmulti
(nab
, E.a
) }
1062 | "birds-eye-columns" ->
1063 { c
with beyecolumns
= Some
(max
(int_of_string v
) 2) }
1064 | "selection-command" -> { c
with selcmd
= unentS v
}
1065 | "synctex-command" -> { c
with stcmd
= unentS v
}
1066 | "pax-command" -> { c
with paxcmd
= unentS v
}
1067 | "askpass-command" -> { c
with passcmd
= unentS v
}
1068 | "savepath-command" -> { c
with savecmd
= unentS v
}
1069 | "update-cursor" -> { c
with updatecurs
= bool_of_string v
}
1070 | "hint-font-size" -> { c
with hfsize
= bound
(int_of_string v
) 5 100 }
1071 | "page-scroll-scale" -> { c
with pgscale
= float_of_string v
}
1072 | "use-pbo" -> { c
with usepbo
= bool_of_string v
}
1073 | "wheel-scrolls-pages" -> { c
with wheelbypage
= bool_of_string v
}
1074 | "horizontal-scrollbar-visible" ->
1077 then c
.scrollb
lor scrollbhv
1078 else c
.scrollb
land (lnot
scrollbhv)
1080 { c
with scrollb
= b }
1081 | "vertical-scrollbar-visible" ->
1084 then c
.scrollb
lor scrollbvv
1085 else c
.scrollb
land (lnot
scrollbvv)
1087 { c
with scrollb
= b }
1088 | "remote-in-a-new-instance" -> { c
with riani
= bool_of_string v
}
1092 then Some
(ref (0.0, 0, 0))
1094 | "point-and-x-mark" -> { c
with paxmark
= MTE.of_string v
}
1095 | "scroll-bar-on-the-left" -> { c
with leftscroll
= bool_of_string v
}
1096 | "title" -> { c
with title
= unentS v
}
1097 | "last-visit" -> { c
with lastvisit
= float_of_string v
}
1098 | "edit-annotations-inline" -> { c
with annotinline
= bool_of_string v
}
1099 | "coarse-presentation-positioning" ->
1100 { c
with coarseprespos
= bool_of_string v
}
1101 | "use-document-css" -> { c
with usedoccss
= bool_of_string v
}
1104 dolog
"error processing attribute (`%S' = `%S'): %s" k v
@@ exntos exn
;
1107 let rec fold c
= function
1110 let c = apply c k v
in
1113 fold { c with keyhashes
= copykeyhashes c } attrs
;
1116 let fromstring f pos
n v
d =
1119 dolog
"error processing attribute (%S=%S) at %d\n%s" n v pos
@@ exntos exn
;
1123 let bookmark_of attrs
=
1124 let rec fold title page rely visy
= function
1125 | ("title", v
) :: rest
-> fold v page rely visy rest
1126 | ("page", v
) :: rest
-> fold title v rely visy rest
1127 | ("rely", v
) :: rest
-> fold title page v visy rest
1128 | ("visy", v
) :: rest
-> fold title page rely v rest
1129 | _ :: rest
-> fold title page rely visy rest
1130 | [] -> title
, page
, rely
, visy
1132 fold "invalid" "0" "0" "0" attrs
1136 let rec fold path page rely pan visy origin
= function
1137 | ("path", v
) :: rest
-> fold v page rely pan visy origin rest
1138 | ("page", v
) :: rest
-> fold path v rely pan visy origin rest
1139 | ("rely", v
) :: rest
-> fold path page v pan visy origin rest
1140 | ("pan", v
) :: rest
-> fold path page rely v visy origin rest
1141 | ("visy", v
) :: rest
-> fold path page rely pan v origin rest
1142 | ("origin", v
) :: rest
-> fold path page rely pan visy v rest
1143 | _ :: rest
-> fold path page rely pan visy origin rest
1144 | [] -> path
, page
, rely
, pan
, visy
, origin
1146 fold E.s "0" "0" "0" "0" E.s attrs
1150 let rec fold rs ls
= function
1151 | ("out", v
) :: rest
-> fold v ls rest
1152 | ("in", v
) :: rest
-> fold rs v rest
1153 | _ :: rest
-> fold ls rs rest
1159 let setconf dst src
=
1160 dst
.scrollbw
<- src
.scrollbw
;
1161 dst
.scrollh
<- src
.scrollh
;
1162 dst
.icase
<- src
.icase
;
1163 dst
.preload
<- src
.preload
;
1164 dst
.pagebias
<- src
.pagebias
;
1165 dst
.verbose
<- src
.verbose
;
1166 dst
.scrollstep
<- src
.scrollstep
;
1167 dst
.maxhfit
<- src
.maxhfit
;
1168 dst
.crophack
<- src
.crophack
;
1169 dst
.autoscrollstep
<- src
.autoscrollstep
;
1170 dst
.maxwait
<- src
.maxwait
;
1171 dst
.hlinks
<- src
.hlinks
;
1172 dst
.underinfo
<- src
.underinfo
;
1173 dst
.interpagespace
<- src
.interpagespace
;
1174 dst
.zoom <- src
.zoom;
1175 dst
.presentation
<- src
.presentation
;
1176 dst
.angle
<- src
.angle
;
1177 dst
.cwinw
<- src
.cwinw
;
1178 dst
.cwinh
<- src
.cwinh
;
1179 dst
.savebmarks
<- src
.savebmarks
;
1180 dst
.memlimit
<- src
.memlimit
;
1181 dst
.fitmodel
<- src
.fitmodel
;
1182 dst
.texcount
<- src
.texcount
;
1183 dst
.sliceheight
<- src
.sliceheight
;
1184 dst
.thumbw
<- src
.thumbw
;
1185 dst
.jumpback
<- src
.jumpback
;
1186 dst
.bgcolor
<- src
.bgcolor
;
1187 dst
.tilew
<- src
.tilew
;
1188 dst
.tileh
<- src
.tileh
;
1189 dst
.mustoresize
<- src
.mustoresize
;
1190 dst
.checkers
<- src
.checkers
;
1191 dst
.aalevel
<- src
.aalevel
;
1192 dst
.trimmargins
<- src
.trimmargins
;
1193 dst
.trimfuzz
<- src
.trimfuzz
;
1194 dst
.urilauncher
<- src
.urilauncher
;
1195 dst
.colorspace
<- src
.colorspace
;
1196 dst
.invert
<- src
.invert
;
1197 dst
.colorscale
<- src
.colorscale
;
1198 dst
.ghyllscroll
<- src
.ghyllscroll
;
1199 dst
.columns
<- src
.columns
;
1200 dst
.beyecolumns
<- src
.beyecolumns
;
1201 dst
.selcmd
<- src
.selcmd
;
1202 dst
.updatecurs
<- src
.updatecurs
;
1203 dst
.pathlauncher
<- src
.pathlauncher
;
1204 dst
.keyhashes
<- copykeyhashes src
;
1205 dst
.hfsize
<- src
.hfsize
;
1206 dst
.hscrollstep
<- src
.hscrollstep
;
1207 dst
.pgscale
<- src
.pgscale
;
1208 dst
.usepbo
<- src
.usepbo
;
1209 dst
.wheelbypage
<- src
.wheelbypage
;
1210 dst
.stcmd
<- src
.stcmd
;
1211 dst
.paxcmd
<- src
.paxcmd
;
1212 dst
.passcmd
<- src
.passcmd
;
1213 dst
.savecmd
<- src
.savecmd
;
1214 dst
.scrollb
<- src
.scrollb
;
1215 dst
.riani
<- src
.riani
;
1216 dst
.paxmark
<- src
.paxmark
;
1217 dst
.leftscroll
<- src
.leftscroll
;
1218 dst
.title
<- src
.title
;
1219 dst
.annotinline
<- src
.annotinline
;
1220 dst
.coarseprespos
<- src
.coarseprespos
;
1222 dst
.usedoccss
<- src
.usedoccss
;
1226 else Some
((ref (0.0, 0, 0)));
1229 let findkeyhash c name =
1230 try List.assoc
name c.keyhashes
1231 with Not_found
-> failwith
("invalid mode name `" ^
name ^
"'")
1236 let h = Hashtbl.create
10 in
1237 let dc = { defconf with angle
= defconf.angle
} in
1238 let rec toplevel v t spos
_ =
1240 | Vdata
| Vcdata
| Vend
-> v
1241 | Vopen
("llppconfig", _, closed
) ->
1244 else { v
with f = llppconfig
}
1245 | Vopen
_ -> parse_error
"unexpected subelement at top level" s spos
1246 | Vclose
_ -> parse_error
"unexpected close at top level" s spos
1248 and llppconfig v t spos
_ =
1250 | Vdata
| Vcdata
-> v
1251 | Vend
-> parse_error
"unexpected end of input in llppconfig" s spos
1252 | Vopen
("defaults", attrs
, closed
) ->
1253 let c = config_of dc attrs
in
1257 else { v
with f = defaults
}
1259 | Vopen
("ui-font", attrs
, closed
) ->
1260 let rec getsize size
= function
1262 | ("size", v
) :: rest
->
1264 fromstring int_of_string spos
"size" v
fstate.fontsize
in
1266 | l -> getsize size l
1268 fstate.fontsize
<- getsize fstate.fontsize attrs
;
1271 else { v
with f = uifont
(Buffer.create
10) }
1273 | Vopen
("doc", attrs
, closed
) ->
1274 let pathent, spage
, srely
, span
, svisy
, origin
= doc_of attrs
in
1275 let path = unentS pathent
1276 and origin
= unentS origin
1277 and pageno = fromstring int_of_string spos
"page" spage
0
1278 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1279 and pan
= fromstring int_of_string spos
"pan" span
0
1280 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1281 let c = config_of dc attrs
in
1282 let anchor = (pageno, rely
, visy
) in
1284 then (Hashtbl.add
h path (c, [], pan
, anchor, origin
); v
)
1285 else { v
with f = doc
path origin pan
anchor c [] }
1288 parse_error
"unexpected subelement in llppconfig" s spos
1290 | Vclose
"llppconfig" -> { v
with f = toplevel }
1291 | Vclose
_ -> parse_error
"unexpected close in llppconfig" s spos
1293 and defaults v t spos
_ =
1295 | Vdata
| Vcdata
-> v
1296 | Vend
-> parse_error
"unexpected end of input in defaults" s spos
1297 | Vopen
("keymap", attrs
, closed
) ->
1299 try List.assoc
"mode" attrs
1300 with Not_found
-> "global" in
1305 let h = findkeyhash dc modename in
1306 KeyMap.iter
(Hashtbl.replace
h) keymap
;
1309 { v
with f = pkeymap
ret KeyMap.empty
}
1311 | Vopen
(_, _, _) ->
1312 parse_error
"unexpected subelement in defaults" s spos
1314 | Vclose
"defaults" ->
1315 { v
with f = llppconfig
}
1317 | Vclose
_ -> parse_error
"unexpected close in defaults" s spos
1319 and uifont
b v t spos epos
=
1322 Buffer.add_substring
b s spos
(epos
- spos
);
1324 | Vopen
(_, _, _) ->
1325 parse_error
"unexpected subelement in ui-font" s spos
1326 | Vclose
"ui-font" ->
1327 if emptystr
!fontpath
1328 then fontpath := Buffer.contents
b;
1329 { v
with f = llppconfig
}
1330 | Vclose
_ -> parse_error
"unexpected close in ui-font" s spos
1331 | Vend
-> parse_error
"unexpected end of input in ui-font" s spos
1333 and doc
path origin pan
anchor c bookmarks v t spos
_ =
1335 | Vdata
| Vcdata
-> v
1336 | Vend
-> parse_error
"unexpected end of input in doc" s spos
1337 | Vopen
("bookmarks", _, closed
) ->
1340 else { v
with f = pbookmarks
path origin pan
anchor c bookmarks
}
1342 | Vopen
("keymap", attrs
, closed
) ->
1344 try List.assoc
"mode" attrs
1345 with Not_found
-> "global"
1351 let h = findkeyhash c modename in
1352 KeyMap.iter
(Hashtbl.replace
h) keymap
;
1353 doc
path origin pan
anchor c bookmarks
1355 { v
with f = pkeymap
ret KeyMap.empty
}
1357 | Vopen
("css", [], false) ->
1358 { v
with f = pcss
path origin pan
anchor c bookmarks
}
1360 | Vopen
(_, _, _) ->
1361 parse_error
"unexpected subelement in doc" s spos
1364 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor, origin
);
1365 { v
with f = llppconfig
}
1367 | Vclose
_ -> parse_error
"unexpected close in doc" s spos
1369 and pcss
path origin pan
anchor c bookmarks v t spos epos
=
1372 let b = Buffer.create
10 in
1373 Buffer.add_substring
b s spos
(epos
- spos
);
1374 { v
with f = pcss
path origin pan
anchor
1375 { c with css
= Buffer.contents
b }
1377 | Vend
-> parse_error
"unexpected end of input in css" s spos
1378 | Vopen
_ -> parse_error
"unexpected subelement in css" s spos
1379 | Vclose
"css" -> { v
with f = doc
path origin pan
anchor c bookmarks
}
1380 | Vclose
_ -> parse_error
"unexpected close in css" s spos
1382 and pkeymap
ret keymap v t spos
_ =
1384 | Vdata
| Vcdata
-> v
1385 | Vend
-> parse_error
"unexpected end of input in keymap" s spos
1386 | Vopen
("map", attrs
, closed
) ->
1387 let r, l = map_of attrs
in
1388 let kss = fromstring keys_of_string spos
"in" r [] in
1389 let lss = fromstring keys_of_string spos
"out" l [] in
1393 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
1394 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
1397 then { v
with f = pkeymap
ret keymap }
1400 { v
with f = skip
"map" f }
1403 parse_error
"unexpected subelement in keymap" s spos
1405 | Vclose
"keymap" ->
1406 { v
with f = ret keymap }
1408 | Vclose
_ -> parse_error
"unexpected close in keymap" s spos
1410 and pbookmarks
path origin pan
anchor c bookmarks v t spos
_ =
1412 | Vdata
| Vcdata
-> v
1413 | Vend
-> parse_error
"unexpected end of input in bookmarks" s spos
1414 | Vopen
("item", attrs
, closed
) ->
1415 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
1416 let page = fromstring int_of_string spos
"page" spage
0
1417 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1418 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1420 (unentS titleent, 0, Oanchor
(page, rely
, visy
)) :: bookmarks
1423 then { v
with f = pbookmarks
path origin pan
anchor c bookmarks }
1426 { v
with f = skip
"item" f }
1429 parse_error
"unexpected subelement in bookmarks" s spos
1431 | Vclose
"bookmarks" ->
1432 { v
with f = doc
path origin pan
anchor c bookmarks }
1434 | Vclose
_ -> parse_error
"unexpected close in bookmarks" s spos
1436 and skip tag
f v t spos
_ =
1438 | Vdata
| Vcdata
-> v
1440 parse_error
("unexpected end of input in skipped " ^ tag
) s spos
1441 | Vopen
(tag'
, _, closed
) ->
1445 let f'
() = { v
with f = skip tag
f } in
1446 { v
with f = skip tag'
f'
}
1450 else parse_error
("unexpected close in skipped " ^ tag
) s spos
1453 parse
{ f = toplevel; accu
= () } s;
1457 let do_load f contents
=
1460 | Parser.Parse_error
(msg
, s, pos
) ->
1461 let subs = Parser.subs s pos
in
1462 Utils.error
"parse error: %s: at %d [..%S..]" msg pos
subs
1464 | exn
-> Utils.error
"parse error: %s" @@ exntos exn
1469 let xdgconfdir = Utils.getenvwithdef
"XDG_CONFIG_HOME" E.s in
1470 if emptystr
xdgconfdir
1473 let dir = Filename.concat
home ".config" in
1474 if Sys.is_directory
dir then dir else home
1478 Filename.concat
dir "llpp.conf"
1481 let confpath = ref defconfpath;;
1483 let load2 f default
=
1484 match filecontents
!confpath with
1485 | contents
-> f @@ do_load get contents
1486 | exception Unix.Unix_error
(Unix.ENOENT
, "open", _) ->
1487 f (Hashtbl.create
0, defconf)
1489 dolog
"error loading configuration from `%S': %s" !confpath @@ exntos exn
;
1493 let load1 f = load2 f false;;
1501 (fun path (conf, _, _, _, _) ((_, besttime
) as best
) ->
1502 if conf.lastvisit
> besttime
1503 then (path, conf.lastvisit
)
1506 (state.path, -.infinity
)
1510 let pc, pb
, px
, pa
, po
=
1512 let absname = abspath
state.path in
1513 Hashtbl.find h absname
1514 with Not_found
-> dc, [], 0, emptyanchor, state.origin
1518 state.bookmarks <- pb
;
1522 then state.anchor <- pa
;
1523 cbput state.hists
.nav pa
;
1531 Hashtbl.fold (fun path (pc, pb
, px
, pa
, po
) accu
->
1532 (path, pc, pb
, px
, pa
, po
) :: accu
)
1538 let add_attrs bb always
dc c time
=
1540 Buffer.add_string bb
"\n ";
1541 Printf.bprintf bb fmt
s
1543 let o c fmt
s = if c then o' fmt
s else ignore
in
1544 let ob s a
b = o (always
|| a
!= b) "%s='%b'" s a
1545 and op
s a
b = o (always
|| a
<> b) "%s='%b'" s (a
!= None
)
1546 and oi
s a
b = o (always
|| a
!= b) "%s='%d'" s a
1547 and oI
s a
b = o (always
|| a
!= b) "%s='%s'" s (string_with_suffix_of_int a
)
1548 and oz
s a
b = o (always
|| a
<> b) "%s='%g'" s (a
*.100.)
1549 and oF
s a
b = o (always
|| a
<> b) "%s='%f'" s a
1550 and oL
s a
b = o (always
|| a
<> b) "%s='%Ld'" s a
1551 and oc
s a
b = o (always
|| a
<> b) "%s='%s'" s (color_to_string a
)
1552 and oC
s a
b = o (always
|| a
<> b) "%s='%s'" s (CSTE.to_string a
)
1553 and oR
s a
b = o (always
|| a
<> b) "%s='%s'" s (irect_to_string a
)
1554 and oFm
s a
b = o (always
|| a
<> b) "%s='%s'" s (FMTE.to_string a
)
1556 o (always
|| a
land m
<> b land m
) "%s='%b'" s (a
land m
!= 0)
1557 and oPm
s a
b = o (always
|| a
<> b) "%s='%s'" s (MTE.to_string a
)
1559 o (always
|| a
<> b) "%s='%s'" s @@ Parser.enent a
0 (String.length a
)
1564 | Some
(_N
, _A
, _B
) -> o'
"%s='%u,%u,%u'" s _N _A _B
1568 | _ -> o'
"%s='none'" s
1578 else string_of_float
f
1585 | Cmulti
((n, a
, b), _) when n > 1 -> o'
"%s='%d,%d,%d'" s n a
b
1586 | Csplit
(n, _) when n > 1 -> o'
"%s='%d'" s ~
-n
1587 | Cmulti
_ | Csplit
_ | Csingle
_ -> ()
1592 | Some
c when c > 1 -> o'
"%s='%d'" s c
1595 oi
"width" c.cwinw
dc.cwinw
;
1596 oi
"height" c.cwinh
dc.cwinh
;
1597 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
1598 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
1599 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
1600 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
1601 ob "case-insensitive-search" c.icase
dc.icase
;
1602 ob "preload" c.preload
dc.preload
;
1603 oi
"page-bias" c.pagebias
dc.pagebias
;
1604 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
1605 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
1606 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
1607 ob "crop-hack" c.crophack
dc.crophack
;
1608 oW
"throttle" c.maxwait
dc.maxwait
;
1609 ob "highlight-links" c.hlinks
dc.hlinks
;
1610 ob "under-cursor-info" c.underinfo
dc.underinfo
;
1611 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
1612 oz
"zoom" c.zoom dc.zoom;
1613 ob "presentation" c.presentation
dc.presentation
;
1614 oi
"rotation-angle" c.angle
dc.angle
;
1615 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
1616 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
1617 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
1618 oi
"tex-count" c.texcount
dc.texcount
;
1619 oi
"slice-height" c.sliceheight
dc.sliceheight
;
1620 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
1621 ob "persistent-location" c.jumpback
dc.jumpback
;
1622 oc
"background-color" c.bgcolor
dc.bgcolor
;
1623 oi
"tile-width" c.tilew
dc.tilew
;
1624 oi
"tile-height" c.tileh
dc.tileh
;
1625 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
1626 ob "checkers" c.checkers
dc.checkers
;
1627 oi
"aalevel" c.aalevel
dc.aalevel
;
1628 ob "trim-margins" c.trimmargins
dc.trimmargins
;
1629 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
1630 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
1631 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
1632 oC
"color-space" c.colorspace
dc.colorspace
;
1633 ob "invert-colors" c.invert
dc.invert
;
1634 oF
"brightness" c.colorscale
dc.colorscale
;
1635 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
1636 oco
"columns" c.columns
dc.columns
;
1637 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
1638 os
"selection-command" c.selcmd
dc.selcmd
;
1639 os
"synctex-command" c.stcmd
dc.stcmd
;
1640 os
"pax-command" c.paxcmd
dc.paxcmd
;
1641 os
"askpass-command" c.passcmd
dc.passcmd
;
1642 os
"savepath-command" c.savecmd
dc.savecmd
;
1643 ob "update-cursor" c.updatecurs
dc.updatecurs
;
1644 oi
"hint-font-size" c.hfsize
dc.hfsize
;
1645 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
1646 oF
"page-scroll-scale" c.pgscale
dc.pgscale
;
1647 ob "use-pbo" c.usepbo
dc.usepbo
;
1648 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
1649 ob "remote-in-a-new-instance" c.riani
dc.riani
;
1650 op
"point-and-x" c.pax
dc.pax
;
1651 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
1652 ob "scroll-bar-on-the-left" c.leftscroll
dc.leftscroll
;
1654 then os
"title" c.title
dc.title
;
1655 oL
"last-visit" (Int64.of_float time
) 0L;
1656 ob "edit-annotations-inline" c.annotinline
dc.annotinline
;
1657 ob "coarse-presentation-positioning" c.coarseprespos
dc.coarseprespos
;
1658 ob "use-document-css" c.usedoccss
dc.usedoccss
;
1661 let keymapsbuf always
dc c =
1663 let bb = create
16 in
1664 let rec loop = function
1666 | (modename, h) :: rest
->
1667 let dh = findkeyhash dc modename in
1668 if always
|| h <> dh
1670 if Hashtbl.length
h > 0
1672 if length
bb > 0 then add_char
bb '
\n'
;
1673 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
1674 Hashtbl.iter
(fun i
o ->
1675 if always
|| match Hashtbl.find dh i
1676 with | dO
-> dO
<> o | exception Not_found
-> false
1679 if Wsi.withctrl m
then add_string
bb "ctrl-";
1680 if Wsi.withalt m
then add_string
bb "alt-";
1681 if Wsi.withshift m
then add_string
bb "shift-";
1682 if Wsi.withmeta m
then add_string
bb "meta-";
1683 add_string
bb (Wsi.keyname
k);
1686 let rec loop = function
1688 | km
:: [] -> addkm km
1689 | km
:: rest
-> addkm km
; add_char
bb ' '
; loop rest
1693 add_string
bb "<map in='";
1697 add_string
bb "' out='"; addkm km
; add_string
bb "'/>\n"
1700 add_string
bb "' out='"; addkms kms
; add_string
bb "'/>\n"
1702 | KMmulti
(ins
, kms
) ->
1703 add_char
bb ' '
; addkms ins
; add_string
bb "' out='";
1704 addkms kms
; add_string
bb "'/>\n"
1706 add_string
bb "</keymap>";
1715 let keystostrlist c =
1716 let rec loop accu
= function
1718 | (modename, h) :: rest
->
1720 if Hashtbl.length
h > 0
1722 let accu = Printf.sprintf
"\xc2\xb7Keys for %s" modename :: accu in
1723 Hashtbl.fold (fun i
o a
->
1724 let bb = Buffer.create
10 in
1726 if Wsi.withctrl m
then Buffer.add_string
bb "ctrl-";
1727 if Wsi.withalt m
then Buffer.add_string
bb "alt-";
1728 if Wsi.withshift m
then Buffer.add_string
bb "shift-";
1729 if Wsi.withmeta m
then Buffer.add_string
bb "meta-";
1730 Buffer.add_string
bb (Wsi.keyname
k);
1733 let rec loop = function
1735 | km
:: [] -> addkm km
1737 addkm km
; Buffer.add_char
bb ' '
;
1743 Buffer.add_char
bb '
\t'
;
1751 | KMmulti
(ins
, kms
) ->
1752 Buffer.add_char
bb ' '
;
1754 Buffer.add_string
bb "\t";
1757 Buffer.contents
bb :: a
1767 let save1 bb leavebirdseye x
h dc =
1768 let uifontsize = fstate.fontsize
in
1769 let dc = if conf.bedefault
then conf else dc in
1770 Buffer.add_string
bb "<llppconfig>\n";
1772 if nonemptystr
!fontpath
1774 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
1780 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
1783 Buffer.add_string
bb "<defaults";
1784 add_attrs bb true dc dc nan
;
1785 let kb = keymapsbuf true dc dc in
1786 if Buffer.length
kb > 0
1788 Buffer.add_string
bb ">\n";
1789 Buffer.add_buffer
bb kb;
1790 Buffer.add_string
bb "\n</defaults>\n";
1792 else Buffer.add_string
bb "/>\n";
1794 let adddoc path pan
anchor c bookmarks time origin
=
1795 if bookmarks == [] && c = dc && anchor = emptyanchor
1798 Printf.bprintf
bb "<doc path='%s'"
1799 (Parser.enent
path 0 (String.length
path));
1801 if nonemptystr origin
1802 then Printf.bprintf
bb "\n origin='%s'"
1803 (Parser.enent origin
0 (String.length origin
));
1805 if anchor <> emptyanchor
1807 let n, rely
, visy
= anchor in
1808 Printf.bprintf
bb "\n page='%d'" n;
1811 then Printf.bprintf
bb " rely='%f'" rely
;
1813 if abs_float visy
> 1e-6
1814 then Printf.bprintf
bb " visy='%f'" visy
;
1818 then Printf.bprintf
bb " pan='%d'" pan
;
1820 add_attrs bb false dc c time
;
1821 if nonemptystr
c.css
1822 then Printf.bprintf
bb ">\n <css><![CDATA[%s]]></css>" c.css
;
1823 let kb = keymapsbuf false dc c in
1825 begin match bookmarks with
1827 if Buffer.length
kb > 0
1829 Buffer.add_string
bb ">\n";
1830 Buffer.add_buffer
bb kb;
1831 Buffer.add_string
bb "\n</doc>\n";
1834 if nonemptystr
c.css
1835 then Buffer.add_string
bb "\n</doc>\n"
1836 else Buffer.add_string
bb "/>\n"
1838 Buffer.add_string
bb ">\n<bookmarks>\n";
1839 List.iter
(fun (title
, _, kind
) ->
1840 begin match kind
with
1841 | Oanchor
(page, rely
, visy
) ->
1843 "<item title='%s' page='%d'"
1844 (Parser.enent title
0 (String.length title
))
1849 Printf.bprintf
bb " rely='%f'" rely
1851 if abs_float visy
> 1e-6
1853 Printf.bprintf
bb " visy='%f'" visy
1855 | Ohistory
_ | Onone
| Ouri
_ | Oremote
_
1856 | Oremotedest
_ | Olaunch
_ ->
1857 failwith
"unexpected link in bookmarks"
1859 Buffer.add_string
bb "/>\n";
1861 Buffer.add_string
bb "</bookmarks>";
1862 if Buffer.length
kb > 0
1864 Buffer.add_string
bb "\n";
1865 Buffer.add_buffer
bb kb;
1867 Buffer.add_string
bb "\n</doc>\n";
1873 match state.mode
with
1874 | Birdseye
(c, pan, _, _, _) ->
1876 match conf.columns
with
1877 | Cmulti
((c, _, _), _) -> Some
c
1881 match c.columns
with
1882 | Cmulti
(c, _) -> Cmulti
(c, E.a
)
1883 | Csingle
_ -> Csingle
E.a
1884 | Csplit
_ -> failwith
"quit from bird's eye while split"
1886 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
1889 | LinkNav
_ -> x
, conf
1891 let docpath = if nonemptystr
state.path then abspath
state.path else E.s in
1892 if nonemptystr
docpath
1894 adddoc docpath pan (getanchor ())
1896 let autoscrollstep =
1897 match state.autoscroll
with
1899 | None
-> conf.autoscrollstep
1901 begin match state.mode
with
1902 | Birdseye beye
-> leavebirdseye beye
true
1907 { conf with autoscrollstep = autoscrollstep }
1909 (if conf.savebmarks
then state.bookmarks else [])
1913 Hashtbl.iter
(fun path (c, bookmarks, x
, anchor, origin
) ->
1914 if docpath <> abspath
path
1915 then adddoc path x
anchor c bookmarks c.lastvisit origin
1917 Buffer.add_string
bb "</llppconfig>\n";
1921 let save leavebirdseye
=
1922 let relx = float state.x
/. float state.winw
in
1924 let cx w = truncate
(relx *. float w) in
1926 (fun (w, h, x
) ws
->
1928 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
1929 | Wsi.MaxVert
-> (w, conf.cwinh
, x
)
1930 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
1932 (state.winw
, state.winh
, state.x
) state.winstate
1936 let bb = Buffer.create
32768 in
1938 save1 bb leavebirdseye x
h dc
1940 if load1 save2 && Buffer.length
bb > 0
1943 let tmp = !confpath ^
".tmp" in
1944 let oc = open_out_bin
tmp in
1945 Buffer.output_buffer
oc bb;
1947 Unix.rename
tmp !confpath;
1949 dolog
"error saving configuration: %s" @@ exntos exn
1953 let href = ref @@ Hashtbl.create
0 in
1954 let cref = ref defconf in
1957 if Sys.file_exists
path
1959 else (dolog
"removing %s" path; None
) in
1960 Hashtbl.filter_map_inplace
f h;
1965 ignore
(load1 push);
1966 let bb = Buffer.create
32768 in
1967 let save2 (_h
, dc) = save1 bb (fun _ _ -> ()) 0 !href dc in
1968 if load1 save2 && Buffer.length
bb > 0
1971 let tmp = !confpath ^
".tmp" in
1972 let oc = open_out_bin
tmp in
1973 Buffer.output_buffer
oc bb;
1975 Unix.rename
tmp !confpath;
1977 dolog
"error saving configuration: %s" @@ exntos exn
1981 let logcurrently = function
1982 | Idle
-> dolog
"Idle"
1983 | Loading
(l, gen
) ->
1984 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
1985 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col
, row
, tilew
, tileh
) ->
1987 "Tiling %d[%d,%d] page=%s cs=%s angle=%d"
1988 l.pageno col row
(~
> pageopaque
)
1989 (CSTE.to_string colorspace
) angle
;
1990 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1991 angle gen
conf.angle
state.gen
1993 conf.tilew
conf.tileh
;