I often find myself needing this:

Say you have a test.c file; it includes other files, say:

#include <stdio.h>
#include "mylib.h"
#include "../mylib_extra.h"
#include "../mylib_bonus.h"
...

... then, say, "mylib.h" in the same directory, loads also something else:

#include <special.h>
#include "/path/to/calculator.h"
#include "testing/tester.h"
...

... etc. Now, some of these statements refer to system directories, which one must know beforehand - but in principle, I guess it would be possible to write a tool, which given a pattern of the "include" statement, could recursively open all files referred to in the initial file, look for the same statements there, open files further - until it draws a tree map. Items it couldn't open without a knowledge of the path, would be marked.

I would imagine a tool like that working like this (where files found/opened are marked with a (*), and no markings otherwise)

$ ./getincludetree test.c

test.c
- <stdio.h> 
- "mylib.h" (*)
-- <special.h> 
-- "/path/to/calculator.h" (*)
--- ...
-- "testing/tester.h" (*)
--- ...
- "../mylib_extra.h" (*)
-- ...
- "../mylib_bonus.h" (*)
-- ...

Even better, if you could specify a pattern for the include statement, then instead of #include "...", one could use, say \input{...} and use the same tool for finding the include structure of a Latex document, as well.

Is there anything like that out there?

Many thanks in advance for any answers,
Cheers!

  • Are you looking for a Makefile or something like that? I don't really get the problem? – Bernhard May 24 '12 at 11:12
  • @Bernhard - not a makefile, a command-line tool that can work under Linux (edited tags); I was just wandering if there are any existing command line programs which can do the above... Cheers! – sdaau May 24 '12 at 16:10

You want to implement an autoloader class, a file scanner with caching: http://anthonybush.com/projects/autoloader/source/.

  • Thanks for that, @David - I was thinking more of something like a ready-made command line tool; this looks like it will need some coding to implement.. Great resource, though - cheers! – sdaau May 24 '12 at 14:01

Hmmm. Seems like you want:

Cscope
Ctags
Gnu global

Google those names, think that should help you. They are source indexers.

  • Many thanks for that, @chiggsy - looks like "source indexer" is what I was looking for - will report back once I get around to it. Cheers! – sdaau May 24 '12 at 18:32

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.