2012-06-22 10:05:41 +01:00
|
|
|
module FlexNBD
|
2018-02-02 21:34:14 +00:00
|
|
|
def self.binary(str)
|
2014-02-21 19:10:55 +00:00
|
|
|
if str.respond_to? :force_encoding
|
2018-02-02 21:34:14 +00:00
|
|
|
str.force_encoding 'ASCII-8BIT'
|
2014-02-21 19:10:55 +00:00
|
|
|
else
|
|
|
|
str
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-06-22 10:05:41 +01:00
|
|
|
# eeevil is his one and only name...
|
|
|
|
def self.read_constants
|
|
|
|
parents = []
|
2018-02-02 21:34:14 +00:00
|
|
|
current = File.expand_path('.')
|
|
|
|
while current != '/'
|
2012-06-22 10:05:41 +01:00
|
|
|
parents << current
|
2018-02-02 21:34:14 +00:00
|
|
|
current = File.expand_path(File.join(current, '..'))
|
2012-06-22 10:05:41 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
source_root = parents.find do |dirname|
|
2018-02-02 21:34:14 +00:00
|
|
|
File.directory?(File.join(dirname, 'src'))
|
2012-06-22 10:05:41 +01:00
|
|
|
end
|
|
|
|
|
2018-02-02 21:34:14 +00:00
|
|
|
raise 'No source root!' unless source_root
|
2012-06-22 10:05:41 +01:00
|
|
|
|
2018-02-02 21:34:14 +00:00
|
|
|
headers = Dir[File.join(source_root, 'src', '{common,proxy,server}', '*.h')]
|
2012-06-22 10:05:41 +01:00
|
|
|
|
|
|
|
headers.each do |header_filename|
|
2018-02-02 21:34:14 +00:00
|
|
|
txt_lines = File.readlines(header_filename)
|
2012-06-22 10:05:41 +01:00
|
|
|
txt_lines.each do |line|
|
|
|
|
if line =~ /^#\s*define\s+([A-Z0-9_]+)\s+(\d+)\s*$/
|
2012-07-14 17:25:26 +01:00
|
|
|
# Bodge until I can figure out what to do with #ifdefs
|
2018-02-02 21:34:14 +00:00
|
|
|
const_set(Regexp.last_match(1), Regexp.last_match(2).to_i) unless const_defined?(Regexp.last_match(1))
|
2012-06-22 10:05:41 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-02-02 21:34:14 +00:00
|
|
|
read_constants
|
2012-06-22 10:05:41 +01:00
|
|
|
|
2014-02-21 19:10:55 +00:00
|
|
|
REQUEST_MAGIC = binary("\x25\x60\x95\x13") unless defined?(REQUEST_MAGIC)
|
|
|
|
REPLY_MAGIC = binary("\x67\x44\x66\x98") unless defined?(REPLY_MAGIC)
|
2013-02-15 16:51:28 +00:00
|
|
|
end # module FlexNBD
|