• Home
  • Raw
  • Download

Lines Matching +full:is +full:- +full:extglob

6 /*-
14 * is granted to deal in this work without restriction, including un-
18 * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
37 * good string is KSH_ESC_STRING "c" except on hardware terminals like the
54 static const char ctrl_x_e[] = "fc -e \"${VISUAL:-${EDITOR:-vi}}\" --";
74 #define toedchar(x) (((_POSIX_VDISABLE != -1) && ((x) == _POSIX_VDISABLE)) ? \
84 #define XCF_IS_COMMAND BIT(3) /* return flag: is command */
152 i = -1; in x_read()
186 return ((n == 1) ? (int)(unsigned char)c : -1); in x_getc()
200 /*-
203 * 1 if a carriage return is indicated (comment added)
205 * -1 if there is an error (not enough room for comment chars)
215 /* somewhat arbitrary - it's what AT&T ksh does */ in x_do_comment()
232 /* See if there's room for the #s - 1 per \n */ in x_do_comment()
237 return (-1); in x_do_comment()
239 for (i = len, j = len + n; --i >= 0; ) { in x_do_comment()
241 buf[--j] = '#'; in x_do_comment()
242 buf[--j] = buf[i]; in x_do_comment()
270 /* Special case for 1 match (prefix is whole word) */ in x_print_expansions()
273 /* Any (non-trailing) slashes in non-common word suffixes? */ in x_print_expansions()
281 !mksh_cdirsep(words[0][prefix_len - 1])) in x_print_expansions()
282 prefix_len--; in x_print_expansions()
307 * Convert backslash-escaped string to QCHAR-escaped
322 if (escaping || (ch == QCHAR && (cp - dp) > 1)) { in x_glob_hlp_add_qchar()
347 * after unescaping; if the flag is set, the original string
348 * is freed if changed and assumed backslash-escaped, if not
349 * it is assumed QCHAR-escaped
367 *--cp = '/'; in x_glob_hlp_tilde_and_rem_qchar()
377 /* ... convert it from backslash-escaped via QCHAR-escaped... */ in x_glob_hlp_tilde_and_rem_qchar()
395 * - does expansion, checks for no match, etc.
396 * - sets *wordsp to array of matching strings
397 * - returns number of matching strings
415 s->start = s->str = toglob; in x_file_glob()
450 * "ab*" exists is not an error). in x_file_glob()
451 * Also, check for empty result - happens if we tried in x_file_glob()
453 * string (e.g., "$FOO" when there is no FOO, etc). in x_file_glob()
485 if ((t = ascstrcmp(a->word + a->base, b->word + b->base))) in path_order_cmp()
487 if (a->path_order > b->path_order) in path_order_cmp()
489 if (a->path_order < b->path_order) in path_order_cmp()
490 return (-1); in path_order_cmp()
510 for (l = e->loc; l; l = l->next) in x_command_glob()
511 glob_table(pat, &w, &l->funs); in x_command_glob()
536 if (!last_info || info[i].base != last_info->base || in x_command_glob()
537 strncmp(words[i], last_info->word, info[i].base) != 0) { in x_command_glob()
554 for (i = j = 0; i < nwords - 1; i++) { in x_command_glob()
591 for (; (start > 0 && IS_WORDC(buf[start - 1])) || in x_locate_word()
592 (start > 1 && buf[start - 2] == '\\'); start--) in x_locate_word()
602 int p = start - 1; in x_locate_word()
604 /* Figure out if this is a command */ in x_locate_word()
606 p--; in x_locate_word()
610 * If command has a /, path, etc. is not searched; in x_locate_word()
611 * only current directory is searched which is just in x_locate_word()
623 return (end - start); in x_locate_word()
638 * Don't do command globing on zero length strings - it takes too in x_cf_glob()
657 * '?', or '[') or an extglob, then it is globbed based in x_cf_glob()
673 * just expand based on the extglob in x_cf_glob()
734 --prefix_len; in x_longest_prefix()
742 afree(words[--nwords], ATEMP); in x_free_words()
746 /*-
747 * Return the offset of the basename of string s (which ends at se - need not
748 * be null terminated). Trailing slashes are ignored. If s is just a slash,
749 * then the offset is 0 (actually, length - 1).
770 p = se - 1; in x_basename()
772 --p; in x_basename()
775 --p; in x_basename()
779 return (p - s); in x_basename()
794 if (gmatchx(te->name, pat, false)) { in glob_table()
797 strdupx(cp, te->name, ATEMP); in glob_table()
818 pathlen = p - sp; in glob_path()
844 /* Check that each match is executable... */ in glob_path()
856 wp->len = j; in glob_path()
867 * keybinding-specific function
875 while (wlen - add > 0) in x_escape()
878 rval = -1; in x_escape()
887 wlen -= add; in x_escape()
928 /*-
930 * 0 = enumerate M-= complete as much as possible and then list
931 * 1 = complete M-Esc
932 * 2 = list M-?
937 CT_COMPLIST /* complete and then list (if non-exact) */
954 static int x_adj_done; /* is incremented by x_adjust() */
963 static int x_nextcmd; /* for newline-and-next */
983 static int wbuf_len; /* length of window buffers (x_cols - 3) */
989 static int prompt_trunc; /* how much of prompt to truncate or -1 */
1025 static int unget_char = -1;
1162 /* more non-standard ones */
1231 if (c == -1) in x_e_getmbc()
1232 return (-1); in x_e_getmbc()
1237 if (c == -1) in x_e_getmbc()
1238 return (-1); in x_e_getmbc()
1247 /* XXX x_e_ungetc is one-octet only */ in x_e_getmbc()
1249 if (c == -1) in x_e_getmbc()
1250 return (-1); in x_e_getmbc()
1257 * minimum required space to work with on a line - if the prompt
1258 * leaves less space than this on a line, the prompt is truncated
1265 prompt_trunc = pprompt(prompt, doprint ? 0 : -1); in x_init_prompt()
1267 prompt_trunc -= pwidth; in x_init_prompt()
1268 if ((mksh_uari_t)pwidth > ((mksh_uari_t)x_cols - 3 - MIN_EDIT_SPACE)) { in x_init_prompt()
1270 prompt_trunc = -1; in x_init_prompt()
1294 x_displen = (xx_cols = x_cols) - 2 - (x_col = pwidth); in x_emacs()
1300 int off = source->line - x_nextcmd; in x_emacs()
1301 if (histptr - history >= off) { in x_emacs()
1302 x_load_hist(histptr - off); in x_emacs()
1305 x_nextcmd = -1; in x_emacs()
1313 f = x_curprefix == -1 ? XFUNC_insert : in x_emacs()
1346 i = xep - xbuf; in x_emacs()
1352 /* ad-hoc hack for fixing the cursor position */ in x_emacs()
1375 if (!--left) { in x_insert()
1378 while (x_arg--) in x_insert()
1384 if (x_curprefix == -1) { in x_insert()
1387 while (save_arg--) in x_insert()
1409 while (x_arg--) in x_insert()
1420 * we no longer need to bother checking if macroptr is in x_ins_string()
1421 * not NULL but first char is NUL; x_e_getc() does it in x_ins_string()
1432 return (-1); in x_do_ins()
1434 memmove(xcp + len, xcp, xep - xcp + 1); in x_do_ins()
1449 return (-1); in x_ins()
1475 x_goto(xcp - 1); in x_del_back()
1526 nb = cp - xcp; in x_delete()
1533 xmp -= nb; in x_delete()
1541 xep -= nb; in x_delete()
1543 memmove(xcp, xcp + nb, xep - xcp + 1); in x_delete()
1550 * there is no need to ' ', '\b'. in x_delete()
1553 if ((i = xx_cols - 2 - x_col) > 0 || xep - xlp == 0) { in x_delete()
1555 while (i--) in x_delete()
1557 if (x_col == xx_cols - 2) { in x_delete()
1561 while (nw--) in x_delete()
1610 while (x_arg--) { in x_bword()
1611 while (cp != xbuf && ctype(cp[-1], C_MFS)) { in x_bword()
1612 cp--; in x_bword()
1615 while (cp != xbuf && !ctype(cp[-1], C_MFS)) { in x_bword()
1616 cp--; in x_bword()
1634 while (x_arg--) { in x_fword()
1640 nc = x_nb2nc(cp - xcp); in x_fword()
1671 --cp; in x_bs0()
1680 *p = x_bs0((*p) - 1, NULL); in x_bs3()
1682 while (i--) in x_bs3()
1738 while (x_arg--) { in x_mv_back()
1739 x_goto(xcp - 1); in x_mv_back()
1755 while (x_arg--) { in x_mv_forw()
1776 while (x_arg--) { in x_search_char_forw()
1797 for (; x_arg--; cp = p) in x_search_char_back()
1799 if (p-- == xbuf) in x_search_char_back()
1863 x_load_hist(x_histp - x_arg); in x_prev_com()
1876 * If no argument is given history 1 is probably not what you
1885 x_load_hist(histptr + x_arg - source->line); in x_goto_hist()
1914 strlcpy(xbuf, sp, xend - xbuf); in x_load_hist()
1929 x_nextcmd = source->line - (histptr - x_histncp) + 1; in x_nl_next_com()
1946 int offset = -1; /* offset of match in xbuf, else -1 */ in x_search_hist()
1954 x_e_puts("\nI-search: "); in x_search_hist()
1983 offset = -1; in x_search_hist()
1987 p = x_bs0(p - 1, pat); in x_search_hist()
1991 offset = -1; in x_search_hist()
1998 if ((size_t)(p - pat) >= sizeof(pat) - 1) { in x_search_hist()
2007 x_goto(xbuf + offset + (p - pat) - in x_search_hist()
2037 --patlen; in x_search()
2038 for (hp = x_histp - (sameline ? 0 : 1); hp >= history; --hp) { in x_search()
2050 return (-1); in x_search()
2058 return (x_search_dir(-1)); in x_search_hist_up()
2073 size_t curs = xcp - xbuf; in x_search_dir()
2087 /* return position of first match of pattern in string, else -1 */
2092 return ((strncmp(str, pat + 1, strlen(pat + 1)) == 0) ? 0 : -1); in x_match()
2095 return ((q == NULL) ? -1 : q - str); in x_match()
2103 x_push(xep - (xcp = xbuf)); in x_del_line()
2143 * clear line from x_col (current cursor position) to xx_cols - 2,
2144 * then output lastch, then go back to x_col; if lastch is space,
2161 while (col < (xx_cols - 2)) { in x_clrtoeol()
2169 --col; in x_clrtoeol()
2177 if (prompt_trunc != -1) in x_pprompt()
2195 x_displen = xx_cols - 2 - x_col; in x_redraw()
2199 /* check whether there is more off-screen */ in x_redraw()
2213 /*- in x_transpose()
2214 * What transpose is meant to do seems to be up for debate. This in x_transpose()
2215 * is a general summary of the options; the text is abcd with the in x_transpose()
2221 * Pdksh currently goes with GNU behavior since I believe this is the in x_transpose()
2231 if (xcp - xbuf == 1) { in x_transpose()
2240 if (utf_mbtowc(&tmpa, xcp) == (size_t)-1) { in x_transpose()
2245 if (utf_mbtowc(&tmpb, xcp) == (size_t)-1) { in x_transpose()
2258 if (utf_mbtowc(&tmpa, xcp) == (size_t)-1) { in x_transpose()
2263 if (utf_mbtowc(&tmpb, xcp) == (size_t)-1) { in x_transpose()
2279 x_curprefix = -1; in x_literal()
2307 size_t col = xcp - xbuf; in x_kill()
2308 size_t lastcol = xep - xbuf; in x_kill()
2315 ndel = col - narg; in x_kill()
2317 ndel = narg - col; in x_kill()
2337 killtp--; in x_yank()
2361 x_goto(xcp - len); in x_meta_yank()
2365 killtp = KILLSIZE - 1; in x_meta_yank()
2367 killtp--; in x_meta_yank()
2379 strip_nuls(xbuf, xep - xbuf); in x_intr()
2381 histsave(&source->line, xbuf, HIST_STORE, true); in x_intr()
2410 /* we only support PF2-'1' for now */ in x_vt_hack()
2427 /* XXX x_e_ungetc is one-octet only */ in x_vt_hack()
2431 /*- in x_vt_hack()
2433 * - ESC+[ or ESC+O or Ctrl-X (Prefix 2) in x_vt_hack()
2434 * - 1 (vt_hack) in x_vt_hack()
2435 * - ; in x_vt_hack()
2436 * - 5 (Ctrl key combiner) or 3 (Alt key combiner) in x_vt_hack()
2495 shf_puts("-m ", shl_stdout); in x_bind_showone()
2553 case XFUNC_insert: /* auto-insert */ in x_bind_showall()
2633 return (-1); in x_bind()
2713 rsize = xmp - xcp; in x_kill_region()
2716 rsize = xcp - xmp; in x_kill_region()
2805 nwords = x_cf_glob(&i, xbuf, xep - xbuf, xcp - xbuf, in x_expand()
2813 x_delete(x_nb2nc(end - start), false); in x_expand()
2832 /* 0 for list, 1 for complete and 2 for complete-list */ in do_complete()
2839 nwords = x_cf_glob(&flags, xbuf, xep - xbuf, xcp - xbuf, in do_complete()
2853 olen = end - start; in do_complete()
2859 * is always at most one result, too in do_complete()
2872 * match iff entire original string is part of the in do_complete()
2873 * longest prefix, implying the latter is at least in do_complete()
2892 xep -= olen; in do_complete()
2893 memmove(xcp, xcp + olen, xep - xcp + 1); in do_complete()
2898 * append a space if this is a single non-directory match in do_complete()
2901 if (nwords == 1 && !mksh_cdirsep(words[0][nlen - 1]) && in do_complete()
2909 /*-
2911 * x_adjust - redraw the line adjusting starting point etc.
2914 * This function is called when we have exceeded the bounds
2939 * if the available space is too small; in x_adjust()
2942 if ((xbp = xcp - (x_displen / 2)) < xbuf) in x_adjust()
2944 /* elide UTF-8 fixup as penalty */ in x_adjust()
2952 xbp = x_bs0(xbp - 1, xbuf); in x_adjust()
2953 col_left -= (n = x_size2(xbp, NULL)); in x_adjust()
2970 unget_char = c < 0 ? -1 : (c & 255); in x_e_ungetc()
2980 unget_char = -1; in x_e_getc()
3027 x_col--; in x_e_putc2()
3034 if (x_adj_ok && (x_col < 0 || x_col >= (xx_cols - 2))) in x_e_putc2()
3073 x_col--; in x_e_putc3()
3080 if (x_adj_ok && (x_col < 0 || x_col >= (xx_cols - 2))) in x_e_putc3()
3093 /*-
3095 * x_set_arg - set an arg value for next function
3098 * This is a simple implementation of M-[0-9].
3136 ssize_t len = xep - xbuf; in x_comment()
3137 int ret = x_do_comment(xbuf, xend - xbuf, &len); in x_comment()
3177 /* This is what AT&T ksh seems to do... Very bizarre */ in x_version()
3192 histsave(&source->line, xbuf, HIST_STORE, true); in x_edit_line()
3195 x_arg = source->line - (histptr - x_histp); in x_edit_line()
3198 shf_snprintf(xbuf, xend - xbuf, Tf_sd, ctrl_x_e, x_arg); in x_edit_line()
3200 strlcpy(xbuf, ctrl_x_e, xend - xbuf); in x_edit_line()
3206 /*-
3208 * x_prev_histword - recover word from prev command
3213 * numeric arg is supplied then the n'th word from the
3214 * start of the previous command is used.
3218 * Bound to M-.
3229 /* -1 = defaulted; 0+ = argument */ in x_prev_histword()
3230 static int last_arg = -1; in x_prev_histword()
3238 last_arg = x_arg_defaulted ? -1 : x_arg; in x_prev_histword()
3239 xhp = histptr - (m - 1); in x_prev_histword()
3246 if ((x_arg = last_arg) == -1) { in x_prev_histword()
3249 rcp = &cp[strlen(cp) - 1]; in x_prev_histword()
3251 * ignore white-space after the last word in x_prev_histword()
3254 rcp--; in x_prev_histword()
3256 rcp--; in x_prev_histword()
3266 * ignore white-space at start of line in x_prev_histword()
3270 while (x_arg-- > 0) { in x_prev_histword()
3312 /*-
3314 * x_fold_case - convert word to UPPER/lower/Capital case
3317 * This function is used to implement M-U/M-u, M-L/M-l, M-C/M-c
3332 while (x_arg--) { in x_fold_case()
3334 * first skip over any white-space in x_fold_case()
3370 /*-
3372 * x_lastcp - last visible char
3513 #define vU 0x10 /* an UN-undoable command (that isn't a vM) */
3539 /* 5 ( ) * + , - . / */
3601 static char lastcmd[MAXVICMD]; /* last non-move command */
3613 * The format of buf is the alias contents followed by a NUL byte followed
3614 * by the name (letter) of the alias. The end of the buffer is marked by
3615 * a double NUL. The name of the alias is stored so recursive macros can
3636 ohnum = hnum = hlast = histnum(-1) + 1; in x_vi()
3659 if (wbuf_len != x_cols - 3 && ((wbuf_len = x_cols - 3))) { in x_vi()
3667 winwidth = x_cols - pwidth - 3; in x_vi()
3689 if (c == -1) in x_vi()
3704 if (vs->linelen == 0) { in x_vi()
3706 c = -1; in x_vi()
3721 if (c == -1 || (ssize_t)LINE <= vs->linelen) in x_vi()
3722 return (-1); in x_vi()
3724 if (vs->cbuf != buf) in x_vi()
3725 memcpy(buf, vs->cbuf, vs->linelen); in x_vi()
3727 buf[vs->linelen++] = '\n'; in x_vi()
3729 return (vs->linelen); in x_vi()
3763 case -1: in vi_hook()
3770 vs->cursor--; in vi_hook()
3792 vs->cursor = 0; in vi_hook()
3793 vs->linelen = 0; in vi_hook()
3796 return (-1); in vi_hook()
3801 vs->cursor = 0; in vi_hook()
3802 vs->linelen = 0; in vi_hook()
3813 del_range(vs->cursor, vs->cursor + 1); in vi_hook()
3816 vs->cbuf[vs->cursor++] = ch; in vi_hook()
3898 srchlen--; in vi_hook()
3899 vs->linelen -= char_len(locpat[srchlen]); in vi_hook()
3900 vs->cursor = vs->linelen; in vi_hook()
3909 vs->linelen = 1; in vi_hook()
3910 vs->cursor = 1; in vi_hook()
3926 while (i-- > n) in vi_hook()
3927 vs->linelen -= char_len(locpat[i]); in vi_hook()
3929 vs->cursor = vs->linelen; in vi_hook()
3933 if (srchlen == SRCHLEN - 1) in vi_hook()
3938 if ((size_t)vs->linelen + 2 > in vi_hook()
3939 (size_t)vs->cbufsize) in vi_hook()
3941 vs->cbuf[vs->linelen++] = '^'; in vi_hook()
3942 vs->cbuf[vs->linelen++] = ksh_unctrl(ch); in vi_hook()
3944 if (vs->linelen >= vs->cbufsize) in vi_hook()
3946 vs->cbuf[vs->linelen++] = ch; in vi_hook()
3948 vs->cursor = vs->linelen; in vi_hook()
3962 if (!vs->cursor) in vi_hook()
3965 if ((size_t)vs->cursor >= sizeof(srchpat) - 1) in vi_hook()
3966 vs->cursor = sizeof(srchpat) - 2; in vi_hook()
3970 memcpy(srchpat + 1, vs->cbuf, vs->cursor); in vi_hook()
3971 srchpat[vs->cursor + 1] = '\0'; in vi_hook()
3973 argc1 = 2 + (int)vs->cursor; in vi_hook()
3988 case -1: in vi_hook()
4001 /* back from a 'v' command - don't redraw the screen */ in vi_hook()
4011 case -1: in vi_hook()
4032 /* back from a 'v' command - can't happen */ in vi_hook()
4071 if (vs->cursor == undo->cursor) { in vi_insert()
4076 inslen--; in vi_insert()
4077 vs->cursor--; in vi_insert()
4078 if (vs->cursor >= undo->linelen) in vi_insert()
4079 vs->linelen--; in vi_insert()
4081 vs->cbuf[vs->cursor] = undo->cbuf[vs->cursor]; in vi_insert()
4083 if (vs->cursor == 0) in vi_insert()
4086 inslen--; in vi_insert()
4087 vs->cursor--; in vi_insert()
4088 vs->linelen--; in vi_insert()
4089 memmove(&vs->cbuf[vs->cursor], &vs->cbuf[vs->cursor + 1], in vi_insert()
4090 vs->linelen - vs->cursor + 1); in vi_insert()
4096 if (vs->cursor != 0) { in vi_insert()
4098 memmove(vs->cbuf, &vs->cbuf[vs->cursor], in vi_insert()
4099 vs->linelen - vs->cursor); in vi_insert()
4100 vs->linelen -= vs->cursor; in vi_insert()
4101 vs->cursor = 0; in vi_insert()
4107 if (vs->cursor != 0) { in vi_insert()
4109 memmove(&vs->cbuf[tcursor], &vs->cbuf[vs->cursor], in vi_insert()
4110 vs->linelen - vs->cursor); in vi_insert()
4111 vs->linelen -= vs->cursor - tcursor; in vi_insert()
4112 if (inslen < vs->cursor - tcursor) in vi_insert()
4115 inslen -= vs->cursor - tcursor; in vi_insert()
4116 vs->cursor = tcursor; in vi_insert()
4130 return (-1); in vi_insert()
4150 return (redo_insert(lastac - 1)); in vi_insert()
4174 if (vs->linelen >= vs->cbufsize - 1) in vi_insert()
4175 return (-1); in vi_insert()
4178 memmove(&vs->cbuf[vs->cursor + 1], &vs->cbuf[vs->cursor], in vi_insert()
4179 vs->linelen - vs->cursor); in vi_insert()
4180 vs->linelen++; in vi_insert()
4182 vs->cbuf[vs->cursor++] = ch; in vi_insert()
4183 if (insert == REPLACE && vs->cursor > vs->linelen) in vi_insert()
4184 vs->linelen++; in vi_insert()
4204 if (cur == vs->linelen && cur != 0) in vi_cmd()
4205 cur--; in vi_cmd()
4206 vs->cursor = cur; in vi_cmd()
4208 return (-1); in vi_cmd()
4212 undo->winleft = vs->winleft; in vi_cmd()
4213 memmove(undo->cbuf, vs->cbuf, vs->linelen); in vi_cmd()
4214 undo->linelen = vs->linelen; in vi_cmd()
4215 undo->cursor = vs->cursor; in vi_cmd()
4236 if (!cmd[1] || !ap || !(ap->flag & ISSET)) in vi_cmd()
4237 return (-1); in vi_cmd()
4238 /* check if this is a recursive call... */ in vi_cmd()
4242 return (-1); in vi_cmd()
4244 nlen = strlen(ap->val.s) + 1; in vi_cmd()
4246 macro.len - (macro.p - macro.buf); in vi_cmd()
4252 memcpy(nbuf, ap->val.s, nlen); in vi_cmd()
4270 if (vs->linelen != 0) in vi_cmd()
4271 vs->cursor++; in vi_cmd()
4279 vs->cursor = vs->linelen; in vi_cmd()
4284 vs->cursor = domovebeg(); in vi_cmd()
4285 del_range(vs->cursor, vs->linelen); in vi_cmd()
4301 c2 = vs->linelen; in vi_cmd()
4303 return (-1); in vi_cmd()
4306 return (-1); in vi_cmd()
4308 !ctype(vs->cbuf[vs->cursor], C_SPACE)) { in vi_cmd()
4310 --ncursor; in vi_cmd()
4311 } while (ctype(vs->cbuf[ncursor], C_SPACE)); in vi_cmd()
4314 if (ncursor > vs->cursor) { in vi_cmd()
4315 c1 = vs->cursor; in vi_cmd()
4319 c2 = vs->cursor; in vi_cmd()
4328 vs->cursor = c1; in vi_cmd()
4340 if (vs->linelen != 0) in vi_cmd()
4341 vs->cursor++; in vi_cmd()
4343 --argcnt > 0) in vi_cmd()
4345 if (vs->cursor != 0) in vi_cmd()
4346 vs->cursor--; in vi_cmd()
4348 return (-1); in vi_cmd()
4356 --argcnt > 0) in vi_cmd()
4358 if (any && vs->cursor != 0) in vi_cmd()
4359 vs->cursor--; in vi_cmd()
4361 return (-1); in vi_cmd()
4367 del_range(vs->cursor, vs->linelen); in vi_cmd()
4372 yank_range(vs->cursor, vs->linelen); in vi_cmd()
4373 del_range(vs->cursor, vs->linelen); in vi_cmd()
4374 if (vs->cursor != 0) in vi_cmd()
4375 vs->cursor--; in vi_cmd()
4386 argcnt = hlast - (source->line - argcnt); in vi_cmd()
4387 if (grabhist(modified, argcnt - 1) < 0) in vi_cmd()
4388 return (-1); in vi_cmd()
4391 hnum = argcnt - 1; in vi_cmd()
4404 vs->cursor = domovebeg(); in vi_cmd()
4412 return (-1); in vi_cmd()
4420 case ORD('-'): in vi_cmd()
4422 if (grabhist(modified, hnum - argcnt) < 0) in vi_cmd()
4423 return (-1); in vi_cmd()
4426 hnum -= argcnt; in vi_cmd()
4431 if (vs->linelen == 0) in vi_cmd()
4432 return (-1); in vi_cmd()
4440 if (vs->cursor + argcnt > vs->linelen) in vi_cmd()
4441 return (-1); in vi_cmd()
4443 vs->cbuf[vs->cursor + n] = cmd[1]; in vi_cmd()
4444 vs->cursor += n - 1; in vi_cmd()
4455 if (vs->linelen == 0) in vi_cmd()
4456 return (-1); in vi_cmd()
4459 if (vs->cursor + argcnt > vs->linelen) in vi_cmd()
4460 argcnt = vs->linelen - vs->cursor; in vi_cmd()
4461 del_range(vs->cursor, vs->cursor + argcnt); in vi_cmd()
4468 vs->cbuf[vs->linelen] = '\0'; in vi_cmd()
4469 histsave(&source->line, vs->cbuf, in vi_cmd()
4472 argcnt = source->line + 1 - in vi_cmd()
4473 (hlast - hnum); in vi_cmd()
4476 shf_snprintf(vs->cbuf, vs->cbufsize, Tf_sd, in vi_cmd()
4479 strlcpy(vs->cbuf, ctrl_x_e, vs->cbufsize); in vi_cmd()
4480 vs->linelen = strlen(vs->cbuf); in vi_cmd()
4484 if (vs->linelen == 0) in vi_cmd()
4485 return (-1); in vi_cmd()
4488 if (vs->cursor + argcnt > vs->linelen) in vi_cmd()
4489 argcnt = vs->linelen - vs->cursor; in vi_cmd()
4490 yank_range(vs->cursor, vs->cursor + argcnt); in vi_cmd()
4491 del_range(vs->cursor, vs->cursor + argcnt); in vi_cmd()
4495 if (vs->cursor > 0) { in vi_cmd()
4498 if (vs->cursor < argcnt) in vi_cmd()
4499 argcnt = vs->cursor; in vi_cmd()
4500 yank_range(vs->cursor - argcnt, vs->cursor); in vi_cmd()
4501 del_range(vs->cursor - argcnt, vs->cursor); in vi_cmd()
4502 vs->cursor -= argcnt; in vi_cmd()
4504 return (-1); in vi_cmd()
4515 return (-1); in vi_cmd()
4517 return (-1); in vi_cmd()
4524 hnum = -1; in vi_cmd()
4538 return (-1); in vi_cmd()
4547 return (-1); in vi_cmd()
4554 /* flag from cursor-up command */ in vi_cmd()
4555 vs->cursor = argcnt - 2; in vi_cmd()
4564 if (histnum(-1) < 0) in vi_cmd()
4565 return (-1); in vi_cmd()
4570 while (*p && --argcnt) { in vi_cmd()
4577 return (-1); in vi_cmd()
4595 if (vs->cursor != vs->linelen) in vi_cmd()
4596 vs->cursor++; in vi_cmd()
4603 if (vs->cursor != 0) in vi_cmd()
4604 vs->cursor--; in vi_cmd()
4605 return (-1); in vi_cmd()
4616 if (vs->linelen == 0) in vi_cmd()
4617 return (-1); in vi_cmd()
4619 p = &vs->cbuf[vs->cursor]; in vi_cmd()
4629 if (vs->cursor < vs->linelen - 1) in vi_cmd()
4630 vs->cursor++; in vi_cmd()
4637 int ret = x_do_comment(vs->cbuf, vs->cbufsize, in vi_cmd()
4638 &vs->linelen); in vi_cmd()
4640 vs->cursor = 0; in vi_cmd()
4655 return (-1); in vi_cmd()
4662 return (-1); in vi_cmd()
4684 if (vs->linelen != 0) in vi_cmd()
4685 vs->cursor++; in vi_cmd()
4689 if (insert == 0 && vs->cursor != 0 && vs->cursor >= vs->linelen) in vi_cmd()
4690 vs->cursor--; in vi_cmd()
4703 if (!sub && vs->cursor == 0) in domove()
4704 return (-1); in domove()
4709 if (!sub && vs->cursor == 0) in domove()
4710 return (-1); in domove()
4715 if (!sub && vs->cursor + 1 >= vs->linelen) in domove()
4716 return (-1); in domove()
4718 if (sub && ncursor < vs->linelen) in domove()
4723 if (!sub && vs->cursor + 1 >= vs->linelen) in domove()
4724 return (-1); in domove()
4726 if (sub && ncursor < vs->linelen) in domove()
4740 return (-1); in domove()
4747 return (-1); in domove()
4754 if (!sub && vs->cursor == 0) in domove()
4755 return (-1); in domove()
4756 ncursor = vs->cursor - argcnt; in domove()
4763 if (!sub && vs->cursor + 1 >= vs->linelen) in domove()
4764 return (-1); in domove()
4765 if (vs->linelen != 0) { in domove()
4766 ncursor = vs->cursor + argcnt; in domove()
4767 if (ncursor > vs->linelen) in domove()
4768 ncursor = vs->linelen; in domove()
4773 if (!sub && vs->cursor + 1 >= vs->linelen) in domove()
4774 return (-1); in domove()
4779 if (!sub && vs->cursor + 1 >= vs->linelen) in domove()
4780 return (-1); in domove()
4794 if (ncursor > vs->linelen) in domove()
4795 ncursor = vs->linelen; in domove()
4797 ncursor--; in domove()
4801 if (vs->linelen != 0) in domove()
4802 ncursor = vs->linelen; in domove()
4808 ncursor = vs->cursor; in domove()
4809 while (ncursor < vs->linelen && in domove()
4810 (i = bracktype(vs->cbuf[ncursor])) == 0) in domove()
4812 if (ncursor == vs->linelen) in domove()
4813 return (-1); in domove()
4817 if (++ncursor >= vs->linelen) in domove()
4818 return (-1); in domove()
4820 if (--ncursor < 0) in domove()
4821 return (-1); in domove()
4823 t = bracktype(vs->cbuf[ncursor]); in domove()
4826 else if (t == -i) in domove()
4827 bcount--; in domove()
4834 return (-1); in domove()
4844 while (ncursor < vs->linelen - 1 && in domovebeg()
4845 ctype(vs->cbuf[ncursor], C_SPACE)) in domovebeg()
4853 while (count-- > 0) in redo_insert()
4855 return (-1); in redo_insert()
4856 if (vs->cursor > 0) in redo_insert()
4857 vs->cursor--; in redo_insert()
4865 yanklen = b - a; in yank_range()
4867 memmove(ybuf, &vs->cbuf[a], yanklen); in yank_range()
4885 return (-1); in bracktype()
4888 return (-2); in bracktype()
4891 return (-3); in bracktype()
4905 memmove(holdbufp, vs->cbuf, vs->linelen); in save_cbuf()
4906 holdlen = vs->linelen; in save_cbuf()
4913 vs->cursor = 0; in restore_cbuf()
4914 vs->linelen = holdlen; in restore_cbuf()
4915 memmove(vs->cbuf, holdbufp, holdlen); in restore_cbuf()
4925 news->cbuf = alloc(old->cbufsize, AEDIT); in save_edstate()
4926 memcpy(news->cbuf, old->cbuf, old->linelen); in save_edstate()
4927 news->cbufsize = old->cbufsize; in save_edstate()
4928 news->linelen = old->linelen; in save_edstate()
4929 news->cursor = old->cursor; in save_edstate()
4930 news->winleft = old->winleft; in save_edstate()
4937 memcpy(news->cbuf, old->cbuf, old->linelen); in restore_edstate()
4938 news->linelen = old->linelen; in restore_edstate()
4939 news->cursor = old->cursor; in restore_edstate()
4940 news->winleft = old->winleft; in restore_edstate()
4947 afree(old->cbuf, AEDIT); in free_edstate()
4952 * this is used for calling x_escape() in complete_word()
4966 if (vs->cursor + len >= vs->cbufsize) in putbuf()
4967 return (-1); in putbuf()
4968 if (vs->cursor + len > vs->linelen) in putbuf()
4969 vs->linelen = vs->cursor + len; in putbuf()
4971 if (vs->linelen + len >= vs->cbufsize) in putbuf()
4972 return (-1); in putbuf()
4973 memmove(&vs->cbuf[vs->cursor + len], &vs->cbuf[vs->cursor], in putbuf()
4974 vs->linelen - vs->cursor); in putbuf()
4975 vs->linelen += len; in putbuf()
4977 memmove(&vs->cbuf[vs->cursor], buf, len); in putbuf()
4978 vs->cursor += len; in putbuf()
4985 if (vs->linelen != b) in del_range()
4986 memmove(&vs->cbuf[a], &vs->cbuf[b], vs->linelen - b); in del_range()
4987 vs->linelen -= b - a; in del_range()
4995 if (vs->linelen == 0) in findch()
4996 return (-1); in findch()
4997 ncursor = vs->cursor; in findch()
4998 while (cnt--) { in findch()
5001 if (++ncursor == vs->linelen) in findch()
5002 return (-1); in findch()
5004 if (--ncursor < 0) in findch()
5005 return (-1); in findch()
5007 } while (vs->cbuf[ncursor] != ch); in findch()
5011 ncursor--; in findch()
5023 ncursor = vs->cursor; in forwword()
5024 while (ncursor < vs->linelen && argcnt--) { in forwword()
5025 if (ctype(vs->cbuf[ncursor], C_ALNUX)) in forwword()
5026 while (ncursor < vs->linelen && in forwword()
5027 ctype(vs->cbuf[ncursor], C_ALNUX)) in forwword()
5029 else if (!ctype(vs->cbuf[ncursor], C_SPACE)) in forwword()
5030 while (ncursor < vs->linelen && in forwword()
5031 !ctype(vs->cbuf[ncursor], C_ALNUX | C_SPACE)) in forwword()
5033 while (ncursor < vs->linelen && in forwword()
5034 ctype(vs->cbuf[ncursor], C_SPACE)) in forwword()
5045 ncursor = vs->cursor; in backword()
5046 while (ncursor > 0 && argcnt--) { in backword()
5047 while (--ncursor > 0 && ctype(vs->cbuf[ncursor], C_SPACE)) in backword()
5050 if (ctype(vs->cbuf[ncursor], C_ALNUX)) in backword()
5051 while (--ncursor >= 0 && in backword()
5052 ctype(vs->cbuf[ncursor], C_ALNUX)) in backword()
5055 while (--ncursor >= 0 && in backword()
5056 !ctype(vs->cbuf[ncursor], C_ALNUX | C_SPACE)) in backword()
5069 ncursor = vs->cursor; in endword()
5070 while (ncursor < vs->linelen && argcnt--) { in endword()
5071 while (++ncursor < vs->linelen - 1 && in endword()
5072 ctype(vs->cbuf[ncursor], C_SPACE)) in endword()
5074 if (ncursor < vs->linelen - 1) { in endword()
5075 if (ctype(vs->cbuf[ncursor], C_ALNUX)) in endword()
5076 while (++ncursor < vs->linelen && in endword()
5077 ctype(vs->cbuf[ncursor], C_ALNUX)) in endword()
5080 while (++ncursor < vs->linelen && in endword()
5081 !ctype(vs->cbuf[ncursor], C_ALNUX | C_SPACE)) in endword()
5083 ncursor--; in endword()
5094 ncursor = vs->cursor; in Forwword()
5095 while (ncursor < vs->linelen && argcnt--) { in Forwword()
5096 while (ncursor < vs->linelen && in Forwword()
5097 !ctype(vs->cbuf[ncursor], C_SPACE)) in Forwword()
5099 while (ncursor < vs->linelen && in Forwword()
5100 ctype(vs->cbuf[ncursor], C_SPACE)) in Forwword()
5111 ncursor = vs->cursor; in Backword()
5112 while (ncursor > 0 && argcnt--) { in Backword()
5113 while (--ncursor >= 0 && ctype(vs->cbuf[ncursor], C_SPACE)) in Backword()
5115 while (ncursor >= 0 && !ctype(vs->cbuf[ncursor], C_SPACE)) in Backword()
5116 ncursor--; in Backword()
5127 ncursor = vs->cursor; in Endword()
5128 while (ncursor < vs->linelen - 1 && argcnt--) { in Endword()
5129 while (++ncursor < vs->linelen - 1 && in Endword()
5130 ctype(vs->cbuf[ncursor], C_SPACE)) in Endword()
5132 if (ncursor < vs->linelen - 1) { in Endword()
5133 while (++ncursor < vs->linelen && in Endword()
5134 !ctype(vs->cbuf[ncursor], C_SPACE)) in Endword()
5136 ncursor--; in Endword()
5148 return (-1); in grabhist()
5157 return (-1); in grabhist()
5161 if ((vs->linelen = strlen(hptr)) >= vs->cbufsize) in grabhist()
5162 vs->linelen = vs->cbufsize - 1; in grabhist()
5163 memmove(vs->cbuf, hptr, vs->linelen); in grabhist()
5164 vs->cursor = 0; in grabhist()
5176 if ((start == 0 && !fwd) || (start >= hlast - 1 && fwd)) in grabsearch()
5177 return (-1); in grabsearch()
5181 start--; in grabsearch()
5189 return (-1); in grabsearch()
5195 if ((vs->linelen = strlen(hptr)) >= vs->cbufsize) in grabsearch()
5196 vs->linelen = vs->cbufsize - 1; in grabsearch()
5197 memmove(vs->cbuf, hptr, vs->linelen); in grabsearch()
5198 vs->cursor = 0; in grabsearch()
5220 display(wbuf[1 - win], wbuf[win], leftside); in refresh()
5221 win = 1 - win; in refresh()
5229 if (vs->cursor < vs->winleft) in outofwin()
5232 cur = vs->winleft; in outofwin()
5233 while (cur < vs->cursor) in outofwin()
5234 col = newcol((unsigned char)vs->cbuf[cur++], col); in outofwin()
5249 while (tcur < vs->cursor) { in rewindow()
5250 if (tcol - holdcol2 > winwidth / 2) { in rewindow()
5256 tcol = newcol((unsigned char)vs->cbuf[tcur++], tcol); in rewindow()
5258 while (tcol - holdcol1 > winwidth / 2) in rewindow()
5259 holdcol1 = newcol((unsigned char)vs->cbuf[holdcur1++], in rewindow()
5261 vs->winleft = holdcur1; in rewindow()
5282 cur = vs->winleft; in display()
5285 while (col < winwidth && cur < vs->linelen) { in display()
5286 if (cur == vs->cursor && leftside) in display()
5288 if ((ch = vs->cbuf[cur]) == '\t') in display()
5304 if (cur == vs->cursor && !leftside) in display()
5305 ncol = col + pwidth - 1; in display()
5308 if (cur == vs->cursor) in display()
5323 while (cnt--) { in display()
5334 if (vs->winleft > 0 && moreright) in display()
5336 * POSIX says to use * for this but that is a globbing in display()
5337 * character and may confuse people; + is more innocuous in display()
5340 else if (vs->winleft > 0) in display()
5360 if (col + 1 < x_col - col) { in ed_mov_opt()
5366 while (x_col-- > col) in ed_mov_opt()
5370 wb = &wb[x_col - pwidth]; in ed_mov_opt()
5399 nwords = x_cf_glob(&i, vs->cbuf, vs->linelen, vs->cursor, in expand_word()
5403 return (-1); in expand_word()
5409 vs->cursor = start; in expand_word()
5413 rval = -1; in expand_word()
5417 rval = -1; in expand_word()
5421 i = buf->cursor - end; in expand_word()
5423 vs->cursor += i; in expand_word()
5466 nwords = x_cf_glob(&flags, vs->cbuf, vs->linelen, vs->cursor, in complete_word()
5470 return (-1); in complete_word()
5475 count--; in complete_word()
5482 return (-1); in complete_word()
5513 vs->cursor = start; in complete_word()
5516 * escape all shell-sensitive characters and put the result into in complete_word()
5529 * append a space if this is a non-directory match in complete_word()
5532 if (match_len > 0 && !mksh_cdirsep(match[match_len - 1]) && in complete_word()
5555 nwords = x_cf_glob(&i, est->cbuf, est->linelen, est->cursor, in print_expansions()
5559 return (-1); in print_expansions()
5618 x_nextcmd = -1; in x_init()
5656 (termtype[6] == '\0' || termtype[6] == '-')) in x_initterm()
5661 (termtype[4] == '\0' || termtype[4] == '-')) in x_initterm()
5674 if (!kshsetjmp(e->jbuf)) { in x_eval_region_helper()
5715 cp = helper(rgbeg, rgend - rgbeg); in x_operate_region()
5727 restlen = xep - rgend; in x_operate_region()
5728 /* check for LINE overflow, until this is dynamically allocated */ in x_operate_region()