1 /* 2 * ***************************************************************************** 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 * 6 * Copyright (c) 2018-2020 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 typedef enum BcStatus { 50 51 BC_STATUS_SUCCESS = 0, 52 BC_STATUS_ERROR_MATH, 53 BC_STATUS_ERROR_PARSE, 54 BC_STATUS_ERROR_EXEC, 55 BC_STATUS_ERROR_FATAL, 56 BC_STATUS_EOF, 57 BC_STATUS_QUIT, 58 59 } BcStatus; 60 61 typedef enum BcError { 62 63 BC_ERROR_MATH_NEGATIVE, 64 BC_ERROR_MATH_NON_INTEGER, 65 BC_ERROR_MATH_OVERFLOW, 66 BC_ERROR_MATH_DIVIDE_BY_ZERO, 67 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, 76 77 BC_ERROR_EXEC_IBASE, 78 BC_ERROR_EXEC_OBASE, 79 BC_ERROR_EXEC_SCALE, 80 BC_ERROR_EXEC_READ_EXPR, 81 BC_ERROR_EXEC_REC_READ, 82 BC_ERROR_EXEC_TYPE, 83 84 BC_ERROR_EXEC_STACK, 85 86 BC_ERROR_EXEC_PARAMS, 87 BC_ERROR_EXEC_UNDEF_FUNC, 88 BC_ERROR_EXEC_VOID_VAL, 89 90 BC_ERROR_PARSE_EOF, 91 BC_ERROR_PARSE_CHAR, 92 BC_ERROR_PARSE_STRING, 93 BC_ERROR_PARSE_COMMENT, 94 BC_ERROR_PARSE_TOKEN, 95 #if BC_ENABLED 96 BC_ERROR_PARSE_EXPR, 97 BC_ERROR_PARSE_EMPTY_EXPR, 98 BC_ERROR_PARSE_PRINT, 99 BC_ERROR_PARSE_FUNC, 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, 106 107 BC_ERROR_POSIX_NAME_LEN, 108 BC_ERROR_POSIX_COMMENT, 109 BC_ERROR_POSIX_KW, 110 BC_ERROR_POSIX_DOT, 111 BC_ERROR_POSIX_RET, 112 BC_ERROR_POSIX_BOOL, 113 BC_ERROR_POSIX_REL_POS, 114 BC_ERROR_POSIX_MULTIREL, 115 BC_ERROR_POSIX_FOR, 116 BC_ERROR_POSIX_EXP_NUM, 117 BC_ERROR_POSIX_REF, 118 BC_ERROR_POSIX_VOID, 119 BC_ERROR_POSIX_BRACE, 120 #endif // BC_ENABLED 121 122 BC_ERROR_NELEMS, 123 124 #if BC_ENABLED 125 BC_ERROR_POSIX_START = BC_ERROR_POSIX_NAME_LEN, 126 BC_ERROR_POSIX_END = BC_ERROR_POSIX_BRACE, 127 #endif // BC_ENABLED 128 129 } BcError; 130 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) 136 137 #if BC_ENABLED 138 #define BC_ERR_IDX_WARN (BC_ERR_IDX_NELEMS) 139 #endif // BC_ENABLED 140 141 #define BC_UNUSED(e) ((void) (e)) 142 143 #ifndef BC_LIKELY 144 #define BC_LIKELY(e) (e) 145 #endif // BC_LIKELY 146 147 #ifndef BC_UNLIKELY 148 #define BC_UNLIKELY(e) (e) 149 #endif // BC_UNLIKELY 150 151 #define BC_ERR(e) BC_UNLIKELY(e) 152 #define BC_NO_ERR(s) BC_LIKELY(s) 153 154 #ifndef BC_DEBUG_CODE 155 #define BC_DEBUG_CODE (0) 156 #endif // BC_DEBUG_CODE 157 158 #if __STDC_VERSION__ >= 201100L 159 #include <stdnoreturn.h> 160 #define BC_NORETURN _Noreturn 161 #else // __STDC_VERSION__ 162 #define BC_NORETURN 163 #define BC_MUST_RETURN 164 #endif // __STDC_VERSION__ 165 166 // Workarounds for AIX's POSIX incompatibility. 167 #ifndef SIZE_MAX 168 #define SIZE_MAX __SIZE_MAX__ 169 #endif // SIZE_MAX 170 #ifndef UINTMAX_C 171 #define UINTMAX_C __UINTMAX_C 172 #endif // UINTMAX_C 173 #ifndef UINT32_C 174 #define UINT32_C __UINT32_C 175 #endif // UINT32_C 176 #ifndef UINT_FAST32_MAX 177 #define UINT_FAST32_MAX __UINT_FAST32_MAX__ 178 #endif // UINT_FAST32_MAX 179 #ifndef UINT16_MAX 180 #define UINT16_MAX __UINT16_MAX__ 181 #endif // UINT16_MAX 182 #ifndef SIG_ATOMIC_MAX 183 #define SIG_ATOMIC_MAX __SIG_ATOMIC_MAX__ 184 #endif // SIG_ATOMIC_MAX 185 186 #endif // BC_STATUS_H 187