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)
49 typedef enum BcStatus {
51 BC_STATUS_SUCCESS = 0,
53 BC_STATUS_ERROR_PARSE,
55 BC_STATUS_ERROR_FATAL,
61 typedef enum BcError {
63 BC_ERROR_MATH_NEGATIVE,
64 BC_ERROR_MATH_NON_INTEGER,
65 BC_ERROR_MATH_OVERFLOW,
66 BC_ERROR_MATH_DIVIDE_BY_ZERO,
68 BC_ERROR_FATAL_ALLOC_ERR,
69 BC_ERROR_FATAL_IO_ERR,
70 BC_ERROR_FATAL_FILE_ERR,
71 BC_ERROR_FATAL_BIN_FILE,
72 BC_ERROR_FATAL_PATH_DIR,
73 BC_ERROR_FATAL_OPTION,
74 BC_ERROR_FATAL_OPTION_NO_ARG,
75 BC_ERROR_FATAL_OPTION_ARG,
80 BC_ERROR_EXEC_READ_EXPR,
81 BC_ERROR_EXEC_REC_READ,
87 BC_ERROR_EXEC_UNDEF_FUNC,
88 BC_ERROR_EXEC_VOID_VAL,
92 BC_ERROR_PARSE_STRING,
93 BC_ERROR_PARSE_COMMENT,
97 BC_ERROR_PARSE_EMPTY_EXPR,
100 BC_ERROR_PARSE_ASSIGN,
101 BC_ERROR_PARSE_NO_AUTO,
102 BC_ERROR_PARSE_DUP_LOCAL,
103 BC_ERROR_PARSE_BLOCK,
104 BC_ERROR_PARSE_RET_VOID,
105 BC_ERROR_PARSE_REF_VAR,
107 BC_ERROR_POSIX_NAME_LEN,
108 BC_ERROR_POSIX_COMMENT,
113 BC_ERROR_POSIX_REL_POS,
114 BC_ERROR_POSIX_MULTIREL,
116 BC_ERROR_POSIX_EXP_NUM,
119 BC_ERROR_POSIX_BRACE,
125 BC_ERROR_POSIX_START = BC_ERROR_POSIX_NAME_LEN,
126 BC_ERROR_POSIX_END = BC_ERROR_POSIX_BRACE,
131 #define BC_ERR_IDX_MATH (0)
132 #define BC_ERR_IDX_PARSE (1)
133 #define BC_ERR_IDX_EXEC (2)
134 #define BC_ERR_IDX_FATAL (3)
135 #define BC_ERR_IDX_NELEMS (4)
138 #define BC_ERR_IDX_WARN (BC_ERR_IDX_NELEMS)
141 #define BC_UNUSED(e) ((void) (e))
144 #define BC_LIKELY(e) (e)
148 #define BC_UNLIKELY(e) (e)
149 #endif // BC_UNLIKELY
151 #define BC_ERR(e) BC_UNLIKELY(e)
152 #define BC_NO_ERR(s) BC_LIKELY(s)
154 #ifndef BC_DEBUG_CODE
155 #define BC_DEBUG_CODE (0)
156 #endif // BC_DEBUG_CODE
158 #if __STDC_VERSION__ >= 201100L
159 #include <stdnoreturn.h>
160 #define BC_NORETURN _Noreturn
161 #else // __STDC_VERSION__
163 #define BC_MUST_RETURN
164 #endif // __STDC_VERSION__
166 // Workarounds for AIX's POSIX incompatibility.
168 #define SIZE_MAX __SIZE_MAX__
171 #define UINTMAX_C __UINTMAX_C
174 #define UINT32_C __UINT32_C
176 #ifndef UINT_FAST32_MAX
177 #define UINT_FAST32_MAX __UINT_FAST32_MAX__
178 #endif // UINT_FAST32_MAX
180 #define UINT16_MAX __UINT16_MAX__
182 #ifndef SIG_ATOMIC_MAX
183 #define SIG_ATOMIC_MAX __SIG_ATOMIC_MAX__
184 #endif // SIG_ATOMIC_MAX
186 #endif // BC_STATUS_H