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

Function node__try

extern/editline/src/keymacro.c:317–374  ·  view source on GitHub ↗

node__try(): * Find a node that matches *str or allocate a new one */

Source from the content-addressed store, hash-verified

315 * Find a node that matches *str or allocate a new one
316 */
317private int
318node__try(EditLine *el, keymacro_node_t *ptr, const Char *str,
319 keymacro_value_t *val, int ntype)
320{
321
322 if (ptr->ch != *str) {
323 keymacro_node_t *xm;
324
325 for (xm = ptr; xm->sibling != NULL; xm = xm->sibling)
326 if (xm->sibling->ch == *str)
327 break;
328 if (xm->sibling == NULL)
329 xm->sibling = node__get(*str); /* setup new node */
330 ptr = xm->sibling;
331 }
332 if (*++str == '\0') {
333 /* we're there */
334 if (ptr->next != NULL) {
335 node__put(el, ptr->next);
336 /* lose longer keys with this prefix */
337 ptr->next = NULL;
338 }
339 switch (ptr->type) {
340 case XK_CMD:
341 case XK_NOD:
342 break;
343 case XK_STR:
344 case XK_EXE:
345 if (ptr->val.str)
346 el_free(ptr->val.str);
347 break;
348 default:
349 EL_ABORT((el->el_errfile, "Bad XK_ type %d\n",
350 ptr->type));
351 break;
352 }
353
354 switch (ptr->type = ntype) {
355 case XK_CMD:
356 ptr->val = *val;
357 break;
358 case XK_STR:
359 case XK_EXE:
360 if ((ptr->val.str = Strdup(val->str)) == NULL)
361 return -1;
362 break;
363 default:
364 EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ntype));
365 break;
366 }
367 } else {
368 /* still more chars to go */
369 if (ptr->next == NULL)
370 ptr->next = node__get(*str); /* setup new node */
371 (void) node__try(el, ptr->next, str, val, ntype);
372 }
373 return 0;
374}

Callers 1

keymacro_addFunction · 0.85

Calls 2

node__getFunction · 0.85
node__putFunction · 0.85

Tested by

no test coverage detected