Witness: add pidl output
[wireshark-wip.git] / epan / value_string.h
blob1155a29ee5909c953866cb8d0333b2ab63d6f910
1 /* value_string.h
2 * Definitions for value_string structures and routines
4 * $Id$
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #ifndef __VALUE_STRING_H__
26 #define __VALUE_STRING_H__
28 #include <glib.h>
29 #include "ws_symbol_export.h"
31 /* VALUE TO STRING MATCHING */
33 typedef struct _value_string {
34 guint32 value;
35 const gchar *strptr;
36 } value_string;
38 WS_DLL_PUBLIC
39 const gchar*
40 val_to_str(const guint32 val, const value_string *vs, const char *fmt);
42 WS_DLL_PUBLIC
43 const gchar*
44 val_to_str_const(const guint32 val, const value_string *vs, const char *unknown_str);
46 WS_DLL_PUBLIC
47 const gchar*
48 try_val_to_str(const guint32 val, const value_string *vs);
50 WS_DLL_PUBLIC
51 const gchar*
52 try_val_to_str_idx(const guint32 val, const value_string *vs, gint *idx);
54 /* 64-BIT VALUE TO STRING MATCHING */
56 typedef struct _val64_string {
57 guint64 value;
58 const gchar *strptr;
59 } val64_string;
61 WS_DLL_PUBLIC
62 const gchar*
63 val64_to_str(const guint64 val, const val64_string *vs, const char *fmt);
65 WS_DLL_PUBLIC
66 const gchar*
67 val64_to_str_const(const guint64 val, const val64_string *vs, const char *unknown_str);
69 WS_DLL_PUBLIC
70 const gchar*
71 try_val64_to_str(const guint64 val, const val64_string *vs);
73 WS_DLL_PUBLIC
74 const gchar*
75 try_val64_to_str_idx(const guint64 val, const val64_string *vs, gint *idx);
77 /* STRING TO VALUE MATCHING */
79 WS_DLL_PUBLIC
80 guint32
81 str_to_val(const gchar *val, const value_string *vs, const guint32 err_val);
83 WS_DLL_PUBLIC
84 gint
85 str_to_val_idx(const gchar *val, const value_string *vs);
87 /* EXTENDED VALUE TO STRING MATCHING */
89 struct _value_string_ext;
90 typedef const value_string *(*_value_string_match2_t)(const guint32, const struct _value_string_ext *);
92 typedef struct _value_string_ext {
93 _value_string_match2_t _vs_match2;
94 guint32 _vs_first_value; /* first value of the value_string array */
95 guint _vs_num_entries; /* number of entries in the value_string array */
96 /* (excluding final {0, NULL}) */
97 const value_string *_vs_p; /* the value string array address */
98 const gchar *_vs_name; /* vse "Name" (for error messages) */
99 } value_string_ext;
101 #define VALUE_STRING_EXT_VS_P(x) (x)->_vs_p
102 #define VALUE_STRING_EXT_VS_NUM_ENTRIES(x) (x)->_vs_num_entries
103 #define VALUE_STRING_EXT_VS_NAME(x) (x)->_vs_name
105 WS_DLL_PUBLIC
106 const value_string*
107 _try_val_to_str_ext_init(const guint32 val, const value_string_ext *vse);
108 #define VALUE_STRING_EXT_INIT(x) { _try_val_to_str_ext_init, 0, array_length(x)-1, x, #x }
110 WS_DLL_PUBLIC
111 value_string_ext*
112 value_string_ext_new(value_string *vs, guint vs_tot_num_entries, const gchar *vs_name);
114 WS_DLL_PUBLIC
115 const gchar*
116 val_to_str_ext(const guint32 val, const value_string_ext *vs, const char *fmt);
118 WS_DLL_PUBLIC
119 const gchar*
120 val_to_str_ext_const(const guint32 val, const value_string_ext *vs, const char *unknown_str);
122 WS_DLL_PUBLIC
123 const gchar*
124 try_val_to_str_ext(const guint32 val, const value_string_ext *vse);
126 WS_DLL_PUBLIC
127 const gchar*
128 try_val_to_str_idx_ext(const guint32 val, value_string_ext *vse, gint *idx);
130 /* STRING TO STRING MATCHING */
132 typedef struct _string_string {
133 const gchar *value;
134 const gchar *strptr;
135 } string_string;
137 WS_DLL_PUBLIC
138 const gchar*
139 str_to_str(const gchar *val, const string_string *vs, const char *fmt);
141 WS_DLL_PUBLIC
142 const gchar*
143 try_str_to_str(const gchar *val, const string_string *vs);
145 WS_DLL_PUBLIC
146 const gchar*
147 try_str_to_str_idx(const gchar *val, const string_string *vs, gint *idx);
149 /* RANGE TO STRING MATCHING */
151 typedef struct _range_string {
152 guint32 value_min;
153 guint32 value_max;
154 const gchar *strptr;
155 } range_string;
157 WS_DLL_PUBLIC
158 const gchar*
159 rval_to_str(const guint32 val, const range_string *rs, const char *fmt);
161 WS_DLL_PUBLIC
162 const gchar *
163 rval_to_str_const(const guint32 val, const range_string *rs, const char *unknown_str);
165 WS_DLL_PUBLIC
166 const gchar*
167 try_rval_to_str(const guint32 val, const range_string *rs);
169 WS_DLL_PUBLIC
170 const gchar*
171 try_rval_to_str_idx(const guint32 val, const range_string *rs, gint *idx);
173 /* MISC (generally do not use) */
175 WS_DLL_LOCAL
176 gboolean
177 value_string_ext_validate(const value_string_ext *vse);
179 WS_DLL_LOCAL
180 const gchar*
181 value_string_ext_match_type_str(const value_string_ext *vse);
183 #endif /* __VALUE_STRING_H__ */