3 external fz_version
: unit -> string = "ml_fz_version";;
6 { mutable fontsize
: int
7 ; mutable wwidth
: float
8 ; mutable maxrows
: int
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)
93 and params
= (angle
* fitmodel
* trimparams
94 * texcount
* sliceheight
* memsize
95 * colorspace
* fontpath
* trimcachepath
96 * haspbo
* usefontconfig
)
100 and opaque
= Opaque.t
101 and rectcolor
= (float * float * float * float)
106 and fontpath
= string
107 and trimcachepath
= string
109 and trimparams
= (trimmargins
* irect
)
110 and colorspace
= | Rgb
| Bgr
| Gray
112 and usefontconfig
= bool
119 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
123 | Ulinkgoto
of (int * int)
125 | Uunexpected
of string
126 | Ulaunch
of launchcommand
128 | Uremote
of (filename
* pageno
)
129 | Uremotedest
of (filename
* destname
)
130 | Uannotation
of (opaque
* slinkindex
)
132 and facename
= string
133 and launchcommand
= string
134 and filename
= string
136 and destname
= string
148 | LDfirstvisible
of (int * int * int)
157 and anchor
= pageno
* top
* dtop
158 and rect
= float * float * float * float * float * float * float * float
159 and infochange
= | Memused
| Docinfo
| Pdim
162 class type uioh
= object
163 method display
: unit
164 method key
: int -> int -> uioh
165 method button
: int -> bool -> int -> int -> int -> uioh
166 method multiclick
: int -> int -> int -> int -> uioh
167 method motion
: int -> int -> uioh
168 method pmotion
: int -> int -> uioh
169 method infochanged
: infochange
-> unit
170 method scrollpw
: (int * float * float)
171 method scrollph
: (int * float * float)
172 method modehash
: keyhash
173 method eformsgs
: bool
174 method alwaysscrolly
: bool
177 module type TextEnumType
=
181 val names
: string array
184 module TextEnumMake
(Ten
: TextEnumType
) =
186 let names = Ten.names;;
187 let to_int (t
: Ten.t
) = Obj.magic t
;;
188 let to_string t
= names.(to_int t
);;
189 let of_int n
: Ten.t
= Obj.magic n
;;
192 if i
= Array.length
names
193 then failwith
("invalid " ^
Ten.name ^
": " ^ s
)
202 module CSTE
= TextEnumMake
(struct
203 type t
= colorspace
;;
204 let name = "colorspace";;
205 let names = [|"rgb"; "bgr"; "gray"|];;
208 module MTE
= TextEnumMake
(struct
211 let names = [|"page"; "block"; "line"; "word"|];;
214 module FMTE
= TextEnumMake
(struct
216 let name = "fitmodel";;
217 let names = [|"width"; "proportional"; "page"|];;
221 { mutable scrollbw
: int
222 ; mutable scrollh
: int
223 ; mutable scrollb
: scrollb
224 ; mutable icase
: bool
225 ; mutable preload
: bool
226 ; mutable pagebias
: int
227 ; mutable verbose
: bool
228 ; mutable debug
: bool
229 ; mutable scrollstep
: int
230 ; mutable hscrollstep
: int
231 ; mutable maxhfit
: bool
232 ; mutable crophack
: bool
233 ; mutable autoscrollstep
: int
234 ; mutable maxwait
: float option
235 ; mutable hlinks
: bool
236 ; mutable underinfo
: bool
237 ; mutable interpagespace
: interpagespace
238 ; mutable zoom
: float
239 ; mutable presentation
: bool
240 ; mutable angle
: angle
241 ; mutable cwinw
: int
242 ; mutable cwinh
: int
243 ; mutable savebmarks
: bool
244 ; mutable fitmodel
: fitmodel
245 ; mutable trimmargins
: trimmargins
246 ; mutable trimfuzz
: irect
247 ; mutable memlimit
: memsize
248 ; mutable texcount
: texcount
249 ; mutable sliceheight
: sliceheight
250 ; mutable thumbw
: width
251 ; mutable jumpback
: bool
252 ; mutable bgcolor
: (float * float * float)
253 ; mutable bedefault
: bool
254 ; mutable tilew
: int
255 ; mutable tileh
: int
256 ; mutable mustoresize
: memsize
257 ; mutable checkers
: bool
258 ; mutable aalevel
: int
259 ; mutable urilauncher
: string
260 ; mutable pathlauncher
: string
261 ; mutable colorspace
: colorspace
262 ; mutable invert
: bool
263 ; mutable colorscale
: float
264 ; mutable ghyllscroll
: (int * int * int) option
265 ; mutable columns
: columns
266 ; mutable beyecolumns
: columncount
option
267 ; mutable selcmd
: string
268 ; mutable paxcmd
: string
269 ; mutable passcmd
: string
270 ; mutable savecmd
: string
271 ; mutable updatecurs
: bool
272 ; mutable keyhashes
: (string * keyhash
) list
273 ; mutable hfsize
: int
274 ; mutable pgscale
: float
275 ; mutable usepbo
: bool
276 ; mutable wheelbypage
: bool
277 ; mutable stcmd
: string
278 ; mutable riani
: bool
279 ; mutable pax
: (float * int * int) ref option
280 ; mutable paxmark
: mark
281 ; mutable leftscroll
: bool
282 ; mutable title
: string
283 ; mutable lastvisit
: float
284 ; mutable annotinline
: bool
287 | Csingle
of singlecolumn
288 | Cmulti
of multicolumns
289 | Csplit
of splitcolumns
294 | Olaunch
of launchcommand
295 | Oremote
of (filename
* pageno
)
296 | Oremotedest
of (filename
* destname
)
297 | Ohistory
of (filename
* conf
* outline list
* x
* anchor
* filename
)
298 and outline
= (caption
* outlinelevel
* outlinekind
)
299 and outlinelevel
= int
317 type tile
= opaque
* pixmapsize
* elapsed
318 and elapsed
= float;;
319 type pagemapkey
= pageno
* gen
;;
320 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
325 | Loading
of (page
* gen
)
327 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
329 | Outlining
of outline list
332 type mpos
= int * int
334 | Msel
of (mpos
* mpos
)
336 | Mscrolly
| Mscrollx
337 | Mzoom
of (buttonno
* step
)
338 | Mzoomrect
of (mpos
* mpos
)
345 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
346 | Textentry
of (textentry
* onleave
)
348 | LinkNav
of linktarget
349 and onleave
= leavetextentrystatus
-> unit
350 and leavetextentrystatus
= | Cancel
| Confirm
351 and helpitem
= string * int * action
354 | Action
of (uioh
-> uioh
)
356 | Ltexact
of (pageno
* direction
)
357 | Ltgendir
of direction
358 | Ltnotready
of (pageno
* direction
)
359 and direction
= int (* -1, 0, 1 *)
360 and textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
361 and onkey
= string -> int -> te
362 and ondone
= string -> unit
363 and histcancel
= unit -> unit
364 and onhist
= ((histcmd
-> string) * histcancel
)
365 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
366 and cancelonempty
= bool
371 | TEswitch
of textentry
383 { mutable ss
: Unix.file_descr
384 ; mutable wsfd
: Unix.file_descr
385 ; mutable stderr
: Unix.file_descr
386 ; mutable errmsgs
: Buffer.t
387 ; mutable newerrmsgs
: bool
391 ; mutable anchor
: anchor
392 ; mutable ranchors
: (string * string * anchor
* string) list
394 ; mutable layout
: page list
395 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
396 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
397 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
398 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
399 ; mutable pagecount
: int
400 ; mutable currently
: currently
401 ; mutable mstate
: mstate
402 ; mutable searchpattern
: string
403 ; mutable rects
: (pageno
* rectcolor
* rect
) list
404 ; mutable rects1
: (pageno
* rectcolor
* rect
) list
405 ; prects
: (pageno
, float array
) Hashtbl.t
406 ; mutable text
: string
407 ; mutable winstate
: Wsi.winstate list
408 ; mutable mode
: mode
409 ; mutable uioh
: uioh
410 ; mutable outlines
: outline array
411 ; mutable bookmarks
: outline list
412 ; mutable path
: string
413 ; mutable password
: string
414 ; mutable nameddest
: string
415 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
416 ; mutable memused
: memsize
418 ; mutable throttle
: (page list
* int * float) option
419 ; mutable autoscroll
: int option
420 ; mutable ghyll
: (int option -> unit)
421 ; mutable help
: helpitem array
422 ; mutable docinfo
: (int * string) list
423 ; mutable checkerstexid
: GlTex.texture_id
option
425 ; mutable prevzoom
: (float * int)
426 ; mutable progress
: float
427 ; mutable redisplay
: bool
428 ; mutable mpos
: mpos
429 ; mutable keystate
: keystate
430 ; mutable glinks
: bool
431 ; mutable prevcolumns
: (columns
* float) option
434 ; mutable reprf
: (unit -> unit)
435 ; mutable origin
: string
436 ; mutable roam
: (unit -> unit)
437 ; mutable bzoom
: bool
438 ; mutable traw
: [`
float] Raw.t
439 ; mutable vraw
: [`
float] Raw.t
442 { pat
: string circbuf
443 ; pag
: string circbuf
444 ; nav
: anchor circbuf
445 ; sel
: string circbuf
449 let emptyanchor = (0, 0.0, 0.0);;
450 let emptykeyhash = Hashtbl.create
0;;
452 let noreprf () = ();;
455 let nouioh : uioh
= object (self
)
457 method key _ _
= self
458 method multiclick _ _ _ _
= self
459 method button _ _ _ _ _
= self
460 method motion _ _
= self
461 method pmotion _ _
= self
462 method infochanged _
= ()
463 method scrollpw
= (0, nan
, nan
)
464 method scrollph
= (0, nan
, nan
)
465 method modehash
= emptykeyhash
466 method eformsgs
= false
467 method alwaysscrolly
= false
470 let platform_to_string = function
471 | Punknown
-> "unknown"
476 | Pcygwin
-> "Cygwin"
480 Printf.sprintf
"llpp version %s, fitz %s, ocaml %s/%d bit"
481 Help.version (fz_version
()) Sys.ocaml_version
Sys.word_size
487 ; scrollb
= scrollbhv lor scrollbvv
503 ; presentation
= false
508 ; fitmodel
= FitProportional
509 ; trimmargins
= false
510 ; trimfuzz
= (0,0,0,0)
511 ; memlimit
= 32 lsl 20
516 ; bgcolor
= (0.5, 0.5, 0.5)
520 ; mustoresize
= 256 lsl 20
525 | Plinux
| Psun
| Pbsd
-> "xdg-open \"%s\""
526 | Posx
-> "open \"%s\""
527 | Pcygwin
-> "cygstart \"%s\""
528 | Punknown
-> "echo %s")
529 ; pathlauncher
= "lp \"%s\""
532 | Plinux
| Pbsd
| Psun
-> "xsel -i"
543 ; columns
= Csingle
[||]
549 ; wheelbypage
= false
550 ; stcmd
= "echo SyncTex"
553 ; paxmark
= Mark_word
559 let mk n
= (n
, Hashtbl.create
1) in
573 let conf = { defconf with angle
= defconf.angle
};;
576 let command = Str.global_replace percentsre url
conf.urilauncher
in
577 try ignore
@@ spawn
command []
578 with exn
-> dolog
"failed to execute `%s': %s" command @@ exntos exn
582 if emptystr
conf.urilauncher
585 let url = geturl uri
in
587 then dolog
"obtained empty url from uri %S\n" uri
595 :: "(searching in this text works just by typing (i.e. no initial '/'))"
600 let url = geturl s
in
602 then (s
, 0, Action
(fun uioh
-> gotourl url; uioh
))
603 else (s
, 0, Noaction
)
608 { store
= Array.make n v
615 let cbcap b
= Array.length b
.store
;;
620 b
.wc
<- (b
.wc
+ 1) mod cap;
622 b
.len
<- min
(b
.len
+ 1) cap;
625 let cbempty b
= b
.len
= 0;;
627 let cbgetg b circular dir
=
631 let rc = b
.rc + dir
in
643 else bound
rc 0 (b
.len
-1)
649 let cbget b
= cbgetg b
false;;
650 let cbgetc b
= cbgetg b
true;;
655 ; stderr
= Unix.stderr
656 ; errmsgs
= Buffer.create
0
661 ; anchor
= emptyanchor
665 ; tilelru
= Queue.create
()
666 ; pagemap
= Hashtbl.create
10
667 ; tilemap
= Hashtbl.create
10
674 ; prects
= Hashtbl.create
1
678 ; searchpattern
= E.s
686 { nav
= cbnew 10 emptyanchor
698 ; checkerstexid
= None
699 ; prevzoom
= (1.0, 0)
713 ; traw
= Raw.create_static `
float ~len
:8
714 ; vraw
= Raw.create_static `
float ~len
:8
718 let copykeyhashes c
=
719 List.map
(fun (k
, v
) -> k
, Hashtbl.copy v
) c
.keyhashes
;
723 let d = state.winh
- h
in
724 max
conf.interpagespace
((d + 1) / 2)
727 let rowyh (c
, coverA
, coverB
) b n
=
728 if c
= 1 || (n
< coverA
|| n
>= state.pagecount
- coverB
)
730 let _, _, vy
, (_, _, h
, _) = b
.(n
) in
733 let n'
= n - coverA
in
736 let e = min
state.pagecount
(s + c
) in
737 let rec find m miny maxh
= if m
= e then miny
, maxh
else
738 let _, _, y
, (_, _, h
, _) = b
.(m
) in
739 let miny = min
miny y
in
740 let maxh = max
maxh h
in
746 let ((c
, coverA
, coverB
) as cl
), b
=
747 match conf.columns
with
748 | Csingle b
-> (1, 0, 0), b
749 | Cmulti
(c
, b
) -> c
, b
750 | Csplit
(_, b
) -> (1, 0, 0), b
752 if Array.length b
= 0
755 let rec bsearch nmin nmax
=
757 then bound nmin
0 (state.pagecount
-1)
759 let n = (nmax
+ nmin
) / 2 in
760 let vy, h
= rowyh cl b
n in
764 let ips = calcips h
in
766 let y1 = vy + h
+ ips in
770 then 0, vy + h
+ conf.interpagespace
772 let y0 = vy - conf.interpagespace
in
773 y0, y0 + h
+ conf.interpagespace
783 if n < state.pagecount
- coverB
784 then ((n-coverA
)/c
)*c
+ coverA
791 then bsearch (n+1) nmax
792 else bsearch nmin
(n-1)
795 bsearch 0 (state.pagecount
-1);
799 match conf.columns
with
800 | Cmulti
((_, _, _) as cl
, b
) ->
801 if Array.length b
> 0
803 let y, h
= rowyh cl b
(Array.length b
- 1) in
804 y + h
+ (if conf.presentation
then calcips h
else 0)
807 if Array.length b
> 0
809 let (_, _, y, (_, _, h
, _)) = 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
820 let getpageywh pageno
=
821 let pageno = bound
pageno 0 (state.pagecount
-1) in
822 match conf.columns
with
824 if Array.length b
= 0
827 let (_, _, y, (_, w
, h
, _)) = b
.(pageno) in
835 if Array.length b
= 0
838 let y, h
= rowyh cl b
pageno in
839 let (_, _, _, (_, w
, _, _)) = b
.(pageno) in
847 if Array.length b
= 0
851 let (_, _, y, (_, w
, h
, _)) = b
.(n) in
855 let getpageyh pageno =
856 let y,_,h
= getpageywh pageno in
860 let getpagedim pageno =
863 | (n, _, _, _) as pdim
:: rest
->
865 then (if n = pageno then pdim
else ppdim
)
870 f (-1, -1, -1, -1) state.pdims
873 let getpdimno pageno =
877 | (n, _, _, _) :: rest
->
879 then (if n = pageno then np else p
)
887 let getpagey pageno = fst
(getpageyh pageno);;
891 let coloff = l
.pagecol
* l
.pageh
in
892 float (l
.pagey
+ coloff) /. float l
.pageh
900 then float l
.pagedispy
/. float (calcips l
.pageh
)
901 else float l
.pagedispy
/. float conf.interpagespace
904 (l
.pageno, top, dtop)
908 match state.layout
with
909 | l
:: _ -> getanchor1 l
911 let n = page_of_y state.y in
915 let y, h
= getpageyh n in
916 let dy = y - state.y in
920 let ips = calcips h
in
921 float (dy + ips) /. float ips
923 float dy /. float conf.interpagespace
928 let fontpath = ref E.s;;
930 type historder
= [ `lastvisit
| `title
| `path
| `file
];;
933 Map.Make
(struct type t
= (int * int) let compare = compare end);;
936 let l = String.length
s in
937 let b = Buffer.create
l in
938 Parser.unent
b s 0 l;
943 try Sys.getenv
"HOME"
945 dolog
"cannot determine home directory location: %s" @@ exntos exn
;
949 let modifier_of_string = function
950 | "alt" -> Wsi.altmask
951 | "shift" -> Wsi.shiftmask
952 | "ctrl" | "control" -> Wsi.ctrlmask
953 | "meta" -> Wsi.metamask
957 let keys_of_string s =
958 let key_of_string r
s =
959 let elems = Str.full_split r
s in
962 let m1 = modifier_of_string s in
964 then (Wsi.namekey
s, m
)
967 | Str.Delim
s when n land 1 = 0 -> g s
969 | Str.Delim
_ -> (k
, m
)
971 let rec loop n k m
= function
974 let k, m
= f n k m x
in
979 let elems = Str.split whitere
s in
980 List.map
(key_of_string (Str.regexp
"-")) elems
983 let config_of c attrs
=
987 | "scroll-bar-width" -> { c
with scrollbw
= max
0 (int_of_string v
) }
988 | "scroll-handle-height" -> { c
with scrollh
= max
0 (int_of_string v
) }
989 | "case-insensitive-search" -> { c
with icase
= bool_of_string v
}
990 | "preload" -> { c
with preload
= bool_of_string v
}
991 | "page-bias" -> { c
with pagebias
= int_of_string v
}
992 | "scroll-step" -> { c
with scrollstep
= max
1 (int_of_string v
) }
993 | "horizontal-scroll-step" ->
994 { c
with hscrollstep
= max
(int_of_string v
) 1 }
995 | "auto-scroll-step" ->
996 { c
with autoscrollstep
= max
0 (int_of_string v
) }
997 | "max-height-fit" -> { c
with maxhfit
= bool_of_string v
}
998 | "crop-hack" -> { c
with crophack
= bool_of_string v
}
1001 match String.lowercase v
with
1002 | "true" -> Some infinity
1004 | f -> Some
(float_of_string
f)
1006 { c
with maxwait
= mw }
1007 | "highlight-links" -> { c
with hlinks
= bool_of_string v
}
1008 | "under-cursor-info" -> { c
with underinfo
= bool_of_string v
}
1009 | "vertical-margin" ->
1010 { c
with interpagespace
= max
0 (int_of_string v
) }
1012 let zoom = float_of_string v
/. 100. in
1013 let zoom = max
zoom 0.0 in
1014 { c
with zoom = zoom }
1015 | "presentation" -> { c
with presentation
= bool_of_string v
}
1016 | "rotation-angle" -> { c
with angle
= int_of_string v
}
1017 | "width" -> { c
with cwinw
= max
20 (int_of_string v
) }
1018 | "height" -> { c
with cwinh
= max
20 (int_of_string v
) }
1019 | "persistent-bookmarks" -> { c
with savebmarks
= bool_of_string v
}
1020 | "proportional-display" ->
1023 then FitProportional
1026 { c
with fitmodel
= fm }
1027 | "fit-model" -> { c
with fitmodel
= FMTE.of_string v
}
1028 | "pixmap-cache-size" ->
1029 { c
with memlimit
= max
2 (int_of_string_with_suffix v
) }
1030 | "tex-count" -> { c
with texcount
= max
1 (int_of_string v
) }
1031 | "slice-height" -> { c
with sliceheight
= max
2 (int_of_string v
) }
1032 | "thumbnail-width" -> { c
with thumbw
= max
2 (int_of_string v
) }
1033 | "persistent-location" -> { c
with jumpback
= bool_of_string v
}
1034 | "background-color" -> { c
with bgcolor
= color_of_string v
}
1035 | "tile-width" -> { c
with tilew
= max
2 (int_of_string v
) }
1036 | "tile-height" -> { c
with tileh
= max
2 (int_of_string v
) }
1037 | "mupdf-store-size" ->
1038 { c
with mustoresize
= max
1024 (int_of_string_with_suffix v
) }
1039 | "checkers" -> { c
with checkers
= bool_of_string v
}
1040 | "aalevel" -> { c
with aalevel
= max
0 (int_of_string v
) }
1041 | "trim-margins" -> { c
with trimmargins
= bool_of_string v
}
1042 | "trim-fuzz" -> { c
with trimfuzz
= irect_of_string v
}
1043 | "uri-launcher" -> { c
with urilauncher
= unentS v
}
1044 | "path-launcher" -> { c
with pathlauncher
= unentS v
}
1045 | "color-space" -> { c
with colorspace
= CSTE.of_string v
}
1046 | "invert-colors" -> { c
with invert
= bool_of_string v
}
1047 | "brightness" -> { c
with colorscale
= float_of_string v
}
1048 | "ghyllscroll" -> { c
with ghyllscroll
= ghyllscroll_of_string v
}
1050 let (n, _, _) as nab
= multicolumns_of_string v
in
1052 then { c
with columns
= Csplit
(-n, E.a
) }
1053 else { c
with columns
= Cmulti
(nab
, E.a
) }
1054 | "birds-eye-columns" ->
1055 { c
with beyecolumns
= Some
(max
(int_of_string v
) 2) }
1056 | "selection-command" -> { c
with selcmd
= unentS v
}
1057 | "synctex-command" -> { c
with stcmd
= unentS v
}
1058 | "pax-command" -> { c
with paxcmd
= unentS v
}
1059 | "askpass-command" -> { c
with passcmd
= unentS v
}
1060 | "savepath-command" -> { c
with savecmd
= unentS v
}
1061 | "update-cursor" -> { c
with updatecurs
= bool_of_string v
}
1062 | "hint-font-size" -> { c
with hfsize
= bound
(int_of_string v
) 5 100 }
1063 | "page-scroll-scale" -> { c
with pgscale
= float_of_string v
}
1064 | "use-pbo" -> { c
with usepbo
= bool_of_string v
}
1065 | "wheel-scrolls-pages" -> { c
with wheelbypage
= bool_of_string v
}
1066 | "horizontal-scrollbar-visible" ->
1069 then c
.scrollb
lor scrollbhv
1070 else c
.scrollb
land (lnot
scrollbhv)
1072 { c
with scrollb
= b }
1073 | "vertical-scrollbar-visible" ->
1076 then c
.scrollb
lor scrollbvv
1077 else c
.scrollb
land (lnot
scrollbvv)
1079 { c
with scrollb
= b }
1080 | "remote-in-a-new-instance" -> { c
with riani
= bool_of_string v
}
1084 then Some
(ref (0.0, 0, 0))
1086 | "point-and-x-mark" -> { c
with paxmark
= MTE.of_string v
}
1087 | "scroll-bar-on-the-left" -> { c
with leftscroll
= bool_of_string v
}
1088 | "title" -> { c
with title
= unentS v
}
1089 | "last-visit" -> { c
with lastvisit
= float_of_string v
}
1090 | "edit-annotations-inline" -> { c
with annotinline
= bool_of_string v
}
1093 dolog
"error processing attribute (`%S' = `%S'): %s" k v
@@ exntos exn
;
1096 let rec fold c
= function
1099 let c = apply c k v
in
1102 fold { c with keyhashes
= copykeyhashes c } attrs
;
1105 let fromstring f pos
n v
d =
1108 dolog
"error processing attribute (%S=%S) at %d\n%s" n v pos
@@ exntos exn
;
1112 let bookmark_of attrs
=
1113 let rec fold title page rely visy
= function
1114 | ("title", v
) :: rest
-> fold v page rely visy rest
1115 | ("page", v
) :: rest
-> fold title v rely visy rest
1116 | ("rely", v
) :: rest
-> fold title page v visy rest
1117 | ("visy", v
) :: rest
-> fold title page rely v rest
1118 | _ :: rest
-> fold title page rely visy rest
1119 | [] -> title
, page
, rely
, visy
1121 fold "invalid" "0" "0" "0" attrs
1125 let rec fold path page rely pan visy origin
= function
1126 | ("path", v
) :: rest
-> fold v page rely pan visy origin rest
1127 | ("page", v
) :: rest
-> fold path v rely pan visy origin rest
1128 | ("rely", v
) :: rest
-> fold path page v pan visy origin rest
1129 | ("pan", v
) :: rest
-> fold path page rely v visy origin rest
1130 | ("visy", v
) :: rest
-> fold path page rely pan v origin rest
1131 | ("origin", v
) :: rest
-> fold path page rely pan visy v rest
1132 | _ :: rest
-> fold path page rely pan visy origin rest
1133 | [] -> path
, page
, rely
, pan
, visy
, origin
1135 fold E.s "0" "0" "0" "0" E.s attrs
1139 let rec fold rs ls
= function
1140 | ("out", v
) :: rest
-> fold v ls rest
1141 | ("in", v
) :: rest
-> fold rs v rest
1142 | _ :: rest
-> fold ls rs rest
1148 let setconf dst src
=
1149 dst
.scrollbw
<- src
.scrollbw
;
1150 dst
.scrollh
<- src
.scrollh
;
1151 dst
.icase
<- src
.icase
;
1152 dst
.preload
<- src
.preload
;
1153 dst
.pagebias
<- src
.pagebias
;
1154 dst
.verbose
<- src
.verbose
;
1155 dst
.scrollstep
<- src
.scrollstep
;
1156 dst
.maxhfit
<- src
.maxhfit
;
1157 dst
.crophack
<- src
.crophack
;
1158 dst
.autoscrollstep
<- src
.autoscrollstep
;
1159 dst
.maxwait
<- src
.maxwait
;
1160 dst
.hlinks
<- src
.hlinks
;
1161 dst
.underinfo
<- src
.underinfo
;
1162 dst
.interpagespace
<- src
.interpagespace
;
1163 dst
.zoom <- src
.zoom;
1164 dst
.presentation
<- src
.presentation
;
1165 dst
.angle
<- src
.angle
;
1166 dst
.cwinw
<- src
.cwinw
;
1167 dst
.cwinh
<- src
.cwinh
;
1168 dst
.savebmarks
<- src
.savebmarks
;
1169 dst
.memlimit
<- src
.memlimit
;
1170 dst
.fitmodel
<- src
.fitmodel
;
1171 dst
.texcount
<- src
.texcount
;
1172 dst
.sliceheight
<- src
.sliceheight
;
1173 dst
.thumbw
<- src
.thumbw
;
1174 dst
.jumpback
<- src
.jumpback
;
1175 dst
.bgcolor
<- src
.bgcolor
;
1176 dst
.tilew
<- src
.tilew
;
1177 dst
.tileh
<- src
.tileh
;
1178 dst
.mustoresize
<- src
.mustoresize
;
1179 dst
.checkers
<- src
.checkers
;
1180 dst
.aalevel
<- src
.aalevel
;
1181 dst
.trimmargins
<- src
.trimmargins
;
1182 dst
.trimfuzz
<- src
.trimfuzz
;
1183 dst
.urilauncher
<- src
.urilauncher
;
1184 dst
.colorspace
<- src
.colorspace
;
1185 dst
.invert
<- src
.invert
;
1186 dst
.colorscale
<- src
.colorscale
;
1187 dst
.ghyllscroll
<- src
.ghyllscroll
;
1188 dst
.columns
<- src
.columns
;
1189 dst
.beyecolumns
<- src
.beyecolumns
;
1190 dst
.selcmd
<- src
.selcmd
;
1191 dst
.updatecurs
<- src
.updatecurs
;
1192 dst
.pathlauncher
<- src
.pathlauncher
;
1193 dst
.keyhashes
<- copykeyhashes src
;
1194 dst
.hfsize
<- src
.hfsize
;
1195 dst
.hscrollstep
<- src
.hscrollstep
;
1196 dst
.pgscale
<- src
.pgscale
;
1197 dst
.usepbo
<- src
.usepbo
;
1198 dst
.wheelbypage
<- src
.wheelbypage
;
1199 dst
.stcmd
<- src
.stcmd
;
1200 dst
.paxcmd
<- src
.paxcmd
;
1201 dst
.passcmd
<- src
.passcmd
;
1202 dst
.savecmd
<- src
.savecmd
;
1203 dst
.scrollb
<- src
.scrollb
;
1204 dst
.riani
<- src
.riani
;
1205 dst
.paxmark
<- src
.paxmark
;
1206 dst
.leftscroll
<- src
.leftscroll
;
1207 dst
.title
<- src
.title
;
1208 dst
.annotinline
<- src
.annotinline
;
1212 else Some
((ref (0.0, 0, 0)));
1215 let findkeyhash c name =
1216 try List.assoc
name c.keyhashes
1217 with Not_found
-> failwith
("invalid mode name `" ^
name ^
"'")
1222 let h = Hashtbl.create
10 in
1223 let dc = { defconf with angle
= defconf.angle
} in
1224 let rec toplevel v t spos
_ =
1226 | Vdata
| Vcdata
| Vend
-> v
1227 | Vopen
("llppconfig", _, closed
) ->
1230 else { v
with f = llppconfig
}
1232 error
"unexpected subelement at top level" s spos
1233 | Vclose
_ -> error
"unexpected close at top level" s spos
1235 and llppconfig v t spos
_ =
1237 | Vdata
| Vcdata
-> v
1238 | Vend
-> error
"unexpected end of input in llppconfig" s spos
1239 | Vopen
("defaults", attrs
, closed
) ->
1240 let c = config_of dc attrs
in
1244 else { v
with f = defaults
}
1246 | Vopen
("ui-font", attrs
, closed
) ->
1247 let rec getsize size
= function
1249 | ("size", v
) :: rest
->
1251 fromstring int_of_string spos
"size" v
fstate.fontsize
in
1253 | l -> getsize size l
1255 fstate.fontsize
<- getsize fstate.fontsize attrs
;
1258 else { v
with f = uifont
(Buffer.create
10) }
1260 | Vopen
("doc", attrs
, closed
) ->
1261 let pathent, spage
, srely
, span
, svisy
, origin
= doc_of attrs
in
1262 let path = unentS pathent
1263 and origin
= unentS origin
1264 and pageno = fromstring int_of_string spos
"page" spage
0
1265 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1266 and pan
= fromstring int_of_string spos
"pan" span
0
1267 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1268 let c = config_of dc attrs
in
1269 let anchor = (pageno, rely
, visy
) in
1271 then (Hashtbl.add
h path (c, [], pan
, anchor, origin
); v
)
1272 else { v
with f = doc
path origin pan
anchor c [] }
1275 error
"unexpected subelement in llppconfig" s spos
1277 | Vclose
"llppconfig" -> { v
with f = toplevel }
1278 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
1280 and defaults v t spos
_ =
1282 | Vdata
| Vcdata
-> v
1283 | Vend
-> error
"unexpected end of input in defaults" s spos
1284 | Vopen
("keymap", attrs
, closed
) ->
1286 try List.assoc
"mode" attrs
1287 with Not_found
-> "global" in
1292 let h = findkeyhash dc modename in
1293 KeyMap.iter
(Hashtbl.replace
h) keymap
;
1296 { v
with f = pkeymap
ret KeyMap.empty
}
1298 | Vopen
(_, _, _) ->
1299 error
"unexpected subelement in defaults" s spos
1301 | Vclose
"defaults" ->
1302 { v
with f = llppconfig
}
1304 | Vclose
_ -> error
"unexpected close in defaults" s spos
1306 and uifont
b v t spos epos
=
1309 Buffer.add_substring
b s spos
(epos
- spos
);
1311 | Vopen
(_, _, _) ->
1312 error
"unexpected subelement in ui-font" s spos
1313 | Vclose
"ui-font" ->
1314 if emptystr
!fontpath
1315 then fontpath := Buffer.contents
b;
1316 { v
with f = llppconfig
}
1317 | Vclose
_ -> error
"unexpected close in ui-font" s spos
1318 | Vend
-> error
"unexpected end of input in ui-font" s spos
1320 and doc
path origin pan
anchor c bookmarks v t spos
_ =
1322 | Vdata
| Vcdata
-> v
1323 | Vend
-> error
"unexpected end of input in doc" s spos
1324 | Vopen
("bookmarks", _, closed
) ->
1327 else { v
with f = pbookmarks
path origin pan
anchor c bookmarks
}
1329 | Vopen
("keymap", attrs
, closed
) ->
1331 try List.assoc
"mode" attrs
1332 with Not_found
-> "global"
1338 let h = findkeyhash c modename in
1339 KeyMap.iter
(Hashtbl.replace
h) keymap
;
1340 doc
path origin pan
anchor c bookmarks
1342 { v
with f = pkeymap
ret KeyMap.empty
}
1344 | Vopen
(_, _, _) ->
1345 error
"unexpected subelement in doc" s spos
1348 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor, origin
);
1349 { v
with f = llppconfig
}
1351 | Vclose
_ -> error
"unexpected close in doc" s spos
1353 and pkeymap
ret keymap v t spos
_ =
1355 | Vdata
| Vcdata
-> v
1356 | Vend
-> error
"unexpected end of input in keymap" s spos
1357 | Vopen
("map", attrs
, closed
) ->
1358 let r, l = map_of attrs
in
1359 let kss = fromstring keys_of_string spos
"in" r [] in
1360 let lss = fromstring keys_of_string spos
"out" l [] in
1364 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
1365 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
1368 then { v
with f = pkeymap
ret keymap }
1371 { v
with f = skip
"map" f }
1374 error
"unexpected subelement in keymap" s spos
1376 | Vclose
"keymap" ->
1377 { v
with f = ret keymap }
1379 | Vclose
_ -> error
"unexpected close in keymap" s spos
1381 and pbookmarks
path origin pan
anchor c bookmarks v t spos
_ =
1383 | Vdata
| Vcdata
-> v
1384 | Vend
-> error
"unexpected end of input in bookmarks" s spos
1385 | Vopen
("item", attrs
, closed
) ->
1386 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
1387 let page = fromstring int_of_string spos
"page" spage
0
1388 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1389 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1391 (unentS titleent, 0, Oanchor
(page, rely
, visy
)) :: bookmarks
1394 then { v
with f = pbookmarks
path origin pan
anchor c bookmarks }
1397 { v
with f = skip
"item" f }
1400 error
"unexpected subelement in bookmarks" s spos
1402 | Vclose
"bookmarks" ->
1403 { v
with f = doc
path origin pan
anchor c bookmarks }
1405 | Vclose
_ -> Parser.parse_error
"unexpected close in bookmarks" s spos
1407 and skip tag
f v t spos
_ =
1409 | Vdata
| Vcdata
-> v
1411 Parser.parse_error
("unexpected end of input in skipped " ^ tag
) s spos
1412 | Vopen
(tag'
, _, closed
) ->
1416 let f'
() = { v
with f = skip tag
f } in
1417 { v
with f = skip tag'
f'
}
1421 else Parser.parse_error
("unexpected close in skipped " ^ tag
) s spos
1424 parse
{ f = toplevel; accu
= () } s;
1428 let do_load f contents
=
1431 | Parser.Parse_error
(msg
, s, pos
) ->
1432 let subs = Parser.subs s pos
in
1433 Utils.error
"parse error: %s: at %d [..%S..]" msg pos
subs
1435 | exn
-> Utils.error
"parse error: %s" @@ exntos exn
1440 let xdgconfdir = Utils.getenvwithdef
"XDG_CONFIG_HOME" E.s in
1441 if emptystr
xdgconfdir
1444 let dir = Filename.concat
home ".config" in
1445 if Sys.is_directory
dir then dir else home
1449 Filename.concat
dir "llpp.conf"
1452 let confpath = ref defconfpath;;
1454 let load2 f default
=
1455 match filecontents
!confpath with
1456 | contents
-> f @@ do_load get contents
1457 | exception Unix.Unix_error
(Unix.ENOENT
, "open", _) ->
1458 f (Hashtbl.create
0, defconf)
1460 dolog
"error loading configuration from `%S': %s" !confpath @@ exntos exn
;
1464 let load1 f = load2 f false;;
1472 (fun path (conf, _, _, _, _) ((_, besttime
) as best
) ->
1473 if conf.lastvisit
> besttime
1474 then (path, conf.lastvisit
)
1477 (state.path, -.infinity
)
1481 let pc, pb
, px
, pa
, po
=
1483 let absname = abspath
state.path in
1484 Hashtbl.find h absname
1485 with Not_found
-> dc, [], 0, emptyanchor, state.origin
1489 state.bookmarks <- pb
;
1493 then state.anchor <- pa
;
1494 cbput state.hists
.nav pa
;
1502 Hashtbl.fold (fun path (pc, pb
, px
, pa
, po
) accu
->
1503 (path, pc, pb
, px
, pa
, po
) :: accu
)
1509 let add_attrs bb always
dc c time
=
1511 Buffer.add_string bb
"\n ";
1512 Printf.bprintf bb fmt
s
1514 let o c fmt
s = if c then o' fmt
s else ignore
in
1515 let ob s a
b = o (always
|| a
!= b) "%s='%b'" s a
1516 and op
s a
b = o (always
|| a
<> b) "%s='%b'" s (a
!= None
)
1517 and oi
s a
b = o (always
|| a
!= b) "%s='%d'" s a
1518 and oI
s a
b = o (always
|| a
!= b) "%s='%s'" s (string_with_suffix_of_int a
)
1519 and oz
s a
b = o (always
|| a
<> b) "%s='%g'" s (a
*.100.)
1520 and oF
s a
b = o (always
|| a
<> b) "%s='%f'" s a
1521 and oL
s a
b = o (always
|| a
<> b) "%s='%Ld'" s a
1522 and oc
s a
b = o (always
|| a
<> b) "%s='%s'" s (color_to_string a
)
1523 and oC
s a
b = o (always
|| a
<> b) "%s='%s'" s (CSTE.to_string a
)
1524 and oR
s a
b = o (always
|| a
<> b) "%s='%s'" s (irect_to_string a
)
1525 and oFm
s a
b = o (always
|| a
<> b) "%s='%s'" s (FMTE.to_string a
)
1526 and oSv
s a
b m
= o (always
|| a
<> b) "%s='%b'" s (a
land m
!= 0)
1527 and oPm
s a
b = o (always
|| a
<> b) "%s='%s'" s (MTE.to_string a
)
1529 o (always
|| a
<> b) "%s='%s'" s @@ Parser.enent a
0 (String.length a
)
1534 | Some
(_N
, _A
, _B
) -> o'
"%s='%u,%u,%u'" s _N _A _B
1538 | _ -> o'
"%s='none'" s
1548 else string_of_float
f
1555 | Cmulti
((n, a
, b), _) when n > 1 -> o'
"%s='%d,%d,%d'" s n a
b
1556 | Csplit
(n, _) when n > 1 -> o'
"%s='%d'" s ~
-n
1557 | Cmulti
_ | Csplit
_ | Csingle
_ -> ()
1562 | Some
c when c > 1 -> o'
"%s='%d'" s c
1565 oi
"width" c.cwinw
dc.cwinw
;
1566 oi
"height" c.cwinh
dc.cwinh
;
1567 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
1568 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
1569 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
1570 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
1571 ob "case-insensitive-search" c.icase
dc.icase
;
1572 ob "preload" c.preload
dc.preload
;
1573 oi
"page-bias" c.pagebias
dc.pagebias
;
1574 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
1575 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
1576 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
1577 ob "crop-hack" c.crophack
dc.crophack
;
1578 oW
"throttle" c.maxwait
dc.maxwait
;
1579 ob "highlight-links" c.hlinks
dc.hlinks
;
1580 ob "under-cursor-info" c.underinfo
dc.underinfo
;
1581 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
1582 oz
"zoom" c.zoom dc.zoom;
1583 ob "presentation" c.presentation
dc.presentation
;
1584 oi
"rotation-angle" c.angle
dc.angle
;
1585 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
1586 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
1587 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
1588 oi
"tex-count" c.texcount
dc.texcount
;
1589 oi
"slice-height" c.sliceheight
dc.sliceheight
;
1590 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
1591 ob "persistent-location" c.jumpback
dc.jumpback
;
1592 oc
"background-color" c.bgcolor
dc.bgcolor
;
1593 oi
"tile-width" c.tilew
dc.tilew
;
1594 oi
"tile-height" c.tileh
dc.tileh
;
1595 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
1596 ob "checkers" c.checkers
dc.checkers
;
1597 oi
"aalevel" c.aalevel
dc.aalevel
;
1598 ob "trim-margins" c.trimmargins
dc.trimmargins
;
1599 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
1600 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
1601 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
1602 oC
"color-space" c.colorspace
dc.colorspace
;
1603 ob "invert-colors" c.invert
dc.invert
;
1604 oF
"brightness" c.colorscale
dc.colorscale
;
1605 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
1606 oco
"columns" c.columns
dc.columns
;
1607 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
1608 os
"selection-command" c.selcmd
dc.selcmd
;
1609 os
"synctex-command" c.stcmd
dc.stcmd
;
1610 os
"pax-command" c.paxcmd
dc.paxcmd
;
1611 os
"askpass-command" c.passcmd
dc.passcmd
;
1612 os
"savepath-command" c.savecmd
dc.savecmd
;
1613 ob "update-cursor" c.updatecurs
dc.updatecurs
;
1614 oi
"hint-font-size" c.hfsize
dc.hfsize
;
1615 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
1616 oF
"page-scroll-scale" c.pgscale
dc.pgscale
;
1617 ob "use-pbo" c.usepbo
dc.usepbo
;
1618 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
1619 ob "remote-in-a-new-instance" c.riani
dc.riani
;
1620 op
"point-and-x" c.pax
dc.pax
;
1621 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
1622 ob "scroll-bar-on-the-left" c.leftscroll
dc.leftscroll
;
1624 then os
"title" c.title
dc.title
;
1625 oL
"last-visit" (Int64.of_float time
) 0L;
1626 ob "edit-annotations-inline" c.annotinline
dc.annotinline
;
1629 let keymapsbuf always
dc c =
1630 let bb = Buffer.create
16 in
1631 let rec loop = function
1633 | (modename, h) :: rest
->
1634 let dh = findkeyhash dc modename in
1635 if always
|| h <> dh
1637 if Hashtbl.length
h > 0
1639 if Buffer.length
bb > 0
1640 then Buffer.add_char
bb '
\n'
;
1641 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
1642 Hashtbl.iter
(fun i
o ->
1643 let isdifferent = always
||
1645 let dO = Hashtbl.find dh i
in
1647 with Not_found
-> true
1652 if Wsi.withctrl m
then Buffer.add_string
bb "ctrl-";
1653 if Wsi.withalt m
then Buffer.add_string
bb "alt-";
1654 if Wsi.withshift m
then Buffer.add_string
bb "shift-";
1655 if Wsi.withmeta m
then Buffer.add_string
bb "meta-";
1656 Buffer.add_string
bb (Wsi.keyname
k);
1659 let rec loop = function
1661 | km
:: [] -> addkm km
1662 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
1666 Buffer.add_string
bb "<map in='";
1670 Buffer.add_string
bb "' out='";
1672 Buffer.add_string
bb "'/>\n"
1675 Buffer.add_string
bb "' out='";
1677 Buffer.add_string
bb "'/>\n"
1679 | KMmulti
(ins
, kms
) ->
1680 Buffer.add_char
bb ' '
;
1682 Buffer.add_string
bb "' out='";
1684 Buffer.add_string
bb "'/>\n"
1686 Buffer.add_string
bb "</keymap>";
1695 let save1 bb leavebirdseye x
h dc =
1696 let uifontsize = fstate.fontsize
in
1697 let dc = if conf.bedefault
then conf else dc in
1698 Buffer.add_string
bb "<llppconfig>\n";
1700 if nonemptystr
!fontpath
1702 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
1708 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
1711 Buffer.add_string
bb "<defaults";
1712 add_attrs bb true dc dc nan
;
1713 let kb = keymapsbuf true dc dc in
1714 if Buffer.length
kb > 0
1716 Buffer.add_string
bb ">\n";
1717 Buffer.add_buffer
bb kb;
1718 Buffer.add_string
bb "\n</defaults>\n";
1720 else Buffer.add_string
bb "/>\n";
1722 let adddoc path pan
anchor c bookmarks time origin
=
1723 if bookmarks == [] && c = dc && anchor = emptyanchor
1726 Printf.bprintf
bb "<doc path='%s'"
1727 (Parser.enent
path 0 (String.length
path));
1729 if nonemptystr origin
1731 Printf.bprintf
bb "\n origin='%s'"
1732 (Parser.enent origin
0 (String.length origin
));
1734 if anchor <> emptyanchor
1736 let n, rely
, visy
= anchor in
1737 Printf.bprintf
bb "\n page='%d'" n;
1740 Printf.bprintf
bb " rely='%f'" rely
1742 if abs_float visy
> 1e-6
1744 Printf.bprintf
bb " visy='%f'" visy
1749 then Printf.bprintf
bb " pan='%d'" pan
;
1751 add_attrs bb false dc c time
;
1752 let kb = keymapsbuf false dc c in
1754 begin match bookmarks with
1756 if Buffer.length
kb > 0
1758 Buffer.add_string
bb ">\n";
1759 Buffer.add_buffer
bb kb;
1760 Buffer.add_string
bb "\n</doc>\n";
1762 else Buffer.add_string
bb "/>\n"
1764 Buffer.add_string
bb ">\n<bookmarks>\n";
1765 List.iter
(fun (title
, _, kind
) ->
1766 begin match kind
with
1767 | Oanchor
(page, rely
, visy
) ->
1769 "<item title='%s' page='%d'"
1770 (Parser.enent title
0 (String.length title
))
1775 Printf.bprintf
bb " rely='%f'" rely
1777 if abs_float visy
> 1e-6
1779 Printf.bprintf
bb " visy='%f'" visy
1781 | Ohistory
_ | Onone
| Ouri
_ | Oremote
_
1782 | Oremotedest
_ | Olaunch
_ ->
1783 failwith
"unexpected link in bookmarks"
1785 Buffer.add_string
bb "/>\n";
1787 Buffer.add_string
bb "</bookmarks>";
1788 if Buffer.length
kb > 0
1790 Buffer.add_string
bb "\n";
1791 Buffer.add_buffer
bb kb;
1793 Buffer.add_string
bb "\n</doc>\n";
1799 match state.mode
with
1800 | Birdseye
(c, pan, _, _, _) ->
1802 match conf.columns
with
1803 | Cmulti
((c, _, _), _) -> Some
c
1807 match c.columns
with
1808 | Cmulti
(c, _) -> Cmulti
(c, E.a
)
1809 | Csingle
_ -> Csingle
E.a
1810 | Csplit
_ -> failwith
"quit from bird's eye while split"
1812 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
1815 | LinkNav
_ -> x
, conf
1817 let docpath = if nonemptystr
state.path then abspath
state.path else E.s in
1818 if nonemptystr
docpath
1820 adddoc docpath pan (getanchor ())
1822 let autoscrollstep =
1823 match state.autoscroll
with
1825 | None
-> conf.autoscrollstep
1827 begin match state.mode
with
1828 | Birdseye beye
-> leavebirdseye beye
true
1833 { conf with autoscrollstep = autoscrollstep }
1835 (if conf.savebmarks
then state.bookmarks else [])
1839 Hashtbl.iter
(fun path (c, bookmarks, x
, anchor, origin
) ->
1840 if docpath <> abspath
path
1841 then adddoc path x
anchor c bookmarks c.lastvisit origin
1843 Buffer.add_string
bb "</llppconfig>\n";
1847 let save leavebirdseye
=
1848 let relx = float state.x
/. float state.winw
in
1850 let cx w = truncate
(relx *. float w) in
1852 (fun (w, h, x
) ws
->
1854 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
1855 | Wsi.MaxVert
-> (w, conf.cwinh
, x
)
1856 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
1858 (state.winw
, state.winh
, state.x
) state.winstate
1862 let bb = Buffer.create
32768 in
1864 save1 bb leavebirdseye x
h dc
1866 if load1 save2 && Buffer.length
bb > 0
1869 let tmp = !confpath ^
".tmp" in
1870 let oc = open_out_bin
tmp in
1871 Buffer.output_buffer
oc bb;
1873 Unix.rename
tmp !confpath;
1875 dolog
"error saving configuration: %s" @@ exntos exn
1880 (* This here has a potential of rising SIGPIPE, silently and
1881 seemingly harmlessly (when -gc was supplied an invalid
1882 executable for instance) probably needs revisiting *)
1883 let n'
= Unix.write fd
(Bytes.of_string s) 0 n in
1885 then Utils.error
"Unix.write %d = %d" n n'
1887 let href = ref (Hashtbl.create
0) in
1888 let cref = ref defconf in
1890 let f path (pc, _pb
, _px
, _pa
, _po
) =
1892 Printf.sprintf
"%s\000%ld\000" path (Int32.of_float
pc.lastvisit
)
1894 wr s (String.length
s)
1901 ignore
(load1 push);
1902 Unix.shutdown fd
Unix.SHUTDOWN_SEND
;
1903 let s = fdcontents fd
in
1905 match String.index_from
s ppos '
\000'
with
1906 | exception Not_found
-> ()
1908 match String.index_from
s (zpos1
+1) '
\000'
with
1909 | exception Not_found
-> error
"invalid gc input in (%S) at %d" s zpos1
1911 let okey = StringLabels.sub
s ~pos
:ppos ~len
:(zpos1
-ppos
) in
1912 let nkey = StringLabels.sub
s ~pos
:(zpos1
+1) ~len
:(zpos2
-zpos1
-1) in
1914 then (Hashtbl.remove
!href okey; f (zpos2
+1))
1916 match Hashtbl.find !href okey with
1917 | exception Not_found
-> Utils.error
"gc: cannot find %S" okey
1919 Hashtbl.remove
!href okey;
1920 Hashtbl.replace
!href nkey v;
1924 let bb = Buffer.create
32768 in
1925 let save2 (_h
, dc) = save1 bb (fun _ _ -> ()) 0 !href dc in
1926 if load1 save2 && Buffer.length
bb > 0
1929 let tmp = !confpath ^
".tmp" in
1930 let oc = open_out_bin
tmp in
1931 Buffer.output_buffer
oc bb;
1933 Unix.rename
tmp !confpath;
1935 dolog
"error saving configuration: %s" @@ exntos exn
1939 let logcurrently = function
1940 | Idle
-> dolog
"Idle"
1941 | Loading
(l, gen
) ->
1942 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
1943 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col
, row
, tilew
, tileh
) ->
1945 "Tiling %d[%d,%d] page=%s cs=%s angle"
1946 l.pageno col row
(~
> pageopaque
)
1947 (CSTE.to_string colorspace
)
1949 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1950 angle gen
conf.angle
state.gen
1952 conf.tilew
conf.tileh