3 external fz_version
: unit -> string = "ml_fz_version";;
6 { mutable fontsize
: int
7 ; mutable wwidth
: float
8 ; mutable maxrows
: int
13 { fontsize
= 20 * Wsi.fontsizefactor
()
21 let fastghyllscroll = (5,1,2);;
22 let neatghyllscroll = (10,1,9);;
24 let irect_of_string s
=
25 Scanf.sscanf s
"%d/%d/%d/%d" (fun x0 y0 x1 y1
-> (x0
,y0
,x1
,y1
))
28 let irect_to_string (x0
,y0
,x1
,y1
) =
29 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
32 let ghyllscroll_of_string s
=
34 | "fast" -> Some
fastghyllscroll
35 | "neat" -> Some
(10,1,9)
39 Scanf.sscanf s
"%u,%u,%u" (fun n a b
-> n
, a
, b
) in
40 if n
<= a
|| n
<= b
|| a
>= b
41 then error
"N(%d),A(%d),B(%d) (N <= A, A < B, N <= B)" n a b
;
45 let ghyllscroll_to_string ((n
, a
, b
) as nab
) =
46 if nab
= fastghyllscroll then "fast"
47 else if nab
= neatghyllscroll then "neat"
48 else Printf.sprintf
"%d,%d,%d" n a b
;
51 let multicolumns_to_string (n
, a
, b
) =
53 then Printf.sprintf
"%d" n
54 else Printf.sprintf
"%d,%d,%d" n a b
;
57 let multicolumns_of_string s
=
59 (int_of_string s
, 0, 0)
61 Scanf.sscanf s
"%u,%u,%u" (fun n a b
->
63 then failwith
"subtly broken";
71 | KMmulti
of key list
* key list
73 and keyhash
= (key
, keymap
) Hashtbl.t
76 | KSinto
of (key list
* key list
)
77 and interpagespace
= int
78 and multicolumns
= multicol
* pagegeom
79 and singlecolumn
= pagegeom
80 and splitcolumns
= columncount
* pagegeom
81 and pagegeom
= (pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
82 and multicol
= columncount
* covercount
* covercount
86 and fitmodel
= | FitWidth
| FitProportional
| FitPage
87 and trimmargins
= bool
88 and irect
= (int * int * int * int)
94 (angle
* fitmodel
* trimparams
* texcount
* sliceheight
* memsize
95 * colorspace
* fontpath
* trimcachepath
* haspbo
)
100 and rectcolor
= (float * float * float * float)
105 and fontpath
= string
106 and trimcachepath
= string
109 and trimparams
= (trimmargins
* irect
)
110 and colorspace
= | Rgb
| Bgr
| Gray
112 and usefontconfig
= bool
120 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
125 | Uannotation
of (opaque
* slinkindex
)
127 and facename
= string
128 and launchcommand
= string
129 and filename
= string
132 and destname
= string
144 | LDfirstvisible
of (int * int * int)
153 and anchor
= pageno
* top
* dtop
154 and rect
= float * float * float * float * float * float * float * float
155 and infochange
= | Memused
| Docinfo
| Pdim
160 method display
: unit
161 method key
: int -> int -> uioh
162 method button
: int -> bool -> int -> int -> int -> uioh
163 method multiclick
: int -> int -> int -> int -> uioh
164 method motion
: int -> int -> uioh
165 method pmotion
: int -> int -> uioh
166 method infochanged
: infochange
-> unit
167 method scrollpw
: (int * float * float)
168 method scrollph
: (int * float * float)
169 method modehash
: keyhash
170 method eformsgs
: bool
171 method alwaysscrolly
: bool
172 method scroll
: int -> int -> uioh
173 method zoom
: float -> int -> int -> unit
176 module type TextEnumType
=
180 val names
: string array
183 module TextEnumMake
(Ten
: TextEnumType
) =
185 let names = Ten.names;;
186 let to_int (t
: Ten.t
) = Obj.magic t
;;
187 let to_string t
= names.(to_int t
);;
188 let of_int n
: Ten.t
= Obj.magic n
;;
191 if i
= Array.length
names
192 then failwith
("invalid " ^
Ten.name ^
": " ^ s
)
201 module CSTE
= TextEnumMake
(struct
202 type t
= colorspace
;;
203 let name = "colorspace";;
204 let names = [|"rgb"; "bgr"; "gray"|];;
207 module MTE
= TextEnumMake
(struct
210 let names = [|"page"; "block"; "line"; "word"|];;
213 module FMTE
= TextEnumMake
(struct
215 let name = "fitmodel";;
216 let names = [|"width"; "proportional"; "page"|];;
220 { mutable scrollbw
: int
221 ; mutable scrollh
: int
222 ; mutable scrollb
: scrollb
223 ; mutable icase
: bool
224 ; mutable preload
: bool
225 ; mutable pagebias
: int
226 ; mutable verbose
: bool
227 ; mutable debug
: bool
228 ; mutable scrollstep
: int
229 ; mutable hscrollstep
: int
230 ; mutable maxhfit
: bool
231 ; mutable crophack
: bool
232 ; mutable autoscrollstep
: int
233 ; mutable maxwait
: float option
234 ; mutable hlinks
: bool
235 ; mutable underinfo
: bool
236 ; mutable interpagespace
: interpagespace
237 ; mutable zoom
: float
238 ; mutable presentation
: bool
239 ; mutable angle
: angle
240 ; mutable cwinw
: int
241 ; mutable cwinh
: int
242 ; mutable savebmarks
: bool
243 ; mutable fitmodel
: fitmodel
244 ; mutable trimmargins
: trimmargins
245 ; mutable trimfuzz
: irect
246 ; mutable memlimit
: memsize
247 ; mutable texcount
: texcount
248 ; mutable sliceheight
: sliceheight
249 ; mutable thumbw
: width
250 ; mutable jumpback
: bool
251 ; mutable bgcolor
: (float * float * float)
252 ; mutable bedefault
: bool
253 ; mutable tilew
: int
254 ; mutable tileh
: int
255 ; mutable mustoresize
: memsize
256 ; mutable checkers
: bool
257 ; mutable aalevel
: int
258 ; mutable urilauncher
: string
259 ; mutable pathlauncher
: string
260 ; mutable colorspace
: colorspace
261 ; mutable invert
: bool
262 ; mutable colorscale
: float
263 ; mutable ghyllscroll
: (int * int * int) option
264 ; mutable columns
: columns
265 ; mutable beyecolumns
: columncount
option
266 ; mutable selcmd
: string
267 ; mutable paxcmd
: string
268 ; mutable passcmd
: string
269 ; mutable savecmd
: string
270 ; mutable updatecurs
: bool
271 ; mutable keyhashes
: (string * keyhash
) list
272 ; mutable hfsize
: int
273 ; mutable pgscale
: float
274 ; mutable usepbo
: bool
275 ; mutable wheelbypage
: bool
276 ; mutable stcmd
: string
277 ; mutable riani
: bool
278 ; mutable pax
: (float * int * int) ref option
279 ; mutable paxmark
: mark
280 ; mutable leftscroll
: bool
281 ; mutable title
: string
282 ; mutable lastvisit
: float
283 ; mutable annotinline
: bool
284 ; mutable coarseprespos
: bool
286 ; mutable usedoccss
: usedoccss
289 | Csingle
of singlecolumn
290 | Cmulti
of multicolumns
291 | Csplit
of splitcolumns
296 | Olaunch
of launchcommand
297 | Oremote
of (filename
* pageno
)
298 | Oremotedest
of (filename
* destname
)
299 | Ohistory
of (filename
* conf
* outline list
* x
* anchor
* filename
)
300 and outline
= (caption
* outlinelevel
* outlinekind
)
301 and outlinelevel
= int
319 type tile
= opaque
* pixmapsize
* elapsed
320 and elapsed
= float;;
321 type pagemapkey
= pageno
* gen
;;
322 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
327 | Loading
of (page
* gen
)
329 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
331 | Outlining
of outline list
334 type mpos
= int * int
336 | Msel
of (mpos
* mpos
)
338 | Mscrolly
| Mscrollx
339 | Mzoom
of (buttonno
* step
* mpos
)
340 | Mzoomrect
of (mpos
* mpos
)
347 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
348 | Textentry
of (textentry
* onleave
)
350 | LinkNav
of linktarget
351 and onleave
= leavetextentrystatus
-> unit
352 and leavetextentrystatus
= | Cancel
| Confirm
353 and helpitem
= string * int * action
356 | Action
of (uioh
-> uioh
)
358 | Ltexact
of (pageno
* direction
)
359 | Ltgendir
of direction
360 | Ltnotready
of (pageno
* direction
)
361 and direction
= int (* -1, 0, 1 *)
362 and textentry
= string * string * onhist
option
363 * onkey
* ondone
* cancelonempty
364 and onkey
= string -> Keys.t
-> te
365 and ondone
= string -> unit
366 and histcancel
= unit -> unit
367 and onhist
= ((histcmd
-> string) * histcancel
)
368 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
369 and cancelonempty
= bool
374 | TEswitch
of textentry
386 { mutable ss
: Unix.file_descr
387 ; mutable wsfd
: Unix.file_descr
388 ; mutable stderr
: Unix.file_descr
389 ; mutable errmsgs
: Buffer.t
390 ; mutable newerrmsgs
: bool
394 ; mutable anchor
: anchor
395 ; mutable ranchors
: (string * string * anchor
* string) list
397 ; mutable layout
: page list
398 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
399 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
400 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
401 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
402 ; mutable pagecount
: int
403 ; mutable currently
: currently
404 ; mutable mstate
: mstate
405 ; mutable searchpattern
: string
406 ; mutable rects
: (pageno
* rectcolor
* rect
) list
407 ; mutable rects1
: (pageno
* rectcolor
* rect
) list
408 ; prects
: (pageno
, float array
) Hashtbl.t
409 ; mutable text
: string
410 ; mutable winstate
: Wsi.winstate list
411 ; mutable mode
: mode
412 ; mutable uioh
: uioh
413 ; mutable outlines
: outline array
414 ; mutable bookmarks
: outline list
415 ; mutable path
: string
416 ; mutable password
: string
417 ; mutable nameddest
: string
418 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
419 ; mutable memused
: memsize
421 ; mutable throttle
: (page list
* int * float) option
422 ; mutable autoscroll
: int option
423 ; mutable ghyll
: (int option -> unit)
424 ; mutable help
: helpitem array
425 ; mutable docinfo
: (int * string) list
426 ; mutable checkerstexid
: GlTex.texture_id
option
428 ; mutable prevzoom
: (float * int)
429 ; mutable progress
: float
430 ; mutable redisplay
: bool
431 ; mutable mpos
: mpos
432 ; mutable keystate
: keystate
433 ; mutable glinks
: bool
434 ; mutable prevcolumns
: (columns
* float) option
437 ; mutable reprf
: (unit -> unit)
438 ; mutable origin
: string
439 ; mutable roam
: (unit -> unit)
440 ; mutable bzoom
: bool
441 ; mutable traw
: [`
float] Raw.t
442 ; mutable vraw
: [`
float] Raw.t
443 ; mutable lnava
: (pageno
* linkno
) option
446 { pat
: string circbuf
447 ; pag
: string circbuf
448 ; nav
: anchor circbuf
449 ; sel
: string circbuf
453 let emptyanchor = (0, 0.0, 0.0);;
454 let emptykeyhash = Hashtbl.create
0;;
456 let noreprf () = ();;
459 let nouioh : uioh
= object (self
)
461 method key _ _
= self
462 method multiclick _ _ _ _
= self
463 method button _ _ _ _ _
= self
464 method motion _ _
= self
465 method pmotion _ _
= self
466 method infochanged _
= ()
467 method scrollpw
= (0, nan
, nan
)
468 method scrollph
= (0, nan
, nan
)
469 method modehash
= emptykeyhash
470 method eformsgs
= false
471 method alwaysscrolly
= false
472 method scroll _ _
= self
473 method zoom _ _ _
= ()
476 let platform_to_string = function
477 | Punknown
-> "unknown"
482 | Pcygwin
-> "Cygwin"
486 Printf.sprintf
"llpp version %s, fitz %s, ocaml %s/%d bit"
487 Help.version (fz_version
()) Sys.ocaml_version
Sys.word_size
493 ; scrollb
= scrollbhv lor scrollbvv
509 ; presentation
= false
514 ; fitmodel
= FitProportional
515 ; trimmargins
= false
516 ; trimfuzz
= (0,0,0,0)
517 ; memlimit
= 32 lsl 20
522 ; bgcolor
= (0.5, 0.5, 0.5)
526 ; mustoresize
= 256 lsl 20
531 | Plinux
| Psun
| Pbsd
-> "xdg-open \"%s\""
532 | Posx
-> "open \"%s\""
533 | Pcygwin
-> "cygstart \"%s\""
534 | Punknown
-> "echo %s")
535 ; pathlauncher
= "lp \"%s\""
538 | Plinux
| Pbsd
| Psun
-> "xsel -i"
549 ; columns
= Csingle
[||]
552 ; hfsize
= 12 * Wsi.fontsizefactor
()
555 ; wheelbypage
= false
556 ; stcmd
= "echo SyncTex"
559 ; paxmark
= Mark_word
564 ; coarseprespos
= false
568 let mk n
= (n
, Hashtbl.create
1) in
582 let conf = { defconf with angle
= defconf.angle
};;
585 let command = Str.global_replace percentsre url
conf.urilauncher
in
586 try ignore
@@ spawn
command []
587 with exn
-> dolog
"failed to execute `%s': %s" command @@ exntos exn
591 if emptystr
conf.urilauncher
594 match geturl uri
with
595 | "" -> dolog
"obtained empty url from uri %S" uri
602 :: "(searching in this text works just by typing (i.e. no initial '/'))"
607 | "" -> (s
, 0, Noaction
)
608 | url
-> (s
, 0, Action
(fun uioh
-> gotourl url
; uioh
))
613 { store
= Array.make n v
620 let cbcap b
= Array.length b
.store
;;
625 b
.wc
<- (b
.wc
+ 1) mod cap;
627 b
.len
<- min
(b
.len
+ 1) cap;
630 let cbempty b
= b
.len
= 0;;
632 let cbgetg b circular dir
=
636 let rc = b
.rc + dir
in
648 else bound
rc 0 (b
.len
-1)
654 let cbget b
= cbgetg b
false;;
655 let cbgetc b
= cbgetg b
true;;
660 ; stderr
= Unix.stderr
661 ; errmsgs
= Buffer.create
0
666 ; anchor
= emptyanchor
670 ; tilelru
= Queue.create
()
671 ; pagemap
= Hashtbl.create
10
672 ; tilemap
= Hashtbl.create
10
679 ; prects
= Hashtbl.create
1
683 ; searchpattern
= E.s
691 { nav
= cbnew 10 emptyanchor
703 ; checkerstexid
= None
704 ; prevzoom
= (1.0, 0)
718 ; traw
= Raw.create_static `
float ~len
:8
719 ; vraw
= Raw.create_static `
float ~len
:8
724 let copykeyhashes c
=
725 List.map
(fun (k
, v
) -> k
, Hashtbl.copy v
) c
.keyhashes
;
729 let d = state.winh
- h
in
730 max
conf.interpagespace
((d + 1) / 2)
733 let rowyh (c
, coverA
, coverB
) b n
=
734 if c
= 1 || (n
< coverA
|| n
>= state.pagecount
- coverB
)
736 let _, _, vy
, (_, _, h
, _) = b
.(n
) in
739 let n'
= n - coverA
in
742 let e = min
state.pagecount
(s + c
) in
743 let rec find m miny maxh
= if m
= e then miny
, maxh
else
744 let _, _, y
, (_, _, h
, _) = b
.(m
) in
745 let miny = min
miny y
in
746 let maxh = max
maxh h
in
752 let ((c
, coverA
, coverB
) as cl
), b
=
753 match conf.columns
with
754 | Csingle b
-> (1, 0, 0), b
755 | Cmulti
(c
, b
) -> c
, b
756 | Csplit
(_, b
) -> (1, 0, 0), b
758 if Array.length b
= 0
761 let rec bsearch nmin nmax
=
763 then bound nmin
0 (state.pagecount
-1)
765 let n = (nmax
+ nmin
) / 2 in
766 let vy, h
= rowyh cl b
n in
770 let ips = calcips h
in
772 let y1 = vy + h
+ ips in
776 then 0, vy + h
+ conf.interpagespace
778 let y0 = vy - conf.interpagespace
in
779 y0, y0 + h
+ conf.interpagespace
789 if n < state.pagecount
- coverB
790 then ((n-coverA
)/c
)*c
+ coverA
797 then bsearch (n+1) nmax
798 else bsearch nmin
(n-1)
801 bsearch 0 (state.pagecount
-1);
805 match conf.columns
with
806 | Cmulti
((_, _, _) as cl
, b
) ->
807 if Array.length b
> 0
809 let y, h
= rowyh cl b
(Array.length b
- 1) in
810 y + h
+ (if conf.presentation
then calcips h
else 0)
813 if Array.length b
> 0
815 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
816 y + h
+ (if conf.presentation
then calcips h
else 0)
819 if Array.length b
> 0
821 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
826 let getpageywh pageno
=
827 let pageno = bound
pageno 0 (state.pagecount
-1) in
828 match conf.columns
with
830 if Array.length b
= 0
833 let (_, _, y, (_, w
, h
, _)) = b
.(pageno) in
841 if Array.length b
= 0
844 let y, h
= rowyh cl b
pageno in
845 let (_, _, _, (_, w
, _, _)) = b
.(pageno) in
853 if Array.length b
= 0
857 let (_, _, y, (_, w
, h
, _)) = b
.(n) in
861 let getpageyh pageno =
862 let y,_,h
= getpageywh pageno in
866 let getpagedim pageno =
869 | (n, _, _, _) as pdim
:: rest
->
871 then (if n = pageno then pdim
else ppdim
)
876 f (-1, -1, -1, -1) state.pdims
879 let getpdimno pageno =
883 | (n, _, _, _) :: rest
->
885 then (if n = pageno then np else p
)
893 let getpagey pageno = fst
(getpageyh pageno);;
897 let coloff = l
.pagecol
* l
.pageh
in
898 float (l
.pagey
+ coloff) /. float l
.pageh
906 then float l
.pagedispy
/. float (calcips l
.pageh
)
907 else float l
.pagedispy
/. float conf.interpagespace
910 (l
.pageno, top, dtop)
914 match state.layout
with
915 | l
:: _ -> getanchor1 l
917 let n = page_of_y state.y in
921 let y, h
= getpageyh n in
922 let dy = y - state.y in
926 let ips = calcips h
in
927 float (dy + ips) /. float ips
929 float dy /. float conf.interpagespace
934 let fontpath = ref E.s;;
936 type historder
= [ `lastvisit
| `title
| `path
| `file
];;
939 Map.Make
(struct type t
= (int * int) let compare = compare end);;
942 let l = String.length
s in
943 let b = Buffer.create
l in
944 Parser.unent
b s 0 l;
949 try Sys.getenv
"HOME"
951 dolog
"cannot determine home directory location: %s" @@ exntos exn
;
955 let modifier_of_string = function
956 | "alt" -> Wsi.altmask
957 | "shift" -> Wsi.shiftmask
958 | "ctrl" | "control" -> Wsi.ctrlmask
959 | "meta" -> Wsi.metamask
963 let keys_of_string s =
964 let key_of_string r
s =
965 let elems = Str.full_split r
s in
968 let m1 = modifier_of_string s in
970 then (Wsi.namekey
s, m
)
973 | Str.Delim
s when n land 1 = 0 -> g s
975 | Str.Delim
_ -> (k
, m
)
977 let rec loop n k m
= function
980 let k, m
= f n k m x
in
985 let elems = Str.split whitere
s in
986 List.map
(key_of_string (Str.regexp
"-")) elems
989 let config_of c attrs
=
993 | "scroll-bar-width" -> { c
with scrollbw
= max
0 (int_of_string v
) }
994 | "scroll-handle-height" -> { c
with scrollh
= max
0 (int_of_string v
) }
995 | "case-insensitive-search" -> { c
with icase
= bool_of_string v
}
996 | "preload" -> { c
with preload
= bool_of_string v
}
997 | "page-bias" -> { c
with pagebias
= int_of_string v
}
998 | "scroll-step" -> { c
with scrollstep
= max
1 (int_of_string v
) }
999 | "horizontal-scroll-step" ->
1000 { c
with hscrollstep
= max
(int_of_string v
) 1 }
1001 | "auto-scroll-step" ->
1002 { c
with autoscrollstep
= max
0 (int_of_string v
) }
1003 | "max-height-fit" -> { c
with maxhfit
= bool_of_string v
}
1004 | "crop-hack" -> { c
with crophack
= bool_of_string v
}
1007 match String.map asciilower v
with
1008 | "true" -> Some infinity
1010 | f -> Some
(float_of_string
f)
1012 { c
with maxwait
= mw }
1013 | "highlight-links" -> { c
with hlinks
= bool_of_string v
}
1014 | "under-cursor-info" -> { c
with underinfo
= bool_of_string v
}
1015 | "vertical-margin" ->
1016 { c
with interpagespace
= max
0 (int_of_string v
) }
1018 let zoom = float_of_string v
/. 100. in
1019 let zoom = max
zoom 0.0 in
1020 { c
with zoom = zoom }
1021 | "presentation" -> { c
with presentation
= bool_of_string v
}
1022 | "rotation-angle" -> { c
with angle
= int_of_string v
}
1023 | "width" -> { c
with cwinw
= max
20 (int_of_string v
) }
1024 | "height" -> { c
with cwinh
= max
20 (int_of_string v
) }
1025 | "persistent-bookmarks" -> { c
with savebmarks
= bool_of_string v
}
1026 | "proportional-display" ->
1029 then FitProportional
1032 { c
with fitmodel
= fm }
1033 | "fit-model" -> { c
with fitmodel
= FMTE.of_string v
}
1034 | "pixmap-cache-size" ->
1035 { c
with memlimit
= max
2 (int_of_string_with_suffix v
) }
1036 | "tex-count" -> { c
with texcount
= max
1 (int_of_string v
) }
1037 | "slice-height" -> { c
with sliceheight
= max
2 (int_of_string v
) }
1038 | "thumbnail-width" -> { c
with thumbw
= max
2 (int_of_string v
) }
1039 | "persistent-location" -> { c
with jumpback
= bool_of_string v
}
1040 | "background-color" -> { c
with bgcolor
= color_of_string v
}
1041 | "tile-width" -> { c
with tilew
= max
2 (int_of_string v
) }
1042 | "tile-height" -> { c
with tileh
= max
2 (int_of_string v
) }
1043 | "mupdf-store-size" ->
1044 { c
with mustoresize
= max
1024 (int_of_string_with_suffix v
) }
1045 | "checkers" -> { c
with checkers
= bool_of_string v
}
1046 | "aalevel" -> { c
with aalevel
= max
0 (int_of_string v
) }
1047 | "trim-margins" -> { c
with trimmargins
= bool_of_string v
}
1048 | "trim-fuzz" -> { c
with trimfuzz
= irect_of_string v
}
1049 | "uri-launcher" -> { c
with urilauncher
= unentS v
}
1050 | "path-launcher" -> { c
with pathlauncher
= unentS v
}
1051 | "color-space" -> { c
with colorspace
= CSTE.of_string v
}
1052 | "invert-colors" -> { c
with invert
= bool_of_string v
}
1053 | "brightness" -> { c
with colorscale
= float_of_string v
}
1054 | "ghyllscroll" -> { c
with ghyllscroll
= ghyllscroll_of_string v
}
1056 let (n, _, _) as nab
= multicolumns_of_string v
in
1058 then { c
with columns
= Csplit
(-n, E.a
) }
1059 else { c
with columns
= Cmulti
(nab
, E.a
) }
1060 | "birds-eye-columns" ->
1061 { c
with beyecolumns
= Some
(max
(int_of_string v
) 2) }
1062 | "selection-command" -> { c
with selcmd
= unentS v
}
1063 | "synctex-command" -> { c
with stcmd
= unentS v
}
1064 | "pax-command" -> { c
with paxcmd
= unentS v
}
1065 | "askpass-command" -> { c
with passcmd
= unentS v
}
1066 | "savepath-command" -> { c
with savecmd
= unentS v
}
1067 | "update-cursor" -> { c
with updatecurs
= bool_of_string v
}
1068 | "hint-font-size" -> { c
with hfsize
= bound
(int_of_string v
) 5 100 }
1069 | "page-scroll-scale" -> { c
with pgscale
= float_of_string v
}
1070 | "use-pbo" -> { c
with usepbo
= bool_of_string v
}
1071 | "wheel-scrolls-pages" -> { c
with wheelbypage
= bool_of_string v
}
1072 | "horizontal-scrollbar-visible" ->
1075 then c
.scrollb
lor scrollbhv
1076 else c
.scrollb
land (lnot
scrollbhv)
1078 { c
with scrollb
= b }
1079 | "vertical-scrollbar-visible" ->
1082 then c
.scrollb
lor scrollbvv
1083 else c
.scrollb
land (lnot
scrollbvv)
1085 { c
with scrollb
= b }
1086 | "remote-in-a-new-instance" -> { c
with riani
= bool_of_string v
}
1090 then Some
(ref (0.0, 0, 0))
1092 | "point-and-x-mark" -> { c
with paxmark
= MTE.of_string v
}
1093 | "scroll-bar-on-the-left" -> { c
with leftscroll
= bool_of_string v
}
1094 | "title" -> { c
with title
= unentS v
}
1095 | "last-visit" -> { c
with lastvisit
= float_of_string v
}
1096 | "edit-annotations-inline" -> { c
with annotinline
= bool_of_string v
}
1097 | "coarse-presentation-positioning" ->
1098 { c
with coarseprespos
= bool_of_string v
}
1099 | "use-document-css" -> { c
with usedoccss
= bool_of_string v
}
1102 dolog
"error processing attribute (`%S' = `%S'): %s" k v
@@ exntos exn
;
1105 let rec fold c
= function
1108 let c = apply c k v
in
1111 fold { c with keyhashes
= copykeyhashes c } attrs
;
1114 let fromstring f pos
n v
d =
1117 dolog
"error processing attribute (%S=%S) at %d\n%s" n v pos
@@ exntos exn
;
1121 let bookmark_of attrs
=
1122 let rec fold title page rely visy
= function
1123 | ("title", v
) :: rest
-> fold v page rely visy rest
1124 | ("page", v
) :: rest
-> fold title v rely visy rest
1125 | ("rely", v
) :: rest
-> fold title page v visy rest
1126 | ("visy", v
) :: rest
-> fold title page rely v rest
1127 | _ :: rest
-> fold title page rely visy rest
1128 | [] -> title
, page
, rely
, visy
1130 fold "invalid" "0" "0" "0" attrs
1134 let rec fold path page rely pan visy origin
= function
1135 | ("path", v
) :: rest
-> fold v page rely pan visy origin rest
1136 | ("page", v
) :: rest
-> fold path v rely pan visy origin rest
1137 | ("rely", v
) :: rest
-> fold path page v pan visy origin rest
1138 | ("pan", v
) :: rest
-> fold path page rely v visy origin rest
1139 | ("visy", v
) :: rest
-> fold path page rely pan v origin rest
1140 | ("origin", v
) :: rest
-> fold path page rely pan visy v rest
1141 | _ :: rest
-> fold path page rely pan visy origin rest
1142 | [] -> path
, page
, rely
, pan
, visy
, origin
1144 fold E.s "0" "0" "0" "0" E.s attrs
1148 let rec fold rs ls
= function
1149 | ("out", v
) :: rest
-> fold v ls rest
1150 | ("in", v
) :: rest
-> fold rs v rest
1151 | _ :: rest
-> fold ls rs rest
1157 let setconf dst src
=
1158 dst
.scrollbw
<- src
.scrollbw
;
1159 dst
.scrollh
<- src
.scrollh
;
1160 dst
.icase
<- src
.icase
;
1161 dst
.preload
<- src
.preload
;
1162 dst
.pagebias
<- src
.pagebias
;
1163 dst
.verbose
<- src
.verbose
;
1164 dst
.scrollstep
<- src
.scrollstep
;
1165 dst
.maxhfit
<- src
.maxhfit
;
1166 dst
.crophack
<- src
.crophack
;
1167 dst
.autoscrollstep
<- src
.autoscrollstep
;
1168 dst
.maxwait
<- src
.maxwait
;
1169 dst
.hlinks
<- src
.hlinks
;
1170 dst
.underinfo
<- src
.underinfo
;
1171 dst
.interpagespace
<- src
.interpagespace
;
1172 dst
.zoom <- src
.zoom;
1173 dst
.presentation
<- src
.presentation
;
1174 dst
.angle
<- src
.angle
;
1175 dst
.cwinw
<- src
.cwinw
;
1176 dst
.cwinh
<- src
.cwinh
;
1177 dst
.savebmarks
<- src
.savebmarks
;
1178 dst
.memlimit
<- src
.memlimit
;
1179 dst
.fitmodel
<- src
.fitmodel
;
1180 dst
.texcount
<- src
.texcount
;
1181 dst
.sliceheight
<- src
.sliceheight
;
1182 dst
.thumbw
<- src
.thumbw
;
1183 dst
.jumpback
<- src
.jumpback
;
1184 dst
.bgcolor
<- src
.bgcolor
;
1185 dst
.tilew
<- src
.tilew
;
1186 dst
.tileh
<- src
.tileh
;
1187 dst
.mustoresize
<- src
.mustoresize
;
1188 dst
.checkers
<- src
.checkers
;
1189 dst
.aalevel
<- src
.aalevel
;
1190 dst
.trimmargins
<- src
.trimmargins
;
1191 dst
.trimfuzz
<- src
.trimfuzz
;
1192 dst
.urilauncher
<- src
.urilauncher
;
1193 dst
.colorspace
<- src
.colorspace
;
1194 dst
.invert
<- src
.invert
;
1195 dst
.colorscale
<- src
.colorscale
;
1196 dst
.ghyllscroll
<- src
.ghyllscroll
;
1197 dst
.columns
<- src
.columns
;
1198 dst
.beyecolumns
<- src
.beyecolumns
;
1199 dst
.selcmd
<- src
.selcmd
;
1200 dst
.updatecurs
<- src
.updatecurs
;
1201 dst
.pathlauncher
<- src
.pathlauncher
;
1202 dst
.keyhashes
<- copykeyhashes src
;
1203 dst
.hfsize
<- src
.hfsize
;
1204 dst
.hscrollstep
<- src
.hscrollstep
;
1205 dst
.pgscale
<- src
.pgscale
;
1206 dst
.usepbo
<- src
.usepbo
;
1207 dst
.wheelbypage
<- src
.wheelbypage
;
1208 dst
.stcmd
<- src
.stcmd
;
1209 dst
.paxcmd
<- src
.paxcmd
;
1210 dst
.passcmd
<- src
.passcmd
;
1211 dst
.savecmd
<- src
.savecmd
;
1212 dst
.scrollb
<- src
.scrollb
;
1213 dst
.riani
<- src
.riani
;
1214 dst
.paxmark
<- src
.paxmark
;
1215 dst
.leftscroll
<- src
.leftscroll
;
1216 dst
.title
<- src
.title
;
1217 dst
.annotinline
<- src
.annotinline
;
1218 dst
.coarseprespos
<- src
.coarseprespos
;
1220 dst
.usedoccss
<- src
.usedoccss
;
1224 else Some
((ref (0.0, 0, 0)));
1227 let findkeyhash c name =
1228 try List.assoc
name c.keyhashes
1229 with Not_found
-> failwith
("invalid mode name `" ^
name ^
"'")
1234 let h = Hashtbl.create
10 in
1235 let dc = { defconf with angle
= defconf.angle
} in
1236 let rec toplevel v t spos
_ =
1238 | Vdata
| Vcdata
| Vend
-> v
1239 | Vopen
("llppconfig", _, closed
) ->
1242 else { v
with f = llppconfig
}
1243 | Vopen
_ -> parse_error
"unexpected subelement at top level" s spos
1244 | Vclose
_ -> parse_error
"unexpected close at top level" s spos
1246 and llppconfig v t spos
_ =
1248 | Vdata
| Vcdata
-> v
1249 | Vend
-> parse_error
"unexpected end of input in llppconfig" s spos
1250 | Vopen
("defaults", attrs
, closed
) ->
1251 let c = config_of dc attrs
in
1255 else { v
with f = defaults
}
1257 | Vopen
("ui-font", attrs
, closed
) ->
1258 let rec getsize size
= function
1260 | ("size", v
) :: rest
->
1262 fromstring int_of_string spos
"size" v
fstate.fontsize
in
1264 | l -> getsize size l
1266 fstate.fontsize
<- getsize fstate.fontsize attrs
;
1269 else { v
with f = uifont
(Buffer.create
10) }
1271 | Vopen
("doc", attrs
, closed
) ->
1272 let pathent, spage
, srely
, span
, svisy
, origin
= doc_of attrs
in
1273 let path = unentS pathent
1274 and origin
= unentS origin
1275 and pageno = fromstring int_of_string spos
"page" spage
0
1276 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1277 and pan
= fromstring int_of_string spos
"pan" span
0
1278 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1279 let c = config_of dc attrs
in
1280 let anchor = (pageno, rely
, visy
) in
1282 then (Hashtbl.add
h path (c, [], pan
, anchor, origin
); v
)
1283 else { v
with f = doc
path origin pan
anchor c [] }
1286 parse_error
"unexpected subelement in llppconfig" s spos
1288 | Vclose
"llppconfig" -> { v
with f = toplevel }
1289 | Vclose
_ -> parse_error
"unexpected close in llppconfig" s spos
1291 and defaults v t spos
_ =
1293 | Vdata
| Vcdata
-> v
1294 | Vend
-> parse_error
"unexpected end of input in defaults" s spos
1295 | Vopen
("keymap", attrs
, closed
) ->
1297 try List.assoc
"mode" attrs
1298 with Not_found
-> "global" in
1303 let h = findkeyhash dc modename in
1304 KeyMap.iter
(Hashtbl.replace
h) keymap
;
1307 { v
with f = pkeymap
ret KeyMap.empty
}
1309 | Vopen
(_, _, _) ->
1310 parse_error
"unexpected subelement in defaults" s spos
1312 | Vclose
"defaults" ->
1313 { v
with f = llppconfig
}
1315 | Vclose
_ -> parse_error
"unexpected close in defaults" s spos
1317 and uifont
b v t spos epos
=
1320 Buffer.add_substring
b s spos
(epos
- spos
);
1322 | Vopen
(_, _, _) ->
1323 parse_error
"unexpected subelement in ui-font" s spos
1324 | Vclose
"ui-font" ->
1325 if emptystr
!fontpath
1326 then fontpath := Buffer.contents
b;
1327 { v
with f = llppconfig
}
1328 | Vclose
_ -> parse_error
"unexpected close in ui-font" s spos
1329 | Vend
-> parse_error
"unexpected end of input in ui-font" s spos
1331 and doc
path origin pan
anchor c bookmarks v t spos
_ =
1333 | Vdata
| Vcdata
-> v
1334 | Vend
-> parse_error
"unexpected end of input in doc" s spos
1335 | Vopen
("bookmarks", _, closed
) ->
1338 else { v
with f = pbookmarks
path origin pan
anchor c bookmarks
}
1340 | Vopen
("keymap", attrs
, closed
) ->
1342 try List.assoc
"mode" attrs
1343 with Not_found
-> "global"
1349 let h = findkeyhash c modename in
1350 KeyMap.iter
(Hashtbl.replace
h) keymap
;
1351 doc
path origin pan
anchor c bookmarks
1353 { v
with f = pkeymap
ret KeyMap.empty
}
1355 | Vopen
("css", [], false) ->
1356 { v
with f = pcss
path origin pan
anchor c bookmarks
}
1358 | Vopen
(_, _, _) ->
1359 parse_error
"unexpected subelement in doc" s spos
1362 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor, origin
);
1363 { v
with f = llppconfig
}
1365 | Vclose
_ -> parse_error
"unexpected close in doc" s spos
1367 and pcss
path origin pan
anchor c bookmarks v t spos epos
=
1370 let b = Buffer.create
10 in
1371 Buffer.add_substring
b s spos
(epos
- spos
);
1372 { v
with f = pcss
path origin pan
anchor
1373 { c with css
= Buffer.contents
b }
1375 | Vend
-> parse_error
"unexpected end of input in css" s spos
1376 | Vopen
_ -> parse_error
"unexpected subelement in css" s spos
1377 | Vclose
"css" -> { v
with f = doc
path origin pan
anchor c bookmarks
}
1378 | Vclose
_ -> parse_error
"unexpected close in css" s spos
1380 and pkeymap
ret keymap v t spos
_ =
1382 | Vdata
| Vcdata
-> v
1383 | Vend
-> parse_error
"unexpected end of input in keymap" s spos
1384 | Vopen
("map", attrs
, closed
) ->
1385 let r, l = map_of attrs
in
1386 let kss = fromstring keys_of_string spos
"in" r [] in
1387 let lss = fromstring keys_of_string spos
"out" l [] in
1391 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
1392 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
1395 then { v
with f = pkeymap
ret keymap }
1398 { v
with f = skip
"map" f }
1401 parse_error
"unexpected subelement in keymap" s spos
1403 | Vclose
"keymap" ->
1404 { v
with f = ret keymap }
1406 | Vclose
_ -> parse_error
"unexpected close in keymap" s spos
1408 and pbookmarks
path origin pan
anchor c bookmarks v t spos
_ =
1410 | Vdata
| Vcdata
-> v
1411 | Vend
-> parse_error
"unexpected end of input in bookmarks" s spos
1412 | Vopen
("item", attrs
, closed
) ->
1413 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
1414 let page = fromstring int_of_string spos
"page" spage
0
1415 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1416 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1418 (unentS titleent, 0, Oanchor
(page, rely
, visy
)) :: bookmarks
1421 then { v
with f = pbookmarks
path origin pan
anchor c bookmarks }
1424 { v
with f = skip
"item" f }
1427 parse_error
"unexpected subelement in bookmarks" s spos
1429 | Vclose
"bookmarks" ->
1430 { v
with f = doc
path origin pan
anchor c bookmarks }
1432 | Vclose
_ -> parse_error
"unexpected close in bookmarks" s spos
1434 and skip tag
f v t spos
_ =
1436 | Vdata
| Vcdata
-> v
1438 parse_error
("unexpected end of input in skipped " ^ tag
) s spos
1439 | Vopen
(tag'
, _, closed
) ->
1443 let f'
() = { v
with f = skip tag
f } in
1444 { v
with f = skip tag'
f'
}
1448 else parse_error
("unexpected close in skipped " ^ tag
) s spos
1451 parse
{ f = toplevel; accu
= () } s;
1455 let do_load f contents
=
1458 | Parser.Parse_error
(msg
, s, pos
) ->
1459 let subs = Parser.subs s pos
in
1460 Utils.error
"parse error: %s: at %d [..%S..]" msg pos
subs
1462 | exn
-> Utils.error
"parse error: %s" @@ exntos exn
1467 let xdgconfdir = Utils.getenvwithdef
"XDG_CONFIG_HOME" E.s in
1468 if emptystr
xdgconfdir
1471 let dir = Filename.concat
home ".config" in
1472 if Sys.is_directory
dir then dir else home
1476 Filename.concat
dir "llpp.conf"
1479 let confpath = ref defconfpath;;
1481 let load2 f default
=
1482 match filecontents
!confpath with
1483 | contents
-> f @@ do_load get contents
1484 | exception Unix.Unix_error
(Unix.ENOENT
, "open", _) ->
1485 f (Hashtbl.create
0, defconf)
1487 dolog
"error loading configuration from `%S': %s" !confpath @@ exntos exn
;
1491 let load1 f = load2 f false;;
1499 (fun path (conf, _, _, _, _) ((_, besttime
) as best
) ->
1500 if conf.lastvisit
> besttime
1501 then (path, conf.lastvisit
)
1504 (state.path, -.infinity
)
1508 let pc, pb
, px
, pa
, po
=
1510 let absname = abspath
state.path in
1511 Hashtbl.find h absname
1512 with Not_found
-> dc, [], 0, emptyanchor, state.origin
1516 state.bookmarks <- pb
;
1520 then state.anchor <- pa
;
1521 cbput state.hists
.nav pa
;
1529 Hashtbl.fold (fun path (pc, pb
, px
, pa
, po
) accu
->
1530 (path, pc, pb
, px
, pa
, po
) :: accu
)
1536 let add_attrs bb always
dc c time
=
1538 Buffer.add_string bb
"\n ";
1539 Printf.bprintf bb fmt
s
1541 let o c fmt
s = if c then o' fmt
s else ignore
in
1542 let ob s a
b = o (always
|| a
!= b) "%s='%b'" s a
1543 and op
s a
b = o (always
|| a
<> b) "%s='%b'" s (a
!= None
)
1544 and oi
s a
b = o (always
|| a
!= b) "%s='%d'" s a
1545 and oI
s a
b = o (always
|| a
!= b) "%s='%s'" s (string_with_suffix_of_int a
)
1546 and oz
s a
b = o (always
|| a
<> b) "%s='%g'" s (a
*.100.)
1547 and oF
s a
b = o (always
|| a
<> b) "%s='%f'" s a
1548 and oL
s a
b = o (always
|| a
<> b) "%s='%Ld'" s a
1549 and oc
s a
b = o (always
|| a
<> b) "%s='%s'" s (color_to_string a
)
1550 and oC
s a
b = o (always
|| a
<> b) "%s='%s'" s (CSTE.to_string a
)
1551 and oR
s a
b = o (always
|| a
<> b) "%s='%s'" s (irect_to_string a
)
1552 and oFm
s a
b = o (always
|| a
<> b) "%s='%s'" s (FMTE.to_string a
)
1553 and oSv
s a
b m
= o (always
|| a
<> b) "%s='%b'" s (a
land m
!= 0)
1554 and oPm
s a
b = o (always
|| a
<> b) "%s='%s'" s (MTE.to_string a
)
1556 o (always
|| a
<> b) "%s='%s'" s @@ Parser.enent a
0 (String.length a
)
1561 | Some
(_N
, _A
, _B
) -> o'
"%s='%u,%u,%u'" s _N _A _B
1565 | _ -> o'
"%s='none'" s
1575 else string_of_float
f
1582 | Cmulti
((n, a
, b), _) when n > 1 -> o'
"%s='%d,%d,%d'" s n a
b
1583 | Csplit
(n, _) when n > 1 -> o'
"%s='%d'" s ~
-n
1584 | Cmulti
_ | Csplit
_ | Csingle
_ -> ()
1589 | Some
c when c > 1 -> o'
"%s='%d'" s c
1592 oi
"width" c.cwinw
dc.cwinw
;
1593 oi
"height" c.cwinh
dc.cwinh
;
1594 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
1595 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
1596 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
1597 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
1598 ob "case-insensitive-search" c.icase
dc.icase
;
1599 ob "preload" c.preload
dc.preload
;
1600 oi
"page-bias" c.pagebias
dc.pagebias
;
1601 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
1602 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
1603 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
1604 ob "crop-hack" c.crophack
dc.crophack
;
1605 oW
"throttle" c.maxwait
dc.maxwait
;
1606 ob "highlight-links" c.hlinks
dc.hlinks
;
1607 ob "under-cursor-info" c.underinfo
dc.underinfo
;
1608 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
1609 oz
"zoom" c.zoom dc.zoom;
1610 ob "presentation" c.presentation
dc.presentation
;
1611 oi
"rotation-angle" c.angle
dc.angle
;
1612 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
1613 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
1614 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
1615 oi
"tex-count" c.texcount
dc.texcount
;
1616 oi
"slice-height" c.sliceheight
dc.sliceheight
;
1617 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
1618 ob "persistent-location" c.jumpback
dc.jumpback
;
1619 oc
"background-color" c.bgcolor
dc.bgcolor
;
1620 oi
"tile-width" c.tilew
dc.tilew
;
1621 oi
"tile-height" c.tileh
dc.tileh
;
1622 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
1623 ob "checkers" c.checkers
dc.checkers
;
1624 oi
"aalevel" c.aalevel
dc.aalevel
;
1625 ob "trim-margins" c.trimmargins
dc.trimmargins
;
1626 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
1627 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
1628 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
1629 oC
"color-space" c.colorspace
dc.colorspace
;
1630 ob "invert-colors" c.invert
dc.invert
;
1631 oF
"brightness" c.colorscale
dc.colorscale
;
1632 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
1633 oco
"columns" c.columns
dc.columns
;
1634 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
1635 os
"selection-command" c.selcmd
dc.selcmd
;
1636 os
"synctex-command" c.stcmd
dc.stcmd
;
1637 os
"pax-command" c.paxcmd
dc.paxcmd
;
1638 os
"askpass-command" c.passcmd
dc.passcmd
;
1639 os
"savepath-command" c.savecmd
dc.savecmd
;
1640 ob "update-cursor" c.updatecurs
dc.updatecurs
;
1641 oi
"hint-font-size" c.hfsize
dc.hfsize
;
1642 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
1643 oF
"page-scroll-scale" c.pgscale
dc.pgscale
;
1644 ob "use-pbo" c.usepbo
dc.usepbo
;
1645 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
1646 ob "remote-in-a-new-instance" c.riani
dc.riani
;
1647 op
"point-and-x" c.pax
dc.pax
;
1648 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
1649 ob "scroll-bar-on-the-left" c.leftscroll
dc.leftscroll
;
1651 then os
"title" c.title
dc.title
;
1652 oL
"last-visit" (Int64.of_float time
) 0L;
1653 ob "edit-annotations-inline" c.annotinline
dc.annotinline
;
1654 ob "coarse-presentation-positioning" c.coarseprespos
dc.coarseprespos
;
1655 ob "use-document-css" c.usedoccss
dc.usedoccss
;
1658 let keymapsbuf always
dc c =
1660 let bb = create
16 in
1661 let rec loop = function
1663 | (modename, h) :: rest
->
1664 let dh = findkeyhash dc modename in
1665 if always
|| h <> dh
1667 if Hashtbl.length
h > 0
1669 if length
bb > 0 then add_char
bb '
\n'
;
1670 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
1671 Hashtbl.iter
(fun i
o ->
1672 if always
|| match Hashtbl.find dh i
1673 with | dO
-> dO
<> o | exception Not_found
-> false
1676 if Wsi.withctrl m
then add_string
bb "ctrl-";
1677 if Wsi.withalt m
then add_string
bb "alt-";
1678 if Wsi.withshift m
then add_string
bb "shift-";
1679 if Wsi.withmeta m
then add_string
bb "meta-";
1680 add_string
bb (Wsi.keyname
k);
1683 let rec loop = function
1685 | km
:: [] -> addkm km
1686 | km
:: rest
-> addkm km
; add_char
bb ' '
; loop rest
1690 add_string
bb "<map in='";
1694 add_string
bb "' out='"; addkm km
; add_string
bb "'/>\n"
1697 add_string
bb "' out='"; addkms kms
; add_string
bb "'/>\n"
1699 | KMmulti
(ins
, kms
) ->
1700 add_char
bb ' '
; addkms ins
; add_string
bb "' out='";
1701 addkms kms
; add_string
bb "'/>\n"
1703 add_string
bb "</keymap>";
1712 let keystostrlist c =
1713 let rec loop accu
= function
1715 | (modename, h) :: rest
->
1717 if Hashtbl.length
h > 0
1719 let accu = Printf.sprintf
"\xc2\xb7Keys for %s" modename :: accu in
1720 Hashtbl.fold (fun i
o a
->
1721 let bb = Buffer.create
10 in
1723 if Wsi.withctrl m
then Buffer.add_string
bb "ctrl-";
1724 if Wsi.withalt m
then Buffer.add_string
bb "alt-";
1725 if Wsi.withshift m
then Buffer.add_string
bb "shift-";
1726 if Wsi.withmeta m
then Buffer.add_string
bb "meta-";
1727 Buffer.add_string
bb (Wsi.keyname
k);
1730 let rec loop = function
1732 | km
:: [] -> addkm km
1734 addkm km
; Buffer.add_char
bb ' '
;
1740 Buffer.add_char
bb '
\t'
;
1748 | KMmulti
(ins
, kms
) ->
1749 Buffer.add_char
bb ' '
;
1751 Buffer.add_string
bb "\t";
1754 Buffer.contents
bb :: a
1764 let save1 bb leavebirdseye x
h dc =
1765 let uifontsize = fstate.fontsize
in
1766 let dc = if conf.bedefault
then conf else dc in
1767 Buffer.add_string
bb "<llppconfig>\n";
1769 if nonemptystr
!fontpath
1771 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
1777 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
1780 Buffer.add_string
bb "<defaults";
1781 add_attrs bb true dc dc nan
;
1782 let kb = keymapsbuf true dc dc in
1783 if Buffer.length
kb > 0
1785 Buffer.add_string
bb ">\n";
1786 Buffer.add_buffer
bb kb;
1787 Buffer.add_string
bb "\n</defaults>\n";
1789 else Buffer.add_string
bb "/>\n";
1791 let adddoc path pan
anchor c bookmarks time origin
=
1792 if bookmarks == [] && c = dc && anchor = emptyanchor
1795 Printf.bprintf
bb "<doc path='%s'"
1796 (Parser.enent
path 0 (String.length
path));
1798 if nonemptystr origin
1799 then Printf.bprintf
bb "\n origin='%s'"
1800 (Parser.enent origin
0 (String.length origin
));
1802 if anchor <> emptyanchor
1804 let n, rely
, visy
= anchor in
1805 Printf.bprintf
bb "\n page='%d'" n;
1808 then Printf.bprintf
bb " rely='%f'" rely
;
1810 if abs_float visy
> 1e-6
1811 then Printf.bprintf
bb " visy='%f'" visy
;
1815 then Printf.bprintf
bb " pan='%d'" pan
;
1817 add_attrs bb false dc c time
;
1818 if nonemptystr
c.css
1819 then Printf.bprintf
bb ">\n <css><![CDATA[%s]]></css>" c.css
;
1820 let kb = keymapsbuf false dc c in
1822 begin match bookmarks with
1824 if Buffer.length
kb > 0
1826 Buffer.add_string
bb ">\n";
1827 Buffer.add_buffer
bb kb;
1828 Buffer.add_string
bb "\n</doc>\n";
1831 if nonemptystr
c.css
1832 then Buffer.add_string
bb "\n</doc>\n"
1833 else Buffer.add_string
bb "/>\n"
1835 Buffer.add_string
bb ">\n<bookmarks>\n";
1836 List.iter
(fun (title
, _, kind
) ->
1837 begin match kind
with
1838 | Oanchor
(page, rely
, visy
) ->
1840 "<item title='%s' page='%d'"
1841 (Parser.enent title
0 (String.length title
))
1846 Printf.bprintf
bb " rely='%f'" rely
1848 if abs_float visy
> 1e-6
1850 Printf.bprintf
bb " visy='%f'" visy
1852 | Ohistory
_ | Onone
| Ouri
_ | Oremote
_
1853 | Oremotedest
_ | Olaunch
_ ->
1854 failwith
"unexpected link in bookmarks"
1856 Buffer.add_string
bb "/>\n";
1858 Buffer.add_string
bb "</bookmarks>";
1859 if Buffer.length
kb > 0
1861 Buffer.add_string
bb "\n";
1862 Buffer.add_buffer
bb kb;
1864 Buffer.add_string
bb "\n</doc>\n";
1870 match state.mode
with
1871 | Birdseye
(c, pan, _, _, _) ->
1873 match conf.columns
with
1874 | Cmulti
((c, _, _), _) -> Some
c
1878 match c.columns
with
1879 | Cmulti
(c, _) -> Cmulti
(c, E.a
)
1880 | Csingle
_ -> Csingle
E.a
1881 | Csplit
_ -> failwith
"quit from bird's eye while split"
1883 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
1886 | LinkNav
_ -> x
, conf
1888 let docpath = if nonemptystr
state.path then abspath
state.path else E.s in
1889 if nonemptystr
docpath
1891 adddoc docpath pan (getanchor ())
1893 let autoscrollstep =
1894 match state.autoscroll
with
1896 | None
-> conf.autoscrollstep
1898 begin match state.mode
with
1899 | Birdseye beye
-> leavebirdseye beye
true
1904 { conf with autoscrollstep = autoscrollstep }
1906 (if conf.savebmarks
then state.bookmarks else [])
1910 Hashtbl.iter
(fun path (c, bookmarks, x
, anchor, origin
) ->
1911 if docpath <> abspath
path
1912 then adddoc path x
anchor c bookmarks c.lastvisit origin
1914 Buffer.add_string
bb "</llppconfig>\n";
1918 let save leavebirdseye
=
1919 let relx = float state.x
/. float state.winw
in
1921 let cx w = truncate
(relx *. float w) in
1923 (fun (w, h, x
) ws
->
1925 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
1926 | Wsi.MaxVert
-> (w, conf.cwinh
, x
)
1927 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
1929 (state.winw
, state.winh
, state.x
) state.winstate
1933 let bb = Buffer.create
32768 in
1935 save1 bb leavebirdseye x
h dc
1937 if load1 save2 && Buffer.length
bb > 0
1940 let tmp = !confpath ^
".tmp" in
1941 let oc = open_out_bin
tmp in
1942 Buffer.output_buffer
oc bb;
1944 Unix.rename
tmp !confpath;
1946 dolog
"error saving configuration: %s" @@ exntos exn
1950 let href = ref @@ Hashtbl.create
0 in
1951 let cref = ref defconf in
1954 if Sys.file_exists
path
1956 else (dolog
"removing %s" path; None
) in
1957 Hashtbl.filter_map_inplace
f h;
1962 ignore
(load1 push);
1963 let bb = Buffer.create
32768 in
1964 let save2 (_h
, dc) = save1 bb (fun _ _ -> ()) 0 !href dc in
1965 if load1 save2 && Buffer.length
bb > 0
1968 let tmp = !confpath ^
".tmp" in
1969 let oc = open_out_bin
tmp in
1970 Buffer.output_buffer
oc bb;
1972 Unix.rename
tmp !confpath;
1974 dolog
"error saving configuration: %s" @@ exntos exn
1978 let logcurrently = function
1979 | Idle
-> dolog
"Idle"
1980 | Loading
(l, gen
) ->
1981 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
1982 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col
, row
, tilew
, tileh
) ->
1984 "Tiling %d[%d,%d] page=%s cs=%s angle=%d"
1985 l.pageno col row
(~
> pageopaque
)
1986 (CSTE.to_string colorspace
) angle
;
1987 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1988 angle gen
conf.angle
state.gen
1990 conf.tilew
conf.tileh
;