• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * *****************************************************************************
3  *
4  * Copyright (c) 2018-2019 Gavin D. Howard and contributors.
5  *
6  * All rights reserved.
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 #ifndef BC_ENABLED
40 #define BC_ENABLED (1)
41 #endif // BC_ENABLED
42 
43 #ifndef DC_ENABLED
44 #define DC_ENABLED (1)
45 #endif // DC_ENABLED
46 
47 typedef enum BcStatus {
48 
49 	BC_STATUS_SUCCESS = 0,
50 	BC_STATUS_ERROR_MATH,
51 	BC_STATUS_ERROR_PARSE,
52 	BC_STATUS_ERROR_EXEC,
53 	BC_STATUS_ERROR_FATAL,
54 	BC_STATUS_EOF,
55 	BC_STATUS_EMPTY_EXPR,
56 	BC_STATUS_QUIT,
57 	BC_STATUS_SIGNAL,
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 
75 	BC_ERROR_EXEC_IBASE,
76 	BC_ERROR_EXEC_OBASE,
77 	BC_ERROR_EXEC_SCALE,
78 	BC_ERROR_EXEC_READ_EXPR,
79 	BC_ERROR_EXEC_REC_READ,
80 	BC_ERROR_EXEC_TYPE,
81 
82 	BC_ERROR_EXEC_STACK,
83 
84 	BC_ERROR_EXEC_PARAMS,
85 	BC_ERROR_EXEC_UNDEF_FUNC,
86 	BC_ERROR_EXEC_VOID_VAL,
87 
88 	BC_ERROR_PARSE_EOF,
89 	BC_ERROR_PARSE_CHAR,
90 	BC_ERROR_PARSE_STRING,
91 	BC_ERROR_PARSE_COMMENT,
92 	BC_ERROR_PARSE_TOKEN,
93 #if BC_ENABLED
94 	BC_ERROR_PARSE_EXPR,
95 	BC_ERROR_PARSE_EMPTY_EXPR,
96 	BC_ERROR_PARSE_PRINT,
97 	BC_ERROR_PARSE_FUNC,
98 	BC_ERROR_PARSE_ASSIGN,
99 	BC_ERROR_PARSE_NO_AUTO,
100 	BC_ERROR_PARSE_DUP_LOCAL,
101 	BC_ERROR_PARSE_BLOCK,
102 	BC_ERROR_PARSE_RET_VOID,
103 	BC_ERROR_PARSE_REF_VAR,
104 
105 	BC_ERROR_POSIX_NAME_LEN,
106 	BC_ERROR_POSIX_COMMENT,
107 	BC_ERROR_POSIX_KW,
108 	BC_ERROR_POSIX_DOT,
109 	BC_ERROR_POSIX_RET,
110 	BC_ERROR_POSIX_BOOL,
111 	BC_ERROR_POSIX_REL_POS,
112 	BC_ERROR_POSIX_MULTIREL,
113 	BC_ERROR_POSIX_FOR,
114 	BC_ERROR_POSIX_EXP_NUM,
115 	BC_ERROR_POSIX_REF,
116 	BC_ERROR_POSIX_VOID,
117 	BC_ERROR_POSIX_BRACE,
118 #endif // BC_ENABLED
119 
120 	BC_ERROR_NELEMS,
121 
122 #if BC_ENABLED
123 	BC_ERROR_POSIX_START = BC_ERROR_POSIX_NAME_LEN,
124 	BC_ERROR_POSIX_END = BC_ERROR_POSIX_BRACE,
125 #endif // BC_ENABLED
126 
127 } BcError;
128 
129 #define BC_ERR_IDX_MATH (0)
130 #define BC_ERR_IDX_PARSE (1)
131 #define BC_ERR_IDX_EXEC (2)
132 #define BC_ERR_IDX_FATAL (3)
133 #define BC_ERR_IDX_NELEMS (4)
134 
135 #if BC_ENABLED
136 #define BC_ERR_IDX_WARN (BC_ERR_IDX_NELEMS)
137 #endif // BC_ENABLED
138 
139 #define BC_UNUSED(e) ((void) (e))
140 
141 #ifndef BC_LIKELY
142 #define BC_LIKELY(e) (e)
143 #endif // BC_LIKELY
144 
145 #ifndef BC_UNLIKELY
146 #define BC_UNLIKELY(e) (e)
147 #endif // BC_UNLIKELY
148 
149 #define BC_ERR(e) BC_UNLIKELY(e)
150 #define BC_NO_ERR(s) BC_LIKELY(s)
151 
152 #ifndef BC_DEBUG_CODE
153 #define BC_DEBUG_CODE (0)
154 #endif // BC_DEBUG_CODE
155 
156 #endif // BC_STATUS_H
157