summaryrefslogtreecommitdiffstats
path: root/src/utils_arg_macros.h
blob: eba0ecac885b4160db94fefabb90220698835e91 (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
/*
 * Command line arguments parsing helpers
 *
 * Copyright (C) 2020-2024 Red Hat, Inc. All rights reserved.
 * Copyright (C) 2020-2024 Ondrej Kozina
 *
 * 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 UTILS_ARG_MACROS_H
#define UTILS_ARG_MACROS_H

#include <assert.h>

#define ARG_SET(X) !!tool_core_args[(X)].set

#define ARG_STR(X) ({ \
	assert(tool_core_args[(X)].type == CRYPT_ARG_STRING); \
	tool_core_args[(X)].u.str_value; \
})

#define ARG_INT32(X) ({ \
	assert(tool_core_args[(X)].type == CRYPT_ARG_INT32); \
	tool_core_args[(X)].u.i32_value; \
})

#define ARG_UINT32(X) ({ \
	assert(tool_core_args[(X)].type == CRYPT_ARG_UINT32); \
	tool_core_args[(X)].u.u32_value; \
})

#define ARG_INT64(X) ({ \
	assert(tool_core_args[(X)].type == CRYPT_ARG_INT64); \
	tool_core_args[(X)].u.i64_value; \
})

#define ARG_UINT64(X) ({ \
	assert(tool_core_args[(X)].type == CRYPT_ARG_UINT64); \
	tool_core_args[(X)].u.u64_value; \
})

#define ARG_SET_TRUE(X) do { \
        tool_core_args[(X)].set = true; \
} while (0)

#define ARG_SET_STR(X, Y) \
do { \
	char *str; \
	assert(tool_core_args[(X)].set == false && tool_core_args[(X)].type == CRYPT_ARG_STRING); \
	str = (Y); \
	assert(str != NULL); \
	tool_core_args[(X)].u.str_value = str; \
	tool_core_args[(X)].set = true; \
} while (0)

#define ARG_SET_INT32(X, Y) \
do { \
	assert(tool_core_args[(X)].set == false && tool_core_args[(X)].type == CRYPT_ARG_INT32); \
	tool_core_args[(X)].u.i32_value = (Y); \
	tool_core_args[(X)].set = true; \
} while (0)

#define ARG_SET_UINT32(X, Y) \
do { \
	assert(tool_core_args[(X)].set == false && tool_core_args[(X)].type == CRYPT_ARG_UINT32); \
	tool_core_args[(X)].u.u32_value = (Y); \
	tool_core_args[(X)].set = true; \
} while (0)

#define ARG_SET_INT64(X, Y) \
do { \
	assert(tool_core_args[(X)].set == false && tool_core_args[(X)].type == CRYPT_ARG_INT64); \
	tool_core_args[(X)].u.i64_value = (Y); \
	tool_core_args[(X)].set = true; \
} while (0)

#define ARG_SET_UINT64(X, Y) \
do { \
	assert(tool_core_args[(X)].set == false && tool_core_args[(X)].type == CRYPT_ARG_UINT64); \
	tool_core_args[(X)].u.u64_value = (Y); \
	tool_core_args[(X)].set = true; \
} while (0)


#define ARG_INIT_ALIAS(X) \
do { \
	assert(tool_core_args[(X)].type == CRYPT_ARG_ALIAS); \
	tool_core_args[(X)].u.o.ptr = &tool_core_args[tool_core_args[(X)].u.o.id]; \
} while (0)

#endif