~ubuntu-branches/ubuntu/lucid/camomile/lucid

« back to all changes in this revision

Viewing changes to tools/parse_uniset.ml

  • Committer: Bazaar Package Importer
  • Author(s): Sylvain Le Gall
  • Date: 2005-12-03 01:18:55 UTC
  • Revision ID: james.westby@ubuntu.com-20051203011855-qzvwlld1xyqnl62t
Tags: upstream-0.6.3
ImportĀ upstreamĀ versionĀ 0.6.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(* $Id: parse_uniset.ml,v 1.10 2003/12/19 17:24:34 yori Exp $ *)
 
2
(* Copyright 2002 Yamagata Yoriyuki. distributed with LGPL *)
 
3
 
 
4
let tbl_rw = ref USet.empty
 
5
 
 
6
(* remove comments *)
 
7
let range_pat = Str.regexp "\\([0-9A-Fa-f]+\\)\\.\\.\\([0-9A-Fa-f]+\\)"
 
8
let num_pat = Str.regexp "[0-9A-Za-z]+"
 
9
 
 
10
(* let get_line () =
 
11
  let s = read_line () in
 
12
  if Str.string_match line_pat s 0 then Str.matched_group 1 s else s *)
 
13
 
 
14
let prev_entry = ref 0
 
15
 
 
16
let read_data () =
 
17
  try while true do
 
18
    let s = read_line () in
 
19
    if Str.string_match range_pat s 0 then
 
20
      let u1 = UChar.chr_of_uint (int_of_string ("0x"^(Str.matched_group 1 s))) in
 
21
      let u2 = UChar.chr_of_uint (int_of_string ("0x"^(Str.matched_group 2 s))) in
 
22
      tbl_rw := USet.add_range u1 u2 !tbl_rw
 
23
    else if Str.string_match num_pat s 0 then
 
24
      let u = UChar.chr_of_uint (int_of_string ("0x"^(Str.matched_string s))) in
 
25
      tbl_rw := USet.add u !tbl_rw
 
26
    else ()
 
27
  done with End_of_file -> ()
 
28
 
 
29
let main () =
 
30
  read_data ();
 
31
  let dir, name =
 
32
    let dir = ref None in
 
33
    let name = ref None in
 
34
    Arg.parse [] (fun s ->
 
35
      match !dir with
 
36
        None -> dir := Some s;
 
37
      | Some _ -> 
 
38
          if !name = None then name := Some s else
 
39
          raise (Arg.Bad "Too many arguments"))
 
40
      "Parse unicode lists";
 
41
    match !dir, !name with
 
42
      (Some dir, Some name) -> dir, name
 
43
    | _ -> raise (Arg.Bad "Some arguments are missing.") in
 
44
  let c = open_out_bin (Filename.concat dir (name ^ "_set.mar")) in
 
45
  output_value c !tbl_rw;
 
46
  close_out c;
 
47
  let c = open_out_bin (Filename.concat dir (name ^ ".mar")) in
 
48
  let tbl = UCharTbl.Bool.of_set !tbl_rw in
 
49
  output_value c tbl;
 
50
  close_out c 
 
51
  
 
52
let _ = main ()