Make throttled scrolling again and make preloading more robust
[llpp.git] / convert.ml
blob8b5028e375fdc06c342839581ffe2dec93a3986e
1 open Format;;
3 let enent s pos len =
4 let b = Buffer.create len in
5 let rec loop i =
6 if i - pos = len
7 then Buffer.contents b
8 else (
9 begin match s.[i] with
10 | '<' -> Buffer.add_string b "&lt;"
11 | '>' -> Buffer.add_string b "&gt;"
12 | '\'' -> Buffer.add_string b "&apos;"
13 | '"' -> Buffer.add_string b "&quot;"
14 | '&' -> Buffer.add_string b "&amp;"
15 | c ->
16 let code = Char.code c in
17 if code = 0 || code > 0x7f
18 then (
19 Buffer.add_string b "&#";
20 Buffer.add_string b (string_of_int code);
21 Buffer.add_char b ';';
23 else Buffer.add_char b c
24 end;
25 loop (i+1)
28 loop pos
31 let main statepath =
32 let hash =
33 try
34 let ic = open_in_bin statepath in
35 let hash = input_value ic in
36 close_in ic;
37 hash
38 with exn ->
39 if false
40 then
41 prerr_endline ("Error loading state " ^ Printexc.to_string exn)
43 Hashtbl.create 1
45 print_endline "<llppconfig>";
46 Hashtbl.iter (fun path (bookmarks, w, h) ->
47 if false
48 then (
49 printf "<doc width=\"%d\" height=\"%d\">\n"
50 w h
52 printf " <![CDATA[%s]]>\n" path;
54 else (
55 printf "<doc path=\"%s\" width=\"%d\" height=\"%d\">\n"
56 (enent path 0 (String.length path)) w h
60 if bookmarks <> []
61 then (
62 printf " <bookmarks>\n";
64 List.iter (fun (title, level, page, rely) ->
65 printf
66 (* " <bookmark page=\"%d\" rely=\"%f\"><![CDATA[%s]]></bookmark>\n" *)
67 " <item title=\"%s\" page=\"%d\" rely=\"%f\"/>\n"
68 title page rely) bookmarks;
69 printf " </bookmarks>";
71 printf "</doc>\n@.";
72 ) hash;
73 print_endline "</llppconfig>";
76 let _ = main Sys.argv.(1);;