From Didier Gautheron via bug 3052:
[obnox/wireshark/wip.git] / epan / value_string.h
1 /* value_string.h
2  * Definitions for value_string structures and routines
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
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.
14  *
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.
19  *
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.
23  */
24
25 #ifndef __VALUE_STRING_H__
26 #define __VALUE_STRING_H__
27
28 #include <glib.h>
29
30 /* Struct for the val_to_str, match_strval_idx, and match_strval functions */
31
32 typedef struct _value_string {
33   guint32  value;
34   const gchar   *strptr;
35 } value_string;
36
37 /* Struct for the str_to_str, match_strstr_idx, and match_strstr functions */
38
39 typedef struct _string_string {
40   const gchar   *value;
41   const gchar   *strptr;
42 } string_string;
43
44 /* Struct for the rval_to_str, match_strrval_idx, and match_strrval functions */
45 typedef struct _range_string {
46   guint32        value_min;
47   guint32        value_max;
48   const gchar   *strptr;
49 } range_string;
50
51 /* #define VS_DEF(x) { x, #x } */
52 /* #define VS_END    { 0, NULL } */
53
54 /* Tries to match val against each element in the value_string array vs.
55    Returns the associated string ptr, and sets "*idx" to the index in
56    that table, on a match, and returns NULL, and sets "*idx" to -1,
57    on failure. */
58 extern const gchar* match_strval_idx(guint32 val, const value_string *vs, gint *idx);
59
60 /* Like match_strval_idx(), but doesn't return the index. */
61 extern const gchar* match_strval(guint32 val, const value_string *vs);
62
63 /* Tries to match val against each element in the value_string array vs.
64    Returns the associated string ptr on a match.
65    Formats val with fmt, and returns the resulting string, on failure. */
66 extern const gchar* val_to_str(guint32 val, const value_string *vs, const char *fmt);
67
68 /* Tries to match val against each element in the value_string array vs.
69    Returns the associated string ptr, and sets "*idx" to the index in
70    that table, on a match, and returns NULL, and sets "*idx" to -1,
71    on failure. */
72 extern const gchar* match_strstr_idx(const gchar *val, const string_string *vs, gint *idx);
73
74 /* Like match_strval_idx(), but doesn't return the index. */
75 extern const gchar* match_strstr(const gchar *val, const string_string *vs);
76
77 /* Tries to match val against each element in the value_string array vs.
78    Returns the associated string ptr on a match.
79    Formats val with fmt, and returns the resulting string, on failure. */
80 extern const gchar* str_to_str(const gchar *val, const string_string *vs, const char *fmt);
81
82 /* Generate a string describing an enumerated bitfield (an N-bit field
83    with various specific values having particular names). */
84 extern const char *decode_enumerated_bitfield(guint32 val, guint32 mask,
85   int width, const value_string *tab, const char *fmt);
86
87 /* Generate a string describing an enumerated bitfield (an N-bit field
88    with various specific values having particular names). */
89 extern const char *decode_enumerated_bitfield_shifted(guint32 val, guint32 mask,
90   int width, const value_string *tab, const char *fmt);
91
92
93 /* ranges aware versions */
94
95 /* Tries to match val against each range in the range_string array rs.
96    Returns the associated string ptr on a match.
97    Formats val with fmt, and returns the resulting string, on failure. */
98 extern const gchar* rval_to_str(guint32 val, const range_string *rs, const char *fmt);
99
100 /* Tries to match val against each range in the range_string array rs.
101    Returns the associated string ptr, and sets "*idx" to the index in
102    that table, on a match, and returns NULL, and sets "*idx" to -1,
103    on failure. */
104 extern const gchar *match_strrval_idx(guint32 val, const range_string *rs, gint *idx);
105
106 /* Like match_strrval_idx(), but doesn't return the index. */
107 extern const gchar *match_strrval(guint32 val, const range_string *rs);
108
109 #endif /* __VALUE_STRING_H__ */