forked from enlightenment/efl
Use eina conversion functions (Remove code from eet).
SVN revision: 36844
This commit is contained in:
parent
f08f865b75
commit
1e13a4aec2
|
@ -80,8 +80,6 @@ int eet_dictionary_string_get_double(const Eet_Dictionary *ed, int
|
||||||
int eet_dictionary_string_get_hash(const Eet_Dictionary *ed, int index);
|
int eet_dictionary_string_get_hash(const Eet_Dictionary *ed, int index);
|
||||||
|
|
||||||
int _eet_hash_gen(const char *key, int hash_size);
|
int _eet_hash_gen(const char *key, int hash_size);
|
||||||
int _eet_string_to_double_convert(const char *src, long long *m, long *e);
|
|
||||||
void _eet_double_to_string_convert(char des[128], double d);
|
|
||||||
|
|
||||||
const void* eet_identity_check(const void *data_base, unsigned int data_length,
|
const void* eet_identity_check(const void *data_base, unsigned int data_length,
|
||||||
const void *signature_base, unsigned int signature_length,
|
const void *signature_base, unsigned int signature_length,
|
||||||
|
|
|
@ -26,6 +26,8 @@
|
||||||
# include <winsock2.h>
|
# include <winsock2.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <Eina.h>
|
||||||
|
|
||||||
#include "Eet.h"
|
#include "Eet.h"
|
||||||
#include "Eet_private.h"
|
#include "Eet_private.h"
|
||||||
|
|
||||||
|
@ -545,7 +547,7 @@ eet_data_get_float(const Eet_Dictionary *ed, const void *src, const void *src_en
|
||||||
|
|
||||||
if (_eet_data_float_cache_get(s, len, d) != 0) return len + 1;
|
if (_eet_data_float_cache_get(s, len, d) != 0) return len + 1;
|
||||||
|
|
||||||
_eet_string_to_double_convert(s, &mantisse, &exponent);
|
if (eina_convert_atod(s, len, &mantisse, &exponent) == EINA_FALSE) return -1;
|
||||||
*d = (float)ldexp((double)mantisse, exponent);
|
*d = (float)ldexp((double)mantisse, exponent);
|
||||||
|
|
||||||
return len + 1;
|
return len + 1;
|
||||||
|
@ -564,7 +566,7 @@ eet_data_put_float(Eet_Dictionary *ed, const void *src, int *size_ret)
|
||||||
char buf[128];
|
char buf[128];
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
_eet_double_to_string_convert(buf, (double)(*(float *)src));
|
eina_convert_dtoa((double)(*(float *)src), buf);
|
||||||
|
|
||||||
if (!ed)
|
if (!ed)
|
||||||
{
|
{
|
||||||
|
@ -608,7 +610,7 @@ eet_data_get_double(const Eet_Dictionary *ed, const void *src, const void *src_e
|
||||||
|
|
||||||
if (_eet_data_double_cache_get(s, len, d) != 0) return len + 1;
|
if (_eet_data_double_cache_get(s, len, d) != 0) return len + 1;
|
||||||
|
|
||||||
_eet_string_to_double_convert(s, &mantisse, &exponent);
|
if (eina_convert_atod(s, len, &mantisse, &exponent) == EINA_FALSE) return -1;
|
||||||
*d = ldexp((double) mantisse, exponent);
|
*d = ldexp((double) mantisse, exponent);
|
||||||
|
|
||||||
return len + 1;
|
return len + 1;
|
||||||
|
@ -627,7 +629,7 @@ eet_data_put_double(Eet_Dictionary *ed, const void *src, int *size_ret)
|
||||||
char buf[128];
|
char buf[128];
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
_eet_double_to_string_convert(buf, (double)(*(double *)src));
|
eina_convert_dtoa((double)(*(double *)src), buf);
|
||||||
|
|
||||||
if (!ed)
|
if (!ed)
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
|
#include <Eina.h>
|
||||||
|
|
||||||
#include "Eet.h"
|
#include "Eet.h"
|
||||||
#include "Eet_private.h"
|
#include "Eet_private.h"
|
||||||
|
|
||||||
|
@ -264,7 +266,7 @@ eet_dictionary_string_get_float(const Eet_Dictionary *ed, int index, float *resu
|
||||||
long long mantisse = 0;
|
long long mantisse = 0;
|
||||||
long exponent = 0;
|
long exponent = 0;
|
||||||
|
|
||||||
if (!_eet_string_to_double_convert(str, &mantisse, &exponent))
|
if (eina_convert_atod(str, ed->all[index].len, &mantisse, &exponent) == EINA_FALSE)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ed->all[index].convert.f = ldexpf((float) mantisse, exponent);
|
ed->all[index].convert.f = ldexpf((float) mantisse, exponent);
|
||||||
|
@ -299,7 +301,7 @@ eet_dictionary_string_get_double(const Eet_Dictionary *ed, int index, double *re
|
||||||
long long mantisse = 0;
|
long long mantisse = 0;
|
||||||
long exponent = 0;
|
long exponent = 0;
|
||||||
|
|
||||||
if (!_eet_string_to_double_convert(str, &mantisse, &exponent))
|
if (eina_convert_atod(str, ed->all[index].len, &mantisse, &exponent) == EINA_FALSE)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ed->all[index].convert.d = ldexp((double) mantisse, exponent);
|
ed->all[index].convert.d = ldexp((double) mantisse, exponent);
|
||||||
|
|
|
@ -51,6 +51,8 @@ void *alloca (size_t);
|
||||||
# include <openssl/err.h>
|
# include <openssl/err.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <Eina.h>
|
||||||
|
|
||||||
#include "Eet.h"
|
#include "Eet.h"
|
||||||
#include "Eet_private.h"
|
#include "Eet_private.h"
|
||||||
|
|
||||||
|
@ -702,6 +704,8 @@ eet_init(void)
|
||||||
ERR_load_crypto_strings();
|
ERR_load_crypto_strings();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
eina_init();
|
||||||
|
|
||||||
return eet_initcount;
|
return eet_initcount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -717,6 +721,8 @@ eet_shutdown(void)
|
||||||
ERR_free_strings();
|
ERR_free_strings();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
eina_shutdown();
|
||||||
|
|
||||||
return eet_initcount;
|
return eet_initcount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,161 +32,3 @@ _eet_hash_gen(const char *key, int hash_size)
|
||||||
return hash_num;
|
return hash_num;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* On Windows (using MinGW or VC++), printf-like functions */
|
|
||||||
/* rely on MSVCRT, which does not fully support the C99 */
|
|
||||||
/* specifications. In particular, they do not support the */
|
|
||||||
/* modifier character %a. */
|
|
||||||
|
|
||||||
|
|
||||||
/* That function converts a string created by a valid %a */
|
|
||||||
/* modifier to a double. */
|
|
||||||
/* */
|
|
||||||
/* The string must have the following format: */
|
|
||||||
/* */
|
|
||||||
/* [-]0xh.hhhhhp[+-]e */
|
|
||||||
/* */
|
|
||||||
/* where e is a decimal number. */
|
|
||||||
/* If n is the number of cyphers after the point, the */
|
|
||||||
/* returned mantisse and exponents are */
|
|
||||||
/* */
|
|
||||||
/* mantisse: [-]hhhhhh */
|
|
||||||
/* exponent: 2^([+-]e - 4 * n) */
|
|
||||||
int
|
|
||||||
_eet_string_to_double_convert(const char *src, long long *m, long *e)
|
|
||||||
{
|
|
||||||
const char *str;
|
|
||||||
long long mantisse;
|
|
||||||
long exponent;
|
|
||||||
int nbr_decimals;
|
|
||||||
int sign;
|
|
||||||
|
|
||||||
str = src;
|
|
||||||
sign = +1;
|
|
||||||
|
|
||||||
if (*str == '-')
|
|
||||||
{
|
|
||||||
sign = -1;
|
|
||||||
str++;
|
|
||||||
}
|
|
||||||
if (*str == '0')
|
|
||||||
{
|
|
||||||
str++;
|
|
||||||
if (*str == 'x')
|
|
||||||
str++;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf(stderr, "[Eet] Error 1 during conversion of '%s'\n", src);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fprintf(stderr, "[Eet] Error 2 during conversion of '%s'\n", src);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
nbr_decimals = 0;
|
|
||||||
mantisse = (*str >= 'a') ? *str - 'a' + 10 : *str - '0';
|
|
||||||
str++;
|
|
||||||
if (*str == '.')
|
|
||||||
{
|
|
||||||
str++;
|
|
||||||
while (*str != 'p')
|
|
||||||
{
|
|
||||||
mantisse <<= 4;
|
|
||||||
mantisse += (*str >= 'a') ? *str - 'a' + 10 : *str - '0';
|
|
||||||
str++;
|
|
||||||
nbr_decimals++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (sign < 0)
|
|
||||||
mantisse = -mantisse;
|
|
||||||
if (*str != 'p')
|
|
||||||
{
|
|
||||||
fprintf(stderr, "[Eet] Error 3 during conversion '%s'\n", src);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
sign = +1;
|
|
||||||
str++;
|
|
||||||
if (*str == '-')
|
|
||||||
{
|
|
||||||
sign = -1;
|
|
||||||
str++;
|
|
||||||
}
|
|
||||||
else if (*str == '+') str++;
|
|
||||||
|
|
||||||
exponent = 0;
|
|
||||||
while (*str != '\0')
|
|
||||||
{
|
|
||||||
exponent *= 10;
|
|
||||||
exponent += *str - '0';
|
|
||||||
str++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sign < 0)
|
|
||||||
exponent = -exponent;
|
|
||||||
|
|
||||||
*m = mantisse;
|
|
||||||
*e = exponent - (nbr_decimals << 2);
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* That function converts a double to a string that as the */
|
|
||||||
/* following format: */
|
|
||||||
/* */
|
|
||||||
/* [-]0xh.hhhhhp[+-]e */
|
|
||||||
/* */
|
|
||||||
/* where h is a hexadecimal number and e a decimal number. */
|
|
||||||
void
|
|
||||||
_eet_double_to_string_convert(char des[128], double d)
|
|
||||||
{
|
|
||||||
static const char look_up_table[] = {'0', '1', '2', '3', '4',
|
|
||||||
'5', '6', '7', '8', '9',
|
|
||||||
'a', 'b', 'c', 'd', 'e', 'f'};
|
|
||||||
int p;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (d < 0.0)
|
|
||||||
{
|
|
||||||
*(des++) = '-';
|
|
||||||
d = -d;
|
|
||||||
}
|
|
||||||
|
|
||||||
d = frexp(d, &p);
|
|
||||||
|
|
||||||
if (p)
|
|
||||||
{
|
|
||||||
d *= 2;
|
|
||||||
p -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
*(des++) = '0';
|
|
||||||
*(des++) = 'x';
|
|
||||||
*(des++) = look_up_table[(size_t)d];
|
|
||||||
*(des++) = '.';
|
|
||||||
|
|
||||||
for (i = 0; i < 16; i++)
|
|
||||||
{
|
|
||||||
d -= floor(d);
|
|
||||||
d *= 16;
|
|
||||||
*(des++) = look_up_table[(size_t)d];
|
|
||||||
}
|
|
||||||
|
|
||||||
while (*(des - 1) == '0')
|
|
||||||
des--;
|
|
||||||
|
|
||||||
if (*(des - 1) == '.')
|
|
||||||
des--;
|
|
||||||
|
|
||||||
*(des++) = 'p';
|
|
||||||
if (p < 0)
|
|
||||||
{
|
|
||||||
*(des++) = '-';
|
|
||||||
p = -p;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
*(des++) = '+';
|
|
||||||
|
|
||||||
snprintf(des, 128, "%d", p);
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue