-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdsl2txt.rb
52 lines (45 loc) · 1.22 KB
/
dsl2txt.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require 'optparse'
require 'fileutils'
require File.expand_path('../lib/Dictionary', __FILE__)
require File.expand_path('../lib/Card', __FILE__)
require File.expand_path('../lib/TxtDictionary', __FILE__)
require File.expand_path('../lib/transliteration', __FILE__)
$IN = ""
$OUT = ""
$separotor = nil
opts = OptionParser.new
opts.on("-i FILE", "--in FILE", "input DSL file to convert", String) {|val| $IN = val }
opts.on("-o DIR", "--out DIR", "directory to extract txt files", String) { |val|
if ($OUT.empty?)
$OUT = val
else
$stderr.puts "Error: output directory can be defined only once!\n\n"
$stderr.puts opts
exit
end
}
opts.on_tail("-h", "--help", "Show this message") do
$stderr.puts opts
exit
end
rest = opts.parse(ARGV)
if ($IN.size == 0 || $OUT.size == 0)
$stderr.puts opts
exit
end
if File.exist?($OUT)
$stderr.puts "WARNING: Output directory already exists: '#{$OUT}'"
# exit
else
$stderr.puts "Creating output directory: '#{$OUT}'"
Dir.mkdir($OUT)
end
# load the DSL dictionary
d = nil
File.open($IN, 'rb') { |f|
d = Dictionary.load_from_dsl(f)
}
d.get_txt_dicts.each { |dict|
# dict.print_out("CON")
dict.extract_to_dir($OUT)
}