1/*
2 * Legal Notice
3 *
4 * This document and associated source code (the "Work") is a part of a
5 * benchmark specification maintained by the TPC.
6 *
7 * The TPC reserves all right, title, and interest to the Work as provided
8 * under U.S. and international laws, including without limitation all patent
9 * and trademark rights therein.
10 *
11 * No Warranty
12 *
13 * 1.1 TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THE INFORMATION
14 * CONTAINED HEREIN IS PROVIDED "AS IS" AND WITH ALL FAULTS, AND THE
15 * AUTHORS AND DEVELOPERS OF THE WORK HEREBY DISCLAIM ALL OTHER
16 * WARRANTIES AND CONDITIONS, EITHER EXPRESS, IMPLIED OR STATUTORY,
17 * INCLUDING, BUT NOT LIMITED TO, ANY (IF ANY) IMPLIED WARRANTIES,
18 * DUTIES OR CONDITIONS OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR
19 * PURPOSE, OF ACCURACY OR COMPLETENESS OF RESPONSES, OF RESULTS, OF
20 * WORKMANLIKE EFFORT, OF LACK OF VIRUSES, AND OF LACK OF NEGLIGENCE.
21 * ALSO, THERE IS NO WARRANTY OR CONDITION OF TITLE, QUIET ENJOYMENT,
22 * QUIET POSSESSION, CORRESPONDENCE TO DESCRIPTION OR NON-INFRINGEMENT
23 * WITH REGARD TO THE WORK.
24 * 1.2 IN NO EVENT WILL ANY AUTHOR OR DEVELOPER OF THE WORK BE LIABLE TO
25 * ANY OTHER PARTY FOR ANY DAMAGES, INCLUDING BUT NOT LIMITED TO THE
26 * COST OF PROCURING SUBSTITUTE GOODS OR SERVICES, LOST PROFITS, LOSS
27 * OF USE, LOSS OF DATA, OR ANY INCIDENTAL, CONSEQUENTIAL, DIRECT,
28 * INDIRECT, OR SPECIAL DAMAGES WHETHER UNDER CONTRACT, TORT, WARRANTY,
29 * OR OTHERWISE, ARISING IN ANY WAY OUT OF THIS OR ANY OTHER AGREEMENT
30 * RELATING TO THE WORK, WHETHER OR NOT SUCH AUTHOR OR DEVELOPER HAD
31 * ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.
32 *
33 * Contributors:
34 * Gradient Systems
35 */
36#include "config.h"
37#include "porting.h"
38#include <stdio.h>
39#include "error_msg.h"
40#include "grammar_support.h"
41static int *LN;
42static char *FN;
43
44err_msg_t Errors[MAX_ERROR + 2] = {{
45 EFLG_NO_ARG,
46 "",
47 },
48 {EFLG_STR_ARG, "File '%s' not found"},
49 {EFLG_NO_ARG, "Line exceeds maximum length"},
50 {EFLG_STR_ARG, "Memory allocation failed %s"},
51 {EFLG_STR_ARG, "Syntax Error: \n'%s'"},
52 {EFLG_NO_ARG, "Invalid/Out-of-range Argument"},
53 {EFLG_STR_ARG, "'%s' is not a unique name"},
54 {EFLG_STR_ARG, "'%s' is not a valid name"},
55 {EFLG_NO_ARG, "Command parse failed"},
56 {EFLG_NO_ARG, "Invalid tag found"},
57 {EFLG_STR_ARG, "Read failed on '%s'"},
58 {EFLG_NO_ARG, "Too Many Templates!"},
59 {EFLG_NO_ARG, "Each workload definition must be in its own file"},
60 {EFLG_NO_ARG, "Query Class name must be unique within a workload definition"},
61 {EFLG_NO_ARG, "Query Template must be unique within a query class"},
62 {EFLG_STR_ARG | EFLG_SYSTEM, "Open failed on '%s'"},
63 {EFLG_STR_ARG, "%s not yet implemented"}, /* QERR_NOT_IMPLEMENTED */
64 {EFLG_STR_ARG, "string trucated to '%s'"},
65 {EFLG_NO_ARG, "Non-terminated string"},
66 {EFLG_STR_ARG, "failed to write to '%s'"},
67 {EFLG_NO_ARG, "No type vector defined for distribution"},
68 {EFLG_NO_ARG, "No weight count defined for distribution"},
69 {EFLG_NO_ARG, "No limits defined for pricing calculations"},
70 {EFLG_STR_ARG, "Percentage is out of bounds in substitution '%s'"},
71 {EFLG_STR_ARG, "Name is not a distribution or table name: '%s'"},
72 {EFLG_NO_ARG, "Cannot evaluate expression"},
73 {EFLG_STR_ARG, "Substitution'%s' is used before being initialized"}, /* QERR_NO_INIT
74 */
75 {EFLG_NO_ARG, "RANGE()/LIST()/ULIST() not supported for NORMAL "
76 "distributions"},
77 {EFLG_STR_ARG, "Bad Nesting; '%s' not found"},
78 {EFLG_STR_ARG, "Include stack overflow when opening '%s'"},
79 {EFLG_STR_ARG, "Bad function call: '%s'"},
80 {EFLG_STR_ARG, "Bad Hierarchy Call: '%s'"},
81 {EFLG_NO_ARG, "Must set types and weights before defining names"},
82 {EFLG_NO_ARG, "More than 20 arguments in definition"},
83 {EFLG_NO_ARG, "Argument type mismatch"},
84 {EFLG_NO_ARG, "RANGE()/LIST()/ULIST() cannot be used in the "
85 "same expression"}, /* QERR_RANGE_LIST
86 */
87 {EFLG_NO_ARG, "Selected scale factor is NOT valid for result publication"},
88 {EFLG_STR_ARG, "Parameter setting failed for '%s'"},
89 {EFLG_STR_ARG, "Table %s is being joined without an explicit rule"},
90 {EFLG_STR_ARG, "Table %s is not yet fully defined"},
91 {EFLG_STR_ARG, "Table %s is a child; it is populated during the build of "
92 "its parent (e.g., catalog_sales builds catalog returns)"},
93 {EFLG_NO_ARG, "Command line arguments for dbgen_version exceed 200 "
94 "characters; truncated"},
95 {EFLG_NO_ARG, "A query template list must be supplied using the "
96 "INPUT option"}, /* QERR_NO_QUERYLIST
97 */
98 {EFLG_NO_ARG, "Invalid query number found in permutation!"}, /* QERR_QUERY_RANGE
99 */
100 {EFLG_NO_ARG, "RANGE/LIST/ULIST expressions not valid as "
101 "function parameters"}, /* QERR_MODIFIED_PARAM
102 */
103 {EFLG_NO_ARG, "RANGE/LIST/ULIST truncated to available "
104 "values"}, /* QERR_MODIFIED_PARAM
105 */
106 {EFLG_NO_ARG, "This scale factor is valid for QUALIFICATION "
107 "ONLY"}, /* QERR_QUALIFICATION_SCALE
108 */
109 {EFLG_STR_ARG, "Generating %s requires the '-update' option"}, /* QERR_TABLE_UPDATE
110 */
111 {0, NULL}};
112
113/*
114 * Routine:
115 * Purpose:
116 * Algorithm:
117 * Data Structures:
118 *
119 * Params:
120 * Returns:
121 * Called By:
122 * Calls:
123 * Assumptions:
124 * Side Effects:
125 * TODO: None
126 */
127void ProcessErrorCode(int nErrorCode, char *szRoutineName, char *szParam, int nParam) {
128 switch (nErrorCode) {
129 case QERR_NO_FILE:
130 ReportError(QERR_NO_FILE, szParam, 1);
131 break;
132 case QERR_SYNTAX:
133 case QERR_RANGE_ERROR:
134 case QERR_NON_UNIQUE:
135 case QERR_BAD_NAME:
136 case QERR_DEFINE_OVERFLOW:
137 case QERR_INVALID_TAG:
138 case QERR_READ_FAILED:
139 case QERR_NO_MEMORY:
140 case QERR_LINE_TOO_LONG:
141 ReportError(nErrorCode, szRoutineName, 1);
142 break;
143 }
144 return;
145}
146
147/*
148 * Routine:
149 * Purpose:
150 * Algorithm:
151 * Data Structures:
152 *
153 * Params:
154 * Returns:
155 * Called By:
156 * Calls:
157 * Assumptions:
158 * Side Effects:
159 * TODO: None
160 */
161int ReportError(int nError, char *msg, int bExit) {
162 fprintf(stderr, "ERROR?!\n");
163 return (nError);
164}
165
166/*
167 * Routine:
168 * Purpose:
169 * Algorithm:
170 * Data Structures:
171 *
172 * Params:
173 * Returns:
174 * Called By:
175 * Calls:
176 * Assumptions:
177 * Side Effects:
178 * TODO: None
179 */
180int ReportErrorNoLine(int nError, char *msg, int bExit) {
181 char e_msg[1024];
182
183 if (nError < MAX_ERROR) {
184 switch (Errors[-nError].flags & EFLG_ARG_MASK) {
185 case EFLG_NO_ARG:
186 fprintf(stderr, "%s: %s\n", (bExit) ? "ERROR" : "Warning", Errors[-nError].prompt);
187 break;
188 case EFLG_STR_ARG:
189 sprintf(e_msg, Errors[-nError].prompt, msg);
190 fprintf(stderr, "%s: %s\n", (bExit) ? "ERROR" : "Warning", e_msg);
191 break;
192 }
193
194 if (Errors[-nError].flags & EFLG_SYSTEM)
195 perror(msg);
196 }
197
198 if (bExit)
199 exit(nError);
200 else
201 return (nError);
202}
203
204/*
205 * Routine:
206 * Purpose:
207 * Algorithm:
208 * Data Structures:
209 *
210 * Params:
211 * Returns:
212 * Called By:
213 * Calls:
214 * Assumptions:
215 * Side Effects:
216 * TODO: None
217 */
218void SetErrorGlobals(char *szFileName, int *nLineNumber) {
219 FN = szFileName;
220 LN = nLineNumber;
221
222 return;
223}
224