2000-01-27 17:06:02 +00:00
|
|
|
/*
|
2000-03-24 12:11:38 +00:00
|
|
|
lib_replace.c
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-03-24 12:11:38 +00:00
|
|
|
(description)
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-03-24 12:11:38 +00:00
|
|
|
Copyright (C) 1996-1997 Id Software, Inc.
|
|
|
|
Copyright (C) 1999,2000 contributors of the QuakeForge project
|
|
|
|
Please see the file "AUTHORS" for a list of contributors
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-03-24 12:11:38 +00:00
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-03-24 12:11:38 +00:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
2000-01-27 17:06:02 +00:00
|
|
|
|
2000-03-24 12:11:38 +00:00
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
$Id$
|
2000-01-27 17:06:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <ctype.h>
|
2000-03-31 22:46:39 +00:00
|
|
|
#include <stdlib.h>
|
2000-04-02 12:13:19 +00:00
|
|
|
#include <stdio.h>
|
2000-01-27 17:06:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
============================================================================
|
|
|
|
|
|
|
|
LIBRARY REPLACEMENT FUNCTIONS
|
|
|
|
|
|
|
|
============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
int Q_atoi (char *str)
|
|
|
|
{
|
|
|
|
int val;
|
|
|
|
int sign;
|
|
|
|
int c;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
if (*str == '-')
|
|
|
|
{
|
|
|
|
sign = -1;
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
sign = 1;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
val = 0;
|
|
|
|
|
|
|
|
//
|
|
|
|
// check for hex
|
|
|
|
//
|
|
|
|
if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X') )
|
|
|
|
{
|
|
|
|
str += 2;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
c = *str++;
|
|
|
|
if (c >= '0' && c <= '9')
|
|
|
|
val = (val<<4) + c - '0';
|
|
|
|
else if (c >= 'a' && c <= 'f')
|
|
|
|
val = (val<<4) + c - 'a' + 10;
|
|
|
|
else if (c >= 'A' && c <= 'F')
|
|
|
|
val = (val<<4) + c - 'A' + 10;
|
|
|
|
else
|
|
|
|
return val*sign;
|
|
|
|
}
|
|
|
|
}
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
//
|
|
|
|
// check for character
|
|
|
|
//
|
|
|
|
if (str[0] == '\'')
|
|
|
|
{
|
|
|
|
return sign * str[1];
|
|
|
|
}
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
//
|
|
|
|
// assume decimal
|
|
|
|
//
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
c = *str++;
|
|
|
|
if (c <'0' || c > '9')
|
|
|
|
return val*sign;
|
|
|
|
val = val*10 + c - '0';
|
|
|
|
}
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
float Q_atof (char *str)
|
|
|
|
{
|
|
|
|
double val;
|
|
|
|
int sign;
|
|
|
|
int c;
|
|
|
|
int decimal, total;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
if (*str == '-')
|
|
|
|
{
|
|
|
|
sign = -1;
|
|
|
|
str++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
sign = 1;
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
val = 0;
|
|
|
|
|
|
|
|
//
|
|
|
|
// check for hex
|
|
|
|
//
|
|
|
|
if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X') )
|
|
|
|
{
|
|
|
|
str += 2;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
c = *str++;
|
|
|
|
if (c >= '0' && c <= '9')
|
|
|
|
val = (val*16) + c - '0';
|
|
|
|
else if (c >= 'a' && c <= 'f')
|
|
|
|
val = (val*16) + c - 'a' + 10;
|
|
|
|
else if (c >= 'A' && c <= 'F')
|
|
|
|
val = (val*16) + c - 'A' + 10;
|
|
|
|
else
|
|
|
|
return val*sign;
|
|
|
|
}
|
|
|
|
}
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
//
|
|
|
|
// check for character
|
|
|
|
//
|
|
|
|
if (str[0] == '\'')
|
|
|
|
{
|
|
|
|
return sign * str[1];
|
|
|
|
}
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
//
|
|
|
|
// assume decimal
|
|
|
|
//
|
|
|
|
decimal = -1;
|
|
|
|
total = 0;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
c = *str++;
|
|
|
|
if (c == '.')
|
|
|
|
{
|
|
|
|
decimal = total;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (c <'0' || c > '9')
|
|
|
|
break;
|
|
|
|
val = val*10 + c - '0';
|
|
|
|
total++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (decimal == -1)
|
|
|
|
return val*sign;
|
|
|
|
while (total > decimal)
|
|
|
|
{
|
|
|
|
val /= 10;
|
|
|
|
total--;
|
|
|
|
}
|
2000-03-19 15:59:51 +00:00
|
|
|
|
2000-01-27 17:06:02 +00:00
|
|
|
return val*sign;
|
|
|
|
}
|
2000-03-31 22:46:39 +00:00
|
|
|
|
|
|
|
// Note, this is /NOT/ a work-alike strcmp, this groups numbers sanely.
|
2000-04-01 05:47:25 +00:00
|
|
|
//int Q_qstrcmp(const char *val, const char *ref)
|
2000-04-02 12:13:19 +00:00
|
|
|
int Q_qstrcmp(char **os1, char **os2)
|
2000-03-31 22:46:39 +00:00
|
|
|
{
|
2000-04-02 12:13:19 +00:00
|
|
|
int in1, in2, n1, n2;
|
|
|
|
char *s1, *s2;
|
|
|
|
s1 = *os1;
|
|
|
|
s2 = *os2;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
in1 = in2 = n1 = n2 = 0;
|
|
|
|
|
2000-04-03 15:33:04 +00:00
|
|
|
if ((in1 = isdigit((int) *s1)))
|
2000-04-02 12:13:19 +00:00
|
|
|
n1 = strtol(s1, &s1, 10);
|
|
|
|
|
2000-04-03 15:33:04 +00:00
|
|
|
if ((in2 = isdigit((int) *s2)))
|
2000-04-02 12:13:19 +00:00
|
|
|
n2 = strtol(s2, &s2, 10);
|
|
|
|
|
|
|
|
if (in1 && in2) {
|
|
|
|
if (n1 != n2)
|
|
|
|
return n1-n2;
|
|
|
|
} else {
|
|
|
|
if (*s1 != *s2)
|
|
|
|
return *s1 - *s2;
|
|
|
|
else if (*s1 == '\0')
|
|
|
|
return *s1 - *s2;
|
|
|
|
s1++;
|
|
|
|
s2++;
|
2000-03-31 22:46:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|