/src/wireshark/epan/params.h
Line | Count | Source |
1 | | /** @file |
2 | | * |
3 | | * Definitions for parameter handling routines |
4 | | * |
5 | | * Wireshark - Network traffic analyzer |
6 | | * By Gerald Combs <gerald@wireshark.org> |
7 | | * Copyright 1998 Gerald Combs |
8 | | * |
9 | | * SPDX-License-Identifier: GPL-2.0-or-later |
10 | | */ |
11 | | |
12 | | #ifndef __PARAMS_H__ |
13 | | #define __PARAMS_H__ |
14 | | |
15 | | /* |
16 | | * Definition of a value for an enumerated type. |
17 | | * |
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/ |
20 | | * option menus. |
21 | | * "value" is the value. |
22 | | */ |
23 | | typedef struct { |
24 | | const char *name; |
25 | | const char *description; |
26 | | int value; |
27 | | } enum_val_t; |
28 | | |
29 | | /* ----- Public enum_val_t "Helper" macros ----- */ |
30 | | /* |
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: |
34 | | * |
35 | | * #define foo_VALUE_STRING_LIST(XXX) \ |
36 | | * XXX( FOO_A, 1, "aaa" ) \ |
37 | | * XXX( FOO_B, 3, "bbb" ) |
38 | | * |
39 | | * The code VS_LIST_TO_ENUM_VAL_T_ARRAY_STATIC(foo, foo_ev); will define a static enum_val_t array: |
40 | | * |
41 | | * static const enum_val_t foo_ev[] = { |
42 | | * { "aaa", "aaa", 1 }, |
43 | | * { "bbb", "bbb", 3 }, |
44 | | * { NULL, NULL, 0 } |
45 | | * }; |
46 | | * |
47 | | * The code VS_LIST_TO_ENUM_VAL_T_ARRAY_GLOBAL_DEF(foo, foo_ev); will define a global enum_val_t array: |
48 | | * |
49 | | * const enum_val_t foo_ev[] = { |
50 | | * { "aaa", "aaa", 1 }, |
51 | | * { "bbb", "bbb", 3 }, |
52 | | * { NULL, NULL, 0 } |
53 | | * }; |
54 | | * |
55 | | * The code VS_LIST_TO_ENUM_VAL_T_ARRAY_GLOBAL_DCL(foo_ev); will declare a extern enum_val_t array: |
56 | | * |
57 | | * extern const enum_val_t foo_ev[]; |
58 | | */ |
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[] |
62 | | |
63 | | /* |
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.: |
66 | | * |
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" ) |
70 | | * |
71 | | * The code ENUM_VAL_T_ENUM(foo2); will define an enumeration type: |
72 | | * |
73 | | * enum { |
74 | | * FOO_A = 1, |
75 | | * FOO_B = 3, |
76 | | * _foo_ENUM_DUMMY = 0 |
77 | | * }; |
78 | | * Note, you can use code "typedef ENUM_VAL_T_ENUM(foo2) enum_foo_t;" to define a |
79 | | * named enumeration. |
80 | | * |
81 | | * The code ENUM_VAL_T_ARRAY_STATIC(foo2); will define a static enum_val_t array: |
82 | | * |
83 | | * static const enum_val_t foo2[] = { |
84 | | * { "aaa", "The description of aaa", 1 }, |
85 | | * { "bbb", "The description of bbb", 3 }, |
86 | | * { NULL, NULL, 0 } |
87 | | * }; |
88 | | * |
89 | | * The code ENUM_VAL_T_ARRAY_GLOBAL_DEF(foo2); will define a global enum_val_t array: |
90 | | * |
91 | | * const enum_val_t foo2[] = { |
92 | | * { "aaa", "The description of aaa", 1 }, |
93 | | * { "bbb", "The description of bbb", 3 }, |
94 | | * { NULL, NULL, 0 } |
95 | | * }; |
96 | | * |
97 | | * The code VS_LIST_TO_ENUM_VAL_T_ARRAY_GLOBAL_DCL(foo2); will declare a extern enum_val_t array: |
98 | | * |
99 | | * extern const enum_val_t foo2[]; |
100 | | */ |
101 | | #define ENUM_VAL_T_ENUM(array_name) _EV_ENUM_XXX(array_name, _ENUM_VAL_T_LIST, _EV_ENUM_ENTRY) |
102 | 32 | #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[] |
105 | | |
106 | | /* |
107 | | * Reuse the format of enum_val list to create value_string array: |
108 | | * |
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: |
110 | | * |
111 | | * static const value_string foo2_vs[] = { |
112 | | * { 1, "aaa" }, |
113 | | * { 3, "bbb" }, |
114 | | * { 0, NULL } |
115 | | * }; |
116 | | * |
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: |
118 | | * |
119 | | * const value_string foo2_vs[] = { |
120 | | * { 1, "aaa" }, |
121 | | * { 3, "bbb" }, |
122 | | * { 0, NULL } |
123 | | * }; |
124 | | * |
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: |
126 | | * |
127 | | * extern const value_string foo2_vs[]; |
128 | | * |
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. |
133 | | * |
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. |
136 | | */ |
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[] |
140 | | |
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[] |
144 | | |
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[] |
148 | | |
149 | | /* -- Private macros -- */ |
150 | | #define _EV_ARRAY_XXX(array_name, new_array_name, array_suffix, macro) \ |
151 | 8 | const enum_val_t new_array_name[] = { \ |
152 | 8 | array_name##array_suffix(macro) \ |
153 | 8 | { NULL, NULL, 0 } \ |
154 | 8 | } |
155 | | |
156 | 32 | #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 }, |
158 | | |
159 | | #define _EV_ENUM_XXX(array_name, array_suffix, macro) \ |
160 | | enum { \ |
161 | | array_name##array_suffix(macro) \ |
162 | | _##array_name##_ENUM_DUMMY = 0 \ |
163 | | } |
164 | | |
165 | | #define _EV_ENUM_ENTRY(enum_name, value, name, description) enum_name = value, |
166 | | |
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) \ |
170 | | { 0, NULL } \ |
171 | | } |
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 } |
175 | | |
176 | | #endif /* params.h */ |
177 | | |