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