split utf_ptradjx into utf_ptradj function (to save space) and

self-assignment macro; remove some uses of the macro in favour
of foo += utf_ptradj(foo)
This commit is contained in:
tg 2009-05-16 15:09:07 +00:00
parent 36f737f5cb
commit 8a7223d4cd
3 changed files with 20 additions and 13 deletions

18
edit.c
View File

@ -5,7 +5,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.162 2009/05/16 14:34:57 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.163 2009/05/16 15:09:06 tg Exp $");
/* tty driver characters we are interested in */
typedef struct {
@ -763,6 +763,18 @@ utf_skipcols(const char *p, int cols)
return (p);
}
size_t
utf_ptradj(const char *src)
{
register size_t n;
if (!UTFMODE ||
*(const unsigned char *)(src) < 0xC2 ||
(n = utf_mbtowc(NULL, src)) == (size_t)-1)
n = 1;
return (n);
}
/* UTF-8 hack: low-level functions */
/* --- begin of wcwidth.c excerpt --- */
@ -1738,7 +1750,7 @@ x_bword(void)
}
x_goto(cp);
for (cp = xcp; cp < (xcp + nb); ++nc)
utf_ptradjx(cp, cp);
cp += utf_ptradj(cp);
return nc;
}
@ -1759,7 +1771,7 @@ x_fword(int move)
cp++;
}
for (cp2 = xcp; cp2 < cp; ++nc)
utf_ptradjx(cp2, cp2);
cp2 += utf_ptradj(cp2);
if (move)
x_goto(cp);
return nc;

4
expr.c
View File

@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.24 2009/04/07 18:41:35 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.25 2009/05/16 15:09:07 tg Exp $");
/* The order of these enums is constrained by the order of opinfo[] */
enum token {
@ -505,7 +505,7 @@ exprtoken(Expr_state *es)
es->tok = VAR;
} else if (c == '1' && cp[1] == '#') {
cp += 2;
utf_ptradjx(cp, cp);
cp += utf_ptradj(cp);
strndupx(tvar, es->tokp, cp - es->tokp, ATEMP);
goto process_tvar;
} else if (ksh_isdigit(c)) {

11
sh.h
View File

@ -102,7 +102,7 @@
#define __SCCSID(x) __IDSTRING(sccsid,x)
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.294 2009/05/16 14:19:23 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.295 2009/05/16 15:09:07 tg Exp $");
#endif
#define MKSH_VERSION "R37 2009/05/16"
@ -370,13 +370,7 @@ char *ucstrstr(char *, const char *);
#define strnul(s) ((s) + strlen(s))
#define utf_ptradjx(src, dst) do { \
size_t utf_ptradjx_len; \
\
if (!UTFMODE || \
*(const unsigned char *)(src) < 0xC2 || \
(utf_ptradjx_len = utf_mbtowc(NULL, (src))) == (size_t)-1) \
utf_ptradjx_len = 1; \
(dst) = (src) + utf_ptradjx_len; \
(dst) = (src) + utf_ptradj(src); \
} while (/* CONSTCOND */ 0)
#ifdef MKSH_SMALL
@ -1318,6 +1312,7 @@ size_t utf_wctomb(char *, unsigned int);
int utf_widthadj(const char *, const char **);
int utf_mbswidth(const char *);
const char *utf_skipcols(const char *, int);
size_t utf_ptradj(const char *);
/* eval.c */
char *substitute(const char *, int);
char **eval(const char **, int);