2 * Command line arguments parsing helpers
4 * Copyright (C) 2020-2023 Red Hat, Inc. All rights reserved.
5 * Copyright (C) 2020-2023 Ondrej Kozina
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #ifndef UTILS_ARG_MACROS_H
23 #define UTILS_ARG_MACROS_H
27 #define ARG_SET(X) !!tool_core_args[(X)].set
29 #define ARG_STR(X) ({ \
30 assert(tool_core_args[(X)].type == CRYPT_ARG_STRING); \
31 tool_core_args[(X)].u.str_value; \
34 #define ARG_INT32(X) ({ \
35 assert(tool_core_args[(X)].type == CRYPT_ARG_INT32); \
36 tool_core_args[(X)].u.i32_value; \
39 #define ARG_UINT32(X) ({ \
40 assert(tool_core_args[(X)].type == CRYPT_ARG_UINT32); \
41 tool_core_args[(X)].u.u32_value; \
44 #define ARG_INT64(X) ({ \
45 assert(tool_core_args[(X)].type == CRYPT_ARG_INT64); \
46 tool_core_args[(X)].u.i64_value; \
49 #define ARG_UINT64(X) ({ \
50 assert(tool_core_args[(X)].type == CRYPT_ARG_UINT64); \
51 tool_core_args[(X)].u.u64_value; \
54 #define ARG_SET_TRUE(X) do { \
55 tool_core_args[(X)].set = true; \
58 #define ARG_SET_STR(X, Y) \
61 assert(tool_core_args[(X)].set == false && tool_core_args[(X)].type == CRYPT_ARG_STRING); \
63 assert(str != NULL); \
64 tool_core_args[(X)].u.str_value = str; \
65 tool_core_args[(X)].set = true; \
68 #define ARG_SET_INT32(X, Y) \
70 assert(tool_core_args[(X)].set == false && tool_core_args[(X)].type == CRYPT_ARG_INT32); \
71 tool_core_args[(X)].u.i32_value = (Y); \
72 tool_core_args[(X)].set = true; \
75 #define ARG_SET_UINT32(X, Y) \
77 assert(tool_core_args[(X)].set == false && tool_core_args[(X)].type == CRYPT_ARG_UINT32); \
78 tool_core_args[(X)].u.u32_value = (Y); \
79 tool_core_args[(X)].set = true; \
82 #define ARG_SET_INT64(X, Y) \
84 assert(tool_core_args[(X)].set == false && tool_core_args[(X)].type == CRYPT_ARG_INT64); \
85 tool_core_args[(X)].u.i64_value = (Y); \
86 tool_core_args[(X)].set = true; \
89 #define ARG_SET_UINT64(X, Y) \
91 assert(tool_core_args[(X)].set == false && tool_core_args[(X)].type == CRYPT_ARG_UINT64); \
92 tool_core_args[(X)].u.u64_value = (Y); \
93 tool_core_args[(X)].set = true; \
97 #define ARG_INIT_ALIAS(X) \
99 assert(tool_core_args[(X)].type == CRYPT_ARG_ALIAS); \
100 tool_core_args[(X)].u.o.ptr = &tool_core_args[tool_core_args[(X)].u.o.id]; \