!       ABEL_INIT.TPU
!
!       Table of Contents as of 27-Mar-1988
!
!       Procedure name              Page    Description
!       --------------              ----    -----------
!
!       eveplus_insert_text            1    [EPK] Insert text regardless of mode
!       eveplus_search_quietly         1    [EPK] Search w/o "String not found"
!       eveplus_replace                1    [EPK] Replace old text with new
!       eveplus_find_buffer            2    [EPK] Xlate buffer name to pointer
!       eveplus_defined_procedure      2    [EPK] See if a procedure is defined
!       eveplus_set_shift_key          3    [EPK] Define shift key, save old
!       eveplus_key                    4    [EPK] Redefine key, save old def'n
!       eveplus_restore_key            5    [EPK] Restore a saved key definition
!       tpu$init_procedure             6    Main initialization routine
!       eve$init_variables             7    Initialize global variables
!       abl$user_init                  8    Execute the Abel initialization file


!                                                                       Page 1

!   EVEPLUS_KERNEL.TPU
!       The following routines are from the EvePlus kernel [EPK]

procedure eveplus_insert_text(the_text) ! [EPK] Insert text regardless of mode

! Insert text, even in overstrike mode
!
! Parameter:
!   the_text        str/rng     text to insert
!
! Source:
!   Eveplus

eve$insert_text(the_text);
endprocedure;


procedure eveplus_search_quietly        ! [EPK] Search w/o "String not found"
    (target, dir)

! Search without "String not found" message
!
! Parameters:
!   target          str/rng     string or range to find
!   dir             keyword     direction
!
! Source:
!   Eveplus

on_error
    return(0);
endon_error;
return(search(target, dir));
endprocedure;


procedure eveplus_replace(old, new)     ! [EPK] Replace old text with new

! Simple replace function
!
! Parameters:
!   old             str/pat     string to search for
!   new             string      replacement string
!
! Source:
!   Eveplus

local
    ptr,
    old_mode;
on_error
    return(0);
endon_error;
ptr := search(old, current_direction);
if (ptr <> 0) then
    position(ptr);
    erase(ptr);
    eve$insert_text(new);
    return(1);
else
    return(0);
endif;
endprocedure;



!                                                                       Page 2


procedure eveplus_find_buffer           ! [EPK] Xlate buffer name to pointer
    (buffer_name)

! Translate a buffer name to a buffer pointer
!
! Parameters:
!   buffer_name     string      string containing the buffer name
!
! Source:
!   Eveplus

local
    the_buffer,     ! Used to hold the buffer pointer
    the_name;       ! A read/write copy of the name

    the_name := buffer_name;
    change_case(the_name, UPPER);
    the_buffer := get_info(buffers, "first");
    loop
        exitif (the_buffer = 0);
        exitif (the_name = get_info(the_buffer, "name"));
        the_buffer := get_info(buffer, "next");
    endloop;
    return the_buffer;

endprocedure


procedure eveplus_defined_procedure(x)  ! [EPK] See if a procedure is defined

! Returns true if x contains a defined procedure
!
! Parameters:
!   x               string      procedure name
!
! Source:
!   Eveplus

local   temp;

on_error
    if (error = tpu$_multiplenames) then
        return(1);
    else
        return(0);
    endif;
endon_error;
    temp := expand_name(x, PROCEDURES);
    return(1);
endprocedure;



!                                                                       Page 3


procedure eveplus_set_shift_key         ! [EPK] Define shift key, save old
    (new_shift_key)

! Define shift key, save old
!
! Parameters:
!   new_shift_key   keyword     key to use as shift key
!
! Source:
!   Eveplus

local
    old_shift_key;
old_shift_key := eveplus_g_shift_key;
eveplus_g_shift_key := new_shift_key;
if new_shift_key =  ctrl_y_key then
    set (shift_key, key_name (pf1, shift_key));
    undefine_key ( old_shift_key );
else
    set ( shift_key, new_shift_key );
    define_key ("execute (lookup_key (eve$get_shift_key, program))",
            new_shift_key, "shift key");
endif;
return ( old_shift_key );
endprocedure



!                                                                       Page 4


procedure eveplus_key                   ! [EPK] Redefine key, save old def'n
      ( new_pgm, default_key, new_doc, key_string )

! Redefine a key, saving old definition
!
!   1) Determine if we have a user specified key; if not, use default.
!   2) Save the present definition & doc. of the user specified key.
!   3) Do a define key on the new key information.
!
! A note on methods:
!
! We use a string argument for the variable name of the user specified key
! so that: 1) We can successfully pass it to this procedure if its not defined.
!          2) We can generate variables to hold the old key's info, avoiding
!             passing more arguments for these.
!
! We combine the string argument with string constants to form valid TPU
! statements which we then execute.  (Ha! We TPU programmers can limp
!                                     along without LISP very well thanks!)
!
! Parameters:
!   new_pgm         ???         valid 1st argument for define_key builtin
!   default_key     ???         default keyname if user hasn't defined one
!   new_doc         ???         valid 3rd argument for define_key builtin
!   key_string      ???         string containing name for user defined keys
!
! Source:
!   Eveplus

on_error endon_error;
eveplus$x := default_key;   ! default, to global variables; the variables
eveplus$x_string := key_string; ! Move arguments, which are local by
eveplus$x_old_pgm := 0;     ! in and EXECUTE statement are all global.

! Determine if we have a user specified key; if not, use default.

if expand_name ( eveplus$x_string, variables ) <> eve$x_null then
    execute (   'if(get_info('+eveplus$x_string+',"type")=integer)then '
            +'eveplus$x:='+eveplus$x_string+';'
        +'else '
            +eveplus$x_string+':=eveplus$x;'
    +'endif;' );
