BEL was, and Vi mode is, not EBCDIC-safe
This commit is contained in:
parent
2231ff566d
commit
8df7c0c94a
74
edit.c
74
edit.c
@ -28,7 +28,7 @@
|
||||
|
||||
#ifndef MKSH_NO_CMDLINE_EDITING
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.329 2017/04/28 00:38:28 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.330 2017/04/28 00:49:32 tg Exp $");
|
||||
|
||||
/*
|
||||
* in later versions we might use libtermcap for this, but since external
|
||||
@ -1313,7 +1313,7 @@ x_insert(int c)
|
||||
if (c == 0) {
|
||||
invmbs:
|
||||
left = 0;
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
return (KSTD);
|
||||
}
|
||||
if (UTFMODE) {
|
||||
@ -1375,7 +1375,7 @@ static int
|
||||
x_do_ins(const char *cp, size_t len)
|
||||
{
|
||||
if (xep + len >= xend) {
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
return (-1);
|
||||
}
|
||||
memmove(xcp + len, xcp, xep - xcp + 1);
|
||||
@ -1415,7 +1415,7 @@ x_del_back(int c MKSH_A_UNUSED)
|
||||
ssize_t i = 0;
|
||||
|
||||
if (xcp == xbuf) {
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
return (KSTD);
|
||||
}
|
||||
do {
|
||||
@ -1441,7 +1441,7 @@ x_del_char(int c MKSH_A_UNUSED)
|
||||
}
|
||||
|
||||
if (!i) {
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
return (KSTD);
|
||||
}
|
||||
x_delete(i, false);
|
||||
@ -1551,7 +1551,7 @@ x_bword(void)
|
||||
char *cp = xcp;
|
||||
|
||||
if (cp == xbuf) {
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
return (0);
|
||||
}
|
||||
while (x_arg--) {
|
||||
@ -1575,7 +1575,7 @@ x_fword(bool move)
|
||||
char *cp = xcp;
|
||||
|
||||
if (cp == xep) {
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
return (0);
|
||||
}
|
||||
while (x_arg--) {
|
||||
@ -1679,7 +1679,7 @@ static int
|
||||
x_mv_back(int c MKSH_A_UNUSED)
|
||||
{
|
||||
if (xcp == xbuf) {
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
return (KSTD);
|
||||
}
|
||||
while (x_arg--) {
|
||||
@ -1696,7 +1696,7 @@ x_mv_forw(int c MKSH_A_UNUSED)
|
||||
char *cp = xcp, *cp2;
|
||||
|
||||
if (xcp == xep) {
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
return (KSTD);
|
||||
}
|
||||
while (x_arg--) {
|
||||
@ -1717,13 +1717,13 @@ x_search_char_forw(int c MKSH_A_UNUSED)
|
||||
|
||||
*xep = '\0';
|
||||
if (x_e_getmbc(tmp) < 0) {
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
return (KSTD);
|
||||
}
|
||||
while (x_arg--) {
|
||||
if ((cp = (cp == xep) ? NULL : strstr(cp + 1, tmp)) == NULL &&
|
||||
(cp = strstr(xbuf, tmp)) == NULL) {
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
return (KSTD);
|
||||
}
|
||||
}
|
||||
@ -1738,7 +1738,7 @@ x_search_char_back(int c MKSH_A_UNUSED)
|
||||
bool b;
|
||||
|
||||
if (x_e_getmbc(tmp) < 0) {
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
return (KSTD);
|
||||
}
|
||||
for (; x_arg--; cp = p)
|
||||
@ -1746,7 +1746,7 @@ x_search_char_back(int c MKSH_A_UNUSED)
|
||||
if (p-- == xbuf)
|
||||
p = xep;
|
||||
if (p == cp) {
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
return (KSTD);
|
||||
}
|
||||
if ((tmp[1] && ((p+1) > xep)) ||
|
||||
@ -1842,7 +1842,7 @@ x_load_hist(char **hp)
|
||||
sp = holdbufp;
|
||||
modified = 0;
|
||||
} else if (hp < history || hp > histptr) {
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
return;
|
||||
}
|
||||
if (sp == NULL)
|
||||
@ -1935,7 +1935,7 @@ x_search_hist(int c)
|
||||
/* add char to pattern */
|
||||
/* overflow check... */
|
||||
if ((size_t)(p - pat) >= sizeof(pat) - 1) {
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
continue;
|
||||
}
|
||||
*p++ = c, *p = '\0';
|
||||
@ -1981,7 +1981,7 @@ x_search(char *pat, int sameline, int offset)
|
||||
return (i);
|
||||
}
|
||||
}
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
x_histp = histptr;
|
||||
return (-1);
|
||||
}
|
||||
@ -2161,11 +2161,11 @@ x_transpose(int c MKSH_A_UNUSED)
|
||||
* to the one they want.
|
||||
*/
|
||||
if (xcp == xbuf) {
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
return (KSTD);
|
||||
} else if (xcp == xep || Flag(FGMACS)) {
|
||||
if (xcp - xbuf == 1) {
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
return (KSTD);
|
||||
}
|
||||
/*
|
||||
@ -2174,12 +2174,12 @@ x_transpose(int c MKSH_A_UNUSED)
|
||||
*/
|
||||
x_bs3(&xcp);
|
||||
if (utf_mbtowc(&tmpa, xcp) == (size_t)-1) {
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
return (KSTD);
|
||||
}
|
||||
x_bs3(&xcp);
|
||||
if (utf_mbtowc(&tmpb, xcp) == (size_t)-1) {
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
return (KSTD);
|
||||
}
|
||||
utf_wctomb(xcp, tmpa);
|
||||
@ -2192,12 +2192,12 @@ x_transpose(int c MKSH_A_UNUSED)
|
||||
* cursor, move cursor position along one.
|
||||
*/
|
||||
if (utf_mbtowc(&tmpa, xcp) == (size_t)-1) {
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
return (KSTD);
|
||||
}
|
||||
x_bs3(&xcp);
|
||||
if (utf_mbtowc(&tmpb, xcp) == (size_t)-1) {
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
return (KSTD);
|
||||
}
|
||||
utf_wctomb(xcp, tmpa);
|
||||
@ -2334,7 +2334,7 @@ x_abort(int c MKSH_A_UNUSED)
|
||||
static int
|
||||
x_error(int c MKSH_A_UNUSED)
|
||||
{
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
return (KSTD);
|
||||
}
|
||||
|
||||
@ -2610,7 +2610,7 @@ x_kill_region(int c MKSH_A_UNUSED)
|
||||
char *xr;
|
||||
|
||||
if (xmp == NULL) {
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
return (KSTD);
|
||||
}
|
||||
if (xmp > xcp) {
|
||||
@ -2632,7 +2632,7 @@ x_xchg_point_mark(int c MKSH_A_UNUSED)
|
||||
char *tmp;
|
||||
|
||||
if (xmp == NULL) {
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
return (KSTD);
|
||||
}
|
||||
tmp = xmp;
|
||||
@ -2710,7 +2710,7 @@ x_expand(int c MKSH_A_UNUSED)
|
||||
&start, &end, &words);
|
||||
|
||||
if (nwords == 0) {
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
return (KSTD);
|
||||
}
|
||||
x_goto(xbuf + start);
|
||||
@ -2720,7 +2720,7 @@ x_expand(int c MKSH_A_UNUSED)
|
||||
while (i < nwords) {
|
||||
if (x_escape(words[i], strlen(words[i]), x_do_ins) < 0 ||
|
||||
(++i < nwords && x_ins(T1space) < 0)) {
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
return (KSTD);
|
||||
}
|
||||
}
|
||||
@ -2744,7 +2744,7 @@ do_complete(
|
||||
&start, &end, &words);
|
||||
/* no match */
|
||||
if (nwords == 0) {
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
return;
|
||||
}
|
||||
if (type == CT_LIST) {
|
||||
@ -2920,7 +2920,7 @@ x_e_putc2(int c)
|
||||
} else
|
||||
x_putc(c);
|
||||
switch (c) {
|
||||
case 7:
|
||||
case KSH_BEL:
|
||||
break;
|
||||
case '\r':
|
||||
case '\n':
|
||||
@ -2960,7 +2960,7 @@ x_e_putc3(const char **cp)
|
||||
x_putc(c);
|
||||
}
|
||||
switch (c) {
|
||||
case 7:
|
||||
case KSH_BEL:
|
||||
break;
|
||||
case '\r':
|
||||
case '\n':
|
||||
@ -3014,7 +3014,7 @@ x_set_arg(int c)
|
||||
}
|
||||
if (c < 0 || first) {
|
||||
x_set_arg_too_big:
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
x_arg = 1;
|
||||
x_arg_defaulted = true;
|
||||
} else {
|
||||
@ -3033,7 +3033,7 @@ x_comment(int c MKSH_A_UNUSED)
|
||||
int ret = x_do_comment(xbuf, xend - xbuf, &len);
|
||||
|
||||
if (ret < 0)
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
else {
|
||||
x_modified();
|
||||
xep = xbuf + len;
|
||||
@ -3084,7 +3084,7 @@ x_edit_line(int c MKSH_A_UNUSED)
|
||||
{
|
||||
if (x_arg_defaulted) {
|
||||
if (xep == xbuf) {
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
return (KSTD);
|
||||
}
|
||||
if (modified) {
|
||||
@ -3139,7 +3139,7 @@ x_prev_histword(int c MKSH_A_UNUSED)
|
||||
last_arg = x_arg_defaulted ? -1 : x_arg;
|
||||
xhp = histptr - (m - 1);
|
||||
if ((xhp < history) || !(cp = *xhp)) {
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
x_modified();
|
||||
return (KSTD);
|
||||
}
|
||||
@ -3227,7 +3227,7 @@ x_fold_case(int c)
|
||||
char *cp = xcp;
|
||||
|
||||
if (cp == xep) {
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
return (KSTD);
|
||||
}
|
||||
while (x_arg--) {
|
||||
@ -5480,7 +5480,7 @@ vi_error(void)
|
||||
{
|
||||
/* Beem out of any macros as soon as an error occurs */
|
||||
vi_macro_reset();
|
||||
x_putc(7);
|
||||
x_putc(KSH_BEL);
|
||||
x_flush();
|
||||
}
|
||||
|
||||
@ -5605,7 +5605,7 @@ x_eval_region(int c MKSH_A_UNUSED)
|
||||
if (cp == NULL) {
|
||||
/* command cannot be parsed */
|
||||
x_eval_region_err:
|
||||
x_e_putc2(7);
|
||||
x_e_putc2(KSH_BEL);
|
||||
x_redraw('\r');
|
||||
return (KSTD);
|
||||
}
|
||||
|
12
misc.c
12
misc.c
@ -30,7 +30,7 @@
|
||||
#include <grp.h>
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.264 2017/04/28 00:38:31 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.265 2017/04/28 00:49:33 tg Exp $");
|
||||
|
||||
#define KSH_CHVT_FLAG
|
||||
#ifdef MKSH_SMALL
|
||||
@ -1146,7 +1146,7 @@ print_value_quoted(struct shf *shf, const char *s)
|
||||
++p;
|
||||
switch (c) {
|
||||
/* see unbksl() in this file for comments */
|
||||
case 7:
|
||||
case KSH_BEL:
|
||||
c = 'a';
|
||||
if (0)
|
||||
/* FALLTHROUGH */
|
||||
@ -2135,13 +2135,7 @@ unbksl(bool cstyle, int (*fg)(void), void (*fp)(int))
|
||||
fc = (*fg)();
|
||||
switch (fc) {
|
||||
case 'a':
|
||||
/*
|
||||
* according to the comments in pdksh, \007 seems
|
||||
* to be more portable than \a (due to HP-UX cc,
|
||||
* Ultrix cc, old pcc, etc.) so we avoid the escape
|
||||
* sequence altogether in mksh and assume ASCII
|
||||
*/
|
||||
wc = 7;
|
||||
wc = KSH_BEL;
|
||||
break;
|
||||
case 'b':
|
||||
wc = '\b';
|
||||
|
25
sh.h
25
sh.h
@ -175,7 +175,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef EXTERN
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.820 2017/04/28 00:38:32 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.821 2017/04/28 00:49:33 tg Exp $");
|
||||
#endif
|
||||
#define MKSH_VERSION "R55 2017/04/27"
|
||||
|
||||
@ -487,6 +487,17 @@ extern int __cdecl setegid(gid_t);
|
||||
#define ISTRIP 0
|
||||
#endif
|
||||
|
||||
#ifdef MKSH_EBCDIC
|
||||
#define KSH_BEL '\a'
|
||||
#else
|
||||
/*
|
||||
* According to the comments in pdksh, \007 seems to be more portable
|
||||
* than \a (HP-UX cc, Ultrix cc, old pcc, etc.) so we avoid the escape
|
||||
* sequence if ASCII can be assumed.
|
||||
*/
|
||||
#define KSH_BEL 7
|
||||
#endif
|
||||
|
||||
|
||||
/* some useful #defines */
|
||||
#ifdef EXTERN
|
||||
@ -508,9 +519,12 @@ extern int __cdecl setegid(gid_t);
|
||||
*
|
||||
* MAGIC can be followed by MAGIC (to escape the octet itself) or one of:
|
||||
* ' !)*,-?[]{|}' 0x80|' !*+?@' (probably… hysteric raisins abound)
|
||||
*
|
||||
* The |0x80 is likely unsafe on EBCDIC :( though the listed chars are
|
||||
* low-bit7 at least on cp1047 so YMMV
|
||||
*/
|
||||
#define MAGIC (7) /* prefix for *?[!{,} during expand */
|
||||
#define ISMAGIC(c) ((unsigned char)(c) == MAGIC)
|
||||
#define MAGIC KSH_BEL /* prefix for *?[!{,} during expand */
|
||||
#define ISMAGIC(c) (ord(c) == ord(MAGIC))
|
||||
|
||||
EXTERN const char *safe_prompt; /* safe prompt if PS1 substitution fails */
|
||||
|
||||
@ -665,6 +679,11 @@ im_sorry_dave(void)
|
||||
#define MKSH_S_NOVI 0
|
||||
#endif
|
||||
|
||||
#ifdef MKSH_EBCDIC
|
||||
#undef MKSH_S_NOVI
|
||||
#define MKSH_S_NOVI 1
|
||||
#endif
|
||||
|
||||
#if defined(MKSH_NOPROSPECTOFWORK) && !defined(MKSH_UNEMPLOYED)
|
||||
#define MKSH_UNEMPLOYED 1
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user