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/
30 (* Usage: make_table <hashtbls_dump_file> *)
33 let debug_print s = if debug then prerr_endline s
37 `Entities, "/usr/share/gtkmathview/entities-table.xml";
38 `Dictionary, "/usr/share/editex/dictionary-tex.xml"
40 `Entities, "macros/entities-table.xml";
41 `Dictionary, "macros/dictionary-tex.xml";
42 `Entities, "macros/extra-entities.xml";
45 let macro2utf8 = Hashtbl.create 2000
46 let utf82macro = Hashtbl.create 2000
48 let add_macro macro utf8 =
49 debug_print (sprintf "Adding macro %s = '%s'" macro utf8);
50 Hashtbl.add macro2utf8 macro utf8;
51 Hashtbl.add utf82macro utf8 macro
53 let rec find_first_tag pull_parser =
54 match pull_parser () with
55 | Some (E_start_tag _ as e) -> e
56 | None -> assert false
57 | _ -> find_first_tag pull_parser
59 let iter_entities_file f pull_parser =
60 ignore (find_first_tag pull_parser); (* <entities-table> *)
62 match pull_parser () with
63 | Some (E_start_tag ("entity", attrs, _)) ->
65 let name = List.assoc "name" attrs in
66 let value = List.assoc "value" attrs in
68 with Not_found -> ());
75 let iter_dictionary_file f pull_parser =
76 ignore (find_first_tag pull_parser); (* <dictionary> *)
78 match pull_parser () with
79 | Some (E_start_tag ("entry", attrs, _)) ->
81 let name = List.assoc "name" attrs in
82 let value = List.assoc "val" attrs in
84 with Not_found -> ());
94 let entry = `Entry_document [ `Extend_dtd_fully; `Parse_xml_decl ] in
95 let config = { default_config with encoding = `Enc_utf8 } in
97 create_entity_manager ~is_document:true config (from_file fname)
99 let pull_parser = create_pull_parser config entry entity_manager in
101 | `Entities -> iter_entities_file add_macro pull_parser
102 | `Dictionary -> iter_dictionary_file add_macro pull_parser)
106 let oc = open_out Sys.argv.(1) in
108 Marshal.to_channel oc (macro2utf8, utf82macro) [];