Skip to content

Commit

Permalink
xrCore: fix codestyle
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleivg committed May 25, 2018
1 parent 15b8864 commit 4d135e5
Showing 1 changed file with 159 additions and 133 deletions.
292 changes: 159 additions & 133 deletions src/xrCore/xr_ini.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,123 +20,138 @@ XRCORE_API CInifile const* pSettingsAuth = nullptr;
* @param readOnly
* @return
*/
int _cdecl _i64toa_s(int64_t value, char *str, size_t size, int radix){
uint64_t val;
unsigned int digit;
int is_negative;
char buffer[65], *pos;
size_t len;

if (!(str != NULL))
return MSVCRT_EINVAL;
if (!(size > 0))
return MSVCRT_EINVAL;
if (!(radix >= 2 && radix <= 36)) {
str[0] = '\0';
return MSVCRT_EINVAL;
}

if (value < 0 && radix == 10) {
is_negative = 1;
val = -value;
} else {
is_negative = 0;
val = value;
}

pos = buffer + 64;
*pos = '\0';

do {
digit = val % radix;
val /= radix;

if (digit < 10)
*--pos = '0' + digit;
else
*--pos = 'a' + digit - 10;
} while (val != 0);

if (is_negative)
*--pos = '-';

len = buffer + 65 - pos;
if (len > size) {
size_t i;
char *p = str;

/* Copy the temporary buffer backwards up to the available number of
* characters. Don't copy the negative sign if present. */

if (is_negative) {
p++;
size--;
}

for (pos = buffer + 63, i = 0; i < size; i++)
*p++ = *pos--;

str[0] = '\0';
return MSVCRT_ERANGE;
}

memcpy(str, pos, len);
return 0;
}

int _cdecl _ui64toa_s(uint64_t value, char *str, size_t size, int radix) {
char buffer[65], *pos;
int digit;

if (!(str != NULL))
return MSVCRT_EINVAL;
if (!(size > 0))
return MSVCRT_EINVAL;
if (!(radix >= 2 && radix <= 36)) {
str[0] = '\0';
return MSVCRT_EINVAL;
}

pos = buffer + 64;
*pos = '\0';

do {
digit = value % radix;
value /= radix;

if (digit < 10)
*--pos = '0' + digit;
else
*--pos = 'a' + digit - 10;
} while (value != 0);

if (buffer - pos + 65 > size) {
return MSVCRT_EINVAL;
}

memcpy(str, pos, buffer - pos + 65);
return 0;
}

