2009-03-29 07:30:54 +00:00
|
|
|
# This file is part of Metasm, the Ruby assembly manipulation suite
|
2010-09-09 18:19:35 +00:00
|
|
|
# Copyright (C) 2006-2009 Yoann GUILLOT
|
2009-03-29 07:30:54 +00:00
|
|
|
#
|
|
|
|
# Licence is LGPL, see LICENCE in the top-level directory
|
|
|
|
|
|
|
|
#
|
|
|
|
# shows the preprocessor path to find a specific line
|
|
|
|
# usage: ruby chdr-find.rb 'regex pattern' list of files.h
|
|
|
|
#
|
|
|
|
|
|
|
|
def gets
|
2013-08-30 21:28:33 +00:00
|
|
|
l = $ungets
|
|
|
|
$ungets = nil
|
|
|
|
l || super()
|
2009-03-29 07:30:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def parse(root=false)
|
2013-08-30 21:28:33 +00:00
|
|
|
want = false
|
|
|
|
ret = []
|
|
|
|
while l = gets
|
|
|
|
case l = l.strip
|
|
|
|
when /^#if/
|
|
|
|
ret << l
|
|
|
|
r = parse(true)
|
|
|
|
if r.empty?
|
|
|
|
ret.pop
|
|
|
|
else
|
|
|
|
want = true
|
|
|
|
rr = r.pop
|
|
|
|
ret.concat r.map { |l_| (l_[0,3] == '#el' ? ' ' : ' ') << l_ }
|
|
|
|
ret << rr
|
|
|
|
end
|
|
|
|
when /^#el/
|
|
|
|
if not root
|
|
|
|
$ungets = l
|
|
|
|
break
|
|
|
|
end
|
|
|
|
ret << l
|
|
|
|
r = parse
|
|
|
|
want = true if not r.empty?
|
|
|
|
ret.concat r
|
|
|
|
when /^#endif/
|
|
|
|
if not root
|
|
|
|
$ungets = l
|
|
|
|
break
|
|
|
|
end
|
|
|
|
ret << l
|
|
|
|
break
|
|
|
|
when /#$srch/ #, /^#include/
|
|
|
|
want = true
|
|
|
|
ret << l
|
|
|
|
end
|
|
|
|
end
|
|
|
|
want ? ret : []
|
2009-03-29 07:30:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
$srch = ARGV.shift
|
|
|
|
puts parse
|