diff options
Diffstat (limited to 'libmailutils/diag/diag.c')
-rw-r--r-- | libmailutils/diag/diag.c | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/libmailutils/diag/diag.c b/libmailutils/diag/diag.c index 318afe0a4..b5a7482a6 100644 --- a/libmailutils/diag/diag.c +++ b/libmailutils/diag/diag.c @@ -29,6 +29,7 @@ #include <mailutils/errno.h> #include <mailutils/stdstream.h> #include <mailutils/stream.h> +#include <mailutils/locus.h> void mu_diag_init () @@ -56,17 +57,52 @@ mu_diag_output (int level, const char *fmt, ...) } void -mu_diag_at_locus (int level, struct mu_locus const *loc, const char *fmt, ...) +mu_vdiag_at_locus_range (int level, struct mu_locus_range const *loc, + const char *fmt, va_list ap) +{ + struct mu_locus_range old = MU_LOCUS_RANGE_INITIALIZER; + int restore = 0; + + if (loc) + { + if (mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM, + MU_IOCTL_LOGSTREAM_GET_LOCUS_RANGE, &old) == 0) + { + mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM, + MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, (void*) loc); + restore = 1; + } + } + + mu_diag_voutput (level, fmt, ap); + + if (restore) + { + mu_stream_ioctl (mu_strerr, MU_IOCTL_LOGSTREAM, + MU_IOCTL_LOGSTREAM_SET_LOCUS_RANGE, &old); + mu_locus_range_deinit (&old); + } +} + +void +mu_diag_at_locus_range (int level, struct mu_locus_range const *loc, + const char *fmt, ...) { va_list ap; + va_start (ap, fmt); + mu_vdiag_at_locus_range (level, loc, fmt, ap); + va_end (ap); +} +void +mu_diag_at_locus_point (int level, struct mu_locus_point const *loc, + const char *fmt, ...) +{ + va_list ap; + struct mu_locus_range lr = MU_LOCUS_RANGE_INITIALIZER; + lr.beg = *loc; va_start (ap, fmt); - if (loc && loc->mu_file) - mu_stream_printf (mu_strerr, "\033f<%d>%s\033l<%u>\033c<%u>", - (unsigned) strlen (loc->mu_file), loc->mu_file, - loc->mu_line, - loc->mu_col); - mu_diag_voutput (level, fmt, ap); + mu_vdiag_at_locus_range (level, &lr, fmt, ap); va_end (ap); } |