Appending new line characters to files

Charles Curley charlescurley at charlescurley.com
Fri Mar 10 12:23:38 MST 2006


I changed your subject line to something more descriptive so as to
attract folks who (like me) rarely read more than the subject line.

On Fri, Mar 10, 2006 at 11:55:43AM -0700, Steve wrote:
> Hello all,
> My scriptfu is terrible, but anyways, I'm trying to compile a program
> that is completely crossplatform but was originally written using MS
> Visual Studio, as such numerous .cc and .h files do not have newline
> characters at the end.

And may have control Z at the end as well. This is an ancient CP/M and
DOS-ism that occasionally pops up.

> This is causing GCC to complain "Warning no newline at end of file!"
> which since there are 1593 files, means I'm getting ALOT of these
> essentially pointless messages.
> At first I thought Ok, I'll just figure out how to shut off the
> warnings from GCC but realised that would require a change to the make
> file.

And the problem is? All you need to do is find out where make gets the
options it feeds to gcc. By ancient and honorable custom, there should
be one or more variables called OPTS or variations on that theme.

If the makefile was generated by VS, you will have some hacking to do
there as well to make it cross platform.

> What I really want to do is parse one directory and all of it's
> subdirectories (it's really, really deep), and just append a newline
> character to each file which does not have one.

Why bother with the conditional? Why not just append a new line to
each file, needed or not? That should allow you to do something like:

find -type f \( -iname *.h -o -iname *.c \) -exec foo {} /;

where foo is an awk command or some such that simply appends what you
need.

However, if you want to retain cross-compilation compatibility, you
need to add both a new line character and a carriage return (I forget
which comes first).

> 
> I looked at the perlscript called "deep" which looked like it would do
> the trick, but when I tried it, it literally appened \n rather than
> the newline character itself, which busted my entire build.

Well, at least you have some perl code you can hack.

-- 

Charles Curley                  /"\    ASCII Ribbon Campaign
Looking for fine software       \ /    Respect for open standards
and/or writing?                  X     No HTML/RTF in email
http://www.charlescurley.com    / \    No M$ Word docs in email

Key fingerprint = CE5C 6645 A45A 64E4 94C0  809C FFF6 4C48 4ECD DFDB
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: not available
Url : http://plug.org/pipermail/plug/attachments/20060310/e451c9f7/attachment.bin 


More information about the PLUG mailing list