8 module TU = TextUnparser
13 module XU = XmlUnparser
15 let help = "Usage: xhtbl [ -LX | -O <dir> | -d0 | -d1 | -d2 | -e1 | -e2 | -p0 | -p1 | -p2 | <file> ]*"
16 let help_L = " Output lexer tokens"
17 let help_O = "<dir> Set this output directory"
18 let help_X = " Clear all options"
19 let help_d0 = " Output table contents after phase zero (parsing)"
20 let help_d1 = " Output table contents after phase one (sizing)"
21 let help_d2 = " Output table contents after phase two (filling)"
22 let help_e1 = " Disabled"
23 let help_e2 = " Output debug information during phase two (filling)"
24 let help_p0 = " Process until phase zero (parsing)"
25 let help_p1 = " Process until phase one (sizing)"
26 let help_p2 = " Process until phase two (filling)"
30 let includes, tables = ref [], ref []
32 let set_output_dir s = O.output_dir := s
34 let process_directive och bname (name, table, css) =
35 tables := name :: !tables;
36 if !O.d0 then TU.debug table;
37 if not !O.p0 then begin
38 let size = P1.process table in
39 if !O.d1 then TU.debug table;
40 if not !O.p1 then begin
41 let matrix = M.make size in
42 let _ = P2.process table matrix in
43 if !O.d2 then TU.debug table;
44 if not !O.p2 then P3.process css matrix;
45 let name = if name = "" then bname else name in
46 XU.output och name matrix
50 let process_file fname =
51 let bname = F.chop_extension (F.basename fname) in
52 let ich = open_in fname in
53 let lexbuf = Lexing.from_channel ich in
54 let ns, ds = TP.script TL.token lexbuf in
55 close_in ich; includes := bname :: !includes;
56 let ns = ("", "http://www.w3.org/1999/xhtml") :: ns in
57 let och = XU.open_out bname ns in
58 L.iter (process_directive och bname) ds;
63 "-L", A.Set O.debug_lexer, help_L;
64 "-O", A.String set_output_dir, help_O;
65 "-X", A.Unit O.clear, help_X;
66 "-d0", A.Set O.d0, help_d0;
67 "-d1", A.Set O.d1, help_d1;
68 "-d2", A.Set O.d2, help_d2;
69 "-e1", A.Set O.e1, help_e1;
70 "-e2", A.Set O.e2, help_e2;
71 "-p0", A.Set O.p0, help_p0;
72 "-p1", A.Set O.p1, help_p1;
73 "-p2", A.Set O.p2, help_p2;
75 XU.write_hook hook !includes !tables