From d35f226f34ff93bb33aa3866a7ae43ab395c0f46 Mon Sep 17 00:00:00 2001 From: Andrei Drexler Date: Thu, 25 Jun 2009 20:31:08 +0000 Subject: [PATCH] More fixes for negative numbers in ui scripts. --- reaction/ta_ui/ui_shared.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/reaction/ta_ui/ui_shared.c b/reaction/ta_ui/ui_shared.c index 1678ee5f..8c8c50a8 100644 --- a/reaction/ta_ui/ui_shared.c +++ b/reaction/ta_ui/ui_shared.c @@ -485,10 +485,23 @@ Float_Parse qboolean Float_Parse(char **p, float *f) { char *token; + qboolean negative = qfalse; - token = COM_ParseExt(p, qfalse); - if (token && token[0] != 0) { + for ( token = COM_ParseExt(p, qfalse); + token && *token; + token = COM_ParseExt(p, qfalse) ) + { + if (*token != '-') + break; + + negative ^= qtrue; + } + + if (token && token[0] != 0) + { *f = atof(token); + if (negative) + *f = -*f; return qtrue; } else { return qfalse; @@ -582,11 +595,23 @@ Int_Parse qboolean Int_Parse(char **p, int *i) { char *token; + qboolean negative = qfalse; - token = COM_ParseExt(p, qfalse); + for ( token = COM_ParseExt(p, qfalse); + token && *token; + token = COM_ParseExt(p, qfalse) ) + { + if (*token != '-') + break; - if (token && token[0] != 0) { + negative ^= qtrue; + } + + if (token && token[0] != 0) + { *i = atoi(token); + if (negative) + *i = -*i; return qtrue; } else { return qfalse;