node_lookup(): * look for the str starting at node ptr. * Print if last node */
| 488 | * Print if last node |
| 489 | */ |
| 490 | private int |
| 491 | node_lookup(EditLine *el, const Char *str, keymacro_node_t *ptr, size_t cnt) |
| 492 | { |
| 493 | ssize_t used; |
| 494 | |
| 495 | if (ptr == NULL) |
| 496 | return -1; /* cannot have null ptr */ |
| 497 | |
| 498 | if (!str || *str == 0) { |
| 499 | /* no more chars in str. node_enum from here. */ |
| 500 | (void) node_enum(el, ptr, cnt); |
| 501 | return 0; |
| 502 | } else { |
| 503 | /* If match put this char into el->el_keymacro.buf. Recurse */ |
| 504 | if (ptr->ch == *str) { |
| 505 | /* match found */ |
| 506 | used = ct_visual_char(el->el_keymacro.buf + cnt, |
| 507 | KEY_BUFSIZ - cnt, ptr->ch); |
| 508 | if (used == -1) |
| 509 | return -1; /* ran out of buffer space */ |
| 510 | if (ptr->next != NULL) |
| 511 | /* not yet at leaf */ |
| 512 | return (node_lookup(el, str + 1, ptr->next, |
| 513 | (size_t)used + cnt)); |
| 514 | else { |
| 515 | /* next node is null so key should be complete */ |
| 516 | if (str[1] == 0) { |
| 517 | size_t px = cnt + (size_t)used; |
| 518 | el->el_keymacro.buf[px] = '"'; |
| 519 | el->el_keymacro.buf[px + 1] = '\0'; |
| 520 | keymacro_kprint(el, el->el_keymacro.buf, |
| 521 | &ptr->val, ptr->type); |
| 522 | return 0; |
| 523 | } else |
| 524 | return -1; |
| 525 | /* mismatch -- str still has chars */ |
| 526 | } |
| 527 | } else { |
| 528 | /* no match found try sibling */ |
| 529 | if (ptr->sibling) |
| 530 | return (node_lookup(el, str, ptr->sibling, |
| 531 | cnt)); |
| 532 | else |
| 533 | return -1; |
| 534 | } |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | |
| 539 | /* node_enum(): |
no test coverage detected