?? TITLE := 'cli$output_procedures' ??
?? NEWTITLE := 'cli$output_procedures "global" declarations', EJECT ??
{
{ PURPOSE:
{   The purpose of this "module" is to provide simple output procedures for
{   those programs which write to a legible, but not a list, file.
{
{ NOTES:
{   . clp$op_initialize must be called before any other procedure in this
{     "module" is called. It will initialize certain global variables used by
{     the other modules and which may be accessed by the caller.
{
{   . Names of global variables and procedures in this module follow the
{     standard naming conventions with OP_ being appended to the first $ of
{     each name.
{

?? PUSH (LISTEXT := ON) ??
*IF NOT $true(osv$unix)
*copyc amt$page_format
*copyc amt$page_length
*copyc amt$page_width
*IFEND
*copyc clt$command_line
*copyc clt$command_line_index
*copyc clt$command_line_size
?? POP ??
*IF NOT $true(osv$unix)
*copyc amp$put_next
*ELSE
*copyc amp_put_next
*IFEND
*copyc clp$convert_integer_to_string
*copyc clp$convert_real_to_string

  VAR
    clv$op: [STATIC] record
*IF NOT $true(osv$unix)
      file_id: amt$file_identifier,
*IFEND
      get_out: ^procedure (    stat: ost$status),
      line: string (amc$max_page_width),
      line_size: 0 .. amc$max_page_width,
      page_width: amt$page_width,
    recend;

?? TITLE := 'clp$op_initialize', EJECT ??

  PROCEDURE clp$op_initialize
*IF NOT $true(osv$unix)
    (    file_id: amt$file_identifier;
         page_width: amt$page_width;
*ELSE
    (    page_width: amt$page_width;
*IFEND
         get_out: ^procedure (    stat: ost$status));


*IF NOT $true(osv$unix)
    clv$op.file_id := file_id;
*IFEND
    clv$op.page_width := page_width;
    clv$op.line := '';
    clv$op.line_size := 0;
    clv$op.get_out := get_out;

  PROCEND clp$op_initialize;
?? TITLE := 'clp$op_add_integer_to_line', EJECT ??

  PROCEDURE [INLINE] clp$op_add_integer_to_line
    (    int: integer);

    VAR
      ignore_status: ost$status,
      int_string: ost$string;


    clp$convert_integer_to_string (int, 10, FALSE, int_string, ignore_status);
    clp$op_add_to_line (int_string.value (1, int_string.size));

  PROCEND clp$op_add_integer_to_line;
?? TITLE := 'clp$op_add_real_to_line', EJECT ??

*IF NOT $true(osv$unix)
  PROCEDURE [INLINE] clp$op_add_real_to_line
    (    real_number: longreal);

    VAR
      ignore_status: ost$status,
      real_string: ost$string;


    clp$convert_real_to_string (real_number, clc$max_real_number_digits,
          real_string, ignore_status);
    clp$op_add_to_line (real_string.value (1, real_string.size));

  PROCEND clp$op_add_real_to_line;
*IFEND
?? TITLE := 'clp$op_add_to_line', EJECT ??

  PROCEDURE clp$op_add_to_line
    (    str: string ( * ));

    VAR
      size: 0 .. osc$max_string_size + 1;


    size := STRLENGTH (str);
    IF (clv$op.line_size + size) <= clv$op.page_width THEN
      clv$op.line (clv$op.line_size + 1, size) := str;
      clv$op.line_size := clv$op.line_size + size;
      RETURN;
    IFEND;

    clp$op_flush_line;
    clp$op_tab_line (3);
    clv$op.line (clv$op.line_size + 1, size) := str;
    clv$op.line_size := clv$op.line_size + size;

  PROCEND clp$op_add_to_line;
?? TITLE := 'clp$op_tab_line', EJECT ??

  PROCEDURE clp$op_tab_line
    (    column: integer);


    IF (clv$op.line_size < column - 1) AND
          (clv$op.line_size <= clv$op.page_width) THEN
      clv$op.line (clv$op.line_size + 1, * ) := ' ';
      clv$op.line_size := column - 1;
    IFEND;

  PROCEND clp$op_tab_line;
?? TITLE := 'clp$op_flush_line', EJECT ??

  PROCEDURE [INLINE] clp$op_flush_line;


    IF clv$op.line_size > 0 THEN
      clp$op_put_line (clv$op.line (1, clv$op.line_size));
    IFEND;

  PROCEND clp$op_flush_line;
?? TITLE := 'clp$op_put_line', EJECT ??

  PROCEDURE clp$op_put_line
    (    line: string ( * ));

    VAR
*IF NOT $true(osv$unix)
      ignore_byte_address: amt$file_byte_address,
      local_status: ost$status;
*ELSE
      data_line: string (256),
      length: integer,
      local_status: ost$status,
      stat: integer;
*IFEND


*IF NOT $true(osv$unix)
    amp$put_next (clv$op.file_id, ^line, STRLENGTH (line), ignore_byte_address,
          local_status);
*ELSE
    length := STRLENGTH (line);
    data_line := line;
    amp_put_next (data_line, length);
    local_status.normal := TRUE;
*IFEND

    IF NOT local_status.normal THEN
      clv$op.get_out^ (local_status);
    IFEND;
    clv$op.line_size := 0;
    clv$op.line := '';

  PROCEND clp$op_put_line;
?? TITLE := 'clp$op_start_line', EJECT ??

  PROCEDURE [INLINE] clp$op_start_line
    (    str: string ( * ));


    clv$op.line := str;
    clv$op.line_size := STRLENGTH (str);

  PROCEND clp$op_start_line;
?? TITLE := 'clp$op_echo', EJECT ??
{
{ PURPOSE:
{   The purpose of this procedure is to echo the given line to the
{   output file.
{

  PROCEDURE clp$op_echo
    (    line: ^clt$command_line);

    CONST
      continuation_mark_char = '.',
      line_prefix = '{ ',
      line_prefix_size = 2,
      min_continuation_mark = '..',
      min_continuation_mark_size = 2;

    VAR
      continuation_line: boolean,
      index: clt$command_line_index,
      line_size: clt$command_line_size,
      size: clt$command_line_size;


    line_size := STRLENGTH (line^);
    continuation_line := (line_size >= min_continuation_mark_size) AND
          (line^ (line_size - min_continuation_mark_size + 1,
          min_continuation_mark_size) = min_continuation_mark);
    IF continuation_line THEN
      line_size := line_size - min_continuation_mark_size;
      WHILE (line_size > 0) AND (line^ (line_size) = continuation_mark_char) DO
        line_size := line_size - 1;
      WHILEND;
    IFEND;

    index := 1;
    WHILE TRUE DO
      clp$op_start_line (line_prefix);
      size := line_size - index + 1;
      IF (line_prefix_size + size + ($INTEGER (continuation_line) *
            min_continuation_mark_size)) <= clv$op.page_width THEN
        clp$op_add_to_line (line^ (index, size));
        IF continuation_line THEN
          clp$op_add_to_line (min_continuation_mark);
        IFEND;
        clp$op_flush_line;
        RETURN;
      IFEND;
      size := clv$op.page_width - line_prefix_size -
            min_continuation_mark_size;
      WHILE (size > 0) AND (line^ (index + size - 1) =
            continuation_mark_char) DO
        size := size - 1;
      WHILEND;
      IF size = 0 THEN
        size := clv$op.page_width - line_prefix_size -
              min_continuation_mark_size;
      IFEND;
      clp$op_add_to_line (line^ (index, size));
      clp$op_add_to_line (min_continuation_mark);
      clp$op_flush_line;
      index := index + size;
    WHILEND;

  PROCEND clp$op_echo;
?? OLDTITLE ??
