Algorithm help..

imported_vr6

Platinum Member
Jul 6, 2001
2,740
0
0
I have a bunch of C++ Source(.cpp) and Header files(.h) in a directory.
I am building an tool using VB.

A user will select any C++ Source file, we'll call it "SeedFile"
i have to find all the source and header files required by the SeedFile inorder to compile that "seedfile".

How would you do it?
I was thinking..

1. Read in SeedFile search for the any string that has #include
2. parse out the #include to get the xxx.h
3. using my list of xxx.h file, find all the corresponding xxx.cpp files, since they typically have the same name.
4. Read in each .cpp file.
5. repeat.

doesn't sound very efficient. any suggestions, problems???
 

KingNothing

Diamond Member
Apr 6, 2002
7,141
1
0
Use recursion. Have a function that takes a filename and a list as arguments. It adds the filename to the list, reads in the file, and then calls itself with each #include filename.
 

DanceMan

Senior member
Jan 26, 2001
474
0
0
Watch out for your end condition for recursion and make sure you don't have a 'circular' problem. Standard header files might cause you a problem, you might want to include a filter for those to not recurse into those any further.

What are you planning to do about template includes? Just ignore them?

DanceMan
 

torpid

Lifer
Sep 14, 2003
11,631
11
76
Also make sure you don't get stuck in a loop. Something might include a file that you have already included. Be sure to check the list before adding & traversing.
 

imported_vr6

Platinum Member
Jul 6, 2001
2,740
0
0
never thought about template includes... probably wont run across them so not gonna worry about them as of now. i am checking to make sure if the file have no already been included.

std headers.. those are gonna be skipped.

end condition would be end EOF

no?