1 #!/usr/bin/ocamlrun /usr/bin/ocaml
4 * Stefano Zacchiroli <zack@cs.unibo.it>
5 * for the HELM Team http://helm.cs.unibo.it/
7 * This file is part of HELM, an Hypertextual, Electronic
8 * Library of Mathematics, developed at the Computer Science
9 * Department, University of Bologna, Italy.
11 * HELM is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * HELM is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with HELM; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
26 * For details, see the HELM World-Wide-Web page,
27 * http://helm.cs.unibo.it/
38 let index = "INDEX.xml" ;;
39 let template = "hbugs_tutor.TPL.ml" ;;
41 (* apply a set of regexp substitutions specified as a list of pairs
42 <pattern,template> to a string *)
43 let rec apply_subst ~fill s =
46 | (pat, templ)::rest ->
47 apply_subst ~fill:rest (Pcre.replace ~pat ~templ s)
49 (* fill a ~template file with substitutions specified in ~fill (see
50 apply_subst) and save output to ~output *)
51 let fill_template ~template ~fill ~output =
52 printf "Creating %s ... " output; flush stdout;
53 let (ic, oc) = (open_in template, open_out output) in
54 let rec fill_template' () =
55 output_string oc ((apply_subst ~fill (input_line ic)) ^ "\n");
59 output_string oc (sprintf
61 THIS CODE IS GENERATED - DO NOT MODIFY!
63 the source of this code is template \"%s\"
64 the template was filled with data read from \"%s\"
71 printf "done!\n"; flush stdout
74 parse_wfdocument_entity default_config (from_file fname) default_spec
77 match node#node_type with T_element "tutor" -> true | _ -> false
80 match node#node_type with T_element _ -> true | _ -> false
84 (parse_xml index)#root#iter_nodes
88 | node when is_tutor node ->
89 (try (* skip hand-written tutors *)
90 ignore (find_element "no_auto" node);
92 with Not_found -> ());
95 (match node#attribute "source" with
98 with Not_found -> assert false
101 List.map (* create substitution list from index data *)
103 let name = (* node name *)
104 (match node#node_type with
108 let value = node#data in (* node value *)
109 (sprintf "@%s@" (String.uppercase name), (* pattern *)
110 value)) (* substitution *)
111 (List.filter is_element node#sub_nodes)
113 fill_template ~fill ~template ~output