home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1999 April / PCO0499.ISO / filesbbs / os2 / apach134.arj / APACH134.ZIP / src / helpers / ppl.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1998-09-16  |  1.1 KB  |  56 lines

  1. #!/bin/sh
  2. ##
  3. ##  ppl.sh -- pretty print a colon-sperarated list by avoiding 
  4. ##            `tr' and `fmt' because these tools are different
  5. ##            between Unix platforms
  6. ##
  7. ##  Written by Ralf S. Engelschall <rse@apache.org>
  8. ##  for pretty printing lists in the --help option of
  9. ##  Apache's Autoconf-style Interface (APACI)
  10. ##
  11. #
  12. # This script falls under the Apache License.
  13. # See http://www.apache.org/docs/LICENSE
  14.  
  15.  
  16. list=`
  17. IFS=:
  18. for entry in $*; do
  19.     if [ ".$entry" != . ]; then
  20.         echo $entry
  21.     fi
  22. done |\
  23. sort |\
  24. awk '
  25.     BEGIN { list = ""; n = 0; }
  26.     { 
  27.         list = list $1;
  28.         n = n + 1;
  29.         if (n == 1 || n == 2) {
  30.             list = list ":";
  31.         }
  32.         if (n == 3) {
  33.             list = list "\n";
  34.             n = 0;
  35.         }
  36.     }
  37.     END { print list; }
  38. '`
  39. IFS='
  40. '
  41. for entry in $list; do
  42.     echo $entry |\
  43.     awk -F: '
  44.         { printf("%-15s %-15s %-15s\n", $1, $2, $3); }
  45.     '
  46. done |\
  47. awk '{ 
  48.     if (length($0) > 48) { 
  49.         printf("%s\n", substr($0, 0, 47));
  50.     } else { 
  51.         print $0; 
  52.     }
  53. }' |\
  54. sed -e 's/^/                        [/' -e 's/$/]/'
  55.  
  56.