Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!shelby!apple!brutus.cs.uiuc.edu!wuarchive!wugate!uunet!bfmny0!tneff From: tneff@bfmny0.UUCP (Tom Neff) Newsgroups: alt.sources Subject: Blank trimmer Summary: blank trim tabs and blanks on the right, eliminate extra blank lines Message-ID: <14602@bfmny0.UUCP> Date: 28 Aug 89 19:55:20 GMT Reply-To: tneff@bfmny0.UU.NET (Tom Neff) Organization: Arhythmic Aerobics Treatment Facility, Los Cheetos, CA Lines: 66 Expires: Sender: Followup-To: Distribution: Keywords: This is one of those nasty hacks purists get on your case for because you can do it all with sed(1). However I have a specialized application where I use real long lines and I want fast performance, so I wrote this little C filter that (a) trims blanks and tabs off the right side of every input line and (b) allows no more than one blank line at a time in the output. I just thought I'd pass it along in case anyone else needs something similar. Hack away, I don't want to hear about it. ------ cut the GREEN wire first! ------ No, cut the RED wire f>>BOOM<< ------ #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create: # trimx.c # This archive created: Mon Aug 28 15:50:36 1989 export PATH; PATH=/bin:/usr/bin:$PATH if test -f 'trimx.c' then echo shar: "will not over-write existing file 'trimx.c'" else sed 's/^X//' << \SHAR_EOF > 'trimx.c' X/* X * trimx - blank trim from the right X * X * $Log: trimx.c,v $ X * Revision 1.1 89/06/19 15:01:49 tneff X * Initial revision X * X */ X X#ident "@(#) $Id: trimx.c,v 1.1 89/06/19 15:01:49 tneff Exp $" X X#include X Xmain() X{ X char s[65536]; /* whatever */ X register char *p; X X int jebl = 0; /* just emitted blank line */ X X while (gets(s) != NULL) X { X for (p = s + strlen(s) - 1; X p >= s && (*p == ' ' || *p == '\t'); X p--); X *(++p) = '\0'; X if ((p != s) || !jebl) X puts(s); X jebl = (p == s); X } X X fflush(stdout); X exit(0); X} SHAR_EOF fi exit 0 # End of shell archive -- "We walked on the moon -- (( Tom Neff you be polite" )) tneff@bfmny0.UU.NET