Merge pull request #4 from He-Ro/minor-fixes
[llpp.git] / keystoml.ml
blob555f95220cd96744a2cda078216676798d9cb3cb
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
8 let l = String.length s in
9 if l > 11 && String.sub s 0 5 = "-----"
10 then
11 "\xc2\xb7" ^ String.sub s 5 (l - 10)
12 else
14 else
15 let rec findnonwsback i =
16 if i = -1 then 0 else
17 if s.[i] = ' '
18 then findnonwsback (i-1)
19 else i
21 let nonwspos = findnonwsback dashpos in
22 if nonwspos = -1
23 then s
24 else
25 let b = Buffer.create 80 in
26 Buffer.add_substring b s 0 (nonwspos+1);
27 Buffer.add_char b '\t';
28 Buffer.add_substring b s (dashpos+1) (String.length s - dashpos - 1);
29 Buffer.contents b
32 let lines =
33 let lines =
34 let rec fold accu =
35 match (try Some (input_line stdin) with _ -> None) with
36 | Some line -> fold (tabify line :: accu)
37 | None -> List.rev accu
39 fold []
41 lines
44 let _ =
45 printf "let keys = [\n";
46 List.iter (fun l -> printf " %S;\n" l) lines;
47 printf "];;\n"