1 #!/usr/bin/ocamlrun /usr/bin/ocaml
3 * Copyright (C) 2003-2004:
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 = "data/tutors_index.xml"
39 let template = "data/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)
48 (* fill a ~template file with substitutions specified in ~fill (see
49 apply_subst) and save output to ~output *)
50 let fill_template ~template ~fill ~output =
51 printf "Creating %s ... " output; flush stdout;
52 let (ic, oc) = (open_in template, open_out output) in
53 let rec fill_template' () =
54 output_string oc ((apply_subst ~fill (input_line ic)) ^ "\n");
58 output_string oc (sprintf
60 THIS CODE IS GENERATED - DO NOT MODIFY!
62 the source of this code is template \"%s\"
63 the template was filled with data read from \"%s\"
70 printf "done!\n"; flush stdout
72 parse_wfdocument_entity default_config (from_file fname) default_spec
74 match node#node_type with T_element "tutor" -> true | _ -> false
76 match node#node_type with T_element _ -> true | _ -> false
78 (parse_xml index)#root#iter_nodes
82 | node when is_tutor node ->
83 (try (* skip hand-written tutors *)
84 ignore (find_element "no_auto" node);
86 with Not_found -> ());
89 (match node#attribute "source" with
92 with Not_found -> assert false
95 List.map (* create substitution list from index data *)
97 let name = (* node name *)
98 (match node#node_type with
102 let value = node#data in (* node value *)
103 (sprintf "@%s@" (String.uppercase name), (* pattern *)
104 value)) (* substitution *)
105 (List.filter is_element node#sub_nodes)
107 fill_template ~fill ~template ~output