]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambdadelta/hls.ml
update in basic_2
[helm.git] / matita / matita / contribs / lambdadelta / hls.ml
1 let cols =
2    try int_of_string (Sys.getenv "COLUMNS")
3    with Not_found -> failwith "environment variable COLUMNS not visible"
4
5 let hl = ref []
6
7 let normal = "\x1B[0m"
8
9 let color = "\x1B[32m"
10
11 let add s =
12    if s = "" then false else
13    begin hl := s :: !hl; true end
14
15 let rec read ich =
16    if Scanf.fscanf ich "%s " add then read ich
17
18 let length l s = max l (String.length s)
19
20 let split s =
21 try 
22    let i = String.rindex s '.' in
23    if i = 0 then s, "" else
24    String.sub s 0 i, String.sub s i (String.length s - i)    
25 with Not_found -> s, ""
26
27 let compare s1 s2 =
28    let n1, e1 = split s1 in
29    let n2, e2 = split s2 in
30    let e = String.compare e1 e2 in
31    if e = 0 then String.compare n1 n2 else e
32
33 let write l c s =
34    let pre, post = if List.mem s !hl then color, normal else "", "" in
35    let spc = String.make (l - String.length s) ' ' in
36    let bol, ret =
37        if c = 0 || c = cols then "", l else
38        if c + l < cols then " ", c + succ l else "\n", l
39    in
40    Printf.printf "%s%s%s%s%s" bol pre s post spc;
41    ret
42
43 let process fname =
44    let ich = open_in fname in
45    read ich; close_in ich
46
47 let help = ""
48
49 let main =
50    Arg.parse [] process help;
51    let files = Sys.readdir "." in
52    let l = Array.fold_left length 0 files in
53    if cols < l then failwith "window too small";
54    Array.fast_sort compare files;
55    let c = Array.fold_left (write l) 0 files in
56    if 0 < c && c < cols then print_newline ();
57