I have a folder named ‘Competition’ that stores all of my code for the robot, and in this folder I have a RobotC file named ‘CompTemp.c’ and a subfolder named ‘Headers’. Inside the Headers subfolder, I have numerous files that add functions, tasks, etc. for use in the main CompTemp.c file.
I know I could do:
and so on. But since there are a large number of files in this folder, and since I want to be able to easily add, remove, or modify these files and filenames, I was wondering if there was a way to include all of the files in the subfolder at once. IE, I’m wondering if it’s possible to do something like this:
and have RobotC automatically include every file that is under the Headers subfolder.
Is this at all possible? Or am I stuck with manually writing the import statements for each folder?
Thanks in advance!
You need to do a #include for each file. What you can do is make a file containing all of the #include statements, then put a #include for that file.
Aw, I was hoping for a more elegant solution, since I will need to keep adding new files to that folder. Oh well, thanks for your response!
I include just one header file that has all the .h files
You can write a program that reads the directory and looks for all the .h files. It then generates a file that has an entry for all the .h files using the full path name.
You can get clever and say that files named
file_blah_blah_x.h are experimental and not part of the regular build where
file_blah_blah.h is part of the mainstream.
Then the program generates header files in two flavors
Experimental – all the files, and when there is a _x.h file, include it, if there is one that has a same name other than the _x.h, don’t include it.
Production – all of the files except those that end in _x.h
In my case the _x.h files have debug code in it, or are new code I’m writing. Easy to copy the .h, change it’s name to _x.h, put the debug code in, run. fix, run. Comment out the debug code and save as the regular name.
I’m sure others have similar systems the use.
Building tools to make things work the way you want is a time honored tradition. I use AWK to roll my own stuff, but there are build tools out there to automate some of the process.