!++
! FILENAME: SKSPROCS.TPU 
! FUNCTION: Misc. procedures developed by SKS.
! 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:     18-NOV-1986 Original.
! HISTORY:  current.
! CONTENTS:
!           eve_start_notes
!           eve_select_capitalize
!           eve_inverse_word      
!           eve_count_char
!
!23456789A123456789B123456789C123456789D123456789E123456789F123456789G123456789H
!--
!*----------------------------------------------------------------------------*!

procedure sksprocs_module_ident 

  local file_date,
        module_vers;

  file_date := "-<( 30-DEC-1988 09:33:56.15 )>-";
  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;

!*----------------------------------------------------------------------------*!
!
! This procedure is for use with VAX Notes. It will move the contents of the
! current buffer to a new buffer and split the screen to display the both
! buffers.

procedure eve_start_notes

local   cut_range,
        o_n_buffer;

!Create a new buffer and window to hold the Old Note and make it read only.

o_n_buffer := create_buffer ("Old Note");
set (no_write, o_n_buffer);

cut_range := create_range(beginning_of(current_buffer),
                          end_of(current_buffer),none);
eve_two_windows;
unmap (eve$main_window);
map (eve$top_window, o_n_buffer);
eve$set_status_line (eve$top_window);

move_text(cut_range);
eve_other_window;

!eve_notes_margins;    ! Set the margins

endprocedure;

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

procedure eve_select_capitalize
!
local   number;

if not (eve$prompt_number ("", number,
        "Enter Type (1=ALL UPPER,2=all lower,3=Capitalize First Char,4=Inverse): ",
        "No type selected, capitalization not changed."))
then
  return;
endif;

message ("number " + str(number) );

CASE number
          
  [1] : eve_uppercase_word;
  [2] : eve_lowercase_word;
  [3] : eve_capitalize_word;
  [4] : eve_inverse_word;
 
  [otherwise] : message("INVALID choice.");

ENDCASE;

endprocedure;

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

! The procedure DEC forgot. SKS 28-DEC-1988
! Invert the case of the characters in the current word. If a select range is 
! specified, invert the case of all of the characters in the range. Works just
! like eve_uppercase_word and eve_lowercase_word

procedure eve_inverse_word      ! Invert case current word

local   word_range,             ! Range for current word
        the_range;

position (search (ANCHOR, FORWARD));    ! snap to text

if not eve$test_if_modifiable (current_buffer)
then
    eve$learn_abort;
    return (FALSE);
endif;

if eve$x_select_position <> 0
then
    if get_info (eve$x_select_position, "buffer") = current_buffer
    then
        the_range := select_range;
        change_case (the_range, INVERT);
        eve$x_select_position := 0;
!%IF eve$x_option_evej
!%THEN
!% eve$conversion_start;
!%ENDIF
        return (TRUE);
    endif;
endif;

if get_info (eve$x_found_range, "type") = RANGE
then
    if get_info (eve$x_found_range, "buffer") = current_buffer
    then
        change_case (eve$x_found_range, INVERT);
!%IF eve$x_option_evej
!%THEN
!% eve$conversion_start;
!%ENDIF
        return (TRUE);
    endif;
endif;

word_range := eve$current_word;
if word_range <> 0
then
    change_case (word_range, INVERT);
endif;
!%IF eve$x_option_evej
!%THEN
!% eve$conversion_start;
!%ENDIF
return (TRUE);

endprocedure;

!*---------------------------------------------------------------------------*!
!
procedure eve_count_char
!
! This search procedure will count the number of occurrences of a single 
! character in a file.
!
local   number,          ! Decimal value of character to be found
        found,           ! Number of occurences found               
        target,          ! Target to be replaced.
        found_range;     ! Range of current occurrence

  if not (eve$prompt_number ("", number,
              "Decimal ASCII Character Number: ", "No number given."))
  then
    return;
  endif;

  found := 0;

  target := ANCHOR + ASCII(number);

  end_mark := end_of(current_buffer);
  position(beginning_of(current_buffer));

  message ("Searching...");

  loop
    exitif mark(none) = end_mark;
    found_range := search_quietly(target, forward);

    if found_range <> 0 then
      found := found + 1;
    endif;

    move_horizontal (1);

  endloop;

  if found = 1 then
    message ("There was 1 character found in the file.");
  else
    message ("There were " + str(found) + " characters found in the file");
  endif;

endprocedure;

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


