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

Function ad_structure

internal/cbm/doc_adoc.c:185–220  ·  view source on GitHub ↗

Delimited blocks, then the headings outside them. */

Source from the content-addressed store, hash-verified

183
184/* Delimited blocks, then the headings outside them. */
185static void ad_structure(ad_doc_t *d) {
186 int open = -1;
187 for (int i = 0; i < d->n; i++) {
188 int dl = ad_delim(&d->L[i]);
189 if (open < 0) {
190 if (dl) {
191 open = i;
192 d->in_block[i] = d->L[i].s[0] == '/' ? 2 : 1;
193 }
194 continue;
195 }
196 const ad_line_t *o = &d->L[open];
197 d->in_block[i] = d->L[open].s[0] == '/' ? 2 : 1;
198 if (dl && dl == ad_rlen(o) && memcmp(d->L[i].s, o->s, (size_t)dl) == 0) {
199 open = -1;
200 }
201 }
202 d->heads = (ad_head_t *)cbm_arena_alloc(d->scratch, (size_t)d->n * sizeof(*d->heads));
203 if (!d->heads) {
204 d->failed = true;
205 return;
206 }
207 for (int i = 0; i < d->n; i++) {
208 int ta;
209 int tb;
210 if (d->in_block[i] || ad_heading(&d->L[i], &ta, &tb) == 0) {
211 continue;
212 }
213 char *title = cbm_arena_strndup(d->ctx->arena, d->L[i].s + ta, (size_t)(tb - ta));
214 if (!title) {
215 d->failed = true;
216 return;
217 }
218 d->heads[d->nheads++] = (ad_head_t){.line = i, .title = title};
219 }
220}
221
222/* qn_safe_segment (extract_defs.c): whitespace runs become '-'. */
223static const char *ad_qn_segment(CBMArena *a, const char *name) {

Callers 1

Calls 5

ad_delimFunction · 0.85
ad_rlenFunction · 0.85
ad_headingFunction · 0.85
cbm_arena_allocFunction · 0.70
cbm_arena_strndupFunction · 0.70

Tested by

no test coverage detected