• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Algorithm help..

imported_vr6

Platinum Member
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???
 
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.
 
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
 
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.
 
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?
 
Back
Top