]> matita.cs.unibo.it Git - helm.git/blob - matita/components/binaries/mac/mac.ml
lambdadelta
[helm.git] / matita / components / binaries / mac / mac.ml
1 (*
2     ||M||  This file is part of HELM, an Hypertextual, Electronic        
3     ||A||  Library of Mathematics, developed at the Computer Science     
4     ||T||  Department, University of Bologna, Italy.                     
5     ||I||                                                                
6     ||T||  HELM is free software; you can redistribute it and/or         
7     ||A||  modify it under the terms of the GNU General Public License   
8     \   /  version 2 or (at your option) any later version.      
9      \ /   This software is distributed as is, NO WARRANTY.     
10       V_______________________________________________________________ *)
11
12 module A = Arg
13 module P = Printf
14
15 module O = Options 
16 module L = Lexer
17
18 let help   = "Usage: mac [ -LXQV | -p <int> ]* [ <file> ]*"
19 let help_L = " Activate lexer debugging"
20 let help_Q = " Read data from standard input"
21 let help_V = " Show version information"
22 let help_X = " Reset options and counters"
23 let help_p = "<int> Assume <int> characters per page (default: 5120)"
24
25 let active = ref false
26
27 let process_channel ich =
28    let lexbuf = Lexing.from_channel ich in
29    L.token lexbuf; active := true
30
31 let output_version () =
32    P.printf "mac 0.1.1 M - July 2013\n"
33
34 let process_stdin () =
35    process_channel stdin
36
37 let process_file fname =
38    let ich = open_in fname in
39    process_channel ich; close_in ich
40
41 let set_page i =
42    if i > 0 then O.page := i
43
44 let output_count () =
45    if !active then
46       let pages = !O.count / !O.page in
47       let pages = if !O.count mod !O.page = 0 then pages else succ pages in
48       P.printf "%u %u\n" !O.count pages
49
50 let main () =
51    A.parse [
52       "-L", A.Set O.debug_lexer, help_L;
53       "-Q", Arg.Unit process_stdin, help_Q; 
54       "-V", Arg.Unit output_version, help_V; 
55       "-X", A.Unit O.clear, help_X;
56    ] process_file help;
57    output_count ()
58
59 let _ = main ()