home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / unix / volume26 / aliasmth / part01 < prev    next >
Encoding:
Text File  |  1993-04-03  |  4.2 KB  |  135 lines

  1. Newsgroups: comp.sources.unix
  2. From: janet@cs.uwa.edu.au (Janet Jackson)
  3. Subject: v26i095: aliasmooth - perl script for tidying up the aliases file, Part01/01
  4. Sender: unix-sources-moderator@vix.com
  5. Approved: paul@vix.com
  6.  
  7. Submitted-By: janet@cs.uwa.edu.au (Janet Jackson)
  8. Posting-Number: Volume 26, Issue 95
  9. Archive-Name: aliasmooth/part01
  10.  
  11. aliasmooth is a perl script for tidying up the aliases file.  It rewrites
  12. each alias with new continuation lines, so that each line is as long as
  13. possible up to 80 characters (where the tab at the beginning of each
  14. continuation line counts as 8 characters).  It also alphabetically sorts
  15. the addresses in each alias.  It leaves everything else alone - comments
  16. and blank lines stay in place, and the aliases stay in the same order.
  17.  
  18. aliasmooth is a filter, so use it thus:  aliasmooth </etc/aliases >newfile
  19.  
  20.     janet@cs.uwa.edu.au (Janet Jackson)
  21.  
  22. #! /bin/sh
  23. # This is a shell archive, meaning:
  24. # 1. Remove everything above the #! /bin/sh line.
  25. # 2. Save the resulting text in a file.
  26. # 3. Execute the file with /bin/sh (not csh) to create the files:
  27. #    README
  28. #    aliasmooth
  29. # This archive created: Thu Apr 23 17:48:45 1992
  30. export PATH; PATH=/bin:$PATH
  31. echo shar: extracting "'README'" '(234 characters)'
  32. if test -f 'README'
  33. then
  34.     echo shar: will not over-write existing file "'README'"
  35. else
  36. sed 's/^X//' << \SHAR_EOF > 'README'
  37. Xaliasmooth - a perl filter for neatening continuation lines in the mail
  38. Xaliases file, and sorting the usernames in each alias.
  39. X
  40. XUSAGE EXAMPLE: aliasmooth </etc/aliases >/tmp/aliases.new
  41. X
  42. XJanet Jackson
  43. X<janet@cs.uwa.edu.au>
  44. X1992-04-23
  45. SHAR_EOF
  46. if test 234 -ne "`wc -c < 'README'`"
  47. then
  48.     echo shar: error transmitting "'README'" '(should have been 234 characters)'
  49. fi
  50. fi # end of overwriting check
  51. echo shar: extracting "'aliasmooth'" '(2069 characters)'
  52. if test -f 'aliasmooth'
  53. then
  54.     echo shar: will not over-write existing file "'aliasmooth'"
  55. else
  56. sed 's/^X//' << \SHAR_EOF > 'aliasmooth'
  57. X#!/usr/bin/perl
  58. X
  59. X# aliasmooth
  60. X#
  61. X# Script for neatening continuation lines in alias file.
  62. X#
  63. X# Usage: aliasmooth <oldfile >newfile
  64. X#
  65. X# Janet Jackson <janet@cs.uwa.edu.au>, 1992-04-23
  66. X
  67. X
  68. X$_ = <STDIN>;                           # read first line
  69. Xwhile ($_)                              # Stop now if at eof
  70. X{
  71. X   # $_ is new alias, comment, or blank
  72. X
  73. X   while ($_ && (/^#/ || /^\s*$/))    # Find next alias: check for EOF,
  74. X                                      # and skip comment or blank lines
  75. X   {
  76. X      print $_;                          # Spit out the line.
  77. X      $_ = <STDIN>;                      # Read next line.
  78. X   }
  79. X
  80. X   if ($_)                               # Not EOF, so on a new alias
  81. X   {
  82. X
  83. X      $alias = '';                       # reset $alias for new alias
  84. X      do
  85. X      {
  86. X         s/[\s\n]//g;                    # remove newline & whitespace
  87. X         $alias .= $_;                   # Append to $alias
  88. X         # Process any continuation lines:  read next line; process it if
  89. X         # not EOF and not(new alias or comment or blank)
  90. X      } while ( ($_ = <STDIN>) && !(/:/ || /^#/ || /^\s*$/) );
  91. X
  92. X      # now at EOF, or $_ is new alias, comment, or blank
  93. X
  94. X      ($name, $users) = split( /:/, $alias, 2 );
  95. X
  96. X      # print out alias, creating continuation lines if necessary
  97. X      print "$name: ";
  98. X      $linelen = length( $name ) + 2;
  99. X      $comma = '';
  100. X      $commalen = 0;
  101. X      foreach $user ( sort split( /,/, $users ) )
  102. X      {
  103. X         $ulen = length( $user );
  104. X         if ( ($linelen + $commalen + $ulen) > 79 )    # gonna be too long
  105. X         {
  106. X            print "$comma\n\t$user";        # make continuation line
  107. X            $linelen = 8 + $ulen;
  108. X         }
  109. X         else                                  # tack on end of current line
  110. X         {
  111. X            print "$comma$user";
  112. X            $linelen += ($commalen + $ulen);
  113. X         }
  114. X         $comma = ',';                         # not on first name anymore
  115. X         $commalen = 1;
  116. X      }
  117. X      print "\n";
  118. X
  119. X   }
  120. X   # At EOF or $_ is new alias, comment, or blank
  121. X}
  122. X
  123. Xexit 0;
  124. X
  125. X# end of aliasmooth
  126. SHAR_EOF
  127. if test 2069 -ne "`wc -c < 'aliasmooth'`"
  128. then
  129.     echo shar: error transmitting "'aliasmooth'" '(should have been 2069 characters)'
  130. fi
  131. chmod +x 'aliasmooth'
  132. fi # end of overwriting check
  133. #    End of shell archive
  134. exit 0
  135.