3 * Definitions for parameter handling routines
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
16 * Definition of a value for an enumerated type.
18 * "name" is the name one would use on the command line for the value.
19 * "description" is the description of the value, used in combo boxes/
21 * "value" is the value.
25 const char *description
;
29 /* ----- Public enum_val_t "Helper" macros ----- */
31 * Reuse the macro format of the list of value strings (that is used by value_string.h
32 * for generating definitions of enum and/or value strings array) to generating
33 * enum_val_t array. For example, there is a macro of a value strings list like:
35 * #define foo_VALUE_STRING_LIST(XXX) \
36 * XXX( FOO_A, 1, "aaa" ) \
37 * XXX( FOO_B, 3, "bbb" )
39 * The code VS_LIST_TO_ENUM_VAL_T_ARRAY_STATIC(foo, foo_ev); will define a static enum_val_t array:
41 * static const enum_val_t foo_ev[] = {
42 * { "aaa", "aaa", 1 },
43 * { "bbb", "bbb", 3 },
47 * The code VS_LIST_TO_ENUM_VAL_T_ARRAY_GLOBAL_DEF(foo, foo_ev); will define a global enum_val_t array:
49 * const enum_val_t foo_ev[] = {
50 * { "aaa", "aaa", 1 },
51 * { "bbb", "bbb", 3 },
55 * The code VS_LIST_TO_ENUM_VAL_T_ARRAY_GLOBAL_DCL(foo_ev); will declare a extern enum_val_t array:
57 * extern const enum_val_t foo_ev[];
59 #define VS_LIST_TO_ENUM_VAL_T_ARRAY_STATIC( array_name, new_array_name) static _EV_ARRAY_XXX(array_name, new_array_name, _VALUE_STRING_LIST, _EV_ARRAY_ENTRY_FROM_VS)
60 #define VS_LIST_TO_ENUM_VAL_T_ARRAY_GLOBAL_DEF(array_name, new_array_name) _EV_ARRAY_XXX(array_name, new_array_name, _VALUE_STRING_LIST, _EV_ARRAY_ENTRY_FROM_VS)
61 #define VS_LIST_TO_ENUM_VAL_T_ARRAY_GLOBAL_DCL(new_array_name) extern const enum_val_t new_array_name[]
64 * Provide the capability to define a list of enum_val_t(s) once and
65 * then to expand the list as an enum and/or as a enum_val_t array.:
67 * #define foo2_ENUM_VAL_T_LIST(XXX) \
68 * XXX( FOO_A, 1, "aaa", "The description of aaa" ) \
69 * XXX( FOO_B, 3, "bbb", "The description of bbb" )
71 * The code ENUM_VAL_T_ENUM(foo2); will define an enumeration type:
78 * Note, you can use code "typedef ENUM_VAL_T_ENUM(foo2) enum_foo_t;" to define a
81 * The code ENUM_VAL_T_ARRAY_STATIC(foo2); will define a static enum_val_t array:
83 * static const enum_val_t foo2[] = {
84 * { "aaa", "The description of aaa", 1 },
85 * { "bbb", "The description of bbb", 3 },
89 * The code ENUM_VAL_T_ARRAY_GLOBAL_DEF(foo2); will define a global enum_val_t array:
91 * const enum_val_t foo2[] = {
92 * { "aaa", "The description of aaa", 1 },
93 * { "bbb", "The description of bbb", 3 },
97 * The code VS_LIST_TO_ENUM_VAL_T_ARRAY_GLOBAL_DCL(foo2); will declare a extern enum_val_t array:
99 * extern const enum_val_t foo2[];
101 #define ENUM_VAL_T_ENUM(array_name) _EV_ENUM_XXX(array_name, _ENUM_VAL_T_LIST, _EV_ENUM_ENTRY)
102 #define ENUM_VAL_T_ARRAY_STATIC( array_name) static _EV_ARRAY_XXX(array_name, array_name, _ENUM_VAL_T_LIST, _EV_ARRAY_ENTRY)
103 #define ENUM_VAL_T_ARRAY_GLOBAL_DEF(array_name) _EV_ARRAY_XXX(array_name, array_name, _ENUM_VAL_T_LIST, _EV_ARRAY_ENTRY)
104 #define ENUM_VAL_T_ARRAY_GLOBAL_DCL(array_name) extern const enum_val_t array_name[]
107 * Reuse the format of enum_val list to create value_string array:
109 * The code ENUM_VAL_T_TO_VS_ARRAY_STATIC(foo2, foo2_vs); will define a static value_string array from an enum_val list:
111 * static const value_string foo2_vs[] = {
117 * The code ENUM_VAL_T_TO_VS_ARRAY_GLOBAL_DEF(foo2, foo2_vs); will define a global value_string array from an enum_val list:
119 * const value_string foo2_vs[] = {
125 * The code ENUM_VAL_T_TO_VS_ARRAY_GLOBAL_DCL(foo2_vs); will declare a extern value_string array from an enum_val list:
127 * extern const value_string foo2_vs[];
129 * The macros ENUM_VAL_T_TO_VS_ARRAY_STATIC2, ENUM_VAL_T_TO_VS_ARRAY_GLOBAL_DEF2 and ENUM_VAL_T_TO_VS_ARRAY_GLOBAL_DCL2
130 * are similar to ENUM_VAL_T_TO_VS_ARRAY_STATIC, ENUM_VAL_T_TO_VS_ARRAY_GLOBAL_DEF and ENUM_VAL_T_TO_VS_ARRAY_GLOBAL_DCL
131 * except that ENUM_VAL_T_TO_VS_ARRAY_XXX(s) uses the 'name' field of enum_val list as the 'string' field of value_string,
132 * and ENUM_VAL_T_TO_VS_ARRAY_XXX2(s) uses the 'enum_name' field.
134 * Similarly, The macros ENUM_VAL_T_TO_VS_ARRAY_XXX3(s) uses the 'description' field of enum_val list as the 'string'
135 * field of value_string.
137 #define ENUM_VAL_T_TO_VS_ARRAY_STATIC( array_name, new_array_name) static _EV_TO_VS_ARRAY_XXX(array_name, new_array_name, _ENUM_VAL_T_LIST, _VS_ARRAY_ENTRY_FROM_EV)
138 #define ENUM_VAL_T_TO_VS_ARRAY_GLOBAL_DEF(array_name, new_array_name) _EV_TO_VS_ARRAY_XXX(array_name, new_array_name, _ENUM_VAL_T_LIST, _VS_ARRAY_ENTRY_FROM_EV)
139 #define ENUM_VAL_T_TO_VS_ARRAY_GLOBAL_DCL(new_array_name) extern const value_string new_array_name[]
141 #define ENUM_VAL_T_TO_VS_ARRAY_STATIC2( array_name, new_array_name) static _EV_TO_VS_ARRAY_XXX(array_name, new_array_name, _ENUM_VAL_T_LIST, _VS_ARRAY_ENTRY_FROM_EV2)
142 #define ENUM_VAL_T_TO_VS_ARRAY_GLOBAL_DEF2(array_name, new_array_name) _EV_TO_VS_ARRAY_XXX(array_name, new_array_name, _ENUM_VAL_T_LIST, _VS_ARRAY_ENTRY_FROM_EV2)
143 #define ENUM_VAL_T_TO_VS_ARRAY_GLOBAL_DCL2(new_array_name) extern const value_string new_array_name[]
145 #define ENUM_VAL_T_TO_VS_ARRAY_STATIC3( array_name, new_array_name) static _EV_TO_VS_ARRAY_XXX(array_name, new_array_name, _ENUM_VAL_T_LIST, _VS_ARRAY_ENTRY_FROM_EV3)
146 #define ENUM_VAL_T_TO_VS_ARRAY_GLOBAL_DEF3(array_name, new_array_name) _EV_TO_VS_ARRAY_XXX(array_name, new_array_name, _ENUM_VAL_T_LIST, _VS_ARRAY_ENTRY_FROM_EV3)
147 #define ENUM_VAL_T_TO_VS_ARRAY_GLOBAL_DCL3(new_array_name) extern const value_string new_array_name[]
149 /* -- Private macros -- */
150 #define _EV_ARRAY_XXX(array_name, new_array_name, array_suffix, macro) \
151 const enum_val_t new_array_name[] = { \
152 array_name##array_suffix(macro) \
156 #define _EV_ARRAY_ENTRY(enum_name, value, name, description) { name, description, value },
157 #define _EV_ARRAY_ENTRY_FROM_VS(enum_name, value, string) { string, string, value },
159 #define _EV_ENUM_XXX(array_name, array_suffix, macro) \
161 array_name##array_suffix(macro) \
162 _##array_name##_ENUM_DUMMY = 0 \
165 #define _EV_ENUM_ENTRY(enum_name, value, name, description) enum_name = value,
167 #define _EV_TO_VS_ARRAY_XXX(array_name, new_array_name, array_suffix, macro) \
168 const value_string new_array_name[] = { \
169 array_name##array_suffix(macro) \
172 #define _VS_ARRAY_ENTRY_FROM_EV(enum_name, value, name, description) { value, name }
173 #define _VS_ARRAY_ENTRY_FROM_EV2(enum_name, value, name, description) { value, #enum_name }
174 #define _VS_ARRAY_ENTRY_FROM_EV3(enum_name, value, name, description) { value, description }
176 #endif /* params.h */