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
"invalid ghyll N(%d),A(%d),B(%d) (N <= A, A < B, N <= B)"
46 let ghyllscroll_to_string ((n
, a
, b
) as nab
) =
47 (**) if nab
= fastghyllscroll then "fast"
48 else if nab
= neatghyllscroll then "neat"
49 else Printf.sprintf
"%d,%d,%d" n a b
;
52 let multicolumns_to_string (n
, a
, b
) =
54 then Printf.sprintf
"%d" n
55 else Printf.sprintf
"%d,%d,%d" n a b
;
58 let multicolumns_of_string s
=
60 (int_of_string s
, 0, 0)
62 Scanf.sscanf s
"%u,%u,%u" (fun n a b
->
64 then failwith
"subtly broken"; (n
, a
, b
)
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
100 and opaque
= Opaque.t
106 and fontpath
= string
107 and trimcachepath
= string
109 and trimparams
= (trimmargins
* irect
)
110 and colorspace
= | Rgb
| Bgr
| Gray
118 and tileparams
= (x
* y
* width
* height
* tilex
* tiley
)
122 | Ulinkgoto
of (int * int)
124 | Uunexpected
of string
125 | Ulaunch
of launchcommand
127 | Uremote
of (filename
* pageno
)
128 | Uremotedest
of (filename
* destname
)
129 and facename
= string
130 and launchcommand
= string
131 and filename
= string
133 and destname
= string
145 | LDfirstvisible
of (int * int * int)
154 and anchor
= pageno
* top
* dtop
155 and rect
= float * float * float * float * float * float * float * float
156 and infochange
= | Memused
| Docinfo
| Pdim
159 class type uioh
= object
160 method display
: unit
161 method key
: int -> int -> uioh
162 method button
: int -> bool -> int -> int -> int -> uioh
163 method multiclick
: int -> int -> int -> int -> uioh
164 method motion
: int -> int -> uioh
165 method pmotion
: int -> int -> uioh
166 method infochanged
: infochange
-> unit
167 method scrollpw
: (int * float * float)
168 method scrollph
: (int * float * float)
169 method modehash
: keyhash
170 method eformsgs
: bool
173 module type TextEnumType
=
177 val names
: string array
180 module TextEnumMake
(Ten
: TextEnumType
) =
182 let names = Ten.names;;
183 let to_int (t
: Ten.t
) = Obj.magic t
;;
184 let to_string t
= names.(to_int t
);;
185 let of_int n
: Ten.t
= Obj.magic n
;;
188 if i
= Array.length
names
189 then failwith
("invalid " ^
Ten.name ^
": " ^ s
)
198 module CSTE
= TextEnumMake
(struct
199 type t
= colorspace
;;
200 let name = "colorspace";;
201 let names = [|"rgb"; "bgr"; "gray"|];;
204 module MTE
= TextEnumMake
(struct
207 let names = [|"page"; "block"; "line"; "word"|];;
210 module FMTE
= TextEnumMake
(struct
212 let name = "fitmodel";;
213 let names = [|"width"; "proportional"; "page"|];;
217 { mutable scrollbw
: int
218 ; mutable scrollh
: int
219 ; mutable scrollb
: scrollb
220 ; mutable icase
: bool
221 ; mutable preload
: bool
222 ; mutable pagebias
: int
223 ; mutable verbose
: bool
224 ; mutable debug
: bool
225 ; mutable scrollstep
: int
226 ; mutable hscrollstep
: int
227 ; mutable maxhfit
: bool
228 ; mutable crophack
: bool
229 ; mutable autoscrollstep
: int
230 ; mutable maxwait
: float option
231 ; mutable hlinks
: bool
232 ; mutable underinfo
: bool
233 ; mutable interpagespace
: interpagespace
234 ; mutable zoom
: float
235 ; mutable presentation
: bool
236 ; mutable angle
: angle
237 ; mutable cwinw
: int
238 ; mutable cwinh
: int
239 ; mutable savebmarks
: bool
240 ; mutable fitmodel
: fitmodel
241 ; mutable trimmargins
: trimmargins
242 ; mutable trimfuzz
: irect
243 ; mutable memlimit
: memsize
244 ; mutable texcount
: texcount
245 ; mutable sliceheight
: sliceheight
246 ; mutable thumbw
: width
247 ; mutable jumpback
: bool
248 ; mutable bgcolor
: (float * float * float)
249 ; mutable bedefault
: bool
250 ; mutable tilew
: int
251 ; mutable tileh
: int
252 ; mutable mustoresize
: memsize
253 ; mutable checkers
: bool
254 ; mutable aalevel
: int
255 ; mutable urilauncher
: string
256 ; mutable pathlauncher
: string
257 ; mutable colorspace
: colorspace
258 ; mutable invert
: bool
259 ; mutable colorscale
: float
260 ; mutable redirectstderr
: bool
261 ; mutable ghyllscroll
: (int * int * int) option
262 ; mutable columns
: columns
263 ; mutable beyecolumns
: columncount
option
264 ; mutable selcmd
: string
265 ; mutable paxcmd
: string
266 ; mutable updatecurs
: bool
267 ; mutable keyhashes
: (string * keyhash
) list
268 ; mutable hfsize
: int
269 ; mutable pgscale
: float
270 ; mutable usepbo
: bool
271 ; mutable wheelbypage
: bool
272 ; mutable stcmd
: string
273 ; mutable riani
: bool
274 ; mutable pax
: (float * int * int) ref option
275 ; mutable paxmark
: mark
276 ; mutable leftscroll
: bool
277 ; mutable title
: string
278 ; mutable lastvisit
: float
281 | Csingle
of singlecolumn
282 | Cmulti
of multicolumns
283 | Csplit
of splitcolumns
288 | Olaunch
of launchcommand
289 | Oremote
of (filename
* pageno
)
290 | Oremotedest
of (filename
* destname
)
291 | Ohistory
of (filename
* (conf
* outline list
* x
* anchor
))
292 | Oaction
of (unit -> unit)
293 and outline
= (caption
* outlinelevel
* outlinekind
)
294 and outlinelevel
= int
312 type tile
= opaque
* pixmapsize
* elapsed
313 and elapsed
= float;;
314 type pagemapkey
= pageno
* gen
;;
315 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
320 | Loading
of (page
* gen
)
322 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
324 | Outlining
of outline list
327 type mpos
= int * int
329 | Msel
of (mpos
* mpos
)
331 | Mscrolly
| Mscrollx
332 | Mzoom
of (int * int)
333 | Mzoomrect
of (mpos
* mpos
)
338 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
339 | Textentry
of (textentry
* onleave
)
341 | LinkNav
of linktarget
342 and onleave
= leavetextentrystatus
-> unit
343 and leavetextentrystatus
= | Cancel
| Confirm
344 and helpitem
= string * int * action
347 | Action
of (uioh
-> uioh
)
349 | Ltexact
of (pageno
* int)
351 and textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
352 and onkey
= string -> int -> te
353 and ondone
= string -> unit
354 and histcancel
= unit -> unit
355 and onhist
= ((histcmd
-> string) * histcancel
)
356 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
357 and cancelonempty
= bool
362 | TEswitch
of textentry
374 { mutable ss
: Unix.file_descr
375 ; mutable wsfd
: Unix.file_descr
376 ; mutable errfd
: Unix.file_descr
option
377 ; mutable stderr
: Unix.file_descr
378 ; mutable errmsgs
: Buffer.t
379 ; mutable newerrmsgs
: bool
383 ; mutable anchor
: anchor
384 ; mutable ranchors
: (string * string * anchor
* string) list
386 ; mutable layout
: page list
387 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
388 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
389 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
390 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
391 ; mutable pagecount
: int
392 ; mutable currently
: currently
393 ; mutable mstate
: mstate
394 ; mutable searchpattern
: string
395 ; mutable rects
: (pageno
* recttype
* rect
) list
396 ; mutable rects1
: (pageno
* recttype
* rect
) list
397 ; mutable text
: string
398 ; mutable winstate
: Wsi.winstate list
399 ; mutable mode
: mode
400 ; mutable uioh
: uioh
401 ; mutable outlines
: outline array
402 ; mutable bookmarks
: outline list
403 ; mutable path
: string
404 ; mutable password
: string
405 ; mutable nameddest
: string
406 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
407 ; mutable memused
: memsize
409 ; mutable throttle
: (page list
* int * float) option
410 ; mutable autoscroll
: int option
411 ; mutable ghyll
: (int option -> unit)
412 ; mutable help
: helpitem array
413 ; mutable docinfo
: (int * string) list
414 ; mutable checkerstexid
: GlTex.texture_id
option
416 ; mutable prevzoom
: (float * int)
417 ; mutable progress
: float
418 ; mutable redisplay
: bool
419 ; mutable mpos
: mpos
420 ; mutable keystate
: keystate
421 ; mutable glinks
: bool
422 ; mutable prevcolumns
: (columns
* float) option
425 ; mutable reprf
: (unit -> unit)
426 ; mutable origin
: string
427 ; mutable roam
: (unit -> unit)
428 ; mutable bzoom
: bool
429 ; mutable traw
: [`
float] Raw.t
430 ; mutable vraw
: [`
float] Raw.t
433 { pat
: string circbuf
434 ; pag
: string circbuf
435 ; nav
: anchor circbuf
436 ; sel
: string circbuf
440 let emptyanchor = (0, 0.0, 0.0);;
441 let emptykeyhash = Hashtbl.create
0;;
442 let firstgeomcmds = E.s
, [];;
444 let noreprf () = ();;
447 let nouioh : uioh
= object (self
)
449 method key _ _
= self
450 method multiclick _ _ _ _
= self
451 method button _ _ _ _ _
= self
452 method motion _ _
= self
453 method pmotion _ _
= self
454 method infochanged _
= ()
455 method scrollpw
= (0, nan
, nan
)
456 method scrollph
= (0, nan
, nan
)
457 method modehash
= emptykeyhash
458 method eformsgs
= false
461 let platform_to_string = function
462 | Punknown
-> "unknown"
467 | Pcygwin
-> "Cygwin"
471 Printf.sprintf
"llpp version %s, fitz %s, ocaml %s/%d bit"
472 Help.version (fz_version
()) Sys.ocaml_version
Sys.word_size
476 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
477 let len = String.length s
in
478 if colonpos >= 0 && colonpos + 3 < len
480 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
483 try String.rindex_from s
colonpos ' '
487 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
490 | "http" | "ftp" | "mailto" ->
492 try String.index_from s
colonpos ' '
493 with Not_found
-> len
495 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
505 ; scrollb
= scrollbhv lor scrollbvv
521 ; presentation
= false
526 ; fitmodel
= FitProportional
527 ; trimmargins
= false
528 ; trimfuzz
= (0,0,0,0)
529 ; memlimit
= 32 lsl 20
534 ; bgcolor
= (0.5, 0.5, 0.5)
538 ; mustoresize
= 256 lsl 20
543 | Plinux
| Psun
| Pbsd
-> "xdg-open \"%s\""
544 | Posx
-> "open \"%s\""
545 | Pcygwin
-> "cygstart \"%s\""
546 | Punknown
-> "echo %s")
547 ; pathlauncher
= "lp \"%s\""
550 | Plinux
| Pbsd
| Psun
-> "xsel -i"
558 ; redirectstderr
= false
560 ; columns
= Csingle
[||]
566 ; wheelbypage
= false
567 ; stcmd
= "echo SyncTex"
570 ; paxmark
= Mark_word
575 let mk n
= (n
, Hashtbl.create
1) in
589 let conf = { defconf with angle
= defconf.angle
};;
592 if emptystr
conf.urilauncher
593 then print_endline uri
595 let url = geturl uri
in
597 then Printf.eprintf
"obtained empty url from uri %S\n" uri
599 let re = Str.regexp
"%s" in
600 let command = Str.global_replace
re url conf.urilauncher
in
604 "failed to execute `%s': %s\n" command (exntos exn
);
612 :: "(searching in this text works just by typing (i.e. no initial '/'))"
617 let url = geturl s
in
619 then (s
, 0, Action
(fun u
-> gotouri url; u
))
620 else (s
, 0, Noaction
)
625 { store
= Array.make n v
632 let cbcap b
= Array.length b
.store
;;
637 b
.wc
<- (b
.wc
+ 1) mod cap;
639 b
.len <- min
(b
.len + 1) cap;
642 let cbempty b
= b
.len = 0;;
644 let cbgetg b circular dir
=
648 let rc = b
.rc + dir
in
660 else bound
rc 0 (b
.len-1)
666 let cbget b
= cbgetg b
false;;
667 let cbgetc b
= cbgetg b
true;;
673 ; stderr
= Unix.stderr
674 ; errmsgs
= Buffer.create
0
679 ; anchor
= emptyanchor
683 ; tilelru
= Queue.create
()
684 ; pagemap
= Hashtbl.create
10
685 ; tilemap
= Hashtbl.create
10
695 ; searchpattern
= E.s
701 ; geomcmds
= firstgeomcmds
703 { nav
= cbnew 10 emptyanchor
715 ; checkerstexid
= None
716 ; prevzoom
= (1.0, 0)
730 ; traw
= Raw.create_static `
float ~
len:8
731 ; vraw
= Raw.create_static `
float ~
len:8
735 let copykeyhashes c
=
736 List.map
(fun (k
, v
) -> k
, Hashtbl.copy v
) c
.keyhashes
;
740 let d = state.winh
- h
in
741 max
conf.interpagespace
((d + 1) / 2)
744 let rowyh (c
, coverA
, coverB
) b n
=
745 if c
= 1 || (n
< coverA
|| n
>= state.pagecount
- coverB
)
747 let _, _, vy
, (_, _, h
, _) = b
.(n
) in
750 let n'
= n - coverA
in
753 let e = min
state.pagecount
(s + c
) in
754 let rec find m miny maxh
= if m
= e then miny
, maxh
else
755 let _, _, y
, (_, _, h
, _) = b
.(m
) in
756 let miny = min
miny y
in
757 let maxh = max
maxh h
in
763 let ((c
, coverA
, coverB
) as cl
), b
=
764 match conf.columns
with
765 | Csingle b
-> (1, 0, 0), b
766 | Cmulti
(c
, b
) -> c
, b
767 | Csplit
(_, b
) -> (1, 0, 0), b
769 if Array.length b
= 0
772 let rec bsearch nmin nmax
=
774 then bound nmin
0 (state.pagecount
-1)
776 let n = (nmax
+ nmin
) / 2 in
777 let vy, h
= rowyh cl b
n in
781 let ips = calcips h
in
783 let y1 = vy + h
+ ips in
787 then 0, vy + h
+ conf.interpagespace
789 let y0 = vy - conf.interpagespace
in
790 y0, y0 + h
+ conf.interpagespace
800 if n < state.pagecount
- coverB
801 then ((n-coverA
)/c
)*c
+ coverA
808 then bsearch (n+1) nmax
809 else bsearch nmin
(n-1)
812 bsearch 0 (state.pagecount
-1);
816 match conf.columns
with
817 | Cmulti
((_, _, _) as cl
, b
) ->
818 if Array.length b
> 0
820 let y, h
= rowyh cl b
(Array.length b
- 1) in
821 y + h
+ (if conf.presentation
then calcips h
else 0)
824 if Array.length b
> 0
826 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
827 y + h
+ (if conf.presentation
then calcips h
else 0)
830 if Array.length b
> 0
832 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
837 let getpageywh pageno
=
838 let pageno = bound
pageno 0 (state.pagecount
-1) in
839 match conf.columns
with
841 if Array.length b
= 0
844 let (_, _, y, (_, w
, h
, _)) = b
.(pageno) in
852 if Array.length b
= 0
855 let y, h
= rowyh cl b
pageno in
856 let (_, _, _, (_, w
, _, _)) = b
.(pageno) in
864 if Array.length b
= 0
868 let (_, _, y, (_, w
, h
, _)) = b
.(n) in
872 let getpageyh pageno =
873 let y,_,h
= getpageywh pageno in
877 let getpagedim pageno =
880 | (n, _, _, _) as pdim
:: rest
->
882 then (if n = pageno then pdim
else ppdim
)
887 f (-1, -1, -1, -1) state.pdims
890 let getpagey pageno = fst
(getpageyh pageno);;
894 let coloff = l
.pagecol
* l
.pageh
in
895 float (l
.pagey
+ coloff) /. float l
.pageh
903 then float l
.pagedispy
/. float (calcips l
.pageh
)
904 else float l
.pagedispy
/. float conf.interpagespace
907 (l
.pageno, top, dtop)
911 match state.layout
with
912 | l
:: _ -> getanchor1 l
914 let n = page_of_y state.y in
918 let y, h
= getpageyh n in
919 let dy = y - state.y in
923 let ips = calcips h
in
924 float (dy + ips) /. float ips
926 float dy /. float conf.interpagespace
931 let fontpath = ref E.s;;
933 type historder
= [ `lastvisit
| `title
| `path
| `file
];;
934 let historder : historder ref = ref `lastvisit
;;
937 Map.Make
(struct type t
= (int * int) let compare = compare end);;
942 let l = String.length
s in
943 let b = Buffer.create
l in
949 try Sys.getenv
"HOME"
952 ("Can not determine home directory location: " ^ exntos exn
);
956 let modifier_of_string = function
957 | "alt" -> Wsi.altmask
958 | "shift" -> Wsi.shiftmask
959 | "ctrl" | "control" -> Wsi.ctrlmask
960 | "meta" -> Wsi.metamask
965 let r = Str.regexp
"-" in
967 let elems = Str.full_split
r s in
970 let m1 = modifier_of_string s in
972 then (Wsi.namekey
s, m
)
975 | Str.Delim
s when n land 1 = 0 -> g s
977 | Str.Delim
_ -> (k
, m
)
979 let rec loop n k m
= function
982 let k, m
= f n k m x
in
989 let r = Str.regexp
"[ \t]" in
991 let elems = Str.split
r s in
992 List.map
key_of_string elems
995 let config_of c attrs
=
999 | "scroll-bar-width" -> { c
with scrollbw
= max
0 (int_of_string v
) }
1000 | "scroll-handle-height" -> { c
with scrollh
= max
0 (int_of_string v
) }
1001 | "case-insensitive-search" -> { c
with icase
= bool_of_string v
}
1002 | "preload" -> { c
with preload
= bool_of_string v
}
1003 | "page-bias" -> { c
with pagebias
= int_of_string v
}
1004 | "scroll-step" -> { c
with scrollstep
= max
1 (int_of_string v
) }
1005 | "horizontal-scroll-step" ->
1006 { c
with hscrollstep
= max
(int_of_string v
) 1 }
1007 | "auto-scroll-step" ->
1008 { c
with autoscrollstep
= max
0 (int_of_string v
) }
1009 | "max-height-fit" -> { c
with maxhfit
= bool_of_string v
}
1010 | "crop-hack" -> { c
with crophack
= bool_of_string v
}
1013 match String.lowercase v
with
1014 | "true" -> Some infinity
1016 | f -> Some
(float_of_string
f)
1018 { c
with maxwait
= mw}
1019 | "highlight-links" -> { c
with hlinks
= bool_of_string v
}
1020 | "under-cursor-info" -> { c
with underinfo
= bool_of_string v
}
1021 | "vertical-margin" ->
1022 { c
with interpagespace
= max
0 (int_of_string v
) }
1024 let zoom = float_of_string v
/. 100. in
1025 let zoom = max
zoom 0.0 in
1026 { c
with zoom = zoom }
1027 | "presentation" -> { c
with presentation
= bool_of_string v
}
1028 | "rotation-angle" -> { c
with angle
= int_of_string v
}
1029 | "width" -> { c
with cwinw
= max
20 (int_of_string v
) }
1030 | "height" -> { c
with cwinh
= max
20 (int_of_string v
) }
1031 | "persistent-bookmarks" -> { c
with savebmarks
= bool_of_string v
}
1032 | "proportional-display" ->
1035 then FitProportional
1038 { c
with fitmodel
= fm }
1039 | "fit-model" -> { c
with fitmodel
= FMTE.of_string v
}
1040 | "pixmap-cache-size" ->
1041 { c
with memlimit
= max
2 (int_of_string_with_suffix v
) }
1042 | "tex-count" -> { c
with texcount
= max
1 (int_of_string v
) }
1043 | "slice-height" -> { c
with sliceheight
= max
2 (int_of_string v
) }
1044 | "thumbnail-width" -> { c
with thumbw
= max
2 (int_of_string v
) }
1045 | "persistent-location" -> { c
with jumpback
= bool_of_string v
}
1046 | "background-color" -> { c
with bgcolor
= color_of_string v
}
1047 | "tile-width" -> { c
with tilew
= max
2 (int_of_string v
) }
1048 | "tile-height" -> { c
with tileh
= max
2 (int_of_string v
) }
1049 | "mupdf-store-size" ->
1050 { c
with mustoresize
= max
1024 (int_of_string_with_suffix v
) }
1051 | "checkers" -> { c
with checkers
= bool_of_string v
}
1052 | "aalevel" -> { c
with aalevel
= max
0 (int_of_string v
) }
1053 | "trim-margins" -> { c
with trimmargins
= bool_of_string v
}
1054 | "trim-fuzz" -> { c
with trimfuzz
= irect_of_string v
}
1055 | "uri-launcher" -> { c
with urilauncher
= unent v
}
1056 | "path-launcher" -> { c
with pathlauncher
= unent v
}
1057 | "color-space" -> { c
with colorspace
= CSTE.of_string v
}
1058 | "invert-colors" -> { c
with invert
= bool_of_string v
}
1059 | "brightness" -> { c
with colorscale
= float_of_string v
}
1060 | "redirectstderr" -> { c
with redirectstderr
= bool_of_string v
}
1061 | "ghyllscroll" -> { c
with ghyllscroll
= ghyllscroll_of_string v
}
1063 let (n, _, _) as nab
= multicolumns_of_string v
in
1065 then { c
with columns
= Csplit
(-n, E.a
) }
1066 else { c
with columns
= Cmulti
(nab
, E.a
) }
1067 | "birds-eye-columns" ->
1068 { c
with beyecolumns
= Some
(max
(int_of_string v
) 2) }
1069 | "selection-command" -> { c
with selcmd
= unent v
}
1070 | "synctex-command" -> { c
with stcmd
= unent v
}
1071 | "pax-command" -> { c
with paxcmd
= unent v
}
1072 | "update-cursor" -> { c
with updatecurs
= bool_of_string v
}
1073 | "hint-font-size" -> { c
with hfsize
= bound
(int_of_string v
) 5 100 }
1074 | "page-scroll-scale" -> { c
with pgscale
= float_of_string v
}
1075 | "use-pbo" -> { c
with usepbo
= bool_of_string v
}
1076 | "wheel-scrolls-pages" -> { c
with wheelbypage
= bool_of_string v
}
1077 | "horizontal-scrollbar-visible" ->
1080 then c
.scrollb
lor scrollbhv
1081 else c
.scrollb
land (lnot
scrollbhv)
1083 { c
with scrollb
= b }
1084 | "vertical-scrollbar-visible" ->
1087 then c
.scrollb
lor scrollbvv
1088 else c
.scrollb
land (lnot
scrollbvv)
1090 { c
with scrollb
= b }
1091 | "remote-in-a-new-instance" -> { c
with riani
= bool_of_string v
}
1095 then Some
(ref (0.0, 0, 0))
1097 | "point-and-x-mark" -> { c
with paxmark
= MTE.of_string v
}
1098 | "scroll-bar-on-the-left" -> { c
with leftscroll
= bool_of_string v
}
1099 | "title" -> { c
with title
= unent v
}
1100 | "last-visit" -> { c
with lastvisit
= float_of_string v
}
1103 prerr_endline
("Error processing attribute (`" ^
1104 k ^
"'=`" ^ v ^
"'): " ^ exntos exn
);
1107 let rec fold c
= function
1110 let c = apply c k v
in
1113 fold { c with keyhashes
= copykeyhashes c } attrs
;
1116 let fromstring f pos
n v
d =
1119 dolog
"Error processing attribute (%S=%S) at %d\n%s"
1120 n v pos
(exntos exn
)
1125 let bookmark_of attrs
=
1126 let rec fold title page rely visy
= function
1127 | ("title", v
) :: rest
-> fold v page rely visy rest
1128 | ("page", v
) :: rest
-> fold title v rely visy rest
1129 | ("rely", v
) :: rest
-> fold title page v visy rest
1130 | ("visy", v
) :: rest
-> fold title page rely v rest
1131 | _ :: rest
-> fold title page rely visy rest
1132 | [] -> title
, page
, rely
, visy
1134 fold "invalid" "0" "0" "0" attrs
1138 let rec fold path page rely pan visy
= function
1139 | ("path", v
) :: rest
-> fold v page rely pan visy rest
1140 | ("page", v
) :: rest
-> fold path v rely pan visy rest
1141 | ("rely", v
) :: rest
-> fold path page v pan visy rest
1142 | ("pan", v
) :: rest
-> fold path page rely v visy rest
1143 | ("visy", v
) :: rest
-> fold path page rely pan v rest
1144 | _ :: rest
-> fold path page rely pan visy rest
1145 | [] -> path
, page
, rely
, pan
, visy
1147 fold E.s "0" "0" "0" "0" attrs
1151 let rec fold rs ls
= function
1152 | ("out", v
) :: rest
-> fold v ls rest
1153 | ("in", v
) :: rest
-> fold rs v rest
1154 | _ :: rest
-> fold ls rs rest
1160 let setconf dst src
=
1161 dst
.scrollbw
<- src
.scrollbw
;
1162 dst
.scrollh
<- src
.scrollh
;
1163 dst
.icase
<- src
.icase
;
1164 dst
.preload
<- src
.preload
;
1165 dst
.pagebias
<- src
.pagebias
;
1166 dst
.verbose
<- src
.verbose
;
1167 dst
.scrollstep
<- src
.scrollstep
;
1168 dst
.maxhfit
<- src
.maxhfit
;
1169 dst
.crophack
<- src
.crophack
;
1170 dst
.autoscrollstep
<- src
.autoscrollstep
;
1171 dst
.maxwait
<- src
.maxwait
;
1172 dst
.hlinks
<- src
.hlinks
;
1173 dst
.underinfo
<- src
.underinfo
;
1174 dst
.interpagespace
<- src
.interpagespace
;
1175 dst
.zoom <- src
.zoom;
1176 dst
.presentation
<- src
.presentation
;
1177 dst
.angle
<- src
.angle
;
1178 dst
.cwinw
<- src
.cwinw
;
1179 dst
.cwinh
<- src
.cwinh
;
1180 dst
.savebmarks
<- src
.savebmarks
;
1181 dst
.memlimit
<- src
.memlimit
;
1182 dst
.fitmodel
<- src
.fitmodel
;
1183 dst
.texcount
<- src
.texcount
;
1184 dst
.sliceheight
<- src
.sliceheight
;
1185 dst
.thumbw
<- src
.thumbw
;
1186 dst
.jumpback
<- src
.jumpback
;
1187 dst
.bgcolor
<- src
.bgcolor
;
1188 dst
.tilew
<- src
.tilew
;
1189 dst
.tileh
<- src
.tileh
;
1190 dst
.mustoresize
<- src
.mustoresize
;
1191 dst
.checkers
<- src
.checkers
;
1192 dst
.aalevel
<- src
.aalevel
;
1193 dst
.trimmargins
<- src
.trimmargins
;
1194 dst
.trimfuzz
<- src
.trimfuzz
;
1195 dst
.urilauncher
<- src
.urilauncher
;
1196 dst
.colorspace
<- src
.colorspace
;
1197 dst
.invert
<- src
.invert
;
1198 dst
.colorscale
<- src
.colorscale
;
1199 dst
.redirectstderr
<- src
.redirectstderr
;
1200 dst
.ghyllscroll
<- src
.ghyllscroll
;
1201 dst
.columns
<- src
.columns
;
1202 dst
.beyecolumns
<- src
.beyecolumns
;
1203 dst
.selcmd
<- src
.selcmd
;
1204 dst
.updatecurs
<- src
.updatecurs
;
1205 dst
.pathlauncher
<- src
.pathlauncher
;
1206 dst
.keyhashes
<- copykeyhashes src
;
1207 dst
.hfsize
<- src
.hfsize
;
1208 dst
.hscrollstep
<- src
.hscrollstep
;
1209 dst
.pgscale
<- src
.pgscale
;
1210 dst
.usepbo
<- src
.usepbo
;
1211 dst
.wheelbypage
<- src
.wheelbypage
;
1212 dst
.stcmd
<- src
.stcmd
;
1213 dst
.paxcmd
<- src
.paxcmd
;
1214 dst
.scrollb
<- src
.scrollb
;
1215 dst
.riani
<- src
.riani
;
1216 dst
.paxmark
<- src
.paxmark
;
1217 dst
.leftscroll
<- src
.leftscroll
;
1218 dst
.title
<- src
.title
;
1222 else Some
((ref (0.0, 0, 0)));
1225 let findkeyhash c name =
1226 try List.assoc
name c.keyhashes
1227 with Not_found
-> failwith
("invalid mode name `" ^
name ^
"'")
1231 let h = Hashtbl.create
10 in
1232 let dc = { defconf with angle
= defconf.angle
} in
1233 let rec toplevel v t spos
_ =
1235 | Vdata
| Vcdata
| Vend
-> v
1236 | Vopen
("llppconfig", _, closed
) ->
1239 else { v
with f = llppconfig
}
1241 error
"unexpected subelement at top level" s spos
1242 | Vclose
_ -> error
"unexpected close at top level" s spos
1244 and llppconfig v t spos
_ =
1246 | Vdata
| Vcdata
-> v
1247 | Vend
-> error
"unexpected end of input in llppconfig" s spos
1248 | Vopen
("defaults", attrs
, closed
) ->
1249 let c = config_of dc attrs
in
1253 else { v
with f = defaults
}
1255 | Vopen
("ui-font", attrs
, closed
) ->
1256 let rec getsize size
= function
1258 | ("size", v
) :: rest
->
1260 fromstring int_of_string spos
"size" v
fstate.fontsize
in
1262 | l -> getsize size l
1264 fstate.fontsize
<- getsize fstate.fontsize attrs
;
1267 else { v
with f = uifont
(Buffer.create
10) }
1269 | Vopen
("doc", attrs
, closed
) ->
1270 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
1271 let path = unent pathent
1272 and pageno = fromstring int_of_string spos
"page" spage
0
1273 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1274 and pan
= fromstring int_of_string spos
"pan" span
0
1275 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1276 let c = config_of dc attrs
in
1277 let anchor = (pageno, rely
, visy
) in
1279 then (Hashtbl.add
h path (c, [], pan
, anchor); v
)
1280 else { v
with f = doc
path pan
anchor c [] }
1283 error
"unexpected subelement in llppconfig" s spos
1285 | Vclose
"llppconfig" -> { v
with f = toplevel }
1286 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
1288 and defaults v t spos
_ =
1290 | Vdata
| Vcdata
-> v
1291 | Vend
-> error
"unexpected end of input in defaults" s spos
1292 | Vopen
("keymap", attrs
, closed
) ->
1294 try List.assoc
"mode" attrs
1295 with Not_found
-> "global" in
1300 let h = findkeyhash dc modename in
1301 KeyMap.iter
(Hashtbl.replace
h) keymap
;
1304 { v
with f = pkeymap
ret KeyMap.empty
}
1306 | Vopen
(_, _, _) ->
1307 error
"unexpected subelement in defaults" s spos
1309 | Vclose
"defaults" ->
1310 { v
with f = llppconfig
}
1312 | Vclose
_ -> error
"unexpected close in defaults" s spos
1314 and uifont
b v t spos
epos =
1317 Buffer.add_substring
b s spos
(epos - spos
);
1319 | Vopen
(_, _, _) ->
1320 error
"unexpected subelement in ui-font" s spos
1321 | Vclose
"ui-font" ->
1322 if emptystr
!fontpath
1323 then fontpath := Buffer.contents
b;
1324 { v
with f = llppconfig
}
1325 | Vclose
_ -> error
"unexpected close in ui-font" s spos
1326 | Vend
-> error
"unexpected end of input in ui-font" s spos
1328 and doc
path pan
anchor c bookmarks v t spos
_ =
1330 | Vdata
| Vcdata
-> v
1331 | Vend
-> error
"unexpected end of input in doc" s spos
1332 | Vopen
("bookmarks", _, closed
) ->
1335 else { v
with f = pbookmarks
path pan
anchor c bookmarks
}
1337 | Vopen
("keymap", attrs
, closed
) ->
1339 try List.assoc
"mode" attrs
1340 with Not_found
-> "global"
1346 let h = findkeyhash c modename in
1347 KeyMap.iter
(Hashtbl.replace
h) keymap
;
1348 doc
path pan
anchor c bookmarks
1350 { v
with f = pkeymap
ret KeyMap.empty
}
1352 | Vopen
(_, _, _) ->
1353 error
"unexpected subelement in doc" s spos
1356 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
1357 { v
with f = llppconfig
}
1359 | Vclose
_ -> error
"unexpected close in doc" s spos
1361 and pkeymap
ret keymap v t spos
_ =
1363 | Vdata
| Vcdata
-> v
1364 | Vend
-> error
"unexpected end of input in keymap" s spos
1365 | Vopen
("map", attrs
, closed
) ->
1366 let r, l = map_of attrs
in
1367 let kss = fromstring keys_of_string spos
"in" r [] in
1368 let lss = fromstring keys_of_string spos
"out" l [] in
1372 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
1373 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
1376 then { v
with f = pkeymap
ret keymap }
1379 { v
with f = skip
"map" f }
1382 error
"unexpected subelement in keymap" s spos
1384 | Vclose
"keymap" ->
1385 { v
with f = ret keymap }
1387 | Vclose
_ -> error
"unexpected close in keymap" s spos
1389 and pbookmarks
path pan
anchor c bookmarks v t spos
_ =
1391 | Vdata
| Vcdata
-> v
1392 | Vend
-> error
"unexpected end of input in bookmarks" s spos
1393 | Vopen
("item", attrs
, closed
) ->
1394 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
1395 let page = fromstring int_of_string spos
"page" spage
0
1396 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1397 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1399 (unent titleent, 0, Oanchor
(page, rely
, visy
)) :: bookmarks
1402 then { v
with f = pbookmarks
path pan
anchor c bookmarks }
1405 { v
with f = skip
"item" f }
1408 error
"unexpected subelement in bookmarks" s spos
1410 | Vclose
"bookmarks" ->
1411 { v
with f = doc
path pan
anchor c bookmarks }
1413 | Vclose
_ -> Parser.parse_error
"unexpected close in bookmarks" s spos
1415 and skip tag
f v t spos
_ =
1417 | Vdata
| Vcdata
-> v
1419 Parser.parse_error
("unexpected end of input in skipped " ^ tag
) s spos
1420 | Vopen
(tag'
, _, closed
) ->
1424 let f'
() = { v
with f = skip tag
f } in
1425 { v
with f = skip tag'
f'
}
1429 else Parser.parse_error
("unexpected close in skipped " ^ tag
) s spos
1432 parse
{ f = toplevel; accu
= () } s;
1438 let len = in_channel_length ic
in
1439 let s = really_input_string ic
len in
1442 | Parse_error
(msg
, s, pos
) ->
1443 let subs = subs s pos
in
1444 Utils.error
"parse error: %s: at %d [..%s..]" msg pos
subs
1447 failwith
("config load error: " ^ exntos exn
)
1452 let xdgconfdir = Utils.getenvwithdef
"XDG_CONFIG_HOME" E.s in
1453 if xdgconfdir == E.s
1456 let dir = Filename.concat
home ".config" in
1457 if Sys.is_directory
dir then dir else home
1461 Filename.concat
dir "llpp.conf"
1464 let confpath = ref defconfpath;;
1467 if Sys.file_exists
!confpath
1470 (try Some
(open_in_bin
!confpath)
1473 ("Error opening configuration file `" ^
!confpath ^
"': " ^
1484 ("Error loading configuration from `" ^
!confpath ^
"': " ^
1493 f (Hashtbl.create
0, defconf)
1502 (fun path (conf, _, _, _) ((_, besttime
) as best
) ->
1503 if conf.lastvisit
> besttime
1504 then (path, conf.lastvisit
)
1507 (state.path, -.infinity
)
1511 let pc, pb
, px
, pa
=
1514 if emptystr
state.origin
1518 let absname = abspath
path in
1519 Hashtbl.find h absname
1520 with Not_found
-> dc, [], 0, emptyanchor
1524 state.bookmarks <- pb
;
1527 then state.anchor <- pa
;
1528 cbput state.hists
.nav pa
;
1534 let gethist listref
=
1537 Hashtbl.fold (fun path (pc, pb
, px
, pa
) accu
->
1538 (path, pc, pb
, px
, pa
) :: accu
)
1545 let add_attrs bb always
dc c time
=
1548 then Printf.bprintf bb
"\n %s='%b'" s a
1551 then Printf.bprintf bb
"\n %s='%b'" s (a
!= None
)
1554 then Printf.bprintf bb
"\n %s='%d'" s a
1557 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a
)
1560 then Printf.bprintf bb
"\n %s='%g'" s (a
*.100.)
1563 then Printf.bprintf bb
"\n %s='%F'" s a
1567 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a
)
1571 Printf.bprintf bb
"\n %s='%s'" s (CSTE.to_string a
)
1575 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a
)
1579 Printf.bprintf bb
"\n %s='%s'" s (enent a
0 (String.length a
))
1584 | Some
(_N
, _A
, _B
) ->
1585 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
1590 Printf.bprintf bb
"\n %s='none'" s
1600 else string_of_float
f
1602 Printf.bprintf bb
"\n %s='%s'" s v
1607 | Cmulti
((n, a
, b), _) when n > 1 ->
1608 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a
b
1609 | Csplit
(n, _) when n > 1 ->
1610 Printf.bprintf bb
"\n %s='%d'" s ~
-n
1611 | Cmulti
_ | Csplit
_ | Csingle
_ -> ()
1616 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
1621 Printf.bprintf bb
"\n %s='%s'" s (FMTE.to_string a
)
1625 Printf.bprintf bb
"\n %s='%b'" s (a
land m
!= 0)
1629 Printf.bprintf bb
"\n %s='%s'" s (MTE.to_string a
)
1631 oi
"width" c.cwinw
dc.cwinw
;
1632 oi
"height" c.cwinh
dc.cwinh
;
1633 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
1634 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
1635 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
1636 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
1637 ob "case-insensitive-search" c.icase
dc.icase
;
1638 ob "preload" c.preload
dc.preload
;
1639 oi
"page-bias" c.pagebias
dc.pagebias
;
1640 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
1641 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
1642 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
1643 ob "crop-hack" c.crophack
dc.crophack
;
1644 oW
"throttle" c.maxwait
dc.maxwait
;
1645 ob "highlight-links" c.hlinks
dc.hlinks
;
1646 ob "under-cursor-info" c.underinfo
dc.underinfo
;
1647 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
1648 oz
"zoom" c.zoom dc.zoom;
1649 ob "presentation" c.presentation
dc.presentation
;
1650 oi
"rotation-angle" c.angle
dc.angle
;
1651 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
1652 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
1653 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
1654 oi
"tex-count" c.texcount
dc.texcount
;
1655 oi
"slice-height" c.sliceheight
dc.sliceheight
;
1656 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
1657 ob "persistent-location" c.jumpback
dc.jumpback
;
1658 oc
"background-color" c.bgcolor
dc.bgcolor
;
1659 oi
"tile-width" c.tilew
dc.tilew
;
1660 oi
"tile-height" c.tileh
dc.tileh
;
1661 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
1662 ob "checkers" c.checkers
dc.checkers
;
1663 oi
"aalevel" c.aalevel
dc.aalevel
;
1664 ob "trim-margins" c.trimmargins
dc.trimmargins
;
1665 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
1666 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
1667 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
1668 oC
"color-space" c.colorspace
dc.colorspace
;
1669 ob "invert-colors" c.invert
dc.invert
;
1670 oF
"brightness" c.colorscale
dc.colorscale
;
1671 ob "redirectstderr" c.redirectstderr
dc.redirectstderr
;
1672 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
1673 oco
"columns" c.columns
dc.columns
;
1674 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
1675 os
"selection-command" c.selcmd
dc.selcmd
;
1676 os
"synctex-command" c.stcmd
dc.stcmd
;
1677 os
"pax-command" c.paxcmd
dc.paxcmd
;
1678 ob "update-cursor" c.updatecurs
dc.updatecurs
;
1679 oi
"hint-font-size" c.hfsize
dc.hfsize
;
1680 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
1681 oF
"page-scroll-scale" c.pgscale
dc.pgscale
;
1682 ob "use-pbo" c.usepbo
dc.usepbo
;
1683 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
1684 ob "remote-in-a-new-instance" c.riani
dc.riani
;
1685 op
"point-and-x" c.pax
dc.pax
;
1686 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
1687 ob "scroll-bar-on-the-left" c.leftscroll
dc.leftscroll
;
1689 then os
"title" c.title
dc.title
;
1690 oF
"last-visit" (snd
(modf time
)) 0.0;
1693 let keymapsbuf always
dc c =
1694 let bb = Buffer.create
16 in
1695 let rec loop = function
1697 | (modename, h) :: rest
->
1698 let dh = findkeyhash dc modename in
1699 if always
|| h <> dh
1701 if Hashtbl.length
h > 0
1703 if Buffer.length
bb > 0
1704 then Buffer.add_char
bb '
\n'
;
1705 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
1706 Hashtbl.iter
(fun i o
->
1707 let isdifferent = always
||
1709 let dO = Hashtbl.find dh i
in
1711 with Not_found
-> true
1716 if Wsi.withctrl m
then Buffer.add_string
bb "ctrl-";
1717 if Wsi.withalt m
then Buffer.add_string
bb "alt-";
1718 if Wsi.withshift m
then Buffer.add_string
bb "shift-";
1719 if Wsi.withmeta m
then Buffer.add_string
bb "meta-";
1720 Buffer.add_string
bb (Wsi.keyname
k);
1723 let rec loop = function
1725 | km
:: [] -> addkm km
1726 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
1730 Buffer.add_string
bb "<map in='";
1734 Buffer.add_string
bb "' out='";
1736 Buffer.add_string
bb "'/>\n"
1739 Buffer.add_string
bb "' out='";
1741 Buffer.add_string
bb "'/>\n"
1743 | KMmulti
(ins
, kms
) ->
1744 Buffer.add_char
bb ' '
;
1746 Buffer.add_string
bb "' out='";
1748 Buffer.add_string
bb "'/>\n"
1750 Buffer.add_string
bb "</keymap>";
1759 let save1 bb leavebirdseye x
h dc =
1760 let uifontsize = fstate.fontsize
in
1761 let dc = if conf.bedefault
then conf else dc in
1762 Buffer.add_string
bb "<llppconfig>\n";
1764 if nonemptystr
!fontpath
1766 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
1772 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
1775 Buffer.add_string
bb "<defaults";
1776 add_attrs bb true dc dc nan
;
1777 let kb = keymapsbuf true dc dc in
1778 if Buffer.length
kb > 0
1780 Buffer.add_string
bb ">\n";
1781 Buffer.add_buffer
bb kb;
1782 Buffer.add_string
bb "\n</defaults>\n";
1784 else Buffer.add_string
bb "/>\n";
1786 let adddoc path pan
anchor c bookmarks time
=
1787 if bookmarks == [] && c = dc && anchor = emptyanchor
1790 Printf.bprintf
bb "<doc path='%s'"
1791 (enent
path 0 (String.length
path));
1793 if anchor <> emptyanchor
1795 let n, rely
, visy
= anchor in
1796 Printf.bprintf
bb "\n page='%d'" n;
1799 Printf.bprintf
bb " rely='%f'" rely
1801 if abs_float visy
> 1e-6
1803 Printf.bprintf
bb " visy='%f'" visy
1808 then Printf.bprintf
bb " pan='%d'" pan
;
1810 add_attrs bb false dc c time
;
1811 let kb = keymapsbuf false dc c in
1813 begin match bookmarks with
1815 if Buffer.length
kb > 0
1817 Buffer.add_string
bb ">\n";
1818 Buffer.add_buffer
bb kb;
1819 Buffer.add_string
bb "\n</doc>\n";
1821 else Buffer.add_string
bb "/>\n"
1823 Buffer.add_string
bb ">\n<bookmarks>\n";
1824 List.iter
(fun (title
, _, kind
) ->
1825 begin match kind
with
1826 | Oanchor
(page, rely
, visy
) ->
1828 "<item title='%s' page='%d'"
1829 (enent title
0 (String.length title
))
1834 Printf.bprintf
bb " rely='%f'" rely
1836 if abs_float visy
> 1e-6
1838 Printf.bprintf
bb " visy='%f'" visy
1840 | Ohistory
_ | Onone
| Ouri
_ | Oremote
_
1841 | Oremotedest
_ | Olaunch
_ | Oaction
_ ->
1842 failwith
"unexpected link in bookmarks"
1844 Buffer.add_string
bb "/>\n";
1846 Buffer.add_string
bb "</bookmarks>";
1847 if Buffer.length
kb > 0
1849 Buffer.add_string
bb "\n";
1850 Buffer.add_buffer
bb kb;
1852 Buffer.add_string
bb "\n</doc>\n";
1858 match state.mode
with
1859 | Birdseye
(c, pan, _, _, _) ->
1861 match conf.columns
with
1862 | Cmulti
((c, _, _), _) -> Some
c
1866 match c.columns
with
1867 | Cmulti
(c, _) -> Cmulti
(c, E.a
)
1868 | Csingle
_ -> Csingle
E.a
1869 | Csplit
_ -> failwith
"quit from bird's eye while split"
1871 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
1874 | LinkNav
_ -> x
, conf
1876 let docpath = abspath
state.path in
1877 adddoc docpath pan (getanchor ())
1879 let autoscrollstep =
1880 match state.autoscroll
with
1882 | None
-> conf.autoscrollstep
1884 begin match state.mode
with
1885 | Birdseye beye
-> leavebirdseye beye
true
1890 { conf with autoscrollstep = autoscrollstep }
1892 (if conf.savebmarks
then state.bookmarks else [])
1895 Hashtbl.iter
(fun path (c, bookmarks, x
, anchor) ->
1896 if docpath <> abspath
path
1897 then adddoc path x
anchor c bookmarks c.lastvisit
1899 Buffer.add_string
bb "</llppconfig>\n";
1903 let save leavebirdseye
=
1904 let relx = float state.x
/. float state.winw
in
1906 let cx w = truncate
(relx *. float w) in
1908 (fun (w, h, x
) ws
->
1910 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
1911 | Wsi.MaxVert
-> (w, conf.cwinh
, x
)
1912 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
1914 (state.winw
, state.winh
, state.x
) state.winstate
1918 let bb = Buffer.create
32768 in
1920 save1 bb leavebirdseye x
h dc
1922 if load1 save2 && Buffer.length
bb > 0
1925 let tmp = !confpath ^
".tmp" in
1926 let oc = open_out_bin
tmp in
1927 Buffer.output_buffer
oc bb;
1929 Unix.rename
tmp !confpath;
1932 ("error while saving configuration: " ^ exntos exn
)
1937 let n'
= Unix.write fdo
(Bytes.of_string s) 0 n in
1939 then Utils.error
"Unix.write %d = %d" n n'
1942 try Unix.read fdi
s 0 n
1943 with exn
-> Utils.error
"reading gc pipe %s" (exntos exn
) in
1944 let href = ref (Hashtbl.create
0) in
1945 let cref = ref defconf in
1947 let f path (pc, _pb
, _px
, _pa
) =
1949 Printf.sprintf
"%s\000%ld\000" path (Int32.of_float
pc.lastvisit
)
1951 wr s (String.length
s)
1956 Unix.shutdown fdo
Unix.SHUTDOWN_SEND
;
1959 ignore
(load1 push);
1961 let b = Buffer.create
32768 in
1962 let s = Bytes.create
4096 in
1964 let n = rd s (Bytes.length
s) in
1966 then Buffer.contents
b
1967 else (Buffer.add_subbytes
b s 0 n; f ())
1972 let zpos1 = try String.index_from
s ppos '
\000'
with Not_found
-> -1 in
1973 if zpos1 = -1 then ()
1976 try String.index_from
s (zpos1+1) '
\000'
with Not_found
-> -1 in
1977 if zpos2 = -1 then failwith
"moo2"
1979 let okey = StringLabels.sub
s ~pos
:ppos ~
len:(zpos1-ppos
) in
1980 let nkey = StringLabels.sub
s ~pos
:(zpos1+1) ~
len:(zpos2-zpos1-1) in
1982 then (Hashtbl.remove
!href okey; f (zpos2+1))
1985 try Hashtbl.find !href okey
1986 with Not_found
-> Utils.error
"gc: could not find %S" okey
1988 Hashtbl.remove
!href okey;
1989 Hashtbl.replace
!href nkey v;
1995 let bb = Buffer.create
32768 in
1996 let save2 (_h
, dc) = save1 bb (fun _ _ -> ()) 0 !href dc in
1997 if load1 save2 && Buffer.length
bb > 0
2000 let tmp = !confpath ^
".tmp" in
2001 let oc = open_out_bin
tmp in
2002 Buffer.output_buffer
oc bb;
2004 Unix.rename
tmp !confpath;
2007 ("error while saving configuration: " ^ exntos exn
)