else
    execute ( eveplus$x_string+ ':=  eveplus$x;' );
endif;

! Save the present definition & doc. of the user specified key
! one exists.

eveplus$x_old_pgm := lookup_key ( eveplus$x, program);

if (get_info ( eveplus$x_old_pgm, "type") = program) then
    execute( eveplus$x_string
        +'_doc := lookup_key ( eveplus$x, comment);'
        +eveplus$x_string
        +'_pgm := lookup_key ( eveplus$x, program);');
else
    execute( eveplus$x_string +'_doc := "~none~";');
endif;

! Do a define key on the new key information

define_key ( new_pgm, eveplus$x, new_doc );
endprocedure



!                                                                       Page 5


procedure eveplus_restore_key (the_key) ! [EPK] Restore a saved key definition

! This is the companion procedure to EVEplus_key, and restores the previous
! definition of a key saved during EVEplus_key.   See EVEplus_key for
! more info.
!
! Parameters:
!   the_key         keyword     key to restore
!
! Source:
!   Eveplus

on_error endon_error;
eveplus$x_string := the_key;
if expand_name ( eveplus$x_string+'_pgm', variables ) <> eve$x_null then
    execute ( 'define_key('+eveplus$x_string+'_pgm,'
        +eveplus$x_string+',' +eveplus$x_string+'_doc); ');
else
    execute ( 'undefine_key ('+eveplus$x_string+'); ');
endif;
endprocedure

! This is the end of the EvePlus kernel routines



!                                                                       Page 6


procedure tpu$init_procedure            ! Main initialization routine

! Main VAXTPU initialization routine
!
! Source:
!   Eve

local default_journal_name,             ! Default journal name
      output_file_name,                 ! Original output file name
      parsed_output_file_name,          ! Full filespec for output file
      input_file_name_only,             ! No node, disk, directory, or version
      journal_error;                    ! True if can't parse journal file name

on_error
    if error = tpu$_parsefail then
        if default_journal_name = 0 then        ! error in parsing output file
            message (fao ("Don't understand output file name: !AS",
                          output_file_name));
        else                                    ! error in parsing journal file
            journal_error := 1;
        endif;
    endif;
endon_error;

! Initialize our variables

eve$init_variables;

! Turn off message headers (facility, severity, id)

set (message_flags, 1);

! Create all the necessary default buffers and windows

! Create the prompt area - this will go over the command window

screen_length := get_info (screen, "visible_length");
set (prompt_area, screen_length - 1, 1, reverse);

! Message buffer/window - turn on bell for broadcast messages

message_buffer := eve$init_buffer ("Messages", eve$x_null);
message_window := create_window (screen_length, 1, off);
if message_window <> 0 then
    map (message_window, message_buffer);
endif;
set (bell, broadcast, on);

! Command buffer/window

eve$command_buffer := eve$init_buffer ("Commands", eve$x_null);
set (permanent, eve$command_buffer);
set (overstrike, eve$command_buffer);   ! for VMS V4 line-editing compatibility
set (reverse, eve$command_buffer);      ! for VMS V4 line-editing compatibility
eve$command_window := create_window (screen_length - 1, 1, off);
if eve$command_window <> 0 then
    map (eve$command_window, eve$command_buffer);
endif;

! Prompt buffer/window

eve$prompt_buffer := eve$init_buffer ("Prompts", eve$x_null);
eve$prompt_window := create_window (screen_length - 1, 1, off);
if eve$prompt_window <> 0 then
    set (video, eve$prompt_window, reverse);
endif;

! Get the help buffer, show buffer, and info window

help_buffer := eve$init_buffer ("Help", eve$x_null);
show_buffer := eve$init_buffer ("Show", eve$x_null);
info_window := create_window (1, screen_length - 2, on);

! Get the dcl buffer

eve$dcl_buffer := eve$init_buffer ("DCL", eve$x_null);

! Create windows for top and bottom halves of the screen
! Top window may be one line longer than bottom window.

eve$main_window_length := screen_length - 2;
eve$bottom_window_length := eve$main_window_length / 2;
eve$top_window_length := eve$main_window_length - eve$bottom_window_length;
eve$main_window := create_window (1, eve$main_window_length, on);
eve$top_window := create_window (1, eve$top_window_length, on);
eve$bottom_window :=
    create_window (eve$top_window_length + 1, eve$bottom_window_length, on);

! Buffer and window used by parser to display choices when a name is ambiguous

eve$choice_buffer := eve$init_buffer ("Choices", eve$x_null);
set (permanent, eve$choice_buffer);
eve$choice_window :=
    create_window (eve$main_window_length + 1 - eve$x_choice_window_length,
                   eve$x_choice_window_length, on);

! Now do the paste buffer

paste_buffer := eve$init_buffer ("Insert Here", "[End of Insert Here buffer]");

! Create a buffer using get_file

main_buffer := create_buffer ("Main");
if eve$main_window <> 0 then
    map (eve$main_window, main_buffer);
    position (eve$main_window);
    if eve$x_default_right_margin < 0 then
        set (margins, main_buffer, eve$x_default_left_margin,
            -eve$x_default_right_margin);
    else
        set (margins, main_buffer, eve$x_default_left_margin,
            get_info (eve$main_window, "width") - eve$x_default_right_margin);
    endif;
    set(tab_stops,main_buffer,eve$x_default_tab_interval);
!    set (margins, main_buffer, eve$x_default_left_margin,
!         get_info (eve$main_window, "width") - eve$x_default_right_margin);
else
    position (main_buffer);
endif;

