3 let irect_of_string s
=
4 Scanf.sscanf s
"%d/%d/%d/%d" (fun x0 y0 x1 y1
-> (x0
,y0
,x1
,y1
))
6 let irect_to_string (x0
,y0
,x1
,y1
) = Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
8 let multicolumns_to_string (n
, a
, b
) =
10 then Printf.sprintf
"%d" n
11 else Printf.sprintf
"%d,%d,%d" n a b
13 let multicolumns_of_string s
=
15 (int_of_string s
, 0, 0)
17 Scanf.sscanf s
"%u,%u,%u" (fun n a b
->
19 then error
"subtly broken";
33 and trimmargins
= bool
34 and trimparams
= (trimmargins
* irect
)
39 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
44 | Uannotation
of (opaque
* slinkindex
)
47 and launchcommand
= string
57 | LDfirstvisible
of (int * int * int)
65 and anchor
= pageno
* top
* dtop
66 and rect
= float * float * float * float * float * float * float * float
67 and infochange
= | Memused
| Docinfo
| Pdim
68 and redirstderr
= bool
70 { mutable fontsize
: int
71 ; mutable wwidth
: float
72 ; mutable maxrows
: int
76 { fontsize
= Wsi.fontsizescale
20
84 method key
: int -> int -> uioh
85 method button
: int -> bool -> int -> int -> int -> uioh
86 method multiclick
: int -> int -> int -> int -> uioh
87 method motion
: int -> int -> uioh
88 method pmotion
: int -> int -> uioh
89 method infochanged
: infochange
-> unit
90 method scrollpw
: (int * float * float)
91 method scrollph
: (int * float * float)
92 method modehash
: keyhash
93 method eformsgs
: bool
94 method alwaysscrolly
: bool
95 method scroll
: int -> int -> uioh
96 method zoom
: float -> int -> int -> unit
99 module type TextEnumType
= sig
102 val names
: string array
105 module TextEnumMake
(Ten
: TextEnumType
) = struct
106 let names = Ten.names
107 let to_int (t
: Ten.t
) = Obj.magic t
108 let to_string t
= names.(to_int t
)
109 let of_int n
: Ten.t
= Obj.magic n
112 if i
= Array.length
names
113 then error
"invalid %s: %s" Ten.name s
122 module CSTE
= TextEnumMake
(struct
124 let name = "colorspace"
125 let names = [|"rgb"; "gray"|]
128 module MTE
= TextEnumMake
(struct
131 let names = [|"page"; "block"; "line"; "word"|]
134 module FMTE
= TextEnumMake
(struct
136 let name = "fitmodel"
137 let names = [|"width"; "proportional"; "page"|]
144 | Olaunch
of launchcommand
145 | Oremote
of (filename
* pageno
)
146 | Oremotedest
of (filename
* destname
)
147 | Ohistory
of (filename
* conf
* outline list
* x
* anchor
* filename
)
148 and outline
= (caption
* outlinelevel
* outlinekind
)
149 and outlinelevel
= int
165 type tile
= opaque
* pixmapsize
* elapsed
167 and pagemapkey
= pageno
* gen
168 and tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
173 | Loading
of (page
* gen
)
175 of (page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
)
176 | Outlining
of outline list
180 | Msel
of (mpos
* mpos
)
182 | Mscrolly
| Mscrollx
183 | Mzoom
of (buttonno
* step
* mpos
)
184 | Mzoomrect
of (mpos
* mpos
)
189 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
190 | Textentry
of (textentry
* onleave
)
191 | LinkNav
of linktarget
192 and onleave
= leavetextentrystatus
-> unit
193 and leavetextentrystatus
= | Cancel
| Confirm
194 and helpitem
= string * int * action
195 and action
= (uioh
-> uioh
) option
197 | Ltexact
of (pageno
* direction
)
198 | Ltgendir
of direction
199 | Ltnotready
of (pageno
* direction
)
200 and direction
= int (* -1, 0, 1 *)
201 and textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
202 and onkey
= string -> Keys.t
-> te
203 and ondone
= string -> unit
204 and histcancel
= unit -> unit
205 and onhist
= ((histcmd
-> string) * histcancel
)
206 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
207 and cancelonempty
= bool
212 | TEswitch
of textentry
224 let emptykeyhash = Hashtbl.create
0
231 method key _ _
= self
232 method multiclick _ _ _ _
= self
233 method button _ _ _ _ _
= self
234 method motion _ _
= self
235 method pmotion _ _
= self
236 method infochanged _
= ()
237 method scrollpw
= (0, nan
, nan
)
238 method scrollph
= (0, nan
, nan
)
239 method modehash
= emptykeyhash
240 method eformsgs
= false
241 method alwaysscrolly
= false
242 method scroll _ _
= self
243 method zoom _ _ _
= ()
247 { store
= Array.make n v
253 let cbcap b
= Array.length b
.store
255 let cbput ?
(update_rc
=true) b v
=
258 b
.wc
<- (b
.wc
+ 1) mod cap;
261 b
.len
<- min
(b
.len
+ 1) cap
263 let cbput_dont_update_rc b v
= cbput ~update_rc
:false b v
265 let cbempty b
= b
.len
= 0
267 let cbgetg b circular dir
=
271 let rc = b
.rc + dir
in
283 else bound
rc 0 (b
.len
-1)
288 let cbget b
= cbgetg b
false
289 let cbgetc b
= cbgetg b
true
292 { pat
: string circbuf
293 ; pag
: string circbuf
294 ; sel
: string circbuf
298 try Sys.getenv
"HOME"
300 dolog
"cannot determine home directory location: %s" @@ exntos exn
;
305 let dir = Filename.concat
home ".config" in
306 if Sys.is_directory
dir then dir else home
308 Filename.concat
dir "llpp.conf"
311 let confpath = ref defconfpath
312 let ss = ref Unix.stdin
313 let wsfd = ref Unix.stdin
314 let stderr = ref Unix.stdin
315 let selfexec = ref E.s
316 let ignoredoctitlte = ref false
317 let errmsgs = Buffer.create
0
318 let newerrmsgs = ref false
325 let ranchors : (string * string * anchor * string) list
ref = ref []
326 let maxy = ref max_int
327 let layout : page list
ref = ref []
328 let pagemap : (pagemapkey
, opaque
) Hashtbl.t
= Hashtbl.create
0
329 let tilemap : (tilemapkey
, tile
) Hashtbl.t
= Hashtbl.create
0
330 let pdims : (pageno
* width
* height
* leftx
) list
ref = ref []
331 let pagecount = ref max_int
332 let currently = ref Idle
333 let mstate = ref Mnone
334 let searchpattern = ref E.s
335 let rects : (pageno
* rectcolor
* rect
) list
ref = ref []
336 let rects1 : (pageno
* rectcolor
* rect
) list
ref = ref []
339 let password = ref E.s
340 let nameddest = ref E.s
342 let winstate : Wsi.winstate list
ref = ref []
343 let mode : mode ref = ref View
344 let uioh : uioh ref = ref nouioh
345 let outlines : outline array
ref = ref [||]
346 let bookmarks : outline list
ref = ref []
347 let geomcmds : (string * ((string * (unit -> unit)) list
)) ref = ref (E.s
, [])
348 let memused : memsize
ref = ref 0
349 let gen : gen ref = ref 0
350 let autoscroll : int option ref = ref None
351 let help : helpitem array
ref = ref E.a
352 let docinfo : (int * string) list
ref = ref []
353 let hists : hists ref =
354 ref { pat
= cbnew 10 E.s
; pag
= cbnew 10 E.s
; sel
= cbnew 10 E.s
; }
355 let prevzoom = ref (1.0, 0)
356 let progress = ref ~
-.1.0
357 let mpos = ref (-1, -1)
358 let keystate = ref KSnone
359 let glinks = ref false
360 let prevcolumns : (columns
* zoom
) option ref = ref None
363 let reprf = ref noreprf
364 let roamf = ref noroamf
365 let bzoom = ref false
366 let lnava : (pageno
* linkno
) option ref = ref None
367 let reload : (x * y * float) option ref = ref None
368 let nav : anchor nav ref = ref { past
= []; future
= []; }
369 let tilelru : (tilemapkey
* opaque
* pixmapsize
) Queue.t
= Queue.create
()
370 let fontpath = ref E.s
373 let conf = { defconf
with keyhashes
= copykeyhashes defconf
}
376 let d = !S.winh - h
in
377 max
conf.interpagespace
((d + 1) / 2)
379 let rowyh (c
, coverA
, coverB
) b n
=
380 if c
= 1 || (n
< coverA
|| n
>= !S.pagecount - coverB
)
382 let _, _, vy
, (_, _, h
, _) = b
.(n
) in
385 let n'
= n - coverA
in
388 let e = min
!S.pagecount (s + c
) in
389 let rec findminmax m miny maxh
=
393 let _, _, y, (_, _, h
, _) = b
.(m
) in
394 let miny = min
miny y in
395 let maxh = max
maxh h
in
396 findminmax (m
+1) miny maxh
398 findminmax s max_int
0
401 let ((c
, coverA
, coverB
) as cl
), b
=
402 match conf.columns
with
403 | Csplit
(_, b
) | Csingle b
-> (1, 0, 0), b
404 | Cmulti
(c
, b
) -> c
, b
406 if Array.length b
= 0
409 let rec bsearch nmin nmax
=
411 then bound nmin
0 (!S.pagecount-1)
413 let n = (nmax
+ nmin
) / 2 in
414 let vy, h
= rowyh cl b
n in
418 let ips = calcips h
in
420 let y1 = vy + h
+ ips in
424 then 0, vy + h
+ conf.interpagespace
426 let y0 = vy - conf.interpagespace
in
427 y0, y0 + h
+ conf.interpagespace
437 if n < !S.pagecount - coverB
438 then ((n-coverA
)/c
)*c
+ coverA
445 then bsearch (n+1) nmax
446 else bsearch nmin
(n-1)
449 bsearch 0 (!S.pagecount-1)
452 match conf.columns
with
453 | Cmulti
((_, _, _) as cl
, b
) ->
454 if Array.length b
> 0
456 let y, h
= rowyh cl b
(Array.length b
- 1) in
457 y + h
+ (if conf.presentation
then calcips h
else 0)
460 if Array.length b
> 0
462 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
463 y + h
+ (if conf.presentation
then calcips h
else 0)
466 if Array.length b
> 0
468 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
472 let getpageywh pageno
=
473 let pageno = bound
pageno 0 (!S.pagecount-1) in
474 match conf.columns
with
476 if Array.length b
= 0
479 let (_, _, y, (_, w, h
, _)) = b
.(pageno) in
487 if Array.length b
= 0
490 let y, h
= rowyh cl b
pageno in
491 let (_, _, _, (_, w, _, _)) = b
.(pageno) in
499 if Array.length b
= 0
503 let (_, _, y, (_, w, h
, _)) = b
.(n) in
506 let getpageyh pageno =
507 let y,_,h
= getpageywh pageno in
510 let getpagedim pageno =
513 | (n, _, _, _) as pdim
:: rest
->
515 then (if n = pageno then pdim
else ppdim
)
519 f (-1, -1, -1, -1) !S.pdims
521 let getpdimno pageno =
525 | (n, _, _, _) :: rest
->
527 then (if n = pageno then np else p
)
533 let getpagey pageno = fst
(getpageyh pageno)
537 let coloff = l
.pagecol
* l
.pageh
in
538 float (l
.pagey
+ coloff) /. float l
.pageh
545 then float l
.pagedispy
/. float (calcips l
.pageh
)
546 else float l
.pagedispy
/. float conf.interpagespace
549 (l
.pageno, top, dtop)
553 | l
:: _ -> getanchor1 l
555 let n = page_of_y !S.y in
559 let y, h
= getpageyh n in
564 let ips = calcips h
in
565 float (dy + ips) /. float ips
566 else float dy /. float conf.interpagespace
570 type historder
= [ `lastvisit
| `title
| `
path | `file
]
573 Map.Make
(struct type t
= (int * int) let compare = compare end)
576 let l = String.length
s in
577 let b = Buffer.create
l in
578 Parser.unent
b s 0 l;
581 let modifier_of_string = function
582 | "alt" -> Wsi.altmask
583 | "shift" -> Wsi.shiftmask
584 | "ctrl" | "control" -> Wsi.ctrlmask
585 | "meta" -> Wsi.metamask
588 let keys_of_string s =
589 let key_of_string r
s =
590 let elems = Str.full_split r
s in
593 let m1 = modifier_of_string s in
595 then (Wsi.namekey
s, m
)
598 | Str.Delim
s when n land 1 = 0 -> g s
600 | Str.Delim
_ -> (k
, m
)
602 let rec loop n k m
= function
605 let k, m
= f n k m
x in
610 let elems = Str.split
Utils.Re.whitespace
s in
611 List.map
(key_of_string (Str.regexp
"-")) elems
614 let l = String.length v
in
616 then error
"set must contain more than one char, but has %d" l;
617 let module S
= Set.Make
(struct type t
= char
let compare = compare end) in
621 let e = String.get v i
in
623 then error
"set has duplicates (at least '%c')" e
624 else check (S.add
e s) (i
+1)
626 check (S.singleton
(String.get v
0)) 1
628 let config_of c attrs
=
629 let maxv ?
(f=int_of_string
) u
s = max u
@@ f s in
633 | "scroll-bar-width" -> { c
with scrollbw
= maxv 0 v
}
634 | "scroll-handle-height" -> { c
with scrollh
= maxv 0 v
}
635 | "case-insensitive-search" -> { c
with icase
= bool_of_string v
}
636 | "preload" -> { c
with preload
= bool_of_string v
}
637 | "page-bias" -> { c
with pagebias
= int_of_string v
}
638 | "scroll-step" -> { c
with scrollstep
= maxv 1 v
}
639 | "horizontal-scroll-step" -> { c
with hscrollstep
= maxv 1 v
}
640 | "auto-scroll-step" -> { c
with autoscrollstep
= maxv 0 v
}
641 | "max-height-fit" -> { c
with maxhfit
= bool_of_string v
}
642 | "highlight-links" -> { c
with hlinks
= bool_of_string v
}
643 | "under-cursor-info" -> { c
with underinfo
= bool_of_string v
}
644 | "vertical-margin" -> { c
with interpagespace
= maxv 0 v
}
646 let zoom = float_of_string v
/. 100. in
647 let zoom = max
zoom 0.0 in
648 { c
with zoom = zoom }
649 | "presentation" -> { c
with presentation
= bool_of_string v
}
650 | "rotation-angle" -> { c
with angle
= int_of_string v
}
651 | "width" -> { c
with cwinw
= maxv 20 v
}
652 | "height" -> { c
with cwinh
= maxv 20 v
}
653 | "proportional-display" ->
654 { c
with fitmodel
= if bool_of_string v
658 | "fit-model" -> { c
with fitmodel
= FMTE.of_string v
}
659 | "pixmap-cache-size" ->
660 { c
with memlimit
= maxv ~
f:int_of_string_with_suffix
2 v
}
661 | "tex-count" -> { c
with texcount
= maxv 1 v
}
662 | "slice-height" -> { c
with sliceheight
= maxv 2 v
}
663 | "thumbnail-width" -> { c
with thumbw
= maxv 2 v
}
664 | "background-color" -> { c
with bgcolor
= color_of_string v
}
665 | "paper-color" -> { c
with papercolor
= rgba_of_string v
}
666 | "scrollbar-color" -> { c
with sbarcolor
= rgba_of_string v
}
667 | "scrollbar-handle-color" -> { c
with sbarhndlcolor
= rgba_of_string v
}
668 | "texture-color" -> { c
with texturecolor
= rgba_of_string v
}
669 | "tile-width" -> { c
with tilew
= maxv 2 v
}
670 | "tile-height" -> { c
with tileh
= maxv 2 v
}
671 | "mupdf-store-size" ->
672 { c
with mustoresize
= maxv ~
f:int_of_string_with_suffix
1024 v
}
673 | "aalevel" -> { c
with aalevel
= maxv 0 v
}
674 | "trim-margins" -> { c
with trimmargins
= bool_of_string v
}
675 | "trim-fuzz" -> { c
with trimfuzz
= irect_of_string v
}
676 | "uri-launcher" -> { c
with urilauncher
= unentS v
}
677 | "path-launcher" -> { c
with pathlauncher
= unentS v
}
678 | "color-space" -> { c
with colorspace
= CSTE.of_string v
}
679 | "invert-colors" -> { c
with invert
= bool_of_string v
}
680 | "brightness" -> { c
with colorscale
= float_of_string v
}
682 let (n, _, _) as nab
= multicolumns_of_string v
in
684 then { c
with columns
= Csplit
(-n, E.a
) }
685 else { c
with columns
= Cmulti
(nab
, E.a
) }
686 | "birds-eye-columns" -> { c
with beyecolumns
= Some
(maxv 2 v
) }
687 | "selection-command" -> { c
with selcmd
= unentS v
}
688 | "paste-command" -> { c
with pastecmd
= unentS v
}
689 | "synctex-command" -> { c
with stcmd
= unentS v
}
690 | "pax-command" -> { c
with paxcmd
= unentS v
}
691 | "askpass-command" -> { c
with passcmd
= unentS v
}
692 | "savepath-command" -> { c
with savecmd
= unentS v
}
693 | "update-cursor" -> { c
with updatecurs
= bool_of_string v
}
694 | "hint-font-size" -> { c
with hfsize
= bound
(int_of_string v
) 5 100 }
695 | "page-scroll-scale" -> { c
with pgscale
= float_of_string v
}
696 | "wheel-scrolls-pages" -> { c
with wheelbypage
= bool_of_string v
}
697 | "horizontal-scrollbar-visible" ->
698 { c
with scrollb
= if bool_of_string v
699 then c
.scrollb
lor scrollbhv
700 else c
.scrollb
land (lnot scrollbhv
)
702 | "vertical-scrollbar-visible" ->
703 { c
with scrollb
= if bool_of_string v
704 then c
.scrollb
lor scrollbvv
705 else c
.scrollb
land (lnot scrollbvv
)
707 | "remote-in-a-new-instance" -> { c
with riani
= bool_of_string v
}
709 { c
with pax
= if bool_of_string v
then Some
0.0 else None
}
710 | "point-and-x-mark" -> { c
with paxmark
= MTE.of_string v
}
711 | "scroll-bar-on-the-left" -> { c
with leftscroll
= bool_of_string v
}
712 | "title" -> { c
with title
= unentS v
}
713 | "last-visit" -> { c
with lastvisit
= float_of_string v
}
714 | "edit-annotations-inline" -> { c
with annotinline
= bool_of_string v
}
715 | "coarse-presentation-positioning" ->
716 { c
with coarseprespos
= bool_of_string v
}
717 | "use-document-css" -> { c
with usedoccss
= bool_of_string v
}
718 | "hint-charset" -> validatehcs v
; { c
with hcs
= v
}
719 | "rlw" -> { c
with rlw
= int_of_string v
}
720 | "rlh" -> { c
with rlh
= int_of_string v
}
721 | "rlem" -> { c
with rlem
= int_of_string v
}
724 dolog
"error processing attribute (`%S' = `%S'): %s" k v
@@ exntos exn
;
727 let rec fold c
= function
730 let c = apply c k v
in
733 fold { c with keyhashes
= copykeyhashes
c } attrs
735 let fromstring f pos
n v
d =
738 dolog
"error processing attribute (%S=%S) at %d\n%s" n v pos
@@ exntos exn
;
741 let bookmark_of attrs
=
742 let rec fold title page rely visy
= function
743 | ("title", v
) :: rest
-> fold v page rely visy rest
744 | ("page", v
) :: rest
-> fold title v rely visy rest
745 | ("rely", v
) :: rest
-> fold title page v visy rest
746 | ("visy", v
) :: rest
-> fold title page rely v rest
747 | _ :: rest
-> fold title page rely visy rest
748 | [] -> title
, page
, rely
, visy
750 fold "invalid" "0" "0" "0" attrs
753 let rec fold path key page rely pan visy
origin dcf
= function
754 | ("path", v
) :: rest
-> fold v key page rely pan visy
origin dcf rest
755 | ("key", v
) :: rest
-> fold path v page rely pan visy
origin dcf rest
756 | ("page", v
) :: rest
-> fold path key v rely pan visy
origin dcf rest
757 | ("rely", v
) :: rest
-> fold path key page v pan visy
origin dcf rest
758 | ("pan", v
) :: rest
-> fold path key page rely v visy
origin dcf rest
759 | ("visy", v
) :: rest
-> fold path key page rely pan v
origin dcf rest
760 | ("origin", v
) :: rest
-> fold path key page rely pan visy v dcf rest
761 | ("dcf", v
) :: rest
-> fold path key page rely pan visy
origin v rest
762 | _ :: rest
-> fold path key page rely pan visy
origin dcf rest
763 | [] -> path, key
, page
, rely
, pan
, visy
, origin, dcf
765 fold E.s E.s "0" "0" "0" "0" E.s E.s attrs
768 let rec fold rs ls
= function
769 | ("out", v
) :: rest
-> fold v ls rest
770 | ("in", v
) :: rest
-> fold rs v rest
771 | _ :: rest
-> fold ls rs rest
776 let findkeyhash c name =
777 try List.assoc
name c.keyhashes
778 with Not_found
-> error
"invalid mode name `%s'" name
782 let h = Hashtbl.create
10 in
783 let dc = { defconf
with angle
= defconf
.angle
} in
784 let rec toplevel v t spos
_ =
786 | Vdata
| Vcdata
| Vend
-> v
787 | Vopen
("llppconfig", _, closed
) ->
790 else { v
with f = llppconfig
}
791 | Vopen
_ -> parse_error
"unexpected subelement at top level" s spos
792 | Vclose
_ -> parse_error
"unexpected close at top level" s spos
794 and llppconfig v t spos
_ =
796 | Vdata
| Vcdata
-> v
797 | Vend
-> parse_error
"unexpected end of input in llppconfig" s spos
798 | Vopen
("defaults", attrs
, closed
) ->
799 let c = config_of dc attrs
in
803 else { v
with f = defaults
}
805 | Vopen
("ui-font", attrs
, closed
) ->
806 let rec getsize size
= function
808 | ("size", v
) :: rest
->
810 fromstring int_of_string spos
"size" v
fstate.fontsize
in
812 | l -> getsize size l
814 fstate.fontsize
<- getsize fstate.fontsize attrs
;
817 else { v
with f = uifont
(Buffer.create
10) }
819 | Vopen
("doc", attrs
, closed
) ->
820 let pathent, key
, spage
, srely
, span
, svisy
, origin, dcf
822 let path = unentS pathent
823 and origin = unentS origin
824 and pageno = fromstring int_of_string spos
"page" spage
0
825 and rely
= fromstring float_of_string spos
"rely" srely
0.0
826 and pan
= fromstring int_of_string spos
"pan" span
0
827 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
828 let c = config_of dc attrs
in
831 let anchor = (pageno, rely
, visy
) in
833 then (Hashtbl.add
h path (c, [], pan
, anchor, origin); v
)
834 else { v
with f = doc
path origin pan
anchor c [] }
836 | Vopen
_ -> parse_error
"unexpected subelement in llppconfig" s spos
837 | Vclose
"llppconfig" -> { v
with f = toplevel }
838 | Vclose
_ -> parse_error
"unexpected close in llppconfig" s spos
840 and defaults v t spos
_ =
842 | Vdata
| Vcdata
-> v
843 | Vend
-> parse_error
"unexpected end of input in defaults" s spos
844 | Vopen
("keymap", attrs
, closed
) ->
846 try List.assoc
"mode" attrs
847 with Not_found
-> "global" in
852 let h = findkeyhash dc modename in
853 KeyMap.iter
(Hashtbl.replace
h) keymap
;
856 { v
with f = pkeymap
ret KeyMap.empty
}
858 | Vopen
(_, _, _) -> parse_error
"unexpected subelement in defaults" s spos
860 | Vclose
"defaults" ->
861 { v
with f = llppconfig
}
863 | Vclose
_ -> parse_error
"unexpected close in defaults" s spos
865 and uifont
b v t spos epos
=
868 Buffer.add_substring
b s spos
(epos
- spos
);
870 | Vopen
(_, _, _) -> parse_error
"unexpected subelement in ui-font" s spos
871 | Vclose
"ui-font" ->
872 if emptystr
!S.fontpath
873 then S.fontpath := Buffer.contents
b;
874 { v
with f = llppconfig
}
875 | Vclose
_ -> parse_error
"unexpected close in ui-font" s spos
876 | Vend
-> parse_error
"unexpected end of input in ui-font" s spos
878 and doc
path origin pan
anchor c bookmarks v t spos
_ =
880 | Vdata
| Vcdata
-> v
881 | Vend
-> parse_error
"unexpected end of input in doc" s spos
882 | Vopen
("bookmarks", _, closed
) ->
885 else { v
with f = pbookmarks
path origin pan
anchor c bookmarks }
887 | Vopen
("keymap", attrs
, closed
) ->
889 try List.assoc
"mode" attrs
890 with Not_found
-> "global"
896 let h = findkeyhash c modename in
897 KeyMap.iter
(Hashtbl.replace
h) keymap
;
898 doc
path origin pan
anchor c bookmarks
900 { v
with f = pkeymap
ret KeyMap.empty
}
902 | Vopen
("css", [], false) ->
903 { v
with f = pcss
path origin pan
anchor c bookmarks }
906 parse_error
"unexpected subelement in doc" s spos
909 Hashtbl.add
h path (c, List.rev
bookmarks, pan
, anchor, origin);
910 { v
with f = llppconfig
}
912 | Vclose
_ -> parse_error
"unexpected close in doc" s spos
914 and pcss
path origin pan
anchor c bookmarks v t spos epos
=
917 let b = Buffer.create
10 in
918 Buffer.add_substring
b s spos
(epos
- spos
);
919 { v
with f = pcss
path origin pan
anchor
920 { c with css
= Buffer.contents
b }
922 | Vend
-> parse_error
"unexpected end of input in css" s spos
923 | Vopen
_ -> parse_error
"unexpected subelement in css" s spos
924 | Vclose
"css" -> { v
with f = doc
path origin pan
anchor c bookmarks }
925 | Vclose
_ -> parse_error
"unexpected close in css" s spos
927 and pkeymap
ret keymap v t spos
_ =
929 | Vdata
| Vcdata
-> v
930 | Vend
-> parse_error
"unexpected end of input in keymap" s spos
931 | Vopen
("map", attrs
, closed
) ->
932 let r, l = map_of attrs
in
933 let kss = fromstring keys_of_string spos
"in" r [] in
934 let lss = fromstring keys_of_string spos
"out" l [] in
938 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
939 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
942 then { v
with f = pkeymap
ret keymap }
945 { v
with f = skip
"map" f }
947 | Vopen
_ -> parse_error
"unexpected subelement in keymap" s spos
949 { v
with f = ret keymap }
950 | Vclose
_ -> parse_error
"unexpected close in keymap" s spos
952 and pbookmarks
path origin pan
anchor c bookmarks v t spos
_ =
954 | Vdata
| Vcdata
-> v
955 | Vend
-> parse_error
"unexpected end of input in bookmarks" s spos
956 | Vopen
("item", attrs
, closed
) ->
957 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
958 let page = fromstring int_of_string spos
"page" spage
0
959 and rely
= fromstring float_of_string spos
"rely" srely
0.0
960 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
962 (unentS titleent, 0, Oanchor
(page, rely
, visy
)) :: bookmarks
965 then { v
with f = pbookmarks
path origin pan
anchor c bookmarks }
968 { v
with f = skip
"item" f }
970 | Vopen
_ -> parse_error
"unexpected subelement in bookmarks" s spos
971 | Vclose
"bookmarks" ->
972 { v
with f = doc
path origin pan
anchor c bookmarks }
973 | Vclose
_ -> parse_error
"unexpected close in bookmarks" s spos
975 and skip tag
f v t spos
_ =
977 | Vdata
| Vcdata
-> v
978 | Vend
-> parse_error
("unexpected end of input in skipped " ^ tag
) s spos
979 | Vopen
(tag'
, _, closed
) ->
983 let f'
() = { v
with f = skip tag
f } in
984 { v
with f = skip tag'
f'
}
988 else parse_error
("unexpected close in skipped " ^ tag
) s spos
990 parse
{ f = toplevel; accu
= () } s;
993 let do_load f contents
=
996 | Parser.Parse_error
(msg
, s, pos
) ->
997 let subs = Parser.subs s pos
in
998 Utils.error
"parse error: %s: at %d [..%S..]" msg pos
subs
1000 | exn
-> Utils.error
"parse error: %s" @@ exntos exn
1002 let load2 f default
=
1003 match filecontents
!S.confpath with
1004 | contents
-> f @@ do_load get contents
1005 | exception Unix.Unix_error
(Unix.ENOENT
, "open", _) ->
1006 f (Hashtbl.create
0, defconf
)
1008 dolog
"error loading configuration from `%S': %s"
1009 !S.confpath @@ exntos exn
;
1012 let load1 f = load2 f false
1020 (fun path (conf, _, _, _, _) ((_, besttime
) as best
) ->
1021 if conf.lastvisit
> besttime
1022 then (path, conf.lastvisit
)
1025 (!S.path, -.infinity
)
1029 let pc, pb
, px
, pa
, po
=
1030 let def = dc, [], 0, E.j
, !S.origin in
1034 let absname = abspath
!S.path in
1035 match Hashtbl.find h absname with
1036 | (c,b,x,a
,_) -> (c,b,x,a
,!S.origin)
1037 | exception Not_found
->
1038 let exception E
of (conf * outline list
* int * anchor * string) in
1039 let key = try Digest.file
absname |> Digest.to_hex
with _ -> E.s in
1043 Hashtbl.iter
(fun p
((c, _, _, _, _) as v
) ->
1046 dolog
"will use %s's settings due to matching keys" p
;
1053 | exception E v
-> v
1067 Hashtbl.fold (fun path (pc, pb
, px
, pa
, po
) accu
->
1068 (path, pc, pb
, px
, pa
, po
) :: accu
)
1073 let add_attrs bb always
dc c time
=
1075 Buffer.add_string bb
"\n ";
1076 Printf.bprintf bb fmt
s
1078 let o c fmt
s = if c then o' fmt
s else ignore
in
1079 let ob s a
b = o (always
|| a
!= b) "%s='%b'" s a
1080 and op
s a
b = o (always
|| a
<> b) "%s='%b'" s (a
!= None
)
1081 and oi
s a
b = o (always
|| a
!= b) "%s='%d'" s a
1082 and oI
s a
b = o (always
|| a
!= b) "%s='%s'" s (string_with_suffix_of_int a
)
1083 and oz
s a
b = o (always
|| a
<> b) "%s='%g'" s (a
*.100.)
1084 and oF
s a
b = o (always
|| a
<> b) "%s='%f'" s a
1085 and oL
s a
b = o (always
|| a
<> b) "%s='%Ld'" s a
1086 and oc
s a
b = o (always
|| a
<> b) "%s='%s'" s (color_to_string a
)
1087 and oA
s a
b = o (always
|| a
<> b) "%s='%s'" s (rgba_to_string a
)
1088 and oC
s a
b = o (always
|| a
<> b) "%s='%s'" s (CSTE.to_string a
)
1089 and oR
s a
b = o (always
|| a
<> b) "%s='%s'" s (irect_to_string a
)
1090 and oFm
s a
b = o (always
|| a
<> b) "%s='%s'" s (FMTE.to_string a
)
1092 o (always
|| a
land m
<> b land m
) "%s='%b'" s (a
land m
!= 0)
1093 and oPm
s a
b = o (always
|| a
<> b) "%s='%s'" s (MTE.to_string a
)
1095 o (always
|| a
<> b) "%s='%s'" s @@ Parser.enent a
0 (String.length a
)
1100 | Cmulti
((n, a
, b), _) when n > 1 -> o'
"%s='%d,%d,%d'" s n a
b
1101 | Csplit
(n, _) when n > 1 -> o'
"%s='%d'" s ~
-n
1102 | Cmulti
_ | Csplit
_ | Csingle
_ -> ()
1107 | Some
c when c > 1 -> o'
"%s='%d'" s c
1110 oi
"width" c.cwinw
dc.cwinw
;
1111 oi
"height" c.cwinh
dc.cwinh
;
1112 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
1113 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
1114 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb scrollbhv
;
1115 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb scrollbvv
;
1116 ob "case-insensitive-search" c.icase
dc.icase
;
1117 ob "preload" c.preload
dc.preload
;
1118 oi
"page-bias" c.pagebias
dc.pagebias
;
1119 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
1120 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
1121 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
1122 ob "highlight-links" c.hlinks
dc.hlinks
;
1123 ob "under-cursor-info" c.underinfo
dc.underinfo
;
1124 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
1125 oz
"zoom" c.zoom dc.zoom;
1126 ob "presentation" c.presentation
dc.presentation
;
1127 oi
"rotation-angle" c.angle
dc.angle
;
1128 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
1129 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
1130 oi
"tex-count" c.texcount
dc.texcount
;
1131 oi
"slice-height" c.sliceheight
dc.sliceheight
;
1132 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
1133 oc
"background-color" c.bgcolor
dc.bgcolor
;
1134 oA
"paper-color" c.papercolor
dc.papercolor
;
1135 oA
"scrollbar-color" c.sbarcolor
dc.sbarcolor
;
1136 oA
"scrollbar-handle-color" c.sbarhndlcolor
dc.sbarhndlcolor
;
1137 oA
"texture-color" c.texturecolor
dc.texturecolor
;
1138 oi
"tile-width" c.tilew
dc.tilew
;
1139 oi
"tile-height" c.tileh
dc.tileh
;
1140 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
1141 oi
"aalevel" c.aalevel
dc.aalevel
;
1142 ob "trim-margins" c.trimmargins
dc.trimmargins
;
1143 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
1144 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
1145 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
1146 oC
"color-space" c.colorspace
dc.colorspace
;
1147 ob "invert-colors" c.invert
dc.invert
;
1148 oF
"brightness" c.colorscale
dc.colorscale
;
1149 oco
"columns" c.columns
dc.columns
;
1150 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
1151 os
"selection-command" c.selcmd
dc.selcmd
;
1152 os
"paste-command" c.pastecmd
dc.pastecmd
;
1153 os
"synctex-command" c.stcmd
dc.stcmd
;
1154 os
"pax-command" c.paxcmd
dc.paxcmd
;
1155 os
"askpass-command" c.passcmd
dc.passcmd
;
1156 os
"savepath-command" c.savecmd
dc.savecmd
;
1157 ob "update-cursor" c.updatecurs
dc.updatecurs
;
1158 oi
"hint-font-size" c.hfsize
dc.hfsize
;
1159 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
1160 oF
"page-scroll-scale" c.pgscale
dc.pgscale
;
1161 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
1162 ob "remote-in-a-new-instance" c.riani
dc.riani
;
1163 op
"point-and-x" c.pax
dc.pax
;
1164 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
1165 ob "scroll-bar-on-the-left" c.leftscroll
dc.leftscroll
;
1167 then os
"title" c.title
dc.title
;
1168 oL
"last-visit" (Int64.of_float time
) 0L;
1169 ob "edit-annotations-inline" c.annotinline
dc.annotinline
;
1170 ob "coarse-presentation-positioning" c.coarseprespos
dc.coarseprespos
;
1171 ob "use-document-css" c.usedoccss
dc.usedoccss
;
1172 os
"dcf" c.dcf
dc.dcf
;
1173 os
"hint-charset" c.hcs
dc.hcs
;
1174 oi
"rlw" c.rlw
dc.rlw
;
1175 oi
"rlh" c.rlh
dc.rlh
;
1176 oi
"rlem" c.rlem
dc.rlem
1178 let keymapsbuf always
dc c =
1180 let bb = create
16 in
1181 let rec loop = function
1183 | (modename, h) :: rest
->
1184 let dh = findkeyhash dc modename in
1185 if always
|| h <> dh
1187 if Hashtbl.length
h > 0
1189 if length
bb > 0 then add_char
bb '
\n'
;
1190 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
1191 Hashtbl.iter
(fun i
o ->
1192 if always
|| match Hashtbl.find dh i
1193 with | dO
-> dO
<> o | exception Not_found
-> false
1196 if Wsi.withctrl m
then add_string
bb "ctrl-";
1197 if Wsi.withalt m
then add_string
bb "alt-";
1198 if Wsi.withshift m
then add_string
bb "shift-";
1199 if Wsi.withmeta m
then add_string
bb "meta-";
1200 add_string
bb (Wsi.keyname
k);
1203 let rec loop = function
1205 | km
:: [] -> addkm km
1206 | km
:: rest
-> addkm km
; add_char
bb ' '
; loop rest
1210 add_string
bb "<map in='";
1214 add_string
bb "' out='"; addkm km
; add_string
bb "'/>\n"
1217 add_string
bb "' out='"; addkms kms
; add_string
bb "'/>\n"
1219 | KMmulti
(ins
, kms
) ->
1220 add_char
bb ' '
; addkms ins
; add_string
bb "' out='";
1221 addkms kms
; add_string
bb "'/>\n"
1223 add_string
bb "</keymap>";
1231 let keystostrlist c =
1232 let rec loop accu
= function
1234 | (modename, h) :: rest
->
1236 if Hashtbl.length
h > 0
1238 let accu = Printf.sprintf
"\xc2\xb7Keys for %s" modename :: accu in
1239 Hashtbl.fold (fun i
o a
->
1240 let bb = Buffer.create
10 in
1242 if Wsi.withctrl m
then Buffer.add_string
bb "ctrl-";
1243 if Wsi.withalt m
then Buffer.add_string
bb "alt-";
1244 if Wsi.withshift m
then Buffer.add_string
bb "shift-";
1245 if Wsi.withmeta m
then Buffer.add_string
bb "meta-";
1246 Buffer.add_string
bb (Wsi.keyname
k);
1249 let rec loop = function
1251 | km
:: [] -> addkm km
1253 addkm km
; Buffer.add_char
bb ' '
;
1259 Buffer.add_char
bb '
\t'
;
1261 | KMinsrt km
-> addkm km
1262 | KMinsrl kms
-> addkms kms
1263 | KMmulti
(ins
, kms
) ->
1264 Buffer.add_char
bb ' '
;
1266 Buffer.add_string
bb "\t";
1269 Buffer.contents
bb :: a
1278 let save1 bb leavebirdseye
x h dc =
1279 let uifontsize = fstate.fontsize
in
1280 Buffer.add_string
bb "<llppconfig>\n";
1281 if nonemptystr
!S.fontpath
1283 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
1284 uifontsize !S.fontpath
1288 then Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
1291 Buffer.add_string
bb "<defaults";
1292 add_attrs bb true dc dc nan
;
1293 let kb = keymapsbuf true dc dc in
1294 if Buffer.length
kb > 0
1296 Buffer.add_string
bb ">\n";
1297 Buffer.add_buffer
bb kb;
1298 Buffer.add_string
bb "\n</defaults>\n";
1300 else Buffer.add_string
bb "/>\n";
1302 let adddoc path pan
anchor c bookmarks time
origin =
1303 if not
(bookmarks == [] && c = dc && anchor = E.j
)
1305 Printf.bprintf
bb "<doc path='%s'"
1306 (Parser.enent
path 0 (String.length
path));
1308 if nonemptystr
c.key
1310 Printf.bprintf
bb "\n key='%s'" c.key;
1313 if nonemptystr
origin
1315 Printf.bprintf
bb "\n origin='%s'"
1316 (Parser.enent
origin 0 (String.length
origin));
1321 let n, rely
, visy
= anchor in
1322 Printf.bprintf
bb "\n page='%d'" n;
1325 then Printf.bprintf
bb " rely='%f'" rely
;
1327 if abs_float visy
> 1e-6
1328 then Printf.bprintf
bb " visy='%f'" visy
;
1332 then Printf.bprintf
bb " pan='%d'" pan
;
1334 add_attrs bb false dc c time
;
1335 if nonemptystr
c.css
1336 then Printf.bprintf
bb ">\n <css><![CDATA[%s]]></css>" c.css
;
1337 let kb = keymapsbuf false dc c in
1339 begin match bookmarks with
1341 if Buffer.length
kb > 0
1343 Buffer.add_string
bb ">\n";
1344 Buffer.add_buffer
bb kb;
1345 Buffer.add_string
bb "\n</doc>\n";
1348 if nonemptystr
c.css
1349 then Buffer.add_string
bb "\n</doc>\n"
1350 else Buffer.add_string
bb "/>\n"
1353 Buffer.add_string
bb ">\n<bookmarks>\n";
1354 List.iter
(fun (title
, _, kind
) ->
1355 begin match kind
with
1356 | Oanchor
(page, rely
, visy
) ->
1358 "<item title='%s' page='%d'"
1359 (Parser.enent title
0 (String.length title
))
1362 then Printf.bprintf
bb " rely='%f'" rely
;
1363 if abs_float visy
> 1e-6
1364 then Printf.bprintf
bb " visy='%f'" visy
;
1366 | Ohistory
_ | Onone
| Ouri
_ | Oremote
_
1367 | Oremotedest
_ | Olaunch
_ -> error
"unexpected link in bookmarks"
1369 Buffer.add_string
bb "/>\n";
1371 Buffer.add_string
bb "</bookmarks>";
1372 if Buffer.length
kb > 0
1374 Buffer.add_string
bb "\n";
1375 Buffer.add_buffer
bb kb;
1377 Buffer.add_string
bb "\n</doc>\n"
1384 | Birdseye
(c, pan, _, _, _) ->
1386 match conf.columns
with
1387 | Cmulti
((c, _, _), _) -> Some
c
1391 match c.columns
with
1392 | Cmulti
(c, _) -> Cmulti
(c, E.a
)
1393 | Csingle
_ -> Csingle
E.a
1394 | Csplit
_ -> failwith
"quit from bird's eye while split"
1396 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
1399 | LinkNav
_ -> x, conf
1401 let docpath = if nonemptystr
!S.path then abspath
!S.path else E.s in
1402 if nonemptystr
docpath
1404 adddoc docpath pan (getanchor ())
1406 begin match !S.mode with
1407 | Birdseye beye
-> leavebirdseye beye
true
1413 autoscrollstep
= (match !S.autoscroll with
1415 | None
-> conf.autoscrollstep
)
1416 ; key = (if emptystr
conf.key
1417 then (try Digest.file
docpath |> Digest.to_hex
with _ -> E.s)
1425 Hashtbl.iter
(fun path (c, bookmarks, x, anchor, origin) ->
1426 if docpath <> abspath
path
1427 then adddoc path x anchor c bookmarks c.lastvisit
origin
1429 Buffer.add_string
bb "</llppconfig>\n";
1432 let save leavebirdseye
=
1433 let relx = float !S.x /. float !S.winw in
1435 let cx w = truncate
(relx *. float w) in
1437 (fun (w, h, x) ws
->
1439 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
1440 | Wsi.MaxVert
-> (w, conf.cwinh
, x)
1441 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
1443 (!S.winw, !S.winh, !S.x) !S.winstate
1447 let bb = Buffer.create
32768 in
1448 let save2 (h, dc) = save1 bb leavebirdseye
x h dc in
1449 if load1 save2 && Buffer.length
bb > 0
1452 let tmp = !S.confpath ^
".tmp" in
1453 let oc = open_out_bin
tmp in
1454 Buffer.output_buffer
oc bb;
1456 Unix.rename
tmp !S.confpath;
1457 with exn
-> dolog
"error saving configuration: %s" @@ exntos exn
1460 let href = ref @@ Hashtbl.create
0 in
1461 let cref = ref defconf
in
1464 if Sys.file_exists
path
1466 else (dolog1
"removing entry for %S" path; None
) in
1467 Hashtbl.filter_map_inplace
f h;
1472 ignore
(load1 push);
1473 let bb = Buffer.create
32768 in
1474 let save2 (_h
, dc) = save1 bb (fun _ _ -> ()) 0 !href dc in
1475 if load1 save2 && Buffer.length
bb > 0
1478 let tmp = !S.confpath ^
".tmp" in
1479 let oc = open_out_bin
tmp in
1480 Buffer.output_buffer
oc bb;
1482 Unix.rename
tmp !S.confpath;
1483 with exn
-> dolog
"error saving configuration: %s" @@ exntos exn
1486 let logcurrently = function
1487 | Idle
-> dolog
"Idle"
1488 | Loading
(l, gen) -> dolog
"Loading %d gen=%d curgen=%d" l.pageno gen !S.gen
1489 | Tiling
(l, pageopaque
, colorspace
, angle
, gen, col
, row
, tilew
, tileh
) ->
1490 dolog
"Tiling %d[%d,%d] page=%s cs=%s angle=%d"
1491 l.pageno col row
(Opaque.to_string pageopaque
)
1492 (CSTE.to_string colorspace
) angle
;
1493 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1494 angle
gen conf.angle
!S.gen
1496 conf.tilew
conf.tileh
1497 | Outlining
_ -> dolog
"outlining"