Commit 93a4e6d8 93a4e6d8020655f719c3f6ef8e9b36926cca010e by Sergey Poznyakoff

linetrack: handle #line directives without file name.

* include/mailutils/diag.h (mu_vdiag_at_locus_range): New proto.
* libmailutils/locus/linetrack.c (mu_linetrack_origin): accept
locus point with mu_file==NULL.  Reuse current file name in this
case.  This is to simplify handling of #line directives without
file name.
* libmailutils/tests/linetrack.c: Implement #line directive.
* libmailutils/tests/linetrack.at: Add new test.
1 parent 7892e5ba
......@@ -52,6 +52,8 @@ void mu_diag_cont_printf (const char *fmt, ...) MU_PRINTFLIKE(1,2);
void mu_diag_voutput (int, const char *, va_list);
void mu_diag_output (int, const char *, ...) MU_PRINTFLIKE(2,3);
void mu_vdiag_at_locus_range (int level, struct mu_locus_range const *loc,
const char *fmt, va_list ap);
void mu_diag_at_locus_point (int level, struct mu_locus_point const *loc,
const char *fmt, ...);
void mu_diag_at_locus_range (int level, struct mu_locus_range const *loc,
......
......@@ -163,13 +163,20 @@ mu_linetrack_origin (mu_linetrack_t trk, struct mu_locus_point const *pt)
{
int rc;
struct source *sp;
char const *file_name;
if (!trk || !pt || !pt->mu_file || pt->mu_line == 0)
if (!trk || !pt || pt->mu_line == 0)
return EINVAL;
if (pt->mu_file)
file_name = pt->mu_file;
else if (trk->s_head)
file_name = trk->s_head->file_name;
else
return EINVAL;
sp = malloc (sizeof *sp);
if (!sp)
return errno;
rc = mu_ident_ref (pt->mu_file, &sp->file_name);
rc = mu_ident_ref (file_name, &sp->file_name);
if (rc)
{
free (sp);
......
......@@ -18,7 +18,7 @@ AT_BANNER([Line tracker])
m4_pushdef([TRACKTEST],[
AT_SETUP([$1])
AT_KEYWORDS([tracker $2])
AT_KEYWORDS([tracker linetrack $2])
AT_CHECK([linetrack liber $3 <<EOT
$4[]EOT
],
......@@ -275,5 +275,20 @@ two
archivum:5.4-6: two
])
TRACKTEST([#line directive],[],[9],
[agnosco
veteris\n
vestigia
#line 20
flamme\n
#retreat 8
Naso
],
[liber:1.1-7: agnosco
liber:1.8-14: veteris\n
liber:2.1-8: vestigia
liber:20.1-6: flamme\n
liber:2.8-11: Naso
])
m4_popdef([TRACKTEST])
......
......@@ -46,6 +46,19 @@ com_origin (mu_linetrack_t trk, size_t argc, char **argv)
}
static void
com_line (mu_linetrack_t trk, size_t argc, char **argv)
{
int rc;
struct mu_locus_point pt = MU_LOCUS_POINT_INITIALIZER;
if (getnum (argv[1], &pt.mu_line))
return;
rc = mu_linetrack_origin (trk, &pt);
if (rc)
mu_diag_funcall (MU_DIAG_ERROR, "mu_linetrack_origin", NULL, rc);
}
static void
com_rebase (mu_linetrack_t trk, size_t argc, char **argv)
{
int rc;
......@@ -110,6 +123,7 @@ struct command
static struct command comtab[] = {
{ "retreat", 2, com_retreat },
{ "origin", 4, com_origin },
{ "line", 2, com_line },
{ "point", 1, com_point },
{ "rebase", 4, com_rebase },
{ "bol", 1, com_bol_p },
......