Sat, 03 May 2025 14:37:57 +0200
remove stdio include from error.h
src/ascension/error.h | file | annotate | diff | comparison | revisions | |
src/error.c | file | annotate | diff | comparison | revisions |
--- 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 <stdio.h> +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
--- 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 <stdio.h> +#include <stdarg.h> #include <cx/printf.h> #include <GL/glew.h> +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);