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 redirectstderr
: bool
267 ; mutable ghyllscroll
: (int * int * int) option
268 ; mutable columns
: columns
269 ; mutable beyecolumns
: columncount
option
270 ; mutable selcmd
: string
271 ; mutable paxcmd
: string
272 ; mutable passcmd
: string
273 ; mutable savecmd
: string
274 ; mutable updatecurs
: bool
275 ; mutable keyhashes
: (string * keyhash
) list
276 ; mutable hfsize
: int
277 ; mutable pgscale
: float
278 ; mutable usepbo
: bool
279 ; mutable wheelbypage
: bool
280 ; mutable stcmd
: string
281 ; mutable riani
: bool
282 ; mutable pax
: (float * int * int) ref option
283 ; mutable paxmark
: mark
284 ; mutable leftscroll
: bool
285 ; mutable title
: string
286 ; mutable lastvisit
: float
287 ; mutable annotinline
: bool
290 | Csingle
of singlecolumn
291 | Cmulti
of multicolumns
292 | Csplit
of splitcolumns
297 | Olaunch
of launchcommand
298 | Oremote
of (filename
* pageno
)
299 | Oremotedest
of (filename
* destname
)
300 | Ohistory
of (filename
* (conf
* outline list
* x
* anchor
* filename
))
301 | Oaction
of (unit -> unit)
302 | Oreaction
of (unit -> outline array
)
303 and outline
= (caption
* outlinelevel
* outlinekind
)
304 and outlinelevel
= int
322 type tile
= opaque
* pixmapsize
* elapsed
323 and elapsed
= float;;
324 type pagemapkey
= pageno
* gen
;;
325 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
330 | Loading
of (page
* gen
)
332 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
334 | Outlining
of outline list
337 type mpos
= int * int
339 | Msel
of (mpos
* mpos
)
341 | Mscrolly
| Mscrollx
342 | Mzoom
of (buttonno
* step
)
343 | Mzoomrect
of (mpos
* mpos
)
350 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
351 | Textentry
of (textentry
* onleave
)
353 | LinkNav
of linktarget
354 and onleave
= leavetextentrystatus
-> unit
355 and leavetextentrystatus
= | Cancel
| Confirm
356 and helpitem
= string * int * action
359 | Action
of (uioh
-> uioh
)
361 | Ltexact
of (pageno
* direction
)
362 | Ltgendir
of direction
363 | Ltnotready
of (pageno
* direction
)
364 and direction
= int (* -1, 0, 1 *)
365 and textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
366 and onkey
= string -> int -> te
367 and ondone
= string -> unit
368 and histcancel
= unit -> unit
369 and onhist
= ((histcmd
-> string) * histcancel
)
370 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
371 and cancelonempty
= bool
376 | TEswitch
of textentry
388 { mutable ss
: Unix.file_descr
389 ; mutable wsfd
: Unix.file_descr
390 ; mutable errfd
: Unix.file_descr
option
391 ; mutable stderr
: Unix.file_descr
392 ; mutable errmsgs
: Buffer.t
393 ; mutable newerrmsgs
: bool
397 ; mutable anchor
: anchor
398 ; mutable ranchors
: (string * string * anchor
* string) list
400 ; mutable layout
: page list
401 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
402 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
403 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
404 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
405 ; mutable pagecount
: int
406 ; mutable currently
: currently
407 ; mutable mstate
: mstate
408 ; mutable searchpattern
: string
409 ; mutable rects
: (pageno
* recttype
* rect
) list
410 ; mutable rects1
: (pageno
* recttype
* rect
) list
411 ; mutable text
: string
412 ; mutable winstate
: Wsi.winstate list
413 ; mutable mode
: mode
414 ; mutable uioh
: uioh
415 ; mutable outlines
: outline array
416 ; mutable bookmarks
: outline list
417 ; mutable path
: string
418 ; mutable password
: string
419 ; mutable nameddest
: string
420 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
421 ; mutable memused
: memsize
423 ; mutable throttle
: (page list
* int * float) option
424 ; mutable autoscroll
: int option
425 ; mutable ghyll
: (int option -> unit)
426 ; mutable help
: helpitem array
427 ; mutable docinfo
: (int * string) list
428 ; mutable checkerstexid
: GlTex.texture_id
option
430 ; mutable prevzoom
: (float * int)
431 ; mutable progress
: float
432 ; mutable redisplay
: bool
433 ; mutable mpos
: mpos
434 ; mutable keystate
: keystate
435 ; mutable glinks
: bool
436 ; mutable prevcolumns
: (columns
* float) option
439 ; mutable reprf
: (unit -> unit)
440 ; mutable origin
: string
441 ; mutable roam
: (unit -> unit)
442 ; mutable bzoom
: bool
443 ; mutable traw
: [`
float] Raw.t
444 ; mutable vraw
: [`
float] Raw.t
447 { pat
: string circbuf
448 ; pag
: string circbuf
449 ; nav
: anchor circbuf
450 ; sel
: string circbuf
454 let emptyanchor = (0, 0.0, 0.0);;
455 let emptykeyhash = Hashtbl.create
0;;
457 let noreprf () = ();;
460 let nouioh : uioh
= object (self
)
462 method key _ _
= self
463 method multiclick _ _ _ _
= self
464 method button _ _ _ _ _
= self
465 method motion _ _
= self
466 method pmotion _ _
= self
467 method infochanged _
= ()
468 method scrollpw
= (0, nan
, nan
)
469 method scrollph
= (0, nan
, nan
)
470 method modehash
= emptykeyhash
471 method eformsgs
= false
472 method alwaysscrolly
= false
475 let platform_to_string = function
476 | Punknown
-> "unknown"
481 | Pcygwin
-> "Cygwin"
485 Printf.sprintf
"llpp version %s, fitz %s, ocaml %s/%d bit"
486 Help.version (fz_version
()) Sys.ocaml_version
Sys.word_size
492 ; scrollb
= scrollbhv lor scrollbvv
508 ; presentation
= false
513 ; fitmodel
= FitProportional
514 ; trimmargins
= false
515 ; trimfuzz
= (0,0,0,0)
516 ; memlimit
= 32 lsl 20
521 ; bgcolor
= (0.5, 0.5, 0.5)
525 ; mustoresize
= 256 lsl 20
530 | Plinux
| Psun
| Pbsd
-> "xdg-open \"%s\""
531 | Posx
-> "open \"%s\""
532 | Pcygwin
-> "cygstart \"%s\""
533 | Punknown
-> "echo %s")
534 ; pathlauncher
= "lp \"%s\""
537 | Plinux
| Pbsd
| Psun
-> "xsel -i"
547 ; redirectstderr
= false
549 ; columns
= Csingle
[||]
555 ; wheelbypage
= false
556 ; stcmd
= "echo SyncTex"
559 ; paxmark
= Mark_word
565 let mk n
= (n
, Hashtbl.create
1) in
579 let conf = { defconf with angle
= defconf.angle
};;
582 if emptystr
conf.urilauncher
583 then print_endline uri
585 let url = geturl uri
in
587 then Printf.eprintf
"obtained empty url from uri %S\n" uri
589 let command = Str.global_replace percentsre
url conf.urilauncher
in
590 try ignore
(popen
command [])
591 with exn
-> dolog
"failed to execute `%s': %s" command (exntos exn
)
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
-> gotouri 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;;
659 ; stderr
= Unix.stderr
660 ; errmsgs
= Buffer.create
0
665 ; anchor
= emptyanchor
669 ; tilelru
= Queue.create
()
670 ; pagemap
= Hashtbl.create
10
671 ; tilemap
= Hashtbl.create
10
681 ; searchpattern
= E.s
689 { nav
= cbnew 10 emptyanchor
701 ; checkerstexid
= None
702 ; prevzoom
= (1.0, 0)
716 ; traw
= Raw.create_static `
float ~len
:8
717 ; vraw
= Raw.create_static `
float ~len
:8
721 let copykeyhashes c
=
722 List.map
(fun (k
, v
) -> k
, Hashtbl.copy v
) c
.keyhashes
;
726 let d = state.winh
- h
in
727 max
conf.interpagespace
((d + 1) / 2)
730 let rowyh (c
, coverA
, coverB
) b n
=
731 if c
= 1 || (n
< coverA
|| n
>= state.pagecount
- coverB
)
733 let _, _, vy
, (_, _, h
, _) = b
.(n
) in
736 let n'
= n - coverA
in
739 let e = min
state.pagecount
(s + c
) in
740 let rec find m miny maxh
= if m
= e then miny
, maxh
else
741 let _, _, y
, (_, _, h
, _) = b
.(m
) in
742 let miny = min
miny y
in
743 let maxh = max
maxh h
in
749 let ((c
, coverA
, coverB
) as cl
), b
=
750 match conf.columns
with
751 | Csingle b
-> (1, 0, 0), b
752 | Cmulti
(c
, b
) -> c
, b
753 | Csplit
(_, b
) -> (1, 0, 0), b
755 if Array.length b
= 0
758 let rec bsearch nmin nmax
=
760 then bound nmin
0 (state.pagecount
-1)
762 let n = (nmax
+ nmin
) / 2 in
763 let vy, h
= rowyh cl b
n in
767 let ips = calcips h
in
769 let y1 = vy + h
+ ips in
773 then 0, vy + h
+ conf.interpagespace
775 let y0 = vy - conf.interpagespace
in
776 y0, y0 + h
+ conf.interpagespace
786 if n < state.pagecount
- coverB
787 then ((n-coverA
)/c
)*c
+ coverA
794 then bsearch (n+1) nmax
795 else bsearch nmin
(n-1)
798 bsearch 0 (state.pagecount
-1);
802 match conf.columns
with
803 | Cmulti
((_, _, _) as cl
, b
) ->
804 if Array.length b
> 0
806 let y, h
= rowyh cl b
(Array.length b
- 1) in
807 y + h
+ (if conf.presentation
then calcips h
else 0)
810 if Array.length b
> 0
812 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
813 y + h
+ (if conf.presentation
then calcips h
else 0)
816 if Array.length b
> 0
818 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
823 let getpageywh pageno
=
824 let pageno = bound
pageno 0 (state.pagecount
-1) in
825 match conf.columns
with
827 if Array.length b
= 0
830 let (_, _, y, (_, w
, h
, _)) = b
.(pageno) in
838 if Array.length b
= 0
841 let y, h
= rowyh cl b
pageno in
842 let (_, _, _, (_, w
, _, _)) = b
.(pageno) in
850 if Array.length b
= 0
854 let (_, _, y, (_, w
, h
, _)) = b
.(n) in
858 let getpageyh pageno =
859 let y,_,h
= getpageywh pageno in
863 let getpagedim pageno =
866 | (n, _, _, _) as pdim
:: rest
->
868 then (if n = pageno then pdim
else ppdim
)
873 f (-1, -1, -1, -1) state.pdims
876 let getpagey pageno = fst
(getpageyh pageno);;
880 let coloff = l
.pagecol
* l
.pageh
in
881 float (l
.pagey
+ coloff) /. float l
.pageh
889 then float l
.pagedispy
/. float (calcips l
.pageh
)
890 else float l
.pagedispy
/. float conf.interpagespace
893 (l
.pageno, top, dtop)
897 match state.layout
with
898 | l
:: _ -> getanchor1 l
900 let n = page_of_y state.y in
904 let y, h
= getpageyh n in
905 let dy = y - state.y in
909 let ips = calcips h
in
910 float (dy + ips) /. float ips
912 float dy /. float conf.interpagespace
917 let fontpath = ref E.s;;
919 type historder
= [ `lastvisit
| `title
| `path
| `file
];;
922 Map.Make
(struct type t
= (int * int) let compare = compare end);;
925 let l = String.length
s in
926 let b = Buffer.create
l in
927 Parser.unent
b s 0 l;
932 try Sys.getenv
"HOME"
935 ("Can not determine home directory location: " ^ exntos exn
);
939 let modifier_of_string = function
940 | "alt" -> Wsi.altmask
941 | "shift" -> Wsi.shiftmask
942 | "ctrl" | "control" -> Wsi.ctrlmask
943 | "meta" -> Wsi.metamask
947 let keys_of_string s =
948 let key_of_string r
s =
949 let elems = Str.full_split r
s in
952 let m1 = modifier_of_string s in
954 then (Wsi.namekey
s, m
)
957 | Str.Delim
s when n land 1 = 0 -> g s
959 | Str.Delim
_ -> (k
, m
)
961 let rec loop n k m
= function
964 let k, m
= f n k m x
in
969 let elems = Str.split whitere
s in
970 List.map
(key_of_string (Str.regexp
"-")) elems
973 let config_of c attrs
=
977 | "scroll-bar-width" -> { c
with scrollbw
= max
0 (int_of_string v
) }
978 | "scroll-handle-height" -> { c
with scrollh
= max
0 (int_of_string v
) }
979 | "case-insensitive-search" -> { c
with icase
= bool_of_string v
}
980 | "preload" -> { c
with preload
= bool_of_string v
}
981 | "page-bias" -> { c
with pagebias
= int_of_string v
}
982 | "scroll-step" -> { c
with scrollstep
= max
1 (int_of_string v
) }
983 | "horizontal-scroll-step" ->
984 { c
with hscrollstep
= max
(int_of_string v
) 1 }
985 | "auto-scroll-step" ->
986 { c
with autoscrollstep
= max
0 (int_of_string v
) }
987 | "max-height-fit" -> { c
with maxhfit
= bool_of_string v
}
988 | "crop-hack" -> { c
with crophack
= bool_of_string v
}
991 match String.lowercase v
with
992 | "true" -> Some infinity
994 | f -> Some
(float_of_string
f)
996 { c
with maxwait
= mw }
997 | "highlight-links" -> { c
with hlinks
= bool_of_string v
}
998 | "under-cursor-info" -> { c
with underinfo
= bool_of_string v
}
999 | "vertical-margin" ->
1000 { c
with interpagespace
= max
0 (int_of_string v
) }
1002 let zoom = float_of_string v
/. 100. in
1003 let zoom = max
zoom 0.0 in
1004 { c
with zoom = zoom }
1005 | "presentation" -> { c
with presentation
= bool_of_string v
}
1006 | "rotation-angle" -> { c
with angle
= int_of_string v
}
1007 | "width" -> { c
with cwinw
= max
20 (int_of_string v
) }
1008 | "height" -> { c
with cwinh
= max
20 (int_of_string v
) }
1009 | "persistent-bookmarks" -> { c
with savebmarks
= bool_of_string v
}
1010 | "proportional-display" ->
1013 then FitProportional
1016 { c
with fitmodel
= fm }
1017 | "fit-model" -> { c
with fitmodel
= FMTE.of_string v
}
1018 | "pixmap-cache-size" ->
1019 { c
with memlimit
= max
2 (int_of_string_with_suffix v
) }
1020 | "tex-count" -> { c
with texcount
= max
1 (int_of_string v
) }
1021 | "slice-height" -> { c
with sliceheight
= max
2 (int_of_string v
) }
1022 | "thumbnail-width" -> { c
with thumbw
= max
2 (int_of_string v
) }
1023 | "persistent-location" -> { c
with jumpback
= bool_of_string v
}
1024 | "background-color" -> { c
with bgcolor
= color_of_string v
}
1025 | "tile-width" -> { c
with tilew
= max
2 (int_of_string v
) }
1026 | "tile-height" -> { c
with tileh
= max
2 (int_of_string v
) }
1027 | "mupdf-store-size" ->
1028 { c
with mustoresize
= max
1024 (int_of_string_with_suffix v
) }
1029 | "checkers" -> { c
with checkers
= bool_of_string v
}
1030 | "aalevel" -> { c
with aalevel
= max
0 (int_of_string v
) }
1031 | "trim-margins" -> { c
with trimmargins
= bool_of_string v
}
1032 | "trim-fuzz" -> { c
with trimfuzz
= irect_of_string v
}
1033 | "uri-launcher" -> { c
with urilauncher
= unentS v
}
1034 | "path-launcher" -> { c
with pathlauncher
= unentS v
}
1035 | "color-space" -> { c
with colorspace
= CSTE.of_string v
}
1036 | "invert-colors" -> { c
with invert
= bool_of_string v
}
1037 | "brightness" -> { c
with colorscale
= float_of_string v
}
1038 | "redirectstderr" -> { c
with redirectstderr
= bool_of_string v
}
1039 | "ghyllscroll" -> { c
with ghyllscroll
= ghyllscroll_of_string v
}
1041 let (n, _, _) as nab
= multicolumns_of_string v
in
1043 then { c
with columns
= Csplit
(-n, E.a
) }
1044 else { c
with columns
= Cmulti
(nab
, E.a
) }
1045 | "birds-eye-columns" ->
1046 { c
with beyecolumns
= Some
(max
(int_of_string v
) 2) }
1047 | "selection-command" -> { c
with selcmd
= unentS v
}
1048 | "synctex-command" -> { c
with stcmd
= unentS v
}
1049 | "pax-command" -> { c
with paxcmd
= unentS v
}
1050 | "askpass-command" -> { c
with passcmd
= unentS v
}
1051 | "savepath-command" -> { c
with savecmd
= unentS v
}
1052 | "update-cursor" -> { c
with updatecurs
= bool_of_string v
}
1053 | "hint-font-size" -> { c
with hfsize
= bound
(int_of_string v
) 5 100 }
1054 | "page-scroll-scale" -> { c
with pgscale
= float_of_string v
}
1055 | "use-pbo" -> { c
with usepbo
= bool_of_string v
}
1056 | "wheel-scrolls-pages" -> { c
with wheelbypage
= bool_of_string v
}
1057 | "horizontal-scrollbar-visible" ->
1060 then c
.scrollb
lor scrollbhv
1061 else c
.scrollb
land (lnot
scrollbhv)
1063 { c
with scrollb
= b }
1064 | "vertical-scrollbar-visible" ->
1067 then c
.scrollb
lor scrollbvv
1068 else c
.scrollb
land (lnot
scrollbvv)
1070 { c
with scrollb
= b }
1071 | "remote-in-a-new-instance" -> { c
with riani
= bool_of_string v
}
1075 then Some
(ref (0.0, 0, 0))
1077 | "point-and-x-mark" -> { c
with paxmark
= MTE.of_string v
}
1078 | "scroll-bar-on-the-left" -> { c
with leftscroll
= bool_of_string v
}
1079 | "title" -> { c
with title
= unentS v
}
1080 | "last-visit" -> { c
with lastvisit
= float_of_string v
}
1081 | "edit-annotations-inline" -> { c
with annotinline
= bool_of_string v
}
1084 prerr_endline
("Error processing attribute (`" ^
1085 k ^
"'=`" ^ v ^
"'): " ^ exntos exn
);
1088 let rec fold c
= function
1091 let c = apply c k v
in
1094 fold { c with keyhashes
= copykeyhashes c } attrs
;
1097 let fromstring f pos
n v
d =
1100 dolog
"Error processing attribute (%S=%S) at %d\n%s"
1101 n v pos
(exntos exn
);
1105 let bookmark_of attrs
=
1106 let rec fold title page rely visy
= function
1107 | ("title", v
) :: rest
-> fold v page rely visy rest
1108 | ("page", v
) :: rest
-> fold title v rely visy rest
1109 | ("rely", v
) :: rest
-> fold title page v visy rest
1110 | ("visy", v
) :: rest
-> fold title page rely v rest
1111 | _ :: rest
-> fold title page rely visy rest
1112 | [] -> title
, page
, rely
, visy
1114 fold "invalid" "0" "0" "0" attrs
1118 let rec fold path page rely pan visy origin
= function
1119 | ("path", v
) :: rest
-> fold v page rely pan visy origin rest
1120 | ("page", v
) :: rest
-> fold path v rely pan visy origin rest
1121 | ("rely", v
) :: rest
-> fold path page v pan visy origin rest
1122 | ("pan", v
) :: rest
-> fold path page rely v visy origin rest
1123 | ("visy", v
) :: rest
-> fold path page rely pan v origin rest
1124 | ("origin", v
) :: rest
-> fold path page rely pan visy v rest
1125 | _ :: rest
-> fold path page rely pan visy origin rest
1126 | [] -> path
, page
, rely
, pan
, visy
, origin
1128 fold E.s "0" "0" "0" "0" E.s attrs
1132 let rec fold rs ls
= function
1133 | ("out", v
) :: rest
-> fold v ls rest
1134 | ("in", v
) :: rest
-> fold rs v rest
1135 | _ :: rest
-> fold ls rs rest
1141 let setconf dst src
=
1142 dst
.scrollbw
<- src
.scrollbw
;
1143 dst
.scrollh
<- src
.scrollh
;
1144 dst
.icase
<- src
.icase
;
1145 dst
.preload
<- src
.preload
;
1146 dst
.pagebias
<- src
.pagebias
;
1147 dst
.verbose
<- src
.verbose
;
1148 dst
.scrollstep
<- src
.scrollstep
;
1149 dst
.maxhfit
<- src
.maxhfit
;
1150 dst
.crophack
<- src
.crophack
;
1151 dst
.autoscrollstep
<- src
.autoscrollstep
;
1152 dst
.maxwait
<- src
.maxwait
;
1153 dst
.hlinks
<- src
.hlinks
;
1154 dst
.underinfo
<- src
.underinfo
;
1155 dst
.interpagespace
<- src
.interpagespace
;
1156 dst
.zoom <- src
.zoom;
1157 dst
.presentation
<- src
.presentation
;
1158 dst
.angle
<- src
.angle
;
1159 dst
.cwinw
<- src
.cwinw
;
1160 dst
.cwinh
<- src
.cwinh
;
1161 dst
.savebmarks
<- src
.savebmarks
;
1162 dst
.memlimit
<- src
.memlimit
;
1163 dst
.fitmodel
<- src
.fitmodel
;
1164 dst
.texcount
<- src
.texcount
;
1165 dst
.sliceheight
<- src
.sliceheight
;
1166 dst
.thumbw
<- src
.thumbw
;
1167 dst
.jumpback
<- src
.jumpback
;
1168 dst
.bgcolor
<- src
.bgcolor
;
1169 dst
.tilew
<- src
.tilew
;
1170 dst
.tileh
<- src
.tileh
;
1171 dst
.mustoresize
<- src
.mustoresize
;
1172 dst
.checkers
<- src
.checkers
;
1173 dst
.aalevel
<- src
.aalevel
;
1174 dst
.trimmargins
<- src
.trimmargins
;
1175 dst
.trimfuzz
<- src
.trimfuzz
;
1176 dst
.urilauncher
<- src
.urilauncher
;
1177 dst
.colorspace
<- src
.colorspace
;
1178 dst
.invert
<- src
.invert
;
1179 dst
.colorscale
<- src
.colorscale
;
1180 dst
.redirectstderr
<- src
.redirectstderr
;
1181 dst
.ghyllscroll
<- src
.ghyllscroll
;
1182 dst
.columns
<- src
.columns
;
1183 dst
.beyecolumns
<- src
.beyecolumns
;
1184 dst
.selcmd
<- src
.selcmd
;
1185 dst
.updatecurs
<- src
.updatecurs
;
1186 dst
.pathlauncher
<- src
.pathlauncher
;
1187 dst
.keyhashes
<- copykeyhashes src
;
1188 dst
.hfsize
<- src
.hfsize
;
1189 dst
.hscrollstep
<- src
.hscrollstep
;
1190 dst
.pgscale
<- src
.pgscale
;
1191 dst
.usepbo
<- src
.usepbo
;
1192 dst
.wheelbypage
<- src
.wheelbypage
;
1193 dst
.stcmd
<- src
.stcmd
;
1194 dst
.paxcmd
<- src
.paxcmd
;
1195 dst
.passcmd
<- src
.passcmd
;
1196 dst
.savecmd
<- src
.savecmd
;
1197 dst
.scrollb
<- src
.scrollb
;
1198 dst
.riani
<- src
.riani
;
1199 dst
.paxmark
<- src
.paxmark
;
1200 dst
.leftscroll
<- src
.leftscroll
;
1201 dst
.title
<- src
.title
;
1202 dst
.annotinline
<- src
.annotinline
;
1206 else Some
((ref (0.0, 0, 0)));
1209 let findkeyhash c name =
1210 try List.assoc
name c.keyhashes
1211 with Not_found
-> failwith
("invalid mode name `" ^
name ^
"'")
1216 let h = Hashtbl.create
10 in
1217 let dc = { defconf with angle
= defconf.angle
} in
1218 let rec toplevel v t spos
_ =
1220 | Vdata
| Vcdata
| Vend
-> v
1221 | Vopen
("llppconfig", _, closed
) ->
1224 else { v
with f = llppconfig
}
1226 error
"unexpected subelement at top level" s spos
1227 | Vclose
_ -> error
"unexpected close at top level" s spos
1229 and llppconfig v t spos
_ =
1231 | Vdata
| Vcdata
-> v
1232 | Vend
-> error
"unexpected end of input in llppconfig" s spos
1233 | Vopen
("defaults", attrs
, closed
) ->
1234 let c = config_of dc attrs
in
1238 else { v
with f = defaults
}
1240 | Vopen
("ui-font", attrs
, closed
) ->
1241 let rec getsize size
= function
1243 | ("size", v
) :: rest
->
1245 fromstring int_of_string spos
"size" v
fstate.fontsize
in
1247 | l -> getsize size l
1249 fstate.fontsize
<- getsize fstate.fontsize attrs
;
1252 else { v
with f = uifont
(Buffer.create
10) }
1254 | Vopen
("doc", attrs
, closed
) ->
1255 let pathent, spage
, srely
, span
, svisy
, origin
= doc_of attrs
in
1256 let path = unentS pathent
1257 and origin
= unentS origin
1258 and pageno = fromstring int_of_string spos
"page" spage
0
1259 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1260 and pan
= fromstring int_of_string spos
"pan" span
0
1261 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1262 let c = config_of dc attrs
in
1263 let anchor = (pageno, rely
, visy
) in
1265 then (Hashtbl.add
h path (c, [], pan
, anchor, origin
); v
)
1266 else { v
with f = doc
path origin pan
anchor c [] }
1269 error
"unexpected subelement in llppconfig" s spos
1271 | Vclose
"llppconfig" -> { v
with f = toplevel }
1272 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
1274 and defaults v t spos
_ =
1276 | Vdata
| Vcdata
-> v
1277 | Vend
-> error
"unexpected end of input in defaults" s spos
1278 | Vopen
("keymap", attrs
, closed
) ->
1280 try List.assoc
"mode" attrs
1281 with Not_found
-> "global" in
1286 let h = findkeyhash dc modename in
1287 KeyMap.iter
(Hashtbl.replace
h) keymap
;
1290 { v
with f = pkeymap
ret KeyMap.empty
}
1292 | Vopen
(_, _, _) ->
1293 error
"unexpected subelement in defaults" s spos
1295 | Vclose
"defaults" ->
1296 { v
with f = llppconfig
}
1298 | Vclose
_ -> error
"unexpected close in defaults" s spos
1300 and uifont
b v t spos epos
=
1303 Buffer.add_substring
b s spos
(epos
- spos
);
1305 | Vopen
(_, _, _) ->
1306 error
"unexpected subelement in ui-font" s spos
1307 | Vclose
"ui-font" ->
1308 if emptystr
!fontpath
1309 then fontpath := Buffer.contents
b;
1310 { v
with f = llppconfig
}
1311 | Vclose
_ -> error
"unexpected close in ui-font" s spos
1312 | Vend
-> error
"unexpected end of input in ui-font" s spos
1314 and doc
path origin pan
anchor c bookmarks v t spos
_ =
1316 | Vdata
| Vcdata
-> v
1317 | Vend
-> error
"unexpected end of input in doc" s spos
1318 | Vopen
("bookmarks", _, closed
) ->
1321 else { v
with f = pbookmarks
path origin pan
anchor c bookmarks
}
1323 | Vopen
("keymap", attrs
, closed
) ->
1325 try List.assoc
"mode" attrs
1326 with Not_found
-> "global"
1332 let h = findkeyhash c modename in
1333 KeyMap.iter
(Hashtbl.replace
h) keymap
;
1334 doc
path origin pan
anchor c bookmarks
1336 { v
with f = pkeymap
ret KeyMap.empty
}
1338 | Vopen
(_, _, _) ->
1339 error
"unexpected subelement in doc" s spos
1342 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor, origin
);
1343 { v
with f = llppconfig
}
1345 | Vclose
_ -> error
"unexpected close in doc" s spos
1347 and pkeymap
ret keymap v t spos
_ =
1349 | Vdata
| Vcdata
-> v
1350 | Vend
-> error
"unexpected end of input in keymap" s spos
1351 | Vopen
("map", attrs
, closed
) ->
1352 let r, l = map_of attrs
in
1353 let kss = fromstring keys_of_string spos
"in" r [] in
1354 let lss = fromstring keys_of_string spos
"out" l [] in
1358 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
1359 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
1362 then { v
with f = pkeymap
ret keymap }
1365 { v
with f = skip
"map" f }
1368 error
"unexpected subelement in keymap" s spos
1370 | Vclose
"keymap" ->
1371 { v
with f = ret keymap }
1373 | Vclose
_ -> error
"unexpected close in keymap" s spos
1375 and pbookmarks
path origin pan
anchor c bookmarks v t spos
_ =
1377 | Vdata
| Vcdata
-> v
1378 | Vend
-> error
"unexpected end of input in bookmarks" s spos
1379 | Vopen
("item", attrs
, closed
) ->
1380 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
1381 let page = fromstring int_of_string spos
"page" spage
0
1382 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1383 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1385 (unentS titleent, 0, Oanchor
(page, rely
, visy
)) :: bookmarks
1388 then { v
with f = pbookmarks
path origin pan
anchor c bookmarks }
1391 { v
with f = skip
"item" f }
1394 error
"unexpected subelement in bookmarks" s spos
1396 | Vclose
"bookmarks" ->
1397 { v
with f = doc
path origin pan
anchor c bookmarks }
1399 | Vclose
_ -> Parser.parse_error
"unexpected close in bookmarks" s spos
1401 and skip tag
f v t spos
_ =
1403 | Vdata
| Vcdata
-> v
1405 Parser.parse_error
("unexpected end of input in skipped " ^ tag
) s spos
1406 | Vopen
(tag'
, _, closed
) ->
1410 let f'
() = { v
with f = skip tag
f } in
1411 { v
with f = skip tag'
f'
}
1415 else Parser.parse_error
("unexpected close in skipped " ^ tag
) s spos
1418 parse
{ f = toplevel; accu
= () } s;
1422 let do_load f contents
=
1425 | Parser.Parse_error
(msg
, s, pos
) ->
1426 let subs = Parser.subs s pos
in
1427 Utils.error
"parse error: %s: at %d [..%s..]" msg pos
subs
1430 failwith
("config load error: " ^ exntos exn
)
1435 let xdgconfdir = Utils.getenvwithdef
"XDG_CONFIG_HOME" E.s in
1436 if emptystr
xdgconfdir
1439 let dir = Filename.concat
home ".config" in
1440 if Sys.is_directory
dir then dir else home
1444 Filename.concat
dir "llpp.conf"
1447 let confpath = ref defconfpath;;
1449 let load2 f default
=
1450 match filecontents
!confpath with
1451 | contents
-> f @@ do_load get contents
1452 | exception Unix.Unix_error
(Unix.ENOENT
, "open", _) ->
1453 f (Hashtbl.create
0, defconf)
1455 dolog
"Error loading config from `%S': %s" !confpath @@ exntos exn
;
1459 let load1 f = load2 f false;;
1467 (fun path (conf, _, _, _, _) ((_, besttime
) as best
) ->
1468 if conf.lastvisit
> besttime
1469 then (path, conf.lastvisit
)
1472 (state.path, -.infinity
)
1476 let pc, pb
, px
, pa
, po
=
1478 let absname = abspath
state.path in
1479 Hashtbl.find h absname
1480 with Not_found
-> dc, [], 0, emptyanchor, state.origin
1484 state.bookmarks <- pb
;
1488 then state.anchor <- pa
;
1489 cbput state.hists
.nav pa
;
1497 Hashtbl.fold (fun path (pc, pb
, px
, pa
, po
) accu
->
1498 (path, pc, pb
, px
, pa
, po
) :: accu
)
1504 let add_attrs bb always
dc c time
=
1507 then Printf.bprintf bb
"\n %s='%b'" s a
1510 then Printf.bprintf bb
"\n %s='%b'" s (a
!= None
)
1513 then Printf.bprintf bb
"\n %s='%d'" s a
1516 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a
)
1519 then Printf.bprintf bb
"\n %s='%g'" s (a
*.100.)
1522 then Printf.bprintf bb
"\n %s='%f'" s a
1525 then Printf.bprintf bb
"\n %s='%Ld'" s a
1528 then Printf.bprintf bb
"\n %s='%s'" s (color_to_string a
)
1531 then Printf.bprintf bb
"\n %s='%s'" s (CSTE.to_string a
)
1534 then Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a
)
1538 Printf.bprintf bb
"\n %s='%s'" s (Parser.enent a
0 (String.length a
))
1543 | Some
(_N
, _A
, _B
) ->
1544 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
1549 Printf.bprintf bb
"\n %s='none'" s
1559 else string_of_float
f
1561 Printf.bprintf bb
"\n %s='%s'" s v
1566 | Cmulti
((n, a
, b), _) when n > 1 ->
1567 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a
b
1568 | Csplit
(n, _) when n > 1 ->
1569 Printf.bprintf bb
"\n %s='%d'" s ~
-n
1570 | Cmulti
_ | Csplit
_ | Csingle
_ -> ()
1575 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
1579 then Printf.bprintf bb
"\n %s='%s'" s (FMTE.to_string a
)
1582 then Printf.bprintf bb
"\n %s='%b'" s (a
land m
!= 0)
1585 then Printf.bprintf bb
"\n %s='%s'" s (MTE.to_string a
)
1587 oi
"width" c.cwinw
dc.cwinw
;
1588 oi
"height" c.cwinh
dc.cwinh
;
1589 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
1590 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
1591 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
1592 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
1593 ob "case-insensitive-search" c.icase
dc.icase
;
1594 ob "preload" c.preload
dc.preload
;
1595 oi
"page-bias" c.pagebias
dc.pagebias
;
1596 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
1597 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
1598 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
1599 ob "crop-hack" c.crophack
dc.crophack
;
1600 oW
"throttle" c.maxwait
dc.maxwait
;
1601 ob "highlight-links" c.hlinks
dc.hlinks
;
1602 ob "under-cursor-info" c.underinfo
dc.underinfo
;
1603 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
1604 oz
"zoom" c.zoom dc.zoom;
1605 ob "presentation" c.presentation
dc.presentation
;
1606 oi
"rotation-angle" c.angle
dc.angle
;
1607 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
1608 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
1609 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
1610 oi
"tex-count" c.texcount
dc.texcount
;
1611 oi
"slice-height" c.sliceheight
dc.sliceheight
;
1612 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
1613 ob "persistent-location" c.jumpback
dc.jumpback
;
1614 oc
"background-color" c.bgcolor
dc.bgcolor
;
1615 oi
"tile-width" c.tilew
dc.tilew
;
1616 oi
"tile-height" c.tileh
dc.tileh
;
1617 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
1618 ob "checkers" c.checkers
dc.checkers
;
1619 oi
"aalevel" c.aalevel
dc.aalevel
;
1620 ob "trim-margins" c.trimmargins
dc.trimmargins
;
1621 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
1622 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
1623 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
1624 oC
"color-space" c.colorspace
dc.colorspace
;
1625 ob "invert-colors" c.invert
dc.invert
;
1626 oF
"brightness" c.colorscale
dc.colorscale
;
1627 ob "redirectstderr" c.redirectstderr
dc.redirectstderr
;
1628 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
1629 oco
"columns" c.columns
dc.columns
;
1630 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
1631 os
"selection-command" c.selcmd
dc.selcmd
;
1632 os
"synctex-command" c.stcmd
dc.stcmd
;
1633 os
"pax-command" c.paxcmd
dc.paxcmd
;
1634 os
"askpass-command" c.passcmd
dc.passcmd
;
1635 os
"savepath-command" c.savecmd
dc.savecmd
;
1636 ob "update-cursor" c.updatecurs
dc.updatecurs
;
1637 oi
"hint-font-size" c.hfsize
dc.hfsize
;
1638 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
1639 oF
"page-scroll-scale" c.pgscale
dc.pgscale
;
1640 ob "use-pbo" c.usepbo
dc.usepbo
;
1641 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
1642 ob "remote-in-a-new-instance" c.riani
dc.riani
;
1643 op
"point-and-x" c.pax
dc.pax
;
1644 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
1645 ob "scroll-bar-on-the-left" c.leftscroll
dc.leftscroll
;
1647 then os
"title" c.title
dc.title
;
1648 oL
"last-visit" (Int64.of_float time
) 0L;
1649 ob "edit-annotations-inline" c.annotinline
dc.annotinline
;
1652 let keymapsbuf always
dc c =
1653 let bb = Buffer.create
16 in
1654 let rec loop = function
1656 | (modename, h) :: rest
->
1657 let dh = findkeyhash dc modename in
1658 if always
|| h <> dh
1660 if Hashtbl.length
h > 0
1662 if Buffer.length
bb > 0
1663 then Buffer.add_char
bb '
\n'
;
1664 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
1665 Hashtbl.iter
(fun i o
->
1666 let isdifferent = always
||
1668 let dO = Hashtbl.find dh i
in
1670 with Not_found
-> true
1675 if Wsi.withctrl m
then Buffer.add_string
bb "ctrl-";
1676 if Wsi.withalt m
then Buffer.add_string
bb "alt-";
1677 if Wsi.withshift m
then Buffer.add_string
bb "shift-";
1678 if Wsi.withmeta m
then Buffer.add_string
bb "meta-";
1679 Buffer.add_string
bb (Wsi.keyname
k);
1682 let rec loop = function
1684 | km
:: [] -> addkm km
1685 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
1689 Buffer.add_string
bb "<map in='";
1693 Buffer.add_string
bb "' out='";
1695 Buffer.add_string
bb "'/>\n"
1698 Buffer.add_string
bb "' out='";
1700 Buffer.add_string
bb "'/>\n"
1702 | KMmulti
(ins
, kms
) ->
1703 Buffer.add_char
bb ' '
;
1705 Buffer.add_string
bb "' out='";
1707 Buffer.add_string
bb "'/>\n"
1709 Buffer.add_string
bb "</keymap>";
1718 let save1 bb leavebirdseye x
h dc =
1719 let uifontsize = fstate.fontsize
in
1720 let dc = if conf.bedefault
then conf else dc in
1721 Buffer.add_string
bb "<llppconfig>\n";
1723 if nonemptystr
!fontpath
1725 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
1731 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
1734 Buffer.add_string
bb "<defaults";
1735 add_attrs bb true dc dc nan
;
1736 let kb = keymapsbuf true dc dc in
1737 if Buffer.length
kb > 0
1739 Buffer.add_string
bb ">\n";
1740 Buffer.add_buffer
bb kb;
1741 Buffer.add_string
bb "\n</defaults>\n";
1743 else Buffer.add_string
bb "/>\n";
1745 let adddoc path pan
anchor c bookmarks time origin
=
1746 if bookmarks == [] && c = dc && anchor = emptyanchor
1749 Printf.bprintf
bb "<doc path='%s'"
1750 (Parser.enent
path 0 (String.length
path));
1752 if nonemptystr origin
1754 Printf.bprintf
bb "\n origin='%s'"
1755 (Parser.enent origin
0 (String.length origin
));
1757 if anchor <> emptyanchor
1759 let n, rely
, visy
= anchor in
1760 Printf.bprintf
bb "\n page='%d'" n;
1763 Printf.bprintf
bb " rely='%f'" rely
1765 if abs_float visy
> 1e-6
1767 Printf.bprintf
bb " visy='%f'" visy
1772 then Printf.bprintf
bb " pan='%d'" pan
;
1774 add_attrs bb false dc c time
;
1775 let kb = keymapsbuf false dc c in
1777 begin match bookmarks with
1779 if Buffer.length
kb > 0
1781 Buffer.add_string
bb ">\n";
1782 Buffer.add_buffer
bb kb;
1783 Buffer.add_string
bb "\n</doc>\n";
1785 else Buffer.add_string
bb "/>\n"
1787 Buffer.add_string
bb ">\n<bookmarks>\n";
1788 List.iter
(fun (title
, _, kind
) ->
1789 begin match kind
with
1790 | Oanchor
(page, rely
, visy
) ->
1792 "<item title='%s' page='%d'"
1793 (Parser.enent title
0 (String.length title
))
1798 Printf.bprintf
bb " rely='%f'" rely
1800 if abs_float visy
> 1e-6
1802 Printf.bprintf
bb " visy='%f'" visy
1804 | Ohistory
_ | Onone
| Ouri
_ | Oremote
_
1805 | Oremotedest
_ | Olaunch
_ | Oaction
_ | Oreaction
_ ->
1806 failwith
"unexpected link in bookmarks"
1808 Buffer.add_string
bb "/>\n";
1810 Buffer.add_string
bb "</bookmarks>";
1811 if Buffer.length
kb > 0
1813 Buffer.add_string
bb "\n";
1814 Buffer.add_buffer
bb kb;
1816 Buffer.add_string
bb "\n</doc>\n";
1822 match state.mode
with
1823 | Birdseye
(c, pan, _, _, _) ->
1825 match conf.columns
with
1826 | Cmulti
((c, _, _), _) -> Some
c
1830 match c.columns
with
1831 | Cmulti
(c, _) -> Cmulti
(c, E.a
)
1832 | Csingle
_ -> Csingle
E.a
1833 | Csplit
_ -> failwith
"quit from bird's eye while split"
1835 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
1838 | LinkNav
_ -> x
, conf
1840 let docpath = if nonemptystr
state.path then abspath
state.path else E.s in
1841 if nonemptystr
docpath
1843 adddoc docpath pan (getanchor ())
1845 let autoscrollstep =
1846 match state.autoscroll
with
1848 | None
-> conf.autoscrollstep
1850 begin match state.mode
with
1851 | Birdseye beye
-> leavebirdseye beye
true
1856 { conf with autoscrollstep = autoscrollstep }
1858 (if conf.savebmarks
then state.bookmarks else [])
1862 Hashtbl.iter
(fun path (c, bookmarks, x
, anchor, origin
) ->
1863 if docpath <> abspath
path
1864 then adddoc path x
anchor c bookmarks c.lastvisit origin
1866 Buffer.add_string
bb "</llppconfig>\n";
1870 let save leavebirdseye
=
1871 let relx = float state.x
/. float state.winw
in
1873 let cx w = truncate
(relx *. float w) in
1875 (fun (w, h, x
) ws
->
1877 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
1878 | Wsi.MaxVert
-> (w, conf.cwinh
, x
)
1879 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
1881 (state.winw
, state.winh
, state.x
) state.winstate
1885 let bb = Buffer.create
32768 in
1887 save1 bb leavebirdseye x
h dc
1889 if load1 save2 && Buffer.length
bb > 0
1892 let tmp = !confpath ^
".tmp" in
1893 let oc = open_out_bin
tmp in
1894 Buffer.output_buffer
oc bb;
1896 Unix.rename
tmp !confpath;
1899 ("error while saving configuration: " ^ exntos exn
)
1904 let n'
= Unix.write fdo
(Bytes.of_string s) 0 n in
1906 then Utils.error
"Unix.write %d = %d" n n'
1909 try Unix.read fdi
s 0 n
1910 with exn
-> Utils.error
"reading gc pipe %s" (exntos exn
) in
1911 let href = ref (Hashtbl.create
0) in
1912 let cref = ref defconf in
1914 let f path (pc, _pb
, _px
, _pa
, _po
) =
1916 Printf.sprintf
"%s\000%ld\000" path (Int32.of_float
pc.lastvisit
)
1918 wr s (String.length
s)
1923 Unix.shutdown fdo
Unix.SHUTDOWN_SEND
;
1926 ignore
(load1 push);
1928 let b = Buffer.create
32768 in
1929 let s = Bytes.create
4096 in
1931 let n = rd s (Bytes.length
s) in
1933 then Buffer.contents
b
1934 else (Buffer.add_subbytes
b s 0 n; f ())
1939 match String.index_from
s ppos '
\000'
with
1942 try String.index_from
s (zpos1
+1) '
\000'
with Not_found
-> -1 in
1944 then error
"Incorrect gc input in (%S) at %d" s zpos1
1946 let okey = StringLabels.sub
s ~pos
:ppos ~len
:(zpos1
-ppos
) in
1947 let nkey = StringLabels.sub
s ~pos
:(zpos1
+1) ~len
:(zpos2-zpos1
-1) in
1949 then (Hashtbl.remove
!href okey; f (zpos2+1))
1952 try Hashtbl.find !href okey
1953 with Not_found
-> Utils.error
"gc: could not find %S" okey
1955 Hashtbl.remove
!href okey;
1956 Hashtbl.replace
!href nkey v;
1958 | exception Not_found
-> ()
1961 let bb = Buffer.create
32768 in
1962 let save2 (_h
, dc) = save1 bb (fun _ _ -> ()) 0 !href dc in
1963 if load1 save2 && Buffer.length
bb > 0
1966 let tmp = !confpath ^
".tmp" in
1967 let oc = open_out_bin
tmp in
1968 Buffer.output_buffer
oc bb;
1970 Unix.rename
tmp !confpath;
1973 ("error while saving configuration: " ^ exntos exn
)
1977 let logcurrently = function
1978 | Idle
-> dolog
"Idle"
1979 | Loading
(l, gen
) ->
1980 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
1981 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col
, row
, tilew
, tileh
) ->
1983 "Tiling %d[%d,%d] page=%s cs=%s angle"
1984 l.pageno col row
(~
> pageopaque
)
1985 (CSTE.to_string colorspace
)
1987 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1988 angle gen
conf.angle
state.gen
1990 conf.tilew
conf.tileh