1 /* $NetBSD: vi.c,v 1.62 2016/05/09 21:46:56 christos Exp $ */
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Christos Zoulas of Cornell University.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #if !defined(lint) && !defined(SCCSID)
38 static char sccsid[] = "@(#)vi.c 8.1 (Berkeley) 6/4/93";
40 __RCSID("$NetBSD: vi.c,v 1.62 2016/05/09 21:46:56 christos Exp $");
42 #endif /* not lint && not SCCSID */
45 * vi.c: Vi mode commands.
60 static el_action_t cv_action(EditLine *, wint_t);
61 static el_action_t cv_paste(EditLine *, wint_t);
67 cv_action(EditLine *el, wint_t c)
70 if (el->el_chared.c_vcmd.action != NOP) {
71 /* 'cc', 'dd' and (possibly) friends */
72 if (c != (wint_t)el->el_chared.c_vcmd.action)
77 cv_yank(el, el->el_line.buffer,
78 (int)(el->el_line.lastchar - el->el_line.buffer));
79 el->el_chared.c_vcmd.action = NOP;
80 el->el_chared.c_vcmd.pos = 0;
82 el->el_line.lastchar = el->el_line.buffer;
83 el->el_line.cursor = el->el_line.buffer;
86 el->el_map.current = el->el_map.key;
90 el->el_chared.c_vcmd.pos = el->el_line.cursor;
91 el->el_chared.c_vcmd.action = c;
96 * Paste previous deletion before or after the cursor
99 cv_paste(EditLine *el, wint_t c)
101 c_kill_t *k = &el->el_chared.c_kill;
102 size_t len = (size_t)(k->last - k->buf);
104 if (k->buf == NULL || len == 0)
107 (void) fprintf(el->el_errfile, "Paste: \"%.*ls\"\n", (int)len,
113 if (!c && el->el_line.cursor < el->el_line.lastchar)
114 el->el_line.cursor++;
116 c_insert(el, (int)len);
117 if (el->el_line.cursor + len > el->el_line.lastchar)
119 (void) memcpy(el->el_line.cursor, k->buf, len *
120 sizeof(*el->el_line.cursor));
127 * Vi paste previous deletion to the right of the cursor
130 libedit_private el_action_t
132 vi_paste_next(EditLine *el, wint_t c __attribute__((__unused__)))
135 return cv_paste(el, 0);
140 * Vi paste previous deletion to the left of the cursor
143 libedit_private el_action_t
145 vi_paste_prev(EditLine *el, wint_t c __attribute__((__unused__)))
148 return cv_paste(el, 1);
152 /* vi_prev_big_word():
153 * Vi move to the previous space delimited word
156 libedit_private el_action_t
158 vi_prev_big_word(EditLine *el, wint_t c __attribute__((__unused__)))
161 if (el->el_line.cursor == el->el_line.buffer)
164 el->el_line.cursor = cv_prev_word(el->el_line.cursor,
166 el->el_state.argument,
169 if (el->el_chared.c_vcmd.action != NOP) {
178 * Vi move to the previous word
181 libedit_private el_action_t
183 vi_prev_word(EditLine *el, wint_t c __attribute__((__unused__)))
186 if (el->el_line.cursor == el->el_line.buffer)
189 el->el_line.cursor = cv_prev_word(el->el_line.cursor,
191 el->el_state.argument,
194 if (el->el_chared.c_vcmd.action != NOP) {
202 /* vi_next_big_word():
203 * Vi move to the next space delimited word
206 libedit_private el_action_t
208 vi_next_big_word(EditLine *el, wint_t c __attribute__((__unused__)))
211 if (el->el_line.cursor >= el->el_line.lastchar - 1)
214 el->el_line.cursor = cv_next_word(el, el->el_line.cursor,
215 el->el_line.lastchar, el->el_state.argument, cv__isWord);
217 if (el->el_map.type == MAP_VI)
218 if (el->el_chared.c_vcmd.action != NOP) {
227 * Vi move to the next word
230 libedit_private el_action_t
232 vi_next_word(EditLine *el, wint_t c __attribute__((__unused__)))
235 if (el->el_line.cursor >= el->el_line.lastchar - 1)
238 el->el_line.cursor = cv_next_word(el, el->el_line.cursor,
239 el->el_line.lastchar, el->el_state.argument, cv__isword);
241 if (el->el_map.type == MAP_VI)
242 if (el->el_chared.c_vcmd.action != NOP) {
251 * Vi change case of character under the cursor and advance one character
254 libedit_private el_action_t
255 vi_change_case(EditLine *el, wint_t c)
259 if (el->el_line.cursor >= el->el_line.lastchar)
262 for (i = 0; i < el->el_state.argument; i++) {
264 c = *el->el_line.cursor;
266 *el->el_line.cursor = towlower(c);
267 else if (iswlower(c))
268 *el->el_line.cursor = towupper(c);
270 if (++el->el_line.cursor >= el->el_line.lastchar) {
271 el->el_line.cursor--;
282 * Vi change prefix command
285 libedit_private el_action_t
287 vi_change_meta(EditLine *el, wint_t c __attribute__((__unused__)))
291 * Delete with insert == change: first we delete and then we leave in
294 return cv_action(el, DELETE | INSERT);
298 /* vi_insert_at_bol():
299 * Vi enter insert mode at the beginning of line
302 libedit_private el_action_t
304 vi_insert_at_bol(EditLine *el, wint_t c __attribute__((__unused__)))
307 el->el_line.cursor = el->el_line.buffer;
309 el->el_map.current = el->el_map.key;
314 /* vi_replace_char():
315 * Vi replace character under the cursor with the next character typed
318 libedit_private el_action_t
320 vi_replace_char(EditLine *el, wint_t c __attribute__((__unused__)))
323 if (el->el_line.cursor >= el->el_line.lastchar)
326 el->el_map.current = el->el_map.key;
327 el->el_state.inputmode = MODE_REPLACE_1;
333 /* vi_replace_mode():
334 * Vi enter replace mode
337 libedit_private el_action_t
339 vi_replace_mode(EditLine *el, wint_t c __attribute__((__unused__)))
342 el->el_map.current = el->el_map.key;
343 el->el_state.inputmode = MODE_REPLACE;
349 /* vi_substitute_char():
350 * Vi replace character under the cursor and enter insert mode
353 libedit_private el_action_t
355 vi_substitute_char(EditLine *el, wint_t c __attribute__((__unused__)))
358 c_delafter(el, el->el_state.argument);
359 el->el_map.current = el->el_map.key;
364 /* vi_substitute_line():
365 * Vi substitute entire line
368 libedit_private el_action_t
370 vi_substitute_line(EditLine *el, wint_t c __attribute__((__unused__)))
374 cv_yank(el, el->el_line.buffer,
375 (int)(el->el_line.lastchar - el->el_line.buffer));
376 (void) em_kill_line(el, 0);
377 el->el_map.current = el->el_map.key;
382 /* vi_change_to_eol():
383 * Vi change to end of line
386 libedit_private el_action_t
388 vi_change_to_eol(EditLine *el, wint_t c __attribute__((__unused__)))
392 cv_yank(el, el->el_line.cursor,
393 (int)(el->el_line.lastchar - el->el_line.cursor));
394 (void) ed_kill_line(el, 0);
395 el->el_map.current = el->el_map.key;
401 * Vi enter insert mode
404 libedit_private el_action_t
406 vi_insert(EditLine *el, wint_t c __attribute__((__unused__)))
409 el->el_map.current = el->el_map.key;
416 * Vi enter insert mode after the cursor
419 libedit_private el_action_t
421 vi_add(EditLine *el, wint_t c __attribute__((__unused__)))
425 el->el_map.current = el->el_map.key;
426 if (el->el_line.cursor < el->el_line.lastchar) {
427 el->el_line.cursor++;
428 if (el->el_line.cursor > el->el_line.lastchar)
429 el->el_line.cursor = el->el_line.lastchar;
436 return (el_action_t)ret;
441 * Vi enter insert mode at end of line
444 libedit_private el_action_t
446 vi_add_at_eol(EditLine *el, wint_t c __attribute__((__unused__)))
449 el->el_map.current = el->el_map.key;
450 el->el_line.cursor = el->el_line.lastchar;
457 * Vi delete prefix command
460 libedit_private el_action_t
462 vi_delete_meta(EditLine *el, wint_t c __attribute__((__unused__)))
465 return cv_action(el, DELETE);
469 /* vi_end_big_word():
470 * Vi move to the end of the current space delimited word
473 libedit_private el_action_t
475 vi_end_big_word(EditLine *el, wint_t c __attribute__((__unused__)))
478 if (el->el_line.cursor == el->el_line.lastchar)
481 el->el_line.cursor = cv__endword(el->el_line.cursor,
482 el->el_line.lastchar, el->el_state.argument, cv__isWord);
484 if (el->el_chared.c_vcmd.action != NOP) {
485 el->el_line.cursor++;
494 * Vi move to the end of the current word
497 libedit_private el_action_t
499 vi_end_word(EditLine *el, wint_t c __attribute__((__unused__)))
502 if (el->el_line.cursor == el->el_line.lastchar)
505 el->el_line.cursor = cv__endword(el->el_line.cursor,
506 el->el_line.lastchar, el->el_state.argument, cv__isword);
508 if (el->el_chared.c_vcmd.action != NOP) {
509 el->el_line.cursor++;
518 * Vi undo last change
521 libedit_private el_action_t
523 vi_undo(EditLine *el, wint_t c __attribute__((__unused__)))
525 c_undo_t un = el->el_chared.c_undo;
530 /* switch line buffer and undo buffer */
531 el->el_chared.c_undo.buf = el->el_line.buffer;
532 el->el_chared.c_undo.len = el->el_line.lastchar - el->el_line.buffer;
533 el->el_chared.c_undo.cursor =
534 (int)(el->el_line.cursor - el->el_line.buffer);
535 el->el_line.limit = un.buf + (el->el_line.limit - el->el_line.buffer);
536 el->el_line.buffer = un.buf;
537 el->el_line.cursor = un.buf + un.cursor;
538 el->el_line.lastchar = un.buf + un.len;
544 /* vi_command_mode():
545 * Vi enter command mode (use alternative key bindings)
548 libedit_private el_action_t
550 vi_command_mode(EditLine *el, wint_t c __attribute__((__unused__)))
553 /* [Esc] cancels pending action */
554 el->el_chared.c_vcmd.action = NOP;
555 el->el_chared.c_vcmd.pos = 0;
557 el->el_state.doingarg = 0;
559 el->el_state.inputmode = MODE_INSERT;
560 el->el_map.current = el->el_map.alt;
562 if (el->el_line.cursor > el->el_line.buffer)
563 el->el_line.cursor--;
570 * Vi move to the beginning of line
573 libedit_private el_action_t
574 vi_zero(EditLine *el, wint_t c)
577 if (el->el_state.doingarg)
578 return ed_argument_digit(el, c);
580 el->el_line.cursor = el->el_line.buffer;
581 if (el->el_chared.c_vcmd.action != NOP) {
589 /* vi_delete_prev_char():
590 * Vi move to previous character (backspace)
591 * [^H] in insert mode only
593 libedit_private el_action_t
595 vi_delete_prev_char(EditLine *el, wint_t c __attribute__((__unused__)))
598 if (el->el_line.cursor <= el->el_line.buffer)
602 el->el_line.cursor--;
608 * Vi list choices for completion or indicate end of file if empty line
611 libedit_private el_action_t
613 vi_list_or_eof(EditLine *el, wint_t c)
616 if (el->el_line.cursor == el->el_line.lastchar) {
617 if (el->el_line.cursor == el->el_line.buffer) {
618 terminal_writec(el, c); /* then do a EOF */
622 * Here we could list completions, but it is an
631 *el->el_line.lastchar = '\0'; /* just in case */
632 return CC_LIST_CHOICES;
635 * Just complain for now.
644 /* vi_kill_line_prev():
645 * Vi cut from beginning of line to cursor
648 libedit_private el_action_t
650 vi_kill_line_prev(EditLine *el, wint_t c __attribute__((__unused__)))
654 cp = el->el_line.buffer;
655 kp = el->el_chared.c_kill.buf;
656 while (cp < el->el_line.cursor)
657 *kp++ = *cp++; /* copy it */
658 el->el_chared.c_kill.last = kp;
659 c_delbefore(el, (int)(el->el_line.cursor - el->el_line.buffer));
660 el->el_line.cursor = el->el_line.buffer; /* zap! */
666 * Vi search history previous
669 libedit_private el_action_t
671 vi_search_prev(EditLine *el, wint_t c __attribute__((__unused__)))
674 return cv_search(el, ED_SEARCH_PREV_HISTORY);
679 * Vi search history next
682 libedit_private el_action_t
684 vi_search_next(EditLine *el, wint_t c __attribute__((__unused__)))
687 return cv_search(el, ED_SEARCH_NEXT_HISTORY);
691 /* vi_repeat_search_next():
692 * Vi repeat current search in the same search direction
695 libedit_private el_action_t
697 vi_repeat_search_next(EditLine *el, wint_t c __attribute__((__unused__)))
700 if (el->el_search.patlen == 0)
703 return cv_repeat_srch(el, el->el_search.patdir);
707 /* vi_repeat_search_prev():
708 * Vi repeat current search in the opposite search direction
712 libedit_private el_action_t
713 vi_repeat_search_prev(EditLine *el, wint_t c __attribute__((__unused__)))
716 if (el->el_search.patlen == 0)
719 return (cv_repeat_srch(el,
720 el->el_search.patdir == ED_SEARCH_PREV_HISTORY ?
721 ED_SEARCH_NEXT_HISTORY : ED_SEARCH_PREV_HISTORY));
726 * Vi move to the character specified next
729 libedit_private el_action_t
731 vi_next_char(EditLine *el, wint_t c __attribute__((__unused__)))
733 return cv_csearch(el, CHAR_FWD, -1, el->el_state.argument, 0);
738 * Vi move to the character specified previous
741 libedit_private el_action_t
743 vi_prev_char(EditLine *el, wint_t c __attribute__((__unused__)))
745 return cv_csearch(el, CHAR_BACK, -1, el->el_state.argument, 0);
749 /* vi_to_next_char():
750 * Vi move up to the character specified next
753 libedit_private el_action_t
755 vi_to_next_char(EditLine *el, wint_t c __attribute__((__unused__)))
757 return cv_csearch(el, CHAR_FWD, -1, el->el_state.argument, 1);
761 /* vi_to_prev_char():
762 * Vi move up to the character specified previous
765 libedit_private el_action_t
767 vi_to_prev_char(EditLine *el, wint_t c __attribute__((__unused__)))
769 return cv_csearch(el, CHAR_BACK, -1, el->el_state.argument, 1);
773 /* vi_repeat_next_char():
774 * Vi repeat current character search in the same search direction
777 libedit_private el_action_t
779 vi_repeat_next_char(EditLine *el, wint_t c __attribute__((__unused__)))
782 return cv_csearch(el, el->el_search.chadir, el->el_search.chacha,
783 el->el_state.argument, el->el_search.chatflg);
787 /* vi_repeat_prev_char():
788 * Vi repeat current character search in the opposite search direction
791 libedit_private el_action_t
793 vi_repeat_prev_char(EditLine *el, wint_t c __attribute__((__unused__)))
796 int dir = el->el_search.chadir;
798 r = cv_csearch(el, -dir, el->el_search.chacha,
799 el->el_state.argument, el->el_search.chatflg);
800 el->el_search.chadir = dir;
806 * Vi go to matching () {} or []
809 libedit_private el_action_t
811 vi_match(EditLine *el, wint_t c __attribute__((__unused__)))
813 const wchar_t match_chars[] = L"()[]{}";
815 size_t delta, i, count;
818 *el->el_line.lastchar = '\0'; /* just in case */
820 i = wcscspn(el->el_line.cursor, match_chars);
821 o_ch = el->el_line.cursor[i];
824 delta = (size_t)(wcschr(match_chars, o_ch) - match_chars);
825 c_ch = match_chars[delta ^ 1];
827 delta = 1 - (delta & 1) * 2;
829 for (cp = &el->el_line.cursor[i]; count; ) {
831 if (cp < el->el_line.buffer || cp >= el->el_line.lastchar)
835 else if (*cp == c_ch)
839 el->el_line.cursor = cp;
841 if (el->el_chared.c_vcmd.action != NOP) {
842 /* NB posix says char under cursor should NOT be deleted
843 for -ve delta - this is different to netbsd vi. */
845 el->el_line.cursor++;
853 * Vi undo all changes to line
856 libedit_private el_action_t
858 vi_undo_line(EditLine *el, wint_t c __attribute__((__unused__)))
866 * Vi go to specified column
868 * NB netbsd vi goes to screen column 'n', posix says nth character
870 libedit_private el_action_t
872 vi_to_column(EditLine *el, wint_t c __attribute__((__unused__)))
875 el->el_line.cursor = el->el_line.buffer;
876 el->el_state.argument--;
877 return ed_next_char(el, 0);
881 * Vi yank to end of line
884 libedit_private el_action_t
886 vi_yank_end(EditLine *el, wint_t c __attribute__((__unused__)))
889 cv_yank(el, el->el_line.cursor,
890 (int)(el->el_line.lastchar - el->el_line.cursor));
898 libedit_private el_action_t
900 vi_yank(EditLine *el, wint_t c __attribute__((__unused__)))
903 return cv_action(el, YANK);
907 * Vi comment out current command
910 libedit_private el_action_t
912 vi_comment_out(EditLine *el, wint_t c __attribute__((__unused__)))
915 el->el_line.cursor = el->el_line.buffer;
917 *el->el_line.cursor = '#';
919 return ed_newline(el, 0);
923 * Vi include shell alias
925 * NB: posix implies that we should enter insert mode, however
926 * this is against historical precedent...
928 libedit_private el_action_t
930 vi_alias(EditLine *el, wint_t c __attribute__((__unused__)))
933 const char *alias_text;
935 if (el->el_chared.c_aliasfun == NULL)
940 if (el_getc(el, &alias_name[1]) != 1)
943 alias_text = (*el->el_chared.c_aliasfun)(el->el_chared.c_aliasarg,
945 if (alias_text != NULL)
946 el_wpush(el, ct_decode_string(alias_text, &el->el_scratch));
950 /* vi_to_history_line():
951 * Vi go to specified history file line.
954 libedit_private el_action_t
956 vi_to_history_line(EditLine *el, wint_t c __attribute__((__unused__)))
958 int sv_event_no = el->el_history.eventno;
962 if (el->el_history.eventno == 0) {
963 (void) wcsncpy(el->el_history.buf, el->el_line.buffer,
965 el->el_history.last = el->el_history.buf +
966 (el->el_line.lastchar - el->el_line.buffer);
969 /* Lack of a 'count' means oldest, not 1 */
970 if (!el->el_state.doingarg) {
971 el->el_history.eventno = 0x7fffffff;
974 /* This is brain dead, all the rest of this code counts
975 * upwards going into the past. Here we need count in the
976 * other direction (to match the output of fc -l).
977 * I could change the world, but this seems to suffice.
979 el->el_history.eventno = 1;
980 if (hist_get(el) == CC_ERROR)
982 el->el_history.eventno = 1 + el->el_history.ev.num
983 - el->el_state.argument;
984 if (el->el_history.eventno < 0) {
985 el->el_history.eventno = sv_event_no;
990 if (rval == CC_ERROR)
991 el->el_history.eventno = sv_event_no;
996 * Vi edit history line with vi
999 libedit_private el_action_t
1001 vi_histedit(EditLine *el, wint_t c __attribute__((__unused__)))
1007 char tempfile[] = "/tmp/histedit.XXXXXXXXXX";
1010 wchar_t *line = NULL;
1012 if (el->el_state.doingarg) {
1013 if (vi_to_history_line(el, 0) == CC_ERROR)
1017 fd = mkstemp(tempfile);
1020 len = (size_t)(el->el_line.lastchar - el->el_line.buffer);
1021 #define TMP_BUFSIZ (EL_BUFSIZ * MB_LEN_MAX)
1022 cp = el_malloc(TMP_BUFSIZ * sizeof(*cp));
1025 line = el_malloc(len * sizeof(*line) + 1);
1028 wcsncpy(line, el->el_line.buffer, len);
1030 wcstombs(cp, line, TMP_BUFSIZ - 1);
1031 cp[TMP_BUFSIZ - 1] = '\0';
1034 write(fd, "\n", (size_t)1);
1041 execlp("vi", "vi", tempfile, (char *)NULL);
1045 while (waitpid(pid, &status, 0) != pid)
1047 lseek(fd, (off_t)0, SEEK_SET);
1048 st = read(fd, cp, TMP_BUFSIZ - 1);
1051 len = (size_t)(el->el_line.limit - el->el_line.buffer);
1052 len = mbstowcs(el->el_line.buffer, cp, len);
1053 if (len > 0 && el->el_line.buffer[len - 1] == '\n')
1058 el->el_line.cursor = el->el_line.buffer;
1059 el->el_line.lastchar = el->el_line.buffer + len;
1067 /* return CC_REFRESH; */
1068 return ed_newline(el, 0);
1077 /* vi_history_word():
1078 * Vi append word from previous input line
1080 * Who knows where this one came from!
1081 * '_' in vi means 'entire current line', so 'cc' is a synonym for 'c_'
1083 libedit_private el_action_t
1085 vi_history_word(EditLine *el, wint_t c __attribute__((__unused__)))
1087 const wchar_t *wp = HIST_FIRST(el);
1088 const wchar_t *wep, *wsp;
1098 while (iswspace(*wp))
1103 while (*wp && !iswspace(*wp))
1106 } while ((!el->el_state.doingarg || --el->el_state.argument > 0)
1109 if (wsp == NULL || (el->el_state.doingarg && el->el_state.argument != 0))
1113 len = (int)(wep - wsp);
1114 if (el->el_line.cursor < el->el_line.lastchar)
1115 el->el_line.cursor++;
1116 c_insert(el, len + 1);
1117 cp = el->el_line.cursor;
1118 lim = el->el_line.limit;
1121 while (wsp < wep && cp < lim)
1123 el->el_line.cursor = cp;
1125 el->el_map.current = el->el_map.key;
1130 * Vi redo last non-motion command
1133 libedit_private el_action_t
1135 vi_redo(EditLine *el, wint_t c __attribute__((__unused__)))
1137 c_redo_t *r = &el->el_chared.c_redo;
1139 if (!el->el_state.doingarg && r->count) {
1140 el->el_state.doingarg = 1;
1141 el->el_state.argument = r->count;
1144 el->el_chared.c_vcmd.pos = el->el_line.cursor;
1145 el->el_chared.c_vcmd.action = r->action;
1146 if (r->pos != r->buf) {
1147 if (r->pos + 1 > r->lim)
1149 r->pos = r->lim - 1;
1151 el_wpush(el, r->buf);
1154 el->el_state.thiscmd = r->cmd;
1155 el->el_state.thisch = r->ch;
1156 return (*el->el_map.func[r->cmd])(el, r->ch);