Remove decode_enumerated_bitfield and decode_enumerated_bitfield_shifted.
[metze/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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24
25 #ifndef __VALUE_STRING_H__
26 #define __VALUE_STRING_H__
27
28 #include <glib.h>
29 #include "ws_symbol_export.h"
30
31 /* VALUE TO STRING MATCHING */
32
33 typedef struct _value_string {
34   guint32  value;
35   const gchar   *strptr;
36 } value_string;
37
38 WS_DLL_PUBLIC
39 const gchar*
40 val_to_str(const guint32 val, const value_string *vs, const char *fmt);
41
42 WS_DLL_PUBLIC
43 const gchar*
44 val_to_str_const(const guint32 val, const value_string *vs, const char *unknown_str);
45
46 WS_DLL_PUBLIC
47 const gchar*
48 try_val_to_str(const guint32 val, const value_string *vs);
49
50 WS_DLL_PUBLIC
51 const gchar*
52 try_val_to_str_idx(const guint32 val, const value_string *vs, gint *idx);
53
54 /* EXTENDED VALUE TO STRING MATCHING */
55
56 struct _value_string_ext;
57 typedef const value_string *(*_value_string_match2_t)(const guint32, const struct _value_string_ext *);
58
59 typedef struct _value_string_ext {
60   _value_string_match2_t _vs_match2;
61   guint32 _vs_first_value;    /* first value of the value_string array       */
62   guint   _vs_num_entries;    /* number of entries in the value_string array */
63                               /*  (excluding final {0, NULL})                */
64   const value_string *_vs_p;  /* the value string array address              */
65   const gchar *_vs_name;      /* vse "Name" (for error messages)             */
66 } value_string_ext;
67
68 #define VALUE_STRING_EXT_VS_P(x) (x)->_vs_p
69 #define VALUE_STRING_EXT_VS_NUM_ENTRIES(x) (x)->_vs_num_entries
70 #define VALUE_STRING_EXT_VS_NAME(x) (x)->_vs_name
71
72 WS_DLL_PUBLIC
73 const value_string*
74 _try_val_to_str_ext_init(const guint32 val, const value_string_ext *vse);
75 #define VALUE_STRING_EXT_INIT(x) { _try_val_to_str_ext_init, 0, array_length(x)-1, x, #x }
76
77 WS_DLL_PUBLIC
78 value_string_ext*
79 value_string_ext_new(value_string *vs, guint vs_tot_num_entries, const gchar *vs_name);
80
81 WS_DLL_PUBLIC
82 const gchar*
83 val_to_str_ext(const guint32 val, const value_string_ext *vs, const char *fmt);
84
85 WS_DLL_PUBLIC
86 const gchar*
87 val_to_str_ext_const(const guint32 val, const value_string_ext *vs, const char *unknown_str);
88
89 WS_DLL_PUBLIC
90 const gchar*
91 try_val_to_str_ext(const guint32 val, const value_string_ext *vse);
92
93 WS_DLL_PUBLIC
94 const gchar*
95 try_val_to_str_idx_ext(const guint32 val, value_string_ext *vse, gint *idx);
96
97 /* STRING TO STRING MATCHING */
98
99 typedef struct _string_string {
100   const gchar   *value;
101   const gchar   *strptr;
102 } string_string;
103
104 WS_DLL_PUBLIC
105 const gchar*
106 str_to_str(const gchar *val, const string_string *vs, const char *fmt);
107
108 WS_DLL_PUBLIC
109 const gchar*
110 try_str_to_str(const gchar *val, const string_string *vs);
111
112 WS_DLL_PUBLIC
113 const gchar*
114 try_str_to_str_idx(const gchar *val, const string_string *vs, gint *idx);
115
116 /* RANGE TO STRING MATCHING */
117
118 typedef struct _range_string {
119   guint32        value_min;
120   guint32        value_max;
121   const gchar   *strptr;
122 } range_string;
123
124 WS_DLL_PUBLIC
125 const gchar*
126 rval_to_str(const guint32 val, const range_string *rs, const char *fmt);
127
128 WS_DLL_PUBLIC
129 const gchar*
130 try_rval_to_str(const guint32 val, const range_string *rs);
131
132 WS_DLL_PUBLIC
133 const gchar*
134 try_rval_to_str_idx(const guint32 val, const range_string *rs, gint *idx);
135
136 /* MISC (generally do not use) */
137
138 WS_DLL_LOCAL
139 gboolean
140 value_string_ext_validate(const value_string_ext *vse);
141
142 WS_DLL_LOCAL
143 const gchar*
144 value_string_ext_match_type_str(const value_string_ext *vse);
145
146 #endif /* __VALUE_STRING_H__ */