home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
p2demo21.exe
/
PEL
/
ISPF.PEL
< prev
next >
Wrap
Text File
|
1995-04-20
|
91KB
|
3,120 lines
# $Header: P:\source\wmacros\ispf.pev 1.111 20 Apr 1995 11:02:54 pfhmlw0 $
##############################################################################
#
# Compuware Corporation
# 31440 Northwestern Highway
# Farmington Hills, Michigan 48334-2564
#
# This source code listing contains information that is
# proprietary to Compuware Corporation and may not be copied
# duplicated, translated, transmitted, stored, retrieved
# or in any manner or by any method conveyed or disclosed
# to a third party or parties without express written
# permission from Compuware Corporation.
#
#
##############################################################################
#### $Workfile: ispf.pel $: Key bindings for ISPF compatibility
global ispf_cr_mode = 0 # OFF = ISPF style cr mode flag (CR does not insert)
global ispf_tab_mode = 1 # ON = ISPF style tab mode flag (Switch lc <-> data)
global ispf_motion_mode = 1 # ON = ISPF style home & end flag (no move past edge)
global ispf_enter_mode = 1 # 0 = <Enter> is Enter 1 = <Enter> is New-Line
global ispf_home_mode = 1 # 1 = <Home> is command, 0 = <Home> is home
# <Num-5> is home <Num-5> is command
global ispf_scroll_amt = "CSR" # Default scroll amount
global ispf_autosave = FALSE # ISPF's AUTOSAVE State
local ispf_primary # Table of ISPF Primary Commands -> PEL Functions
global ispf_keymap = -1 # The ISPF keymap!
global ispf_caps_mode = 0 # TRUE = CAPS ON
local ispf_te_mode = FALSE # TRUE = Text Entry Mode.
local ispf_aid_func = "" # Function to call for AID keys.
global ispf_undo_size = 30 # Max number of entries in ispf_undo_stack
local ispf_undo_stack # stack of undo_index's for each buffer
local ispf_undo_index # pointer to current entry in ispf_undo_stack
local ispf_last_index # pointer to last entry in ispf_undo_stack
global error_mark # string to mark errors with.
local rfind_failed = 0 # TRUE = last RFIND or RCHANGE failed
local rfind_key = 0 # TRUE = perform RFIND instead of CHANGE
#
# Flags used by ispf_parse_find to return search state
#
global ispf_default = 0 # Default starting values for ispf_flags
local ispf_flags
local ISPF_DIRS = 0x0003F # Mask for Direction Flags
local ISPF_ALL = 0x00001
local ISPF_NEXT = 0x00002
local ISPF_PREV = 0x00004
local ISPF_FIRST = 0x00008
local ISPF_LAST = 0x00010
local ISPF_PROMPT = 0x00020
local ISPF_PARMS = 0x00700 # Mask for Parameter Flags
local ISPF_CHARS = 0x00100
local ISPF_PREFIX = 0x00200
local ISPF_SUFFIX = 0x00400
local ISPF_WORD = 0x00800
local ISPF_EXCLUDE = 0x000C0 # Mask for Exclude Flags
local ISPF_X = 0x00040 # (Not currently used)
local ISPF_NX = 0x00080 # (Not currently used)
local ISPF_ICASE = 0x01000 # Ignore Case
local ISPF_REGEX = 0x02000 # Use regular experessions
local ISPF_BLOCK = 0x04000 # Perform a block Find/Change
local ISPF_ERROR = 0x08000 # Set by ispf_parse_find for errors
local old_linenumber_format
local insert_on
#
# ISPF Emulation Functions
#
global function ISPF()
{
ispf()
}
# read the ispf settings the first time ispf is selected
local read_ispf_settings = 1
global function ispf()
{
local prevPauseOnError
if (read_ispf_settings)
{
read_ispf_settings = 0
read_config_section("$ISPF$")
}
if (emulation_mode != "ispf")
{
emulation_mode = "ispf"
execute_event_handler( EVENT.EMULATION_CHANGED )
# hook our exit routine BEFORE the standard one!
delete_event(EVENT.EXIT_EDITOR, "exit_editor")
attach_event_handler(EVENT.EXIT_EDITOR, "ispf_quit")
attach_event_handler(EVENT.EXIT_EDITOR, "exit_editor")
attach_event_handler(EVENT.NEW_EDIT_FILE, "ispf_new_file")
attach_event_handler(EVENT.NEW_EMPTY_BUFFER, "ispf_empty_file")
attach_event_handler(EVENT.EMULATION_CHANGED, "ispf_exit")
attach_event_handler(EVENT.MENU_COMMAND, "ispexec")
# pause if an error or warning occurs during initialization
prevPauseOnError = pause_on_error
pause_on_error = 1
# set up ispf menu and keymap
create_ispf_keymap()
ispf_menu()
# Set the message level to all messages.
message_level = 0
# Turn on extended_quotes for find & change.
extended_quotes = TRUE
# set up the find, error and change marks for global searches
find_mark = "==FND>"
error_mark = "==ERR>"
change_mark = "==CHG>"
# setup some default window values
default_scroll_context_top = 0
default_scroll_context_bottom = 0
default_scroll_context_right = 0
default_scroll_context_left = 0
default_visible_end_buffer = strrepeat("=", 33) "BOTTOM OF DATA" \
strrepeat("=", 175)
# set up default search characteristics
search_flags = SEARCH_MAXIMAL_MATCH \
+ SEARCH_FORWARD \
+ SEARCH_BLOCK \
+ SEARCH_HIGHLIGHT \
+ SEARCH_MARK_CHG \
+ SEARCH_WRAPS \
# + SEARCH_REGEX \
# misc defaults
insert_on = !and(buffer_flags, BUFFER_OVERTYPE_MODE)
toggle_buffer_flags(BUFFER_OVERTYPE_MODE, 0 )
pause_on_error = prevPauseOnError
old_linenumber_format = linenumber_format
}
# Always turn on line commands and numbers
toggle_linecommands( 1 )
linecommands_enabled = 1
default_linenumber_format = nominal_linenumber_format
setup_windows()
setup_buffers()
}
global function setup_buffers()
{
if (current_buffer && buffer_size == 0)
execute_event_handler(EVENT.NEW_EMPTY_BUFFER)
}
global function setup_windows()
{
local start_window
if (current_window)
{
start_window = current_window
do
{
linenumber_format = default_linenumber_format
visible_end_buffer = default_visible_end_buffer
visible_newlines = default_visible_newlines
visible_spaces = default_visible_spaces
visible_tabs = default_visible_tabs
visible_virtual_lines = default_visible_virtual_lines
visible_virtual_spaces = default_visible_virtual_spaces
scroll_context_top = default_scroll_context_top
scroll_context_bottom = default_scroll_context_bottom
scroll_context_right = default_scroll_context_right
scroll_context_left = default_scroll_context_left
} while (next_window() != start_window)
}
}
# this function is used to customize the menu so that the keys you have
# assigned to do the same thing as the menuitem will show on the menu
# It should be global and start with the string inside emulation_mode
function ispf_menu()
{
local menu = menu_info(0, MI_MENUHANDLE);
cua_menu(1) # Start with CUA's menu with No FKeys!
# Alter ISPF Specific Menuitems.
if ( menu )
{
modify_menuitem( menu, IDM_CLOSE, MI_KEYSTEXT, "PF3")
modify_menuitem( menu, IDM_EXIT, MI_KEYSTEXT, "PF4")
modify_menuitem( menu, IDM_FINDAGAIN, MI_KEYSTEXT, "PF5")
modify_menuitem( menu, IDM_ADDFILE, MI_KEYSTEXT, "Ctrl-O")
modify_menuitem( menu, IDM_NEXT, MI_KEYSTEXT, "Ctrl-N")
menu_functions[IDM_COMMAND] = "ispf_command"
}
ispf_alter_menu()
}
local function ispf_alter_menu()
{
local menu = menu_info(0, MI_MENUHANDLE);
if ( menu )
{
if (ispf_home_mode)
modify_menuitem( menu, IDM_COMMAND, MI_KEYSTEXT, "Home")
else
modify_menuitem( menu, IDM_COMMAND, MI_KEYSTEXT, "Num-5")
}
}
local function ispf_fix_menu()
{
menu_functions[IDM_COMMAND] = "gui_command"
}
global function create_ispf_keymap()
{
# Enable the keymap. Subsequent mods to the keymap will persist
# through the end of the session.
# Only one-time initialization should follow this point.
if ( ispf_keymap >= 0 )
{
current_keymap = ispf_keymap
return
}
else
{
current_keymap = ispf_keymap = create_keymap( ascii_keymap )
assign_ispf_keys()
assign_ispf_line_commands()
assign_ispf_primary_commands()
# assign_mouse_buttons()
optional_function("local_keys")
}
}
global function assign_ispf_keys()
{
#--------------------------------------------------------------
# Function Key bindings (F1-F12)
#--------------------------------------------------------------
# assign_key( "<F1>", "isrexec HELP" )
assign_key( "<F2>", "isrexec SPLIT" )
assign_key( "<F3>", "isrexec END" )
assign_key( "<F4>", "isrexec RETURN" )
assign_key( "<F5>", "isrexec RFIND" )
assign_key( "<F6>", "isrexec RCHANGE" )
assign_key( "<F7>", "isrexec UP" )
assign_key( "<F8>", "isrexec DOWN" )
assign_key( "<F9>", "isrexec SWAP" )
assign_key( "<F10>", "isrexec LEFT" )
assign_key( "<F11>", "isrexec RIGHT" )
assign_key( "<F12>", "isrexec RETRIEVE" )
#--------------------------------------------------------------
# Function Key bindings (F12-F24)
#--------------------------------------------------------------
# assign_key( "<Shift-F1>", "isrexec HELP" )
assign_key( "<Shift-F2>", "isrexec SPLIT" )
assign_key( "<Shift-F3>", "isrexec END" )
assign_key( "<Shift-F4>", "isrexec RETURN" )
assign_key( "<Shift-F5>", "isrexec RFIND" )
assign_key( "<Shift-F6>", "isrexec RCHANGE" )
assign_key( "<Shift-F7>", "isrexec UP" )
assign_key( "<Shift-F8>", "isrexec DOWN" )
assign_key( "<Shift-F9>", "isrexec SWAP" )
assign_key( "<Shift-F10>", "isrexec LEFT" )
assign_key( "<Shift-F11>", "isrexec RIGHT" )
assign_key( "<Shift-F12>", "isrexec RETRIEVE" )
#--------------------------------------------------------------
# Define Alt-# Keys to emulate 3270 Terminal Emulators (IRMA).
#--------------------------------------------------------------
# assign_key( "<Alt-1>", "isrexec HELP" )
assign_key( "<Alt-2>", "isrexec SPLIT" )
assign_key( "<Alt-3>", "isrexec END" )
assign_key( "<Alt-4>", "isrexec RETURN" )
assign_key( "<Alt-5>", "isrexec RFIND" )
assign_key( "<Alt-6>", "isrexec RCHANGE" )
assign_key( "<Alt-7>", "isrexec UP" )
assign_key( "<Alt-8>", "isrexec DOWN" )
assign_key( "<Alt-9>", "isrexec SWAP" )
assign_key( "<Alt-0>", "isrexec LEFT" )
assign_key( "<Alt-->", "isrexec RIGHT" )
assign_key( "<Alt-=>", "isrexec RETRIEVE" )
#--------------------------------------------------------------
# Define Ctrl-# Keys to emulate 3270 Terminal Emulators (IRMA).
#--------------------------------------------------------------
# assign_key( "<Ctrl-1>", "isrexec HELP" )
assign_key( "<Ctrl-2>", "isrexec SPLIT" )
assign_key( "<Ctrl-3>", "isrexec END" )
assign_key( "<Ctrl-4>", "isrexec RETURN" )
assign_key( "<Ctrl-5>", "isrexec RFIND" )
assign_key( "<Ctrl-6>", "isrexec RCHANGE" )
assign_key( "<Ctrl-7>", "isrexec UP" )
assign_key( "<Ctrl-8>", "isrexec DOWN" )
assign_key( "<Ctrl-9>", "isrexec SWAP" )
assign_key( "<Ctrl-0>", "isrexec LEFT" )
assign_key( "<Ctrl-->", "isrexec RIGHT" )
assign_key( "<Ctrl-=>", "isrexec RETRIEVE" )
#--------------------------------------------------------------
# Ctrl + Alt key combinations on the main keyboard:
#--------------------------------------------------------------
#--------------------------------------------------------------
# Menu
#--------------------------------------------------------------
assign_key( "<Esc>", "expand_template")
assign_key( "<Ctrl-F1>", "display_help_item")
assign_key( "<Ctrl-H>", "display_help_item")
#--------------------------------------------------------------
# Cursor Movement
#--------------------------------------------------------------
assign_key( "<Ctrl-G>", "ispexec goto_line_key" )
#--------------------------------------------------------------
# Marked Blocks
#--------------------------------------------------------------
assign_key( "<Ctrl-M>", "set_inclusive_mark" )
assign_key( "<Ctrl-L>", "set_line_mark" )
assign_key( "<Ctrl-C>", "set_column_mark" )
assign_key( "<Ctrl-E>", "set_exclusive_mark" ) # Ctrl-A
#--------------------------------------------------------------
# Command Dialog
#--------------------------------------------------------------
assign_key( "<Ctrl-A>", "ispf_command" )
#--------------------------------------------------------------
# Basic Text commands
#--------------------------------------------------------------
assign_key( "<Ctrl-D>", "delete_line" )
assign_key( "<Ctrl-K>", "delete_to_eol" )
#--------------------------------------------------------------
# Manipulating Buffers
#--------------------------------------------------------------
assign_key( "<Ctrl-O>", "ispexec gui_open" )
assign_key( "<Ctrl-R>", "ispexec gui_insert_file" )
assign_key( "<Ctrl-W>", "ispexec write_block_or_buffer_key" )
assign_key( "<Ctrl-N>", "ispexec next_buffer_mask" )
assign_key( "<Ctrl-Shift-N>", "ispexec prev_buffer_mask" )
assign_key( "<Ctrl-B>", "ispexec buffer_list" )
assign_key( "<Ctrl-X>", "ispexec write_and_exit" )
#--------------------------------------------------------------
# Searching and translating
#--------------------------------------------------------------
assign_key( "<Ctrl-S>", "ispexec gui_find" )
assign_key( "<Ctrl-Shift-S>", "ispexec gui_find" )
assign_key( "<Ctrl-F>", "ispexec search_again" )
assign_key( "<Ctrl-T>", "ispexec gui_change" )
assign_key( "<Ctrl-Shift-T>", "ispexec gui_change" )
assign_key( "<Alt-Shift-S>", function_id("toggle_search_flags", SEARCH_CASE) )
assign_key( "<Alt-Shift-R>", function_id("toggle_search_flags", SEARCH_REGEX) )
#--------------------------------------------------------------
# Bookmarks
#--------------------------------------------------------------
assign_key( "<Ctrl-J>", "ispexec goto_bookmark" )
#--------------------------------------------------------------
# Miscellaneous
#--------------------------------------------------------------
assign_key( "<Alt-W>", "gui_save" )
assign_key( "<Alt-X>", "ispexec done" )
assign_key( "<Ctrl-V>", "print_version" )
assign_key( "<Ctrl-Q>", "insert_quoted_key" )
#--------------------------------------------------------------
# Numpad keys, keypad keys & non-ASCII keys on main keyboard:
#--------------------------------------------------------------
#--------------------------------------------------------------
# ISPF specific Definitions
#--------------------------------------------------------------
assign_key( "<Tab>", "ispf_tab" )
# use BackTab for OS2 and Shift-Tab for windows
assign_key( "<BackTab>", "ispf_backtab" )
assign_key( "<Enter>", "ispf_return" )
assign_key( "<Ctrl-Enter>", "ispf_enter" )
assign_key( "<Num-Enter>", "ispf_execute" )
assign_key( "<Ctrl>", "ispf_execute" )
assign_key( "<Space>", "insert_key" )
assign_key( "<Backspace>", "backspace" )
assign_key( "<Home>", "ispf_home_key" )
assign_key( "<Num-5>", "ispf_center_key" )
assign_key( "<End>", "ispf_end_key" )
assign_key( "<Alt-Left>", "left 2" )
assign_key( "<Alt-Right>", "right 2" )
assign_key( "<Alt-Down>", "down 2" )
assign_key( "<Alt-Up>", "up 2" )
#--------------------------------------------------------------
# Copy of CUA Definitions since ISPF does not define any of
# these actions itself.
#--------------------------------------------------------------
#--------------------------------------------------------------
# Cursor Movement
#--------------------------------------------------------------
assign_key( "<Left>", "left" ) #CUA
assign_key( "<Right>", "right" ) #CUA
assign_key( "<Down>", "down" ) #CUA
assign_key( "<Up>", "up" ) #CUA
assign_key( "<PageDown>", "isrexec DOWN" ) #CUA
assign_key( "<PageUp>", "isrexec UP" ) #CUA
assign_key( "<Alt-F4>", "done2" ) #CUA
assign_key( "<Ctrl-Left>", "prev_word" ) #CUA
assign_key( "<Ctrl-Right>", "next_word" ) #CUA
assign_key( "<Ctrl-Down>", "down_whitespace" )
assign_key( "<Ctrl-Up>", "up_whitespace" )
assign_key( "<Ctrl-Home>", "goto_bol" )
assign_key( "<Ctrl-End>", "goto_eol" )
assign_key( "<Ctrl-PageDown>", "ispexec goto_buffer_bottom" )
assign_key( "<Ctrl-PageUp>", "ispexec goto_buffer_top" )
assign_key( "<Ctrl-Num-Left>", "prev_word" ) #CUA
assign_key( "<Ctrl-Num-Right>", "next_word" ) #CUA
assign_key( "<Ctrl-Num-Down>", "down_whitespace" )
assign_key( "<Ctrl-Num-Up>", "up_whitespace" )
assign_key( "<Ctrl-Num-Home>", "goto_bol" )
assign_key( "<Ctrl-Num-End>", "goto_eol" )
assign_key( "<Ctrl-Num-PageDown>", "ispexec goto_buffer_bottom" )
assign_key( "<Ctrl-Num-PageUp>", "ispexec goto_buffer_top" )
#--------------------------------------------------------------
# Marked Blocks
#--------------------------------------------------------------
assign_key( "<Shift-Delete>", "gui_delete_to_scrap" ) #CUA
assign_key( "<Shift-Insert>", "ispexec insert_scrap" ) #CUA
assign_key( "<Ctrl-Insert>", "copy_to_scrap_key" ) #CUA
assign_key( "<Ctrl-Delete>", "delete_to_eol" )
assign_key( "<Num-->", "gui_delete_to_scrap" )
assign_key( "<Num-+>", "copy_to_scrap_key" )
assign_key( "<Shift-Left>", "cua_extend" ) #CUA
assign_key( "<Shift-Right>", "cua_extend" ) #CUA
assign_key( "<Shift-Down>", "cua_extend" ) #CUA
assign_key( "<Shift-Up>", "cua_extend" ) #CUA
assign_key( "<Shift-Home>", "cua_extend" ) #CUA
assign_key( "<Shift-End>", "cua_extend" ) #CUA
assign_key( "<Shift-PageDown>", "cua_extend" ) #CUA
assign_key( "<Shift-PageUp>", "cua_extend" ) #CUA
assign_key( "<Ctrl-Shift-Left>", "cua_extend" ) #CUA
assign_key( "<Ctrl-Shift-Right>", "cua_extend" ) #CUA
assign_key( "<Ctrl-Shift-Down>", "cua_extend" )
assign_key( "<Ctrl-Shift-Up>", "cua_extend" )
assign_key( "<Ctrl-Shift-Home>", "cua_extend" ) #CUA
assign_key( "<Ctrl-Shift-End>", "cua_extend" ) #CUA
assign_key( "<Ctrl-Shift-PageDown>", "cua_extend" ) #CUA
assign_key( "<Ctrl-Shift-PageUp>", "cua_extend" ) #CUA
#--------------------------------------------------------------
# Basic Text commands
#--------------------------------------------------------------
assign_key( "<Delete>", "delete_chars" ) #CUA
assign_key( "<Insert>", function_id("toggle_buffer_flags", BUFFER_OVERTYPE_MODE) ) #CUA
assign_key( "<Ctrl-Backspace>", "delete_prev_word" )
assign_key( "<Shift-Backspace>", "delete_word" )
#--------------------------------------------------------------
# Undo / Redo
#--------------------------------------------------------------
assign_key( "<Alt-Backspace>", "undo" ) #CUA
assign_key( "<Alt-Shift-Backspace>", "redo" )
#--------------------------------------------------------------
# Commands borrowed from Brief
#--------------------------------------------------------------
assign_key( "<Num-*>", "undo" )
assign_key( "<Num-/>", "redo" )
assign_key( "<Alt-Num-->", "ispexec prev_buffer_mask" )
assign_key( "<Ctrl-Num-->", "ispexec brief_delete_buffer" )
}
global function assign_ispf_line_commands()
{
delete_lc()
assign_transfer("C", "copy_to_dest") # Setup transfer commands
assign_transfer("CC", "copy_to_dest")
assign_transfer("M", "move_to_dest")
assign_transfer("MM", "move_to_dest")
assign_transfer(".line", "copy_to_dest")
assign_lc(".label", "validate_label") # Setup special commands
assign_lc(".insert", "cleanup_insert")
assign_lc("=flag", "")
assign_lc("C", "mark_1_line") # Setup source commands
assign_lc("CC", "mark_lines")
assign_lc("M", "mark_1_line")
assign_lc("MM", "mark_lines")
assign_lc("B", "transfer_lines B") # Setup destination commands
assign_lc("A", "transfer_lines A")
assign_lc("I", "insert_lines") # Setup the rest of the commands
assign_lc("TE", "ispf_text_entry")
assign_lc("TS", "ispf_text_split")
assign_lc("TJ", "ispf_text_join")
assign_lc("R", "repeat_lines")
assign_lc("RR", "mark_lines repeat_lines")
assign_lc("D", "delete_lines")
assign_lc("DD", "mark_lines delete_lines")
assign_lc("S", "select_lines") # CPE Extension to ISPF
assign_lc("SS", "mark_lines select_lines")
assign_lc("LC", "lcase_lines")
assign_lc("LCC", "mark_lines lcase_lines")
assign_lc("LCLC", "mark_lines lcase_lines")
assign_lc("UC", "ucase_lines")
assign_lc("UCC", "mark_lines ucase_lines")
assign_lc("UCUC", "mark_lines ucase_lines")
assign_lc("(", "lshift_cols")
assign_lc("((", "mark_lines lshift_cols")
assign_lc(")", "rshift_cols")
assign_lc("))", "mark_lines rshift_cols")
assign_lc("<", "lshift_data")
assign_lc("<<", "mark_lines lshift_data")
assign_lc(">", "rshift_data")
assign_lc(">>", "mark_lines rshift_data")
assign_lc("TF", "ispf_nyi")
assign_lc("O", "ispf_nyi")
assign_lc("OO", "ispf_nyi")
assign_lc("X", "ispf_nyi")
assign_lc("XX", "ispf_nyi")
}
global function assign_ispf_primary_commands()
{
ispf_primary["HELP"] = "display_help_item"
ispf_primary["FSPLIT"] = "ispf_fsplit"
ispf_primary["SPLIT"] = "ispf_split"
ispf_primary["SWAP"] = "ispf_swap"
ispf_primary["RETRIEVE"] = "ispf_command 1"
ispf_primary["FIND"] = "ispf_find"
ispf_primary["F"] = "ispf_find"
ispf_primary["CHANGE"] = "ispf_change"
ispf_primary["CHG"] = "ispf_change"
ispf_primary["C"] = "ispf_change"
ispf_primary["RFIND"] = "ispf_rfind"
ispf_primary["RCHANGE"] = "ispf_rchange"
ispf_primary["RIGHT"] = "ispf_right"
ispf_primary["LEFT"] = "ispf_left"
ispf_primary["UP"] = "ispf_up"
ispf_primary["U"] = "ispf_up"
ispf_primary["DOWN"] = "ispf_down"
ispf_primary["D"] = "ispf_down"
ispf_primary["LOCATE"] = "ispf_locate"
ispf_primary["LOC"] = "ispf_locate"
ispf_primary["L"] = "ispf_locate"
ispf_primary["DELETE"] = "ispf_delete"
ispf_primary["DEL"] = "ispf_delete"
ispf_primary["INSERT"] = "islexec I"
ispf_primary["INS"] = "islexec I"
ispf_primary["TENTER"] = "islexec TE"
ispf_primary["TE"] = "islexec TE"
ispf_primary["TJOIN"] = "islexec TJ"
ispf_primary["TJ"] = "islexec TJ"
ispf_primary["TSPLIT"] = "islexec TS"
ispf_primary["TS"] = "islexec TS"
ispf_primary["COPY"] = "ispf_copy_file"
ispf_primary["MOVE"] = "ispf_move_file"
ispf_primary["CREATE"] = "ispf_create_file"
ispf_primary["CRE"] = "ispf_create_file"
ispf_primary["REPLACE"] = "ispf_replace_file"
ispf_primary["REPL"] = "ispf_replace_file"
ispf_primary["REP"] = "ispf_replace_file"
ispf_primary["RESET"] = "ispf_reset"
ispf_primary["RES"] = "ispf_reset"
ispf_primary["UNDO"] = "ispf_undo"
ispf_primary["REDO"] = "ispf_redo"
ispf_primary["LABEL"] = "ispf_label"
ispf_primary["NEW"] = "gui_new" # CPE Extension to ISPF
ispf_primary["EDIT"] = "create_buf_and_win_key"
ispf_primary["E"] = "create_buf_and_win_key"
ispf_primary["BROWSE"] = "browse_file"
ispf_primary["B"] = "browse_file"
ispf_primary["SAVE"] = "write_buffer_key"
ispf_primary["SAV"] = "write_buffer_key"
ispf_primary["S"] = "write_buffer_key"
ispf_primary["CANCEL"] = "ispf_close 1 0"
ispf_primary["CAN"] = "ispf_close 1 0"
ispf_primary["END"] = "ispf_close 0 0"
ispf_primary["RETURN"] = "ispf_close 0 1"
ispf_primary["=X"] = "ispf_close 0 1"
ispf_primary["CPE"] = ""
ispf_primary["PEL"] = ""
ispf_primary["DOS"] = "system"
ispf_primary["OS2"] = "system"
ispf_primary["TSO"] = "system"
ispf_primary["RECOVERY"] = "ispf_recovery"
ispf_primary["AUTOSAVE"] = "set_ispf_autosave"
ispf_primary["TABS"] = "set_ispf_tabs"
ispf_primary["CAPS"] = "set_ispf_caps"
ispf_primary["HEX"] = "set_ispf_hex"
ispf_primary["CUT"] = "ispf_cut"
ispf_primary["PASTE"] = "ispf_paste"
ispf_primary["SHIFT"] = "ispf_nyi"
ispf_primary["TFLOW"] = "ispf_nyi"
ispf_primary["PRINT"] = "ispf_nyi"
# this is NOT what profile does in the "real" thing,
# but this should be an acceptable replacement.
ispf_primary["PRO"] = "create_ispf_page"
ispf_primary["PROFILE"] = "create_ispf_page"
}
#
# Global function to process the ISPF Command Line
#
global function ispf_command(retrieve)
{
local command
local ret
local fid = function_id( "ispf_command_key" )
rfind_key = FALSE
lc_message = ""
ispf_aid_func = ""
#
# install an event handler to make command history
# available to the prompt function.
#
attach_event_handler( EVENT.INVALID_PCHAR, fid )
if (retrieve)
command = prompt_history("ISPF", "COMMAND ===>", "", 1)
else
command = prompt_history("ISPF", "COMMAND ===>")
#
# remove the prompt event handler
#
delete_event( EVENT.INVALID_PCHAR, fid )
if (length(ispf_aid_func))
ret = invoke_function(ispf_aid_func " " command)
else if (length(command))
ret = isrexec(command)
else
ret = FALSE
#
# update the message line.
#
show_message(FALSE)
return ret
}
#
# Event Handler for ISPF Command Prompt Keys.
#
global function ispf_command_key()
{
local orig_key = current_key
if ( current_key == key_to_int("<Ctrl>") )
current_key = KEYCODE_ENTER
else if ( current_key == key_to_int("<Ctrl-Enter>") )
current_key = KEYCODE_ENTER
else if ( in_binding(current_key, function_id("isrexec RETRIEVE")) )
current_key = KEYCODE_UP
else if ( in_binding(current_key, function_id("isrexec UP")) ||
in_binding(current_key, function_id("isrexec DOWN")) ||
in_binding(current_key, function_id("isrexec LEFT")) ||
in_binding(current_key, function_id("isrexec RIGHT")) )
{
ispf_aid_func = keymap_binding(sprintf("#%d", current_key))
current_key = KEYCODE_ENTER
}
else if ( in_binding(current_key, function_id("isrexec RFIND")) )
{
rfind_key = TRUE
current_key = KEYCODE_ENTER
}
}
#
# Global function to add ISPF commands to the symbol_list
#
global function ispf_commands(searchFor)
{
local i
searchFor = tolower(searchFor)
for (i in ispf_primary)
{
if (match(tolower(i), "^" searchFor ".*" ))
symbol_list[i] = i
}
}
#
# Global Function to determine if a keycode is mapped to a specific function
#
global function in_binding(key, fid, keymap)
{
local keycode = sprintf("#%d", key)
local bindings
if (argcount() == 1 || !fid)
{
if (argcount() > 2 && keymap)
return length(keymap_binding(keycode, keymap)) > 0
else
return length(keymap_binding(keycode)) > 0
}
else
{
if (argcount() > 2 && keymap)
bindings = function_binding(fid, keymap)
else
bindings = function_binding(fid)
return (index(bindings, keycode) > 0)
}
}
#
# Global function to process_command_lines before executing a function.
#
global function ispexec(cmd)
{
local ret
ispf_te_mode = FALSE # Reset TE Mode.
ispf_push_undo()
if (process_line_commands() && argcount() && length(cmd))
ret = execute_function(cmd)
else
{
if (ispf_caps_mode)
{
set_line_mark()
upper()
remove_selection()
}
ret = FALSE
}
#
# update the message line.
#
show_message(FALSE)
return ret
}
#
# Global function to process ISPF Primary Commands
#
global function isrexec(command, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
{
local i
local ret
local cmd
local cmd2
local args
local line
ispf_te_mode = FALSE # Reset TE Mode.
command = trim(ltrim(command))
i = cindex(command, " \t")
if (i)
{
args = ltrim(substr(command, i))
command = substr(command, 1, i-1)
}
if (argcount() >= 2)
{
args = args " " arg1
if (argcount() >= 3)
{
args = args " " arg2
if (argcount() >= 4)
{
args = args " " arg3
if (argcount() >= 5)
{
args = args " " arg4
if (argcount() >= 6)
{
args = args " " arg5
if (argcount() >= 7)
{
args = args " " arg6
if (argcount() >= 8)
{
args = args " " arg7
if (argcount() >= 9)
args = args " " arg8
}
}
}
}
}
}
}
cmd = toupper(command)
if (cmd in ispf_primary)
{
cmd2 = ispf_primary[cmd]
lc_command = cmd
if (length(args))
line = cmd2 " " args
else
line = cmd2
}
else if (length(args))
line = command " " args
else
line = command
# DON'T push undo info for UNDO & REDO or it will break redo!!!!!!!!!
if (cmd2 != "ispf_undo" && cmd2 != "ispf_redo")
ispf_push_undo()
if (cmd2 == "ispf_reset") # RESET doesn't process_commands first
ret = invoke_function(line)
else if (process_line_commands())
ret = invoke_function(line)
show_message(FALSE)
return ret
}
#
# Global function to execute ISPF Line Commands from the command line
#
function islexec(cmd, lptr, arg)
{
lc_restore = 1
lc_line = (argcount() >= 1 && lptr) ? find_label(lptr) : current_line
lc_arg = (argcount() >= 2 && arg) ? arg+0 : 0
if (!lc_arg)
{
if (cmd == "TS" || cmd == "TF")
lc_arg = current_column
else
lc_arg = 1
}
if (cmd in lc)
return invoke_function(lc[cmd])
else
return invoke_function(cmd)
}
#
# Global function to push an entry onto ispf's undo stack
#
global function ispf_push_undo()
{
local i
local index = ispf_undo_index[current_buffer]
if (ispf_undo_stack[current_buffer][index] != undo_index())
{
if (index > ispf_undo_size)
{
for (i in ispf_undo_stack[current_buffer])
{
ispf_undo_stack[current_buffer][i] = ispf_undo_stack[current_buffer] \
[i+1]
}
index = ispf_undo_size
}
else
{
index++
ispf_undo_index[current_buffer] = index
if (ispf_last_index[current_buffer] < index)
ispf_last_index[current_buffer] = index
}
ispf_undo_stack[current_buffer][index] = undo_index()
}
}
#
# Global function to pop an entry from ispf's undo stack (and undo it)
#
global function ispf_undo()
{
if (ispf_undo_index[current_buffer])
undo(ispf_undo_stack[current_buffer][--ispf_undo_index[current_buffer]])
else
undo()
}
#
# Global function to redo an ispf_undo
#
global function ispf_redo()
{
if (ispf_undo_index[current_buffer] < ispf_last_index[current_buffer])
redo(ispf_undo_stack[current_buffer][ispf_undo_index[current_buffer]++])
else
redo()
}
#
# Global function to browse a file (open in Read-Only mode)
#
global function browse_file( fn )
{
if ( !fn )
fn = prompt_history( "EDITFILE", "File: ", "" )
if( fn )
{
if (filesize( fn ) > 0)
{
if( create_buf_and_win( fn ))
{
buffer_flags = or(buffer_flags, BUFFER_READ_ONLY)
display_filename()
}
else
error( "Cannot open file '%s'", fn )
}
else
error( "File '%s' does not exist", fn )
}
}
#
# Global function to find a labeled line
#
global function find_label(arg)
{
local i
local label
local line = 0
if (isdigit(arg))
line = atoi(arg)
else
{
label = toupper(trim(ltrim(arg)))
if (label == ".ZF" || label == ".ZFIRST")
line = 1
else if (label == ".ZL" || label == ".ZLAST")
line = buffer_last_line
else if (label == ".ZCSR" || label == ".ZCURSOR")
line = current_line
else
{
for ( i in line_command )
{
if (trim(ltrim(line_command[i])) == label)
{
line = atoi(i)
line_command[line] = label
break
}
}
}
}
return line
}
#
# Global function to mark the lines between two labeled lines
#
global function mark_range(select, from, to, col1, col2)
{
local colsOK
local toLine
local fromLine
local useCols = (argcount() >= 4)
if (argcount() == 0)
select = 0
else if (useCols)
{
if (!from)
{
from = 1
if (!to)
to = buffer_last_line
}
}
if (argcount() >= 2 && from)
{
fromLine = find_label(from)
if (fromLine)
{
if (argcount() >= 3 && to)
{
if (!select)
{
lc_arg = 1
lc_line = fromLine
lc_command = ".line"
if (useCols)
mark_cols(col1, col2)
else
mark_cols()
}
toLine = find_label(to)
if (toLine)
{
if (select)
{
if (useCols)
{
colsOK = (col1 < col2)
if (fromLine < toLine)
{
create_linecol_selection(COLUMN_SELECTION,
fromLine, colsOK ? col1 : col2,
toLine, colsOK ? col2 : col1)
goto_pos(fromLine, colsOK ? col1 : col2)
}
else
{
create_linecol_selection(COLUMN_SELECTION,
toLine, colsOK ? col1 : col2,
fromLine, colsOK ? col2 : col1)
goto_pos(toLine, colsOK ? col1 : col2)
}
}
else
{
if (fromLine <= toLine)
{
create_linecol_selection(LINE_SELECTION, fromLine, 1,
toLine, 1)
goto_line(fromLine)
}
else
{
create_linecol_selection(LINE_SELECTION, toLine, 1,
fromLine, 1)
goto_line(toLine)
}
}
}
else
{
lc_line = toLine
if (useCols)
mark_cols(col1, col2)
else
mark_cols()
}
}
else
{
error("Invalid label %s", to)
return FALSE
}
}
else
{
if (select)
{
create_linecol_selection(LINE_SELECTION, fromLine, 1, fromLine, 1)
goto_line(fromLine)
}
else
{
lc_arg = 1
lc_line = fromLine
lc_command = ".line"
mark_1_line()
}
}
}
else
{
error("Invalid label %s", from)
return FALSE
}
}
else if (select)
{
error("No range to select")
return FALSE
}
return TRUE
}
global function ispf_enter()
{
if (ispf_enter_mode)
ispf_execute()
else
ispf_cr()
}
global function ispf_return()
{
if (ispf_enter_mode)
ispf_cr()
else
ispf_execute()
}
global function ispf_execute(cmd)
{
local line
ispexec(cmd)
if (lc_restore)
{
down()
if (auto_indent_mode)
{
skip_whitespace()
if (!read_buffer( 1 ))
{
line = current_line
do {
prev_line()
} while( current_line > 1 && !read_buffer( 1 ))
current_line = line
}
}
else
goto_window_left()
}
}
global function ispf_cr()
{
if( !ispf_cr_mode )
{
if (current_line >= buffer_last_line)
{
goto_bolc()
beep()
return
}
else
down()
if (!ispf_te_mode && (current_column < 1 || ispf_tab_mode))
goto_bolc()
else
goto_window_left()
}
else if( auto_indent_mode )
insert_auto_indent()
else
insert_newline()
}
global function ispf_tab()
{
if (ispf_te_mode)
{
down()
goto_pos(0, window_margin + 1)
}
else if (current_column < 1)
goto_pos(0, window_margin + 1)
else if( ispf_tab_mode )
{
down()
goto_bolc()
}
else if( selection_type() || !and(buffer_flags, BUFFER_OVERTYPE_MODE))
{
indent_tab_maybe()
}
else
goto_next_tab()
}
global function ispf_backtab()
{
if (ispf_te_mode)
{
up()
goto_pos(0, window_margin + 1)
}
else if( ispf_tab_mode )
{
if (current_column < 1)
goto_pos(current_line - 1, window_margin + 1)
else
goto_bolc()
}
else if (current_column == 1 && !selection_type())
goto_bolc()
else
outdent_tab_maybe()
}
global function ispf_center_key()
{
if (ispf_home_mode)
{
if (ispf_motion_mode)
ispf_home()
else
home_key(current_key)
}
else
ispf_command()
}
global function ispf_home_key()
{
if (ispf_home_mode)
ispf_command()
else if (ispf_motion_mode)
ispf_home()
else
home_key()
}
global function ispf_end_key()
{
if (ispf_motion_mode)
ispf_end()
else
end_key()
}
global function ispf_home()
{
goto_window_top()
goto_window_left()
}
global function ispf_end()
{
if (current_line_width <= window_margin + window_text_width - linenumber_width)
goto_eol()
else
goto_window_right()
}
global function ispf_up(amt)
{
if (argcount() < 1)
amt = ispf_scroll_amt
else
amt = toupper(amt)
if (amt == "C" || amt == "CSR" || amt == "CRSR" || amt == "CURSOR")
{
amt = current_line - window_first - window_text_height + 1
if (amt)
scroll_vertical(amt)
else
page_up()
}
else if (amt == "M" || amt == "MAX")
scroll_vertical(-window_first + 1)
else if (amt == "H" || amt == "HALF")
scroll_vertical(-(window_text_height / 2))
else if (amt == "P" || amt == "PAGE")
scroll_vertical(-window_text_height)
else if (amt == "D" || amt == "DATA")
page_up()
else if (isdigit(amt))
scroll_vertical(-amt)
else
error("Invalid Scroll Amount %s", amt)
current_line = window_first + window_text_height - 1
update_current_view()
}
global function ispf_down(amt)
{
if (argcount() < 1)
amt = ispf_scroll_amt
else
amt = toupper(amt)
if (amt == "C" || amt == "CSR" || amt == "CRSR" || amt == "CURSOR")
{
amt = current_line - window_first
if (amt)
scroll_vertical(amt)
else
page_down()
}
else if (amt == "M" || amt == "MAX")
scroll_vertical(buffer_last_line - window_first - window_text_height + 2)
else if (amt == "H" || amt == "HALF")
scroll_vertical(window_text_height / 2)
else if (amt == "P" || amt == "PAGE")
scroll_vertical(window_text_height)
else if (amt == "D" || amt == "DATA")
page_down()
else if (isdigit(amt))
scroll_vertical(amt)
else
error("Invalid Scroll Amount %s", amt)
current_line = window_first
update_current_view()
}
global function ispf_left(amt)
{
local width
if (argcount())
amt = toupper(amt)
else
amt = ispf_scroll_amt
if (amt == "C" || amt == "CSR" || amt == "CRSR" || amt == "CURSOR")
{
width = window_text_width - linenumber_width
amt = window_margin + width - current_column
if (amt > 0 && amt < width - 1)
scroll_horizontal(-amt)
else
left_page()
}
else if (amt == "M" || amt == "MAX")
goto_bol()
else if (amt == "H" || amt == "HALF")
left_half_page()
else if (amt == "P" || amt == "PAGE")
left_page()
else if (amt == "D" || amt == "DATA")
scroll_horizontal(-(window_text_width - linenumber_width) + 1)
else if (isdigit(amt))
scroll_horizontal(-amt)
else
error("Invalid Scroll Amount %s", amt)
goto_window_left()
}
global function ispf_right(amt)
{
if (argcount())
amt = toupper(amt)
else
amt = ispf_scroll_amt
if (amt == "C" || amt == "CSR" || amt == "CRSR" || amt == "CURSOR")
{
amt = current_column - window_margin - 1
if (amt > 0 && amt < window_text_width - linenumber_width)
scroll_horizontal(amt)
else
right_page()
}
else if (amt == "M" || amt == "MAX")
scroll_horizontal(wp_right_margin - current_column + window_text_width)
else if (amt == "H" || amt == "HALF")
right_half_page()
else if (amt == "P" || amt == "PAGE")
right_page()
else if (amt == "D" || amt == "DATA")
scroll_horizontal((window_text_width - linenumber_width) - 1)
else if (isdigit(amt))
scroll_horizontal(amt)
else
error("Invalid Scroll Amount %s", amt)
goto_window_left()
}
global function ispf_text_entry()
{
ispf_te_mode = TRUE
lc_arg = max(lc_arg, window_text_height + 1)
return insert_lines()
}
global function ispf_text_split()
{
local OK
local old_flags = buffer_flags
restore_position(1)
save_position()
goto_pos(lc_line, 0)
buffer_flags = and(old_flags, not(BUFFER_OVERTYPE_MODE ))
OK = insert_auto_indent(1)
buffer_flags = old_flags
lc_restore = 0
if (OK)
return LC_OK
else
return LC_NOTOK
}
global function ispf_text_join()
{
goto_line(lc_line)
goto_eol()
if (delete_chars())
return LC_OK
else
return LC_NOTOK
}
global function ispf_copy_file( fn, where, lptr, from, to )
{
local pos
local line
local old_flags
local after = FALSE
local before = FALSE
local result = FALSE
local numargs = argcount()
local on_last_line = FALSE
if ( !fn )
{
fn = prompt_history( "EDITFILE", "File to read: ", "" )
if ( !fn )
return
}
if ( fn )
{
if (numargs > 1 && length(where))
{
where = toupper(where)
before = (where == "BEFORE" || where == "B")
if (!before)
after = (where == "AFTER" || where == "A")
if (!before && !after)
{
from = where
to = lptr
}
else if (numargs >= 3 && length(lptr))
line = find_label(lptr)
else
{
error("Invalid BEFORE or AFTER clause specified")
return
}
}
if (length(from) || length(to))
{
error("The line-range is not yet supported in the COPY and MOVE commands")
return
}
if (line)
{
goto_line(line)
goto_bol()
}
else if (tr_count)
{
if (current_buffer != tr_dest_buffer)
current_buffer = tr_dest_buffer
goto_mark(tr_dest_mark)
}
else
{
error("No Destination specified for the COPY or MOVE")
return
}
# make sure the buffer is NOT read-only so it won't play havok with
# the newline games we might need to play.
if ( and(buffer_flags, BUFFER_READ_ONLY) )
{
error("Read only file.")
return
}
on_last_line = (current_line >= buffer_last_line)
if (on_last_line)
{
if (tr_after || after)
{
# if we insert something AFTER the last line, we need to move
# to the end of the line and save that position so we can
# insert a newline there if the copy is sucessful.
goto_eol()
pos = create_mark(pick_unused_mark())
}
else if (current_line_length) # The normal method will work if the
on_last_line = FALSE # last line has something on it.
else # otherwise we'll just back up before
prev_char() # the last cr & insert one at the end
} # later.
else if (tr_after || after)
down()
if (!on_last_line)
{
# mark the next_char which will be the first char after the read.
# (if we mark this char, it won't be moved by the read)
next_char()
pos = create_mark(pick_unused_mark())
prev_char()
}
if ((result = read_file( fn )))
{
if (on_last_line)
{
if (tr_after || after)
goto_mark(pos) # restore saved pos
}
else
{
goto_mark(pos) # restore saved pos
prev_char() # backup since we saved the pos of the NEXT char.
}
# insert a newline in the buffer since the file we read probaby
# doesn't have a new as the last char, which would cause the last
# line of the file and the next line in the buffer to be joined.
# OR - we just inserted the file at the end and the last line of
# the buffer just got joined to the first line of the file.
old_flags = buffer_flags
buffer_flags = and(buffer_flags, not(BUFFER_OVERTYPE_MODE))
insert_newline()
buffer_flags = old_flags
if (!line && tr_count)
{
# if we were copying after the last line, we need to move the
# dest mark there since the line_command will have been pushed
# there by the read.
if (on_last_line)
{
goto_buffer_bottom()
delete_mark(tr_dest_mark)
tr_dest_mark = create_mark(pick_unused_mark())
}
else if (!(tr_after || after))
{
# if we read the data BEFORE the mark, we need to move the mark
# so that reset_transfer() will delete the correct line-command.
delete_mark(tr_dest_mark)
tr_dest_mark = pos
}
reset_transfer(LC_OK, TRUE)
}
else if (!on_last_line)
delete_mark(pos)
update_current_view()
}
else
delete_mark(pos)
}
return result
}
global function ispf_move_file( fn, where, lptr)
{
if (ispf_copy_file(fn, where, lptr))
{
system("del " fn)
return TRUE
}
else
return FALSE
}
global function ispf_create_file( fn, from, to )
{
if (substr(fn, 1, 1) == ".")
{
to = from
from = fn
fn = ""
delete fn
}
if (!fn)
fn = prompt( "File to create: ", "" )
if (fn)
{
if (filesize(fn) <= 0)
{
if (argcount() > 1)
ispf_write_file(fn, from, to)
else
ispf_write_file(fn)
}
else
error("Unable to create file, %s already exists", fn)
}
}
global function ispf_replace_file( fn, from, to )
{
if (substr(fn, 1, 1) == ".")
{
to = from
from = fn
fn = ""
delete fn
}
if (!fn)
fn = prompt_history( "EDITFILE", "File to replace: ", "" )
if (fn)
{
if (argcount() > 1)
ispf_write_file(fn, from, to)
else
ispf_write_file(fn)
}
}
global function ispf_write_file( fn, from, to )
{
local old_name = buffer_filename
if (argcount() > 1)
{
if (!mark_range(0, from, to))
return
}
tr_write_file = fn
if (perform_transfer("write_marked_lines") >= LC_NOTOK)
{
change_output_name( fn )
write_buffer()
change_output_name( old_name )
}
delete tr_write_file
}
global function ispf_cut( from, to )
{
if (argcount())
{
if (!mark_range(0, from, to))
return
}
perform_transfer("cut_marked_lines")
}
global function ispf_paste(where, lptr)
{
local line
local after = FALSE
local before = FALSE
local result = FALSE
local numargs = argcount()
if (numargs && length(where))
{
where = toupper(where)
before = (where == "BEFORE" || where == "B")
if (!before)
after = (where == "AFTER" || where == "A")
if (numargs >= 2 && length(lptr))
line = find_label(lptr)
else
{
error("Invalid BEFORE or AFTER clause specified")
return
}
}
if (line)
{
goto_line(line)
goto_bol()
}
else if (tr_count)
{
if (current_buffer != tr_dest_buffer)
current_buffer = tr_dest_buffer
goto_mark(tr_dest_mark)
if (tr_after)
down()
}
else
{
error("No Destination specified for the PASTE")
return
}
if ((result = insert_scrap()))
{
if (!line && tr_count)
reset_transfer(LC_OK, TRUE)
update_current_view()
}
return result
}
function ispf_find( arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 )
{
local result, count
if (ispf_parse_find( FALSE, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 ))
{
if (and(ispf_flags, ISPF_PROMPT))
{
result = find_all( search_pattern, 1 )
count = result[0]
}
else if (and(ispf_flags, ISPF_ALL))
{
result = find_all( search_pattern, 0 )
count = result[0]
}
else
count = string_search( search_pattern )
rfind_failed = (count == 0)
return count
}
else
return -1
}
function ispf_change( arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 )
{
local count
search_flags = or(search_flags, SEARCH_HIGHLIGHT)
if (ispf_parse_find(TRUE, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8))
{
if (rfind_key)
{
ispf_rfind()
return 0
}
else
{
count = string_replace( search_pattern, replace_pattern )
if (and(ispf_flags, ISPF_BLOCK))
remove_selection()
rfind_failed = (count == 0)
return count
}
}
else
return -1
}
function ispf_rfind()
{
if (rfind_failed)
search_flags = or(search_flags, SEARCH_WRAPS)
else
search_flags = and(search_flags, not(SEARCH_WRAPS))
rfind_failed = !search_again()
}
function ispf_rchange()
{
if (rfind_failed)
search_flags = or(search_flags, SEARCH_WRAPS)
else
search_flags = and(search_flags, not(SEARCH_WRAPS))
rfind_failed = !replace_again(1) # do NOT advance before changing!
}
#
# Function to parse an ISPF find or change command
#
local function ispf_parse_find( change, arg1, arg2, arg3, arg4,
arg5, arg6, arg7, arg8 )
{
local i
local args
local from, to
local col1, col2
local numargs = argcount()
local wordchars = "A-Za-z0-9#$@"
local isword = "[" wordchars "]"
local noword = "[^" wordchars "]"
ispf_flags = ispf_default
# get the search_pattern
if ( numargs == 0 || length(arg1) == 0)
{
search_pattern = ispf_parse_pattern()
}
else if (arg1 != "*")
search_pattern = ispf_parse_pattern(arg1)
# get the replace_pattern if it's needed
if (change)
{
if (numargs < 2 || length(arg2) == 0)
replace_pattern = ispf_parse_pattern("", TRUE)
else if (arg2 != "*")
replace_pattern = ispf_parse_pattern(arg2, TRUE)
if (numargs > 2 && length(arg3))
{
numargs -= 2
args[1] = toupper(arg3)
args[2] = toupper(arg4)
args[3] = toupper(arg5)
args[4] = toupper(arg6)
args[5] = toupper(arg7)
args[6] = toupper(arg8)
}
else
numargs = 0
}
else if (numargs > 1 && length(arg2))
{
numargs--
args[1] = toupper(arg2)
args[2] = toupper(arg3)
args[3] = toupper(arg4)
args[4] = toupper(arg5)
args[5] = toupper(arg6)
args[6] = toupper(arg7)
args[7] = toupper(arg8)
}
else
numargs = 0
if (numargs > 1)
{
# get the rest of the find/change arguments and set the ispf_flags
for(i = 1; i <= numargs; i++)
{
if (length(args[i]))
{
if (isdigit(args[i])) # columns
{
if (col1)
col2 = args[i]
else
col1 = args[i]
}
else if (substr(args[i], 1, 1) == ".") # lines
{
if (from)
to = args[i]
else
from = args[i]
}
else if (args[i] == "ALL")
{
if (and(ispf_flags, ISPF_DIRS))
{
error("Only one of ALL/NEXT/PREV/FIRST/LAST/PROMPT may be specified")
ispf_flags += ISPF_ERROR
return FALSE
}
else
ispf_flags += ISPF_ALL
}
else if (args[i] == "PROMPT" || args[i] == "PRO")
{
if (and(ispf_flags, ISPF_DIRS))
{
error("Only one of ALL/NEXT/PREV/FIRST/LAST/PROMPT may be specified")
ispf_flags += ISPF_ERROR
return FALSE
}
else
ispf_flags += ISPF_PROMPT
}
else if (args[i] == "NEXT")
{
if (and(ispf_flags, ISPF_DIRS))
{
error("Only one of ALL/NEXT/PREV/FIRST/LAST/PROMPT may be specified")
ispf_flags += ISPF_ERROR
return FALSE
}
else
ispf_flags += ISPF_NEXT
}
else if (args[i] == "PREV")
{
if (and(ispf_flags, ISPF_DIRS))
{
error("Only one of ALL/NEXT/PREV/FIRST/LAST/PROMPT may be specified")
ispf_flags += ISPF_ERROR
return FALSE
}
else
ispf_flags += ISPF_PREV
}
else if (args[i] == "FIRST")
{
if (and(ispf_flags, ISPF_DIRS))
{
error("Only one of ALL/NEXT/PREV/FIRST/LAST/PROMPT may be specified")
ispf_flags += ISPF_ERROR
return FALSE
}
else
ispf_flags += ISPF_FIRST
}
else if (args[i] == "LAST")
{
if (and(ispf_flags, ISPF_DIRS))
{
error("Only one of ALL/NEXT/PREV/FIRST/LAST/PROMPT may be specified")
ispf_flags += ISPF_ERROR
return FALSE
}
else
ispf_flags += ISPF_LAST
}
else if ((args[i] == "CHARS" || args[i] == "CHAR"))
{
if (and(ispf_flags, ISPF_PARMS))
{
error("Only one of CHARS/PREFIX/SUFFIX/WORD may be specified")
ispf_flags += ISPF_ERROR
return FALSE
}
else
ispf_flags += ISPF_CHARS
}
else if (args[i] == "PREFIX" || args[i] == "PRE")
{
if (and(ispf_flags, ISPF_PARMS))
{
error("Only one of CHARS/PREFIX/SUFFIX/WORD may be specified")
ispf_flags += ISPF_ERROR
return FALSE
}
else
ispf_flags += ISPF_PREFIX
}
else if (args[i] == "SUFFIX" || args[i] == "SUF")
{
if (and(ispf_flags, ISPF_PARMS))
{
error("Only one of CHARS/PREFIX/SUFFIX/WORD may be specified")
ispf_flags += ISPF_ERROR
return FALSE
}
else
ispf_flags += ISPF_SUFFIX
}
else if (args[i] == "WORD")
{
if (and(ispf_flags, ISPF_PARMS))
{
error("Only one of CHARS/PREFIX/SUFFIX/WORD may be specified")
ispf_flags += ISPF_ERROR
return FALSE
}
else
ispf_flags += ISPF_WORD
}
else if (args[i] == "X")
{
if (and(ispf_flags, ISPF_EXCLUDE))
{
error("Only one of X/NX may be specified")
ispf_flags += ISPF_ERROR
return FALSE
}
else
ispf_flags += ISPF_X
}
else if (args[i] == "NX")
{
if (and(ispf_flags, ISPF_EXCLUDE))
{
error("Only one of X/NX may be specified")
ispf_flags += ISPF_ERROR
return FALSE
}
else
ispf_flags += ISPF_NX
}
else
{
error("Invalid parameter %s in find/change command", args[i])
ispf_flags += ISPF_ERROR
return FALSE
}
}
}
# if a range was specified, mark the range.
if (from || col1)
{
ispf_flags = or(ispf_flags, ISPF_BLOCK)
if (col1)
mark_range(1, from, to, col1, col2)
else
mark_range(1, from, to)
}
}
# setup the search_count based on the ispf_flags
if (and(ispf_flags, ISPF_ALL))
{
search_flags = or( search_flags, SEARCH_WRAPS )
search_count = MAX_SEARCH
}
else if (and(ispf_flags, ISPF_BLOCK))
{
search_flags = and( search_flags, not(SEARCH_WRAPS) )
search_count = MAX_SEARCH
}
else if (and(ispf_flags, ISPF_PROMPT))
{
search_flags = or( search_flags, SEARCH_WRAPS )
search_count = 0
}
else
{
search_flags = and( search_flags, not(SEARCH_WRAPS) )
search_count = 1
}
# setup the search_flags based on the ispf_flags
if (and(ispf_flags, ISPF_FIRST))
{
goto_line(1)
search_flags = or(search_flags, SEARCH_FORWARD)
search_flags = and(search_flags, not(SEARCH_ADVANCE))
}
else if (and(ispf_flags, ISPF_LAST))
{
goto_line(buffer_last_line)
search_flags = and( search_flags, not( SEARCH_FORWARD ))
search_flags = and(search_flags, not(SEARCH_ADVANCE))
}
else if (and(ispf_flags, ISPF_PREV))
search_flags = and( search_flags, not( SEARCH_FORWARD ))
# else if (and(ispf_flags, ISPF_NEXT))
# search_flags = or( search_flags, SEARCH_FORWARD )
else
search_flags = or( search_flags, SEARCH_FORWARD )
if (and(ispf_flags, ISPF_PREFIX))
{
search_pattern = "(^|" noword ")\\c{" ispf_escape_regex(search_pattern) "}"
search_flags = or( search_flags, SEARCH_REGEX )
}
else if (and(ispf_flags, ISPF_SUFFIX))
{
search_pattern = "{" ispf_escape_regex(search_pattern) "}("noword "|$)"
search_flags = or( search_flags, SEARCH_REGEX )
}
else if (and(ispf_flags, ISPF_WORD))
{
search_pattern = "(^|" noword ")\\c{" ispf_escape_regex(search_pattern) \
"}("noword "|$)"
search_flags = or( search_flags, SEARCH_REGEX )
}
else if (and(ispf_flags, ISPF_REGEX))
search_flags = or( search_flags, SEARCH_REGEX )
else
search_flags = and( search_flags, not( SEARCH_REGEX ))
if (and(ispf_flags, ISPF_ICASE))
search_flags = and(search_flags, not(SEARCH_CASE))
else
search_flags = or(search_flags, SEARCH_CASE)
if (and(ispf_flags, ISPF_BLOCK))
search_flags = or(search_flags, SEARCH_BLOCK)
else
search_flags = and(search_flags, not(SEARCH_BLOCK))
return TRUE
}
#
# Function to parse an ISPF find or change pattern
#
local function ispf_parse_pattern(pattern, for_change)
{
local i
local ch
local len
local type
local string
local result
local from_history
if (!length(pattern))
{
if (for_change)
pattern = prompt_history("REPLACE", "Replacement: ", replace_pattern )
else
pattern = prompt_history( "SEARCH", " Search for: ", search_pattern )
from_history = TRUE # The pattern could come from the history stack
} # and therefore might be a REGEX expression.
type = toupper(substr(pattern, 1, 2))
if (type == "C'" || type == "C\"") # Characer
{
result = substr(pattern, 3, length(pattern)-3) # remove quotes
ispf_flags = and(ispf_flags, not(ISPF_ICASE))
}
else if (type == "X'" || type == "X\"") # heX
{
string = substr(pattern, 3, length(pattern)-3) # remove quotes
len = length(string)
for (i = 1; i <= len; i += 2)
{
while (index(" \t", substr(string, i, 1)))
{
if (++i > len)
break
}
if (i <= len)
{
result = result chr( 0 + ("0x" substr(string, i, 2)))
}
}
ispf_flags = and(ispf_flags, not(ISPF_ICASE))
}
else if (type == "P'" || type == "P\"") # Picture
{
string = substr(pattern, 3, length(pattern)-3) # remove quotes
len = length(string)
for (i = 1; i <= len; i++)
{
ch = substr(string,i,1)
if (ch == "=")
ch = "."
else if (ch == "^")
ch = "[~ \t]"
else if (ch == ".")
ch = "[\x01-\x1F\x7F-\xFF]" # PEL doesn't line 0x00
else if (ch == "#")
ch = "[0-9]"
else if (ch == "-")
ch = "[~0-9]"
else if (ch == "@")
ch = "[A-Za-z]"
else if (ch == "<")
ch = "[a-z]"
else if (ch == ">")
ch = "[A-Z]"
else if (ch == "$")
ch = "[~0-9A-Za-z]"
else if (index("[]|(){}*+?\"\\", ch))
ch = "\\" ch
result = result ch
}
ispf_flags = or(ispf_flags, or(ISPF_REGEX, ISPF_ICASE))
}
else if (type == "R'" || type == "R\"") # Regex
{
result = substr(pattern, 3, length(pattern)-3) # remove quotes
ispf_flags = or(ispf_flags, or(ISPF_REGEX, ISPF_ICASE))
}
else
{
result = pattern
if (from_history && cindex(pattern, "^.<>$[]|(){}*+?\\"))
ispf_flags = or(ispf_flags, ISPF_REGEX)
if (!for_change)
ispf_flags = or(ispf_flags, ISPF_ICASE)
}
return result
}
local function ispf_escape_regex(pattern)
{
local i
local ch
local len
local result
if (!and(ispf_flags, ISPF_REGEX) && cindex(pattern, "^.<>$[]|(){}*+?\\"))
{
len = length(pattern)
for (i = 1; i <= len; i++)
{
ch = substr(pattern,i,1)
if (index("^.<>$[]|(){}*+?\"\\", ch))
result = result "\\" ch
else
result = result ch
}
return result
}
else
return pattern
}
global function ispf_locate(arg1, arg2, arg3, arg4)
{
local dir
local argn
local line
local label
local found
if (argcount() < 1)
goto_line_key()
else if (argcount() == 1 && (isdigit(arg1) || substr(arg1,1,1) == "."))
{
line = find_label(arg1)
if (line)
{
goto_line(line)
if (!isdigit(arg1))
message("Label %s found", label)
}
else
error("Label %s not found", arg1)
}
else
{
arg1 = toupper(arg1)
if (arg1 == "NEXT" || arg1 == "N")
{
dir = "N"
argn = toupper(arg2)
}
else if (arg1 == "PREV" || arg1 == "P")
{
dir = "P"
argn = toupper(arg2)
}
else if (arg1 == "FIRST" || arg1 == "F")
{
dir = "F"
argn = toupper(arg2)
}
else if (arg1 == "LAST" || arg1 == "L")
{
dir = "L"
argn = toupper(arg2)
}
else
{
dir = "N"
argn = arg1
}
if (argn == "LABEL" || argn == "LAB" || argn == "L")
{
if (argn == arg1)
loc_line("L", dir, arg2, arg3)
else
loc_line("L", dir, arg3, arg4)
}
else if (argn == "COMMAND" || argn == "CMD" || argn == "M")
{
if (argn == arg1)
loc_line("M", dir, arg2, arg3)
else
loc_line("M", dir, arg3, arg4)
}
else if (argn == "ERROR" || argn == "ERR" || argn == "E")
{
if (argn == arg1)
loc_line("E", dir, arg2, arg3)
else
loc_line("E", dir, arg3, arg4)
}
else if (argn == "CHANGE" || argn == "CHG" || argn == "C")
{
if (argn == arg1)
loc_line("C", dir, arg2, arg3)
else
loc_line("C", dir, arg3, arg4)
}
else if (argn == "SPECIAL" || argn == "SPE" || argn == "S")
{
if (argn == arg1)
loc_line("S", dir, arg2, arg3)
else
loc_line("S", dir, arg3, arg4)
}
else if (argn == "ANY" || argn == "A")
{
if (argn == arg1)
loc_line("A", dir, arg2, arg3)
else
loc_line("A", dir, arg3, arg4)
}
else if (argn == "FIND" || argn == "FND" || argn == "F")
{
if (argn == arg1)
loc_line("F", dir, arg2, arg3)
else
loc_line("F", dir, arg3, arg4)
}
else if (argn == "EXCLUDED" || argn == "EXC" || argn == "X")
error("eXcluded line not supported")
else
error("Invalid parameters for LOCATE")
}
}
local function loc_line(what, dir, from, to)
{
local ch
local cmd
local line
local lineno
local start_line
local found_line
local last_line
local end_line
if (argcount() >= 3 && from)
start_line = find_label(from)
else if (dir == "N")
start_line = current_line + 1
else
start_line = 1
if (argcount() >= 4 && to)
end_line = find_label(to)
else
end_line = buffer_last_line
for (line in line_command)
{
lineno = line+0
if (lineno >= end_line)
break
else if (lineno >= start_line)
{
if (what == "A")
found_line = line
else
{
cmd = trim(ltrim(line_command[line]))
ch = substr(cmd,1,1)
if (cmd == change_mark)
{
if (what == "C")
found_line = line
}
else if (cmd == find_mark)
{
if (what == "F")
found_line = line
}
else if (cmd == error_mark)
{
if (what == "E")
found_line = line
}
else if (ch == "=")
{
if (what == "S")
found_line = line
}
else if (ch == ".")
{
if (what == "L")
found_line = line
}
else
{
if (what == "M")
found_line = line
}
}
if (found_line)
{
if (dir == "N" || dir == "F")
break;
else
{
if (dir == "reset")
delete_line_command(found_line)
else
last_line = found_line
found_line = ""
}
}
if (dir == "P" && lineno >= current_line)
break;
}
}
if (dir == "N" || dir == "F")
{
if (found_line)
goto_line(found_line)
else
error("Line not Located")
}
else if (dir != "reset")
{
if (last_line)
goto_line(last_line)
else
error("Line not Located")
}
}
global function ispf_reset(arg1, arg2, arg3)
{
local fid = 0
if (argcount() == 0)
reset_line_commands(FALSE)
else
{
arg1 = toupper(arg1)
if (arg1 == "EXCLUDED" || arg1 == "EXC" || arg1 == "X")
error("eXcluded lines not supported")
else if (argcount() == 2 && (isdigit(arg1) || substr(arg1,1,1) == "."))
loc_line("A", "reset", arg1, arg2)
else
{
if (arg1 == "LABEL" || arg1 == "LAB" || arg1 == "L")
fid = function_id("ispf:loc_line", "L", "reset", arg2, arg3)
else if (arg1 == "COMMAND" || arg1 == "CMD" || arg1 == "M")
fid = function_id("ispf:loc_line", "M", "reset", arg2, arg3)
else if (arg1 == "ERROR" || arg1 == "ERR" || arg1 == "E")
fid = function_id("ispf:loc_line", "E", "reset", arg2, arg3)
else if (arg1 == "CHANGE" || arg1 == "CHG" || arg1 == "C")
fid = function_id("ispf:loc_line", "C", "reset", arg2, arg3)
else if (arg1 == "SPECIAL" || arg1 == "SPE" || arg1 == "S")
fid = function_id("ispf:loc_line", "S", "reset", arg2, arg3)
else if (arg1 == "ALL" || arg1 == "A")
reset_line_commands(TRUE)
else
error("Invalid parameters for RESET")
if (fid)
{
if (argcount() > 1)
reset_line_commands(FALSE, fid)
else
execute_function( fid )
}
}
}
}
global function ispf_label(lptr, name)
{
local label
if (argcount() > 1)
{
label = toupper(ltrim(trim(name)))
if (substr(label,1,1) == ".")
line_command[find_label(lptr)] = label
else
error("Invalid label %s", name)
}
else if (argcount() > 0)
label = line_command[find_label(lptr)]
else
error("Line not specified in a label request")
return label
}
global function ispf_delete( arg1, arg2, arg3)
{
local to
if (toupper(arg1) == "ALL")
{
lc_line = find_label(arg2)
to = find_label(arg3)
}
else
{
lc_line = find_label(arg1)
to = find_label(arg2)
}
if (lc_line == 0)
lc_line = 1
if (to)
lc_arg = to - lc_line + 1
else
lc_arg = 1
delete_lines() # simulate a delete lines line command.
}
global function ispf_recovery( on )
{
on = toupper(on)
if (!argcount() || on == "ON")
autosave(autosave_time)
else if (on == "OFF")
autosave(0)
else
error("Invalid parameter %s for RECOVERY", on)
}
global function set_ispf_autosave( on )
{
on = toupper(on)
if (!argcount() || on == "ON")
ispf_autosave = TRUE
else if (on == "OFF")
ispf_autosave = FALSE
else
error("Invalid parameter %s for AUTOSAVE", on)
}
global function set_ispf_tabs( on, dmy )
{
on = toupper(on)
if (!argcount() || on == "ON")
ispf_tab_mode = FALSE
else if (on == "OFF")
ispf_tab_mode = TRUE
else
error("Invalid parameter %s for TABS", on)
}
global function set_ispf_caps( on )
{
on = toupper(on)
if (!argcount() || on == "ON")
ispf_caps_mode = TRUE
else if (on == "OFF")
ispf_caps_mode = FALSE
else
error("Invalid parameter %s for CAPS", on)
}
global function set_ispf_hex( on )
{
on = toupper(on)
if (!argcount() || on == "ON" || on == "PC")
toggle_dump_mode(TRUE)
else if (on == "OFF")
toggle_dump_mode(FALSE)
else
error("Invalid parameter %s for HEX", on)
}
global function ispf_fsplit()
{
local cwindow
local height
local y1
if( is_system_window())
return
else if (mdi_mode == 1 && !create_new_bufwin)
switch_to_sdi()
else if (mdi_mode)
{
cwindow = current_window
height = window_height
if (cwindow != next_window())
{
height += window_height
y1 = window_y0
delete_window()
current_window = cwindow
frame_window(window_x0, window_y0 < y1 ? window_y0 : y1,
window_width, height)
}
}
}
global function ispf_split()
{
local cwindow
local amount
local height
local y0, y1
if (is_system_window())
return
if (current_line <= window_first || \
current_line >= window_first + window_text_height)
{
if (mdi_mode == 1 && !create_new_bufwin)
{
cwindow = current_window
if (next_window() != cwindow && next_window() == cwindow)
{
switch_to_sdi() # if we have only 2 windows
return
}
}
if (mdi_mode)
{
cwindow = current_window
height = window_height
if (next_window() != cwindow)
{
height += window_height
y1 = window_y0
delete_window()
current_window = cwindow
frame_window(window_x0, window_y0 < y1 ? window_y0 : y1,
window_width, height)
}
}
}
else
{
height = window_height - ((current_line - window_first) \
* text_char_height)
if (mdi_mode == 0)
{
switch_to_mdi()
split_window_horizontal(height)
}
else
{
y0 = window_y0
amount = window_height / 2
if (current_window == next_window())
split_window_horizontal(height)
else if( amount < WINDOW_MIN_HEIGHT * text_char_height)
{
if (mdi_mode == 1 && !create_new_bufwin)
switch_to_sdi()
else
{
cwindow = current_window
height = window_height
if (next_window() != cwindow)
{
height += window_height
y1 = window_y0
delete_window()
current_window = cwindow
frame_window(window_x0, window_y0 < y1 ? window_y0 : y1,
window_width, height)
}
}
}
else
{
# grow this window
y1 = window_y0
height = window_height + amount
if (y1 > y0)
frame_window( window_x0, y1 - amount, window_width, height )
else
frame_window( window_x0, y1, window_width, height )
# shrink the other window
prev_window()
height = window_height - amount
if (y1 > y0)
frame_window( window_x0, y0, window_width, amount )
else
frame_window( window_x0, y0 + amount, window_width, amount )
}
}
}
}
global function ispf_swap(expand)
{
if ( mdi_mode )
next_window()
else
next_buffer()
}
global function ispf_close(cancel, exit_flag)
{
local this_window = current_window
local this_buffer = current_buffer
if (buffer_is_modified())
{
if (argcount() && cancel)
buffer_flags = and( buffer_flags, not( BUFFER_MODIFIED ) )
else if (ispf_autosave)
write_buffer()
}
if (mdi_mode == 2)
{
next_window()
if (current_window != this_window)
{
current_window = this_window
delete_window(this_window)
}
else if (argcount() >= 2 && exit_flag)
quit(1,1)
else
delete_buffer(this_buffer)
}
else if ( mdi_mode == 1)
{
next_window()
if (current_window != this_window)
{
current_window = this_window
delete_window(this_window)
this_window = current_window
next_window()
if (current_window != this_window)
{
current_window = this_window
return
}
}
else
{
next_buffer()
if (current_buffer != this_buffer)
delete_buffer(this_buffer)
}
switch_to_sdi()
}
else if (mdi_mode == 0)
{
if (argcount() >= 2 && exit_flag)
quit(1,1)
else
{
next_buffer()
if (current_buffer != this_buffer)
delete_buffer(this_buffer)
else
quit(1,1)
}
}
}
#
# EVENT.NEW_EMPTY_FILE Occured - Perform a Text Entry on the first line.
#
global function ispf_empty_file()
{
lc_line = 0
lc_arg = 1
ispf_text_entry()
goto_line(1)
}
#
# EVENT.NEW_EDITFILE Occured - Save the initial state
#
global function ispf_new_file()
{
new_edit_file()
ispf_push_undo()
}
#
# EVENT.EMULATION_CHANGED Occured - ISPF Emulation is no longer active.
#
global function ispf_exit()
{
reset_line_commands()
find_mark = "" # remove the find, error and change marks
error_mark = "" # for global searches
change_mark = ""
delete ispf_undo_stack # delete ispf's undo stack
delete ispf_undo_index
delete ispf_last_index
extended_quotes = FALSE # Turn off extended quotes.
ispf_fix_menu() # Fix any altered menuitems.
toggle_linecommands( 0 ) # turn off line commands and
default_linenumber_format = # restore line numbers to prev. state
linenumber_format = old_linenumber_format
default_visible_end_buffer = # Remove the END OF DATA line.
visible_end_buffer = ""
setup_windows() # Reset all windows to new defaults.
toggle_buffer_flags(BUFFER_OVERTYPE_MODE, insert_on )
# delete event handlers
delete_event(EVENT.EXIT_EDITOR, "ispf_quit")
delete_event(EVENT.NEW_EDIT_FILE, "ispf_new_file")
delete_event(EVENT.NEW_EMPTY_BUFFER, "ispf_empty_file")
delete_event(EVENT.EMULATION_CHANGED, "ispf_exit")
delete_event(EVENT.TOOLBAR_COMMAND, "ispexec")
delete_event(EVENT.MENU_COMMAND, "ispexec")
}
#
# EVENT.EXIT_EDITOR Occured - The editor is exiting.
#
global function ispf_quit()
{
local start_buffer
if (ispf_autosave)
{
for (start_buffer = 0; current_buffer != start_buffer;)
{
if (!start_buffer)
start_buffer = current_buffer
if (buffer_is_modified())
write_buffer()
}
}
}
global function ispf_nyi()
{
warning("ISPF function %s is not supported", lc_command)
return LC_NOTOK
}
################# ISPF SETTINGS NOTEBOOK PAGE ########################
global function create_ispf_page(dlgid)
{
local dhIspfSettings = create_dialog(function_id( "ispf_settings_callback" ),
dlgid, IDD_ISPF_SETTINGS, resource_dll)
attach_help(editor_helpfile, dhIspfSettings)
initialize_ispf_settings( dhIspfSettings );
begin_dialog(dhIspfSettings)
}
#
# ISPF Settings Notebook Page functions
#
local function initialize_ispf_settings( handle )
{
set_dialog_item( handle, IDE_SCROLL_AMOUNT, DAC_EDIT_TEXT, ispf_scroll_amt "")
if ( ispf_enter_mode )
{
set_dialog_item( handle, IDC_ENTER_MODE, DAC_CHECK)
set_dialog_item( handle, IDC_CR_MODE, DAC_TEXT,
"3270 [Return] emulates ~PC Enter")
}
else
{
set_dialog_item( handle, IDC_ENTER_MODE, DAC_UNCHECK)
set_dialog_item( handle, IDC_CR_MODE, DAC_TEXT,
"[Ctrl+Return] emulates ~PC Enter")
}
if ( ispf_cr_mode )
set_dialog_item( handle, IDC_CR_MODE, DAC_CHECK)
else
set_dialog_item( handle, IDC_CR_MODE, DAC_UNCHECK)
if ( ispf_home_mode )
{
set_dialog_item( handle, IDC_HOME_MODE, DAC_CHECK)
set_dialog_item( handle, IDC_MOTION_MODE, DAC_TEXT,
"[Home] and [End] move to ~edge of window ONLY")
}
else
{
set_dialog_item( handle, IDC_HOME_MODE, DAC_UNCHECK)
set_dialog_item( handle, IDC_MOTION_MODE, DAC_TEXT,
"[Num+5] and [End] move to ~edge of window ONLY")
}
if ( ispf_motion_mode )
set_dialog_item( handle, IDC_MOTION_MODE, DAC_CHECK)
else
set_dialog_item( handle, IDC_MOTION_MODE, DAC_UNCHECK)
if ( cursor_enters_linecommands )
set_dialog_item( handle, IDC_CURSOR_MODE, DAC_CHECK)
else
set_dialog_item( handle, IDC_CURSOR_MODE, DAC_UNCHECK)
if ( ispf_tab_mode )
set_dialog_item( handle, IDC_TAB_MODE, DAC_CHECK)
else
set_dialog_item( handle, IDC_TAB_MODE, DAC_UNCHECK)
if ( ispf_autosave )
set_dialog_item( handle, IDC_ISPF_AUTOSAVE, DAC_CHECK)
else
set_dialog_item( handle, IDC_ISPF_AUTOSAVE, DAC_UNCHECK)
}
global function ispf_settings_callback()
{
local handle = callback_dialog_handle
if (callback_msg == DM_HELPREQUESTED)
{
if(isWindows())
display_help("ISPF Settings", callback_dialog_handle);
else
display_help("ispfpage", callback_dialog_handle);
return DRC_MSG_PROCESSED
}
else if((callback_msg == DM_CLICK) || (callback_msg == DM_DOUBLE_CLICK) )
{
if ( callback_index == IDC_ENTER_MODE)
{
if (query_dialog_item(handle, IDC_ENTER_MODE, DAC_CHECK))
set_dialog_item( handle, IDC_CR_MODE, DAC_TEXT,
"3270 [Return] emulates ~PC Enter")
else
set_dialog_item( handle, IDC_CR_MODE, DAC_TEXT,
"[Ctrl+Return] emulates ~PC Enter")
return DRC_MSG_PROCESSED
}
else if ( callback_index == IDC_HOME_MODE)
{
if (query_dialog_item(handle, IDC_HOME_MODE, DAC_CHECK))
set_dialog_item( handle, IDC_MOTION_MODE, DAC_TEXT,
"[Home] and [End] move to ~edge of window ONLY")
else
set_dialog_item( handle, IDC_MOTION_MODE, DAC_TEXT,
"[Num+5] and [End] move to ~edge of window ONLY")
return DRC_MSG_PROCESSED
}
else
return DRC_CONTINUE
}
else if ( callback_msg == DM_CANCEL )
return DRC_EXIT
else if ( callback_msg == DM_OK )
{
assign_ispf_changes(handle)
return DRC_EXIT
}
else
return DRC_CONTINUE
}
global function assign_ispf_changes(dlgid)
{
ispf_scroll_amt = toupper(query_dialog_item(dlgid, IDE_SCROLL_AMOUNT, DAC_EDIT_TEXT));
ispf_enter_mode = query_dialog_item(dlgid, IDC_ENTER_MODE, DAC_CHECK);
ispf_cr_mode = query_dialog_item(dlgid, IDC_CR_MODE, DAC_CHECK);
ispf_tab_mode = query_dialog_item(dlgid, IDC_TAB_MODE, DAC_CHECK);
ispf_motion_mode = query_dialog_item(dlgid, IDC_MOTION_MODE, DAC_CHECK);
ispf_autosave = query_dialog_item(dlgid, IDC_ISPF_AUTOSAVE, DAC_CHECK);
cursor_enters_linecommands = query_dialog_item(dlgid, IDC_CURSOR_MODE, DAC_CHECK);
if(query_dialog_item(dlgid, IDC_HOME_MODE, DAC_CHECK))
{
ispf_home_mode = TRUE;
ispf_alter_menu();
}
}
global function save_ispf_settings()
{
local data_array
local index = 0
# if read_config_compiler is 1 then we haven't read the config
# information in so don't try to write it just return.
if (read_ispf_settings == 1)
return data_array;
data_array[ index++ ] = sprintf( "cursor_enters_linecommands=%d\n", cursor_enters_linecommands )
data_array[ index++ ] = sprintf( "ispf_caps_mode=%d\n", ispf_caps_mode )
data_array[ index++ ] = sprintf( "ispf_scroll_amt=\"%s\"\n", ispf_scroll_amt )
data_array[ index++ ] = sprintf( "ispf_enter_mode=%d\n", ispf_enter_mode )
data_array[ index++ ] = sprintf( "ispf_cr_mode=%d\n", ispf_cr_mode )
data_array[ index++ ] = sprintf( "ispf_home_mode=%d\n", ispf_home_mode )
data_array[ index++ ] = sprintf( "ispf_motion_mode=%d\n", ispf_motion_mode )
data_array[ index++ ] = sprintf( "ispf_tab_mode=%d\n", ispf_tab_mode )
data_array[ index++ ] = sprintf( "ispf_autosave=%d\n", ispf_autosave )
data_array[ index++ ] = sprintf( "\n" )
return data_array
}