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"; (n
, a
, b
)
72 | KMmulti
of key list
* key list
74 and keyhash
= (key
, keymap
) Hashtbl.t
77 | KSinto
of (key list
* key list
)
78 and interpagespace
= int
79 and multicolumns
= multicol
* pagegeom
80 and singlecolumn
= pagegeom
81 and splitcolumns
= columncount
* pagegeom
82 and pagegeom
= (pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
83 and multicol
= columncount
* covercount
* covercount
87 and fitmodel
= | FitWidth
| FitProportional
| FitPage
88 and trimmargins
= bool
89 and irect
= (int * int * int * int)
94 and params
= (angle
* fitmodel
* trimparams
95 * texcount
* sliceheight
* memsize
96 * colorspace
* fontpath
* trimcachepath
97 * haspbo
* usefontconfig
)
101 and opaque
= Opaque.t
107 and fontpath
= string
108 and trimcachepath
= string
110 and trimparams
= (trimmargins
* irect
)
111 and colorspace
= | Rgb
| Bgr
| Gray
113 and usefontconfig
= bool
120 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
124 | Ulinkgoto
of (int * int)
126 | Uunexpected
of string
127 | Ulaunch
of launchcommand
129 | Uremote
of (filename
* pageno
)
130 | Uremotedest
of (filename
* destname
)
131 | Uannotation
of (opaque
* slinkindex
)
133 and facename
= string
134 and launchcommand
= string
135 and filename
= string
137 and destname
= string
149 | LDfirstvisible
of (int * int * int)
158 and anchor
= pageno
* top
* dtop
159 and rect
= float * float * float * float * float * float * float * float
160 and infochange
= | Memused
| Docinfo
| Pdim
163 class type uioh
= object
164 method display
: unit
165 method key
: int -> int -> uioh
166 method button
: int -> bool -> int -> int -> int -> uioh
167 method multiclick
: int -> int -> int -> int -> uioh
168 method motion
: int -> int -> uioh
169 method pmotion
: int -> int -> uioh
170 method infochanged
: infochange
-> unit
171 method scrollpw
: (int * float * float)
172 method scrollph
: (int * float * float)
173 method modehash
: keyhash
174 method eformsgs
: bool
175 method alwaysscrolly
: bool
178 module type TextEnumType
=
182 val names
: string array
185 module TextEnumMake
(Ten
: TextEnumType
) =
187 let names = Ten.names;;
188 let to_int (t
: Ten.t
) = Obj.magic t
;;
189 let to_string t
= names.(to_int t
);;
190 let of_int n
: Ten.t
= Obj.magic n
;;
193 if i
= Array.length
names
194 then failwith
("invalid " ^
Ten.name ^
": " ^ s
)
203 module CSTE
= TextEnumMake
(struct
204 type t
= colorspace
;;
205 let name = "colorspace";;
206 let names = [|"rgb"; "bgr"; "gray"|];;
209 module MTE
= TextEnumMake
(struct
212 let names = [|"page"; "block"; "line"; "word"|];;
215 module FMTE
= TextEnumMake
(struct
217 let name = "fitmodel";;
218 let names = [|"width"; "proportional"; "page"|];;
222 { mutable scrollbw
: int
223 ; mutable scrollh
: int
224 ; mutable scrollb
: scrollb
225 ; mutable icase
: bool
226 ; mutable preload
: bool
227 ; mutable pagebias
: int
228 ; mutable verbose
: bool
229 ; mutable debug
: bool
230 ; mutable scrollstep
: int
231 ; mutable hscrollstep
: int
232 ; mutable maxhfit
: bool
233 ; mutable crophack
: bool
234 ; mutable autoscrollstep
: int
235 ; mutable maxwait
: float option
236 ; mutable hlinks
: bool
237 ; mutable underinfo
: bool
238 ; mutable interpagespace
: interpagespace
239 ; mutable zoom
: float
240 ; mutable presentation
: bool
241 ; mutable angle
: angle
242 ; mutable cwinw
: int
243 ; mutable cwinh
: int
244 ; mutable savebmarks
: bool
245 ; mutable fitmodel
: fitmodel
246 ; mutable trimmargins
: trimmargins
247 ; mutable trimfuzz
: irect
248 ; mutable memlimit
: memsize
249 ; mutable texcount
: texcount
250 ; mutable sliceheight
: sliceheight
251 ; mutable thumbw
: width
252 ; mutable jumpback
: bool
253 ; mutable bgcolor
: (float * float * float)
254 ; mutable bedefault
: bool
255 ; mutable tilew
: int
256 ; mutable tileh
: int
257 ; mutable mustoresize
: memsize
258 ; mutable checkers
: bool
259 ; mutable aalevel
: int
260 ; mutable urilauncher
: string
261 ; mutable pathlauncher
: string
262 ; mutable colorspace
: colorspace
263 ; mutable invert
: bool
264 ; mutable colorscale
: float
265 ; mutable redirectstderr
: bool
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 and outline
= (caption
* outlinelevel
* outlinekind
)
302 and outlinelevel
= int
320 type tile
= opaque
* pixmapsize
* elapsed
321 and elapsed
= float;;
322 type pagemapkey
= pageno
* gen
;;
323 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
328 | Loading
of (page
* gen
)
330 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
332 | Outlining
of outline list
335 type mpos
= int * int
337 | Msel
of (mpos
* mpos
)
339 | Mscrolly
| Mscrollx
340 | Mzoom
of (buttonno
* step
)
341 | Mzoomrect
of (mpos
* mpos
)
348 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
349 | Textentry
of (textentry
* onleave
)
351 | LinkNav
of linktarget
352 and onleave
= leavetextentrystatus
-> unit
353 and leavetextentrystatus
= | Cancel
| Confirm
354 and helpitem
= string * int * action
357 | Action
of (uioh
-> uioh
)
359 | Ltexact
of (pageno
* direction
)
360 | Ltgendir
of direction
361 | Ltnotready
of (pageno
* direction
)
362 and direction
= int (* -1, 0, 1 *)
363 and textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
364 and onkey
= string -> int -> te
365 and ondone
= string -> unit
366 and histcancel
= unit -> unit
367 and onhist
= ((histcmd
-> string) * histcancel
)
368 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
369 and cancelonempty
= bool
374 | TEswitch
of textentry
386 { mutable ss
: Unix.file_descr
387 ; mutable wsfd
: Unix.file_descr
388 ; mutable errfd
: Unix.file_descr
option
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"
545 ; redirectstderr
= false
547 ; columns
= Csingle
[||]
553 ; wheelbypage
= false
554 ; stcmd
= "echo SyncTex"
557 ; paxmark
= Mark_word
563 let mk n
= (n
, Hashtbl.create
1) in
577 let conf = { defconf with angle
= defconf.angle
};;
580 if emptystr
conf.urilauncher
581 then print_endline uri
583 let url = geturl uri
in
585 then (Printf.eprintf
"obtained empty url from uri %S\n" uri
)
587 let re = Str.regexp
"%s" in
588 let command = Str.global_replace
re url conf.urilauncher
in
589 try ignore
(popen
command [])
592 "failed to execute `%s': %s\n" command (exntos exn
);
600 :: "(searching in this text works just by typing (i.e. no initial '/'))"
605 let url = geturl s
in
607 then (s
, 0, Action
(fun u
-> gotouri url; u
))
608 else (s
, 0, Noaction
)
613 { store
= Array.make n v
620 let cbcap b
= Array.length b
.store
;;
625 b
.wc
<- (b
.wc
+ 1) mod cap;
627 b
.len
<- min
(b
.len
+ 1) cap;
630 let cbempty b
= b
.len
= 0;;
632 let cbgetg b circular dir
=
636 let rc = b
.rc + dir
in
648 else bound
rc 0 (b
.len
-1)
654 let cbget b
= cbgetg b
false;;
655 let cbgetc b
= cbgetg b
true;;
661 ; stderr
= Unix.stderr
662 ; errmsgs
= Buffer.create
0
667 ; anchor
= emptyanchor
671 ; tilelru
= Queue.create
()
672 ; pagemap
= Hashtbl.create
10
673 ; tilemap
= Hashtbl.create
10
683 ; searchpattern
= E.s
691 { nav
= cbnew 10 emptyanchor
703 ; checkerstexid
= None
704 ; prevzoom
= (1.0, 0)
718 ; traw
= Raw.create_static `
float ~len
:8
719 ; vraw
= Raw.create_static `
float ~len
:8
723 let copykeyhashes c
=
724 List.map
(fun (k
, v
) -> k
, Hashtbl.copy v
) c
.keyhashes
;
728 let d = state.winh
- h
in
729 max
conf.interpagespace
((d + 1) / 2)
732 let rowyh (c
, coverA
, coverB
) b n
=
733 if c
= 1 || (n
< coverA
|| n
>= state.pagecount
- coverB
)
735 let _, _, vy
, (_, _, h
, _) = b
.(n
) in
738 let n'
= n - coverA
in
741 let e = min
state.pagecount
(s + c
) in
742 let rec find m miny maxh
= if m
= e then miny
, maxh
else
743 let _, _, y
, (_, _, h
, _) = b
.(m
) in
744 let miny = min
miny y
in
745 let maxh = max
maxh h
in
751 let ((c
, coverA
, coverB
) as cl
), b
=
752 match conf.columns
with
753 | Csingle b
-> (1, 0, 0), b
754 | Cmulti
(c
, b
) -> c
, b
755 | Csplit
(_, b
) -> (1, 0, 0), b
757 if Array.length b
= 0
760 let rec bsearch nmin nmax
=
762 then bound nmin
0 (state.pagecount
-1)
764 let n = (nmax
+ nmin
) / 2 in
765 let vy, h
= rowyh cl b
n in
769 let ips = calcips h
in
771 let y1 = vy + h
+ ips in
775 then 0, vy + h
+ conf.interpagespace
777 let y0 = vy - conf.interpagespace
in
778 y0, y0 + h
+ conf.interpagespace
788 if n < state.pagecount
- coverB
789 then ((n-coverA
)/c
)*c
+ coverA
796 then bsearch (n+1) nmax
797 else bsearch nmin
(n-1)
800 bsearch 0 (state.pagecount
-1);
804 match conf.columns
with
805 | Cmulti
((_, _, _) as cl
, b
) ->
806 if Array.length b
> 0
808 let y, h
= rowyh cl 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
815 y + h
+ (if conf.presentation
then calcips h
else 0)
818 if Array.length b
> 0
820 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
825 let getpageywh pageno
=
826 let pageno = bound
pageno 0 (state.pagecount
-1) in
827 match conf.columns
with
829 if Array.length b
= 0
832 let (_, _, y, (_, w
, h
, _)) = b
.(pageno) in
840 if Array.length b
= 0
843 let y, h
= rowyh cl b
pageno in
844 let (_, _, _, (_, w
, _, _)) = b
.(pageno) in
852 if Array.length b
= 0
856 let (_, _, y, (_, w
, h
, _)) = b
.(n) in
860 let getpageyh pageno =
861 let y,_,h
= getpageywh pageno in
865 let getpagedim pageno =
868 | (n, _, _, _) as pdim
:: rest
->
870 then (if n = pageno then pdim
else ppdim
)
875 f (-1, -1, -1, -1) state.pdims
878 let getpagey pageno = fst
(getpageyh pageno);;
882 let coloff = l
.pagecol
* l
.pageh
in
883 float (l
.pagey
+ coloff) /. float l
.pageh
891 then float l
.pagedispy
/. float (calcips l
.pageh
)
892 else float l
.pagedispy
/. float conf.interpagespace
895 (l
.pageno, top, dtop)
899 match state.layout
with
900 | l
:: _ -> getanchor1 l
902 let n = page_of_y state.y in
906 let y, h
= getpageyh n in
907 let dy = y - state.y in
911 let ips = calcips h
in
912 float (dy + ips) /. float ips
914 float dy /. float conf.interpagespace
919 let fontpath = ref E.s;;
921 type historder
= [ `lastvisit
| `title
| `path
| `file
];;
922 let historder : historder ref = ref `lastvisit
;;
925 Map.Make
(struct type t
= (int * int) let compare = compare end);;
930 let l = String.length
s in
931 let b = Buffer.create
l in
937 try Sys.getenv
"HOME"
940 ("Can not determine home directory location: " ^ exntos exn
);
944 let modifier_of_string = function
945 | "alt" -> Wsi.altmask
946 | "shift" -> Wsi.shiftmask
947 | "ctrl" | "control" -> Wsi.ctrlmask
948 | "meta" -> Wsi.metamask
953 let r = Str.regexp
"-" in
955 let elems = Str.full_split
r s in
958 let m1 = modifier_of_string s in
960 then (Wsi.namekey
s, m
)
963 | Str.Delim
s when n land 1 = 0 -> g s
965 | Str.Delim
_ -> (k
, m
)
967 let rec loop n k m
= function
970 let k, m
= f n k m x
in
977 let r = Str.regexp
"[ \t]" in
979 let elems = Str.split
r s in
980 List.map
key_of_string 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
= unent v
}
1044 | "path-launcher" -> { c
with pathlauncher
= unent 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 | "redirectstderr" -> { c
with redirectstderr
= bool_of_string v
}
1049 | "ghyllscroll" -> { c
with ghyllscroll
= ghyllscroll_of_string v
}
1051 let (n, _, _) as nab
= multicolumns_of_string v
in
1053 then { c
with columns
= Csplit
(-n, E.a
) }
1054 else { c
with columns
= Cmulti
(nab
, E.a
) }
1055 | "birds-eye-columns" ->
1056 { c
with beyecolumns
= Some
(max
(int_of_string v
) 2) }
1057 | "selection-command" -> { c
with selcmd
= unent v
}
1058 | "synctex-command" -> { c
with stcmd
= unent v
}
1059 | "pax-command" -> { c
with paxcmd
= unent v
}
1060 | "askpass-command" -> { c
with passcmd
= unent v
}
1061 | "savepath-command" -> { c
with savecmd
= unent v
}
1062 | "update-cursor" -> { c
with updatecurs
= bool_of_string v
}
1063 | "hint-font-size" -> { c
with hfsize
= bound
(int_of_string v
) 5 100 }
1064 | "page-scroll-scale" -> { c
with pgscale
= float_of_string v
}
1065 | "use-pbo" -> { c
with usepbo
= bool_of_string v
}
1066 | "wheel-scrolls-pages" -> { c
with wheelbypage
= bool_of_string v
}
1067 | "horizontal-scrollbar-visible" ->
1070 then c
.scrollb
lor scrollbhv
1071 else c
.scrollb
land (lnot
scrollbhv)
1073 { c
with scrollb
= b }
1074 | "vertical-scrollbar-visible" ->
1077 then c
.scrollb
lor scrollbvv
1078 else c
.scrollb
land (lnot
scrollbvv)
1080 { c
with scrollb
= b }
1081 | "remote-in-a-new-instance" -> { c
with riani
= bool_of_string v
}
1085 then Some
(ref (0.0, 0, 0))
1087 | "point-and-x-mark" -> { c
with paxmark
= MTE.of_string v
}
1088 | "scroll-bar-on-the-left" -> { c
with leftscroll
= bool_of_string v
}
1089 | "title" -> { c
with title
= unent v
}
1090 | "last-visit" -> { c
with lastvisit
= float_of_string v
}
1091 | "edit-annots-inline" -> { c
with annotinline
= bool_of_string v
}
1094 prerr_endline
("Error processing attribute (`" ^
1095 k ^
"'=`" ^ v ^
"'): " ^ exntos exn
);
1098 let rec fold c
= function
1101 let c = apply c k v
in
1104 fold { c with keyhashes
= copykeyhashes c } attrs
;
1107 let fromstring f pos
n v
d =
1110 dolog
"Error processing attribute (%S=%S) at %d\n%s"
1111 n v pos
(exntos exn
)
1116 let bookmark_of attrs
=
1117 let rec fold title page rely visy
= function
1118 | ("title", v
) :: rest
-> fold v page rely visy rest
1119 | ("page", v
) :: rest
-> fold title v rely visy rest
1120 | ("rely", v
) :: rest
-> fold title page v visy rest
1121 | ("visy", v
) :: rest
-> fold title page rely v rest
1122 | _ :: rest
-> fold title page rely visy rest
1123 | [] -> title
, page
, rely
, visy
1125 fold "invalid" "0" "0" "0" attrs
1129 let rec fold path page rely pan visy origin
= function
1130 | ("path", v
) :: rest
-> fold v page rely pan visy origin rest
1131 | ("page", v
) :: rest
-> fold path v rely pan visy origin rest
1132 | ("rely", v
) :: rest
-> fold path page v pan visy origin rest
1133 | ("pan", v
) :: rest
-> fold path page rely v visy origin rest
1134 | ("visy", v
) :: rest
-> fold path page rely pan v origin rest
1135 | ("origin", v
) :: rest
-> fold path page rely pan visy v rest
1136 | _ :: rest
-> fold path page rely pan visy origin rest
1137 | [] -> path
, page
, rely
, pan
, visy
, origin
1139 fold E.s "0" "0" "0" "0" E.s attrs
1143 let rec fold rs ls
= function
1144 | ("out", v
) :: rest
-> fold v ls rest
1145 | ("in", v
) :: rest
-> fold rs v rest
1146 | _ :: rest
-> fold ls rs rest
1152 let setconf dst src
=
1153 dst
.scrollbw
<- src
.scrollbw
;
1154 dst
.scrollh
<- src
.scrollh
;
1155 dst
.icase
<- src
.icase
;
1156 dst
.preload
<- src
.preload
;
1157 dst
.pagebias
<- src
.pagebias
;
1158 dst
.verbose
<- src
.verbose
;
1159 dst
.scrollstep
<- src
.scrollstep
;
1160 dst
.maxhfit
<- src
.maxhfit
;
1161 dst
.crophack
<- src
.crophack
;
1162 dst
.autoscrollstep
<- src
.autoscrollstep
;
1163 dst
.maxwait
<- src
.maxwait
;
1164 dst
.hlinks
<- src
.hlinks
;
1165 dst
.underinfo
<- src
.underinfo
;
1166 dst
.interpagespace
<- src
.interpagespace
;
1167 dst
.zoom <- src
.zoom;
1168 dst
.presentation
<- src
.presentation
;
1169 dst
.angle
<- src
.angle
;
1170 dst
.cwinw
<- src
.cwinw
;
1171 dst
.cwinh
<- src
.cwinh
;
1172 dst
.savebmarks
<- src
.savebmarks
;
1173 dst
.memlimit
<- src
.memlimit
;
1174 dst
.fitmodel
<- src
.fitmodel
;
1175 dst
.texcount
<- src
.texcount
;
1176 dst
.sliceheight
<- src
.sliceheight
;
1177 dst
.thumbw
<- src
.thumbw
;
1178 dst
.jumpback
<- src
.jumpback
;
1179 dst
.bgcolor
<- src
.bgcolor
;
1180 dst
.tilew
<- src
.tilew
;
1181 dst
.tileh
<- src
.tileh
;
1182 dst
.mustoresize
<- src
.mustoresize
;
1183 dst
.checkers
<- src
.checkers
;
1184 dst
.aalevel
<- src
.aalevel
;
1185 dst
.trimmargins
<- src
.trimmargins
;
1186 dst
.trimfuzz
<- src
.trimfuzz
;
1187 dst
.urilauncher
<- src
.urilauncher
;
1188 dst
.colorspace
<- src
.colorspace
;
1189 dst
.invert
<- src
.invert
;
1190 dst
.colorscale
<- src
.colorscale
;
1191 dst
.redirectstderr
<- src
.redirectstderr
;
1192 dst
.ghyllscroll
<- src
.ghyllscroll
;
1193 dst
.columns
<- src
.columns
;
1194 dst
.beyecolumns
<- src
.beyecolumns
;
1195 dst
.selcmd
<- src
.selcmd
;
1196 dst
.updatecurs
<- src
.updatecurs
;
1197 dst
.pathlauncher
<- src
.pathlauncher
;
1198 dst
.keyhashes
<- copykeyhashes src
;
1199 dst
.hfsize
<- src
.hfsize
;
1200 dst
.hscrollstep
<- src
.hscrollstep
;
1201 dst
.pgscale
<- src
.pgscale
;
1202 dst
.usepbo
<- src
.usepbo
;
1203 dst
.wheelbypage
<- src
.wheelbypage
;
1204 dst
.stcmd
<- src
.stcmd
;
1205 dst
.paxcmd
<- src
.paxcmd
;
1206 dst
.passcmd
<- src
.passcmd
;
1207 dst
.savecmd
<- src
.savecmd
;
1208 dst
.scrollb
<- src
.scrollb
;
1209 dst
.riani
<- src
.riani
;
1210 dst
.paxmark
<- src
.paxmark
;
1211 dst
.leftscroll
<- src
.leftscroll
;
1212 dst
.title
<- src
.title
;
1213 dst
.annotinline
<- src
.annotinline
;
1217 else Some
((ref (0.0, 0, 0)));
1220 let findkeyhash c name =
1221 try List.assoc
name c.keyhashes
1222 with Not_found
-> failwith
("invalid mode name `" ^
name ^
"'")
1226 let h = Hashtbl.create
10 in
1227 let dc = { defconf with angle
= defconf.angle
} in
1228 let rec toplevel v t spos
_ =
1230 | Vdata
| Vcdata
| Vend
-> v
1231 | Vopen
("llppconfig", _, closed
) ->
1234 else { v
with f = llppconfig
}
1236 error
"unexpected subelement at top level" s spos
1237 | Vclose
_ -> error
"unexpected close at top level" s spos
1239 and llppconfig v t spos
_ =
1241 | Vdata
| Vcdata
-> v
1242 | Vend
-> error
"unexpected end of input in llppconfig" s spos
1243 | Vopen
("defaults", attrs
, closed
) ->
1244 let c = config_of dc attrs
in
1248 else { v
with f = defaults
}
1250 | Vopen
("ui-font", attrs
, closed
) ->
1251 let rec getsize size
= function
1253 | ("size", v
) :: rest
->
1255 fromstring int_of_string spos
"size" v
fstate.fontsize
in
1257 | l -> getsize size l
1259 fstate.fontsize
<- getsize fstate.fontsize attrs
;
1262 else { v
with f = uifont
(Buffer.create
10) }
1264 | Vopen
("doc", attrs
, closed
) ->
1265 let pathent, spage
, srely
, span
, svisy
, origin
= doc_of attrs
in
1266 let path = unent pathent
1267 and origin
= unent origin
1268 and pageno = fromstring int_of_string spos
"page" spage
0
1269 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1270 and pan
= fromstring int_of_string spos
"pan" span
0
1271 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1272 let c = config_of dc attrs
in
1273 let anchor = (pageno, rely
, visy
) in
1275 then (Hashtbl.add
h path (c, [], pan
, anchor, origin
); v
)
1276 else { v
with f = doc
path origin pan
anchor c [] }
1279 error
"unexpected subelement in llppconfig" s spos
1281 | Vclose
"llppconfig" -> { v
with f = toplevel }
1282 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
1284 and defaults v t spos
_ =
1286 | Vdata
| Vcdata
-> v
1287 | Vend
-> error
"unexpected end of input in defaults" s spos
1288 | Vopen
("keymap", attrs
, closed
) ->
1290 try List.assoc
"mode" attrs
1291 with Not_found
-> "global" in
1296 let h = findkeyhash dc modename in
1297 KeyMap.iter
(Hashtbl.replace
h) keymap
;
1300 { v
with f = pkeymap
ret KeyMap.empty
}
1302 | Vopen
(_, _, _) ->
1303 error
"unexpected subelement in defaults" s spos
1305 | Vclose
"defaults" ->
1306 { v
with f = llppconfig
}
1308 | Vclose
_ -> error
"unexpected close in defaults" s spos
1310 and uifont
b v t spos epos
=
1313 Buffer.add_substring
b s spos
(epos
- spos
);
1315 | Vopen
(_, _, _) ->
1316 error
"unexpected subelement in ui-font" s spos
1317 | Vclose
"ui-font" ->
1318 if emptystr
!fontpath
1319 then fontpath := Buffer.contents
b;
1320 { v
with f = llppconfig
}
1321 | Vclose
_ -> error
"unexpected close in ui-font" s spos
1322 | Vend
-> error
"unexpected end of input in ui-font" s spos
1324 and doc
path origin pan
anchor c bookmarks v t spos
_ =
1326 | Vdata
| Vcdata
-> v
1327 | Vend
-> error
"unexpected end of input in doc" s spos
1328 | Vopen
("bookmarks", _, closed
) ->
1331 else { v
with f = pbookmarks
path origin pan
anchor c bookmarks
}
1333 | Vopen
("keymap", attrs
, closed
) ->
1335 try List.assoc
"mode" attrs
1336 with Not_found
-> "global"
1342 let h = findkeyhash c modename in
1343 KeyMap.iter
(Hashtbl.replace
h) keymap
;
1344 doc
path origin pan
anchor c bookmarks
1346 { v
with f = pkeymap
ret KeyMap.empty
}
1348 | Vopen
(_, _, _) ->
1349 error
"unexpected subelement in doc" s spos
1352 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor, origin
);
1353 { v
with f = llppconfig
}
1355 | Vclose
_ -> error
"unexpected close in doc" s spos
1357 and pkeymap
ret keymap v t spos
_ =
1359 | Vdata
| Vcdata
-> v
1360 | Vend
-> error
"unexpected end of input in keymap" s spos
1361 | Vopen
("map", attrs
, closed
) ->
1362 let r, l = map_of attrs
in
1363 let kss = fromstring keys_of_string spos
"in" r [] in
1364 let lss = fromstring keys_of_string spos
"out" l [] in
1368 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
1369 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
1372 then { v
with f = pkeymap
ret keymap }
1375 { v
with f = skip
"map" f }
1378 error
"unexpected subelement in keymap" s spos
1380 | Vclose
"keymap" ->
1381 { v
with f = ret keymap }
1383 | Vclose
_ -> error
"unexpected close in keymap" s spos
1385 and pbookmarks
path origin pan
anchor c bookmarks v t spos
_ =
1387 | Vdata
| Vcdata
-> v
1388 | Vend
-> error
"unexpected end of input in bookmarks" s spos
1389 | Vopen
("item", attrs
, closed
) ->
1390 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
1391 let page = fromstring int_of_string spos
"page" spage
0
1392 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1393 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1395 (unent titleent, 0, Oanchor
(page, rely
, visy
)) :: bookmarks
1398 then { v
with f = pbookmarks
path origin pan
anchor c bookmarks }
1401 { v
with f = skip
"item" f }
1404 error
"unexpected subelement in bookmarks" s spos
1406 | Vclose
"bookmarks" ->
1407 { v
with f = doc
path origin pan
anchor c bookmarks }
1409 | Vclose
_ -> Parser.parse_error
"unexpected close in bookmarks" s spos
1411 and skip tag
f v t spos
_ =
1413 | Vdata
| Vcdata
-> v
1415 Parser.parse_error
("unexpected end of input in skipped " ^ tag
) s spos
1416 | Vopen
(tag'
, _, closed
) ->
1420 let f'
() = { v
with f = skip tag
f } in
1421 { v
with f = skip tag'
f'
}
1425 else Parser.parse_error
("unexpected close in skipped " ^ tag
) s spos
1428 parse
{ f = toplevel; accu
= () } s;
1434 let len = in_channel_length ic
in
1435 let s = really_input_string ic
len in
1438 | Parse_error
(msg
, s, pos
) ->
1439 let subs = subs s pos
in
1440 Utils.error
"parse error: %s: at %d [..%s..]" msg pos
subs
1443 failwith
("config load error: " ^ exntos exn
)
1448 let xdgconfdir = Utils.getenvwithdef
"XDG_CONFIG_HOME" E.s in
1449 if xdgconfdir == E.s
1452 let dir = Filename.concat
home ".config" in
1453 if Sys.is_directory
dir then dir else home
1457 Filename.concat
dir "llpp.conf"
1460 let confpath = ref defconfpath;;
1463 if Sys.file_exists
!confpath
1465 match open_in_bin
!confpath with
1472 ("Error loading configuration from `" ^
!confpath ^
"': " ^
1479 | (exception exn
) ->
1481 ("Error opening configuration file `" ^
!confpath ^
"': " ^
1485 f (Hashtbl.create
0, defconf)
1494 (fun path (conf, _, _, _, _) ((_, besttime
) as best
) ->
1495 if conf.lastvisit
> besttime
1496 then (path, conf.lastvisit
)
1499 (state.path, -.infinity
)
1503 let pc, pb
, px
, pa
, po
=
1505 let absname = abspath
state.path in
1506 Hashtbl.find h absname
1507 with Not_found
-> dc, [], 0, emptyanchor, state.origin
1511 state.bookmarks <- pb
;
1515 then state.anchor <- pa
;
1516 cbput state.hists
.nav pa
;
1522 let gethist listref
=
1525 Hashtbl.fold (fun path (pc, pb
, px
, pa
, po
) accu
->
1526 (path, pc, pb
, px
, pa
, po
) :: accu
)
1533 let add_attrs bb always
dc c time
=
1536 then Printf.bprintf bb
"\n %s='%b'" s a
1539 then Printf.bprintf bb
"\n %s='%b'" s (a
!= None
)
1542 then Printf.bprintf bb
"\n %s='%d'" s a
1545 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a
)
1548 then Printf.bprintf bb
"\n %s='%g'" s (a
*.100.)
1551 then Printf.bprintf bb
"\n %s='%f'" s a
1554 then Printf.bprintf bb
"\n %s='%Ld'" s a
1557 then Printf.bprintf bb
"\n %s='%s'" s (color_to_string a
)
1560 then Printf.bprintf bb
"\n %s='%s'" s (CSTE.to_string a
)
1563 then Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a
)
1566 then Printf.bprintf bb
"\n %s='%s'" s (enent a
0 (String.length a
))
1571 | Some
(_N
, _A
, _B
) ->
1572 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
1577 Printf.bprintf bb
"\n %s='none'" s
1587 else string_of_float
f
1589 Printf.bprintf bb
"\n %s='%s'" s v
1594 | Cmulti
((n, a
, b), _) when n > 1 ->
1595 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a
b
1596 | Csplit
(n, _) when n > 1 ->
1597 Printf.bprintf bb
"\n %s='%d'" s ~
-n
1598 | Cmulti
_ | Csplit
_ | Csingle
_ -> ()
1603 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
1607 then Printf.bprintf bb
"\n %s='%s'" s (FMTE.to_string a
)
1610 then Printf.bprintf bb
"\n %s='%b'" s (a
land m
!= 0)
1613 then Printf.bprintf bb
"\n %s='%s'" s (MTE.to_string a
)
1615 oi
"width" c.cwinw
dc.cwinw
;
1616 oi
"height" c.cwinh
dc.cwinh
;
1617 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
1618 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
1619 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
1620 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
1621 ob "case-insensitive-search" c.icase
dc.icase
;
1622 ob "preload" c.preload
dc.preload
;
1623 oi
"page-bias" c.pagebias
dc.pagebias
;
1624 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
1625 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
1626 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
1627 ob "crop-hack" c.crophack
dc.crophack
;
1628 oW
"throttle" c.maxwait
dc.maxwait
;
1629 ob "highlight-links" c.hlinks
dc.hlinks
;
1630 ob "under-cursor-info" c.underinfo
dc.underinfo
;
1631 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
1632 oz
"zoom" c.zoom dc.zoom;
1633 ob "presentation" c.presentation
dc.presentation
;
1634 oi
"rotation-angle" c.angle
dc.angle
;
1635 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
1636 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
1637 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
1638 oi
"tex-count" c.texcount
dc.texcount
;
1639 oi
"slice-height" c.sliceheight
dc.sliceheight
;
1640 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
1641 ob "persistent-location" c.jumpback
dc.jumpback
;
1642 oc
"background-color" c.bgcolor
dc.bgcolor
;
1643 oi
"tile-width" c.tilew
dc.tilew
;
1644 oi
"tile-height" c.tileh
dc.tileh
;
1645 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
1646 ob "checkers" c.checkers
dc.checkers
;
1647 oi
"aalevel" c.aalevel
dc.aalevel
;
1648 ob "trim-margins" c.trimmargins
dc.trimmargins
;
1649 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
1650 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
1651 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
1652 oC
"color-space" c.colorspace
dc.colorspace
;
1653 ob "invert-colors" c.invert
dc.invert
;
1654 oF
"brightness" c.colorscale
dc.colorscale
;
1655 ob "redirectstderr" c.redirectstderr
dc.redirectstderr
;
1656 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
1657 oco
"columns" c.columns
dc.columns
;
1658 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
1659 os
"selection-command" c.selcmd
dc.selcmd
;
1660 os
"synctex-command" c.stcmd
dc.stcmd
;
1661 os
"pax-command" c.paxcmd
dc.paxcmd
;
1662 os
"askpass-command" c.passcmd
dc.passcmd
;
1663 os
"savepath-command" c.savecmd
dc.savecmd
;
1664 ob "update-cursor" c.updatecurs
dc.updatecurs
;
1665 oi
"hint-font-size" c.hfsize
dc.hfsize
;
1666 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
1667 oF
"page-scroll-scale" c.pgscale
dc.pgscale
;
1668 ob "use-pbo" c.usepbo
dc.usepbo
;
1669 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
1670 ob "remote-in-a-new-instance" c.riani
dc.riani
;
1671 op
"point-and-x" c.pax
dc.pax
;
1672 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
1673 ob "scroll-bar-on-the-left" c.leftscroll
dc.leftscroll
;
1675 then os
"title" c.title
dc.title
;
1676 oL
"last-visit" (Int64.of_float time
) 0L;
1677 ob "edit-annotations-inline" c.annotinline
dc.annotinline
;
1680 let keymapsbuf always
dc c =
1681 let bb = Buffer.create
16 in
1682 let rec loop = function
1684 | (modename, h) :: rest
->
1685 let dh = findkeyhash dc modename in
1686 if always
|| h <> dh
1688 if Hashtbl.length
h > 0
1690 if Buffer.length
bb > 0
1691 then Buffer.add_char
bb '
\n'
;
1692 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
1693 Hashtbl.iter
(fun i o
->
1694 let isdifferent = always
||
1696 let dO = Hashtbl.find dh i
in
1698 with Not_found
-> true
1703 if Wsi.withctrl m
then Buffer.add_string
bb "ctrl-";
1704 if Wsi.withalt m
then Buffer.add_string
bb "alt-";
1705 if Wsi.withshift m
then Buffer.add_string
bb "shift-";
1706 if Wsi.withmeta m
then Buffer.add_string
bb "meta-";
1707 Buffer.add_string
bb (Wsi.keyname
k);
1710 let rec loop = function
1712 | km
:: [] -> addkm km
1713 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
1717 Buffer.add_string
bb "<map in='";
1721 Buffer.add_string
bb "' out='";
1723 Buffer.add_string
bb "'/>\n"
1726 Buffer.add_string
bb "' out='";
1728 Buffer.add_string
bb "'/>\n"
1730 | KMmulti
(ins
, kms
) ->
1731 Buffer.add_char
bb ' '
;
1733 Buffer.add_string
bb "' out='";
1735 Buffer.add_string
bb "'/>\n"
1737 Buffer.add_string
bb "</keymap>";
1746 let save1 bb leavebirdseye x
h dc =
1747 let uifontsize = fstate.fontsize
in
1748 let dc = if conf.bedefault
then conf else dc in
1749 Buffer.add_string
bb "<llppconfig>\n";
1751 if nonemptystr
!fontpath
1753 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
1759 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
1762 Buffer.add_string
bb "<defaults";
1763 add_attrs bb true dc dc nan
;
1764 let kb = keymapsbuf true dc dc in
1765 if Buffer.length
kb > 0
1767 Buffer.add_string
bb ">\n";
1768 Buffer.add_buffer
bb kb;
1769 Buffer.add_string
bb "\n</defaults>\n";
1771 else Buffer.add_string
bb "/>\n";
1773 let adddoc path pan
anchor c bookmarks time origin
=
1774 if bookmarks == [] && c = dc && anchor = emptyanchor
1777 Printf.bprintf
bb "<doc path='%s'"
1778 (enent
path 0 (String.length
path));
1780 if nonemptystr origin
1782 Printf.bprintf
bb "\n origin='%s'"
1783 (enent origin
0 (String.length origin
));
1785 if anchor <> emptyanchor
1787 let n, rely
, visy
= anchor in
1788 Printf.bprintf
bb "\n page='%d'" n;
1791 Printf.bprintf
bb " rely='%f'" rely
1793 if abs_float visy
> 1e-6
1795 Printf.bprintf
bb " visy='%f'" visy
1800 then Printf.bprintf
bb " pan='%d'" pan
;
1802 add_attrs bb false dc c time
;
1803 let kb = keymapsbuf false dc c in
1805 begin match bookmarks with
1807 if Buffer.length
kb > 0
1809 Buffer.add_string
bb ">\n";
1810 Buffer.add_buffer
bb kb;
1811 Buffer.add_string
bb "\n</doc>\n";
1813 else Buffer.add_string
bb "/>\n"
1815 Buffer.add_string
bb ">\n<bookmarks>\n";
1816 List.iter
(fun (title
, _, kind
) ->
1817 begin match kind
with
1818 | Oanchor
(page, rely
, visy
) ->
1820 "<item title='%s' page='%d'"
1821 (enent title
0 (String.length title
))
1826 Printf.bprintf
bb " rely='%f'" rely
1828 if abs_float visy
> 1e-6
1830 Printf.bprintf
bb " visy='%f'" visy
1832 | Ohistory
_ | Onone
| Ouri
_ | Oremote
_
1833 | Oremotedest
_ | Olaunch
_ | Oaction
_ ->
1834 failwith
"unexpected link in bookmarks"
1836 Buffer.add_string
bb "/>\n";
1838 Buffer.add_string
bb "</bookmarks>";
1839 if Buffer.length
kb > 0
1841 Buffer.add_string
bb "\n";
1842 Buffer.add_buffer
bb kb;
1844 Buffer.add_string
bb "\n</doc>\n";
1850 match state.mode
with
1851 | Birdseye
(c, pan, _, _, _) ->
1853 match conf.columns
with
1854 | Cmulti
((c, _, _), _) -> Some
c
1858 match c.columns
with
1859 | Cmulti
(c, _) -> Cmulti
(c, E.a
)
1860 | Csingle
_ -> Csingle
E.a
1861 | Csplit
_ -> failwith
"quit from bird's eye while split"
1863 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
1866 | LinkNav
_ -> x
, conf
1868 let docpath = if nonemptystr
state.path then abspath
state.path else E.s in
1869 if nonemptystr
docpath
1871 adddoc docpath pan (getanchor ())
1873 let autoscrollstep =
1874 match state.autoscroll
with
1876 | None
-> conf.autoscrollstep
1878 begin match state.mode
with
1879 | Birdseye beye
-> leavebirdseye beye
true
1884 { conf with autoscrollstep = autoscrollstep }
1886 (if conf.savebmarks
then state.bookmarks else [])
1890 Hashtbl.iter
(fun path (c, bookmarks, x
, anchor, origin
) ->
1891 if docpath <> abspath
path
1892 then adddoc path x
anchor c bookmarks c.lastvisit origin
1894 Buffer.add_string
bb "</llppconfig>\n";
1898 let save leavebirdseye
=
1899 let relx = float state.x
/. float state.winw
in
1901 let cx w = truncate
(relx *. float w) in
1903 (fun (w, h, x
) ws
->
1905 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
1906 | Wsi.MaxVert
-> (w, conf.cwinh
, x
)
1907 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
1909 (state.winw
, state.winh
, state.x
) state.winstate
1913 let bb = Buffer.create
32768 in
1915 save1 bb leavebirdseye x
h dc
1917 if load1 save2 && Buffer.length
bb > 0
1920 let tmp = !confpath ^
".tmp" in
1921 let oc = open_out_bin
tmp in
1922 Buffer.output_buffer
oc bb;
1924 Unix.rename
tmp !confpath;
1927 ("error while saving configuration: " ^ exntos exn
)
1932 let n'
= Unix.write fdo
(Bytes.of_string s) 0 n in
1934 then Utils.error
"Unix.write %d = %d" n n'
1937 try Unix.read fdi
s 0 n
1938 with exn
-> Utils.error
"reading gc pipe %s" (exntos exn
) in
1939 let href = ref (Hashtbl.create
0) in
1940 let cref = ref defconf in
1942 let f path (pc, _pb
, _px
, _pa
, _po
) =
1944 Printf.sprintf
"%s\000%ld\000" path (Int32.of_float
pc.lastvisit
)
1946 wr s (String.length
s)
1951 Unix.shutdown fdo
Unix.SHUTDOWN_SEND
;
1954 ignore
(load1 push);
1956 let b = Buffer.create
32768 in
1957 let s = Bytes.create
4096 in
1959 let n = rd s (Bytes.length
s) in
1961 then Buffer.contents
b
1962 else (Buffer.add_subbytes
b s 0 n; f ())
1967 match String.index_from
s ppos '
\000'
with
1970 try String.index_from
s (zpos1
+1) '
\000'
with Not_found
-> -1 in
1972 then error
"Incorrect gc input in (%S) at %d" s zpos1
1974 let okey = StringLabels.sub
s ~pos
:ppos ~
len:(zpos1
-ppos
) in
1975 let nkey = StringLabels.sub
s ~pos
:(zpos1
+1) ~
len:(zpos2-zpos1
-1) in
1977 then (Hashtbl.remove
!href okey; f (zpos2+1))
1980 try Hashtbl.find !href okey
1981 with Not_found
-> Utils.error
"gc: could not find %S" okey
1983 Hashtbl.remove
!href okey;
1984 Hashtbl.replace
!href nkey v;
1986 | exception Not_found
-> ()
1989 let bb = Buffer.create
32768 in
1990 let save2 (_h
, dc) = save1 bb (fun _ _ -> ()) 0 !href dc in
1991 if load1 save2 && Buffer.length
bb > 0
1994 let tmp = !confpath ^
".tmp" in
1995 let oc = open_out_bin
tmp in
1996 Buffer.output_buffer
oc bb;
1998 Unix.rename
tmp !confpath;
2001 ("error while saving configuration: " ^ exntos exn
)
2005 let logcurrently = function
2006 | Idle
-> dolog
"Idle"
2007 | Loading
(l, gen
) ->
2008 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
2009 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col
, row
, tilew
, tileh
) ->
2011 "Tiling %d[%d,%d] page=%s cs=%s angle"
2012 l.pageno col row
(~
> pageopaque
)
2013 (CSTE.to_string colorspace
)
2015 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2016 angle gen
conf.angle
state.gen
2018 conf.tilew
conf.tileh