2 """dictd C5 format writer""" |
2 """dictd C5 format writer""" |
3 |
3 |
4 import io |
4 import io |
5 import sys |
5 import sys |
6 import codecs |
6 import codecs |
|
7 import regex |
7 |
8 |
8 import gadict |
9 import gadict |
9 |
10 |
10 |
11 |
11 FINAME = None |
12 FINAME = None |
12 FONAME = None |
13 FONAME = None |
13 if len(sys.argv) >= 2: |
|
14 FINAME = sys.argv[1] |
|
15 if len(sys.argv) >= 3: |
|
16 FONAME = sys.argv[2] |
|
17 LANGS = None |
14 LANGS = None |
18 if len(sys.argv) >= 4: |
15 |
19 LANGS = set(sys.argv[3].split(",")) |
16 # -lang:ru,uk |
|
17 ARG_LANG_RE = regex.compile("-lang:(.+)") |
|
18 # -freq:var:TAG=FILE or -freq:freq:TAG=FILE |
|
19 ARG_FREQ_RE = regex.compile("-freq:(freq|var):([^=]+)=(.+)") |
|
20 |
|
21 look_for_files = False |
|
22 for idx in range(1, len(sys.argv)): |
|
23 arg = sys.argv[idx] |
|
24 if arg == "--": |
|
25 look_for_files = True |
|
26 continue |
|
27 if not look_for_files: |
|
28 m = ARG_LANG_RE.match(arg) |
|
29 if m: |
|
30 LANGS = set(m.group(1).split(",")) |
|
31 for lang in LANGS: |
|
32 if len(lang) != 2: |
|
33 raise Exception("Incorrect language specification: '{:s}'".format(arg)) |
|
34 continue |
|
35 m = ARG_FREQ_RE.match(arg) |
|
36 if m: |
|
37 LANGS = set(arg.split(",")) |
|
38 for lang in LANGS: |
|
39 if len(lang) != 2: |
|
40 raise Exception("Incorrect language specification: '{:s}'".format(arg)) |
|
41 continue |
|
42 if arg.startswith("-"): |
|
43 raise Exception("Unsupported option format: '{:s}'".format(arg)) |
|
44 if not FINAME: |
|
45 FINAME = arg |
|
46 continue |
|
47 if not FONAME: |
|
48 FONAME = arg |
|
49 continue |
|
50 raise Exception("Unnecessary argument: '{:s}'".format(arg)) |
|
51 |
20 |
52 |
21 FIN = io.open(FINAME, mode='r', buffering=1, encoding="utf-8") |
53 FIN = io.open(FINAME, mode='r', buffering=1, encoding="utf-8") |
22 |
54 |
23 PARSER = gadict.Parser() |
55 PARSER = gadict.Parser() |
24 try: |
56 try: |