| 489 | /* ── Tokens ──────────────────────────────────────────────────────── */ |
| 490 | |
| 491 | static void ad_push(ad_doc_t *d, int line, int syntax, const char *raw) { |
| 492 | if (!raw) { |
| 493 | d->failed = true; |
| 494 | return; |
| 495 | } |
| 496 | CBMExtractCtx *ctx = d->ctx; |
| 497 | int lo = 0; |
| 498 | int hi = d->nheads; |
| 499 | while (lo < hi) { |
| 500 | int mid = lo + ((hi - lo) / 2); |
| 501 | if (d->heads[mid].line <= line) { |
| 502 | lo = mid + 1; |
| 503 | } else { |
| 504 | hi = mid; |
| 505 | } |
| 506 | } |
| 507 | const ad_head_t *sec = lo > 0 ? &d->heads[lo - 1] : NULL; |
| 508 | if (sec && sec->shared_qn) { |
| 509 | sec = NULL; |
| 510 | } |
| 511 | CBMDocLink link = { |
| 512 | .source_qn = sec ? sec->qn : (ctx->module_qn ? ctx->module_qn : ""), |
| 513 | .raw = raw, |
| 514 | .line = (uint32_t)line + 1, |
| 515 | .def_line = sec ? (uint32_t)sec->line + 1 : 1, |
| 516 | .syntax = (uint16_t)syntax, |
| 517 | .flags = sec ? 0 : CBM_DOCLINK_FLAG_FILE, |
| 518 | }; |
| 519 | cbm_doclinks_push(&ctx->result->doc_links, ctx->arena, link); |
| 520 | } |
| 521 | |
| 522 | /* A value of the include's attribute list (`tag=x`, `tags="a;b"`, `lines=1..5`). */ |
| 523 | static void ad_attrlist_value(const char *al, int n, const char *key, char *out, size_t cap) { |
no test coverage detected