From 072f0c594526d96dac1c181d057eb9cf5d16862d Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Thu, 24 Apr 2025 18:37:11 -0400 Subject: eprintf --- Makefile | 4 ++-- eprintf.c | 27 +++++++++++++++++++++++++++ eprintf.h | 2 ++ 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 eprintf.c create mode 100644 eprintf.h diff --git a/Makefile b/Makefile index 5fe4011..d9eb3a9 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ CFLAGS = -std=c99 -Wall -Wextra -pedantic -Wno-deprecated-declarations -D_XOPEN_SOURCE=700L LDFLAGS = -lSDL2 -lSDL2_ttf -lm -SRC = main.c microui.c renderer.c widget.c ui.c unit.c engine.c compressor.c +SRC = main.c microui.c renderer.c widget.c ui.c unit.c engine.c compressor.c eprintf.c OBJ = ${SRC:.c=.o} -HDR = microui.h renderer.h widget.h ui.h unit.h engine.h +HDR = microui.h renderer.h widget.h ui.h unit.h engine.h eprintf.h util.h TEST_SRC = test.c test_angular_speed.c test_fraction.c test_pressure.c test_temperature.c test_volume.c test_volume_flow_rate.c test_mass_flow_rate.c test_engine.c unit.c engine.c TEST_OBJ = ${TEST_SRC:.c=.o} diff --git a/eprintf.c b/eprintf.c new file mode 100644 index 0000000..386293b --- /dev/null +++ b/eprintf.c @@ -0,0 +1,27 @@ +#include +#include +#include + +#include "eprintf.h" + +void +eprintf(const char *fmt, ...) { + va_list args; + + va_start(args, fmt); + fprintf(stderr, "error: "); + vfprintf(stderr, fmt, args); + fprintf(stderr, "\n"); + va_end(args); + exit(1); +} + +void weprintf(const char *fmt, ...) { + va_list args; + + va_start(args, fmt); + fprintf(stderr, "warning: "); + vfprintf(stderr, fmt, args); + fprintf(stderr, "\n"); + va_end(args); +} diff --git a/eprintf.h b/eprintf.h new file mode 100644 index 0000000..224b852 --- /dev/null +++ b/eprintf.h @@ -0,0 +1,2 @@ +void eprintf(const char *fmt, ...); +void weprintf(const char *fmt, ...); -- cgit v1.2.3