2 * *****************************************************************************
4 * SPDX-License-Identifier: BSD-2-Clause
6 * Copyright (c) 2018-2020 Gavin D. Howard and contributors.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
11 * * Redistributions of source code must retain the above copyright notice, this
12 * list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
30 * *****************************************************************************
32 * All bc status codes.
42 #define BC_ENABLED (1)
46 #define DC_ENABLED (1)
51 typedef enum BcStatus {
53 BC_STATUS_SUCCESS = 0,
55 BC_STATUS_ERROR_PARSE,
57 BC_STATUS_ERROR_FATAL,
66 BC_ERR_MATH_NON_INTEGER,
68 BC_ERR_MATH_DIVIDE_BY_ZERO,
70 BC_ERR_FATAL_ALLOC_ERR,
72 BC_ERR_FATAL_FILE_ERR,
73 BC_ERR_FATAL_BIN_FILE,
74 BC_ERR_FATAL_PATH_DIR,
76 BC_ERR_FATAL_OPTION_NO_ARG,
77 BC_ERR_FATAL_OPTION_ARG,
82 BC_ERR_EXEC_READ_EXPR,
89 BC_ERR_EXEC_UNDEF_FUNC,
99 BC_ERR_PARSE_EMPTY_EXPR,
103 BC_ERR_PARSE_NO_AUTO,
104 BC_ERR_PARSE_DUP_LOCAL,
106 BC_ERR_PARSE_RET_VOID,
107 BC_ERR_PARSE_REF_VAR,
109 BC_ERR_POSIX_NAME_LEN,
110 BC_ERR_POSIX_COMMENT,
115 BC_ERR_POSIX_REL_POS,
116 BC_ERR_POSIX_MULTIREL,
118 BC_ERR_POSIX_EXP_NUM,
127 BC_ERR_POSIX_START = BC_ERR_POSIX_NAME_LEN,
128 BC_ERR_POSIX_END = BC_ERR_POSIX_BRACE,
133 #define BC_ERR_IDX_MATH (0)
134 #define BC_ERR_IDX_PARSE (1)
135 #define BC_ERR_IDX_EXEC (2)
136 #define BC_ERR_IDX_FATAL (3)
137 #define BC_ERR_IDX_NELEMS (4)
140 #define BC_ERR_IDX_WARN (BC_ERR_IDX_NELEMS)
143 #define BC_UNUSED(e) ((void) (e))
146 #define BC_LIKELY(e) (e)
150 #define BC_UNLIKELY(e) (e)
151 #endif // BC_UNLIKELY
153 #define BC_ERR(e) BC_UNLIKELY(e)
154 #define BC_NO_ERR(s) BC_LIKELY(s)
156 #ifndef BC_DEBUG_CODE
157 #define BC_DEBUG_CODE (0)
158 #endif // BC_DEBUG_CODE
160 #if __STDC_VERSION__ >= 201100L
161 #include <stdnoreturn.h>
162 #define BC_NORETURN _Noreturn
163 #else // __STDC_VERSION__
165 #define BC_MUST_RETURN
166 #endif // __STDC_VERSION__
168 #if defined(__clang__) || defined(__GNUC__)
169 #define BC_FALLTHROUGH __attribute__((fallthrough));
170 #else // defined(__clang__) || defined(__GNUC__)
171 #define BC_FALLTHROUGH
172 #endif //defined(__clang__) || defined(__GNUC__)
174 // Workarounds for AIX's POSIX incompatibility.
176 #define SIZE_MAX __SIZE_MAX__
179 #define UINTMAX_C __UINTMAX_C
182 #define UINT32_C __UINT32_C
184 #ifndef UINT_FAST32_MAX
185 #define UINT_FAST32_MAX __UINT_FAST32_MAX__
186 #endif // UINT_FAST32_MAX
188 #define UINT16_MAX __UINT16_MAX__
190 #ifndef SIG_ATOMIC_MAX
191 #define SIG_ATOMIC_MAX __SIG_ATOMIC_MAX__
192 #endif // SIG_ATOMIC_MAX
194 #endif // BC_STATUS_H