| 167 | } |
| 168 | |
| 169 | char *cbm_macro_expand(CBMArena *arena, const CBMMacroEntry *entry, const char **args, |
| 170 | int arg_count) { |
| 171 | if (!entry || !entry->expansion) |
| 172 | return NULL; |
| 173 | const char *tmpl = entry->expansion; |
| 174 | char buf[1024]; |
| 175 | int out = 0; |
| 176 | const char *p = tmpl; |
| 177 | while (*p && out < (int)sizeof(buf) - 1) { |
| 178 | if (*p == '%') { |
| 179 | bool matched = false; |
| 180 | for (int i = 0; i < entry->param_count && i < CBM_MACRO_MAX_PARAMS; i++) { |
| 181 | if (!entry->param_names[i]) |
| 182 | continue; |
| 183 | int pnlen = (int)strlen(entry->param_names[i]); |
| 184 | if (strncasecmp(p, entry->param_names[i], pnlen) == 0) { |
| 185 | const char *arg = (args && i < arg_count) ? args[i] : ""; |
| 186 | int alen = (int)strlen(arg); |
| 187 | if (out + alen < (int)sizeof(buf) - 1) { |
| 188 | memcpy(buf + out, arg, alen); |
| 189 | out += alen; |
| 190 | } |
| 191 | p += pnlen; |
| 192 | matched = true; |
| 193 | break; |
| 194 | } |
| 195 | } |
| 196 | if (!matched) |
| 197 | buf[out++] = *p++; |
| 198 | } else { |
| 199 | buf[out++] = *p++; |
| 200 | } |
| 201 | } |
| 202 | buf[out] = '\0'; |
| 203 | return cbm_arena_strdup(arena, buf); |
| 204 | } |
| 205 | |
| 206 | char *cbm_macro_extract_callee(CBMArena *arena, const char *expansion) { |
| 207 | if (!expansion) |
nothing calls this directly
no test coverage detected