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