From: divverent Date: Wed, 9 Jun 2010 09:58:16 +0000 (+0000) Subject: VM_sprintf(): make %i treat the input as QC integer, as opposed to float. %d of cours... X-Git-Tag: xonotic-v0.1.0preview~230^2~246 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=4d61e95a5205a37ed58f0145ca6cbdadd4d517b9;p=xonotic%2Fdarkplaces.git VM_sprintf(): make %i treat the input as QC integer, as opposed to float. %d of course continues to expect a QC float. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10232 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/dpdefs/dpextensions.qc b/dpdefs/dpextensions.qc index a9448df1..4c57054a 100644 --- a/dpdefs/dpextensions.qc +++ b/dpdefs/dpextensions.qc @@ -963,7 +963,8 @@ string(string format, ...) sprintf = #627; // optional: ., .*, or .*$ for the precision // length modifiers: h for forcing a float, l for forcing an int/entity (by default, %d etc. cast a float to int) // conversions: -// di take a float if no length is specified or h is, and an int/entity if l is specified as length, and cast it to an int +// d takes a float if no length is specified or h is, and an int/entity if l is specified as length, and cast it to an int +// i takes an int/entity if no length is specified or i is, and a float if h is specified as length, and cast it to an int // ouxXc take a float if no length is specified or h is, and an int/entity if l is specified as length, and cast it to an unsigned int // eEfFgG take a float if no length is specified or h is, and an int/entity if l is specified as length, and cast it to a double // s takes a string diff --git a/prvm_cmds.c b/prvm_cmds.c index cb78833c..239e7b3e 100644 --- a/prvm_cmds.c +++ b/prvm_cmds.c @@ -5956,7 +5956,7 @@ void VM_sprintf(void) int width, precision, thisarg, flags; char formatbuf[16]; char *f; - qboolean isfloat; + int isfloat; static int dummyivec[3] = {0, 0, 0}; static float dummyvec[3] = {0, 0, 0}; @@ -5996,6 +5996,7 @@ void VM_sprintf(void) precision = -1; thisarg = -1; flags = 0; + isfloat = -1; // is number following? if(*s >= '0' && *s <= '9') @@ -6118,14 +6119,13 @@ noflags: } } - isfloat = true; for(;;) { switch(*s) { - case 'h': isfloat = true; break; - case 'l': isfloat = false; break; - case 'L': isfloat = false; break; + case 'h': isfloat = 1; break; + case 'l': isfloat = 0; break; + case 'L': isfloat = 0; break; case 'j': break; case 'z': break; case 't': break; @@ -6136,6 +6136,15 @@ noflags: } nolength: + // now s points to the final directive char and is no longer changed + if(isfloat < 0) + { + if(*s == 'i') + isfloat = 0; + else + isfloat = 1; + } + if(thisarg < 0) thisarg = argpos++;