Sync error.c completely and create a custom error printer

Make sure the custom error printer never ends with fatal errors terminating
the application.
This commit is contained in:
Jiří Techet 2016-10-14 23:26:59 +02:00
parent c56047be5a
commit f82218ab07
2 changed files with 22 additions and 3 deletions

View File

@ -40,7 +40,7 @@ extern bool stderrDefaultErrorPrinter (const errorSelection selection,
#endif
fputs ("\n", stderr);
return false;
return (selected (selection, FATAL) || Option.fatalWarnings)? true: false;
}
extern void error (const errorSelection selection,
@ -50,7 +50,7 @@ extern void error (const errorSelection selection,
bool shouldExit;
va_start (ap, format);
shouldExit = false;
shouldExit = (* errorPrinter) (selection, format, ap, errorPrinterData);
va_end (ap);
if (shouldExit)

View File

@ -29,16 +29,35 @@
#include "output.h"
#include "options.h"
#include <string.h>
#include <errno.h>
typedef struct {
TMCtagsNewTagCallback tag_callback;
TMCtagsPassStartCallback pass_callback;
gpointer user_data;
} CallbackUserData;
extern bool nofatalErrorPrinter (const errorSelection selection,
const char *const format,
va_list ap, void *data CTAGS_ATTR_UNUSED)
{
fprintf (stderr, "%s: ", (selection & WARNING) ? "Warning: " : "Error");
vfprintf (stderr, format, ap);
if (selection & PERROR)
#ifdef HAVE_STRERROR
fprintf (stderr, " : %s", strerror (errno));
#else
perror (" ");
#endif
fputs ("\n", stderr);
return false;
}
void tm_ctags_init(void)
{
setErrorPrinter (stderrDefaultErrorPrinter, NULL);
setErrorPrinter (nofatalErrorPrinter, NULL);
setTagWriter (&ctagsWriter);
checkRegex ();