36 #if !defined(lint) && !defined(SCCSID)
38 static char sccsid[] =
"@(#)common.c 8.1 (Berkeley) 6/4/93";
54 ed_end_of_file(
EditLine *el, Int c __attribute__((__unused__)))
58 *el->el_line.lastchar =
'\0';
70 int count = el->el_state.argument;
75 if (el->el_line.lastchar + el->el_state.argument >=
78 if (!ch_enlargebufs(el, (
size_t) count))
83 if (el->el_state.inputmode == MODE_INSERT
84 || el->el_line.cursor >= el->el_line.lastchar)
87 *el->el_line.cursor++ = c;
90 if (el->el_state.inputmode != MODE_REPLACE_1)
91 c_insert(el, el->el_state.argument);
93 while (count-- && el->el_line.cursor < el->el_line.lastchar)
94 *el->el_line.cursor++ = c;
98 if (el->el_state.inputmode == MODE_REPLACE_1)
99 return vi_command_mode(el, 0);
109 protected el_action_t
111 ed_delete_prev_word(
EditLine *el, Int c __attribute__((__unused__)))
115 if (el->el_line.cursor == el->el_line.buffer)
118 cp = c__prev_word(el->el_line.cursor, el->el_line.buffer,
119 el->el_state.argument, ce__isword);
121 for (p = cp, kp = el->el_chared.c_kill.buf; p < el->el_line.cursor; p++)
123 el->el_chared.c_kill.last = kp;
125 c_delbefore(el, (
int)(el->el_line.cursor - cp));
126 el->el_line.cursor = cp;
127 if (el->el_line.cursor < el->el_line.buffer)
128 el->el_line.cursor = el->el_line.buffer;
137 protected el_action_t
139 ed_delete_next_char(
EditLine *el, Int c __attribute__((__unused__)))
142 #define EL el->el_line
143 (void) fprintf(el->el_errlfile,
144 "\nD(b: %x(%s) c: %x(%s) last: %x(%s) limit: %x(%s)\n",
145 EL.buffer, EL.buffer, EL.cursor, EL.cursor, EL.lastchar,
146 EL.lastchar, EL.limit, EL.limit);
148 if (el->el_line.cursor == el->el_line.lastchar) {
150 if (el->el_map.type == MAP_VI) {
151 if (el->el_line.cursor == el->el_line.buffer) {
157 terminal_writec(el, c);
162 el->el_line.cursor--;
168 if (el->el_line.cursor != el->el_line.buffer)
169 el->el_line.cursor--;
174 c_delafter(el, el->el_state.argument);
175 if (el->el_line.cursor >= el->el_line.lastchar &&
176 el->el_line.cursor > el->el_line.buffer)
178 el->el_line.cursor = el->el_line.lastchar - 1;
187 protected el_action_t
189 ed_kill_line(
EditLine *el, Int c __attribute__((__unused__)))
193 cp = el->el_line.cursor;
194 kp = el->el_chared.c_kill.buf;
195 while (cp < el->el_line.lastchar)
197 el->el_chared.c_kill.last = kp;
199 el->el_line.lastchar = el->el_line.cursor;
208 protected el_action_t
210 ed_move_to_end(
EditLine *el, Int c __attribute__((__unused__)))
213 el->el_line.cursor = el->el_line.lastchar;
214 if (el->el_map.type == MAP_VI) {
215 if (el->el_chared.c_vcmd.action != NOP) {
220 el->el_line.cursor--;
231 protected el_action_t
233 ed_move_to_beg(
EditLine *el, Int c __attribute__((__unused__)))
236 el->el_line.cursor = el->el_line.buffer;
238 if (el->el_map.type == MAP_VI) {
240 while (Isspace(*el->el_line.cursor))
241 el->el_line.cursor++;
242 if (el->el_chared.c_vcmd.action != NOP) {
255 protected el_action_t
256 ed_transpose_chars(
EditLine *el, Int c)
259 if (el->el_line.cursor < el->el_line.lastchar) {
260 if (el->el_line.lastchar <= &el->el_line.buffer[1])
263 el->el_line.cursor++;
265 if (el->el_line.cursor > &el->el_line.buffer[1]) {
267 c = el->el_line.cursor[-2];
268 el->el_line.cursor[-2] = el->el_line.cursor[-1];
269 el->el_line.cursor[-1] = c;
280 protected el_action_t
282 ed_next_char(
EditLine *el, Int c __attribute__((__unused__)))
284 Char *lim = el->el_line.lastchar;
286 if (el->el_line.cursor >= lim ||
287 (el->el_line.cursor == lim - 1 &&
288 el->el_map.type == MAP_VI &&
289 el->el_chared.c_vcmd.action == NOP))
292 el->el_line.cursor += el->el_state.argument;
293 if (el->el_line.cursor > lim)
294 el->el_line.cursor = lim;
296 if (el->el_map.type == MAP_VI)
297 if (el->el_chared.c_vcmd.action != NOP) {
309 protected el_action_t
311 ed_prev_word(
EditLine *el, Int c __attribute__((__unused__)))
314 if (el->el_line.cursor == el->el_line.buffer)
317 el->el_line.cursor = c__prev_word(el->el_line.cursor,
319 el->el_state.argument,
322 if (el->el_map.type == MAP_VI)
323 if (el->el_chared.c_vcmd.action != NOP) {
335 protected el_action_t
337 ed_prev_char(
EditLine *el, Int c __attribute__((__unused__)))
340 if (el->el_line.cursor > el->el_line.buffer) {
341 el->el_line.cursor -= el->el_state.argument;
342 if (el->el_line.cursor < el->el_line.buffer)
343 el->el_line.cursor = el->el_line.buffer;
345 if (el->el_map.type == MAP_VI)
346 if (el->el_chared.c_vcmd.action != NOP) {
360 protected el_action_t
361 ed_quoted_insert(
EditLine *el, Int c)
367 num = FUN(el,getc)(el, &tc);
371 return ed_insert(el, c);
373 return ed_end_of_file(el, 0);
380 protected el_action_t
387 if (el->el_state.doingarg) {
389 if (el->el_state.lastcmd == EM_UNIVERSAL_ARGUMENT)
390 el->el_state.argument = c -
'0';
392 if (el->el_state.argument > 1000000)
394 el->el_state.argument =
395 (el->el_state.argument * 10) + (c -
'0');
400 return ed_insert(el, c);
408 protected el_action_t
409 ed_argument_digit(
EditLine *el, Int c)
415 if (el->el_state.doingarg) {
416 if (el->el_state.argument > 1000000)
418 el->el_state.argument = (el->el_state.argument * 10) +
421 el->el_state.argument = c -
'0';
422 el->el_state.doingarg = 1;
432 protected el_action_t
434 ed_unassigned(
EditLine *el __attribute__((__unused__)),
435 Int c __attribute__((__unused__)))
450 protected el_action_t
452 ed_tty_sigint(
EditLine *el __attribute__((__unused__)),
453 Int c __attribute__((__unused__)))
464 protected el_action_t
466 ed_tty_dsusp(
EditLine *el __attribute__((__unused__)),
467 Int c __attribute__((__unused__)))
478 protected el_action_t
480 ed_tty_flush_output(
EditLine *el __attribute__((__unused__)),
481 Int c __attribute__((__unused__)))
492 protected el_action_t
494 ed_tty_sigquit(
EditLine *el __attribute__((__unused__)),
495 Int c __attribute__((__unused__)))
506 protected el_action_t
508 ed_tty_sigtstp(
EditLine *el __attribute__((__unused__)),
509 Int c __attribute__((__unused__)))
520 protected el_action_t
522 ed_tty_stop_output(
EditLine *el __attribute__((__unused__)),
523 Int c __attribute__((__unused__)))
534 protected el_action_t
536 ed_tty_start_output(
EditLine *el __attribute__((__unused__)),
537 Int c __attribute__((__unused__)))
548 protected el_action_t
550 ed_newline(
EditLine *el, Int c __attribute__((__unused__)))
554 *el->el_line.lastchar++ =
'\n';
555 *el->el_line.lastchar =
'\0';
564 protected el_action_t
566 ed_delete_prev_char(
EditLine *el, Int c __attribute__((__unused__)))
569 if (el->el_line.cursor <= el->el_line.buffer)
572 c_delbefore(el, el->el_state.argument);
573 el->el_line.cursor -= el->el_state.argument;
574 if (el->el_line.cursor < el->el_line.buffer)
575 el->el_line.cursor = el->el_line.buffer;
584 protected el_action_t
586 ed_clear_screen(
EditLine *el, Int c __attribute__((__unused__)))
589 terminal_clear_screen(el);
590 re_clear_display(el);
599 protected el_action_t
601 ed_redisplay(
EditLine *el __attribute__((__unused__)),
602 Int c __attribute__((__unused__)))
613 protected el_action_t
615 ed_start_over(
EditLine *el, Int c __attribute__((__unused__)))
627 protected el_action_t
629 ed_sequence_lead_in(
EditLine *el __attribute__((__unused__)),
630 Int c __attribute__((__unused__)))
641 protected el_action_t
643 ed_prev_history(
EditLine *el, Int c __attribute__((__unused__)))
646 int sv_event = el->el_history.eventno;
648 el->el_chared.c_undo.len = -1;
649 *el->el_line.lastchar =
'\0';
651 if (el->el_history.eventno == 0) {
653 (void) Strncpy(el->el_history.buf, el->el_line.buffer,
655 el->el_history.last = el->el_history.buf +
656 (el->el_line.lastchar - el->el_line.buffer);
658 el->el_history.eventno += el->el_state.argument;
660 if (hist_get(el) == CC_ERROR) {
661 if (el->el_map.type == MAP_VI) {
662 el->el_history.eventno = sv_event;
670 return CC_REFRESH_BEEP;
679 protected el_action_t
681 ed_next_history(
EditLine *el, Int c __attribute__((__unused__)))
683 el_action_t beep = CC_REFRESH, rval;
685 el->el_chared.c_undo.len = -1;
686 *el->el_line.lastchar =
'\0';
688 el->el_history.eventno -= el->el_state.argument;
690 if (el->el_history.eventno < 0) {
691 el->el_history.eventno = 0;
692 beep = CC_REFRESH_BEEP;
695 if (rval == CC_REFRESH)
706 protected el_action_t
708 ed_search_prev_history(
EditLine *el, Int c __attribute__((__unused__)))
714 el->el_chared.c_vcmd.action = NOP;
715 el->el_chared.c_undo.len = -1;
716 *el->el_line.lastchar =
'\0';
717 if (el->el_history.eventno < 0) {
719 (void) fprintf(el->el_errfile,
720 "e_prev_search_hist(): eventno < 0;\n");
722 el->el_history.eventno = 0;
725 if (el->el_history.eventno == 0) {
726 (void) Strncpy(el->el_history.buf, el->el_line.buffer,
728 el->el_history.last = el->el_history.buf +
729 (el->el_line.lastchar - el->el_line.buffer);
731 if (el->el_history.ref == NULL)
740 for (h = 1; h <= el->el_history.eventno; h++)
745 (void) fprintf(el->el_errfile,
"Comparing with \"%s\"\n", hp);
747 if ((Strncmp(hp, el->el_line.buffer, (
size_t)
748 (el->el_line.lastchar - el->el_line.buffer)) ||
749 hp[el->el_line.lastchar - el->el_line.buffer]) &&
760 (void) fprintf(el->el_errfile,
"not found\n");
764 el->el_history.eventno = h;
774 protected el_action_t
776 ed_search_next_history(
EditLine *el, Int c __attribute__((__unused__)))
782 el->el_chared.c_vcmd.action = NOP;
783 el->el_chared.c_undo.len = -1;
784 *el->el_line.lastchar =
'\0';
786 if (el->el_history.eventno == 0)
789 if (el->el_history.ref == NULL)
798 for (h = 1; h < el->el_history.eventno && hp; h++) {
800 (void) fprintf(el->el_errfile,
"Comparing with \"%s\"\n", hp);
802 if ((Strncmp(hp, el->el_line.buffer, (
size_t)
803 (el->el_line.lastchar - el->el_line.buffer)) ||
804 hp[el->el_line.lastchar - el->el_line.buffer]) &&
811 if (!c_hmatch(el, el->el_history.buf)) {
813 (void) fprintf(el->el_errfile,
"not found\n");
818 el->el_history.eventno = found;
828 protected el_action_t
830 ed_prev_line(
EditLine *el, Int c __attribute__((__unused__)))
833 int nchars = c_hpos(el);
838 if (*(ptr = el->el_line.cursor) ==
'\n')
841 for (; ptr >= el->el_line.buffer; ptr--)
842 if (*ptr ==
'\n' && --el->el_state.argument <= 0)
845 if (el->el_state.argument > 0)
851 for (ptr--; ptr >= el->el_line.buffer && *ptr !=
'\n'; ptr--)
858 nchars-- > 0 && ptr < el->el_line.lastchar && *ptr !=
'\n';
862 el->el_line.cursor = ptr;
871 protected el_action_t
873 ed_next_line(
EditLine *el, Int c __attribute__((__unused__)))
876 int nchars = c_hpos(el);
881 for (ptr = el->el_line.cursor; ptr < el->el_line.lastchar; ptr++)
882 if (*ptr ==
'\n' && --el->el_state.argument <= 0)
885 if (el->el_state.argument > 0)
892 nchars-- > 0 && ptr < el->el_line.lastchar && *ptr !=
'\n';
896 el->el_line.cursor = ptr;
905 protected el_action_t
907 ed_command(
EditLine *el, Int c __attribute__((__unused__)))
909 Char tmpbuf[EL_BUFSIZ];
912 tmplen = c_gets(el, tmpbuf, STR(
"\n: "));
913 terminal__putc(el,
'\n');
915 if (tmplen < 0 || (tmpbuf[tmplen] = 0, parse_line(el, tmpbuf)) == -1)
918 el->el_map.current = el->el_map.key;
919 re_clear_display(el);