Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Sync from libucl, and only convert string to boolean and/or integers
Baptiste Daroussin committed 12 years ago
commit 30a0f921dc577d4614a563c8e9c680f31c696b13
parent 40277e7
7 files changed +42 -17
modified external/libucl/include/ucl.h
@@ -164,9 +164,15 @@ ucl_object_new (void)
 * String conversion flags
 */
enum ucl_string_flags {
-
	UCL_STRING_ESCAPE = 0x0,  /**< UCL_STRING_ESCAPE perform JSON escape */
-
	UCL_STRING_TRIM = 0x1,    /**< UCL_STRING_TRIM trim leading and trailing whitespaces */
-
	UCL_STRING_PARSE = 0x2    /**< UCL_STRING_PARSE parse passed string (and detect booleans and numbers) */
+
	UCL_STRING_ESCAPE = 0x1,  /**< UCL_STRING_ESCAPE perform JSON escape */
+
	UCL_STRING_TRIM = 0x2,    /**< UCL_STRING_TRIM trim leading and trailing whitespaces */
+
	UCL_STRING_PARSE_BOOLEAN = 0x4,    /**< UCL_STRING_PARSE_BOOLEAN parse passed string and detect boolean */
+
	UCL_STRING_PARSE_INT = 0x8,    /**< UCL_STRING_PARSE_INT parse passed string and detect integer number */
+
	UCL_STRING_PARSE_DOUBLE = 0x10,    /**< UCL_STRING_PARSE_DOUBLE parse passed string and detect integer or float number */
+
	UCL_STRING_PARSE_NUMBER =  UCL_STRING_PARSE_INT|UCL_STRING_PARSE_DOUBLE ,  /**<
+
									UCL_STRING_PARSE_NUMBER parse passed string and detect number */
+
	UCL_STRING_PARSE =  UCL_STRING_PARSE_BOOLEAN|UCL_STRING_PARSE_NUMBER   /**<
+
									UCL_STRING_PARSE parse passed string (and detect booleans and numbers) */
};

/**
modified external/libucl/src/ucl_internal.h
@@ -240,9 +240,10 @@ ucl_maybe_parse_boolean (ucl_object_t *obj, const unsigned char *start, size_t l
 * @param start start of string
 * @param end end of string
 * @param pos position where parsing has stopped
+
 * @param allow_double allow parsing of floating point values
 * @return 0 if string is numeric and error code (EINVAL or ERANGE) in case of conversion error
 */
int ucl_maybe_parse_number (ucl_object_t *obj,
-
		const char *start, const char *end, const char **pos);
+
		const char *start, const char *end, const char **pos, bool allow_double);

