!++
! FILENAME: COMMENT_LINES.TPU
! FUNCTION: This file contains procedures for inserting comment lines.
! AUTHOR:   Steven K. Shapiro, (C) Copyright SKS Enterprises, Austin TX.
!                                  All Rights Reserved.
!
!           The format, structure and contents of this file are the sole
!           property  of Steven K. Shapiro  and are  copyrighted to  SKS
!           Enterprises, Austin Texas.
!
!           The information may be freely distributed, used and modified
!           provided  that the  information in this  header block is not
!           changed, altered, disturbed or modified in any way.
!
! DATE:     25-AUG-1987 Original.
! HISTORY:  current.
! CONTENTS:
!           eve_comment_line
!           eve_pascom_line
!           eve_comcom_line
!           eve_plicom_line
!           eve_tpucom_line
!           eve_forcom_line
!           eve_rnocom_line
!           eve_ccom_line
!           eve_maccom_line
!           eve_draw_comment_box
!
!23456789A123456789B123456789C123456789D123456789E123456789F123456789G123456789H
!--
!*----------------------------------------------------------------------------*!

procedure comment_lines_module_ident

  local file_date,
        module_vers;

  file_date := "-<( 29-DEC-1988 11:40:10.49 )>-";
  module_vers := substr(file_date,5,2) +
                 substr(file_date,8,3) +
                 substr(file_date,14,2) +
                 substr(file_date,17,5) ;

  return module_vers;

endprocedure;

!*----------------------------------------------------------------------------*!

! Figure out what type of file is being edited via the buffer name extension
! and dispatch the appropriate comment line procedure.

procedure eve_comment_line

local file_name,
      file_type;

file_name := get_info (current_buffer,"name");
file_type := file_parse (file_name,"","",TYPE);

CASE file_type

  [".PAS"] : eve_pascom_line;
  [".PLI"] : eve_plicom_line;
  [".TPU"] : eve_tpucom_line;
  [".MAC"] : eve_maccom_line;
  [".FOR"] : eve_forcom_line;
  [".C"]   : eve_ccom_line;
  [".COM"] : eve_comcom_line;
  [".RNO"] : eve_rnocom_line;
  [".TXT"] : eve_tpucom_line;

  [otherwise] : eve_tpucom_line;

ENDCASE;

endprocedure;

!*----------------------------------------------------------------------------*!


procedure eve_pascom_line

! This procedure will place a comment line at the current cursor location.

    split_line;
    copy_text("{------------------------------------------------------------------------------}");
    split_line;

endprocedure;


!*----------------------------------------------------------------------------*!

procedure eve_comcom_line

! This procedure will place a comment line at the current cursor location.

    split_line;
    copy_text("$!------------------------------------------------------------------------------");
    split_line;

endprocedure;


!*----------------------------------------------------------------------------*!

procedure eve_plicom_line

! This procedure will place a comment line at the current cursor location.

    split_line;
    copy_text("/*----------------------------------------------------------------------------*/");
    split_line;

endprocedure;

!*----------------------------------------------------------------------------*!

procedure eve_tpucom_line

! This procedure will place a comment line at the current cursor location.

    split_line;
    copy_text("!*----------------------------------------------------------------------------*!");
    split_line;

endprocedure;

!*----------------------------------------------------------------------------*!

procedure eve_forcom_line

! This procedure will place a comment line at the current cursor location.

    split_line;
    copy_text("C*----------------------------------------------------------------------------*C");
    split_line;

endprocedure;

!*----------------------------------------------------------------------------*!

procedure eve_rnocom_line

! This procedure will place a comment line at the current cursor location.

    split_line;
    copy_text(".!*---------------------------------------------------------------------------*!");
    split_line;

endprocedure;

!*----------------------------------------------------------------------------*!

procedure eve_ccom_line

! This procedure will place a comment line at the current cursor location.

    split_line;
    copy_text("/*----------------------------------------------------------------------------*/");
    split_line;

endprocedure;

!*----------------------------------------------------------------------------*!

procedure eve_maccom_line

! This procedure will place a comment line at the current cursor location.

    split_line;
    copy_text(".!*---------------------------------------------------------------------------*!");
    split_line;

endprocedure;

!*----------------------------------------------------------------------------*!

! Draw a comment box for .PAS, .C, .PLI, .FOR, .TPU and .TXT files. The type of 
! box drawn is based on the filename extension.

procedure eve_draw_comment_box

local
  file_name,
  file_type,
  box_char,
  saved_mode,
  end_column,
  start_column,
  temp,
  end_select,
  top_text,
  bottom_text;

! check for no select active

if evedt_v_begin_select = 0
then
  message("Rectangular select not active.");
  return
endif;

file_name := get_info (current_buffer,"name");
file_type := file_parse (file_name,"","",TYPE);

! set insert mode

saved_mode := evedt_set_mode(insert);

! make sure there is a character at the corner of the box opposite the
! begin_select mark.  if the end_select mark is before the begin_select mark,
! juggle the markers so that begin_select precedes end_select.

evedt_pad_blank;

if mark(none) >= evedt_v_begin_select
then
  end_select := mark(none)
