Recursive copy */
| 573 | |
| 574 | /* Recursive copy */ |
| 575 | void tpl_copy(tpl_t* tpl, const tpl_t* srctpl) |
| 576 | { |
| 577 | tpl_node_t **tail = &tpl->head; |
| 578 | tpl_node_t *curr_node = srctpl->head; |
| 579 | tpl_tcell_t **last_section = &tpl->first; |
| 580 | tpl_tcell_t *curr_section = srctpl->first; |
| 581 | |
| 582 | for (; curr_section != NULL; curr_section = curr_section->next) |
| 583 | { |
| 584 | /* Copy text and fields until the current section's position */ |
| 585 | while (curr_node != *curr_section->preceding) |
| 586 | { |
| 587 | /* Text */ |
| 588 | if (curr_node->val != NULL) |
| 589 | { |
| 590 | *tail = create_node(curr_node->len); |
| 591 | (void)memcpy((*tail)->val, curr_node->val, curr_node->len); |
| 592 | (*tail)->val[curr_node->len] = 0; |
| 593 | } |
| 594 | /* Field */ |
| 595 | else |
| 596 | { |
| 597 | /* Create node and set fval to field cell */ |
| 598 | *tail = create_node(0); |
| 599 | (*tail)->val = NULL; |
| 600 | |
| 601 | tpl_cpy_field((*tail)->fval, |
| 602 | tpl, |
| 603 | curr_node->fval->key, |
| 604 | (int) strlen(curr_node->fval->key), |
| 605 | curr_node->fval->val, |
| 606 | curr_node->fval->len); |
| 607 | |
| 608 | } |
| 609 | |
| 610 | tail = &(*tail)->next; |
| 611 | curr_node = curr_node->next; |
| 612 | } |
| 613 | |
| 614 | /* Create emtpy section entry for current section */ |
| 615 | *last_section = tpl_make_section(tpl, |
| 616 | curr_section->key, |
| 617 | (int) strlen(curr_section->key)); |
| 618 | |
| 619 | (*last_section)->preceding = tail; |
| 620 | |
| 621 | |
| 622 | /* Consolidate added content into a single node in newly created |
| 623 | section entry so that only one memory allocation is needed */ |
| 624 | if (curr_section->tpl->added_head != NULL) |
| 625 | { |
| 626 | tpl_node_t *some_node = curr_section->tpl->added_head; |
| 627 | char *buffer; |
| 628 | int len = 0; |
| 629 | |
| 630 | /* Get length of added content */ |
| 631 | for (; some_node!=NULL; some_node=some_node->next) |
| 632 | len += some_node->len; |
nothing calls this directly
no test coverage detected
searching dependent graphs…