aboutsummaryrefslogtreecommitdiffstats
path: root/epan/value_string.c
diff options
context:
space:
mode:
authorStephen Fisher <steve@stephen-fisher.com>2006-12-07 20:29:40 +0000
committerStephen Fisher <steve@stephen-fisher.com>2006-12-07 20:29:40 +0000
commitc980cede98fada00249cc6d7218ef519302926f4 (patch)
treecde84151baa939faa211ceff602a1dde6d0ff848 /epan/value_string.c
parentf4e3b4c03367f0ac40bde83db1f2960566bd3aa7 (diff)
From Francesco Fondelli:
I defined a range_string struct. It's like value_string but stores range <-> string pairs. Moreover I wrote rval_to_str(), match_strrval_idx() match_strrval() which are behaving exactly as val_to_str(), match_strval_idx() and match_strval(). svn path=/trunk/; revision=20061
Diffstat (limited to 'epan/value_string.c')
-rw-r--r--epan/value_string.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/epan/value_string.c b/epan/value_string.c
index a6fd925725..49d44d5b29 100644
--- a/epan/value_string.c
+++ b/epan/value_string.c
@@ -109,3 +109,50 @@ decode_enumerated_bitfield_shifted(guint32 val, guint32 mask, int width,
g_snprintf(p, 1024-(p-buf), fmt, val_to_str((val & mask) >> shift, tab, "Unknown"));
return buf;
}
+
+
+/* FF: ranges aware versions */
+
+/* Tries to match val against each range in the range_string array rs.
+ Returns the associated string ptr on a match.
+ Formats val with fmt, and returns the resulting string, on failure. */
+const gchar *rval_to_str(guint32 val, const range_string *rs, const char *fmt)
+{
+ const gchar *ret = NULL;
+
+ g_assert(fmt != NULL);
+
+ ret = match_strrval(val, rs);
+ if(ret != NULL)
+ return ret;
+
+ return ep_strdup_printf(fmt, val);
+}
+
+/* Tries to match val against each range in the range_string array rs.
+ Returns the associated string ptr, and sets "*idx" to the index in
+ that table, on a match, and returns NULL, and sets "*idx" to -1,
+ on failure. */
+const gchar *match_strrval_idx(guint32 val, const range_string *rs, gint *idx)
+{
+ gint i = 0;
+
+ while(rs[i].strptr) {
+ if( (val >= rs[i].value_min) && (val <= rs[i].value_max) ) {
+ *idx = i;
+ return (rs[i].strptr);
+ }
+ i++;
+ }
+
+ *idx = -1;
+ return (NULL);
+}
+
+/* Like match_strrval_idx(), but doesn't return the index. */
+const gchar *match_strrval(guint32 val, const range_string *rs)
+{
+ gint ignore_me = 0;
+ return match_strrval_idx(val, rs, &ignore_me);
+}
+