home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / news / cnews.tar / util / namecheck.awk < prev    next >
Text File  |  1994-11-27  |  2KB  |  71 lines

  1. # awk program to check newsgroup names for validity, rigorously
  2. # echo groupname | awk -f namecheck.awk
  3. # It may look like some things in per-component checking could be done
  4. # more efficiently by moving them into whole-name checking.  The presence
  5. # of encoded name components messes this up.
  6. NR == 1 {
  7.     # whole-name checks
  8.     bad = 1
  9.     if (NF == 0)
  10.         print "empty name"
  11.     else if (NF > 1)
  12.         print "white space in name"
  13.     else if ($1 ~ /^\./ || $1 ~ /\.$/ || $1 ~ /\.\./)
  14.         print "bad dot(s) in name"
  15.     else if ($1 !~ /^[a-zA-Z]/)    # A-Z is caught later
  16.         print "name does not begin with a letter"
  17.     else if ($1 ~ /^(junk|control)\./)
  18.         print "name starts with control or junk"
  19.     else
  20.         bad = 0
  21.     if (bad == 1)
  22.         exit 1
  23.  
  24.     # per-component checks
  25.     nc = split($1, cpt, ".")
  26.     for (i = 1; i <= nc; i++) {
  27.         bad = 1
  28.         c = cpt[i]
  29.         # some of these two-part tests may look like they could be
  30.         # simplified to one-parters, but some broken awks then fail
  31.         if (c ~ /^=/ && c !~ /^=\?[^=?]+\?[^=?]+\?[^?]+\?=$/)
  32.             print "name component resembles encoded word but isn't one"
  33.         else if (c ~ /^=/ && c !~ /^=[a-zA-Z0-9+_=?-]*=$/)
  34.             print "bad character in encoded name component"
  35.         else if (c ~ /^=/ && c !~ /^=\?[^?]+\?b\?/)
  36.             print "encoded name component does not use b encoding"
  37.         else if (c ~ /^=/)
  38.             bad = 0        # looks like an okay encoded word
  39.         else if (c ~ /^[0-9]*$/)
  40.             print "all-numeric name component"
  41.         else if (c !~ /^[a-zA-Z0-9]/)    # A-Z caught later
  42.             print "name component starts with non-alphanumeric"
  43.         else if (c !~ /[a-zA-Z]/)    # A-Z caught later
  44.             print "name component does not contain letter"
  45.         else if (c == "all" || c == "ctl")
  46.             print "`all' or `ctl' used as name component"
  47.         else if (length(c) > 14)
  48.             print "name component longer than 14 characters"
  49.         else if (c ~ /[A-Z]/)
  50.             print "uppercase letter(s) in name"
  51.         else if (c ~ /[^a-z0-9+_-]/)
  52.             print "illegal character(s) in name"
  53.         else if (c ~ /--|__|\+\+./)    # sigh, c++ etc must be allowed
  54.             print "repeated punctuation in name"
  55.         else if (c == cpt[i+1])
  56.             print "repeated component(s) in name"
  57.         else
  58.             bad = 0
  59.  
  60.         if (bad == 1)
  61.             exit 1
  62.     }
  63. }
  64. NR >= 2 {
  65.     print "newline(s) in name"
  66.     exit 1
  67. }
  68. END {
  69.     exit 0
  70. }
  71.