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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #ifndef __VALUE_STRING_H__
26 #define __VALUE_STRING_H__
29 #include "ws_symbol_export.h"
31 /* VALUE TO STRING MATCHING */
33 typedef struct _value_string
{
40 val_to_str(const guint32 val
, const value_string
*vs
, const char *fmt
);
44 val_to_str_const(const guint32 val
, const value_string
*vs
, const char *unknown_str
);
48 try_val_to_str(const guint32 val
, const value_string
*vs
);
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
{
63 val64_to_str(const guint64 val
, const val64_string
*vs
, const char *fmt
);
67 val64_to_str_const(const guint64 val
, const val64_string
*vs
, const char *unknown_str
);
71 try_val64_to_str(const guint64 val
, const val64_string
*vs
);
75 try_val64_to_str_idx(const guint64 val
, const val64_string
*vs
, gint
*idx
);
77 /* STRING TO VALUE MATCHING */
81 str_to_val(const gchar
*val
, const value_string
*vs
, const guint32 err_val
);
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) */
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
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 }
112 value_string_ext_new(value_string
*vs
, guint vs_tot_num_entries
, const gchar
*vs_name
);
116 val_to_str_ext(const guint32 val
, const value_string_ext
*vs
, const char *fmt
);
120 val_to_str_ext_const(const guint32 val
, const value_string_ext
*vs
, const char *unknown_str
);
124 try_val_to_str_ext(const guint32 val
, const value_string_ext
*vse
);
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
{
139 str_to_str(const gchar
*val
, const string_string
*vs
, const char *fmt
);
143 try_str_to_str(const gchar
*val
, const string_string
*vs
);
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
{
159 rval_to_str(const guint32 val
, const range_string
*rs
, const char *fmt
);
163 rval_to_str_const(const guint32 val
, const range_string
*rs
, const char *unknown_str
);
167 try_rval_to_str(const guint32 val
, const range_string
*rs
);
171 try_rval_to_str_idx(const guint32 val
, const range_string
*rs
, gint
*idx
);
173 /* MISC (generally do not use) */
177 value_string_ext_validate(const value_string_ext
*vse
);
181 value_string_ext_match_type_str(const value_string_ext
*vse
);
183 #endif /* __VALUE_STRING_H__ */