1 /* 2 Copyright (c) 2003 by Stefan Kurtz and The Institute for 3 Genomic Research. This is OSI Certified Open Source Software. 4 Please see the file LICENSE for licensing information and 5 the file ACKNOWLEDGEMENTS for names of contributors to the 6 code base. 7 */ 8 9 //\Ignore{ 10 11 #ifndef ERRORDEF_H 12 #define ERRORDEF_H 13 #include <stdio.h> 14 #include <stdlib.h> 15 #include "types.h" 16 17 #ifdef __cplusplus 18 extern "C" { 19 #endif 20 21 char *messagespace(void); 22 Sint maxerrormsg(void); 23 24 #ifdef __cplusplus 25 } 26 #endif 27 28 //} 29 30 /* 31 This file contains some macros to write error messages into a 32 buffer returned by the function \texttt{messagespace}. 33 */ 34 35 /* 36 There is a generic macro \texttt{GENERROR} (definition 37 not given) that checks if the 38 result of the computation \texttt{C} exceed the value returned 39 by the function \texttt{maxerrormessage}. If so, then a 40 corresponding error message is written to stderr. 41 */ 42 43 //\IgnoreLatex{ 44 45 #ifdef DEBUG 46 #define THROWERRORLINE\ 47 DEBUG2(1,"# throw error message in %s line %lu\n",__FILE__,\ 48 (Showuint) __LINE__) 49 #else 50 #define THROWERRORLINE /* Nothing */ 51 #endif 52 53 #define GENERROR(C);\ 54 THROWERRORLINE;\ 55 if((C) >= maxerrormsg())\ 56 {\ 57 fprintf(stderr,"file %s, line %lu: "\ 58 "space for errormessage too small\n",\ 59 __FILE__,(Showuint) __LINE__);\ 60 exit(EXIT_FAILURE);\ 61 } 62 63 /* 64 The different error macros call \texttt{sprintf} with the corresponding 65 number of arguments. 66 */ 67 68 69 #define ERROR0(F)\ 70 GENERROR(sprintf(messagespace(),F)) 71 72 #define ERROR1(F,A1)\ 73 GENERROR(sprintf(messagespace(),F,A1)) 74 75 #define ERROR2(F,A1,A2)\ 76 GENERROR(sprintf(messagespace(),F,A1,A2)) 77 78 #define ERROR3(F,A1,A2,A3)\ 79 GENERROR(sprintf(messagespace(),F,A1,A2,A3)) 80 81 #define ERROR4(F,A1,A2,A3,A4)\ 82 GENERROR(sprintf(messagespace(),F,A1,A2,A3,A4)) 83 84 #define ERROR5(F,A1,A2,A3,A4,A5)\ 85 GENERROR(sprintf(messagespace(),F,A1,A2,A3,A4,A5)) 86 87 //} 88 89 90 /* 91 The following is a macro to show the usage line for all programs 92 which have options and an indexname as the last argument. 93 */ 94 95 #define USAGEOUT\ 96 ERROR2("Usage: %s options indexname\n"\ 97 "%s -help shows possible options",\ 98 argv[0],argv[0]); 99 100 /* 101 The following is the standard message in the main function. It shows the 102 program name and the error message as returned by the function 103 \texttt{messagespace}. 104 */ 105 106 #define STANDARDMESSAGE\ 107 fprintf(stderr,"%s: %s\n",argv[0],messagespace());\ 108 return EXIT_FAILURE 109 110 #define SIMPLESTANDARDMESSAGE\ 111 fprintf(stderr,"%s\n",messagespace());\ 112 return EXIT_FAILURE 113 114 /* 115 The following is a generell error message which leads to a termination 116 of the program. 117 */ 118 119 #define NOTSUPPOSED\ 120 fprintf(stderr,"%s: line %lu: This case is not supposed to occur\n",\ 121 __FILE__,(Showuint) __LINE__);\ 122 exit(EXIT_FAILURE) 123 124 /* 125 The following macro checks a ptr. If it is \texttt{NULL}, then the 126 program terminates with an error. 127 */ 128 129 #ifdef DEBUG 130 #define NOTSUPPOSEDTOBENULL(PTR)\ 131 if((PTR) == NULL)\ 132 {\ 133 NOTSUPPOSED;\ 134 } 135 #else 136 #define NOTSUPPOSEDTOBENULL(PTR) /* Nothing */ 137 #endif 138 139 //\Ignore{ 140 141 #endif 142 143 //} 144