Commit 6a8033e1 authored by Ken Raeburn's avatar Ken Raeburn

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.
parent 994a7c3b
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
......
......@@ -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 */
......
......@@ -2003,9 +2003,7 @@ find_handler_clause (Lisp_Object handlers, Lisp_Object conditions,
/* VARARGS 1 */
void
error (m, a1, a2, a3)
char *m;
char *a1, *a2, *a3;
error (char *m, ...)
{
char buf[200];
int size = 200;
......@@ -2015,15 +2013,18 @@ error (m, a1, a2, a3)
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;
......
......@@ -21,6 +21,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#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. */
......@@ -2648,8 +2650,8 @@ extern void restore_message (void);
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);
......@@ -2798,7 +2800,7 @@ extern void float_to_string (unsigned char *, double);
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;
......@@ -2910,7 +2912,7 @@ extern Lisp_Object internal_condition_case_n (Lisp_Object (*) (int, Lisp_Object
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);
......
......@@ -8494,9 +8494,8 @@ message_with_string (char *m, Lisp_Object string, int log)
/* 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)
{
......@@ -8505,7 +8504,7 @@ message (char *m, EMACS_INT a1, EMACS_INT a2, EMACS_INT a3)
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);
......@@ -8533,13 +8532,9 @@ message (char *m, EMACS_INT a1, EMACS_INT a2, EMACS_INT a3)
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);
}
......@@ -8553,17 +8548,29 @@ message (char *m, EMACS_INT a1, EMACS_INT a2, EMACS_INT a3)
}
}
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);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment