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);;
24 let irect_of_string s
=
25 Scanf.sscanf s
"%d/%d/%d/%d" (fun x0 y0 x1 y1
-> (x0
,y0
,x1
,y1
))
28 let irect_to_string (x0
,y0
,x1
,y1
) =
29 Printf.sprintf
"%d/%d/%d/%d" x0 y0 x1 y1
32 let ghyllscroll_of_string s
=
34 | "fast" -> Some
fastghyllscroll
35 | "neat" -> Some
(10,1,9)
39 Scanf.sscanf s
"%u,%u,%u" (fun n a b
-> n
, a
, b
) in
40 if n
<= a
|| n
<= b
|| a
>= b
41 then error
"N(%d),A(%d),B(%d) (N <= A, A < B, N <= B)" n a b
;
45 let ghyllscroll_to_string ((n
, a
, b
) as nab
) =
46 (**) if nab
= fastghyllscroll then "fast"
47 else if nab
= neatghyllscroll then "neat"
48 else Printf.sprintf
"%d,%d,%d" n a b
;
51 let multicolumns_to_string (n
, a
, b
) =
53 then Printf.sprintf
"%d" n
54 else Printf.sprintf
"%d,%d,%d" n a b
;
57 let multicolumns_of_string s
=
59 (int_of_string s
, 0, 0)
61 Scanf.sscanf s
"%u,%u,%u" (fun n a b
->
63 then failwith
"subtly broken";
71 | KMmulti
of key list
* key list
73 and keyhash
= (key
, keymap
) Hashtbl.t
76 | KSinto
of (key list
* key list
)
77 and interpagespace
= int
78 and multicolumns
= multicol
* pagegeom
79 and singlecolumn
= pagegeom
80 and splitcolumns
= columncount
* pagegeom
81 and pagegeom
= (pdimno
* x
* y
* (pageno
* width
* height
* leftx
)) array
82 and multicol
= columncount
* covercount
* covercount
86 and fitmodel
= | FitWidth
| FitProportional
| FitPage
87 and trimmargins
= bool
88 and irect
= (int * int * int * int)
93 and params
= (angle
* fitmodel
* trimparams
94 * texcount
* sliceheight
* memsize
95 * colorspace
* fontpath
* trimcachepath
96 * haspbo
* usefontconfig
)
100 and opaque
= Opaque.t
101 and rectcolor
= (float * float * float * float)
106 and fontpath
= string
107 and trimcachepath
= string
109 and trimparams
= (trimmargins
* irect
)
110 and colorspace
= | Rgb
| Bgr
| Gray
112 and usefontconfig
= bool
119 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
123 | Ulinkgoto
of (int * int)
125 | Uunexpected
of string
126 | Ulaunch
of launchcommand
128 | Uremote
of (filename
* pageno
)
129 | Uremotedest
of (filename
* destname
)
130 | Uannotation
of (opaque
* slinkindex
)
132 and facename
= string
133 and launchcommand
= string
134 and filename
= string
136 and destname
= string
148 | LDfirstvisible
of (int * int * int)
157 and anchor
= pageno
* top
* dtop
158 and rect
= float * float * float * float * float * float * float * float
159 and infochange
= | Memused
| Docinfo
| Pdim
162 class type uioh
= object
163 method display
: unit
164 method key
: int -> int -> uioh
165 method button
: int -> bool -> int -> int -> int -> uioh
166 method multiclick
: int -> int -> int -> int -> uioh
167 method motion
: int -> int -> uioh
168 method pmotion
: int -> int -> uioh
169 method infochanged
: infochange
-> unit
170 method scrollpw
: (int * float * float)
171 method scrollph
: (int * float * float)
172 method modehash
: keyhash
173 method eformsgs
: bool
174 method alwaysscrolly
: bool
177 module type TextEnumType
=
181 val names
: string array
184 module TextEnumMake
(Ten
: TextEnumType
) =
186 let names = Ten.names;;
187 let to_int (t
: Ten.t
) = Obj.magic t
;;
188 let to_string t
= names.(to_int t
);;
189 let of_int n
: Ten.t
= Obj.magic n
;;
192 if i
= Array.length
names
193 then failwith
("invalid " ^
Ten.name ^
": " ^ s
)
202 module CSTE
= TextEnumMake
(struct
203 type t
= colorspace
;;
204 let name = "colorspace";;
205 let names = [|"rgb"; "bgr"; "gray"|];;
208 module MTE
= TextEnumMake
(struct
211 let names = [|"page"; "block"; "line"; "word"|];;
214 module FMTE
= TextEnumMake
(struct
216 let name = "fitmodel";;
217 let names = [|"width"; "proportional"; "page"|];;
221 { mutable scrollbw
: int
222 ; mutable scrollh
: int
223 ; mutable scrollb
: scrollb
224 ; mutable icase
: bool
225 ; mutable preload
: bool
226 ; mutable pagebias
: int
227 ; mutable verbose
: bool
228 ; mutable debug
: bool
229 ; mutable scrollstep
: int
230 ; mutable hscrollstep
: int
231 ; mutable maxhfit
: bool
232 ; mutable crophack
: bool
233 ; mutable autoscrollstep
: int
234 ; mutable maxwait
: float option
235 ; mutable hlinks
: bool
236 ; mutable underinfo
: bool
237 ; mutable interpagespace
: interpagespace
238 ; mutable zoom
: float
239 ; mutable presentation
: bool
240 ; mutable angle
: angle
241 ; mutable cwinw
: int
242 ; mutable cwinh
: int
243 ; mutable savebmarks
: bool
244 ; mutable fitmodel
: fitmodel
245 ; mutable trimmargins
: trimmargins
246 ; mutable trimfuzz
: irect
247 ; mutable memlimit
: memsize
248 ; mutable texcount
: texcount
249 ; mutable sliceheight
: sliceheight
250 ; mutable thumbw
: width
251 ; mutable jumpback
: bool
252 ; mutable bgcolor
: (float * float * float)
253 ; mutable bedefault
: bool
254 ; mutable tilew
: int
255 ; mutable tileh
: int
256 ; mutable mustoresize
: memsize
257 ; mutable checkers
: bool
258 ; mutable aalevel
: int
259 ; mutable urilauncher
: string
260 ; mutable pathlauncher
: string
261 ; mutable colorspace
: colorspace
262 ; mutable invert
: bool
263 ; mutable colorscale
: float
264 ; mutable ghyllscroll
: (int * int * int) option
265 ; mutable columns
: columns
266 ; mutable beyecolumns
: columncount
option
267 ; mutable selcmd
: string
268 ; mutable paxcmd
: string
269 ; mutable passcmd
: string
270 ; mutable savecmd
: string
271 ; mutable updatecurs
: bool
272 ; mutable keyhashes
: (string * keyhash
) list
273 ; mutable hfsize
: int
274 ; mutable pgscale
: float
275 ; mutable usepbo
: bool
276 ; mutable wheelbypage
: bool
277 ; mutable stcmd
: string
278 ; mutable riani
: bool
279 ; mutable pax
: (float * int * int) ref option
280 ; mutable paxmark
: mark
281 ; mutable leftscroll
: bool
282 ; mutable title
: string
283 ; mutable lastvisit
: float
284 ; mutable annotinline
: bool
285 ; mutable coarseprespos
: bool
288 | Csingle
of singlecolumn
289 | Cmulti
of multicolumns
290 | Csplit
of splitcolumns
295 | Olaunch
of launchcommand
296 | Oremote
of (filename
* pageno
)
297 | Oremotedest
of (filename
* destname
)
298 | Ohistory
of (filename
* conf
* outline list
* x
* anchor
* filename
)
299 and outline
= (caption
* outlinelevel
* outlinekind
)
300 and outlinelevel
= int
318 type tile
= opaque
* pixmapsize
* elapsed
319 and elapsed
= float;;
320 type pagemapkey
= pageno
* gen
;;
321 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
326 | Loading
of (page
* gen
)
328 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
330 | Outlining
of outline list
333 type mpos
= int * int
335 | Msel
of (mpos
* mpos
)
337 | Mscrolly
| Mscrollx
338 | Mzoom
of (buttonno
* step
)
339 | Mzoomrect
of (mpos
* mpos
)
346 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
347 | Textentry
of (textentry
* onleave
)
349 | LinkNav
of linktarget
350 and onleave
= leavetextentrystatus
-> unit
351 and leavetextentrystatus
= | Cancel
| Confirm
352 and helpitem
= string * int * action
355 | Action
of (uioh
-> uioh
)
357 | Ltexact
of (pageno
* direction
)
358 | Ltgendir
of direction
359 | Ltnotready
of (pageno
* direction
)
360 and direction
= int (* -1, 0, 1 *)
361 and textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
362 and onkey
= string -> int -> te
363 and ondone
= string -> unit
364 and histcancel
= unit -> unit
365 and onhist
= ((histcmd
-> string) * histcancel
)
366 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
367 and cancelonempty
= bool
372 | TEswitch
of textentry
384 { mutable ss
: Unix.file_descr
385 ; mutable wsfd
: Unix.file_descr
386 ; mutable stderr
: Unix.file_descr
387 ; mutable errmsgs
: Buffer.t
388 ; mutable newerrmsgs
: bool
392 ; mutable anchor
: anchor
393 ; mutable ranchors
: (string * string * anchor
* string) list
395 ; mutable layout
: page list
396 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
397 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
398 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
399 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
400 ; mutable pagecount
: int
401 ; mutable currently
: currently
402 ; mutable mstate
: mstate
403 ; mutable searchpattern
: string
404 ; mutable rects
: (pageno
* rectcolor
* rect
) list
405 ; mutable rects1
: (pageno
* rectcolor
* rect
) list
406 ; prects
: (pageno
, float array
) Hashtbl.t
407 ; mutable text
: string
408 ; mutable winstate
: Wsi.winstate list
409 ; mutable mode
: mode
410 ; mutable uioh
: uioh
411 ; mutable outlines
: outline array
412 ; mutable bookmarks
: outline list
413 ; mutable path
: string
414 ; mutable password
: string
415 ; mutable nameddest
: string
416 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
417 ; mutable memused
: memsize
419 ; mutable throttle
: (page list
* int * float) option
420 ; mutable autoscroll
: int option
421 ; mutable ghyll
: (int option -> unit)
422 ; mutable help
: helpitem array
423 ; mutable docinfo
: (int * string) list
424 ; mutable checkerstexid
: GlTex.texture_id
option
426 ; mutable prevzoom
: (float * int)
427 ; mutable progress
: float
428 ; mutable redisplay
: bool
429 ; mutable mpos
: mpos
430 ; mutable keystate
: keystate
431 ; mutable glinks
: bool
432 ; mutable prevcolumns
: (columns
* float) option
435 ; mutable reprf
: (unit -> unit)
436 ; mutable origin
: string
437 ; mutable roam
: (unit -> unit)
438 ; mutable bzoom
: bool
439 ; mutable traw
: [`
float] Raw.t
440 ; mutable vraw
: [`
float] Raw.t
443 { pat
: string circbuf
444 ; pag
: string circbuf
445 ; nav
: anchor circbuf
446 ; sel
: string circbuf
450 let emptyanchor = (0, 0.0, 0.0);;
451 let emptykeyhash = Hashtbl.create
0;;
453 let noreprf () = ();;
456 let nouioh : uioh
= object (self
)
458 method key _ _
= self
459 method multiclick _ _ _ _
= self
460 method button _ _ _ _ _
= self
461 method motion _ _
= self
462 method pmotion _ _
= self
463 method infochanged _
= ()
464 method scrollpw
= (0, nan
, nan
)
465 method scrollph
= (0, nan
, nan
)
466 method modehash
= emptykeyhash
467 method eformsgs
= false
468 method alwaysscrolly
= false
471 let platform_to_string = function
472 | Punknown
-> "unknown"
477 | Pcygwin
-> "Cygwin"
481 Printf.sprintf
"llpp version %s, fitz %s, ocaml %s/%d bit"
482 Help.version (fz_version
()) Sys.ocaml_version
Sys.word_size
488 ; scrollb
= scrollbhv lor scrollbvv
504 ; presentation
= false
509 ; fitmodel
= FitProportional
510 ; trimmargins
= false
511 ; trimfuzz
= (0,0,0,0)
512 ; memlimit
= 32 lsl 20
517 ; bgcolor
= (0.5, 0.5, 0.5)
521 ; mustoresize
= 256 lsl 20
526 | Plinux
| Psun
| Pbsd
-> "xdg-open \"%s\""
527 | Posx
-> "open \"%s\""
528 | Pcygwin
-> "cygstart \"%s\""
529 | Punknown
-> "echo %s")
530 ; pathlauncher
= "lp \"%s\""
533 | Plinux
| Pbsd
| Psun
-> "xsel -i"
544 ; columns
= Csingle
[||]
550 ; wheelbypage
= false
551 ; stcmd
= "echo SyncTex"
554 ; paxmark
= Mark_word
559 ; coarseprespos
= false
561 let mk n
= (n
, Hashtbl.create
1) in
575 let conf = { defconf with angle
= defconf.angle
};;
578 let command = Str.global_replace percentsre url
conf.urilauncher
in
579 try ignore
@@ spawn
command []
580 with exn
-> dolog
"failed to execute `%s': %s" command @@ exntos exn
584 if emptystr
conf.urilauncher
587 let url = geturl uri
in
589 then dolog
"obtained empty url from uri %S" uri
597 :: "(searching in this text works just by typing (i.e. no initial '/'))"
602 let url = geturl s
in
604 then (s
, 0, Action
(fun uioh
-> gotourl url; uioh
))
605 else (s
, 0, Noaction
)
610 { store
= Array.make n v
617 let cbcap b
= Array.length b
.store
;;
622 b
.wc
<- (b
.wc
+ 1) mod cap;
624 b
.len
<- min
(b
.len
+ 1) cap;
627 let cbempty b
= b
.len
= 0;;
629 let cbgetg b circular dir
=
633 let rc = b
.rc + dir
in
645 else bound
rc 0 (b
.len
-1)
651 let cbget b
= cbgetg b
false;;
652 let cbgetc b
= cbgetg b
true;;
657 ; stderr
= Unix.stderr
658 ; errmsgs
= Buffer.create
0
663 ; anchor
= emptyanchor
667 ; tilelru
= Queue.create
()
668 ; pagemap
= Hashtbl.create
10
669 ; tilemap
= Hashtbl.create
10
676 ; prects
= Hashtbl.create
1
680 ; searchpattern
= E.s
688 { nav
= cbnew 10 emptyanchor
700 ; checkerstexid
= None
701 ; prevzoom
= (1.0, 0)
715 ; traw
= Raw.create_static `
float ~len
:8
716 ; vraw
= Raw.create_static `
float ~len
:8
720 let copykeyhashes c
=
721 List.map
(fun (k
, v
) -> k
, Hashtbl.copy v
) c
.keyhashes
;
725 let d = state.winh
- h
in
726 max
conf.interpagespace
((d + 1) / 2)
729 let rowyh (c
, coverA
, coverB
) b n
=
730 if c
= 1 || (n
< coverA
|| n
>= state.pagecount
- coverB
)
732 let _, _, vy
, (_, _, h
, _) = b
.(n
) in
735 let n'
= n - coverA
in
738 let e = min
state.pagecount
(s + c
) in
739 let rec find m miny maxh
= if m
= e then miny
, maxh
else
740 let _, _, y
, (_, _, h
, _) = b
.(m
) in
741 let miny = min
miny y
in
742 let maxh = max
maxh h
in
748 let ((c
, coverA
, coverB
) as cl
), b
=
749 match conf.columns
with
750 | Csingle b
-> (1, 0, 0), b
751 | Cmulti
(c
, b
) -> c
, b
752 | Csplit
(_, b
) -> (1, 0, 0), b
754 if Array.length b
= 0
757 let rec bsearch nmin nmax
=
759 then bound nmin
0 (state.pagecount
-1)
761 let n = (nmax
+ nmin
) / 2 in
762 let vy, h
= rowyh cl b
n in
766 let ips = calcips h
in
768 let y1 = vy + h
+ ips in
772 then 0, vy + h
+ conf.interpagespace
774 let y0 = vy - conf.interpagespace
in
775 y0, y0 + h
+ conf.interpagespace
785 if n < state.pagecount
- coverB
786 then ((n-coverA
)/c
)*c
+ coverA
793 then bsearch (n+1) nmax
794 else bsearch nmin
(n-1)
797 bsearch 0 (state.pagecount
-1);
801 match conf.columns
with
802 | Cmulti
((_, _, _) as cl
, b
) ->
803 if Array.length b
> 0
805 let y, h
= rowyh cl b
(Array.length b
- 1) in
806 y + h
+ (if conf.presentation
then calcips h
else 0)
809 if Array.length b
> 0
811 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
812 y + h
+ (if conf.presentation
then calcips h
else 0)
815 if Array.length b
> 0
817 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
822 let getpageywh pageno
=
823 let pageno = bound
pageno 0 (state.pagecount
-1) in
824 match conf.columns
with
826 if Array.length b
= 0
829 let (_, _, y, (_, w
, h
, _)) = b
.(pageno) in
837 if Array.length b
= 0
840 let y, h
= rowyh cl b
pageno in
841 let (_, _, _, (_, w
, _, _)) = b
.(pageno) in
849 if Array.length b
= 0
853 let (_, _, y, (_, w
, h
, _)) = b
.(n) in
857 let getpageyh pageno =
858 let y,_,h
= getpageywh pageno in
862 let getpagedim pageno =
865 | (n, _, _, _) as pdim
:: rest
->
867 then (if n = pageno then pdim
else ppdim
)
872 f (-1, -1, -1, -1) state.pdims
875 let getpdimno pageno =
879 | (n, _, _, _) :: rest
->
881 then (if n = pageno then np else p
)
889 let getpagey pageno = fst
(getpageyh pageno);;
893 let coloff = l
.pagecol
* l
.pageh
in
894 float (l
.pagey
+ coloff) /. float l
.pageh
902 then float l
.pagedispy
/. float (calcips l
.pageh
)
903 else float l
.pagedispy
/. float conf.interpagespace
906 (l
.pageno, top, dtop)
910 match state.layout
with
911 | l
:: _ -> getanchor1 l
913 let n = page_of_y state.y in
917 let y, h
= getpageyh n in
918 let dy = y - state.y in
922 let ips = calcips h
in
923 float (dy + ips) /. float ips
925 float dy /. float conf.interpagespace
930 let fontpath = ref E.s;;
932 type historder
= [ `lastvisit
| `title
| `path
| `file
];;
935 Map.Make
(struct type t
= (int * int) let compare = compare end);;
938 let l = String.length
s in
939 let b = Buffer.create
l in
940 Parser.unent
b s 0 l;
945 try Sys.getenv
"HOME"
947 dolog
"cannot determine home directory location: %s" @@ exntos exn
;
951 let modifier_of_string = function
952 | "alt" -> Wsi.altmask
953 | "shift" -> Wsi.shiftmask
954 | "ctrl" | "control" -> Wsi.ctrlmask
955 | "meta" -> Wsi.metamask
959 let keys_of_string s =
960 let key_of_string r
s =
961 let elems = Str.full_split r
s in
964 let m1 = modifier_of_string s in
966 then (Wsi.namekey
s, m
)
969 | Str.Delim
s when n land 1 = 0 -> g s
971 | Str.Delim
_ -> (k
, m
)
973 let rec loop n k m
= function
976 let k, m
= f n k m x
in
981 let elems = Str.split whitere
s in
982 List.map
(key_of_string (Str.regexp
"-")) elems
985 let config_of c attrs
=
989 | "scroll-bar-width" -> { c
with scrollbw
= max
0 (int_of_string v
) }
990 | "scroll-handle-height" -> { c
with scrollh
= max
0 (int_of_string v
) }
991 | "case-insensitive-search" -> { c
with icase
= bool_of_string v
}
992 | "preload" -> { c
with preload
= bool_of_string v
}
993 | "page-bias" -> { c
with pagebias
= int_of_string v
}
994 | "scroll-step" -> { c
with scrollstep
= max
1 (int_of_string v
) }
995 | "horizontal-scroll-step" ->
996 { c
with hscrollstep
= max
(int_of_string v
) 1 }
997 | "auto-scroll-step" ->
998 { c
with autoscrollstep
= max
0 (int_of_string v
) }
999 | "max-height-fit" -> { c
with maxhfit
= bool_of_string v
}
1000 | "crop-hack" -> { c
with crophack
= bool_of_string v
}
1003 match String.lowercase v
with
1004 | "true" -> Some infinity
1006 | f -> Some
(float_of_string
f)
1008 { c
with maxwait
= mw }
1009 | "highlight-links" -> { c
with hlinks
= bool_of_string v
}
1010 | "under-cursor-info" -> { c
with underinfo
= bool_of_string v
}
1011 | "vertical-margin" ->
1012 { c
with interpagespace
= max
0 (int_of_string v
) }
1014 let zoom = float_of_string v
/. 100. in
1015 let zoom = max
zoom 0.0 in
1016 { c
with zoom = zoom }
1017 | "presentation" -> { c
with presentation
= bool_of_string v
}
1018 | "rotation-angle" -> { c
with angle
= int_of_string v
}
1019 | "width" -> { c
with cwinw
= max
20 (int_of_string v
) }
1020 | "height" -> { c
with cwinh
= max
20 (int_of_string v
) }
1021 | "persistent-bookmarks" -> { c
with savebmarks
= bool_of_string v
}
1022 | "proportional-display" ->
1025 then FitProportional
1028 { c
with fitmodel
= fm }
1029 | "fit-model" -> { c
with fitmodel
= FMTE.of_string v
}
1030 | "pixmap-cache-size" ->
1031 { c
with memlimit
= max
2 (int_of_string_with_suffix v
) }
1032 | "tex-count" -> { c
with texcount
= max
1 (int_of_string v
) }
1033 | "slice-height" -> { c
with sliceheight
= max
2 (int_of_string v
) }
1034 | "thumbnail-width" -> { c
with thumbw
= max
2 (int_of_string v
) }
1035 | "persistent-location" -> { c
with jumpback
= bool_of_string v
}
1036 | "background-color" -> { c
with bgcolor
= color_of_string v
}
1037 | "tile-width" -> { c
with tilew
= max
2 (int_of_string v
) }
1038 | "tile-height" -> { c
with tileh
= max
2 (int_of_string v
) }
1039 | "mupdf-store-size" ->
1040 { c
with mustoresize
= max
1024 (int_of_string_with_suffix v
) }
1041 | "checkers" -> { c
with checkers
= bool_of_string v
}
1042 | "aalevel" -> { c
with aalevel
= max
0 (int_of_string v
) }
1043 | "trim-margins" -> { c
with trimmargins
= bool_of_string v
}
1044 | "trim-fuzz" -> { c
with trimfuzz
= irect_of_string v
}
1045 | "uri-launcher" -> { c
with urilauncher
= unentS v
}
1046 | "path-launcher" -> { c
with pathlauncher
= unentS v
}
1047 | "color-space" -> { c
with colorspace
= CSTE.of_string v
}
1048 | "invert-colors" -> { c
with invert
= bool_of_string v
}
1049 | "brightness" -> { c
with colorscale
= float_of_string v
}
1050 | "ghyllscroll" -> { c
with ghyllscroll
= ghyllscroll_of_string v
}
1052 let (n, _, _) as nab
= multicolumns_of_string v
in
1054 then { c
with columns
= Csplit
(-n, E.a
) }
1055 else { c
with columns
= Cmulti
(nab
, E.a
) }
1056 | "birds-eye-columns" ->
1057 { c
with beyecolumns
= Some
(max
(int_of_string v
) 2) }
1058 | "selection-command" -> { c
with selcmd
= unentS v
}
1059 | "synctex-command" -> { c
with stcmd
= unentS v
}
1060 | "pax-command" -> { c
with paxcmd
= unentS v
}
1061 | "askpass-command" -> { c
with passcmd
= unentS v
}
1062 | "savepath-command" -> { c
with savecmd
= unentS v
}
1063 | "update-cursor" -> { c
with updatecurs
= bool_of_string v
}
1064 | "hint-font-size" -> { c
with hfsize
= bound
(int_of_string v
) 5 100 }
1065 | "page-scroll-scale" -> { c
with pgscale
= float_of_string v
}
1066 | "use-pbo" -> { c
with usepbo
= bool_of_string v
}
1067 | "wheel-scrolls-pages" -> { c
with wheelbypage
= bool_of_string v
}
1068 | "horizontal-scrollbar-visible" ->
1071 then c
.scrollb
lor scrollbhv
1072 else c
.scrollb
land (lnot
scrollbhv)
1074 { c
with scrollb
= b }
1075 | "vertical-scrollbar-visible" ->
1078 then c
.scrollb
lor scrollbvv
1079 else c
.scrollb
land (lnot
scrollbvv)
1081 { c
with scrollb
= b }
1082 | "remote-in-a-new-instance" -> { c
with riani
= bool_of_string v
}
1086 then Some
(ref (0.0, 0, 0))
1088 | "point-and-x-mark" -> { c
with paxmark
= MTE.of_string v
}
1089 | "scroll-bar-on-the-left" -> { c
with leftscroll
= bool_of_string v
}
1090 | "title" -> { c
with title
= unentS v
}
1091 | "last-visit" -> { c
with lastvisit
= float_of_string v
}
1092 | "edit-annotations-inline" -> { c
with annotinline
= bool_of_string v
}
1093 | "coarse-presentation-positioning" ->
1094 { c
with coarseprespos
= bool_of_string v
}
1097 dolog
"error processing attribute (`%S' = `%S'): %s" k v
@@ exntos exn
;
1100 let rec fold c
= function
1103 let c = apply c k v
in
1106 fold { c with keyhashes
= copykeyhashes c } attrs
;
1109 let fromstring f pos
n v
d =
1112 dolog
"error processing attribute (%S=%S) at %d\n%s" 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
.ghyllscroll
<- src
.ghyllscroll
;
1192 dst
.columns
<- src
.columns
;
1193 dst
.beyecolumns
<- src
.beyecolumns
;
1194 dst
.selcmd
<- src
.selcmd
;
1195 dst
.updatecurs
<- src
.updatecurs
;
1196 dst
.pathlauncher
<- src
.pathlauncher
;
1197 dst
.keyhashes
<- copykeyhashes src
;
1198 dst
.hfsize
<- src
.hfsize
;
1199 dst
.hscrollstep
<- src
.hscrollstep
;
1200 dst
.pgscale
<- src
.pgscale
;
1201 dst
.usepbo
<- src
.usepbo
;
1202 dst
.wheelbypage
<- src
.wheelbypage
;
1203 dst
.stcmd
<- src
.stcmd
;
1204 dst
.paxcmd
<- src
.paxcmd
;
1205 dst
.passcmd
<- src
.passcmd
;
1206 dst
.savecmd
<- src
.savecmd
;
1207 dst
.scrollb
<- src
.scrollb
;
1208 dst
.riani
<- src
.riani
;
1209 dst
.paxmark
<- src
.paxmark
;
1210 dst
.leftscroll
<- src
.leftscroll
;
1211 dst
.title
<- src
.title
;
1212 dst
.annotinline
<- src
.annotinline
;
1213 dst
.coarseprespos
<- src
.coarseprespos
;
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 ^
"'")
1227 let h = Hashtbl.create
10 in
1228 let dc = { defconf with angle
= defconf.angle
} in
1229 let rec toplevel v t spos
_ =
1231 | Vdata
| Vcdata
| Vend
-> v
1232 | Vopen
("llppconfig", _, closed
) ->
1235 else { v
with f = llppconfig
}
1237 error
"unexpected subelement at top level" s spos
1238 | Vclose
_ -> error
"unexpected close at top level" s spos
1240 and llppconfig v t spos
_ =
1242 | Vdata
| Vcdata
-> v
1243 | Vend
-> error
"unexpected end of input in llppconfig" s spos
1244 | Vopen
("defaults", attrs
, closed
) ->
1245 let c = config_of dc attrs
in
1249 else { v
with f = defaults
}
1251 | Vopen
("ui-font", attrs
, closed
) ->
1252 let rec getsize size
= function
1254 | ("size", v
) :: rest
->
1256 fromstring int_of_string spos
"size" v
fstate.fontsize
in
1258 | l -> getsize size l
1260 fstate.fontsize
<- getsize fstate.fontsize attrs
;
1263 else { v
with f = uifont
(Buffer.create
10) }
1265 | Vopen
("doc", attrs
, closed
) ->
1266 let pathent, spage
, srely
, span
, svisy
, origin
= doc_of attrs
in
1267 let path = unentS pathent
1268 and origin
= unentS origin
1269 and pageno = fromstring int_of_string spos
"page" spage
0
1270 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1271 and pan
= fromstring int_of_string spos
"pan" span
0
1272 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1273 let c = config_of dc attrs
in
1274 let anchor = (pageno, rely
, visy
) in
1276 then (Hashtbl.add
h path (c, [], pan
, anchor, origin
); v
)
1277 else { v
with f = doc
path origin pan
anchor c [] }
1280 error
"unexpected subelement in llppconfig" s spos
1282 | Vclose
"llppconfig" -> { v
with f = toplevel }
1283 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
1285 and defaults v t spos
_ =
1287 | Vdata
| Vcdata
-> v
1288 | Vend
-> error
"unexpected end of input in defaults" s spos
1289 | Vopen
("keymap", attrs
, closed
) ->
1291 try List.assoc
"mode" attrs
1292 with Not_found
-> "global" in
1297 let h = findkeyhash dc modename in
1298 KeyMap.iter
(Hashtbl.replace
h) keymap
;
1301 { v
with f = pkeymap
ret KeyMap.empty
}
1303 | Vopen
(_, _, _) ->
1304 error
"unexpected subelement in defaults" s spos
1306 | Vclose
"defaults" ->
1307 { v
with f = llppconfig
}
1309 | Vclose
_ -> error
"unexpected close in defaults" s spos
1311 and uifont
b v t spos epos
=
1314 Buffer.add_substring
b s spos
(epos
- spos
);
1316 | Vopen
(_, _, _) ->
1317 error
"unexpected subelement in ui-font" s spos
1318 | Vclose
"ui-font" ->
1319 if emptystr
!fontpath
1320 then fontpath := Buffer.contents
b;
1321 { v
with f = llppconfig
}
1322 | Vclose
_ -> error
"unexpected close in ui-font" s spos
1323 | Vend
-> error
"unexpected end of input in ui-font" s spos
1325 and doc
path origin pan
anchor c bookmarks v t spos
_ =
1327 | Vdata
| Vcdata
-> v
1328 | Vend
-> error
"unexpected end of input in doc" s spos
1329 | Vopen
("bookmarks", _, closed
) ->
1332 else { v
with f = pbookmarks
path origin pan
anchor c bookmarks
}
1334 | Vopen
("keymap", attrs
, closed
) ->
1336 try List.assoc
"mode" attrs
1337 with Not_found
-> "global"
1343 let h = findkeyhash c modename in
1344 KeyMap.iter
(Hashtbl.replace
h) keymap
;
1345 doc
path origin pan
anchor c bookmarks
1347 { v
with f = pkeymap
ret KeyMap.empty
}
1349 | Vopen
(_, _, _) ->
1350 error
"unexpected subelement in doc" s spos
1353 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor, origin
);
1354 { v
with f = llppconfig
}
1356 | Vclose
_ -> error
"unexpected close in doc" s spos
1358 and pkeymap
ret keymap v t spos
_ =
1360 | Vdata
| Vcdata
-> v
1361 | Vend
-> error
"unexpected end of input in keymap" s spos
1362 | Vopen
("map", attrs
, closed
) ->
1363 let r, l = map_of attrs
in
1364 let kss = fromstring keys_of_string spos
"in" r [] in
1365 let lss = fromstring keys_of_string spos
"out" l [] in
1369 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
1370 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
1373 then { v
with f = pkeymap
ret keymap }
1376 { v
with f = skip
"map" f }
1379 error
"unexpected subelement in keymap" s spos
1381 | Vclose
"keymap" ->
1382 { v
with f = ret keymap }
1384 | Vclose
_ -> error
"unexpected close in keymap" s spos
1386 and pbookmarks
path origin pan
anchor c bookmarks v t spos
_ =
1388 | Vdata
| Vcdata
-> v
1389 | Vend
-> error
"unexpected end of input in bookmarks" s spos
1390 | Vopen
("item", attrs
, closed
) ->
1391 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
1392 let page = fromstring int_of_string spos
"page" spage
0
1393 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1394 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1396 (unentS titleent, 0, Oanchor
(page, rely
, visy
)) :: bookmarks
1399 then { v
with f = pbookmarks
path origin pan
anchor c bookmarks }
1402 { v
with f = skip
"item" f }
1405 error
"unexpected subelement in bookmarks" s spos
1407 | Vclose
"bookmarks" ->
1408 { v
with f = doc
path origin pan
anchor c bookmarks }
1410 | Vclose
_ -> Parser.parse_error
"unexpected close in bookmarks" s spos
1412 and skip tag
f v t spos
_ =
1414 | Vdata
| Vcdata
-> v
1416 Parser.parse_error
("unexpected end of input in skipped " ^ tag
) s spos
1417 | Vopen
(tag'
, _, closed
) ->
1421 let f'
() = { v
with f = skip tag
f } in
1422 { v
with f = skip tag'
f'
}
1426 else Parser.parse_error
("unexpected close in skipped " ^ tag
) s spos
1429 parse
{ f = toplevel; accu
= () } s;
1433 let do_load f contents
=
1436 | Parser.Parse_error
(msg
, s, pos
) ->
1437 let subs = Parser.subs s pos
in
1438 Utils.error
"parse error: %s: at %d [..%S..]" msg pos
subs
1440 | exn
-> Utils.error
"parse error: %s" @@ exntos exn
1445 let xdgconfdir = Utils.getenvwithdef
"XDG_CONFIG_HOME" E.s in
1446 if emptystr
xdgconfdir
1449 let dir = Filename.concat
home ".config" in
1450 if Sys.is_directory
dir then dir else home
1454 Filename.concat
dir "llpp.conf"
1457 let confpath = ref defconfpath;;
1459 let load2 f default
=
1460 match filecontents
!confpath with
1461 | contents
-> f @@ do_load get contents
1462 | exception Unix.Unix_error
(Unix.ENOENT
, "open", _) ->
1463 f (Hashtbl.create
0, defconf)
1465 dolog
"error loading configuration from `%S': %s" !confpath @@ exntos exn
;
1469 let load1 f = load2 f false;;
1477 (fun path (conf, _, _, _, _) ((_, besttime
) as best
) ->
1478 if conf.lastvisit
> besttime
1479 then (path, conf.lastvisit
)
1482 (state.path, -.infinity
)
1486 let pc, pb
, px
, pa
, po
=
1488 let absname = abspath
state.path in
1489 Hashtbl.find h absname
1490 with Not_found
-> dc, [], 0, emptyanchor, state.origin
1494 state.bookmarks <- pb
;
1498 then state.anchor <- pa
;
1499 cbput state.hists
.nav pa
;
1507 Hashtbl.fold (fun path (pc, pb
, px
, pa
, po
) accu
->
1508 (path, pc, pb
, px
, pa
, po
) :: accu
)
1514 let add_attrs bb always
dc c time
=
1516 Buffer.add_string bb
"\n ";
1517 Printf.bprintf bb fmt
s
1519 let o c fmt
s = if c then o' fmt
s else ignore
in
1520 let ob s a
b = o (always
|| a
!= b) "%s='%b'" s a
1521 and op
s a
b = o (always
|| a
<> b) "%s='%b'" s (a
!= None
)
1522 and oi
s a
b = o (always
|| a
!= b) "%s='%d'" s a
1523 and oI
s a
b = o (always
|| a
!= b) "%s='%s'" s (string_with_suffix_of_int a
)
1524 and oz
s a
b = o (always
|| a
<> b) "%s='%g'" s (a
*.100.)
1525 and oF
s a
b = o (always
|| a
<> b) "%s='%f'" s a
1526 and oL
s a
b = o (always
|| a
<> b) "%s='%Ld'" s a
1527 and oc
s a
b = o (always
|| a
<> b) "%s='%s'" s (color_to_string a
)
1528 and oC
s a
b = o (always
|| a
<> b) "%s='%s'" s (CSTE.to_string a
)
1529 and oR
s a
b = o (always
|| a
<> b) "%s='%s'" s (irect_to_string a
)
1530 and oFm
s a
b = o (always
|| a
<> b) "%s='%s'" s (FMTE.to_string a
)
1531 and oSv
s a
b m
= o (always
|| a
<> b) "%s='%b'" s (a
land m
!= 0)
1532 and oPm
s a
b = o (always
|| a
<> b) "%s='%s'" s (MTE.to_string a
)
1534 o (always
|| a
<> b) "%s='%s'" s @@ Parser.enent a
0 (String.length a
)
1539 | Some
(_N
, _A
, _B
) -> o'
"%s='%u,%u,%u'" s _N _A _B
1543 | _ -> o'
"%s='none'" s
1553 else string_of_float
f
1560 | Cmulti
((n, a
, b), _) when n > 1 -> o'
"%s='%d,%d,%d'" s n a
b
1561 | Csplit
(n, _) when n > 1 -> o'
"%s='%d'" s ~
-n
1562 | Cmulti
_ | Csplit
_ | Csingle
_ -> ()
1567 | Some
c when c > 1 -> o'
"%s='%d'" s c
1570 oi
"width" c.cwinw
dc.cwinw
;
1571 oi
"height" c.cwinh
dc.cwinh
;
1572 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
1573 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
1574 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
1575 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
1576 ob "case-insensitive-search" c.icase
dc.icase
;
1577 ob "preload" c.preload
dc.preload
;
1578 oi
"page-bias" c.pagebias
dc.pagebias
;
1579 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
1580 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
1581 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
1582 ob "crop-hack" c.crophack
dc.crophack
;
1583 oW
"throttle" c.maxwait
dc.maxwait
;
1584 ob "highlight-links" c.hlinks
dc.hlinks
;
1585 ob "under-cursor-info" c.underinfo
dc.underinfo
;
1586 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
1587 oz
"zoom" c.zoom dc.zoom;
1588 ob "presentation" c.presentation
dc.presentation
;
1589 oi
"rotation-angle" c.angle
dc.angle
;
1590 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
1591 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
1592 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
1593 oi
"tex-count" c.texcount
dc.texcount
;
1594 oi
"slice-height" c.sliceheight
dc.sliceheight
;
1595 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
1596 ob "persistent-location" c.jumpback
dc.jumpback
;
1597 oc
"background-color" c.bgcolor
dc.bgcolor
;
1598 oi
"tile-width" c.tilew
dc.tilew
;
1599 oi
"tile-height" c.tileh
dc.tileh
;
1600 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
1601 ob "checkers" c.checkers
dc.checkers
;
1602 oi
"aalevel" c.aalevel
dc.aalevel
;
1603 ob "trim-margins" c.trimmargins
dc.trimmargins
;
1604 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
1605 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
1606 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
1607 oC
"color-space" c.colorspace
dc.colorspace
;
1608 ob "invert-colors" c.invert
dc.invert
;
1609 oF
"brightness" c.colorscale
dc.colorscale
;
1610 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
1611 oco
"columns" c.columns
dc.columns
;
1612 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
1613 os
"selection-command" c.selcmd
dc.selcmd
;
1614 os
"synctex-command" c.stcmd
dc.stcmd
;
1615 os
"pax-command" c.paxcmd
dc.paxcmd
;
1616 os
"askpass-command" c.passcmd
dc.passcmd
;
1617 os
"savepath-command" c.savecmd
dc.savecmd
;
1618 ob "update-cursor" c.updatecurs
dc.updatecurs
;
1619 oi
"hint-font-size" c.hfsize
dc.hfsize
;
1620 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
1621 oF
"page-scroll-scale" c.pgscale
dc.pgscale
;
1622 ob "use-pbo" c.usepbo
dc.usepbo
;
1623 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
1624 ob "remote-in-a-new-instance" c.riani
dc.riani
;
1625 op
"point-and-x" c.pax
dc.pax
;
1626 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
1627 ob "scroll-bar-on-the-left" c.leftscroll
dc.leftscroll
;
1629 then os
"title" c.title
dc.title
;
1630 oL
"last-visit" (Int64.of_float time
) 0L;
1631 ob "edit-annotations-inline" c.annotinline
dc.annotinline
;
1632 ob "coarse-presentation-positioning" c.coarseprespos
dc.coarseprespos
;
1635 let keymapsbuf always
dc c =
1636 let bb = Buffer.create
16 in
1637 let rec loop = function
1639 | (modename, h) :: rest
->
1640 let dh = findkeyhash dc modename in
1641 if always
|| h <> dh
1643 if Hashtbl.length
h > 0
1645 if Buffer.length
bb > 0
1646 then Buffer.add_char
bb '
\n'
;
1647 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
1648 Hashtbl.iter
(fun i
o ->
1649 let isdifferent = always
||
1651 let dO = Hashtbl.find dh i
in
1653 with Not_found
-> true
1658 if Wsi.withctrl m
then Buffer.add_string
bb "ctrl-";
1659 if Wsi.withalt m
then Buffer.add_string
bb "alt-";
1660 if Wsi.withshift m
then Buffer.add_string
bb "shift-";
1661 if Wsi.withmeta m
then Buffer.add_string
bb "meta-";
1662 Buffer.add_string
bb (Wsi.keyname
k);
1665 let rec loop = function
1667 | km
:: [] -> addkm km
1668 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
1672 Buffer.add_string
bb "<map in='";
1676 Buffer.add_string
bb "' out='";
1678 Buffer.add_string
bb "'/>\n"
1681 Buffer.add_string
bb "' out='";
1683 Buffer.add_string
bb "'/>\n"
1685 | KMmulti
(ins
, kms
) ->
1686 Buffer.add_char
bb ' '
;
1688 Buffer.add_string
bb "' out='";
1690 Buffer.add_string
bb "'/>\n"
1692 Buffer.add_string
bb "</keymap>";
1701 let save1 bb leavebirdseye x
h dc =
1702 let uifontsize = fstate.fontsize
in
1703 let dc = if conf.bedefault
then conf else dc in
1704 Buffer.add_string
bb "<llppconfig>\n";
1706 if nonemptystr
!fontpath
1708 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
1714 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
1717 Buffer.add_string
bb "<defaults";
1718 add_attrs bb true dc dc nan
;
1719 let kb = keymapsbuf true dc dc in
1720 if Buffer.length
kb > 0
1722 Buffer.add_string
bb ">\n";
1723 Buffer.add_buffer
bb kb;
1724 Buffer.add_string
bb "\n</defaults>\n";
1726 else Buffer.add_string
bb "/>\n";
1728 let adddoc path pan
anchor c bookmarks time origin
=
1729 if bookmarks == [] && c = dc && anchor = emptyanchor
1732 Printf.bprintf
bb "<doc path='%s'"
1733 (Parser.enent
path 0 (String.length
path));
1735 if nonemptystr origin
1737 Printf.bprintf
bb "\n origin='%s'"
1738 (Parser.enent origin
0 (String.length origin
));
1740 if anchor <> emptyanchor
1742 let n, rely
, visy
= anchor in
1743 Printf.bprintf
bb "\n page='%d'" n;
1746 Printf.bprintf
bb " rely='%f'" rely
1748 if abs_float visy
> 1e-6
1750 Printf.bprintf
bb " visy='%f'" visy
1755 then Printf.bprintf
bb " pan='%d'" pan
;
1757 add_attrs bb false dc c time
;
1758 let kb = keymapsbuf false dc c in
1760 begin match bookmarks with
1762 if Buffer.length
kb > 0
1764 Buffer.add_string
bb ">\n";
1765 Buffer.add_buffer
bb kb;
1766 Buffer.add_string
bb "\n</doc>\n";
1768 else Buffer.add_string
bb "/>\n"
1770 Buffer.add_string
bb ">\n<bookmarks>\n";
1771 List.iter
(fun (title
, _, kind
) ->
1772 begin match kind
with
1773 | Oanchor
(page, rely
, visy
) ->
1775 "<item title='%s' page='%d'"
1776 (Parser.enent title
0 (String.length title
))
1781 Printf.bprintf
bb " rely='%f'" rely
1783 if abs_float visy
> 1e-6
1785 Printf.bprintf
bb " visy='%f'" visy
1787 | Ohistory
_ | Onone
| Ouri
_ | Oremote
_
1788 | Oremotedest
_ | Olaunch
_ ->
1789 failwith
"unexpected link in bookmarks"
1791 Buffer.add_string
bb "/>\n";
1793 Buffer.add_string
bb "</bookmarks>";
1794 if Buffer.length
kb > 0
1796 Buffer.add_string
bb "\n";
1797 Buffer.add_buffer
bb kb;
1799 Buffer.add_string
bb "\n</doc>\n";
1805 match state.mode
with
1806 | Birdseye
(c, pan, _, _, _) ->
1808 match conf.columns
with
1809 | Cmulti
((c, _, _), _) -> Some
c
1813 match c.columns
with
1814 | Cmulti
(c, _) -> Cmulti
(c, E.a
)
1815 | Csingle
_ -> Csingle
E.a
1816 | Csplit
_ -> failwith
"quit from bird's eye while split"
1818 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
1821 | LinkNav
_ -> x
, conf
1823 let docpath = if nonemptystr
state.path then abspath
state.path else E.s in
1824 if nonemptystr
docpath
1826 adddoc docpath pan (getanchor ())
1828 let autoscrollstep =
1829 match state.autoscroll
with
1831 | None
-> conf.autoscrollstep
1833 begin match state.mode
with
1834 | Birdseye beye
-> leavebirdseye beye
true
1839 { conf with autoscrollstep = autoscrollstep }
1841 (if conf.savebmarks
then state.bookmarks else [])
1845 Hashtbl.iter
(fun path (c, bookmarks, x
, anchor, origin
) ->
1846 if docpath <> abspath
path
1847 then adddoc path x
anchor c bookmarks c.lastvisit origin
1849 Buffer.add_string
bb "</llppconfig>\n";
1853 let save leavebirdseye
=
1854 let relx = float state.x
/. float state.winw
in
1856 let cx w = truncate
(relx *. float w) in
1858 (fun (w, h, x
) ws
->
1860 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
1861 | Wsi.MaxVert
-> (w, conf.cwinh
, x
)
1862 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
1864 (state.winw
, state.winh
, state.x
) state.winstate
1868 let bb = Buffer.create
32768 in
1870 save1 bb leavebirdseye x
h dc
1872 if load1 save2 && Buffer.length
bb > 0
1875 let tmp = !confpath ^
".tmp" in
1876 let oc = open_out_bin
tmp in
1877 Buffer.output_buffer
oc bb;
1879 Unix.rename
tmp !confpath;
1881 dolog
"error saving configuration: %s" @@ exntos exn
1886 (* This here has a potential of rising SIGPIPE, silently and
1887 seemingly harmlessly (when -gc was supplied an invalid
1888 executable for instance) probably needs revisiting *)
1889 let n'
= Unix.write fd
(Bytes.of_string s) 0 n in
1891 then Utils.error
"Unix.write %d = %d" n n'
1893 let href = ref (Hashtbl.create
0) in
1894 let cref = ref defconf in
1896 let f path (pc, _pb
, _px
, _pa
, _po
) =
1898 Printf.sprintf
"%s\000%ld\000" path (Int32.of_float
pc.lastvisit
)
1900 wr s (String.length
s)
1907 ignore
(load1 push);
1908 Unix.shutdown fd
Unix.SHUTDOWN_SEND
;
1909 let s = fdcontents fd
in
1911 match String.index_from
s ppos '
\000'
with
1912 | exception Not_found
-> ()
1914 match String.index_from
s (zpos1
+1) '
\000'
with
1915 | exception Not_found
-> error
"invalid gc input in (%S) at %d" s zpos1
1917 let okey = StringLabels.sub
s ~pos
:ppos ~len
:(zpos1
-ppos
) in
1918 let nkey = StringLabels.sub
s ~pos
:(zpos1
+1) ~len
:(zpos2
-zpos1
-1) in
1920 then (Hashtbl.remove
!href okey; f (zpos2
+1))
1922 match Hashtbl.find !href okey with
1923 | exception Not_found
-> Utils.error
"gc: cannot find %S" okey
1925 Hashtbl.remove
!href okey;
1926 Hashtbl.replace
!href nkey v;
1930 let bb = Buffer.create
32768 in
1931 let save2 (_h
, dc) = save1 bb (fun _ _ -> ()) 0 !href dc in
1932 if load1 save2 && Buffer.length
bb > 0
1935 let tmp = !confpath ^
".tmp" in
1936 let oc = open_out_bin
tmp in
1937 Buffer.output_buffer
oc bb;
1939 Unix.rename
tmp !confpath;
1941 dolog
"error saving configuration: %s" @@ exntos exn
1945 let logcurrently = function
1946 | Idle
-> dolog
"Idle"
1947 | Loading
(l, gen
) ->
1948 dolog
"Loading %d gen=%d curgen=%d" l.pageno gen
state.gen
1949 | Tiling
(l, pageopaque
, colorspace
, angle
, gen
, col
, row
, tilew
, tileh
) ->
1951 "Tiling %d[%d,%d] page=%s cs=%s angle"
1952 l.pageno col row
(~
> pageopaque
)
1953 (CSTE.to_string colorspace
)
1955 dolog
"gen=(%d,%d) (%d,%d) tile=(%d,%d) (%d,%d)"
1956 angle gen
conf.angle
state.gen
1958 conf.tilew
conf.tileh