home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sources.unix
- From: janet@cs.uwa.edu.au (Janet Jackson)
- Subject: v26i095: aliasmooth - perl script for tidying up the aliases file, Part01/01
- Sender: unix-sources-moderator@vix.com
- Approved: paul@vix.com
-
- Submitted-By: janet@cs.uwa.edu.au (Janet Jackson)
- Posting-Number: Volume 26, Issue 95
- Archive-Name: aliasmooth/part01
-
- aliasmooth is a perl script for tidying up the aliases file. It rewrites
- each alias with new continuation lines, so that each line is as long as
- possible up to 80 characters (where the tab at the beginning of each
- continuation line counts as 8 characters). It also alphabetically sorts
- the addresses in each alias. It leaves everything else alone - comments
- and blank lines stay in place, and the aliases stay in the same order.
-
- aliasmooth is a filter, so use it thus: aliasmooth </etc/aliases >newfile
-
- janet@cs.uwa.edu.au (Janet Jackson)
-
- #! /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 the files:
- # README
- # aliasmooth
- # This archive created: Thu Apr 23 17:48:45 1992
- export PATH; PATH=/bin:$PATH
- echo shar: extracting "'README'" '(234 characters)'
- if test -f 'README'
- then
- echo shar: will not over-write existing file "'README'"
- else
- sed 's/^X//' << \SHAR_EOF > 'README'
- Xaliasmooth - a perl filter for neatening continuation lines in the mail
- Xaliases file, and sorting the usernames in each alias.
- X
- XUSAGE EXAMPLE: aliasmooth </etc/aliases >/tmp/aliases.new
- X
- XJanet Jackson
- X<janet@cs.uwa.edu.au>
- X1992-04-23
- SHAR_EOF
- if test 234 -ne "`wc -c < 'README'`"
- then
- echo shar: error transmitting "'README'" '(should have been 234 characters)'
- fi
- fi # end of overwriting check
- echo shar: extracting "'aliasmooth'" '(2069 characters)'
- if test -f 'aliasmooth'
- then
- echo shar: will not over-write existing file "'aliasmooth'"
- else
- sed 's/^X//' << \SHAR_EOF > 'aliasmooth'
- X#!/usr/bin/perl
- X
- X# aliasmooth
- X#
- X# Script for neatening continuation lines in alias file.
- X#
- X# Usage: aliasmooth <oldfile >newfile
- X#
- X# Janet Jackson <janet@cs.uwa.edu.au>, 1992-04-23
- X
- X
- X$_ = <STDIN>; # read first line
- Xwhile ($_) # Stop now if at eof
- X{
- X # $_ is new alias, comment, or blank
- X
- X while ($_ && (/^#/ || /^\s*$/)) # Find next alias: check for EOF,
- X # and skip comment or blank lines
- X {
- X print $_; # Spit out the line.
- X $_ = <STDIN>; # Read next line.
- X }
- X
- X if ($_) # Not EOF, so on a new alias
- X {
- X
- X $alias = ''; # reset $alias for new alias
- X do
- X {
- X s/[\s\n]//g; # remove newline & whitespace
- X $alias .= $_; # Append to $alias
- X # Process any continuation lines: read next line; process it if
- X # not EOF and not(new alias or comment or blank)
- X } while ( ($_ = <STDIN>) && !(/:/ || /^#/ || /^\s*$/) );
- X
- X # now at EOF, or $_ is new alias, comment, or blank
- X
- X ($name, $users) = split( /:/, $alias, 2 );
- X
- X # print out alias, creating continuation lines if necessary
- X print "$name: ";
- X $linelen = length( $name ) + 2;
- X $comma = '';
- X $commalen = 0;
- X foreach $user ( sort split( /,/, $users ) )
- X {
- X $ulen = length( $user );
- X if ( ($linelen + $commalen + $ulen) > 79 ) # gonna be too long
- X {
- X print "$comma\n\t$user"; # make continuation line
- X $linelen = 8 + $ulen;
- X }
- X else # tack on end of current line
- X {
- X print "$comma$user";
- X $linelen += ($commalen + $ulen);
- X }
- X $comma = ','; # not on first name anymore
- X $commalen = 1;
- X }
- X print "\n";
- X
- X }
- X # At EOF or $_ is new alias, comment, or blank
- X}
- X
- Xexit 0;
- X
- X# end of aliasmooth
- SHAR_EOF
- if test 2069 -ne "`wc -c < 'aliasmooth'`"
- then
- echo shar: error transmitting "'aliasmooth'" '(should have been 2069 characters)'
- fi
- chmod +x 'aliasmooth'
- fi # end of overwriting check
- # End of shell archive
- exit 0
-