#include "compat.h"#include "sys.h"#include <stdlib.h>#include "el.h"Include dependency graph for chared.c:

Go to the source code of this file.
Defines | |
| #define | EL_LEAVE 2 |
Functions | |
| __RCSID ("$NetBSD:chared.c, v 1.14 2001/05/17 01:02:17 christos Exp $") | |
| protected void | cv_undo (EditLine *el, int action, size_t size, char *ptr) |
| protected void | c_insert (EditLine *el, int num) |
| protected void | c_delafter (EditLine *el, int num) |
| protected void | c_delbefore (EditLine *el, int num) |
| protected int | ce__isword (int p) |
| protected int | cv__isword (int p) |
| protected char * | c__prev_word (char *p, char *low, int n, int(*wtest)(int)) |
| protected char * | c__next_word (char *p, char *high, int n, int(*wtest)(int)) |
| protected char * | cv_next_word (EditLine *el, char *p, char *high, int n, int(*wtest)(int)) |
| protected char * | cv_prev_word (EditLine *el, char *p, char *low, int n, int(*wtest)(int)) |
| protected void | cv_delfini (EditLine *el) |
| protected char * | cv__endword (char *p, char *high, int n) |
| protected int | ch_init (EditLine *el) |
| protected void | ch_reset (EditLine *el) |
| protected int | ch_enlargebufs (EditLine *el, size_t addlen) |
| protected void | ch_end (EditLine *el) |
| public int | el_insertstr (EditLine *el, const char *s) |
| public void | el_deletestr (EditLine *el, int n) |
| protected int | c_gets (EditLine *el, char *buf) |
| protected int | c_hpos (EditLine *el) |
|
|
Definition at line 57 of file chared.c. Referenced by ch_enlargebufs(). |
|
||||||||||||
|
|
|
||||||||||||||||||||
|
Definition at line 196 of file chared.c. References p. Referenced by ce_inc_search(), em_capitol_case(), em_delete_next_word(), em_lower_case(), em_next_word(), and em_upper_case().
|
|
||||||||||||||||||||
|
Definition at line 172 of file chared.c. References p. Referenced by ed_delete_prev_word(), ed_prev_word(), and em_copy_prev_word().
00173 {
00174 p--;
00175
00176 while (n--) {
00177 while ((p >= low) && !(*wtest)((unsigned char) *p))
00178 p--;
00179 while ((p >= low) && (*wtest)((unsigned char) *p))
00180 p--;
00181 }
00182
00183 /* cp now points to one character before the word */
00184 p++;
00185 if (p < low)
00186 p = low;
00187 /* cp now points where we want it */
00188 return (p);
00189 }
|
|
||||||||||||
|
Definition at line 101 of file chared.c. References el_map_t::current, el_line_t::cursor, cv_undo(), EditLine, editline::el_line, editline::el_map, el_map_t::emacs, INSERT, and el_line_t::lastchar. Referenced by cv_delfini(), ed_delete_next_char(), ed_digit(), ed_insert(), em_delete_next_word(), em_delete_or_list(), em_kill_region(), and vi_substitute_char().
00102 {
00103
00104 if (el->el_line.cursor + num > el->el_line.lastchar)
00105 num = el->el_line.lastchar - el->el_line.cursor;
00106
00107 if (num > 0) {
00108 char *cp;
00109
00110 if (el->el_map.current != el->el_map.emacs)
00111 cv_undo(el, INSERT, (size_t)num, el->el_line.cursor);
00112
00113 for (cp = el->el_line.cursor; cp <= el->el_line.lastchar; cp++)
00114 *cp = cp[num];
00115
00116 el->el_line.lastchar -= num;
00117 }
00118 }
|
|
||||||||||||
|
Definition at line 125 of file chared.c. References el_line_t::buffer, el_map_t::current, el_line_t::cursor, cv_undo(), EditLine, editline::el_line, editline::el_map, el_map_t::emacs, INSERT, and el_line_t::lastchar. Referenced by cv_delfini(), ed_delete_prev_char(), ed_delete_prev_word(), el_deletestr(), em_kill_region(), vi_delete_prev_char(), and vi_kill_line_prev().
00126 {
00127
00128 if (el->el_line.cursor - num < el->el_line.buffer)
00129 num = el->el_line.cursor - el->el_line.buffer;
00130
00131 if (num > 0) {
00132 char *cp;
00133
00134 if (el->el_map.current != el->el_map.emacs)
00135 cv_undo(el, INSERT, (size_t)num,
00136 el->el_line.cursor - num);
00137
00138 for (cp = el->el_line.cursor - num;
00139 cp <= el->el_line.lastchar;
00140 cp++)
00141 *cp = cp[num];
00142
00143 el->el_line.lastchar -= num;
00144 }
00145 }
|
|
||||||||||||
|
Definition at line 629 of file chared.c. References el_line_t::buffer, CC_REFRESH, el_line_t::cursor, ed_end_of_file(), EditLine, EL_BUFSIZ, el_getc(), editline::el_line, el_line_t::lastchar, len, re_refresh(), and term_beep(). Referenced by cv_search(), and ed_command().
00630 {
00631 char ch;
00632 int len = 0;
00633
00634 for (ch = 0; ch == 0;) {
00635 if (el_getc(el, &ch) != 1)
00636 return (ed_end_of_file(el, 0));
00637 switch (ch) {
00638 case 0010: /* Delete and backspace */
00639 case 0177:
00640 if (len > 1) {
00641 *el->el_line.cursor-- = '\0';
00642 el->el_line.lastchar = el->el_line.cursor;
00643 buf[len--] = '\0';
00644 } else {
00645 el->el_line.buffer[0] = '\0';
00646 el->el_line.lastchar = el->el_line.buffer;
00647 el->el_line.cursor = el->el_line.buffer;
00648 return (CC_REFRESH);
00649 }
00650 re_refresh(el);
00651 ch = 0;
00652 break;
00653
00654 case 0033: /* ESC */
00655 case '\r': /* Newline */
00656 case '\n':
00657 break;
00658
00659 default:
00660 if (len >= EL_BUFSIZ)
00661 term_beep(el);
00662 else {
00663 buf[len++] = ch;
00664 *el->el_line.cursor++ = ch;
00665 el->el_line.lastchar = el->el_line.cursor;
00666 }
00667 re_refresh(el);
00668 ch = 0;
00669 break;
00670 }
00671 }
00672 buf[len] = ch;
00673 return (len);
00674 }
|
|
|
Definition at line 681 of file chared.c. References el_line_t::buffer, el_line_t::cursor, EditLine, and editline::el_line. Referenced by ed_next_line(), and ed_prev_line().
00682 {
00683 char *ptr;
00684
00685 /*
00686 * Find how many characters till the beginning of this line.
00687 */
00688 if (el->el_line.cursor == el->el_line.buffer)
00689 return (0);
00690 else {
00691 for (ptr = el->el_line.cursor - 1;
00692 ptr >= el->el_line.buffer && *ptr != '\n';
00693 ptr--)
00694 continue;
00695 return (el->el_line.cursor - ptr - 1);
00696 }
00697 }
|
|
||||||||||||
|
Definition at line 81 of file chared.c. References el_line_t::cursor, EditLine, editline::el_line, el_line_t::lastchar, and el_line_t::limit. Referenced by cv_paste(), cv_search(), ed_command(), ed_digit(), ed_insert(), el_insertstr(), em_copy_prev_word(), em_yank(), and vi_undo().
00082 {
00083 char *cp;
00084
00085 if (el->el_line.lastchar + num >= el->el_line.limit)
00086 return; /* can't go past end of buffer */
00087
00088 if (el->el_line.cursor < el->el_line.lastchar) {
00089 /* if I must move chars */
00090 for (cp = el->el_line.lastchar; cp >= el->el_line.cursor; cp--)
00091 cp[num] = *cp;
00092 }
00093 el->el_line.lastchar += num;
00094 }
|
|
|
Definition at line 152 of file chared.c. References p. Referenced by ce_inc_search(), ed_delete_prev_word(), ed_prev_word(), em_capitol_case(), em_copy_prev_word(), em_delete_next_word(), em_lower_case(), em_next_word(), em_upper_case(), vi_next_word(), and vi_prev_word().
00153 {
00154 return (isalpha(p) || isdigit(p) || strchr("*?_-.[]~=", p) != NULL);
00155 }
|
|
|
Definition at line 570 of file chared.c. References c_undo_t::buf, c_kill_t::buf, el_line_t::buffer, el_chared_t::c_kill, el_chared_t::c_macro, el_chared_t::c_undo, ch_reset(), EditLine, editline::el_chared, el_free, editline::el_line, el_line_t::limit, c_macro_t::macro, and ptr_t. Referenced by el_end().
00571 {
00572 el_free((ptr_t) el->el_line.buffer);
00573 el->el_line.buffer = NULL;
00574 el->el_line.limit = NULL;
00575 el_free((ptr_t) el->el_chared.c_undo.buf);
00576 el->el_chared.c_undo.buf = NULL;
00577 el_free((ptr_t) el->el_chared.c_kill.buf);
00578 el->el_chared.c_kill.buf = NULL;
00579 el_free((ptr_t) el->el_chared.c_macro.macro);
00580 el->el_chared.c_macro.macro = NULL;
00581 ch_reset(el);
00582 }
|
|
||||||||||||
|
Definition at line 493 of file chared.c. References EditLine, EL_LEAVE, editline::el_line, el_realloc, hist_enlargebuf(), and el_line_t::limit. Referenced by ed_digit(), ed_insert(), el_gets(), el_insertstr(), and em_yank().
00496 {
00497 size_t sz, newsz;
00498 char *newbuffer, *oldbuf, *oldkbuf;
00499
00500 sz = el->el_line.limit - el->el_line.buffer + EL_LEAVE;
00501 newsz = sz * 2;
00502 /*
00503 * If newly required length is longer than current buffer, we need
00504 * to make the buffer big enough to hold both old and new stuff.
00505 */
00506 if (addlen > sz) {
00507 while(newsz - sz < addlen)
00508 newsz *= 2;
00509 }
00510
00511 /*
00512 * Reallocate line buffer.
00513 */
00514 newbuffer = el_realloc(el->el_line.buffer, newsz);
00515 if (!newbuffer)
00516 return 0;
00517
00518 /* zero the newly added memory, leave old data in */
00519 (void) memset(&newbuffer[sz], 0, newsz - sz);
00520
00521 oldbuf = el->el_line.buffer;
00522
00523 el->el_line.buffer = newbuffer;
00524 el->el_line.cursor = newbuffer + (el->el_line.cursor - oldbuf);
00525 el->el_line.lastchar = newbuffer + (el->el_line.lastchar - oldbuf);
00526 el->el_line.limit = &newbuffer[newsz - EL_LEAVE];
00527
00528 /*
00529 * Reallocate kill buffer.
00530 */
00531 newbuffer = el_realloc(el->el_chared.c_kill.buf, newsz);
00532 if (!newbuffer)
00533 return 0;
00534
00535 /* zero the newly added memory, leave old data in */
00536 (void) memset(&newbuffer[sz], 0, newsz - sz);
00537
00538 oldkbuf = el->el_chared.c_kill.buf;
00539
00540 el->el_chared.c_kill.buf = newbuffer;
00541 el->el_chared.c_kill.last = newbuffer +
00542 (el->el_chared.c_kill.last - oldkbuf);
00543 el->el_chared.c_kill.mark = el->el_line.buffer +
00544 (el->el_chared.c_kill.mark - oldbuf);
00545
00546 /*
00547 * Reallocate undo buffer.
00548 */
00549 newbuffer = el_realloc(el->el_chared.c_undo.buf, newsz);
00550 if (!newbuffer)
00551 return 0;
00552
00553 /* zero the newly added memory, leave old data in */
00554 (void) memset(&newbuffer[sz], 0, newsz - sz);
00555
00556 el->el_chared.c_undo.ptr = el->el_line.buffer +
00557 (el->el_chared.c_undo.ptr - oldbuf);
00558 el->el_chared.c_undo.buf = newbuffer;
00559
00560 if (!hist_enlargebuf(el, sz, newsz))
00561 return 0;
00562
00563 return 1;
00564 }
|
|
|
|
||||||||||||||||
|
Definition at line 383 of file chared.c. References p. Referenced by vi_end_word(), and vi_to_end_word().
00384 {
00385 p++;
00386
00387 while (n--) {
00388 while ((p < high) && isspace((unsigned char) *p))
00389 p++;
00390
00391 if (isalnum((unsigned char) *p))
00392 while ((p < high) && isalnum((unsigned char) *p))
00393 p++;
00394 else
00395 while ((p < high) && !(isspace((unsigned char) *p) ||
00396 isalnum((unsigned char) *p)))
00397 p++;
00398 }
00399 p--;
00400 return (p);
00401 }
|
|
|
Definition at line 162 of file chared.c. References p. Referenced by vi_next_space_word(), and vi_prev_space_word().
00163 {
00164 return (!isspace(p));
00165 }
|
|
|
||||||||||||||||||||||||
|
Definition at line 214 of file chared.c. References c_vcmd_t::action, el_chared_t::c_vcmd, DELETE, EditLine, editline::el_chared, INSERT, and p. Referenced by vi_next_space_word(), and vi_next_word().
00215 {
00216 int test;
00217
00218 while (n--) {
00219 test = (*wtest)((unsigned char) *p);
00220 while ((p < high) && (*wtest)((unsigned char) *p) == test)
00221 p++;
00222 /*
00223 * vi historically deletes with cw only the word preserving the
00224 * trailing whitespace! This is not what 'w' does..
00225 */
00226 if (el->el_chared.c_vcmd.action != (DELETE|INSERT))
00227 while ((p < high) && isspace((unsigned char) *p))
00228 p++;
00229 }
00230
00231 /* p now points where we want it */
00232 if (p > high)
00233 return (high);
00234 else
00235 return (p);
00236 }
|
|
||||||||||||||||||||||||
|
Definition at line 243 of file chared.c. References c_vcmd_t::action, el_chared_t::c_vcmd, DELETE, EditLine, editline::el_chared, INSERT, and p. Referenced by vi_prev_space_word(), and vi_prev_word().
00244 {
00245 int test;
00246
00247 while (n--) {
00248 p--;
00249 /*
00250 * vi historically deletes with cb only the word preserving the
00251 * leading whitespace! This is not what 'b' does..
00252 */
00253 if (el->el_chared.c_vcmd.action != (DELETE|INSERT))
00254 while ((p > low) && isspace((unsigned char) *p))
00255 p--;
00256 test = (*wtest)((unsigned char) *p);
00257 while ((p >= low) && (*wtest)((unsigned char) *p) == test)
00258 p--;
00259 p++;
00260 while (isspace((unsigned char) *p))
00261 p++;
00262 }
00263
00264 /* p now points where we want it */
00265 if (p < low)
00266 return (low);
00267 else
00268 return (p);
00269 }
|
|
||||||||||||||||||||
|
Definition at line 63 of file chared.c. References c_undo_t::action, c_undo_t::buf, el_chared_t::c_undo, c_undo_t::dsize, EditLine, editline::el_chared, editline::el_errfile, c_undo_t::isize, c_undo_t::ptr, and size. Referenced by c_delafter(), and c_delbefore().
00064 {
00065 c_undo_t *vu = &el->el_chared.c_undo;
00066 vu->action = action;
00067 vu->ptr = ptr;
00068 vu->isize = size;
00069 (void) memcpy(vu->buf, vu->ptr, size);
00070 #ifdef DEBUG_UNDO
00071 (void) fprintf(el->el_errfile, "Undo buffer \"%s\" size = +%d -%d\n",
00072 vu->ptr, vu->isize, vu->dsize);
00073 #endif
00074 }
|
|
||||||||||||
|
Definition at line 611 of file chared.c. References el_line_t::buffer, c_delbefore(), el_line_t::cursor, EditLine, and editline::el_line. Referenced by rl_complete_internal().
00612 {
00613 if (n <= 0)
00614 return;
00615
00616 if (el->el_line.cursor < &el->el_line.buffer[n])
00617 return;
00618
00619 c_delbefore(el, n); /* delete before dot */
00620 el->el_line.cursor -= n;
00621 if (el->el_line.cursor < el->el_line.buffer)
00622 el->el_line.cursor = el->el_line.buffer;
00623 }
|
|
||||||||||||
|
Definition at line 589 of file chared.c. References c_insert(), ch_enlargebufs(), el_line_t::cursor, EditLine, editline::el_line, el_line_t::lastchar, len, and el_line_t::limit. Referenced by complete(), and rl_complete_internal().
00590 {
00591 size_t len;
00592
00593 if ((len = strlen(s)) == 0)
00594 return (-1);
00595 if (el->el_line.lastchar + len >= el->el_line.limit) {
00596 if (!ch_enlargebufs(el, len))
00597 return (-1);
00598 }
00599
00600 c_insert(el, (int)len);
00601 while (*s)
00602 *el->el_line.cursor++ = *s++;
00603 return (0);
00604 }
|
1.3.5