MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / node_lookup

Function node_lookup

extern/editline/src/keymacro.c:490–536  ·  view source on GitHub ↗

node_lookup(): * look for the str starting at node ptr. * Print if last node */

Source from the content-addressed store, hash-verified

488 * Print if last node
489 */
490private int
491node_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():

Callers 1

keymacro_printFunction · 0.85

Calls 3

node_enumFunction · 0.85
ct_visual_charFunction · 0.85
keymacro_kprintFunction · 0.85

Tested by

no test coverage detected