#include file tree generator - (nf)

rpw3 at fortune.UUCP rpw3 at fortune.UUCP
Thu May 31 21:05:47 AEST 1984


#R:ssc-vax:-16200:fortune:26900061:000:1361
fortune!rpw3    May 31 03:22:00 1984

On the principle that the best way to do jobs like this is to use
existing tools plus a little something extra (K & P "Unix Prog. Env."),
may I suggest starting by using the C pre-processor, which gives you a
nice little trace of what file it's handling. Given these files:

	==== a ====	==== b ====	==== c ====	==== d ====

	This is a	This is b	This is c	This is d
	#include "b"	#include "c"
	Back to a	Back to b
	#include "d"
	The end.

The command "cc -E a | grep '^# ' " gives:

	# 1 "a"
	# 1 "./b"
	# 1 "./c"
	# 3 "./b"
	# 3 "a"
	# 1 "./d"
	# 5 "a"

Given that much, I strongly suggest that you can write a SIMPLE little
C program which reads that output, puts it on a stack, outputs each line
indented one more level, and if you see a line that matches anything in
your stack (searching backwards from the end) pop the stack and the
indentation level back to there (and don't print that line). That would
give you the output below:

	# 1 "a"
		# 1 "./b"
			# 1 "./c"
		# 1 "./d"

Further formatting is left as an exercise for the reader...

Note that this correctly handles any includes which are buried in or
generated from macros, since the C pre-processor knows about macros.

Rob Warnock

UUCP:	{ihnp4,ucbvax!amd70,hpda,harpo,sri-unix,allegra}!fortune!rpw3
DDD:	(415)595-8444
USPS:	Fortune Systems Corp, 101 Twin Dolphin Drive, Redwood City, CA 94065



More information about the Comp.unix mailing list