else
  end_select := evedt_v_begin_select;
  evedt_v_begin_select := mark(none);
  position(end_select)
endif;

! figure out what column the box ends in and set end_column there. then, clear
! out the video on evedt_v_begin_select.  figure out the start column.
              
end_column := evedt_current_column;
position(evedt_v_begin_select);
evedt_v_begin_select := mark(none);
start_column := evedt_current_column;

! we may have the upper right and lower left corners of the box selected.  if
! so, start_column and end_column need to be reversed.

if start_column > end_column
then
  temp := end_column;
  end_column := start_column;
  start_column := temp
endif;

! we may be building the box on the first line of the buffer.  in that case, we
! must put a new top line in the buffer.

move_horizontal(-current_offset);

if mark(none) = beginning_of(current_buffer)
then
  split_line;
  position(beginning_of(current_buffer));
  copy_text(evedt_blank_chars(start_column));
  move_vertical(1);
  move_horizontal(-current_offset)
endif;

! determine type of character to use for the box

CASE file_type

  [".PAS"] : box_char  := "-";
  [".C"]   : box_char  := "*";
  [".PLI"] : box_char  := "*";
  [".FOR"] : box_char  := "C";
  [".TPU"] : box_char  := "!";
  [".TXT"] : box_char  := "*";

!  [".COM"] : box_char  := "?";
!  [".MAC"] : box_char  := "?";
!  [".RNO"] : box_char  := "?";

  [otherwise] : box_char  := "*";

ENDCASE;

! determine start / end chars for comment box based on file extension

CASE file_type

  [".PAS"] : top_text := '{' + evedt_blank_chars(end_column-start_column+1) + box_char;
  [".C"]   : top_text := '/' + evedt_blank_chars(end_column-start_column+1) + box_char;
  [".PLI"] : top_text := '/' + evedt_blank_chars(end_column-start_column+1) + box_char;
  [".FOR"] : top_text := 'C' + evedt_blank_chars(end_column-start_column+1) + box_char;
  [".TPU"] : top_text := '!' + evedt_blank_chars(end_column-start_column+1) + box_char;
  [".TXT"] : top_text := '*' + evedt_blank_chars(end_column-start_column+1) + box_char;

!  [".MAC"] : 
!  [".COM"] : 
!  [".RNO"] : 

  [otherwise] : top_text := '/' + evedt_blank_chars(end_column-start_column+1) + box_char;

ENDCASE;

CASE file_type

  [".PAS"] : bottom_text := box_char + evedt_blank_chars(end_column-start_column+1) + '}';
  [".C"]   : bottom_text := box_char + evedt_blank_chars(end_column-start_column+1) + '/';
  [".PLI"] : bottom_text := box_char + evedt_blank_chars(end_column-start_column+1) + '/';
  [".FOR"] : bottom_text := box_char + evedt_blank_chars(end_column-start_column+1) + 'C';
  [".TPU"] : bottom_text := box_char + evedt_blank_chars(end_column-start_column+1) + '!';
  [".TXT"] : bottom_text := box_char + evedt_blank_chars(end_column-start_column+1) + '*';

!  [".MAC"] : 
!  [".COM"] : 
!  [".RNO"] : 

  [otherwise] : bottom_text := box_char + evedt_blank_chars(end_column-start_column+1) + '/';

ENDCASE;

! move back one line and put in the top line of the box

translate(top_text, box_char, " ");
translate(bottom_text, box_char, " ");
set(overstrike, current_buffer);
move_vertical(-1);

! replace all tabs with blanks on this line and pad it, if we need to.

evedt_replace_tabs_with_blanks_and_pad(end_column + 1);

if start_column <> 0
then
  move_horizontal(start_column - 1)
endif;

copy_text(top_text);
move_vertical(1);
move_horizontal(-current_offset);

! step through the selected lines, putting vertical bars on either side of the
! selected text.

loop
  exitif mark(none) > end_select;

! replace all tabs with blanks on this line, if we need to.

  evedt_replace_tabs_with_blanks_and_pad(end_column + 1);


! if start_column is zero, we must insert a vertical bar to do the left column,
! then put the right vertical bar one column farther out than normal.

  if start_column = 0
  then
    set(insert, current_buffer);
    copy_text(box_char);
    set(overstrike, current_buffer);
    move_horizontal(end_column + 1);
  else
    move_horizontal(start_column-1);
    copy_text(box_char);
    move_horizontal(end_column - current_offset + 1)
  endif;

  copy_text(box_char);
  move_horizontal(-current_offset);
  move_vertical(1)
endloop;

! now put in the bottom line of the box.

! replace all tabs with blanks on this line, if we need to.

evedt_replace_tabs_with_blanks_and_pad(end_column + 1);

if start_column <> 0
then
  move_horizontal(start_column - 1)
endif;

copy_text(bottom_text);

! position to the beginning of the cut area, reset begin_select, restore old
! insert/overstrike setting

position(evedt_v_begin_select);
evedt_v_begin_select := 0;
move_horizontal(-current_offset);

if start_column = 0
then
  move_horizontal(1)
else
  move_horizontal(start_column)
endif;

set(saved_mode, current_buffer)

endprocedure

