Big, ugly, horrible, quite possibly buggy... live with it or correct it and let me know */
| 272 | /* Big, ugly, horrible, quite possibly buggy... |
| 273 | live with it or correct it and let me know */ |
| 274 | static int tpl_construct(tpl_t *tpl, const char *p_last, const char *p_end) |
| 275 | { |
| 276 | const char *p_begin = p_last, *p_curr, *p_next; |
| 277 | tpl_node_t **tail = &tpl->head; |
| 278 | tpl_tcell_t **last_section = &tpl->first; |
| 279 | |
| 280 | /* While a field delimiter can be found in what is left */ |
| 281 | while ((p_curr = tpl_strstr(p_last, (ssize_t) (p_end - p_last), |
| 282 | DELIMITER_LEFT, DELIM_LEN_LEFT)) != NULL) |
| 283 | { |
| 284 | /* Advance to beginning of field/section name */ |
| 285 | p_curr += DELIM_LEN_LEFT; |
| 286 | |
| 287 | /* Find end delimiter of identifier or fail with syntax error */ |
| 288 | p_next = tpl_strstr(p_curr, (ssize_t) (p_end - p_curr), |
| 289 | DELIMITER_RIGHT, DELIM_LEN_RIGHT); |
| 290 | |
| 291 | if (p_next == NULL) |
| 292 | { |
| 293 | *last_section = NULL; |
| 294 | *tail = NULL; |
| 295 | return TPL_SYNTAX_ERROR; |
| 296 | } |
| 297 | |
| 298 | /* Section */ |
| 299 | if (p_curr + 1 >= p_begin + SEC_HEAD_LEN |
| 300 | && p_end - p_next >= (int) SEC_TAIL_LEN |
| 301 | && memcmp(SECTIONTAG_HEAD, p_curr - SEC_HEAD_LEN, |
| 302 | SEC_HEAD_LEN) == 0 |
| 303 | && memcmp(SECTIONTAG_TAIL, p_next, SEC_TAIL_LEN) == 0) |
| 304 | { |
| 305 | tpl_tcell_t *section; |
| 306 | |
| 307 | if ((p_curr - SEC_HEAD_LEN - p_last) != 0) |
| 308 | { |
| 309 | int val_len = (int) (p_curr - SEC_HEAD_LEN - p_last); |
| 310 | *tail = create_node(val_len); |
| 311 | (*tail)->val[val_len] = 0; |
| 312 | (void)memcpy((*tail)->val, p_last, val_len); |
| 313 | tail = &(*tail)->next; |
| 314 | } |
| 315 | |
| 316 | /* Create and chain in entry for section */ |
| 317 | section = tpl_make_section(tpl, p_curr, (int) (p_next - p_curr)); |
| 318 | |
| 319 | if (section != NULL) |
| 320 | { |
| 321 | int code; |
| 322 | const char *beginning, *ending; |
| 323 | |
| 324 | *last_section = section; |
| 325 | last_section = §ion->next; |
| 326 | section->preceding = tail; |
| 327 | |
| 328 | /* Advance past the section tag */ |
| 329 | p_last = p_next + SEC_TAIL_LEN; |
| 330 | beginning = p_next + SEC_TAIL_LEN; |
| 331 |
no test coverage detected
searching dependent graphs…