home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Professional
/
OS2PRO194.ISO
/
os2
/
prgramer
/
vcomp
/
vc.cb
< prev
next >
Wrap
Text File
|
1992-03-05
|
7KB
|
185 lines
/*
* Function: Run Visual Compare and locate the next and previous deletion or
* insertion.
* To run: While editing the second of two files you wish to compare
* (filetwo), execute the macro VC with a fileone parameter (where
* fileone is the first of two files you wish to compare). If
* you omit fileone, VC will prompt you for it. VC will save
* fileone and filetwo if necessary, run Visual Compare (using the
* /C command line option and with the composite file redirected to
* the file VC.TMP), load VC.TMP, and locate the first deletion or
* insertion. To locate the next deletion or insertion, press the
* <Alt-v><Alt-n> key sequence. To locate the previous deletion or
* insertion, press the <Alt-v><Alt-p> key sequence. If the file
* VC.TMP already exists, execute VC with "!next" for the fileone
* parameter to load VC.TMP and locate the first deletion or
* insertion.
* Requires: BRIEF 3.0
*/
void vc( void )
{
string vc_next_key = "<Alt-v><Alt-n>";
string vc_prev_key = "<Alt-v><Alt-p>";
string vc_one_start = "START \\$\\$\\$\\$\\$";
string vc_two_start = "START \\$\\$\\$\\$\\$";
string fileone;
string filetwo;
int buffer_cur;
int buffer_tmp;
string buffer_tmp_name;
int ret_code;
string command_string;
int window_cur;
int window_tmp;
if ( !get_parm( 0, fileone, "Enter fileone: " ))
return;
fileone = lower( fileone );
if ( fileone != "!next" && fileone != "!prev" )
{
/* Look for a vc.tmp buffer. */
buffer_cur = inq_buffer();
do
{
buffer_tmp = next_buffer();
set_buffer( buffer_tmp );
inq_names( NULL, NULL, buffer_tmp_name );
}
while ( buffer_tmp != buffer_cur && buffer_tmp_name != "vc.tmp" );
if ( buffer_tmp_name == "vc.tmp" )
{
/*
* Make the current buffer the same as the buffer attached to the
* current window.
*/
set_buffer( buffer_cur );
ret_code = inq_views( buffer_tmp );
if ( !ret_code )
delete_buffer( buffer_tmp );
else
{
/* Can't delete a viewed buffer. */
message( "Unable to delete vc.tmp buffer" );
return;
}
}
/* Look for a fileone buffer. */
do
{
buffer_tmp = next_buffer();
set_buffer( buffer_tmp );
inq_names( NULL, NULL, buffer_tmp_name );
}
while ( buffer_tmp != buffer_cur && buffer_tmp_name != fileone );
if ( buffer_tmp_name == fileone )
{
/* If the fileone buffer has been modified, write it to disk. */
if ( inq_modified() && write_buffer() <= 0 )
return;
/* Get the full file name associated with the fileone buffer. */
inq_names( fileone );
/*
* Make the current buffer the same as the buffer attached to the
* current window.
*/
set_buffer( buffer_cur );
}
/* If the current buffer has been modified, write it to disk. */
if ( inq_modified() && write_buffer() <= 0 )
return;
/* Get the full file name associated with the current buffer. */
inq_names( filetwo );
/*
* Write the composite file to VC.TMP. If you are running OS/2,
* change vcomp to vcompp.
*/
sprintf( command_string, "vcomp %s %s /C > VC.TMP", fileone, filetwo );
if ( dos( command_string, 0 ))
return;
ret_code = edit_file( "VC.TMP" );
if ( ret_code <= 0 )
return;
if ( ret_code == 1 )
{
message( "New VC.TMP file not loaded" );
return;
}
}
else
{
/* Look for a window with a vc.tmp buffer attached to it. */
window_cur = inq_window();
buffer_cur = inq_buffer();
window_tmp = window_cur;
inq_names( NULL, NULL, buffer_tmp_name );
if ( buffer_tmp_name != "vc.tmp" )
{
do
{
window_tmp = next_window( window_tmp );
inq_window_info( window_tmp, buffer_tmp );
set_buffer( buffer_tmp );
inq_names( NULL, NULL, buffer_tmp_name );
}
while ( window_tmp != window_cur && buffer_tmp_name != "vc.tmp" );
}
if ( buffer_tmp_name == "vc.tmp" )
{
/*
* Make the current buffer the same as the buffer attached to the
* current window.
*/
set_buffer( buffer_cur );
/* Jump to the window with a vc.tmp buffer attached to it. */
set_window( window_tmp );
ret_code = 1; /* The buffer already existed. */
}
else
{
/*
* Attach an existing vc.tmp buffer to the current window or
* create a new vc.tmp buffer.
*/
ret_code = edit_file( "VC.TMP" );
if ( ret_code <= 0 )
return;
}
}
sprintf( command_string, "{%s}|{%s}", vc_one_start, vc_two_start );
if ( ret_code == 1 )
{
/* The buffer already existed. */
save_position();
ret_code = 0; /* Assume search failed. */
/*
* Move the current position before calling the appropriate search
* routine so as to not find the same deletion or insertion a second
* time.
*/
if ( fileone == "!next" && next_char())
/* Locate the next deletion or insertion. */
ret_code = search_fwd( command_string );
else if ( fileone == "!prev" && prev_char())
/* Locate the previous deletion or insertion. */
ret_code = search_back( command_string );
/* If search failed, restore the previous position. */
restore_position( !ret_code );
}
else
{
/*
* The buffer was newly created. Define keys to find the next and
* previous deletion or insertion.
*/
assign_to_key( vc_next_key, "vc !next" );
assign_to_key( vc_prev_key, "vc !prev" );
/* Locate the next deletion or insertion. */
ret_code = search_fwd( command_string );
}
if ( ret_code > 0 )
message( "" );
else if ( !ret_code )
message( "No more deletions or insertions" );
}