G Programming Language
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

32 lines
972 B

// log.c
// Log source file for G
// Copyright (C) 2022, Jakob Wakeling
// MIT Licence
#include "log.h"
#include "util/error.h"
#include "util/util.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
bool log_waerr = false;
sint log_level = 4, log_limit = 8;
static sint log_count = 0;
/* Log a compiler fatal (-1), error (0), warning (1-3), or note (4). */
void note(const char *file, UINT ln, UINT cl, sint level, const char *format, ...) {
if (file) { fprintf(stderr, "%s:%zu:%zu: ", file, ln + 1, cl + 1); }
if (level <= -1) { fprintf(stderr, "fatal: "); }
else if (level == 0) { fprintf(stderr, "error: "); }
else if (level <= 3) { fprintf(stderr, "warning: "); }
else if (level >= 4) { fprintf(stderr, "note: "); }
va_list va; va_start(va, format); vfprintf(stderr, format, va); va_end(va);
fputc('\n', stderr); if (level == -1) { exit(1); }
if (level == 0 && (log_count += 1) == log_limit) { error(1, "fatal: error limit reached"); }
}