diff options
author | peter <peter@FreeBSD.org> | 1999-12-11 12:24:21 +0000 |
---|---|---|
committer | peter <peter@FreeBSD.org> | 1999-12-11 12:24:21 +0000 |
commit | b38569ff99f04a0eff4c8387273fafe38bb58c43 (patch) | |
tree | 2ed56a5cb810a4c08d41ea1babfef0e4a2c88b3e /contrib/cvs/diff/util.c | |
parent | 25155fc40f43750917e9621b6e4b57f72e19a29c (diff) | |
parent | 784ea5066cbea73d04e8ce5783dd0eb842e3ac1f (diff) | |
download | FreeBSD-src-b38569ff99f04a0eff4c8387273fafe38bb58c43.zip FreeBSD-src-b38569ff99f04a0eff4c8387273fafe38bb58c43.tar.gz |
This commit was generated by cvs2svn to compensate for changes in r54427,
which included commits to RCS files with non-trunk default branches.
Diffstat (limited to 'contrib/cvs/diff/util.c')
-rw-r--r-- | contrib/cvs/diff/util.c | 56 |
1 files changed, 44 insertions, 12 deletions
diff --git a/contrib/cvs/diff/util.c b/contrib/cvs/diff/util.c index 1b28170..c4d2d71 100644 --- a/contrib/cvs/diff/util.c +++ b/contrib/cvs/diff/util.c @@ -13,13 +13,11 @@ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with GNU DIFF; see the file COPYING. If not, write to -the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ +*/ #include "diff.h" -#ifdef __STDC__ +#if __STDC__ #include <stdarg.h> #else #include <varargs.h> @@ -340,14 +338,14 @@ write_output (text, len) /* Printf something to the output file. */ -#ifdef __STDC__ +#if __STDC__ #define VA_START(args, lastarg) va_start(args, lastarg) #else /* ! __STDC__ */ #define VA_START(args, lastarg) va_start(args) #endif /* __STDC__ */ void -#if defined (__STDC__) +#if __STDC__ printf_output (const char *format, ...) #else printf_output (format, va_alist) @@ -360,17 +358,51 @@ printf_output (format, va_alist) VA_START (args, format); if (callbacks && callbacks->write_output) { - char *p; + /* We implement our own limited printf-like functionality (%s, %d, + and %c only). Callers who want something fancier can use + sprintf. */ + const char *p = format; + char *q; + char *str; + int num; + int ch; + unsigned char buf[100]; + + while ((q = strchr (p, '%')) != NULL) + { + static const char msg[] = + "\ninternal error: bad % in printf_output\n"; + (*callbacks->write_output) (p, q - p); - p = NULL; - vasprintf (&p, format, args); - if (p == NULL) - fatal ("out of memory"); + switch (q[1]) + { + case 's': + str = va_arg (args, char *); + (*callbacks->write_output) (str, strlen (str)); + break; + case 'd': + num = va_arg (args, int); + sprintf (buf, "%d", num); + (*callbacks->write_output) (buf, strlen (buf)); + break; + case 'c': + ch = va_arg (args, int); + buf[0] = ch; + (*callbacks->write_output) (buf, 1); + break; + default: + (*callbacks->write_output) (msg, sizeof (msg) - 1); + /* Don't just keep going, because q + 1 might point to the + terminating '\0'. */ + goto out; + } + p = q + 2; + } (*callbacks->write_output) (p, strlen (p)); - free (p); } else vfprintf (outfile, format, args); + out: va_end (args); } |