LARGE_INTEGER _cdecl _atoi64( const char *str )
{
ULARGE_INTEGER RunningTotal = 0;
int _cdecl _i64toa_s(int64_t value, char *str, size_t size, int radix)
{
uint64_t val;
unsigned int digit;
int is_negative;
char buffer[65], *pos;
size_t len;

if (!(str != NULL))
return MSVCRT_EINVAL;
if (!(size > 0))
return MSVCRT_EINVAL;
if (!(radix >= 2 && radix <= 36))
{
str[0] = '\0';
return MSVCRT_EINVAL;
}

if (value < 0 && radix == 10)
{
is_negative = 1;
val = -value;
}
else
{
is_negative = 0;
val = value;
}

pos = buffer + 64;
*pos = '\0';

do
{
digit = val % radix;
val /= radix;

if (digit < 10)
*--pos = '0' + digit;
else
*--pos = 'a' + digit - 10;
} while (val != 0);

if (is_negative)
*--pos = '-';

len = buffer + 65 - pos;
if (len > size)
{
size_t i;
char *p = str;

/* Copy the temporary buffer backwards up to the available number of
* characters. Don't copy the negative sign if present. */

if (is_negative)
{
p++;
size--;
}

for (pos = buffer + 63, i = 0; i < size; i++)
*p++ = *pos--;

str[0] = '\0';
return MSVCRT_ERANGE;
}

memcpy(str, pos, len);
return 0;
}

int _cdecl _ui64toa_s(uint64_t value, char *str, size_t size, int radix)
{
char buffer[65], *pos;
int digit;

if (!(str != NULL))
return MSVCRT_EINVAL;
if (!(size > 0))
return MSVCRT_EINVAL;
if (!(radix >= 2 && radix <= 36))
{
str[0] = '\0';
return MSVCRT_EINVAL;
}

pos = buffer + 64;
*pos = '\0';

do
{
digit = value % radix;
value /= radix;

if (digit < 10)
*--pos = '0' + digit;
else
*--pos = 'a' + digit - 10;
} while (value != 0);

if (buffer - pos + 65 > size)
{
return MSVCRT_EINVAL;
}

memcpy(str, pos, buffer - pos + 65);
return 0;
}

LARGE_INTEGER _cdecl _atoi64(const char *str)
{
ULARGE_INTEGER RunningTotal = 0;
char bMinus = 0;

while (*str == ' ' || (*str >= '\011' && *str <= '\015')) {
str++;
while (*str == ' ' || (*str >= '\011' && *str <= '\015'))
{
str++;
} /* while */

if (*str == '+') {
str++;
} else if (*str == '-') {
bMinus = 1;
str++;
if (*str == '+')
str++;
else if (*str == '-')
{
bMinus = 1;
str++;
} /* if */

while (*str >= '0' && *str <= '9') {
RunningTotal = RunningTotal * 10 + *str - '0';
str++;
while (*str >= '0' && *str <= '9')
{
RunningTotal = RunningTotal * 10 + *str - '0';
str++;
} /* while */

return bMinus ? -RunningTotal : RunningTotal;
Expand All @@ -147,55 +162,66 @@ uint64_t _cdecl _strtoui64_l(const char *nptr, char **endptr, int base, locale_t
BOOL negative = FALSE;
uint64_t ret = 0;

if (!(nptr != NULL))
return 0;
if (!(base == 0 || base >= 2))
return 0;
if (!(base <= 36))
return 0;

if (!(nptr != NULL)) return 0;
if (!(base == 0 || base >= 2)) return 0;
if (!(base <= 36)) return 0;

while(isspace(*nptr)) nptr++;
while (isspace(*nptr))
nptr++;

if(*nptr == '-') {
if (*nptr == '-')
{
negative = TRUE;
nptr++;
} else if(*nptr == '+')
}
else if (*nptr == '+')
nptr++;

if((base==0 || base==16) && *nptr=='0' && tolower(*(nptr+1))=='x') {
if ((base == 0 || base == 16) && *nptr == '0' && tolower(*(nptr + 1)) == 'x')
{
base = 16;
nptr += 2;
}

if(base == 0) {
if(*nptr=='0')
if (base == 0)
{
if (*nptr == '0')
base = 8;
else
base = 10;
}

while(*nptr) {
while (*nptr)
{
char cur = tolower(*nptr);
int v;

if(isdigit(cur)) {
if(cur >= '0'+base)
if (isdigit(cur))
{
if (cur >= '0' + base)
break;
v = *nptr-'0';
} else {
if(cur<'a' || cur>='a'+base-10)
v = *nptr - '0';
}
else
{
if (cur < 'a' || cur >= 'a' + base - 10)
break;
v = cur-'a'+10;
v = cur - 'a' + 10;
}

nptr++;

if(ret>MSVCRT_UI64_MAX/base || ret*base>MSVCRT_UI64_MAX-v) {
if (ret > MSVCRT_UI64_MAX / base || ret * base > MSVCRT_UI64_MAX - v)
ret = MSVCRT_UI64_MAX;
} else
ret = ret*base + v;
else
ret = ret * base + v;
}

if(endptr)
*endptr = (char*)nptr;
if (endptr)
*endptr = (char*) nptr;

return negative ? -ret : ret;
}
Expand Down

0 comments on commit 4d135e5

Please sign in to comment.