diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2006-05-07 08:16:19 +0000 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2006-05-07 08:16:19 +0000 |
commit | 96e1fbe4c727ac843a4760859148378c22d52b66 (patch) | |
tree | 31e13d571beeca7bb8f92debbcc0988fc427e302 | |
parent | e0842123160e781efcc0ddbf854dae53b7f674e2 (diff) | |
download | diffutils-96e1fbe4c727ac843a4760859148378c22d52b66.tar.gz |
* src/context.c (pr_context_hunk, pr_unidiff_hunk):
Prefer fputs or fputc to fprintf, since it's a tad more efficient
with unlocked-IO on glibc. Long ago we avoided fputs to
work around an ancient SunOS bug, but that's no longer relevant.
* src/diff3.c (output_diff3, dotlines, undotlines):
(output_diff3_edscript, output_diff3_merge): Likewise.
This also avoids a gcc -Wformat-security warning reported
by Jim Meyering.
* src/ed.c (print_ed_hunk, print_forward_ed_hunk, print_rcs_hunk):
Likewise.
* src/normal.c (print_normal_hunk): Likewise.
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | src/context.c | 16 | ||||
-rw-r--r-- | src/diff3.c | 15 | ||||
-rw-r--r-- | src/ed.c | 26 | ||||
-rw-r--r-- | src/normal.c | 10 |
5 files changed, 47 insertions, 34 deletions
@@ -1,3 +1,17 @@ +2006-05-07 Paul Eggert <eggert@cs.ucla.edu> + + * src/context.c (pr_context_hunk, pr_unidiff_hunk): + Prefer fputs or fputc to fprintf, since it's a tad more efficient + with unlocked-IO on glibc. Long ago we avoided fputs to + work around an ancient SunOS bug, but that's no longer relevant. + * src/diff3.c (output_diff3, dotlines, undotlines): + (output_diff3_edscript, output_diff3_merge): Likewise. + This also avoids a gcc -Wformat-security warning reported + by Jim Meyering. + * src/ed.c (print_ed_hunk, print_forward_ed_hunk, print_rcs_hunk): + Likewise. + * src/normal.c (print_normal_hunk): Likewise. + 2006-05-06 Paul Eggert <eggert@cs.ucla.edu> * src/io.c (find_identical_ends): Fix huge performance bug that I diff --git a/src/context.c b/src/context.c index 317c360..435930b 100644 --- a/src/context.c +++ b/src/context.c @@ -183,14 +183,14 @@ pr_context_hunk (struct change *hunk) begin_output (); out = outfile; - fprintf (out, "***************"); + fputs ("***************", out); if (function) print_context_function (out, function); - fprintf (out, "\n*** "); + fputs ("\n*** ", out); print_context_number_range (&files[0], first0, last0); - fprintf (out, " ****\n"); + fputs (" ****\n", out); if (changes & OLD) { @@ -217,9 +217,9 @@ pr_context_hunk (struct change *hunk) } } - fprintf (out, "--- "); + fputs ("--- ", out); print_context_number_range (&files[1], first1, last1); - fprintf (out, " ----\n"); + fputs (" ----\n", out); if (changes & NEW) { @@ -313,11 +313,11 @@ pr_unidiff_hunk (struct change *hunk) begin_output (); out = outfile; - fprintf (out, "@@ -"); + fputs ("@@ -", out); print_unidiff_number_range (&files[0], first0, last0); - fprintf (out, " +"); + fputs (" +", out); print_unidiff_number_range (&files[1], first1, last1); - fprintf (out, " @@"); + fputs (" @@", out); if (function) print_context_function (out, function); diff --git a/src/diff3.c b/src/diff3.c index e1c3b30..9609786 100644 --- a/src/diff3.c +++ b/src/diff3.c @@ -1406,7 +1406,7 @@ output_diff3 (FILE *outputfile, struct diff3_block *diff, line = 0; do { - fprintf (outputfile, line_prefix); + fputs (line_prefix, outputfile); cp = D_RELNUM (ptr, realfile, line); length = D_RELLEN (ptr, realfile, line); fwrite (cp, sizeof (char), length, outputfile); @@ -1438,7 +1438,7 @@ dotlines (FILE *outputfile, struct diff3_block *b, int filenum) if (line[0] == '.') { leading_dot = true; - fprintf (outputfile, "."); + fputc ('.', outputfile); } fwrite (line, sizeof (char), D_RELLEN (b, filenum, i), outputfile); @@ -1455,7 +1455,7 @@ dotlines (FILE *outputfile, struct diff3_block *b, int filenum) static void undotlines (FILE *outputfile, bool leading_dot, long int start, lin num) { - fprintf (outputfile, ".\n"); + fputs (".\n", outputfile); if (leading_dot) { if (num == 1) @@ -1534,7 +1534,7 @@ output_diff3_edscript (FILE *outputfile, struct diff3_block *diff, leading_dot = dotlines (outputfile, b, mapping[FILE1]); } /* Append lines from FILE2. */ - fprintf (outputfile, "=======\n"); + fputs ("=======\n", outputfile); leading_dot |= dotlines (outputfile, b, mapping[FILE2]); } fprintf (outputfile, ">>>>>>> %s\n", file2); @@ -1552,7 +1552,7 @@ output_diff3_edscript (FILE *outputfile, struct diff3_block *diff, { /* Prepend lines from FILE1. */ leading_dot = dotlines (outputfile, b, mapping[FILE1]); - fprintf (outputfile, "=======\n"); + fputs ("=======\n", outputfile); } undotlines (outputfile, leading_dot, low0 + 1, D_NUMLINES (b, mapping[FILE1])); @@ -1585,7 +1585,8 @@ output_diff3_edscript (FILE *outputfile, struct diff3_block *diff, low0, D_NUMLINES (b, mapping[FILE2])); } } - if (finalwrite) fprintf (outputfile, "w\nq\n"); + if (finalwrite) + fputs ("w\nq\n", outputfile); return conflicts_found; } @@ -1676,7 +1677,7 @@ output_diff3_merge (FILE *infile, FILE *outputfile, struct diff3_block *diff, D_RELLEN (b, mapping[FILE1], i), outputfile); } - fprintf (outputfile, "=======\n"); + fputs ("=======\n", outputfile); } /* Put in lines from FILE2. */ @@ -1,7 +1,7 @@ /* Output routines for ed-script format. - Copyright (C) 1988, 1989, 1991, 1992, 1993, 1995, 1998, 2001, 2004 - Free Software Foundation, Inc. + Copyright (C) 1988, 1989, 1991, 1992, 1993, 1995, 1998, 2001, 2004, + 2006 Free Software Foundation, Inc. This file is part of GNU DIFF. @@ -55,7 +55,8 @@ print_ed_hunk (struct change *hunk) /* Print out the line number header for this hunk */ print_number_range (',', &files[0], f0, l0); - fprintf (outfile, "%c\n", change_letter[changes]); + fputc (change_letter[changes], outfile); + fputc ('\n', outfile); /* Print new/changed lines from second file, if needed */ if (changes != OLD) @@ -67,7 +68,7 @@ print_ed_hunk (struct change *hunk) { if (!insert_mode) { - fprintf (outfile, "a\n"); + fputs ("a\n", outfile); insert_mode = true; } if (files[1].linbuf[i][0] == '.' && files[1].linbuf[i][1] == '\n') @@ -75,7 +76,7 @@ print_ed_hunk (struct change *hunk) /* 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. */ - fprintf (outfile, "..\n.\ns/.//\n"); + fputs ("..\n.\ns/.//\n", outfile); insert_mode = false; } else @@ -83,7 +84,7 @@ print_ed_hunk (struct change *hunk) } if (insert_mode) - fprintf (outfile, ".\n"); + fputs (".\n", outfile); } } @@ -111,9 +112,9 @@ pr_forward_ed_hunk (struct change *hunk) begin_output (); - fprintf (outfile, "%c", change_letter[changes]); + fputc (change_letter[changes], outfile); print_number_range (' ', files, f0, l0); - fprintf (outfile, "\n"); + fputc ('\n', outfile); /* If deletion only, print just the number range. */ @@ -126,7 +127,7 @@ pr_forward_ed_hunk (struct change *hunk) for (i = f1; i <= l1; i++) print_1_line ("", &files[1].linbuf[i]); - fprintf (outfile, ".\n"); + fputs (".\n", outfile); } /* Print in a format somewhat like ed commands @@ -158,19 +159,16 @@ print_rcs_hunk (struct change *hunk) if (changes & OLD) { - fprintf (outfile, "d"); /* For deletion, print just the starting line number from file 0 and the number of lines deleted. */ - fprintf (outfile, "%ld %ld\n", tf0, tf0 <= tl0 ? tl0 - tf0 + 1 : 1); + fprintf (outfile, "d%ld %ld\n", tf0, tf0 <= tl0 ? tl0 - tf0 + 1 : 1); } if (changes & NEW) { - fprintf (outfile, "a"); - /* Take last-line-number from file 0 and # lines from file 1. */ translate_range (&files[1], f1, l1, &tf1, &tl1); - fprintf (outfile, "%ld %ld\n", tl0, tf1 <= tl1 ? tl1 - tf1 + 1 : 1); + fprintf (outfile, "a%ld %ld\n", tl0, tf1 <= tl1 ? tl1 - tf1 + 1 : 1); /* Print the inserted lines. */ for (i = f1; i <= l1; i++) diff --git a/src/normal.c b/src/normal.c index fcc6ff4..0f322c9 100644 --- a/src/normal.c +++ b/src/normal.c @@ -1,7 +1,7 @@ /* Normal-format output routines for GNU DIFF. - Copyright (C) 1988, 1989, 1993, 1995, 1998, 2001 Free Software - Foundation, Inc. + Copyright (C) 1988, 1989, 1993, 1995, 1998, 2001, 2006 Free + Software Foundation, Inc. This file is part of GNU DIFF. @@ -52,9 +52,9 @@ print_normal_hunk (struct change *hunk) /* Print out the line number header for this hunk */ print_number_range (',', &files[0], first0, last0); - fprintf (outfile, "%c", change_letter[changes]); + fputc (change_letter[changes], outfile); print_number_range (',', &files[1], first1, last1); - fprintf (outfile, "\n"); + fputc ('\n', outfile); /* Print the lines that the first file has. */ if (changes & OLD) @@ -62,7 +62,7 @@ print_normal_hunk (struct change *hunk) print_1_line ("<", &files[0].linbuf[i]); if (changes == CHANGED) - fprintf (outfile, "---\n"); + fputs ("---\n", outfile); /* Print the lines that the second file has. */ if (changes & NEW) |