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 let command = Str.global_replace percentsre url
conf.urilauncher
in
580 try ignore
@@ spawn
command []
581 with exn
-> dolog
"failed to execute `%s': %s" command @@ exntos exn
585 if emptystr
conf.urilauncher
588 let url = geturl uri
in
590 then dolog
"obtained empty url from uri %S\n" uri
598 :: "(searching in this text works just by typing (i.e. no initial '/'))"
603 let url = geturl s
in
605 then (s
, 0, Action
(fun uioh
-> gotourl url; uioh
))
606 else (s
, 0, Noaction
)
611 { store
= Array.make n v
618 let cbcap b
= Array.length b
.store
;;
623 b
.wc
<- (b
.wc
+ 1) mod cap;
625 b
.len
<- min
(b
.len
+ 1) cap;
628 let cbempty b
= b
.len
= 0;;
630 let cbgetg b circular dir
=
634 let rc = b
.rc + dir
in
646 else bound
rc 0 (b
.len
-1)
652 let cbget b
= cbgetg b
false;;
653 let cbgetc b
= cbgetg b
true;;
658 ; stderr
= Unix.stderr
659 ; errmsgs
= Buffer.create
0
664 ; anchor
= emptyanchor
668 ; tilelru
= Queue.create
()
669 ; pagemap
= Hashtbl.create
10
670 ; tilemap
= Hashtbl.create
10
680 ; searchpattern
= E.s
688 { nav
= cbnew 10 emptyanchor
700 ; checkerstexid
= None
701 ; prevzoom
= (1.0, 0)
715 ; traw
= Raw.create_static `
float ~len
:8
716 ; vraw
= Raw.create_static `
float ~len
:8
720 let copykeyhashes c
=
721 List.map
(fun (k
, v
) -> k
, Hashtbl.copy v
) c
.keyhashes
;
725 let d = state.winh
- h
in
726 max
conf.interpagespace
((d + 1) / 2)
729 let rowyh (c
, coverA
, coverB
) b n
=
730 if c
= 1 || (n
< coverA
|| n
>= state.pagecount
- coverB
)
732 let _, _, vy
, (_, _, h
, _) = b
.(n
) in
735 let n'
= n - coverA
in
738 let e = min
state.pagecount
(s + c
) in
739 let rec find m miny maxh
= if m
= e then miny
, maxh
else
740 let _, _, y
, (_, _, h
, _) = b
.(m
) in
741 let miny = min
miny y
in
742 let maxh = max
maxh h
in
748 let ((c
, coverA
, coverB
) as cl
), b
=
749 match conf.columns
with
750 | Csingle b
-> (1, 0, 0), b
751 | Cmulti
(c
, b
) -> c
, b
752 | Csplit
(_, b
) -> (1, 0, 0), b
754 if Array.length b
= 0
757 let rec bsearch nmin nmax
=
759 then bound nmin
0 (state.pagecount
-1)
761 let n = (nmax
+ nmin
) / 2 in
762 let vy, h
= rowyh cl b
n in
766 let ips = calcips h
in
768 let y1 = vy + h
+ ips in
772 then 0, vy + h
+ conf.interpagespace
774 let y0 = vy - conf.interpagespace
in
775 y0, y0 + h
+ conf.interpagespace
785 if n < state.pagecount
- coverB
786 then ((n-coverA
)/c
)*c
+ coverA
793 then bsearch (n+1) nmax
794 else bsearch nmin
(n-1)
797 bsearch 0 (state.pagecount
-1);
801 match conf.columns
with
802 | Cmulti
((_, _, _) as cl
, b
) ->
803 if Array.length b
> 0
805 let y, h
= rowyh cl b
(Array.length b
- 1) in
806 y + h
+ (if conf.presentation
then calcips h
else 0)
809 if Array.length b
> 0
811 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
812 y + h
+ (if conf.presentation
then calcips h
else 0)
815 if Array.length b
> 0
817 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
822 let getpageywh pageno
=
823 let pageno = bound
pageno 0 (state.pagecount
-1) in
824 match conf.columns
with
826 if Array.length b
= 0
829 let (_, _, y, (_, w
, h
, _)) = b
.(pageno) in
837 if Array.length b
= 0
840 let y, h
= rowyh cl b
pageno in
841 let (_, _, _, (_, w
, _, _)) = b
.(pageno) in
849 if Array.length b
= 0
853 let (_, _, y, (_, w
, h
, _)) = b
.(n) in
857 let getpageyh pageno =
858 let y,_,h
= getpageywh pageno in
862 let getpagedim pageno =
865 | (n, _, _, _) as pdim
:: rest
->
867 then (if n = pageno then pdim
else ppdim
)
872 f (-1, -1, -1, -1) state.pdims
875 let getpagey pageno = fst
(getpageyh pageno);;
879 let coloff = l
.pagecol
* l
.pageh
in
880 float (l
.pagey
+ coloff) /. float l
.pageh
888 then float l
.pagedispy
/. float (calcips l
.pageh
)
889 else float l
.pagedispy
/. float conf.interpagespace
892 (l
.pageno, top, dtop)
896 match state.layout
with
897 | l
:: _ -> getanchor1 l
899 let n = page_of_y state.y in
903 let y, h
= getpageyh n in
904 let dy = y - state.y in
908 let ips = calcips h
in
909 float (dy + ips) /. float ips
911 float dy /. float conf.interpagespace
916 let fontpath = ref E.s;;
918 type historder
= [ `lastvisit
| `title
| `path
| `file
];;
921 Map.Make
(struct type t
= (int * int) let compare = compare end);;
924 let l = String.length
s in
925 let b = Buffer.create
l in
926 Parser.unent
b s 0 l;
931 try Sys.getenv
"HOME"
933 dolog
"cannot determine home directory location: %s" @@ exntos exn
;
937 let modifier_of_string = function
938 | "alt" -> Wsi.altmask
939 | "shift" -> Wsi.shiftmask
940 | "ctrl" | "control" -> Wsi.ctrlmask
941 | "meta" -> Wsi.metamask
945 let keys_of_string s =
946 let key_of_string r
s =
947 let elems = Str.full_split r
s in
950 let m1 = modifier_of_string s in
952 then (Wsi.namekey
s, m
)
955 | Str.Delim
s when n land 1 = 0 -> g s
957 | Str.Delim
_ -> (k
, m
)
959 let rec loop n k m
= function
962 let k, m
= f n k m x
in
967 let elems = Str.split whitere
s in
968 List.map
(key_of_string (Str.regexp
"-")) elems
971 let config_of c attrs
=
975 | "scroll-bar-width" -> { c
with scrollbw
= max
0 (int_of_string v
) }
976 | "scroll-handle-height" -> { c
with scrollh
= max
0 (int_of_string v
) }
977 | "case-insensitive-search" -> { c
with icase
= bool_of_string v
}
978 | "preload" -> { c
with preload
= bool_of_string v
}
979 | "page-bias" -> { c
with pagebias
= int_of_string v
}
980 | "scroll-step" -> { c
with scrollstep
= max
1 (int_of_string v
) }
981 | "horizontal-scroll-step" ->
982 { c
with hscrollstep
= max
(int_of_string v
) 1 }
983 | "auto-scroll-step" ->
984 { c
with autoscrollstep
= max
0 (int_of_string v
) }
985 | "max-height-fit" -> { c
with maxhfit
= bool_of_string v
}
986 | "crop-hack" -> { c
with crophack
= bool_of_string v
}
989 match String.lowercase v
with
990 | "true" -> Some infinity
992 | f -> Some
(float_of_string
f)
994 { c
with maxwait
= mw }
995 | "highlight-links" -> { c
with hlinks
= bool_of_string v
}
996 | "under-cursor-info" -> { c
with underinfo
= bool_of_string v
}
997 | "vertical-margin" ->
998 { c
with interpagespace
= max
0 (int_of_string v
) }
1000 let zoom = float_of_string v
/. 100. in
1001 let zoom = max
zoom 0.0 in
1002 { c
with zoom = zoom }
1003 | "presentation" -> { c
with presentation
= bool_of_string v
}
1004 | "rotation-angle" -> { c
with angle
= int_of_string v
}
1005 | "width" -> { c
with cwinw
= max
20 (int_of_string v
) }
1006 | "height" -> { c
with cwinh
= max
20 (int_of_string v
) }
1007 | "persistent-bookmarks" -> { c
with savebmarks
= bool_of_string v
}
1008 | "proportional-display" ->
1011 then FitProportional
1014 { c
with fitmodel
= fm }
1015 | "fit-model" -> { c
with fitmodel
= FMTE.of_string v
}
1016 | "pixmap-cache-size" ->
1017 { c
with memlimit
= max
2 (int_of_string_with_suffix v
) }
1018 | "tex-count" -> { c
with texcount
= max
1 (int_of_string v
) }
1019 | "slice-height" -> { c
with sliceheight
= max
2 (int_of_string v
) }
1020 | "thumbnail-width" -> { c
with thumbw
= max
2 (int_of_string v
) }
1021 | "persistent-location" -> { c
with jumpback
= bool_of_string v
}
1022 | "background-color" -> { c
with bgcolor
= color_of_string v
}
1023 | "tile-width" -> { c
with tilew
= max
2 (int_of_string v
) }
1024 | "tile-height" -> { c
with tileh
= max
2 (int_of_string v
) }
1025 | "mupdf-store-size" ->
1026 { c
with mustoresize
= max
1024 (int_of_string_with_suffix v
) }
1027 | "checkers" -> { c
with checkers
= bool_of_string v
}
1028 | "aalevel" -> { c
with aalevel
= max
0 (int_of_string v
) }
1029 | "trim-margins" -> { c
with trimmargins
= bool_of_string v
}
1030 | "trim-fuzz" -> { c
with trimfuzz
= irect_of_string v
}
1031 | "uri-launcher" -> { c
with urilauncher
= unentS v
}
1032 | "path-launcher" -> { c
with pathlauncher
= unentS v
}
1033 | "color-space" -> { c
with colorspace
= CSTE.of_string v
}
1034 | "invert-colors" -> { c
with invert
= bool_of_string v
}
1035 | "brightness" -> { c
with colorscale
= float_of_string v
}
1036 | "ghyllscroll" -> { c
with ghyllscroll
= ghyllscroll_of_string v
}
1038 let (n, _, _) as nab
= multicolumns_of_string v
in
1040 then { c
with columns
= Csplit
(-n, E.a
) }
1041 else { c
with columns
= Cmulti
(nab
, E.a
) }
1042 | "birds-eye-columns" ->
1043 { c
with beyecolumns
= Some
(max
(int_of_string v
) 2) }
1044 | "selection-command" -> { c
with selcmd
= unentS v
}
1045 | "synctex-command" -> { c
with stcmd
= unentS v
}
1046 | "pax-command" -> { c
with paxcmd
= unentS v
}
1047 | "askpass-command" -> { c
with passcmd
= unentS v
}
1048 | "savepath-command" -> { c
with savecmd
= unentS v
}
1049 | "update-cursor" -> { c
with updatecurs
= bool_of_string v
}
1050 | "hint-font-size" -> { c
with hfsize
= bound
(int_of_string v
) 5 100 }
1051 | "page-scroll-scale" -> { c
with pgscale
= float_of_string v
}
1052 | "use-pbo" -> { c
with usepbo
= bool_of_string v
}
1053 | "wheel-scrolls-pages" -> { c
with wheelbypage
= bool_of_string v
}
1054 | "horizontal-scrollbar-visible" ->
1057 then c
.scrollb
lor scrollbhv
1058 else c
.scrollb
land (lnot
scrollbhv)
1060 { c
with scrollb
= b }
1061 | "vertical-scrollbar-visible" ->
1064 then c
.scrollb
lor scrollbvv
1065 else c
.scrollb
land (lnot
scrollbvv)
1067 { c
with scrollb
= b }
1068 | "remote-in-a-new-instance" -> { c
with riani
= bool_of_string v
}
1072 then Some
(ref (0.0, 0, 0))
1074 | "point-and-x-mark" -> { c
with paxmark
= MTE.of_string v
}
1075 | "scroll-bar-on-the-left" -> { c
with leftscroll
= bool_of_string v
}
1076 | "title" -> { c
with title
= unentS v
}
1077 | "last-visit" -> { c
with lastvisit
= float_of_string v
}
1078 | "edit-annotations-inline" -> { c
with annotinline
= bool_of_string v
}
1081 dolog
"error processing attribute (`%S' = `%S'): %s" k v
@@ exntos exn
;
1084 let rec fold c
= function
1087 let c = apply c k v
in
1090 fold { c with keyhashes
= copykeyhashes c } attrs
;
1093 let fromstring f pos
n v
d =
1096 dolog
"error processing attribute (%S=%S) at %d\n%s" n v pos
@@ exntos exn
;
1100 let bookmark_of attrs
=
1101 let rec fold title page rely visy
= function
1102 | ("title", v
) :: rest
-> fold v page rely visy rest
1103 | ("page", v
) :: rest
-> fold title v rely visy rest
1104 | ("rely", v
) :: rest
-> fold title page v visy rest
1105 | ("visy", v
) :: rest
-> fold title page rely v rest
1106 | _ :: rest
-> fold title page rely visy rest
1107 | [] -> title
, page
, rely
, visy
1109 fold "invalid" "0" "0" "0" attrs
1113 let rec fold path page rely pan visy origin
= function
1114 | ("path", v
) :: rest
-> fold v page rely pan visy origin rest
1115 | ("page", v
) :: rest
-> fold path v rely pan visy origin rest
1116 | ("rely", v
) :: rest
-> fold path page v pan visy origin rest
1117 | ("pan", v
) :: rest
-> fold path page rely v visy origin rest
1118 | ("visy", v
) :: rest
-> fold path page rely pan v origin rest
1119 | ("origin", v
) :: rest
-> fold path page rely pan visy v rest
1120 | _ :: rest
-> fold path page rely pan visy origin rest
1121 | [] -> path
, page
, rely
, pan
, visy
, origin
1123 fold E.s "0" "0" "0" "0" E.s attrs
1127 let rec fold rs ls
= function
1128 | ("out", v
) :: rest
-> fold v ls rest
1129 | ("in", v
) :: rest
-> fold rs v rest
1130 | _ :: rest
-> fold ls rs rest
1136 let setconf dst src
=
1137 dst
.scrollbw
<- src
.scrollbw
;
1138 dst
.scrollh
<- src
.scrollh
;
1139 dst
.icase
<- src
.icase
;
1140 dst
.preload
<- src
.preload
;
1141 dst
.pagebias
<- src
.pagebias
;
1142 dst
.verbose
<- src
.verbose
;
1143 dst
.scrollstep
<- src
.scrollstep
;
1144 dst
.maxhfit
<- src
.maxhfit
;
1145 dst
.crophack
<- src
.crophack
;
1146 dst
.autoscrollstep
<- src
.autoscrollstep
;
1147 dst
.maxwait
<- src
.maxwait
;
1148 dst
.hlinks
<- src
.hlinks
;
1149 dst
.underinfo
<- src
.underinfo
;
1150 dst
.interpagespace
<- src
.interpagespace
;
1151 dst
.zoom <- src
.zoom;
1152 dst
.presentation
<- src
.presentation
;
1153 dst
.angle
<- src
.angle
;
1154 dst
.cwinw
<- src
.cwinw
;
1155 dst
.cwinh
<- src
.cwinh
;
1156 dst
.savebmarks
<- src
.savebmarks
;
1157 dst
.memlimit
<- src
.memlimit
;
1158 dst
.fitmodel
<- src
.fitmodel
;
1159 dst
.texcount
<- src
.texcount
;
1160 dst
.sliceheight
<- src
.sliceheight
;
1161 dst
.thumbw
<- src
.thumbw
;
1162 dst
.jumpback
<- src
.jumpback
;
1163 dst
.bgcolor
<- src
.bgcolor
;
1164 dst
.tilew
<- src
.tilew
;
1165 dst
.tileh
<- src
.tileh
;
1166 dst
.mustoresize
<- src
.mustoresize
;
1167 dst
.checkers
<- src
.checkers
;
1168 dst
.aalevel
<- src
.aalevel
;
1169 dst
.trimmargins
<- src
.trimmargins
;
1170 dst
.trimfuzz
<- src
.trimfuzz
;
1171 dst
.urilauncher
<- src
.urilauncher
;
1172 dst
.colorspace
<- src
.colorspace
;
1173 dst
.invert
<- src
.invert
;
1174 dst
.colorscale
<- src
.colorscale
;
1175 dst
.ghyllscroll
<- src
.ghyllscroll
;
1176 dst
.columns
<- src
.columns
;
1177 dst
.beyecolumns
<- src
.beyecolumns
;
1178 dst
.selcmd
<- src
.selcmd
;
1179 dst
.updatecurs
<- src
.updatecurs
;
1180 dst
.pathlauncher
<- src
.pathlauncher
;
1181 dst
.keyhashes
<- copykeyhashes src
;
1182 dst
.hfsize
<- src
.hfsize
;
1183 dst
.hscrollstep
<- src
.hscrollstep
;
1184 dst
.pgscale
<- src
.pgscale
;
1185 dst
.usepbo
<- src
.usepbo
;
1186 dst
.wheelbypage
<- src
.wheelbypage
;
1187 dst
.stcmd
<- src
.stcmd
;
1188 dst
.paxcmd
<- src
.paxcmd
;
1189 dst
.passcmd
<- src
.passcmd
;
1190 dst
.savecmd
<- src
.savecmd
;
1191 dst
.scrollb
<- src
.scrollb
;
1192 dst
.riani
<- src
.riani
;
1193 dst
.paxmark
<- src
.paxmark
;
1194 dst
.leftscroll
<- src
.leftscroll
;
1195 dst
.title
<- src
.title
;
1196 dst
.annotinline
<- src
.annotinline
;
1200 else Some
((ref (0.0, 0, 0)));
1203 let findkeyhash c name =
1204 try List.assoc
name c.keyhashes
1205 with Not_found
-> failwith
("invalid mode name `" ^
name ^
"'")
1210 let h = Hashtbl.create
10 in
1211 let dc = { defconf with angle
= defconf.angle
} in
1212 let rec toplevel v t spos
_ =
1214 | Vdata
| Vcdata
| Vend
-> v
1215 | Vopen
("llppconfig", _, closed
) ->
1218 else { v
with f = llppconfig
}
1220 error
"unexpected subelement at top level" s spos
1221 | Vclose
_ -> error
"unexpected close at top level" s spos
1223 and llppconfig v t spos
_ =
1225 | Vdata
| Vcdata
-> v
1226 | Vend
-> error
"unexpected end of input in llppconfig" s spos
1227 | Vopen
("defaults", attrs
, closed
) ->
1228 let c = config_of dc attrs
in
1232 else { v
with f = defaults
}
1234 | Vopen
("ui-font", attrs
, closed
) ->
1235 let rec getsize size
= function
1237 | ("size", v
) :: rest
->
1239 fromstring int_of_string spos
"size" v
fstate.fontsize
in
1241 | l -> getsize size l
1243 fstate.fontsize
<- getsize fstate.fontsize attrs
;
1246 else { v
with f = uifont
(Buffer.create
10) }
1248 | Vopen
("doc", attrs
, closed
) ->
1249 let pathent, spage
, srely
, span
, svisy
, origin
= doc_of attrs
in
1250 let path = unentS pathent
1251 and origin
= unentS origin
1252 and pageno = fromstring int_of_string spos
"page" spage
0
1253 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1254 and pan
= fromstring int_of_string spos
"pan" span
0
1255 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1256 let c = config_of dc attrs
in
1257 let anchor = (pageno, rely
, visy
) in
1259 then (Hashtbl.add
h path (c, [], pan
, anchor, origin
); v
)
1260 else { v
with f = doc
path origin pan
anchor c [] }
1263 error
"unexpected subelement in llppconfig" s spos
1265 | Vclose
"llppconfig" -> { v
with f = toplevel }
1266 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
1268 and defaults v t spos
_ =
1270 | Vdata
| Vcdata
-> v
1271 | Vend
-> error
"unexpected end of input in defaults" s spos
1272 | Vopen
("keymap", attrs
, closed
) ->
1274 try List.assoc
"mode" attrs
1275 with Not_found
-> "global" in
1280 let h = findkeyhash dc modename in
1281 KeyMap.iter
(Hashtbl.replace
h) keymap
;
1284 { v
with f = pkeymap
ret KeyMap.empty
}
1286 | Vopen
(_, _, _) ->
1287 error
"unexpected subelement in defaults" s spos
1289 | Vclose
"defaults" ->
1290 { v
with f = llppconfig
}
1292 | Vclose
_ -> error
"unexpected close in defaults" s spos
1294 and uifont
b v t spos epos
=
1297 Buffer.add_substring
b s spos
(epos
- spos
);
1299 | Vopen
(_, _, _) ->
1300 error
"unexpected subelement in ui-font" s spos
1301 | Vclose
"ui-font" ->
1302 if emptystr
!fontpath
1303 then fontpath := Buffer.contents
b;
1304 { v
with f = llppconfig
}
1305 | Vclose
_ -> error
"unexpected close in ui-font" s spos
1306 | Vend
-> error
"unexpected end of input in ui-font" s spos
1308 and doc
path origin pan
anchor c bookmarks v t spos
_ =
1310 | Vdata
| Vcdata
-> v
1311 | Vend
-> error
"unexpected end of input in doc" s spos
1312 | Vopen
("bookmarks", _, closed
) ->
1315 else { v
with f = pbookmarks
path origin pan
anchor c bookmarks
}
1317 | Vopen
("keymap", attrs
, closed
) ->
1319 try List.assoc
"mode" attrs
1320 with Not_found
-> "global"
1326 let h = findkeyhash c modename in
1327 KeyMap.iter
(Hashtbl.replace
h) keymap
;
1328 doc
path origin pan
anchor c bookmarks
1330 { v
with f = pkeymap
ret KeyMap.empty
}
1332 | Vopen
(_, _, _) ->
1333 error
"unexpected subelement in doc" s spos
1336 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor, origin
);
1337 { v
with f = llppconfig
}
1339 | Vclose
_ -> error
"unexpected close in doc" s spos
1341 and pkeymap
ret keymap v t spos
_ =
1343 | Vdata
| Vcdata
-> v
1344 | Vend
-> error
"unexpected end of input in keymap" s spos
1345 | Vopen
("map", attrs
, closed
) ->
1346 let r, l = map_of attrs
in
1347 let kss = fromstring keys_of_string spos
"in" r [] in
1348 let lss = fromstring keys_of_string spos
"out" l [] in
1352 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
1353 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
1356 then { v
with f = pkeymap
ret keymap }
1359 { v
with f = skip
"map" f }
1362 error
"unexpected subelement in keymap" s spos
1364 | Vclose
"keymap" ->
1365 { v
with f = ret keymap }
1367 | Vclose
_ -> error
"unexpected close in keymap" s spos
1369 and pbookmarks
path origin pan
anchor c bookmarks v t spos
_ =
1371 | Vdata
| Vcdata
-> v
1372 | Vend
-> error
"unexpected end of input in bookmarks" s spos
1373 | Vopen
("item", attrs
, closed
) ->
1374 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
1375 let page = fromstring int_of_string spos
"page" spage
0
1376 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1377 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1379 (unentS titleent, 0, Oanchor
(page, rely
, visy
)) :: bookmarks
1382 then { v
with f = pbookmarks
path origin pan
anchor c bookmarks }
1385 { v
with f = skip
"item" f }
1388 error
"unexpected subelement in bookmarks" s spos
1390 | Vclose
"bookmarks" ->
1391 { v
with f = doc
path origin pan
anchor c bookmarks }
1393 | Vclose
_ -> Parser.parse_error
"unexpected close in bookmarks" s spos
1395 and skip tag
f v t spos
_ =
1397 | Vdata
| Vcdata
-> v
1399 Parser.parse_error
("unexpected end of input in skipped " ^ tag
) s spos
1400 | Vopen
(tag'
, _, closed
) ->
1404 let f'
() = { v
with f = skip tag
f } in
1405 { v
with f = skip tag'
f'
}
1409 else Parser.parse_error
("unexpected close in skipped " ^ tag
) s spos
1412 parse
{ f = toplevel; accu
= () } s;
1416 let do_load f contents
=
1419 | Parser.Parse_error
(msg
, s, pos
) ->
1420 let subs = Parser.subs s pos
in
1421 Utils.error
"parse error: %s: at %d [..%S..]" msg pos
subs
1423 | exn
-> Utils.error
"parse error: %s" @@ exntos exn
1428 let xdgconfdir = Utils.getenvwithdef
"XDG_CONFIG_HOME" E.s in
1429 if emptystr
xdgconfdir
1432 let dir = Filename.concat
home ".config" in
1433 if Sys.is_directory
dir then dir else home
1437 Filename.concat
dir "llpp.conf"
1440 let confpath = ref defconfpath;;
1442 let load2 f default
=
1443 match filecontents
!confpath with
1444 | contents
-> f @@ do_load get contents
1445 | exception Unix.Unix_error
(Unix.ENOENT
, "open", _) ->
1446 f (Hashtbl.create
0, defconf)
1448 dolog
"error loading configuration from `%S': %s" !confpath @@ exntos exn
;
1452 let load1 f = load2 f false;;
1460 (fun path (conf, _, _, _, _) ((_, besttime
) as best
) ->
1461 if conf.lastvisit
> besttime
1462 then (path, conf.lastvisit
)
1465 (state.path, -.infinity
)
1469 let pc, pb
, px
, pa
, po
=
1471 let absname = abspath
state.path in
1472 Hashtbl.find h absname
1473 with Not_found
-> dc, [], 0, emptyanchor, state.origin
1477 state.bookmarks <- pb
;
1481 then state.anchor <- pa
;
1482 cbput state.hists
.nav pa
;
1490 Hashtbl.fold (fun path (pc, pb
, px
, pa
, po
) accu
->
1491 (path, pc, pb
, px
, pa
, po
) :: accu
)
1497 let add_attrs bb always
dc c time
=
1499 Buffer.add_string bb
"\n ";
1500 Printf.bprintf bb fmt
s
1502 let o c fmt
s = if c then o' fmt
s else ignore
in
1503 let ob s a
b = o (always
|| a
!= b) "%s='%b'" s a
1504 and op
s a
b = o (always
|| a
<> b) "%s='%b'" s (a
!= None
)
1505 and oi
s a
b = o (always
|| a
!= b) "%s='%d'" s a
1506 and oI
s a
b = o (always
|| a
!= b) "%s='%s'" s (string_with_suffix_of_int a
)
1507 and oz
s a
b = o (always
|| a
<> b) "%s='%g'" s (a
*.100.)
1508 and oF
s a
b = o (always
|| a
<> b) "%s='%f'" s a
1509 and oL
s a
b = o (always
|| a
<> b) "%s='%Ld'" s a
1510 and oc
s a
b = o (always
|| a
<> b) "%s='%s'" s (color_to_string a
)
1511 and oC
s a
b = o (always
|| a
<> b) "%s='%s'" s (CSTE.to_string a
)
1512 and oR
s a
b = o (always
|| a
<> b) "%s='%s'" s (irect_to_string a
)
1513 and oFm
s a
b = o (always
|| a
<> b) "%s='%s'" s (FMTE.to_string a
)
1514 and oSv
s a
b m
= o (always
|| a
<> b) "%s='%b'" s (a
land m
!= 0)
1515 and oPm
s a
b = o (always
|| a
<> b) "%s='%s'" s (MTE.to_string a
)
1517 o (always
|| a
<> b) "%s='%s'" s @@ Parser.enent a
0 (String.length a
)
1522 | Some
(_N
, _A
, _B
) -> o'
"%s='%u,%u,%u'" s _N _A _B
1526 | _ -> o'
"%s='none'" s
1536 else string_of_float
f
1543 | Cmulti
((n, a
, b), _) when n > 1 -> o'
"%s='%d,%d,%d'" s n a
b
1544 | Csplit
(n, _) when n > 1 -> o'
"%s='%d'" s ~
-n
1545 | Cmulti
_ | Csplit
_ | Csingle
_ -> ()
1550 | Some
c when c > 1 -> o'
"%s='%d'" s c
1553 oi
"width" c.cwinw
dc.cwinw
;
1554 oi
"height" c.cwinh
dc.cwinh
;
1555 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
1556 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
1557 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
1558 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
1559 ob "case-insensitive-search" c.icase
dc.icase
;
1560 ob "preload" c.preload
dc.preload
;
1561 oi
"page-bias" c.pagebias
dc.pagebias
;
1562 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
1563 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
1564 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
1565 ob "crop-hack" c.crophack
dc.crophack
;
1566 oW
"throttle" c.maxwait
dc.maxwait
;
1567 ob "highlight-links" c.hlinks
dc.hlinks
;
1568 ob "under-cursor-info" c.underinfo
dc.underinfo
;
1569 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
1570 oz
"zoom" c.zoom dc.zoom;
1571 ob "presentation" c.presentation
dc.presentation
;
1572 oi
"rotation-angle" c.angle
dc.angle
;
1573 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
1574 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
1575 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
1576 oi
"tex-count" c.texcount
dc.texcount
;
1577 oi
"slice-height" c.sliceheight
dc.sliceheight
;
1578 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
1579 ob "persistent-location" c.jumpback
dc.jumpback
;
1580 oc
"background-color" c.bgcolor
dc.bgcolor
;
1581 oi
"tile-width" c.tilew
dc.tilew
;
1582 oi
"tile-height" c.tileh
dc.tileh
;
1583 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
1584 ob "checkers" c.checkers
dc.checkers
;
1585 oi
"aalevel" c.aalevel
dc.aalevel
;
1586 ob "trim-margins" c.trimmargins
dc.trimmargins
;
1587 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
1588 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
1589 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
1590 oC
"color-space" c.colorspace
dc.colorspace
;
1591 ob "invert-colors" c.invert
dc.invert
;
1592 oF
"brightness" c.colorscale
dc.colorscale
;
1593 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
1594 oco
"columns" c.columns
dc.columns
;
1595 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
1596 os
"selection-command" c.selcmd
dc.selcmd
;
1597 os
"synctex-command" c.stcmd
dc.stcmd
;
1598 os
"pax-command" c.paxcmd
dc.paxcmd
;
1599 os
"askpass-command" c.passcmd
dc.passcmd
;
1600 os
"savepath-command" c.savecmd
dc.savecmd
;
1601 ob "update-cursor" c.updatecurs
dc.updatecurs
;
1602 oi
"hint-font-size" c.hfsize
dc.hfsize
;
1603 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
1604 oF
"page-scroll-scale" c.pgscale
dc.pgscale
;
1605 ob "use-pbo" c.usepbo
dc.usepbo
;
1606 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
1607 ob "remote-in-a-new-instance" c.riani
dc.riani
;
1608 op
"point-and-x" c.pax
dc.pax
;
1609 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
1610 ob "scroll-bar-on-the-left" c.leftscroll
dc.leftscroll
;
1612 then os
"title" c.title
dc.title
;
1613 oL
"last-visit" (Int64.of_float time
) 0L;
1614 ob "edit-annotations-inline" c.annotinline
dc.annotinline
;
1617 let keymapsbuf always
dc c =
1618 let bb = Buffer.create
16 in
1619 let rec loop = function
1621 | (modename, h) :: rest
->
1622 let dh = findkeyhash dc modename in
1623 if always
|| h <> dh
1625 if Hashtbl.length
h > 0
1627 if Buffer.length
bb > 0
1628 then Buffer.add_char
bb '
\n'
;
1629 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
1630 Hashtbl.iter
(fun i
o ->
1631 let isdifferent = always
||
1633 let dO = Hashtbl.find dh i
in
1635 with Not_found
-> true
1640 if Wsi.withctrl m
then Buffer.add_string
bb "ctrl-";
1641 if Wsi.withalt m
then Buffer.add_string
bb "alt-";
1642 if Wsi.withshift m
then Buffer.add_string
bb "shift-";
1643 if Wsi.withmeta m
then Buffer.add_string
bb "meta-";
1644 Buffer.add_string
bb (Wsi.keyname
k);
1647 let rec loop = function
1649 | km
:: [] -> addkm km
1650 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
1654 Buffer.add_string
bb "<map in='";
1658 Buffer.add_string
bb "' out='";
1660 Buffer.add_string
bb "'/>\n"
1663 Buffer.add_string
bb "' out='";
1665 Buffer.add_string
bb "'/>\n"
1667 | KMmulti
(ins
, kms
) ->
1668 Buffer.add_char
bb ' '
;
1670 Buffer.add_string
bb "' out='";
1672 Buffer.add_string
bb "'/>\n"
1674 Buffer.add_string
bb "</keymap>";
1683 let save1 bb leavebirdseye x
h dc =
1684 let uifontsize = fstate.fontsize
in
1685 let dc = if conf.bedefault
then conf else dc in
1686 Buffer.add_string
bb "<llppconfig>\n";
1688 if nonemptystr
!fontpath
1690 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
1696 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
1699 Buffer.add_string
bb "<defaults";
1700 add_attrs bb true dc dc nan
;
1701 let kb = keymapsbuf true dc dc in
1702 if Buffer.length
kb > 0
1704 Buffer.add_string
bb ">\n";
1705 Buffer.add_buffer
bb kb;
1706 Buffer.add_string
bb "\n</defaults>\n";
1708 else Buffer.add_string
bb "/>\n";
1710 let adddoc path pan
anchor c bookmarks time origin
=
1711 if bookmarks == [] && c = dc && anchor = emptyanchor
1714 Printf.bprintf
bb "<doc path='%s'"
1715 (Parser.enent
path 0 (String.length
path));
1717 if nonemptystr origin
1719 Printf.bprintf
bb "\n origin='%s'"
1720 (Parser.enent origin
0 (String.length origin
));
1722 if anchor <> emptyanchor
1724 let n, rely
, visy
= anchor in
1725 Printf.bprintf
bb "\n page='%d'" n;
1728 Printf.bprintf
bb " rely='%f'" rely
1730 if abs_float visy
> 1e-6
1732 Printf.bprintf
bb " visy='%f'" visy
1737 then Printf.bprintf
bb " pan='%d'" pan
;
1739 add_attrs bb false dc c time
;
1740 let kb = keymapsbuf false dc c in
1742 begin match bookmarks with
1744 if Buffer.length
kb > 0
1746 Buffer.add_string
bb ">\n";
1747 Buffer.add_buffer
bb kb;
1748 Buffer.add_string
bb "\n</doc>\n";
1750 else Buffer.add_string
bb "/>\n"
1752 Buffer.add_string
bb ">\n<bookmarks>\n";
1753 List.iter
(fun (title
, _, kind
) ->
1754 begin match kind
with
1755 | Oanchor
(page, rely
, visy
) ->
1757 "<item title='%s' page='%d'"
1758 (Parser.enent title
0 (String.length title
))
1763 Printf.bprintf
bb " rely='%f'" rely
1765 if abs_float visy
> 1e-6
1767 Printf.bprintf
bb " visy='%f'" visy
1769 | Ohistory
_ | Onone
| Ouri
_ | Oremote
_
1770 | Oremotedest
_ | Olaunch
_ | Oaction
_ | Oreaction
_ ->
1771 failwith
"unexpected link in bookmarks"
1773 Buffer.add_string
bb "/>\n";
1775 Buffer.add_string
bb "</bookmarks>";
1776 if Buffer.length
kb > 0
1778 Buffer.add_string
bb "\n";
1779 Buffer.add_buffer
bb kb;
1781 Buffer.add_string
bb "\n</doc>\n";
1787 match state.mode
with
1788 | Birdseye
(c, pan, _, _, _) ->
1790 match conf.columns
with
1791 | Cmulti
((c, _, _), _) -> Some
c
1795 match c.columns
with
1796 | Cmulti
(c, _) -> Cmulti
(c, E.a
)
1797 | Csingle
_ -> Csingle
E.a
1798 | Csplit
_ -> failwith
"quit from bird's eye while split"
1800 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
1803 | LinkNav
_ -> x
, conf
1805 let docpath = if nonemptystr
state.path then abspath
state.path else E.s in
1806 if nonemptystr
docpath
1808 adddoc docpath pan (getanchor ())
1810 let autoscrollstep =
1811 match state.autoscroll
with
1813 | None
-> conf.autoscrollstep
1815 begin match state.mode
with
1816 | Birdseye beye
-> leavebirdseye beye
true
1821 { conf with autoscrollstep = autoscrollstep }
1823 (if conf.savebmarks
then state.bookmarks else [])
1827 Hashtbl.iter
(fun path (c, bookmarks, x
, anchor, origin
) ->
1828 if docpath <> abspath
path
1829 then adddoc path x
anchor c bookmarks c.lastvisit origin
1831 Buffer.add_string
bb "</llppconfig>\n";
1835 let save leavebirdseye
=
1836 let relx = float state.x
/. float state.winw
in
1838 let cx w = truncate
(relx *. float w) in
1840 (fun (w, h, x
) ws
->
1842 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
1843 | Wsi.MaxVert
-> (w, conf.cwinh
, x
)
1844 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
1846 (state.winw
, state.winh
, state.x
) state.winstate
1850 let bb = Buffer.create
32768 in
1852 save1 bb leavebirdseye x
h dc
1854 if load1 save2 && Buffer.length
bb > 0
1857 let tmp = !confpath ^
".tmp" in
1858 let oc = open_out_bin
tmp in
1859 Buffer.output_buffer
oc bb;
1861 Unix.rename
tmp !confpath;
1863 dolog
"error saving configuration: %s" @@ exntos exn
1868 (* This here has a potential of rising SIGPIPE, silently and
1869 seemingly harmlessly (when -gc was supplied an invalid
1870 executable for instance) probably needs revisiting *)
1871 let n'
= Unix.write fd
(Bytes.of_string s) 0 n in
1873 then Utils.error
"Unix.write %d = %d" n n'
1875 let href = ref (Hashtbl.create
0) in
1876 let cref = ref defconf in
1878 let f path (pc, _pb
, _px
, _pa
, _po
) =
1880 Printf.sprintf
"%s\000%ld\000" path (Int32.of_float
pc.lastvisit
)
1882 wr s (String.length
s)
1889 ignore
(load1 push);
1890 Unix.shutdown fd
Unix.SHUTDOWN_SEND
;
1891 let s = fdcontents fd
in
1893 match String.index_from
s ppos '
\000'
with
1894 | exception Not_found
-> ()
1896 match String.index_from
s (zpos1
+1) '
\000'
with
1897 | exception Not_found
-> error
"invalid gc input in (%S) at %d" s zpos1
1899 let okey = StringLabels.sub
s ~pos
:ppos ~len
:(zpos1
-ppos
) in
1900 let nkey = StringLabels.sub
s ~pos
:(zpos1
+1) ~len
:(zpos2
-zpos1
-1) in
1902 then (Hashtbl.remove
!href okey; f (zpos2
+1))
1904 match Hashtbl.find !href okey with
1905 | exception Not_found
-> Utils.error
"gc: cannot find %S" okey
1907 Hashtbl.remove
!href okey;
1908 Hashtbl.replace
!href nkey v;
1912 let bb = Buffer.create
32768 in
1913 let save2 (_h
, dc) = save1 bb (fun _ _ -> ()) 0 !href dc in
1914 if load1 save2 && Buffer.length
bb > 0
1917 let tmp = !confpath ^
".tmp" in
1918 let oc = open_out_bin
tmp in
1919 Buffer.output_buffer
oc bb;
1921 Unix.rename
tmp !confpath;
1923 dolog
"error saving configuration: %s" @@ exntos exn
1927 let logcurrently = function
1928 | Idle
-> dolog
"Idle"
1929 | Loading
(l, gen
) ->
1930 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
1931 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col
, row
, tilew
, tileh
) ->
1933 "Tiling %d[%d,%d] page=%s cs=%s angle"
1934 l.pageno col row
(~
> pageopaque
)
1935 (CSTE.to_string colorspace
)
1937 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1938 angle gen
conf.angle
state.gen
1940 conf.tilew
conf.tileh