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
* w
* h
* tilex
* tiley
)
44 | Utextannot
of (opaque
* slinkindex
)
45 | Ufileannot
of (opaque
* slinkindex
)
48 and launchcommand
= string
58 | LDfirstvisible
of (int * int * int)
66 and anchor
= pageno
* top
* dtop
67 and rect
= float * float * float * float * float * float * float * float
68 and infochange
= | Memused
| Docinfo
| Pdim
69 and redirstderr
= bool
71 { mutable fontsize
: int
72 ; mutable wwidth
: float
73 ; mutable maxrows
: int
77 { fontsize
= Wsi.fontsizescale
20
85 method key
: int -> int -> uioh
86 method button
: int -> bool -> int -> int -> int -> uioh
87 method multiclick
: int -> int -> int -> int -> uioh
88 method motion
: int -> int -> uioh
89 method pmotion
: int -> int -> uioh
90 method infochanged
: infochange
-> unit
91 method scrollpw
: (int * float * float)
92 method scrollph
: (int * float * float)
93 method modehash
: keyhash
94 method eformsgs
: bool
95 method alwaysscrolly
: bool
96 method scroll
: int -> int -> uioh
97 method zoom
: float -> int -> int -> unit
100 module type TextEnumType
= sig
103 val names
: string array
106 module TextEnumMake
(Ten
: TextEnumType
) = struct
107 let names = Ten.names
108 let to_int (t
: Ten.t
) = Obj.magic t
109 let to_string t
= names.(to_int t
)
110 let of_int n
: Ten.t
= Obj.magic n
113 if i
= Array.length
names
114 then error
"invalid %s: %s" Ten.name s
123 module CSTE
= TextEnumMake
(struct
125 let name = "colorspace"
126 let names = [|"rgb"; "gray"|]
129 module MTE
= TextEnumMake
(struct
132 let names = [|"page"; "block"; "line"; "word"|]
135 module FMTE
= TextEnumMake
(struct
137 let name = "fitmodel"
138 let names = [|"width"; "proportional"; "page"|]
145 | Olaunch
of launchcommand
146 | Oremote
of (filename
* pageno
)
147 | Oremotedest
of (filename
* destname
)
148 | Ohistory
of (filename
* conf
* outline list
* x
* anchor
* filename
)
149 and outline
= (caption
* outlinelevel
* outlinekind
)
150 and outlinelevel
= int
166 type tile
= opaque
* pixmapsize
* elapsed
168 and pagemapkey
= pageno
* gen
169 and tilemapkey
= pageno
* gen
* colorspace
* angle
* w
* h
* col
* row
174 | Loading
of (page
* gen
)
176 of (page
* opaque
* colorspace
* angle
* gen
* col
* row
* w
* h
)
177 | Outlining
of outline list
181 | Msel
of (mpos
* mpos
)
183 | Mscrolly
| Mscrollx
184 | Mzoom
of (buttonno
* step
* mpos
)
185 | Mzoomrect
of (mpos
* mpos
)
190 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
191 | Textentry
of (textentry
* onleave
)
192 | LinkNav
of linktarget
193 and onleave
= leavetextentrystatus
-> unit
194 and leavetextentrystatus
= | Cancel
| Confirm
195 and helpitem
= string * int * action
196 and action
= (uioh
-> uioh
) option
198 | Ltexact
of (pageno
* direction
)
199 | Ltgendir
of direction
200 | Ltnotready
of (pageno
* direction
)
201 and direction
= int (* -1, 0, 1 *)
202 and textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
203 and onkey
= string -> Keys.t
-> te
204 and ondone
= string -> unit
205 and histcancel
= unit -> unit
206 and onhist
= ((histcmd
-> string) * histcancel
)
207 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
208 and cancelonempty
= bool
213 | TEswitch
of textentry
225 let emptykeyhash = Hashtbl.create
0
232 method key _ _
= self
233 method multiclick _ _ _ _
= self
234 method button _ _ _ _ _
= self
235 method motion _ _
= self
236 method pmotion _ _
= self
237 method infochanged _
= ()
238 method scrollpw
= (0, nan
, nan
)
239 method scrollph
= (0, nan
, nan
)
240 method modehash
= emptykeyhash
241 method eformsgs
= false
242 method alwaysscrolly
= false
243 method scroll _ _
= self
244 method zoom _ _ _
= ()
248 { store
= Array.make n v
254 let cbcap b
= Array.length b
.store
256 let cbput ?
(update_rc
=true) b v
=
259 b
.wc
<- (b
.wc
+ 1) mod cap;
262 b
.len
<- min
(b
.len
+ 1) cap
264 let cbput_dont_update_rc b v
= cbput ~update_rc
:false b v
266 let cbempty b
= b
.len
= 0
268 let cbgetg b circular dir
=
272 let rc = b
.rc + dir
in
284 else bound
rc 0 (b
.len
-1)
289 let cbget b
= cbgetg b
false
290 let cbgetc b
= cbgetg b
true
293 { pat
: string circbuf
294 ; pag
: string circbuf
295 ; sel
: string circbuf
299 try Sys.getenv
"HOME"
301 dolog
"cannot determine home directory location: %s" @@ exntos exn
;
306 let dir = Filename.concat
home ".config" in
307 if Sys.is_directory
dir then dir else home
309 Filename.concat
dir "llpp.conf"
312 let confpath = ref defconfpath
313 let ss = ref Unix.stdin
314 let wsfd = ref Unix.stdin
315 let stderr = ref Unix.stdin
316 let selfexec = ref E.s
317 let ignoredoctitlte = ref false
318 let errmsgs = Buffer.create
0
319 let newerrmsgs = ref false
326 let ranchors : (string * string * anchor * string) list
ref = ref []
327 let maxy = ref max_int
328 let layout : page list
ref = ref []
329 let pagemap : (pagemapkey
, opaque
) Hashtbl.t
= Hashtbl.create
0
330 let tilemap : (tilemapkey
, tile
) Hashtbl.t
= Hashtbl.create
0
331 let pdims : (pageno
* w * h
* leftx
) list
ref = ref []
332 let pagecount = ref max_int
333 let currently = ref Idle
334 let mstate = ref Mnone
335 let searchpattern = ref E.s
336 let rects : (pageno
* rectcolor
* rect
) list
ref = ref []
337 let rects1 : (pageno
* rectcolor
* rect
) list
ref = ref []
340 let password = ref E.s
341 let nameddest = ref E.s
343 let winstate : Wsi.winstate list
ref = ref []
344 let mode : mode ref = ref View
345 let uioh : uioh ref = ref nouioh
346 let outlines : outline array
ref = ref [||]
347 let bookmarks : outline list
ref = ref []
348 let geomcmds : (string * ((string * (unit -> unit)) list
)) ref
350 let memused : memsize
ref = ref 0
351 let gen : gen ref = ref 0
352 let autoscroll : int option ref = ref None
353 let help : helpitem array
ref = ref E.a
354 let docinfo : (int * string) list
ref = ref []
355 let hists : hists ref
356 = ref { pat
= cbnew 10 E.s
; pag
= cbnew 10 E.s
; sel
= cbnew 10 E.s
; }
357 let prevzoom = ref (1.0, 0)
358 let progress = ref ~
-.1.0
359 let mpos = ref (-1, -1)
360 let keystate = ref KSnone
361 let glinks = ref false
362 let prevcolumns : (columns
* zoom
) option ref = ref None
365 let reprf = ref noreprf
366 let roamf = ref noroamf
367 let bzoom = ref false
368 let lnava : (pageno
* linkno
) option ref = ref None
369 let reload : (x * y * float) option ref = ref None
370 let nav : anchor nav ref = ref { past
= []; future
= []; }
371 let tilelru : (tilemapkey
* opaque
* pixmapsize
) Queue.t
= Queue.create
()
372 let fontpath = ref E.s
373 let redirstderr = ref false
376 let conf = { defconf
with keyhashes
= copykeyhashes defconf
}
379 let d = !S.winh - h
in
380 max
conf.interpagespace
((d + 1) / 2)
382 let rowyh (c
, coverA
, coverB
) b n
=
383 if c
= 1 || (n
< coverA
|| n
>= !S.pagecount - coverB
)
385 let _, _, vy
, (_, _, h
, _) = b
.(n
) in
388 let n'
= n - coverA
in
391 let e = min
!S.pagecount (s + c
) in
392 let rec findminmax m miny maxh
=
396 let _, _, y, (_, _, h
, _) = b
.(m
) in
397 let miny = min
miny y in
398 let maxh = max
maxh h
in
399 findminmax (m
+1) miny maxh
401 findminmax s max_int
0
404 let ((c
, coverA
, coverB
) as cl
), b
=
405 match conf.columns
with
406 | Csplit
(_, b
) | Csingle b
-> (1, 0, 0), b
407 | Cmulti
(c
, b
) -> c
, b
409 if Array.length b
= 0
412 let rec bsearch nmin nmax
=
414 then bound nmin
0 (!S.pagecount-1)
416 let n = (nmax
+ nmin
) / 2 in
417 let vy, h
= rowyh cl b
n in
421 let ips = calcips h
in
423 let y1 = vy + h
+ ips in
427 then 0, vy + h
+ conf.interpagespace
429 let y0 = vy - conf.interpagespace
in
430 y0, y0 + h
+ conf.interpagespace
440 if n < !S.pagecount - coverB
441 then ((n-coverA
)/c
)*c
+ coverA
448 then bsearch (n+1) nmax
449 else bsearch nmin
(n-1)
452 bsearch 0 (!S.pagecount-1)
455 match conf.columns
with
456 | Cmulti
((_, _, _) as cl
, b
) ->
457 if Array.length b
> 0
459 let y, h
= rowyh cl b
(Array.length b
- 1) in
460 y + h
+ (if conf.presentation
then calcips h
else 0)
463 if Array.length b
> 0
465 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
466 y + h
+ (if conf.presentation
then calcips h
else 0)
469 if Array.length b
> 0
471 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
475 let getpageywh pageno
=
476 let pageno = bound
pageno 0 (!S.pagecount-1) in
477 match conf.columns
with
479 if Array.length b
= 0
482 let (_, _, y, (_, w, h
, _)) = b
.(pageno) in
490 if Array.length b
= 0
493 let y, h
= rowyh cl b
pageno in
494 let (_, _, _, (_, w, _, _)) = b
.(pageno) in
502 if Array.length b
= 0
506 let (_, _, y, (_, w, h
, _)) = b
.(n) in
509 let getpageyh pageno =
510 let y,_,h
= getpageywh pageno in
513 let getpagedim pageno =
516 | (n, _, _, _) as pdim
:: rest
->
518 then (if n = pageno then pdim
else ppdim
)
522 f (-1, -1, -1, -1) !S.pdims
524 let getpdimno pageno =
528 | (n, _, _, _) :: rest
->
530 then (if n = pageno then np else p
)
536 let getpagey pageno = fst
(getpageyh pageno)
540 let coloff = l
.pagecol
* l
.pageh
in
541 float (l
.pagey
+ coloff) /. float l
.pageh
548 then float l
.pagedispy
/. float (calcips l
.pageh
)
549 else float l
.pagedispy
/. float conf.interpagespace
552 (l
.pageno, top, dtop)
556 | l
:: _ -> getanchor1 l
558 let n = page_of_y !S.y in
562 let y, h
= getpageyh n in
567 let ips = calcips h
in
568 float (dy + ips) /. float ips
569 else float dy /. float conf.interpagespace
573 type historder
= [ `lastvisit
| `title
| `
path | `file
]
576 Map.Make
(struct type t
= (int * int) let compare = compare end)
579 let l = String.length
s in
580 let b = Buffer.create
l in
581 Parser.unent
b s 0 l;
584 let modifier_of_string = function
585 | "alt" -> Wsi.altmask
586 | "shift" -> Wsi.shiftmask
587 | "ctrl" | "control" -> Wsi.ctrlmask
588 | "meta" -> Wsi.metamask
591 let keys_of_string s =
592 let key_of_string r
s =
593 let elems = Str.full_split r
s in
596 let m1 = modifier_of_string s in
598 then (Wsi.namekey
s, m
)
601 | Str.Delim
s when n land 1 = 0 -> g s
603 | Str.Delim
_ -> (k
, m
)
605 let rec loop n k m
= function
608 let k, m
= f n k m
x in
613 let elems = Str.split
Utils.Re.whitespace
s in
614 List.map
(key_of_string (Str.regexp
"-")) elems
617 let l = String.length v
in
619 then error
"set must contain more than one char, but has %d" l;
620 let module S
= Set.Make
(struct type t
= char
let compare = compare end) in
624 let e = String.get v i
in
626 then error
"set has duplicates (at least '%c')" e
627 else check (S.add
e s) (i
+1)
629 check (S.singleton
(String.get v
0)) 1
631 let config_of c attrs
=
632 let maxv ?
(f=int_of_string
) u
s = max u
@@ f s in
636 | "scroll-bar-width" -> { c
with scrollbw
= maxv 0 v
}
637 | "scroll-handle-height" -> { c
with scrollh
= maxv 0 v
}
638 | "case-insensitive-search" -> { c
with icase
= bool_of_string v
}
639 | "preload" -> { c
with preload
= bool_of_string v
}
640 | "page-bias" -> { c
with pagebias
= int_of_string v
}
641 | "scroll-step" -> { c
with scrollstep
= maxv 1 v
}
642 | "horizontal-scroll-step" -> { c
with hscrollstep
= maxv 1 v
}
643 | "auto-scroll-step" -> { c
with autoscrollstep
= maxv 0 v
}
644 | "max-height-fit" -> { c
with maxhfit
= bool_of_string v
}
645 | "highlight-links" -> { c
with hlinks
= bool_of_string v
}
646 | "under-cursor-info" -> { c
with underinfo
= bool_of_string v
}
647 | "vertical-margin" -> { c
with interpagespace
= maxv 0 v
}
649 let zoom = float_of_string v
/. 100. in
650 let zoom = max
zoom 0.0 in
651 { c
with zoom = zoom }
652 | "presentation" -> { c
with presentation
= bool_of_string v
}
653 | "rotation-angle" -> { c
with angle
= int_of_string v
}
654 | "width" -> { c
with cwinw
= maxv 20 v
}
655 | "height" -> { c
with cwinh
= maxv 20 v
}
656 | "proportional-display" ->
657 { c
with fitmodel
= if bool_of_string v
661 | "fit-model" -> { c
with fitmodel
= FMTE.of_string v
}
662 | "pixmap-cache-size" ->
663 { c
with memlimit
= maxv ~
f:int_of_string_with_suffix
2 v
}
664 | "tex-count" -> { c
with texcount
= maxv 1 v
}
665 | "slice-height" -> { c
with sliceheight
= maxv 2 v
}
666 | "thumbnail-width" -> { c
with thumbw
= maxv 2 v
}
667 | "background-color" -> { c
with bgcolor
= color_of_string v
}
668 | "paper-color" -> { c
with papercolor
= rgba_of_string v
}
669 | "scrollbar-color" -> { c
with sbarcolor
= rgba_of_string v
}
670 | "scrollbar-handle-color" -> { c
with sbarhndlcolor
= rgba_of_string v
}
671 | "texture-color" -> { c
with texturecolor
= rgba_of_string v
}
672 | "tile-width" -> { c
with tilew
= maxv 2 v
}
673 | "tile-height" -> { c
with tileh
= maxv 2 v
}
674 | "mupdf-store-size" ->
675 { c
with mustoresize
= maxv ~
f:int_of_string_with_suffix
1024 v
}
676 | "aalevel" -> { c
with aalevel
= maxv 0 v
}
677 | "trim-margins" -> { c
with trimmargins
= bool_of_string v
}
678 | "trim-fuzz" -> { c
with trimfuzz
= irect_of_string v
}
679 | "uri-launcher" -> { c
with urilauncher
= unentS v
}
680 | "path-launcher" -> { c
with pathlauncher
= unentS v
}
681 | "color-space" -> { c
with colorspace
= CSTE.of_string v
}
682 | "invert-colors" -> { c
with invert
= bool_of_string v
}
683 | "brightness" -> { c
with colorscale
= float_of_string v
}
685 let (n, _, _) as nab
= multicolumns_of_string v
in
687 then { c
with columns
= Csplit
(-n, E.a
) }
688 else { c
with columns
= Cmulti
(nab
, E.a
) }
689 | "birds-eye-columns" -> { c
with beyecolumns
= Some
(maxv 2 v
) }
690 | "selection-command" -> { c
with selcmd
= unentS v
}
691 | "paste-command" -> { c
with pastecmd
= unentS v
}
692 | "synctex-command" -> { c
with stcmd
= unentS v
}
693 | "pax-command" -> { c
with paxcmd
= unentS v
}
694 | "askpass-command" -> { c
with passcmd
= unentS v
}
695 | "savepath-command" -> { c
with savecmd
= unentS v
}
696 | "update-cursor" -> { c
with updatecurs
= bool_of_string v
}
697 | "hint-font-size" -> { c
with hfsize
= bound
(int_of_string v
) 5 100 }
698 | "page-scroll-scale" -> { c
with pgscale
= float_of_string v
}
699 | "wheel-scrolls-pages" -> { c
with wheelbypage
= bool_of_string v
}
700 | "horizontal-scrollbar-visible" ->
701 { c
with scrollb
= if bool_of_string v
702 then c
.scrollb
lor scrollbhv
703 else c
.scrollb
land (lnot scrollbhv
)
705 | "vertical-scrollbar-visible" ->
706 { c
with scrollb
= if bool_of_string v
707 then c
.scrollb
lor scrollbvv
708 else c
.scrollb
land (lnot scrollbvv
)
710 | "remote-in-a-new-instance" -> { c
with riani
= bool_of_string v
}
712 { c
with pax
= if bool_of_string v
then Some
0.0 else None
}
713 | "point-and-x-mark" -> { c
with paxmark
= MTE.of_string v
}
714 | "scroll-bar-on-the-left" -> { c
with leftscroll
= bool_of_string v
}
715 | "title" -> { c
with title
= unentS v
}
716 | "last-visit" -> { c
with lastvisit
= float_of_string v
}
717 | "edit-annotations-inline" -> { c
with annotinline
= bool_of_string v
}
718 | "coarse-presentation-positioning" ->
719 { c
with coarseprespos
= bool_of_string v
}
720 | "use-document-css" -> { c
with usedoccss
= bool_of_string v
}
721 | "hint-charset" -> validatehcs v
; { c
with hcs
= v
}
722 | "rlw" -> { c
with rlw
= int_of_string v
}
723 | "rlh" -> { c
with rlh
= int_of_string v
}
724 | "rlem" -> { c
with rlem
= int_of_string v
}
727 dolog
"error processing attribute (`%S' = `%S'): %s" k v
@@ exntos exn
;
730 let rec fold c
= function
733 let c = apply c k v
in
736 fold { c with keyhashes
= copykeyhashes
c } attrs
738 let fromstring f pos
n v
d =
741 dolog
"error processing attribute (%S=%S) at %d\n%s" n v pos
@@ exntos exn
;
744 let bookmark_of attrs
=
745 let rec fold title page rely visy
= function
746 | ("title", v
) :: rest
-> fold v page rely visy rest
747 | ("page", v
) :: rest
-> fold title v rely visy rest
748 | ("rely", v
) :: rest
-> fold title page v visy rest
749 | ("visy", v
) :: rest
-> fold title page rely v rest
750 | _ :: rest
-> fold title page rely visy rest
751 | [] -> title
, page
, rely
, visy
753 fold "invalid" "0" "0" "0" attrs
756 let rec fold path key page rely pan visy
origin dcf
= function
757 | ("path", v
) :: rest
-> fold v key page rely pan visy
origin dcf rest
758 | ("key", v
) :: rest
-> fold path v page rely pan visy
origin dcf rest
759 | ("page", v
) :: rest
-> fold path key v rely pan visy
origin dcf rest
760 | ("rely", v
) :: rest
-> fold path key page v pan visy
origin dcf rest
761 | ("pan", v
) :: rest
-> fold path key page rely v visy
origin dcf rest
762 | ("visy", v
) :: rest
-> fold path key page rely pan v
origin dcf rest
763 | ("origin", v
) :: rest
-> fold path key page rely pan visy v dcf rest
764 | ("dcf", v
) :: rest
-> fold path key page rely pan visy
origin v rest
765 | _ :: rest
-> fold path key page rely pan visy
origin dcf rest
766 | [] -> path, key
, page
, rely
, pan
, visy
, origin, dcf
768 fold E.s E.s "0" "0" "0" "0" E.s E.s attrs
771 let rec fold rs ls
= function
772 | ("out", v
) :: rest
-> fold v ls rest
773 | ("in", v
) :: rest
-> fold rs v rest
774 | _ :: rest
-> fold ls rs rest
779 let findkeyhash c name =
780 try List.assoc
name c.keyhashes
781 with Not_found
-> error
"invalid mode name `%s'" name
785 let h = Hashtbl.create
10 in
786 let dc = { defconf
with angle
= defconf
.angle
} in
787 let rec toplevel v t spos
_ =
789 | Vdata
| Vcdata
| Vend
-> v
790 | Vopen
("llppconfig", _, closed
) ->
793 else { v
with f = llppconfig
}
794 | Vopen
_ -> parse_error
"unexpected subelement at top level" s spos
795 | Vclose
_ -> parse_error
"unexpected close at top level" s spos
797 and llppconfig v t spos
_ =
799 | Vdata
| Vcdata
-> v
800 | Vend
-> parse_error
"unexpected end of input in llppconfig" s spos
801 | Vopen
("defaults", attrs
, closed
) ->
802 let c = config_of dc attrs
in
806 else { v
with f = defaults
}
808 | Vopen
("ui-font", attrs
, closed
) ->
809 let rec getsize size
= function
811 | ("size", v
) :: rest
->
813 fromstring int_of_string spos
"size" v
fstate.fontsize
in
815 | l -> getsize size l
817 fstate.fontsize
<- getsize fstate.fontsize attrs
;
820 else { v
with f = uifont
(Buffer.create
10) }
822 | Vopen
("doc", attrs
, closed
) ->
823 let pathent, key
, spage
, srely
, span
, svisy
, origin, dcf
825 let path = unentS pathent
826 and origin = unentS origin
827 and pageno = fromstring int_of_string spos
"page" spage
0
828 and rely
= fromstring float_of_string spos
"rely" srely
0.0
829 and pan
= fromstring int_of_string spos
"pan" span
0
830 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
831 let c = config_of dc attrs
in
834 let anchor = (pageno, rely
, visy
) in
836 then (Hashtbl.add
h path (c, [], pan
, anchor, origin); v
)
837 else { v
with f = doc
path origin pan
anchor c [] }
839 | Vopen
_ -> parse_error
"unexpected subelement in llppconfig" s spos
840 | Vclose
"llppconfig" -> { v
with f = toplevel }
841 | Vclose
_ -> parse_error
"unexpected close in llppconfig" s spos
843 and defaults v t spos
_ =
845 | Vdata
| Vcdata
-> v
846 | Vend
-> parse_error
"unexpected end of input in defaults" s spos
847 | Vopen
("keymap", attrs
, closed
) ->
849 try List.assoc
"mode" attrs
850 with Not_found
-> "global" in
855 let h = findkeyhash dc modename in
856 KeyMap.iter
(Hashtbl.replace
h) keymap
;
859 { v
with f = pkeymap
ret KeyMap.empty
}
861 | Vopen
(_, _, _) -> parse_error
"unexpected subelement in defaults" s spos
863 | Vclose
"defaults" ->
864 { v
with f = llppconfig
}
866 | Vclose
_ -> parse_error
"unexpected close in defaults" s spos
868 and uifont
b v t spos epos
=
871 Buffer.add_substring
b s spos
(epos
- spos
);
873 | Vopen
(_, _, _) -> parse_error
"unexpected subelement in ui-font" s spos
874 | Vclose
"ui-font" ->
875 if emptystr
!S.fontpath
876 then S.fontpath := Buffer.contents
b;
877 { v
with f = llppconfig
}
878 | Vclose
_ -> parse_error
"unexpected close in ui-font" s spos
879 | Vend
-> parse_error
"unexpected end of input in ui-font" s spos
881 and doc
path origin pan
anchor c bookmarks v t spos
_ =
883 | Vdata
| Vcdata
-> v
884 | Vend
-> parse_error
"unexpected end of input in doc" s spos
885 | Vopen
("bookmarks", _, closed
) ->
888 else { v
with f = pbookmarks
path origin pan
anchor c bookmarks }
890 | Vopen
("keymap", attrs
, closed
) ->
892 try List.assoc
"mode" attrs
893 with Not_found
-> "global"
899 let h = findkeyhash c modename in
900 KeyMap.iter
(Hashtbl.replace
h) keymap
;
901 doc
path origin pan
anchor c bookmarks
903 { v
with f = pkeymap
ret KeyMap.empty
}
905 | Vopen
("css", [], false) ->
906 { v
with f = pcss
path origin pan
anchor c bookmarks }
909 parse_error
"unexpected subelement in doc" s spos
912 Hashtbl.add
h path (c, List.rev
bookmarks, pan
, anchor, origin);
913 { v
with f = llppconfig
}
915 | Vclose
_ -> parse_error
"unexpected close in doc" s spos
917 and pcss
path origin pan
anchor c bookmarks v t spos epos
=
920 let b = Buffer.create
10 in
921 Buffer.add_substring
b s spos
(epos
- spos
);
922 { v
with f = pcss
path origin pan
anchor
923 { c with css
= Buffer.contents
b }
925 | Vend
-> parse_error
"unexpected end of input in css" s spos
926 | Vopen
_ -> parse_error
"unexpected subelement in css" s spos
927 | Vclose
"css" -> { v
with f = doc
path origin pan
anchor c bookmarks }
928 | Vclose
_ -> parse_error
"unexpected close in css" s spos
930 and pkeymap
ret keymap v t spos
_ =
932 | Vdata
| Vcdata
-> v
933 | Vend
-> parse_error
"unexpected end of input in keymap" s spos
934 | Vopen
("map", attrs
, closed
) ->
935 let r, l = map_of attrs
in
936 let kss = fromstring keys_of_string spos
"in" r [] in
937 let lss = fromstring keys_of_string spos
"out" l [] in
941 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
942 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
945 then { v
with f = pkeymap
ret keymap }
948 { v
with f = skip
"map" f }
950 | Vopen
_ -> parse_error
"unexpected subelement in keymap" s spos
952 { v
with f = ret keymap }
953 | Vclose
_ -> parse_error
"unexpected close in keymap" s spos
955 and pbookmarks
path origin pan
anchor c bookmarks v t spos
_ =
957 | Vdata
| Vcdata
-> v
958 | Vend
-> parse_error
"unexpected end of input in bookmarks" s spos
959 | Vopen
("item", attrs
, closed
) ->
960 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
961 let page = fromstring int_of_string spos
"page" spage
0
962 and rely
= fromstring float_of_string spos
"rely" srely
0.0
963 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
965 (unentS titleent, 0, Oanchor
(page, rely
, visy
)) :: bookmarks
968 then { v
with f = pbookmarks
path origin pan
anchor c bookmarks }
971 { v
with f = skip
"item" f }
973 | Vopen
_ -> parse_error
"unexpected subelement in bookmarks" s spos
974 | Vclose
"bookmarks" ->
975 { v
with f = doc
path origin pan
anchor c bookmarks }
976 | Vclose
_ -> parse_error
"unexpected close in bookmarks" s spos
978 and skip tag
f v t spos
_ =
980 | Vdata
| Vcdata
-> v
981 | Vend
-> parse_error
("unexpected end of input in skipped " ^ tag
) s spos
982 | Vopen
(tag'
, _, closed
) ->
986 let f'
() = { v
with f = skip tag
f } in
987 { v
with f = skip tag'
f'
}
991 else parse_error
("unexpected close in skipped " ^ tag
) s spos
993 parse
{ f = toplevel; accu
= () } s;
996 let do_load f contents
=
999 | Parser.Parse_error
(msg
, s, pos
) ->
1000 let subs = Parser.subs s pos
in
1001 Utils.error
"parse error: %s: at %d [..%S..]" msg pos
subs
1003 | exn
-> Utils.error
"parse error: %s" @@ exntos exn
1005 let load2 f default
=
1006 match filecontents
!S.confpath with
1007 | contents
-> f @@ do_load get contents
1008 | exception Unix.Unix_error
(Unix.ENOENT
, "open", _) ->
1009 f (Hashtbl.create
0, defconf
)
1011 dolog
"error loading configuration from `%S': %s"
1012 !S.confpath @@ exntos exn
;
1015 let load1 f = load2 f false
1023 (fun path (conf, _, _, _, _) ((_, besttime
) as best
) ->
1024 if conf.lastvisit
> besttime
1025 then (path, conf.lastvisit
)
1028 (!S.path, -.infinity
)
1032 let pc, pb
, px
, pa
, po
=
1033 let def = dc, [], 0, E.j
, !S.origin in
1037 let absname = abspath
!S.path in
1038 match Hashtbl.find h absname with
1039 | (c,b,x,a
,_) -> (c,b,x,a
,!S.origin)
1040 | exception Not_found
->
1041 let exception E
of (conf * outline list
* int * anchor * string) in
1042 let key = try Digest.file
absname |> Digest.to_hex
with _ -> E.s in
1046 Hashtbl.iter
(fun p
((c, _, _, _, _) as v
) ->
1049 dolog
"will use %s's settings due to matching keys" p
;
1056 | exception E v
-> v
1070 Hashtbl.fold (fun path (pc, pb
, px
, pa
, po
) accu
->
1071 (path, pc, pb
, px
, pa
, po
) :: accu
)
1076 let add_attrs bb always
dc c time
=
1078 Buffer.add_string bb
"\n ";
1079 Printf.bprintf bb fmt
s
1081 let o c fmt
s = if c then o' fmt
s else ignore
in
1082 let ob s a
b = o (always
|| a
!= b) "%s='%b'" s a
1083 and op
s a
b = o (always
|| a
<> b) "%s='%b'" s (a
!= None
)
1084 and oi
s a
b = o (always
|| a
!= b) "%s='%d'" s a
1085 and oI
s a
b = o (always
|| a
!= b) "%s='%s'" s (string_with_suffix_of_int a
)
1086 and oz
s a
b = o (always
|| a
<> b) "%s='%g'" s (a
*.100.)
1087 and oF
s a
b = o (always
|| a
<> b) "%s='%f'" s a
1088 and oL
s a
b = o (always
|| a
<> b) "%s='%Ld'" s a
1089 and oc
s a
b = o (always
|| a
<> b) "%s='%s'" s (color_to_string a
)
1090 and oA
s a
b = o (always
|| a
<> b) "%s='%s'" s (rgba_to_string a
)
1091 and oC
s a
b = o (always
|| a
<> b) "%s='%s'" s (CSTE.to_string a
)
1092 and oR
s a
b = o (always
|| a
<> b) "%s='%s'" s (irect_to_string a
)
1093 and oFm
s a
b = o (always
|| a
<> b) "%s='%s'" s (FMTE.to_string a
)
1095 o (always
|| a
land m
<> b land m
) "%s='%b'" s (a
land m
!= 0)
1096 and oPm
s a
b = o (always
|| a
<> b) "%s='%s'" s (MTE.to_string a
)
1098 o (always
|| a
<> b) "%s='%s'" s @@ Parser.enent a
0 (String.length a
)
1103 | Cmulti
((n, a
, b), _) when n > 1 -> o'
"%s='%d,%d,%d'" s n a
b
1104 | Csplit
(n, _) when n > 1 -> o'
"%s='%d'" s ~
-n
1105 | Cmulti
_ | Csplit
_ | Csingle
_ -> ()
1110 | Some
c when c > 1 -> o'
"%s='%d'" s c
1113 oi
"width" c.cwinw
dc.cwinw
;
1114 oi
"height" c.cwinh
dc.cwinh
;
1115 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
1116 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
1117 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb scrollbhv
;
1118 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb scrollbvv
;
1119 ob "case-insensitive-search" c.icase
dc.icase
;
1120 ob "preload" c.preload
dc.preload
;
1121 oi
"page-bias" c.pagebias
dc.pagebias
;
1122 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
1123 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
1124 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
1125 ob "highlight-links" c.hlinks
dc.hlinks
;
1126 ob "under-cursor-info" c.underinfo
dc.underinfo
;
1127 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
1128 oz
"zoom" c.zoom dc.zoom;
1129 ob "presentation" c.presentation
dc.presentation
;
1130 oi
"rotation-angle" c.angle
dc.angle
;
1131 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
1132 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
1133 oi
"tex-count" c.texcount
dc.texcount
;
1134 oi
"slice-height" c.sliceheight
dc.sliceheight
;
1135 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
1136 oc
"background-color" c.bgcolor
dc.bgcolor
;
1137 oA
"paper-color" c.papercolor
dc.papercolor
;
1138 oA
"scrollbar-color" c.sbarcolor
dc.sbarcolor
;
1139 oA
"scrollbar-handle-color" c.sbarhndlcolor
dc.sbarhndlcolor
;
1140 oA
"texture-color" c.texturecolor
dc.texturecolor
;
1141 oi
"tile-width" c.tilew
dc.tilew
;
1142 oi
"tile-height" c.tileh
dc.tileh
;
1143 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
1144 oi
"aalevel" c.aalevel
dc.aalevel
;
1145 ob "trim-margins" c.trimmargins
dc.trimmargins
;
1146 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
1147 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
1148 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
1149 oC
"color-space" c.colorspace
dc.colorspace
;
1150 ob "invert-colors" c.invert
dc.invert
;
1151 oF
"brightness" c.colorscale
dc.colorscale
;
1152 oco
"columns" c.columns
dc.columns
;
1153 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
1154 os
"selection-command" c.selcmd
dc.selcmd
;
1155 os
"paste-command" c.pastecmd
dc.pastecmd
;
1156 os
"synctex-command" c.stcmd
dc.stcmd
;
1157 os
"pax-command" c.paxcmd
dc.paxcmd
;
1158 os
"askpass-command" c.passcmd
dc.passcmd
;
1159 os
"savepath-command" c.savecmd
dc.savecmd
;
1160 ob "update-cursor" c.updatecurs
dc.updatecurs
;
1161 oi
"hint-font-size" c.hfsize
dc.hfsize
;
1162 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
1163 oF
"page-scroll-scale" c.pgscale
dc.pgscale
;
1164 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
1165 ob "remote-in-a-new-instance" c.riani
dc.riani
;
1166 op
"point-and-x" c.pax
dc.pax
;
1167 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
1168 ob "scroll-bar-on-the-left" c.leftscroll
dc.leftscroll
;
1170 then os
"title" c.title
dc.title
;
1171 oL
"last-visit" (Int64.of_float time
) 0L;
1172 ob "edit-annotations-inline" c.annotinline
dc.annotinline
;
1173 ob "coarse-presentation-positioning" c.coarseprespos
dc.coarseprespos
;
1174 ob "use-document-css" c.usedoccss
dc.usedoccss
;
1175 os
"dcf" c.dcf
dc.dcf
;
1176 os
"hint-charset" c.hcs
dc.hcs
;
1177 oi
"rlw" c.rlw
dc.rlw
;
1178 oi
"rlh" c.rlh
dc.rlh
;
1179 oi
"rlem" c.rlem
dc.rlem
1181 let keymapsbuf always
dc c =
1183 let bb = create
16 in
1184 let rec loop = function
1186 | (modename, h) :: rest
->
1187 let dh = findkeyhash dc modename in
1188 if always
|| h <> dh
1190 if Hashtbl.length
h > 0
1192 if length
bb > 0 then add_char
bb '
\n'
;
1193 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
1194 Hashtbl.iter
(fun i
o ->
1195 if always
|| match Hashtbl.find dh i
1196 with | dO
-> dO
<> o | exception Not_found
-> false
1199 if Wsi.withctrl m
then add_string
bb "ctrl-";
1200 if Wsi.withalt m
then add_string
bb "alt-";
1201 if Wsi.withshift m
then add_string
bb "shift-";
1202 if Wsi.withmeta m
then add_string
bb "meta-";
1203 add_string
bb (Wsi.keyname
k);
1206 let rec loop = function
1208 | km
:: [] -> addkm km
1209 | km
:: rest
-> addkm km
; add_char
bb ' '
; loop rest
1213 add_string
bb "<map in='";
1217 add_string
bb "' out='"; addkm km
; add_string
bb "'/>\n"
1220 add_string
bb "' out='"; addkms kms
; add_string
bb "'/>\n"
1222 | KMmulti
(ins
, kms
) ->
1223 add_char
bb ' '
; addkms ins
; add_string
bb "' out='";
1224 addkms kms
; add_string
bb "'/>\n"
1226 add_string
bb "</keymap>";
1234 let keystostrlist c =
1235 let rec loop accu
= function
1237 | (modename, h) :: rest
->
1239 if Hashtbl.length
h > 0
1241 let accu = Printf.sprintf
"\xc2\xb7Keys for %s" modename :: accu in
1242 Hashtbl.fold (fun i
o a
->
1243 let bb = Buffer.create
10 in
1245 if Wsi.withctrl m
then Buffer.add_string
bb "ctrl-";
1246 if Wsi.withalt m
then Buffer.add_string
bb "alt-";
1247 if Wsi.withshift m
then Buffer.add_string
bb "shift-";
1248 if Wsi.withmeta m
then Buffer.add_string
bb "meta-";
1249 Buffer.add_string
bb (Wsi.keyname
k);
1252 let rec loop = function
1254 | km
:: [] -> addkm km
1256 addkm km
; Buffer.add_char
bb ' '
;
1262 Buffer.add_char
bb '
\t'
;
1264 | KMinsrt km
-> addkm km
1265 | KMinsrl kms
-> addkms kms
1266 | KMmulti
(ins
, kms
) ->
1267 Buffer.add_char
bb ' '
;
1269 Buffer.add_string
bb "\t";
1272 Buffer.contents
bb :: a
1281 let save1 bb leavebirdseye
x h dc =
1282 let uifontsize = fstate.fontsize
in
1283 Buffer.add_string
bb "<llppconfig>\n";
1284 if nonemptystr
!S.fontpath
1286 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
1287 uifontsize !S.fontpath
1291 then Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
1294 Buffer.add_string
bb "<defaults";
1295 add_attrs bb true dc dc nan
;
1296 let kb = keymapsbuf true dc dc in
1297 if Buffer.length
kb > 0
1299 Buffer.add_string
bb ">\n";
1300 Buffer.add_buffer
bb kb;
1301 Buffer.add_string
bb "\n</defaults>\n";
1303 else Buffer.add_string
bb "/>\n";
1305 let adddoc path pan
anchor c bookmarks time
origin =
1306 if not
(bookmarks == [] && c = dc && anchor = E.j
)
1308 Printf.bprintf
bb "<doc path='%s'"
1309 (Parser.enent
path 0 (String.length
path));
1311 if nonemptystr
c.key
1313 Printf.bprintf
bb "\n key='%s'" c.key;
1316 if nonemptystr
origin
1318 Printf.bprintf
bb "\n origin='%s'"
1319 (Parser.enent
origin 0 (String.length
origin));
1324 let n, rely
, visy
= anchor in
1325 Printf.bprintf
bb "\n page='%d'" n;
1328 then Printf.bprintf
bb " rely='%f'" rely
;
1330 if abs_float visy
> 1e-6
1331 then Printf.bprintf
bb " visy='%f'" visy
;
1335 then Printf.bprintf
bb " pan='%d'" pan
;
1337 add_attrs bb false dc c time
;
1338 if nonemptystr
c.css
1339 then Printf.bprintf
bb ">\n <css><![CDATA[%s]]></css>" c.css
;
1340 let kb = keymapsbuf false dc c in
1342 begin match bookmarks with
1344 if Buffer.length
kb > 0
1346 Buffer.add_string
bb ">\n";
1347 Buffer.add_buffer
bb kb;
1348 Buffer.add_string
bb "\n</doc>\n";
1351 if nonemptystr
c.css
1352 then Buffer.add_string
bb "\n</doc>\n"
1353 else Buffer.add_string
bb "/>\n"
1356 Buffer.add_string
bb ">\n<bookmarks>\n";
1357 List.iter
(fun (title
, _, kind
) ->
1358 begin match kind
with
1359 | Oanchor
(page, rely
, visy
) ->
1361 "<item title='%s' page='%d'"
1362 (Parser.enent title
0 (String.length title
))
1365 then Printf.bprintf
bb " rely='%f'" rely
;
1366 if abs_float visy
> 1e-6
1367 then Printf.bprintf
bb " visy='%f'" visy
;
1369 | Ohistory
_ | Onone
| Ouri
_ | Oremote
_
1370 | Oremotedest
_ | Olaunch
_ -> error
"unexpected link in bookmarks"
1372 Buffer.add_string
bb "/>\n";
1374 Buffer.add_string
bb "</bookmarks>";
1375 if Buffer.length
kb > 0
1377 Buffer.add_string
bb "\n";
1378 Buffer.add_buffer
bb kb;
1380 Buffer.add_string
bb "\n</doc>\n"
1387 | Birdseye
(c, pan, _, _, _) ->
1389 match conf.columns
with
1390 | Cmulti
((c, _, _), _) -> Some
c
1394 match c.columns
with
1395 | Cmulti
(c, _) -> Cmulti
(c, E.a
)
1396 | Csingle
_ -> Csingle
E.a
1397 | Csplit
_ -> failwith
"quit from bird's eye while split"
1399 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
1402 | LinkNav
_ -> x, conf
1404 let docpath = if nonemptystr
!S.path then abspath
!S.path else E.s in
1405 if nonemptystr
docpath
1407 adddoc docpath pan (getanchor ())
1409 begin match !S.mode with
1410 | Birdseye beye
-> leavebirdseye beye
true
1416 autoscrollstep
= (match !S.autoscroll with
1418 | None
-> conf.autoscrollstep
)
1419 ; key = (if emptystr
conf.key
1420 then (try Digest.file
docpath |> Digest.to_hex
with _ -> E.s)
1428 Hashtbl.iter
(fun path (c, bookmarks, x, anchor, origin) ->
1429 if docpath <> abspath
path
1430 then adddoc path x anchor c bookmarks c.lastvisit
origin
1432 Buffer.add_string
bb "</llppconfig>\n";
1435 let save leavebirdseye
=
1436 let relx = float !S.x /. float !S.winw in
1438 let cx w = truncate
(relx *. float w) in
1440 (fun (w, h, x) ws
->
1442 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
1443 | Wsi.MaxVert
-> (w, conf.cwinh
, x)
1444 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
1446 (!S.winw, !S.winh, !S.x) !S.winstate
1450 let bb = Buffer.create
32768 in
1451 let save2 (h, dc) = save1 bb leavebirdseye
x h dc in
1452 if load1 save2 && Buffer.length
bb > 0
1455 let tmp = !S.confpath ^
".tmp" in
1456 let oc = open_out_bin
tmp in
1457 Buffer.output_buffer
oc bb;
1459 Unix.rename
tmp !S.confpath;
1460 with exn
-> dolog
"error saving configuration: %s" @@ exntos exn
1463 let href = ref @@ Hashtbl.create
0 in
1464 let cref = ref defconf
in
1467 if Sys.file_exists
path
1469 else (dolog1
"removing entry for %S" path; None
) in
1470 Hashtbl.filter_map_inplace
f h;
1475 ignore
(load1 push);
1476 let bb = Buffer.create
32768 in
1477 let save2 (_h
, dc) = save1 bb (fun _ _ -> ()) 0 !href dc in
1478 if load1 save2 && Buffer.length
bb > 0
1481 let tmp = !S.confpath ^
".tmp" in
1482 let oc = open_out_bin
tmp in
1483 Buffer.output_buffer
oc bb;
1485 Unix.rename
tmp !S.confpath;
1486 with exn
-> dolog
"error saving configuration: %s" @@ exntos exn
1489 let logcurrently = function
1490 | Idle
-> dolog
"Idle"
1491 | Loading
(l, gen) -> dolog
"Loading %d gen=%d curgen=%d" l.pageno gen !S.gen
1492 | Tiling
(l, pageopaque
, colorspace
, angle
, gen, col
, row
, tilew
, tileh
) ->
1493 dolog
"Tiling %d[%d,%d] page=%s cs=%s angle=%d"
1494 l.pageno col row
(Opaque.to_string pageopaque
)
1495 (CSTE.to_string colorspace
) angle
;
1496 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1497 angle
gen conf.angle
!S.gen
1499 conf.tilew
conf.tileh
1500 | Outlining
_ -> dolog
"outlining"