Lines Matching +full:cmd +full:- +full:cnt +full:- +full:name

3 /*-
18 * 3. Neither the name of the University nor the names of its contributors
46 * the extended-key map.
48 * An extended-key (key) is a sequence of keystrokes introduced
51 * el->el_keymacro.map)
52 * to convert these extended-key sequences into input strs
58 * are in el->el_keymacro.map, adding the key "abc" will cause
62 * -------------
73 * The Nodes of the el->el_keymacro.map. The el->el_keymacro.map is a
108 el->el_keymacro.buf = el_calloc(KEY_BUFSIZ, in keymacro_init()
109 sizeof(*el->el_keymacro.buf)); in keymacro_init()
110 if (el->el_keymacro.buf == NULL) in keymacro_init()
111 return -1; in keymacro_init()
112 el->el_keymacro.map = NULL; in keymacro_init()
124 el_free(el->el_keymacro.buf); in keymacro_end()
125 el->el_keymacro.buf = NULL; in keymacro_end()
126 node__free(el->el_keymacro.map); in keymacro_end()
131 * Associate cmd with a key value
134 keymacro_map_cmd(EditLine *el, int cmd) in keymacro_map_cmd() argument
137 el->el_keymacro.val.cmd = (el_action_t) cmd; in keymacro_map_cmd()
138 return &el->el_keymacro.val; in keymacro_map_cmd()
149 el->el_keymacro.val.str = str; in keymacro_map_str()
150 return &el->el_keymacro.val; in keymacro_map_str()
155 * Takes all nodes on el->el_keymacro.map and puts them on free list.
156 * Then initializes el->el_keymacro.map with arrow keys
163 node__put(el, el->el_keymacro.map); in keymacro_reset()
164 el->el_keymacro.map = NULL; in keymacro_reset()
170 * Calls the recursive function with entry point el->el_keymacro.map
182 return node_trav(el, el->el_keymacro.map, ch, val); in keymacro_get()
187 * Adds key to the el->el_keymacro.map and associates the value in
188 * val with it. If key is already is in el->el_keymacro.map, the new
198 (void) fprintf(el->el_errfile, in keymacro_add()
199 "keymacro_add: Null extended-key not allowed.\n"); in keymacro_add()
202 if (ntype == XK_CMD && val->cmd == ED_SEQUENCE_LEAD_IN) { in keymacro_add()
203 (void) fprintf(el->el_errfile, in keymacro_add()
204 "keymacro_add: sequence-lead-in command not allowed\n"); in keymacro_add()
207 if (el->el_keymacro.map == NULL) in keymacro_add()
209 el->el_keymacro.map = node__get(key[0]); in keymacro_add()
212 /* Now recurse through el->el_keymacro.map */ in keymacro_add()
213 (void) node__try(el, el->el_keymacro.map, key, val, ntype); in keymacro_add()
227 ((map == el->el_map.key && in keymacro_clear()
228 el->el_map.alt[(unsigned char)*in] != ED_SEQUENCE_LEAD_IN) || in keymacro_clear()
229 (map == el->el_map.alt && in keymacro_clear()
230 el->el_map.key[(unsigned char)*in] != ED_SEQUENCE_LEAD_IN))) in keymacro_clear()
244 (void) fprintf(el->el_errfile, in keymacro_delete()
245 "keymacro_delete: Null extended-key not allowed.\n"); in keymacro_delete()
246 return -1; in keymacro_delete()
248 if (el->el_keymacro.map == NULL) in keymacro_delete()
251 (void) node__delete(el, &el->el_keymacro.map, key); in keymacro_delete()
258 * Print entire el->el_keymacro.map if null
264 /* do nothing if el->el_keymacro.map is empty and null key specified */ in keymacro_print()
265 if (el->el_keymacro.map == NULL && *key == 0) in keymacro_print()
268 el->el_keymacro.buf[0] = '"'; in keymacro_print()
269 if (node_lookup(el, key, el->el_keymacro.map, (size_t)1) <= -1) in keymacro_print()
271 (void) fprintf(el->el_errfile, "Unbound extended key \"%ls" in keymacro_print()
286 if (ptr->ch == *ch) { in node_trav()
288 if (ptr->next) { in node_trav()
292 return node_trav(el, ptr->next, ch, val); in node_trav()
294 *val = ptr->val; in node_trav()
295 if (ptr->type != XK_CMD) in node_trav()
297 return ptr->type; in node_trav()
301 if (ptr->sibling) { in node_trav()
303 return node_trav(el, ptr->sibling, ch, val); in node_trav()
305 /* no next sibling -- mismatch */ in node_trav()
306 val->str = NULL; in node_trav()
321 if (ptr->ch != *str) { in node__try()
324 for (xm = ptr; xm->sibling != NULL; xm = xm->sibling) in node__try()
325 if (xm->sibling->ch == *str) in node__try()
327 if (xm->sibling == NULL) in node__try()
328 xm->sibling = node__get(*str); /* setup new node */ in node__try()
329 ptr = xm->sibling; in node__try()
333 if (ptr->next != NULL) { in node__try()
334 node__put(el, ptr->next); in node__try()
336 ptr->next = NULL; in node__try()
338 switch (ptr->type) { in node__try()
343 if (ptr->val.str) in node__try()
344 el_free(ptr->val.str); in node__try()
347 EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", in node__try()
348 ptr->type)); in node__try()
351 switch (ptr->type = ntype) { in node__try()
353 ptr->val = *val; in node__try()
356 if ((ptr->val.str = wcsdup(val->str)) == NULL) in node__try()
357 return -1; in node__try()
360 EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ntype)); in node__try()
364 if (ptr->next == NULL) in node__try()
365 ptr->next = node__get(*str); /* setup new node */ in node__try()
366 (void) node__try(el, ptr->next, str, val, ntype); in node__try()
383 if (ptr->ch != *str) { in node__delete()
386 for (xm = ptr; xm->sibling != NULL; xm = xm->sibling) in node__delete()
387 if (xm->sibling->ch == *str) in node__delete()
389 if (xm->sibling == NULL) in node__delete()
392 ptr = xm->sibling; in node__delete()
397 *inptr = ptr->sibling; in node__delete()
399 prev_ptr->sibling = ptr->sibling; in node__delete()
400 ptr->sibling = NULL; in node__delete()
403 } else if (ptr->next != NULL && in node__delete()
404 node__delete(el, &ptr->next, str) == 1) { in node__delete()
405 if (ptr->next != NULL) in node__delete()
408 *inptr = ptr->sibling; in node__delete()
410 prev_ptr->sibling = ptr->sibling; in node__delete()
411 ptr->sibling = NULL; in node__delete()
429 if (ptr->next != NULL) { in node__put()
430 node__put(el, ptr->next); in node__put()
431 ptr->next = NULL; in node__put()
433 node__put(el, ptr->sibling); in node__put()
435 switch (ptr->type) { in node__put()
440 if (ptr->val.str != NULL) in node__put()
441 el_free(ptr->val.str); in node__put()
444 EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ptr->type)); in node__put()
461 ptr->ch = ch; in node__get()
462 ptr->type = XK_NOD; in node__get()
463 ptr->val.str = NULL; in node__get()
464 ptr->next = NULL; in node__get()
465 ptr->sibling = NULL; in node__get()
474 node__free(k->sibling); in node__free()
475 node__free(k->next); in node__free()
485 size_t cnt) in node_lookup() argument
490 return -1; /* cannot have null ptr */ in node_lookup()
494 (void) node_enum(el, ptr, cnt); in node_lookup()
497 /* If match put this char into el->el_keymacro.buf. Recurse */ in node_lookup()
498 if (ptr->ch == *str) { in node_lookup()
500 used = ct_visual_char(el->el_keymacro.buf + cnt, in node_lookup()
501 KEY_BUFSIZ - cnt, ptr->ch); in node_lookup()
502 if (used == -1) in node_lookup()
503 return -1; /* ran out of buffer space */ in node_lookup()
504 if (ptr->next != NULL) in node_lookup()
506 return (node_lookup(el, str + 1, ptr->next, in node_lookup()
507 (size_t)used + cnt)); in node_lookup()
511 size_t px = cnt + (size_t)used; in node_lookup()
512 el->el_keymacro.buf[px] = '"'; in node_lookup()
513 el->el_keymacro.buf[px + 1] = '\0'; in node_lookup()
514 keymacro_kprint(el, el->el_keymacro.buf, in node_lookup()
515 &ptr->val, ptr->type); in node_lookup()
518 return -1; in node_lookup()
519 /* mismatch -- str still has chars */ in node_lookup()
523 if (ptr->sibling) in node_lookup()
524 return (node_lookup(el, str, ptr->sibling, in node_lookup()
525 cnt)); in node_lookup()
527 return -1; in node_lookup()
537 node_enum(EditLine *el, keymacro_node_t *ptr, size_t cnt) in node_enum() argument
541 if (cnt >= KEY_BUFSIZ - 5) { /* buffer too small */ in node_enum()
542 el->el_keymacro.buf[++cnt] = '"'; in node_enum()
543 el->el_keymacro.buf[++cnt] = '\0'; in node_enum()
544 (void) fprintf(el->el_errfile, in node_enum()
546 (void) fprintf(el->el_errfile, " \"%ls...\"\n", in node_enum()
547 el->el_keymacro.buf); in node_enum()
552 (void) fprintf(el->el_errfile, in node_enum()
555 return -1; in node_enum()
558 used = ct_visual_char(el->el_keymacro.buf + cnt, KEY_BUFSIZ - cnt, in node_enum()
559 ptr->ch); in node_enum()
560 if (ptr->next == NULL) { in node_enum()
562 el->el_keymacro.buf[cnt + (size_t)used ] = '"'; in node_enum()
563 el->el_keymacro.buf[cnt + (size_t)used + 1] = '\0'; in node_enum()
564 keymacro_kprint(el, el->el_keymacro.buf, &ptr->val, ptr->type); in node_enum()
566 (void) node_enum(el, ptr->next, cnt + (size_t)used); in node_enum()
569 if (ptr->sibling) in node_enum()
570 (void) node_enum(el, ptr->sibling, cnt); in node_enum()
585 static const char fmt[] = "%-15s-> %s\n"; in keymacro_kprint()
590 (void) keymacro__decode_str(val->str, unparsbuf, in keymacro_kprint()
593 (void) fprintf(el->el_outfile, fmt, in keymacro_kprint()
594 ct_encode_string(key, &el->el_scratch), unparsbuf); in keymacro_kprint()
597 for (fp = el->el_map.help; fp->name; fp++) in keymacro_kprint()
598 if (val->cmd == fp->func) { in keymacro_kprint()
599 wcstombs(unparsbuf, fp->name, sizeof(unparsbuf)); in keymacro_kprint()
600 unparsbuf[sizeof(unparsbuf) -1] = '\0'; in keymacro_kprint()
601 (void) fprintf(el->el_outfile, fmt, in keymacro_kprint()
602 ct_encode_string(key, &el->el_scratch), unparsbuf); in keymacro_kprint()
606 if (fp->name == NULL) in keymacro_kprint()
607 (void) fprintf(el->el_outfile, in keymacro_kprint()
613 EL_ABORT((el->el_errfile, "Bad XK_ type %d\n", ntype)); in keymacro_kprint()
616 (void) fprintf(el->el_outfile, fmt, ct_encode_string(key, in keymacro_kprint()
617 &el->el_scratch), "no input"); in keymacro_kprint()
649 while (l-- > 0) { in keymacro__decode_str()
650 ssize_t n = ct_encode_char(b, (size_t)(eb - b), *p2++); in keymacro__decode_str()
651 if (n == -1) /* ran out of space */ in keymacro__decode_str()
662 if ((size_t)(b - buf) >= len) in keymacro__decode_str()
663 buf[len - 1] = '\0'; in keymacro__decode_str()
664 return (size_t)(b - buf); in keymacro__decode_str()