home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gnuawk.zip / awklib / eg / prog / labels.awk < prev    next >
Text File  |  1997-03-15  |  1KB  |  54 lines

  1. # labels.awk
  2. # Arnold Robbins, arnold@gnu.ai.mit.edu, Public Domain
  3. # June 1992
  4.  
  5. # Program to print labels.  Each label is 5 lines of data
  6. # that may have blank lines.  The label sheets have 2
  7. # blank lines at the top and 2 at the bottom.
  8.  
  9. BEGIN    { RS = "" ; MAXLINES = 100 }
  10.  
  11. function printpage(    i, j)
  12. {
  13.     if (Nlines <= 0)
  14.         return
  15.  
  16.     printf "\n\n"        # header
  17.  
  18.     for (i = 1; i <= Nlines; i += 10) {
  19.         if (i == 21 || i == 61)
  20.             print ""
  21.         for (j = 0; j < 5; j++) {
  22.             if (i + j > MAXLINES)
  23.                 break
  24.             printf "   %-41s %s\n", line[i+j], line[i+j+5]
  25.         }
  26.         print ""
  27.     }
  28.  
  29.     printf "\n\n"        # footer
  30.  
  31.     for (i in line)
  32.         line[i] = ""
  33. }
  34.  
  35. # main rule
  36. {
  37.     if (Count >= 20) {
  38.         printpage()
  39.         Count = 0
  40.         Nlines = 0
  41.     }
  42.     n = split($0, a, "\n")
  43.     for (i = 1; i <= n; i++)
  44.         line[++Nlines] = a[i]
  45.     for (; i <= 5; i++)
  46.         line[++Nlines] = ""
  47.     Count++
  48. }
  49.  
  50. END    \
  51. {
  52.     printpage()
  53. }
  54.