Game Development Community

dev|Pro Game Development Curriculum

Make GCC stop complaining about missing newlines

by Dreamer · 12/14/2006 (3:02 pm) · 9 comments

GCC is a great compiler, but it's kind of annoying to see it complain about missing newlines at the end of files.
This is a quick fix for that.

Basically it's a little shell function that will append a newline to all .cc and .h files which effectively gets GCC to shut up.

Open a console up.
cd into your TGE directory.
Then type the following.
find . -name \*.cc -o -name \*.h | while read i; do echo >>${i}; done

I want to give thanks to plug.org mailing list for this solution.

Regards,
Dreamer

p.s. This solution is AFAIK Linux only, but it might work on Mac as well.

#1
12/14/2006 (3:50 pm)
You're a good man. I don't care what everybody says about you.
#2
12/14/2006 (4:17 pm)
There is also a compiler flag if you use GCC 4.*

I think I added when I was doing the 1.4.* port, might want to check

-Ron
#3
12/14/2006 (5:06 pm)
Sheesh, and to think I did it all by hand :(

lol great resource!
#4
12/14/2006 (5:31 pm)
I bet this will work with gcc and cygwin on Windows, too.
#5
12/15/2006 (4:06 am)
Yes,

cygwin on windows uses the linux compile info which in turns uses a shell script to copy ib files around. Atleast it did for 1.4.2 ;)

-Ron
#6
12/18/2006 (10:48 am)
I did it this way as I mentioned in the Linux Collaboration thread:
for i in 'find . -iname "*.c" -o -iname "*.cc" -o -iname "*.h" -o -iname "*.cpp"'
do
    echo $i
    echo wq | ed $i > /dev/null 2>&1
done

A minor benefit to this approach is that it only adds the newline if its missing. Echo'ing via >> to the end of the file will always add a newline. Both approaches will change the modification time stamp on the file. Both approaches also could suffer from too many args, but don't yet for me at least under linux, :).
#7
12/31/2006 (2:36 am)
Below a version which works with Linux bash , I have added dos2unix conversion to get clean source file

#!/bin/bash

for i in `find . -iname "*.c" -o -iname "*.cc" -o -iname "*.h" -o -iname "*.cpp"`; do {
    echo ${i}
    echo wq | ed ${i} > /dev/null 2>&1
    dos2unix -d ${i}
} ; done
#8
12/31/2006 (7:47 am)
Ya, dos2unix works. We did not want to go that route and have the end user install yet another app or look into issues with distributing it with TGE. So, we took the clean route of using wq

I was going to-do the entire TGE tree, but never got the OK from GG. They had other platforms in a flux and allowing me to traverse the entire tree would have caused a SVN nightmere

-Ron
#9
01/02/2007 (10:43 am)
I would suggest that you avoid the use of find(1) on nontrivial datasets in backticks. Especially in the case of torque, it can be very large and very expensive, and on many platforms it will outright fail or lead to unexpected effects.

Personally, I did this one:
find . -name \*.cc -o -name \*.cpp -o -name \*.h -exec sh -c 'echo "" >> {}' \;

But in the end there's as many ways of doing this same thing as there are linux users able to do it :-)

Gary (-;