INCLUDE_RE ^(\\?)include::([^\[\s][^\[]*)\[(.*)\]\s*$ */
| 560 | |
| 561 | /* INCLUDE_RE ^(\\?)include::([^\[\s][^\[]*)\[(.*)\]\s*$ */ |
| 562 | static void ad_include(ad_doc_t *d, int i) { |
| 563 | const ad_line_t *l = &d->L[i]; |
| 564 | const char *s = l->s; |
| 565 | int n = ad_rlen(l); |
| 566 | static const char kw[] = "include::"; |
| 567 | int kl = (int)strlen(kw); |
| 568 | if (n < kl + 2 || memcmp(s, kw, (size_t)kl) != 0 || s[kl] == '[' || ad_blank(s[kl]) || |
| 569 | s[n - 1] != ']') { |
| 570 | return; |
| 571 | } |
| 572 | const char *open = memchr(s + kl, '[', (size_t)(n - kl)); |
| 573 | if (!open) { |
| 574 | return; |
| 575 | } |
| 576 | int ta = kl; |
| 577 | int tb = (int)(open - s); |
| 578 | int aa = tb + 1; |
| 579 | int ab = n - 1; |
| 580 | char *target = ad_expand(d, s + ta, tb - ta); |
| 581 | if (!target || strchr(target, '\t')) { |
| 582 | return; |
| 583 | } |
| 584 | char tags[AD_FIELD_MAX]; |
| 585 | char tag1[AD_FIELD_MAX]; |
| 586 | char lines[AD_FIELD_MAX]; |
| 587 | ad_attrlist_value(s + aa, ab - aa, "tags", tags, sizeof(tags)); |
| 588 | ad_attrlist_value(s + aa, ab - aa, "tag", tag1, sizeof(tag1)); |
| 589 | ad_attrlist_value(s + aa, ab - aa, "lines", lines, sizeof(lines)); |
| 590 | char *written = cbm_arena_strndup(d->ctx->arena, s, (size_t)n); |
| 591 | ad_push(d, i, CBM_DOCLINK_ADOC_INCLUDE, |
| 592 | written ? cbm_arena_sprintf(d->ctx->arena, "%s\t%s\t%s\t%s", written, target, |
| 593 | tags[0] ? tags : tag1, lines) |
| 594 | : NULL); |
| 595 | } |
| 596 | |
| 597 | /* Built-in attributes: characters and document settings, never a link. */ |
| 598 | static bool ad_builtin(const char *s, size_t n) { |
no test coverage detected