| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
let copy src dst = |
| 12 |
let cin = open_in src in |
| 13 |
try |
| 14 |
let cout = open_out dst in |
| 15 |
try |
| 16 |
while true do |
| 17 |
output_char cout (input_char cin) |
| 18 |
done |
| 19 |
with End_of_file -> close_out cout; close_in cin |
| 20 |
with Sys_error e -> Printf.eprintf "%s\n" e; exit 1 |
| 21 |
|
| 22 |
let check_if_file_exists f = |
| 23 |
if not (Sys.file_exists f) then begin |
| 24 |
Printf.eprintf "coqdoc: %s: no such file\n" f; |
| 25 |
exit 1 |
| 26 |
end |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
let files_from_file f = |
| 32 |
let files_from_channel ch = |
| 33 |
let buf = Buffer.create 80 in |
| 34 |
let l = ref [] in |
| 35 |
try |
| 36 |
while true do |
| 37 |
match input_char ch with |
| 38 |
| ' ' | '\t' | '\n' -> |
| 39 |
if Buffer.length buf > 0 then l := Buffer.contents buf :: !l; |
| 40 |
Buffer.clear buf |
| 41 |
| c -> Buffer.add_char buf c |
| 42 |
done; |
| 43 |
[] |
| 44 |
with End_of_file -> List.rev !l |
| 45 |
in |
| 46 |
try |
| 47 |
check_if_file_exists f; |
| 48 |
let ch = open_in f in |
| 49 |
let l = files_from_channel ch in |
| 50 |
close_in ch; l |
| 51 |
with Sys_error s -> |
| 52 |
Printf.eprintf "coqdoc: cannot read from file %s (%s)\n" f s; |
| 53 |
exit 1 |