Skip to content

Instantly share code, notes, and snippets.

@gnarl
Created November 8, 2010 21:40
Show Gist options
  • Save gnarl/668313 to your computer and use it in GitHub Desktop.
Save gnarl/668313 to your computer and use it in GitHub Desktop.
def parse_command( command_ary )
o = ""
command_ary.each do |l|
o = o + l.slice(60..-1).chomp
end
o.gsub!('><', ">\n<")
o_ary = o.split("\n")
child = false
line = ""
o_ary.each do |x|
if child
line = line + " " + x
if x.match(/<\/child>/)
child = false
puts line
line = ""
end
else
if x.match(/\<child.*/)
child = true
line = line + " " + x
else
puts x
end
end
end
puts " "
puts " "
end
##########################################################
input_file = ARGV.shift
abort 'Need an input filename!' unless input_file
cmd_ary = []
found_cmd = false
File.open( input_file, 'r' ).each do |l|
unless found_cmd
if l.match(/\A0010\s{3}.*/)
unless l.match(/\A[0-9,a-f]{4}\s{3}00\s00\s00\s04.*/)
found_cmd = true
cmd_ary << l
end
end
else
unless l.match(/\A[0-9,a-f]{4}\s.*/)
found_cmd = false
parse_command( cmd_ary )
cmd_ary =[]
else
cmd_ary << l
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment