Debian Codegraph @

tools/coqdoc/fileUtil.ml

raw symbols SCIP
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
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 (* [files_from_file f] returns the list of file names contained in the
29 file named [f]. These file names must be separated by spaces,
30 tabulations or newlines. *)
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