From bd3ce6ba057962a8cd4dd002312e91a6347d847b Mon Sep 17 00:00:00 2001 From: divverent Date: Fri, 26 Mar 2010 11:42:05 +0000 Subject: [PATCH] new %v conversion in sprintf (uses %g conversions to build a vector) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10060 d7cf8633-e32d-0410-b094-e92efae38249 --- prvm_cmds.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/prvm_cmds.c b/prvm_cmds.c index 52bb52f2..1453d680 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -5723,6 +5723,9 @@ void VM_sprintf(void) char formatbuf[16]; char *f; qboolean isfloat; + static int dummyivec[3] = {0, 0, 0}; + static float dummyvec[3] = {0, 0, 0}; + #define PRINTF_ALTERNATE 1 #define PRINTF_ZEROPAD 2 #define PRINTF_LEFT 4 @@ -5734,7 +5737,9 @@ void VM_sprintf(void) s = PRVM_G_STRING(OFS_PARM0); #define GETARG_FLOAT(a) (((a)>=1 && (a)argc) ? (PRVM_G_FLOAT(OFS_PARM0 + 3 * (a))) : 0) +#define GETARG_VECTOR(a) (((a)>=1 && (a)argc) ? (PRVM_G_VECTOR(OFS_PARM0 + 3 * (a))) : dummyvec) #define GETARG_INT(a) (((a)>=1 && (a)argc) ? (PRVM_G_INT(OFS_PARM0 + 3 * (a))) : 0) +#define GETARG_INTVECTOR(a) (((a)>=1 && (a)argc) ? ((int*) PRVM_G_VECTOR(OFS_PARM0 + 3 * (a))) : dummyivec) #define GETARG_STRING(a) (((a)>=1 && (a)argc) ? (PRVM_G_STRING(OFS_PARM0 + 3 * (a))) : "") for(;;) @@ -5935,6 +5940,16 @@ nolength: precision = 6; o += dpsnprintf(o, end - o, formatbuf, width, precision, (isfloat ? (double) GETARG_FLOAT(thisarg) : (double) GETARG_INT(thisarg))); break; + case 'v': case 'V': + f[-2] += 'g' - 'v'; + if(precision < 0) // not set + precision = 6; + o += dpsnprintf(o, end - o, va("%s %s %s", /* NESTED SPRINTF IS NESTED */ formatbuf, formatbuf, formatbuf), + width, precision, (isfloat ? (double) GETARG_VECTOR(thisarg)[0] : (double) GETARG_INTVECTOR(thisarg)[0]), + width, precision, (isfloat ? (double) GETARG_VECTOR(thisarg)[1] : (double) GETARG_INTVECTOR(thisarg)[1]), + width, precision, (isfloat ? (double) GETARG_VECTOR(thisarg)[2] : (double) GETARG_INTVECTOR(thisarg)[2]) + ); + break; case 'c': if(precision < 0) // not set precision = end - o - 1; -- 2.39.2