aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Zawadzki <darkjames-ws@darkjames.pl>2011-04-28 11:15:46 +0000
committerJakub Zawadzki <darkjames-ws@darkjames.pl>2011-04-28 11:15:46 +0000
commit1ea1e9fef29096ed1833db1694dbd2cf75b94006 (patch)
tree59ff6681309dcd62f829221da471d6be971792e2
parentde18d83f6117f1e4a6ee796b4814249f5e39312b (diff)
Change value_string_ext->_vs_match to return value_string struct (instead of strptr),
Now index can be easily calculated so remove idx pointer from all match functions. Just in case change names if someone is using wireshark internals. svn path=/trunk/; revision=36930
-rw-r--r--epan/value_string.c84
-rw-r--r--epan/value_string.h12
2 files changed, 48 insertions, 48 deletions
diff --git a/epan/value_string.c b/epan/value_string.c
index 3a17cfd1ad..7942b106f4 100644
--- a/epan/value_string.c
+++ b/epan/value_string.c
@@ -142,7 +142,7 @@ value_string_ext_new(value_string *vs, guint vs_tot_num_entries, gchar *vs_name)
vse->_vs_p = vs;
vse->_vs_num_entries = vs_tot_num_entries - 1; /* remember the actual number of entries */
vse->_vs_first_value = 0; /* initialized in _match_strval_ext_init */
- vse->_vs_match = _match_strval_ext_init;
+ vse->_vs_match2 = _match_strval_ext_init;
vse->_vs_name = vs_name;
return vse;
}
@@ -153,9 +153,11 @@ value_string_ext_new(value_string *vs, guint vs_tot_num_entries, gchar *vs_name)
*/
const gchar*
match_strval_ext(const guint32 val, const value_string_ext *vse) {
- gint ignore_me;
- if (vse)
- return vse->_vs_match(val, vse, &ignore_me);
+ if (vse) {
+ const value_string *vs = vse->_vs_match2(val, vse);
+ if (vs)
+ return vs->strptr;
+ }
return NULL;
}
@@ -167,9 +169,15 @@ match_strval_ext(const guint32 val, const value_string_ext *vse) {
const gchar*
match_strval_idx_ext(const guint32 val, value_string_ext *vse, gint *idx) {
- if (vse)
- return vse->_vs_match(val, vse, idx);
- return NULL;
+ if (vse) {
+ const value_string *vs = vse->_vs_match2(val, vse);
+ if (vs) {
+ *idx = (vs - vse->_vs_p);
+ return vs->strptr;
+ }
+ }
+ *idx = -1;
+ return NULL;
}
/* Similar to match_strval_ext except that on failure
@@ -204,38 +212,33 @@ val_to_str_ext_const(const guint32 val, const value_string_ext *vse, const char
return unknown_str;
}
-static const gchar *
-_match_strval_linear(const guint32 val, const value_string_ext *vse, gint *idx)
+static const value_string *
+_match_strval_linear(const guint32 val, const value_string_ext *vse)
{
const value_string *vs_p = vse->_vs_p;
guint i;
for (i=0; i<vse->_vs_num_entries; i++) {
- if (vs_p[i].value == val) {
- *idx = i;
- return vs_p[i].strptr;
- }
+ if (vs_p[i].value == val)
+ return &(vs_p[i]);
}
- *idx = -1;
return NULL;
}
-static const gchar *
-_match_strval_index(const guint32 val, const value_string_ext *vse, gint *idx)
+static const value_string *
+_match_strval_index(const guint32 val, const value_string_ext *vse)
{
guint i;
i = val - vse->_vs_first_value;
if (i < vse->_vs_num_entries) {
g_assert (val == vse->_vs_p[i].value);
- *idx = i;
- return vse->_vs_p[i].strptr;
+ return &(vse->_vs_p[i]);
}
- *idx = -1;
return NULL;
}
-static const gchar *
-_match_strval_bsearch(const guint32 val, const value_string_ext *vse, gint *idx)
+static const value_string *
+_match_strval_bsearch(const guint32 val, const value_string_ext *vse)
{
guint low, i, max;
guint32 item;
@@ -248,12 +251,9 @@ _match_strval_bsearch(const guint32 val, const value_string_ext *vse, gint *idx)
max = i;
else if (val > item)
low = i + 1;
- else{
- *idx = i;
- return vse->_vs_p[i].strptr;
- }
+ else
+ return &(vse->_vs_p[i]);
}
- *idx = -1;
return NULL;
}
@@ -265,8 +265,8 @@ _match_strval_bsearch(const guint32 val, const value_string_ext *vse, gint *idx)
- Verify that the value_string array is terminated
by {0, NULL};
*/
-const gchar *
-_match_strval_ext_init(const guint32 val, const value_string_ext *a_vse, gint *idx)
+const value_string *
+_match_strval_ext_init(const guint32 val, const value_string_ext *a_vse)
{
/* Cast away the constness!
* It's better if the prototype for this function matches the other
@@ -313,42 +313,42 @@ _match_strval_ext_init(const guint32 val, const value_string_ext *a_vse, gint *i
switch (type) {
case VS_SEARCH:
- vse->_vs_match = _match_strval_linear;
+ vse->_vs_match2 = _match_strval_linear;
break;
case VS_BIN_TREE:
- vse->_vs_match = _match_strval_bsearch;
+ vse->_vs_match2 = _match_strval_bsearch;
break;
case VS_INDEX:
- vse->_vs_match = _match_strval_index;
+ vse->_vs_match2 = _match_strval_index;
break;
default:
g_assert_not_reached();
break;
}
- return vse->_vs_match(val, vse, idx);
+ return vse->_vs_match2(val, vse);
}
/* (Fcns for use by proto_registrar_dump_values() [See proto.c]) */
gboolean
-value_string_ext_validate(value_string_ext *vse) {
+value_string_ext_validate(const value_string_ext *vse) {
if (vse == NULL)
return FALSE;
- if ((vse->_vs_match == _match_strval_ext_init) ||
- (vse->_vs_match == _match_strval_linear) ||
- (vse->_vs_match == _match_strval_bsearch) ||
- (vse->_vs_match == _match_strval_index))
+ if ((vse->_vs_match2 == _match_strval_ext_init) ||
+ (vse->_vs_match2 == _match_strval_linear) ||
+ (vse->_vs_match2 == _match_strval_bsearch) ||
+ (vse->_vs_match2 == _match_strval_index))
return TRUE;
return FALSE;
}
-gchar *
-value_string_ext_match_type_str(value_string_ext *vse) {
- if (vse->_vs_match == _match_strval_linear)
+const gchar *
+value_string_ext_match_type_str(const value_string_ext *vse) {
+ if (vse->_vs_match2 == _match_strval_linear)
return "[Linear Search]";
- if (vse->_vs_match == _match_strval_bsearch)
+ if (vse->_vs_match2 == _match_strval_bsearch)
return "[Binary Search]";
- if (vse->_vs_match == _match_strval_index)
+ if (vse->_vs_match2 == _match_strval_index)
return "[Direct (indexed) Access]";
return "[Match Type not initialized or invalid]";
}
diff --git a/epan/value_string.h b/epan/value_string.h
index bfdc0d6b14..e47fcd44c4 100644
--- a/epan/value_string.h
+++ b/epan/value_string.h
@@ -115,10 +115,10 @@ extern const gchar* str_to_str(const gchar *val, const string_string *vs, const
*/
/* --------------------------------------------------------------------*/
struct _value_string_ext;
-typedef const char *(*_value_string_match_t)(const guint32, const struct _value_string_ext *, gint *idx);
+typedef const value_string *(*_value_string_match2_t)(const guint32, const struct _value_string_ext *);
typedef struct _value_string_ext {
- _value_string_match_t _vs_match;
+ _value_string_match2_t _vs_match2;
guint32 _vs_first_value; /* first value of the value_string array */
guint _vs_num_entries; /* number of entries in the value_string array */
/* (excluding final {0, NULL}) */
@@ -132,12 +132,12 @@ typedef struct _value_string_ext {
#define VALUE_STRING_EXT_VS_NAME(x) (x)->_vs_name
/* (Fcns for use by proto_registrar_dump_values() [See proto.c]) */
-gboolean value_string_ext_validate(value_string_ext *vse);
-gchar *value_string_ext_match_type_str(value_string_ext *vse);
+gboolean value_string_ext_validate(const value_string_ext *vse);
+const gchar *value_string_ext_match_type_str(const value_string_ext *vse);
/* --- --- */
-extern const gchar *_match_strval_ext_init(const guint32 val, const value_string_ext *vse, gint *idx);
-#define VALUE_STRING_EXT_INIT(x) { (_value_string_match_t) _match_strval_ext_init, 0, array_length(x)-1, x, #x }
+extern const value_string *_match_strval_ext_init(const guint32 val, const value_string_ext *vse);
+#define VALUE_STRING_EXT_INIT(x) { _match_strval_ext_init, 0, array_length(x)-1, x, #x }
/* Create a value_string_ext given a ptr to a value_string array and the total number of entries. */
/* Note: vs_tot_num_entries should include the required {0, NULL} terminating entry of the array. */