#ifndef MKSH_NO_CMDLINE_EDITING
-__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.306 2016/08/01 18:42:40 tg Exp $");
+__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.312 2016/11/11 23:48:28 tg Exp $");
/*
* in later versions we might use libtermcap for this, but since external
bool use_copy = false;
size_t prefix_len;
XPtrV l = { NULL, 0, 0 };
+ struct columnise_opts co;
/*
* Check if all matches are in the same directory (in this
break;
/* All in same directory? */
if (i == nwords) {
- while (prefix_len > 0 && words[0][prefix_len - 1] != '/')
+ while (prefix_len > 0 &&
+ !mksh_cdirsep(words[0][prefix_len - 1]))
prefix_len--;
use_copy = true;
XPinit(l, nwords + 1);
*/
x_putc('\r');
x_putc('\n');
- pr_list(use_copy ? (char **)XPptrv(l) : words);
+ co.shf = shl_out;
+ co.linesep = '\n';
+ co.do_last = true;
+ co.prefcol = false;
+ pr_list(&co, use_copy ? (char **)XPptrv(l) : words);
if (use_copy)
/* not x_free_words() */
* and if so, discern "~foo/bar" and "~/baz" from "~blah";
* if we have a directory part (the former), try to expand
*/
- if (*s == '~' && (cp = strchr(s, '/')) != NULL) {
+ if (*s == '~' && (cp = mksh_sdirsep(s)) != NULL) {
/* ok, so split into "~foo"/"bar" or "~"/"baz" */
*cp++ = 0;
/* try to expand the tilde */
* like file globbing.
*/
for (p = start; p < end; p++)
- if (buf[p] == '/')
+ if (mksh_cdirsep(buf[p]))
break;
iscmd = p == end;
}
}
}
- if (*toglob == '~' && !vstrchr(toglob, '/')) {
+ if (*toglob == '~' && !mksh_vdirsep(toglob)) {
/* neither for '~foo' (but '~foo/bar') */
*flagsp |= XCF_IS_NOSPACE;
goto dont_add_glob;
if (s == se)
return (0);
- /* Skip trailing slashes */
- for (p = se - 1; p > s && *p == '/'; p--)
- ;
- for (; p > s && *p != '/'; p--)
- ;
- if (*p == '/' && p + 1 < se)
- p++;
+ /* skip trailing directory separators */
+ p = se - 1;
+ while (p > s && mksh_cdirsep(*p))
+ --p;
+ /* drop last component */
+ while (p > s && !mksh_cdirsep(*p))
+ --p;
+ if (mksh_cdirsep(*p) && p + 1 < se)
+ ++p;
return (p - s);
}
{ XFUNC_end_hist, 1, '>' },
{ XFUNC_goto_hist, 1, 'g' },
{ XFUNC_mv_end, 0, CTRL('E') },
- { XFUNC_mv_begin, 0, CTRL('A') },
+ { XFUNC_mv_beg, 0, CTRL('A') },
{ XFUNC_draw_line, 0, CTRL('L') },
{ XFUNC_cls, 1, CTRL('L') },
{ XFUNC_meta1, 0, CTRL('[') },
{ XFUNC_mv_back, 2, 'D' },
#ifndef MKSH_SMALL
{ XFUNC_vt_hack, 2, '1' },
- { XFUNC_mv_begin | 0x80, 2, '7' },
- { XFUNC_mv_begin, 2, 'H' },
+ { XFUNC_mv_beg | 0x80, 2, '7' },
+ { XFUNC_mv_beg, 2, 'H' },
{ XFUNC_mv_end | 0x80, 2, '4' },
{ XFUNC_mv_end | 0x80, 2, '8' },
{ XFUNC_mv_end, 2, 'F' },
/* PC scancodes */
#if !defined(MKSH_SMALL) || defined(__OS2__)
{ XFUNC_meta3, 0, 0 },
- { XFUNC_mv_begin, 3, 71 },
+ { XFUNC_mv_beg, 3, 71 },
{ XFUNC_prev_com, 3, 72 },
#ifndef MKSH_SMALL
{ XFUNC_search_hist_up, 3, 73 },
}
static int
-x_mv_begin(int c MKSH_A_UNUSED)
+x_mv_beg(int c MKSH_A_UNUSED)
{
x_goto(xbuf);
return (KSTD);
case '~':
x_arg = 1;
x_arg_defaulted = true;
- return (x_mv_begin(0));
+ return (x_mv_beg(0));
case ';':
/* "interesting" sequence detected */
break;
* append a space if this is a single non-directory match
* and not a parameter or homedir substitution
*/
- if (nwords == 1 && words[0][nlen - 1] != '/' &&
+ if (nwords == 1 && !mksh_cdirsep(words[0][nlen - 1]) &&
!(flags & XCF_IS_NOSPACE)) {
x_ins(T1space);
}
else
return (redo_insert(lastac - 1));
- /* { Begin nonstandard vi commands */
+ /* { start nonstandard vi commands */
case CTRL('x'):
expand_word(0);
break;
break;
}
/* FALLTHROUGH */
- /* End nonstandard vi commands } */
+ /* end nonstandard vi commands } */
default:
if (es->linelen >= es->cbufsize - 1)
case 'Y':
cmd = "y$";
/* ahhhhhh... */
+
+ /* FALLTHROUGH */
case 'c':
case 'd':
case 'y':
if (hnum == hlast)
hnum = -1;
/* ahhh */
+
+ /* FALLTHROUGH */
case '/':
c3 = 1;
srchlen = 0;
case CTRL('['):
if (!Flag(FVIESCCOMPLETE))
return (-1);
+ /* FALLTHROUGH */
/* AT&T ksh */
case '\\':
/* Nonstandard vi/ksh */
case 'T':
fsavecmd = *cmd;
fsavech = cmd[1];
- /* drop through */
-
+ /* FALLTHROUGH */
case ',':
case ';':
if (fsavecmd == ' ')
* append a space if this is a non-directory match
* and not a parameter or homedir substitution
*/
- if (match_len > 0 && match[match_len - 1] != '/' &&
+ if (match_len > 0 && !mksh_cdirsep(match[match_len - 1]) &&
!(flags & XCF_IS_NOSPACE))
rval = putbuf(T1space, 1, false);
}