[comp.sys.handhelds] Bang, it's clean.

frechett@spot.Colorado.EDU (-=Runaway Daemon=-) (05/23/91)

For lack of a better name this little perl program/script is called bang.
Let's say you are like me, you save programs off of this newsgroup for your
own personal archive.  I currently have 4.1 Megabytes worth of files and 
on my system, disk space is at a premium.  So I wrote this little script to do
a couple things.. First, it will strip out all unnecesary headers such as 
Sender: and a host of other headers that drive me nuts.. You can add or 
delete them at will.
Secondly, it will add a comment line at the very top of the file which
should have some description of what is in the file.  
This is how it works.. Given a recent post that you have saved... say
Piper1.2.Schip     you type
> bang Piper1.2.Schip  This is a Pipe laying game for hp48.  Need SChip. 
And it will first create Piper1.2.Schip which is an exact copy of the original
file then it addes the comment line to a new file called Piper1.2.Schip 
and then strips all the unwanted headers from the old one and puts them in the
new one.  When it is all done the file Piper1.2.Schip has been changed.  
I found that in alot of these posts, the numerous headers take up a hell of 
alot of space and removing them does alot to increase my capacity for more 
stuff.. ;)  
There is one other thing that is really slick about this.. If you try a command
like... 
> grep ^DESC: * > Index                or if you have stuff all in
subdirectories like me..
> grep ^DESC: */* > Index      This will create an index with the name of the
file first (where grep found it.. full pathnames if in directories) and 
then the whole DESC line.  It makes redoing your Index file totally automatic.
Hope someone has a use for it... If someone has a suggestion on how to reduce
the size of the header-stripper construct, let me know. 
	ian

-=Runaway Daemon=-
#!/usr/bin/perl
#
# bang -- by Ian Frechette,
#
if ($#ARGV < 1) { print "Please include comments too.\nUsage bang <file> <Comments>\n"; exit(0);} 
else {
	print "Editting file $ARGV[0].\n";
# Rename the file we are going to change in case of a mistake.
	rename(@ARGV[0], @ARGV[0].'.bak') || die("Can't find file @ARGV[0].\n");
	open(HPFILE, ">>@ARGV[0]");  #Open the orig filename for writing.
	open (BAKFILE, "@ARGV[0].bak"); #Open the backup file for reading
	select(HPFILE); 
	print HPFILE ("DESC: @ARGV[1..$#ARGV]\n"); #Put Description line at 
                                                   #begining of new file.
# This loop is designed to read the contents of the orig file back into the
# new file minus a few annoying headers, including any old DESC: lines. 
LINE: while (<BAKFILE>) {
if (/^DESC/) { next LINE;}
if (/^Article/) { next LINE; }
if (/^Path:/) { next LINE; }
# Might want to leave Message-ID in.. I don't need it... 
if (/^Message-ID:/) { next LINE; }
if (/^Sender:/) { next LINE; }
if (/^Lines:/) { next LINE; }
if (/^Originator:/) { next LINE; }
if (/^X-Local-Date:/) { next LINE; }
if (/^Nntp-Posting-Host:/) { next LINE; }
if (/^References/) { next LINE; }
if (/^X-VMS-To:/) { next LINE; }
if (/^X-VMS-Cc:/) { next LINE; }
if (/^Distribution:/) { next LINE; }
if (/^From\ /) { next LINE; }
if (/^Status:/) { next LINE; }
	print;
	}
select(STDOUT); 
close(HPFILE);
close(BAKFILE);
exit(0); }