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

Function scan_page

internal/cbm/doc_pdf.c:1047–1282  ·  view source on GitHub ↗

One page: its line-local structural tokens, then its join proposals. */

Source from the content-addressed store, hash-verified

1045
1046/* One page: its line-local structural tokens, then its join proposals. */
1047static void scan_page(CBMExtractCtx *ctx, const char *text, size_t len, uint32_t page,
1048 const char *page_qn) {
1049 u32v_t norm = {0};
1050 if (!normalise(text, len, &norm)) {
1051 u32_free(&norm);
1052 ctx->result->doc_links.failed = true;
1053 return;
1054 }
1055 /* lines, each stripped; flat = lines joined by '\n' */
1056 u32v_t flat = {0};
1057 int *starts = NULL;
1058 int nlines = 0;
1059 int cap = 0;
1060 int *lens = NULL;
1061 for (int i = 0; i <= norm.n;) {
1062 int j = i;
1063 while (j < norm.n && norm.v[j] != '\n') {
1064 j++;
1065 }
1066 int a = i;
1067 int b = j;
1068 while (a < b && pdf_u_space(norm.v[a])) {
1069 a++;
1070 }
1071 while (b > a && pdf_u_space(norm.v[b - 1])) {
1072 b--;
1073 }
1074 if (nlines == cap) {
1075 cap = cap ? cap * 2 : PDF_LIST_MIN;
1076 int *g1 = (int *)cbm_realloc(CBM_MEM_CLASS_EXTRACT, starts, (size_t)cap * sizeof(int));
1077 if (g1) {
1078 starts = g1;
1079 }
1080 int *g2 = (int *)cbm_realloc(CBM_MEM_CLASS_EXTRACT, lens, (size_t)cap * sizeof(int));
1081 if (g2) {
1082 lens = g2;
1083 }
1084 if (!g1 || !g2) {
1085 flat.fail = true;
1086 break;
1087 }
1088 }
1089 if (nlines) {
1090 u32_push(&flat, '\n');
1091 }
1092 starts[nlines] = flat.n;
1093 lens[nlines] = b - a;
1094 nlines++;
1095 for (int k = a; k < b; k++) {
1096 u32_push(&flat, norm.v[k]);
1097 }
1098 if (j >= norm.n) {
1099 break;
1100 }
1101 i = j + 1;
1102 }
1103 u32_free(&norm);
1104 candv_t cv = {0};

Callers 2

cbm_pdf_test_scan_pageFunction · 0.85
cbm_pdf_extract_documentFunction · 0.85

Calls 15

u32_freeFunction · 0.85
pdf_u_spaceFunction · 0.85
cbm_reallocFunction · 0.85
u32_pushFunction · 0.85
candidatesFunction · 0.85
cbm_allocFunction · 0.85
structuralFunction · 0.85
kwarg_atFunction · 0.85
sb_cpsFunction · 0.85
kind_syntaxFunction · 0.85
line_ofFunction · 0.85
cbm_callocFunction · 0.85

Tested by

no test coverage detected