1 (* Copyright (C) 2000, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://cs.unibo.it/helm/.
26 module R = Helm_registry
43 requires: (string * string) list;
47 let default_script = {
48 name = ""; contents = []
51 let default_scripts = 2
53 let load_registry registry =
54 let suffix = ".conf.xml" in
56 if Filename.check_suffix registry suffix then registry
57 else registry ^ suffix
59 Printf.eprintf "reading configuration %s ...\n" registry; flush stderr;
63 let eof ich = try Some (input_line ich) with End_of_file -> None in
64 let trim l = Filename.chop_extension (Str.string_after l 2) in
65 let cmd = Printf.sprintf "cd %s && find -name *%s" st.input_path st.script_ext in
66 let ich = Unix.open_process_in cmd in
69 | None -> List.rev files
70 | Some l -> aux (trim l :: files)
73 let _ = Unix.close_process_in ich in
74 {st with files = files}
77 let map file = (Filename.basename file, file) in
78 let requires = List.rev_map map st.files in
79 {st with requires = requires}
82 let default_registry = "transcript" in
83 load_registry default_registry
86 load_registry registry;
88 helm_dir = R.get_string "transcript.helm_dir";
89 heading_path = R.get_string "transcript.heading_path";
90 heading_lines = R.get_int "transcript.heading_lines";
91 package = R.get_string "package.name";
92 base_uri = R.get_string "package.base_uri";
93 input_path = R.get_string "package.input_path";
94 output_path = R.get_string "package.output_path";
95 script_ext = R.get_string "package.script_type";
98 scripts = Array.make default_scripts default_script
100 prerr_endline "reading file names ...";
101 let st = set_files st in
102 let st = set_requires st in
105 let get_index st name =
106 let rec get_index name i =
107 if i >= Array.length st.scripts then None else
108 if st.scripts.(i).name = name then Some i else
109 get_index name (succ i)
111 match get_index name 0, get_index "" 0 with
112 | Some i, _ | _, Some i -> i
113 | None, None -> failwith "not enought script entries"
115 let set_items st name items =
116 let i = get_index st name in
117 let script = st.scripts.(i) in
118 let contents = List.rev_append items script.contents in
119 st.scripts.(i) <- {name = name; contents = contents}
121 let set_heading st name =
122 let heading = Filename.concat st.helm_dir st.heading_path, st.heading_lines in
123 set_items st name [Types.Heading heading]
125 let set_baseuri st name =
126 let baseuri = Filename.concat st.base_uri name in
127 set_items st name [Types.BaseUri baseuri]
130 let i = get_index st name in
131 let script = st.scripts.(i) in
132 let path = Filename.concat st.output_path (Filename.dirname name) in
133 let name = Filename.concat st.output_path (name ^ ".ma") in
134 let cmd = Printf.sprintf "mkdir -p %s" path in
135 let _ = Sys.command cmd in
136 let och = open_out name in
137 Grafite.commit och script.contents;
139 st.scripts.(i) <- default_script
142 let init name = set_heading st name; set_baseuri st name in
143 let produce st name =
144 Printf.eprintf "processing file name: %s ...\n" name; flush stderr;
145 let file = Filename.concat st.input_path (name ^ st.script_ext) in
146 let ich = open_in file in
147 let lexbuf = Lexing.from_channel ich in
149 let items = V8Parser.items V8Lexer.token lexbuf in
151 init name; set_items st name items; commit st name
153 prerr_endline (Printexc.to_string e); close_in ich
155 init st.package; List.iter (produce st) st.files; commit st st.package