Avoid doing extra work
[llpp/slowscroll.git] / keystoml.ml
blob94dfadfd5ec3421a1090ae8897af4dd3a6f5fccb
1 open Printf
3 let r_dash = Str.regexp " - ";;
4 let tabify s =
5 let dashpos = try Str.search_forward r_dash s 0 with Not_found -> -1 in
6 if dashpos < 1
7 then
9 else
10 let rec findnonwsback i =
11 if i = -1 then 0 else
12 if s.[i] = ' '
13 then findnonwsback (i-1)
14 else i
16 let nonwspos = findnonwsback dashpos in
17 if nonwspos = -1
18 then s
19 else
20 let b = Buffer.create 80 in
21 Buffer.add_substring b s 0 (nonwspos+1);
22 Buffer.add_string b "\t";
23 Buffer.add_substring b s dashpos (String.length s - dashpos);
24 Buffer.contents b
27 let lines =
28 let lines =
29 match (try Some (open_in Sys.argv.(1)) with _ -> None) with
30 | None -> []
31 | Some ic ->
32 let lines =
33 let rec fold accu =
34 match (try Some (input_line ic) with _ -> None) with
35 | Some line -> fold (tabify line :: accu)
36 | None -> List.rev accu
38 fold []
40 close_in ic;
41 lines
43 lines;
46 let _ =
47 printf "let keys = [\n";
48 List.iter (fun l -> printf " %S;\n" l) lines;
49 printf "];;\n"