Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site fortune.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxl!ihnp4!fortune!rpw3 From: rpw3@fortune.UUCP Newsgroups: net.unix Subject: Re: #include file tree generator - (nf) Message-ID: <3485@fortune.UUCP> Date: Thu, 31-May-84 07:05:47 EDT Article-I.D.: fortune.3485 Posted: Thu May 31 07:05:47 1984 Date-Received: Sat, 2-Jun-84 09:24:47 EDT Sender: notes@fortune.UUCP Organization: Fortune Systems, Redwood City, CA Lines: 49 #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