eve$x_this_window := eve$main_window;
set (eob_text, main_buffer, abl$eob_text);
input_file := get_info (command_line, "file_name");
if eve$main_window <> 0 then
    if input_file = eve$x_null then
        eve$set_status_line (current_window);
    else
        eve$enter_command_window;
        ! call eve_get_file to read in first file
        copy_text ("get file " + input_file);
        eve$exit_command_window;
        if (current_buffer <> main_buffer) and
           (current_window = eve$main_window) then
            delete (main_buffer);
        endif;
    endif;
endif;

! The output file should be written to the current directory by default
! unless there is another directory specified in the output_file_name.
! We need to use sys$disk:[] as the default file specification so that
! the output file won't be written to the same directory as the input
! file if an input file directory is explicitly specified on the command line.
! We also DON'T want the node, device or directory of the input file, just
! the name.

if get_info (command_line, "output") <> 1 then
    set (no_write, current_buffer);
else
    output_file_name := get_info (command_line, "output_file");
    if output_file_name <> eve$x_null then
        input_file_name_only :=
            file_parse (input_file, eve$x_null, eve$x_null, name) +
            file_parse (input_file, eve$x_null, eve$x_null, type);
        parsed_output_file_name :=
            file_parse (output_file_name, "sys$disk:[]", input_file_name_only);
        if parsed_output_file_name <> eve$x_null then
            set (output_file, current_buffer, parsed_output_file_name);

            ! Want this buffer to be considered modified so it will
            ! be written on exit - for use especially with mail/edit

            split_line;
            append_line;
        endif;
    endif;
endif;

! Start journalling

if (get_info (command_line, "journal") = 1) and
   (get_info (command_line, "read_only") <> 1) then
    default_journal_name := "sys$disk:[]";
    journal_file := get_info (command_line, "journal_file");
    input_file_name_only := file_parse (get_info (current_buffer, "file_name"),
                                        eve$x_null, eve$x_null, name);
    if input_file_name_only = eve$x_null then
        input_file_name_only := "tpu.tjl";
    else
        input_file_name_only := input_file_name_only + ".tjl";
    endif;
    journal_file :=
        file_parse (journal_file, default_journal_name, input_file_name_only);
    if journal_file = eve$x_null then
        journal_file :=
            file_parse (eve$x_null, default_journal_name, input_file_name_only);
    endif;
    if journal_error then
        message (fao ("Don't understand journal file name: !AS", journal_file));
        message ("Editing session is not being journaled");
    else
        journal_open (journal_file);
    endif;

else                            ! Simulate VAXTPU error message
    message ("Editing session is not being journaled");
endif;

! Get rid of shift key - VAXTPU doesn't save result of a set (shift_key)

set (shift_key, key_name (pf1, shift_key));

! Try to determine if terminal is VT100 or VT200 on VMS V3 and V4.
! If terminal is eight-bit, edit-mode, ansi crt, then assume it
! is a VT200 series terminal.  All keypad bindings except for the
! numeric keypad are saved in the section file by default.  The
! following determines the layout of the numeric keypad.

if get_info (screen, "vt200") then      ! works only on VMS V4
    eve$vt200_keys;
else
    if get_info (screen, "vk100") then
        eve$vt100_keys;
    else
        if (get_info (screen, "eightbit")) and
           (get_info (screen, "ansi_crt")) and
           (get_info (screen, "edit_mode")) then
            eve$vt200_keys;
        else
            eve$vt100_keys;
        endif;
    endif;
endif;

set(timer,on,"Thinking...");
eve$set_status_line(current_window);
set(status_line,eve$main_window,none,
    substr(eve$x_spaces,1,abl$window_name_start-1)+"MAIN");
eve$w_main:=eve$main_window;
set(status_line,eve$top_window,none,
    substr(eve$x_spaces,1,abl$window_name_start-1)+"TOP");
eve$w_top:=eve$top_window;
set(status_line,eve$bottom_window,none,
    substr(eve$x_spaces,1,abl$window_name_start-1)+"BOTTOM");
eve$w_bottom:=eve$bottom_window;
set(status_line,info_window,none,
    substr(eve$x_spaces,1,abl$window_name_start-1)+"INFO");
eve$update_status_lines;

! Call user's own initialization procedure, for initializing variables etc.

tpu$local_init;
eve$x_starting_up := 0;

! Call Abel init procedure (executes Abel commands from a file)

abl$user_init;

endprocedure;



!                                                                       Page 7


procedure eve$init_variables            ! Initialize global variables

! Global variables should be initialized to eliminate the possible
! confusion of global variables with procedure names
!
! Source:
!   Eve

! Global string constants

abl$kt_version  := "Abel Version V0.1";         ! Abel version number

eve$kt_version  := "Eve Version V1.1-024";      ! Eve version number
eve$kt_null     := "";                          ! Null string
eve$kt_spaces :=                                ! Used for padding
        "                                ";     ! Add more...32 spaces
eve$kt_spaces := eve$kt_spaces + eve$kt_spaces; ! 64
eve$kt_spaces := eve$kt_spaces + eve$kt_spaces; ! 128
eve$kt_spaces := eve$kt_spaces + eve$kt_spaces; ! 256

