diff options
author | Ken Raeburn <raeburn@raeburn.org> | 2010-07-11 02:59:55 -0400 |
---|---|---|
committer | Ken Raeburn <raeburn@raeburn.org> | 2010-07-11 02:59:55 -0400 |
commit | 6a8033e1c6814ab9b0b0265039f91c701f53048d (patch) | |
tree | e6f26804c0fcf2f009e7b3a30c9c6370cae8e436 /src/doprnt.c | |
parent | 994a7c3beb2fb2fe9f98426529fd45f3d47391d6 (diff) | |
download | emacs-6a8033e1c6814ab9b0b0265039f91c701f53048d.tar.gz |
Make doprnt and related functions ANSI C compliant, with prototypes.
* doprnt.c (doprnt): Take a va_list argument instead of count and
pointer.
* eval.c (error): Change to a standard-C variadic function.
* xdisp.c (vmessage): Renamed from message, made static, and
changed to take a va_list argument.
(message): New variadic wrapper.
(message_nolog): Now a variadic function, calling vmessage.
* lisp.h: Include stdarg.h for va_list.
(doprnt, error, message, message_nolog): Decls updated.
Diffstat (limited to 'src/doprnt.c')
-rw-r--r-- | src/doprnt.c | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/src/doprnt.c b/src/doprnt.c index 3ff2f70dd34..1a165145b56 100644 --- a/src/doprnt.c +++ b/src/doprnt.c @@ -59,9 +59,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ Integers are passed as C integers. */ int -doprnt (char *buffer, register int bufsize, char *format, char *format_end, int nargs, char **args) +doprnt (char *buffer, register int bufsize, char *format, char *format_end, va_list ap) { - int cnt = 0; /* Number of arg to gobble next */ register char *fmt = format; /* Pointer into format string */ register char *bufptr = buffer; /* Pointer into output buffer.. */ @@ -161,8 +160,6 @@ doprnt (char *buffer, register int bufsize, char *format, char *format_end, int case 'd': case 'o': case 'x': - if (cnt == nargs) - error ("Not enough arguments for format string"); if (sizeof (int) == sizeof (EMACS_INT)) ; else if (sizeof (long) == sizeof (EMACS_INT)) @@ -173,7 +170,7 @@ doprnt (char *buffer, register int bufsize, char *format, char *format_end, int string++; else abort (); - sprintf (sprintf_buffer, fmtcpy, args[cnt++]); + sprintf (sprintf_buffer, fmtcpy, va_arg(ap, char *)); /* Now copy into final output, truncating as nec. */ string = (unsigned char *) sprintf_buffer; goto doit; @@ -182,12 +179,8 @@ doprnt (char *buffer, register int bufsize, char *format, char *format_end, int case 'e': case 'g': { - union { double d; char *half[2]; } u; - if (cnt + 1 == nargs) - error ("Not enough arguments for format string"); - u.half[0] = args[cnt++]; - u.half[1] = args[cnt++]; - sprintf (sprintf_buffer, fmtcpy, u.d); + double d = va_arg(ap, double); + sprintf (sprintf_buffer, fmtcpy, d); /* Now copy into final output, truncating as nec. */ string = (unsigned char *) sprintf_buffer; goto doit; @@ -196,11 +189,9 @@ doprnt (char *buffer, register int bufsize, char *format, char *format_end, int case 'S': string[-1] = 's'; case 's': - if (cnt == nargs) - error ("Not enough arguments for format string"); if (fmtcpy[1] != 's') minlen = atoi (&fmtcpy[1]); - string = (unsigned char *) args[cnt++]; + string = va_arg(ap, unsigned char *); tem = strlen (string); width = strwidth (string, tem); goto doit1; @@ -250,16 +241,21 @@ doprnt (char *buffer, register int bufsize, char *format, char *format_end, int continue; case 'c': - if (cnt == nargs) - error ("Not enough arguments for format string"); - tem = CHAR_STRING ((int) (EMACS_INT) args[cnt], charbuf); - string = charbuf; - cnt++; - string[tem] = 0; - width = strwidth (string, tem); - if (fmtcpy[1] != 'c') - minlen = atoi (&fmtcpy[1]); - goto doit1; + { + /* Sometimes for %c we pass a char, which would widen + to int. Sometimes we pass XFASTINT() or XINT() + values, which would be EMACS_INT. Let's hope that + both are passed the same way, otherwise we'll need + to rewrite callers. */ + EMACS_INT chr = va_arg(ap, EMACS_INT); + tem = CHAR_STRING ((int) chr, charbuf); + string = charbuf; + string[tem] = 0; + width = strwidth (string, tem); + if (fmtcpy[1] != 'c') + minlen = atoi (&fmtcpy[1]); + goto doit1; + } case '%': fmt--; /* Drop thru and this % will be treated as normal */ |