home *** CD-ROM | disk | FTP | other *** search
- $macro filecomp;
- {*******************************MULTI-EDIT MACRO******************************
-
- Last Revised: 02-02-90 08:52am
-
- Macro Name: Filecomp
-
- Description: Compares two files
- If /t = 1 User will be prompted for both filenames and
- direction of split. Will support split in any direction.
- Compares line by line, checking for differences in text
- along with differences in indent levels. If any differences
- are found they will be highlighted and the user will be prompted
- whether to continue checking or not. If they choose to get
- out & stop comparing they can resume by choosing compare again.
-
- Parameters:
- /t= Compare Type
- 1 = Compare for First Time
- 2 = Compare again
- If no parameters passed - Defaults to Compare for First Time
-
- /CS=
- 1 = Compare Case Sensitive
- If no parameters passed - Defaults to Case Insensitive
-
- /COL=
- Column to start from
-
- /LEN=
- For use with col to compare a particular column
- in a file
-
-
- (C) Copyright 1989 by American Cybernetics, Inc.
- ******************************************************************************}
-
- def_int(line_no_file1,line_no_file2,old_window_no,diff_found,compare_type,
- reached_eof1,reached_eof2,message_type,error_message_type,pos_no,
- l_num,atleast_1diff,col_where_diff,x,col,win_count,found_err_file,
- quick_exit,lngth1,lngth2,d_type,lngth,lnum,save_x1,save_x2,
- save_win_x1,save_end_col,c_lngth);
- def_str(temp_line1[2048],temp_line2[2048],temp1[2048],temp2[2048],gstr[20],temp[2048],sstr);
-
- refresh := false;
- quick_exit := false;
- old_window_no := window_id;
- load_macro_file('window');
- compare_type := parse_int('/t=',mparm_str); {determine what type of compare}
-
-
- if (compare_type = 1) or (compare_type = 0) then {Compare for first time}
- set_global_int('case_sensitive',(parse_int('/c=',mparm_str)));
- set_global_int('start_col',(parse_int('/col=',mparm_str)));
- set_global_int('compare_lngth',(parse_int('/len=',mparm_str)));
-
- gstr := '!SM!_';
- create_global_str(gstr+'1','/m=filecomp');
- create_global_str(gstr+'X1',' INTERACTIVELY ON SCREEN ');
- create_global_str(gstr+'2','/m=filecomp');
- create_global_str(gstr+'X2',' TO A FILE ');
- create_global_str(gstr+'3','/m=filecomp');
- create_global_str(gstr+'X3',' BOTH');
-
- RUN_MACRO('USERIN^SUBMENU /gclr=1/#=3/M=' + gstr + 'X' + '/S=' +global_str(gstr+'0') +'/G=' + gstr
- + '/X=10/Y=5/L=RESULTS OF FILE COMPARE DISPLAYED/B=0');
- if (return_int = -1) or (return_int = 0) then
- quick_exit := true;
- goto end_of_mac;
- end;
- set_global_int('display_type',return_int);
-
- kill_box; {if you dont do a new screen you will reveal contents}
- new_screen; {of old screen you started out compare from}
-
- if (global_int('display_type') = 2) or (global_int('display_type') = 3) then
- {make sure an error file doesnt already exist if it does delete it}
- found_err_file := false;
- if user_id = '' then
- sstr := caps(me_path + 'file.dif');
- else
- sstr := caps(me_path + user_id + 'file.dif');
- end;
-
- if switch_file(sstr) then
- erase_window;
- found_err_file := true;
- end;
-
- if not(found_err_file) then
- Create_Window;
- end;
-
- window_attr := window_attr or $01; {hide window}
- if user_id = '' then
- file_name := ME_PATH + 'FILE.DIF';
- else
- file_name := ME_PATH + USER_ID + 'FILE.DIF';
- end;
- set_global_int('err_file_window',window_id);
- message_type := 6; {please stand by message}
- call write_errors;
- end;
-
- old_window_no := window_id;
- run_macro('makewin /L=1'); {creates new window, loads the file, & runs setup for ext}
- if caps(file_name) = '?NO-FILE?' then {if they pressed esc assume they want to quit & exit}
- delete_window;
- quick_exit := true;
- goto end_of_mac;
- end;
- if error_level = 0 then {the file existed no trouble loading}
- set_global_int('win_no_file1',window_id);
- set_global_str('filename_1',file_name);
- run_macro('splitwin');
- if (global_int('s_direction') = 0) then {the s_direction global is set}
- quick_exit := true; {in window.src}
- goto end_of_mac;
- end;
- refresh := TRUE;
- redraw;
- refresh := FALSE;
- else
- quick_exit := true;
- goto end_of_mac;
- end;
-
- set_global_int('did_compare_once',1);
- set_global_int('win_no_file2',window_id);
- set_global_str('filename_2',file_name);
-
- line_no_file1 := 1;
- line_no_file2 := 1;
-
- else
- {They pressed compare again - check to see if they already compared once
- make sure they are in the same windows & same filenames then compare
- again - else display error messages}
-
- if (not(global_int('did_compare_once') = 1)) then
- error_message_type := 1;
- goto error_msg; {never compared files - use compare two files first}
- else
- if switch_win_id(global_int('win_no_file1')) then
- if file_name <> global_str('filename_1') then
- error_message_type := 2;
- goto error_msg;
- end;
- else
- error_message_type := 2;
- goto error_msg;
- end;
- if switch_win_id(global_int('win_no_file2')) then
- if file_name <> global_str('filename_2') then
- error_message_type := 2;
- goto error_msg;
- end;
- else
- error_message_type := 2;
- goto error_msg;
- end;
- end;
-
- set_global_int('start_col',(parse_int('/col=',mparm_str)));
- set_global_int('compare_lngth',(parse_int('/len=',mparm_str)));
-
- {routine following will put lines in question at top of screen before checking
- for purposes of screen clarity}
-
- refresh := true; {should be on already in sys but just in case}
- switch_win_id(global_int('win_no_file1'));
- line_no_file1 := c_line; {get actual line no in file1}
- while c_row > 1 do
- up;
- end;
- goto_line(line_no_file1);
- redraw;
-
- switch_win_id(global_int('win_no_file2'));
- line_no_file2 := c_line; {get actual line no in file2}
- while c_row > 1 do
- up;
- end;
- goto_line(line_no_file2);
- redraw;
-
- {they are comparing again get find the err file and goto eof}
-
- if (global_int('display_type') = 2) or (global_int('display_type') = 3) then
- refresh := false;
- if switch_win_id(global_int('err_file_window')) then
- if user_id = '' then
- if ((File_Name) = (ME_PATH + 'FILE.DIF')) then
- window_attr := window_attr or $01; {hide window}
- message_type := 7;
- call write_errors;
- end;
- else
- if ((File_Name) = (ME_PATH + USER_ID + 'FILE.DIF')) then
- window_attr := window_attr or $01; {hide window}
- message_type := 7;
- call write_errors;
- end;
- end;
- else error_message_type := 2;
- goto error_msg;
- end;
- end;
- end;
-
- put_box(18,11,61,14,1,w_t_color,'',true);
- write('PLEASE STANDBY WHILE COMPARING FILES...',20,12,0,w_t_color);
- delay(1000);
- kill_box;
-
- if (global_int('display_type') = 2) then
- working; {add percent done here}
- end;
-
- diff_found := false;
- reached_eof1 := false;
- reached_eof2 := false;
- atleast_1diff := false;
-
- main_loop:
- refresh := false; {turn refresh off while checking to improve performance}
- while not(diff_found) do
- if (window_id <> global_int('win_no_file1')) then
- switch_win_id(global_int('win_no_file1'));
- end;
- goto_line(line_no_file1);
- if (not (at_eof)) then
- temp_line1 := get_line;
- switch_win_id(global_int('win_no_file2'));
- goto_line(line_no_file2);
- if (not (at_eof)) then
- temp_line2 := get_line;
- call compare_lines;
- else reached_eof2 := true;
- goto reached_eof;
- end;
- else reached_eof1 := true;
- goto reached_eof;
- end;
- ++line_no_file1;
- ++line_no_file2;
- end; {while do}
- goto end_of_mac;
-
- compare_lines:
-
- if (not(global_int('case_sensitive') = 1)) then
- temp_line1 := caps(temp_line1);
- temp_line2 := caps(temp_line2);
- end;
-
- if global_int('start_col') > 0 then
- if (global_int('compare_lngth') = 0) then {if no length is specified compare to end of string}
- c_lngth := (length(temp_line1) - global_int('start_col'));
- else
- c_lngth := global_int('compare_lngth');
- end;
- temp1 := temp_line1; {save what it originally looks like before}
- temp2 := temp_line2; {manipulation so you can display it later}
- temp_line1 := copy(temp_line1,global_int('start_col'),c_lngth);
- temp_line2 := copy(temp_line2,global_int('start_col'),c_lngth);
- end;
-
- if temp_line1 <> temp_line2 then
- if (global_int('start_col') = 0) then
- temp1 := temp_line1;
- temp2 := temp_line2;
- end;
- {save_end_col used to line up both strings for easy comparison}
- if length(temp1) >= length(temp2) then
- save_end_col := length(temp1) + 2; {+2 so it will be fully on screen}
- else
- save_end_col := length(temp2) + 2;
- end;
-
- temp_line1 := remove_space(temp_line1); {remove space only cuts it down to a}
- temp_line2 := remove_space(temp_line2); {minimum of one consecutive space }
-
- if temp_line1 <> temp_line2 then
- tabs_to_spaces(temp_line1);
- tabs_to_spaces(temp_line2);
-
- while (xpos(' ',temp_line1,1) <> 0) do {following removes ALL spaces}
- pos_no := xpos(' ',temp_line1,1);
- temp_line1 := str_del(temp_line1,pos_no,1);
- end;
-
- while (xpos(' ',temp_line2,1) <> 0) do
- pos_no := xpos(' ',temp_line2,1);
- temp_line2 := str_del(temp_line2,pos_no,1);
- end;
-
- if temp_line1 <> temp_line2 then
- diff_found := true;
- message_type := 5; {still diff with spaces out}
- goto display_msg;
- else diff_found := true; {now the same only diff is spaces}
- message_type := 4;
- goto display_msg;
- end;
- else
- diff_found := true; {now the same only diff is spaces}
- message_type := 4;
- goto display_msg;
- end;
- end;
- ret;
-
- reached_eof:
- if ((reached_eof2) and not(reached_eof1)) then
- message_type := 1;
- goto display_msg;
- elsif reached_eof1 then {if your at eof 1 switch to window 2 & see if your at eof2 also}
- switch_win_id(global_int('win_no_file2'));
- goto_line(line_no_file2);
- if at_eof then
- reached_eof2 := true;
- end;
- end;
-
- if (reached_eof1 and reached_eof2) then
- diff_found := true;
- message_type := 2;
- goto display_msg;
- elsif (reached_eof1 and (not(reached_eof2))) then
- diff_found := true;
- message_type := 3;
- goto display_msg;
- end;
-
- display_msg:
- if (global_int('display_type') = 1) or (global_int('display_type') = 3) then
- refresh := true;
- end;
- switch_win_id(global_int('win_no_file1'));
- if (message_type = 1) then
- if (global_int('display_type') = 1) or (global_int('display_type') = 3) then
- goto_line(line_no_file1);
- col := (80 - (length(global_str('filename_2')))) / 2;
- put_box(18,7,61,13,1,w_t_color,'',true);
- write('THE END OF FILE WAS REACHED IN FILE: ',20,8,0,w_t_color);
- write('═ ',col-5,9,0,w_t_color);
- write(caps(global_str('filename_2')),col,9,0,w_t_color);
- col := (80 - (length(global_str('filename_1')))) / 2;
- write('PRESS ANY KEY TO GO TO NEXT LINE OF: ',20,10,0,w_t_color);
- write('═ ',col-5,11,0,w_t_color);
- write(caps(global_str('filename_1')),col,11,0,w_t_color);
- read_key;
- kill_box;
- if (global_int('display_type') = 3) then
- call write_errors;
- end;
- elsif (global_int('display_type') = 2) then
- call write_errors;
- end;
- elsif (message_type = 2) then
- if (global_int('display_type') = 1) or (global_int('display_type') = 3) then
- if (atleast_1diff) then
- switch_win_id(global_int('win_no_file1')); {no diffs go back to window 1}
- goto_line(line_no_file1);
- put_box(26,9,56,13,1,w_t_color,'',true);
- write('FILE COMPARISON COMPLETE',28,10,0,w_t_color);
- write(' < PRESS ANY KEY >',28,11,0,w_t_color);
- else
- switch_win_id(global_int('win_no_file2'));
- tof;
- switch_win_id(global_int('win_no_file1'));
- tof;
- put_box(26,10,57,13,1,w_t_color,'',true);
- write(' FILE COMPARISON COMPLETE ',28,10,0,w_t_color);
- write(' NO DIFFERENCES FOUND ! ',28,11,0,w_t_color);
- write(' < PRESS ANY KEY >',32,12,0,w_t_color);
- end;
- read_key;
- kill_box;
- if (global_int('display_type') = 3) then
- call write_errors;
- end;
- elsif (global_int('display_type') = 2) then
- call write_errors;
- end;
- elsif (message_type = 3) then
- if (global_int('display_type') = 1) or (global_int('display_type') = 3) then
- switch_win_id(global_int('win_no_file2')); {reached eof in 1 go to window 2}
- goto_line(line_no_file2);
- col := (80 - (length(global_str('filename_1')))) / 2;
- put_box(18,7,61,13,1,w_t_color,'',true);
- write('THE END OF FILE WAS REACHED IN FILE: ',20,8,0,w_t_color);
- write('═ ',col-5,9,0,w_t_color);
- write(caps(global_str('filename_1')),col,9,0,w_t_color);
- col := (80 - (length(global_str('filename_2')))) / 2;
- write('PRESS ANY KEY TO GO TO NEXT LINE OF: ',20,10,0,w_t_color);
- write('═',col-5,11,0,w_t_color);
- write(caps(global_str('filename_2')),col,11,0,w_t_color);
- read_key;
- kill_box;
- if (global_int('display_type') = 3) then
- call write_errors;
- end;
- elsif (global_int('display_type') = 2) then
- call write_errors;
- end;
- elsif (message_type = 4) then
- call diff_foundmsg;
- elsif (message_type = 5) then
- call diff_foundmsg;
- end;
- goto end_of_mac;
-
- diff_foundmsg:
- call find_col_pos;
- if (global_int('display_type') = 1) or (global_int('display_type') = 3) then
-
- goto_col(save_end_col);
- save_win_x1 := win_x2;
- if col_where_diff > 1 then {if they are different at col 1 dont add 1}
- goto_col(col_where_diff - 1); {- 1 to display last similar column}
- save_x1 := wherex + 1; {+ 1 before you highlight}
- else
- goto_col(col_where_diff);
- save_x1 := wherex;
- end;
- switch_win_id(global_int('win_no_file2'));
- goto_col(save_end_col);
- if col_where_diff > 1 then {if they are different at col 1 dont add 1}
- goto_col(col_where_diff - 1); {- 1 to display last similar column}
- save_x2 := wherex + 1; {+ 1 before you highlight}
- else
- goto_col(col_where_diff);
- save_x2 := wherex;
- end;
- call highlight_difference;
-
- if (message_type = 4) then
- run_macro('userin^verify /C=14/L=10/T= WOULD YOU LIKE TO CONTINUE COMPARING FILES?/S=2/BL= < AN INDENT OR SPACING DIFFERENCE WAS FOUND >');
- elsif (message_type = 5) then
- run_macro('userin^verify /C=14/L=10/T=WOULD YOU LIKE TO CONTINUE COMPARING FILES?/S=2/BL= < LINES ARE DIFFERENT > ');
- end;
-
- if return_int then
- if (global_int('display_type') = 3) then
- call write_errors;
- end;
- diff_found := false;
- line_no_file1 := line_no_file1 + 1;
- line_no_file2 := line_no_file2 + 1;
- atleast_1diff := true;
- goto main_loop;
- else
- if (global_int('display_type') = 3) then
- call write_errors;
- end;
- goto end_of_mac;
- end;
- elsif (global_int('display_type') = 2) then
- call write_errors;
- diff_found := false;
- line_no_file1 := line_no_file1 + 1;
- line_no_file2 := line_no_file2 + 1;
- atleast_1diff := true;
- goto main_loop;
- end;
- ret;
-
- error_msg:
- if error_message_type = 1 then
- put_box(18,2,62,6,1,w_t_color,'',true);
- write('YOU MUST RUN "COMPARE TWO FILES" FIRST!',20,3,0,w_t_color);
- write(' <Press ANY key to continue> ',20,4,0,w_t_color);
- read_key;
- kill_box;
-
- elsif error_message_type = 2 then
- put_box(18,2,62,6,1,w_t_color,'',true);
- write(' ERROR LOCATING FILES ',28,2,0,w_t_color);
- write('YOU MUST RUN "COMPARE TWO FILES" FIRST!',20,3,0,w_t_color);
- write(' <Press ANY key to continue> ',20,4,0,w_t_color);
- read_key;
- kill_box;
- end;
- quick_exit := true;
- goto end_of_mac;
-
- highlight_difference:
- if (global_int('s_direction') = 1) or (global_int('s_direction') = 4) then {RIGHT}{DOWN}
- d_type := 1;
- call write_hlight;
- d_type := 2;
- call write_hlight;
- elsif (global_int('s_direction') = 2) or (global_int('s_direction') = 3) then {LEFT} {UP}
- d_type := 2;
- call write_hlight;
- d_type := 1;
- call write_hlight;
- end;
- ret;
-
- find_col_pos:
- {find col position where difference was encountered}
- if (global_int('start_col') > 0) then
- x := global_int('start_col');
- else
- x := 1;
- end;
- while (str_char(temp1,x) = str_char(temp2,x)) do
- { MAKE_MESSAGE('TEMP1 ' + str_char(temp1,x) + '***');READ_KEY;
- MAKE_MESSAGE('TEMP2 ' + str_char(temp2,x) + '***');READ_KEY;}
- ++x
- end;
- col_where_diff := x;
- ret;
-
- write_hlight:
- if ((global_int('s_direction') = 1) or (global_int('s_direction') = 2)) then {RIGHT}
- lnum := 4;
- elsif (global_int('s_direction') = 3) then {UP}
- if d_type = 1 then
- lnum := 15;
- elsif d_type = 2 then
- lnum := 4;
- end;
- elsif (global_int('s_direction') = 4) then {DOWN}
- if d_type = 1 then
- lnum := 4;
- elsif d_type = 2 then
- lnum := 15;
- end;
- end;
-
- if (d_type = 1) then
- temp := temp1;
- elsif (d_type = 2) then
- temp := temp2;
- end;
- { lngth := length(temp);}
- lngth := save_end_col; {make the lengths both equal to the longest str}
-
-
- IF (global_int('compare_lngth') > 0) then {if you passed a length}
- if ((global_int('s_direction') = 1) or (global_int('s_direction') = 2)
- AND (global_int('compare_lngth') > 39)) then
- lngth := 39; {save guard for screen}
- else
- lngth := global_int('compare_lngth') - (col_where_diff - global_int('start_col'));
- end;
- ELSE
- if (d_type = 1) then
- if (save_win_x1 - (save_x1)) <= (lngth - col_where_diff) then
- lngth := (save_win_x1 - save_x1);
- else
- lngth := (lngth - col_where_diff) + 1;
- end;
- elsif (d_type = 2) then
- if (global_int('s_direction') = 2) then
- lngth := lngth - 1; {when you split left -1 so}
- end; {it doesn't run into border}
- if (win_x2 - (save_x2)) <= (lngth - col_where_diff) then
- lngth := (win_x2 - save_x2);
- else
- lngth := (lngth - col_where_diff) + 1;
- end;
- end;
- END;
-
- IF (d_type = 1) then
- draw_attr(save_x1,lnum,w_h_color,lngth);
- ELSIF (d_type = 2)
- then draw_attr(save_x2,lnum,w_h_color,lngth);
- end;
- ret;
-
- write_errors:
- refresh := false;
- switch_win_id(global_int('err_file_window'));
- if (message_type = 1) then
- put_line('═════════════════════════════════════════════════════════════════');eol;cr;
- put_line('THE END OF FILE WAS REACHED IN FILE: ');eol;cr;
- put_line(caps(global_str('filename_2')));eol;cr;
- put_line('═════════════════════════════════════════════════════════════════');eol;cr;
- elsif (message_type = 2) then
- put_line('FILE COMPARISON COMPLETE');eol;cr;
- if not(atleast_1diff) then
- put_line(' NO DIFFERENCES FOUND ! ');eol;cr;
- put_line('═════════════════════════════════════════════════════════════════');eol;cr;
- end;
- elsif (message_type = 3) then
- put_line('═════════════════════════════════════════════════════════════════');eol;cr;
- put_line('THE END OF FILE WAS REACHED IN FILE: ');eol;cr;
- put_line(caps(global_str('filename_1')));eol;cr;
- put_line('═════════════════════════════════════════════════════════════════');eol;cr;
- elsif (message_type = 4) then
- put_line('╔═══════════════════════════════════════════════════════════════╗');eol;cr;
- text('║ AN INDENT OR SPACING DIFFERENCE WAS FOUND AT COLUMN = '
- + str(col_where_diff));goto_col(65);text('║');eol;cr;
- put_line('╚═══════════════════════════════════════════════════════════════╝');eol;cr;
- call display_err;
- elsif (message_type = 5) then
- put_line('╔═══════════════════════════════════════════════════════════════╗');eol;cr;
- text('║ LINES ARE DIFFERENT AT COLUMN = '
- + str(col_where_diff));goto_col(65);text('║');eol;cr;
- put_line('╚═══════════════════════════════════════════════════════════════╝');eol;cr;
- call display_err;
- elsif (message_type = 6) then
- put_line('╔═══════════════════════════════════════════════════════════════╗');eol;cr;
- put_line('║ FILE COMPARISON OUTPUT ║');eol;cr;
- put_line('╚═══════════════════════════════════════════════════════════════╝');eol;cr;
- elsif (message_type = 7) then
- refresh := false;
- eof;eol;cr;
- put_line('╔═══════════════════════════════════════════════════════════════╗');eol;cr;
- put_line('║ FILE COMPARE RESTARTED ║');eol;cr;
- col := (65 - ((length(global_str('filename_1'))) + 15)) / 2;
- text('║ ');goto_col(col);text(global_str('filename_1') + ' ═ LINE NO: '
- + str(line_no_file1));goto_col(65);text('║');eol;cr;
- col := (65 - ((length(global_str('filename_2'))) + 15)) / 2;
- text('║ ');goto_col(col);text(global_str('filename_2') + ' ═ LINE NO: '
- + str(line_no_file2));goto_col(65);text('║');eol;cr;
- put_line('╚═══════════════════════════════════════════════════════════════╝');eol;cr;
- end;
- ret;
-
- display_err:
- put_line(global_str('filename_1') + ' ═ LINE NO: ' + (str(line_no_file1)));eol;cr;
- put_line(temp1);eol;cr;
- put_line(global_str('filename_2') + ' ═ LINE NO: ' + (str(line_no_file2)));eol;cr;
- put_line(temp2);eol;cr;
- ret;
-
- end_of_mac:
-
- if not(quick_exit) then
- {if they are just writing to a file you should leave them in
- the error file window}
-
- if (global_int('display_type') = 2) or (global_int('display_type') = 3) then
- switch_win_id(global_int('err_file_window'));
- save_file;
- tof;
- Window_Attr := Window_Attr and $FE; {unhide the window}
- end;
-
- if (not(global_int('display_type') = 2)) then
- if (message_type = 1) then
- switch_win_id(global_int('win_no_file1'));
- else
- switch_win_id(global_int('win_no_file2'));
- end;
- end;
-
- {if they are doing it interactively switch to tmp window save the file
- delete the window & go back to the file window}
- end;
-
- refresh := true; {shouldnt have to but...}
- end_macro;
-