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://www.cs.unibo.it/helm/.
26 (* AUTOR: Ferruccio Guidi <fguidi@cs.unibo.it>
31 module type Type = sig
35 val start : string -> bool -> handle
37 val stop : handle -> unit
39 val next : handle -> T.xml_object
41 val xnext : handle -> handle * T.xml_xobject
43 val scan_for : handle -> T.xml_xobject -> handle
47 module Make : Type = struct
53 type mode_t = Text of in_channel * Lexing.lexbuf
54 | GZip of Gzip.in_channel * Lexing.lexbuf
56 type handle = {mode : mode_t; level : int}
59 let gread gch s n = Gzip.input gch s 0 n in
61 let gch = Gzip.open_in (s ^ ".gz") in
62 let glb = Lexing.from_function (gread gch) in
63 {mode = GZip (gch, glb); level = 0}
66 let lb = Lexing.from_channel ch in
67 {mode = Text (ch, lb); level = 0}
70 | {mode = GZip (gch, _)} -> Gzip.close_in gch
71 | {mode = Text (ch, _)} -> close_in ch
74 let lexbuf = match h.mode with
75 | GZip (_, glb) -> glb
78 P.xml L.xml_token lexbuf
83 | T.XML_Open _ -> {h with level = succ h.level}, (obj, h.level)
84 | T.XML_Close _ -> {h with level = pred h.level}, (obj, pred h.level)
85 | _ -> h, (obj, h.level)
87 let rec scan_for h xobj =
88 let h, curr_xobj = xnext h in
89 if curr_xobj = xobj then h else scan_for h xobj