+2010-07-11 Ken Raeburn <raeburn@raeburn.org>
+
+ * 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.
+
2010-07-11 Eli Zaretskii <eliz@gnu.org>
* process.c (syms_of_process) <delete-exited-processes>: Define
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.. */
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))
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;
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;
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;
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 */
/* VARARGS 1 */
void
-error (m, a1, a2, a3)
- char *m;
- char *a1, *a2, *a3;
+error (char *m, ...)
{
char buf[200];
int size = 200;
int allocated = 0;
Lisp_Object string;
- args[0] = a1;
- args[1] = a2;
- args[2] = a3;
-
mlen = strlen (m);
while (1)
{
- int used = doprnt (buffer, size, m, m + mlen, 3, args);
+ va_list ap;
+ int used;
+
+ /* A va_list can't be reused if we have to go around the loop
+ again; we need to "reinitialize" it each time. */
+ va_start(ap, m);
+ used = doprnt (buffer, size, m, m + mlen, ap);
+ va_end(ap);
if (used < size)
break;
size *= 2;
#ifndef EMACS_LISP_H
#define EMACS_LISP_H
+#include <stdarg.h>
+
/* Use the configure flag --enable-checking[=LIST] to enable various
types of run time checks for Lisp objects. */
extern Lisp_Object current_message (void);
extern void set_message (const char *s, Lisp_Object, int, int);
extern void clear_message (int, int);
-extern void message (/* char *, ... */);
-extern void message_nolog (/* char *, ... */);
+extern void message (char *, ...);
+extern void message_nolog (char *, ...);
extern void message1 (char *);
extern void message1_nolog (char *);
extern void message2 (const char *, int, int);
extern void syms_of_print (void);
/* Defined in doprnt.c */
-extern int doprnt (char *, int, char *, char *, int, char **);
+extern int doprnt (char *, int, char *, char *, va_list);
/* Defined in lread.c */
extern Lisp_Object Qvariable_documentation, Qstandard_input;
extern void specbind (Lisp_Object, Lisp_Object);
extern void record_unwind_protect (Lisp_Object (*) (Lisp_Object), Lisp_Object);
extern Lisp_Object unbind_to (int, Lisp_Object);
-extern void error (/* char *, ... */) NO_RETURN;
+extern void error (char *, ...) NO_RETURN;
extern void do_autoload (Lisp_Object, Lisp_Object);
extern Lisp_Object un_autoload (Lisp_Object);
EXFUN (Ffetch_bytecode, 1);
/* Dump an informative message to the minibuf. If M is 0, clear out
any existing message, and let the mini-buffer text show through. */
-/* VARARGS 1 */
-void
-message (char *m, EMACS_INT a1, EMACS_INT a2, EMACS_INT a3)
+static void
+vmessage (char *m, va_list ap)
{
if (noninteractive)
{
if (noninteractive_need_newline)
putc ('\n', stderr);
noninteractive_need_newline = 0;
- fprintf (stderr, m, a1, a2, a3);
+ vfprintf (stderr, m, ap);
if (cursor_in_echo_area == 0)
fprintf (stderr, "\n");
fflush (stderr);
if (m)
{
int len;
- char *a[3];
- a[0] = (char *) a1;
- a[1] = (char *) a2;
- a[2] = (char *) a3;
len = doprnt (FRAME_MESSAGE_BUF (f),
- FRAME_MESSAGE_BUF_SIZE (f), m, (char *)0, 3, a);
+ FRAME_MESSAGE_BUF_SIZE (f), m, (char *)0, ap);
message2 (FRAME_MESSAGE_BUF (f), len, 0);
}
}
}
+void
+message (char *m, ...)
+{
+ va_list ap;
+ va_start (ap, m);
+ vmessage (m, ap);
+ va_end (ap);
+}
+
/* The non-logging version of message. */
void
-message_nolog (char *m, EMACS_INT a1, EMACS_INT a2, EMACS_INT a3)
+message_nolog (char *m, ...)
{
Lisp_Object old_log_max;
+ va_list ap;
+ va_start (ap, m);
old_log_max = Vmessage_log_max;
Vmessage_log_max = Qnil;
- message (m, a1, a2, a3);
+ vmessage (m, ap);
Vmessage_log_max = old_log_max;
+ va_end (ap);
}