aboutsummaryrefslogtreecommitdiffstats
path: root/epan/value_string.h
blob: 1759d0dfb19ac25b14105240125cd8c55637194d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/* value_string.h
 * Definitions for value_string structures and routines
 *
 * $Id$
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifndef __VALUE_STRING_H__
#define __VALUE_STRING_H__

#include <glib.h>
#include "ws_symbol_export.h"

/* VALUE TO STRING MATCHING */

typedef struct _value_string {
  guint32  value;
  const gchar   *strptr;
} value_string;

WS_DLL_PUBLIC
const gchar*
val_to_str(const guint32 val, const value_string *vs, const char *fmt);

WS_DLL_PUBLIC
const gchar*
val_to_str_const(const guint32 val, const value_string *vs, const char *unknown_str);

WS_DLL_PUBLIC
const gchar*
try_val_to_str(const guint32 val, const value_string *vs);

WS_DLL_PUBLIC
const gchar*
try_val_to_str_idx(const guint32 val, const value_string *vs, gint *idx);

/* STRING TO VALUE MATCHING */

WS_DLL_PUBLIC
guint32
str_to_val(const gchar *val, const value_string *vs, const guint32 err_val);

WS_DLL_PUBLIC
gint
str_to_val_idx(const gchar *val, const value_string *vs);

/* EXTENDED VALUE TO STRING MATCHING */

struct _value_string_ext;
typedef const value_string *(*_value_string_match2_t)(const guint32, const struct _value_string_ext *);

typedef struct _value_string_ext {
  _value_string_match2_t _vs_match2;
  guint32 _vs_first_value;    /* first value of the value_string array       */
  guint   _vs_num_entries;    /* number of entries in the value_string array */
                              /*  (excluding final {0, NULL})                */
  const value_string *_vs_p;  /* the value string array address              */
  const gchar *_vs_name;      /* vse "Name" (for error messages)             */
} value_string_ext;

#define VALUE_STRING_EXT_VS_P(x) (x)->_vs_p
#define VALUE_STRING_EXT_VS_NUM_ENTRIES(x) (x)->_vs_num_entries
#define VALUE_STRING_EXT_VS_NAME(x) (x)->_vs_name

WS_DLL_PUBLIC
const value_string*
_try_val_to_str_ext_init(const guint32 val, const value_string_ext *vse);
#define VALUE_STRING_EXT_INIT(x) { _try_val_to_str_ext_init, 0, array_length(x)-1, x, #x }

WS_DLL_PUBLIC
value_string_ext*
value_string_ext_new(value_string *vs, guint vs_tot_num_entries, const gchar *vs_name);

WS_DLL_PUBLIC
const gchar*
val_to_str_ext(const guint32 val, const value_string_ext *vs, const char *fmt);

WS_DLL_PUBLIC
const gchar*
val_to_str_ext_const(const guint32 val, const value_string_ext *vs, const char *unknown_str);

WS_DLL_PUBLIC
const gchar*
try_val_to_str_ext(const guint32 val, const value_string_ext *vse);

WS_DLL_PUBLIC
const gchar*
try_val_to_str_idx_ext(const guint32 val, value_string_ext *vse, gint *idx);

/* STRING TO STRING MATCHING */

typedef struct _string_string {
  const gchar   *value;
  const gchar   *strptr;
} string_string;

WS_DLL_PUBLIC
const gchar*
str_to_str(const gchar *val, const string_string *vs, const char *fmt);

WS_DLL_PUBLIC
const gchar*
try_str_to_str(const gchar *val, const string_string *vs);

WS_DLL_PUBLIC
const gchar*
try_str_to_str_idx(const gchar *val, const string_string *vs, gint *idx);

/* RANGE TO STRING MATCHING */

typedef struct _range_string {
  guint32        value_min;
  guint32        value_max;
  const gchar   *strptr;
} range_string;

WS_DLL_PUBLIC
const gchar*
rval_to_str(const guint32 val, const range_string *rs, const char *fmt);

WS_DLL_PUBLIC
const gchar*
try_rval_to_str(const guint32 val, const range_string *rs);

WS_DLL_PUBLIC
const gchar*
try_rval_to_str_idx(const guint32 val, const range_string *rs, gint *idx);

/* MISC (generally do not use) */

WS_DLL_LOCAL
gboolean
value_string_ext_validate(const value_string_ext *vse);

WS_DLL_LOCAL
const gchar*
value_string_ext_match_type_str(const value_string_ext *vse);

#endif /* __VALUE_STRING_H__ */