i8254: Adjust cpu_initclocks() a little bit.
[dragonfly.git] / lib / libedit / common.c
blob50b8d34f95f6b163b9e91e92a78b708b0830c29c
1 /*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Christos Zoulas of Cornell University.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
32 * @(#)common.c 8.1 (Berkeley) 6/4/93
33 * $NetBSD: common.c,v 1.19 2006/03/06 21:11:56 christos Exp $
34 * $DragonFly: src/lib/libedit/common.c,v 1.6 2007/05/05 00:27:39 pavalos Exp $
37 #include "config.h"
40 * common.c: Common Editor functions
42 #include "el.h"
44 /* ed_end_of_file():
45 * Indicate end of file
46 * [^D]
48 protected el_action_t
49 /*ARGSUSED*/
50 ed_end_of_file(EditLine *el, int c __attribute__((__unused__)))
53 re_goto_bottom(el);
54 *el->el_line.lastchar = '\0';
55 return (CC_EOF);
59 /* ed_insert():
60 * Add character to the line
61 * Insert a character [bound to all insert keys]
63 protected el_action_t
64 ed_insert(EditLine *el, int c)
66 int count = el->el_state.argument;
68 if (c == '\0')
69 return (CC_ERROR);
71 if (el->el_line.lastchar + el->el_state.argument >=
72 el->el_line.limit) {
73 /* end of buffer space, try to allocate more */
74 if (!ch_enlargebufs(el, (size_t) count))
75 return CC_ERROR; /* error allocating more */
78 if (count == 1) {
79 if (el->el_state.inputmode == MODE_INSERT
80 || el->el_line.cursor >= el->el_line.lastchar)
81 c_insert(el, 1);
83 *el->el_line.cursor++ = c;
84 re_fastaddc(el); /* fast refresh for one char. */
85 } else {
86 if (el->el_state.inputmode != MODE_REPLACE_1)
87 c_insert(el, el->el_state.argument);
89 while (count-- && el->el_line.cursor < el->el_line.lastchar)
90 *el->el_line.cursor++ = c;
91 re_refresh(el);
94 if (el->el_state.inputmode == MODE_REPLACE_1)
95 return vi_command_mode(el, 0);
97 return (CC_NORM);
101 /* ed_delete_prev_word():
102 * Delete from beginning of current word to cursor
103 * [M-^?] [^W]
105 protected el_action_t
106 /*ARGSUSED*/
107 ed_delete_prev_word(EditLine *el, int c __attribute__((__unused__)))
109 char *cp, *p, *kp;
111 if (el->el_line.cursor == el->el_line.buffer)
112 return (CC_ERROR);
114 cp = c__prev_word(el->el_line.cursor, el->el_line.buffer,
115 el->el_state.argument, ce__isword);
117 for (p = cp, kp = el->el_chared.c_kill.buf; p < el->el_line.cursor; p++)
118 *kp++ = *p;
119 el->el_chared.c_kill.last = kp;
121 c_delbefore(el, el->el_line.cursor - cp); /* delete before dot */
122 el->el_line.cursor = cp;
123 if (el->el_line.cursor < el->el_line.buffer)
124 el->el_line.cursor = el->el_line.buffer; /* bounds check */
125 return (CC_REFRESH);
129 /* ed_delete_next_char():
130 * Delete character under cursor
131 * [^D] [x]
133 protected el_action_t
134 /*ARGSUSED*/
135 ed_delete_next_char(EditLine *el, int c)
137 #ifdef notdef /* XXX */
138 #define EL el->el_line
139 (void) fprintf(el->el_errlfile,
140 "\nD(b: %x(%s) c: %x(%s) last: %x(%s) limit: %x(%s)\n",
141 EL.buffer, EL.buffer, EL.cursor, EL.cursor, EL.lastchar,
142 EL.lastchar, EL.limit, EL.limit);
143 #endif
144 if (el->el_line.cursor == el->el_line.lastchar) {
145 /* if I'm at the end */
146 if (el->el_map.type == MAP_VI) {
147 if (el->el_line.cursor == el->el_line.buffer) {
148 /* if I'm also at the beginning */
149 #ifdef KSHVI
150 return (CC_ERROR);
151 #else
152 /* then do an EOF */
153 term_writechar(el, c);
154 return (CC_EOF);
155 #endif
156 } else {
157 #ifdef KSHVI
158 el->el_line.cursor--;
159 #else
160 return (CC_ERROR);
161 #endif
163 } else {
164 if (el->el_line.cursor != el->el_line.buffer)
165 el->el_line.cursor--;
166 else
167 return (CC_ERROR);
170 c_delafter(el, el->el_state.argument); /* delete after dot */
171 if (el->el_line.cursor >= el->el_line.lastchar &&
172 el->el_line.cursor > el->el_line.buffer)
173 /* bounds check */
174 el->el_line.cursor = el->el_line.lastchar - 1;
175 return (CC_REFRESH);
179 /* ed_kill_line():
180 * Cut to the end of line
181 * [^K] [^K]
183 protected el_action_t
184 /*ARGSUSED*/
185 ed_kill_line(EditLine *el, int c __attribute__((__unused__)))
187 char *kp, *cp;
189 cp = el->el_line.cursor;
190 kp = el->el_chared.c_kill.buf;
191 while (cp < el->el_line.lastchar)
192 *kp++ = *cp++; /* copy it */
193 el->el_chared.c_kill.last = kp;
194 /* zap! -- delete to end */
195 el->el_line.lastchar = el->el_line.cursor;
196 return (CC_REFRESH);
200 /* ed_move_to_end():
201 * Move cursor to the end of line
202 * [^E] [^E]
204 protected el_action_t
205 /*ARGSUSED*/
206 ed_move_to_end(EditLine *el, int c __attribute__((__unused__)))
209 el->el_line.cursor = el->el_line.lastchar;
210 if (el->el_map.type == MAP_VI) {
211 #ifdef VI_MOVE
212 el->el_line.cursor--;
213 #endif
214 if (el->el_chared.c_vcmd.action != NOP) {
215 cv_delfini(el);
216 return (CC_REFRESH);
219 return (CC_CURSOR);
223 /* ed_move_to_beg():
224 * Move cursor to the beginning of line
225 * [^A] [^A]
227 protected el_action_t
228 /*ARGSUSED*/
229 ed_move_to_beg(EditLine *el, int c __attribute__((__unused__)))
232 el->el_line.cursor = el->el_line.buffer;
234 if (el->el_map.type == MAP_VI) {
235 /* We want FIRST non space character */
236 while (isspace((unsigned char) *el->el_line.cursor))
237 el->el_line.cursor++;
238 if (el->el_chared.c_vcmd.action != NOP) {
239 cv_delfini(el);
240 return (CC_REFRESH);
243 return (CC_CURSOR);
247 /* ed_transpose_chars():
248 * Exchange the character to the left of the cursor with the one under it
249 * [^T] [^T]
251 protected el_action_t
252 ed_transpose_chars(EditLine *el, int c)
255 if (el->el_line.cursor < el->el_line.lastchar) {
256 if (el->el_line.lastchar <= &el->el_line.buffer[1])
257 return (CC_ERROR);
258 else
259 el->el_line.cursor++;
261 if (el->el_line.cursor > &el->el_line.buffer[1]) {
262 /* must have at least two chars entered */
263 c = el->el_line.cursor[-2];
264 el->el_line.cursor[-2] = el->el_line.cursor[-1];
265 el->el_line.cursor[-1] = c;
266 return (CC_REFRESH);
267 } else
268 return (CC_ERROR);
272 /* ed_next_char():
273 * Move to the right one character
274 * [^F] [^F]
276 protected el_action_t
277 /*ARGSUSED*/
278 ed_next_char(EditLine *el, int c __attribute__((__unused__)))
280 char *lim = el->el_line.lastchar;
282 if (el->el_line.cursor >= lim ||
283 (el->el_line.cursor == lim - 1 &&
284 el->el_map.type == MAP_VI &&
285 el->el_chared.c_vcmd.action == NOP))
286 return (CC_ERROR);
288 el->el_line.cursor += el->el_state.argument;
289 if (el->el_line.cursor > lim)
290 el->el_line.cursor = lim;
292 if (el->el_map.type == MAP_VI)
293 if (el->el_chared.c_vcmd.action != NOP) {
294 cv_delfini(el);
295 return (CC_REFRESH);
297 return (CC_CURSOR);
301 /* ed_prev_word():
302 * Move to the beginning of the current word
303 * [M-b] [b]
305 protected el_action_t
306 /*ARGSUSED*/
307 ed_prev_word(EditLine *el, int c __attribute__((__unused__)))
310 if (el->el_line.cursor == el->el_line.buffer)
311 return (CC_ERROR);
313 el->el_line.cursor = c__prev_word(el->el_line.cursor,
314 el->el_line.buffer,
315 el->el_state.argument,
316 ce__isword);
318 if (el->el_map.type == MAP_VI)
319 if (el->el_chared.c_vcmd.action != NOP) {
320 cv_delfini(el);
321 return (CC_REFRESH);
323 return (CC_CURSOR);
327 /* ed_prev_char():
328 * Move to the left one character
329 * [^B] [^B]
331 protected el_action_t
332 /*ARGSUSED*/
333 ed_prev_char(EditLine *el, int c __attribute__((__unused__)))
336 if (el->el_line.cursor > el->el_line.buffer) {
337 el->el_line.cursor -= el->el_state.argument;
338 if (el->el_line.cursor < el->el_line.buffer)
339 el->el_line.cursor = el->el_line.buffer;
341 if (el->el_map.type == MAP_VI)
342 if (el->el_chared.c_vcmd.action != NOP) {
343 cv_delfini(el);
344 return (CC_REFRESH);
346 return (CC_CURSOR);
347 } else
348 return (CC_ERROR);
352 /* ed_quoted_insert():
353 * Add the next character typed verbatim
354 * [^V] [^V]
356 protected el_action_t
357 ed_quoted_insert(EditLine *el, int c)
359 int num;
360 char tc;
362 tty_quotemode(el);
363 num = el_getc(el, &tc);
364 c = (unsigned char) tc;
365 tty_noquotemode(el);
366 if (num == 1)
367 return (ed_insert(el, c));
368 else
369 return (ed_end_of_file(el, 0));
373 /* ed_digit():
374 * Adds to argument or enters a digit
376 protected el_action_t
377 ed_digit(EditLine *el, int c)
380 if (!isdigit(c))
381 return (CC_ERROR);
383 if (el->el_state.doingarg) {
384 /* if doing an arg, add this in... */
385 if (el->el_state.lastcmd == EM_UNIVERSAL_ARGUMENT)
386 el->el_state.argument = c - '0';
387 else {
388 if (el->el_state.argument > 1000000)
389 return (CC_ERROR);
390 el->el_state.argument =
391 (el->el_state.argument * 10) + (c - '0');
393 return (CC_ARGHACK);
396 return ed_insert(el, c);
400 /* ed_argument_digit():
401 * Digit that starts argument
402 * For ESC-n
404 protected el_action_t
405 ed_argument_digit(EditLine *el, int c)
408 if (!isdigit(c))
409 return (CC_ERROR);
411 if (el->el_state.doingarg) {
412 if (el->el_state.argument > 1000000)
413 return (CC_ERROR);
414 el->el_state.argument = (el->el_state.argument * 10) +
415 (c - '0');
416 } else { /* else starting an argument */
417 el->el_state.argument = c - '0';
418 el->el_state.doingarg = 1;
420 return (CC_ARGHACK);
424 /* ed_unassigned():
425 * Indicates unbound character
426 * Bound to keys that are not assigned
428 protected el_action_t
429 /*ARGSUSED*/
430 ed_unassigned(EditLine *el, int c __attribute__((__unused__)))
433 return (CC_ERROR);
438 ** TTY key handling.
441 /* ed_tty_sigint():
442 * Tty interrupt character
443 * [^C]
445 protected el_action_t
446 /*ARGSUSED*/
447 ed_tty_sigint(EditLine *el __attribute__((__unused__)),
448 int c __attribute__((__unused__)))
451 return (CC_NORM);
455 /* ed_tty_dsusp():
456 * Tty delayed suspend character
457 * [^Y]
459 protected el_action_t
460 /*ARGSUSED*/
461 ed_tty_dsusp(EditLine *el __attribute__((__unused__)),
462 int c __attribute__((__unused__)))
465 return (CC_NORM);
469 /* ed_tty_flush_output():
470 * Tty flush output characters
471 * [^O]
473 protected el_action_t
474 /*ARGSUSED*/
475 ed_tty_flush_output(EditLine *el __attribute__((__unused__)),
476 int c __attribute__((__unused__)))
479 return (CC_NORM);
483 /* ed_tty_sigquit():
484 * Tty quit character
485 * [^\]
487 protected el_action_t
488 /*ARGSUSED*/
489 ed_tty_sigquit(EditLine *el __attribute__((__unused__)),
490 int c __attribute__((__unused__)))
493 return (CC_NORM);
497 /* ed_tty_sigtstp():
498 * Tty suspend character
499 * [^Z]
501 protected el_action_t
502 /*ARGSUSED*/
503 ed_tty_sigtstp(EditLine *el __attribute__((__unused__)),
504 int c __attribute__((__unused__)))
507 return (CC_NORM);
511 /* ed_tty_stop_output():
512 * Tty disallow output characters
513 * [^S]
515 protected el_action_t
516 /*ARGSUSED*/
517 ed_tty_stop_output(EditLine *el __attribute__((__unused__)),
518 int c __attribute__((__unused__)))
521 return (CC_NORM);
525 /* ed_tty_start_output():
526 * Tty allow output characters
527 * [^Q]
529 protected el_action_t
530 /*ARGSUSED*/
531 ed_tty_start_output(EditLine *el __attribute__((__unused__)),
532 int c __attribute__((__unused__)))
535 return (CC_NORM);
539 /* ed_newline():
540 * Execute command
541 * [^J]
543 protected el_action_t
544 /*ARGSUSED*/
545 ed_newline(EditLine *el, int c __attribute__((__unused__)))
548 re_goto_bottom(el);
549 *el->el_line.lastchar++ = '\n';
550 *el->el_line.lastchar = '\0';
551 return (CC_NEWLINE);
555 /* ed_delete_prev_char():
556 * Delete the character to the left of the cursor
557 * [^?]
559 protected el_action_t
560 /*ARGSUSED*/
561 ed_delete_prev_char(EditLine *el, int c __attribute__((__unused__)))
564 if (el->el_line.cursor <= el->el_line.buffer)
565 return (CC_ERROR);
567 c_delbefore(el, el->el_state.argument);
568 el->el_line.cursor -= el->el_state.argument;
569 if (el->el_line.cursor < el->el_line.buffer)
570 el->el_line.cursor = el->el_line.buffer;
571 return (CC_REFRESH);
575 /* ed_clear_screen():
576 * Clear screen leaving current line at the top
577 * [^L]
579 protected el_action_t
580 /*ARGSUSED*/
581 ed_clear_screen(EditLine *el, int c __attribute__((__unused__)))
584 term_clear_screen(el); /* clear the whole real screen */
585 re_clear_display(el); /* reset everything */
586 return (CC_REFRESH);
590 /* ed_redisplay():
591 * Redisplay everything
592 * ^R
594 protected el_action_t
595 /*ARGSUSED*/
596 ed_redisplay(EditLine *el __attribute__((__unused__)),
597 int c __attribute__((__unused__)))
600 return (CC_REDISPLAY);
604 /* ed_start_over():
605 * Erase current line and start from scratch
606 * [^G]
608 protected el_action_t
609 /*ARGSUSED*/
610 ed_start_over(EditLine *el, int c __attribute__((__unused__)))
613 ch_reset(el, 0);
614 return (CC_REFRESH);
618 /* ed_sequence_lead_in():
619 * First character in a bound sequence
620 * Placeholder for external keys
622 protected el_action_t
623 /*ARGSUSED*/
624 ed_sequence_lead_in(EditLine *el __attribute__((__unused__)),
625 int c __attribute__((__unused__)))
628 return (CC_NORM);
632 /* ed_prev_history():
633 * Move to the previous history line
634 * [^P] [k]
636 protected el_action_t
637 /*ARGSUSED*/
638 ed_prev_history(EditLine *el, int c __attribute__((__unused__)))
640 char beep = 0;
641 int sv_event = el->el_history.eventno;
643 el->el_chared.c_undo.len = -1;
644 *el->el_line.lastchar = '\0'; /* just in case */
646 if (el->el_history.eventno == 0) { /* save the current buffer
647 * away */
648 (void) strncpy(el->el_history.buf, el->el_line.buffer,
649 EL_BUFSIZ);
650 el->el_history.last = el->el_history.buf +
651 (el->el_line.lastchar - el->el_line.buffer);
653 el->el_history.eventno += el->el_state.argument;
655 if (hist_get(el) == CC_ERROR) {
656 if (el->el_map.type == MAP_VI) {
657 el->el_history.eventno = sv_event;
658 return CC_ERROR;
660 beep = 1;
661 /* el->el_history.eventno was fixed by first call */
662 (void) hist_get(el);
664 if (beep)
665 return CC_REFRESH_BEEP;
666 return CC_REFRESH;
670 /* ed_next_history():
671 * Move to the next history line
672 * [^N] [j]
674 protected el_action_t
675 /*ARGSUSED*/
676 ed_next_history(EditLine *el, int c __attribute__((__unused__)))
678 el_action_t beep = CC_REFRESH, rval;
680 el->el_chared.c_undo.len = -1;
681 *el->el_line.lastchar = '\0'; /* just in case */
683 el->el_history.eventno -= el->el_state.argument;
685 if (el->el_history.eventno < 0) {
686 el->el_history.eventno = 0;
687 beep = CC_REFRESH_BEEP;
689 rval = hist_get(el);
690 if (rval == CC_REFRESH)
691 return beep;
692 return rval;
697 /* ed_search_prev_history():
698 * Search previous in history for a line matching the current
699 * next search history [M-P] [K]
701 protected el_action_t
702 /*ARGSUSED*/
703 ed_search_prev_history(EditLine *el, int c __attribute__((__unused__)))
705 const char *hp;
706 int h;
707 bool_t found = 0;
709 el->el_chared.c_vcmd.action = NOP;
710 el->el_chared.c_undo.len = -1;
711 *el->el_line.lastchar = '\0'; /* just in case */
712 if (el->el_history.eventno < 0) {
713 #ifdef DEBUG_EDIT
714 (void) fprintf(el->el_errfile,
715 "e_prev_search_hist(): eventno < 0;\n");
716 #endif
717 el->el_history.eventno = 0;
718 return (CC_ERROR);
720 if (el->el_history.eventno == 0) {
721 (void) strncpy(el->el_history.buf, el->el_line.buffer,
722 EL_BUFSIZ);
723 el->el_history.last = el->el_history.buf +
724 (el->el_line.lastchar - el->el_line.buffer);
726 if (el->el_history.ref == NULL)
727 return (CC_ERROR);
729 hp = HIST_FIRST(el);
730 if (hp == NULL)
731 return (CC_ERROR);
733 c_setpat(el); /* Set search pattern !! */
735 for (h = 1; h <= el->el_history.eventno; h++)
736 hp = HIST_NEXT(el);
738 while (hp != NULL) {
739 #ifdef SDEBUG
740 (void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp);
741 #endif
742 if ((strncmp(hp, el->el_line.buffer, (size_t)
743 (el->el_line.lastchar - el->el_line.buffer)) ||
744 hp[el->el_line.lastchar - el->el_line.buffer]) &&
745 c_hmatch(el, hp)) {
746 found++;
747 break;
749 h++;
750 hp = HIST_NEXT(el);
753 if (!found) {
754 #ifdef SDEBUG
755 (void) fprintf(el->el_errfile, "not found\n");
756 #endif
757 return (CC_ERROR);
759 el->el_history.eventno = h;
761 return (hist_get(el));
765 /* ed_search_next_history():
766 * Search next in history for a line matching the current
767 * [M-N] [J]
769 protected el_action_t
770 /*ARGSUSED*/
771 ed_search_next_history(EditLine *el, int c __attribute__((__unused__)))
773 const char *hp;
774 int h;
775 bool_t found = 0;
777 el->el_chared.c_vcmd.action = NOP;
778 el->el_chared.c_undo.len = -1;
779 *el->el_line.lastchar = '\0'; /* just in case */
781 if (el->el_history.eventno == 0)
782 return (CC_ERROR);
784 if (el->el_history.ref == NULL)
785 return (CC_ERROR);
787 hp = HIST_FIRST(el);
788 if (hp == NULL)
789 return (CC_ERROR);
791 c_setpat(el); /* Set search pattern !! */
793 for (h = 1; h < el->el_history.eventno && hp; h++) {
794 #ifdef SDEBUG
795 (void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp);
796 #endif
797 if ((strncmp(hp, el->el_line.buffer, (size_t)
798 (el->el_line.lastchar - el->el_line.buffer)) ||
799 hp[el->el_line.lastchar - el->el_line.buffer]) &&
800 c_hmatch(el, hp))
801 found = h;
802 hp = HIST_NEXT(el);
805 if (!found) { /* is it the current history number? */
806 if (!c_hmatch(el, el->el_history.buf)) {
807 #ifdef SDEBUG
808 (void) fprintf(el->el_errfile, "not found\n");
809 #endif
810 return (CC_ERROR);
813 el->el_history.eventno = found;
815 return (hist_get(el));
819 /* ed_prev_line():
820 * Move up one line
821 * Could be [k] [^p]
823 protected el_action_t
824 /*ARGSUSED*/
825 ed_prev_line(EditLine *el, int c __attribute__((__unused__)))
827 char *ptr;
828 int nchars = c_hpos(el);
831 * Move to the line requested
833 if (*(ptr = el->el_line.cursor) == '\n')
834 ptr--;
836 for (; ptr >= el->el_line.buffer; ptr--)
837 if (*ptr == '\n' && --el->el_state.argument <= 0)
838 break;
840 if (el->el_state.argument > 0)
841 return (CC_ERROR);
844 * Move to the beginning of the line
846 for (ptr--; ptr >= el->el_line.buffer && *ptr != '\n'; ptr--)
847 continue;
850 * Move to the character requested
852 for (ptr++;
853 nchars-- > 0 && ptr < el->el_line.lastchar && *ptr != '\n';
854 ptr++)
855 continue;
857 el->el_line.cursor = ptr;
858 return (CC_CURSOR);
862 /* ed_next_line():
863 * Move down one line
864 * Could be [j] [^n]
866 protected el_action_t
867 /*ARGSUSED*/
868 ed_next_line(EditLine *el, int c __attribute__((__unused__)))
870 char *ptr;
871 int nchars = c_hpos(el);
874 * Move to the line requested
876 for (ptr = el->el_line.cursor; ptr < el->el_line.lastchar; ptr++)
877 if (*ptr == '\n' && --el->el_state.argument <= 0)
878 break;
880 if (el->el_state.argument > 0)
881 return (CC_ERROR);
884 * Move to the character requested
886 for (ptr++;
887 nchars-- > 0 && ptr < el->el_line.lastchar && *ptr != '\n';
888 ptr++)
889 continue;
891 el->el_line.cursor = ptr;
892 return (CC_CURSOR);
896 /* ed_command():
897 * Editline extended command
898 * [M-X] [:]
900 protected el_action_t
901 /*ARGSUSED*/
902 ed_command(EditLine *el, int c __attribute__((__unused__)))
904 char tmpbuf[EL_BUFSIZ];
905 int tmplen;
907 tmplen = c_gets(el, tmpbuf, "\n: ");
908 term__putc('\n');
910 if (tmplen < 0 || (tmpbuf[tmplen] = 0, parse_line(el, tmpbuf)) == -1)
911 term_beep(el);
913 el->el_map.current = el->el_map.key;
914 re_clear_display(el);
915 return CC_REFRESH;