summaryrefslogtreecommitdiffstats
path: root/src/diag.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/diag.c')
-rw-r--r--src/diag.c28
1 files changed, 8 insertions, 20 deletions
diff --git a/src/diag.c b/src/diag.c
index bb744f6..4909cf5 100644
--- a/src/diag.c
+++ b/src/diag.c
@@ -1,21 +1,22 @@
// Copyright © Tavian Barnes <tavianator@tavianator.com>
// SPDX-License-Identifier: 0BSD
-#include "prelude.h"
#include "diag.h"
+
#include "alloc.h"
+#include "bfs.h"
#include "bfstd.h"
#include "color.h"
#include "ctx.h"
#include "dstring.h"
#include "expr.h"
-#include <errno.h>
+
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
/** bfs_diagf() implementation. */
-attr(printf(2, 0))
+_printf(2, 0)
static void bfs_vdiagf(const struct bfs_loc *loc, const char *format, va_list args) {
fprintf(stderr, "%s: %s@%s:%d: ", xgetprogname(), loc->func, loc->file, loc->line);
vfprintf(stderr, format, args);
@@ -29,7 +30,8 @@ void bfs_diagf(const struct bfs_loc *loc, const char *format, ...) {
va_end(args);
}
-noreturn void bfs_abortf(const struct bfs_loc *loc, const char *format, ...) {
+_noreturn
+void bfs_abortf(const struct bfs_loc *loc, const char *format, ...) {
va_list args;
va_start(args, format);
bfs_vdiagf(loc, format, args);
@@ -38,10 +40,6 @@ noreturn void bfs_abortf(const struct bfs_loc *loc, const char *format, ...) {
abort();
}
-const char *bfs_errstr(void) {
- return xstrerror(errno);
-}
-
const char *debug_flag_name(enum debug_flags flag) {
switch (flag) {
case DEBUG_COST:
@@ -68,7 +66,7 @@ const char *debug_flag_name(enum debug_flags flag) {
}
void bfs_perror(const struct bfs_ctx *ctx, const char *str) {
- bfs_error(ctx, "%s: %m.\n", str);
+ bfs_error(ctx, "%s: %s.\n", str, errstr());
}
void bfs_error(const struct bfs_ctx *ctx, const char *format, ...) {
@@ -95,19 +93,12 @@ bool bfs_debug(const struct bfs_ctx *ctx, enum debug_flags flag, const char *for
}
void bfs_verror(const struct bfs_ctx *ctx, const char *format, va_list args) {
- int error = errno;
-
bfs_error_prefix(ctx);
-
- errno = error;
cvfprintf(ctx->cerr, format, args);
}
bool bfs_vwarning(const struct bfs_ctx *ctx, const char *format, va_list args) {
- int error = errno;
-
if (bfs_warning_prefix(ctx)) {
- errno = error;
cvfprintf(ctx->cerr, format, args);
return true;
} else {
@@ -116,10 +107,7 @@ bool bfs_vwarning(const struct bfs_ctx *ctx, const char *format, va_list args) {
}
bool bfs_vdebug(const struct bfs_ctx *ctx, enum debug_flags flag, const char *format, va_list args) {
- int error = errno;
-
if (bfs_debug_prefix(ctx, flag)) {
- errno = error;
cvfprintf(ctx->cerr, format, args);
return true;
} else {
@@ -173,7 +161,7 @@ static bool highlight_expr_recursive(const struct bfs_ctx *ctx, const struct bfs
}
}
- for (struct bfs_expr *child = bfs_expr_children(expr); child; child = child->next) {
+ for_expr (child, expr) {
ret |= highlight_expr_recursive(ctx, child, args);
}