diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 1992-09-30 09:21:59 +0000 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 1992-09-30 09:21:59 +0000 |
commit | b98227d8eb71c53f9d3e12537e8410ebde0bf86e (patch) | |
tree | a4bdb525bba832e87b4ef0f4210dbe7060a27278 /src/ifdef.c | |
parent | 0bc4206adad21d679d7cadb7a578402b0e2b0a0a (diff) | |
download | diffutils-b98227d8eb71c53f9d3e12537e8410ebde0bf86e.tar.gz |
entered into RCS
Diffstat (limited to 'src/ifdef.c')
-rw-r--r-- | src/ifdef.c | 45 |
1 files changed, 23 insertions, 22 deletions
diff --git a/src/ifdef.c b/src/ifdef.c index 5ac124a..c5dde5c 100644 --- a/src/ifdef.c +++ b/src/ifdef.c @@ -39,7 +39,8 @@ print_ifdef_script (script) if (next_line < files[0].valid_lines) { begin_output (); - format_ifdef (common_format, next_line, files[0].valid_lines, 0, -1); + format_ifdef (group_format[UNCHANGED], next_line, files[0].valid_lines, + 0, -1); } } @@ -57,9 +58,9 @@ print_ifdef_hunk (hunk) /* Determine range of line numbers involved in each file. */ analyze_hunk (hunk, &first0, &last0, &first1, &last1, &deletes, &inserts); if (inserts) - format = deletes ? ifnelse_format : ifdef_format; + format = deletes ? group_format[CHANGED] : group_format[NEW]; else if (deletes) - format = ifndef_format; + format = group_format[OLD]; else return; @@ -67,7 +68,7 @@ print_ifdef_hunk (hunk) /* Print lines up to this change. */ if (next_line < first0) - format_ifdef (common_format, next_line, first0, 0, -1); + format_ifdef (group_format[UNCHANGED], next_line, first0, 0, -1); /* Print this change. */ next_line = last0 + 1; @@ -98,30 +99,26 @@ format_ifdef (format, beg0, end0, beg1, end1) case '<': /* Print lines deleted from first file. */ - print_ifdef_lines (line_format[0], &files[0], beg0, end0); + print_ifdef_lines (line_format[OLD], &files[0], beg0, end0); continue; case '=': /* Print common lines. */ - print_ifdef_lines (line_format[2], &files[0], beg0, end0); + print_ifdef_lines (line_format[UNCHANGED], &files[0], beg0, end0); continue; case '>': /* Print lines inserted from second file. */ if (end1 == -1) - print_ifdef_lines (line_format[1], &files[0], beg0, end0); + print_ifdef_lines (line_format[NEW], &files[0], beg0, end0); else - print_ifdef_lines (line_format[1], &files[1], beg1, end1); + print_ifdef_lines (line_format[NEW], &files[1], beg1, end1); continue; case '0': c = 0; break; - case 'n': - c = '\n'; - break; - default: break; } @@ -129,8 +126,6 @@ format_ifdef (format, beg0, end0, beg1, end1) } } -const char default_line_format[] = "%l%n"; - /* Use FORMAT to print each line of CURRENT starting with FROM and continuing up to UPTO. */ static void @@ -142,8 +137,12 @@ print_ifdef_lines (format, current, from, upto) const char * const *linbuf = current->linbuf; /* If possible, use a single fwrite; it's faster. */ - if (format == default_line_format && !tab_expand_flag) - fwrite (linbuf[from], sizeof (char), linbuf[upto] - linbuf[from], outfile); + if (!tab_expand_flag && strcmp (format, "%l\n") == 0) + fwrite (linbuf[from], sizeof (char), + linbuf[upto] + (linbuf[upto][-1] != '\n') - linbuf[from], + outfile); + else if (!tab_expand_flag && strcmp (format, "%L") == 0) + fwrite (linbuf[from], sizeof (char), linbuf[upto] - linbuf[from], outfile); else for (; from < upto; from++) { @@ -158,19 +157,21 @@ print_ifdef_lines (format, current, from, upto) { case 0: goto format_done; - + case 'l': - output_1_line (linbuf[from], linbuf[from + 1] - 1, 0, 0); + output_1_line (linbuf[from], + linbuf[from + 1] + - (linbuf[from + 1][-1] == '\n'), 0, 0); + continue; + + case 'L': + output_1_line (linbuf[from], linbuf[from + 1], 0, 0); continue; case '0': c = 0; break; - case 'n': - c = '\n'; - break; - default: break; } |