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"
466 | Pfreebsd
-> "FreeBSD"
467 | Pdragonflybsd
-> "DragonflyBSD"
468 | Popenbsd
-> "OpenBSD"
469 | Pnetbsd
-> "NetBSD"
470 | Pcygwin
-> "Cygwin"
474 Printf.sprintf
"llpp version %s, fitz %s, ocaml %s (%s/%dbit)"
475 Help.version (fz_version
()) Sys.ocaml_version
476 (platform_to_string platform
) Sys.word_size
480 let colonpos = try String.index s '
:'
with Not_found
-> -1 in
481 let len = String.length s
in
482 if colonpos >= 0 && colonpos + 3 < len
484 if s
.[colonpos+1] = '
/'
&& s
.[colonpos+2] = '
/'
487 try String.rindex_from s
colonpos ' '
491 String.sub s
(schemestartpos+1) (colonpos-1-schemestartpos)
494 | "http" | "ftp" | "mailto" ->
496 try String.index_from s
colonpos ' '
497 with Not_found
-> len
499 String.sub s
(schemestartpos+1) (epos-1-schemestartpos)
509 ; scrollb
= scrollbhv lor scrollbvv
525 ; presentation
= false
530 ; fitmodel
= FitProportional
531 ; trimmargins
= false
532 ; trimfuzz
= (0,0,0,0)
533 ; memlimit
= 32 lsl 20
538 ; bgcolor
= (0.5, 0.5, 0.5)
542 ; mustoresize
= 256 lsl 20
547 | Plinux
| Pfreebsd
| Pdragonflybsd
548 | Popenbsd
| Pnetbsd
| Psun
-> "xdg-open \"%s\""
549 | Posx
-> "open \"%s\""
550 | Pcygwin
-> "cygstart \"%s\""
551 | Punknown
-> "echo %s")
552 ; pathlauncher
= "lp \"%s\""
555 | Plinux
| Pfreebsd
| Pdragonflybsd
556 | Popenbsd
| Pnetbsd
| Psun
-> "xsel -i"
564 ; redirectstderr
= false
566 ; columns
= Csingle
[||]
572 ; wheelbypage
= false
573 ; stcmd
= "echo SyncTex"
576 ; paxmark
= Mark_word
581 let mk n
= (n
, Hashtbl.create
1) in
595 let conf = { defconf with angle
= defconf.angle
};;
598 if emptystr
conf.urilauncher
599 then print_endline uri
601 let url = geturl uri
in
603 then Printf.eprintf
"obtained empty url from uri %S\n" uri
605 let re = Str.regexp
"%s" in
606 let command = Str.global_replace
re url conf.urilauncher
in
610 "failed to execute `%s': %s\n" command (exntos exn
);
618 :: "(searching in this text works just by typing (i.e. no initial '/'))"
623 let url = geturl s
in
625 then (s
, 0, Action
(fun u
-> gotouri url; u
))
626 else (s
, 0, Noaction
)
631 { store
= Array.create n v
638 let cbcap b
= Array.length b
.store
;;
643 b
.wc
<- (b
.wc
+ 1) mod cap;
645 b
.len <- min
(b
.len + 1) cap;
648 let cbempty b
= b
.len = 0;;
650 let cbgetg b circular dir
=
654 let rc = b
.rc + dir
in
666 else bound
rc 0 (b
.len-1)
672 let cbget b
= cbgetg b
false;;
673 let cbgetc b
= cbgetg b
true;;
679 ; stderr
= Unix.stderr
680 ; errmsgs
= Buffer.create
0
685 ; anchor
= emptyanchor
689 ; tilelru
= Queue.create
()
690 ; pagemap
= Hashtbl.create
10
691 ; tilemap
= Hashtbl.create
10
701 ; searchpattern
= E.s
707 ; geomcmds
= firstgeomcmds
709 { nav
= cbnew 10 emptyanchor
721 ; checkerstexid
= None
722 ; prevzoom
= (1.0, 0)
736 ; traw
= Raw.create_static `
float ~
len:8
737 ; vraw
= Raw.create_static `
float ~
len:8
741 let copykeyhashes c
=
742 List.map
(fun (k
, v
) -> k
, Hashtbl.copy v
) c
.keyhashes
;
746 let d = state.winh
- h
in
747 max
conf.interpagespace
((d + 1) / 2)
750 let rowyh (c
, coverA
, coverB
) b n
=
751 if c
= 1 || (n
< coverA
|| n
>= state.pagecount
- coverB
)
753 let _, _, vy
, (_, _, h
, _) = b
.(n
) in
756 let n'
= n - coverA
in
759 let e = min
state.pagecount
(s + c
) in
760 let rec find m miny maxh
= if m
= e then miny
, maxh
else
761 let _, _, y
, (_, _, h
, _) = b
.(m
) in
762 let miny = min
miny y
in
763 let maxh = max
maxh h
in
769 let ((c
, coverA
, coverB
) as cl
), b
=
770 match conf.columns
with
771 | Csingle b
-> (1, 0, 0), b
772 | Cmulti
(c
, b
) -> c
, b
773 | Csplit
(_, b
) -> (1, 0, 0), b
775 if Array.length b
= 0
778 let rec bsearch nmin nmax
=
780 then bound nmin
0 (state.pagecount
-1)
782 let n = (nmax
+ nmin
) / 2 in
783 let vy, h
= rowyh cl b
n in
787 let ips = calcips h
in
789 let y1 = vy + h
+ ips in
793 then 0, vy + h
+ conf.interpagespace
795 let y0 = vy - conf.interpagespace
in
796 y0, y0 + h
+ conf.interpagespace
806 if n < state.pagecount
- coverB
807 then ((n-coverA
)/c
)*c
+ coverA
814 then bsearch (n+1) nmax
815 else bsearch nmin
(n-1)
818 bsearch 0 (state.pagecount
-1);
822 match conf.columns
with
823 | Cmulti
((_, _, _) as cl
, b
) ->
824 if Array.length b
> 0
826 let y, h
= rowyh cl 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
833 y + h
+ (if conf.presentation
then calcips h
else 0)
836 if Array.length b
> 0
838 let (_, _, y, (_, _, h
, _)) = b
.(Array.length b
- 1) in
843 let getpageywh pageno
=
844 let pageno = bound
pageno 0 (state.pagecount
-1) in
845 match conf.columns
with
847 if Array.length b
= 0
850 let (_, _, y, (_, w
, h
, _)) = b
.(pageno) in
858 if Array.length b
= 0
861 let y, h
= rowyh cl b
pageno in
862 let (_, _, _, (_, w
, _, _)) = b
.(pageno) in
870 if Array.length b
= 0
874 let (_, _, y, (_, w
, h
, _)) = b
.(n) in
878 let getpageyh pageno =
879 let y,_,h
= getpageywh pageno in
883 let getpagedim pageno =
886 | (n, _, _, _) as pdim
:: rest
->
888 then (if n = pageno then pdim
else ppdim
)
893 f (-1, -1, -1, -1) state.pdims
896 let getpagey pageno = fst
(getpageyh pageno);;
900 let coloff = l
.pagecol
* l
.pageh
in
901 float (l
.pagey
+ coloff) /. float l
.pageh
909 then float l
.pagedispy
/. float (calcips l
.pageh
)
910 else float l
.pagedispy
/. float conf.interpagespace
913 (l
.pageno, top, dtop)
917 match state.layout
with
918 | l
:: _ -> getanchor1 l
920 let n = page_of_y state.y in
924 let y, h
= getpageyh n in
925 let dy = y - state.y in
929 let ips = calcips h
in
930 float (dy + ips) /. float ips
932 float dy /. float conf.interpagespace
937 let fontpath = ref E.s;;
939 type historder
= [ `lastvisit
| `title
| `path
| `file
];;
940 let historder : historder ref = ref `lastvisit
;;
943 Map.Make
(struct type t
= (int * int) let compare = compare end);;
948 let l = String.length
s in
949 let b = Buffer.create
l in
955 try Sys.getenv
"HOME"
958 ("Can not determine home directory location: " ^ exntos exn
);
962 let modifier_of_string = function
963 | "alt" -> Wsi.altmask
964 | "shift" -> Wsi.shiftmask
965 | "ctrl" | "control" -> Wsi.ctrlmask
966 | "meta" -> Wsi.metamask
971 let r = Str.regexp
"-" in
973 let elems = Str.full_split
r s in
976 let m1 = modifier_of_string s in
978 then (Wsi.namekey
s, m
)
981 | Str.Delim
s when n land 1 = 0 -> g s
983 | Str.Delim
_ -> (k
, m
)
985 let rec loop n k m
= function
988 let k, m
= f n k m x
in
995 let r = Str.regexp
"[ \t]" in
997 let elems = Str.split
r s in
998 List.map
key_of_string elems
1001 let config_of c attrs
=
1005 | "scroll-bar-width" -> { c
with scrollbw
= max
0 (int_of_string v
) }
1006 | "scroll-handle-height" -> { c
with scrollh
= max
0 (int_of_string v
) }
1007 | "case-insensitive-search" -> { c
with icase
= bool_of_string v
}
1008 | "preload" -> { c
with preload
= bool_of_string v
}
1009 | "page-bias" -> { c
with pagebias
= int_of_string v
}
1010 | "scroll-step" -> { c
with scrollstep
= max
1 (int_of_string v
) }
1011 | "horizontal-scroll-step" ->
1012 { c
with hscrollstep
= max
(int_of_string v
) 1 }
1013 | "auto-scroll-step" ->
1014 { c
with autoscrollstep
= max
0 (int_of_string v
) }
1015 | "max-height-fit" -> { c
with maxhfit
= bool_of_string v
}
1016 | "crop-hack" -> { c
with crophack
= bool_of_string v
}
1019 match String.lowercase v
with
1020 | "true" -> Some infinity
1022 | f -> Some
(float_of_string
f)
1024 { c
with maxwait
= mw}
1025 | "highlight-links" -> { c
with hlinks
= bool_of_string v
}
1026 | "under-cursor-info" -> { c
with underinfo
= bool_of_string v
}
1027 | "vertical-margin" ->
1028 { c
with interpagespace
= max
0 (int_of_string v
) }
1030 let zoom = float_of_string v
/. 100. in
1031 let zoom = max
zoom 0.0 in
1032 { c
with zoom = zoom }
1033 | "presentation" -> { c
with presentation
= bool_of_string v
}
1034 | "rotation-angle" -> { c
with angle
= int_of_string v
}
1035 | "width" -> { c
with cwinw
= max
20 (int_of_string v
) }
1036 | "height" -> { c
with cwinh
= max
20 (int_of_string v
) }
1037 | "persistent-bookmarks" -> { c
with savebmarks
= bool_of_string v
}
1038 | "proportional-display" ->
1041 then FitProportional
1044 { c
with fitmodel
= fm }
1045 | "fit-model" -> { c
with fitmodel
= FMTE.of_string v
}
1046 | "pixmap-cache-size" ->
1047 { c
with memlimit
= max
2 (int_of_string_with_suffix v
) }
1048 | "tex-count" -> { c
with texcount
= max
1 (int_of_string v
) }
1049 | "slice-height" -> { c
with sliceheight
= max
2 (int_of_string v
) }
1050 | "thumbnail-width" -> { c
with thumbw
= max
2 (int_of_string v
) }
1051 | "persistent-location" -> { c
with jumpback
= bool_of_string v
}
1052 | "background-color" -> { c
with bgcolor
= color_of_string v
}
1053 | "tile-width" -> { c
with tilew
= max
2 (int_of_string v
) }
1054 | "tile-height" -> { c
with tileh
= max
2 (int_of_string v
) }
1055 | "mupdf-store-size" ->
1056 { c
with mustoresize
= max
1024 (int_of_string_with_suffix v
) }
1057 | "checkers" -> { c
with checkers
= bool_of_string v
}
1058 | "aalevel" -> { c
with aalevel
= max
0 (int_of_string v
) }
1059 | "trim-margins" -> { c
with trimmargins
= bool_of_string v
}
1060 | "trim-fuzz" -> { c
with trimfuzz
= irect_of_string v
}
1061 | "uri-launcher" -> { c
with urilauncher
= unent v
}
1062 | "path-launcher" -> { c
with pathlauncher
= unent v
}
1063 | "color-space" -> { c
with colorspace
= CSTE.of_string v
}
1064 | "invert-colors" -> { c
with invert
= bool_of_string v
}
1065 | "brightness" -> { c
with colorscale
= float_of_string v
}
1066 | "redirectstderr" -> { c
with redirectstderr
= bool_of_string v
}
1067 | "ghyllscroll" -> { c
with ghyllscroll
= ghyllscroll_of_string v
}
1069 let (n, _, _) as nab
= multicolumns_of_string v
in
1071 then { c
with columns
= Csplit
(-n, E.a
) }
1072 else { c
with columns
= Cmulti
(nab
, E.a
) }
1073 | "birds-eye-columns" ->
1074 { c
with beyecolumns
= Some
(max
(int_of_string v
) 2) }
1075 | "selection-command" -> { c
with selcmd
= unent v
}
1076 | "synctex-command" -> { c
with stcmd
= unent v
}
1077 | "pax-command" -> { c
with paxcmd
= unent v
}
1078 | "update-cursor" -> { c
with updatecurs
= bool_of_string v
}
1079 | "hint-font-size" -> { c
with hfsize
= bound
(int_of_string v
) 5 100 }
1080 | "page-scroll-scale" -> { c
with pgscale
= float_of_string v
}
1081 | "use-pbo" -> { c
with usepbo
= bool_of_string v
}
1082 | "wheel-scrolls-pages" -> { c
with wheelbypage
= bool_of_string v
}
1083 | "horizontal-scrollbar-visible" ->
1086 then c
.scrollb
lor scrollbhv
1087 else c
.scrollb
land (lnot
scrollbhv)
1089 { c
with scrollb
= b }
1090 | "vertical-scrollbar-visible" ->
1093 then c
.scrollb
lor scrollbvv
1094 else c
.scrollb
land (lnot
scrollbvv)
1096 { c
with scrollb
= b }
1097 | "remote-in-a-new-instance" -> { c
with riani
= bool_of_string v
}
1101 then Some
(ref (0.0, 0, 0))
1103 | "point-and-x-mark" -> { c
with paxmark
= MTE.of_string v
}
1104 | "scroll-bar-on-the-left" -> { c
with leftscroll
= bool_of_string v
}
1105 | "title" -> { c
with title
= unent v
}
1106 | "last-visit" -> { c
with lastvisit
= float_of_string v
}
1109 prerr_endline
("Error processing attribute (`" ^
1110 k ^
"'=`" ^ v ^
"'): " ^ exntos exn
);
1113 let rec fold c
= function
1116 let c = apply c k v
in
1119 fold { c with keyhashes
= copykeyhashes c } attrs
;
1122 let fromstring f pos
n v
d =
1125 dolog
"Error processing attribute (%S=%S) at %d\n%s"
1126 n v pos
(exntos exn
)
1131 let bookmark_of attrs
=
1132 let rec fold title page rely visy
= function
1133 | ("title", v
) :: rest
-> fold v page rely visy rest
1134 | ("page", v
) :: rest
-> fold title v rely visy rest
1135 | ("rely", v
) :: rest
-> fold title page v visy rest
1136 | ("visy", v
) :: rest
-> fold title page rely v rest
1137 | _ :: rest
-> fold title page rely visy rest
1138 | [] -> title
, page
, rely
, visy
1140 fold "invalid" "0" "0" "0" attrs
1144 let rec fold path page rely pan visy
= function
1145 | ("path", v
) :: rest
-> fold v page rely pan visy rest
1146 | ("page", v
) :: rest
-> fold path v rely pan visy rest
1147 | ("rely", v
) :: rest
-> fold path page v pan visy rest
1148 | ("pan", v
) :: rest
-> fold path page rely v visy rest
1149 | ("visy", v
) :: rest
-> fold path page rely pan v rest
1150 | _ :: rest
-> fold path page rely pan visy rest
1151 | [] -> path
, page
, rely
, pan
, visy
1153 fold E.s "0" "0" "0" "0" attrs
1157 let rec fold rs ls
= function
1158 | ("out", v
) :: rest
-> fold v ls rest
1159 | ("in", v
) :: rest
-> fold rs v rest
1160 | _ :: rest
-> fold ls rs rest
1166 let setconf dst src
=
1167 dst
.scrollbw
<- src
.scrollbw
;
1168 dst
.scrollh
<- src
.scrollh
;
1169 dst
.icase
<- src
.icase
;
1170 dst
.preload
<- src
.preload
;
1171 dst
.pagebias
<- src
.pagebias
;
1172 dst
.verbose
<- src
.verbose
;
1173 dst
.scrollstep
<- src
.scrollstep
;
1174 dst
.maxhfit
<- src
.maxhfit
;
1175 dst
.crophack
<- src
.crophack
;
1176 dst
.autoscrollstep
<- src
.autoscrollstep
;
1177 dst
.maxwait
<- src
.maxwait
;
1178 dst
.hlinks
<- src
.hlinks
;
1179 dst
.underinfo
<- src
.underinfo
;
1180 dst
.interpagespace
<- src
.interpagespace
;
1181 dst
.zoom <- src
.zoom;
1182 dst
.presentation
<- src
.presentation
;
1183 dst
.angle
<- src
.angle
;
1184 dst
.cwinw
<- src
.cwinw
;
1185 dst
.cwinh
<- src
.cwinh
;
1186 dst
.savebmarks
<- src
.savebmarks
;
1187 dst
.memlimit
<- src
.memlimit
;
1188 dst
.fitmodel
<- src
.fitmodel
;
1189 dst
.texcount
<- src
.texcount
;
1190 dst
.sliceheight
<- src
.sliceheight
;
1191 dst
.thumbw
<- src
.thumbw
;
1192 dst
.jumpback
<- src
.jumpback
;
1193 dst
.bgcolor
<- src
.bgcolor
;
1194 dst
.tilew
<- src
.tilew
;
1195 dst
.tileh
<- src
.tileh
;
1196 dst
.mustoresize
<- src
.mustoresize
;
1197 dst
.checkers
<- src
.checkers
;
1198 dst
.aalevel
<- src
.aalevel
;
1199 dst
.trimmargins
<- src
.trimmargins
;
1200 dst
.trimfuzz
<- src
.trimfuzz
;
1201 dst
.urilauncher
<- src
.urilauncher
;
1202 dst
.colorspace
<- src
.colorspace
;
1203 dst
.invert
<- src
.invert
;
1204 dst
.colorscale
<- src
.colorscale
;
1205 dst
.redirectstderr
<- src
.redirectstderr
;
1206 dst
.ghyllscroll
<- src
.ghyllscroll
;
1207 dst
.columns
<- src
.columns
;
1208 dst
.beyecolumns
<- src
.beyecolumns
;
1209 dst
.selcmd
<- src
.selcmd
;
1210 dst
.updatecurs
<- src
.updatecurs
;
1211 dst
.pathlauncher
<- src
.pathlauncher
;
1212 dst
.keyhashes
<- copykeyhashes src
;
1213 dst
.hfsize
<- src
.hfsize
;
1214 dst
.hscrollstep
<- src
.hscrollstep
;
1215 dst
.pgscale
<- src
.pgscale
;
1216 dst
.usepbo
<- src
.usepbo
;
1217 dst
.wheelbypage
<- src
.wheelbypage
;
1218 dst
.stcmd
<- src
.stcmd
;
1219 dst
.paxcmd
<- src
.paxcmd
;
1220 dst
.scrollb
<- src
.scrollb
;
1221 dst
.riani
<- src
.riani
;
1222 dst
.paxmark
<- src
.paxmark
;
1223 dst
.leftscroll
<- src
.leftscroll
;
1224 dst
.title
<- src
.title
;
1228 else Some
((ref (0.0, 0, 0)));
1231 let findkeyhash c name =
1232 try List.assoc
name c.keyhashes
1233 with Not_found
-> failwith
("invalid mode name `" ^
name ^
"'")
1237 let h = Hashtbl.create
10 in
1238 let dc = { defconf with angle
= defconf.angle
} in
1239 let rec toplevel v t spos
_ =
1241 | Vdata
| Vcdata
| Vend
-> v
1242 | Vopen
("llppconfig", _, closed
) ->
1245 else { v
with f = llppconfig
}
1247 error
"unexpected subelement at top level" s spos
1248 | Vclose
_ -> error
"unexpected close at top level" s spos
1250 and llppconfig v t spos
_ =
1252 | Vdata
| Vcdata
-> v
1253 | Vend
-> error
"unexpected end of input in llppconfig" s spos
1254 | Vopen
("defaults", attrs
, closed
) ->
1255 let c = config_of dc attrs
in
1259 else { v
with f = defaults
}
1261 | Vopen
("ui-font", attrs
, closed
) ->
1262 let rec getsize size
= function
1264 | ("size", v
) :: rest
->
1266 fromstring int_of_string spos
"size" v
fstate.fontsize
in
1268 | l -> getsize size l
1270 fstate.fontsize
<- getsize fstate.fontsize attrs
;
1273 else { v
with f = uifont
(Buffer.create
10) }
1275 | Vopen
("doc", attrs
, closed
) ->
1276 let pathent, spage
, srely
, span
, svisy
= doc_of attrs
in
1277 let path = unent pathent
1278 and pageno = fromstring int_of_string spos
"page" spage
0
1279 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1280 and pan
= fromstring int_of_string spos
"pan" span
0
1281 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1282 let c = config_of dc attrs
in
1283 let anchor = (pageno, rely
, visy
) in
1285 then (Hashtbl.add
h path (c, [], pan
, anchor); v
)
1286 else { v
with f = doc
path pan
anchor c [] }
1289 error
"unexpected subelement in llppconfig" s spos
1291 | Vclose
"llppconfig" -> { v
with f = toplevel }
1292 | Vclose
_ -> error
"unexpected close in llppconfig" s spos
1294 and defaults v t spos
_ =
1296 | Vdata
| Vcdata
-> v
1297 | Vend
-> error
"unexpected end of input in defaults" s spos
1298 | Vopen
("keymap", attrs
, closed
) ->
1300 try List.assoc
"mode" attrs
1301 with Not_found
-> "global" in
1306 let h = findkeyhash dc modename in
1307 KeyMap.iter
(Hashtbl.replace
h) keymap
;
1310 { v
with f = pkeymap
ret KeyMap.empty
}
1312 | Vopen
(_, _, _) ->
1313 error
"unexpected subelement in defaults" s spos
1315 | Vclose
"defaults" ->
1316 { v
with f = llppconfig
}
1318 | Vclose
_ -> error
"unexpected close in defaults" s spos
1320 and uifont
b v t spos
epos =
1323 Buffer.add_substring
b s spos
(epos - spos
);
1325 | Vopen
(_, _, _) ->
1326 error
"unexpected subelement in ui-font" s spos
1327 | Vclose
"ui-font" ->
1328 if emptystr
!fontpath
1329 then fontpath := Buffer.contents
b;
1330 { v
with f = llppconfig
}
1331 | Vclose
_ -> error
"unexpected close in ui-font" s spos
1332 | Vend
-> error
"unexpected end of input in ui-font" s spos
1334 and doc
path pan
anchor c bookmarks v t spos
_ =
1336 | Vdata
| Vcdata
-> v
1337 | Vend
-> error
"unexpected end of input in doc" s spos
1338 | Vopen
("bookmarks", _, closed
) ->
1341 else { v
with f = pbookmarks
path pan
anchor c bookmarks
}
1343 | Vopen
("keymap", attrs
, closed
) ->
1345 try List.assoc
"mode" attrs
1346 with Not_found
-> "global"
1352 let h = findkeyhash c modename in
1353 KeyMap.iter
(Hashtbl.replace
h) keymap
;
1354 doc
path pan
anchor c bookmarks
1356 { v
with f = pkeymap
ret KeyMap.empty
}
1358 | Vopen
(_, _, _) ->
1359 error
"unexpected subelement in doc" s spos
1362 Hashtbl.add
h path (c, List.rev bookmarks
, pan
, anchor);
1363 { v
with f = llppconfig
}
1365 | Vclose
_ -> error
"unexpected close in doc" s spos
1367 and pkeymap
ret keymap v t spos
_ =
1369 | Vdata
| Vcdata
-> v
1370 | Vend
-> error
"unexpected end of input in keymap" s spos
1371 | Vopen
("map", attrs
, closed
) ->
1372 let r, l = map_of attrs
in
1373 let kss = fromstring keys_of_string spos
"in" r [] in
1374 let lss = fromstring keys_of_string spos
"out" l [] in
1378 | ks
:: [] -> KeyMap.add ks
(KMinsrl
lss) keymap
1379 | ks
:: rest
-> KeyMap.add ks
(KMmulti
(rest
, lss)) keymap
1382 then { v
with f = pkeymap
ret keymap }
1385 { v
with f = skip
"map" f }
1388 error
"unexpected subelement in keymap" s spos
1390 | Vclose
"keymap" ->
1391 { v
with f = ret keymap }
1393 | Vclose
_ -> error
"unexpected close in keymap" s spos
1395 and pbookmarks
path pan
anchor c bookmarks v t spos
_ =
1397 | Vdata
| Vcdata
-> v
1398 | Vend
-> error
"unexpected end of input in bookmarks" s spos
1399 | Vopen
("item", attrs
, closed
) ->
1400 let titleent, spage
, srely
, svisy
= bookmark_of attrs
in
1401 let page = fromstring int_of_string spos
"page" spage
0
1402 and rely
= fromstring float_of_string spos
"rely" srely
0.0
1403 and visy
= fromstring float_of_string spos
"visy" svisy
0.0 in
1405 (unent titleent, 0, Oanchor
(page, rely
, visy
)) :: bookmarks
1408 then { v
with f = pbookmarks
path pan
anchor c bookmarks }
1411 { v
with f = skip
"item" f }
1414 error
"unexpected subelement in bookmarks" s spos
1416 | Vclose
"bookmarks" ->
1417 { v
with f = doc
path pan
anchor c bookmarks }
1419 | Vclose
_ -> Parser.parse_error
"unexpected close in bookmarks" s spos
1421 and skip tag
f v t spos
_ =
1423 | Vdata
| Vcdata
-> v
1425 Parser.parse_error
("unexpected end of input in skipped " ^ tag
) s spos
1426 | Vopen
(tag'
, _, closed
) ->
1430 let f'
() = { v
with f = skip tag
f } in
1431 { v
with f = skip tag'
f'
}
1435 else Parser.parse_error
("unexpected close in skipped " ^ tag
) s spos
1438 parse
{ f = toplevel; accu
= () } s;
1444 let len = in_channel_length ic
in
1445 let s = String.create
len in
1446 really_input ic
s 0 len;
1449 | Parse_error
(msg
, s, pos
) ->
1450 let subs = subs s pos
in
1451 Utils.error
"parse error: %s: at %d [..%s..]" msg pos
subs
1454 failwith
("config load error: " ^ exntos exn
)
1460 let dir = Filename.concat
home ".config" in
1461 if Sys.is_directory
dir then dir else home
1464 Filename.concat
dir "llpp.conf"
1467 let confpath = ref defconfpath;;
1470 if Sys.file_exists
!confpath
1473 (try Some
(open_in_bin
!confpath)
1476 ("Error opening configuration file `" ^
!confpath ^
"': " ^
1487 ("Error loading configuration from `" ^
!confpath ^
"': " ^
1496 f (Hashtbl.create
0, defconf)
1501 let pc, pb
, px
, pa
=
1504 if emptystr
state.origin
1508 let absname = abspath
path in
1509 Hashtbl.find h absname
1510 with Not_found
-> dc, [], 0, emptyanchor
1514 state.bookmarks <- pb
;
1517 then state.anchor <- pa
;
1518 cbput state.hists
.nav pa
;
1524 let gethist listref
=
1527 Hashtbl.fold (fun path (pc, pb
, px
, pa
) accu
->
1528 (path, pc, pb
, px
, pa
) :: accu
)
1535 let add_attrs bb always
dc c time
=
1538 then Printf.bprintf bb
"\n %s='%b'" s a
1541 then Printf.bprintf bb
"\n %s='%b'" s (a
!= None
)
1544 then Printf.bprintf bb
"\n %s='%d'" s a
1547 then Printf.bprintf bb
"\n %s='%s'" s (string_with_suffix_of_int a
)
1550 then Printf.bprintf bb
"\n %s='%g'" s (a
*.100.)
1553 then Printf.bprintf bb
"\n %s='%F'" s a
1557 Printf.bprintf bb
"\n %s='%s'" s (color_to_string a
)
1561 Printf.bprintf bb
"\n %s='%s'" s (CSTE.to_string a
)
1565 Printf.bprintf bb
"\n %s='%s'" s (irect_to_string a
)
1569 Printf.bprintf bb
"\n %s='%s'" s (enent a
0 (String.length a
))
1574 | Some
(_N
, _A
, _B
) ->
1575 Printf.bprintf bb
"\n %s='%u,%u,%u'" s _N _A _B
1580 Printf.bprintf bb
"\n %s='none'" s
1590 else string_of_float
f
1592 Printf.bprintf bb
"\n %s='%s'" s v
1597 | Cmulti
((n, a
, b), _) when n > 1 ->
1598 Printf.bprintf bb
"\n %s='%d,%d,%d'" s n a
b
1599 | Csplit
(n, _) when n > 1 ->
1600 Printf.bprintf bb
"\n %s='%d'" s ~
-n
1601 | Cmulti
_ | Csplit
_ | Csingle
_ -> ()
1606 | Some
c when c > 1 -> Printf.bprintf bb
"\n %s='%d'" s c
1611 Printf.bprintf bb
"\n %s='%s'" s (FMTE.to_string a
)
1615 Printf.bprintf bb
"\n %s='%b'" s (a
land m
!= 0)
1619 Printf.bprintf bb
"\n %s='%s'" s (MTE.to_string a
)
1621 oi
"width" c.cwinw
dc.cwinw
;
1622 oi
"height" c.cwinh
dc.cwinh
;
1623 oi
"scroll-bar-width" c.scrollbw
dc.scrollbw
;
1624 oi
"scroll-handle-height" c.scrollh
dc.scrollh
;
1625 oSv
"horizontal-scrollbar-visible" c.scrollb
dc.scrollb
scrollbhv;
1626 oSv
"vertical-scrollbar-visible" c.scrollb
dc.scrollb
scrollbvv;
1627 ob "case-insensitive-search" c.icase
dc.icase
;
1628 ob "preload" c.preload
dc.preload
;
1629 oi
"page-bias" c.pagebias
dc.pagebias
;
1630 oi
"scroll-step" c.scrollstep
dc.scrollstep
;
1631 oi
"auto-scroll-step" c.autoscrollstep
dc.autoscrollstep
;
1632 ob "max-height-fit" c.maxhfit
dc.maxhfit
;
1633 ob "crop-hack" c.crophack
dc.crophack
;
1634 oW
"throttle" c.maxwait
dc.maxwait
;
1635 ob "highlight-links" c.hlinks
dc.hlinks
;
1636 ob "under-cursor-info" c.underinfo
dc.underinfo
;
1637 oi
"vertical-margin" c.interpagespace
dc.interpagespace
;
1638 oz
"zoom" c.zoom dc.zoom;
1639 ob "presentation" c.presentation
dc.presentation
;
1640 oi
"rotation-angle" c.angle
dc.angle
;
1641 ob "persistent-bookmarks" c.savebmarks
dc.savebmarks
;
1642 oFm
"fit-model" c.fitmodel
dc.fitmodel
;
1643 oI
"pixmap-cache-size" c.memlimit
dc.memlimit
;
1644 oi
"tex-count" c.texcount
dc.texcount
;
1645 oi
"slice-height" c.sliceheight
dc.sliceheight
;
1646 oi
"thumbnail-width" c.thumbw
dc.thumbw
;
1647 ob "persistent-location" c.jumpback
dc.jumpback
;
1648 oc
"background-color" c.bgcolor
dc.bgcolor
;
1649 oi
"tile-width" c.tilew
dc.tilew
;
1650 oi
"tile-height" c.tileh
dc.tileh
;
1651 oI
"mupdf-store-size" c.mustoresize
dc.mustoresize
;
1652 ob "checkers" c.checkers
dc.checkers
;
1653 oi
"aalevel" c.aalevel
dc.aalevel
;
1654 ob "trim-margins" c.trimmargins
dc.trimmargins
;
1655 oR
"trim-fuzz" c.trimfuzz
dc.trimfuzz
;
1656 os
"uri-launcher" c.urilauncher
dc.urilauncher
;
1657 os
"path-launcher" c.pathlauncher
dc.pathlauncher
;
1658 oC
"color-space" c.colorspace
dc.colorspace
;
1659 ob "invert-colors" c.invert
dc.invert
;
1660 oF
"brightness" c.colorscale
dc.colorscale
;
1661 ob "redirectstderr" c.redirectstderr
dc.redirectstderr
;
1662 og
"ghyllscroll" c.ghyllscroll
dc.ghyllscroll
;
1663 oco
"columns" c.columns
dc.columns
;
1664 obeco
"birds-eye-columns" c.beyecolumns
dc.beyecolumns
;
1665 os
"selection-command" c.selcmd
dc.selcmd
;
1666 os
"synctex-command" c.stcmd
dc.stcmd
;
1667 os
"pax-command" c.paxcmd
dc.paxcmd
;
1668 ob "update-cursor" c.updatecurs
dc.updatecurs
;
1669 oi
"hint-font-size" c.hfsize
dc.hfsize
;
1670 oi
"horizontal-scroll-step" c.hscrollstep
dc.hscrollstep
;
1671 oF
"page-scroll-scale" c.pgscale
dc.pgscale
;
1672 ob "use-pbo" c.usepbo
dc.usepbo
;
1673 ob "wheel-scrolls-pages" c.wheelbypage
dc.wheelbypage
;
1674 ob "remote-in-a-new-instance" c.riani
dc.riani
;
1675 op
"point-and-x" c.pax
dc.pax
;
1676 oPm
"point-and-x-mark" c.paxmark
dc.paxmark
;
1677 ob "scroll-bar-on-the-left" c.leftscroll
dc.leftscroll
;
1679 then os
"title" c.title
dc.title
;
1680 oF
"last-visit" (snd
(modf time
)) 0.0;
1683 let keymapsbuf always
dc c =
1684 let bb = Buffer.create
16 in
1685 let rec loop = function
1687 | (modename, h) :: rest
->
1688 let dh = findkeyhash dc modename in
1689 if always
|| h <> dh
1691 if Hashtbl.length
h > 0
1693 if Buffer.length
bb > 0
1694 then Buffer.add_char
bb '
\n'
;
1695 Printf.bprintf
bb "<keymap mode='%s'>\n" modename;
1696 Hashtbl.iter
(fun i o
->
1697 let isdifferent = always
||
1699 let dO = Hashtbl.find dh i
in
1701 with Not_found
-> true
1706 if Wsi.withctrl m
then Buffer.add_string
bb "ctrl-";
1707 if Wsi.withalt m
then Buffer.add_string
bb "alt-";
1708 if Wsi.withshift m
then Buffer.add_string
bb "shift-";
1709 if Wsi.withmeta m
then Buffer.add_string
bb "meta-";
1710 Buffer.add_string
bb (Wsi.keyname
k);
1713 let rec loop = function
1715 | km
:: [] -> addkm km
1716 | km
:: rest
-> addkm km
; Buffer.add_char
bb ' '
; loop rest
1720 Buffer.add_string
bb "<map in='";
1724 Buffer.add_string
bb "' out='";
1726 Buffer.add_string
bb "'/>\n"
1729 Buffer.add_string
bb "' out='";
1731 Buffer.add_string
bb "'/>\n"
1733 | KMmulti
(ins
, kms
) ->
1734 Buffer.add_char
bb ' '
;
1736 Buffer.add_string
bb "' out='";
1738 Buffer.add_string
bb "'/>\n"
1740 Buffer.add_string
bb "</keymap>";
1749 let save1 bb leavebirdseye x
h dc =
1750 let uifontsize = fstate.fontsize
in
1751 let dc = if conf.bedefault
then conf else dc in
1752 Buffer.add_string
bb "<llppconfig>\n";
1754 if nonemptystr
!fontpath
1756 Printf.bprintf
bb "<ui-font size='%d'><![CDATA[%s]]></ui-font>\n"
1762 Printf.bprintf
bb "<ui-font size='%d'/>\n" uifontsize
1765 Buffer.add_string
bb "<defaults";
1766 add_attrs bb true dc dc nan
;
1767 let kb = keymapsbuf true dc dc in
1768 if Buffer.length
kb > 0
1770 Buffer.add_string
bb ">\n";
1771 Buffer.add_buffer
bb kb;
1772 Buffer.add_string
bb "\n</defaults>\n";
1774 else Buffer.add_string
bb "/>\n";
1776 let adddoc path pan
anchor c bookmarks time
=
1777 if bookmarks == [] && c = dc && anchor = emptyanchor
1780 Printf.bprintf
bb "<doc path='%s'"
1781 (enent
path 0 (String.length
path));
1783 if anchor <> emptyanchor
1785 let n, rely
, visy
= anchor in
1786 Printf.bprintf
bb "\n page='%d'" n;
1789 Printf.bprintf
bb " rely='%f'" rely
1791 if abs_float visy
> 1e-6
1793 Printf.bprintf
bb " visy='%f'" visy
1798 then Printf.bprintf
bb " pan='%d'" pan
;
1800 add_attrs bb false dc c time
;
1801 let kb = keymapsbuf false dc c in
1803 begin match bookmarks with
1805 if Buffer.length
kb > 0
1807 Buffer.add_string
bb ">\n";
1808 Buffer.add_buffer
bb kb;
1809 Buffer.add_string
bb "\n</doc>\n";
1811 else Buffer.add_string
bb "/>\n"
1813 Buffer.add_string
bb ">\n<bookmarks>\n";
1814 List.iter
(fun (title
, _, kind
) ->
1815 begin match kind
with
1816 | Oanchor
(page, rely
, visy
) ->
1818 "<item title='%s' page='%d'"
1819 (enent title
0 (String.length title
))
1824 Printf.bprintf
bb " rely='%f'" rely
1826 if abs_float visy
> 1e-6
1828 Printf.bprintf
bb " visy='%f'" visy
1830 | Ohistory
_ | Onone
| Ouri
_ | Oremote
_
1831 | Oremotedest
_ | Olaunch
_ | Oaction
_ ->
1832 failwith
"unexpected link in bookmarks"
1834 Buffer.add_string
bb "/>\n";
1836 Buffer.add_string
bb "</bookmarks>";
1837 if Buffer.length
kb > 0
1839 Buffer.add_string
bb "\n";
1840 Buffer.add_buffer
bb kb;
1842 Buffer.add_string
bb "\n</doc>\n";
1848 match state.mode
with
1849 | Birdseye
(c, pan, _, _, _) ->
1851 match conf.columns
with
1852 | Cmulti
((c, _, _), _) -> Some
c
1856 match c.columns
with
1857 | Cmulti
(c, _) -> Cmulti
(c, E.a
)
1858 | Csingle
_ -> Csingle
E.a
1859 | Csplit
_ -> failwith
"quit from bird's eye while split"
1861 pan, { c with beyecolumns = beyecolumns; columns
= columns
}
1864 | LinkNav
_ -> x
, conf
1866 let docpath = abspath
state.path in
1867 adddoc docpath pan (getanchor ())
1869 let autoscrollstep =
1870 match state.autoscroll
with
1872 | None
-> conf.autoscrollstep
1874 begin match state.mode
with
1875 | Birdseye beye
-> leavebirdseye beye
true
1880 { conf with autoscrollstep = autoscrollstep }
1882 (if conf.savebmarks
then state.bookmarks else [])
1885 Hashtbl.iter
(fun path (c, bookmarks, x
, anchor) ->
1886 if docpath <> abspath
path
1887 then adddoc path x
anchor c bookmarks c.lastvisit
1889 Buffer.add_string
bb "</llppconfig>\n";
1893 let save leavebirdseye
=
1894 let relx = float state.x
/. float state.winw
in
1896 let cx w = truncate
(relx *. float w) in
1898 (fun (w, h, x
) ws
->
1900 | Wsi.Fullscreen
-> (conf.cwinw
, conf.cwinh
, cx conf.cwinw
)
1901 | Wsi.MaxVert
-> (w, conf.cwinh
, x
)
1902 | Wsi.MaxHorz
-> (conf.cwinw
, h, cx conf.cwinw
)
1904 (state.winw
, state.winh
, state.x
) state.winstate
1908 let bb = Buffer.create
32768 in
1910 save1 bb leavebirdseye x
h dc
1912 if load1 save2 && Buffer.length
bb > 0
1915 let tmp = !confpath ^
".tmp" in
1916 let oc = open_out_bin
tmp in
1917 Buffer.output_buffer
oc bb;
1919 Unix.rename
tmp !confpath;
1922 ("error while saving configuration: " ^ exntos exn
)
1927 let n'
= Unix.write fdo
s 0 n in
1929 then Utils.error
"Unix.write %d = %d" n n'
1932 try Unix.read fdi
s 0 n
1933 with exn
-> Utils.error
"reading gc pipe %s" (exntos exn
) in
1934 let href = ref (Hashtbl.create
0) in
1935 let cref = ref defconf in
1937 let f path (pc, _pb
, _px
, _pa
) =
1939 Printf.sprintf
"%s\000%ld\000" path (Int32.of_float
pc.lastvisit
)
1941 wr s (String.length
s)
1946 Unix.shutdown fdo
Unix.SHUTDOWN_SEND
;
1949 ignore
(load1 push);
1951 let b = Buffer.create
32768 in
1952 let s = String.create
4096 in
1954 let n = rd s (String.length
s) in
1956 then Buffer.contents
b
1957 else (Buffer.add_substring
b s 0 n; f ())
1962 let zpos1 = try String.index_from
s ppos '
\000'
with Not_found
-> -1 in
1963 if zpos1 = -1 then ()
1966 try String.index_from
s (zpos1+1) '
\000'
with Not_found
-> -1 in
1967 if zpos2 = -1 then failwith
"moo2"
1969 let okey = StringLabels.sub
s ~pos
:ppos ~
len:(zpos1-ppos
) in
1970 let nkey = StringLabels.sub
s ~pos
:(zpos1+1) ~
len:(zpos2-zpos1-1) in
1972 then (Hashtbl.remove
!href okey; f (zpos2+1))
1975 try Hashtbl.find !href okey
1976 with Not_found
-> Utils.error
"gc: could not find %S" okey
1978 Hashtbl.remove
!href okey;
1979 Hashtbl.replace
!href nkey v;
1985 let bb = Buffer.create
32768 in
1986 let save2 (_h
, dc) = save1 bb (fun _ _ -> ()) 0 !href dc in
1987 if load1 save2 && Buffer.length
bb > 0
1990 let tmp = !confpath ^
".tmp" in
1991 let oc = open_out_bin
tmp in
1992 Buffer.output_buffer
oc bb;
1994 Unix.rename
tmp !confpath;
1997 ("error while saving configuration: " ^ exntos exn
)