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);;
23 let pidset = ref IntSet.empty
;;
24 let addpid pid
= if pid
> 0 then pidset := IntSet.add pid
!pidset;;
25 let haspid pid
= IntSet.mem pid
!pidset;;
26 let delpid pid
= pidset := IntSet.remove pid
!pidset;;
27 let ispidsetempty () = IntSet.is_empty
!pidset;;
29 let irect_of_string s
=
30 Scanf.sscanf s
"%d/%d/%d/%d" (fun x0 y0 x1 y1
-> (x0
,y0
,x1
,y1
))
33 let irect_to_string (x0
,y0
,x1
,y1
) =
34 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
37 let ghyllscroll_of_string s
=
39 | "fast" -> Some
fastghyllscroll
40 | "neat" -> Some
(10,1,9)
44 Scanf.sscanf s
"%u,%u,%u" (fun n a b
-> n
, a
, b
) in
45 if n
<= a
|| n
<= b
|| a
>= b
46 then error
"invalid ghyll N(%d),A(%d),B(%d) (N <= A, A < B, N <= B)"
51 let ghyllscroll_to_string ((n
, a
, b
) as nab
) =
52 (**) if nab
= fastghyllscroll then "fast"
53 else if nab
= neatghyllscroll then "neat"
54 else Printf.sprintf
"%d,%d,%d" n a b
;
57 let multicolumns_to_string (n
, a
, b
) =
59 then Printf.sprintf
"%d" n
60 else Printf.sprintf
"%d,%d,%d" n a b
;
63 let multicolumns_of_string s
=
65 (int_of_string s
, 0, 0)
67 Scanf.sscanf s
"%u,%u,%u" (fun n a b
->
69 then failwith
"subtly broken"; (n
, a
, b
)
76 | KMmulti
of key list
* key list
78 and keyhash
= (key
, keymap
) Hashtbl.t
81 | KSinto
of (key list
* key list
)
82 and interpagespace
= int
83 and multicolumns
= multicol
* pagegeom
84 and singlecolumn
= pagegeom
85 and splitcolumns
= columncount
* pagegeom
86 and pagegeom
= (pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
87 and multicol
= columncount
* covercount
* covercount
91 and fitmodel
= | FitWidth
| FitProportional
| FitPage
92 and trimmargins
= bool
93 and irect
= (int * int * int * int)
98 and params
= (angle
* fitmodel
* trimparams
99 * texcount
* sliceheight
* memsize
100 * colorspace
* fontpath
* trimcachepath
101 * haspbo
* usefontconfig
)
105 and opaque
= Opaque.t
111 and fontpath
= string
112 and trimcachepath
= string
114 and trimparams
= (trimmargins
* irect
)
115 and colorspace
= | Rgb
| Bgr
| Gray
117 and usefontconfig
= bool
124 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
128 | Ulinkgoto
of (int * int)
130 | Uunexpected
of string
131 | Ulaunch
of launchcommand
133 | Uremote
of (filename
* pageno
)
134 | Uremotedest
of (filename
* destname
)
135 | Uannotation
of (opaque
* slinkindex
)
137 and facename
= string
138 and launchcommand
= string
139 and filename
= string
141 and destname
= string
153 | LDfirstvisible
of (int * int * int)
162 and anchor
= pageno
* top
* dtop
163 and rect
= float * float * float * float * float * float * float * float
164 and infochange
= | Memused
| Docinfo
| Pdim
167 class type uioh
= object
168 method display
: unit
169 method key
: int -> int -> uioh
170 method button
: int -> bool -> int -> int -> int -> uioh
171 method multiclick
: int -> int -> int -> int -> uioh
172 method motion
: int -> int -> uioh
173 method pmotion
: int -> int -> uioh
174 method infochanged
: infochange
-> unit
175 method scrollpw
: (int * float * float)
176 method scrollph
: (int * float * float)
177 method modehash
: keyhash
178 method eformsgs
: bool
179 method alwaysscrolly
: bool
182 module type TextEnumType
=
186 val names
: string array
189 module TextEnumMake
(Ten
: TextEnumType
) =
191 let names = Ten.names;;
192 let to_int (t
: Ten.t
) = Obj.magic t
;;
193 let to_string t
= names.(to_int t
);;
194 let of_int n
: Ten.t
= Obj.magic n
;;
197 if i
= Array.length
names
198 then failwith
("invalid " ^
Ten.name ^
": " ^ s
)
207 module CSTE
= TextEnumMake
(struct
208 type t
= colorspace
;;
209 let name = "colorspace";;
210 let names = [|"rgb"; "bgr"; "gray"|];;
213 module MTE
= TextEnumMake
(struct
216 let names = [|"page"; "block"; "line"; "word"|];;
219 module FMTE
= TextEnumMake
(struct
221 let name = "fitmodel";;
222 let names = [|"width"; "proportional"; "page"|];;
226 { mutable scrollbw
: int
227 ; mutable scrollh
: int
228 ; mutable scrollb
: scrollb
229 ; mutable icase
: bool
230 ; mutable preload
: bool
231 ; mutable pagebias
: int
232 ; mutable verbose
: bool
233 ; mutable debug
: bool
234 ; mutable scrollstep
: int
235 ; mutable hscrollstep
: int
236 ; mutable maxhfit
: bool
237 ; mutable crophack
: bool
238 ; mutable autoscrollstep
: int
239 ; mutable maxwait
: float option
240 ; mutable hlinks
: bool
241 ; mutable underinfo
: bool
242 ; mutable interpagespace
: interpagespace
243 ; mutable zoom
: float
244 ; mutable presentation
: bool
245 ; mutable angle
: angle
246 ; mutable cwinw
: int
247 ; mutable cwinh
: int
248 ; mutable savebmarks
: bool
249 ; mutable fitmodel
: fitmodel
250 ; mutable trimmargins
: trimmargins
251 ; mutable trimfuzz
: irect
252 ; mutable memlimit
: memsize
253 ; mutable texcount
: texcount
254 ; mutable sliceheight
: sliceheight
255 ; mutable thumbw
: width
256 ; mutable jumpback
: bool
257 ; mutable bgcolor
: (float * float * float)
258 ; mutable bedefault
: bool
259 ; mutable tilew
: int
260 ; mutable tileh
: int
261 ; mutable mustoresize
: memsize
262 ; mutable checkers
: bool
263 ; mutable aalevel
: int
264 ; mutable urilauncher
: string
265 ; mutable pathlauncher
: string
266 ; mutable colorspace
: colorspace
267 ; mutable invert
: bool
268 ; mutable colorscale
: float
269 ; mutable redirectstderr
: bool
270 ; mutable ghyllscroll
: (int * int * int) option
271 ; mutable columns
: columns
272 ; mutable beyecolumns
: columncount
option
273 ; mutable selcmd
: string
274 ; mutable paxcmd
: string
275 ; mutable passcmd
: string
276 ; mutable savecmd
: string
277 ; mutable updatecurs
: bool
278 ; mutable keyhashes
: (string * keyhash
) list
279 ; mutable hfsize
: int
280 ; mutable pgscale
: float
281 ; mutable usepbo
: bool
282 ; mutable wheelbypage
: bool
283 ; mutable stcmd
: string
284 ; mutable riani
: bool
285 ; mutable pax
: (float * int * int) ref option
286 ; mutable paxmark
: mark
287 ; mutable leftscroll
: bool
288 ; mutable title
: string
289 ; mutable lastvisit
: float
292 | Csingle
of singlecolumn
293 | Cmulti
of multicolumns
294 | Csplit
of splitcolumns
299 | Olaunch
of launchcommand
300 | Oremote
of (filename
* pageno
)
301 | Oremotedest
of (filename
* destname
)
302 | Ohistory
of (filename
* (conf
* outline list
* x
* anchor
))
303 | Oaction
of (unit -> unit)
304 and outline
= (caption
* outlinelevel
* outlinekind
)
305 and outlinelevel
= int
323 type tile
= opaque
* pixmapsize
* elapsed
324 and elapsed
= float;;
325 type pagemapkey
= pageno
* gen
;;
326 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
331 | Loading
of (page
* gen
)
333 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
335 | Outlining
of outline list
338 type mpos
= int * int
340 | Msel
of (mpos
* mpos
)
342 | Mscrolly
| Mscrollx
343 | Mzoom
of (buttonno
* step
)
344 | Mzoomrect
of (mpos
* mpos
)
351 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
352 | Textentry
of (textentry
* onleave
)
354 | LinkNav
of linktarget
355 and onleave
= leavetextentrystatus
-> unit
356 and leavetextentrystatus
= | Cancel
| Confirm
357 and helpitem
= string * int * action
360 | Action
of (uioh
-> uioh
)
362 | Ltexact
of (pageno
* direction
)
363 | Ltgendir
of direction
364 | Ltnotready
of (pageno
* direction
)
365 and direction
= int (* -1, 0, 1 *)
366 and textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
367 and onkey
= string -> int -> te
368 and ondone
= string -> unit
369 and histcancel
= unit -> unit
370 and onhist
= ((histcmd
-> string) * histcancel
)
371 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
372 and cancelonempty
= bool
377 | TEswitch
of textentry
389 { mutable ss
: Unix.file_descr
390 ; mutable wsfd
: Unix.file_descr
391 ; mutable errfd
: Unix.file_descr
option
392 ; mutable stderr
: Unix.file_descr
393 ; mutable errmsgs
: Buffer.t
394 ; mutable newerrmsgs
: bool
398 ; mutable anchor
: anchor
399 ; mutable ranchors
: (string * string * anchor
* string) list
401 ; mutable layout
: page list
402 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
403 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
404 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
405 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
406 ; mutable pagecount
: int
407 ; mutable currently
: currently
408 ; mutable mstate
: mstate
409 ; mutable searchpattern
: string
410 ; mutable rects
: (pageno
* recttype
* rect
) list
411 ; mutable rects1
: (pageno
* recttype
* rect
) list
412 ; mutable text
: string
413 ; mutable winstate
: Wsi.winstate list
414 ; mutable mode
: mode
415 ; mutable uioh
: uioh
416 ; mutable outlines
: outline array
417 ; mutable bookmarks
: outline list
418 ; mutable path
: string
419 ; mutable password
: string
420 ; mutable nameddest
: string
421 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
422 ; mutable memused
: memsize
424 ; mutable throttle
: (page list
* int * float) option
425 ; mutable autoscroll
: int option
426 ; mutable ghyll
: (int option -> unit)
427 ; mutable help
: helpitem array
428 ; mutable docinfo
: (int * string) list
429 ; mutable checkerstexid
: GlTex.texture_id
option
431 ; mutable prevzoom
: (float * int)
432 ; mutable progress
: float
433 ; mutable redisplay
: bool
434 ; mutable mpos
: mpos
435 ; mutable keystate
: keystate
436 ; mutable glinks
: bool
437 ; mutable prevcolumns
: (columns
* float) option
440 ; mutable reprf
: (unit -> unit)
441 ; mutable origin
: string
442 ; mutable roam
: (unit -> unit)
443 ; mutable bzoom
: bool
444 ; mutable traw
: [`
float] Raw.t
445 ; mutable vraw
: [`
float] Raw.t
448 { pat
: string circbuf
449 ; pag
: string circbuf
450 ; nav
: anchor circbuf
451 ; sel
: string circbuf
455 let emptyanchor = (0, 0.0, 0.0);;
456 let emptykeyhash = Hashtbl.create
0;;
457 let firstgeomcmds = E.s
, [];;
459 let noreprf () = ();;
462 let nouioh : uioh
= object (self
)
464 method key _ _
= self
465 method multiclick _ _ _ _
= self
466 method button _ _ _ _ _
= self
467 method motion _ _
= self
468 method pmotion _ _
= self
469 method infochanged _
= ()
470 method scrollpw
= (0, nan
, nan
)
471 method scrollph
= (0, nan
, nan
)
472 method modehash
= emptykeyhash
473 method eformsgs
= false
474 method alwaysscrolly
= false
477 let platform_to_string = function
478 | Punknown
-> "unknown"
483 | Pcygwin
-> "Cygwin"
487 Printf.sprintf
"llpp version %s, fitz %s, ocaml %s/%d bit"
488 Help.version (fz_version
()) Sys.ocaml_version
Sys.word_size
492 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
493 let len = String.length s
in
494 if colonpos >= 0 && colonpos + 3 < len
496 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
499 try String.rindex_from s
colonpos ' '
503 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
506 | "http" | "ftp" | "mailto" ->
508 try String.index_from s
colonpos ' '
509 with Not_found
-> len
511 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
521 ; scrollb
= scrollbhv lor scrollbvv
537 ; presentation
= false
542 ; fitmodel
= FitProportional
543 ; trimmargins
= false
544 ; trimfuzz
= (0,0,0,0)
545 ; memlimit
= 32 lsl 20
550 ; bgcolor
= (0.5, 0.5, 0.5)
554 ; mustoresize
= 256 lsl 20
559 | Plinux
| Psun
| Pbsd
-> "xdg-open \"%s\""
560 | Posx
-> "open \"%s\""
561 | Pcygwin
-> "cygstart \"%s\""
562 | Punknown
-> "echo %s")
563 ; pathlauncher
= "lp \"%s\""
566 | Plinux
| Pbsd
| Psun
-> "xsel -i"
576 ; redirectstderr
= false
578 ; columns
= Csingle
[||]
584 ; wheelbypage
= false
585 ; stcmd
= "echo SyncTex"
588 ; paxmark
= Mark_word
593 let mk n
= (n
, Hashtbl.create
1) in
607 let conf = { defconf with angle
= defconf.angle
};;
610 if emptystr
conf.urilauncher
611 then (print_endline uri
; -1)
613 let url = geturl uri
in
615 then (Printf.eprintf
"obtained empty url from uri %S\n" uri
; -1)
617 let re = Str.regexp
"%s" in
618 let command = Str.global_replace
re url conf.urilauncher
in
622 "failed to execute `%s': %s\n" command (exntos exn
);
631 :: "(searching in this text works just by typing (i.e. no initial '/'))"
636 let url = geturl s
in
638 then (s
, 0, Action
(fun u
-> addpid @@ gotouri url; u
))
639 else (s
, 0, Noaction
)
644 { store
= Array.make n v
651 let cbcap b
= Array.length b
.store
;;
656 b
.wc
<- (b
.wc
+ 1) mod cap;
658 b
.len <- min
(b
.len + 1) cap;
661 let cbempty b
= b
.len = 0;;
663 let cbgetg b circular dir
=
667 let rc = b
.rc + dir
in
679 else bound
rc 0 (b
.len-1)
685 let cbget b
= cbgetg b
false;;
686 let cbgetc b
= cbgetg b
true;;
692 ; stderr
= Unix.stderr
693 ; errmsgs
= Buffer.create
0
698 ; anchor
= emptyanchor
702 ; tilelru
= Queue.create
()
703 ; pagemap
= Hashtbl.create
10
704 ; tilemap
= Hashtbl.create
10
714 ; searchpattern
= E.s
720 ; geomcmds
= firstgeomcmds
722 { nav
= cbnew 10 emptyanchor
734 ; checkerstexid
= None
735 ; prevzoom
= (1.0, 0)
749 ; traw
= Raw.create_static `
float ~
len:8
750 ; vraw
= Raw.create_static `
float ~
len:8
754 let copykeyhashes c
=
755 List.map
(fun (k
, v
) -> k
, Hashtbl.copy v
) c
.keyhashes
;
759 let d = state.winh
- h
in
760 max
conf.interpagespace
((d + 1) / 2)
763 let rowyh (c
, coverA
, coverB
) b n
=
764 if c
= 1 || (n
< coverA
|| n
>= state.pagecount
- coverB
)
766 let _, _, vy
, (_, _, h
, _) = b
.(n
) in
769 let n'
= n - coverA
in
772 let e = min
state.pagecount
(s + c
) in
773 let rec find m miny maxh
= if m
= e then miny
, maxh
else
774 let _, _, y
, (_, _, h
, _) = b
.(m
) in
775 let miny = min
miny y
in
776 let maxh = max
maxh h
in
782 let ((c
, coverA
, coverB
) as cl
), b
=
783 match conf.columns
with
784 | Csingle b
-> (1, 0, 0), b
785 | Cmulti
(c
, b
) -> c
, b
786 | Csplit
(_, b
) -> (1, 0, 0), b
788 if Array.length b
= 0
791 let rec bsearch nmin nmax
=
793 then bound nmin
0 (state.pagecount
-1)
795 let n = (nmax
+ nmin
) / 2 in
796 let vy, h
= rowyh cl b
n in
800 let ips = calcips h
in
802 let y1 = vy + h
+ ips in
806 then 0, vy + h
+ conf.interpagespace
808 let y0 = vy - conf.interpagespace
in
809 y0, y0 + h
+ conf.interpagespace
819 if n < state.pagecount
- coverB
820 then ((n-coverA
)/c
)*c
+ coverA
827 then bsearch (n+1) nmax
828 else bsearch nmin
(n-1)
831 bsearch 0 (state.pagecount
-1);
835 match conf.columns
with
836 | Cmulti
((_, _, _) as cl
, b
) ->
837 if Array.length b
> 0
839 let y, h
= rowyh cl b
(Array.length b
- 1) in
840 y + h
+ (if conf.presentation
then calcips h
else 0)
843 if Array.length b
> 0
845 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
846 y + h
+ (if conf.presentation
then calcips h
else 0)
849 if Array.length b
> 0
851 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
856 let getpageywh pageno
=
857 let pageno = bound
pageno 0 (state.pagecount
-1) in
858 match conf.columns
with
860 if Array.length b
= 0
863 let (_, _, y, (_, w
, h
, _)) = b
.(pageno) in
871 if Array.length b
= 0
874 let y, h
= rowyh cl b
pageno in
875 let (_, _, _, (_, w
, _, _)) = b
.(pageno) in
883 if Array.length b
= 0
887 let (_, _, y, (_, w
, h
, _)) = b
.(n) in
891 let getpageyh pageno =
892 let y,_,h
= getpageywh pageno in
896 let getpagedim pageno =
899 | (n, _, _, _) as pdim
:: rest
->
901 then (if n = pageno then pdim
else ppdim
)
906 f (-1, -1, -1, -1) state.pdims
909 let getpagey pageno = fst
(getpageyh pageno);;
913 let coloff = l
.pagecol
* l
.pageh
in
914 float (l
.pagey
+ coloff) /. float l
.pageh
922 then float l
.pagedispy
/. float (calcips l
.pageh
)
923 else float l
.pagedispy
/. float conf.interpagespace
926 (l
.pageno, top, dtop)
930 match state.layout
with
931 | l
:: _ -> getanchor1 l
933 let n = page_of_y state.y in
937 let y, h
= getpageyh n in
938 let dy = y - state.y in
942 let ips = calcips h
in
943 float (dy + ips) /. float ips
945 float dy /. float conf.interpagespace
950 let fontpath = ref E.s;;
952 type historder
= [ `lastvisit
| `title
| `path
| `file
];;
953 let historder : historder ref = ref `lastvisit
;;
956 Map.Make
(struct type t
= (int * int) let compare = compare end);;
961 let l = String.length
s in
962 let b = Buffer.create
l in
968 try Sys.getenv
"HOME"
971 ("Can not determine home directory location: " ^ exntos exn
);
975 let modifier_of_string = function
976 | "alt" -> Wsi.altmask
977 | "shift" -> Wsi.shiftmask
978 | "ctrl" | "control" -> Wsi.ctrlmask
979 | "meta" -> Wsi.metamask
984 let r = Str.regexp
"-" in
986 let elems = Str.full_split
r s in
989 let m1 = modifier_of_string s in
991 then (Wsi.namekey
s, m
)
994 | Str.Delim
s when n land 1 = 0 -> g s
996 | Str.Delim
_ -> (k
, m
)
998 let rec loop n k m
= function
1001 let k, m
= f n k m x
in
1007 let keys_of_string =
1008 let r = Str.regexp
"[ \t]" in
1010 let elems = Str.split
r s in
1011 List.map
key_of_string elems
1014 let config_of c attrs
=
1018 | "scroll-bar-width" -> { c
with scrollbw
= max
0 (int_of_string v
) }
1019 | "scroll-handle-height" -> { c
with scrollh
= max
0 (int_of_string v
) }
1020 | "case-insensitive-search" -> { c
with icase
= bool_of_string v
}
1021 | "preload" -> { c
with preload
= bool_of_string v
}
1022 | "page-bias" -> { c
with pagebias
= int_of_string v
}
1023 | "scroll-step" -> { c
with scrollstep
= max
1 (int_of_string v
) }
1024 | "horizontal-scroll-step" ->
1025 { c
with hscrollstep
= max
(int_of_string v
) 1 }
1026 | "auto-scroll-step" ->
1027 { c
with autoscrollstep
= max
0 (int_of_string v
) }
1028 | "max-height-fit" -> { c
with maxhfit
= bool_of_string v
}
1029 | "crop-hack" -> { c
with crophack
= bool_of_string v
}
1032 match String.lowercase v
with
1033 | "true" -> Some infinity
1035 | f -> Some
(float_of_string
f)
1037 { c
with maxwait
= mw}
1038 | "highlight-links" -> { c
with hlinks
= bool_of_string v
}
1039 | "under-cursor-info" -> { c
with underinfo
= bool_of_string v
}
1040 | "vertical-margin" ->
1041 { c
with interpagespace
= max
0 (int_of_string v
) }
1043 let zoom = float_of_string v
/. 100. in
1044 let zoom = max
zoom 0.0 in
1045 { c
with zoom = zoom }
1046 | "presentation" -> { c
with presentation
= bool_of_string v
}
1047 | "rotation-angle" -> { c
with angle
= int_of_string v
}
1048 | "width" -> { c
with cwinw
= max
20 (int_of_string v
) }
1049 | "height" -> { c
with cwinh
= max
20 (int_of_string v
) }
1050 | "persistent-bookmarks" -> { c
with savebmarks
= bool_of_string v
}
1051 | "proportional-display" ->
1054 then FitProportional
1057 { c
with fitmodel
= fm }
1058 | "fit-model" -> { c
with fitmodel
= FMTE.of_string v
}
1059 | "pixmap-cache-size" ->
1060 { c
with memlimit
= max
2 (int_of_string_with_suffix v
) }
1061 | "tex-count" -> { c
with texcount
= max
1 (int_of_string v
) }
1062 | "slice-height" -> { c
with sliceheight
= max
2 (int_of_string v
) }
1063 | "thumbnail-width" -> { c
with thumbw
= max
2 (int_of_string v
) }
1064 | "persistent-location" -> { c
with jumpback
= bool_of_string v
}
1065 | "background-color" -> { c
with bgcolor
= color_of_string v
}
1066 | "tile-width" -> { c
with tilew
= max
2 (int_of_string v
) }
1067 | "tile-height" -> { c
with tileh
= max
2 (int_of_string v
) }
1068 | "mupdf-store-size" ->
1069 { c
with mustoresize
= max
1024 (int_of_string_with_suffix v
) }
1070 | "checkers" -> { c
with checkers
= bool_of_string v
}
1071 | "aalevel" -> { c
with aalevel
= max
0 (int_of_string v
) }
1072 | "trim-margins" -> { c
with trimmargins
= bool_of_string v
}
1073 | "trim-fuzz" -> { c
with trimfuzz
= irect_of_string v
}
1074 | "uri-launcher" -> { c
with urilauncher
= unent v
}
1075 | "path-launcher" -> { c
with pathlauncher
= unent v
}
1076 | "color-space" -> { c
with colorspace
= CSTE.of_string v
}
1077 | "invert-colors" -> { c
with invert
= bool_of_string v
}
1078 | "brightness" -> { c
with colorscale
= float_of_string v
}
1079 | "redirectstderr" -> { c
with redirectstderr
= bool_of_string v
}
1080 | "ghyllscroll" -> { c
with ghyllscroll
= ghyllscroll_of_string v
}
1082 let (n, _, _) as nab
= multicolumns_of_string v
in
1084 then { c
with columns
= Csplit
(-n, E.a
) }
1085 else { c
with columns
= Cmulti
(nab
, E.a
) }
1086 | "birds-eye-columns" ->
1087 { c
with beyecolumns
= Some
(max
(int_of_string v
) 2) }
1088 | "selection-command" -> { c
with selcmd
= unent v
}
1089 | "synctex-command" -> { c
with stcmd
= unent v
}
1090 | "pax-command" -> { c
with paxcmd
= unent v
}
1091 | "askpass-command" -> { c
with passcmd
= unent v
}
1092 | "savepath-command" -> { c
with savecmd
= unent v
}
1093 | "update-cursor" -> { c
with updatecurs
= bool_of_string v
}
1094 | "hint-font-size" -> { c
with hfsize
= bound
(int_of_string v
) 5 100 }
1095 | "page-scroll-scale" -> { c
with pgscale
= float_of_string v
}
1096 | "use-pbo" -> { c
with usepbo
= bool_of_string v
}
1097 | "wheel-scrolls-pages" -> { c
with wheelbypage
= bool_of_string v
}
1098 | "horizontal-scrollbar-visible" ->
1101 then c
.scrollb
lor scrollbhv
1102 else c
.scrollb
land (lnot
scrollbhv)
1104 { c
with scrollb
= b }
1105 | "vertical-scrollbar-visible" ->
1108 then c
.scrollb
lor scrollbvv
1109 else c
.scrollb
land (lnot
scrollbvv)
1111 { c
with scrollb
= b }
1112 | "remote-in-a-new-instance" -> { c
with riani
= bool_of_string v
}
1116 then Some
(ref (0.0, 0, 0))
1118 | "point-and-x-mark" -> { c
with paxmark
= MTE.of_string v
}
1119 | "scroll-bar-on-the-left" -> { c
with leftscroll
= bool_of_string v
}
1120 | "title" -> { c
with title
= unent v
}
1121 | "last-visit" -> { c
with lastvisit
= float_of_string v
}
1124 prerr_endline
("Error processing attribute (`" ^
1125 k ^
"'=`" ^ v ^
"'): " ^ exntos exn
);
1128 let rec fold c
= function
1131 let c = apply c k v
in
1134 fold { c with keyhashes
= copykeyhashes c } attrs
;
1137 let fromstring f pos
n v
d =
1140 dolog
"Error processing attribute (%S=%S) at %d\n%s"
1141 n v pos
(exntos exn
)
1146 let bookmark_of attrs
=
1147 let rec fold title page rely visy
= function
1148 | ("title", v
) :: rest
-> fold v page rely visy rest
1149 | ("page", v
) :: rest
-> fold title v rely visy rest
1150 | ("rely", v
) :: rest
-> fold title page v visy rest
1151 | ("visy", v
) :: rest
-> fold title page rely v rest
1152 | _ :: rest
-> fold title page rely visy rest
1153 | [] -> title
, page
, rely
, visy
1155 fold "invalid" "0" "0" "0" attrs
1159 let rec fold path page rely pan visy
= function
1160 | ("path", v
) :: rest
-> fold v page rely pan visy rest
1161 | ("page", v
) :: rest
-> fold path v rely pan visy rest
1162 | ("rely", v
) :: rest
-> fold path page v pan visy rest
1163 | ("pan", v
) :: rest
-> fold path page rely v visy rest
1164 | ("visy", v
) :: rest
-> fold path page rely pan v rest
1165 | _ :: rest
-> fold path page rely pan visy rest
1166 | [] -> path
, page
, rely
, pan
, visy
1168 fold E.s "0" "0" "0" "0" attrs
1172 let rec fold rs ls
= function
1173 | ("out", v
) :: rest
-> fold v ls rest
1174 | ("in", v
) :: rest
-> fold rs v rest
1175 | _ :: rest
-> fold ls rs rest
1181 let setconf dst src
=
1182 dst
.scrollbw
<- src
.scrollbw
;
1183 dst
.scrollh
<- src
.scrollh
;
1184 dst
.icase
<- src
.icase
;
1185 dst
.preload
<- src
.preload
;
1186 dst
.pagebias
<- src
.pagebias
;
1187 dst
.verbose
<- src
.verbose
;
1188 dst
.scrollstep
<- src
.scrollstep
;
1189 dst
.maxhfit
<- src
.maxhfit
;
1190 dst
.crophack
<- src
.crophack
;
1191 dst
.autoscrollstep
<- src
.autoscrollstep
;
1192 dst
.maxwait
<- src
.maxwait
;
1193 dst
.hlinks
<- src
.hlinks
;
1194 dst
.underinfo
<- src
.underinfo
;
1195 dst
.interpagespace
<- src
.interpagespace
;
1196 dst
.zoom <- src
.zoom;
1197 dst
.presentation
<- src
.presentation
;
1198 dst
.angle
<- src
.angle
;
1199 dst
.cwinw
<- src
.cwinw
;
1200 dst
.cwinh
<- src
.cwinh
;
1201 dst
.savebmarks
<- src
.savebmarks
;
1202 dst
.memlimit
<- src
.memlimit
;
1203 dst
.fitmodel
<- src
.fitmodel
;
1204 dst
.texcount
<- src
.texcount
;
1205 dst
.sliceheight
<- src
.sliceheight
;
1206 dst
.thumbw
<- src
.thumbw
;
1207 dst
.jumpback
<- src
.jumpback
;
1208 dst
.bgcolor
<- src
.bgcolor
;
1209 dst
.tilew
<- src
.tilew
;
1210 dst
.tileh
<- src
.tileh
;
1211 dst
.mustoresize
<- src
.mustoresize
;
1212 dst
.checkers
<- src
.checkers
;
1213 dst
.aalevel
<- src
.aalevel
;
1214 dst
.trimmargins
<- src
.trimmargins
;
1215 dst
.trimfuzz
<- src
.trimfuzz
;
1216 dst
.urilauncher
<- src
.urilauncher
;
1217 dst
.colorspace
<- src
.colorspace
;
1218 dst
.invert
<- src
.invert
;
1219 dst
.colorscale
<- src
.colorscale
;
1220 dst
.redirectstderr
<- src
.redirectstderr
;
1221 dst
.ghyllscroll
<- src
.ghyllscroll
;
1222 dst
.columns
<- src
.columns
;
1223 dst
.beyecolumns
<- src
.beyecolumns
;
1224 dst
.selcmd
<- src
.selcmd
;
1225 dst
.updatecurs
<- src
.updatecurs
;
1226 dst
.pathlauncher
<- src
.pathlauncher
;
1227 dst
.keyhashes
<- copykeyhashes src
;
1228 dst
.hfsize
<- src
.hfsize
;
1229 dst
.hscrollstep
<- src
.hscrollstep
;
1230 dst
.pgscale
<- src
.pgscale
;
1231 dst
.usepbo
<- src
.usepbo
;
1232 dst
.wheelbypage
<- src
.wheelbypage
;
1233 dst
.stcmd
<- src
.stcmd
;
1234 dst
.paxcmd
<- src
.paxcmd
;
1235 dst
.passcmd
<- src
.passcmd
;
1236 dst
.savecmd
<- src
.savecmd
;
1237 dst
.scrollb
<- src
.scrollb
;
1238 dst
.riani
<- src
.riani
;
1239 dst
.paxmark
<- src
.paxmark
;
1240 dst
.leftscroll
<- src
.leftscroll
;
1241 dst
.title
<- src
.title
;
1245 else Some
((ref (0.0, 0, 0)));
1248 let findkeyhash c name =
1249 try List.assoc
name c.keyhashes
1250 with Not_found
-> failwith
("invalid mode name `" ^
name ^
"'")
1254 let h = Hashtbl.create
10 in
1255 let dc = { defconf with angle
= defconf.angle
} in
1256 let rec toplevel v t spos
_ =
1258 | Vdata
| Vcdata
| Vend
-> v
1259 | Vopen
("llppconfig", _, closed
) ->
1262 else { v
with f = llppconfig
}
1264 error
"unexpected subelement at top level" s spos
1265 | Vclose
_ -> error
"unexpected close at top level" s spos
1267 and llppconfig v t spos
_ =
1269 | Vdata
| Vcdata
-> v
1270 | Vend
-> error
"unexpected end of input in llppconfig" s spos
1271 | Vopen
("defaults", attrs
, closed
) ->
1272 let c = config_of dc attrs
in
1276 else { v
with f = defaults
}
1278 | Vopen
("ui-font", attrs
, closed
) ->
1279 let rec getsize size
= function
1281 | ("size", v
) :: rest
->
1283 fromstring int_of_string spos
"size" v
fstate.fontsize
in
1285 | l -> getsize size l
1287 fstate.fontsize
<- getsize fstate.fontsize attrs
;
1290 else { v
with f = uifont
(Buffer.create
10) }
1292 | Vopen
("doc", attrs
, closed
) ->
1293 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
1294 let path = unent pathent
1295 and pageno = fromstring int_of_string spos
"page" spage
0
1296 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1297 and pan
= fromstring int_of_string spos
"pan" span
0
1298 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1299 let c = config_of dc attrs
in
1300 let anchor = (pageno, rely
, visy
) in
1302 then (Hashtbl.add
h path (c, [], pan
, anchor); v
)
1303 else { v
with f = doc
path pan
anchor c [] }
1306 error
"unexpected subelement in llppconfig" s spos
1308 | Vclose
"llppconfig" -> { v
with f = toplevel }
1309 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
1311 and defaults v t spos
_ =
1313 | Vdata
| Vcdata
-> v
1314 | Vend
-> error
"unexpected end of input in defaults" s spos
1315 | Vopen
("keymap", attrs
, closed
) ->
1317 try List.assoc
"mode" attrs
1318 with Not_found
-> "global" in
1323 let h = findkeyhash dc modename in
1324 KeyMap.iter
(Hashtbl.replace
h) keymap
;
1327 { v
with f = pkeymap
ret KeyMap.empty
}
1329 | Vopen
(_, _, _) ->
1330 error
"unexpected subelement in defaults" s spos
1332 | Vclose
"defaults" ->
1333 { v
with f = llppconfig
}
1335 | Vclose
_ -> error
"unexpected close in defaults" s spos
1337 and uifont
b v t spos
epos =
1340 Buffer.add_substring
b s spos
(epos - spos
);
1342 | Vopen
(_, _, _) ->
1343 error
"unexpected subelement in ui-font" s spos
1344 | Vclose
"ui-font" ->
1345 if emptystr
!fontpath
1346 then fontpath := Buffer.contents
b;
1347 { v
with f = llppconfig
}
1348 | Vclose
_ -> error
"unexpected close in ui-font" s spos
1349 | Vend
-> error
"unexpected end of input in ui-font" s spos
1351 and doc
path pan
anchor c bookmarks v t spos
_ =
1353 | Vdata
| Vcdata
-> v
1354 | Vend
-> error
"unexpected end of input in doc" s spos
1355 | Vopen
("bookmarks", _, closed
) ->
1358 else { v
with f = pbookmarks
path pan
anchor c bookmarks
}
1360 | Vopen
("keymap", attrs
, closed
) ->
1362 try List.assoc
"mode" attrs
1363 with Not_found
-> "global"
1369 let h = findkeyhash c modename in
1370 KeyMap.iter
(Hashtbl.replace
h) keymap
;
1371 doc
path pan
anchor c bookmarks
1373 { v
with f = pkeymap
ret KeyMap.empty
}
1375 | Vopen
(_, _, _) ->
1376 error
"unexpected subelement in doc" s spos
1379 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
1380 { v
with f = llppconfig
}
1382 | Vclose
_ -> error
"unexpected close in doc" s spos
1384 and pkeymap
ret keymap v t spos
_ =
1386 | Vdata
| Vcdata
-> v
1387 | Vend
-> error
"unexpected end of input in keymap" s spos
1388 | Vopen
("map", attrs
, closed
) ->
1389 let r, l = map_of attrs
in
1390 let kss = fromstring keys_of_string spos
"in" r [] in
1391 let lss = fromstring keys_of_string spos
"out" l [] in
1395 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
1396 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
1399 then { v
with f = pkeymap
ret keymap }
1402 { v
with f = skip
"map" f }
1405 error
"unexpected subelement in keymap" s spos
1407 | Vclose
"keymap" ->
1408 { v
with f = ret keymap }
1410 | Vclose
_ -> error
"unexpected close in keymap" s spos
1412 and pbookmarks
path pan
anchor c bookmarks v t spos
_ =
1414 | Vdata
| Vcdata
-> v
1415 | Vend
-> error
"unexpected end of input in bookmarks" s spos
1416 | Vopen
("item", attrs
, closed
) ->
1417 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
1418 let page = fromstring int_of_string spos
"page" spage
0
1419 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1420 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1422 (unent titleent, 0, Oanchor
(page, rely
, visy
)) :: bookmarks
1425 then { v
with f = pbookmarks
path pan
anchor c bookmarks }
1428 { v
with f = skip
"item" f }
1431 error
"unexpected subelement in bookmarks" s spos
1433 | Vclose
"bookmarks" ->
1434 { v
with f = doc
path pan
anchor c bookmarks }
1436 | Vclose
_ -> Parser.parse_error
"unexpected close in bookmarks" s spos
1438 and skip tag
f v t spos
_ =
1440 | Vdata
| Vcdata
-> v
1442 Parser.parse_error
("unexpected end of input in skipped " ^ tag
) s spos
1443 | Vopen
(tag'
, _, closed
) ->
1447 let f'
() = { v
with f = skip tag
f } in
1448 { v
with f = skip tag'
f'
}
1452 else Parser.parse_error
("unexpected close in skipped " ^ tag
) s spos
1455 parse
{ f = toplevel; accu
= () } s;
1461 let len = in_channel_length ic
in
1462 let s = really_input_string ic
len in
1465 | Parse_error
(msg
, s, pos
) ->
1466 let subs = subs s pos
in
1467 Utils.error
"parse error: %s: at %d [..%s..]" msg pos
subs
1470 failwith
("config load error: " ^ exntos exn
)
1475 let xdgconfdir = Utils.getenvwithdef
"XDG_CONFIG_HOME" E.s in
1476 if xdgconfdir == E.s
1479 let dir = Filename.concat
home ".config" in
1480 if Sys.is_directory
dir then dir else home
1484 Filename.concat
dir "llpp.conf"
1487 let confpath = ref defconfpath;;
1490 if Sys.file_exists
!confpath
1493 (try Some
(open_in_bin
!confpath)
1496 ("Error opening configuration file `" ^
!confpath ^
"': " ^
1507 ("Error loading configuration from `" ^
!confpath ^
"': " ^
1516 f (Hashtbl.create
0, defconf)
1525 (fun path (conf, _, _, _) ((_, besttime
) as best
) ->
1526 if conf.lastvisit
> besttime
1527 then (path, conf.lastvisit
)
1530 (state.path, -.infinity
)
1534 let pc, pb
, px
, pa
=
1537 if emptystr
state.origin
1541 let absname = abspath
path in
1542 Hashtbl.find h absname
1543 with Not_found
-> dc, [], 0, emptyanchor
1547 state.bookmarks <- pb
;
1550 then state.anchor <- pa
;
1551 cbput state.hists
.nav pa
;
1557 let gethist listref
=
1560 Hashtbl.fold (fun path (pc, pb
, px
, pa
) accu
->
1561 (path, pc, pb
, px
, pa
) :: accu
)
1568 let add_attrs bb always
dc c time
=
1571 then Printf.bprintf bb
"\n %s='%b'" s a
1574 then Printf.bprintf bb
"\n %s='%b'" s (a
!= None
)
1577 then Printf.bprintf bb
"\n %s='%d'" s a
1580 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a
)
1583 then Printf.bprintf bb
"\n %s='%g'" s (a
*.100.)
1586 then Printf.bprintf bb
"\n %s='%f'" s a
1590 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a
)
1594 Printf.bprintf bb
"\n %s='%s'" s (CSTE.to_string a
)
1598 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a
)
1602 Printf.bprintf bb
"\n %s='%s'" s (enent a
0 (String.length a
))
1607 | Some
(_N
, _A
, _B
) ->
1608 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
1613 Printf.bprintf bb
"\n %s='none'" s
1623 else string_of_float
f
1625 Printf.bprintf bb
"\n %s='%s'" s v
1630 | Cmulti
((n, a
, b), _) when n > 1 ->
1631 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a
b
1632 | Csplit
(n, _) when n > 1 ->
1633 Printf.bprintf bb
"\n %s='%d'" s ~
-n
1634 | Cmulti
_ | Csplit
_ | Csingle
_ -> ()
1639 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
1644 Printf.bprintf bb
"\n %s='%s'" s (FMTE.to_string a
)
1648 Printf.bprintf bb
"\n %s='%b'" s (a
land m
!= 0)
1652 Printf.bprintf bb
"\n %s='%s'" s (MTE.to_string a
)
1654 oi
"width" c.cwinw
dc.cwinw
;
1655 oi
"height" c.cwinh
dc.cwinh
;
1656 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
1657 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
1658 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
1659 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
1660 ob "case-insensitive-search" c.icase
dc.icase
;
1661 ob "preload" c.preload
dc.preload
;
1662 oi
"page-bias" c.pagebias
dc.pagebias
;
1663 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
1664 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
1665 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
1666 ob "crop-hack" c.crophack
dc.crophack
;
1667 oW
"throttle" c.maxwait
dc.maxwait
;
1668 ob "highlight-links" c.hlinks
dc.hlinks
;
1669 ob "under-cursor-info" c.underinfo
dc.underinfo
;
1670 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
1671 oz
"zoom" c.zoom dc.zoom;
1672 ob "presentation" c.presentation
dc.presentation
;
1673 oi
"rotation-angle" c.angle
dc.angle
;
1674 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
1675 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
1676 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
1677 oi
"tex-count" c.texcount
dc.texcount
;
1678 oi
"slice-height" c.sliceheight
dc.sliceheight
;
1679 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
1680 ob "persistent-location" c.jumpback
dc.jumpback
;
1681 oc
"background-color" c.bgcolor
dc.bgcolor
;
1682 oi
"tile-width" c.tilew
dc.tilew
;
1683 oi
"tile-height" c.tileh
dc.tileh
;
1684 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
1685 ob "checkers" c.checkers
dc.checkers
;
1686 oi
"aalevel" c.aalevel
dc.aalevel
;
1687 ob "trim-margins" c.trimmargins
dc.trimmargins
;
1688 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
1689 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
1690 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
1691 oC
"color-space" c.colorspace
dc.colorspace
;
1692 ob "invert-colors" c.invert
dc.invert
;
1693 oF
"brightness" c.colorscale
dc.colorscale
;
1694 ob "redirectstderr" c.redirectstderr
dc.redirectstderr
;
1695 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
1696 oco
"columns" c.columns
dc.columns
;
1697 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
1698 os
"selection-command" c.selcmd
dc.selcmd
;
1699 os
"synctex-command" c.stcmd
dc.stcmd
;
1700 os
"pax-command" c.paxcmd
dc.paxcmd
;
1701 os
"askpass-command" c.passcmd
dc.passcmd
;
1702 os
"savepath-command" c.savecmd
dc.savecmd
;
1703 ob "update-cursor" c.updatecurs
dc.updatecurs
;
1704 oi
"hint-font-size" c.hfsize
dc.hfsize
;
1705 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
1706 oF
"page-scroll-scale" c.pgscale
dc.pgscale
;
1707 ob "use-pbo" c.usepbo
dc.usepbo
;
1708 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
1709 ob "remote-in-a-new-instance" c.riani
dc.riani
;
1710 op
"point-and-x" c.pax
dc.pax
;
1711 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
1712 ob "scroll-bar-on-the-left" c.leftscroll
dc.leftscroll
;
1714 then os
"title" c.title
dc.title
;
1715 oF
"last-visit" (snd
(modf time
)) 0.0;
1718 let keymapsbuf always
dc c =
1719 let bb = Buffer.create
16 in
1720 let rec loop = function
1722 | (modename, h) :: rest
->
1723 let dh = findkeyhash dc modename in
1724 if always
|| h <> dh
1726 if Hashtbl.length
h > 0
1728 if Buffer.length
bb > 0
1729 then Buffer.add_char
bb '
\n'
;
1730 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
1731 Hashtbl.iter
(fun i o
->
1732 let isdifferent = always
||
1734 let dO = Hashtbl.find dh i
in
1736 with Not_found
-> true
1741 if Wsi.withctrl m
then Buffer.add_string
bb "ctrl-";
1742 if Wsi.withalt m
then Buffer.add_string
bb "alt-";
1743 if Wsi.withshift m
then Buffer.add_string
bb "shift-";
1744 if Wsi.withmeta m
then Buffer.add_string
bb "meta-";
1745 Buffer.add_string
bb (Wsi.keyname
k);
1748 let rec loop = function
1750 | km
:: [] -> addkm km
1751 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
1755 Buffer.add_string
bb "<map in='";
1759 Buffer.add_string
bb "' out='";
1761 Buffer.add_string
bb "'/>\n"
1764 Buffer.add_string
bb "' out='";
1766 Buffer.add_string
bb "'/>\n"
1768 | KMmulti
(ins
, kms
) ->
1769 Buffer.add_char
bb ' '
;
1771 Buffer.add_string
bb "' out='";
1773 Buffer.add_string
bb "'/>\n"
1775 Buffer.add_string
bb "</keymap>";
1784 let save1 bb leavebirdseye x
h dc =
1785 let uifontsize = fstate.fontsize
in
1786 let dc = if conf.bedefault
then conf else dc in
1787 Buffer.add_string
bb "<llppconfig>\n";
1789 if nonemptystr
!fontpath
1791 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
1797 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
1800 Buffer.add_string
bb "<defaults";
1801 add_attrs bb true dc dc nan
;
1802 let kb = keymapsbuf true dc dc in
1803 if Buffer.length
kb > 0
1805 Buffer.add_string
bb ">\n";
1806 Buffer.add_buffer
bb kb;
1807 Buffer.add_string
bb "\n</defaults>\n";
1809 else Buffer.add_string
bb "/>\n";
1811 let adddoc path pan
anchor c bookmarks time
=
1812 if bookmarks == [] && c = dc && anchor = emptyanchor
1815 Printf.bprintf
bb "<doc path='%s'"
1816 (enent
path 0 (String.length
path));
1818 if anchor <> emptyanchor
1820 let n, rely
, visy
= anchor in
1821 Printf.bprintf
bb "\n page='%d'" n;
1824 Printf.bprintf
bb " rely='%f'" rely
1826 if abs_float visy
> 1e-6
1828 Printf.bprintf
bb " visy='%f'" visy
1833 then Printf.bprintf
bb " pan='%d'" pan
;
1835 add_attrs bb false dc c time
;
1836 let kb = keymapsbuf false dc c in
1838 begin match bookmarks with
1840 if Buffer.length
kb > 0
1842 Buffer.add_string
bb ">\n";
1843 Buffer.add_buffer
bb kb;
1844 Buffer.add_string
bb "\n</doc>\n";
1846 else Buffer.add_string
bb "/>\n"
1848 Buffer.add_string
bb ">\n<bookmarks>\n";
1849 List.iter
(fun (title
, _, kind
) ->
1850 begin match kind
with
1851 | Oanchor
(page, rely
, visy
) ->
1853 "<item title='%s' page='%d'"
1854 (enent title
0 (String.length title
))
1859 Printf.bprintf
bb " rely='%f'" rely
1861 if abs_float visy
> 1e-6
1863 Printf.bprintf
bb " visy='%f'" visy
1865 | Ohistory
_ | Onone
| Ouri
_ | Oremote
_
1866 | Oremotedest
_ | Olaunch
_ | Oaction
_ ->
1867 failwith
"unexpected link in bookmarks"
1869 Buffer.add_string
bb "/>\n";
1871 Buffer.add_string
bb "</bookmarks>";
1872 if Buffer.length
kb > 0
1874 Buffer.add_string
bb "\n";
1875 Buffer.add_buffer
bb kb;
1877 Buffer.add_string
bb "\n</doc>\n";
1883 match state.mode
with
1884 | Birdseye
(c, pan, _, _, _) ->
1886 match conf.columns
with
1887 | Cmulti
((c, _, _), _) -> Some
c
1891 match c.columns
with
1892 | Cmulti
(c, _) -> Cmulti
(c, E.a
)
1893 | Csingle
_ -> Csingle
E.a
1894 | Csplit
_ -> failwith
"quit from bird's eye while split"
1896 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
1899 | LinkNav
_ -> x
, conf
1901 let docpath = abspath
state.path in
1902 adddoc docpath pan (getanchor ())
1904 let autoscrollstep =
1905 match state.autoscroll
with
1907 | None
-> conf.autoscrollstep
1909 begin match state.mode
with
1910 | Birdseye beye
-> leavebirdseye beye
true
1915 { conf with autoscrollstep = autoscrollstep }
1917 (if conf.savebmarks
then state.bookmarks else [])
1920 Hashtbl.iter
(fun path (c, bookmarks, x
, anchor) ->
1921 if docpath <> abspath
path
1922 then adddoc path x
anchor c bookmarks c.lastvisit
1924 Buffer.add_string
bb "</llppconfig>\n";
1928 let save leavebirdseye
=
1929 let relx = float state.x
/. float state.winw
in
1931 let cx w = truncate
(relx *. float w) in
1933 (fun (w, h, x
) ws
->
1935 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
1936 | Wsi.MaxVert
-> (w, conf.cwinh
, x
)
1937 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
1939 (state.winw
, state.winh
, state.x
) state.winstate
1943 let bb = Buffer.create
32768 in
1945 save1 bb leavebirdseye x
h dc
1947 if load1 save2 && Buffer.length
bb > 0
1950 let tmp = !confpath ^
".tmp" in
1951 let oc = open_out_bin
tmp in
1952 Buffer.output_buffer
oc bb;
1954 Unix.rename
tmp !confpath;
1957 ("error while saving configuration: " ^ exntos exn
)
1962 let n'
= Unix.write fdo
(Bytes.of_string s) 0 n in
1964 then Utils.error
"Unix.write %d = %d" n n'
1967 try Unix.read fdi
s 0 n
1968 with exn
-> Utils.error
"reading gc pipe %s" (exntos exn
) in
1969 let href = ref (Hashtbl.create
0) in
1970 let cref = ref defconf in
1972 let f path (pc, _pb
, _px
, _pa
) =
1974 Printf.sprintf
"%s\000%ld\000" path (Int32.of_float
pc.lastvisit
)
1976 wr s (String.length
s)
1981 Unix.shutdown fdo
Unix.SHUTDOWN_SEND
;
1984 ignore
(load1 push);
1986 let b = Buffer.create
32768 in
1987 let s = Bytes.create
4096 in
1989 let n = rd s (Bytes.length
s) in
1991 then Buffer.contents
b
1992 else (Buffer.add_subbytes
b s 0 n; f ())
1997 match String.index_from
s ppos '
\000'
with
2000 try String.index_from
s (zpos1
+1) '
\000'
with Not_found
-> -1 in
2002 then error
"Incorrect gc input in (%S) at %d" s zpos1
2004 let okey = StringLabels.sub
s ~pos
:ppos ~
len:(zpos1
-ppos
) in
2005 let nkey = StringLabels.sub
s ~pos
:(zpos1
+1) ~
len:(zpos2-zpos1
-1) in
2007 then (Hashtbl.remove
!href okey; f (zpos2+1))
2010 try Hashtbl.find !href okey
2011 with Not_found
-> Utils.error
"gc: could not find %S" okey
2013 Hashtbl.remove
!href okey;
2014 Hashtbl.replace
!href nkey v;
2016 | exception Not_found
-> ()
2019 let bb = Buffer.create
32768 in
2020 let save2 (_h
, dc) = save1 bb (fun _ _ -> ()) 0 !href dc in
2021 if load1 save2 && Buffer.length
bb > 0
2024 let tmp = !confpath ^
".tmp" in
2025 let oc = open_out_bin
tmp in
2026 Buffer.output_buffer
oc bb;
2028 Unix.rename
tmp !confpath;
2031 ("error while saving configuration: " ^ exntos exn
)
2035 let logcurrently = function
2036 | Idle
-> dolog
"Idle"
2037 | Loading
(l, gen
) ->
2038 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
2039 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col
, row
, tilew
, tileh
) ->
2041 "Tiling %d[%d,%d] page=%s cs=%s angle"
2042 l.pageno col row
(~
> pageopaque
)
2043 (CSTE.to_string colorspace
)
2045 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
2046 angle gen
conf.angle
state.gen
2048 conf.tilew
conf.tileh