void Compare_Files(void) { int n; for ( /* all new texts */ n = 0; n < Number_Of_New_Texts; n++ ) { int first = ( /* if compare to old only */ is_set_option('S') ? Number_Of_New_Texts + 1 : /* else if do not compare to self */ is_set_option('s') ? n + 1 /* else */ : n ); if (is_set_option('e')) { /* from first to Number_Of_Texts in steps */ int m; for (m = first; m < Number_Of_Texts; m++) { compare_one_text(n, m, m+1); } } else { /* from first to Number_Of_Texts in one action */ if (first < Number_Of_Texts) { compare_one_text(n, first, Number_Of_Texts); } } } }
/* Sends the run info to add_to_percentages or to add_to_runs. */ void add_run(struct text *txt0, size_t i0, struct text *txt1, size_t i1, size_t size ) { if (is_set_option('p')) { add_to_percentages(txt0, txt1, size); } else { add_to_runs(txt0, i0, txt1, i1, size); } }
void Show_Runs(void) { #ifdef DB_RUN fprintf(Debug_File, "Starting Show_Runs()\n"); #endif /* DB_RUN */ const struct run *run = /*ZZ*/ (is_set_option('u') ? unsorted_runs() : sorted_runs()); while (run) { #ifdef DB_RUN db_run(run); #endif /* DB_RUN */ show_run(run); print_char('\n'); fflush(Output_File); run = run->rn_next; } discard_runs(); }
static void print_and_remove_perc_info_for_top_file(struct match **m_hook) { struct match *m = *m_hook; const char *fname = m->ma_fname0; print_perc_info(m); *m_hook = m->ma_next; Free(m); while ((m = *m_hook)) { if (m->ma_fname0 == fname) { if (is_set_option('P')) { print_perc_info(m); } /* remove the struct */ *m_hook = m->ma_next; Free(m); } else { /* skip the struct */ m_hook = &m->ma_next; continue; } } }
void add_run(struct text *txt0, size_t i0, struct text *txt1, size_t i1, size_t size ) { /* Adds the run of given size to our collection. */ struct run *r = new(struct run); set_chunk(&r->rn_chunk0, txt0, i0 - txt0->tx_start, size); set_chunk(&r->rn_chunk1, txt1, i1 - txt1->tx_start, size); r->rn_size = size; #ifdef DB_RUN db_run_info("Added", r, 0); #endif /* DB_RUN */ if (is_set_option('p')) { add_to_percentages(r); } else { add_to_runs(r); } }
void Read_Input_Files(int argc, const char *argv[], int round) { int n; Init_Text(argc); Init_Token_Array(); /* Assume all texts to be new */ Number_Of_New_Texts = Number_Of_Texts; /* Read the files */ for (n = 0; n < Number_Of_Texts; n++) { const char *fname = argv[n]; struct text *txt = &Text[n]; if (round == 1 && !is_set_option('T')) { fprintf(Output_File, "File %s: ", fname); } txt->tx_fname = fname; txt->tx_pos = 0; txt->tx_start = txt->tx_limit = Text_Length(); if (is_new_old_separator(fname)) { if (round == 1 && !is_set_option('T')) { fprintf(Output_File, "separator\n"); } Number_Of_New_Texts = n; } else { if (!Open_Text(First, txt)) { if (round == 1 && !is_set_option('T')) { fprintf(Output_File, ">>>> cannot open <<<< "); } /* the file has still been opened with a null file for uniformity */ } while (Next_Text_Token_Obtained(First)) { if (!Token_EQ(lex_token, End_Of_Line)) { Store_Token(lex_token); } } Close_Text(First, txt); txt->tx_limit = Text_Length(); /* report */ if (round == 1 && !is_set_option('T')) { fprint_count(Output_File, txt->tx_limit - txt->tx_start, token_name ); fprintf(Output_File, ", "); fprint_count(Output_File, lex_nl_cnt-1, "line"); if (lex_non_ascii_cnt) { fprintf(Output_File, ", "); fprint_count(Output_File, lex_non_ascii_cnt, "non-ASCII character" ); } fprintf(Output_File, "\n"); } #ifdef DB_TEXT db_print_text(txt); #endif /* DB_TEXT */ } fflush(Output_File); } /* report total */ if (round == 1 && !is_set_option('T')) { fprintf(Output_File, "Total: "); fprint_count(Output_File, Text_Length() - 1, token_name); fprintf(Output_File, "\n\n"); fflush(Output_File); } }
static void show_run(const struct run *run) { /* The animals came in two by two ... */ const struct chunk *cnk0 = &run->rn_chunk0; const struct chunk *cnk1 = &run->rn_chunk1; size_t nl_cnt0 = cnk0->ch_last.ps_nl_cnt - cnk0->ch_first.ps_nl_cnt; size_t nl_cnt1 = cnk1->ch_last.ps_nl_cnt - cnk1->ch_first.ps_nl_cnt; FILE *f0; FILE *f1; /* display heading of chunk */ if (!is_set_option('d')) { /* no assumptions about the lengths of the file names! */ size_t size = run->rn_size; int pos = 0; pos += pr_head(cnk0); while (pos < max_line_length + 1) { pos += prs(" "); } pos += prs("|"); pos += pr_head(cnk1); while (pos < 2*max_line_length - unslen(size)) { pos += prs(" "); } fprintf(Output_File, "[%s]\n", size_t2string(size)); } else { (void)pr_head(cnk0); fprintf(Output_File, "\n"); (void)pr_head(cnk1); fprintf(Output_File, "\n"); } /* stop if that suffices */ if (is_set_option('n')) return; /* ... had enough so soon ... */ /* open the files that hold the chunks */ f0 = open_chunk(cnk0); f1 = open_chunk(cnk1); /* display the chunks in the required format */ if (!is_set_option('d')) { /* fill 2-column lines and print them */ while (nl_cnt0 != 0 || nl_cnt1 != 0) { if (nl_cnt0) { fill_line(f0, line0); nl_cnt0--; } else { clear_line(line0); } if (nl_cnt1) { fill_line(f1, line1); nl_cnt1--; } else { clear_line(line1); } show_2C_line(line0, line1); } } else { /* display the lines in a diff(1)-like format */ while (nl_cnt0--) { show_1C_line(f0, "<"); } fprintf(Output_File, "---\n"); while (nl_cnt1--) { show_1C_line(f1, ">"); } } /* close the pertinent files */ fclose(f0); fclose(f1); }
void Read_Input_Files(int argc, const char *argv[]) { int n; Init_Text(argc); Init_Token_Array(); /* Initially assume all texts to be new */ Number_of_New_Texts = Number_of_Texts; /* Read the files */ for (n = 0; n < Number_of_Texts; n++) { const char *fname = argv[n]; struct text *txt = &Text[n]; if (!is_set_option('T')) { fprintf(Output_File, "File %s: ", fname); } txt->tx_fname = fname; txt->tx_pos = 0; txt->tx_start = Token_Array_Length(); txt->tx_limit = Token_Array_Length(); if (is_new_old_separator(fname)) { if (!is_set_option('T')) { fprintf(Output_File, "new/old separator\n"); } if (Number_of_New_Texts == Number_of_Texts) { Number_of_New_Texts = n; } else fatal("more than one new/old separator"); } else { int file_opened = 0; if (Open_Text(First_Pass, txt)) { file_opened = 1; } else { /* print a warning */ if (is_set_option('T')) { /* the file name has not yet been printed; print it now */ fprintf(Output_File, "File %s: ", fname); } fprintf(Output_File, ">>>> cannot open <<<<\n"); /* the file has still been opened with a null file for uniformity */ } while (Next_Text_Token_Obtained()) { if (!Token_EQ(lex_token, End_Of_Line)) { Store_Token(lex_token); } } Close_Text(First_Pass, txt); txt->tx_limit = Token_Array_Length(); txt->tx_EOL_terminated = Token_EQ(lex_token, End_Of_Line); /* report */ if (file_opened && !is_set_option('T')) { fprint_count(Output_File, txt->tx_limit - txt->tx_start, Token_Name ); fprintf(Output_File, ", "); fprint_count(Output_File, lex_nl_cnt - 1 + (!txt->tx_EOL_terminated ? 1 : 0), "line" ); if (!txt->tx_EOL_terminated) { fprintf(Output_File, " (not NL-terminated)"); } if (lex_non_ascii_cnt) { fprintf(Output_File, ", "); fprint_count(Output_File, lex_non_ascii_cnt, "non-ASCII character" ); } fprintf(Output_File, "\n"); } #ifdef DB_TEXT db_print_text(txt); #endif /* DB_TEXT */ } fflush(Output_File); } /* report total */ int sep_present = (Number_of_Texts != Number_of_New_Texts); fprintf(Output_File, "Total input: "); fprint_count(Output_File, (!sep_present ? Number_of_Texts : Number_of_Texts - 1), "file" ); fprintf(Output_File, " (%d new, %d old), ", Number_of_New_Texts, (!sep_present ? 0 : Number_of_Texts - Number_of_New_Texts - 1) ); fprint_count(Output_File, Token_Array_Length() - 1, Token_Name); fprintf(Output_File, "\n\n"); fflush(Output_File); }
static void show_run(const struct run *run) { max_line_length = Page_Width / 2 - 1; max_line_length_UTF8 = max_line_length * FONT_SIZE; /* The animals came in two by two ... */ const struct chunk *cnk0 = &run->rn_chunk0; const struct chunk *cnk1 = &run->rn_chunk1; size_t nl_cnt0 = cnk0->ch_last.ps_nl_cnt - cnk0->ch_first.ps_nl_cnt; size_t nl_cnt1 = cnk1->ch_last.ps_nl_cnt - cnk1->ch_first.ps_nl_cnt; FILE *f0; FILE *f1; /* display heading of chunk */ if (!is_set_option('d')) { /* no assumptions about the lengths of the file names! */ size_t size = run->rn_size; int pos = print_header(cnk0); print_spaces(max_line_length - pos); print_char('|'); pos = print_header(cnk1); print_spaces(max_line_length - pos - length_size_t(size) - 2); fprintf(Output_File, "[%s]\n", size_t2string(size)); } else { /* diff-like format */ (void)print_header(cnk0); print_char('\n'); (void)print_header(cnk1); print_char('\n'); } /* stop if that suffices */ if (is_set_option('n')) return; /* ... had enough so soon ... */ /* open the files that hold the chunks */ f0 = open_chunk(cnk0); f1 = open_chunk(cnk1); /* display the chunks in the required format */ if (!is_set_option('d')) { /* print 2-column format */ while (nl_cnt0 != 0 || nl_cnt1 != 0) { int pos_UTF8 = 0; if (nl_cnt0) { pos_UTF8 = print_UTF8_line(f0); nl_cnt0--; } print_UTF8_spaces(max_line_length_UTF8 - pos_UTF8); print_char('|'); if (nl_cnt1) { (void)print_UTF8_line(f1); nl_cnt1--; } print_char('\n'); } } else { /* display the chunks in a diff(1)-like format */ while (nl_cnt0--) { show_1C_line(f0, "<"); } (void)print_string("---\n"); while (nl_cnt1--) { show_1C_line(f1, ">"); } } /* close the pertinent files */ fclose(f0); fclose(f1); }