1 /* 2 * ***************************************************************************** 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 * 6 * Copyright (c) 2018-2021 Gavin D. Howard and contributors. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions are met: 10 * 11 * * Redistributions of source code must retain the above copyright notice, this 12 * list of conditions and the following disclaimer. 13 * 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. 17 * 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. 29 * 30 * ***************************************************************************** 31 * 32 * All bc status codes. 33 * 34 */ 35 36 #ifndef BC_STATUS_H 37 #define BC_STATUS_H 38 39 #include <stdint.h> 40 41 #ifndef BC_ENABLED 42 #define BC_ENABLED (1) 43 #endif // BC_ENABLED 44 45 #ifndef DC_ENABLED 46 #define DC_ENABLED (1) 47 #endif // DC_ENABLED 48 49 #if BC_ENABLE_AFL 50 #ifndef __AFL_HAVE_MANUAL_CONTROL 51 #error Must compile with afl-clang-fast for fuzzing 52 #endif // __AFL_HAVE_MANUAL_CONTROL 53 #endif // BC_ENABLE_AFL 54 55 #ifndef BC_ENABLE_MEMCHECK 56 #define BC_ENABLE_MEMCHECK (0) 57 #endif // BC_ENABLE_MEMCHECK 58 59 #include <bcl.h> 60 61 typedef enum BcStatus { 62 63 BC_STATUS_SUCCESS = 0, 64 BC_STATUS_ERROR_MATH, 65 BC_STATUS_ERROR_PARSE, 66 BC_STATUS_ERROR_EXEC, 67 BC_STATUS_ERROR_FATAL, 68 BC_STATUS_EOF, 69 BC_STATUS_QUIT, 70 71 } BcStatus; 72 73 typedef enum BcErr { 74 75 BC_ERR_MATH_NEGATIVE, 76 BC_ERR_MATH_NON_INTEGER, 77 BC_ERR_MATH_OVERFLOW, 78 BC_ERR_MATH_DIVIDE_BY_ZERO, 79 80 BC_ERR_FATAL_ALLOC_ERR, 81 BC_ERR_FATAL_IO_ERR, 82 BC_ERR_FATAL_FILE_ERR, 83 BC_ERR_FATAL_BIN_FILE, 84 BC_ERR_FATAL_PATH_DIR, 85 BC_ERR_FATAL_OPTION, 86 BC_ERR_FATAL_OPTION_NO_ARG, 87 BC_ERR_FATAL_OPTION_ARG, 88 89 BC_ERR_EXEC_IBASE, 90 BC_ERR_EXEC_OBASE, 91 BC_ERR_EXEC_SCALE, 92 BC_ERR_EXEC_READ_EXPR, 93 BC_ERR_EXEC_REC_READ, 94 BC_ERR_EXEC_TYPE, 95 96 BC_ERR_EXEC_STACK, 97 98 BC_ERR_EXEC_PARAMS, 99 BC_ERR_EXEC_UNDEF_FUNC, 100 BC_ERR_EXEC_VOID_VAL, 101 102 BC_ERR_PARSE_EOF, 103 BC_ERR_PARSE_CHAR, 104 BC_ERR_PARSE_STRING, 105 BC_ERR_PARSE_COMMENT, 106 BC_ERR_PARSE_TOKEN, 107 #if BC_ENABLED 108 BC_ERR_PARSE_EXPR, 109 BC_ERR_PARSE_EMPTY_EXPR, 110 BC_ERR_PARSE_PRINT, 111 BC_ERR_PARSE_FUNC, 112 BC_ERR_PARSE_ASSIGN, 113 BC_ERR_PARSE_NO_AUTO, 114 BC_ERR_PARSE_DUP_LOCAL, 115 BC_ERR_PARSE_BLOCK, 116 BC_ERR_PARSE_RET_VOID, 117 BC_ERR_PARSE_REF_VAR, 118 119 BC_ERR_POSIX_NAME_LEN, 120 BC_ERR_POSIX_COMMENT, 121 BC_ERR_POSIX_KW, 122 BC_ERR_POSIX_DOT, 123 BC_ERR_POSIX_RET, 124 BC_ERR_POSIX_BOOL, 125 BC_ERR_POSIX_REL_POS, 126 BC_ERR_POSIX_MULTIREL, 127 BC_ERR_POSIX_FOR, 128 BC_ERR_POSIX_EXP_NUM, 129 BC_ERR_POSIX_REF, 130 BC_ERR_POSIX_VOID, 131 BC_ERR_POSIX_BRACE, 132 #endif // BC_ENABLED 133 134 BC_ERR_NELEMS, 135 136 #if BC_ENABLED 137 BC_ERR_POSIX_START = BC_ERR_POSIX_NAME_LEN, 138 BC_ERR_POSIX_END = BC_ERR_POSIX_BRACE, 139 #endif // BC_ENABLED 140 141 } BcErr; 142 143 #define BC_ERR_IDX_MATH (0) 144 #define BC_ERR_IDX_PARSE (1) 145 #define BC_ERR_IDX_EXEC (2) 146 #define BC_ERR_IDX_FATAL (3) 147 #define BC_ERR_IDX_NELEMS (4) 148 149 #if BC_ENABLED 150 #define BC_ERR_IDX_WARN (BC_ERR_IDX_NELEMS) 151 #endif // BC_ENABLED 152 153 #define BC_UNUSED(e) ((void) (e)) 154 155 #ifndef BC_LIKELY 156 #define BC_LIKELY(e) (e) 157 #endif // BC_LIKELY 158 159 #ifndef BC_UNLIKELY 160 #define BC_UNLIKELY(e) (e) 161 #endif // BC_UNLIKELY 162 163 #define BC_ERR(e) BC_UNLIKELY(e) 164 #define BC_NO_ERR(s) BC_LIKELY(s) 165 166 #ifndef BC_DEBUG_CODE 167 #define BC_DEBUG_CODE (0) 168 #endif // BC_DEBUG_CODE 169 170 #if __STDC_VERSION__ >= 201100L 171 #include <stdnoreturn.h> 172 #define BC_NORETURN _Noreturn 173 #else // __STDC_VERSION__ 174 #define BC_NORETURN 175 #define BC_MUST_RETURN 176 #endif // __STDC_VERSION__ 177 178 #if defined(__clang__) || defined(__GNUC__) 179 #if defined(__has_attribute) && __has_attribute(fallthrough) 180 #define BC_FALLTHROUGH __attribute__((fallthrough)); 181 #else // defined(__has_attribute) && __has_attribute(fallthrough) 182 #define BC_FALLTHROUGH 183 #endif // defined(__has_attribute) && __has_attribute(fallthrough) 184 #else // defined(__clang__) || defined(__GNUC__) 185 #define BC_FALLTHROUGH 186 #endif // defined(__clang__) || defined(__GNUC__) 187 188 // Workarounds for AIX's POSIX incompatibility. 189 #ifndef SIZE_MAX 190 #define SIZE_MAX __SIZE_MAX__ 191 #endif // SIZE_MAX 192 #ifndef UINTMAX_C 193 #define UINTMAX_C __UINTMAX_C 194 #endif // UINTMAX_C 195 #ifndef UINT32_C 196 #define UINT32_C __UINT32_C 197 #endif // UINT32_C 198 #ifndef UINT_FAST32_MAX 199 #define UINT_FAST32_MAX __UINT_FAST32_MAX__ 200 #endif // UINT_FAST32_MAX 201 #ifndef UINT16_MAX 202 #define UINT16_MAX __UINT16_MAX__ 203 #endif // UINT16_MAX 204 #ifndef SIG_ATOMIC_MAX 205 #define SIG_ATOMIC_MAX __SIG_ATOMIC_MAX__ 206 #endif // SIG_ATOMIC_MAX 207 208 #endif // BC_STATUS_H 209