From c86376d43505f4580076a0ab95b5d0af991ab8b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Tue, 5 Mar 2019 19:27:01 +0000 Subject: [PATCH] Provisional error messages with abort(). Former-commit-id: eba2bd11556cb9f39fb344f9867102f29229455d --- qpms/error.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++ qpms/qpms_error.h | 19 +++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 qpms/error.c create mode 100644 qpms/qpms_error.h diff --git a/qpms/error.c b/qpms/error.c new file mode 100644 index 0000000..6027190 --- /dev/null +++ b/qpms/error.c @@ -0,0 +1,48 @@ +#include "qpms_error.h" +#include +#include +#include + +void qpms_pr_error(const char *fmt, ...) { + fflush(stdout); + va_list ap; + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + fputc('\n', stderr); + fflush(stderr); + abort(); +} + + +//void qpms_error(const char *fmt, ...); + +void qpms_pr_error_at_line(const char *filename, unsigned int linenum, + const char *fmt, ...) { + fflush(stdout); + fprintf(stderr, "%s:%u: ", filename, linenum); + va_list ap; + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + fputc('\n', stderr); + fflush(stderr); + abort(); +} + +void qpms_pr_error_at_flf(const char *filename, unsigned int linenum, + const char *func, + const char *fmt, ...) { + fflush(stdout); + fprintf(stderr, "%s:%u, %s: ", filename, linenum, func); + va_list ap; + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + fputc('\n', stderr); + fflush(stderr); + abort(); +} +//void qpms_error_at_line(const char *filename, unsigned int linenum, +// const char *fmt, ...); + diff --git a/qpms/qpms_error.h b/qpms/qpms_error.h new file mode 100644 index 0000000..45f88aa --- /dev/null +++ b/qpms/qpms_error.h @@ -0,0 +1,19 @@ +#ifndef QPMS_ERROR_H +#define QPMS_ERROR_H + +/// Provisional error message with abort(); +void qpms_pr_error(const char *fmt, ...); +//void qpms_error(const char *fmt, ...); + +/// Provisional error message with abort(), indicating source and line number. +void qpms_pr_error_at_line(const char *filename, unsigned int linenum, + const char *fmt, ...); + +void qpms_pr_error_at_flf(const char *filename, unsigned int linenum, + const char *func, + const char *fmt, ...); + +//void qpms_error_at_line(const char *filename, unsigned int linenum, +// const char *fmt, ...); + +#endif