eve$kt_beyond_eol       := "beyond_eol";        ! Argument to get_info
eve$kt_buffer           := "buffer";            ! Argument to get_info
eve$kt_current_row      := "current_row";       ! Argument to get_info
eve$kt_file_name        := "file_name";         ! Argument to get_info
eve$kt_first            := "first";             ! Argument to get_info
eve$kt_last             := "last";              ! Argument to get_info
eve$kt_left_margin      := "left_margin";       ! Argument to get_info
eve$kt_mode             := "mode";              ! Argument to get_info
eve$kt_name             := "name";              ! Argument to get_info
eve$kt_offset_column    := "offset_column";     ! Argument to get_info
eve$kt_output_file      := "output_file";       ! Argument to get_info
eve$kt_record_count     := "record_count";      ! Argument to get_info
eve$kt_right_margin     := "right_margin";      ! Argument to get_info
eve$kt_type             := "type";              ! Argument to get_info
eve$kt_visible_length   := "visible_length";    ! Argument to get_info
eve$kt_visible_top      := "visible_top";       ! Argument to get_info
eve$kt_width            := "width";             ! Argument to get_info

! Global integer constants

eve$k_no_arg := -2147483648;    ! Place holder when no argument is specified

! Global boolean constants

true := 1;
false := 0;

! Global keyword variables

eve$x_highlighting := reverse;  ! Highlighting used by select and replace

! Global string variables

! The following three are provided only for compatability reasons
! The coresponding eve$_... string "constants" should be used instead
! These variables may be deleted in future versions.

eve$x_version   := eve$kt_version;  ! Eve version number
eve$x_null      := eve$kt_null;     ! Null string
eve$x_spaces    := eve$kt_spaces;   ! Used for padding

eve$x_word_separators :=        ! Word separators:
    ascii(9) +                  !   tab
    ascii(10) +                 !   line feed
    ascii(11) +                 !   veritcal tab
    ascii(12) +                 !   form feed
    ascii(13) +                 !   carriage return
    ascii(32);                  !   space

eve$x_fill_separators :=        ! Fill separators:
    ascii(9) +                  !   tab
    ascii(10) +                 !   line feed
    ascii(11) +                 !   veritcal tab
    ascii(12) +                 !   form feed
    ascii(13) +                 !   carriage return
    ascii(32);                  !   space

eve$x_whitespace :=             ! Whitespace characters:
    ascii(9) +                  !   tab
    ascii(32);                  !   space

abl$x_qualifier_character :=    ! Qualifier introducer
    "/";

abl$x_qualifier_prefix :=       ! Prefix for qualifier variables
    "abl$q_";

abl$x_qual_def_prefix :=        ! Prefix for qualifier definition variables
    "abl$qd_";

abl$x_qualifier_characters :=   ! Valid characters in a qualifier
    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_?";

eve$x_token_separators :=       ! Token separators: space and horizontal tab
    abl$x_qualifier_character + ! Add qualifier introducer as separator
    " " + ascii(9);

eve$x_symbol_characters :=      ! Symbol characters are alphanumerics plus
                                ! "$" and "_", including multinational
                                ! character set
                                ! Support a couple other characters, too
    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890$_" +
    "àáâãäåæçèéêëìíîïñòóôõö÷øùúûüýÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÑÒÓÔÕÖ×ØÙÚÛÜÝß" +
    "!@#$%^&*()-+=|\,<.>?:;{}[]`~";

eve$x_runoff_characters :=      ! Characters used to begin Runoff commands
    "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!;";

eve$x_digit_characters :=       ! Digits - allow lowercase l for numeral 1
    "0123456789l";

eve$x_not_alphabetic :=         ! Non-alphabetic graphic characters
    "!@#$%^&*()[]{}-_+=~`|\:;""'<,>.?/¡¢£¥§¨©ª«°±²³µ¶·¹º»¼½¿";

eve$x_command_prompt :=         ! Command prompt for Do key
    "Command: ";
eve$x_eve_command_prompt :=     ! Command prompt used in eve_define_key
    "Eve command: ";

! Global (uninitialized) string variables

eve$x_argument_type  := eve$kt_null; ! Type of argument expected by eve$parse
                                     ! Can be "integer" or "string"
eve$x_command_line   := eve$kt_null; ! Command as typed after pressing Do
eve$x_do_line        := eve$kt_null; ! Last line given to do command
eve$x_parsed_do_line := eve$kt_null; ! Parsed version of eve$x_do_line
eve$x_restore_text   := eve$kt_null; ! String to be inserted by restore command
eve$x_target         := eve$kt_null; ! Last string given to find command
eve$x_start_do_key   := eve$kt_null; ! Key (comment) that started a DO sequence
eve$x_stop_do_key    := eve$kt_null; ! Key (comment) that ended a DO sequence

! Global pattern variables

eve$pattern_end_of_word :=      ! End of a word
! Don't move off current character position
              (
              anchor
                &
! If on eol,then match that
              (
              (line_end)
              |
! Leading spaces, on a word delimiter
            ( (span (eve$x_whitespace)) & (any (eve$x_word_separators) | '')))
              |
! No leading spaces, on a word delimiter, move one past it
              (any (eve$x_word_separators))
              |
! No leading spaces, on a real word, go one beyond it
              (scan (eve$x_word_separators))
              |
! No leading spaces, on a last real word of line, match reat of line
              remain
             )
             &
! After matching, skip over trailing spaces if any,
! except if match occurred at the eol. In this case, don't skip over blanks

             (line_begin | span (eve$x_whitespace) | '')
;

eve$pattern_paragraph_break :=  ! Blank line or Runoff command line
    anchor & line_begin &
        (("." & any (eve$x_runoff_characters)) |
         ((eve$kt_null | span (eve$x_word_separators)) & line_end));
eve$pattern_startprocedure :=   ! Start of a VAXTPU procedure
    line_begin & "procedure" & span (eve$x_word_separators);
eve$pattern_afterprocname :=    ! What you can find after a procedure name
    line_end | any (eve$x_word_separators) | any (";!(");
