|
1 /* -*- Mode: C -*- */ 2 3 #ifndef HT_ERROR_TAGS_H 4 #define HT_ERROR_TAGS_H 5 6 /* ********************************************************************** */ 7 /* The kinds of messages ('color tags'): */ 8 9 #define _C_TAG_NONE (1 << 0) 10 #define C_TAG_NONE _C_TAG_NONE 11 /* This is a message that explicitly does not want a prefix. 12 * Use this seldom, e.g. for help pages for lengthy version 13 * information etc. 14 * 15 * For banners, there is a special tag C_TAG_BANNER, which 16 * also suppresses the prefix. 17 */ 18 19 #define _C_TAG_UNCLASSIFIED (1 << 1) 20 #define C_TAG_UNCLASSIFIED _C_TAG_UNCLASSIFIED 21 #define C_TAG_NOCLASS C_TAG_UNCLASSIFIED 22 /* An unclassified message (use this seldom). 23 * This is almost like the above, but progname[PID]: are printed. 24 * E.g. all fprintf (stderr, ...) is internally translated to this error tag. 25 */ 26 27 #define _C_TAG_BANNER (1 << 2) 28 #define C_TAG_BANNER _C_TAG_BANNER 29 /* For informational messages at the beginning of the program. */ 30 31 #define _C_TAG_PROGRESS (1 << 3) 32 #define C_TAG_PROGRESS _C_TAG_PROGRESS 33 /* Progress messages. A bit like Info, but can be seperately filtered. */ 34 35 #define _C_TAG_INFO (1 << 4) 36 #define C_TAG_INFO _C_TAG_INFO 37 /* This is information that is really useful for the user. It should 38 * be displayed even in quiet mode operation. If your program has a 39 * very quiet mode, then these messages could be swiched off then. */ 40 41 #define _C_TAG_NOTE (1 << 5) 42 #define C_TAG_NOTE _C_TAG_NOTE 43 /* This is merely a note and is likely to disappear when the user wants a 44 * quiet program. */ 45 46 #define _C_TAG_PROMPT (1 << 6) 47 #define C_TAG_PROMPT _C_TAG_PROMPT 48 /* This is a prompt when you ask the user something */ 49 50 #define _C_TAG_WARN (1 << 7) 51 #define C_TAG_WARN _C_TAG_WARN 52 #define C_TAG_WARNING C_TAG_WARN 53 /* A warning message */ 54 55 #define _C_TAG_ERR (1 << 8) 56 #define C_TAG_ERR _C_TAG_ERR 57 #define C_TAG_ERROR C_TAG_ERR 58 /* An error message */ 59 60 #define _C_TAG_INTERNAL (1 << 9) 61 #define C_TAG_INTERNAL _C_TAG_INTERNAL 62 /* internal error */ 63 64 #define _C_TAG_FATAL (1 << 10) 65 #define C_TAG_FATAL _C_TAG_FATAL 66 /* Fatal error: these are errors that immediately call exit(1) or abort), 67 * because everything is bad. */ 68 69 #define _C_TAG_ASSERT (1 << 11) 70 #define C_TAG_ASSERT _C_TAG_ASSERT 71 #define C_TAG_ASSERTION C_TAG_ASSERT 72 /* Failed assertion. 73 * These have to print their own tag, not error number is output. 74 * However, it should be tried to output the file and line number using 75 * the normal liberror mechanisms (which is not always trivial to change 76 * for existing libraries). 77 */ 78 #define _C_TAG_DEBUG (1 << 12) 79 #define C_TAG_DEBUG _C_TAG_DEBUG 80 /* debug output (usually disabled) */ 81 82 83 #define C_TAG_BITS 13 /* 13 is maximum, since 13 + 9 + 9 + 1 is 32. */ 84 #define C_TAG_NEXT_BIT C_TAG_BITS 85 86 #define C_TAG_MASK ((1 << C_TAG_BITS) - 1) 87 88 89 #define C_TAG_VARIANT (((unsigned)1) << ((unsigned)31)) 90 /* A bit that modifies the above message in some ways that 91 * depends on the tag. */ 92 93 #define C_TAG_PRE_FATAL (C_TAG_FATAL | C_TAG_VARIANT) 94 95 #define C_TAG_PRE_ASSERT (C_TAG_ASSERTION | C_TAG_VARIANT) 96 #define C_TAG_PRE_ASSERTION (C_TAG_ASSERTION | C_TAG_VARIANT) 97 /* Variants that do not cause immediate termination of the 98 * program. */ 99 100 /* 101 * Other color tags that rather describe groups of tags (not for eprintf group!) */ 102 #define C_TAG_ALL C_TAG_MASK 103 #define C_TAG_ALL_NORMAL (C_TAG_ALL & ~C_TAG_NONE & ~C_TAG_UNCLASSIFIED) 104 105 #define C_TAG_ERRORS (_C_TAG_ERR | _C_TAG_INTERNAL | _C_TAG_FATAL | _C_TAG_ASSERT) 106 /* These are classified to be errors. */ 107 108 #define C_TAG_WARNINGS (_C_TAG_WARN) 109 /* These are classified to be warnings (trivial, but in accordance with C_TAG_ERRORS). */ 110 111 #define C_TAG_INFOS (_C_TAG_PROGRESS | _C_TAG_NOTE | _C_TAG_INFO) 112 /* These are classified to be info messages */ 113 114 115 #define C_TAG_GROUP_STDOUT (_C_TAG_BANNER | _C_TAG_PROMPT | _C_TAG_INFO | _C_TAG_NOTE) 116 #define C_TAG_GROUP_STDERR (C_TAG_MASK & ~C_TAG_GROUP_STDOUT) 117 /* Some people print all of these to stderr. */ 118 119 /* Special value for continued message (for eprintf group only!) */ 120 #define C_TAG_MORE -1 121 /* Adds the message to the last error message. */ 122 123 #define C_TAG_PREFIX -2 124 #define C_TAG_SUFFIX -3 125 /* For composing messages with multiple eprintfs: when C_TAG_PREFIX 126 * is used, no messages is generated, but this is buffered until 127 * the next non C_TAG_PREFIX tag is found. Then, the buffered 128 * prefix is prepended. 129 * 130 * SUFFIX works accordingly. 131 * 132 * This is useful since it is the only way of printing without a \n at 133 * the end of the string. All other tags add \n automatically. 134 */ 135 136 /* Subsystem encoding in the color tag fields: */ 137 #define C_TAG_SUBSYSTEM_FIRST_BIT C_TAG_NEXT_BIT 138 #define C_TAG_SUBSYSTEM_BITS 9 139 140 #define C_TAG_SUBSYSTEM_SHIFT C_TAG_SUBSYSTEM_FIRST_BIT 141 #define C_TAG_SUBSYSTEM_MASK_LOW ((1 << C_TAG_SUBSYSTEM_BITS) - 1) 142 #define C_TAG_SUBSYSTEM_MAX C_TAG_SUBSYSTEM_MASK_LOW 143 #define C_TAG_SUBSYSTEM_MASK (C_TAG_SUBSYSTEM_MASK_LOW << C_TAG_SUBSYSTEM_SHIFT) 144 145 #define C_TAG_SUBSYSTEM_NEXT_BIT (C_TAG_SUBSYSTEM_FIRST_BIT + C_TAG_SUBSYSTEM_BITS) 146 147 /* Subsystem encoding in the color tag fields: */ 148 #define C_TAG_GROUP_FIRST_BIT C_TAG_SUBSYSTEM_NEXT_BIT 149 #define C_TAG_GROUP_BITS 9 150 151 #define C_TAG_GROUP_SHIFT C_TAG_GROUP_FIRST_BIT 152 #define C_TAG_GROUP_MASK_LOW ((1 << C_TAG_GROUP_BITS) - 1) 153 #define C_TAG_GROUP_MAX C_TAG_GROUP_MASK_LOW 154 #define C_TAG_GROUP_MASK (C_TAG_GROUP_MASK_LOW << C_TAG_GROUP_SHIFT) 155 156 #define C_TAG_GROUP_NEXT_BIT (C_TAG_GROUP_FIRST_BIT + C_TAG_GROUP_BITS) 157 158 #define ERR_IS_DEVEL(X) (((X) & C_TAG_DEBUG) && (((X) & C_TAG_MASK) != C_TAG_DEBUG)) 159 160 #define ERR_PURE_TAG(X) ((((X) & C_TAG_MASK) == C_TAG_DEBUG) ? \ 161 C_TAG_DEBUG \ 162 : ((X) & (C_TAG_MASK & ~C_TAG_DEBUG))) 163 164 #define ERR_EXACTLY_ONE_BIT(X) \ 165 ((X) != 0 && (((X) | ((X)-1)) == (2*(X)-1))) 166 167 168 /* ********************************************************************** */ 169 /* A simple means of adding a module string is to define 170 * ERR_MODULE_TOKEN (a token) or ERR_MODULE (a string) during 171 * compilation of a file. 172 * 173 * Note that the following tags are not redefined: 174 * C_TAG_BANNER 175 * C_TAG_ASSERTION 176 * C_TAG_PROGESS 177 * If you want them, too, you can make similar definitions for these 178 * tags in your own files. 179 */ 180 #if !defined(IN_LIBERROR_COMPILE) 181 # if defined(ERR_MODULE_TOKEN) || defined(ERR_MODULE) 182 183 # ifndef ERR_MODULE 184 # define ERR_MAKE_STRING_AUX(X) #X 185 # define ERR_MAKE_STRING(X) ERR_MAKE_STRING_AUX(X) 186 # define ERR_MODULE ERR_MAKE_STRING(ERR_MODULE_TOKEN) 187 # endif 188 189 #define ERR_SUBSYSTEM_ID (_err_subsystem_cache()) 190 191 # undef C_TAG_ERR 192 # define C_TAG_ERR (_C_TAG_ERR + ERR_SUBSYSTEM_ID) 193 # undef C_TAG_WARN 194 # define C_TAG_WARN (_C_TAG_WARN + ERR_SUBSYSTEM_ID) 195 # undef C_TAG_INFO 196 # define C_TAG_INFO (_C_TAG_INFO + ERR_SUBSYSTEM_ID) 197 # undef C_TAG_NOTE 198 # define C_TAG_NOTE (_C_TAG_NOTE + ERR_SUBSYSTEM_ID) 199 # undef C_TAG_PROMPT 200 # define C_TAG_PROMPT (_C_TAG_PROMPT + ERR_SUBSYSTEM_ID) 201 # undef C_TAG_DEBUG 202 # define C_TAG_DEBUG (_C_TAG_DEBUG + ERR_SUBSYSTEM_ID) 203 # undef C_TAG_INTERNAL 204 # define C_TAG_INTERNAL (_C_TAG_INTERNAL + ERR_SUBSYSTEM_ID) 205 # undef C_TAG_FATAL 206 # define C_TAG_FATAL (_C_TAG_FATAL + ERR_SUBSYSTEM_ID) 207 208 # endif /* defined MODULES_TOKEN */ 209 #endif /* !defined IN_LIBERROR_COMPILE */ 210 211 #endif /* !defined HT_ERROR_TAGS_H */