Commit 16383a01 16383a0184fd266e33c7d16ef55ce0d39dd1206e by Sergey Poznyakoff

Improve linetrack interface

* include/mailutils/locus.h (mu_linetrack_rebase): New proto.
* libmailutils/locus/linetrack.c (mu_linetrack_rebase): New function.
* libmailutils/diag/diag.c (mu_diag_at_locus_range): New function.
1 parent 44ae83d0
......@@ -65,6 +65,7 @@ void mu_lrange_debug (struct mu_locus_range const *loc,
int mu_linetrack_create (mu_linetrack_t *ret,
char const *file_name, size_t max_lines);
int mu_linetrack_rebase (mu_linetrack_t trk, struct mu_locus_point const *pt);
void mu_linetrack_free (mu_linetrack_t trk);
void mu_linetrack_destroy (mu_linetrack_t *trk);
void mu_linetrack_advance (mu_linetrack_t trk,
......
......@@ -29,6 +29,7 @@
#include <mailutils/errno.h>
#include <mailutils/stdstream.h>
#include <mailutils/stream.h>
#include <mailutils/locus.h>
void
mu_diag_init ()
......@@ -71,6 +72,37 @@ mu_diag_at_locus (int level, struct mu_locus const *loc, const char *fmt, ...)
}
void
mu_diag_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;
}
}
va_start (ap, fmt);
mu_diag_voutput (level, fmt, ap);
va_end (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_vprintf (int level, const char *fmt, va_list ap)
{
mu_diag_init ();
......
......@@ -28,6 +28,24 @@ struct mu_linetrack
cols[head + n] (0 <= n <= tos). */
};
static inline unsigned *
cols_ptr (mu_linetrack_t trk, size_t n)
{
return &trk->cols[(trk->head + n) % trk->max_lines];
}
static inline unsigned *
cols_tos_ptr (mu_linetrack_t trk)
{
return cols_ptr (trk, trk->tos);
}
static inline unsigned
cols_peek (mu_linetrack_t trk, size_t n)
{
return *cols_ptr (trk, n);
}
int
mu_linetrack_create (mu_linetrack_t *ret,
char const *file_name, size_t max_lines)
......@@ -65,6 +83,20 @@ mu_linetrack_create (mu_linetrack_t *ret,
return 0;
}
int
mu_linetrack_rebase (mu_linetrack_t trk, struct mu_locus_point const *pt)
{
char const *file_name;
int rc = mu_ident_ref (pt->mu_file, &file_name);
if (rc)
return rc;
mu_ident_deref (trk->file_name);
trk->file_name = file_name;
trk->hline = pt->mu_line;
*cols_ptr (trk, 0) = pt->mu_col;
return 0;
}
void
mu_linetrack_free (mu_linetrack_t trk)
{
......@@ -87,18 +119,6 @@ mu_linetrack_destroy (mu_linetrack_t *trk)
}
static inline unsigned *
cols_tos_ptr (mu_linetrack_t trk)
{
return &trk->cols[(trk->head + trk->tos) % trk->max_lines];
}
static inline unsigned
cols_peek (mu_linetrack_t trk, size_t n)
{
return trk->cols[(trk->head + n) % trk->max_lines];
}
static inline unsigned *
push (mu_linetrack_t trk)
{
unsigned *ptr;
......