static void print_normal_hunk (struct change *hunk) { lin first0, last0, first1, last1; register lin i; /* Determine range of line numbers involved in each file. */ enum changes changes = analyze_hunk (hunk, &first0, &last0, &first1, &last1); if (!changes) return; begin_output (); /* Print out the line number header for this hunk */ print_number_range (',', &files[0], first0, last0); fprintf (outfile, "%c", change_letter[changes]); print_number_range (',', &files[1], first1, last1); fprintf (outfile, "\n"); /* Print the lines that the first file has. */ if (changes & OLD) for (i = first0; i <= last0; i++) print_1_line ("<", &files[0].linbuf[i]); if (changes == CHANGED) fprintf (outfile, "---\n"); /* Print the lines that the second file has. */ if (changes & NEW) for (i = first1; i <= last1; i++) print_1_line (">", &files[1].linbuf[i]); }
static void print_rcs_hunk (struct change *hunk) { lin i, f0, l0, f1, l1; long int tf0, tl0, tf1, tl1; /* Determine range of line numbers involved in each file. */ enum changes changes = analyze_hunk (hunk, &f0, &l0, &f1, &l1); if (!changes) return; begin_output (); translate_range (&files[0], f0, l0, &tf0, &tl0); if (changes & OLD) { /* For deletion, print just the starting line number from file 0 and the number of lines deleted. */ fprintf (outfile, "d%ld %ld\n", tf0, tf0 <= tl0 ? tl0 - tf0 + 1 : 1); } if (changes & NEW) { /* Take last-line-number from file 0 and # lines from file 1. */ translate_range (&files[1], f1, l1, &tf1, &tl1); fprintf (outfile, "a%ld %ld\n", tl0, tf1 <= tl1 ? tl1 - tf1 + 1 : 1); /* Print the inserted lines. */ for (i = f1; i <= l1; i++) print_1_line ("", &files[1].linbuf[i]); } }
static void pr_forward_ed_hunk (struct change *hunk) { lin i, f0, l0, f1, l1; /* Determine range of line numbers involved in each file. */ enum changes changes = analyze_hunk (hunk, &f0, &l0, &f1, &l1); if (!changes) return; begin_output (); fputc (change_letter[changes], outfile); print_number_range (' ', files, f0, l0); fputc ('\n', outfile); /* If deletion only, print just the number range. */ if (changes == OLD) return; /* For insertion (with or without deletion), print the number range and the lines from file 2. */ for (i = f1; i <= l1; i++) print_1_line ("", &files[1].linbuf[i]); fputs (".\n", outfile); }
static void print_ed_hunk (struct change *hunk) { lin f0, l0, f1, l1; enum changes changes; #ifdef DEBUG debug_script (hunk); #endif /* Determine range of line numbers involved in each file. */ changes = analyze_hunk (hunk, &f0, &l0, &f1, &l1); if (!changes) return; begin_output (); /* Print out the line number header for this hunk */ print_number_range (',', &files[0], f0, l0); fputc (change_letter[changes], outfile); fputc ('\n', outfile); /* Print new/changed lines from second file, if needed */ if (changes != OLD) { lin i; bool insert_mode = true; for (i = f1; i <= l1; i++) { if (!insert_mode) { fputs ("a\n", outfile); insert_mode = true; } if (files[1].linbuf[i][0] == '.' && files[1].linbuf[i][1] == '\n') { /* The file's line is just a dot, and it would exit insert mode. Precede the dot with another dot, exit insert mode and remove the extra dot. */ fputs ("..\n.\ns/.//\n", outfile); insert_mode = false; } else print_1_line ("", &files[1].linbuf[i]); } if (insert_mode) fputs (".\n", outfile); } }
static void pr_unidiff_hunk (struct change *hunk) { lin first0, last0, first1, last1; lin i, j, k; struct change *next; char const *function; FILE *out; /* Determine range of line numbers involved in each file. */ if (! analyze_hunk (hunk, &first0, &last0, &first1, &last1)) return; /* Include a context's width before and after. */ i = - files[0].prefix_lines; first0 = MAX (first0 - context, i); first1 = MAX (first1 - context, i); if (last0 < files[0].valid_lines - context) last0 += context; else last0 = files[0].valid_lines - 1; if (last1 < files[1].valid_lines - context) last1 += context; else last1 = files[1].valid_lines - 1; /* If desired, find the preceding function definition line in file 0. */ function = NULL; if (function_regexp.fastmap) function = find_function (files[0].linbuf, first0); begin_output (); out = outfile; set_color_context (LINE_NUMBER_CONTEXT); fputs ("@@ -", out); print_unidiff_number_range (&files[0], first0, last0); fputs (" +", out); print_unidiff_number_range (&files[1], first1, last1); fputs (" @@", out); set_color_context (RESET_CONTEXT); if (function) print_context_function (out, function); putc ('\n', out); next = hunk; i = first0; j = first1; while (i <= last0 || j <= last1) { /* If the line isn't a difference, output the context from file 0. */ if (!next || i < next->line0) { char const *const *line = &files[0].linbuf[i++]; if (! (suppress_blank_empty && **line == '\n')) putc (initial_tab ? '\t' : ' ', out); print_1_line (NULL, line); j++; } else { /* For each difference, first output the deleted part. */ k = next->deleted; if (k) set_color_context (DELETE_CONTEXT); while (k--) { char const * const *line = &files[0].linbuf[i++]; putc ('-', out); if (initial_tab && ! (suppress_blank_empty && **line == '\n')) putc ('\t', out); print_1_line_nl (NULL, line, true); if (!k) set_color_context (RESET_CONTEXT); if (line[1][-1] == '\n') putc ('\n', out); } /* Then output the inserted part. */ k = next->inserted; if (k) set_color_context (ADD_CONTEXT); while (k--) { char const * const *line = &files[1].linbuf[j++]; putc ('+', out); if (initial_tab && ! (suppress_blank_empty && **line == '\n')) putc ('\t', out); print_1_line_nl (NULL, line, true); if (!k) set_color_context (RESET_CONTEXT); if (line[1][-1] == '\n') putc ('\n', out); } /* We're done with this hunk, so on to the next! */ next = next->link; } } }
static void pr_unidiff_hunk (struct change *hunk) { lin first0, last0, first1, last1; lin i, j, k; struct change *next; char const *function; FILE *out; /* Determine range of line numbers involved in each file. */ if (! analyze_hunk (hunk, &first0, &last0, &first1, &last1)) return; /* Include a context's width before and after. */ i = - files[0].prefix_lines; first0 = MAX (first0 - context, i); first1 = MAX (first1 - context, i); if (last0 < files[0].valid_lines - context) last0 += context; else last0 = files[0].valid_lines - 1; if (last1 < files[1].valid_lines - context) last1 += context; else last1 = files[1].valid_lines - 1; /* If desired, find the preceding function definition line in file 0. */ function = 0; if (function_regexp.fastmap) function = find_function (files[0].linbuf, first0); begin_output (); out = outfile; fprintf (out, "@@ -"); print_unidiff_number_range (&files[0], first0, last0); fprintf (out, " +"); print_unidiff_number_range (&files[1], first1, last1); fprintf (out, " @@"); if (function) print_context_function (out, function); putc ('\n', out); next = hunk; i = first0; j = first1; while (i <= last0 || j <= last1) { /* If the line isn't a difference, output the context from file 0. */ if (!next || i < next->line0) { putc (initial_tab ? '\t' : ' ', out); print_1_line (0, &files[0].linbuf[i++]); j++; } else { /* For each difference, first output the deleted part. */ k = next->deleted; while (k--) { putc ('-', out); if (initial_tab) putc ('\t', out); print_1_line (0, &files[0].linbuf[i++]); } /* Then output the inserted part. */ k = next->inserted; while (k--) { putc ('+', out); if (initial_tab) putc ('\t', out); print_1_line (0, &files[1].linbuf[j++]); } /* We're done with this hunk, so on to the next! */ next = next->link; } } }
static void pr_context_hunk (struct change *hunk) { lin first0, last0, first1, last1, i; char const *prefix; char const *function; FILE *out; /* Determine range of line numbers involved in each file. */ enum changes changes = analyze_hunk (hunk, &first0, &last0, &first1, &last1); if (! changes) return; /* Include a context's width before and after. */ i = - files[0].prefix_lines; first0 = MAX (first0 - context, i); first1 = MAX (first1 - context, i); if (last0 < files[0].valid_lines - context) last0 += context; else last0 = files[0].valid_lines - 1; if (last1 < files[1].valid_lines - context) last1 += context; else last1 = files[1].valid_lines - 1; /* If desired, find the preceding function definition line in file 0. */ function = 0; if (function_regexp.fastmap) function = find_function (files[0].linbuf, first0); begin_output (); out = outfile; fprintf (out, "***************"); if (function) print_context_function (out, function); fprintf (out, "\n*** "); print_context_number_range (&files[0], first0, last0); fprintf (out, " ****\n"); if (changes & OLD) { struct change *next = hunk; for (i = first0; i <= last0; i++) { /* Skip past changes that apply (in file 0) only to lines before line I. */ while (next && next->line0 + next->deleted <= i) next = next->link; /* Compute the marking for line I. */ prefix = " "; if (next && next->line0 <= i) /* The change NEXT covers this line. If lines were inserted here in file 1, this is "changed". Otherwise it is "deleted". */ prefix = (next->inserted > 0 ? "!" : "-"); print_1_line (prefix, &files[0].linbuf[i]); } } fprintf (out, "--- "); print_context_number_range (&files[1], first1, last1); fprintf (out, " ----\n"); if (changes & NEW) { struct change *next = hunk; for (i = first1; i <= last1; i++) { /* Skip past changes that apply (in file 1) only to lines before line I. */ while (next && next->line1 + next->inserted <= i) next = next->link; /* Compute the marking for line I. */ prefix = " "; if (next && next->line1 <= i) /* The change NEXT covers this line. If lines were deleted here in file 0, this is "changed". Otherwise it is "inserted". */ prefix = (next->deleted > 0 ? "!" : "+"); print_1_line (prefix, &files[1].linbuf[i]); } } }