home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / news / cnews.tar / util / canonsys.awk < prev    next >
Text File  |  1993-06-03  |  858b  |  39 lines

  1. # canonicalise the sys file:
  2. # delete comments & leading whitespace, collapse continued lines
  3. # rewritten to avoid assignment to $0, which is broken in older awks
  4. # rewritten again (based on an idea from Charles Lindsey) to avoid
  5. #  problems with awks that don't like very long print/printfs
  6. BEGIN { midline = 0 }
  7. /^#/ {                # comment
  8.     if (midline)
  9.         print "mid-line comment in sys" | "cat >&2"
  10.     next
  11. }
  12. /^[\t ]*$/ {            # empty line
  13.     if (midline)
  14.         print "mid-line empty line in sys" | "cat >&2"
  15.     next
  16. }
  17. {
  18.     # strip leading white space
  19.     for (n = 1; substr($0, n, 1) ~ /^[\t ]/; n++)
  20.         {}
  21.     thisln = substr($0, n)
  22. }
  23. /\\$/ {                # continued line
  24.     printf "%s", substr(thisln, 1, length(thisln)-1)
  25.     midline = 1
  26.     next
  27. }
  28. {                # non-continued line
  29.     print thisln
  30.     midline = 0
  31.     next
  32. }
  33. END {
  34.     if (midline) {
  35.         print "unterminated line in sys" | "cat >&2"
  36.         printf "\n"
  37.     }
  38. }
  39.