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
96 * haspbo
* usefontconfig
)
100 and opaque
= Opaque.t
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 string
131 and facename
= string
132 and launchcommand
= string
133 and filename
= string
135 and destname
= string
147 | LDfirstvisible
of (int * int * int)
156 and anchor
= pageno
* top
* dtop
157 and rect
= float * float * float * float * float * float * float * float
158 and infochange
= | Memused
| Docinfo
| Pdim
161 class type uioh
= object
162 method display
: unit
163 method key
: int -> int -> uioh
164 method button
: int -> bool -> int -> int -> int -> uioh
165 method multiclick
: int -> int -> int -> int -> uioh
166 method motion
: int -> int -> uioh
167 method pmotion
: int -> int -> uioh
168 method infochanged
: infochange
-> unit
169 method scrollpw
: (int * float * float)
170 method scrollph
: (int * float * float)
171 method modehash
: keyhash
172 method eformsgs
: bool
175 module type TextEnumType
=
179 val names
: string array
182 module TextEnumMake
(Ten
: TextEnumType
) =
184 let names = Ten.names;;
185 let to_int (t
: Ten.t
) = Obj.magic t
;;
186 let to_string t
= names.(to_int t
);;
187 let of_int n
: Ten.t
= Obj.magic n
;;
190 if i
= Array.length
names
191 then failwith
("invalid " ^
Ten.name ^
": " ^ s
)
200 module CSTE
= TextEnumMake
(struct
201 type t
= colorspace
;;
202 let name = "colorspace";;
203 let names = [|"rgb"; "bgr"; "gray"|];;
206 module MTE
= TextEnumMake
(struct
209 let names = [|"page"; "block"; "line"; "word"|];;
212 module FMTE
= TextEnumMake
(struct
214 let name = "fitmodel";;
215 let names = [|"width"; "proportional"; "page"|];;
219 { mutable scrollbw
: int
220 ; mutable scrollh
: int
221 ; mutable scrollb
: scrollb
222 ; mutable icase
: bool
223 ; mutable preload
: bool
224 ; mutable pagebias
: int
225 ; mutable verbose
: bool
226 ; mutable debug
: bool
227 ; mutable scrollstep
: int
228 ; mutable hscrollstep
: int
229 ; mutable maxhfit
: bool
230 ; mutable crophack
: bool
231 ; mutable autoscrollstep
: int
232 ; mutable maxwait
: float option
233 ; mutable hlinks
: bool
234 ; mutable underinfo
: bool
235 ; mutable interpagespace
: interpagespace
236 ; mutable zoom
: float
237 ; mutable presentation
: bool
238 ; mutable angle
: angle
239 ; mutable cwinw
: int
240 ; mutable cwinh
: int
241 ; mutable savebmarks
: bool
242 ; mutable fitmodel
: fitmodel
243 ; mutable trimmargins
: trimmargins
244 ; mutable trimfuzz
: irect
245 ; mutable memlimit
: memsize
246 ; mutable texcount
: texcount
247 ; mutable sliceheight
: sliceheight
248 ; mutable thumbw
: width
249 ; mutable jumpback
: bool
250 ; mutable bgcolor
: (float * float * float)
251 ; mutable bedefault
: bool
252 ; mutable tilew
: int
253 ; mutable tileh
: int
254 ; mutable mustoresize
: memsize
255 ; mutable checkers
: bool
256 ; mutable aalevel
: int
257 ; mutable urilauncher
: string
258 ; mutable pathlauncher
: string
259 ; mutable colorspace
: colorspace
260 ; mutable invert
: bool
261 ; mutable colorscale
: float
262 ; mutable redirectstderr
: bool
263 ; mutable ghyllscroll
: (int * int * int) option
264 ; mutable columns
: columns
265 ; mutable beyecolumns
: columncount
option
266 ; mutable selcmd
: string
267 ; mutable paxcmd
: string
268 ; mutable updatecurs
: bool
269 ; mutable keyhashes
: (string * keyhash
) list
270 ; mutable hfsize
: int
271 ; mutable pgscale
: float
272 ; mutable usepbo
: bool
273 ; mutable wheelbypage
: bool
274 ; mutable stcmd
: string
275 ; mutable riani
: bool
276 ; mutable pax
: (float * int * int) ref option
277 ; mutable paxmark
: mark
278 ; mutable leftscroll
: bool
279 ; mutable title
: string
280 ; mutable lastvisit
: float
283 | Csingle
of singlecolumn
284 | Cmulti
of multicolumns
285 | Csplit
of splitcolumns
290 | Olaunch
of launchcommand
291 | Oremote
of (filename
* pageno
)
292 | Oremotedest
of (filename
* destname
)
293 | Ohistory
of (filename
* (conf
* outline list
* x
* anchor
))
294 | Oaction
of (unit -> unit)
295 and outline
= (caption
* outlinelevel
* outlinekind
)
296 and outlinelevel
= int
314 type tile
= opaque
* pixmapsize
* elapsed
315 and elapsed
= float;;
316 type pagemapkey
= pageno
* gen
;;
317 type tilemapkey
= pageno
* gen
* colorspace
* angle
* width
* height
* col
* row
322 | Loading
of (page
* gen
)
324 page
* opaque
* colorspace
* angle
* gen
* col
* row
* width
* height
326 | Outlining
of outline list
329 type mpos
= int * int
331 | Msel
of (mpos
* mpos
)
333 | Mscrolly
| Mscrollx
334 | Mzoom
of (int * int)
335 | Mzoomrect
of (mpos
* mpos
)
340 | Birdseye
of (conf
* leftx
* pageno
* pageno
* anchor
)
341 | Textentry
of (textentry
* onleave
)
343 | LinkNav
of linktarget
344 and onleave
= leavetextentrystatus
-> unit
345 and leavetextentrystatus
= | Cancel
| Confirm
346 and helpitem
= string * int * action
349 | Action
of (uioh
-> uioh
)
351 | Ltexact
of (pageno
* int)
353 and textentry
= string * string * onhist
option * onkey
* ondone
* cancelonempty
354 and onkey
= string -> int -> te
355 and ondone
= string -> unit
356 and histcancel
= unit -> unit
357 and onhist
= ((histcmd
-> string) * histcancel
)
358 and histcmd
= HCnext
| HCprev
| HCfirst
| HClast
359 and cancelonempty
= bool
364 | TEswitch
of textentry
376 { mutable ss
: Unix.file_descr
377 ; mutable wsfd
: Unix.file_descr
378 ; mutable errfd
: Unix.file_descr
option
379 ; mutable stderr
: Unix.file_descr
380 ; mutable errmsgs
: Buffer.t
381 ; mutable newerrmsgs
: bool
385 ; mutable anchor
: anchor
386 ; mutable ranchors
: (string * string * anchor
* string) list
388 ; mutable layout
: page list
389 ; pagemap
: (pagemapkey
, opaque
) Hashtbl.t
390 ; tilemap
: (tilemapkey
, tile
) Hashtbl.t
391 ; tilelru
: (tilemapkey
* opaque
* pixmapsize
) Queue.t
392 ; mutable pdims
: (pageno
* width
* height
* leftx
) list
393 ; mutable pagecount
: int
394 ; mutable currently
: currently
395 ; mutable mstate
: mstate
396 ; mutable searchpattern
: string
397 ; mutable rects
: (pageno
* recttype
* rect
) list
398 ; mutable rects1
: (pageno
* recttype
* rect
) list
399 ; mutable text
: string
400 ; mutable winstate
: Wsi.winstate list
401 ; mutable mode
: mode
402 ; mutable uioh
: uioh
403 ; mutable outlines
: outline array
404 ; mutable bookmarks
: outline list
405 ; mutable path
: string
406 ; mutable password
: string
407 ; mutable nameddest
: string
408 ; mutable geomcmds
: (string * ((string * (unit -> unit)) list
))
409 ; mutable memused
: memsize
411 ; mutable throttle
: (page list
* int * float) option
412 ; mutable autoscroll
: int option
413 ; mutable ghyll
: (int option -> unit)
414 ; mutable help
: helpitem array
415 ; mutable docinfo
: (int * string) list
416 ; mutable checkerstexid
: GlTex.texture_id
option
418 ; mutable prevzoom
: (float * int)
419 ; mutable progress
: float
420 ; mutable redisplay
: bool
421 ; mutable mpos
: mpos
422 ; mutable keystate
: keystate
423 ; mutable glinks
: bool
424 ; mutable prevcolumns
: (columns
* float) option
427 ; mutable reprf
: (unit -> unit)
428 ; mutable origin
: string
429 ; mutable roam
: (unit -> unit)
430 ; mutable bzoom
: bool
431 ; mutable traw
: [`
float] Raw.t
432 ; mutable vraw
: [`
float] Raw.t
435 { pat
: string circbuf
436 ; pag
: string circbuf
437 ; nav
: anchor circbuf
438 ; sel
: string circbuf
442 let emptyanchor = (0, 0.0, 0.0);;
443 let emptykeyhash = Hashtbl.create
0;;
444 let firstgeomcmds = E.s
, [];;
446 let noreprf () = ();;
449 let nouioh : uioh
= object (self
)
451 method key _ _
= self
452 method multiclick _ _ _ _
= self
453 method button _ _ _ _ _
= self
454 method motion _ _
= self
455 method pmotion _ _
= self
456 method infochanged _
= ()
457 method scrollpw
= (0, nan
, nan
)
458 method scrollph
= (0, nan
, nan
)
459 method modehash
= emptykeyhash
460 method eformsgs
= false
463 let platform_to_string = function
464 | Punknown
-> "unknown"
469 | Pcygwin
-> "Cygwin"
473 Printf.sprintf
"llpp version %s, fitz %s, ocaml %s/%d bit"
474 Help.version (fz_version
()) Sys.ocaml_version
Sys.word_size
478 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
479 let len = String.length s
in
480 if colonpos >= 0 && colonpos + 3 < len
482 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
485 try String.rindex_from s
colonpos ' '
489 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
492 | "http" | "ftp" | "mailto" ->
494 try String.index_from s
colonpos ' '
495 with Not_found
-> len
497 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
507 ; scrollb
= scrollbhv lor scrollbvv
523 ; presentation
= false
528 ; fitmodel
= FitProportional
529 ; trimmargins
= false
530 ; trimfuzz
= (0,0,0,0)
531 ; memlimit
= 32 lsl 20
536 ; bgcolor
= (0.5, 0.5, 0.5)
540 ; mustoresize
= 256 lsl 20
545 | Plinux
| Psun
| Pbsd
-> "xdg-open \"%s\""
546 | Posx
-> "open \"%s\""
547 | Pcygwin
-> "cygstart \"%s\""
548 | Punknown
-> "echo %s")
549 ; pathlauncher
= "lp \"%s\""
552 | Plinux
| Pbsd
| Psun
-> "xsel -i"
560 ; redirectstderr
= false
562 ; columns
= Csingle
[||]
568 ; wheelbypage
= false
569 ; stcmd
= "echo SyncTex"
572 ; paxmark
= Mark_word
577 let mk n
= (n
, Hashtbl.create
1) in
591 let conf = { defconf with angle
= defconf.angle
};;
594 if emptystr
conf.urilauncher
595 then print_endline uri
597 let url = geturl uri
in
599 then Printf.eprintf
"obtained empty url from uri %S\n" uri
601 let re = Str.regexp
"%s" in
602 let command = Str.global_replace
re url conf.urilauncher
in
606 "failed to execute `%s': %s\n" command (exntos exn
);
614 :: "(searching in this text works just by typing (i.e. no initial '/'))"
619 let url = geturl s
in
621 then (s
, 0, Action
(fun u
-> gotouri url; u
))
622 else (s
, 0, Noaction
)
627 { store
= Array.make n v
634 let cbcap b
= Array.length b
.store
;;
639 b
.wc
<- (b
.wc
+ 1) mod cap;
641 b
.len <- min
(b
.len + 1) cap;
644 let cbempty b
= b
.len = 0;;
646 let cbgetg b circular dir
=
650 let rc = b
.rc + dir
in
662 else bound
rc 0 (b
.len-1)
668 let cbget b
= cbgetg b
false;;
669 let cbgetc b
= cbgetg b
true;;
675 ; stderr
= Unix.stderr
676 ; errmsgs
= Buffer.create
0
681 ; anchor
= emptyanchor
685 ; tilelru
= Queue.create
()
686 ; pagemap
= Hashtbl.create
10
687 ; tilemap
= Hashtbl.create
10
697 ; searchpattern
= E.s
703 ; geomcmds
= firstgeomcmds
705 { nav
= cbnew 10 emptyanchor
717 ; checkerstexid
= None
718 ; prevzoom
= (1.0, 0)
732 ; traw
= Raw.create_static `
float ~
len:8
733 ; vraw
= Raw.create_static `
float ~
len:8
737 let copykeyhashes c
=
738 List.map
(fun (k
, v
) -> k
, Hashtbl.copy v
) c
.keyhashes
;
742 let d = state.winh
- h
in
743 max
conf.interpagespace
((d + 1) / 2)
746 let rowyh (c
, coverA
, coverB
) b n
=
747 if c
= 1 || (n
< coverA
|| n
>= state.pagecount
- coverB
)
749 let _, _, vy
, (_, _, h
, _) = b
.(n
) in
752 let n'
= n - coverA
in
755 let e = min
state.pagecount
(s + c
) in
756 let rec find m miny maxh
= if m
= e then miny
, maxh
else
757 let _, _, y
, (_, _, h
, _) = b
.(m
) in
758 let miny = min
miny y
in
759 let maxh = max
maxh h
in
765 let ((c
, coverA
, coverB
) as cl
), b
=
766 match conf.columns
with
767 | Csingle b
-> (1, 0, 0), b
768 | Cmulti
(c
, b
) -> c
, b
769 | Csplit
(_, b
) -> (1, 0, 0), b
771 if Array.length b
= 0
774 let rec bsearch nmin nmax
=
776 then bound nmin
0 (state.pagecount
-1)
778 let n = (nmax
+ nmin
) / 2 in
779 let vy, h
= rowyh cl b
n in
783 let ips = calcips h
in
785 let y1 = vy + h
+ ips in
789 then 0, vy + h
+ conf.interpagespace
791 let y0 = vy - conf.interpagespace
in
792 y0, y0 + h
+ conf.interpagespace
802 if n < state.pagecount
- coverB
803 then ((n-coverA
)/c
)*c
+ coverA
810 then bsearch (n+1) nmax
811 else bsearch nmin
(n-1)
814 bsearch 0 (state.pagecount
-1);
818 match conf.columns
with
819 | Cmulti
((_, _, _) as cl
, b
) ->
820 if Array.length b
> 0
822 let y, h
= rowyh cl b
(Array.length b
- 1) in
823 y + h
+ (if conf.presentation
then calcips h
else 0)
826 if Array.length b
> 0
828 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
829 y + h
+ (if conf.presentation
then calcips h
else 0)
832 if Array.length b
> 0
834 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
839 let getpageywh pageno
=
840 let pageno = bound
pageno 0 (state.pagecount
-1) in
841 match conf.columns
with
843 if Array.length b
= 0
846 let (_, _, y, (_, w
, h
, _)) = b
.(pageno) in
854 if Array.length b
= 0
857 let y, h
= rowyh cl b
pageno in
858 let (_, _, _, (_, w
, _, _)) = b
.(pageno) in
866 if Array.length b
= 0
870 let (_, _, y, (_, w
, h
, _)) = b
.(n) in
874 let getpageyh pageno =
875 let y,_,h
= getpageywh pageno in
879 let getpagedim pageno =
882 | (n, _, _, _) as pdim
:: rest
->
884 then (if n = pageno then pdim
else ppdim
)
889 f (-1, -1, -1, -1) state.pdims
892 let getpagey pageno = fst
(getpageyh pageno);;
896 let coloff = l
.pagecol
* l
.pageh
in
897 float (l
.pagey
+ coloff) /. float l
.pageh
905 then float l
.pagedispy
/. float (calcips l
.pageh
)
906 else float l
.pagedispy
/. float conf.interpagespace
909 (l
.pageno, top, dtop)
913 match state.layout
with
914 | l
:: _ -> getanchor1 l
916 let n = page_of_y state.y in
920 let y, h
= getpageyh n in
921 let dy = y - state.y in
925 let ips = calcips h
in
926 float (dy + ips) /. float ips
928 float dy /. float conf.interpagespace
933 let fontpath = ref E.s;;
935 type historder
= [ `lastvisit
| `title
| `path
| `file
];;
936 let historder : historder ref = ref `lastvisit
;;
939 Map.Make
(struct type t
= (int * int) let compare = compare end);;
944 let l = String.length
s in
945 let b = Buffer.create
l in
951 try Sys.getenv
"HOME"
954 ("Can not determine home directory location: " ^ exntos exn
);
958 let modifier_of_string = function
959 | "alt" -> Wsi.altmask
960 | "shift" -> Wsi.shiftmask
961 | "ctrl" | "control" -> Wsi.ctrlmask
962 | "meta" -> Wsi.metamask
967 let r = Str.regexp
"-" in
969 let elems = Str.full_split
r s in
972 let m1 = modifier_of_string s in
974 then (Wsi.namekey
s, m
)
977 | Str.Delim
s when n land 1 = 0 -> g s
979 | Str.Delim
_ -> (k
, m
)
981 let rec loop n k m
= function
984 let k, m
= f n k m x
in
991 let r = Str.regexp
"[ \t]" in
993 let elems = Str.split
r s in
994 List.map
key_of_string elems
997 let config_of c attrs
=
1001 | "scroll-bar-width" -> { c
with scrollbw
= max
0 (int_of_string v
) }
1002 | "scroll-handle-height" -> { c
with scrollh
= max
0 (int_of_string v
) }
1003 | "case-insensitive-search" -> { c
with icase
= bool_of_string v
}
1004 | "preload" -> { c
with preload
= bool_of_string v
}
1005 | "page-bias" -> { c
with pagebias
= int_of_string v
}
1006 | "scroll-step" -> { c
with scrollstep
= max
1 (int_of_string v
) }
1007 | "horizontal-scroll-step" ->
1008 { c
with hscrollstep
= max
(int_of_string v
) 1 }
1009 | "auto-scroll-step" ->
1010 { c
with autoscrollstep
= max
0 (int_of_string v
) }
1011 | "max-height-fit" -> { c
with maxhfit
= bool_of_string v
}
1012 | "crop-hack" -> { c
with crophack
= bool_of_string v
}
1015 match String.lowercase v
with
1016 | "true" -> Some infinity
1018 | f -> Some
(float_of_string
f)
1020 { c
with maxwait
= mw}
1021 | "highlight-links" -> { c
with hlinks
= bool_of_string v
}
1022 | "under-cursor-info" -> { c
with underinfo
= bool_of_string v
}
1023 | "vertical-margin" ->
1024 { c
with interpagespace
= max
0 (int_of_string v
) }
1026 let zoom = float_of_string v
/. 100. in
1027 let zoom = max
zoom 0.0 in
1028 { c
with zoom = zoom }
1029 | "presentation" -> { c
with presentation
= bool_of_string v
}
1030 | "rotation-angle" -> { c
with angle
= int_of_string v
}
1031 | "width" -> { c
with cwinw
= max
20 (int_of_string v
) }
1032 | "height" -> { c
with cwinh
= max
20 (int_of_string v
) }
1033 | "persistent-bookmarks" -> { c
with savebmarks
= bool_of_string v
}
1034 | "proportional-display" ->
1037 then FitProportional
1040 { c
with fitmodel
= fm }
1041 | "fit-model" -> { c
with fitmodel
= FMTE.of_string v
}
1042 | "pixmap-cache-size" ->
1043 { c
with memlimit
= max
2 (int_of_string_with_suffix v
) }
1044 | "tex-count" -> { c
with texcount
= max
1 (int_of_string v
) }
1045 | "slice-height" -> { c
with sliceheight
= max
2 (int_of_string v
) }
1046 | "thumbnail-width" -> { c
with thumbw
= max
2 (int_of_string v
) }
1047 | "persistent-location" -> { c
with jumpback
= bool_of_string v
}
1048 | "background-color" -> { c
with bgcolor
= color_of_string v
}
1049 | "tile-width" -> { c
with tilew
= max
2 (int_of_string v
) }
1050 | "tile-height" -> { c
with tileh
= max
2 (int_of_string v
) }
1051 | "mupdf-store-size" ->
1052 { c
with mustoresize
= max
1024 (int_of_string_with_suffix v
) }
1053 | "checkers" -> { c
with checkers
= bool_of_string v
}
1054 | "aalevel" -> { c
with aalevel
= max
0 (int_of_string v
) }
1055 | "trim-margins" -> { c
with trimmargins
= bool_of_string v
}
1056 | "trim-fuzz" -> { c
with trimfuzz
= irect_of_string v
}
1057 | "uri-launcher" -> { c
with urilauncher
= unent v
}
1058 | "path-launcher" -> { c
with pathlauncher
= unent v
}
1059 | "color-space" -> { c
with colorspace
= CSTE.of_string v
}
1060 | "invert-colors" -> { c
with invert
= bool_of_string v
}
1061 | "brightness" -> { c
with colorscale
= float_of_string v
}
1062 | "redirectstderr" -> { c
with redirectstderr
= bool_of_string v
}
1063 | "ghyllscroll" -> { c
with ghyllscroll
= ghyllscroll_of_string v
}
1065 let (n, _, _) as nab
= multicolumns_of_string v
in
1067 then { c
with columns
= Csplit
(-n, E.a
) }
1068 else { c
with columns
= Cmulti
(nab
, E.a
) }
1069 | "birds-eye-columns" ->
1070 { c
with beyecolumns
= Some
(max
(int_of_string v
) 2) }
1071 | "selection-command" -> { c
with selcmd
= unent v
}
1072 | "synctex-command" -> { c
with stcmd
= unent v
}
1073 | "pax-command" -> { c
with paxcmd
= unent v
}
1074 | "update-cursor" -> { c
with updatecurs
= bool_of_string v
}
1075 | "hint-font-size" -> { c
with hfsize
= bound
(int_of_string v
) 5 100 }
1076 | "page-scroll-scale" -> { c
with pgscale
= float_of_string v
}
1077 | "use-pbo" -> { c
with usepbo
= bool_of_string v
}
1078 | "wheel-scrolls-pages" -> { c
with wheelbypage
= bool_of_string v
}
1079 | "horizontal-scrollbar-visible" ->
1082 then c
.scrollb
lor scrollbhv
1083 else c
.scrollb
land (lnot
scrollbhv)
1085 { c
with scrollb
= b }
1086 | "vertical-scrollbar-visible" ->
1089 then c
.scrollb
lor scrollbvv
1090 else c
.scrollb
land (lnot
scrollbvv)
1092 { c
with scrollb
= b }
1093 | "remote-in-a-new-instance" -> { c
with riani
= bool_of_string v
}
1097 then Some
(ref (0.0, 0, 0))
1099 | "point-and-x-mark" -> { c
with paxmark
= MTE.of_string v
}
1100 | "scroll-bar-on-the-left" -> { c
with leftscroll
= bool_of_string v
}
1101 | "title" -> { c
with title
= unent v
}
1102 | "last-visit" -> { c
with lastvisit
= float_of_string v
}
1105 prerr_endline
("Error processing attribute (`" ^
1106 k ^
"'=`" ^ v ^
"'): " ^ exntos exn
);
1109 let rec fold c
= function
1112 let c = apply c k v
in
1115 fold { c with keyhashes
= copykeyhashes c } attrs
;
1118 let fromstring f pos
n v
d =
1121 dolog
"Error processing attribute (%S=%S) at %d\n%s"
1122 n v pos
(exntos exn
)
1127 let bookmark_of attrs
=
1128 let rec fold title page rely visy
= function
1129 | ("title", v
) :: rest
-> fold v page rely visy rest
1130 | ("page", v
) :: rest
-> fold title v rely visy rest
1131 | ("rely", v
) :: rest
-> fold title page v visy rest
1132 | ("visy", v
) :: rest
-> fold title page rely v rest
1133 | _ :: rest
-> fold title page rely visy rest
1134 | [] -> title
, page
, rely
, visy
1136 fold "invalid" "0" "0" "0" attrs
1140 let rec fold path page rely pan visy
= function
1141 | ("path", v
) :: rest
-> fold v page rely pan visy rest
1142 | ("page", v
) :: rest
-> fold path v rely pan visy rest
1143 | ("rely", v
) :: rest
-> fold path page v pan visy rest
1144 | ("pan", v
) :: rest
-> fold path page rely v visy rest
1145 | ("visy", v
) :: rest
-> fold path page rely pan v rest
1146 | _ :: rest
-> fold path page rely pan visy rest
1147 | [] -> path
, page
, rely
, pan
, visy
1149 fold E.s "0" "0" "0" "0" attrs
1153 let rec fold rs ls
= function
1154 | ("out", v
) :: rest
-> fold v ls rest
1155 | ("in", v
) :: rest
-> fold rs v rest
1156 | _ :: rest
-> fold ls rs rest
1162 let setconf dst src
=
1163 dst
.scrollbw
<- src
.scrollbw
;
1164 dst
.scrollh
<- src
.scrollh
;
1165 dst
.icase
<- src
.icase
;
1166 dst
.preload
<- src
.preload
;
1167 dst
.pagebias
<- src
.pagebias
;
1168 dst
.verbose
<- src
.verbose
;
1169 dst
.scrollstep
<- src
.scrollstep
;
1170 dst
.maxhfit
<- src
.maxhfit
;
1171 dst
.crophack
<- src
.crophack
;
1172 dst
.autoscrollstep
<- src
.autoscrollstep
;
1173 dst
.maxwait
<- src
.maxwait
;
1174 dst
.hlinks
<- src
.hlinks
;
1175 dst
.underinfo
<- src
.underinfo
;
1176 dst
.interpagespace
<- src
.interpagespace
;
1177 dst
.zoom <- src
.zoom;
1178 dst
.presentation
<- src
.presentation
;
1179 dst
.angle
<- src
.angle
;
1180 dst
.cwinw
<- src
.cwinw
;
1181 dst
.cwinh
<- src
.cwinh
;
1182 dst
.savebmarks
<- src
.savebmarks
;
1183 dst
.memlimit
<- src
.memlimit
;
1184 dst
.fitmodel
<- src
.fitmodel
;
1185 dst
.texcount
<- src
.texcount
;
1186 dst
.sliceheight
<- src
.sliceheight
;
1187 dst
.thumbw
<- src
.thumbw
;
1188 dst
.jumpback
<- src
.jumpback
;
1189 dst
.bgcolor
<- src
.bgcolor
;
1190 dst
.tilew
<- src
.tilew
;
1191 dst
.tileh
<- src
.tileh
;
1192 dst
.mustoresize
<- src
.mustoresize
;
1193 dst
.checkers
<- src
.checkers
;
1194 dst
.aalevel
<- src
.aalevel
;
1195 dst
.trimmargins
<- src
.trimmargins
;
1196 dst
.trimfuzz
<- src
.trimfuzz
;
1197 dst
.urilauncher
<- src
.urilauncher
;
1198 dst
.colorspace
<- src
.colorspace
;
1199 dst
.invert
<- src
.invert
;
1200 dst
.colorscale
<- src
.colorscale
;
1201 dst
.redirectstderr
<- src
.redirectstderr
;
1202 dst
.ghyllscroll
<- src
.ghyllscroll
;
1203 dst
.columns
<- src
.columns
;
1204 dst
.beyecolumns
<- src
.beyecolumns
;
1205 dst
.selcmd
<- src
.selcmd
;
1206 dst
.updatecurs
<- src
.updatecurs
;
1207 dst
.pathlauncher
<- src
.pathlauncher
;
1208 dst
.keyhashes
<- copykeyhashes src
;
1209 dst
.hfsize
<- src
.hfsize
;
1210 dst
.hscrollstep
<- src
.hscrollstep
;
1211 dst
.pgscale
<- src
.pgscale
;
1212 dst
.usepbo
<- src
.usepbo
;
1213 dst
.wheelbypage
<- src
.wheelbypage
;
1214 dst
.stcmd
<- src
.stcmd
;
1215 dst
.paxcmd
<- src
.paxcmd
;
1216 dst
.scrollb
<- src
.scrollb
;
1217 dst
.riani
<- src
.riani
;
1218 dst
.paxmark
<- src
.paxmark
;
1219 dst
.leftscroll
<- src
.leftscroll
;
1220 dst
.title
<- src
.title
;
1224 else Some
((ref (0.0, 0, 0)));
1227 let findkeyhash c name =
1228 try List.assoc
name c.keyhashes
1229 with Not_found
-> failwith
("invalid mode name `" ^
name ^
"'")
1233 let h = Hashtbl.create
10 in
1234 let dc = { defconf with angle
= defconf.angle
} in
1235 let rec toplevel v t spos
_ =
1237 | Vdata
| Vcdata
| Vend
-> v
1238 | Vopen
("llppconfig", _, closed
) ->
1241 else { v
with f = llppconfig
}
1243 error
"unexpected subelement at top level" s spos
1244 | Vclose
_ -> error
"unexpected close at top level" s spos
1246 and llppconfig v t spos
_ =
1248 | Vdata
| Vcdata
-> v
1249 | Vend
-> error
"unexpected end of input in llppconfig" s spos
1250 | Vopen
("defaults", attrs
, closed
) ->
1251 let c = config_of dc attrs
in
1255 else { v
with f = defaults
}
1257 | Vopen
("ui-font", attrs
, closed
) ->
1258 let rec getsize size
= function
1260 | ("size", v
) :: rest
->
1262 fromstring int_of_string spos
"size" v
fstate.fontsize
in
1264 | l -> getsize size l
1266 fstate.fontsize
<- getsize fstate.fontsize attrs
;
1269 else { v
with f = uifont
(Buffer.create
10) }
1271 | Vopen
("doc", attrs
, closed
) ->
1272 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
1273 let path = unent pathent
1274 and pageno = fromstring int_of_string spos
"page" spage
0
1275 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1276 and pan
= fromstring int_of_string spos
"pan" span
0
1277 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1278 let c = config_of dc attrs
in
1279 let anchor = (pageno, rely
, visy
) in
1281 then (Hashtbl.add
h path (c, [], pan
, anchor); v
)
1282 else { v
with f = doc
path pan
anchor c [] }
1285 error
"unexpected subelement in llppconfig" s spos
1287 | Vclose
"llppconfig" -> { v
with f = toplevel }
1288 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
1290 and defaults v t spos
_ =
1292 | Vdata
| Vcdata
-> v
1293 | Vend
-> error
"unexpected end of input in defaults" s spos
1294 | Vopen
("keymap", attrs
, closed
) ->
1296 try List.assoc
"mode" attrs
1297 with Not_found
-> "global" in
1302 let h = findkeyhash dc modename in
1303 KeyMap.iter
(Hashtbl.replace
h) keymap
;
1306 { v
with f = pkeymap
ret KeyMap.empty
}
1308 | Vopen
(_, _, _) ->
1309 error
"unexpected subelement in defaults" s spos
1311 | Vclose
"defaults" ->
1312 { v
with f = llppconfig
}
1314 | Vclose
_ -> error
"unexpected close in defaults" s spos
1316 and uifont
b v t spos
epos =
1319 Buffer.add_substring
b s spos
(epos - spos
);
1321 | Vopen
(_, _, _) ->
1322 error
"unexpected subelement in ui-font" s spos
1323 | Vclose
"ui-font" ->
1324 if emptystr
!fontpath
1325 then fontpath := Buffer.contents
b;
1326 { v
with f = llppconfig
}
1327 | Vclose
_ -> error
"unexpected close in ui-font" s spos
1328 | Vend
-> error
"unexpected end of input in ui-font" s spos
1330 and doc
path pan
anchor c bookmarks v t spos
_ =
1332 | Vdata
| Vcdata
-> v
1333 | Vend
-> error
"unexpected end of input in doc" s spos
1334 | Vopen
("bookmarks", _, closed
) ->
1337 else { v
with f = pbookmarks
path pan
anchor c bookmarks
}
1339 | Vopen
("keymap", attrs
, closed
) ->
1341 try List.assoc
"mode" attrs
1342 with Not_found
-> "global"
1348 let h = findkeyhash c modename in
1349 KeyMap.iter
(Hashtbl.replace
h) keymap
;
1350 doc
path pan
anchor c bookmarks
1352 { v
with f = pkeymap
ret KeyMap.empty
}
1354 | Vopen
(_, _, _) ->
1355 error
"unexpected subelement in doc" s spos
1358 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
1359 { v
with f = llppconfig
}
1361 | Vclose
_ -> error
"unexpected close in doc" s spos
1363 and pkeymap
ret keymap v t spos
_ =
1365 | Vdata
| Vcdata
-> v
1366 | Vend
-> error
"unexpected end of input in keymap" s spos
1367 | Vopen
("map", attrs
, closed
) ->
1368 let r, l = map_of attrs
in
1369 let kss = fromstring keys_of_string spos
"in" r [] in
1370 let lss = fromstring keys_of_string spos
"out" l [] in
1374 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
1375 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
1378 then { v
with f = pkeymap
ret keymap }
1381 { v
with f = skip
"map" f }
1384 error
"unexpected subelement in keymap" s spos
1386 | Vclose
"keymap" ->
1387 { v
with f = ret keymap }
1389 | Vclose
_ -> error
"unexpected close in keymap" s spos
1391 and pbookmarks
path pan
anchor c bookmarks v t spos
_ =
1393 | Vdata
| Vcdata
-> v
1394 | Vend
-> error
"unexpected end of input in bookmarks" s spos
1395 | Vopen
("item", attrs
, closed
) ->
1396 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
1397 let page = fromstring int_of_string spos
"page" spage
0
1398 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1399 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1401 (unent titleent, 0, Oanchor
(page, rely
, visy
)) :: bookmarks
1404 then { v
with f = pbookmarks
path pan
anchor c bookmarks }
1407 { v
with f = skip
"item" f }
1410 error
"unexpected subelement in bookmarks" s spos
1412 | Vclose
"bookmarks" ->
1413 { v
with f = doc
path pan
anchor c bookmarks }
1415 | Vclose
_ -> Parser.parse_error
"unexpected close in bookmarks" s spos
1417 and skip tag
f v t spos
_ =
1419 | Vdata
| Vcdata
-> v
1421 Parser.parse_error
("unexpected end of input in skipped " ^ tag
) s spos
1422 | Vopen
(tag'
, _, closed
) ->
1426 let f'
() = { v
with f = skip tag
f } in
1427 { v
with f = skip tag'
f'
}
1431 else Parser.parse_error
("unexpected close in skipped " ^ tag
) s spos
1434 parse
{ f = toplevel; accu
= () } s;
1440 let len = in_channel_length ic
in
1441 let s = really_input_string ic
len in
1444 | Parse_error
(msg
, s, pos
) ->
1445 let subs = subs s pos
in
1446 Utils.error
"parse error: %s: at %d [..%s..]" msg pos
subs
1449 failwith
("config load error: " ^ exntos exn
)
1454 let xdgconfdir = Utils.getenvwithdef
"XDG_CONFIG_HOME" E.s in
1455 if xdgconfdir == E.s
1458 let dir = Filename.concat
home ".config" in
1459 if Sys.is_directory
dir then dir else home
1463 Filename.concat
dir "llpp.conf"
1466 let confpath = ref defconfpath;;
1469 if Sys.file_exists
!confpath
1472 (try Some
(open_in_bin
!confpath)
1475 ("Error opening configuration file `" ^
!confpath ^
"': " ^
1486 ("Error loading configuration from `" ^
!confpath ^
"': " ^
1495 f (Hashtbl.create
0, defconf)
1504 (fun path (conf, _, _, _) ((_, besttime
) as best
) ->
1505 if conf.lastvisit
> besttime
1506 then (path, conf.lastvisit
)
1509 (state.path, -.infinity
)
1513 let pc, pb
, px
, pa
=
1516 if emptystr
state.origin
1520 let absname = abspath
path in
1521 Hashtbl.find h absname
1522 with Not_found
-> dc, [], 0, emptyanchor
1526 state.bookmarks <- pb
;
1529 then state.anchor <- pa
;
1530 cbput state.hists
.nav pa
;
1536 let gethist listref
=
1539 Hashtbl.fold (fun path (pc, pb
, px
, pa
) accu
->
1540 (path, pc, pb
, px
, pa
) :: accu
)
1547 let add_attrs bb always
dc c time
=
1550 then Printf.bprintf bb
"\n %s='%b'" s a
1553 then Printf.bprintf bb
"\n %s='%b'" s (a
!= None
)
1556 then Printf.bprintf bb
"\n %s='%d'" s a
1559 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a
)
1562 then Printf.bprintf bb
"\n %s='%g'" s (a
*.100.)
1565 then Printf.bprintf bb
"\n %s='%f'" s a
1569 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a
)
1573 Printf.bprintf bb
"\n %s='%s'" s (CSTE.to_string a
)
1577 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a
)
1581 Printf.bprintf bb
"\n %s='%s'" s (enent a
0 (String.length a
))
1586 | Some
(_N
, _A
, _B
) ->
1587 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
1592 Printf.bprintf bb
"\n %s='none'" s
1602 else string_of_float
f
1604 Printf.bprintf bb
"\n %s='%s'" s v
1609 | Cmulti
((n, a
, b), _) when n > 1 ->
1610 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a
b
1611 | Csplit
(n, _) when n > 1 ->
1612 Printf.bprintf bb
"\n %s='%d'" s ~
-n
1613 | Cmulti
_ | Csplit
_ | Csingle
_ -> ()
1618 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
1623 Printf.bprintf bb
"\n %s='%s'" s (FMTE.to_string a
)
1627 Printf.bprintf bb
"\n %s='%b'" s (a
land m
!= 0)
1631 Printf.bprintf bb
"\n %s='%s'" s (MTE.to_string a
)
1633 oi
"width" c.cwinw
dc.cwinw
;
1634 oi
"height" c.cwinh
dc.cwinh
;
1635 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
1636 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
1637 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
1638 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
1639 ob "case-insensitive-search" c.icase
dc.icase
;
1640 ob "preload" c.preload
dc.preload
;
1641 oi
"page-bias" c.pagebias
dc.pagebias
;
1642 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
1643 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
1644 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
1645 ob "crop-hack" c.crophack
dc.crophack
;
1646 oW
"throttle" c.maxwait
dc.maxwait
;
1647 ob "highlight-links" c.hlinks
dc.hlinks
;
1648 ob "under-cursor-info" c.underinfo
dc.underinfo
;
1649 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
1650 oz
"zoom" c.zoom dc.zoom;
1651 ob "presentation" c.presentation
dc.presentation
;
1652 oi
"rotation-angle" c.angle
dc.angle
;
1653 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
1654 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
1655 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
1656 oi
"tex-count" c.texcount
dc.texcount
;
1657 oi
"slice-height" c.sliceheight
dc.sliceheight
;
1658 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
1659 ob "persistent-location" c.jumpback
dc.jumpback
;
1660 oc
"background-color" c.bgcolor
dc.bgcolor
;
1661 oi
"tile-width" c.tilew
dc.tilew
;
1662 oi
"tile-height" c.tileh
dc.tileh
;
1663 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
1664 ob "checkers" c.checkers
dc.checkers
;
1665 oi
"aalevel" c.aalevel
dc.aalevel
;
1666 ob "trim-margins" c.trimmargins
dc.trimmargins
;
1667 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
1668 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
1669 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
1670 oC
"color-space" c.colorspace
dc.colorspace
;
1671 ob "invert-colors" c.invert
dc.invert
;
1672 oF
"brightness" c.colorscale
dc.colorscale
;
1673 ob "redirectstderr" c.redirectstderr
dc.redirectstderr
;
1674 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
1675 oco
"columns" c.columns
dc.columns
;
1676 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
1677 os
"selection-command" c.selcmd
dc.selcmd
;
1678 os
"synctex-command" c.stcmd
dc.stcmd
;
1679 os
"pax-command" c.paxcmd
dc.paxcmd
;
1680 ob "update-cursor" c.updatecurs
dc.updatecurs
;
1681 oi
"hint-font-size" c.hfsize
dc.hfsize
;
1682 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
1683 oF
"page-scroll-scale" c.pgscale
dc.pgscale
;
1684 ob "use-pbo" c.usepbo
dc.usepbo
;
1685 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
1686 ob "remote-in-a-new-instance" c.riani
dc.riani
;
1687 op
"point-and-x" c.pax
dc.pax
;
1688 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
1689 ob "scroll-bar-on-the-left" c.leftscroll
dc.leftscroll
;
1691 then os
"title" c.title
dc.title
;
1692 oF
"last-visit" (snd
(modf time
)) 0.0;
1695 let keymapsbuf always
dc c =
1696 let bb = Buffer.create
16 in
1697 let rec loop = function
1699 | (modename, h) :: rest
->
1700 let dh = findkeyhash dc modename in
1701 if always
|| h <> dh
1703 if Hashtbl.length
h > 0
1705 if Buffer.length
bb > 0
1706 then Buffer.add_char
bb '
\n'
;
1707 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
1708 Hashtbl.iter
(fun i o
->
1709 let isdifferent = always
||
1711 let dO = Hashtbl.find dh i
in
1713 with Not_found
-> true
1718 if Wsi.withctrl m
then Buffer.add_string
bb "ctrl-";
1719 if Wsi.withalt m
then Buffer.add_string
bb "alt-";
1720 if Wsi.withshift m
then Buffer.add_string
bb "shift-";
1721 if Wsi.withmeta m
then Buffer.add_string
bb "meta-";
1722 Buffer.add_string
bb (Wsi.keyname
k);
1725 let rec loop = function
1727 | km
:: [] -> addkm km
1728 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
1732 Buffer.add_string
bb "<map in='";
1736 Buffer.add_string
bb "' out='";
1738 Buffer.add_string
bb "'/>\n"
1741 Buffer.add_string
bb "' out='";
1743 Buffer.add_string
bb "'/>\n"
1745 | KMmulti
(ins
, kms
) ->
1746 Buffer.add_char
bb ' '
;
1748 Buffer.add_string
bb "' out='";
1750 Buffer.add_string
bb "'/>\n"
1752 Buffer.add_string
bb "</keymap>";
1761 let save1 bb leavebirdseye x
h dc =
1762 let uifontsize = fstate.fontsize
in
1763 let dc = if conf.bedefault
then conf else dc in
1764 Buffer.add_string
bb "<llppconfig>\n";
1766 if nonemptystr
!fontpath
1768 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
1774 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
1777 Buffer.add_string
bb "<defaults";
1778 add_attrs bb true dc dc nan
;
1779 let kb = keymapsbuf true dc dc in
1780 if Buffer.length
kb > 0
1782 Buffer.add_string
bb ">\n";
1783 Buffer.add_buffer
bb kb;
1784 Buffer.add_string
bb "\n</defaults>\n";
1786 else Buffer.add_string
bb "/>\n";
1788 let adddoc path pan
anchor c bookmarks time
=
1789 if bookmarks == [] && c = dc && anchor = emptyanchor
1792 Printf.bprintf
bb "<doc path='%s'"
1793 (enent
path 0 (String.length
path));
1795 if anchor <> emptyanchor
1797 let n, rely
, visy
= anchor in
1798 Printf.bprintf
bb "\n page='%d'" n;
1801 Printf.bprintf
bb " rely='%f'" rely
1803 if abs_float visy
> 1e-6
1805 Printf.bprintf
bb " visy='%f'" visy
1810 then Printf.bprintf
bb " pan='%d'" pan
;
1812 add_attrs bb false dc c time
;
1813 let kb = keymapsbuf false dc c in
1815 begin match bookmarks with
1817 if Buffer.length
kb > 0
1819 Buffer.add_string
bb ">\n";
1820 Buffer.add_buffer
bb kb;
1821 Buffer.add_string
bb "\n</doc>\n";
1823 else Buffer.add_string
bb "/>\n"
1825 Buffer.add_string
bb ">\n<bookmarks>\n";
1826 List.iter
(fun (title
, _, kind
) ->
1827 begin match kind
with
1828 | Oanchor
(page, rely
, visy
) ->
1830 "<item title='%s' page='%d'"
1831 (enent title
0 (String.length title
))
1836 Printf.bprintf
bb " rely='%f'" rely
1838 if abs_float visy
> 1e-6
1840 Printf.bprintf
bb " visy='%f'" visy
1842 | Ohistory
_ | Onone
| Ouri
_ | Oremote
_
1843 | Oremotedest
_ | Olaunch
_ | Oaction
_ ->
1844 failwith
"unexpected link in bookmarks"
1846 Buffer.add_string
bb "/>\n";
1848 Buffer.add_string
bb "</bookmarks>";
1849 if Buffer.length
kb > 0
1851 Buffer.add_string
bb "\n";
1852 Buffer.add_buffer
bb kb;
1854 Buffer.add_string
bb "\n</doc>\n";
1860 match state.mode
with
1861 | Birdseye
(c, pan, _, _, _) ->
1863 match conf.columns
with
1864 | Cmulti
((c, _, _), _) -> Some
c
1868 match c.columns
with
1869 | Cmulti
(c, _) -> Cmulti
(c, E.a
)
1870 | Csingle
_ -> Csingle
E.a
1871 | Csplit
_ -> failwith
"quit from bird's eye while split"
1873 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
1876 | LinkNav
_ -> x
, conf
1878 let docpath = abspath
state.path in
1879 adddoc docpath pan (getanchor ())
1881 let autoscrollstep =
1882 match state.autoscroll
with
1884 | None
-> conf.autoscrollstep
1886 begin match state.mode
with
1887 | Birdseye beye
-> leavebirdseye beye
true
1892 { conf with autoscrollstep = autoscrollstep }
1894 (if conf.savebmarks
then state.bookmarks else [])
1897 Hashtbl.iter
(fun path (c, bookmarks, x
, anchor) ->
1898 if docpath <> abspath
path
1899 then adddoc path x
anchor c bookmarks c.lastvisit
1901 Buffer.add_string
bb "</llppconfig>\n";
1905 let save leavebirdseye
=
1906 let relx = float state.x
/. float state.winw
in
1908 let cx w = truncate
(relx *. float w) in
1910 (fun (w, h, x
) ws
->
1912 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
1913 | Wsi.MaxVert
-> (w, conf.cwinh
, x
)
1914 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
1916 (state.winw
, state.winh
, state.x
) state.winstate
1920 let bb = Buffer.create
32768 in
1922 save1 bb leavebirdseye x
h dc
1924 if load1 save2 && Buffer.length
bb > 0
1927 let tmp = !confpath ^
".tmp" in
1928 let oc = open_out_bin
tmp in
1929 Buffer.output_buffer
oc bb;
1931 Unix.rename
tmp !confpath;
1934 ("error while saving configuration: " ^ exntos exn
)
1939 let n'
= Unix.write fdo
(Bytes.of_string s) 0 n in
1941 then Utils.error
"Unix.write %d = %d" n n'
1944 try Unix.read fdi
s 0 n
1945 with exn
-> Utils.error
"reading gc pipe %s" (exntos exn
) in
1946 let href = ref (Hashtbl.create
0) in
1947 let cref = ref defconf in
1949 let f path (pc, _pb
, _px
, _pa
) =
1951 Printf.sprintf
"%s\000%ld\000" path (Int32.of_float
pc.lastvisit
)
1953 wr s (String.length
s)
1958 Unix.shutdown fdo
Unix.SHUTDOWN_SEND
;
1961 ignore
(load1 push);
1963 let b = Buffer.create
32768 in
1964 let s = Bytes.create
4096 in
1966 let n = rd s (Bytes.length
s) in
1968 then Buffer.contents
b
1969 else (Buffer.add_subbytes
b s 0 n; f ())
1974 match String.index_from
s ppos '
\000'
with
1977 try String.index_from
s (zpos1
+1) '
\000'
with Not_found
-> -1 in
1979 then error
"Incorrect gc input in (%S) at %d" s zpos1
1981 let okey = StringLabels.sub
s ~pos
:ppos ~
len:(zpos1
-ppos
) in
1982 let nkey = StringLabels.sub
s ~pos
:(zpos1
+1) ~
len:(zpos2-zpos1
-1) in
1984 then (Hashtbl.remove
!href okey; f (zpos2+1))
1987 try Hashtbl.find !href okey
1988 with Not_found
-> Utils.error
"gc: could not find %S" okey
1990 Hashtbl.remove
!href okey;
1991 Hashtbl.replace
!href nkey v;
1993 | exception Not_found
-> ()
1996 let bb = Buffer.create
32768 in
1997 let save2 (_h
, dc) = save1 bb (fun _ _ -> ()) 0 !href dc in
1998 if load1 save2 && Buffer.length
bb > 0
2001 let tmp = !confpath ^
".tmp" in
2002 let oc = open_out_bin
tmp in
2003 Buffer.output_buffer
oc bb;
2005 Unix.rename
tmp !confpath;
2008 ("error while saving configuration: " ^ exntos exn
)