int main(int argc, char **argv) { E_edit edit_end; char *filename[2]; int max_d; /* max number of differences allowed */ int i; /* loop counter */ /* ** parse the command line */ _Y_doargs(argc, argv, &(filename[0]), &(filename[1]), &max_d); /* ** initialize the default tolerance if it ** hasn't been set already. */ T_initdefault(); /* ** read and then parse the files */ /* ** L_initfile return a code that indicates if the ** entire file was read or not ** ** P_fileparse also knows how to start at someplace other ** than the first line of file ** ** Taken together, this is enough to do step our way ** through the file using an exact match algorithm. ** ** Oh well, someday . . . */ for (i = 0; i <= 1; i++) { /* ** read the file into core */ (void) L_init_file(i, filename[i]); K_settmax(i, 0); /* start tokens at 0 */ /* ** and parse the files into tokens */ P_file_parse(i, 0, L_getrlmax(i), _Y_flags); } if (_Y_vflag) { return (V_visual(_Y_flags)); } /* ** if max_d was not set on the command line ** set it to be as large as is possible ** since the most changes possible would ** be to delete all the tokens in the ** first file and add all the tokens from ** the second, the max possible is the ** sum of the number of tokens in the ** two files. */ if (-1 == max_d) max_d = K_gettmax(0) + K_gettmax(1); if (_Y_eflag) { edit_end = Q_do_exact(K_gettmax(0), K_gettmax(1), max_d, _Y_flags); } else { edit_end = G_do_miller(K_gettmax(0), K_gettmax(1), max_d, _Y_flags); } if (E_NULL != edit_end) { O_output(edit_end, _Y_flags); return (1); } return (0); }
int QAdiff(SEPFILE **canFile,SEPFILE **resFile,SEPFILE *diffFile,i4 max_d) { char *toktype = NULL ; register i4 i ; i4 memerr ; STATUS ret_val ; register FILE_TOKENS *t = NULL ; E_edit ed_res ; totaldiffs = no_tokens = failMem = 0; list_head = list_tail = NULL; SEPrewind(diffFile, TRUE); if (grammar_methods&GRAMMAR_SED_C) { if( (ret_val = Run_SED_on_file(canFile,&SEPcanloc)) != OK ) { char tempbuffer[TEST_LINE+1]; clean_token_blocks(); IISTmove(ERx("ERROR: SED command failed"),' ', TEST_LINE, tempbuffer); tempbuffer[TEST_LINE] = '\0'; SEPputrec(tempbuffer, diffFile); return(1); } } if (grammar_methods&GRAMMAR_LEX) { SEPrewind(*canFile, TRUE); currSEPptr = *canFile; yylex(); } if (failMem) { char tempbuffer[TEST_LINE+1]; clean_token_blocks(); IISTmove(ERx("ERROR: lack of memory while lexing"),' ', TEST_LINE, tempbuffer); tempbuffer[TEST_LINE] = '\0'; SEPputrec(tempbuffer, diffFile); return(1); } list1 = list_head; numtokens1 = no_tokens; size_tokarray(1, numtokens1+1); for (i = 1, t = list1; t != NULL; i++, t = t->next) tokarray1[i] = t; if (tracing & TRACE_TOKENS) Trace_Token_List(ERx("Canon"), ++no_cans, numtokens1, tokarray1); failMem = no_tokens = 0; list_head = list_tail = NULL; if (grammar_methods&GRAMMAR_SED_R) { if( (ret_val = Run_SED_on_file(resFile,& SEPresloc)) != OK ) { char tempbuffer[TEST_LINE+1]; clean_token_blocks(); IISTmove(ERx("ERROR: SED command failed"),' ', TEST_LINE, tempbuffer); tempbuffer[TEST_LINE] = '\0'; SEPputrec(tempbuffer, diffFile); return(1); } } if (grammar_methods&GRAMMAR_LEX) { SEPrewind(*resFile, FALSE); currSEPptr = *resFile; yylex(); } if (failMem) { char tempbuffer[TEST_LINE+1]; clean_token_blocks(); IISTmove(ERx("ERROR: lack of memory while lexing"),' ', TEST_LINE, tempbuffer); tempbuffer[TEST_LINE] = '\0'; SEPputrec(tempbuffer, diffFile); return(1); } list2 = list_head; numtokens2 = no_tokens; size_tokarray(2, numtokens2+1); for (i = 1, t = list2 ; t != NULL ; i++, t = t->next) tokarray2[i] = t; if (tracing & TRACE_TOKENS) Trace_Token_List(ERx("Result"), ++no_res, numtokens2, tokarray2); ed_res = G_do_miller(numtokens1,numtokens2,max_d,&memerr); if (memerr) { char tempbuffer[TEST_LINE+1]; clean_edit_blocks(); IISTmove(ERx("ERROR: lack of memory while diffing"),' ', TEST_LINE, tempbuffer); tempbuffer[TEST_LINE] = '\0'; SEPputrec(tempbuffer, diffFile); return(1); } if (totaldiffs) O_output(ed_res, 0, totaldiffs, diffFile); free_tokens(); SEPrewind(*canFile, FALSE); SEPrewind(*resFile, FALSE); return(totaldiffs); }