mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-25 05:41:20 +00:00
[ruamoko] Move some string functions
sprintf, vsprintf and strlen now in rua_strings, and strlen now returns int like it should.
This commit is contained in:
parent
c945c42989
commit
0ad9f559ea
13 changed files with 76 additions and 72 deletions
|
@ -521,18 +521,6 @@ PF_vtos (progs_t *pr)
|
|||
RETURN_STRING (pr, string);
|
||||
}
|
||||
|
||||
/*
|
||||
float (string s) strlen
|
||||
*/
|
||||
static void
|
||||
PF_strlen (progs_t *pr)
|
||||
{
|
||||
const char *s;
|
||||
|
||||
s = P_GSTRING (pr, 0);
|
||||
R_FLOAT (pr) = strlen(s);
|
||||
}
|
||||
|
||||
/*
|
||||
float (string char, string s) charcount
|
||||
*/
|
||||
|
@ -565,43 +553,6 @@ PF_charcount (progs_t *pr)
|
|||
# define INT_WIDTH 20
|
||||
#endif
|
||||
|
||||
#define MAX_ARG 7
|
||||
/*
|
||||
string (...) sprintf
|
||||
*/
|
||||
static void
|
||||
PF_sprintf (progs_t *pr)
|
||||
{
|
||||
const char *fmt = P_GSTRING (pr, 0);
|
||||
int count = pr->pr_argc - 1;
|
||||
pr_type_t **args = pr->pr_params + 1;
|
||||
dstring_t *dstr;
|
||||
|
||||
dstr = dstring_newstr ();
|
||||
PR_Sprintf (pr, dstr, "PF_sprintf", fmt, count, args);
|
||||
RETURN_STRING (pr, dstr->str);
|
||||
dstring_delete (dstr);
|
||||
}
|
||||
|
||||
static void
|
||||
PF_vsprintf (progs_t *pr)
|
||||
{
|
||||
const char *fmt = P_GSTRING (pr, 0);
|
||||
__auto_type args = &P_PACKED (pr, pr_va_list_t, 1);
|
||||
pr_type_t *list_start = PR_GetPointer (pr, args->list);
|
||||
pr_type_t **list = alloca (args->count * sizeof (*list));
|
||||
dstring_t *dstr;
|
||||
|
||||
for (int i = 0; i < args->count; i++) {
|
||||
list[i] = list_start + i * pr->pr_param_size;
|
||||
}
|
||||
|
||||
dstr = dstring_newstr ();
|
||||
PR_Sprintf (pr, dstr, "PF_vsprintf", fmt, args->count, list);
|
||||
RETURN_STRING (pr, dstr->str);
|
||||
dstring_delete (dstr);
|
||||
}
|
||||
|
||||
/*
|
||||
string () gametype
|
||||
*/
|
||||
|
@ -659,10 +610,7 @@ static builtin_t builtins[] = {
|
|||
{"stof", PF_stof, 81},
|
||||
|
||||
|
||||
{"strlen", PF_strlen, QF 100},
|
||||
{"charcount", PF_charcount, QF 101},
|
||||
{"sprintf", PF_sprintf, QF 109},
|
||||
{"vsprintf", PF_vsprintf, -1},
|
||||
{"ftoi", PF_ftoi, QF 110},
|
||||
{"itof", PF_itof, QF 111},
|
||||
{"itos", PF_itos, QF 112},
|
||||
|
|
|
@ -50,6 +50,48 @@
|
|||
|
||||
#include "rua_internal.h"
|
||||
|
||||
static void
|
||||
bi_strlen (progs_t *pr)
|
||||
{
|
||||
const char *s;
|
||||
|
||||
s = P_GSTRING (pr, 0);
|
||||
R_INT (pr) = strlen(s);
|
||||
}
|
||||
|
||||
static void
|
||||
bi_sprintf (progs_t *pr)
|
||||
{
|
||||
const char *fmt = P_GSTRING (pr, 0);
|
||||
int count = pr->pr_argc - 1;
|
||||
pr_type_t **args = pr->pr_params + 1;
|
||||
dstring_t *dstr;
|
||||
|
||||
dstr = dstring_newstr ();
|
||||
PR_Sprintf (pr, dstr, "bi_sprintf", fmt, count, args);
|
||||
RETURN_STRING (pr, dstr->str);
|
||||
dstring_delete (dstr);
|
||||
}
|
||||
|
||||
static void
|
||||
bi_vsprintf (progs_t *pr)
|
||||
{
|
||||
const char *fmt = P_GSTRING (pr, 0);
|
||||
__auto_type args = &P_PACKED (pr, pr_va_list_t, 1);
|
||||
pr_type_t *list_start = PR_GetPointer (pr, args->list);
|
||||
pr_type_t **list = alloca (args->count * sizeof (*list));
|
||||
dstring_t *dstr;
|
||||
|
||||
for (int i = 0; i < args->count; i++) {
|
||||
list[i] = list_start + i * pr->pr_param_size;
|
||||
}
|
||||
|
||||
dstr = dstring_newstr ();
|
||||
PR_Sprintf (pr, dstr, "bi_vsprintf", fmt, args->count, list);
|
||||
RETURN_STRING (pr, dstr->str);
|
||||
dstring_delete (dstr);
|
||||
}
|
||||
|
||||
static void
|
||||
bi_str_new (progs_t *pr)
|
||||
{
|
||||
|
@ -147,6 +189,9 @@ bi_str_char (progs_t *pr)
|
|||
}
|
||||
|
||||
static builtin_t builtins[] = {
|
||||
{"strlen", bi_strlen, -1},
|
||||
{"sprintf", bi_sprintf, -1},
|
||||
{"vsprintf", bi_vsprintf, -1},
|
||||
{"str_new", bi_str_new, -1},
|
||||
{"str_free", bi_str_free, -1},
|
||||
{"str_copy", bi_str_copy, -1},
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "key.h"
|
||||
#include "sound.h"
|
||||
#include "legacy_string.h"
|
||||
#include "string.h"
|
||||
|
||||
#include "gui/Text.h"
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "draw.h"
|
||||
#include "system.h"
|
||||
#include "debug.h"
|
||||
#include "legacy_string.h"
|
||||
#include "string.h"
|
||||
#include "key.h"
|
||||
#include "options_util.h"
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
*/
|
||||
|
||||
#include "debug.h"
|
||||
#include "legacy_string.h"
|
||||
#include "string.h"
|
||||
#include "qfs.h"
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ nobase_pkginclude_HEADERS= \
|
|||
crudefile.h debug.h entities.h infokey.h math.h message.h nq_message.h \
|
||||
physics.h msgbuf.h qfile.h qfs.h qw_message.h qw_physics.h qw_sys.h \
|
||||
server.h sound.h script.h string.h sv_sound.h system.h types.h \
|
||||
legacy_string.h \
|
||||
\
|
||||
draw.h key.h \
|
||||
\
|
||||
|
|
12
ruamoko/include/legacy_string.h
Normal file
12
ruamoko/include/legacy_string.h
Normal file
|
@ -0,0 +1,12 @@
|
|||
#ifndef __ruamoko_legacy_string_h
|
||||
#define __ruamoko_legacy_string_h
|
||||
|
||||
@extern string ftos (float f);
|
||||
@extern string vtos (vector v);
|
||||
@extern float stof (string s);
|
||||
@extern float charcount (string goal, string s);
|
||||
@extern string itos (int i);
|
||||
@extern int stoi (string s);
|
||||
@extern vector stov (string s);
|
||||
|
||||
#endif//__ruamoko_legacy_string_h
|
|
@ -1,17 +1,9 @@
|
|||
#ifndef __ruamoko_string_h
|
||||
#define __ruamoko_string_h
|
||||
|
||||
@extern string ftos (float f);
|
||||
@extern string vtos (vector v);
|
||||
@extern float stof (string s);
|
||||
@extern float strlen (string s);
|
||||
@extern float charcount (string goal, string s);
|
||||
@extern int strlen (string s);
|
||||
@extern string sprintf (string fmt, ...);
|
||||
@extern string vsprintf (string fmt, @va_list args);
|
||||
@extern string itos (int i);
|
||||
@extern int stoi (string s);
|
||||
@extern vector stov (string s);
|
||||
|
||||
@extern string str_new (void);
|
||||
@extern string str_free (string str);
|
||||
@extern string str_copy (string dst, string src);
|
||||
|
|
|
@ -46,7 +46,7 @@ libr_a_AR=$(PAK) -cf
|
|||
include $(libr_a_dep) # am--include-marker
|
||||
r_depfiles_remade += $(libr_a_dep)
|
||||
|
||||
common_src=debug.r system.r
|
||||
common_src=debug.r system.r legacy_string.r
|
||||
server_src= \
|
||||
crudefile.r entities.r infokey.r message.r \
|
||||
physics.r server.r sv_sound.r
|
||||
|
|
9
ruamoko/lib/legacy_string.r
Normal file
9
ruamoko/lib/legacy_string.r
Normal file
|
@ -0,0 +1,9 @@
|
|||
#include <string.h>
|
||||
|
||||
string (float f) ftos = #26;
|
||||
string (vector v) vtos = #27;
|
||||
float (string s) stof = #81;
|
||||
float (string goal, string s) charcount = #0x000f0000 + 101;
|
||||
string (int i) itos = #0x000f0000 + 112;
|
||||
int (string s) stoi = #0x000f0000 + 113;
|
||||
vector (string s) stov = #0x000f0000 + 114;
|
|
@ -1,16 +1,8 @@
|
|||
#include <string.h>
|
||||
|
||||
string (float f) ftos = #26;
|
||||
string (vector v) vtos = #27;
|
||||
float (string s) stof = #81;
|
||||
float (string s) strlen = #0x000f0000 + 100;
|
||||
float (string goal, string s) charcount = #0x000f0000 + 101;
|
||||
string (string fmt, ...) sprintf = #0x000f0000 + 109;
|
||||
int (string s) strlen = #0;
|
||||
string (string fmt, ...) sprintf = #0;
|
||||
string vsprintf (string fmt, @va_list args) = #0;
|
||||
string (int i) itos = #0x000f0000 + 112;
|
||||
int (string s) stoi = #0x000f0000 + 113;
|
||||
vector (string s) stov = #0x000f0000 + 114;
|
||||
|
||||
string (void) str_new = #0;
|
||||
string (string str) str_free = #0;
|
||||
string (string dst, string src) str_copy = #0;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "Lexer.h"
|
||||
#include "Number.h"
|
||||
#include "legacy_string.h"
|
||||
#include "string.h"
|
||||
#include "Boolean.h"
|
||||
#include "Error.h"
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "Number.h"
|
||||
#include "legacy_string.h"
|
||||
#include "string.h"
|
||||
|
||||
@implementation Number
|
||||
|
|
Loading…
Reference in a new issue