Sha256: 0a04ffd0aea93c2817e79249596c2356059bea8ad4ebc17e808edb5448b6ae2f

Contents?: true

Size: 976 Bytes

Versions: 6

Compression:

Stored size: 976 Bytes

Contents

#    This file is part of Metasm, the Ruby assembly manipulation suite
#    Copyright (C) 2006-2009 Yoann GUILLOT
#
#    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
	l = $ungets
	$ungets = nil
	l || super()
end

def parse(root=false)
	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 : []
end

$srch = ARGV.shift
puts parse

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
metasm-1.0.5 misc/cheader-findpppath.rb
metasm-1.0.4 misc/cheader-findpppath.rb
metasm-1.0.3 misc/cheader-findpppath.rb
metasm-1.0.2 misc/cheader-findpppath.rb
metasm-1.0.1 misc/cheader-findpppath.rb
metasm-1.0.0 misc/cheader-findpppath.rb