1 /*
2 * Copyright (c) 1998-2003, Darren Hiebert
3 *
4 * This source code is released for free distribution under the terms of the
5 * GNU General Public License version 2 or (at your option) any later version.
6 *
7 * This code is derived from the main part of ctags.
8 * This source code is NOT released for the public domain.
9 */
10
11 /*
12 * INCLUDE FILES
13 */
14
15 #include "general.h"
16 #include "readtags-stub.h"
17 #include "routines.h"
18 #include "routines_p.h"
19
20 #include <errno.h>
21 #include <stdarg.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 #ifdef DEBUG
27
debugAssert(const char * assertion,const char * file,unsigned int line,const char * function)28 extern void debugAssert (const char *assertion, const char *file, unsigned int line, const char *function)
29 {
30 fprintf(stderr, "readtags: %s:%u: %s%sAssertion `%s' failed.\n",
31 file, line,
32 function ? function : "", function ? ": " : "",
33 assertion);
34 fflush(stderr);
35 abort();
36 }
37
38 #endif
39
40 #define selected(var,feature) (((int)(var) & (int)(feature)) == (int)feature)
41
stderrDefaultErrorPrinter(const errorSelection selection,const char * const format,va_list ap,void * data CTAGS_ATTR_UNUSED)42 extern bool stderrDefaultErrorPrinter (const errorSelection selection,
43 const char *const format,
44 va_list ap, void *data CTAGS_ATTR_UNUSED)
45 {
46 fprintf (stderr, "%s: %s", getExecutableName (),
47 selected (selection, WARNING) ? "Warning: " :
48 selected (selection, NOTICE) ? "Notice: " : "");
49 vfprintf (stderr, format, ap);
50 if (selected (selection, PERROR))
51 {
52 #ifdef HAVE_STRERROR
53 fprintf (stderr, " : %s", strerror (errno));
54 #else
55 perror (" ");
56 #endif
57 }
58 fputs ("\n", stderr);
59
60 return (selected (selection, FATAL))? true: false;
61 }
62
error(const errorSelection selection,const char * const format,...)63 extern void error (const errorSelection selection,
64 const char *const format, ...)
65 {
66 va_list ap;
67 bool shouldExit;
68
69 if (selected (selection, NOTICE))
70 return;
71
72 va_start (ap, format);
73 shouldExit = stderrDefaultErrorPrinter (selection, format, ap, NULL);
74 va_end (ap);
75
76 if (shouldExit)
77 exit (1);
78 }
79