|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
In linux/unix, is there anyway to add the #include line to all *.c or
*.cpp files automatically? I have a large project which contains thousands of .c or .cpp source files. However, I decided to #include a common header file into all source files in order to config them globally. Is there anyway to do that easily? |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
RedDevilDan wrote:
> In linux/unix, is there anyway to add the #include line to all *.c or > *.cpp files automatically? > > I have a large project which contains thousands of .c or .cpp source > files. However, I decided to #include a common header file into all > source files in order to config them globally. Is there anyway to do > that easily? > Find out a/some header file(s) which are common to those .c/.cpp files. You could add your #include to those header files. Saves you the trouble of changing all the .c/.cpp files. Vino. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On 2006-12-01, RedDevilDan wrote:
> In linux/unix, is there anyway to add the #include line to all *.c or > *.cpp files automatically? > > I have a large project which contains thousands of .c or .cpp source > files. However, I decided to #include a common header file into all > source files in order to config them globally. Is there anyway to do > that easily? for file in *.c *.cpp do if [ -f "$file" ] then { printf "#include <xxx.h>\n#include '\"yyy.h\"\n" cat "$file" } > tempfile && cp -- tempfile "$file" fi done -- Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell> Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) ===== My code in this post, if any, assumes the POSIX locale ===== and is released under the GNU General Public Licence |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
Thinking in c++ Vol 2 has an example in Chapter 4(I don't remember
clearly). You can see the category of this book to find this example quickly. I'm very sorry I don't remember what section this example lies in. Chris F.A. Johnson wrote: > On 2006-12-01, RedDevilDan wrote: > > In linux/unix, is there anyway to add the #include line to all *.c or > > *.cpp files automatically? > > > > I have a large project which contains thousands of .c or .cpp source > > files. However, I decided to #include a common header file into all > > source files in order to config them globally. Is there anyway to do > > that easily? > > for file in *.c *.cpp > do > if [ -f "$file" ] > then > { > printf "#include <xxx.h>\n#include '\"yyy.h\"\n" > cat "$file" > } > tempfile && cp -- tempfile "$file" > fi > done > > -- > Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell> > Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress) > ===== My code in this post, if any, assumes the POSIX locale > ===== and is released under the GNU General Public Licence |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Thu, 30 Nov 2006 22:35:40 -0800, RedDevilDan wrote:
> In linux/unix, is there anyway to add the #include line to all *.c or > *.cpp files automatically? > > I have a large project which contains thousands of .c or .cpp source > files. However, I decided to #include a common header file into all > source files in order to config them globally. Is there anyway to do > that easily? Usually this is a bad idea, it tends to increase coupling between different parts of the program. Chris has already give you a loop that will do what you want, however if you are using gcc then at least the current version has an option '-include' which you could add to your build system. To quote the manual -include file Process file as if "#include "file"" appeared as the first line of the primary source file. However, the first directory searched for file is the preprocessor's working directory instead of the directory containing the main source file. If not found there, it is searched for in the remainder of the "#include "..."" search chain as normal. If multiple -include options are given, the files are included in the order they appear on the command line. |
|
![]() |
| Outils de la discussion | |
|
|