[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Mix different C source files into a single one

Horacius ReX

12/29/2007 6:06:00 PM

Hi,

I have a C program split into different source files. I am trying a
new compiler and for some reason it only accepts a single source file.
So I need to "mix" all my different C source files into a single one.

Do you know about some type of python script able to do this kind of
task ?

Thanks
4 Answers

Michael L Torrie

12/29/2007 7:41:00 PM

0

Horacius ReX wrote:
> Hi,
>
> I have a C program split into different source files. I am trying a
> new compiler and for some reason it only accepts a single source file.
> So I need to "mix" all my different C source files into a single one.
>
> Do you know about some type of python script able to do this kind of
> task ?

No, but bash and friends can:

cat *.c > newfile.c

If you're stuck working with windows, the copy command can also
concatenate files.

After concatenating the files, editing the file to remove/merge #include
directives would work. Any compiler that can only deal with a single
source file is of course extremely limited in what it can do, so this
manual process shouldn't be too bad for short programs (all that this
compiler can really deal with).

>
> Thanks

John Machin

12/29/2007 8:42:00 PM

0

On Dec 30, 5:05 am, Horacius ReX <horacius....@gmail.com> wrote:
> Hi,
>
> I have a C program split into different source files. I am trying a
> new compiler and for some reason it only accepts a single source file.

The relevance of this question to this newsgroup is zero, but ...

Smashing all of your source files into one is an "interesting"
reaction to the perceived problem. Consider these alternatives:

1. Abandon any further trialling of this new compiler ... which new
compiler is it? Which compiler are you currently using?

2. Use "make" or something similar to automate the process of
compiling each changed source file followed by a linking step.

3. Write yourself a shell script that compiles each source file and
then links it.

HTH,
John

Benjamin

12/29/2007 9:48:00 PM

0

On Dec 29, 12:05 pm, Horacius ReX <horacius....@gmail.com> wrote:
> Hi,
>
> I have a C program split into different source files. I am trying a
> new compiler and for some reason it only accepts a single source file.
> So I need to "mix" all my different C source files into a single one.
That sounds like one crumy compiler.
>
> Do you know about some type of python script able to do this kind of
> task ?
No, but we can write one:

import sys

if __name__ == "__main__":
glob = ""
for file in sys.argv[1:-1]:
glob += "\n" + open(file, "r").read()
open(sys.argv[-1], "w").write(glob)

It's stupid, but it'll work for basic tasks. (I would actually just
use cat; that's what it's for. :))
>
> Thanks

Grant Edwards

12/29/2007 10:03:00 PM

0

On 2007-12-29, Horacius ReX <horacius.rex@gmail.com> wrote:

> I have a C program split into different source files. I am
> trying a new compiler and for some reason it only accepts a
> single source file.

That's pretty much the way they all work.

> So I need to "mix" all my different C source files into a
> single one.

You compile them individually, then you link the object files
together.

> Do you know about some type of python script able to do this
> kind of task ?

$ man make

--
Grant