2 try int_of_string (Sys.getenv "COLUMNS")
3 with Not_found -> failwith "environment variable COLUMNS not visible"
12 if s = "" then false else
13 begin hl := s :: !hl; true end
16 if Scanf.fscanf ich "%s " add then read ich
18 let length l s = max l (String.length s)
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, ""
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
34 let pre, post = if List.mem s !hl then color, normal else "", "" in
35 let spc = String.make (l - String.length s) ' ' in
37 if c = 0 || c = cols then "", l else
38 if c + l < cols then " ", c + succ l else "\n", l
40 Printf.printf "%s%s%s%s%s" bol pre s post spc;
44 let ich = open_in fname in
45 read ich; close_in ich
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 ();