FUNCTION $wrapped_block_text, $wbt (
  string: string 0..256 = $required
  maximum_line_length: integer 18..255 = 132
  maximum_line_count: integer 13..247 = 247
  )

" PURPOSE:
" This function generates a series of lines of block text for the banner page.
" The length of these lines conforms to the parameter MAXIMUM_LINE_LENGTH, and
" the total number of lines conforms to the parameter MAXIMUM_LINE_COUNT.
"
" DESIGN:
" Calculate the number of block characters that will appear on a line and the
" total number of lines to be generated from the STRING parameter. Call the
" $BLOCK_TEXT function on as many portions of the string that is necessary
" and append the value returned from that function to the return value of
" this function.
"
" NOTE:
" This function is a support function for the GENERATE_BANNER_PAGE procedure.
" It is oriented toward generating lines of block text that currently appear
" on banner pages generated by CDCNET, and provides an interface to the
" $BLOCK_TEXT function that obeys page length & width limits.
"
" The minimum value for MAXIMUM_LINE_LENGTH is obtained by adding the number
" of blanks for indendation to the width of one block character. The maximum
" value is the maximum page width that CDCNET supports for batch devices.
"
" The minimum value for MAXIMUM_LINE_COUNT is the length of one block text
" character. The maximum value is the greatest multiple of the length of a
" block character that is less than the maximum number of lines possible on a
" single printed page for a CDCNET batch device.

" Soft constants for documentation.
  VAR
    blanks_for_indentation: integer 1..5 = 5
    block_char_length: integer 1..13 = 13
    block_char_width: integer 1..13 = 13
    lines_from_$block_text: integer 1..10 = 10
  VAREND

  VAR
    append_index: integer
    block_lines_from_string: integer
    chars_for_block_line: string 1..256
    current_block_line: integer
    current_offset_in_string: integer
    number_of_block_chars_on_line: integer
    return_value: list of string 0..256
    current_block_line_text: list of string 0..256
  VAREND

" Calculate the number of block characters that will fit on one line base on the maximum line
" length specified by the caller and constants associated to the banner page layout.

  number_of_block_chars_on_line = ((maximum_line_length - blanks_for_indentation)/block_char_width)
  IF ((maximum_line_length - blanks_for_indentation) - (number_of_block_chars_on_line * block_char_width)) =..
         10 THEN
    number_of_block_chars_on_line = number_of_block_chars_on_line + 1
  IFEND

" Calculate the number of block lines that will be generated from the string
" based on the width of the block text characters and the number of characters
" in the string.  Check if an additional block line needs to be generated for
" the last few characters on the line which may not fill the full line width.

  block_lines_from_string = $integer(($strlen(string)/number_of_block_chars_on_line))
  IF $mod($strlen(string), number_of_block_chars_on_line) <> 0 THEN
    block_lines_from_string = block_lines_from_string + 1
  IFEND

" Ensure the number of block lines to be generated from the string conforms to
" the maximum line count parameter.  Partial block lines are not printed so the
" integer math rounds the line count down properly.

  IF (block_lines_from_string * block_char_length)> maximum_line_count THEN
    block_lines_from_string = $integer((maximum_line_count/block_char_length))
  IFEND

  FOR current_block_line = 1 TO block_lines_from_string DO

" Find the position in the string which is the start of this block line.

    current_offset_in_string = ((current_block_line - 1)* number_of_block_chars_on_line) + 1

" Pass the characters for this block line to the $BLOCK_TEXT function.

    chars_for_block_line = $substring(string, current_offset_in_string, number_of_block_chars_on_line)
    current_block_line_text = $block_text(chars_for_block_line)

" Append the output of the $BLOCK_TEXT function to the return value of this function.

    FOR append_index = 1 TO lines_from_$block_text DO
      return_value = $add(..
            $substring(' ', 1, blanks_for_indentation, ' ')//current_block_line_text(append_index) ..
            return_value)
    FOREND

" Append the necessary blank lines to the return value of this function.

    FOR append_index = 1 TO (block_char_length - lines_from_$block_text) DO
      return_value = $add((' ') return_value)
    FOREND
  FOREND
  EXIT function WITH $reverse(return_value)

FUNCEND $wrapped_block_text
