-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathksv
executable file
·65 lines (52 loc) · 1.92 KB
/
ksv
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
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'optparse'
# Some additional magic to make it work right after repo checkout,
# without installation to proper Ruby library dirs
# See `bin/ksdump` for more comments
script_dir = __dir__
unless script_dir.nil? || script_dir == '.'
$LOAD_PATH << File.expand_path('../lib', script_dir)
$LOAD_PATH << File.expand_path('../../runtime/ruby/lib', script_dir)
end
require 'kaitai/struct/visualizer'
# ======================================================================
options = {}
parser = OptionParser.new do |opts|
opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} [options] <file_to_parse.bin> <format.ksy>...|<format.rb>"
opts.separator ''
opts.on('-I', '--import-path [DIRECTORIES]', '.ksy library search path(s) for imports (see also KSPATH env variable)') do |v|
options[:import_path] = v
end
opts.on('--opaque-types [BOOLEAN]', 'opaque types allowed, default: false') do |v|
options[:opaque_types] = v
end
opts.on('-r', '--require [PATH]', 'load ("require") .rb file into Ruby process') do |v|
$LOAD_PATH << '.' unless $LOAD_PATH.include?('.')
require v
end
opts.on('--version', 'show versions of ksv, ksc and kaitai-struct (Kaitai Struct runtime library for Ruby)') do |_v|
puts "kaitai-struct-visualizer #{Kaitai::Struct::Visualizer::VERSION}"
if system('kaitai-struct-compiler', '--version').nil?
$stderr.puts 'ksv: unable to find and run kaitai-struct-compiler in your PATH'
exit 1
end
require 'kaitai/struct/struct'
puts "kaitai-struct #{Kaitai::Struct::VERSION} (Kaitai Struct runtime library for Ruby)"
exit 0
end
end
begin
parser.parse!
rescue OptionParser::InvalidOption => e
puts e
puts parser
exit 1
end
if ARGV.size < 2
puts parser
exit 1
end
c = Kaitai::Struct::Visualizer::KSYCompiler.new(options)
v = Kaitai::Struct::Visualizer::Visualizer.new(c, ARGV[0], ARGV[1..-1], options)
v.run