From aac897f2337471637d9a47b38e1b7b35ab0359b5 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sat, 14 Aug 2004 15:15:53 +0000 Subject: [PATCH] Added obj_find_anum() which is obj_find_aval() combined with atol() and a default value (this is a very common idiom at many places). Added size_attr() which calculates size of a given attribute in the current bucket format. --- lib/obj2buck.c | 13 +++++++++++++ lib/object.c | 8 ++++++++ lib/object.h | 3 +++ 3 files changed, 24 insertions(+) diff --git a/lib/obj2buck.c b/lib/obj2buck.c index 367764a5..6cd25896 100644 --- a/lib/obj2buck.c +++ b/lib/obj2buck.c @@ -42,6 +42,19 @@ attr_set_type(uns type) } } +uns +size_attr(uns len) +{ + ASSERT(len <= MAX_ATTR_SIZE); + if (use_v33) + { + len++; + return len + utf8_space(len); + } + else + return len + 2; +} + inline byte * put_attr(byte *ptr, uns type, byte *val, uns len) { diff --git a/lib/object.c b/lib/object.c index ab882c12..6a2a90c5 100644 --- a/lib/object.c +++ b/lib/object.c @@ -15,6 +15,7 @@ #include #include +#include void obj_dump(struct odes *o) @@ -117,6 +118,13 @@ obj_find_aval(struct odes *o, uns x) return a ? a->val : NULL; } +uns +obj_find_anum(struct odes *o, uns x, uns def) +{ + struct oattr *a = obj_find_attr(o, x); + return a ? (uns)atol(a->val) : def; +} + struct oattr * obj_set_attr(struct odes *o, uns x, byte *v) { diff --git a/lib/object.h b/lib/object.h index 01c47dfb..c889953b 100644 --- a/lib/object.h +++ b/lib/object.h @@ -34,6 +34,7 @@ struct oattr *obj_find_attr(struct odes *, uns); struct oattr *obj_find_attr_last(struct odes *, uns); uns obj_del_attr(struct odes *, struct oattr *); byte *obj_find_aval(struct odes *, uns); +uns obj_find_anum(struct odes *, uns, uns); struct oattr *obj_set_attr(struct odes *, uns, byte *); struct oattr *obj_set_attr_num(struct odes *, uns, uns); struct oattr *obj_add_attr(struct odes *, uns, byte *); @@ -65,6 +66,8 @@ int obj_read(struct fastbuf *, struct odes *); void attr_set_type(uns type); +uns size_attr(uns len); + byte *put_attr(byte *ptr, uns type, byte *val, uns len); byte *put_attr_str(byte *ptr, uns type, byte *val); byte *put_attr_vformat(byte *ptr, uns type, byte *mask, va_list va); -- 2.39.2