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); ...@@ -52,6 +52,8 @@ void mu_diag_cont_printf (const char *fmt, ...) MU_PRINTFLIKE(1,2);
52 52
53 void mu_diag_voutput (int, const char *, va_list); 53 void mu_diag_voutput (int, const char *, va_list);
54 void mu_diag_output (int, const char *, ...) MU_PRINTFLIKE(2,3); 54 void mu_diag_output (int, const char *, ...) MU_PRINTFLIKE(2,3);
55 void mu_vdiag_at_locus_range (int level, struct mu_locus_range const *loc,
56 const char *fmt, va_list ap);
55 void mu_diag_at_locus_point (int level, struct mu_locus_point const *loc, 57 void mu_diag_at_locus_point (int level, struct mu_locus_point const *loc,
56 const char *fmt, ...); 58 const char *fmt, ...);
57 void mu_diag_at_locus_range (int level, struct mu_locus_range const *loc, 59 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) ...@@ -163,13 +163,20 @@ mu_linetrack_origin (mu_linetrack_t trk, struct mu_locus_point const *pt)
163 { 163 {
164 int rc; 164 int rc;
165 struct source *sp; 165 struct source *sp;
166 char const *file_name;
166 167
167 if (!trk || !pt || !pt->mu_file || pt->mu_line == 0) 168 if (!trk || !pt || pt->mu_line == 0)
169 return EINVAL;
170 if (pt->mu_file)
171 file_name = pt->mu_file;
172 else if (trk->s_head)
173 file_name = trk->s_head->file_name;
174 else
168 return EINVAL; 175 return EINVAL;
169 sp = malloc (sizeof *sp); 176 sp = malloc (sizeof *sp);
170 if (!sp) 177 if (!sp)
171 return errno; 178 return errno;
172 rc = mu_ident_ref (pt->mu_file, &sp->file_name); 179 rc = mu_ident_ref (file_name, &sp->file_name);
173 if (rc) 180 if (rc)
174 { 181 {
175 free (sp); 182 free (sp);
......
...@@ -18,7 +18,7 @@ AT_BANNER([Line tracker]) ...@@ -18,7 +18,7 @@ AT_BANNER([Line tracker])
18 18
19 m4_pushdef([TRACKTEST],[ 19 m4_pushdef([TRACKTEST],[
20 AT_SETUP([$1]) 20 AT_SETUP([$1])
21 AT_KEYWORDS([tracker $2]) 21 AT_KEYWORDS([tracker linetrack $2])
22 AT_CHECK([linetrack liber $3 <<EOT 22 AT_CHECK([linetrack liber $3 <<EOT
23 $4[]EOT 23 $4[]EOT
24 ], 24 ],
...@@ -275,5 +275,20 @@ two ...@@ -275,5 +275,20 @@ two
275 archivum:5.4-6: two 275 archivum:5.4-6: two
276 ]) 276 ])
277 277
278 TRACKTEST([#line directive],[],[9],
279 [agnosco
280 veteris\n
281 vestigia
282 #line 20
283 flamme\n
284 #retreat 8
285 Naso
286 ],
287 [liber:1.1-7: agnosco
288 liber:1.8-14: veteris\n
289 liber:2.1-8: vestigia
290 liber:20.1-6: flamme\n
291 liber:2.8-11: Naso
292 ])
278 293
279 m4_popdef([TRACKTEST]) 294 m4_popdef([TRACKTEST])
......
...@@ -46,6 +46,19 @@ com_origin (mu_linetrack_t trk, size_t argc, char **argv) ...@@ -46,6 +46,19 @@ com_origin (mu_linetrack_t trk, size_t argc, char **argv)
46 } 46 }
47 47
48 static void 48 static void
49 com_line (mu_linetrack_t trk, size_t argc, char **argv)
50 {
51 int rc;
52 struct mu_locus_point pt = MU_LOCUS_POINT_INITIALIZER;
53
54 if (getnum (argv[1], &pt.mu_line))
55 return;
56 rc = mu_linetrack_origin (trk, &pt);
57 if (rc)
58 mu_diag_funcall (MU_DIAG_ERROR, "mu_linetrack_origin", NULL, rc);
59 }
60
61 static void
49 com_rebase (mu_linetrack_t trk, size_t argc, char **argv) 62 com_rebase (mu_linetrack_t trk, size_t argc, char **argv)
50 { 63 {
51 int rc; 64 int rc;
...@@ -110,6 +123,7 @@ struct command ...@@ -110,6 +123,7 @@ struct command
110 static struct command comtab[] = { 123 static struct command comtab[] = {
111 { "retreat", 2, com_retreat }, 124 { "retreat", 2, com_retreat },
112 { "origin", 4, com_origin }, 125 { "origin", 4, com_origin },
126 { "line", 2, com_line },
113 { "point", 1, com_point }, 127 { "point", 1, com_point },
114 { "rebase", 4, com_rebase }, 128 { "rebase", 4, com_rebase },
115 { "bol", 1, com_bol_p }, 129 { "bol", 1, com_bol_p },
......