eve$pattern_endprocedure :=     ! End of a VAXTPU procedure
    (line_begin & "endprocedure") &
    (line_end | any (eve$x_word_separators) | any (";!"));
eve$pattern_procname :=         ! VAXTPU procedure name
    anchor & (span (eve$x_symbol_characters) | remain);
eve$pattern_whitespace := anchor & (span (eve$x_whitespace));
eve$pattern_trim := span(" ") & line_end; ! Used for trimming buffer

! Global key map variables

eve$x_key_map_list  := "TPU$KEY_MAP_LIST";      ! EVE's default key map list
eve$x_user_keys     := "eve$user_keys";         ! Keys defined by user
eve$x_vt100_keys    := "eve$vt100_keys";        ! VT100 numeric keypad
eve$x_vt200_keys    := "eve$vt200_keys";        ! VT200 numeric keypad
eve$x_standard_keys := "eve$standard_keys";     ! Main EVE keys

! Global marker variables

eve$x_select_position := 0;             ! Marker for start of select range

! Global window variables

eve$x_pre_command_window := 0;  ! Current window when Do key is pressed
eve$x_this_window := 0;         ! Current text window using Eve window commands

! Global process varibles

eve$x_dcl_process := 0;         ! DCL subprocess used by DCL command

! Global integer variables

eve$x_choice_window_length := 6;  ! Length of window where choices are displayed
                                  ! for ambiguous commands, files, buffers, etc.
eve$x_command_prompt_length := 9; ! Length of eve$x_command_prompt
eve$x_default_left_margin := 1;   ! Left margin for new buffers
eve$x_default_right_margin := 1;  ! Amount to subtract from window width
                                  ! for right margin for new buffers
eve$x_default_tab_interval := 8;
eve$x_hot_zone_size := 8;         ! Number of characters before right margin
                                  ! where word wrap will occur
eve$x_largest_right_margin := 983;! Maximum value allowed by set (margins...)
eve$x_largest_width := 65535;     ! Maximum value allowed by set (width...)
eve$x_max_buffer_name_length := 43;  ! Buffer names can be any size, but this is
                                     ! the largest size that will be shown on
                                     ! the status line without being truncated
