home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Best Objectech Shareware Selections
/
UNTITLED.iso
/
boss
/
word
/
text
/
024
/
diff.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-04
|
24KB
|
733 lines
/*
* Being that the windows in TDE are numbered and lettered, we can easily
* prompt for windows to diff. Might as well do a few standard diff
* options: ignore leading space, ignore all space, ignore blank lines,
* ignore end-of-line, and Ignore/Match case. Once the diff is defined,
* just press one key to find the next diff. Any two visible windows may
* be diffed, which is really nice for comparing similar functions or
* data in seperate areas of a file.
*
*
* New editor name: TDE, the Thomson-Davis Editor.
* Author: Frank Davis
* Date: June 5, 1991, version 1.0
* Date: July 29, 1991, version 1.1
* Date: October 5, 1991, version 1.2
* Date: January 20, 1992, version 1.3
* Date: February 17, 1992, version 1.4
* Date: April 1, 1992, version 1.5
* Date: June 5, 1992, version 2.0
* Date: October 31, 1992, version 2.1
* Date: April 1, 1993, version 2.2
* Date: June 5, 1993, version 3.0
*
* This code is released into the public domain, Frank Davis.
* You may distribute it freely.
*/
#include "tdestr.h"
#include "common.h"
#include "define.h"
#include "tdefunc.h"
/*
* Name: define_diff
* Purpose: get info needed to initialize diff
* Date: October 31, 1992
* Passed: window: pointer to current window
* Notes: allow the user to start the diff at the beginning of the
* file or at the current cursor location. once the diff
* has been defined, the user may press one key to diff again.
* user may diff any two visible windows on the screen.
*/
int define_diff( WINDOW *window )
{
int rc;
char temp[MAX_COLS];
int num1;
int let1;
int num2;
int let2;
int start;
char line_buff[(MAX_COLS+1)*2]; /* buffer for char and attribute */
char buff[MAX_COLS*2]; /* buffer for char and attribute */
/*
* get window number and letter of the first diff window. then,
* verify that window - does it exit? is it visible?
*/
*temp = '\0';
rc = get_name( diff_prompt1, window->bottom_line, temp,
g_display.message_color );
if (rc == OK) {
rc = verify_number( temp, &num1 );
if (rc == OK)
rc = verify_letter( temp, &let1, &diff.w1 );
} else
return( ERROR );
if (rc == ERROR) {
combine_strings( buff, diff_prompt6a, temp, diff_prompt6b );
error( WARNING, window->bottom_line, buff );
return( ERROR );
}
/*
* get and verify the next window number and letter to diff.
*/
*temp = '\0';
rc = get_name( diff_prompt2, window->bottom_line, temp,
g_display.message_color );
if (rc == OK) {
rc = verify_number( temp, &num2 );
if (rc == OK)
rc = verify_letter( temp, &let2, &diff.w2 );
} else
return( ERROR );
if (rc == ERROR) {
combine_strings( buff, diff_prompt6a, temp, diff_prompt6b );
error( WARNING, window->bottom_line, buff );
return( ERROR );
}
/*
* are leading spaces significant?
*/
save_screen_line( 0, window->bottom_line, line_buff );
set_prompt( diff_prompt7a, window->bottom_line );
start = get_yn( );
restore_screen_line( 0, window->bottom_line, line_buff );
if (start != ERROR)
diff.leading = start == A_YES ? TRUE : FALSE;
else
return( ERROR );
/*
* are all spaces significant?
*/
save_screen_line( 0, window->bottom_line, line_buff );
set_prompt( diff_prompt7b, window->bottom_line );
start = get_yn( );
restore_screen_line( 0, window->bottom_line, line_buff );
if (start != ERROR) {
if (start == A_YES)
diff.leading = diff.all_space = TRUE;
else
diff.all_space = FALSE;
} else
return( ERROR );
/*
* are blank lines significant?
*/
save_screen_line( 0, window->bottom_line, line_buff );
set_prompt( diff_prompt7c, window->bottom_line );
start = get_yn( );
restore_screen_line( 0, window->bottom_line, line_buff );
if (start != ERROR)
diff.blank_lines = start == A_YES ? TRUE : FALSE;
else
return( ERROR );
/*
* is end of line significant?
*/
save_screen_line( 0, window->bottom_line, line_buff );
set_prompt( diff_prompt7d, window->bottom_line );
start = get_yn( );
restore_screen_line( 0, window->bottom_line, line_buff );
if (start != ERROR)
diff.ignore_eol = start == A_YES ? TRUE : FALSE;
else
return( ERROR );
/*
* now, find out were to start the diff -- beginning of file or
* current cursor location.
*/
save_screen_line( 0, window->bottom_line, line_buff );
set_prompt( diff_prompt3, window->bottom_line );
start = get_bc( );
restore_screen_line( 0, window->bottom_line, line_buff );
if (start != ERROR) {
entab_linebuff( );
if (un_copy_line( window->ll, window, TRUE ) == ERROR)
return( ERROR );
/*
* if everything is everything, initialize the diff pointers.
*/
diff.defined = TRUE;
if (start == BEGINNING) {
diff.d1 = diff.w1->file_info->line_list;
diff.d2 = diff.w2->file_info->line_list;
diff.rline1 = 1L;
diff.rline2 = 1L;
diff.bin_offset1 = 0;
diff.bin_offset2 = 0;
rc = differ( 0, 0, window->bottom_line );
} else {
diff.d1 = diff.w1->ll;
diff.d2 = diff.w2->ll;
diff.rline1 = diff.w1->rline;
diff.rline2 = diff.w2->rline;
diff.bin_offset1 = diff.w1->bin_offset;
diff.bin_offset2 = diff.w2->bin_offset;
rc = differ( diff.w1->rcol, diff.w2->rcol, window->bottom_line );
}
}
return( rc );
}
/*
* Name: repeat_diff
* Purpose: compare two cursor positions
* Date: October 31, 1992
* Passed: window: pointer to current window
* Notes: user may press this key at any time once the diff has been
* defined.
*/
int repeat_diff( WINDOW *window )
{
register int rc = ERROR;
if (diff.defined) {
entab_linebuff( );
if (un_copy_line( window->ll, window, TRUE ) == ERROR)
return( ERROR );
/*
* initialize the diff pointers.
*/
diff.d1 = diff.w1->ll;
diff.d2 = diff.w2->ll;
diff.rline1 = diff.w1->rline;
diff.rline2 = diff.w2->rline;
diff.bin_offset1 = diff.w1->bin_offset;
diff.bin_offset2 = diff.w2->bin_offset;
rc = differ( diff.w1->rcol, diff.w2->rcol, window->bottom_line );
} else
error( WARNING, window->bottom_line, diff_prompt5 );
return( rc );
}
/*
* Name: differ
* Purpose: diff text pointers
* Date: October 31, 1992
* Passed: initial_rcol1: beginning column to begin diff in window1
* initial_rcol2: beginning column to begin diff in window2
* bottom: line to display diagnostics
* Notes: a straight diff on text pointers is simple; however, diffing
* with leading spaces and tabs is kinda messy. let's do the
* messy diff.
*/
int differ( int initial_rcol1, int initial_rcol2, int bottom )
{
int rcol1; /* virtual real column on diff window 1 */
int rcol2; /* virtual real column on diff window 2 */
int r1; /* real real column rcol1 - needed for tabs */
int r2; /* real real column rcol2 - needed for tabs */
char c1; /* character under r1 */
char c2; /* character under r2 */
int leading1; /* adjustment for leading space in window 1 */
int leading2; /* adjustment for leading space in window 2 */
int len1; /* length of diff1 line */
int len2; /* length of diff2 line */
line_list_ptr node1; /* scratch node in window 1 */
line_list_ptr node2; /* scratch node in window 2 */
text_ptr diff1; /* scratch text ptr in wind