main()
click to toggle source
# File ripper/tools/generate.rb, line 5 def main mode = nil ids1src = nil ids2src = nil output = nil parser = @parser = OptionParser.new parser.banner = "Usage: #{File.basename($0)} --mode=MODE [--ids1src=PATH] [--ids2src=PATH] [--output=PATH]" parser.on('--mode=MODE', 'check, eventids1, or eventids2table.') {|m| mode = m } parser.on('--ids1src=PATH', 'A source file of event-IDs 1 (parse.y).') {|path| ids1src = path } parser.on('--ids2src=PATH', 'A source file of event-IDs 2 (eventids2.c).') {|path| ids2src = path } parser.on('--output=PATH', 'An output file.') {|path| output = path } parser.on('--help', 'Prints this message and quit.') { puts parser.help exit true } begin parser.parse! rescue OptionParser::ParseError => err usage err.message end usage 'no mode given' unless mode case mode when 'check' usage 'no --ids1src' unless ids1src usage 'no --ids2src' unless ids2src h = read_ids1_with_locations(ids1src) check_arity h ids2 = read_ids2(ids2src) common = h.keys & ids2 unless common.empty? abort "event crash: #{common.join(' ')}" end exit 0 when 'eventids1' usage 'no --ids1src' unless ids1src result = generate_eventids1(read_ids1(ids1src)) when 'eventids2table' usage 'no --ids2src' unless ids2src result = generate_eventids2_table(read_ids2(ids2src)) end if output File.open(output, 'w') {|f| f.write result } else puts result end end