[ruamoko] Make RUA_Sprintf more generally useful

It now takes the function name to print in error message (passed on to
PR_Sprintf) and the argument number of the format string. The variable
arguments (in ...) are assumed to be immediately after the format
argument.
This commit is contained in:
Bill Currie 2022-02-05 20:24:17 +09:00
parent f4b81d30b0
commit c10b09d41b
4 changed files with 12 additions and 10 deletions

View file

@ -52,7 +52,9 @@ void RUA_String_Init (struct progs_s *pr, int secure);
void RUA_QFile_Init (struct progs_s *pr, int secure);
void RUA_QFS_Init (struct progs_s *pr, int secure);
void RUA_Sprintf (struct progs_s *pr, struct dstring_s *dstr);
// the variable args are assumed to come immediately after fmt_arg
void RUA_Sprintf (struct progs_s *pr, struct dstring_s *dstr, const char *func,
int fmt_arg);
int QFile_AllocHandle (struct progs_s *pr, QFile *file);
QFile *QFile_GetFile (struct progs_s *pr, int handle);

View file

@ -61,14 +61,14 @@ bi_strlen (progs_t *pr)
}
void
RUA_Sprintf (progs_t *pr, dstring_t *dstr)
RUA_Sprintf (progs_t *pr, dstring_t *dstr, const char *func, int fmt_arg)
{
const char *fmt = P_GSTRING (pr, 0);
int count = pr->pr_argc - 1;
pr_type_t **args = pr->pr_params + 1;
const char *fmt = P_GSTRING (pr, fmt_arg);
int count = pr->pr_argc - (fmt_arg + 1);
pr_type_t **args = pr->pr_params + (fmt_arg + 1);
if (pr->progs->version == PROG_VERSION) {
__auto_type va_list = &P_PACKED (pr, pr_va_list_t, 1);
__auto_type va_list = &P_PACKED (pr, pr_va_list_t, (fmt_arg + 1));
count = va_list->count;
if (count) {
args = alloca (count * sizeof (pr_type_t *));
@ -80,7 +80,7 @@ RUA_Sprintf (progs_t *pr, dstring_t *dstr)
}
}
PR_Sprintf (pr, dstr, "bi_sprintf", fmt, count, args);
PR_Sprintf (pr, dstr, func, fmt, count, args);
}
static void
@ -89,7 +89,7 @@ bi_sprintf (progs_t *pr)
dstring_t *dstr;
dstr = dstring_newstr ();
RUA_Sprintf (pr, dstr);
RUA_Sprintf (pr, dstr, "sprintf", 0);
RETURN_STRING (pr, dstr->str);
dstring_delete (dstr);
}

View file

@ -150,7 +150,7 @@ bi_printf (progs_t *pr)
{
dstring_t *dstr = dstring_new ();
RUA_Sprintf (pr, dstr);
RUA_Sprintf (pr, dstr, "printf", 0);
if (dstr->str) {
Sys_Printf ("%s", dstr->str);
}

View file

@ -54,7 +54,7 @@ bi_printf (progs_t *pr)
dstring_clear (dstr);
}
RUA_Sprintf (pr, dstr);
RUA_Sprintf (pr, dstr, "printf", 0);
if (dstr->str) {
fputs (dstr->str, stdout);