1 /*** error.h ****************************************************************** 2 ** 3 ** This file is part of BibTool. 4 ** It is distributed under the GNU General Public License. 5 ** See the file COPYING for details. 6 ** 7 ** (c) 1996-2020 Gerd Neugebauer 8 ** 9 ** Net: gene@gerd-neugebauer.de 10 ** 11 ** This program is free software; you can redistribute it and/or modify 12 ** it under the terms of the GNU General Public License as published by 13 ** the Free Software Foundation; either version 2, or (at your option) 14 ** any later version. 15 ** 16 ** This program is distributed in the hope that it will be useful, 17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 ** GNU General Public License for more details. 20 ** 21 ** You should have received a copy of the GNU General Public License 22 ** along with this program; if not, write to the Free Software 23 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 ** 25 **----------------------------------------------------------------------------- 26 ** Description: 27 ** This header file provides means for issuing error 28 ** messages. Most of the macros provided in this header file are 29 ** based on the function |error()| described in |error.c|. 30 ** Nevertheless this function covers the general cases the macros 31 ** in this header file are more convenient since they hide the 32 ** unneccesary arguments of the |error()| function providing 33 ** appropriate values. 34 ** 35 ** This header file makes availlable the function |error()| as 36 ** defined in |error.c|. 37 ** 38 ******************************************************************************/ 39 40 #include<stdio.h> 41 #include<bibtool/type.h> 42 #include<bibtool/symbols.h> 43 44 /*----------------------------------------------------------------------------- 45 ** Constant: ERR_NONE 46 ** Type: int 47 ** Purpose: No error flags. 48 **___________________________________________________ */ 49 #define ERR_NONE 0 50 51 /*----------------------------------------------------------------------------- 52 ** Constant: ERR_ERROR 53 ** Type: int 54 ** Purpose: Error type: Indicate that the error can not be 55 ** suppressed and the messaged is marked as error. 56 **___________________________________________________ */ 57 #define ERR_ERROR 1 58 59 /*----------------------------------------------------------------------------- 60 ** Constant: ERR_WARNING 61 ** Type: int 62 ** Purpose: Error type: Indicate that the error is in fact a 63 ** warning which can be suppressed. The messaged is 64 ** marked as warning. This flag is only in effect if the 65 ** |ERR_ERROR| flag is not set. 66 **___________________________________________________ */ 67 #define ERR_WARNING 2 68 #define ERR_WARN 2 69 70 /*----------------------------------------------------------------------------- 71 ** Constant: ERR_MESSAGE 72 ** Type: int 73 ** Purpose: Error type: Indicate that the error is in fact a 74 ** message. 75 **___________________________________________________ */ 76 #define ERR_MESSAGE 4 77 78 /*----------------------------------------------------------------------------- 79 ** Constant: ERR_POINT 80 ** Type: int 81 ** Purpose: Error type: Indicate that the line and the error 82 ** pointer should be displayed (if not suppressed via 83 ** other flags). 84 **___________________________________________________ */ 85 #define ERR_POINT 8 86 87 /*----------------------------------------------------------------------------- 88 ** Constant: ERR_FILE 89 ** Type: int 90 ** Purpose: Error type: Indicate that the file name and line 91 ** number should be displayed (if not suppressed via 92 ** other flags). 93 **___________________________________________________ */ 94 #define ERR_FILE 16 95 96 /*----------------------------------------------------------------------------- 97 ** Constant: ERR_NO_NL 98 ** Type: int 99 ** Purpose: Error type: Indicate that the terminating newline should be 100 ** suppressed. 101 **___________________________________________________ */ 102 #define ERR_NO_NL 32 103 104 /*----------------------------------------------------------------------------- 105 ** Constant: ERR_EXIT 106 ** Type: int 107 ** Purpose: Error type: Indicate that the |error()| function 108 ** should be terminated by |exit()| instead of 109 ** returning. 110 **___________________________________________________ */ 111 #define ERR_EXIT 256 112 113 extern char *err_format; 114 extern String err_point; 115 extern String err_oom; 116 extern FILE *err_file; 117 118 /*----------------------------------------------------------------------------- 119 ** Macro: ERROR_EXIT() 120 ** Type: void 121 ** Purpose: Raise an error, print the single string argument as 122 ** error message and terminate the program with |exit()|. 123 ** Arguments: 124 ** X Error message. 125 ** Returns: nothing 126 **___________________________________________________ */ 127 #define ERROR_EXIT(X) \ 128 error(ERR_ERROR|ERR_EXIT,(String)X, \ 129 (String)0,(String)0,(String)0,(String)0,0,NO_SYMBOL) 130 131 /*----------------------------------------------------------------------------- 132 ** Macro: OUT_OF_MEMORY() 133 ** Type: void 134 ** Purpose: Raise an error because |malloc()| or |realloc()| 135 ** failed. The argument denoted the type of memory for 136 ** which the allocation failed. The program is 137 ** terminated. 138 ** Arguments: 139 ** X String denoting the type of unallocatable memory. 140 ** Returns: nothing 141 **___________________________________________________ */ 142 #define OUT_OF_MEMORY(X) \ 143 error(ERR_ERROR|ERR_EXIT,err_oom, \ 144 (String)X,err_point,(String)0,(String)0,0,NO_SYMBOL) 145 146 /*----------------------------------------------------------------------------- 147 ** Macro: ERROR() 148 ** Type: void 149 ** Purpose: Raise an error. Print the argument as error message 150 ** and continue. 151 ** Arguments: 152 ** X Error message. 153 ** Returns: nothing 154 **___________________________________________________ */ 155 #define ERROR(X) \ 156 error(ERR_ERROR,(String)X, \ 157 (String)0,(String)0,(String)0,(String)0,0,NO_SYMBOL) 158 159 /*----------------------------------------------------------------------------- 160 ** Macro: ERROR2() 161 ** Type: void 162 ** Purpose: Raise an error. Print the two arguments as error message 163 ** and continue. 164 ** Arguments: 165 ** X First error message. 166 ** Y Continuation of the error message. 167 ** Returns: nothing 168 **___________________________________________________ */ 169 #define ERROR2(X,Y) \ 170 error(ERR_ERROR,(String)X, \ 171 (String)Y,(String)0,(String)0,(String)0,0,NO_SYMBOL) 172 173 /*----------------------------------------------------------------------------- 174 ** Macro: ERROR3() 175 ** Type: void 176 ** Purpose: Raise an error. Print the three arguments as error message 177 ** and continue. 178 ** Arguments: 179 ** X First error message. 180 ** Y Continuation of the error message. 181 ** Z Second continuation of the error message. 182 ** Returns: nothing 183 **___________________________________________________ */ 184 #define ERROR3(X,Y,Z) \ 185 error(ERR_ERROR,(String)X, \ 186 (String)Y,(String)Z,(String)0,(String)0,0,NO_SYMBOL) 187 188 /*----------------------------------------------------------------------------- 189 ** Macro: WARNING() 190 ** Type: void 191 ** Purpose: Raise a warning. Print the argument as warning message 192 ** and continue. 193 ** Arguments: 194 ** X Warning message. 195 ** Returns: nothing 196 **___________________________________________________ */ 197 #define WARNING(X) \ 198 error(ERR_WARN,(String)X, \ 199 (String)0,(String)0,(String)0,(String)0,0,NO_SYMBOL) 200 201 /*----------------------------------------------------------------------------- 202 ** Macro: WARNING2() 203 ** Type: void 204 ** Purpose: Raise a warning. Print the two arguments as warning message 205 ** and continue. 206 ** Arguments: 207 ** X First warning message. 208 ** Y Continuation of warning message. 209 ** Returns: nothing 210 **___________________________________________________ */ 211 #define WARNING2(X,Y) \ 212 error(ERR_WARN,(String)X, \ 213 (String)Y,(String)0,(String)0,(String)0,0,NO_SYMBOL) 214 215 /*----------------------------------------------------------------------------- 216 ** Macro: WARNING3() 217 ** Type: void 218 ** Purpose: Raise a warning. Print the thre arguments as warning message 219 ** and continue. 220 ** Arguments: 221 ** X First warning message. 222 ** Y Continuation of warning message. 223 ** Z Second continuation of warning message. 224 ** Returns: nothing 225 **___________________________________________________ */ 226 #define WARNING3(X,Y,Z) \ 227 error(ERR_WARN,(String)X, \ 228 (String)Y, (String)Z, StringNULL, StringNULL, 0, NO_SYMBOL) 229 230 /*----------------------------------------------------------------------------- 231 ** Macro: Err() 232 ** Type: void 233 ** Purpose: Print a string to the error stream. This message is 234 ** preceded with an indicator. The message is \emph{not} 235 ** automatically terminated by a newline. 236 ** Arguments: 237 ** S String to print. 238 ** Returns: nothing 239 **___________________________________________________ */ 240 #define Err(S) (void)fprintf(err_file,err_format,S) 241 242 /*----------------------------------------------------------------------------- 243 ** Macro: ErrC() 244 ** Type: void 245 ** Purpose: Print a single character to the error stream. 246 ** Arguments: 247 ** CHAR Character to send to output. 248 ** Returns: nothing 249 **___________________________________________________ */ 250 #define ErrC(CHAR) (void)fputc(CHAR,err_file) 251 252 /*----------------------------------------------------------------------------- 253 ** Macro: ErrPrint() 254 ** Type: void 255 ** Purpose: Print a string to the error stream. The string is not 256 ** preceded by any indicator not is it automatically 257 ** terminated by a newline. 258 ** Arguments: 259 ** F String to print. 260 ** Returns: nothing 261 **___________________________________________________ */ 262 #define ErrPrint(F) (void)fputs(F,err_file) 263 264 /*----------------------------------------------------------------------------- 265 ** Macro: ErrPrintF() 266 ** Type: void 267 ** Purpose: Apply a formatting instruction (with |printf()|). This 268 ** macro takes a format string and a second argument 269 ** which is determined by the formatting string. 270 ** Arguments: 271 ** F Format. 272 ** A Argument. 273 ** Returns: nothing 274 **___________________________________________________ */ 275 #define ErrPrintF(F,A) (void)fprintf(err_file,F,A) 276 277 /*----------------------------------------------------------------------------- 278 ** Macro: ErrPrintF2() 279 ** Type: void 280 ** Purpose: Apply a formatting instruction (with |printf()|). This 281 ** macro takes a format string and two additional arguments 282 ** which are determined by the formatting string. 283 ** Arguments: 284 ** F Format 285 ** A First argument. 286 ** B Second argument. 287 ** Returns: nothing 288 **___________________________________________________ */ 289 #define ErrPrintF2(F,A,B) (void)fprintf(err_file,F,A,B) 290 291 /*----------------------------------------------------------------------------- 292 ** Macro: ErrPrintF3() 293 ** Type: void 294 ** Purpose: Apply a formatting instruction (with |printf()|). This 295 ** macro takes a format string and three additional arguments 296 ** which are determined by the formatting string. 297 ** Arguments: 298 ** F Format 299 ** A First argument. 300 ** B Second argument. 301 ** C Third argument. 302 ** Returns: nothing 303 **___________________________________________________ */ 304 #define ErrPrintF3(F,A,B,C) (void)fprintf(err_file,F,A,B,C) 305 306 /*----------------------------------------------------------------------------- 307 ** Constant: FlushErr() 308 ** Type: void 309 ** Purpose: Flush the error stream. This can be useful when single 310 ** characters are written to an error stream which does 311 ** buffering. 312 ** Returns: nothing 313 **___________________________________________________ */ 314 #define FlushErr (void)fflush(err_file) 315 316 /*----------------------------------------------------------------------------- 317 ** Macro: VerbosePrint1() 318 ** Type: void 319 ** Purpose: Print an informative message to the error stream. 320 ** Arguments: 321 ** A Verbose message. 322 ** Returns: nothing 323 **___________________________________________________ */ 324 #define VerbosePrint1(A) (void)fprintf(err_file,"--- BibTool: %s\n",A) 325 326 /*----------------------------------------------------------------------------- 327 ** Macro: VerbosePrint2() 328 ** Type: void 329 ** Purpose: Print an informative message consisting of two 330 ** substrings to the error stream. 331 ** Arguments: 332 ** A Verbose message. 333 ** B Continuation of verbose message. 334 ** Returns: nothing 335 **___________________________________________________ */ 336 #define VerbosePrint2(A,B) (void)fprintf(err_file,"--- BibTool: %s%s\n",A,B) 337 338 /*----------------------------------------------------------------------------- 339 ** Macro: VerbosePrint3() 340 ** Type: void 341 ** Purpose: Print an informative message consisting of three 342 ** substrings to the error stream. 343 ** Arguments: 344 ** A Verbose message. 345 ** B Continuation of verbose message. 346 ** C Second continuation of verbose message. 347 ** Returns: nothing 348 **___________________________________________________ */ 349 #define VerbosePrint3(A,B,C) (void)fprintf(err_file,"--- BibTool: %s%s%s\n",A,B,C) 350 351 /*----------------------------------------------------------------------------- 352 ** Macro: VerbosePrint4() 353 ** Type: void 354 ** Purpose: Print an informative message consisting of four 355 ** substrings to the error stream. 356 ** Arguments: 357 ** A Verbose message. 358 ** B Continuation of verbose message. 359 ** C Second continuation of verbose message. 360 ** D Third continuation of verbose message. 361 ** Returns: nothing 362 **___________________________________________________ */ 363 #define VerbosePrint4(A,B,C,D) (void)fprintf(err_file,"--- BibTool: %s%s%s%s\n",A,B,C,D) 364 365 #ifdef DEBUG 366 367 /*----------------------------------------------------------------------------- 368 ** Macro: DebugPrint1() 369 ** Type: void 370 ** Purpose: This Macro is for debugging purposes. The compilation 371 ** determines whether this macro prints its argument or 372 ** simply ignores it. This is achieved by defining or 373 ** undefining the macro |DEBUG| when compiling. 374 ** Arguments: 375 ** A Debug message. 376 ** Returns: nothing 377 **___________________________________________________ */ 378 #define DebugPrint1(A) (void)fprintf(err_file,"+++ BibTool: %s\n",A) 379 380 /*----------------------------------------------------------------------------- 381 ** Macro: DebugPrint2() 382 ** Type: void 383 ** Purpose: This Macro is for debugging purposes. The compilation 384 ** determines whether this macro prints its arguments or 385 ** simply ignores them. This is achieved by defining or 386 ** undefining the macro |DEBUG| when compiling. 387 ** Arguments: 388 ** A Debug message. 389 ** B Continuation of the debug message. 390 ** Returns: nothing 391 **___________________________________________________ */ 392 #define DebugPrint2(A,B) (void)fprintf(err_file,"+++ BibTool: %s%s\n",A,B) 393 394 /*----------------------------------------------------------------------------- 395 ** Macro: DebugPrint3() 396 ** Type: void 397 ** Purpose: 398 ** Purpose: This Macro is for debugging purposes. The compilation 399 ** determines whether this macro prints its arguments or 400 ** simply ignores them. This is achieved by defining or 401 ** undefining the macro |DEBUG| when compiling. 402 ** Arguments:Debug message. 403 ** A Debug message. 404 ** B Continuation of the debug message. 405 ** C Second continuation of the debug message. 406 ** Returns: nothing 407 **___________________________________________________ */ 408 #define DebugPrint3(A,B,C) (void)fprintf(err_file,"+++ BibTool: %s%s%s\n",A,B,C) 409 410 /*----------------------------------------------------------------------------- 411 ** Macro: DebugPrintF1() 412 ** Type: void 413 ** Purpose: This Macro is for debugging purposes. The compilation 414 ** determines whether this macro prints its argument or 415 ** simply ignores it. This is achieved by defining or 416 ** undefining the macro |DEBUG| when compiling. 417 ** Arguments: 418 ** A Debug message. 419 ** Returns: nothing 420 **___________________________________________________ */ 421 #define DebugPrintF1(A) (void)fprintf(err_file,A) 422 423 /*----------------------------------------------------------------------------- 424 ** Macro: DebugPrintF2() 425 ** Type: void 426 ** Purpose: This Macro is for debugging purposes. The compilation 427 ** determines whether this macro prints its arguments or 428 ** simply ignores them. This is achieved by defining or 429 ** undefining the macro |DEBUG| when compiling. 430 ** Arguments: 431 ** F The format for the debug message. 432 ** A Debug message. 433 ** Returns: nothing 434 **___________________________________________________ */ 435 #define DebugPrintF2(F,A) (void)fprintf(err_file,F,A) 436 437 /*----------------------------------------------------------------------------- 438 ** Macro: DebugPrintF3() 439 ** Type: void 440 ** Purpose: 441 ** Purpose: This Macro is for debugging purposes. The compilation 442 ** determines whether this macro prints its arguments or 443 ** simply ignores them. This is achieved by defining or 444 ** undefining the macro |DEBUG| when compiling. 445 ** Arguments:Debug message. 446 ** F The format for the debug message. 447 ** A Debug message. 448 ** B Continuation of the debug message. 449 ** Returns: nothing 450 **___________________________________________________ */ 451 #define DebugPrintF3(F,A,B) (void)fprintf(err_file,F,A,B) 452 #else 453 #define DebugPrint1(A) 454 #define DebugPrint2(A,B) 455 #define DebugPrint3(A,B,C) 456 #define DebugPrintF1(A) 457 #define DebugPrintF2(A,B) 458 #define DebugPrintF3(A,B,C) 459 #endif 460 461 #ifdef __STDC__ 462 #define _ARG(A) A 463 #else 464 #define _ARG(A) () 465 #endif 466 void err_location _ARG((int lineno,String fname,char* s1)); 467 void error _ARG((int type,String s1,String s2,String s3,String line,String err_pos,int line_no,Symbol fname)); 468 void init_error _ARG((FILE * file)); 469