# HG changeset patch # User Mike Becker # Date 1746275877 -7200 # Node ID a35b39abe2b2facf96e6d80c6b05e8727bdc39d0 # Parent 895f92cff6b872a7cc76ef5c6e80dde11485a8c6 remove stdio include from error.h diff -r 895f92cff6b8 -r a35b39abe2b2 src/ascension/error.h --- a/src/ascension/error.h Sat May 03 14:30:56 2025 +0200 +++ b/src/ascension/error.h Sat May 03 14:37:57 2025 +0200 @@ -28,9 +28,8 @@ #ifndef ASC_ERROR_H #define ASC_ERROR_H -#include +void asc_error_impl(const char *file, unsigned line, char const *fmt, ...); -void asc_error_impl(const char* file, unsigned line, char const* fmt, ...); #define asc_error(...) asc_error_impl(__FILE__, __LINE__, __VA_ARGS__) void asc_error_gl(unsigned code, const char *message); @@ -38,14 +37,18 @@ int asc_error_catch_all_gl(void); bool asc_has_error(void); -char const* asc_get_error(void); + +char const *asc_get_error(void); + void asc_clear_error(void); -#define asc_wprintf(...) printf("[WARNING %s %u] ", __FILE__, __LINE__); printf(__VA_ARGS__); putchar('\n') +void asc_printf(const char *level, const char *file, unsigned line, const char *fmt, ...); + +#define asc_wprintf(...) asc_printf("WARNING", __FILE__, __LINE__, __VA_ARGS__) #ifdef NDEBUG #define asc_dprintf(...) #else -#define asc_dprintf(...) printf("[DEBUG %s %u] ", __FILE__, __LINE__); printf(__VA_ARGS__); putchar('\n') +#define asc_dprintf(...) asc_printf("DEBUG", __FILE__, __LINE__, __VA_ARGS__) #endif diff -r 895f92cff6b8 -r a35b39abe2b2 src/error.c --- a/src/error.c Sat May 03 14:30:56 2025 +0200 +++ b/src/error.c Sat May 03 14:37:57 2025 +0200 @@ -28,19 +28,29 @@ #include "ascension/context.h" #include "ascension/error.h" +#include +#include #include #include +void asc_printf(const char *level, const char *file, unsigned line, const char *fmt, ...) { + printf("[%s %s %u] ", level, file, line); + va_list ap; + va_start(ap, fmt); + vprintf(fmt, ap); + va_end(ap); + putchar('\n'); +} void asc_error_impl(const char* file, unsigned line, char const* fmt, ...) { asc_set_flag(asc_context.flags, ASC_FLAG_HAS_ERROR); // write to error buffer + CxBuffer* buf = &asc_context.error_buffer; + size_t bufpos = buf->pos; va_list args; va_start(args, fmt); - CxBuffer* buf = &asc_context.error_buffer; - size_t bufpos = buf->pos; int written = cx_vfprintf(buf, cxBufferWriteFunc, fmt, args); cxBufferPut(buf, '\n'); va_end(args);