Remove building with NOCRYPTO option
[minix.git] / lib / libedit / common.c
blob1726b0f812fb399ddd348c6726018189cdea4f99
1 /* $NetBSD: common.c,v 1.29 2012/03/24 20:08:43 christos Exp $ */
3 /*-
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
12 * are met:
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
32 * SUCH DAMAGE.
35 #include "config.h"
36 #if !defined(lint) && !defined(SCCSID)
37 #if 0
38 static char sccsid[] = "@(#)common.c 8.1 (Berkeley) 6/4/93";
39 #else
40 __RCSID("$NetBSD: common.c,v 1.29 2012/03/24 20:08:43 christos Exp $");
41 #endif
42 #endif /* not lint && not SCCSID */
45 * common.c: Common Editor functions
47 #include "el.h"
49 /* ed_end_of_file():
50 * Indicate end of file
51 * [^D]
53 protected el_action_t
54 /*ARGSUSED*/
55 ed_end_of_file(EditLine *el, Int c __attribute__((__unused__)))
58 re_goto_bottom(el);
59 *el->el_line.lastchar = '\0';
60 return CC_EOF;
64 /* ed_insert():
65 * Add character to the line
66 * Insert a character [bound to all insert keys]
68 protected el_action_t
69 ed_insert(EditLine *el, Int c)
71 int count = el->el_state.argument;
73 if (c == '\0')
74 return CC_ERROR;
76 if (el->el_line.lastchar + el->el_state.argument >=
77 el->el_line.limit) {
78 /* end of buffer space, try to allocate more */
79 if (!ch_enlargebufs(el, (size_t) count))
80 return CC_ERROR; /* error allocating more */
83 if (count == 1) {
84 if (el->el_state.inputmode == MODE_INSERT
85 || el->el_line.cursor >= el->el_line.lastchar)
86 c_insert(el, 1);
88 *el->el_line.cursor++ = c;
89 re_fastaddc(el); /* fast refresh for one char. */
90 } else {
91 if (el->el_state.inputmode != MODE_REPLACE_1)
92 c_insert(el, el->el_state.argument);
94 while (count-- && el->el_line.cursor < el->el_line.lastchar)
95 *el->el_line.cursor++ = c;
96 re_refresh(el);
99 if (el->el_state.inputmode == MODE_REPLACE_1)
100 return vi_command_mode(el, 0);
102 return CC_NORM;
106 /* ed_delete_prev_word():
107 * Delete from beginning of current word to cursor
108 * [M-^?] [^W]
110 protected el_action_t
111 /*ARGSUSED*/
112 ed_delete_prev_word(EditLine *el, Int c __attribute__((__unused__)))
114 Char *cp, *p, *kp;
116 if (el->el_line.cursor == el->el_line.buffer)
117 return CC_ERROR;
119 cp = c__prev_word(el->el_line.cursor, el->el_line.buffer,
120 el->el_state.argument, ce__isword);
122 for (p = cp, kp = el->el_chared.c_kill.buf; p < el->el_line.cursor; p++)
123 *kp++ = *p;
124 el->el_chared.c_kill.last = kp;
126 c_delbefore(el, (int)(el->el_line.cursor - cp));/* delete before dot */
127 el->el_line.cursor = cp;
128 if (el->el_line.cursor < el->el_line.buffer)
129 el->el_line.cursor = el->el_line.buffer; /* bounds check */
130 return CC_REFRESH;
134 /* ed_delete_next_char():
135 * Delete character under cursor
136 * [^D] [x]
138 protected el_action_t
139 /*ARGSUSED*/
140 ed_delete_next_char(EditLine *el, Int c __attribute__((__unused__)))
142 #ifdef DEBUG_EDIT
143 #define EL el->el_line
144 (void) fprintf(el->el_errlfile,
145 "\nD(b: %x(%s) c: %x(%s) last: %x(%s) limit: %x(%s)\n",
146 EL.buffer, EL.buffer, EL.cursor, EL.cursor, EL.lastchar,
147 EL.lastchar, EL.limit, EL.limit);
148 #endif
149 if (el->el_line.cursor == el->el_line.lastchar) {
150 /* if I'm at the end */
151 if (el->el_map.type == MAP_VI) {
152 if (el->el_line.cursor == el->el_line.buffer) {
153 /* if I'm also at the beginning */
154 #ifdef KSHVI
155 return CC_ERROR;
156 #else
157 /* then do an EOF */
158 terminal_writec(el, c);
159 return CC_EOF;
160 #endif
161 } else {
162 #ifdef KSHVI
163 el->el_line.cursor--;
164 #else
165 return CC_ERROR;
166 #endif
168 } else
169 return CC_ERROR;
171 c_delafter(el, el->el_state.argument); /* delete after dot */
172 if (el->el_map.type == MAP_VI &&
173 el->el_line.cursor >= el->el_line.lastchar &&
174 el->el_line.cursor > el->el_line.buffer)
175 /* bounds check */
176 el->el_line.cursor = el->el_line.lastchar - 1;
177 return CC_REFRESH;
181 /* ed_kill_line():
182 * Cut to the end of line
183 * [^K] [^K]
185 protected el_action_t
186 /*ARGSUSED*/
187 ed_kill_line(EditLine *el, Int c __attribute__((__unused__)))
189 Char *kp, *cp;
191 cp = el->el_line.cursor;
192 kp = el->el_chared.c_kill.buf;
193 while (cp < el->el_line.lastchar)
194 *kp++ = *cp++; /* copy it */
195 el->el_chared.c_kill.last = kp;
196 /* zap! -- delete to end */
197 el->el_line.lastchar = el->el_line.cursor;
198 return CC_REFRESH;
202 /* ed_move_to_end():
203 * Move cursor to the end of line
204 * [^E] [^E]
206 protected el_action_t
207 /*ARGSUSED*/
208 ed_move_to_end(EditLine *el, Int c __attribute__((__unused__)))
211 el->el_line.cursor = el->el_line.lastchar;
212 if (el->el_map.type == MAP_VI) {
213 if (el->el_chared.c_vcmd.action != NOP) {
214 cv_delfini(el);
215 return CC_REFRESH;
217 #ifdef VI_MOVE
218 el->el_line.cursor--;
219 #endif
221 return CC_CURSOR;
225 /* ed_move_to_beg():
226 * Move cursor to the beginning of line
227 * [^A] [^A]
229 protected el_action_t
230 /*ARGSUSED*/
231 ed_move_to_beg(EditLine *el, Int c __attribute__((__unused__)))
234 el->el_line.cursor = el->el_line.buffer;
236 if (el->el_map.type == MAP_VI) {
237 /* We want FIRST non space character */
238 while (Isspace(*el->el_line.cursor))
239 el->el_line.cursor++;
240 if (el->el_chared.c_vcmd.action != NOP) {
241 cv_delfini(el);
242 return CC_REFRESH;
245 return CC_CURSOR;
249 /* ed_transpose_chars():
250 * Exchange the character to the left of the cursor with the one under it
251 * [^T] [^T]
253 protected el_action_t
254 ed_transpose_chars(EditLine *el, Int c)
257 if (el->el_line.cursor < el->el_line.lastchar) {
258 if (el->el_line.lastchar <= &el->el_line.buffer[1])
259 return CC_ERROR;
260 else
261 el->el_line.cursor++;
263 if (el->el_line.cursor > &el->el_line.buffer[1]) {
264 /* must have at least two chars entered */
265 c = el->el_line.cursor[-2];
266 el->el_line.cursor[-2] = el->el_line.cursor[-1];
267 el->el_line.cursor[-1] = c;
268 return CC_REFRESH;
269 } else
270 return CC_ERROR;
274 /* ed_next_char():
275 * Move to the right one character
276 * [^F] [^F]
278 protected el_action_t
279 /*ARGSUSED*/
280 ed_next_char(EditLine *el, Int c __attribute__((__unused__)))
282 Char *lim = el->el_line.lastchar;
284 if (el->el_line.cursor >= lim ||
285 (el->el_line.cursor == lim - 1 &&
286 el->el_map.type == MAP_VI &&
287 el->el_chared.c_vcmd.action == NOP))
288 return CC_ERROR;
290 el->el_line.cursor += el->el_state.argument;
291 if (el->el_line.cursor > lim)
292 el->el_line.cursor = lim;
294 if (el->el_map.type == MAP_VI)
295 if (el->el_chared.c_vcmd.action != NOP) {
296 cv_delfini(el);
297 return CC_REFRESH;
299 return CC_CURSOR;
303 /* ed_prev_word():
304 * Move to the beginning of the current word
305 * [M-b] [b]
307 protected el_action_t
308 /*ARGSUSED*/
309 ed_prev_word(EditLine *el, Int c __attribute__((__unused__)))
312 if (el->el_line.cursor == el->el_line.buffer)
313 return CC_ERROR;
315 el->el_line.cursor = c__prev_word(el->el_line.cursor,
316 el->el_line.buffer,
317 el->el_state.argument,
318 ce__isword);
320 if (el->el_map.type == MAP_VI)
321 if (el->el_chared.c_vcmd.action != NOP) {
322 cv_delfini(el);
323 return CC_REFRESH;
325 return CC_CURSOR;
329 /* ed_prev_char():
330 * Move to the left one character
331 * [^B] [^B]
333 protected el_action_t
334 /*ARGSUSED*/
335 ed_prev_char(EditLine *el, Int c __attribute__((__unused__)))
338 if (el->el_line.cursor > el->el_line.buffer) {
339 el->el_line.cursor -= el->el_state.argument;
340 if (el->el_line.cursor < el->el_line.buffer)
341 el->el_line.cursor = el->el_line.buffer;
343 if (el->el_map.type == MAP_VI)
344 if (el->el_chared.c_vcmd.action != NOP) {
345 cv_delfini(el);
346 return CC_REFRESH;
348 return CC_CURSOR;
349 } else
350 return CC_ERROR;
354 /* ed_quoted_insert():
355 * Add the next character typed verbatim
356 * [^V] [^V]
358 protected el_action_t
359 ed_quoted_insert(EditLine *el, Int c)
361 int num;
362 Char tc;
364 tty_quotemode(el);
365 num = FUN(el,getc)(el, &tc);
366 c = tc;
367 tty_noquotemode(el);
368 if (num == 1)
369 return ed_insert(el, c);
370 else
371 return ed_end_of_file(el, 0);
375 /* ed_digit():
376 * Adds to argument or enters a digit
378 protected el_action_t
379 ed_digit(EditLine *el, Int c)
382 if (!Isdigit(c))
383 return CC_ERROR;
385 if (el->el_state.doingarg) {
386 /* if doing an arg, add this in... */
387 if (el->el_state.lastcmd == EM_UNIVERSAL_ARGUMENT)
388 el->el_state.argument = c - '0';
389 else {
390 if (el->el_state.argument > 1000000)
391 return CC_ERROR;
392 el->el_state.argument =
393 (el->el_state.argument * 10) + (c - '0');
395 return CC_ARGHACK;
398 return ed_insert(el, c);
402 /* ed_argument_digit():
403 * Digit that starts argument
404 * For ESC-n
406 protected el_action_t
407 ed_argument_digit(EditLine *el, Int c)
410 if (!Isdigit(c))
411 return CC_ERROR;
413 if (el->el_state.doingarg) {
414 if (el->el_state.argument > 1000000)
415 return CC_ERROR;
416 el->el_state.argument = (el->el_state.argument * 10) +
417 (c - '0');
418 } else { /* else starting an argument */
419 el->el_state.argument = c - '0';
420 el->el_state.doingarg = 1;
422 return CC_ARGHACK;
426 /* ed_unassigned():
427 * Indicates unbound character
428 * Bound to keys that are not assigned
430 protected el_action_t
431 /*ARGSUSED*/
432 ed_unassigned(EditLine *el __attribute__((__unused__)),
433 Int c __attribute__((__unused__)))
436 return CC_ERROR;
441 ** TTY key handling.
444 /* ed_tty_sigint():
445 * Tty interrupt character
446 * [^C]
448 protected el_action_t
449 /*ARGSUSED*/
450 ed_tty_sigint(EditLine *el __attribute__((__unused__)),
451 Int c __attribute__((__unused__)))
454 return CC_NORM;
458 /* ed_tty_dsusp():
459 * Tty delayed suspend character
460 * [^Y]
462 protected el_action_t
463 /*ARGSUSED*/
464 ed_tty_dsusp(EditLine *el __attribute__((__unused__)),
465 Int c __attribute__((__unused__)))
468 return CC_NORM;
472 /* ed_tty_flush_output():
473 * Tty flush output characters
474 * [^O]
476 protected el_action_t
477 /*ARGSUSED*/
478 ed_tty_flush_output(EditLine *el __attribute__((__unused__)),
479 Int c __attribute__((__unused__)))
482 return CC_NORM;
486 /* ed_tty_sigquit():
487 * Tty quit character
488 * [^\]
490 protected el_action_t
491 /*ARGSUSED*/
492 ed_tty_sigquit(EditLine *el __attribute__((__unused__)),
493 Int c __attribute__((__unused__)))
496 return CC_NORM;
500 /* ed_tty_sigtstp():
501 * Tty suspend character
502 * [^Z]
504 protected el_action_t
505 /*ARGSUSED*/
506 ed_tty_sigtstp(EditLine *el __attribute__((__unused__)),
507 Int c __attribute__((__unused__)))
510 return CC_NORM;
514 /* ed_tty_stop_output():
515 * Tty disallow output characters
516 * [^S]
518 protected el_action_t
519 /*ARGSUSED*/
520 ed_tty_stop_output(EditLine *el __attribute__((__unused__)),
521 Int c __attribute__((__unused__)))
524 return CC_NORM;
528 /* ed_tty_start_output():
529 * Tty allow output characters
530 * [^Q]
532 protected el_action_t
533 /*ARGSUSED*/
534 ed_tty_start_output(EditLine *el __attribute__((__unused__)),
535 Int c __attribute__((__unused__)))
538 return CC_NORM;
542 /* ed_newline():
543 * Execute command
544 * [^J]
546 protected el_action_t
547 /*ARGSUSED*/
548 ed_newline(EditLine *el, Int c __attribute__((__unused__)))
551 re_goto_bottom(el);
552 *el->el_line.lastchar++ = '\n';
553 *el->el_line.lastchar = '\0';
554 return CC_NEWLINE;
558 /* ed_delete_prev_char():
559 * Delete the character to the left of the cursor
560 * [^?]
562 protected el_action_t
563 /*ARGSUSED*/
564 ed_delete_prev_char(EditLine *el, Int c __attribute__((__unused__)))
567 if (el->el_line.cursor <= el->el_line.buffer)
568 return CC_ERROR;
570 c_delbefore(el, el->el_state.argument);
571 el->el_line.cursor -= el->el_state.argument;
572 if (el->el_line.cursor < el->el_line.buffer)
573 el->el_line.cursor = el->el_line.buffer;
574 return CC_REFRESH;
578 /* ed_clear_screen():
579 * Clear screen leaving current line at the top
580 * [^L]
582 protected el_action_t
583 /*ARGSUSED*/
584 ed_clear_screen(EditLine *el, Int c __attribute__((__unused__)))
587 terminal_clear_screen(el); /* clear the whole real screen */
588 re_clear_display(el); /* reset everything */
589 return CC_REFRESH;
593 /* ed_redisplay():
594 * Redisplay everything
595 * ^R
597 protected el_action_t
598 /*ARGSUSED*/
599 ed_redisplay(EditLine *el __attribute__((__unused__)),
600 Int c __attribute__((__unused__)))
603 return CC_REDISPLAY;
607 /* ed_start_over():
608 * Erase current line and start from scratch
609 * [^G]
611 protected el_action_t
612 /*ARGSUSED*/
613 ed_start_over(EditLine *el, Int c __attribute__((__unused__)))
616 ch_reset(el, 0);
617 return CC_REFRESH;
621 /* ed_sequence_lead_in():
622 * First character in a bound sequence
623 * Placeholder for external keys
625 protected el_action_t
626 /*ARGSUSED*/
627 ed_sequence_lead_in(EditLine *el __attribute__((__unused__)),
628 Int c __attribute__((__unused__)))
631 return CC_NORM;
635 /* ed_prev_history():
636 * Move to the previous history line
637 * [^P] [k]
639 protected el_action_t
640 /*ARGSUSED*/
641 ed_prev_history(EditLine *el, Int c __attribute__((__unused__)))
643 char beep = 0;
644 int sv_event = el->el_history.eventno;
646 el->el_chared.c_undo.len = -1;
647 *el->el_line.lastchar = '\0'; /* just in case */
649 if (el->el_history.eventno == 0) { /* save the current buffer
650 * away */
651 (void) Strncpy(el->el_history.buf, el->el_line.buffer,
652 EL_BUFSIZ);
653 el->el_history.last = el->el_history.buf +
654 (el->el_line.lastchar - el->el_line.buffer);
656 el->el_history.eventno += el->el_state.argument;
658 if (hist_get(el) == CC_ERROR) {
659 if (el->el_map.type == MAP_VI) {
660 el->el_history.eventno = sv_event;
663 beep = 1;
664 /* el->el_history.eventno was fixed by first call */
665 (void) hist_get(el);
667 if (beep)
668 return CC_REFRESH_BEEP;
669 return CC_REFRESH;
673 /* ed_next_history():
674 * Move to the next history line
675 * [^N] [j]
677 protected el_action_t
678 /*ARGSUSED*/
679 ed_next_history(EditLine *el, Int c __attribute__((__unused__)))
681 el_action_t beep = CC_REFRESH, rval;
683 el->el_chared.c_undo.len = -1;
684 *el->el_line.lastchar = '\0'; /* just in case */
686 el->el_history.eventno -= el->el_state.argument;
688 if (el->el_history.eventno < 0) {
689 el->el_history.eventno = 0;
690 beep = CC_REFRESH_BEEP;
692 rval = hist_get(el);
693 if (rval == CC_REFRESH)
694 return beep;
695 return rval;
700 /* ed_search_prev_history():
701 * Search previous in history for a line matching the current
702 * next search history [M-P] [K]
704 protected el_action_t
705 /*ARGSUSED*/
706 ed_search_prev_history(EditLine *el, Int c __attribute__((__unused__)))
708 const Char *hp;
709 int h;
710 bool_t found = 0;
712 el->el_chared.c_vcmd.action = NOP;
713 el->el_chared.c_undo.len = -1;
714 *el->el_line.lastchar = '\0'; /* just in case */
715 if (el->el_history.eventno < 0) {
716 #ifdef DEBUG_EDIT
717 (void) fprintf(el->el_errfile,
718 "e_prev_search_hist(): eventno < 0;\n");
719 #endif
720 el->el_history.eventno = 0;
721 return CC_ERROR;
723 if (el->el_history.eventno == 0) {
724 (void) Strncpy(el->el_history.buf, el->el_line.buffer,
725 EL_BUFSIZ);
726 el->el_history.last = el->el_history.buf +
727 (el->el_line.lastchar - el->el_line.buffer);
729 if (el->el_history.ref == NULL)
730 return CC_ERROR;
732 hp = HIST_FIRST(el);
733 if (hp == NULL)
734 return CC_ERROR;
736 c_setpat(el); /* Set search pattern !! */
738 for (h = 1; h <= el->el_history.eventno; h++)
739 hp = HIST_NEXT(el);
741 while (hp != NULL) {
742 #ifdef SDEBUG
743 (void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp);
744 #endif
745 if ((Strncmp(hp, el->el_line.buffer, (size_t)
746 (el->el_line.lastchar - el->el_line.buffer)) ||
747 hp[el->el_line.lastchar - el->el_line.buffer]) &&
748 c_hmatch(el, hp)) {
749 found++;
750 break;
752 h++;
753 hp = HIST_NEXT(el);
756 if (!found) {
757 #ifdef SDEBUG
758 (void) fprintf(el->el_errfile, "not found\n");
759 #endif
760 return CC_ERROR;
762 el->el_history.eventno = h;
764 return hist_get(el);
768 /* ed_search_next_history():
769 * Search next in history for a line matching the current
770 * [M-N] [J]
772 protected el_action_t
773 /*ARGSUSED*/
774 ed_search_next_history(EditLine *el, Int c __attribute__((__unused__)))
776 const Char *hp;
777 int h;
778 bool_t found = 0;
780 el->el_chared.c_vcmd.action = NOP;
781 el->el_chared.c_undo.len = -1;
782 *el->el_line.lastchar = '\0'; /* just in case */
784 if (el->el_history.eventno == 0)
785 return CC_ERROR;
787 if (el->el_history.ref == NULL)
788 return CC_ERROR;
790 hp = HIST_FIRST(el);
791 if (hp == NULL)
792 return CC_ERROR;
794 c_setpat(el); /* Set search pattern !! */
796 for (h = 1; h < el->el_history.eventno && hp; h++) {
797 #ifdef SDEBUG
798 (void) fprintf(el->el_errfile, "Comparing with \"%s\"\n", hp);
799 #endif
800 if ((Strncmp(hp, el->el_line.buffer, (size_t)
801 (el->el_line.lastchar - el->el_line.buffer)) ||
802 hp[el->el_line.lastchar - el->el_line.buffer]) &&
803 c_hmatch(el, hp))
804 found = h;
805 hp = HIST_NEXT(el);
808 if (!found) { /* is it the current history number? */
809 if (!c_hmatch(el, el->el_history.buf)) {
810 #ifdef SDEBUG
811 (void) fprintf(el->el_errfile, "not found\n");
812 #endif
813 return CC_ERROR;
816 el->el_history.eventno = found;
818 return hist_get(el);
822 /* ed_prev_line():
823 * Move up one line
824 * Could be [k] [^p]
826 protected el_action_t
827 /*ARGSUSED*/
828 ed_prev_line(EditLine *el, Int c __attribute__((__unused__)))
830 Char *ptr;
831 int nchars = c_hpos(el);
834 * Move to the line requested
836 if (*(ptr = el->el_line.cursor) == '\n')
837 ptr--;
839 for (; ptr >= el->el_line.buffer; ptr--)
840 if (*ptr == '\n' && --el->el_state.argument <= 0)
841 break;
843 if (el->el_state.argument > 0)
844 return CC_ERROR;
847 * Move to the beginning of the line
849 for (ptr--; ptr >= el->el_line.buffer && *ptr != '\n'; ptr--)
850 continue;
853 * Move to the character requested
855 for (ptr++;
856 nchars-- > 0 && ptr < el->el_line.lastchar && *ptr != '\n';
857 ptr++)
858 continue;
860 el->el_line.cursor = ptr;
861 return CC_CURSOR;
865 /* ed_next_line():
866 * Move down one line
867 * Could be [j] [^n]
869 protected el_action_t
870 /*ARGSUSED*/
871 ed_next_line(EditLine *el, Int c __attribute__((__unused__)))
873 Char *ptr;
874 int nchars = c_hpos(el);
877 * Move to the line requested
879 for (ptr = el->el_line.cursor; ptr < el->el_line.lastchar; ptr++)
880 if (*ptr == '\n' && --el->el_state.argument <= 0)
881 break;
883 if (el->el_state.argument > 0)
884 return CC_ERROR;
887 * Move to the character requested
889 for (ptr++;
890 nchars-- > 0 && ptr < el->el_line.lastchar && *ptr != '\n';
891 ptr++)
892 continue;
894 el->el_line.cursor = ptr;
895 return CC_CURSOR;
899 /* ed_command():
900 * Editline extended command
901 * [M-X] [:]
903 protected el_action_t
904 /*ARGSUSED*/
905 ed_command(EditLine *el, Int c __attribute__((__unused__)))
907 Char tmpbuf[EL_BUFSIZ];
908 int tmplen;
910 tmplen = c_gets(el, tmpbuf, STR("\n: "));
911 terminal__putc(el, '\n');
913 if (tmplen < 0 || (tmpbuf[tmplen] = 0, parse_line(el, tmpbuf)) == -1)
914 terminal_beep(el);
916 el->el_map.current = el->el_map.key;
917 re_clear_display(el);
918 return CC_REFRESH;