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

Function op_note_module

src/pipeline/pass_operator.c:203–239  ·  view source on GitHub ↗

Note the `module` line of a go.mod at `file`. */

Source from the content-addressed store, hash-verified

201
202/* Note the `module` line of a go.mod at `file`. */
203static void op_note_module(op_modules_t *m, const char *file, const char *text) {
204 for (const char *p = strstr(text, "module"); p; p = strstr(p + SKIP_ONE, "module")) {
205 if ((p > text && p[-SKIP_ONE] != '\n') ||
206 (p[OP_SLEN("module")] != ' ' && p[OP_SLEN("module")] != '\t')) {
207 continue;
208 }
209 const char *q = p + OP_SLEN("module");
210 while (*q == ' ' || *q == '\t' || *q == '"') {
211 q++;
212 }
213 size_t n = strcspn(q, " \t\r\n\"/");
214 while (q[n] == '/') { /* module paths contain '/' */
215 n += SKIP_ONE + strcspn(q + n + SKIP_ONE, " \t\r\n\"/");
216 }
217 if (n == 0) {
218 return;
219 }
220 if (m->count == m->cap) {
221 int cap = m->cap ? m->cap * PAIR_LEN : OP_GROW_MIN;
222 op_module_t *grown =
223 cbm_realloc(CBM_MEM_CLASS_OTHER, m->items, (size_t)cap * sizeof(*grown));
224 if (!grown) {
225 return;
226 }
227 m->items = grown;
228 m->cap = cap;
229 }
230 char path[CBM_SZ_1K];
231 char dir[CBM_SZ_1K];
232 snprintf(path, sizeof(path), "%.*s", (int)n, q);
233 op_dirname(file, dir, sizeof(dir));
234 m->items[m->count].path = cbm_mem_strdup(CBM_MEM_CLASS_OTHER, path);
235 m->items[m->count].dir = cbm_mem_strdup(CBM_MEM_CLASS_OTHER, dir);
236 m->count++;
237 return;
238 }
239}
240
241/* The repository directory of import path `import`: below the go.mod whose
242 * module path is its longest prefix ("" when no module of the repository

Callers 1

Calls 3

cbm_reallocFunction · 0.85
op_dirnameFunction · 0.85
cbm_mem_strdupFunction · 0.85

Tested by

no test coverage detected