PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Add a #include line to all c/c++ plus files
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Add a #include line to all c/c++ plus files

Réponse
 
LinkBack Outils de la discussion
Vieux 01/12/2006, 06h35   #1
RedDevilDan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Add a #include line to all c/c++ plus files

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?

  Réponse avec citation
Vieux 01/12/2006, 06h45   #2
Vino
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Add a #include line to all c/c++ plus files

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.
  Réponse avec citation
Vieux 01/12/2006, 07h34   #3
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Add a #include line to all c/c++ plus files

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
  Réponse avec citation
Vieux 01/12/2006, 09h24   #4
Robbie
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Add a #include line to all c/c++ plus files

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


  Réponse avec citation
Vieux 01/12/2006, 18h58   #5
Icarus Sparry
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Add a #include line to all c/c++ plus files

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.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 12h38.


Édité par : vBulletin® version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,13686 seconds with 13 queries