1 /****************************************************************************************/
\r
4 /* Author: Jim Mischel */
\r
5 /* Description: Various useful utility functions. */
\r
7 /* The contents of this file are subject to the Genesis3D Public License */
\r
8 /* Version 1.01 (the "License"); you may not use this file except in */
\r
9 /* compliance with the License. You may obtain a copy of the License at */
\r
10 /* http://www.genesis3d.com */
\r
12 /* Software distributed under the License is distributed on an "AS IS" */
\r
13 /* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See */
\r
14 /* the License for the specific language governing rights and limitations */
\r
15 /* under the License. */
\r
17 /* The Original Code is Genesis3D, released March 25, 1999. */
\r
18 /*Genesis3D Version 1.1 released November 15, 1999 */
\r
19 /* Copyright (C) 1999 WildTangent, Inc. All Rights Reserved */
\r
21 /****************************************************************************************/
\r
30 char *Util_Strdup (const char *s)
\r
36 rslt = geRam_Allocate (strlen (s) + 1);
\r
44 geBoolean Util_SetString (char **ppString, const char *NewValue)
\r
48 if (NewValue == NULL)
\r
54 pNewString = Util_Strdup (NewValue);
\r
55 if (pNewString == NULL)
\r
60 if (*ppString != NULL)
\r
62 geRam_Free (*ppString);
\r
64 *ppString = pNewString;
\r
70 geBoolean Util_IsValidInt
\r
76 // no overflow checking here...
\r
77 // also no hex numbers supported yet...
\r
96 while (isdigit (*c))
\r
105 *TheVal = sign * val;
\r
114 geBoolean Util_IsValidFloat
\r
133 else if (*c == '+')
\r
138 while (isdigit (*c))
\r
140 num = (num * 10) + (*c - '0');
\r
150 while (isdigit (*c))
\r
152 num += ((geFloat)(*c - '0'))/div;
\r
169 unsigned int Util_htoi (const char *s)
\r
171 unsigned int hexValue;
\r
175 if ((s[0] == '0') && ((s[1] == 'x') || (s[1] == 'X')))
\r
178 while (isxdigit (*c))
\r
180 // I know there's a faster way, I just don't remember
\r
183 if ((*c >= '0') && (*c <= '9'))
\r
185 hexValue += (*c - '0');
\r
187 else if ((*c >= 'A') && (*c <= 'F'))
\r
189 hexValue += (*c - 'A') + 10;
\r
193 hexValue += (*c - 'a') + 10;
\r
201 void Util_QuoteString (const char *s, char *d)
\r
203 unsigned int dest, src;
\r
208 for (src = 0; src < strlen (s); ++src)
\r
213 // need to escape quotes and backslashes
\r
214 if ((c == '"') || (c == '\\'))
\r
226 geBoolean Util_GetEndStringValue
\r
236 geBoolean bValueFound = GE_FALSE ;
\r
238 assert (psz != NULL);
\r
239 assert (pVal != NULL);
\r
240 assert (pLastChar != NULL);
\r
245 while( (i > 0) && (isdigit (psz[i-1])) )
\r
250 Num += ((c - '0') * Power);
\r
253 bValueFound = GE_TRUE ;
\r
262 return bValueFound ;
\r
265 geBoolean Util_FileExists (const char *Filename)
\r
267 return (_access (Filename, 0) == 0) ? GE_TRUE : GE_FALSE;
\r