xref: /freebsd/contrib/bc/include/status.h (revision 10328f8b)
1252884aeSStefan Eßer /*
2252884aeSStefan Eßer  * *****************************************************************************
3252884aeSStefan Eßer  *
43aa99676SStefan Eßer  * SPDX-License-Identifier: BSD-2-Clause
5252884aeSStefan Eßer  *
610328f8bSStefan Eßer  * Copyright (c) 2018-2021 Gavin D. Howard and contributors.
7252884aeSStefan Eßer  *
8252884aeSStefan Eßer  * Redistribution and use in source and binary forms, with or without
9252884aeSStefan Eßer  * modification, are permitted provided that the following conditions are met:
10252884aeSStefan Eßer  *
11252884aeSStefan Eßer  * * Redistributions of source code must retain the above copyright notice, this
12252884aeSStefan Eßer  *   list of conditions and the following disclaimer.
13252884aeSStefan Eßer  *
14252884aeSStefan Eßer  * * Redistributions in binary form must reproduce the above copyright notice,
15252884aeSStefan Eßer  *   this list of conditions and the following disclaimer in the documentation
16252884aeSStefan Eßer  *   and/or other materials provided with the distribution.
17252884aeSStefan Eßer  *
18252884aeSStefan Eßer  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19252884aeSStefan Eßer  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20252884aeSStefan Eßer  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21252884aeSStefan Eßer  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22252884aeSStefan Eßer  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23252884aeSStefan Eßer  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24252884aeSStefan Eßer  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25252884aeSStefan Eßer  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26252884aeSStefan Eßer  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27252884aeSStefan Eßer  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28252884aeSStefan Eßer  * POSSIBILITY OF SUCH DAMAGE.
29252884aeSStefan Eßer  *
30252884aeSStefan Eßer  * *****************************************************************************
31252884aeSStefan Eßer  *
32252884aeSStefan Eßer  * All bc status codes.
33252884aeSStefan Eßer  *
34252884aeSStefan Eßer  */
35252884aeSStefan Eßer 
36252884aeSStefan Eßer #ifndef BC_STATUS_H
37252884aeSStefan Eßer #define BC_STATUS_H
38252884aeSStefan Eßer 
39252884aeSStefan Eßer #include <stdint.h>
40252884aeSStefan Eßer 
41252884aeSStefan Eßer #ifndef BC_ENABLED
42252884aeSStefan Eßer #define BC_ENABLED (1)
43252884aeSStefan Eßer #endif // BC_ENABLED
44252884aeSStefan Eßer 
45252884aeSStefan Eßer #ifndef DC_ENABLED
46252884aeSStefan Eßer #define DC_ENABLED (1)
47252884aeSStefan Eßer #endif // DC_ENABLED
48252884aeSStefan Eßer 
4910328f8bSStefan Eßer #if BC_ENABLE_AFL
5010328f8bSStefan Eßer #ifndef __AFL_HAVE_MANUAL_CONTROL
5110328f8bSStefan Eßer #error Must compile with afl-clang-fast for fuzzing
5210328f8bSStefan Eßer #endif // __AFL_HAVE_MANUAL_CONTROL
5310328f8bSStefan Eßer #endif // BC_ENABLE_AFL
5410328f8bSStefan Eßer 
5510328f8bSStefan Eßer #ifndef BC_ENABLE_MEMCHECK
5610328f8bSStefan Eßer #define BC_ENABLE_MEMCHECK (0)
5710328f8bSStefan Eßer #endif // BC_ENABLE_MEMCHECK
5810328f8bSStefan Eßer 
5950696a6eSStefan Eßer #include <bcl.h>
6050696a6eSStefan Eßer 
61252884aeSStefan Eßer typedef enum BcStatus {
62252884aeSStefan Eßer 
63252884aeSStefan Eßer 	BC_STATUS_SUCCESS = 0,
64252884aeSStefan Eßer 	BC_STATUS_ERROR_MATH,
65252884aeSStefan Eßer 	BC_STATUS_ERROR_PARSE,
66252884aeSStefan Eßer 	BC_STATUS_ERROR_EXEC,
67252884aeSStefan Eßer 	BC_STATUS_ERROR_FATAL,
68252884aeSStefan Eßer 	BC_STATUS_EOF,
69252884aeSStefan Eßer 	BC_STATUS_QUIT,
70252884aeSStefan Eßer 
71252884aeSStefan Eßer } BcStatus;
72252884aeSStefan Eßer 
7350696a6eSStefan Eßer typedef enum BcErr {
74252884aeSStefan Eßer 
7550696a6eSStefan Eßer 	BC_ERR_MATH_NEGATIVE,
7650696a6eSStefan Eßer 	BC_ERR_MATH_NON_INTEGER,
7750696a6eSStefan Eßer 	BC_ERR_MATH_OVERFLOW,
7850696a6eSStefan Eßer 	BC_ERR_MATH_DIVIDE_BY_ZERO,
79252884aeSStefan Eßer 
8050696a6eSStefan Eßer 	BC_ERR_FATAL_ALLOC_ERR,
8150696a6eSStefan Eßer 	BC_ERR_FATAL_IO_ERR,
8250696a6eSStefan Eßer 	BC_ERR_FATAL_FILE_ERR,
8350696a6eSStefan Eßer 	BC_ERR_FATAL_BIN_FILE,
8450696a6eSStefan Eßer 	BC_ERR_FATAL_PATH_DIR,
8550696a6eSStefan Eßer 	BC_ERR_FATAL_OPTION,
8650696a6eSStefan Eßer 	BC_ERR_FATAL_OPTION_NO_ARG,
8750696a6eSStefan Eßer 	BC_ERR_FATAL_OPTION_ARG,
88252884aeSStefan Eßer 
8950696a6eSStefan Eßer 	BC_ERR_EXEC_IBASE,
9050696a6eSStefan Eßer 	BC_ERR_EXEC_OBASE,
9150696a6eSStefan Eßer 	BC_ERR_EXEC_SCALE,
9250696a6eSStefan Eßer 	BC_ERR_EXEC_READ_EXPR,
9350696a6eSStefan Eßer 	BC_ERR_EXEC_REC_READ,
9450696a6eSStefan Eßer 	BC_ERR_EXEC_TYPE,
95252884aeSStefan Eßer 
9650696a6eSStefan Eßer 	BC_ERR_EXEC_STACK,
97252884aeSStefan Eßer 
9850696a6eSStefan Eßer 	BC_ERR_EXEC_PARAMS,
9950696a6eSStefan Eßer 	BC_ERR_EXEC_UNDEF_FUNC,
10050696a6eSStefan Eßer 	BC_ERR_EXEC_VOID_VAL,
101252884aeSStefan Eßer 
10250696a6eSStefan Eßer 	BC_ERR_PARSE_EOF,
10350696a6eSStefan Eßer 	BC_ERR_PARSE_CHAR,
10450696a6eSStefan Eßer 	BC_ERR_PARSE_STRING,
10550696a6eSStefan Eßer 	BC_ERR_PARSE_COMMENT,
10650696a6eSStefan Eßer 	BC_ERR_PARSE_TOKEN,
107252884aeSStefan Eßer #if BC_ENABLED
10850696a6eSStefan Eßer 	BC_ERR_PARSE_EXPR,
10950696a6eSStefan Eßer 	BC_ERR_PARSE_EMPTY_EXPR,
11050696a6eSStefan Eßer 	BC_ERR_PARSE_PRINT,
11150696a6eSStefan Eßer 	BC_ERR_PARSE_FUNC,
11250696a6eSStefan Eßer 	BC_ERR_PARSE_ASSIGN,
11350696a6eSStefan Eßer 	BC_ERR_PARSE_NO_AUTO,
11450696a6eSStefan Eßer 	BC_ERR_PARSE_DUP_LOCAL,
11550696a6eSStefan Eßer 	BC_ERR_PARSE_BLOCK,
11650696a6eSStefan Eßer 	BC_ERR_PARSE_RET_VOID,
11750696a6eSStefan Eßer 	BC_ERR_PARSE_REF_VAR,
118252884aeSStefan Eßer 
11950696a6eSStefan Eßer 	BC_ERR_POSIX_NAME_LEN,
12050696a6eSStefan Eßer 	BC_ERR_POSIX_COMMENT,
12150696a6eSStefan Eßer 	BC_ERR_POSIX_KW,
12250696a6eSStefan Eßer 	BC_ERR_POSIX_DOT,
12350696a6eSStefan Eßer 	BC_ERR_POSIX_RET,
12450696a6eSStefan Eßer 	BC_ERR_POSIX_BOOL,
12550696a6eSStefan Eßer 	BC_ERR_POSIX_REL_POS,
12650696a6eSStefan Eßer 	BC_ERR_POSIX_MULTIREL,
12750696a6eSStefan Eßer 	BC_ERR_POSIX_FOR,
12850696a6eSStefan Eßer 	BC_ERR_POSIX_EXP_NUM,
12950696a6eSStefan Eßer 	BC_ERR_POSIX_REF,
13050696a6eSStefan Eßer 	BC_ERR_POSIX_VOID,
13150696a6eSStefan Eßer 	BC_ERR_POSIX_BRACE,
132252884aeSStefan Eßer #endif // BC_ENABLED
133252884aeSStefan Eßer 
13450696a6eSStefan Eßer 	BC_ERR_NELEMS,
135252884aeSStefan Eßer 
136252884aeSStefan Eßer #if BC_ENABLED
13750696a6eSStefan Eßer 	BC_ERR_POSIX_START = BC_ERR_POSIX_NAME_LEN,
13850696a6eSStefan Eßer 	BC_ERR_POSIX_END = BC_ERR_POSIX_BRACE,
139252884aeSStefan Eßer #endif // BC_ENABLED
140252884aeSStefan Eßer 
14150696a6eSStefan Eßer } BcErr;
142252884aeSStefan Eßer 
143252884aeSStefan Eßer #define BC_ERR_IDX_MATH (0)
144252884aeSStefan Eßer #define BC_ERR_IDX_PARSE (1)
145252884aeSStefan Eßer #define BC_ERR_IDX_EXEC (2)
146252884aeSStefan Eßer #define BC_ERR_IDX_FATAL (3)
147252884aeSStefan Eßer #define BC_ERR_IDX_NELEMS (4)
148252884aeSStefan Eßer 
149252884aeSStefan Eßer #if BC_ENABLED
150252884aeSStefan Eßer #define BC_ERR_IDX_WARN (BC_ERR_IDX_NELEMS)
151252884aeSStefan Eßer #endif // BC_ENABLED
152252884aeSStefan Eßer 
153252884aeSStefan Eßer #define BC_UNUSED(e) ((void) (e))
154252884aeSStefan Eßer 
155252884aeSStefan Eßer #ifndef BC_LIKELY
156252884aeSStefan Eßer #define BC_LIKELY(e) (e)
157252884aeSStefan Eßer #endif // BC_LIKELY
158252884aeSStefan Eßer 
159252884aeSStefan Eßer #ifndef BC_UNLIKELY
160252884aeSStefan Eßer #define BC_UNLIKELY(e) (e)
161252884aeSStefan Eßer #endif // BC_UNLIKELY
162252884aeSStefan Eßer 
163252884aeSStefan Eßer #define BC_ERR(e) BC_UNLIKELY(e)
164252884aeSStefan Eßer #define BC_NO_ERR(s) BC_LIKELY(s)
165252884aeSStefan Eßer 
166252884aeSStefan Eßer #ifndef BC_DEBUG_CODE
167252884aeSStefan Eßer #define BC_DEBUG_CODE (0)
168252884aeSStefan Eßer #endif // BC_DEBUG_CODE
169252884aeSStefan Eßer 
170252884aeSStefan Eßer #if __STDC_VERSION__ >= 201100L
171252884aeSStefan Eßer #include <stdnoreturn.h>
172252884aeSStefan Eßer #define BC_NORETURN _Noreturn
173252884aeSStefan Eßer #else // __STDC_VERSION__
174252884aeSStefan Eßer #define BC_NORETURN
175252884aeSStefan Eßer #define BC_MUST_RETURN
176252884aeSStefan Eßer #endif // __STDC_VERSION__
177252884aeSStefan Eßer 
17850696a6eSStefan Eßer #if defined(__clang__) || defined(__GNUC__)
179e458944cSStefan Eßer #if defined(__has_attribute) && __has_attribute(fallthrough)
18050696a6eSStefan Eßer #define BC_FALLTHROUGH __attribute__((fallthrough));
181e458944cSStefan Eßer #else // defined(__has_attribute) && __has_attribute(fallthrough)
182e458944cSStefan Eßer #define BC_FALLTHROUGH
183e458944cSStefan Eßer #endif // defined(__has_attribute) && __has_attribute(fallthrough)
18450696a6eSStefan Eßer #else // defined(__clang__) || defined(__GNUC__)
18550696a6eSStefan Eßer #define BC_FALLTHROUGH
18650696a6eSStefan Eßer #endif // defined(__clang__) || defined(__GNUC__)
18750696a6eSStefan Eßer 
188252884aeSStefan Eßer // Workarounds for AIX's POSIX incompatibility.
189252884aeSStefan Eßer #ifndef SIZE_MAX
190252884aeSStefan Eßer #define SIZE_MAX __SIZE_MAX__
191252884aeSStefan Eßer #endif // SIZE_MAX
192252884aeSStefan Eßer #ifndef UINTMAX_C
193252884aeSStefan Eßer #define UINTMAX_C __UINTMAX_C
194252884aeSStefan Eßer #endif // UINTMAX_C
195252884aeSStefan Eßer #ifndef UINT32_C
196252884aeSStefan Eßer #define UINT32_C __UINT32_C
197252884aeSStefan Eßer #endif // UINT32_C
198252884aeSStefan Eßer #ifndef UINT_FAST32_MAX
199252884aeSStefan Eßer #define UINT_FAST32_MAX __UINT_FAST32_MAX__
200252884aeSStefan Eßer #endif // UINT_FAST32_MAX
201252884aeSStefan Eßer #ifndef UINT16_MAX
202252884aeSStefan Eßer #define UINT16_MAX __UINT16_MAX__
203252884aeSStefan Eßer #endif // UINT16_MAX
204252884aeSStefan Eßer #ifndef SIG_ATOMIC_MAX
205252884aeSStefan Eßer #define SIG_ATOMIC_MAX __SIG_ATOMIC_MAX__
206252884aeSStefan Eßer #endif // SIG_ATOMIC_MAX
207252884aeSStefan Eßer 
208252884aeSStefan Eßer #endif // BC_STATUS_H
209