• Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Insert header comment into every source file?

d000hg

My post count is Majestic
Joined
Dec 1, 2007
Messages
38,987
Likes received
2,910
Thanks received
678
Location
My house
Is there a tool I can use to insert a comment into every source file in one go... e.g a copyright notice or whatever?

Sorry for all the threads today :) gearing up to a new project.
 
Didn't we used to do this in DOS?

COPY COPYRITE.TXT + C:\SYSTEM\SOURCE\*.SRC C:\SYSTEM\SOURCE2
 
Slightly more obscure solutions than I was expecting :) It's easy enough to write one even, but it seems like an obvious utility that must be floating around... I don't suppose Visual Studio has a way to do this natively by any chance?
 
Slightly more obscure solutions than I was expecting :)
Huh? How is a single line o/s command obscure?

I suppose you could buy a macro programming language online, like WinBatch, and learn how to use it and use that, I suppose.

Or learn how to do it in Python and write something in that.

Or outsource it to Bob Shawadiwadi on Freelancers.net or whatever that site is called.

Or write a pre-compiler that parses the source for required text and inserts it if not present, then re-compile the system.

Reverse engineer the compiler to insert the text into the source.

Rename every source file to have "®d000hgCo" appended to the name.

Or use whatever programming language you are working with to write something.

Or, FFS, write a macro in Word to do it! :bang:

Get one of the admin staff to do it.

Get the most junior developer on the team to do it.

How many files are we talking about here? I could have copy 'n' pasted a copyright message in to 20 or 30 documents in the time it has taken me to write this. :freaky:
 
Is there a tool I can use to insert a comment into every source file in one go... e.g a copyright notice or whatever?

Sorry for all the threads today :) gearing up to a new project.

Code:
cat copyright.txt code.c > code2.c

I'm a bit rusty on Unix but
Code:
cat copyright.txt code.c > code.c
might also work since cat operates on copies of the original files, not the files themselves. So the output could be sent back to one of the original files.

EDIT :

Since you are working in a windows environment use type instead of cat. The second option may not work since I dont know how type treats the original data.
 
Last edited: 13:51
I'd do this:

Code:
for file in *.c *.h
do
cat copyright.txt $file > mytemp
mv mytemp $file
done

EDIT: I'd say "cat copyright.txt code.c > code.c" is risky, I've never heard of cat operating on copies of files. I could be wrong, but I've been around Unix a long time.
 
I'd do this:

Code:
for file in *.c *.h
do
cat copyright.txt $file > mytemp
mv mytemp $file
done

EDIT: I'd say "cat copyright.txt code.c > code.c" is risky, I've never heard of cat operating on copies of files. I could be wrong, but I've been around Unix a long time.

Your version is the safe way, I did say that cat copyright.txt code.c > code.c *might* work and that I was rusty. I'd test it first if I were you :o

From memory it's an "undocumented feature" of cat that redirecting the output to one of the original files will overwrite the contents of that file without warning, rather than barfing with an error message from trying to write to an open file.
 

Advertisers

Back
Top