From: Stefano Zacchiroli Date: Fri, 4 Feb 2005 13:58:53 +0000 (+0000) Subject: added gzip support to Xml X-Git-Tag: V_0_1_0~21 X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=commitdiff_plain;h=cdef799a0e2e3c7db8bb2b95cd124767a4126c61;p=helm.git added gzip support to Xml --- diff --git a/helm/ocaml/METAS/meta.helm-xml.src b/helm/ocaml/METAS/meta.helm-xml.src index 1cd68fed8..7330c766c 100644 --- a/helm/ocaml/METAS/meta.helm-xml.src +++ b/helm/ocaml/METAS/meta.helm-xml.src @@ -1,4 +1,4 @@ -requires="" +requires="zip" version="0.0.1" archive(byte)="xml.cma" archive(native)="xml.cmxa" diff --git a/helm/ocaml/xml/Makefile b/helm/ocaml/xml/Makefile index f6c43d228..41a7edaa4 100644 --- a/helm/ocaml/xml/Makefile +++ b/helm/ocaml/xml/Makefile @@ -1,5 +1,5 @@ PACKAGE = xml -REQUIRES = +REQUIRES = zip PREDICATES = INTERFACE_FILES = xml.mli diff --git a/helm/ocaml/xml/xml.ml b/helm/ocaml/xml/xml.ml index 9dcd16fc0..64c066a1e 100644 --- a/helm/ocaml/xml/xml.ml +++ b/helm/ocaml/xml/xml.ml @@ -101,6 +101,10 @@ let pp_to_outchan strm oc = flush oc ;; +let pp_to_gzipchan strm oc = + pp_gen (fun s -> Gzip.output oc s 0 (String.length s)) strm; + Gzip.flush oc + (** pretty printer to string *) let pp_to_string strm = let buf = Buffer.create 10240 in @@ -112,21 +116,27 @@ let pp_to_string strm = (* Usage: *) (* pp tokens None pretty prints the output on stdout *) (* pp tokens (Some filename) pretty prints the output on the file filename *) -let pp ?(quiet=false) strm fn = - match fn with - | Some filename -> - let outchan = open_out filename in - (try - pp_to_outchan strm outchan; - with e -> - close_out outchan; - raise e); - close_out outchan; - if not quiet then - begin - print_string ("\nWriting on file \"" ^ filename ^ - "\" was succesfull\n"); - flush stdout - end - | None -> pp_to_outchan strm stdout +let pp ?(gzip=false) strm fn = + if gzip then + match fn with + | Some filename -> + let outchan = Gzip.open_out filename in + (try + pp_to_gzipchan strm outchan; + with e -> + Gzip.close_out outchan; + raise e); + Gzip.close_out outchan + | None -> failwith "Can't sent gzipped output to stdout" + else + match fn with + | Some filename -> + let outchan = open_out filename in + (try + pp_to_outchan strm outchan; + with e -> + close_out outchan; + raise e); + close_out outchan + | None -> pp_to_outchan strm stdout ;; diff --git a/helm/ocaml/xml/xml.mli b/helm/ocaml/xml/xml.mli index a48e7d6b9..b1fcbe5b0 100644 --- a/helm/ocaml/xml/xml.mli +++ b/helm/ocaml/xml/xml.mli @@ -63,8 +63,9 @@ val xml_cdata : string -> token Stream.t (* The pretty printer for streams of token *) (* Usage: *) (* pp tokens None pretty prints the output on stdout *) -(* pp tokens (Some filename) pretty prints the output on the file filename *) -val pp : ?quiet:bool -> token Stream.t -> string option -> unit +(* pp tokens (Some filename) pretty prints the output on the file filename +* @param gzip if set to true files are gzipped. Defaults to false *) +val pp : ?gzip:bool -> token Stream.t -> string option -> unit val pp_to_outchan : token Stream.t -> out_channel -> unit val pp_to_string : token Stream.t -> string