home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / v / vsnbl220.zip / LABCENT.SNO < prev    next >
Text File  |  1991-02-14  |  4KB  |  135 lines

  1. *    LABCENT.SNO
  2. *
  3. *    Reads mailing labels from standard input file,
  4. *    writes them to standard out centered in a W char x H line window,
  5. *    with F blank lines after each label.
  6. *
  7. *    For typical 3-1/2" x 15/16" labels, and 12 pitch type, use:
  8. *        W = 40, H = 5, F = 1
  9. *
  10. *    Set parameters W, H, and F as appropriate, then invoke
  11. *    the program with:
  12. *
  13. *    SNOBOL4 LABCENT <LABEL.IN >LABEL.OUT
  14. *
  15. *    Notes:    The input labels are expected to be left justified, as
  16. *        they would when output from a program like PC-FILE.
  17. *
  18. *        They remain left justified in the output, but positioned
  19. *        so that the longest line is centered on the label.
  20. *
  21. *        One or more blank lines must separate individual labels.
  22. *        There can be any number of blank lines between labels in
  23. *        the input file; they are discarded.
  24. *
  25. *        Labels containing more than H lines are displayed on the
  26. *        screen, and are not copied to the output.
  27. *
  28. *
  29. *    Format Definitions:
  30. *
  31.     W  = 40                    ;* Label Width
  32.     H  = 5                    ;* Max lines in label
  33.     F  = 1                    ;* Fill lines between labels
  34.  
  35.     &trim = 1
  36.     &anchor = 1
  37.  
  38.     label = array(H)            ;* Array to hold label
  39.     input(.input,5,W)            ;* Set input line width
  40.  
  41. ************************************************************************
  42. *
  43. *    Function Definitions
  44. *
  45. * READ_LABEL - Read Label from Input file.
  46. *
  47. *    number_of_lines = read_label(array)
  48. *
  49. *    Skips to first non-blank line, reads label into array argument,
  50. *    and returns the number of lines read as the function result.
  51. *
  52. *    Function fails if end-of-file read before a non-blank line found.
  53. *
  54. *    Labels too large for the given array are displayed on the screen,
  55. *    then ignored.
  56. *
  57.     DEFINE('read_label(a)line')        :(read_label_end)
  58. *    Scan for non-blank line
  59. read_label read_label = 0
  60. rl_0    line = input                :f(freturn)
  61.     DIFFER(line)                :f(rl_0)
  62.  
  63. *    Count line and store it away
  64. rl_1    read_label = read_label + 1
  65.     a[read_label] = line            :f(rl_2)
  66.  
  67. * Here for subsequent label lines.  Return on EOF or blank line.
  68.     line = input                :f(return)
  69.     DIFFER(line)                :s(rl_1) f(return)
  70.  
  71. * Here if too many lines in label.  Display label.
  72. rl_2    screen = 
  73.     read_label = 0
  74. rl_3    read_label = read_label + 1
  75.     screen = a[read_label]            :s(rl_3)
  76.     screen = line                :(read_label)
  77. read_label_end
  78.  
  79.  
  80. * SCAN_LABEL - Scan label for longest line.
  81. *
  82. *    max_width = scan_label(array,n_lines)
  83. *
  84. *    Returns the width of the longest line in an array.
  85. *
  86.     DEFINE('scan_label(a,n)i,line')        :(scan_label_end)
  87. scan_label
  88.     i = i + 1
  89.     gt(i,n)                    :s(return)
  90.     scan_label = gt(size(a[i]),scan_label) size(a[i])    :(scan_label)
  91. scan_label_end
  92.  
  93.  
  94. * WRITE_LABEL - Write out centered label.
  95. *
  96. *    write_label(array, n_lines, before, after, margin)
  97. *
  98. *
  99.     DEFINE('write_label(a,n,before,after,margin)i')
  100.     crlf = char(13) char(10)        ;* Carriage return/line feed
  101.                         :(write_label_end)
  102. write_label
  103. * Put out preceeding blank lines.
  104.     output = ge(before, 1) dupl(crlf,before - 1)
  105.  
  106. * Put out label.
  107.     i = 1
  108. wl_1    output = dupl(' ',margin) a[i]
  109.     i = lt(i,n) i + 1            :s(wl_1)
  110.  
  111. * Put out lines following label.
  112.     output = ge(after, 1) dupl(crlf,after - 1)    :(return)
  113. write_label_end
  114.  
  115.  
  116. ************************************************************************
  117. *
  118. * Main Loop.  Get and print a label.
  119. *
  120. * Read label
  121. main    n_lines = read_label(label)        :f(end)
  122.  
  123. * Get width of longest line
  124.     max    = scan_label(label,n_lines)
  125.  
  126. * Compute spacing parameters around label.
  127.     after = (H - n_lines) / 2
  128.     before = H - n_lines - after
  129.     margin = (W - max) / 2
  130.  
  131. * Write centered label
  132.     write_label(label,n_lines,before,after + F,margin)    :(main)
  133.  
  134. end
  135.