eve$x_max_mark_length := 82;    ! 132 - 50 (see execute's in go to and show)
eve$x_max_scroll_offset := 4;   ! Maximum number of lines above/below the
                                ! final position of a find command

eve$x_ambiguous_parse := 0;     ! True when choices are being displayed
eve$x_buffer_of_mark := 0;      ! Used by go to command
eve$x_command_index := 1;       ! Index into eve$x_command_line while parsing
eve$x_command_length := 0;      ! Length of eve$x_command_line
eve$x_command_line_flag := 0;   ! True while a command line is executing
eve$x_is_number := 0;           ! True if current token is a number
eve$x_is_symbol := 0;           ! True if current token is a symbol
eve$x_is_quoted_string := 0;    ! True if current token is a quoted string
eve$x_is_punctuation := 0;      ! True if current token is punctuation
abl$x_is_qualifier := 0;        ! True is current token is a qualifier
eve$x_number_of_windows := 1;   ! Number of windows currently being displayed
eve$x_repeat_count := 1;        ! Number of times to execute current command
eve$x_restoring_line := 0;      ! True if restore command needs to do a
                                ! split_line after the copy_text
eve$x_starting_up := 1;         ! True during eve$init_procedure
eve$x_trimming := 0;            ! True if lines should be trimmed of
                                ! extra spaces before writing files
eve$x_vt200_keypad := 1;        ! True if LK201 keyboard is being used

! Calluser definitions

abl$cu_echo             := 0;   ! echo string, verifies link to calluser
abl$cu_begin_sort       := 1;   ! sort routines
abl$cu_release_rec      := 2;   !       .
abl$cu_sort_merge       := 3;   !       .
abl$cu_return_rec       := 4;   !       .
abl$cu_end_sort         := 5;   !       .
abl$cu_clear            := 6;   ! math routines
abl$cu_add              := 7;   !       .
abl$cu_subtract         := 8;   !       .
abl$cu_multiply         := 9;   !       .
abl$cu_divide           := 10;  !       .
abl$cu_equals           := 11;  !       .
abl$cu_error            := 12;  ! force on_error execution
abl$cu_sort_position    := 13;  ! added sort functionality
abl$cu_sort_length      := 14;  !       .
abl$cu_sort_order       := 15;  !       .
abl$cu_init_sort        := 16;  !       .
abl$cu_sqrt             := 17;  ! math routine

! Argument information for eve$parse

abl$kt_integer                  := "integer";
abl$kt_string                   := "string";

eve$arg1_ascii                  := abl$kt_string;
eve$arg1_block_text             := abl$kt_string;
eve$arg1_box                    := abl$kt_string;
eve$arg1_buffer                 := abl$kt_string;
eve$arg1_change_case            := abl$kt_string;
eve$arg1_change_word_case       := abl$kt_string;
eve$arg1_cube                   := abl$kt_string;
eve$arg2_cube                   := abl$kt_string;
eve$arg1_dcl                    := abl$kt_string;
eve$arg1_default_left_margin    := abl$kt_integer;
eve$arg1_default_right_margin   := abl$kt_integer;
eve$arg1_default_tab_every      := abl$kt_integer;
eve$arg1_define_key             := abl$kt_string;
eve$arg1_destroy_buffer         := abl$kt_string;
eve$arg1_do                     := abl$kt_string;
eve$arg1_extend_tpu             := abl$kt_string;
eve$arg1_find                   := abl$kt_string;
eve$arg1_get_file               := abl$kt_string;
eve$arg1_go_to                  := abl$kt_string;
eve$arg1_help                   := abl$kt_string;
eve$arg1_include_file           := abl$kt_string;
eve$arg1_line                   := abl$kt_string;
eve$arg1_list_commands          := abl$kt_string;
eve$arg1_mark                   := abl$kt_string;
eve$arg1_nowist                 := abl$kt_string;
eve$arg1_repeat                 := abl$kt_integer;
eve$arg1_replace                := abl$kt_string;
eve$arg2_replace                := abl$kt_string;
eve$arg1_save_extended_tpu      := abl$kt_string;
eve$arg1_search                 := abl$kt_string;
eve$arg1_set_autoindent         := abl$kt_string;
eve$arg1_set_dcl                := abl$kt_string;
eve$arg1_set_eliminate_tabs     := abl$kt_string;
eve$arg1_set_left_margin        := abl$kt_integer;
eve$arg1_set_right_margin       := abl$kt_integer;
eve$arg1_set_scroll_factor      := abl$kt_integer;
eve$arg1_set_tabs_at            := abl$kt_string;
eve$arg1_set_tabs_every         := abl$kt_integer;
eve$arg1_set_text               := abl$kt_string;
eve$arg1_set_trim               := abl$kt_string;
eve$arg1_set_width              := abl$kt_integer;
eve$arg1_set_word_wrap          := abl$kt_integer;
eve$arg1_set_write              := abl$kt_string;
eve$arg1_shift_left             := abl$kt_integer;
eve$arg1_shift_right            := abl$kt_integer;
eve$arg1_sort                   := abl$kt_string;
eve$arg2_sort                   := abl$kt_string;
eve$arg1_substitute             := abl$kt_string;
eve$arg2_substitute             := abl$kt_string;
eve$arg1_tpu                    := abl$kt_string;
eve$arg1_tsearch                := abl$kt_string;
eve$arg1_window                 := abl$kt_string;
eve$arg1_write_file             := abl$kt_string;

! Qualifier definitions for commands (see eve$parse for documentation)

abl$qd_ascii                    := "/previous~";
abl$qd_block_insert_here        := "/log";
abl$qd_block_remove             := "/remove/append~/reset/log";
abl$qd_block_select             := "/select~/reset~";
abl$qd_block_text               := "/check/reset/prompt";
abl$qd_box                      := "/reset";
abl$qd_buffer                   := "/new~/old~/ask";
abl$qd_center_line              := "/left_margin%-1/right_margin%-1" +
                                    "/check_width~/here~/reset";
abl$qd_change_case              := "/reset";
abl$qd_cube                     := "/reset/depth%3/orientation$NE";
abl$qd_dcl                      := "/cr~/eof~/echo";
abl$qd_default_left_margin      := "/all~";
abl$qd_default_right_margin     := "/all~";
abl$qd_default_tab_every        := "/all~";
abl$qd_destroy_buffer           := "/confirm";
abl$qd_eliminate_tabs           := "/log";
abl$qd_erase_line               := "/start~/end~";
abl$qd_erase_word               := "/edt~/whitespace~";
abl$qd_fill_paragraph           := "/indent%0/whole/autoleft~/left_margin%0" +
                                    "/right_margin%0";
abl$qd_fx                       := "/bold~/underline~/blink~/reverse~/normal~";
abl$qd_get_file                 := "/confirm/again~/recent~/read_only~";
abl$qd_help                     := "/keypress~";
abl$qd_list_commands            := "/qualifiers~";
abl$qd_move_by_line             := "/end~";
abl$qd_nowist                   := "/lines%10";
abl$qd_number_lines             := "/start%1/increment%1/reset";
abl$qd_other_window             := "/previous~";
abl$qd_remove                   := "/append~/remove/reset";
abl$qd_scramble                 := "/prompt";
abl$qd_search                   := "/prompt/ascii~/case_sensitive~/hunt" +
                                    "/wildcard/previous~";
abl$qd_select                   := "/select~/reset~";
abl$qd_sort                     := "/position%0/length%0/order$ascending/reset";
abl$qd_substitute               :=
                                    !
                                    ! old/new string qualifiers
                                    !
                                    "/previous~/delimited~/prompt/old_ascii~" +
                                    "/new_ascii~/wildcard~" +
                                    !
                                    ! substitution processing
                                    !
                                    "/iterate~/loop~/match/case_sensitive~" +
                                    "/ask/whole/reset~";
abl$qd_trim_buffer              := "/log";
abl$qd_tsearch                  := "/previous~/prompt";
abl$qd_unscramble               := "/prompt";
abl$qd_where                    := "/full~";
abl$qd_window                   := "/top%0/bottom%0/length%0" +
                                    "/rtop%0/rbottom%0" +
                                    "/delete~/unmap~/new~/old~" +
                                    "/list~/split~/original~";
abl$qd_write_file               := "/trim_whitespace$default" +
                                    "/eliminate_tabs$default" +
                                    "/reset/remove~";

! Global variables used for qualifiers (see eve$parse for documentation)

abl$q_again                     :=0;
abl$q_all                       :=0;
abl$q_append                    :=0;
abl$q_ascii                     :=0;
abl$q_ask                       :=0;
abl$q_autoleft                  :=0;
abl$q_begin                     :=0;
abl$q_blink                     :=0;
abl$q_bold                      :=0;
abl$q_bottom                    :=0;
abl$q_case_sensitive            :=0;
abl$q_check                     :=0;
abl$q_check_width               :=0;
abl$q_confirm                   :=0;
abl$q_cr                        :=0;
abl$q_delete                    :=0;
abl$q_delimited                 :=0;
abl$q_depth                     :=0;
abl$q_echo                      :=0;
abl$q_edt                       :=0;
abl$q_eliminate_tabs            :=0;
abl$q_eof                       :=0;
abl$q_end                       :=0;
abl$q_fresh                     :=0;
abl$q_full                      :=0;
abl$q_here                      :=0;
abl$q_hunt                      :=0;
abl$q_increment                 :=0;
abl$q_indent                    :=0;
abl$q_iterate                   :=0;
abl$q_keypress                  :=0;
abl$q_left_margin               :=0;
abl$q_length                    :=0;
abl$q_lines                     :=0;
abl$q_list                      :=0;
abl$q_log                       :=0;
abl$q_loop                      :=0;
abl$q_match                     :=0;
abl$q_new                       :=0;
abl$q_new_ascii                 :=0;
abl$q_normal                    :=0;
abl$q_old                       :=0;
abl$q_old_ascii                 :=0;
abl$q_order                     :=0;
abl$q_orientation               :=0;
abl$q_original                  :=0;
abl$q_position                  :=0;
abl$q_previous                  :=0;
abl$q_prompt                    :=0;
abl$q_qualifiers                :=0;
abl$q_read_only                 :=0;
abl$q_recent                    :=0;
abl$q_remove                    :=0;
abl$q_reset                     :=0;
abl$q_reverse                   :=0;
abl$q_right_margin              :=0;
abl$q_rbottom                   :=0;
abl$q_rtop                      :=0;
abl$q_select                    :=0;
abl$q_split                     :=0;
abl$q_start                     :=0;
abl$q_top                       :=0;
abl$q_trim_whitespace           :=0;
abl$q_underline                 :=0;
abl$q_unmap                     :=0;
abl$q_whitespace                :=0;
abl$q_whole                     :=0;
abl$q_wildcard                  :=0;

! Other Abel Variables

abl$ascii_character_set :=
    ascii(0) + ascii(1) + ascii(2) + ascii(3) + ascii(4) + ascii(5) + ascii(6) +
    ascii(7) + ascii(8) + ascii(9) + ascii(10) + ascii(11) + ascii(12) +
    ascii(13) + ascii(14) + ascii(15) + ascii(16) + ascii(17) + ascii(18) +
    ascii(19) + ascii(20) + ascii(21) + ascii(22) + ascii(23) + ascii(24) +
    ascii(25) + ascii(26) + ascii(27) + ascii(28) + ascii(29) + ascii(30) +
    ascii(31) + ascii(32) + ascii(33) + ascii(34) + ascii(35) + ascii(36) +
    ascii(37) + ascii(38) + ascii(39) + ascii(40) + ascii(41) + ascii(42) +
    ascii(43) + ascii(44) + ascii(45) + ascii(46) + ascii(47) + ascii(48) +
    ascii(49) + ascii(50) + ascii(51) + ascii(52) + ascii(53) + ascii(54) +
    ascii(55) + ascii(56) + ascii(57) + ascii(58) + ascii(59) + ascii(60) +
    ascii(61) + ascii(62) + ascii(63) + ascii(64) + ascii(65) + ascii(66) +
    ascii(67) + ascii(68) + ascii(69) + ascii(70) + ascii(71) + ascii(72) +
    ascii(73) + ascii(74) + ascii(75) + ascii(76) + ascii(77) + ascii(78) +
    ascii(79) + ascii(80) + ascii(81) + ascii(82) + ascii(83) + ascii(84) +
    ascii(85) + ascii(86) + ascii(87) + ascii(88) + ascii(89) + ascii(90) +
    ascii(91) + ascii(92) + ascii(93) + ascii(94) + ascii(95) + ascii(96) +
    ascii(97) + ascii(98) + ascii(99) + ascii(100) + ascii(101) + ascii(102) +
    ascii(103) + ascii(104) + ascii(105) + ascii(106) + ascii(107) + ascii(108)
    + ascii(109) + ascii(110) + ascii(111) + ascii(112) + ascii(113) +
    ascii(114) + ascii(115) + ascii(116) + ascii(117) + ascii(118) + ascii(119)
    + ascii(120) + ascii(121) + ascii(122) + ascii(123) + ascii(124) +
    ascii(125) + ascii(126) + ascii(127) + ascii(128) + ascii(129) + ascii(130)
    + ascii(131) + ascii(132) + ascii(133) + ascii(134) + ascii(135) +
    ascii(136) + ascii(137) + ascii(138) + ascii(139) + ascii(140) + ascii(141)
    + ascii(142) + ascii(143) + ascii(144) + ascii(145) + ascii(146) +
    ascii(147) + ascii(148) + ascii(149) + ascii(150) + ascii(151) + ascii(152)
    + ascii(153) + ascii(154) + ascii(155) + ascii(156) + ascii(157) +
    ascii(158) + ascii(159) + ascii(160) + ascii(161) + ascii(162) + ascii(163)
    + ascii(164) + ascii(165) + ascii(166) + ascii(167) + ascii(168) +
    ascii(169) + ascii(170) + ascii(171) + ascii(172) + ascii(173) + ascii(174)
    + ascii(175) + ascii(176) + ascii(177) + ascii(178) + ascii(179) +
    ascii(180) + ascii(181) + ascii(182) + ascii(183) + ascii(184) + ascii(185)
    + ascii(186) + ascii(187) + ascii(188) + ascii(189) + ascii(190) +
    ascii(191) + ascii(192) + ascii(193) + ascii(194) + ascii(195) + ascii(196)
    + ascii(197) + ascii(198) + ascii(199) + ascii(200) + ascii(201) +
    ascii(202) + ascii(203) + ascii(204) + ascii(205) + ascii(206) + ascii(207)
    + ascii(208) + ascii(209) + ascii(210) + ascii(211) + ascii(212) +
    ascii(213) + ascii(214) + ascii(215) + ascii(216) + ascii(217) + ascii(218)
    + ascii(219) + ascii(220) + ascii(221) + ascii(222) + ascii(223) +
    ascii(224) + ascii(225) + ascii(226) + ascii(227) + ascii(228) + ascii(229)
    + ascii(230) + ascii(231) + ascii(232) + ascii(233) + ascii(234) +
    ascii(235) + ascii(236) + ascii(237) + ascii(238) + ascii(239) + ascii(240)
    + ascii(241) + ascii(242) + ascii(243) + ascii(244) + ascii(245) +
    ascii(246) + ascii(247) + ascii(248) + ascii(249) + ascii(250) + ascii(251)
    + ascii(252) + ascii(253) + ascii(254) + ascii(255);

abl$ascii_values                := "";              ! eve_ascii last user input
abl$ascii_text                  := "";              ! eve_ascii last ascii str
abl$autoindent                  := 0;               ! eve$split_line
abl$buffer_name_length          := 25;              ! eve$set_status_line
abl$dcl_interactive             := 0;               ! eve_return
abl$eob_text                    := "[End of file]"; ! eve_buffer eob text
abl$help_file                   := "abl$help";      ! eve_help help file
abl$keypad_help                 := "";              ! eve_help keypad identifier

abl$qualifier_definition        := "";              ! eve$parse/abl$proc-qual
abl$scroll_factor               := 0;               ! eve_set_scroll_factor
abl$search_pattern              := "";              ! eve_search
abl$search_text                 := "";              ! eve_search
abl$sort_ascending              := 0;               ! abl$extended_sort_buffer
abl$sort_descending             := 1;               ! abl$extended_sort_buffer
abl$sort_max_line_length        := 256;             ! abl$extended_sort_buffer
abl$substitute_search_pattern   := "";              ! eve_substitute
abl$substitute_search_text      := "";              ! eve_substitute
abl$substitute_replace_text     := "";              ! eve_substitute
abl$tsearch_pattern             := "";              ! eve_tsearch
abl$tsearch_text                := "";              ! eve_tsearch
abl$window_name_start           := 63;              ! eve$set_status_line
abl$x                           := 0;               ! any ad hoc execute("...")
abl$x_block_select_position     := 0;               ! eve_block_select mark
abl$x_elimming                  := 0;               ! eve_set_tab_eliminate
abl$x_virtual_offset            := -1;              ! abl$virtual_mark/position
abl$x_virtual_line              := -1;              ! abl$virtual_mark/position
abl$x_virtual_buffer            := 0;               ! abl$virtual_mark/position
edt$x_word                      :=                  ! tab, LF, VT, FF, CR, space
                                    ascii(9) + ascii(10) + ascii(11) +
                                    ascii(12) + ascii(13) + ascii(32);
edt$x_forward_word              := (anchor & ((line_end) | (span(' '))) |
                                    (any(edt$x_word)) | (scan(edt$x_word)) |
                                    remain ) & (line_begin|span(' ') | '');


endprocedure;



!                                                                       Page 8


procedure abl$user_init                 ! Execute the Abel initialization file

! Provides Abel users a native-Abel initialization file, kind of like TPUINI
! but using Abel commands instead.  Abel looks for the logical ABELINI to
! point to the file, or looks for the file ABELINI.ABEL in the current
! directory.
!
! The TPUINI file is still read and executed.
!
! The lines in the Abel init file should be regular Abel commands
! complete with qualifiers and parameters as necessary.  If an incomplete
! command is used in the init file, Abel will behave exactly as it would if you
! had pressed the Do key and typed the command there.
!
! Source:
!   Abel

local
    filename,                   ! filename of init
    starting_position;              ! where we started

on_error
endon_error;

!
! Remember the user's starting place
!
starting_position := mark(none);
!
! See if we can find an initialization file
!
filename := file_search("abelini");
if filename = "" then filename := file_search("abelini.abel") endif;
if filename = "" then
    return;
endif;
!
! Found a file, so create a buffer and load the file
!
abl$init_buffer := create_buffer("Abel Initialization",filename);
set (permanent, abl$init_buffer);
set (system, abl$init_buffer);
!
! Perform eve_do on all the lines in the file
!
position(beginning_of(abl$init_buffer));
abl$do('eve_abel','');
!
! Go back to the place where we started
!
position(starting_position);
message("");
endprocedure


procedure eve_abel

! Performs each line of the current buffer as a DO command line.  If the user
! changes buffers on us, then we quit and tell him the line number we stopped
! on and allow the buffer switch.  Some other interesting problems need to be
! dealt with, like what if the user includes the TOP command in the buffer
! (endless loop).  We could be starting to add a whole Abel editing language
! with loops and branches eventually.
!
! Source:
!   Abel

local
    starting_position,
    starting_buffer,
    ending_position;

!
! Initializations
!
starting_buffer := current_buffer;
starting_position := mark(none);
!
! For all lines in the current buffer, eve_do them
!
position(beginning_of(starting_buffer));
loop
    exitif mark(none) = end_of(starting_buffer);
    eve_do(current_line);
    if current_buffer <> starting_buffer then
        ending_position := mark(none);
        position(starting_buffer);
        message(
            "Current buffer switched, cannot continue Abel processing at line "+
            str(eve$what_line));
        position(ending_position);
        return 0;
    endif;
    move_vertical(1);
endloop;
!
! Finish
!
position(starting_position);

endprocedure
