]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/pxp/pxp/examples/readme/main.ml
Initial revision
[helm.git] / helm / DEVEL / pxp / pxp / examples / readme / main.ml
1 (* $Id$
2  * ----------------------------------------------------------------------
3  *
4  *)
5
6 open Pxp_types
7 open Pxp_document
8 open Pxp_yacc
9
10
11 let rec print_error e =
12   prerr_endline(string_of_exn e)
13 ;;
14
15
16 let run f a =
17   try f a with
18       e -> print_error e
19 ;;
20
21
22 let convert_to_html filename =
23   (* read in style definition *)
24   let document =
25     parse_document_entity
26       { default_config with encoding = `Enc_iso88591 }
27       (from_file filename)
28       To_html.tag_map
29   in
30   let root = document # root in
31   let store = new To_html.store in
32   root # extension # to_html store stdout
33 ;;
34
35
36 let convert_to_text filename =
37   (* read in style definition *)
38   let document =
39     parse_document_entity
40       default_config
41       (from_file filename)
42       To_text.tag_map
43   in
44   let root = document # root in
45   let store = new To_text.store in
46   let box = new To_text.box 79 79 in
47   root # extension # to_box store box;
48   box # output 0 0 stdout
49 ;;
50
51
52 let main() =
53   let want_html = ref false in
54   let want_text = ref false in
55   let filename = ref None in
56   Arg.parse
57       [ "-html", Arg.Set want_html, 
58               "  convert file to html";
59         "-text", Arg.Set want_text,
60               "  convert file to text";
61       ]
62       (fun s -> 
63          match !filename with
64              None -> filename := Some s
65            | Some _ ->
66                raise (Arg.Bad "Multiple arguments not allowed."))
67       "usage: readme [ -text | -html ] input.xml >output";
68   let fn =
69     match !filename with
70         None -> 
71           prerr_endline "readme: no input";
72           exit 1
73       | Some s -> s
74   in
75   match !want_html, !want_text with
76       true, false ->
77         run convert_to_html fn
78     | false, true ->
79         run convert_to_text fn
80     | _ ->
81         prerr_endline ("readme: Please select exactly one output format")
82 ;;
83
84 main();;
85
86 (* ======================================================================
87  * History:
88  *
89  * $Log$
90  * Revision 1.1  2000/11/17 09:57:31  lpadovan
91  * Initial revision
92  *
93  * Revision 1.5  2000/07/08 17:58:17  gerd
94  *      Updated because of PXP API changes.
95  *
96  * Revision 1.4  2000/06/04 20:25:38  gerd
97  *      Updates because of renamed PXP modules.
98  *
99  * Revision 1.3  2000/05/01 16:46:40  gerd
100  *      Using the new error formatter.
101  *
102  * Revision 1.2  1999/08/23 16:54:19  gerd
103  *      Minor changes.
104  *
105  * Revision 1.1  1999/08/22 22:29:32  gerd
106  *      Initial revision.
107  *
108  *)