* convert most of the interna of edit.c to unsigned where it's

important for the signedness of the target, to enable using
  high-bit7 characters on the command line (eg. in UTF-8 locales)
* make emacs-usemeta and vi-show8 equivalent and document that
  in the manual page (i.e. beware if you're in a latin1 locale)
* do not reference SUSv3 (helps GNU groff), write \&" out instead
This commit is contained in:
tg 2006-02-16 11:48:32 +00:00
parent 9d6fc21153
commit 9e838e765c
2 changed files with 48 additions and 42 deletions

78
edit.c
View File

@ -5,7 +5,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.19 2006/01/30 12:37:21 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/edit.c,v 1.20 2006/02/16 11:48:31 tg Exp $");
/* tty driver characters we are interested in */ /* tty driver characters we are interested in */
typedef struct { typedef struct {
@ -28,7 +28,7 @@ X_chars edchars;
int x_getc(void); int x_getc(void);
void x_flush(void); void x_flush(void);
void x_putc(int); void x_putc(int);
void x_puts(const char *); void x_puts(const u_char *);
bool x_mode(bool); bool x_mode(bool);
int promptlen(const char *, const char **); int promptlen(const char *, const char **);
int x_do_comment(char *, int, int *); int x_do_comment(char *, int, int *);
@ -156,7 +156,7 @@ x_putc(int c)
} }
void void
x_puts(const char *s) x_puts(const u_char *s)
{ {
while (*s != 0) while (*s != 0)
shf_putc(*s++, shl_out); shf_putc(*s++, shl_out);
@ -870,7 +870,7 @@ static Area aedit;
#define AEDIT &aedit /* area for kill ring and macro defns */ #define AEDIT &aedit /* area for kill ring and macro defns */
#define MKCTRL(x) ((x) == '?' ? 0x7F : (x) & 0x1F) /* ASCII */ #define MKCTRL(x) ((x) == '?' ? 0x7F : (x) & 0x1F) /* ASCII */
#define UNCTRL(x) ((x) == 0x7F ? '?' : (x) | 0x40) /* ASCII */ #define UNCTRL(x) ((x) ^ 0x40) /* ASCII */
#define META(x) ((x) & 0x7f) #define META(x) ((x) & 0x7f)
#define ISMETA(x) (Flag(FEMACSUSEMETA) && ((x) & 0x80)) #define ISMETA(x) (Flag(FEMACSUSEMETA) && ((x) & 0x80))
@ -973,7 +973,7 @@ static void x_goto(char *);
static void x_bs(int); static void x_bs(int);
static int x_size_str(char *); static int x_size_str(char *);
static int x_size(int); static int x_size(int);
static void x_zots(char *); static void x_zots(u_char *);
static void x_zotc(int); static void x_zotc(int);
static void x_load_hist(char **); static void x_load_hist(char **);
static int x_search(char *, int, int); static int x_search(char *, int, int);
@ -1368,7 +1368,7 @@ x_do_ins(const char *cp, int len)
static int static int
x_ins(char *s) x_ins(char *s)
{ {
char *cp = xcp; u_char *cp = (u_char *)xcp;
int adj = x_adj_done; int adj = x_adj_done;
if (x_do_ins(s, strlen(s)) < 0) if (x_do_ins(s, strlen(s)) < 0)
@ -1383,7 +1383,7 @@ x_ins(char *s)
x_zots(cp); x_zots(cp);
if (adj == x_adj_done) { /* has x_adjust() been called? */ if (adj == x_adj_done) { /* has x_adjust() been called? */
/* no */ /* no */
for (cp = xlp; cp > xcp; ) for (cp = (u_char *)xlp; cp > (u_char *)xcp; )
x_bs(*--cp); x_bs(*--cp);
} }
x_adj_ok = 1; x_adj_ok = 1;
@ -1439,7 +1439,7 @@ static void
x_delete(int nc, int push) x_delete(int nc, int push)
{ {
int i, j; int i, j;
char *cp; u_char *cp;
if (nc == 0) if (nc == 0)
return; return;
@ -1456,15 +1456,15 @@ x_delete(int nc, int push)
x_push(nc); x_push(nc);
xep -= nc; xep -= nc;
cp = xcp; cp = (u_char *)xcp;
j = 0; j = 0;
i = nc; i = nc;
while (i--) { while (i--) {
j += x_size(*cp++); j += x_size(*(u_char *)cp++);
} }
memmove(xcp, xcp + nc, xep - xcp + 1); /* Copies the null */ memmove(xcp, xcp + nc, xep - xcp + 1); /* Copies the null */
x_adj_ok = 0; /* don't redraw */ x_adj_ok = 0; /* don't redraw */
x_zots(xcp); x_zots((u_char *)xcp);
/* /*
* if we are already filling the line, * if we are already filling the line,
* there is no need to ' ','\b'. * there is no need to ' ','\b'.
@ -1482,7 +1482,7 @@ x_delete(int nc, int push)
/*x_goto(xcp);*/ /*x_goto(xcp);*/
x_adj_ok = 1; x_adj_ok = 1;
xlp_valid = false; xlp_valid = false;
for (cp = x_lastcp(); cp > xcp;) for (cp = (u_char *)x_lastcp(); cp > (u_char *)xcp; )
x_bs(*--cp); x_bs(*--cp);
return; return;
@ -1571,11 +1571,15 @@ x_goto(char *cp)
xcp = cp; xcp = cp;
x_adjust(); x_adjust();
} else if (cp < xcp) { /* move back */ } else if (cp < xcp) { /* move back */
while (cp < xcp) u_char *uxcp = (u_char *)xcp;
x_bs(*--xcp); while ((u_char *)cp < uxcp)
x_bs(*--uxcp);
xcp = (char *)uxcp;
} else if (cp > xcp) { /* move forward */ } else if (cp > xcp) { /* move forward */
while (cp > xcp) u_char *uxcp = (u_char *)xcp;
x_zotc(*xcp++); while ((u_char *)cp > uxcp)
x_zotc(*uxcp++);
xcp = (char *)uxcp;
} }
} }
@ -1594,7 +1598,7 @@ x_size_str(char *cp)
{ {
int size = 0; int size = 0;
while (*cp) while (*cp)
size += x_size(*cp++); size += x_size(*(u_char *)cp++);
return size; return size;
} }
@ -1603,18 +1607,18 @@ x_size(int c)
{ {
if (c == '\t') if (c == '\t')
return 4; /* Kludge, tabs are always four spaces. */ return 4; /* Kludge, tabs are always four spaces. */
if (iscntrl(c)) /* control char */ if (c < ' ' || c == 0x7f)
return 2; return 2; /* control u_char */
return 1; return 1;
} }
static void static void
x_zots(char *str) x_zots(u_char *str)
{ {
int adj = x_adj_done; int adj = x_adj_done;
x_lastcp(); x_lastcp();
while (*str && str < xlp && adj == x_adj_done) while (*str && str < (u_char *)xlp && adj == x_adj_done)
x_zotc(*str++); x_zotc(*str++);
} }
@ -1624,7 +1628,7 @@ x_zotc(int c)
if (c == '\t') { if (c == '\t') {
/* Kludge, tabs are always four spaces. */ /* Kludge, tabs are always four spaces. */
x_e_puts(" "); x_e_puts(" ");
} else if (iscntrl(c)) { } else if (c < ' ' || c == 0x7f) {
x_e_putc('^'); x_e_putc('^');
x_e_putc(UNCTRL(c)); x_e_putc(UNCTRL(c));
} else } else
@ -1944,7 +1948,7 @@ static void
x_redraw(int limit) x_redraw(int limit)
{ {
int i, j; int i, j;
char *cp; u_char *cp;
x_adj_ok = 0; x_adj_ok = 0;
if (limit == -1) if (limit == -1)
@ -1958,8 +1962,8 @@ x_redraw(int limit)
} }
x_displen = xx_cols - 2 - x_col; x_displen = xx_cols - 2 - x_col;
xlp_valid = false; xlp_valid = false;
cp = x_lastcp(); cp = (u_char *)x_lastcp();
x_zots(xbp); x_zots((u_char *)xbp);
if (xbp != xbuf || xep > xlp) if (xbp != xbuf || xep > xlp)
limit = xx_cols; limit = xx_cols;
if (limit >= 0) { if (limit >= 0) {
@ -1983,7 +1987,7 @@ x_redraw(int limit)
while (j--) while (j--)
x_e_putc('\b'); x_e_putc('\b');
} }
for (cp = xlp; cp > xcp; ) for (cp = (u_char *)xlp; cp > (u_char *)xcp; )
x_bs(*--cp); x_bs(*--cp);
x_adj_ok = 1; x_adj_ok = 1;
return; return;
@ -2018,10 +2022,10 @@ x_transpose(int c __attribute__((unused)))
/* Gosling/Unipress emacs style: Swap two characters before the /* Gosling/Unipress emacs style: Swap two characters before the
* cursor, do not change cursor position * cursor, do not change cursor position
*/ */
x_bs(xcp[-1]); x_bs(((u_char *)xcp)[-1]);
x_bs(xcp[-2]); x_bs(((u_char *)xcp)[-2]);
x_zotc(xcp[-1]); x_zotc(((u_char *)xcp)[-1]);
x_zotc(xcp[-2]); x_zotc(((u_char *)xcp)[-2]);
tmp = xcp[-1]; tmp = xcp[-1];
xcp[-1] = xcp[-2]; xcp[-1] = xcp[-2];
xcp[-2] = tmp; xcp[-2] = tmp;
@ -2029,13 +2033,13 @@ x_transpose(int c __attribute__((unused)))
/* GNU emacs style: Swap the characters before and under the /* GNU emacs style: Swap the characters before and under the
* cursor, move cursor position along one. * cursor, move cursor position along one.
*/ */
x_bs(xcp[-1]); x_bs(((u_char *)xcp)[-1]);
x_zotc(xcp[0]); x_zotc(((u_char *)xcp)[0]);
x_zotc(xcp[-1]); x_zotc(((u_char *)xcp)[-1]);
tmp = xcp[-1]; tmp = xcp[-1];
xcp[-1] = xcp[0]; xcp[-1] = xcp[0];
xcp[0] = tmp; xcp[0] = tmp;
x_bs(xcp[0]); x_bs(((u_char *)xcp)[0]);
x_goto(xcp + 1); x_goto(xcp + 1);
} }
return KSTD; return KSTD;
@ -2212,7 +2216,7 @@ x_mapout(int c)
static char buf[8]; static char buf[8];
char *p = buf; char *p = buf;
if (iscntrl(c)) { if (c < ' ' || c == 0x7f) {
*p++ = '^'; *p++ = '^';
*p++ = UNCTRL(c); *p++ = UNCTRL(c);
} else } else
@ -2868,7 +2872,7 @@ x_lastcp(void)
if (!xlp_valid) { if (!xlp_valid) {
for (i = 0, rcp = xbp; rcp < xep && i < x_displen; rcp++) for (i = 0, rcp = xbp; rcp < xep && i < x_displen; rcp++)
i += x_size(*rcp); i += x_size(*(u_char *)rcp);
xlp = rcp; xlp = rcp;
} }
xlp_valid = true; xlp_valid = true;
@ -4932,7 +4936,7 @@ static void
x_vi_zotc(int c) x_vi_zotc(int c)
{ {
if (Flag(FVISHOW8) && (c & 0x80)) { if (Flag(FVISHOW8) && (c & 0x80)) {
x_puts("M-"); x_puts((u_char *)"M-");
c &= 0x7f; c &= 0x7f;
} }
if (c < ' ' || c == 0x7f) { if (c < ' ' || c == 0x7f) {

12
mksh.1
View File

@ -1,4 +1,4 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.29 2006/01/30 12:37:23 tg Exp $ .\" $MirOS: src/bin/mksh/mksh.1,v 1.30 2006/02/16 11:48:32 tg Exp $
.\" $OpenBSD: ksh.1,v 1.109 2005/12/06 20:40:02 jmc Exp $ .\" $OpenBSD: ksh.1,v 1.109 2005/12/06 20:40:02 jmc Exp $
.\" $OpenBSD: sh.1tbl,v 1.53 2004/12/10 01:56:56 jaredy Exp $ .\" $OpenBSD: sh.1tbl,v 1.53 2004/12/10 01:56:56 jaredy Exp $
.\" .\"
@ -1858,9 +1858,9 @@ escapes for
.Ql ` , .Ql ` ,
.Ql \e , .Ql \e ,
and and
.Ql \enewline . .Ql \enewline ,
Handling of double quotes follows but not for
.St -susv3 . .Ql \&" .
If multiple here documents are used on the same command line, they are saved in If multiple here documents are used on the same command line, they are saved in
order. order.
.It \*(Lt\*(Lt- Ar marker .It \*(Lt\*(Lt- Ar marker
@ -3261,6 +3261,8 @@ Enable BRL emacs-like command-line editing (interactive shells only); see
.It Ic emacs-usemeta .It Ic emacs-usemeta
In emacs command-line editing, use the 8th bit as meta (^[) prefix. In emacs command-line editing, use the 8th bit as meta (^[) prefix.
This is disabled by default, so you can use high-bit7 characters in pathnames. This is disabled by default, so you can use high-bit7 characters in pathnames.
If this option is not set, characters in the range 128\-160 are printed as is,
which may cause problems in some locales.
.It Ic gmacs .It Ic gmacs
Enable gmacs-like command-line editing (interactive shells only). Enable gmacs-like command-line editing (interactive shells only).
Currently identical to emacs editing except that transpose (^T) acts slightly Currently identical to emacs editing except that transpose (^T) acts slightly
@ -3334,7 +3336,7 @@ In vi command-line editing, do command and file name completion when escape
Prefix characters with the eighth bit set with Prefix characters with the eighth bit set with
.Sq M- . .Sq M- .
If this option is not set, characters in the range 128\-160 are printed as is, If this option is not set, characters in the range 128\-160 are printed as is,
which may cause problems. which may cause problems in some locales.
.It Ic vi-tabcomplete .It Ic vi-tabcomplete
In vi command-line editing, do command and file name completion when tab (^I) In vi command-line editing, do command and file name completion when tab (^I)
is entered in insert mode. is entered in insert mode.