1 (* Copyright (C) 2004, 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://helm.cs.unibo.it/
31 let debug_print s = if debug then prerr_endline s
33 (* source files for tables xml parsing (if unmarshall=false) *)
36 `Entities, "/usr/share/gtkmathview/entities-table.xml";
37 `Dictionary, "/usr/share/editex/dictionary-tex.xml"
39 `Entities, "data/entities-table.xml";
40 `Dictionary, "data/dictionary-tex.xml";
41 `Entities, "data/extra-entities.xml";
45 let rec find_first_tag pull_parser =
46 match pull_parser () with
47 | Some (E_start_tag _ as e) -> e
48 | None -> assert false
49 | _ -> find_first_tag pull_parser
51 let iter_entities_file f pull_parser =
52 ignore (find_first_tag pull_parser); (* <entities-table> *)
54 match pull_parser () with
55 | Some (E_start_tag ("entity", attrs, _, _)) ->
57 let name = List.assoc "name" attrs in
58 let value = List.assoc "value" attrs in
60 with Not_found -> ());
67 let iter_dictionary_file f pull_parser =
68 ignore (find_first_tag pull_parser); (* <dictionary> *)
70 match pull_parser () with
71 | Some (E_start_tag ("entry", attrs, _, _)) ->
73 let name = List.assoc "name" attrs in
74 let value = List.assoc "val" attrs in
76 with Not_found -> ());
83 let parse_from_xml () =
84 let (macro2utf8, utf82macro) = (Hashtbl.create 2000, Hashtbl.create 2000) in
85 let add_macro macro utf8 =
86 debug_print (sprintf "Adding macro %s = '%s'" macro utf8);
87 Hashtbl.add macro2utf8 macro utf8;
88 (* Hashtbl.add utf82macro utf8 macro *)
93 let entry = `Entry_document [ `Extend_dtd_fully; `Parse_xml_decl ] in
94 let config = PxpHelmConf.pxp_config in
96 create_entity_manager ~is_document:true config (from_file fname)
98 let pull_parser = create_pull_parser config entry entity_manager in
100 | `Entities -> iter_entities_file add_macro pull_parser
101 | `Dictionary -> iter_dictionary_file add_macro pull_parser)
108 let oc = open_out Sys.argv.(1) in
109 output_string oc "(* GENERATED by make_table: DO NOT EDIT! *)\n";
110 output_string oc "let macro2utf8 = Hashtbl.create 2000\n";
111 let macro2utf8 = parse_from_xml () in
114 fprintf oc "let _ = Hashtbl.add macro2utf8 \"%s\" \"%s\"\n"
115 macro (String.escaped utf8))