home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / net / bind-contrib.tar.gz / bind-contrib.tar / contrib / hostmaint / txt2host.awk < prev    next >
Encoding:
AWK Script  |  1996-10-25  |  1.3 KB  |  58 lines

  1. BEGIN { origin = "msu.edu"; FS = ":" }
  2. /^HOST/ {
  3.   nf = split($0,f,FS)
  4.   for (i=2; i<= 6; i++) {
  5.     sub("^  *","",f[i])
  6.     sub("  *$","",f[i])
  7.   }
  8.   ip = f[2]
  9.   names = f[3]
  10.   cpu = f[4]
  11.   opsys = f[5]
  12.   proto = f[6]
  13.   opts = f[7]
  14.   for (i=8; i <= nf; i++)  opts = opts FS f[i]
  15.   global = 0
  16.   noabbr = 0;
  17.   comment = "";
  18.   for (;;) {
  19.     sub("^  *","",opts)
  20.     if (substr(opts,1,8) == "comment=") {
  21.       comment = substr(opts,9,length(opts));
  22.       break
  23.     }
  24.     c = index(opts,",")
  25.     if (c) opt = substr(opts,1,c-1)
  26.     else opt = opts
  27.     sub("  *$","",opt)
  28.     if (opt == "global") {
  29.       global = 1;
  30.     }
  31.     if (opt == "noabbr") {
  32.       noabbr = 1;
  33.     }
  34.     if (c) opts = substr(opts,c+1,length(opts))
  35.     else break
  36.   }
  37.   if (cpu != "" || opsys != "") comment = opsys ": " cpu ": " comment
  38.   nn = split(names,nlist,",")
  39.   printf "%s\t", ip
  40.   for (n=1; n <= nn; n++) {
  41.     name = nlist[n];
  42.     sub("^  *","",name)
  43.     sub("  *$","",name)
  44.     np = split(name,part,".")
  45.     printf "%s ", name;
  46.     if (np > 3 && global) printf "%s.%s.%s ",part[1], part[np-1], part[np];
  47.     if (np > 1 && ! noabbr) printf "%s ", part[1];
  48.   }
  49.   if (comment != "") printf "\t# %s", comment
  50.   printf "\n";
  51.   next;
  52. }
  53. /^#/ { print }
  54. /^[0-9]/ { print }
  55. /^;/ { print "#" substr($0,2,length($0)) }
  56. /^MX:/ { print "#" $0 }
  57. { next }
  58.