home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
p2demo21.exe
/
PEL
/
PVCS.PEL
< prev
next >
Wrap
Text File
|
1995-02-28
|
21KB
|
701 lines
# $Header: P:\source\wmacros\pvcs.pev 1.57 28 Feb 1995 13:47:12 PFHJXM0 $
##############################################################################
#
# 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: pvcs.pel $: PVCS support
### global variables
global PVCS_DISABLED = 0x00
global PVCS_ENABLE_MENU = 0x01
global PVCS_ENABLE_GETS = 0x02
global PVCS_ENABLE_EMPTY_GETS = 0x04
local IDC_VCS_ON_MOD = 101;
local IDC_VCS_ON_NON = 102;
global PVCS_CUR_BUF = "{Current Buffer}"
global default_get_command = "get -l $<";
global default_put_command = "put -u $<";
global get_command = default_get_command;
global put_command = default_put_command;
### local variables
global pvcsEnabled
local pvcsPutEnabled
#local pvcsEmptyEnabled
#local pvcsMenuEnabled
local pvcsPutId
local pvcsGetId
local pvcsGetEmptyId
local pvcsBuffersGot
#local pvcsRevision = ""
# These are possible future PVCS ids. They are commented out
# because they produce warnings when not used.
#local IDM_PVCS = 2999
#local IDM_GET = 3000
#local IDM_PUT = 3001
#local IDM_INDENT = 3002
#local IDM_REGEN = 3003
#local IDM_VCS = 3004
#local IDM_VCOMPRESS = 3005
#local IDM_VDEL = 3006
#local IDM_VDIFF = 3007
#local IDM_VJOURNAL = 3008
#local IDM_VLOG = 3009
#local IDM_VLOGIN = 3010
#local IDM_VMRG = 3011
#local IDM_VNAME = 3012
#
## pvcs() and
## toggle_pvcs()
#
# Enable PVCS get and put. The "on" argument can be set to one of
# four values depending on the desired configuration:
#
# PVCS_DISABLED = 0 - disable PVCS
# PVCS_ENABLE_GETS = 1 - enable get and put via existing file edits
# PVCS_ENABLE_EMPTY_GETS = 2 - enable get and put via non-existant
# file reads
# PVCS_ENABLE_GETS +
# PVCS_ENABLE_EMPTY_GETS = 3 - enable get and put via existing and
# non-existant files
#
global function pvcs( on )
{
if ( argcount() )
toggle_pvcs( on )
else
toggle_pvcs()
}
global function toggle_pvcs( on )
{
local hmenu
if ( !argcount())
{
# on = not(and(pvcsEnabled, PVCS_ENABLE_GETS));
if(and(pvcsEnabled, PVCS_ENABLE_GETS))
on = PVCS_DISABLED;
else
on = PVCS_ENABLE_GETS + PVCS_ENABLE_MENU;
message( "PVCS " (on ? "Enabled." : "Disabled." ))
}
else
on = 0+on
pvcs_menu( on )
#
# enable puts for all files
#
if (on && !pvcsPutEnabled)
{
pvcsPutEnabled = 1
pvcsPutId = function_id( "pvcs_put_buffer" )
attach_event_handler( EVENT.EDIT_FILE_SAVE, pvcsPutId )
}
else if (!on && pvcsPutEnabled)
{
pvcsPutEnabled = 0
delete_event( EVENT.EDIT_FILE_SAVE, pvcsPutId )
}
#
# enable gets for existing files
#
if (and( on, PVCS_ENABLE_GETS ) && !and(pvcsEnabled, PVCS_ENABLE_GETS))
{
pvcsGetId = function_id( "pvcs_get_existing_buffer" )
attach_event_handler( EVENT.READ_ONLY_MOD, pvcsGetId )
}
else if (!and( on, PVCS_ENABLE_GETS ) && and(pvcsEnabled, PVCS_ENABLE_GETS))
{
delete_event( EVENT.READ_ONLY_MOD, pvcsGetId )
}
pvcsEnabled = set_flag_bits(pvcsEnabled, PVCS_ENABLE_GETS, on);
#
# enable gets for non-existing files
#
if (and( on, PVCS_ENABLE_EMPTY_GETS ) && !and(pvcsEnabled, PVCS_ENABLE_EMPTY_GETS))
{
pvcsGetEmptyId = function_id( "pvcs_get_empty" )
attach_event_handler( EVENT.NEW_EDIT_FILE, pvcsGetEmptyId )
}
else if (!and( on, PVCS_ENABLE_EMPTY_GETS ) && and(pvcsEnabled, PVCS_ENABLE_EMPTY_GETS))
{
delete_event( EVENT.NEW_EDIT_FILE, pvcsGetEmptyId )
}
pvcsEnabled = set_flag_bits(pvcsEnabled, PVCS_ENABLE_EMPTY_GETS, on);
# Enable the pvcs menu without turning on the pvcs features;
pvcsEnabled = set_flag_bits(pvcsEnabled, PVCS_ENABLE_MENU, on);
}
###
### event handlers for PVCS
###
### event handler invoked when attempting to edit a non-exisiting file
global function pvcs_get_empty()
{
local prevPauseOnError
prevPauseOnError = pause_on_error
pause_on_error = 0
if ( and(pvcsEnabled, PVCS_ENABLE_EMPTY_GETS) && filemode( buffer_filename ) < 0)
{
# file doesn't exist
pvcs_get_existing_buffer( 1 )
}
pause_on_error = prevPauseOnError
}
### event handler invoked when attempting to edit a read-only buffer
## pvcs_get_existing_buffer()
#
# forceget instructs not to delete the buffer and reload, just perform
# the PVCS command.
#
global function pvcs_get_existing_buffer( forceget )
{
local cmd
local prevPauseOnError
local fmode = filemode( buffer_filename )
local read_only = (fmode > 0 && and(fmode, _READ_ONLY))
prevPauseOnError = pause_on_error
pause_on_error = 0
# check the file's read-only status
if ( forceget || (and(pvcsEnabled, PVCS_ENABLE_GETS) && read_only ) )
{
if (buffer_is_modified())
{
if (toupper(confirm(buffer_filename " has been MODIFIED, get anyway? [YN]", "YyNn")) \
!= "Y")
{
pause_on_error = prevPauseOnError
return
}
}
else if (!read_only)
{
if (toupper(confirm("Any changes to " buffer_filename " will be lost, get anyway? [YN]", "YyNn")) \
!= "Y")
{
pause_on_error = prevPauseOnError
return
}
}
cmd = prompt_history("PVCSGET", "Enter a VCS \"get\" command: ",
# get_command " " pvcsRevision buffer_filename,
expand_command(get_command, buffer_filename),
FALSE, FALSE, "pvcs_get_dialog" )
if ( cmd )
{
# perform the GET command
pvcsSystemCommand( cmd, forceget )
# add this buffer to the list if we have it locked
if ( !and(buffer_flags, BUFFER_READ_ONLY) )
pvcsBuffersGot[ current_buffer ] = (cmd ~ /<-[Ll]/)
}
}
pause_on_error = prevPauseOnError
}
### event handler invoked when attempting to write a buffer
global function pvcs_put_buffer( forceput )
{
local priorPvcsEnabled
local cmd
local temp_fname
# see if the current buffer originated from a PVCS get
if ( (pvcsEnabled && current_buffer in pvcsBuffersGot && \
pvcsBuffersGot[current_buffer] ) || forceput )
{
cmd = prompt_history(
"PVCSPUT",
"Enter a VCS \"put\" command: ",
# put_command " " pvcsRevision buffer_filename,
expand_command(put_command, buffer_filename),
FALSE,
FALSE, "pvcs_put_dialog" )
if ( cmd )
{
# write the current buffer to disk if necessary,
priorPvcsEnabled = pvcsEnabled
pvcsEnabled = 0 # prevent recursion
write_buffer_key()
pvcsEnabled = priorPvcsEnabled
# perform the put command
pvcsSystemCommand( cmd )
}
}
}
## support functions for pvcs commands
local bufferSavedState[]
local function pvcsSystemCommand( cmd, forceget )
{
enable_buffer_change_error()
# save the current state of the current buffer
saveBufferState()
# change to the directory where the file is
push_dir( path_path( buffer_filename ))
# run command in a separate session and disable redrawing of
# the editor window
# dos_box(cmd, SYS_NOEXPOSE + SYS_PROMPT, cmd)
system_pause(cmd, SYS_SESSION + SYS_NOEXPOSE)
# restore the prior working directory
pop_dir()
# re-edit the file and restore the state of the
# buffer to what it was, depending on the file's
# new read-write/read-only status, etc.
rereadNewBuffer()
# if a wildcard GET or PUT was performed, check all buffers
# for conflicts
if ( cmd ~ /[*?][^ \t]*$/ )
checkAllFilemodes();
}
local function checkAllFilemodes()
{
#
# PVCS GET and PUT commands can result in changes to the filemodes
# of one or more files. This function synchronizes the read-write/
# read-only status of all buffers currently in the editor with their
# corresponding disk files.
#
local priorBuffer = current_buffer
local sentinel = next_buffer("", 0, 1)
local fmode
do {
fmode = filemode( buffer_filename )
if ( fmode >= 0 )
{
if ( !and( fmode, _READ_ONLY ) != \
!and( buffer_flags, BUFFER_READ_ONLY ) )
{
# read only status differs:
saveBufferState()
bufferSavedState[ "filetime" ] = 0
rereadNewBuffer()
}
}
} while( next_buffer("", 0, 1) != sentinel )
current_buffer = priorBuffer
}
local function saveBufferState()
{
#
# save salient info about the current buffer in an array
#
bufferSavedState[ "filename" ] = buffer_filename
bufferSavedState[ "filetime" ] = filetime( buffer_filename )
bufferSavedState[ "name" ] = buffer_name
bufferSavedState[ "flags" ] = buffer_flags
bufferSavedState[ "line" ] = current_line
bufferSavedState[ "column" ] = current_column
bufferSavedState[ "keymap" ] = buffer_keymap
bufferSavedState[ "tabs" ] = buffer_tabs
}
local function rereadNewBuffer()
{
local fmode
local anything
local old_create_new_bufwin;
#
# re-read a buffer which has possibly been changed by a system
# command, using the attributes saved by function saveBufferState()
#
# if ( anything in bufferSavedState )
if ( bufferSavedState["filename"] )
{
# has the disk file changed?
if ( bufferSavedState[ "filetime" ] != filetime( buffer_filename ))
{
# delete the current buffer without asking
#
buffer_flags = and( buffer_flags, not( BUFFER_MODIFIED ))
old_create_new_bufwin = create_new_bufwin;
create_new_bufwin = 0;
delete_buffer();
create_new_bufwin = old_create_new_bufwin;
# create a new buffer with the same attributes
# as before
#
current_buffer = create_buffer( bufferSavedState[ "name" ], \
bufferSavedState[ "filename" ], \
bufferSavedState[ "flags" ] )
new_edit_file()
current_line = bufferSavedState[ "line" ]
current_column = bufferSavedState[ "column" ]
buffer_keymap = bufferSavedState[ "keymap" ]
buffer_tabs = bufferSavedState[ "tabs" ]
center_cursor()
}
delete bufferSavedState
}
# update the read-only bit of the buffer to match the disk file
#
fmode = filemode( buffer_filename )
if ( fmode >= 0 )
toggle_buffer_flags( BUFFER_READ_ONLY, and( fmode, _READ_ONLY ) )
# warning("filetime(curr_buff) == %d", filetime( buffer_filename ) )
return fmode
}
## assemble a logfile revision or disk filename
#
global function pvcs_make_name( ver, name )
{
ver = trim( ltrim( ver ))
name = trim( ltrim( name ))
# check for version label or revision number or "*"
if ( ver )
{
if ( isalpha( substr( ver, 1, 1 )))
ver = "-v" "\"" ver "\"" # version label
else if ( substr( ver, 1, 1 ) == "*" )
ver = "-r" substr( ver, 2 ) # trunk tip revision
else if ( ver !~ /^-[rRvV]/ )
ver = "-r" ver # revision number
ver = ver " "
}
# replace {current buffer} string with the name of a new temp file
if ( name == PVCS_CUR_BUF )
{
if ( ver )
name = buffer_filename
else
{
name = pvcs_create_temp_file()
write_buffer( name )
}
}
return ver name
}
###
# pvcs_create_temp_file() and
# pvcs_cleanup_temp_files()
#
local pvcs_temp_files[]
## create a temp file and add the name to the list
#
global function pvcs_create_temp_file()
{
local fn = create_temp_name()
pvcs_temp_files[ fn ] = 0
return fn
}
## remove any accumulated temporary files
#
global function pvcs_cleanup_temp_files()
{
local fn
if ( pvcs_temp_files )
{
for ( fn in pvcs_temp_files )
{
unlink( fn )
}
delete( pvcs_temp_files )
}
}
## display the output from a system command in the current window
#
global function pvcs_system_output( bufName, outputFile, removeIt )
{
if ( filesize( outputFile ))
{
# read the file into an empty buffer
create_buf_and_win( outputFile )
buffer_name = bufName
copy_buffer_internally()
# if removeIt argument is TRUE, wait for any key then
# delete the buffer.
if ( removeIt )
{
goto_buffer_bottom()
message( "Hit any key to continue." )
display_update()
while ( !keyboard_input_pending )
{
}
getkey()
delete_buffer()
}
}
message( "" )
}
###
### put up a menu of PVCS system commands
###
global function pvcs_menu(on)
{
local priorPvcsEnabled
local mainmenu
# get the main menu
mainmenu = menu_info(0, MI_MENUHANDLE)
if ( mainmenu )
{
if ( on )
{
modify_menuitem( mainmenu, IDM_GET, MI_ENABLED )
modify_menuitem( mainmenu, IDM_PUT, MI_ENABLED )
modify_menuitem( mainmenu, IDM_VDIFF, MI_ENABLED )
}
else
{
modify_menuitem( mainmenu, IDM_GET, MI_DISABLED )
modify_menuitem( mainmenu, IDM_PUT, MI_DISABLED )
modify_menuitem( mainmenu, IDM_VDIFF, MI_DISABLED )
}
}
}
######## VCS SETTINGS PAGE #####################################################
global function create_vcs_page(pageid, dlgid)
{
local handle;
handle = create_page(function_id( "vcs_settings_callback" ),
dlgid, IDD_VCS_SETTINGS, resource_dll)
attach_help(editor_helpfile, handle);
if(isWindows())
nbPagePrefix[pageid].help = "VCS Settings";
else
nbPagePrefix[pageid].help = "vcspage";
add_dialog_item( handle, IDB_UNDO, DCTRL_PUSH_BUTTON);
initialize_vcs_settings(handle);
set_notebook_page_dialog(dlgid, pageid, handle);
nbPagePrefix[pageid].dialog_handle = handle;
}
local function initialize_vcs_settings(handle)
{
nb_initializing = TRUE
set_dialog_item( handle, IDE_GET_COMMAND, DAC_EDIT_TEXT, get_command "")
set_dialog_item( handle, IDE_PUT_COMMAND, DAC_EDIT_TEXT, put_command "")
if(and(pvcsEnabled, PVCS_ENABLE_MENU))
{
set_dialog_item( handle, IDE_GET_COMMAND, DAC_ENABLE)
set_dialog_item( handle, IDE_PUT_COMMAND, DAC_ENABLE)
set_dialog_item( handle, IDC_VCS_ENABLE, DAC_CHECK)
if(and(pvcsEnabled, PVCS_ENABLE_GETS))
set_dialog_item( handle, IDC_VCS_ON_MOD, DAC_CHECK)
else
set_dialog_item( handle, IDC_VCS_ON_MOD, DAC_UNCHECK)
if(and(pvcsEnabled, PVCS_ENABLE_EMPTY_GETS))
set_dialog_item( handle, IDC_VCS_ON_NON, DAC_CHECK)
else
set_dialog_item( handle, IDC_VCS_ON_NON, DAC_UNCHECK)
}
else
{
set_dialog_item( handle, IDE_GET_COMMAND, DAC_DISABLE)
set_dialog_item( handle, IDE_PUT_COMMAND, DAC_DISABLE)
set_dialog_item( handle, IDC_VCS_ON_MOD, DAC_DISABLE)
set_dialog_item( handle, IDC_VCS_ON_NON, DAC_DISABLE)
set_dialog_item( handle, IDC_VCS_ENABLE, DAC_UNCHECK)
set_dialog_item( handle, IDC_VCS_ON_MOD, DAC_UNCHECK)
set_dialog_item( handle, IDC_VCS_ON_NON, DAC_UNCHECK)
}
nb_initializing = FALSE;
}
global function vcs_settings_callback()
{
local new_val, return_msg = DRC_CONTINUE;
if(callback_msg == DM_HELPREQUESTED)
{
display_help(nbPagePrefix[current_nb_page].help, callback_dialog_handle);
return_msg = DRC_MSG_PROCESSED;
}
else if( callback_msg == DM_CANCEL )
{
# dialog_return_value = ""
nbPagePrefix[current_nb_page].modified = FALSE;
return_msg = DRC_MSG_PROCESSED
}
else if( (callback_msg == DM_CLICK) || (callback_msg == DM_DOUBLE_CLICK) )
{
if ( callback_index == IDB_UNDO )
{
nbPagePrefix[current_nb_page].modified = FALSE;
initialize_vcs_settings(callback_dialog_handle)
}
else
{
enable_undo(callback_dialog_handle, callback_index);
nbPagePrefix[current_nb_page].modified = TRUE;
if(callback_index == IDB_DEFAULT)
{
default_vcs_settings(callback_dialog_handle);
}
else if(callback_index == IDC_VCS_ENABLE)
{
if(query_dialog_item(callback_dialog_handle, callback_index, DAC_CHECK))
{
set_dialog_item(callback_dialog_handle, IDE_GET_COMMAND, DAC_ENABLE);
set_dialog_item(callback_dialog_handle, IDE_PUT_COMMAND, DAC_ENABLE);
set_dialog_item(callback_dialog_handle, IDC_VCS_ON_MOD, DAC_ENABLE);
set_dialog_item(callback_dialog_handle, IDC_VCS_ON_NON, DAC_ENABLE);
}
else
{
set_dialog_item(callback_dialog_handle, IDE_GET_COMMAND, DAC_DISABLE);
set_dialog_item(callback_dialog_handle, IDE_PUT_COMMAND, DAC_DISABLE);
set_dialog_item(callback_dialog_handle, IDC_VCS_ON_MOD, DAC_UNCHECK);
set_dialog_item(callback_dialog_handle, IDC_VCS_ON_NON, DAC_UNCHECK);
set_dialog_item(callback_dialog_handle, IDC_VCS_ON_MOD, DAC_DISABLE);
set_dialog_item(callback_dialog_handle, IDC_VCS_ON_NON, DAC_DISABLE);
}
}
}
return_msg = DRC_MSG_PROCESSED;
}
else if ( callback_msg == DM_KILL_FOCUS )
{
if ( nb_initializing )
return_msg = DRC_CONTINUE;
else
{
nbPagePrefix[current_nb_page].modified = TRUE;
return_msg = DRC_MSG_PROCESSED;
}
}
else if(callback_msg == DM_CHANGE)
enable_undo(callback_dialog_handle, callback_index);
return return_msg;
}
global function assign_vcs_changes(handle)
{
local on = 0;
get_command = query_dialog_item(handle, IDE_GET_COMMAND, DAC_EDIT_TEXT);
put_command = query_dialog_item(handle, IDE_PUT_COMMAND, DAC_EDIT_TEXT);
if(query_dialog_item(handle, IDC_VCS_ENABLE, DAC_CHECK))
{
on += PVCS_ENABLE_MENU;
if(query_dialog_item(handle, IDC_VCS_ON_MOD, DAC_CHECK))
on += PVCS_ENABLE_GETS;
if(query_dialog_item(handle, IDC_VCS_ON_NON, DAC_CHECK))
on += PVCS_ENABLE_EMPTY_GETS;
}
toggle_pvcs(on);
}
local function default_vcs_settings( handle )
{
nb_initializing = TRUE
set_dialog_item( handle, IDE_GET_COMMAND, DAC_EDIT_TEXT, default_get_command "");
set_dialog_item( handle, IDE_PUT_COMMAND, DAC_EDIT_TEXT, default_put_command "");
set_dialog_item( handle, IDE_GET_COMMAND, DAC_DISABLE);
set_dialog_item( handle, IDE_PUT_COMMAND, DAC_DISABLE);
set_dialog_item( handle, IDC_VCS_ENABLE, DAC_UNCHECK);
nb_initializing = FALSE;
}
function pvcs_settings( settings_index, settings_data[] )
{
local new_array;
settings_data[ settings_index++ ] = sprintf( "SET_VCS %d,%s,%s\n",
pvcsEnabled,
quote_string(get_command),
quote_string(put_command) )
new_array.array = settings_data
new_array.index = settings_index
return new_array
}