2 * Definitions for value_string structures and routines
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 #ifndef __VALUE_STRING_H__
26 #define __VALUE_STRING_H__
30 /* Struct for the val_to_str, match_strval_idx, and match_strval functions */
32 typedef struct _value_string {
37 /* Struct for the rval_to_str, match_strrval_idx, and match_strrval functions */
38 typedef struct _range_string {
44 /* #define VS_DEF(x) { x, #x } */
45 /* #define VS_END { 0, NULL } */
47 /* Tries to match val against each element in the value_string array vs.
48 Returns the associated string ptr, and sets "*idx" to the index in
49 that table, on a match, and returns NULL, and sets "*idx" to -1,
51 extern const gchar* match_strval_idx(guint32 val, const value_string *vs, gint *idx);
53 /* Like match_strval_idx(), but doesn't return the index. */
54 extern const gchar* match_strval(guint32 val, const value_string *vs);
56 /* Tries to match val against each element in the value_string array vs.
57 Returns the associated string ptr on a match.
58 Formats val with fmt, and returns the resulting string, on failure. */
59 extern const gchar* val_to_str(guint32 val, const value_string *vs, const char *fmt);
61 /* Generate a string describing an enumerated bitfield (an N-bit field
62 with various specific values having particular names). */
63 extern const char *decode_enumerated_bitfield(guint32 val, guint32 mask,
64 int width, const value_string *tab, const char *fmt);
66 /* Generate a string describing an enumerated bitfield (an N-bit field
67 with various specific values having particular names). */
68 extern const char *decode_enumerated_bitfield_shifted(guint32 val, guint32 mask,
69 int width, const value_string *tab, const char *fmt);
72 /* ranges aware versions */
74 /* Tries to match val against each range in the range_string array rs.
75 Returns the associated string ptr on a match.
76 Formats val with fmt, and returns the resulting string, on failure. */
77 extern const gchar* rval_to_str(guint32 val, const range_string *rs, const char *fmt);
79 /* Tries to match val against each range in the range_string array rs.
80 Returns the associated string ptr, and sets "*idx" to the index in
81 that table, on a match, and returns NULL, and sets "*idx" to -1,
83 extern const gchar *match_strrval_idx(guint32 val, const range_string *rs, gint *idx);
85 /* Like match_strrval_idx(), but doesn't return the index. */
86 extern const gchar *match_strrval(guint32 val, const range_string *rs);
88 #endif /* __VALUE_STRING_H__ */