forked from bcpierce00/unison
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocs.ml
65 lines (57 loc) · 1.66 KB
/
docs.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
open Printf
let main() = begin
(* The structure *)
set_binary_mode_out stdout true;
let ml = stdout in
fprintf ml "(* DO NOT MODIFY.\n\
\032 This file has been automatically generated, see docs.ml. *)\n\n";
(* Process the manual *)
let rec findFirstSNIP ch =
try
let l = input_line ch in
if l <> "----SNIP----" then findFirstSNIP ch
with
End_of_file ->
(Printf.printf "File does not contain ----SNIP----\n";
exit 1) in
let prsection ch =
let name = input_line ch in
let shortname = input_line ch in
if shortname <> "" then begin
let empty = input_line ch in
if empty<>"" then
(fprintf stderr "Second line after SNIP is '%s', not empty!\n" empty;
exit 1)
end;
fprintf ml " (\"%s\", (\"%s\", \n \"" shortname name;
let rec loop () =
let l = input_line ch in
if l<>"----SNIP----" then begin
for n=0 to (String.length l) - 1 do
let e =
if n=0 && l.[n]=' ' then "\\032"
else if l.[n]='"' then "\\\""
else if l.[n]='\'' then "'"
else if (Char.code l.[n])>=128 then sprintf "\\%d" (Char.code l.[n])
else Char.escaped l.[n] in
output_string ml e;
done;
fprintf ml "\\n\\\n ";
loop()
end in
(try loop() with End_of_file -> ());
fprintf ml "\"))\n::\n" in
let prmanual() =
fprintf ml "let docs =\n";
set_binary_mode_in stdin true;
let ch = stdin in
findFirstSNIP ch;
try
while true do prsection ch done
with End_of_file -> ();
fprintf ml " [];;\n\n" in
(* Docs *)
prmanual ();
end (* of main *);;
(*--------------------------------------------------------------------------*)
Printexc.catch main ();;