Esempio n. 1
0
void _parse_value(code *code, mpz_t value, map* vars) {
  if (_is_numeric(code->source[code->pos])) {
    _parse_integer(code, value);
  } else {
    char *var = malloc(1024 * sizeof(char));
    _parse_variable_name(code, var);
    map_get(vars, var, value);
    free(var);
  }
}
Esempio n. 2
0
static unsigned long long simple_strtoull_patch(const char *cp, char **endp, unsigned int base)
{
	unsigned long long result;
	unsigned int rv;

	cp = _parse_integer_fixup_radix(cp, &base);
	rv = _parse_integer(cp, base, &result);

	return result;
}
Esempio n. 3
0
/**
 * simple_strtoull - convert a string to an unsigned long long
 * @cp: The start of the string
 * @endp: A pointer to the end of the parsed string will be placed here
 * @base: The number base to use
 *
 * This function is obsolete. Please use kstrtoull instead.
 */
unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base)
{
	unsigned long long result;
	unsigned int rv;

	cp = _parse_integer_fixup_radix(cp, &base);
	rv = _parse_integer(cp, base, &result);
	/* FIXME */
	cp += (rv & ~KSTRTOX_OVERFLOW);

	if (endp)
		*endp = (char *)cp;

	return result;
}
static int _kstrtoull(const char *s, unsigned int base, unsigned long long *res)
{
    unsigned long long _res;
    unsigned int rv;

    s = _parse_integer_fixup_radix(s, &base);
    rv = _parse_integer(s, base, &_res);
    if (rv & KSTRTOX_OVERFLOW)
        return -ERANGE;
    if (rv == 0)
        return -EINVAL;
    s += rv;
    if (*s == '\n')
        s++;
    if (*s)
        return -EINVAL;
    *res = _res;
    return 0;
}
Esempio n. 5
0
int parse_json_file(FILE *fptr, JSON_T *json_obj)
{
	int ret;
	char *key;
	char first_meet;
	char *tmpstr;
	long long tmpnum;
	double floatnum, decimal;
	JSON_T *value;

	if (!json_obj)
		return -ENOMEM;

	key = NULL;
	tmpstr = NULL;
	value = NULL;
	memset(json_obj, 0, sizeof(JSON_T));
	json_obj->type = JSON;
	json_obj->keys = NULL;

	_PARSE_SYMBOL(fptr, "{", NULL);

	while (!feof(fptr)) {
		_PARSE_SYMBOL(fptr, "\"}", &first_meet);
		if (first_meet == '}')
			break;

		ret = _parse_string(fptr, &key);
		if (ret < 0)
			goto error_handle;
		//printf("string = %s : ", key);

		_PARSE_SYMBOL(fptr, ":", NULL);
		_PARSE_SYMBOL(fptr, "\"{-0123456789.", &first_meet);
		value = malloc(sizeof(JSON_T));
		if (!value) {
			ret = -ENOMEM;
			goto error_handle;
		}
		memset(value, 0, sizeof(JSON_T));

		switch (first_meet) {
		case '\"':
			ret = _parse_string(fptr, &tmpstr);
			if (ret < 0)
				goto error_handle;
			value->type = STRING;
			value->str = tmpstr;
			//printf("value = %s\n", tmpstr);
			break;
		case '{':
			fseek(fptr, -1, SEEK_CUR);
			ret = parse_json_file(fptr, value);
			if (ret < 0)
				goto error_handle;
			break;
		case '-':
			ret = _parse_integer(fptr, &tmpnum);
			if (ret < 0) {
				goto error_handle;
			} else if (ret == 1) {
				ret = _parse_decimal(fptr, &decimal);
				if (ret < 0)
					goto error_handle;
				floatnum = tmpnum + decimal;
				value->type = FLOAT;
				value->floating = -floatnum;
			} else {
				value->type = INTEGER;
				value->integer = -tmpnum;
			}
			//printf("value = %lld\n", -tmpnum);
			break;
		default:
			fseek(fptr, -1, SEEK_CUR);
			ret = _parse_integer(fptr, &tmpnum);
			if (ret < 0) {
				goto error_handle;
			} else if (ret == 1) {
				ret = _parse_decimal(fptr, &decimal);
				if (ret < 0)
					goto error_handle;
				floatnum = tmpnum + decimal;
				value->type = FLOAT;
				value->floating = floatnum;
			} else {
				value->type = INTEGER;
				value->integer = tmpnum;
			}
			//printf("value = %lld\n", tmpnum);
			break;	
		}

		/* Insert */
		ret = insert_json_obj(json_obj, key, value);
		if (ret < 0)
			goto error_handle;

		key = NULL;
		tmpstr = NULL;
		value = NULL;

		_PARSE_SYMBOL(fptr, "},", &first_meet);
		if (first_meet == '}')
			break;
	}

	return 0;

error_handle:
	/* Do not free self because it perhaps results in
	double free error when recursing */
	free_json_obj_field(json_obj);
	if (key)
		free(key);
	if (tmpstr)
		free(tmpstr);
	if (value)
		free(value);
	return ret;
}