1 /* @include ajmess ************************************************************
2 **
3 ** AJAX message functions
4 **
5 ** @author Richard Durbin and Ed Griffiths from ACEdb (messubs.c)
6 ** @version $Revision: 1.29 $
7 ** @modified Ian Longden for EMBOSS
8 ** @modified $Date: 2011/10/18 14:23:40 $ by $Author: rice $
9 ** @@
10 **
11 ** This library is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU Lesser General Public
13 ** License as published by the Free Software Foundation; either
14 ** version 2.1 of the License, or (at your option) any later version.
15 **
16 ** This library 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 GNU
19 ** Lesser General Public License for more details.
20 **
21 ** You should have received a copy of the GNU Lesser General Public
22 ** License along with this library; if not, write to the Free Software
23 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
24 ** MA  02110-1301,  USA.
25 **
26 ******************************************************************************/
27 
28 #ifndef AJMESS_H
29 #define AJMESS_H
30 
31 /* ========================================================================= */
32 /* ============================= include files ============================= */
33 /* ========================================================================= */
34 
35 #include "ajdefine.h"
36 #include "ajstr.h"
37 
38 #include <stdarg.h>
39 #include <setjmp.h>
40 
41 AJ_BEGIN_DECLS
42 
43 
44 
45 
46 /* ========================================================================= */
47 /* =============================== constants =============================== */
48 /* ========================================================================= */
49 
50 
51 
52 
53 #ifndef WIN32
54 extern AjBool acdDebugSet;
55 extern AjBool acdDebugBuffer;
56 extern AjBool acdDebug;
57 extern AjPStr acdProgram;
58 extern AjPStr acdAppldoc;
59 extern AjPStr acdArgSave;
60 extern AjPStr acdInputSave;
61 #else /* WIN32 */
62 
63 #ifdef AJAXDLL_EXPORTS
64 __declspec(dllexport) AjBool acdDebugSet;
65 __declspec(dllexport) AjBool acdDebugBuffer;
66 __declspec(dllexport) AjBool acdDebug;
67 __declspec(dllexport) AjPStr acdProgram;
68 __declspec(dllexport) AjPStr acdAppldoc;
69 __declspec(dllexport) AjPStr acdArgSave;
70 __declspec(dllexport) AjPStr acdInputSave;
71 #else /* !AJAXDLL_EXPORTS */
72 __declspec(dllimport) AjBool acdDebugSet;
73 __declspec(dllimport) AjBool acdDebugBuffer;
74 __declspec(dllimport) AjBool acdDebug;
75 __declspec(dllimport) AjPStr acdProgram;
76 __declspec(dllimport) AjPStr acdAppldoc;
77 __declspec(dllimport) AjPStr acdArgSave;
78 __declspec(dllimport) AjPStr acdInputSave;
79 #endif /* AJAXDLL_EXPORTS */
80 
81 #endif /* !WIN32 */
82 
83 
84 
85 
86 /* ========================================================================= */
87 /* ============================== public data ============================== */
88 /* ========================================================================= */
89 
90 
91 
92 
93 /* @data AjPError *************************************************************
94 **
95 ** Ajax error message levels object
96 **
97 ** @alias AjSError
98 ** @alias AjOError
99 **
100 ** @attr warning [AjBool] Display ajWarn messages
101 ** @attr error [AjBool] Display ajErr messages
102 ** @attr fatal [AjBool] Display ajFatal messages
103 ** @attr die [AjBool] Display ajDie messages
104 ** @@
105 ******************************************************************************/
106 
107 typedef struct AjSError
108 {
109     AjBool warning;
110     AjBool error;
111     AjBool fatal;
112     AjBool die;
113 } AjOError;
114 
115 #define AjPError AjOError*
116 
117 #ifndef WIN32
118 extern AjOError AjErrorLevel;
119 #else /* WIN32 */
120 
121 #ifdef AJAXDLL_EXPORTS
122 __declspec(dllexport) AjOError AjErrorLevel;
123 #else /* !AJAXDLL_EXPORTS */
124 __declspec(dllimport) AjOError AjErrorLevel;
125 #endif /* AJAXDLL_EXPORTS */
126 
127 #endif /* !WIN32 */
128 
129 #define SUBDIR_DELIMITER_STR "\\"
130 
131 
132 
133 typedef void (*AjMessVoidRoutine)(void);
134 typedef void (*AjMessOutRoutine)(const char*);
135 
136 
137 
138 
139 /* ========================================================================= */
140 /* =========================== public functions ============================ */
141 /* ========================================================================= */
142 
143 
144 
145 
146 /*
147 ** Prototype definitions
148 */
149 
150 AjMessVoidRoutine ajMessRegBeep(AjMessVoidRoutine func);
151 AjMessOutRoutine  ajMessRegCrash(AjMessOutRoutine func);
152 AjMessOutRoutine  ajMessRegDump(AjMessOutRoutine func);
153 AjMessOutRoutine  ajMessRegErr(AjMessOutRoutine func);
154 AjMessOutRoutine  ajMessRegExit(AjMessOutRoutine func);
155 AjMessOutRoutine  ajMessRegOut(AjMessOutRoutine func);
156 AjMessOutRoutine  ajMessRegWarn(AjMessOutRoutine func);
157 
158 void              ajMessSetErr(const char *filename, ajint line_num);
159 void              ajMessCrashFL(const char *format, ...);
160 void              ajMessVCrashFL(const char *format, va_list args);
161 void              ajMessCrashCodeFL(const char *code);
162 
163 /* External Interface.                                                       */
164 /* Note: ajMesscrash is a macro and makes use of the ',' operator            */
165 /* in C. This means that the ajMesscrash macro will only produce a single C  */
166 /* statement and hence can be used within brackets etc. and will not break   */
167 /* existing code, e.g.                                                       */
168 /*                     funcblah(ajMesscrash("hello"));                       */
169 /* will become:                                                              */
170 /* funcblah(uMessSetErrorOrigin(__FILE__, __LINE__), uMessCrash("hello"));   */
171 /*                                                                           */
172 
173 void              ajMessErrorInit(const char *progname); /* Record
174                                                             the application's
175                                                             name for use in
176                                                             error messages. */
177 
178 void              ajMessBeep(void); /* make a beep */
179 
180 AjBool            ajMessErrorSetFile(const char *errfile);  /* set file to
181                                                                read codes +
182                                                                messages from */
183 void              ajMessCodesDelete(void);  /* Delete the code/message pairs */
184 
185 void              ajMessOut(const char *format, ...);  /* simple message,
186                                                           no newline */
187 void              ajMessOutCode(const char *name);       /* as above but uses
188                                                             codes to get
189                                                             message */
190 void              ajMessDump(const char *format, ...); /* write to
191                                                           log file */
192 void              ajMessErrorCode(const char *name);      /* as above but
193                                                              uses code to
194                                                              get message */
195 void              ajMessExit(void);
196 void              ajMessExitDebug(void);
197 void              ajMessExitmsg(const char *format, ...);  /* error message,
198                                                               write to log
199                                                               file & exit */
200 void              ajDebug(const char *fmt, ...);
201 AjBool            ajDebugOn(void);
202 AjBool            ajDebugTest(const char *token);
203 FILE*             ajMessGetDebugfile(void);
204 void              ajDie(const char *format, ...);
205 void              ajErr(const char *format, ...); /* error message and
206                                                      write to
207                                                      log file */
208 ajint             ajUserGet(AjPStr *pthis, const char *fmt, ...);
209 void              ajUser(const char *format, ...);  /* simple msg with
210                                                        newline */
211 void              ajUserDumpC(const char* txt);  /* simple msg with string
212                                                     and newline */
213 void              ajUserDumpS(const AjPStr str);  /* simple msg with string
214                                                      and newline */
215 void              ajVDie(const char *format, va_list args); /* error message
216                                                                and
217                                                                write to log
218                                                                file */
219 void              ajVErr(const char *format, va_list args); /* error message
220                                                                and
221                                                                write to log
222                                                                file */
223 void              ajVUser(const char *format, va_list args);
224 void              ajVWarn(const char *format, va_list args); /* warning
225                                                                 message */
226 void              ajWarn(const char *format, ...); /* warning message */
227 
228 /* abort - but see below */
229 
230 /* ask for data satisfying format get results via freecard() */
231 
232 const char*       ajMessGetSysmessageC(void);
233 /* wrapped system error message for use in ajMesserror/crash() */
234 
235 ajint             ajMessGetCountError(void);
236 /* return numbers of error so far */
237 
238 /**** routines to catch crashes if necessary, e.g. when dumping ****/
239 
240 
241 
242 const char*       ajMessGetMessageC(void);
243 
244 void              ajMessInvokeDebugger(void);
245 
246 
247 #define ajMessCrash   ajMessSetErr(__FILE__, __LINE__), ajMessCrashFL
248 #define ajMessCrashCode ajMessSetErr(__FILE__, __LINE__), ajMessCrashCodeFL
249 #define ajFatal   ajMessSetErr(__FILE__, __LINE__), ajMessCrashFL
250 #define ajVFatal   ajMessSetErr(__FILE__, __LINE__), ajMessVCrashFL
251 
252 
253 /*
254 ** End of prototype definitions
255 */
256 
257 
258 /* if a setjmp() stack context is set using ajMessCatch*() then rather than
259 ** exiting or giving an error message, ajMessCrash() and messError() will
260 ** longjmp() back to the context.
261 ** ajMessCatch*() return the previous value. Use argument = 0 to reset.
262 ** ajMessCaughtMessage() can be called from the jumped-to routine to get
263 ** the error message that would have been printed.
264 */
265 
266 #ifdef AJ_COMPILE_DEPRECATED_BOOK
267 #endif /* AJ_COMPILE_DEPRECATED_BOOK */
268 
269 #ifdef AJ_COMPILE_DEPRECATED
270 
271 __deprecated ajint             ajMessErrorCount(void);
272 __deprecated char*             ajMessCaughtMessage(void);
273 __deprecated char*             ajMessSysErrorText(void);
274 __deprecated FILE*             ajDebugFile(void);
275 
276 #endif /* AJ_COMPILE_DEPRECATED */
277 
278 
279 
280 
281 AJ_END_DECLS
282 
283 #endif /* AJMESS_H */
284