4 { mutable fontsize
: int
5 ; mutable wwidth
: float
6 ; mutable maxrows
: int
11 { fontsize
= 20 * Wsi.fontsizefactor
()
17 let irect_of_string s
=
18 Scanf.sscanf s
"%d/%d/%d/%d" (fun x0 y0 x1 y1
-> (x0
,y0
,x1
,y1
))
21 let irect_to_string (x0
,y0
,x1
,y1
) =
22 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
25 let multicolumns_to_string (n
, a
, b
) =
27 then Printf.sprintf
"%d" n
28 else Printf.sprintf
"%d,%d,%d" n a b
;
31 let multicolumns_of_string s
=
33 (int_of_string s
, 0, 0)
35 Scanf.sscanf s
"%u,%u,%u" (fun n a b
->
37 then error
"subtly broken";
45 (angle
* fitmodel
* trimparams
* texcount
* sliceheight
* memsize
46 * colorspace
* fontpath
* trimcachepath
* haspbo
)
55 and trimcachepath
= string
57 and trimmargins
= bool
58 and trimparams
= (trimmargins
* irect
)
60 and usefontconfig
= bool
66 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
71 | Uannotation
of (opaque
* slinkindex
)
74 and launchcommand
= string
84 | LDfirstvisible
of (int * int * int)
93 and anchor
= pageno
* top
* dtop
94 and rect
= float * float * float * float * float * float * float * float
95 and infochange
= | Memused
| Docinfo
| Pdim
100 method display
: unit
101 method key
: int -> int -> uioh
102 method button
: int -> bool -> int -> int -> int -> uioh
103 method multiclick
: int -> int -> int -> int -> uioh
104 method motion
: int -> int -> uioh
105 method pmotion
: int -> int -> uioh
106 method infochanged
: infochange
-> unit
107 method scrollpw
: (int * float * float)
108 method scrollph
: (int * float * float)
109 method modehash
: keyhash
110 method eformsgs
: bool
111 method alwaysscrolly
: bool
112 method scroll
: int -> int -> uioh
113 method zoom
: float -> int -> int -> unit
116 module type TextEnumType
= sig
119 val names
: string array
122 module TextEnumMake
(Ten
: TextEnumType
) = struct
123 let names = Ten.names;;
124 let to_int (t
: Ten.t
) = Obj.magic t
;;
125 let to_string t
= names.(to_int t
);;
126 let of_int n
: Ten.t
= Obj.magic n
;;
129 if i
= Array.length
names
130 then error
"invalid %s: %s" Ten.name s
139 module CSTE
= TextEnumMake
(struct
140 type t
= colorspace
;;
141 let name = "colorspace";;
142 let names = [|"rgb"; "bgr"; "gray"|];;
145 module MTE
= TextEnumMake
(struct
148 let names = [|"page"; "block"; "line"; "word"|];;
151 module FMTE
= TextEnumMake
(struct
153 let name = "fitmodel";;
154 let names = [|"width"; "proportional"; "page"|];;
161 | Olaunch
of launchcommand
162 | Oremote
of (filename
* pageno
)
163 | Oremotedest
of (filename
* destname
)
164 | Ohistory
of (filename
* conf
* outline list
* x
* anchor
* filename
)
165 and outline
= (caption
* outlinelevel
* outlinekind
)
166 and outlinelevel
= int
184 type tile
= opaque
* pixmapsize
* elapsed
185 and elapsed
= float;;
186 type pagemapkey
= pageno
* gen
;;
187 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
192 | Loading
of (page
* gen
)
194 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
196 | Outlining
of outline list
199 type mpos
= int * int
201 | Msel
of (mpos
* mpos
)
203 | Mscrolly
| Mscrollx
204 | Mzoom
of (buttonno
* step
* mpos
)
205 | Mzoomrect
of (mpos
* mpos
)
212 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
213 | Textentry
of (textentry
* onleave
)
215 | LinkNav
of linktarget
216 and onleave
= leavetextentrystatus
-> unit
217 and leavetextentrystatus
= | Cancel
| Confirm
218 and helpitem
= string * int * action
221 | Action
of (uioh
-> uioh
)
223 | Ltexact
of (pageno
* direction
)
224 | Ltgendir
of direction
225 | Ltnotready
of (pageno
* direction
)
226 and direction
= int (* -1, 0, 1 *)
227 and textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
228 and onkey
= string -> Keys.t
-> te
229 and ondone
= string -> unit
230 and histcancel
= unit -> unit
231 and onhist
= ((histcmd
-> string) * histcancel
)
232 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
233 and cancelonempty
= bool
238 | TEswitch
of textentry
250 { mutable ss
: Unix.file_descr
251 ; mutable wsfd
: Unix.file_descr
252 ; mutable stderr
: Unix.file_descr
253 ; mutable errmsgs
: Buffer.t
254 ; mutable newerrmsgs
: bool
258 ; mutable anchor
: anchor
259 ; mutable ranchors
: (string * string * anchor
* string) list
261 ; mutable layout
: page list
262 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
263 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
264 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
265 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
266 ; mutable pagecount
: int
267 ; mutable currently
: currently
268 ; mutable mstate
: mstate
269 ; mutable searchpattern
: string
270 ; mutable rects
: (pageno
* rectcolor
* rect
) list
271 ; mutable rects1
: (pageno
* rectcolor
* rect
) list
272 ; prects
: (pageno
, float array
) Hashtbl.t
273 ; mutable text
: string
274 ; mutable winstate
: Wsi.winstate list
275 ; mutable mode
: mode
276 ; mutable uioh
: uioh
277 ; mutable outlines
: outline array
278 ; mutable bookmarks
: outline list
279 ; mutable path
: string
280 ; mutable password
: string
281 ; mutable nameddest
: string
282 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
283 ; mutable memused
: memsize
285 ; mutable autoscroll
: int option
286 ; mutable help
: helpitem array
287 ; mutable docinfo
: (int * string) list
289 ; mutable prevzoom
: (float * int)
290 ; mutable progress
: float
291 ; mutable mpos
: mpos
292 ; mutable keystate
: keystate
293 ; mutable glinks
: bool
294 ; mutable prevcolumns
: (columns
* float) option
297 ; mutable reprf
: (unit -> unit)
298 ; mutable origin
: string
299 ; mutable roam
: (unit -> unit)
300 ; mutable bzoom
: bool
301 ; mutable lnava
: (pageno
* linkno
) option
302 ; mutable slideshow
: int
305 { pat
: string circbuf
306 ; pag
: string circbuf
307 ; nav
: anchor circbuf
308 ; sel
: string circbuf
312 let emptyanchor = (0, 0.0, 0.0);;
313 let emptykeyhash = Hashtbl.create
0;;
314 let noreprf () = ();;
320 method key _ _
= self
321 method multiclick _ _ _ _
= self
322 method button _ _ _ _ _
= self
323 method motion _ _
= self
324 method pmotion _ _
= self
325 method infochanged _
= ()
326 method scrollpw
= (0, nan
, nan
)
327 method scrollph
= (0, nan
, nan
)
328 method modehash
= emptykeyhash
329 method eformsgs
= false
330 method alwaysscrolly
= false
331 method scroll _ _
= self
332 method zoom _ _ _
= ()
335 let platform_to_string = function
336 | Punknown
-> "unknown"
342 let conf = { defconf
with keyhashes
= copykeyhashes defconf
};;
345 { store
= Array.make n v
352 let cbcap b
= Array.length b
.store
;;
354 let cbput ?
(update_rc
=true) b v
=
357 b
.wc
<- (b
.wc
+ 1) mod cap;
360 b
.len
<- min
(b
.len
+ 1) cap;
363 let cbput_dont_update_rc b v
= cbput ~update_rc
:false b v
;;
365 let cbempty b
= b
.len
= 0;;
367 let cbgetg b circular dir
=
371 let rc = b
.rc + dir
in
383 else bound
rc 0 (b
.len
-1)
389 let cbget b
= cbgetg b
false;;
390 let cbgetc b
= cbgetg b
true;;
395 ; stderr
= Unix.stderr
396 ; errmsgs
= Buffer.create
0
401 ; anchor
= emptyanchor
405 ; tilelru
= Queue.create
()
406 ; pagemap
= Hashtbl.create
10
407 ; tilemap
= Hashtbl.create
10
414 ; prects
= Hashtbl.create
1
418 ; searchpattern
= E.s
426 { nav
= cbnew 10 emptyanchor
436 ; prevzoom
= (1.0, 0)
455 let d = state.winh
- h
in
456 max
conf.interpagespace
((d + 1) / 2)
459 let rowyh (c
, coverA
, coverB
) b n
=
460 if c
= 1 || (n
< coverA
|| n
>= state.pagecount
- coverB
)
462 let _, _, vy
, (_, _, h
, _) = b
.(n
) in
465 let n'
= n - coverA
in
468 let e = min
state.pagecount
(s + c
) in
469 let rec find m miny maxh
= if m
= e then miny
, maxh
else
470 let _, _, y
, (_, _, h
, _) = b
.(m
) in
471 let miny = min
miny y
in
472 let maxh = max
maxh h
in
478 let ((c
, coverA
, coverB
) as cl
), b
=
479 match conf.columns
with
480 | Csplit
(_, b
) | Csingle b
-> (1, 0, 0), b
481 | Cmulti
(c
, b
) -> c
, b
483 if Array.length b
= 0
486 let rec bsearch nmin nmax
=
488 then bound nmin
0 (state.pagecount
-1)
490 let n = (nmax
+ nmin
) / 2 in
491 let vy, h
= rowyh cl b
n in
495 let ips = calcips h
in
497 let y1 = vy + h
+ ips in
501 then 0, vy + h
+ conf.interpagespace
503 let y0 = vy - conf.interpagespace
in
504 y0, y0 + h
+ conf.interpagespace
514 if n < state.pagecount
- coverB
515 then ((n-coverA
)/c
)*c
+ coverA
522 then bsearch (n+1) nmax
523 else bsearch nmin
(n-1)
526 bsearch 0 (state.pagecount
-1);
530 match conf.columns
with
531 | Cmulti
((_, _, _) as cl
, b
) ->
532 if Array.length b
> 0
534 let y, h
= rowyh cl b
(Array.length b
- 1) in
535 y + h
+ (if conf.presentation
then calcips h
else 0)
538 if Array.length b
> 0
540 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
541 y + h
+ (if conf.presentation
then calcips h
else 0)
544 if Array.length b
> 0
546 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
551 let getpageywh pageno
=
552 let pageno = bound
pageno 0 (state.pagecount
-1) in
553 match conf.columns
with
555 if Array.length b
= 0
558 let (_, _, y, (_, w
, h
, _)) = b
.(pageno) in
566 if Array.length b
= 0
569 let y, h
= rowyh cl b
pageno in
570 let (_, _, _, (_, w
, _, _)) = b
.(pageno) in
578 if Array.length b
= 0
582 let (_, _, y, (_, w
, h
, _)) = b
.(n) in
586 let getpageyh pageno =
587 let y,_,h
= getpageywh pageno in
591 let getpagedim pageno =
594 | (n, _, _, _) as pdim
:: rest
->
596 then (if n = pageno then pdim
else ppdim
)
601 f (-1, -1, -1, -1) state.pdims
604 let getpdimno pageno =
608 | (n, _, _, _) :: rest
->
610 then (if n = pageno then np else p
)
618 let getpagey pageno = fst
(getpageyh pageno);;
622 let coloff = l
.pagecol
* l
.pageh
in
623 float (l
.pagey
+ coloff) /. float l
.pageh
630 then float l
.pagedispy
/. float (calcips l
.pageh
)
631 else float l
.pagedispy
/. float conf.interpagespace
634 (l
.pageno, top, dtop)
638 match state.layout
with
639 | l
:: _ -> getanchor1 l
641 let n = page_of_y state.y in
645 let y, h
= getpageyh n in
646 let dy = y - state.y in
650 let ips = calcips h
in
651 float (dy + ips) /. float ips
653 float dy /. float conf.interpagespace
658 let fontpath = ref E.s;;
660 type historder
= [ `lastvisit
| `title
| `path
| `file
];;
663 Map.Make
(struct type t
= (int * int) let compare = compare end);;
666 let l = String.length
s in
667 let b = Buffer.create
l in
668 Parser.unent
b s 0 l;
673 try Sys.getenv
"HOME"
675 dolog
"cannot determine home directory location: %s" @@ exntos exn
;
679 let modifier_of_string = function
680 | "alt" -> Wsi.altmask
681 | "shift" -> Wsi.shiftmask
682 | "ctrl" | "control" -> Wsi.ctrlmask
683 | "meta" -> Wsi.metamask
687 let keys_of_string s =
688 let key_of_string r
s =
689 let elems = Str.full_split r
s in
692 let m1 = modifier_of_string s in
694 then (Wsi.namekey
s, m
)
697 | Str.Delim
s when n land 1 = 0 -> g s
699 | Str.Delim
_ -> (k
, m
)
701 let rec loop n k m
= function
704 let k, m
= f n k m x
in
709 let elems = Str.split
Utils.Re.whitespace
s in
710 List.map
(key_of_string (Str.regexp
"-")) elems
713 let config_of c attrs
=
717 | "scroll-bar-width" -> { c
with scrollbw
= max
0 (int_of_string v
) }
718 | "scroll-handle-height" -> { c
with scrollh
= max
0 (int_of_string v
) }
719 | "case-insensitive-search" -> { c
with icase
= bool_of_string v
}
720 | "preload" -> { c
with preload
= bool_of_string v
}
721 | "page-bias" -> { c
with pagebias
= int_of_string v
}
722 | "scroll-step" -> { c
with scrollstep
= max
1 (int_of_string v
) }
723 | "horizontal-scroll-step" ->
724 { c
with hscrollstep
= max
(int_of_string v
) 1 }
725 | "auto-scroll-step" ->
726 { c
with autoscrollstep
= max
0 (int_of_string v
) }
727 | "max-height-fit" -> { c
with maxhfit
= bool_of_string v
}
728 | "highlight-links" -> { c
with hlinks
= bool_of_string v
}
729 | "under-cursor-info" -> { c
with underinfo
= bool_of_string v
}
730 | "vertical-margin" ->
731 { c
with interpagespace
= max
0 (int_of_string v
) }
733 let zoom = float_of_string v
/. 100. in
734 let zoom = max
zoom 0.0 in
735 { c
with zoom = zoom }
736 | "presentation" -> { c
with presentation
= bool_of_string v
}
737 | "rotation-angle" -> { c
with angle
= int_of_string v
}
738 | "width" -> { c
with cwinw
= max
20 (int_of_string v
) }
739 | "height" -> { c
with cwinh
= max
20 (int_of_string v
) }
740 | "proportional-display" ->
746 { c
with fitmodel
= fm }
747 | "fit-model" -> { c
with fitmodel
= FMTE.of_string v
}
748 | "pixmap-cache-size" ->
749 { c
with memlimit
= max
2 (int_of_string_with_suffix v
) }
750 | "tex-count" -> { c
with texcount
= max
1 (int_of_string v
) }
751 | "slice-height" -> { c
with sliceheight
= max
2 (int_of_string v
) }
752 | "thumbnail-width" -> { c
with thumbw
= max
2 (int_of_string v
) }
753 | "background-color" -> { c
with bgcolor
= color_of_string v
}
754 | "scrollbar-color" -> { c
with sbarcolor
= rgba_of_string v
}
755 | "scrollbar-handle-color" -> { c
with sbarhndlcolor
= rgba_of_string v
}
756 | "tile-width" -> { c
with tilew
= max
2 (int_of_string v
) }
757 | "tile-height" -> { c
with tileh
= max
2 (int_of_string v
) }
758 | "mupdf-store-size" ->
759 { c
with mustoresize
= max
1024 (int_of_string_with_suffix v
) }
760 | "checkers" -> { c
with checkers
= bool_of_string v
}
761 | "aalevel" -> { c
with aalevel
= max
0 (int_of_string v
) }
762 | "trim-margins" -> { c
with trimmargins
= bool_of_string v
}
763 | "trim-fuzz" -> { c
with trimfuzz
= irect_of_string v
}
764 | "uri-launcher" -> { c
with urilauncher
= unentS v
}
765 | "path-launcher" -> { c
with pathlauncher
= unentS v
}
766 | "color-space" -> { c
with colorspace
= CSTE.of_string v
}
767 | "invert-colors" -> { c
with invert
= bool_of_string v
}
768 | "brightness" -> { c
with colorscale
= float_of_string v
}
770 let (n, _, _) as nab
= multicolumns_of_string v
in
772 then { c
with columns
= Csplit
(-n, E.a
) }
773 else { c
with columns
= Cmulti
(nab
, E.a
) }
774 | "birds-eye-columns" ->
775 { c
with beyecolumns
= Some
(max
(int_of_string v
) 2) }
776 | "selection-command" -> { c
with selcmd
= unentS v
}
777 | "synctex-command" -> { c
with stcmd
= unentS v
}
778 | "pax-command" -> { c
with paxcmd
= unentS v
}
779 | "askpass-command" -> { c
with passcmd
= unentS v
}
780 | "savepath-command" -> { c
with savecmd
= unentS v
}
781 | "update-cursor" -> { c
with updatecurs
= bool_of_string v
}
782 | "hint-font-size" -> { c
with hfsize
= bound
(int_of_string v
) 5 100 }
783 | "page-scroll-scale" -> { c
with pgscale
= float_of_string v
}
784 | "use-pbo" -> { c
with usepbo
= bool_of_string v
}
785 | "wheel-scrolls-pages" -> { c
with wheelbypage
= bool_of_string v
}
786 | "horizontal-scrollbar-visible" ->
789 then c
.scrollb
lor scrollbhv
790 else c
.scrollb
land (lnot scrollbhv
)
792 { c
with scrollb
= b }
793 | "vertical-scrollbar-visible" ->
796 then c
.scrollb
lor scrollbvv
797 else c
.scrollb
land (lnot scrollbvv
)
799 { c
with scrollb
= b }
800 | "remote-in-a-new-instance" -> { c
with riani
= bool_of_string v
}
806 | "point-and-x-mark" -> { c
with paxmark
= MTE.of_string v
}
807 | "scroll-bar-on-the-left" -> { c
with leftscroll
= bool_of_string v
}
808 | "title" -> { c
with title
= unentS v
}
809 | "last-visit" -> { c
with lastvisit
= float_of_string v
}
810 | "edit-annotations-inline" -> { c
with annotinline
= bool_of_string v
}
811 | "coarse-presentation-positioning" ->
812 { c
with coarseprespos
= bool_of_string v
}
813 | "use-document-css" -> { c
with usedoccss
= bool_of_string v
}
816 dolog
"error processing attribute (`%S' = `%S'): %s" k v
@@ exntos exn
;
819 let rec fold c
= function
822 let c = apply c k v
in
825 fold { c with keyhashes
= copykeyhashes
c } attrs
;
828 let fromstring f pos
n v
d =
831 dolog
"error processing attribute (%S=%S) at %d\n%s" n v pos
@@ exntos exn
;
835 let bookmark_of attrs
=
836 let rec fold title page rely visy
= function
837 | ("title", v
) :: rest
-> fold v page rely visy rest
838 | ("page", v
) :: rest
-> fold title v rely visy rest
839 | ("rely", v
) :: rest
-> fold title page v visy rest
840 | ("visy", v
) :: rest
-> fold title page rely v rest
841 | _ :: rest
-> fold title page rely visy rest
842 | [] -> title
, page
, rely
, visy
844 fold "invalid" "0" "0" "0" attrs
848 let rec fold path key page rely pan visy origin
= function
849 | ("path", v
) :: rest
-> fold v key page rely pan visy origin rest
850 | ("key", v
) :: rest
-> fold path v page rely pan visy origin rest
851 | ("page", v
) :: rest
-> fold path key v rely pan visy origin rest
852 | ("rely", v
) :: rest
-> fold path key page v pan visy origin rest
853 | ("pan", v
) :: rest
-> fold path key page rely v visy origin rest
854 | ("visy", v
) :: rest
-> fold path key page rely pan v origin rest
855 | ("origin", v
) :: rest
-> fold path key page rely pan visy v rest
856 | _ :: rest
-> fold path key page rely pan visy origin rest
857 | [] -> path
, key
, page
, rely
, pan
, visy
, origin
859 fold E.s E.s "0" "0" "0" "0" E.s attrs
863 let rec fold rs ls
= function
864 | ("out", v
) :: rest
-> fold v ls rest
865 | ("in", v
) :: rest
-> fold rs v rest
866 | _ :: rest
-> fold ls rs rest
872 let findkeyhash c name =
873 try List.assoc
name c.keyhashes
874 with Not_found
-> error
"invalid mode name `%s'" name
879 let h = Hashtbl.create
10 in
880 let dc = { defconf
with angle
= defconf
.angle
} in
881 let rec toplevel v t spos
_ =
883 | Vdata
| Vcdata
| Vend
-> v
884 | Vopen
("llppconfig", _, closed
) ->
887 else { v
with f = llppconfig
}
888 | Vopen
_ -> parse_error
"unexpected subelement at top level" s spos
889 | Vclose
_ -> parse_error
"unexpected close at top level" s spos
891 and llppconfig v t spos
_ =
893 | Vdata
| Vcdata
-> v
894 | Vend
-> parse_error
"unexpected end of input in llppconfig" s spos
895 | Vopen
("defaults", attrs
, closed
) ->
896 let c = config_of dc attrs
in
900 else { v
with f = defaults
}
902 | Vopen
("ui-font", attrs
, closed
) ->
903 let rec getsize size
= function
905 | ("size", v
) :: rest
->
907 fromstring int_of_string spos
"size" v
fstate.fontsize
in
909 | l -> getsize size l
911 fstate.fontsize
<- getsize fstate.fontsize attrs
;
914 else { v
with f = uifont
(Buffer.create
10) }
916 | Vopen
("doc", attrs
, closed
) ->
917 let pathent, key
, spage
, srely
, span
, svisy
, origin
= doc_of attrs
in
918 let path = unentS pathent
919 and origin
= unentS origin
920 and pageno = fromstring int_of_string spos
"page" spage
0
921 and rely
= fromstring float_of_string spos
"rely" srely
0.0
922 and pan
= fromstring int_of_string spos
"pan" span
0
923 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
924 let c = config_of dc attrs
in
926 let anchor = (pageno, rely
, visy
) in
928 then (Hashtbl.add
h path (c, [], pan
, anchor, origin
); v
)
929 else { v
with f = doc
path origin pan
anchor c [] }
932 parse_error
"unexpected subelement in llppconfig" s spos
934 | Vclose
"llppconfig" -> { v
with f = toplevel }
935 | Vclose
_ -> parse_error
"unexpected close in llppconfig" s spos
937 and defaults v t spos
_ =
939 | Vdata
| Vcdata
-> v
940 | Vend
-> parse_error
"unexpected end of input in defaults" s spos
941 | Vopen
("keymap", attrs
, closed
) ->
943 try List.assoc
"mode" attrs
944 with Not_found
-> "global" in
949 let h = findkeyhash dc modename in
950 KeyMap.iter
(Hashtbl.replace
h) keymap
;
953 { v
with f = pkeymap
ret KeyMap.empty
}
956 parse_error
"unexpected subelement in defaults" s spos
958 | Vclose
"defaults" ->
959 { v
with f = llppconfig
}
961 | Vclose
_ -> parse_error
"unexpected close in defaults" s spos
963 and uifont
b v t spos epos
=
966 Buffer.add_substring
b s spos
(epos
- spos
);
969 parse_error
"unexpected subelement in ui-font" s spos
970 | Vclose
"ui-font" ->
971 if emptystr
!fontpath
972 then fontpath := Buffer.contents
b;
973 { v
with f = llppconfig
}
974 | Vclose
_ -> parse_error
"unexpected close in ui-font" s spos
975 | Vend
-> parse_error
"unexpected end of input in ui-font" s spos
977 and doc
path origin pan
anchor c bookmarks v t spos
_ =
979 | Vdata
| Vcdata
-> v
980 | Vend
-> parse_error
"unexpected end of input in doc" s spos
981 | Vopen
("bookmarks", _, closed
) ->
984 else { v
with f = pbookmarks
path origin pan
anchor c bookmarks
}
986 | Vopen
("keymap", attrs
, closed
) ->
988 try List.assoc
"mode" attrs
989 with Not_found
-> "global"
995 let h = findkeyhash c modename in
996 KeyMap.iter
(Hashtbl.replace
h) keymap
;
997 doc
path origin pan
anchor c bookmarks
999 { v
with f = pkeymap
ret KeyMap.empty
}
1001 | Vopen
("css", [], false) ->
1002 { v
with f = pcss
path origin pan
anchor c bookmarks
}
1004 | Vopen
(_, _, _) ->
1005 parse_error
"unexpected subelement in doc" s spos
1008 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor, origin
);
1009 { v
with f = llppconfig
}
1011 | Vclose
_ -> parse_error
"unexpected close in doc" s spos
1013 and pcss
path origin pan
anchor c bookmarks v t spos epos
=
1016 let b = Buffer.create
10 in
1017 Buffer.add_substring
b s spos
(epos
- spos
);
1018 { v
with f = pcss
path origin pan
anchor
1019 { c with css
= Buffer.contents
b }
1021 | Vend
-> parse_error
"unexpected end of input in css" s spos
1022 | Vopen
_ -> parse_error
"unexpected subelement in css" s spos
1023 | Vclose
"css" -> { v
with f = doc
path origin pan
anchor c bookmarks
}
1024 | Vclose
_ -> parse_error
"unexpected close in css" s spos
1026 and pkeymap
ret keymap v t spos
_ =
1028 | Vdata
| Vcdata
-> v
1029 | Vend
-> parse_error
"unexpected end of input in keymap" s spos
1030 | Vopen
("map", attrs
, closed
) ->
1031 let r, l = map_of attrs
in
1032 let kss = fromstring keys_of_string spos
"in" r [] in
1033 let lss = fromstring keys_of_string spos
"out" l [] in
1037 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
1038 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
1041 then { v
with f = pkeymap
ret keymap }
1044 { v
with f = skip
"map" f }
1047 parse_error
"unexpected subelement in keymap" s spos
1049 | Vclose
"keymap" ->
1050 { v
with f = ret keymap }
1052 | Vclose
_ -> parse_error
"unexpected close in keymap" s spos
1054 and pbookmarks
path origin pan
anchor c bookmarks v t spos
_ =
1056 | Vdata
| Vcdata
-> v
1057 | Vend
-> parse_error
"unexpected end of input in bookmarks" s spos
1058 | Vopen
("item", attrs
, closed
) ->
1059 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
1060 let page = fromstring int_of_string spos
"page" spage
0
1061 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1062 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1064 (unentS titleent, 0, Oanchor
(page, rely
, visy
)) :: bookmarks
1067 then { v
with f = pbookmarks
path origin pan
anchor c bookmarks }
1070 { v
with f = skip
"item" f }
1073 parse_error
"unexpected subelement in bookmarks" s spos
1075 | Vclose
"bookmarks" ->
1076 { v
with f = doc
path origin pan
anchor c bookmarks }
1078 | Vclose
_ -> parse_error
"unexpected close in bookmarks" s spos
1080 and skip tag
f v t spos
_ =
1082 | Vdata
| Vcdata
-> v
1084 parse_error
("unexpected end of input in skipped " ^ tag
) s spos
1085 | Vopen
(tag'
, _, closed
) ->
1089 let f'
() = { v
with f = skip tag
f } in
1090 { v
with f = skip tag'
f'
}
1094 else parse_error
("unexpected close in skipped " ^ tag
) s spos
1097 parse
{ f = toplevel; accu
= () } s;
1101 let do_load f contents
=
1104 | Parser.Parse_error
(msg
, s, pos
) ->
1105 let subs = Parser.subs s pos
in
1106 Utils.error
"parse error: %s: at %d [..%S..]" msg pos
subs
1108 | exn
-> Utils.error
"parse error: %s" @@ exntos exn
1113 let xdgconfdir = Utils.getenvwithdef
"XDG_CONFIG_HOME" E.s in
1114 if emptystr
xdgconfdir
1117 let dir = Filename.concat
home ".config" in
1118 if Sys.is_directory
dir then dir else home
1122 Filename.concat
dir "llpp.conf"
1125 let confpath = ref defconfpath;;
1127 let load2 f default
=
1128 match filecontents
!confpath with
1129 | contents
-> f @@ do_load get contents
1130 | exception Unix.Unix_error
(Unix.ENOENT
, "open", _) ->
1131 f (Hashtbl.create
0, defconf
)
1133 dolog
"error loading configuration from `%S': %s" !confpath @@ exntos exn
;
1137 let load1 f = load2 f false;;
1145 (fun path (conf, _, _, _, _) ((_, besttime
) as best
) ->
1146 if conf.lastvisit
> besttime
1147 then (path, conf.lastvisit
)
1150 (state.path, -.infinity
)
1154 let pc, pb
, px
, pa
, po
=
1155 let def = dc, [], 0, emptyanchor, state.origin
in
1156 if emptystr
state.path
1159 let absname = abspath
state.path in
1160 match Hashtbl.find h absname with
1161 | (c,b,x
,a
,_) -> (c,b,x
,a
,state.origin
)
1162 | exception Not_found
->
1163 let exception E
of (conf * outline list
* int * anchor * string) in
1164 let key = try Digest.file
absname |> Digest.to_hex
with _ -> E.s in
1168 Hashtbl.iter
(fun p
((c, _, _, _, _) as v
) ->
1171 dolog
"will use %s's settings due to matching keys" p
;
1178 | exception E v
-> v
1182 state.bookmarks <- pb
;
1186 cbput state.hists
.nav pa
;
1194 Hashtbl.fold (fun path (pc, pb
, px
, pa
, po
) accu
->
1195 (path, pc, pb
, px
, pa
, po
) :: accu
)
1201 let add_attrs bb always
dc c time
=
1203 Buffer.add_string bb
"\n ";
1204 Printf.bprintf bb fmt
s
1206 let o c fmt
s = if c then o' fmt
s else ignore
in
1207 let ob s a
b = o (always
|| a
!= b) "%s='%b'" s a
1208 and op
s a
b = o (always
|| a
<> b) "%s='%b'" s (a
!= None
)
1209 and oi
s a
b = o (always
|| a
!= b) "%s='%d'" s a
1210 and oI
s a
b = o (always
|| a
!= b) "%s='%s'" s (string_with_suffix_of_int a
)
1211 and oz
s a
b = o (always
|| a
<> b) "%s='%g'" s (a
*.100.)
1212 and oF
s a
b = o (always
|| a
<> b) "%s='%f'" s a
1213 and oL
s a
b = o (always
|| a
<> b) "%s='%Ld'" s a
1214 and oc
s a
b = o (always
|| a
<> b) "%s='%s'" s (color_to_string a
)
1215 and oA
s a
b = o (always
|| a
<> b) "%s='%s'" s (rgba_to_string a
)
1216 and oC
s a
b = o (always
|| a
<> b) "%s='%s'" s (CSTE.to_string a
)
1217 and oR
s a
b = o (always
|| a
<> b) "%s='%s'" s (irect_to_string a
)
1218 and oFm
s a
b = o (always
|| a
<> b) "%s='%s'" s (FMTE.to_string a
)
1220 o (always
|| a
land m
<> b land m
) "%s='%b'" s (a
land m
!= 0)
1221 and oPm
s a
b = o (always
|| a
<> b) "%s='%s'" s (MTE.to_string a
)
1223 o (always
|| a
<> b) "%s='%s'" s @@ Parser.enent a
0 (String.length a
)
1228 | Cmulti
((n, a
, b), _) when n > 1 -> o'
"%s='%d,%d,%d'" s n a
b
1229 | Csplit
(n, _) when n > 1 -> o'
"%s='%d'" s ~
-n
1230 | Cmulti
_ | Csplit
_ | Csingle
_ -> ()
1235 | Some
c when c > 1 -> o'
"%s='%d'" s c
1238 oi
"width" c.cwinw
dc.cwinw
;
1239 oi
"height" c.cwinh
dc.cwinh
;
1240 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
1241 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
1242 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb scrollbhv
;
1243 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb scrollbvv
;
1244 ob "case-insensitive-search" c.icase
dc.icase
;
1245 ob "preload" c.preload
dc.preload
;
1246 oi
"page-bias" c.pagebias
dc.pagebias
;
1247 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
1248 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
1249 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
1250 ob "highlight-links" c.hlinks
dc.hlinks
;
1251 ob "under-cursor-info" c.underinfo
dc.underinfo
;
1252 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
1253 oz
"zoom" c.zoom dc.zoom;
1254 ob "presentation" c.presentation
dc.presentation
;
1255 oi
"rotation-angle" c.angle
dc.angle
;
1256 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
1257 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
1258 oi
"tex-count" c.texcount
dc.texcount
;
1259 oi
"slice-height" c.sliceheight
dc.sliceheight
;
1260 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
1261 oc
"background-color" c.bgcolor
dc.bgcolor
;
1262 oA
"scrollbar-color" c.sbarcolor
dc.sbarcolor
;
1263 oA
"scrollbar-handle-color" c.sbarhndlcolor
dc.sbarhndlcolor
;
1264 oi
"tile-width" c.tilew
dc.tilew
;
1265 oi
"tile-height" c.tileh
dc.tileh
;
1266 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
1267 ob "checkers" c.checkers
dc.checkers
;
1268 oi
"aalevel" c.aalevel
dc.aalevel
;
1269 ob "trim-margins" c.trimmargins
dc.trimmargins
;
1270 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
1271 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
1272 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
1273 oC
"color-space" c.colorspace
dc.colorspace
;
1274 ob "invert-colors" c.invert
dc.invert
;
1275 oF
"brightness" c.colorscale
dc.colorscale
;
1276 oco
"columns" c.columns
dc.columns
;
1277 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
1278 os
"selection-command" c.selcmd
dc.selcmd
;
1279 os
"synctex-command" c.stcmd
dc.stcmd
;
1280 os
"pax-command" c.paxcmd
dc.paxcmd
;
1281 os
"askpass-command" c.passcmd
dc.passcmd
;
1282 os
"savepath-command" c.savecmd
dc.savecmd
;
1283 ob "update-cursor" c.updatecurs
dc.updatecurs
;
1284 oi
"hint-font-size" c.hfsize
dc.hfsize
;
1285 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
1286 oF
"page-scroll-scale" c.pgscale
dc.pgscale
;
1287 ob "use-pbo" c.usepbo
dc.usepbo
;
1288 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
1289 ob "remote-in-a-new-instance" c.riani
dc.riani
;
1290 op
"point-and-x" c.pax
dc.pax
;
1291 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
1292 ob "scroll-bar-on-the-left" c.leftscroll
dc.leftscroll
;
1294 then os
"title" c.title
dc.title
;
1295 oL
"last-visit" (Int64.of_float time
) 0L;
1296 ob "edit-annotations-inline" c.annotinline
dc.annotinline
;
1297 ob "coarse-presentation-positioning" c.coarseprespos
dc.coarseprespos
;
1298 ob "use-document-css" c.usedoccss
dc.usedoccss
;
1301 let keymapsbuf always
dc c =
1303 let bb = create
16 in
1304 let rec loop = function
1306 | (modename, h) :: rest
->
1307 let dh = findkeyhash dc modename in
1308 if always
|| h <> dh
1310 if Hashtbl.length
h > 0
1312 if length
bb > 0 then add_char
bb '
\n'
;
1313 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
1314 Hashtbl.iter
(fun i
o ->
1315 if always
|| match Hashtbl.find dh i
1316 with | dO
-> dO
<> o | exception Not_found
-> false
1319 if Wsi.withctrl m
then add_string
bb "ctrl-";
1320 if Wsi.withalt m
then add_string
bb "alt-";
1321 if Wsi.withshift m
then add_string
bb "shift-";
1322 if Wsi.withmeta m
then add_string
bb "meta-";
1323 add_string
bb (Wsi.keyname
k);
1326 let rec loop = function
1328 | km
:: [] -> addkm km
1329 | km
:: rest
-> addkm km
; add_char
bb ' '
; loop rest
1333 add_string
bb "<map in='";
1337 add_string
bb "' out='"; addkm km
; add_string
bb "'/>\n"
1340 add_string
bb "' out='"; addkms kms
; add_string
bb "'/>\n"
1342 | KMmulti
(ins
, kms
) ->
1343 add_char
bb ' '
; addkms ins
; add_string
bb "' out='";
1344 addkms kms
; add_string
bb "'/>\n"
1346 add_string
bb "</keymap>";
1355 let keystostrlist c =
1356 let rec loop accu
= function
1358 | (modename, h) :: rest
->
1360 if Hashtbl.length
h > 0
1362 let accu = Printf.sprintf
"\xc2\xb7Keys for %s" modename :: accu in
1363 Hashtbl.fold (fun i
o a
->
1364 let bb = Buffer.create
10 in
1366 if Wsi.withctrl m
then Buffer.add_string
bb "ctrl-";
1367 if Wsi.withalt m
then Buffer.add_string
bb "alt-";
1368 if Wsi.withshift m
then Buffer.add_string
bb "shift-";
1369 if Wsi.withmeta m
then Buffer.add_string
bb "meta-";
1370 Buffer.add_string
bb (Wsi.keyname
k);
1373 let rec loop = function
1375 | km
:: [] -> addkm km
1377 addkm km
; Buffer.add_char
bb ' '
;
1383 Buffer.add_char
bb '
\t'
;
1391 | KMmulti
(ins
, kms
) ->
1392 Buffer.add_char
bb ' '
;
1394 Buffer.add_string
bb "\t";
1397 Buffer.contents
bb :: a
1407 let save1 bb leavebirdseye x
h dc =
1408 let uifontsize = fstate.fontsize
in
1409 let dc = if conf.bedefault
then conf else dc in
1410 Buffer.add_string
bb "<llppconfig>\n";
1412 if nonemptystr
!fontpath
1413 then Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
1418 then Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
1421 Buffer.add_string
bb "<defaults";
1422 add_attrs bb true dc dc nan
;
1423 let kb = keymapsbuf true dc dc in
1424 if Buffer.length
kb > 0
1426 Buffer.add_string
bb ">\n";
1427 Buffer.add_buffer
bb kb;
1428 Buffer.add_string
bb "\n</defaults>\n";
1430 else Buffer.add_string
bb "/>\n";
1432 let adddoc path pan
anchor c bookmarks time origin
=
1433 if not
(bookmarks == [] && c = dc && anchor = emptyanchor)
1435 Printf.bprintf
bb "<doc path='%s'"
1436 (Parser.enent
path 0 (String.length
path));
1438 if nonemptystr
c.key
1439 then Printf.bprintf
bb "\n key='%s'" c.key;
1441 if nonemptystr origin
1442 then Printf.bprintf
bb "\n origin='%s'"
1443 (Parser.enent origin
0 (String.length origin
));
1445 if anchor <> emptyanchor
1447 let n, rely
, visy
= anchor in
1448 Printf.bprintf
bb "\n page='%d'" n;
1451 then Printf.bprintf
bb " rely='%f'" rely
;
1453 if abs_float visy
> 1e-6
1454 then Printf.bprintf
bb " visy='%f'" visy
;
1458 then Printf.bprintf
bb " pan='%d'" pan
;
1460 add_attrs bb false dc c time
;
1461 if nonemptystr
c.css
1462 then Printf.bprintf
bb ">\n <css><![CDATA[%s]]></css>" c.css
;
1463 let kb = keymapsbuf false dc c in
1465 begin match bookmarks with
1467 if Buffer.length
kb > 0
1469 Buffer.add_string
bb ">\n";
1470 Buffer.add_buffer
bb kb;
1471 Buffer.add_string
bb "\n</doc>\n";
1474 if nonemptystr
c.css
1475 then Buffer.add_string
bb "\n</doc>\n"
1476 else Buffer.add_string
bb "/>\n"
1478 Buffer.add_string
bb ">\n<bookmarks>\n";
1479 List.iter
(fun (title
, _, kind
) ->
1480 begin match kind
with
1481 | Oanchor
(page, rely
, visy
) ->
1483 "<item title='%s' page='%d'"
1484 (Parser.enent title
0 (String.length title
))
1487 then Printf.bprintf
bb " rely='%f'" rely
;
1489 if abs_float visy
> 1e-6
1490 then Printf.bprintf
bb " visy='%f'" visy
;
1491 | Ohistory
_ | Onone
| Ouri
_ | Oremote
_
1492 | Oremotedest
_ | Olaunch
_ -> error
"unexpected link in bookmarks"
1494 Buffer.add_string
bb "/>\n";
1496 Buffer.add_string
bb "</bookmarks>";
1497 if Buffer.length
kb > 0
1499 Buffer.add_string
bb "\n";
1500 Buffer.add_buffer
bb kb;
1502 Buffer.add_string
bb "\n</doc>\n";
1508 match state.mode
with
1509 | Birdseye
(c, pan, _, _, _) ->
1511 match conf.columns
with
1512 | Cmulti
((c, _, _), _) -> Some
c
1516 match c.columns
with
1517 | Cmulti
(c, _) -> Cmulti
(c, E.a
)
1518 | Csingle
_ -> Csingle
E.a
1519 | Csplit
_ -> failwith
"quit from bird's eye while split"
1521 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
1524 | LinkNav
_ -> x
, conf
1526 let docpath = if nonemptystr
state.path then abspath
state.path else E.s in
1527 if nonemptystr
docpath
1529 adddoc docpath pan (getanchor ())
1531 let autoscrollstep =
1532 match state.autoscroll
with
1534 | None
-> conf.autoscrollstep
1536 begin match state.mode
with
1537 | Birdseye beye
-> leavebirdseye beye
true
1542 let key = try Digest.file
docpath |> Digest.to_hex
1544 { conf with autoscrollstep; key }
1550 Hashtbl.iter
(fun path (c, bookmarks, x
, anchor, origin
) ->
1551 if docpath <> abspath
path
1552 then adddoc path x
anchor c bookmarks c.lastvisit origin
1554 Buffer.add_string
bb "</llppconfig>\n";
1558 let save leavebirdseye
=
1559 let relx = float state.x
/. float state.winw
in
1561 let cx w = truncate
(relx *. float w) in
1563 (fun (w, h, x
) ws
->
1565 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
1566 | Wsi.MaxVert
-> (w, conf.cwinh
, x
)
1567 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
1569 (state.winw
, state.winh
, state.x
) state.winstate
1573 let bb = Buffer.create
32768 in
1575 save1 bb leavebirdseye x
h dc
1577 if load1 save2 && Buffer.length
bb > 0
1580 let tmp = !confpath ^
".tmp" in
1581 let oc = open_out_bin
tmp in
1582 Buffer.output_buffer
oc bb;
1584 Unix.rename
tmp !confpath;
1586 dolog
"error saving configuration: %s" @@ exntos exn
1590 let href = ref @@ Hashtbl.create
0 in
1591 let cref = ref defconf
in
1594 if Sys.file_exists
path
1596 else (dolog
"removing entry for '%s'" path; None
) in
1597 Hashtbl.filter_map_inplace
f h;
1602 ignore
(load1 push);
1603 let bb = Buffer.create
32768 in
1604 let save2 (_h
, dc) = save1 bb (fun _ _ -> ()) 0 !href dc in
1605 if load1 save2 && Buffer.length
bb > 0
1608 let tmp = !confpath ^
".tmp" in
1609 let oc = open_out_bin
tmp in
1610 Buffer.output_buffer
oc bb;
1612 Unix.rename
tmp !confpath;
1614 dolog
"error saving configuration: %s" @@ exntos exn
1618 let logcurrently = function
1619 | Idle
-> dolog
"Idle"
1620 | Loading
(l, gen
) ->
1621 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
1622 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col
, row
, tilew
, tileh
) ->
1623 dolog
"Tiling %d[%d,%d] page=%s cs=%s angle=%d"
1624 l.pageno col row
(~
> pageopaque
)
1625 (CSTE.to_string colorspace
) angle
;
1626 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1627 angle gen
conf.angle
state.gen
1629 conf.tilew
conf.tileh
1630 | Outlining
_ -> dolog
"outlining"
1634 dolog
{|l %d dim
=%d
{
1641 l.pageno l.pagedimno
1645 l.pagedispx
l.pagedispy