#endif /* UCL_INTERNAL_H_ */
modified external/libucl/src/ucl_parser.c
@@ -270,7 +270,7 @@ ucl_copy_or_store_ptr (struct ucl_parser *parser,

int
ucl_maybe_parse_number (ucl_object_t *obj,
-
		const char *start, const char *end, const char **pos)
+
		const char *start, const char *end, const char **pos, bool allow_double)
{
	const char *p = start, *c = start;
	char *endptr;
@@ -285,7 +285,7 @@ ucl_maybe_parse_number (ucl_object_t *obj,
		if (isdigit (*p)) {
			p ++;
		}
-
		else {
+
		else if (allow_double) {
			if (p == c) {
				/* Empty digits sequence, not a number */
				*pos = start;
@@ -332,6 +332,9 @@ ucl_maybe_parse_number (ucl_object_t *obj,
				break;
			}
		}
+
		else {
+
			break;
+
		}
	}

	errno = 0;
@@ -463,7 +466,7 @@ ucl_maybe_parse_number (ucl_object_t *obj,
	return EINVAL;

	set_obj:
-
	if (need_double || is_date) {
+
	if (allow_double && (need_double || is_date)) {
		if (!is_date) {
			obj->type = UCL_FLOAT;
		}
@@ -494,7 +497,7 @@ ucl_lex_number (struct ucl_parser *parser,
	const unsigned char *pos;
	int ret;

-
	ret = ucl_maybe_parse_number (obj, chunk->pos, chunk->end, (const char **)&pos);
+
	ret = ucl_maybe_parse_number (obj, chunk->pos, chunk->end, (const char **)&pos, true);

	if (ret == 0) {
		chunk->remain -= pos - chunk->pos;
modified external/libucl/src/ucl_util.c
@@ -824,8 +824,15 @@ ucl_object_fromstring_common (const char *str, size_t len, enum ucl_string_flags
		}
		if ((flags & UCL_STRING_PARSE) && dst != NULL) {
			/* Parse what we have */
-
			if (!ucl_maybe_parse_boolean (obj, dst, obj->len)) {
-
				ucl_maybe_parse_number (obj, dst, dst + obj->len, &pos);
+
			if (flags & UCL_STRING_PARSE_BOOLEAN) {
+
				if (!ucl_maybe_parse_boolean (obj, dst, obj->len) && (flags & UCL_STRING_PARSE_NUMBER)) {
+
					ucl_maybe_parse_number (obj, dst, dst + obj->len, &pos,
+
							flags & UCL_STRING_PARSE_DOUBLE);
+
				}
+
			}
+
			else {
+
				ucl_maybe_parse_number (obj, dst, dst + obj->len, &pos,
+
						flags & UCL_STRING_PARSE_DOUBLE);
			}
		}
	}
modified libpkg/dns_utils.c
@@ -40,6 +40,15 @@ typedef union {
	unsigned char buf[1024];
} query_t;

+
static int
+
srv_cmp(const void *a, const void *b)
+
{
+
	struct dns_srvinfo *srva = (struct dns_srvinfo *)a;
+
	struct dns_srvinfo *srvb = (struct dns_srvinfo *)b;
+

+
	return (srva->priority > srvb->priority);
+
}
+

struct dns_srvinfo *
dns_getsrvinfo(const char *zone)
{
@@ -129,6 +138,8 @@ dns_getsrvinfo(const char *zone)
	for (i = 0; i < n - 1; i++)
		res[i]->next = res[i + 1];

+
	/* Sort against priority then weight */
+

	first = res[0];
	free(res);

modified libpkg/pkg_manifest.c
@@ -299,7 +299,7 @@ pkg_int(struct pkg *pkg, ucl_object_t *obj, int attr)
	char vint[BUFSIZ];
	if (attr == PKG_VERSION) {
		snprintf(vint, sizeof(vint), "%"PRId64, ucl_object_toint(obj));
-
		pkg_set(pkg, attr, vint);
+
		return (pkg_set(pkg, attr, vint));
	}
	return (pkg_set(pkg, attr, ucl_object_toint(obj)));
}
modified libpkg/utils.c
@@ -497,7 +497,7 @@ yaml_sequence_to_object(ucl_object_t *obj, yaml_document_t *doc, yaml_node_t *no
			break;
		case YAML_SCALAR_NODE:
			sub = ucl_object_fromstring_common (val->data.scalar.value,
-
			    val->data.scalar.length, UCL_STRING_TRIM|UCL_STRING_PARSE);
+
			    val->data.scalar.length, UCL_STRING_TRIM|UCL_STRING_PARSE_INT|UCL_STRING_PARSE_BOOLEAN);
			break;
		case YAML_NO_NODE:
			/* Should not happen */
@@ -515,7 +515,6 @@ yaml_mapping_to_object(ucl_object_t *obj, yaml_document_t *doc, yaml_node_t *nod
{
	yaml_node_pair_t *pair;
	yaml_node_t *key, *val;
-
	int flag = 0;

	ucl_object_t *sub;

@@ -532,11 +531,9 @@ yaml_mapping_to_object(ucl_object_t *obj, yaml_document_t *doc, yaml_node_t *nod
			sub = yaml_sequence_to_object(NULL, doc, val);
			break;
		case YAML_SCALAR_NODE:
-
			flag = UCL_STRING_TRIM;
-
			if (strcmp(key->data.scalar.value, "version") != 0)
-
				flag |= UCL_STRING_PARSE;
			sub = ucl_object_fromstring_common (val->data.scalar.value,
-
			    val->data.scalar.length, flag);
+
			    val->data.scalar.length,
+
			    UCL_STRING_TRIM|UCL_STRING_PARSE_INT|UCL_STRING_PARSE_BOOLEAN);
			break;
		case YAML_NO_NODE:
			/* Should not happen */