home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
p2demo21.exe
/
PEL
/
STATE.PEL
< prev
next >
Wrap
Text File
|
1995-04-05
|
40KB
|
1,319 lines
# $Header: P:\source\wmacros\state.pev 1.143 05 Apr 1995 16:32:54 NOBLE $
##############################################################################
#
# 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: state.pel $: config/state file reading and writing
###
### Editor Configuration File
###
## global variable to enable (1) or disable (0) state files
#
global save_state = 0
global SAVE_SETTINGS = 0x0001
global SAVE_COMMANDS = 0x0002
global SAVE_SEARCH = 0x0004
global SAVE_REPLACE = 0x0008
global SAVE_EDITFILE = 0x0010
global SAVE_COMPILE = 0x0020
global SAVE_DIRECTORY = 0x0040
global SAVE_DEFAULT = SAVE_SETTINGS + SAVE_COMMANDS + SAVE_SEARCH + SAVE_REPLACE + SAVE_EDITFILE + SAVE_COMPILE
global save_flags = SAVE_DEFAULT
global editor_running
local config_buffer_ref_count = 0
local the_config_buffer = 0
local startup_dir = "" # last directory if 'save directory on exit' was set. See set_startup_dir().
#local DO_FAST_CONFIG = FALSE
local DO_FAST_CONFIG = TRUE
## read startup configuration and state information saved in a cfg file
#
global function read_config_file() #NO LONGER PUBLIC #INT
{
local config_array[]
local config_buffer
local old_buffer = current_buffer
local try_old_state = FALSE
local comline_count = 0
# install an event to write state information upon exit
attach_event_handler( EVENT.EXIT_EDITOR, function_id( "write_state_file" ) )
# load up the config file and make it the current buffer
# If the file exists, the function will return a good value, and we
# can then process the various sections
#
if ( get_config_buffer() )
{
# save config_buffer id in case one of the sections changes the
# current_buffer
#
config_buffer = current_buffer
current_buffer = old_buffer
read_config_section( "$SAVE_FLAGS$", config_buffer )
config_array = read_config_section( "$SETTINGS$", config_buffer, DO_FAST_CONFIG )
do_fast_config( "$SETTINGS$", config_array )
read_config_section( "$BUFFER1_SETTINGS$", config_buffer )
read_config_section( "$BUFFER2_SETTINGS$", config_buffer )
read_config_section( "$BUFFER3_SETTINGS$", config_buffer )
read_config_section( "$WINDOW1_SETTINGS$", config_buffer )
read_config_section( "$WINDOW2_SETTINGS$", config_buffer )
read_config_section( "$WINDOW3_SETTINGS$", config_buffer )
config_array = read_config_section( "$COLOR_SETTINGS$", config_buffer, DO_FAST_CONFIG )
process_color_config( config_array )
read_config_section( "$KEY_ASSIGNMENTS$", config_buffer )
# read user settings last so there values override everything else
read_config_section( "$USER_SETTINGS$", config_buffer )
comline_count = count_command_line_files()
# This pair of lines reads the entire section into the array, and then
# processes the commands as STATE information. The same technique is
# employed below for other sections;
if ( !comline_count )
{
# Only read the BUFFER_STATE if no files specified on the comand line;
config_array = read_config_section( "$BUFFER_STATE$", config_buffer, DO_FAST_CONFIG )
if ( !config_array ) # If no BUFFER_STATE section, try reading the old style STATE section;
try_old_state = TRUE
else
do_fast_config( "$STATE$", config_array )
}
if(!comline_count || !(comline_count && temp_create_new_bufwin) )
{
# Only read the WINDOW_STATE section if no files on the command line or
# files on the command line with one buffer per window mode turned off;
config_array = read_config_section( "$WINDOW_STATE$", config_buffer, DO_FAST_CONFIG )
if(config_array)
do_fast_config( "$STATE$", config_array )
}
if(comline_count && temp_create_new_bufwin)
{
# If files were passed on the command line and we are in one buffer
# per window mode, we want the editor information, but not the window
# information. In this case, we pass a third parameter to do_fast_config
# that does not process the window information.
config_array = read_config_section( "$WINDOW_STATE$", config_buffer, DO_FAST_CONFIG )
if(config_array)
do_fast_config( "$STATE$", config_array, TRUE )
create_new_bufwin = 1;
temp_create_new_bufwin = -1;
}
if( !config_array && try_old_state )
read_config_section( "$STATE$", config_buffer)
if ( temp_create_new_bufwin != -1 )
create_new_bufwin = temp_create_new_bufwin
display_redraw()
# fix the menu in case there are key assignments in config file that matter
# by calling the corresponding menu function for the current emulation
if ( emulation_mode )
execute_function( emulation_mode"_menu")
# cleanup by removing config_buffer
delete_config_buffer()
}
}
local old_buffer
global function read_config_error()
{
delete_event( EVENT.ERROR, "read_config_error" )
# don't delete config buffer here because we want the user
# to see where the error occured.
config_buffer_ref_count--
if ( config_buffer_ref_count <= 0)
{
if (the_config_buffer)
{
the_config_buffer = 0
}
config_buffer_ref_count = 0
}
}
# read a section from the config file
global function read_config_section( section_name, config_buffer, \
no_execute, include_comments )
{
local fid
local cmd
local data
local index = 1
local free_buffer = FALSE
local re_section_name = ""
attach_event_handler( EVENT.ERROR, "read_config_error" )
old_buffer = current_buffer
# if no config_buffer is specified then get it otherwise use the
# config_buffer passed in.
if (argcount() < 2 || !config_buffer)
{
if (get_config_buffer())
{
config_buffer = current_buffer
free_buffer = TRUE
}
else
return
}
else
current_buffer = config_buffer
goto_buffer_top()
re_section_name = section_name
gsub( "\\$", "\\$", re_section_name )
# look for the section name
if ( search( "^" re_section_name, SEARCH_FWD_REGEX) )
{
# go past section name
if ( down(1) )
{
cmd = ltrim( trim(read_buffer()) )
# go until end of buffer or next section
while (substr(cmd,1,1) != "$")
{
# comments must have a "#" in col 1
if (cmd != "" && substr(cmd,1,1) != "#" )
{
# if the commands are not to be executed, stuff them into the
# return array
#
if (argcount() >= 3 && no_execute)
{
data[index++] = cmd
}
# or new buffer flags with ones from edit_file so we don't
# lose the read only stuff
#
else if ( "buffer_flags" == substr(cmd, 1, 12) )
{
current_buffer = old_buffer
buffer_flags = or(buffer_flags, substr(cmd, 14) );
current_buffer = config_buffer
}
# execute config command
#
else if ((fid = quoted_function_id(cmd)))
{
save_position()
current_buffer = old_buffer
execute_function(fid)
old_buffer = current_buffer
current_buffer = config_buffer
restore_position(TRUE)
}
else
warning( "Config: \"%s\" is invalid, line %d.", cmd, current_line )
}
else if (argcount() >= 4 && include_comments && cmd != "")
{
data[index++] = cmd
}
if ( !down(1) )
break
cmd = ltrim( trim(read_buffer()) )
}
}
}
if ( free_buffer )
delete_config_buffer()
current_buffer = old_buffer
delete_event( EVENT.ERROR, "read_config_error" )
if (argcount() >= 3 && no_execute)
return data
}
global function buffer_state_config()
{
local firstBuf = 0
local buf = 0
local flg = 0
local lastBuffer = ""
local data[]
local i = 1
# append state information
data[ i++ ] = sprintf( "# %s - Buffer State Information\t%s\n", editor_title, ctime() )
buf = firstBuf = current_buffer
# ensure that firstBuf is not a system buffer
if ( and( buffer_flags, BUFFER_SYSTEM ) )
firstBuf = prev_buffer()
do
{
if (buffer_filename && !and(buffer_flags, BUFFER_SCRATCH) )
{
# CFV don't save the read-only bit
#
flg = and( buffer_flags, not( BUFFER_READ_ONLY + BUFFER_MODIFIED + BUFFER_AUTOSAVE_MODIFIED + BUFFER_IN_VIRTUAL_SPACE) )
# the new config method is more complex in that you
# must be sure to insert to the correct buffer!
data[ i++ ] = sprintf( "BUFFER \"%s\", %d, \"%s\", %d, %d, \"%s\", %d\n",
buffer_filename,
flg,
buffer_name,
current_line,
current_column,
buffer_tabs,
auto_indent_mode )
}
} while ( prev_buffer() != firstBuf )
data[ i++ ] = sprintf( "\n" )
current_buffer = firstBuf
return data
}
global function window_state_config()
{
local width = 0
local height = 0
local x_pos = 0
local y_pos = 0
local win_x = 0
local win_y = 0
local editwin_state = 0
local window_number = 1
local MIN_WIDTH = 10
local MIN_HEIGHT = 10
local firstWin = 0
local noStartWin = TRUE
local fmt = ""
local lastBuffer = ""
local data[]
local i = 1
# append state information
data[ i++ ] = sprintf( "# %s - State Information\t%s\n", editor_title, ctime() )
# save the current directory
if ( and( save_flags, SAVE_DIRECTORY ) )
data[ i++ ] = sprintf( "set_startup_dir %s\n", getcwd())
# save editwin's normal position and size
if ( query_editwin_property(EWC_MAXIMIZE) || query_editwin_property(EWC_MINIMIZE) )
{
width = query_editwin_property( EWC_RESTORE_WIDTH )
height = query_editwin_property( EWC_RESTORE_HEIGHT )
x_pos = query_editwin_property( EWC_RESTORE_X_POS )
y_pos = query_editwin_property( EWC_RESTORE_Y_POS )
}
else
{
width = query_editwin_property( EWC_WIDTH )
height = query_editwin_property( EWC_HEIGHT )
x_pos = query_editwin_property( EWC_X_POS )
y_pos = query_editwin_property( EWC_Y_POS )
}
data[ i++ ] = sprintf( "EDITOR " max(width, MIN_WIDTH) ", " max(height, MIN_HEIGHT) "\n" )
lastBuffer = buffer_name
firstWin = current_window;
if ( firstWin != 0 )
{
do
{
next_window( "", 1, 1 ); # We include system windows, but we don't process them?
# don't save information on system windows
if ( !and( window_flags, WINDOW_SYSTEM ) && ( !create_new_bufwin || (create_new_bufwin && !and(buffer_flags, BUFFER_SCRATCH) ) ) )
{
if (noStartWin)
{
# data[ i++ ] = sprintf( "delete_default_window\n" );# make a least one window
# data[ i++ ] = sprintf( "set_editwin_property %d\n", EWC_NORMAL)
noStartWin = 0;
}
if ( query_editwin_property(EWC_MINIMIZE, current_window) ||
query_editwin_property(EWC_MAXIMIZE, current_window) )
{
win_x = query_editwin_property( EWC_RESTORE_X_POS, current_window )
win_y = query_editwin_property( EWC_RESTORE_Y_POS, current_window )
width = query_editwin_property( EWC_RESTORE_WIDTH, current_window )
height = query_editwin_property( EWC_RESTORE_HEIGHT, current_window )
}
else
{
win_x = window_x0
win_y = window_y0
width = window_width
height = window_height
}
data[ i++ ] = sprintf( "WINDOW %d, %d, %d, %d, %d, \"%s\", \"%s\", \"%s\"\n",
win_x,
win_y,
width,
height,
window_flags,
window_name,
linenumber_format,
buffer_name )
data[ i++ ] = sprintf( "WIN_VISIBLES \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\"\n",
visible_end_buffer,
visible_spaces,
visible_tabs,
visible_newlines,
visible_virtual_lines,
visible_virtual_spaces )
data[ i++ ] = sprintf( "WIN_COLORS %d, %d, %d, %d, %d, %d\n",
color_window_fg,
color_window_bg,
color_linenumbers_fg,
color_linenumbers_bg,
color_linecommands_fg,
color_linecommands_bg )
# scroll settings
data[ i++ ] = sprintf( "WIN_CONTEXT %d, %d, %d, %d, %d, %d, %d\n",
scroll_context_top,
scroll_context_bottom,
scroll_context_right,
scroll_context_left,
scroll_unit_horizontal,
scroll_unit_vertical,
scroll_means_pan )
# font information
store_font("window_" window_number, "Fonts")
data[ i++ ] = sprintf( "load_font \"window_%d\" \"Fonts\"\n",
window_number )
if ( mdi_mode == 2 )
data[i++] = sprintf( "toggle_status_bar 1 %d\n", status_bar_flags )
if(and(window_flags, WINDOW_ASCII_DUMP))
{
data[i++] = sprintf("save_hex_state %d \"%s\"\n",
old_hex_info[current_window].status,
old_hex_info[current_window].format "");
}
window_number++
}
} while (firstWin != current_window);
}
if ( query_editwin_property(EWC_MAXIMIZE) )
editwin_state = EWC_MAXIMIZE
else if ( query_editwin_property(EWC_NORMAL) )
editwin_state = EWC_NORMAL
else
editwin_state = EWC_MINIMIZE
# save whether or not the editor was maximized/normal/minimized
data[ i++ ] = sprintf( "EDITOR %d, %d, %d\n", editwin_state, x_pos, y_pos )
data[ i++ ] = sprintf( "\n" )
return data
}
global function save_flags_config()
{
local data[]
local i = 1
data[ i++ ] = sprintf( "save_state=%d\n", save_state )
data[ i++ ] = sprintf( "save_flags=%d\n", save_flags )
data[ i++ ] = sprintf( "\n" )
return data
}
# This functions saves those sections that are considered to be part of
# the SETTINGS of the editor
#
global function save_settings_data( save_settings_now, config_buffer )
{
local old_buffer = current_buffer
local free_buffer = FALSE
# if no config_buffer is specified then get it otherwise use the
# config_buffer passed in.
if (argcount() < 2 || !config_buffer)
{
if (get_config_buffer())
{
config_buffer = current_buffer
current_buffer = old_buffer
free_buffer = TRUE
}
else
return
}
# this function is in both save_settings_data() and
# save_state_data() so that the flags are always updated
#
update_config_section( "$SAVE_FLAGS$", save_flags_config(),
config_buffer )
if ( and( save_flags, SAVE_SETTINGS ) || save_settings_now )
{
update_config_section( "$SETTINGS$", settings_config(),
config_buffer )
update_config_section( "$BUFFER1_SETTINGS$", buffer1_settings_config(),
config_buffer );
update_config_section( "$BUFFER2_SETTINGS$", buffer2_settings_config(),
config_buffer );
update_config_section( "$BUFFER3_SETTINGS$", buffer3_settings_config(),
config_buffer );
update_config_section( "$WINDOW1_SETTINGS$", window1_settings_config(),
config_buffer );
update_config_section( "$WINDOW2_SETTINGS$", window2_settings_config(),
config_buffer );
update_config_section( "$WINDOW3_SETTINGS$", window3_settings_config(),
config_buffer );
update_config_section( "$PRINT_SETTINGS$", save_print_settings(),
config_buffer )
update_config_section( "$ISPF$",
optional_function( "save_ispf_settings" ),
config_buffer )
}
if ( free_buffer )
delete_config_buffer(TRUE)
current_buffer = old_buffer
}
# This functions saves those sections that are considered to be part of
# the STATE of the editor
#
global function save_state_data( save_state_now, config_buffer )
{
local old_buffer = current_buffer
local free_buffer = FALSE
# if no config_buffer is specified then get it otherwise use the
# config_buffer passed in.
if (argcount() < 2 || !config_buffer)
{
if (get_config_buffer())
{
config_buffer = current_buffer
current_buffer = old_buffer
free_buffer = TRUE
}
else
return
}
# this function is in both save_settings_data() and
# save_state_data() so that the flags are always updated
#
update_config_section( "$SAVE_FLAGS$", save_flags_config(),
config_buffer )
if ( save_state || save_state_now )
{
update_config_section( "$BUFFER_STATE$", buffer_state_config(), config_buffer )
update_config_section( "$WINDOW_STATE$", window_state_config(), config_buffer )
}
if ( and( save_flags, SAVE_COMMANDS ) )
update_config_section( "$XMACRO_HISTORY$", history_config("XMACRO"),
config_buffer )
if ( and( save_flags, SAVE_SEARCH ) )
{
update_config_section( "$SEARCH_HISTORY$", history_config("SEARCH"),
config_buffer )
update_config_section( "$SRCHFILES_HISTORY$",
history_config("SRCHFILES"), config_buffer )
}
if ( and( save_flags, SAVE_REPLACE ) )
update_config_section( "$REPLACE_HISTORY$",
history_config("REPLACE"), config_buffer )
if ( and( save_flags, SAVE_EDITFILE ) )
update_config_section( "$EDITFILE_HISTORY$",
history_config("EDITFILE"), config_buffer )
if ( and( save_flags, SAVE_COMPILE ) )
update_config_section( "$COMPILE_HISTORY$",
history_config("COMPILE"), config_buffer )
if ( free_buffer )
delete_config_buffer(TRUE)
current_buffer = old_buffer
}
# faster version of its predecessor
global function update_config_section( section_name, data_array, config_buffer )
{
local re_section_name = ""
local in_target_section = FALSE
local free_buffer = FALSE
local old_buffer = current_buffer
local data, section_begin
# ensure we are getting something to add
#
if ( !data_array )
return
# if no config_buffer is specified then get it otherwise use the
# config_buffer passed in.
if (argcount() < 3 || !config_buffer)
{
if (get_config_buffer())
{
config_buffer = current_buffer
free_buffer = TRUE
}
else
return
}
current_buffer = config_buffer
goto_buffer_top()
# look for the section name
re_section_name = section_name
gsub( "\\$", "\\$", re_section_name )
if ( search( "^" re_section_name, SEARCH_FWD_REGEX) )
{
in_target_section = TRUE
# go to the first line of the section
if ( down(1) )
{
section_begin = current_line
begin_selection( LINE_SELECTION )
# look for the next section
if ( search("^\\$[a-zA-Z0-9_]+\\$", SEARCH_FWD_REGEX) )
up( 1 )
# if no other section, go to eob
else
goto_buffer_bottom()
# delete the body of our current section
end_selection()
# only delete chars if it is at least one line long!
if ( current_line >= section_begin )
delete_chars()
else
{
remove_selection()
down( 1 )
}
}
# else if at the end of the buffer, start on a new line
else
{
goto_eol()
insert_newline()
}
goto_bol()
}
# if it doesn't exist, go to $STATE$; if $STATE$ doesn't exist, go to eob
else # if ( !search("^\\$STATE\\$", SEARCH_FWD_REGEX) )
{
goto_buffer_bottom()
# if we're not on a blank line, make a new one
if ( current_line_length )
{
goto_eol()
insert_newline()
}
}
# if we did not find the section specified, create it
if ( !in_target_section )
{
insert_string( "%s\n", section_name )
}
for ( data in data_array )
{
# replace any hardcoded 0x13 and 0x9 with \n and \t.
# sub( "$", "\\\\n", data_array[ data ] )
gsub( "\t", "\\\\t", data_array[ data ] )
# if we're not on a blank line, make a new one
if ( current_line_length )
{
goto_bol()
insert_newline()
up()
}
insert_string( data_array[ data ] )
}
if ( free_buffer )
delete_config_buffer(TRUE)
current_buffer = old_buffer
}
global function get_config_buffer()
{
local rc
local prevEol
local cfgName
local old_message_level = message_level;
if (config_buffer_ref_count && the_config_buffer)
{
rc = TRUE
current_buffer = the_config_buffer
config_buffer_ref_count++
}
else
{
# search cpe path for the config file
if ( !(cfgName = locate_cpe_file(CPE_FILE_CONFIG)) )
cfgName = editor_path( CPE_FILE_CONFIG )
prevEol = default_buffer_eol_string
default_buffer_eol_string = "\r\n"
current_buffer = create_buffer( "Config File" ,
cfgName ,
BUFFER_SYSTEM +
BUFFER_NO_UNDO +
BUFFER_REAL_SPACE_ONLY )
# Have to be sure to turn insert mode on, otherwise config may get messed up;
message_level = 1;
toggle_buffer_flags(BUFFER_OVERTYPE_MODE, 0);
message_level = old_message_level;
# restore the default end of line sequence
default_buffer_eol_string = prevEol
rc = ( buffer_size > 0 )
# initialize an empty config file
if ( buffer_size == 0 )
{
insert_string( "# %s - Configuration File\n", editor_title )
insert_string( "$USER_SETTINGS$ \n\n# Place user settings here\n\n" )
write_buffer()
}
config_buffer_ref_count = 1
the_config_buffer = current_buffer
}
return( rc )
}
global function delete_config_buffer(forUpdate)
{
local old_buffer
config_buffer_ref_count--
if ( config_buffer_ref_count <= 0)
{
if (the_config_buffer)
{
old_buffer = current_buffer
if (argcount() && forUpdate)
{
current_buffer = the_config_buffer
if (buffer_is_modified())
write_buffer()
}
delete_buffer(the_config_buffer)
if (old_buffer != the_config_buffer)
current_buffer = old_buffer
the_config_buffer = 0
}
config_buffer_ref_count = 0
}
}
# This function is attached to the EVENT.EXIT_EDITOR and is used to save
# the various sections of the config file
#
global function write_state_file()
{
local config_buffer
local old_buffer = current_buffer
if ( get_config_buffer() )
{
# save config_buffer id in case one of the sections changes the
# current_buffer
#
config_buffer = current_buffer
current_buffer = old_buffer
save_state_data(0, config_buffer)
save_settings_data(0, config_buffer)
delete_config_buffer(TRUE)
current_buffer = old_buffer
}
}
#
# attach_win_to_buf()
#
# provide a means of attaching the current window to the current buffer
# from within an execute_function call.
#
global function attach_win_to_buf()
{
attach_window_buffer( current_window, current_buffer );
update_current_view()
}
global function delete_default_window()
{
local cw = current_window;
local wf = window_flags;
next_window();
while( !and( window_flags, WINDOW_SYSTEM ) && current_window)
{
delete_window();
next_window();
}
if (and( wf, WINDOW_SYSTEM) && cw)
assign_current_window( cw );
}
global function editor_start()
{
if ( !query_editwin_property( EWC_MINIMIZE ) )
{
if ( !query_editwin_property( EWC_MAXIMIZE ) )
set_editwin_property( EWC_NORMAL )
set_editwin_property( EWC_TO_TOP )
}
if ( mdi_mode == 2 )
current_window = current_window
delete_event(EVENT.EDITOR_RUNNING, function_id("editor_start"))
editor_running = TRUE
}
# DWM 9/28/94
# Instead of calling all of these functions from the config file,
# just create a function that does all of the work.
global function setup_buffer( filespec, bflags, bname, line, col, tabs, a_i )
{
local mask;
if ( !is_floppy_drive(filespec) || filemode(filespec) != -1 )
{
mask = BUFFER_OVERTYPE_MODE + BUFFER_SNAP_TO_EOL + \
BUFFER_REAL_SPACE_ONLY + BUFFER_EXPAND_TABS + \
BUFFER_TABS_TO_SPACES + BUFFER_WP_CARRY_COMMENTS + \
BUFFER_WP_ENABLED + BUFFER_WP_WRAP_CONTINUOUS
edit_file(filespec )
buffer_flags = set_flag_bits(buffer_flags, mask, bflags )
buffer_name = bname
current_line = line
current_column = col
buffer_tabs = tabs
toggle_auto_indent( a_i )
}
}
global function setup_window( x, y, width, height, flags, wname, lformat, buffer )
{
local old_name = buffer_name
if ( mdi_mode == 2 )
{
current_window = create_window( x, y, width, height, flags )
attach_menu_to_win( current_window )
}
else
current_window = create_window( x, y, width, height, flags )
next_buffer( buffer )
if ( buffer_name == old_name && and(buffer_flags, BUFFER_SYSTEM) )
{
next_buffer()
}
attach_window_buffer( current_window, current_buffer )
update_current_caption()
if ( wname )
window_name = wname
if (and(flags, WINDOW_ASCII_DUMP))
begin_dump_mode()
linenumber_format = lformat
}
global function setup_window_colors( fg, bg, l_fg, l_bg, lc_fg, lc_bg )
{
color_window_fg = fg
color_window_bg = bg
color_linenumbers_fg = l_fg
color_linenumbers_bg = l_bg
color_linecommands_fg = lc_fg
color_linecommands_bg = lc_bg
}
global function setup_window_context( top, bottom, right, left, shorz, svert, smp )
{
scroll_context_top = top
scroll_context_bottom = bottom
scroll_context_right = right
scroll_context_left = left
scroll_unit_horizontal = shorz
scroll_unit_vertical = svert
scroll_means_pan = smp
}
global function setup_window_visibles( veob, vs, vt, vn, vvl, vvs )
{
visible_end_buffer = veob
if ( vs )
visible_spaces = vs
visible_tabs = vt
visible_newlines = vn
visible_virtual_lines = vvl
if ( vvs )
visible_virtual_spaces = vvs
}
global function move_ed_offscreen( width, height )
{
set_editwin_property( EWC_X_POS, 5000 )
set_editwin_property( EWC_Y_POS, 5000 )
set_editwin_property( EWC_WIDTH, width )
set_editwin_property( EWC_HEIGHT, height )
set_editwin_property( EWC_NORMAL )
}
global function setup_editwin( mode, x, y )
{
set_editwin_property( mode )
if ( mode == EWC_NORMAL )
{
set_editwin_property( EWC_X_POS, x )
set_editwin_property( EWC_Y_POS, y )
}
else
{
set_editwin_property( EWC_RESTORE_X_POS, x )
set_editwin_property( EWC_RESTORE_Y_POS, y )
}
}
local function unquote( str )
{
local no_quotes
# first trim whitespace, then "'s
no_quotes = trim( ltrim(str) )
no_quotes = trim( ltrim(no_quotes, "\""), "\"" )
return( unquote_string(no_quotes) )
}
local function process_setting_command( count, cmd, args, arg_list )
{
local ret_val = TRUE
# $SETTINGS$ settings
if ( cmd == "BRIEF" )
optional_function("brief")
else if ( cmd == "CUA" )
optional_function("cua")
else if ( cmd == "EMACS" )
optional_function("emacs")
else if ( cmd == "VI" )
optional_function("vi")
else if ( cmd == "ISPF" )
optional_function("ispf")
else if ( cmd == "NATIVE" )
optional_function("native")
else if ( cmd == "DEF_TABS" )
{
if ( count != 3 )
warning( "DEF_TABS requires 3 arguments in cpe.cfg" )
else
{
default_buffer_tabs = unquote( arg_list[ 1 ] )
default_wp_right_margin = arg_list[ 2 ]
default_wp_left_margin = arg_list[ 3 ]
}
}
else if ( cmd == "WORD_DELIM" )
{
if ( !args )
warning( "WORD_DELIM requires 1 argument in cpe.cfg" )
else
word_delimiter = unquote( args )
}
else if ( cmd == "SRCH_REPL" )
{
if ( count != 3 )
warning( "SRCH_REPL requires 3 arguments in cpe.cfg" )
else
{
search_flags = arg_list[ 1 ]
search_pattern = unquote( arg_list[ 2 ] )
replace_pattern = unquote( arg_list[ 3 ] )
}
}
else if ( cmd == "BACKUP" )
{
if ( count != 2 )
warning( "BACKUP requires 2 arguments in cpe.cfg" )
else
{
backup_files_enabled = arg_list[ 1 ]
backup_directory = unquote( arg_list[ 2 ] )
}
}
else if ( cmd == "DEF_COLS" )
{
if ( count != 12 )
warning( "DEF_COLS requires 12 arguments in cpe.cfg" )
else
{
color_help_bg = arg_list[ 1 ]
color_help_fg = arg_list[ 2 ]
color_message_bg = arg_list[ 3 ]
color_message_fg = arg_list[ 4 ]
color_notify_bg = arg_list[ 5 ]
color_notify_fg = arg_list[ 6 ]
color_warning_bg = arg_list[ 7 ]
color_warning_fg = arg_list[ 8 ]
color_error_bg = arg_list[ 9 ]
color_error_fg = arg_list[ 10 ]
color_bookmark_bg = arg_list[ 11 ]
color_bookmark_fg = arg_list[ 12 ]
}
}
else if ( cmd == "CURSORS" )
{
if ( count != 4 )
warning( "CURSORS requires 4 arguments in cpe.cfg" )
else
{
cursor_normal = arg_list[ 1 ]
cursor_overtype = arg_list[ 2 ]
cursor_virtual = arg_list[ 3 ]
cursor_virtual_overtype = arg_list[ 4 ]
}
}
else if ( cmd == "STAT" )
{
if ( count != 2 )
warning( "STAT requires 2 arguments in cpe.cfg" )
else
{
status_bar_flags = arg_list[ 1 ]
toggle_status_bar( arg_list[2] )
#toggle_toolbar( arg_list[3] )
}
}
else if ( cmd == "SET_VCS" )
{
if ( count != 3 )
warning( "SET_VCS requires 3 arguments in cpe.cfg" )
else
{
pvcs( arg_list[1] )
get_command = unquote( arg_list[2] )
put_command = unquote( arg_list[3] )
}
}
else if ( cmd == "SET_MDI" )
{
if ( count != 2 )
warning( cmd " requires 2 arguments in cpe.cfg" )
else
{
mdi_mode = arg_list[1]
modify_mdi_menu( arg_list[1] )
temp_create_new_bufwin = arg_list[2]+0;
if ( mdi_mode == 2 )
{
create_container_list();
}
}
}
else if ( cmd == "TAGS_PATH" )
{
if ( !args )
warning( "TAGS_PATH requires 1 arguments in cpe.cfg" )
else
tags_path = args
}
else
ret_val = FALSE
return ret_val
}
local function process_state_command( count, cmd, args, arg_list, noWindows )
{
local ret_val = TRUE
# $STATE$ settings
if ( cmd == "EDITOR" )
{
if ( count == 2 )
move_ed_offscreen( arg_list[1], arg_list[2] )
else if ( count == 3 )
{
if ( start_editor_minimized )
{
arg_list[1] = EWC_MINIMIZE
}
setup_editwin( arg_list[1], arg_list[2], arg_list[3] )
}
else
warning( "EDITOR requires 2 or 3 arguments in cpe.cfg" )
}
else if ( cmd == "BUFFER" )
{
if ( count != 7 )
warning( "BUFFER requires 7 arguments in cpe.cfg" )
else
setup_buffer( unquote(arg_list[1]), arg_list[2], unquote(arg_list[3]),
arg_list[4], arg_list[5], unquote(arg_list[6]), arg_list[7] )
}
else if( cmd == "WINDOW" )
{
if(noWindows)
nop();
else if ( count != 8 )
warning( "WINDOW requires 8 arguments in cpe.cfg" )
else
setup_window( arg_list[1], arg_list[2], arg_list[3],
arg_list[4], arg_list[5], unquote(arg_list[6]),
unquote(arg_list[7]), unquote(arg_list[8]) )
}
else if ( cmd == "WIN_COLORS" )
{
if(noWindows)
nop();
else if ( count != 6 )
warning( "COLORS requires 6 arguments in cpe.cfg" )
else
setup_window_colors( arg_list[1], arg_list[2], arg_list[3],
arg_list[4], arg_list[5], arg_list[6] )
}
else if ( cmd == "WIN_CONTEXT" )
{
if(noWindows)
nop();
else if ( count != 7 )
warning( "WIN_CONTEXT requires 7 arguments in cpe.cfg" )
else
setup_window_context( arg_list[1], arg_list[2], arg_list[3],
arg_list[4], arg_list[5], arg_list[6], arg_list[7] )
}
else if ( cmd == "WIN_VISIBLES" )
{
if(noWindows)
nop();
else if ( count != 6 )
warning( "WIN_VISIBLES requires 6 arguments in cpe.cfg" )
else
setup_window_visibles( unquote(arg_list[1]), unquote(arg_list[2]), unquote(arg_list[3]),
unquote(arg_list[4]), unquote(arg_list[5]), unquote(arg_list[6]) )
}
else
ret_val = FALSE
return ret_val
}
local function process_color_config( array )
{
if ( array )
{
default_color_window_fg = array[ 1 ]
default_color_window_bg = array[ 2 ]
default_color_linenumbers_fg = array[ 3 ]
default_color_linenumbers_bg = array[ 4 ]
default_color_linecommands_fg = array[ 5 ]
default_color_linecommands_bg = array[ 6 ]
default_color_message_fg = array[ 7 ]
default_color_message_bg = array[ 8 ]
default_color_notify_fg = array[ 9 ]
default_color_notify_bg = array[ 10 ]
default_color_warning_fg = array[ 11 ]
default_color_warning_bg = array[ 12 ]
default_color_error_fg = array[ 13 ]
default_color_error_bg = array[ 14 ]
default_color_bookmark_fg = array[ 15 ]
default_color_bookmark_bg = array[ 16 ]
}
}
local function do_fast_config( section_name, data_array, noWindows )
{
local index
local cmd
local cmdstr
local str
local args
local count
local arg_list[]
local first_space
local fid
local success
if ( section_name == "$STATE$" )
{
delete_default_window()
}
for ( index in data_array )
{
str = data_array[index]
first_space = cindex( str, " " )
if ( first_space )
cmdstr = prefix( str, first_space - 1 )
else
cmdstr = str
cmd = cmdstr
args = suffix( str, length(str) - first_space )
count = split( args, arg_list, "," )
if ( section_name == "$STATE$" )
success = process_state_command( count, cmd, args, arg_list, noWindows )
else if ( section_name == "$SETTINGS$" )
success = process_setting_command( count, cmd, args, arg_list )
else
{
warning( section_name "--invalid section name" )
return
}
if ( !success )
{
if ( (fid = quoted_function_id(str)) )
execute_function(fid)
else
warning( str "--invalid configuration command" )
}
}
}
# function called on startup if the 'save directory on exit' option was set.
global function set_startup_dir(path)
{
if (!editor_running && argcount() > 0)
{
# We are processing the config file, so save the parameter and set event
# to reinvoke this function when startup is complete.
startup_dir = path
attach_event_handler(EVENT.EDITOR_RUNNING, "set_startup_dir")
}
else if (editor_running)
{
delete_event(EVENT.EDITOR_RUNNING, "set_startup_dir")
if (argcount() < 1)
path = startup_dir # use the path saved above
chdir(path)
}
}