home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume22 / nn6.4 / part21 / format.awk < prev    next >
Text File  |  1990-06-07  |  2KB  |  157 lines

  1. BEGIN {
  2.     linebuf = indent = ""
  3.     curcol = indcol = 0
  4.     maxcol = 78
  5.     progname = ""
  6.     firstsh = 1
  7.     numcol = 0
  8.     spacing = 1
  9.     wordspace = " "
  10.     tab = sprintf("%c",9)
  11. }
  12.  
  13. /^\.SH / {
  14.     if (firstsh == 0) printf("%s\n\n", linebuf)
  15.     firstsh = 0
  16.  
  17.     printf("From: %s\nSubject:", progname);
  18.     for (i = 2; i <= NF; i++) printf(" %s", $i);
  19.     printf("\n\n")
  20.  
  21.     linebuf = indent = ""
  22.     curcol = indcol = 0
  23.     next
  24. }
  25.  
  26. /^\.TH / {
  27.     progname = $2
  28.     next
  29. }
  30.  
  31. /^\.UC / {
  32.     next
  33. }
  34.  
  35. /^\.br/ || /^\.sp/ {
  36.     if (linebuf != indent) {
  37.         printf("%s\n", linebuf)
  38.     }
  39.     linebuf = indent
  40.     curcol = indcol
  41.     next
  42. }
  43.  
  44. /^\.PP/ {
  45.     if (linebuf != indent) printf("%s\n", linebuf)
  46.  
  47.     printf("\n")
  48.  
  49.     linebuf = "   " ; curcol = 3
  50.     indent = "" ; indcol = 0
  51.     next
  52. }
  53.  
  54. /^\.LP/ {
  55.     if (linebuf != indent) printf("%s\n", linebuf)
  56.  
  57.     printf("\n")
  58.  
  59.     linebuf = indent = ""
  60.     curcol = indcol = 0
  61.     next
  62. }
  63.  
  64. /^\.TP/ {
  65.     if (linebuf != indent) printf("%s\n", linebuf)
  66.  
  67.     printf("\n")
  68.  
  69.     getline; linebuf = $0
  70.     indent = "     "
  71.     curcol = indcol = 5
  72.     if (length(linebuf) >= 5) {
  73.         printf("%s\n", linebuf)
  74.         linebuf = indent
  75.     } else {
  76.         while (length(linebuf) < 4) linebuf = linebuf " "
  77.     }
  78.     next
  79. }
  80.  
  81. /^\.\\"ta/ {
  82.     for (numcol = 2; numcol <= NF; numcol++) tabcol[numcol-1] = $numcol
  83.     numcol = NF
  84.     next
  85. }
  86.  
  87. /^\.DT/ {
  88.     numcol = 0
  89.     next
  90. }
  91.  
  92. numcol != 0 {
  93.     j = length($0)
  94.     k = 0
  95.     g = 1
  96.     for (i = 1; i<=j; i++) {
  97.         while (k < tabcol[g]) {
  98.             printf(" ")
  99.             k++
  100.         }
  101.         c = substr($0,i,1)
  102.         if (c == tab) {
  103.             g++
  104.         } else {
  105.             printf("%s", c)
  106.             k++
  107.         }
  108.     }
  109.     printf("\n")
  110.     next
  111. }
  112.  
  113. /^[     ]/ {
  114.     if (linebuf != indent) printf("%s\n",linebuf)
  115.     linebuf = indent "     "
  116.     curcol = indcol+5
  117. }
  118.  
  119. {
  120.     word = 1
  121.     wordspace = " "
  122.     spacing = 1
  123. }
  124.  
  125. /^\.[IB] / {
  126.     word = 2
  127. }
  128.  
  129. /^\.[IB]R / {
  130.     wordspace = ""
  131.     word = 2
  132.     spacing = 0
  133. }
  134.  
  135. {
  136.      sep = " "
  137.     if (linebuf == indent) sep = ""
  138.  
  139.     while (word <= NF) {
  140.         k = length($word)
  141.         if ((curcol + k) > maxcol) {
  142.             printf("%s\n", linebuf)
  143.             linebuf = indent
  144.             curcol = indcol
  145.             sep = ""
  146.         }
  147.         linebuf = linebuf sep $word
  148.         sep = wordspace
  149.         curcol += spacing + k
  150.         word++
  151.     }
  152. }
  153.  
  154. END {
  155.     if (linebuf != indent) printf("%s\n\n", linebuf)
  156. }
  157.