-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
47 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// This Source Form is subject to the terms of the AQUA Software License, | ||
// v. 1.0. Copyright (c) 2024 Aymeric Wibo | ||
|
||
#pragma once | ||
|
||
#include "flamingo.h" | ||
#include "runtime/tree_sitter/api.h" | ||
|
||
#include <assert.h> | ||
#include <stdarg.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
__attribute__((format(printf, 2, 3))) static int error(flamingo_t* flamingo, char const* fmt, ...) { | ||
va_list args; | ||
va_start(args, fmt); | ||
|
||
// TODO validate the size of the program name | ||
|
||
// format caller's error message | ||
|
||
char formatted[sizeof flamingo->err]; | ||
size_t res = vsnprintf(formatted, sizeof formatted, fmt, args); | ||
assert(res < sizeof formatted); | ||
|
||
// format the new error message and concatenate to the previous one if there were still errors outstanding | ||
// TODO truncate the number of errors that we show at once (just do this by seeing how much longer we have) | ||
|
||
if (flamingo->errors_outstanding) { | ||
size_t const prev_len = strlen(flamingo->err); | ||
res = snprintf(flamingo->err + prev_len, sizeof flamingo->err - prev_len, ", %s:%d:%d: %s", flamingo->progname, 0, 0, formatted); | ||
} | ||
|
||
else { | ||
res = snprintf(flamingo->err, sizeof flamingo->err, "%s:%d:%d: %s", flamingo->progname, 0, 0, formatted); | ||
} | ||
|
||
assert(res < sizeof flamingo->err); | ||
|
||
va_end(args); | ||
flamingo->errors_outstanding = true; | ||
|
||
return -1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters