-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreplace-glyph.rb
executable file
·39 lines (35 loc) · 1.04 KB
/
replace-glyph.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
#!/usr/bin/env ruby
require 'optparse'
require 'csv'
replaceGlyphs = {}
ignoreVersion = false
opt = OptionParser.new
opt.banner = "Usage: #{$0} [options] [filename...]"
opt.separator ""
opt.separator "Options:"
opt.on("-l", "--list-file=FILENAME", "Replacement list file (must be tab-separated, may be specified more than once)") { |val|
replaceList = CSV.read(val, col_sep: "\t")
for glyph in replaceList
replaceGlyphs[glyph[0]] = {
'glyph' => glyph[1],
'pos' => glyph[2..5].join(":"),
}
end
}
opt.on("-i", "--ignore-version", "Ignore glyph version") {
ignoreVersion = true
}
opt.on_tail("-h", "--help", "Show this message") {puts opt; exit}
opt.parse!(ARGV)
while l = gets
l.chomp!
csvDat = CSV.parse(l, col_sep: "\t")
glyphName = CSV.parse(l, col_sep: "\t")[0][0]
glyphName2 = glyphName.dup
if ignoreVersion then glyphName2.gsub!(/\@\d+/, "") end
if replaceGlyphs.include?(glyphName2) then
print "#{glyphName}\t99:0:0:#{replaceGlyphs[glyphName2]['pos']}:#{replaceGlyphs[glyphName2]['glyph']}:0:0:0\n"
else
print "#{l}\n"
end
end