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