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);;
25 let irect_of_string s
=
26 Scanf.sscanf s
"%d/%d/%d/%d" (fun x0 y0 x1 y1
-> (x0
,y0
,x1
,y1
))
29 let irect_to_string (x0
,y0
,x1
,y1
) =
30 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
33 let ghyllscroll_of_string s
=
35 | "fast" -> Some
fastghyllscroll
36 | "neat" -> Some
(10,1,9)
40 Scanf.sscanf s
"%u,%u,%u" (fun n a b
-> n
, a
, b
) in
41 if n
<= a
|| n
<= b
|| a
>= b
42 then error
"invalid ghyll N(%d),A(%d),B(%d) (N <= A, A < B, N <= B)"
47 let ghyllscroll_to_string ((n
, a
, b
) as nab
) =
48 (**) if nab
= fastghyllscroll then "fast"
49 else if nab
= neatghyllscroll then "neat"
50 else Printf.sprintf
"%d,%d,%d" n a b
;
53 let multicolumns_to_string (n
, a
, b
) =
55 then Printf.sprintf
"%d" n
56 else Printf.sprintf
"%d,%d,%d" n a b
;
59 let multicolumns_of_string s
=
61 (int_of_string s
, 0, 0)
63 Scanf.sscanf s
"%u,%u,%u" (fun n a b
->
65 then failwith
"subtly broken";
73 | KMmulti
of key list
* key list
75 and keyhash
= (key
, keymap
) Hashtbl.t
78 | KSinto
of (key list
* key list
)
79 and interpagespace
= int
80 and multicolumns
= multicol
* pagegeom
81 and singlecolumn
= pagegeom
82 and splitcolumns
= columncount
* pagegeom
83 and pagegeom
= (pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
84 and multicol
= columncount
* covercount
* covercount
88 and fitmodel
= | FitWidth
| FitProportional
| FitPage
89 and trimmargins
= bool
90 and irect
= (int * int * int * int)
95 and params
= (angle
* fitmodel
* trimparams
96 * texcount
* sliceheight
* memsize
97 * colorspace
* fontpath
* trimcachepath
98 * haspbo
* usefontconfig
)
102 and opaque
= Opaque.t
108 and fontpath
= string
109 and trimcachepath
= string
111 and trimparams
= (trimmargins
* irect
)
112 and colorspace
= | Rgb
| Bgr
| Gray
114 and usefontconfig
= bool
121 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
125 | Ulinkgoto
of (int * int)
127 | Uunexpected
of string
128 | Ulaunch
of launchcommand
130 | Uremote
of (filename
* pageno
)
131 | Uremotedest
of (filename
* destname
)
132 | Uannotation
of (opaque
* slinkindex
)
134 and facename
= string
135 and launchcommand
= string
136 and filename
= string
138 and destname
= string
150 | LDfirstvisible
of (int * int * int)
159 and anchor
= pageno
* top
* dtop
160 and rect
= float * float * float * float * float * float * float * float
161 and infochange
= | Memused
| Docinfo
| Pdim
164 class type uioh
= object
165 method display
: unit
166 method key
: int -> int -> uioh
167 method button
: int -> bool -> int -> int -> int -> uioh
168 method multiclick
: int -> int -> int -> int -> uioh
169 method motion
: int -> int -> uioh
170 method pmotion
: int -> int -> uioh
171 method infochanged
: infochange
-> unit
172 method scrollpw
: (int * float * float)
173 method scrollph
: (int * float * float)
174 method modehash
: keyhash
175 method eformsgs
: bool
176 method alwaysscrolly
: bool
179 module type TextEnumType
=
183 val names
: string array
186 module TextEnumMake
(Ten
: TextEnumType
) =
188 let names = Ten.names;;
189 let to_int (t
: Ten.t
) = Obj.magic t
;;
190 let to_string t
= names.(to_int t
);;
191 let of_int n
: Ten.t
= Obj.magic n
;;
194 if i
= Array.length
names
195 then failwith
("invalid " ^
Ten.name ^
": " ^ s
)
204 module CSTE
= TextEnumMake
(struct
205 type t
= colorspace
;;
206 let name = "colorspace";;
207 let names = [|"rgb"; "bgr"; "gray"|];;
210 module MTE
= TextEnumMake
(struct
213 let names = [|"page"; "block"; "line"; "word"|];;
216 module FMTE
= TextEnumMake
(struct
218 let name = "fitmodel";;
219 let names = [|"width"; "proportional"; "page"|];;
223 { mutable scrollbw
: int
224 ; mutable scrollh
: int
225 ; mutable scrollb
: scrollb
226 ; mutable icase
: bool
227 ; mutable preload
: bool
228 ; mutable pagebias
: int
229 ; mutable verbose
: bool
230 ; mutable debug
: bool
231 ; mutable scrollstep
: int
232 ; mutable hscrollstep
: int
233 ; mutable maxhfit
: bool
234 ; mutable crophack
: bool
235 ; mutable autoscrollstep
: int
236 ; mutable maxwait
: float option
237 ; mutable hlinks
: bool
238 ; mutable underinfo
: bool
239 ; mutable interpagespace
: interpagespace
240 ; mutable zoom
: float
241 ; mutable presentation
: bool
242 ; mutable angle
: angle
243 ; mutable cwinw
: int
244 ; mutable cwinh
: int
245 ; mutable savebmarks
: bool
246 ; mutable fitmodel
: fitmodel
247 ; mutable trimmargins
: trimmargins
248 ; mutable trimfuzz
: irect
249 ; mutable memlimit
: memsize
250 ; mutable texcount
: texcount
251 ; mutable sliceheight
: sliceheight
252 ; mutable thumbw
: width
253 ; mutable jumpback
: bool
254 ; mutable bgcolor
: (float * float * float)
255 ; mutable bedefault
: bool
256 ; mutable tilew
: int
257 ; mutable tileh
: int
258 ; mutable mustoresize
: memsize
259 ; mutable checkers
: bool
260 ; mutable aalevel
: int
261 ; mutable urilauncher
: string
262 ; mutable pathlauncher
: string
263 ; mutable colorspace
: colorspace
264 ; mutable invert
: bool
265 ; mutable colorscale
: float
266 ; mutable ghyllscroll
: (int * int * int) option
267 ; mutable columns
: columns
268 ; mutable beyecolumns
: columncount
option
269 ; mutable selcmd
: string
270 ; mutable paxcmd
: string
271 ; mutable passcmd
: string
272 ; mutable savecmd
: string
273 ; mutable updatecurs
: bool
274 ; mutable keyhashes
: (string * keyhash
) list
275 ; mutable hfsize
: int
276 ; mutable pgscale
: float
277 ; mutable usepbo
: bool
278 ; mutable wheelbypage
: bool
279 ; mutable stcmd
: string
280 ; mutable riani
: bool
281 ; mutable pax
: (float * int * int) ref option
282 ; mutable paxmark
: mark
283 ; mutable leftscroll
: bool
284 ; mutable title
: string
285 ; mutable lastvisit
: float
286 ; mutable annotinline
: bool
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 | Oaction
of (unit -> unit)
301 | Oreaction
of (unit -> outline array
)
302 and outline
= (caption
* outlinelevel
* outlinekind
)
303 and outlinelevel
= int
321 type tile
= opaque
* pixmapsize
* elapsed
322 and elapsed
= float;;
323 type pagemapkey
= pageno
* gen
;;
324 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
329 | Loading
of (page
* gen
)
331 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
333 | Outlining
of outline list
336 type mpos
= int * int
338 | Msel
of (mpos
* mpos
)
340 | Mscrolly
| Mscrollx
341 | Mzoom
of (buttonno
* step
)
342 | Mzoomrect
of (mpos
* mpos
)
349 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
350 | Textentry
of (textentry
* onleave
)
352 | LinkNav
of linktarget
353 and onleave
= leavetextentrystatus
-> unit
354 and leavetextentrystatus
= | Cancel
| Confirm
355 and helpitem
= string * int * action
358 | Action
of (uioh
-> uioh
)
360 | Ltexact
of (pageno
* direction
)
361 | Ltgendir
of direction
362 | Ltnotready
of (pageno
* direction
)
363 and direction
= int (* -1, 0, 1 *)
364 and textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
365 and onkey
= string -> int -> te
366 and ondone
= string -> unit
367 and histcancel
= unit -> unit
368 and onhist
= ((histcmd
-> string) * histcancel
)
369 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
370 and cancelonempty
= bool
375 | TEswitch
of textentry
387 { mutable ss
: Unix.file_descr
388 ; mutable wsfd
: Unix.file_descr
389 ; mutable stderr
: Unix.file_descr
390 ; mutable errmsgs
: Buffer.t
391 ; mutable newerrmsgs
: bool
395 ; mutable anchor
: anchor
396 ; mutable ranchors
: (string * string * anchor
* string) list
398 ; mutable layout
: page list
399 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
400 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
401 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
402 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
403 ; mutable pagecount
: int
404 ; mutable currently
: currently
405 ; mutable mstate
: mstate
406 ; mutable searchpattern
: string
407 ; mutable rects
: (pageno
* recttype
* rect
) list
408 ; mutable rects1
: (pageno
* recttype
* rect
) list
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
445 { pat
: string circbuf
446 ; pag
: string circbuf
447 ; nav
: anchor circbuf
448 ; sel
: string circbuf
452 let emptyanchor = (0, 0.0, 0.0);;
453 let emptykeyhash = Hashtbl.create
0;;
455 let noreprf () = ();;
458 let nouioh : uioh
= object (self
)
460 method key _ _
= self
461 method multiclick _ _ _ _
= self
462 method button _ _ _ _ _
= self
463 method motion _ _
= self
464 method pmotion _ _
= self
465 method infochanged _
= ()
466 method scrollpw
= (0, nan
, nan
)
467 method scrollph
= (0, nan
, nan
)
468 method modehash
= emptykeyhash
469 method eformsgs
= false
470 method alwaysscrolly
= false
473 let platform_to_string = function
474 | Punknown
-> "unknown"
479 | Pcygwin
-> "Cygwin"
483 Printf.sprintf
"llpp version %s, fitz %s, ocaml %s/%d bit"
484 Help.version (fz_version
()) Sys.ocaml_version
Sys.word_size
490 ; scrollb
= scrollbhv lor scrollbvv
506 ; presentation
= false
511 ; fitmodel
= FitProportional
512 ; trimmargins
= false
513 ; trimfuzz
= (0,0,0,0)
514 ; memlimit
= 32 lsl 20
519 ; bgcolor
= (0.5, 0.5, 0.5)
523 ; mustoresize
= 256 lsl 20
528 | Plinux
| Psun
| Pbsd
-> "xdg-open \"%s\""
529 | Posx
-> "open \"%s\""
530 | Pcygwin
-> "cygstart \"%s\""
531 | Punknown
-> "echo %s")
532 ; pathlauncher
= "lp \"%s\""
535 | Plinux
| Pbsd
| Psun
-> "xsel -i"
546 ; columns
= Csingle
[||]
552 ; wheelbypage
= false
553 ; stcmd
= "echo SyncTex"
556 ; paxmark
= Mark_word
562 let mk n
= (n
, Hashtbl.create
1) in
576 let conf = { defconf with angle
= defconf.angle
};;
579 if emptystr
conf.urilauncher
582 let url = geturl uri
in
584 then dolog
"obtained empty url from uri %S\n" uri
586 let command = Str.global_replace percentsre
url conf.urilauncher
in
587 try ignore
(popen
command [])
588 with exn
-> dolog
"failed to execute `%s': %s" command @@ exntos exn
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
-> gotouri 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
677 ; searchpattern
= E.s
685 { nav
= cbnew 10 emptyanchor
697 ; checkerstexid
= None
698 ; prevzoom
= (1.0, 0)
712 ; traw
= Raw.create_static `
float ~len
:8
713 ; vraw
= Raw.create_static `
float ~len
:8
717 let copykeyhashes c
=
718 List.map
(fun (k
, v
) -> k
, Hashtbl.copy v
) c
.keyhashes
;
722 let d = state.winh
- h
in
723 max
conf.interpagespace
((d + 1) / 2)
726 let rowyh (c
, coverA
, coverB
) b n
=
727 if c
= 1 || (n
< coverA
|| n
>= state.pagecount
- coverB
)
729 let _, _, vy
, (_, _, h
, _) = b
.(n
) in
732 let n'
= n - coverA
in
735 let e = min
state.pagecount
(s + c
) in
736 let rec find m miny maxh
= if m
= e then miny
, maxh
else
737 let _, _, y
, (_, _, h
, _) = b
.(m
) in
738 let miny = min
miny y
in
739 let maxh = max
maxh h
in
745 let ((c
, coverA
, coverB
) as cl
), b
=
746 match conf.columns
with
747 | Csingle b
-> (1, 0, 0), b
748 | Cmulti
(c
, b
) -> c
, b
749 | Csplit
(_, b
) -> (1, 0, 0), b
751 if Array.length b
= 0
754 let rec bsearch nmin nmax
=
756 then bound nmin
0 (state.pagecount
-1)
758 let n = (nmax
+ nmin
) / 2 in
759 let vy, h
= rowyh cl b
n in
763 let ips = calcips h
in
765 let y1 = vy + h
+ ips in
769 then 0, vy + h
+ conf.interpagespace
771 let y0 = vy - conf.interpagespace
in
772 y0, y0 + h
+ conf.interpagespace
782 if n < state.pagecount
- coverB
783 then ((n-coverA
)/c
)*c
+ coverA
790 then bsearch (n+1) nmax
791 else bsearch nmin
(n-1)
794 bsearch 0 (state.pagecount
-1);
798 match conf.columns
with
799 | Cmulti
((_, _, _) as cl
, b
) ->
800 if Array.length b
> 0
802 let y, h
= rowyh cl b
(Array.length b
- 1) in
803 y + h
+ (if conf.presentation
then calcips h
else 0)
806 if Array.length b
> 0
808 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
809 y + h
+ (if conf.presentation
then calcips h
else 0)
812 if Array.length b
> 0
814 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
819 let getpageywh pageno
=
820 let pageno = bound
pageno 0 (state.pagecount
-1) in
821 match conf.columns
with
823 if Array.length b
= 0
826 let (_, _, y, (_, w
, h
, _)) = b
.(pageno) in
834 if Array.length b
= 0
837 let y, h
= rowyh cl b
pageno in
838 let (_, _, _, (_, w
, _, _)) = b
.(pageno) in
846 if Array.length b
= 0
850 let (_, _, y, (_, w
, h
, _)) = b
.(n) in
854 let getpageyh pageno =
855 let y,_,h
= getpageywh pageno in
859 let getpagedim pageno =
862 | (n, _, _, _) as pdim
:: rest
->
864 then (if n = pageno then pdim
else ppdim
)
869 f (-1, -1, -1, -1) state.pdims
872 let getpagey pageno = fst
(getpageyh pageno);;
876 let coloff = l
.pagecol
* l
.pageh
in
877 float (l
.pagey
+ coloff) /. float l
.pageh
885 then float l
.pagedispy
/. float (calcips l
.pageh
)
886 else float l
.pagedispy
/. float conf.interpagespace
889 (l
.pageno, top, dtop)
893 match state.layout
with
894 | l
:: _ -> getanchor1 l
896 let n = page_of_y state.y in
900 let y, h
= getpageyh n in
901 let dy = y - state.y in
905 let ips = calcips h
in
906 float (dy + ips) /. float ips
908 float dy /. float conf.interpagespace
913 let fontpath = ref E.s;;
915 type historder
= [ `lastvisit
| `title
| `path
| `file
];;
918 Map.Make
(struct type t
= (int * int) let compare = compare end);;
921 let l = String.length
s in
922 let b = Buffer.create
l in
923 Parser.unent
b s 0 l;
928 try Sys.getenv
"HOME"
930 dolog
"cannot determine home directory location: %s" @@ exntos exn
;
934 let modifier_of_string = function
935 | "alt" -> Wsi.altmask
936 | "shift" -> Wsi.shiftmask
937 | "ctrl" | "control" -> Wsi.ctrlmask
938 | "meta" -> Wsi.metamask
942 let keys_of_string s =
943 let key_of_string r
s =
944 let elems = Str.full_split r
s in
947 let m1 = modifier_of_string s in
949 then (Wsi.namekey
s, m
)
952 | Str.Delim
s when n land 1 = 0 -> g s
954 | Str.Delim
_ -> (k
, m
)
956 let rec loop n k m
= function
959 let k, m
= f n k m x
in
964 let elems = Str.split whitere
s in
965 List.map
(key_of_string (Str.regexp
"-")) elems
968 let config_of c attrs
=
972 | "scroll-bar-width" -> { c
with scrollbw
= max
0 (int_of_string v
) }
973 | "scroll-handle-height" -> { c
with scrollh
= max
0 (int_of_string v
) }
974 | "case-insensitive-search" -> { c
with icase
= bool_of_string v
}
975 | "preload" -> { c
with preload
= bool_of_string v
}
976 | "page-bias" -> { c
with pagebias
= int_of_string v
}
977 | "scroll-step" -> { c
with scrollstep
= max
1 (int_of_string v
) }
978 | "horizontal-scroll-step" ->
979 { c
with hscrollstep
= max
(int_of_string v
) 1 }
980 | "auto-scroll-step" ->
981 { c
with autoscrollstep
= max
0 (int_of_string v
) }
982 | "max-height-fit" -> { c
with maxhfit
= bool_of_string v
}
983 | "crop-hack" -> { c
with crophack
= bool_of_string v
}
986 match String.lowercase v
with
987 | "true" -> Some infinity
989 | f -> Some
(float_of_string
f)
991 { c
with maxwait
= mw }
992 | "highlight-links" -> { c
with hlinks
= bool_of_string v
}
993 | "under-cursor-info" -> { c
with underinfo
= bool_of_string v
}
994 | "vertical-margin" ->
995 { c
with interpagespace
= max
0 (int_of_string v
) }
997 let zoom = float_of_string v
/. 100. in
998 let zoom = max
zoom 0.0 in
999 { c
with zoom = zoom }
1000 | "presentation" -> { c
with presentation
= bool_of_string v
}
1001 | "rotation-angle" -> { c
with angle
= int_of_string v
}
1002 | "width" -> { c
with cwinw
= max
20 (int_of_string v
) }
1003 | "height" -> { c
with cwinh
= max
20 (int_of_string v
) }
1004 | "persistent-bookmarks" -> { c
with savebmarks
= bool_of_string v
}
1005 | "proportional-display" ->
1008 then FitProportional
1011 { c
with fitmodel
= fm }
1012 | "fit-model" -> { c
with fitmodel
= FMTE.of_string v
}
1013 | "pixmap-cache-size" ->
1014 { c
with memlimit
= max
2 (int_of_string_with_suffix v
) }
1015 | "tex-count" -> { c
with texcount
= max
1 (int_of_string v
) }
1016 | "slice-height" -> { c
with sliceheight
= max
2 (int_of_string v
) }
1017 | "thumbnail-width" -> { c
with thumbw
= max
2 (int_of_string v
) }
1018 | "persistent-location" -> { c
with jumpback
= bool_of_string v
}
1019 | "background-color" -> { c
with bgcolor
= color_of_string v
}
1020 | "tile-width" -> { c
with tilew
= max
2 (int_of_string v
) }
1021 | "tile-height" -> { c
with tileh
= max
2 (int_of_string v
) }
1022 | "mupdf-store-size" ->
1023 { c
with mustoresize
= max
1024 (int_of_string_with_suffix v
) }
1024 | "checkers" -> { c
with checkers
= bool_of_string v
}
1025 | "aalevel" -> { c
with aalevel
= max
0 (int_of_string v
) }
1026 | "trim-margins" -> { c
with trimmargins
= bool_of_string v
}
1027 | "trim-fuzz" -> { c
with trimfuzz
= irect_of_string v
}
1028 | "uri-launcher" -> { c
with urilauncher
= unentS v
}
1029 | "path-launcher" -> { c
with pathlauncher
= unentS v
}
1030 | "color-space" -> { c
with colorspace
= CSTE.of_string v
}
1031 | "invert-colors" -> { c
with invert
= bool_of_string v
}
1032 | "brightness" -> { c
with colorscale
= float_of_string v
}
1033 | "ghyllscroll" -> { c
with ghyllscroll
= ghyllscroll_of_string v
}
1035 let (n, _, _) as nab
= multicolumns_of_string v
in
1037 then { c
with columns
= Csplit
(-n, E.a
) }
1038 else { c
with columns
= Cmulti
(nab
, E.a
) }
1039 | "birds-eye-columns" ->
1040 { c
with beyecolumns
= Some
(max
(int_of_string v
) 2) }
1041 | "selection-command" -> { c
with selcmd
= unentS v
}
1042 | "synctex-command" -> { c
with stcmd
= unentS v
}
1043 | "pax-command" -> { c
with paxcmd
= unentS v
}
1044 | "askpass-command" -> { c
with passcmd
= unentS v
}
1045 | "savepath-command" -> { c
with savecmd
= unentS v
}
1046 | "update-cursor" -> { c
with updatecurs
= bool_of_string v
}
1047 | "hint-font-size" -> { c
with hfsize
= bound
(int_of_string v
) 5 100 }
1048 | "page-scroll-scale" -> { c
with pgscale
= float_of_string v
}
1049 | "use-pbo" -> { c
with usepbo
= bool_of_string v
}
1050 | "wheel-scrolls-pages" -> { c
with wheelbypage
= bool_of_string v
}
1051 | "horizontal-scrollbar-visible" ->
1054 then c
.scrollb
lor scrollbhv
1055 else c
.scrollb
land (lnot
scrollbhv)
1057 { c
with scrollb
= b }
1058 | "vertical-scrollbar-visible" ->
1061 then c
.scrollb
lor scrollbvv
1062 else c
.scrollb
land (lnot
scrollbvv)
1064 { c
with scrollb
= b }
1065 | "remote-in-a-new-instance" -> { c
with riani
= bool_of_string v
}
1069 then Some
(ref (0.0, 0, 0))
1071 | "point-and-x-mark" -> { c
with paxmark
= MTE.of_string v
}
1072 | "scroll-bar-on-the-left" -> { c
with leftscroll
= bool_of_string v
}
1073 | "title" -> { c
with title
= unentS v
}
1074 | "last-visit" -> { c
with lastvisit
= float_of_string v
}
1075 | "edit-annotations-inline" -> { c
with annotinline
= bool_of_string v
}
1078 dolog
"error processing attribute (`%S' = `%S'): %s" k v
@@ exntos exn
;
1081 let rec fold c
= function
1084 let c = apply c k v
in
1087 fold { c with keyhashes
= copykeyhashes c } attrs
;
1090 let fromstring f pos
n v
d =
1093 dolog
"error processing attribute (%S=%S) at %d\n%s" n v pos
@@ exntos exn
;
1097 let bookmark_of attrs
=
1098 let rec fold title page rely visy
= function
1099 | ("title", v
) :: rest
-> fold v page rely visy rest
1100 | ("page", v
) :: rest
-> fold title v rely visy rest
1101 | ("rely", v
) :: rest
-> fold title page v visy rest
1102 | ("visy", v
) :: rest
-> fold title page rely v rest
1103 | _ :: rest
-> fold title page rely visy rest
1104 | [] -> title
, page
, rely
, visy
1106 fold "invalid" "0" "0" "0" attrs
1110 let rec fold path page rely pan visy origin
= function
1111 | ("path", v
) :: rest
-> fold v page rely pan visy origin rest
1112 | ("page", v
) :: rest
-> fold path v rely pan visy origin rest
1113 | ("rely", v
) :: rest
-> fold path page v pan visy origin rest
1114 | ("pan", v
) :: rest
-> fold path page rely v visy origin rest
1115 | ("visy", v
) :: rest
-> fold path page rely pan v origin rest
1116 | ("origin", v
) :: rest
-> fold path page rely pan visy v rest
1117 | _ :: rest
-> fold path page rely pan visy origin rest
1118 | [] -> path
, page
, rely
, pan
, visy
, origin
1120 fold E.s "0" "0" "0" "0" E.s attrs
1124 let rec fold rs ls
= function
1125 | ("out", v
) :: rest
-> fold v ls rest
1126 | ("in", v
) :: rest
-> fold rs v rest
1127 | _ :: rest
-> fold ls rs rest
1133 let setconf dst src
=
1134 dst
.scrollbw
<- src
.scrollbw
;
1135 dst
.scrollh
<- src
.scrollh
;
1136 dst
.icase
<- src
.icase
;
1137 dst
.preload
<- src
.preload
;
1138 dst
.pagebias
<- src
.pagebias
;
1139 dst
.verbose
<- src
.verbose
;
1140 dst
.scrollstep
<- src
.scrollstep
;
1141 dst
.maxhfit
<- src
.maxhfit
;
1142 dst
.crophack
<- src
.crophack
;
1143 dst
.autoscrollstep
<- src
.autoscrollstep
;
1144 dst
.maxwait
<- src
.maxwait
;
1145 dst
.hlinks
<- src
.hlinks
;
1146 dst
.underinfo
<- src
.underinfo
;
1147 dst
.interpagespace
<- src
.interpagespace
;
1148 dst
.zoom <- src
.zoom;
1149 dst
.presentation
<- src
.presentation
;
1150 dst
.angle
<- src
.angle
;
1151 dst
.cwinw
<- src
.cwinw
;
1152 dst
.cwinh
<- src
.cwinh
;
1153 dst
.savebmarks
<- src
.savebmarks
;
1154 dst
.memlimit
<- src
.memlimit
;
1155 dst
.fitmodel
<- src
.fitmodel
;
1156 dst
.texcount
<- src
.texcount
;
1157 dst
.sliceheight
<- src
.sliceheight
;
1158 dst
.thumbw
<- src
.thumbw
;
1159 dst
.jumpback
<- src
.jumpback
;
1160 dst
.bgcolor
<- src
.bgcolor
;
1161 dst
.tilew
<- src
.tilew
;
1162 dst
.tileh
<- src
.tileh
;
1163 dst
.mustoresize
<- src
.mustoresize
;
1164 dst
.checkers
<- src
.checkers
;
1165 dst
.aalevel
<- src
.aalevel
;
1166 dst
.trimmargins
<- src
.trimmargins
;
1167 dst
.trimfuzz
<- src
.trimfuzz
;
1168 dst
.urilauncher
<- src
.urilauncher
;
1169 dst
.colorspace
<- src
.colorspace
;
1170 dst
.invert
<- src
.invert
;
1171 dst
.colorscale
<- src
.colorscale
;
1172 dst
.ghyllscroll
<- src
.ghyllscroll
;
1173 dst
.columns
<- src
.columns
;
1174 dst
.beyecolumns
<- src
.beyecolumns
;
1175 dst
.selcmd
<- src
.selcmd
;
1176 dst
.updatecurs
<- src
.updatecurs
;
1177 dst
.pathlauncher
<- src
.pathlauncher
;
1178 dst
.keyhashes
<- copykeyhashes src
;
1179 dst
.hfsize
<- src
.hfsize
;
1180 dst
.hscrollstep
<- src
.hscrollstep
;
1181 dst
.pgscale
<- src
.pgscale
;
1182 dst
.usepbo
<- src
.usepbo
;
1183 dst
.wheelbypage
<- src
.wheelbypage
;
1184 dst
.stcmd
<- src
.stcmd
;
1185 dst
.paxcmd
<- src
.paxcmd
;
1186 dst
.passcmd
<- src
.passcmd
;
1187 dst
.savecmd
<- src
.savecmd
;
1188 dst
.scrollb
<- src
.scrollb
;
1189 dst
.riani
<- src
.riani
;
1190 dst
.paxmark
<- src
.paxmark
;
1191 dst
.leftscroll
<- src
.leftscroll
;
1192 dst
.title
<- src
.title
;
1193 dst
.annotinline
<- src
.annotinline
;
1197 else Some
((ref (0.0, 0, 0)));
1200 let findkeyhash c name =
1201 try List.assoc
name c.keyhashes
1202 with Not_found
-> failwith
("invalid mode name `" ^
name ^
"'")
1207 let h = Hashtbl.create
10 in
1208 let dc = { defconf with angle
= defconf.angle
} in
1209 let rec toplevel v t spos
_ =
1211 | Vdata
| Vcdata
| Vend
-> v
1212 | Vopen
("llppconfig", _, closed
) ->
1215 else { v
with f = llppconfig
}
1217 error
"unexpected subelement at top level" s spos
1218 | Vclose
_ -> error
"unexpected close at top level" s spos
1220 and llppconfig v t spos
_ =
1222 | Vdata
| Vcdata
-> v
1223 | Vend
-> error
"unexpected end of input in llppconfig" s spos
1224 | Vopen
("defaults", attrs
, closed
) ->
1225 let c = config_of dc attrs
in
1229 else { v
with f = defaults
}
1231 | Vopen
("ui-font", attrs
, closed
) ->
1232 let rec getsize size
= function
1234 | ("size", v
) :: rest
->
1236 fromstring int_of_string spos
"size" v
fstate.fontsize
in
1238 | l -> getsize size l
1240 fstate.fontsize
<- getsize fstate.fontsize attrs
;
1243 else { v
with f = uifont
(Buffer.create
10) }
1245 | Vopen
("doc", attrs
, closed
) ->
1246 let pathent, spage
, srely
, span
, svisy
, origin
= doc_of attrs
in
1247 let path = unentS pathent
1248 and origin
= unentS origin
1249 and pageno = fromstring int_of_string spos
"page" spage
0
1250 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1251 and pan
= fromstring int_of_string spos
"pan" span
0
1252 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1253 let c = config_of dc attrs
in
1254 let anchor = (pageno, rely
, visy
) in
1256 then (Hashtbl.add
h path (c, [], pan
, anchor, origin
); v
)
1257 else { v
with f = doc
path origin pan
anchor c [] }
1260 error
"unexpected subelement in llppconfig" s spos
1262 | Vclose
"llppconfig" -> { v
with f = toplevel }
1263 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
1265 and defaults v t spos
_ =
1267 | Vdata
| Vcdata
-> v
1268 | Vend
-> error
"unexpected end of input in defaults" s spos
1269 | Vopen
("keymap", attrs
, closed
) ->
1271 try List.assoc
"mode" attrs
1272 with Not_found
-> "global" in
1277 let h = findkeyhash dc modename in
1278 KeyMap.iter
(Hashtbl.replace
h) keymap
;
1281 { v
with f = pkeymap
ret KeyMap.empty
}
1283 | Vopen
(_, _, _) ->
1284 error
"unexpected subelement in defaults" s spos
1286 | Vclose
"defaults" ->
1287 { v
with f = llppconfig
}
1289 | Vclose
_ -> error
"unexpected close in defaults" s spos
1291 and uifont
b v t spos epos
=
1294 Buffer.add_substring
b s spos
(epos
- spos
);
1296 | Vopen
(_, _, _) ->
1297 error
"unexpected subelement in ui-font" s spos
1298 | Vclose
"ui-font" ->
1299 if emptystr
!fontpath
1300 then fontpath := Buffer.contents
b;
1301 { v
with f = llppconfig
}
1302 | Vclose
_ -> error
"unexpected close in ui-font" s spos
1303 | Vend
-> error
"unexpected end of input in ui-font" s spos
1305 and doc
path origin pan
anchor c bookmarks v t spos
_ =
1307 | Vdata
| Vcdata
-> v
1308 | Vend
-> error
"unexpected end of input in doc" s spos
1309 | Vopen
("bookmarks", _, closed
) ->
1312 else { v
with f = pbookmarks
path origin pan
anchor c bookmarks
}
1314 | Vopen
("keymap", attrs
, closed
) ->
1316 try List.assoc
"mode" attrs
1317 with Not_found
-> "global"
1323 let h = findkeyhash c modename in
1324 KeyMap.iter
(Hashtbl.replace
h) keymap
;
1325 doc
path origin pan
anchor c bookmarks
1327 { v
with f = pkeymap
ret KeyMap.empty
}
1329 | Vopen
(_, _, _) ->
1330 error
"unexpected subelement in doc" s spos
1333 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor, origin
);
1334 { v
with f = llppconfig
}
1336 | Vclose
_ -> error
"unexpected close in doc" s spos
1338 and pkeymap
ret keymap v t spos
_ =
1340 | Vdata
| Vcdata
-> v
1341 | Vend
-> error
"unexpected end of input in keymap" s spos
1342 | Vopen
("map", attrs
, closed
) ->
1343 let r, l = map_of attrs
in
1344 let kss = fromstring keys_of_string spos
"in" r [] in
1345 let lss = fromstring keys_of_string spos
"out" l [] in
1349 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
1350 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
1353 then { v
with f = pkeymap
ret keymap }
1356 { v
with f = skip
"map" f }
1359 error
"unexpected subelement in keymap" s spos
1361 | Vclose
"keymap" ->
1362 { v
with f = ret keymap }
1364 | Vclose
_ -> error
"unexpected close in keymap" s spos
1366 and pbookmarks
path origin pan
anchor c bookmarks v t spos
_ =
1368 | Vdata
| Vcdata
-> v
1369 | Vend
-> error
"unexpected end of input in bookmarks" s spos
1370 | Vopen
("item", attrs
, closed
) ->
1371 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
1372 let page = fromstring int_of_string spos
"page" spage
0
1373 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1374 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1376 (unentS titleent, 0, Oanchor
(page, rely
, visy
)) :: bookmarks
1379 then { v
with f = pbookmarks
path origin pan
anchor c bookmarks }
1382 { v
with f = skip
"item" f }
1385 error
"unexpected subelement in bookmarks" s spos
1387 | Vclose
"bookmarks" ->
1388 { v
with f = doc
path origin pan
anchor c bookmarks }
1390 | Vclose
_ -> Parser.parse_error
"unexpected close in bookmarks" s spos
1392 and skip tag
f v t spos
_ =
1394 | Vdata
| Vcdata
-> v
1396 Parser.parse_error
("unexpected end of input in skipped " ^ tag
) s spos
1397 | Vopen
(tag'
, _, closed
) ->
1401 let f'
() = { v
with f = skip tag
f } in
1402 { v
with f = skip tag'
f'
}
1406 else Parser.parse_error
("unexpected close in skipped " ^ tag
) s spos
1409 parse
{ f = toplevel; accu
= () } s;
1413 let do_load f contents
=
1416 | Parser.Parse_error
(msg
, s, pos
) ->
1417 let subs = Parser.subs s pos
in
1418 Utils.error
"parse error: %s: at %d [..%S..]" msg pos
subs
1420 | exn
-> Utils.error
"parse error: %s" @@ exntos exn
1425 let xdgconfdir = Utils.getenvwithdef
"XDG_CONFIG_HOME" E.s in
1426 if emptystr
xdgconfdir
1429 let dir = Filename.concat
home ".config" in
1430 if Sys.is_directory
dir then dir else home
1434 Filename.concat
dir "llpp.conf"
1437 let confpath = ref defconfpath;;
1439 let load2 f default
=
1440 match filecontents
!confpath with
1441 | contents
-> f @@ do_load get contents
1442 | exception Unix.Unix_error
(Unix.ENOENT
, "open", _) ->
1443 f (Hashtbl.create
0, defconf)
1445 dolog
"error loading configuration from `%S': %s" !confpath @@ exntos exn
;
1449 let load1 f = load2 f false;;
1457 (fun path (conf, _, _, _, _) ((_, besttime
) as best
) ->
1458 if conf.lastvisit
> besttime
1459 then (path, conf.lastvisit
)
1462 (state.path, -.infinity
)
1466 let pc, pb
, px
, pa
, po
=
1468 let absname = abspath
state.path in
1469 Hashtbl.find h absname
1470 with Not_found
-> dc, [], 0, emptyanchor, state.origin
1474 state.bookmarks <- pb
;
1478 then state.anchor <- pa
;
1479 cbput state.hists
.nav pa
;
1487 Hashtbl.fold (fun path (pc, pb
, px
, pa
, po
) accu
->
1488 (path, pc, pb
, px
, pa
, po
) :: accu
)
1494 let add_attrs bb always
dc c time
=
1496 Buffer.add_string bb
"\n ";
1497 Printf.bprintf bb fmt
s
1499 let o c fmt
s = if c then o' fmt
s else ignore
in
1500 let ob s a
b = o (always
|| a
!= b) "%s='%b'" s a
1501 and op
s a
b = o (always
|| a
<> b) "%s='%b'" s (a
!= None
)
1502 and oi
s a
b = o (always
|| a
!= b) "%s='%d'" s a
1503 and oI
s a
b = o (always
|| a
!= b) "%s='%s'" s (string_with_suffix_of_int a
)
1504 and oz
s a
b = o (always
|| a
<> b) "%s='%g'" s (a
*.100.)
1505 and oF
s a
b = o (always
|| a
<> b) "%s='%f'" s a
1506 and oL
s a
b = o (always
|| a
<> b) "%s='%Ld'" s a
1507 and oc
s a
b = o (always
|| a
<> b) "%s='%s'" s (color_to_string a
)
1508 and oC
s a
b = o (always
|| a
<> b) "%s='%s'" s (CSTE.to_string a
)
1509 and oR
s a
b = o (always
|| a
<> b) "%s='%s'" s (irect_to_string a
)
1510 and oFm
s a
b = o (always
|| a
<> b) "%s='%s'" s (FMTE.to_string a
)
1511 and oSv
s a
b m
= o (always
|| a
<> b) "%s='%b'" s (a
land m
!= 0)
1512 and oPm
s a
b = o (always
|| a
<> b) "%s='%s'" s (MTE.to_string a
)
1514 o (always
|| a
<> b) "%s='%s'" s @@ Parser.enent a
0 (String.length a
)
1519 | Some
(_N
, _A
, _B
) -> o'
"%s='%u,%u,%u'" s _N _A _B
1523 | _ -> o'
"%s='none'" s
1533 else string_of_float
f
1540 | Cmulti
((n, a
, b), _) when n > 1 -> o'
"%s='%d,%d,%d'" s n a
b
1541 | Csplit
(n, _) when n > 1 -> o'
"%s='%d'" s ~
-n
1542 | Cmulti
_ | Csplit
_ | Csingle
_ -> ()
1547 | Some
c when c > 1 -> o'
"%s='%d'" s c
1550 oi
"width" c.cwinw
dc.cwinw
;
1551 oi
"height" c.cwinh
dc.cwinh
;
1552 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
1553 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
1554 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
1555 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
1556 ob "case-insensitive-search" c.icase
dc.icase
;
1557 ob "preload" c.preload
dc.preload
;
1558 oi
"page-bias" c.pagebias
dc.pagebias
;
1559 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
1560 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
1561 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
1562 ob "crop-hack" c.crophack
dc.crophack
;
1563 oW
"throttle" c.maxwait
dc.maxwait
;
1564 ob "highlight-links" c.hlinks
dc.hlinks
;
1565 ob "under-cursor-info" c.underinfo
dc.underinfo
;
1566 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
1567 oz
"zoom" c.zoom dc.zoom;
1568 ob "presentation" c.presentation
dc.presentation
;
1569 oi
"rotation-angle" c.angle
dc.angle
;
1570 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
1571 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
1572 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
1573 oi
"tex-count" c.texcount
dc.texcount
;
1574 oi
"slice-height" c.sliceheight
dc.sliceheight
;
1575 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
1576 ob "persistent-location" c.jumpback
dc.jumpback
;
1577 oc
"background-color" c.bgcolor
dc.bgcolor
;
1578 oi
"tile-width" c.tilew
dc.tilew
;
1579 oi
"tile-height" c.tileh
dc.tileh
;
1580 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
1581 ob "checkers" c.checkers
dc.checkers
;
1582 oi
"aalevel" c.aalevel
dc.aalevel
;
1583 ob "trim-margins" c.trimmargins
dc.trimmargins
;
1584 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
1585 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
1586 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
1587 oC
"color-space" c.colorspace
dc.colorspace
;
1588 ob "invert-colors" c.invert
dc.invert
;
1589 oF
"brightness" c.colorscale
dc.colorscale
;
1590 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
1591 oco
"columns" c.columns
dc.columns
;
1592 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
1593 os
"selection-command" c.selcmd
dc.selcmd
;
1594 os
"synctex-command" c.stcmd
dc.stcmd
;
1595 os
"pax-command" c.paxcmd
dc.paxcmd
;
1596 os
"askpass-command" c.passcmd
dc.passcmd
;
1597 os
"savepath-command" c.savecmd
dc.savecmd
;
1598 ob "update-cursor" c.updatecurs
dc.updatecurs
;
1599 oi
"hint-font-size" c.hfsize
dc.hfsize
;
1600 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
1601 oF
"page-scroll-scale" c.pgscale
dc.pgscale
;
1602 ob "use-pbo" c.usepbo
dc.usepbo
;
1603 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
1604 ob "remote-in-a-new-instance" c.riani
dc.riani
;
1605 op
"point-and-x" c.pax
dc.pax
;
1606 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
1607 ob "scroll-bar-on-the-left" c.leftscroll
dc.leftscroll
;
1609 then os
"title" c.title
dc.title
;
1610 oL
"last-visit" (Int64.of_float time
) 0L;
1611 ob "edit-annotations-inline" c.annotinline
dc.annotinline
;
1614 let keymapsbuf always
dc c =
1615 let bb = Buffer.create
16 in
1616 let rec loop = function
1618 | (modename, h) :: rest
->
1619 let dh = findkeyhash dc modename in
1620 if always
|| h <> dh
1622 if Hashtbl.length
h > 0
1624 if Buffer.length
bb > 0
1625 then Buffer.add_char
bb '
\n'
;
1626 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
1627 Hashtbl.iter
(fun i
o ->
1628 let isdifferent = always
||
1630 let dO = Hashtbl.find dh i
in
1632 with Not_found
-> true
1637 if Wsi.withctrl m
then Buffer.add_string
bb "ctrl-";
1638 if Wsi.withalt m
then Buffer.add_string
bb "alt-";
1639 if Wsi.withshift m
then Buffer.add_string
bb "shift-";
1640 if Wsi.withmeta m
then Buffer.add_string
bb "meta-";
1641 Buffer.add_string
bb (Wsi.keyname
k);
1644 let rec loop = function
1646 | km
:: [] -> addkm km
1647 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
1651 Buffer.add_string
bb "<map in='";
1655 Buffer.add_string
bb "' out='";
1657 Buffer.add_string
bb "'/>\n"
1660 Buffer.add_string
bb "' out='";
1662 Buffer.add_string
bb "'/>\n"
1664 | KMmulti
(ins
, kms
) ->
1665 Buffer.add_char
bb ' '
;
1667 Buffer.add_string
bb "' out='";
1669 Buffer.add_string
bb "'/>\n"
1671 Buffer.add_string
bb "</keymap>";
1680 let save1 bb leavebirdseye x
h dc =
1681 let uifontsize = fstate.fontsize
in
1682 let dc = if conf.bedefault
then conf else dc in
1683 Buffer.add_string
bb "<llppconfig>\n";
1685 if nonemptystr
!fontpath
1687 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
1693 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
1696 Buffer.add_string
bb "<defaults";
1697 add_attrs bb true dc dc nan
;
1698 let kb = keymapsbuf true dc dc in
1699 if Buffer.length
kb > 0
1701 Buffer.add_string
bb ">\n";
1702 Buffer.add_buffer
bb kb;
1703 Buffer.add_string
bb "\n</defaults>\n";
1705 else Buffer.add_string
bb "/>\n";
1707 let adddoc path pan
anchor c bookmarks time origin
=
1708 if bookmarks == [] && c = dc && anchor = emptyanchor
1711 Printf.bprintf
bb "<doc path='%s'"
1712 (Parser.enent
path 0 (String.length
path));
1714 if nonemptystr origin
1716 Printf.bprintf
bb "\n origin='%s'"
1717 (Parser.enent origin
0 (String.length origin
));
1719 if anchor <> emptyanchor
1721 let n, rely
, visy
= anchor in
1722 Printf.bprintf
bb "\n page='%d'" n;
1725 Printf.bprintf
bb " rely='%f'" rely
1727 if abs_float visy
> 1e-6
1729 Printf.bprintf
bb " visy='%f'" visy
1734 then Printf.bprintf
bb " pan='%d'" pan
;
1736 add_attrs bb false dc c time
;
1737 let kb = keymapsbuf false dc c in
1739 begin match bookmarks with
1741 if Buffer.length
kb > 0
1743 Buffer.add_string
bb ">\n";
1744 Buffer.add_buffer
bb kb;
1745 Buffer.add_string
bb "\n</doc>\n";
1747 else Buffer.add_string
bb "/>\n"
1749 Buffer.add_string
bb ">\n<bookmarks>\n";
1750 List.iter
(fun (title
, _, kind
) ->
1751 begin match kind
with
1752 | Oanchor
(page, rely
, visy
) ->
1754 "<item title='%s' page='%d'"
1755 (Parser.enent title
0 (String.length title
))
1760 Printf.bprintf
bb " rely='%f'" rely
1762 if abs_float visy
> 1e-6
1764 Printf.bprintf
bb " visy='%f'" visy
1766 | Ohistory
_ | Onone
| Ouri
_ | Oremote
_
1767 | Oremotedest
_ | Olaunch
_ | Oaction
_ | Oreaction
_ ->
1768 failwith
"unexpected link in bookmarks"
1770 Buffer.add_string
bb "/>\n";
1772 Buffer.add_string
bb "</bookmarks>";
1773 if Buffer.length
kb > 0
1775 Buffer.add_string
bb "\n";
1776 Buffer.add_buffer
bb kb;
1778 Buffer.add_string
bb "\n</doc>\n";
1784 match state.mode
with
1785 | Birdseye
(c, pan, _, _, _) ->
1787 match conf.columns
with
1788 | Cmulti
((c, _, _), _) -> Some
c
1792 match c.columns
with
1793 | Cmulti
(c, _) -> Cmulti
(c, E.a
)
1794 | Csingle
_ -> Csingle
E.a
1795 | Csplit
_ -> failwith
"quit from bird's eye while split"
1797 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
1800 | LinkNav
_ -> x
, conf
1802 let docpath = if nonemptystr
state.path then abspath
state.path else E.s in
1803 if nonemptystr
docpath
1805 adddoc docpath pan (getanchor ())
1807 let autoscrollstep =
1808 match state.autoscroll
with
1810 | None
-> conf.autoscrollstep
1812 begin match state.mode
with
1813 | Birdseye beye
-> leavebirdseye beye
true
1818 { conf with autoscrollstep = autoscrollstep }
1820 (if conf.savebmarks
then state.bookmarks else [])
1824 Hashtbl.iter
(fun path (c, bookmarks, x
, anchor, origin
) ->
1825 if docpath <> abspath
path
1826 then adddoc path x
anchor c bookmarks c.lastvisit origin
1828 Buffer.add_string
bb "</llppconfig>\n";
1832 let save leavebirdseye
=
1833 let relx = float state.x
/. float state.winw
in
1835 let cx w = truncate
(relx *. float w) in
1837 (fun (w, h, x
) ws
->
1839 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
1840 | Wsi.MaxVert
-> (w, conf.cwinh
, x
)
1841 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
1843 (state.winw
, state.winh
, state.x
) state.winstate
1847 let bb = Buffer.create
32768 in
1849 save1 bb leavebirdseye x
h dc
1851 if load1 save2 && Buffer.length
bb > 0
1854 let tmp = !confpath ^
".tmp" in
1855 let oc = open_out_bin
tmp in
1856 Buffer.output_buffer
oc bb;
1858 Unix.rename
tmp !confpath;
1860 dolog
"error saving configuration: %s" @@ exntos exn
1865 let n'
= Unix.write fdo
(Bytes.of_string s) 0 n in
1867 then Utils.error
"Unix.write %d = %d" n n'
1870 try Unix.read fdi
s 0 n
1871 with exn
-> Utils.error
"reading gc pipe %s" @@ exntos exn
in
1872 let href = ref (Hashtbl.create
0) in
1873 let cref = ref defconf in
1875 let f path (pc, _pb
, _px
, _pa
, _po
) =
1877 Printf.sprintf
"%s\000%ld\000" path (Int32.of_float
pc.lastvisit
)
1879 wr s (String.length
s)
1884 Unix.shutdown fdo
Unix.SHUTDOWN_SEND
;
1887 ignore
(load1 push);
1889 let b = Buffer.create
32768 in
1890 let s = Bytes.create
4096 in
1892 let n = rd s (Bytes.length
s) in
1894 then Buffer.contents
b
1895 else (Buffer.add_subbytes
b s 0 n; f ())
1900 match String.index_from
s ppos '
\000'
with
1903 try String.index_from
s (zpos1
+1) '
\000'
with Not_found
-> -1 in
1905 then error
"invalid gc input in (%S) at %d" s zpos1
1907 let okey = StringLabels.sub
s ~pos
:ppos ~len
:(zpos1
-ppos
) in
1908 let nkey = StringLabels.sub
s ~pos
:(zpos1
+1) ~len
:(zpos2-zpos1
-1) in
1910 then (Hashtbl.remove
!href okey; f (zpos2+1))
1913 try Hashtbl.find !href okey
1914 with Not_found
-> Utils.error
"gc: cannot find %S" okey
1916 Hashtbl.remove
!href okey;
1917 Hashtbl.replace
!href nkey v;
1919 | exception Not_found
-> ()
1922 let bb = Buffer.create
32768 in
1923 let save2 (_h
, dc) = save1 bb (fun _ _ -> ()) 0 !href dc in
1924 if load1 save2 && Buffer.length
bb > 0
1927 let tmp = !confpath ^
".tmp" in
1928 let oc = open_out_bin
tmp in
1929 Buffer.output_buffer
oc bb;
1931 Unix.rename
tmp !confpath;
1933 dolog
"error saving configuration: %s" @@ exntos exn
1937 let logcurrently = function
1938 | Idle
-> dolog
"Idle"
1939 | Loading
(l, gen
) ->
1940 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
1941 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col
, row
, tilew
, tileh
) ->
1943 "Tiling %d[%d,%d] page=%s cs=%s angle"
1944 l.pageno col row
(~
> pageopaque
)
1945 (CSTE.to_string colorspace
)
1947 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1948 angle gen
conf.angle
state.gen
1950 conf.tilew
conf.tileh