• do not use __typeof__ even if we have statements-as-expressions, to

please pcc, prompted for by Anders “ragge” Magnusson, problem spotted
  originally by Adam “replaced” Hoka
  ⇒ rewrote x_bs2() and utf_backch() into a combined x_bs3() function,
    since these are never used in any other way
• whitespace cleanup, while here
This commit is contained in:
tg 2008-10-26 20:59:40 +00:00
parent 00cbdc2d2e
commit 8230c9d8ae
3 changed files with 113 additions and 129 deletions

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.235 2008/10/24 21:35:42 tg Exp $ # $MirOS: src/bin/mksh/check.t,v 1.236 2008/10/26 20:59:39 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -7,7 +7,7 @@
# http://www.research.att.com/~gsf/public/ifs.sh # http://www.research.att.com/~gsf/public/ifs.sh
expected-stdout: expected-stdout:
@(#)MIRBSD KSH R36 2008/10/24 @(#)MIRBSD KSH R36 2008/10/26
description: description:
Check version of shell. Check version of shell.
stdin: stdin:

62
edit.c
View File

@ -5,7 +5,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.139 2008/10/19 20:15:43 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/edit.c,v 1.140 2008/10/26 20:59:39 tg Exp $");
/* tty driver characters we are interested in */ /* tty driver characters we are interested in */
typedef struct { typedef struct {
@ -742,30 +742,6 @@ x_escape(const char *s, size_t len, int (*putbuf_func)(const char *, size_t))
/* UTF-8 hack: high-level functions */ /* UTF-8 hack: high-level functions */
#if HAVE_EXPSTMT
#define utf_backch(c) (!Flag(FUTFHACK) ? (c) - 1 : ({ \
unsigned char *utf_backch_cp = (unsigned char *)(c); \
--utf_backch_cp; \
while ((*utf_backch_cp >= 0x80) && \
(*utf_backch_cp < 0xC0)) \
--utf_backch_cp; \
(__typeof__ (c))utf_backch_cp; \
}))
#else
#define utf_backch(c) (!Flag(FUTFHACK) ? (c) - 1 : \
(c) + (ptrdiff_t)(utf_backch_((unsigned char *)c) - \
((unsigned char *)(c))))
static unsigned char *utf_backch_(unsigned char *);
static unsigned char *
utf_backch_(unsigned char *utf_backch_cp)
{
--utf_backch_cp;
while ((*utf_backch_cp >= 0x80) && (*utf_backch_cp < 0xC0))
--utf_backch_cp;
return (utf_backch_cp);
}
#endif
int int
utf_widthadj(const char *src, const char **dst) utf_widthadj(const char *src, const char **dst)
{ {
@ -1106,7 +1082,7 @@ static void x_delete(int, int);
static int x_bword(void); static int x_bword(void);
static int x_fword(int); static int x_fword(int);
static void x_goto(char *); static void x_goto(char *);
static void x_bs2(char *); static void x_bs3(char **);
static int x_size_str(char *); static int x_size_str(char *);
static int x_size2(char *, char **); static int x_size2(char *, char **);
static void x_zots(char *); static void x_zots(char *);
@ -1642,7 +1618,7 @@ x_ins(const char *s)
/* no */ /* no */
cp = xlp; cp = xlp;
while (cp > xcp) while (cp > xcp)
x_bs2(cp = utf_backch(cp)); x_bs3(&cp);
} }
if (xlp == xep - 1) if (xlp == xep - 1)
x_redraw(xx_cols); x_redraw(xx_cols);
@ -1750,8 +1726,9 @@ 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; ) cp = x_lastcp();
x_bs2(cp = utf_backch(cp)); while (cp > xcp)
x_bs3(&cp);
x_modified(); x_modified();
return; return;
@ -1846,7 +1823,7 @@ x_goto(char *cp)
x_adjust(); x_adjust();
} else if (cp < xcp) { /* move back */ } else if (cp < xcp) { /* move back */
while (cp < xcp) while (cp < xcp)
x_bs2(xcp = utf_backch(xcp)); x_bs3(&xcp);
} else if (cp > xcp) { /* move forward */ } else if (cp > xcp) { /* move forward */
while (cp > xcp) while (cp > xcp)
x_zotc3(&xcp); x_zotc3(&xcp);
@ -1854,11 +1831,16 @@ x_goto(char *cp)
} }
static void static void
x_bs2(char *cp) x_bs3(char **p)
{ {
int i; int i;
i = x_size2(cp, NULL); (*p)--;
if (Flag(FUTFHACK))
while (((unsigned char)**p & 0xC0) == 0x80)
(*p)--;
i = x_size2(*p, NULL);
while (i--) while (i--)
x_e_putc2('\b'); x_e_putc2('\b');
} }
@ -2370,8 +2352,9 @@ x_redraw(int limit)
while (j--) while (j--)
x_e_putc2('\b'); x_e_putc2('\b');
} }
for (cp = xlp; cp > xcp; ) cp = xlp;
x_bs2(cp = utf_backch(cp)); while (cp > xcp)
x_bs3(&cp);
x_adj_ok = 1; x_adj_ok = 1;
return; return;
} }
@ -2405,12 +2388,12 @@ x_transpose(int c __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_bs2(xcp = utf_backch(xcp)); x_bs3(&xcp);
if (utf_mbtowc(&tmpa, xcp) == (size_t)-1) { if (utf_mbtowc(&tmpa, xcp) == (size_t)-1) {
x_e_putc2(7); x_e_putc2(7);
return KSTD; return KSTD;
} }
x_bs2(xcp = utf_backch(xcp)); x_bs3(&xcp);
if (utf_mbtowc(&tmpb, xcp) == (size_t)-1) { if (utf_mbtowc(&tmpb, xcp) == (size_t)-1) {
x_e_putc2(7); x_e_putc2(7);
return KSTD; return KSTD;
@ -2427,7 +2410,7 @@ x_transpose(int c __unused)
x_e_putc2(7); x_e_putc2(7);
return KSTD; return KSTD;
} }
x_bs2(xcp = utf_backch(xcp)); x_bs3(&xcp);
if (utf_mbtowc(&tmpb, xcp) == (size_t)-1) { if (utf_mbtowc(&tmpb, xcp) == (size_t)-1) {
x_e_putc2(7); x_e_putc2(7);
return KSTD; return KSTD;
@ -3327,8 +3310,9 @@ x_fold_case(int c)
* edit buffer that will be the last displayed on the * edit buffer that will be the last displayed on the
* screen. The sequence: * screen. The sequence:
* *
* for (cp = x_lastcp(); cp > xcp; ) * cp = x_lastcp();
* x_bs2(cp = utf_backch(cp)); * while (cp > xcp)
* x_bs3(&cp);
* *
* Will position the cursor correctly on the screen. * Will position the cursor correctly on the screen.
* *

4
sh.h
View File

@ -100,9 +100,9 @@
#define __SCCSID(x) __IDSTRING(sccsid,x) #define __SCCSID(x) __IDSTRING(sccsid,x)
#ifdef EXTERN #ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.245 2008/10/24 21:35:43 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/sh.h,v 1.246 2008/10/26 20:59:40 tg Exp $");
#endif #endif
#define MKSH_VERSION "R36 2008/10/24" #define MKSH_VERSION "R36 2008/10/26"
#ifndef MKSH_INCLUDES_ONLY #ifndef MKSH_INCLUDES_ONLY