MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / ad_include

Function ad_include

internal/cbm/doc_adoc.c:562–595  ·  view source on GitHub ↗

INCLUDE_RE ^(\\?)include::([^\[\s][^\[]*)\[(.*)\]\s*$ */

Source from the content-addressed store, hash-verified

560
561/* INCLUDE_RE ^(\\?)include::([^\[\s][^\[]*)\[(.*)\]\s*$ */
562static 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. */
598static bool ad_builtin(const char *s, size_t n) {

Callers 1

ad_tokensFunction · 0.85

Calls 7

ad_rlenFunction · 0.85
ad_blankFunction · 0.85
ad_expandFunction · 0.85
ad_attrlist_valueFunction · 0.85
ad_pushFunction · 0.85
cbm_arena_strndupFunction · 0.70
cbm_arena_sprintfFunction · 0.70

Tested by

no test coverage detected