OSDN Git Service

Upgrade to mksh R40.
[android-x86/external-mksh.git] / src / edit.c
index d13df5e..4ed5ca3 100644 (file)
@@ -28,7 +28,7 @@
 
 #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
@@ -238,6 +238,7 @@ x_print_expansions(int nwords, char * const *words, bool is_command)
        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
@@ -257,7 +258,8 @@ x_print_expansions(int nwords, char * const *words, bool is_command)
                                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);
@@ -271,7 +273,11 @@ x_print_expansions(int nwords, char * const *words, bool is_command)
         */
        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() */
@@ -333,7 +339,7 @@ x_glob_hlp_tilde_and_rem_qchar(char *s, bool magic_flag)
         * 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 */
@@ -588,7 +594,7 @@ x_locate_word(const char *buf, int buflen, int pos, int *startp,
                         * like file globbing.
                         */
                        for (p = start; p < end; p++)
-                               if (buf[p] == '/')
+                               if (mksh_cdirsep(buf[p]))
                                        break;
                        iscmd = p == end;
                }
@@ -652,7 +658,7 @@ x_cf_glob(int *flagsp, const char *buf, int buflen, int pos, int *startp,
                        }
                }
 
-               if (*toglob == '~' && !vstrchr(toglob, '/')) {
+               if (*toglob == '~' && !mksh_vdirsep(toglob)) {
                        /* neither for '~foo' (but '~foo/bar') */
                        *flagsp |= XCF_IS_NOSPACE;
                        goto dont_add_glob;
@@ -741,13 +747,15 @@ x_basename(const char *s, const char *se)
        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);
 }
@@ -1048,7 +1056,7 @@ static struct x_defbindings const x_defbindings[] = {
        { 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('[')    },
@@ -1106,8 +1114,8 @@ static struct x_defbindings const x_defbindings[] = {
        { 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'     },
@@ -1119,7 +1127,7 @@ static struct x_defbindings const x_defbindings[] = {
        /* 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      },
@@ -2044,7 +2052,7 @@ x_mv_end(int c MKSH_A_UNUSED)
 }
 
 static int
-x_mv_begin(int c MKSH_A_UNUSED)
+x_mv_beg(int c MKSH_A_UNUSED)
 {
        x_goto(xbuf);
        return (KSTD);
@@ -2328,7 +2336,7 @@ x_vt_hack(int c)
        case '~':
                x_arg = 1;
                x_arg_defaulted = true;
-               return (x_mv_begin(0));
+               return (x_mv_beg(0));
        case ';':
                /* "interesting" sequence detected */
                break;
@@ -2778,7 +2786,7 @@ do_complete(
         * 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);
        }
@@ -4016,7 +4024,7 @@ vi_insert(int ch)
                else
                        return (redo_insert(lastac - 1));
 
-       /* { Begin nonstandard vi commands */
+       /* { start nonstandard vi commands */
        case CTRL('x'):
                expand_word(0);
                break;
@@ -4035,7 +4043,7 @@ vi_insert(int ch)
                        break;
                }
                /* FALLTHROUGH */
-       /* End nonstandard vi commands } */
+       /* end nonstandard vi commands } */
 
        default:
                if (es->linelen >= es->cbufsize - 1)
@@ -4157,6 +4165,8 @@ vi_cmd(int argcnt, const char *cmd)
                case 'Y':
                        cmd = "y$";
                        /* ahhhhhh... */
+
+                       /* FALLTHROUGH */
                case 'c':
                case 'd':
                case 'y':
@@ -4393,6 +4403,8 @@ vi_cmd(int argcnt, const char *cmd)
                        if (hnum == hlast)
                                hnum = -1;
                        /* ahhh */
+
+                       /* FALLTHROUGH */
                case '/':
                        c3 = 1;
                        srchlen = 0;
@@ -4531,6 +4543,7 @@ vi_cmd(int argcnt, const char *cmd)
                case CTRL('['):
                        if (!Flag(FVIESCCOMPLETE))
                                return (-1);
+                       /* FALLTHROUGH */
                /* AT&T ksh */
                case '\\':
                /* Nonstandard vi/ksh */
@@ -4603,8 +4616,7 @@ domove(int argcnt, const char *cmd, int sub)
        case 'T':
                fsavecmd = *cmd;
                fsavech = cmd[1];
-               /* drop through */
-
+               /* FALLTHROUGH */
        case ',':
        case ';':
                if (fsavecmd == ' ')
@@ -5399,7 +5411,7 @@ complete_word(int cmd, int count)
                 * 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);
        }