From 5c0311ff3095a5dd30fb15db54aa394498dd2bcf Mon Sep 17 00:00:00 2001 From: 0scar Date: Mon, 30 Oct 2023 23:11:54 +0100 Subject: The great formattening! --- src/logging.c | 119 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 60 insertions(+), 59 deletions(-) (limited to 'src/logging.c') diff --git a/src/logging.c b/src/logging.c index e8c2199..7870258 100644 --- a/src/logging.c +++ b/src/logging.c @@ -1,81 +1,82 @@ -#include -#include #include +#include +#include -char *itoa(i32 x) { - const i32 size = (((i32)ceil(log10((f64)x)))+1) * sizeof(char); - char *retval = (char*)malloc(size); - if (retval == NULL) { - perror("Failed to allocate memory for itoa"); - exit(EXIT_FAILURE); - } - sprintf(retval, "%d", x); - return retval; +char* itoa(i32 x) { + const i32 size = (((i32)ceil(log10((f64)x))) + 1) * sizeof(char); + char* retval = (char*)malloc(size); + if (retval == NULL) { + perror("Failed to allocate memory for itoa"); + exit(EXIT_FAILURE); + } + sprintf(retval, "%d", x); + return retval; } -void _log(FILE *stream, const char *prefix, const char *fmt, va_list ap) { - if (stream == NULL) { - fprintf(stderr, "_log got NULL in stream argument\n"); - exit(EXIT_FAILURE); - } - fputs(prefix, stream); - vfprintf(stream, fmt, ap); +void _log(FILE* stream, const char* prefix, const char* fmt, va_list ap) { + if (stream == NULL) { + fprintf(stderr, "_log got NULL in stream argument\n"); + exit(EXIT_FAILURE); + } + fputs(prefix, stream); + vfprintf(stream, fmt, ap); } -void LOG(const char *fmt, ...) { - va_list ap; - va_start(ap, fmt); - _log(stdout, "[" TERM_COLOR_BLUE "LOG" TERM_COLOR_RESET "] ", fmt, ap); - va_end(ap); - puts(""); +void LOG(const char* fmt, ...) { + va_list ap; + va_start(ap, fmt); + _log(stdout, "[" TERM_COLOR_BLUE "LOG" TERM_COLOR_RESET "] ", fmt, ap); + va_end(ap); + puts(""); } -void INFO_(const char *fmt, ...) { - va_list ap; - va_start(ap, fmt); - _log(stdout, "[" TERM_COLOR_GREEN "INFO" TERM_COLOR_RESET "] ", fmt, ap); - va_end(ap); +void INFO_(const char* fmt, ...) { + va_list ap; + va_start(ap, fmt); + _log(stdout, "[" TERM_COLOR_GREEN "INFO" TERM_COLOR_RESET "] ", fmt, ap); + va_end(ap); } -void INFO(const char *fmt, ...) { - va_list ap; - va_start(ap, fmt); - _log(stdout, "[" TERM_COLOR_GREEN "INFO" TERM_COLOR_RESET "] ", fmt, ap); - va_end(ap); - puts(""); +void INFO(const char* fmt, ...) { + va_list ap; + va_start(ap, fmt); + _log(stdout, "[" TERM_COLOR_GREEN "INFO" TERM_COLOR_RESET "] ", fmt, ap); + va_end(ap); + puts(""); } -void __DEBUG(const char* file, const i32 line, const char* func, const char *fmt, ...) { - va_list ap; +void __DEBUG(const char* file, const i32 line, const char* func, + const char* fmt, ...) { + va_list ap; - const usize prefix_len = 1024; + const usize prefix_len = 1024; - char *prefix = malloc(sizeof(char) * 1024); + char* prefix = malloc(sizeof(char) * 1024); - snprintf(prefix, - prefix_len, - "["TERM_COLOR_YELLOW"DEBUG"TERM_COLOR_RESET"] " - "%s:%d <%s> ", file, line, func); + snprintf(prefix, prefix_len, + "[" TERM_COLOR_YELLOW "DEBUG" TERM_COLOR_RESET "] " + "%s:%d <%s> ", + file, line, func); - va_start(ap, fmt); - _log(stdout, prefix, fmt, ap); - va_end(ap); + va_start(ap, fmt); + _log(stdout, prefix, fmt, ap); + va_end(ap); - free(prefix); + free(prefix); } -void WARN(const char *fmt, ...) { - va_list ap; - va_start(ap, fmt); - _log(stderr, "[" TERM_COLOR_PURPLE "WARN" TERM_COLOR_RESET "] ", fmt, ap); - va_end(ap); - puts(""); +void WARN(const char* fmt, ...) { + va_list ap; + va_start(ap, fmt); + _log(stderr, "[" TERM_COLOR_PURPLE "WARN" TERM_COLOR_RESET "] ", fmt, ap); + va_end(ap); + puts(""); } -void ERROR(const char *fmt, ...) { - va_list ap; - va_start(ap, fmt); - _log(stderr, "[" TERM_COLOR_RED "ERROR" TERM_COLOR_RESET "] ", fmt, ap); - va_end(ap); - puts(""); +void ERROR(const char* fmt, ...) { + va_list ap; + va_start(ap, fmt); + _log(stderr, "[" TERM_COLOR_RED "ERROR" TERM_COLOR_RESET "] ", fmt, ap); + va_end(ap); + puts(""); } -- cgit v1.3