| 83 | } |
| 84 | |
| 85 | void 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 | } |
no test coverage detected