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

Function cbm_parse_inc_file

internal/cbm/macro_table.c:85–167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83}
84
85void cbm_parse_inc_file(CBMMacroTable *t, CBMArena *arena, const char *content) {
86 if (!content)
87 return;
88 const char *line = content;
89 while (*line) {
90 const char *end = strchr(line, '\n');
91 if (!end)
92 end = line + strlen(line);
93
94 const char *p = line;
95 while (*p == ' ' || *p == '\t')
96 p++;
97
98 if (strncmp(p, "#define", 7) == 0 && (p[7] == ' ' || p[7] == '\t')) {
99 p += 8;
100 while (*p == ' ' || *p == '\t')
101 p++;
102
103 const char *name_start = p;
104 while (*p && *p != '(' && *p != ' ' && *p != '\t' && p < end)
105 p++;
106 if (p == name_start)
107 goto next_line;
108
109 char name[256];
110 int nlen = (int)(p - name_start);
111 if (nlen >= (int)sizeof(name))
112 goto next_line;
113 memcpy(name, name_start, nlen);
114 name[nlen] = '\0';
115
116 int param_count = -1;
117 char param_names_buf[CBM_MACRO_MAX_PARAMS][64];
118 const char *param_name_ptrs[CBM_MACRO_MAX_PARAMS] = {NULL};
119
120 if (*p == '(') {
121 param_count = 0;
122 p++;
123 while (*p && *p != ')' && p < end) {
124 while (*p == ' ' || *p == '\t')
125 p++;
126 if (*p == ')')
127 break;
128 const char *pn_start = p;
129 while (*p && *p != ',' && *p != ')' && p < end)
130 p++;
131 int plen = (int)(p - pn_start);
132 while (plen > 0 && (pn_start[plen - 1] == ' ' || pn_start[plen - 1] == '\t'))
133 plen--;
134 if (plen > 0 && param_count < CBM_MACRO_MAX_PARAMS) {
135 memcpy(param_names_buf[param_count], pn_start, plen < 63 ? plen : 63);
136 param_names_buf[param_count][plen < 63 ? plen : 63] = '\0';
137 param_name_ptrs[param_count] = param_names_buf[param_count];
138 param_count++;
139 }
140 if (*p == ',')
141 p++;
142 }

Callers 2

test_extraction.cFile · 0.85

Calls 2

cbm_macro_table_addFunction · 0.85
cbm_arena_strndupFunction · 0.70

Tested by

no test coverage detected