home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
p2demo21.exe
/
PEL
/
VDIFF.PEL
< prev
next >
Wrap
Text File
|
1995-04-11
|
31KB
|
1,101 lines
# $Header: P:\source\wmacros\vdiff.pev 1.56 11 Apr 1995 11:43:18 WALKER $
##############################################################################
#
# 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: vdiff.pel $: vdiff comparison support
## $Tabs:5 9$
#--------------------------------------------------------------------------
#
# PVCS vdiff dialog box and processing
#
#--------------------------------------------------------------------------
global dhVdiff = 0
local pvcs_vdiff_arr[]
local pvcs_dlg_arr[]
local vdiff_changes[]
local vdiff_prev_status[]
local vdiff_wins[]
local vdiff_bufs[]
local PVCS_VDIFF = 1573
local ID_REFVERSION = 1574
local ID_REFFILE = 1575
local ID_TARGETVERSION = 1576
local ID_TARGETFILE = 1577
local ID_COMPARISON = 1578
local ID_VDIFF = 1579
local ID_VERTICAL = 1580
local ID_HORIZONTAL = 1581
local ID_IGNORE_WHITE = 1582
local IDG_ORIENTATION = 1583
local IDM_FIRST_ITEM = 3709
local IDM_NEXT = 3709
local IDM_PREV = 3710
local IDM_EXIT_VDIFF = 3711
local IDM_MVDIFF = 3712
local IDM_LAST_ITEM = 3712
local kmp = 0
local cw = current_window
local vdiff_ok = TRUE
local in_vdiff = FALSE
local vdiff_ignore_white = TRUE
local old_menu = 0
local old_window = 0
local old_wflags = 0
local old_current_buffer = 0
global default_vdiff_command = "vdiff "
global vdiff_command = default_vdiff_command
local vdiff_win_num
global function pvcs_vdiff()
{
local cmd = ""
local outputFile = ""
local errorFile = ""
local options = ""
local ret_code = 0
local inputError = 0
local i = 0
local winName[]
local name[]
# this is the first time through
if (dhVdiff)
delete_dialog(dhVdiff)
dhVdiff = create_dialog( function_id( "vdiff_callback" ), 0, PVCS_VDIFF, resource_dll );
set_dialog_item(dhVdiff, ID_TARGETFILE, DAC_SET_TEXT_LEN, 256)
set_dialog_item(dhVdiff, ID_REFFILE, DAC_SET_TEXT_LEN, 256)
optional_function( "load_user_vdiff_ref_syntax" )
optional_function( "load_user_vdiff_target_syntax" )
if ( !pvcs_vdiff_arr )
{
pvcs_vdiff_arr[ 5 ] = "1"
pvcs_vdiff_arr[ 6 ] = "0"
pvcs_vdiff_arr[ 7 ] = "1"
pvcs_vdiff_arr[ 8 ] = "0"
}
# always specified :
pvcs_vdiff_arr[ 1 ] = "*" # reference ver
pvcs_vdiff_arr[ 2 ] = buffer_filename # reference name
pvcs_vdiff_arr[ 3 ] = "" # target ver
pvcs_vdiff_arr[ 4 ] = PVCS_CUR_BUF # target name
begin_dialog( dhVdiff )
delete_dialog(dhVdiff)
dhVdiff = 0
if ( vdiff_ok )
{
# assemble disk filenames or logfile revisions
name[0] = pvcs_make_name( pvcs_vdiff_arr[1], pvcs_vdiff_arr[2] )
name[1] = pvcs_make_name( pvcs_vdiff_arr[3], pvcs_vdiff_arr[4] )
# check for existence of files
#
for ( i = 0; i <= 1; i++ )
{
if ( !name[i] )
{
notify( "vdiff:Insufficient parameters passed to vdiff." )
inputError++
break
}
else if ( substr( name[i], 1, 1 ) == "-" )
winName[i] = name[i] # logfile
else
{ # disk file
ret_code = filemode( name[i] )
if ( (!and( ret_code,_READ_ONLY+_HIDDEN+_SYSTEM+_ARCHIVE) || ( ret_code < 0 )) &&
(ret_code != 0) )
{
warning( "vdiff: Can't open file \"%s\".", name[i] )
inputError++
}
# check for name of temp file representing current buffer
winName[i] = ( pvcs_vdiff_arr[ i ? 4 : 2 ] == PVCS_CUR_BUF ) \
? buffer_name " " PVCS_CUR_BUF \
: name[i]
}
}
if ( name[0] == name[1] )
{
notify( "vdiff:\"%s\" specified twice.", name[0] )
inputError++
}
if ( inputError )
{
pvcs_cleanup_temp_files()
return
}
if ( pvcs_vdiff_arr[ 5 ] == "1" )
options = "-e0 -l32000 -n" # retain tabs, infinite context, omit #s
else
options = "-e0" # retain tabs
# add ignore whitespace option if set
if ( vdiff_ignore_white )
options = options " -B"
outputFile = pvcs_create_temp_file()
errorFile = pvcs_create_temp_file()
message( "Issuing PVCS VDIFF command..." )
cmd = vdiff_command " -XO" outputFile " -XE" errorFile " " options " " name[0] " " name[1]
ret_code = system( cmd, 0, 0, 0, SYS_NOEXPOSE )
if ( filesize(errorFile) )
pvcs_system_output( "VDIFF output", errorFile )
if ( !filesize(outputFile) )
ret_code = 1
# vdiff option
if ( ret_code == 0 && pvcs_vdiff_arr[ 5 ] == "1" )
{
in_vdiff = TRUE
# display vdiff output
vdiff( outputFile, winName[0], winName[1], (pvcs_vdiff_arr[7] == "1") ? "vert" : "horz" )
}
else
{
# comparison option or error
pvcs_system_output( "VDIFF output", outputFile, ret_code )
pvcs_cleanup_temp_files()
delete( pvcs_dlg_arr )
}
}
}
global function vdiff_callback()
{
local temp_val = ""
if ( callback_msg == DM_INIT )
{
# preselect radioboxes
set_dialog_item(dhVdiff, ID_COMPARISON, pvcs_vdiff_arr[ 5 ] == "1" ? DAC_CHECK : DAC_UNCHECK )
set_dialog_item(dhVdiff, ID_VDIFF, pvcs_vdiff_arr[ 6 ] == "1" ? DAC_CHECK : DAC_UNCHECK )
set_dialog_item(dhVdiff, ID_VERTICAL, pvcs_vdiff_arr[ 7 ] == "1" ? DAC_CHECK : DAC_UNCHECK )
set_dialog_item(dhVdiff, ID_HORIZONTAL, pvcs_vdiff_arr[ 8 ] == "1" ? DAC_CHECK : DAC_UNCHECK )
set_dialog_item(dhVdiff, ID_IGNORE_WHITE, DAC_CHECK)
set_dialog_item(dhVdiff, ID_REFVERSION, DAC_EDIT_TEXT, "*" )
set_dialog_item(dhVdiff, ID_REFFILE, DAC_EDIT_TEXT, buffer_filename )
set_dialog_item(dhVdiff, ID_TARGETFILE, DAC_EDIT_TEXT, PVCS_CUR_BUF )
set_dialog_item(dhVdiff, ID_TARGETVERSION, DAC_EDIT_TEXT, " " )
set_dialog_item(dhVdiff, ID_REFVERSION, DAC_SETFOCUS)
attach_help(editor_helpfile, dhVdiff)
vdiff_ok = TRUE
}
else if ((callback_msg == DM_CLOSE) ||
(callback_msg == DM_CANCEL) ||
( (callback_msg == DM_CLICK) && (callback_index == DI_CANCEL) ) )
{
vdiff_ok = FALSE
return DRC_EXIT
}
else if ( ( callback_msg == DM_CLICK && callback_index == DI_HELP ) ||
( callback_msg == DM_HELPREQUESTED ) )
{
if(isWindows())
display_help("VCS", dhVdiff);
else
display_help("tmpvcs", dhVdiff);
return DRC_MSG_PROCESSED
}
else if ( callback_msg == DM_CLICK )
{
if ( callback_index == ID_IGNORE_WHITE )
{
vdiff_ignore_white = query_dialog_item(dhVdiff, ID_IGNORE_WHITE, DAC_CHECK)
}
else if ( callback_index == ID_COMPARISON )
{
set_dialog_item(dhVdiff, ID_COMPARISON, DAC_CHECK)
pvcs_vdiff_arr[ 5 ] = "1"
set_dialog_item(dhVdiff, ID_VDIFF, DAC_UNCHECK)
pvcs_vdiff_arr[ 6 ] = "0"
set_dialog_item(dhVdiff, ID_VERTICAL, DAC_ENABLE)
set_dialog_item(dhVdiff, ID_HORIZONTAL, DAC_ENABLE)
set_dialog_item(dhVdiff, IDG_ORIENTATION, DAC_ENABLE)
}
else if ( callback_index == ID_VDIFF )
{
set_dialog_item(dhVdiff, ID_VDIFF, DAC_CHECK)
pvcs_vdiff_arr[ 6 ] = "1"
set_dialog_item(dhVdiff, ID_COMPARISON, DAC_UNCHECK)
pvcs_vdiff_arr[ 5 ] = "0"
set_dialog_item(dhVdiff, ID_VERTICAL, DAC_DISABLE)
set_dialog_item(dhVdiff, ID_HORIZONTAL, DAC_DISABLE)
set_dialog_item(dhVdiff, IDG_ORIENTATION, DAC_DISABLE)
}
else if ( callback_index == ID_VERTICAL )
{
set_dialog_item(dhVdiff, ID_VERTICAL, DAC_CHECK)
pvcs_vdiff_arr[ 7 ] = "1"
set_dialog_item(dhVdiff, ID_HORIZONTAL, DAC_UNCHECK)
pvcs_vdiff_arr[ 8 ] = "0"
}
else if ( callback_index == ID_HORIZONTAL )
{
set_dialog_item(dhVdiff, ID_HORIZONTAL, DAC_CHECK)
pvcs_vdiff_arr[ 8 ] = "1"
set_dialog_item(dhVdiff, ID_VERTICAL, DAC_UNCHECK)
pvcs_vdiff_arr[ 7 ] = "0"
}
return DRC_MSG_PROCESSED
}
else if ( callback_msg == DM_KILL_FOCUS )
{
temp_val = query_dialog_item(callback_dialog_handle, callback_index, DAC_TEXT)
if ( !temp_val )
temp_val = ""
if ( callback_index == ID_REFVERSION )
{
pvcs_vdiff_arr[ 1 ] = temp_val
}
else if ( callback_index == ID_REFFILE )
{
pvcs_vdiff_arr[ 2 ] = temp_val
}
else if ( callback_index == ID_TARGETVERSION )
{
pvcs_vdiff_arr[ 3 ] = temp_val
}
else if ( callback_index == ID_TARGETFILE )
{
pvcs_vdiff_arr[ 4 ] = temp_val
}
}
return DRC_CONTINUE
}
## vdiff()
#
# Compare two files and display the files with changes side by side.
#
# Arguments:
#
# vdiffOutput : name of file containing vdiff output
# refWinName : name appearing in title bar of reference window
# tgtWinName : name appearing in title bar of target window
# shape : "horz" - display files one on top of the other
# : "vert" - display files side by side (default)
#
# The reference and target buffers are constructed entirely from the vdiff
# output file. The function vdiff_build_buffer() performs this action.
# Blank lines are inserted whereever necessary in order to maintain the
# line number equivalence between unchanged lines in the two buffers.
# In addition to the buffers, an array 'vdiff_changes[]' is produced,
# containing a list of all changed lines, and a code indicating the nature
# of the change (insert, delete, move from, move to). The code determines
# which color to use when the line is displayed.
#
#
local remote_win
local function vdiff( vdiffOutput, refWinName, tgtWinName, shape )
{
local delta
local titleb1, titleb2
local called_again
local errors
cw = current_window
old_wflags = window_flags
old_window = current_window
called_again = (argcount() != 4)
old_current_buffer = current_buffer
if ( !called_again )
{
delete( vdiff_changes )
vdiff_prev_status[ "refname" ] = refWinName
vdiff_prev_status[ "tgtname" ] = tgtWinName
vdiff_prev_status[ "shape" ] = shape
message( "Constructing differences..." )
}
else
{
if ( !vdiff_prev_status || !vdiff_changes )
{
notify( "VDIFF must be run first with the `comparison' option." )
return 0
}
refWinName = vdiff_prev_status[ "refname" ]
tgtWinName = vdiff_prev_status[ "tgtname" ]
shape = vdiff_prev_status[ "shape" ]
}
# create windows for reference and target files
#
remote_win = create_remote_window( "PVCS Vdiff" )
mdi_mode = 1
status_bar_flags = STB_MESSAGES + STB_LINE_COLUMN
vdiff_menu()
old_menu = change_menu(menu, remote_win)
vdiff_wins[0] = create_factory_window( 0, 0, 0, 0, 0x10113 + 0x8, remote_win )
vdiff_wins[1] = create_factory_window( 0, 0, 0, 0, 0x10113 + 0x8, remote_win )
# create buffers for reference and target files
#
if ( !called_again )
{
if ( vdiff_bufs )
{
delete_buffer( vdiff_bufs[0] )
delete_buffer( vdiff_bufs[1] )
}
vdiff_bufs[0] = create_buffer( "VDIFF Reference", "", BUFFER_SYSTEM + BUFFER_NO_UNDO )
vdiff_bufs[1] = create_buffer( "VDIFF Target", "", BUFFER_SYSTEM + BUFFER_NO_UNDO )
}
attach_window_buffer( vdiff_wins[0], vdiff_bufs[0] )
attach_window_buffer( vdiff_wins[1], vdiff_bufs[1] )
# assemble reference and target buffers
#
if ( !called_again )
{
current_window = vdiff_wins[0]
errors = vdiff_build_buffer( vdiffOutput, 0 ) # reference
if ( !errors )
{
current_window = vdiff_wins[1]
errors = vdiff_build_buffer( vdiffOutput, 1 ) # target
}
}
if ( errors )
{
delete( vdiff_changes )
delete( vdiff_prev_status )
if ( errors == 1 )
{
# display error messages in current window
assign_current_window( cw )
# pvcs_system_output( "VDIFF output", vdiffOutput, 1 )
}
else
warning( "Unable to process vdiff output / wrong vdiff version" )
}
else
{
set_cursor( 0 ) # set block cursor
current_window = vdiff_wins[1]
current_buffer = vdiff_bufs[1]
goto_buffer_top()
update_current_view()
buffer_name = tgtWinName
if ( filemode(pvcs_vdiff_arr["4"]) != -1 )
{
if ( !pvcs_vdiff_arr["3"] )
buffer_filename = pvcs_vdiff_arr["4"]
}
current_window = vdiff_wins[0]
current_buffer = vdiff_bufs[0]
goto_buffer_top()
update_current_view()
buffer_name = refWinName
if ( filemode(pvcs_vdiff_arr["2"]) != -1 )
{
if ( !pvcs_vdiff_arr["1"] )
buffer_filename = pvcs_vdiff_arr["2"]
}
vdiff_win_num = 0 # current vdiff window
if ( shape == "horz" ) # tiled, one above the other
{
delta = display_height / 2
frame_window( 0, 0, display_width, delta, vdiff_wins[0] )
frame_window( 0, delta, display_width, ((display_height+1)/2)-1, vdiff_wins[1] )
current_window = vdiff_wins[0]
}
else # tiled, side by side
{
delta = display_width / 2
frame_window( 0, 0, delta, display_height - 1, vdiff_wins[0] )
frame_window( delta, 0, delta, display_height - 1, vdiff_wins[1] )
current_window = vdiff_wins[0]
}
restore_window(vdiff_wins[1])
restore_window(vdiff_wins[0])
vdiff_pageup()
message( " n=Next change p=Prev change <Esc> to exit" )
attach_event_handler( EVENT.NEW_CURNT_EDITWIN, function_id("editwin_changed") )
setup_vdiff()
return
}
delete_window( vdiff_wins[0] )
delete_window( vdiff_wins[1] )
delete_remote_window( remote_win )
current_buffer = old_current_buffer
}
local function setup_vdiff()
{
# create a keymap for use in the vdiff windows
#
kmp = create_keymap( empty_keymap )
push_keymap( kmp )
delete_event(EVENT.LMOUSE_DRAG, function_id("lmouse_drag" ) )
delete_event(EVENT.MOUSE_LEFT_DOWN, function_id("mouse_left_down") )
delete_event(EVENT.MOUSE_LEFT_UP, function_id("mouse_left_up" ) )
delete_event(EVENT.RESIZE_EDITWIN, function_id("resize_editwin" ) )
attach_event_handler( EVENT.MOUSE_LEFT_DOWN, function_id("beep") )
attach_event_handler( EVENT.MOUSE_RIGHT_DOWN, function_id("beep") )
attach_event_handler( EVENT.RESIZE_EDITWIN, function_id("vdiff_resize") )
assign_key( "<Up>", "vdiff_up" )
assign_key( "<Down>", "vdiff_down" )
assign_key( "<Left>", "vdiff_left" )
assign_key( "<Right>", "vdiff_right" )
assign_key( "<Home>", "vdiff_home" )
assign_key( "<End>", "vdiff_end" )
assign_key( "<PageUp>", "vdiff_pageup" )
assign_key( "<PageDown>", "vdiff_pagedn" )
assign_key( "<Ctrl-PageUp>", "vdiff_top" )
assign_key( "<Ctrl-PageDown>", "vdiff_bottom" )
assign_key( "n", "vdiff_next" )
assign_key( "N", "vdiff_next" )
assign_key( "p", "vdiff_prev" )
assign_key( "P", "vdiff_prev" )
assign_key( "<Esc>", "exit_vdiff" )
attach_event_handler( EVENT.CLOSING_REMOTE_WINDOW, function_id("close_vdiff") )
}
global function editwin_changed()
{
if ( current_editor == remote_win )
{
if ( in_vdiff == FALSE )
{
setup_vdiff()
in_vdiff = TRUE
}
}
else
{
if ( in_vdiff == TRUE )
{
cleanup_vdiff()
in_vdiff = FALSE
}
}
}
local function cleanup_vdiff()
{
attach_event_handler(EVENT.LMOUSE_DRAG, function_id("lmouse_drag" ) )
attach_event_handler(EVENT.MOUSE_LEFT_DOWN, function_id("mouse_left_down" ) )
attach_event_handler(EVENT.MOUSE_LEFT_UP, function_id("mouse_left_up" ) )
attach_event_handler(EVENT.RESIZE_EDITWIN, function_id("resize_editwin" ) )
delete_event( EVENT.MOUSE_LEFT_DOWN, function_id("beep") )
delete_event( EVENT.MOUSE_RIGHT_DOWN, function_id("beep") )
delete_event( EVENT.RESIZE_EDITWIN, function_id("vdiff_resize") )
pop_keymap()
delete_keymap( kmp )
message( "" )
set_cursor( 1 ) # restore cursor
}
# this function is called when the user double clicks on
# the system icon. We don't need to delete any windows or
# the remote editor window because that will be done for
# us in this case.
global function close_vdiff()
{
local i
delete_event( EVENT.NEW_CURNT_EDITWIN, function_id("editwin_changed") )
delete_event( EVENT.CLOSING_REMOTE_WINDOW, function_id("close_vdiff") )
cleanup_vdiff()
# delete our local list that maps function id's to menu item
# id's. This list was created during the append_menuitem calls.
for ( i = IDM_FIRST_ITEM; i <= IDM_LAST_ITEM; i++ )
if ( i in menu_functions )
delete menu_functions[i]
pvcs_cleanup_temp_files()
delete( pvcs_dlg_arr )
in_vdiff = FALSE
}
global function exit_vdiff( no_delete )
{
local i
local old_create_new_bufwin = create_new_bufwin
if ( in_vdiff )
{
delete_event( EVENT.NEW_CURNT_EDITWIN, function_id("editwin_changed") )
delete_event( EVENT.CLOSING_REMOTE_WINDOW, function_id("close_vdiff") )
cleanup_vdiff()
create_new_bufwin = 0
delete_window( vdiff_wins[0] )
delete_window( vdiff_wins[1] )
delete_menu( submenu, remote_win )
delete_menu( menu, remote_win )
delete_remote_window( remote_win )
create_new_bufwin = old_create_new_bufwin
# delete our local list that maps function id's to menu item
# id's. This list was created during the append_menuitem calls.
for ( i = IDM_FIRST_ITEM; i <= IDM_LAST_ITEM; i++ )
if ( i in menu_functions )
delete menu_functions[i]
pvcs_cleanup_temp_files()
delete( pvcs_dlg_arr )
in_vdiff = FALSE
current_window = cw
display_redraw()
}
}
global function prev_vdiff()
{
in_vdiff = TRUE
# display vdiff output
vdiff()
}
# The following routines perform the actions for each key
# assigned.
#
# vdiff_left_press() - scroll while mouse left down
# vdiff_left_release() - handle mouse left release
# vdiff_home() - goto beginning of line
# vdiff_end() - goto end of line
# vdiff_top() - goto top of buffer
# vdiff_bottom() - goto end of buffer
# vdiff_pageup() - scroll one page up
# vdiff_pagedn() - scroll one page down
# vdiff_right() - scroll one character right
# vdiff_left() - scroll one character left
# vdiff_next() - goto next difference
# vdiff_prev() - goto previous difference
# vdiff_goto() - goto specific line
#
global function vdiff_resize()
{
local width, height
if ( pvcs_vdiff_arr[7] == "1" )
{
frame_window( 0, 0, display_width / 2, display_height, vdiff_wins[0] )
frame_window( display_width / 2, 0, display_width / 2, display_height, vdiff_wins[1] )
}
else
{
frame_window( 0, 0, display_width, display_height / 2, vdiff_wins[0] )
frame_window( 0, display_height / 2, display_width, display_height / 2, vdiff_wins[1] )
}
}
function vdiff_up()
{
flush_keyboard()
execute_on_window( "scroll_vertical -1", vdiff_wins[0] )
execute_on_window( "scroll_vertical -1", vdiff_wins[1] )
# current_window = vdiff_wins[ 0 ]
# scroll_vertical( -1 )
# update_current_view()
#
# current_window = vdiff_wins[ 1 ]
# scroll_vertical( -1 )
# update_current_view()
}
function vdiff_down()
{
flush_keyboard()
execute_on_window( "scroll_vertical 1", vdiff_wins[0] )
execute_on_window( "scroll_vertical 1", vdiff_wins[1] )
}
function vdiff_left()
{
flush_keyboard()
execute_on_window( "scroll_horizontal -1", vdiff_wins[0] )
execute_on_window( "scroll_horizontal -1", vdiff_wins[1] )
}
function vdiff_right()
{
flush_keyboard()
execute_on_window( "scroll_horizontal 1", vdiff_wins[0] )
execute_on_window( "scroll_horizontal 1", vdiff_wins[1] )
}
function vdiff_home()
{
flush_keyboard()
execute_on_window( "goto_bol", vdiff_wins[0] )
execute_on_window( "goto_bol", vdiff_wins[1] )
}
function vdiff_end()
{
flush_keyboard()
execute_on_window( "goto_eol", vdiff_wins[0] )
execute_on_window( "goto_eol", vdiff_wins[1] )
}
function vdiff_pageup()
{
flush_keyboard()
execute_on_window( "page_up 1", vdiff_wins[0] )
execute_on_window( "page_up 1", vdiff_wins[1] )
}
function vdiff_pagedn()
{
flush_keyboard()
execute_on_window( "page_down 1", vdiff_wins[0] )
execute_on_window( "page_down 1", vdiff_wins[1] )
}
function vdiff_top()
{
vdiff_goto( 1 )
}
function vdiff_bottom()
{
vdiff_goto( buffer_last_line - window_text_height )
}
function vdiff_next()
{
local cl = current_line
local action
local line
# find the end of the current block of changes
if ( cl in vdiff_changes ){
action = vdiff_changes[ cl ]
while (( ++cl in vdiff_changes) \
&& ( vdiff_changes[ cl ] == action )){
}
}
# find the start of the next block of changes
for ( line in vdiff_changes ){
if ( line+0 >= cl ){
vdiff_goto( line )
return
}
}
beep()
}
function vdiff_prev()
{
local cl = current_line
local action
local line
local prev
# find the start of the current block of changes
if ( cl in vdiff_changes ){
action = vdiff_changes[ cl ]
while (( --cl in vdiff_changes) \
&& ( vdiff_changes[ cl ] == action )){
}
}
# find the end of the previous block of changes
for ( line in vdiff_changes ){
if ( line+0 >= cl ){
break
}
prev = line
}
# find the start of the block just found
if ( prev ){
line = prev--
action = vdiff_changes[ line ]
while (( prev in vdiff_changes) \
&& ( vdiff_changes[ prev ] == action )){
line = prev--
}
vdiff_goto( line )
return
}
beep()
}
local function vdiff_goto( ln, col )
{
if ( argcount() == 0 )
{
ln = current_line
col = current_column
}
else if ( argcount() == 1 )
col = current_column
execute_on_window( "goto_pos " ln " " col, vdiff_wins[0] )
execute_on_window( "scroll_window_top", vdiff_wins[0] )
execute_on_window( "goto_pos " ln " " col, vdiff_wins[1] )
execute_on_window( "scroll_window_top", vdiff_wins[1] )
}
#---------------------------------------------------------------------
## build a complete target or reference file from vdiff output
#
# arguments:
# vdiffOutput - name of vdiff output file
# win_num - 0 = build target (new) file
# 1 = build reference (old) file
#
# return code:
# 0 if successful ; non-zero otherwise
#
# returned by side effect:
# The output is written into the current buffer.
# The array 'vdiff_changes[]' contains a list of the changed lines.
# Both of the above will be incomplete or empty in the event of failure.
#
local function vdiff_build_buffer( vdiffOutput, win_num )
{
local vdiff_prefix[]
local bufname
local action
local blank_lines
local c
vdiff_prefix[ " " ] = 0 # context
vdiff_prefix[ "=" ] = 9 # eof
# read vdiff output into the current buffer
read_file( vdiffOutput )
if ( win_num == 0 ) # reference buffer
{
vdiff_prefix[ "+" ] = 1 # delete
vdiff_prefix[ "-" ] = 2 # retain
vdiff_prefix[ ">" ] = 1 # moved from
vdiff_prefix[ "<" ] = 2 # moved to
if ( Syntax("vdiff_ref") )
{
languages_id = "vdiff_ref"
syntax_highlight = 1
}
}
else # target buffer
{
vdiff_prefix[ "+" ] = 2 # retain
vdiff_prefix[ "-" ] = 1 # delete
vdiff_prefix[ ">" ] = 2 # moved to
vdiff_prefix[ "<" ] = 1 # moved from
if ( Syntax("vdiff_target") )
{
languages_id = "vdiff_target"
syntax_highlight = 1
}
}
# strip off vdiff header lines
goto_buffer_top()
do {
if ( !delete_line() )
return 1 # not a valid vdiff file
}
while ( read_buffer(1) != "=" )
delete_line()
if ( pvcs_vdiff_arr[ 5 ] == "0" )
{
# remove unwanted line number info
goto_pos( buffer_last_line, 18 )
drop_anchor( COLUMN_SELECTION )
goto_pos( 1, 2 )
delete_chars()
current_column = 1
}
# process each line depending on the first character
while ( 1 )
{
# define an action to perform on this line
c = read_buffer(1)
if ( !(c in vdiff_prefix ) )
break
action = vdiff_prefix[ c ]
# process the line
if ( action == 0 ) # context
{
if ( blank_lines )
{
while ( blank_lines-- > 0 )
{
insert_string("^")
insert_newline()
}
blank_lines = 0
}
if ( !search( "^[^ ]", SEARCH_FWD_REGEX_ADV ) )
break
continue # don't increment line count
}
else if ( action == 1 ) # delete
{
delete_line()
blank_lines++
continue # don't increment line count
}
else if ( action == 2 ) # retain
{
vdiff_changes[ current_line ] += 1 + win_num
blank_lines--
}
else if ( action == 9 ) # eof
{
delete_line()
# check for unexpected "=" prefix
if ( current_line != buffer_last_line )
return 2
goto_buffer_top()
toggle_buffer_flags( BUFFER_MODIFIED, 0 )
return 0 # successful
}
if ( !down() )
break
}
return 1 # invalid vdiff prefix or premature end of file
}
# Save the current status of the cursor and reset to invisible
# OR
# restore the previous saved status depending on the value of "on"
#
local cursors[]
local function set_cursor( on ){
if ( on ){
cursor_normal = cursors[1]
cursor_virtual = cursors[2]
cursor_overtype = cursors[3]
cursor_virtual_overtype = cursors[4]
} else {
cursors[1] = cursor_normal
cursors[2] = cursor_virtual
cursors[3] = cursor_overtype
cursors[4] = cursor_virtual_overtype
cursor_normal = \
cursor_virtual = \
cursor_overtype = \
cursor_virtual_overtype = 0xFFFF
}
}
local menu = 0
local submenu = 0
local function vdiff_menu()
{
menu = create_menu()
submenu = create_menu()
append_menuitem( submenu, IDM_PREV, 0x0408, "~Previous Change", "vdiff_prev" )
append_menuitem( submenu, IDM_NEXT, 0x0408, "~Next Change", "vdiff_next" )
append_menuitem( submenu, 0, 0x0100)
append_menuitem( submenu, IDM_EXIT_VDIFF, 0x0408, "~Exit Vdiff", "exit_vdiff" )
append_menuitem( menu, IDM_MVDIFF, 0x0208, "~Vdiff", submenu )
return menu
}
global function load_factory_vdiff_ref_syntax()
{
local type = "vdiff_ref";
add_syntax_category(type, 0, "All", COLOR_WHITE, COLOR_DARK_BLUE);
# set_factory_categories( type );
add_syntax_item(type, LINE, "+", 0x01020000 + VDIFF_MINUS)
add_syntax_item(type, LINE, "^", 0x01020000 + VDIFF_BLANK)
add_syntax_item(type, LINE, ">", 0x01020000 + VDIFF_MINUS)
add_syntax_item(type, LINE, "-", 0x01020000 + VDIFF_PLUS)
add_syntax_item(type, LINE, "<", 0x01020000 + VDIFF_PLUS)
add_syntax_item(type, LINE, "=", 0x01020000 + VDIFF_PLUS)
set_style_delimiters(type, "");
set_escape_character(type, "");
}
global function add_vdiff_target_type()
{
add_type("vdiff_target", "", "text", "4 7", "1 77", "", "\\",
default_buffer_flags, 0, 1, "()[];:,='", 1);
}
global function add_vdiff_ref_type()
{
add_type("vdiff_ref", "", "text", "4 7", "1 77", "", "\\",
default_buffer_flags, 0, 1, "()[];:,='", 1);
}
global function load_factory_vdiff_target_syntax()
{
local type = "vdiff_target";
add_syntax_category(type, 0, "All", COLOR_WHITE, COLOR_BROWN);
add_syntax_item(type, LINE, "+", 0x01020000 + VDIFF_PLUS)
add_syntax_item(type, LINE, "^", 0x01020000 + VDIFF_BLANK)
add_syntax_item(type, LINE, ">", 0x01020000 + VDIFF_PLUS)
add_syntax_item(type, LINE, "-", 0x01020000 + VDIFF_MINUS)
add_syntax_item(type, LINE, "<", 0x01020000 + VDIFF_MINUS)
add_syntax_item(type, LINE, "=", 0x01020000 + VDIFF_MINUS)
set_style_delimiters(type, "");
set_escape_character(type, "");
}