since so many internal things hardcode 'C' locale anyway,

use own is{digit,lower,upper} macros that go via byte ranges

doesn't affect utf-8 hack because these only operate on single bytes anyway
saves 224t
This commit is contained in:
tg 2006-11-10 06:53:27 +00:00
parent b323a22b59
commit 35b30679c7
7 changed files with 37 additions and 46 deletions

34
edit.c
View File

@ -5,7 +5,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.69 2006/11/10 06:45:27 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.70 2006/11/10 06:53:25 tg Exp $");
/* tty driver characters we are interested in */
typedef struct {
@ -3029,7 +3029,7 @@ x_set_arg(int c)
int first = 1;
c &= CHARMASK; /* strip command prefix */
for (; c >= 0 && isdigit((unsigned char)c); c = x_e_getc(), first = 0)
for (; c >= 0 && ksh_isdigit(c); c = x_e_getc(), first = 0)
n = n * 10 + (c - '0');
if (c < 0 || first) {
x_e_putc2(7);
@ -3208,26 +3208,20 @@ x_fold_case(int c)
* a different action than for the rest.
*/
if (cp != xep) {
if (c == 'L') { /* lowercase */
if (isupper((unsigned char)*cp))
*cp = _tolower((unsigned char)*cp);
} else { /* uppercase, capitalise */
if (islower((unsigned char)*cp))
*cp = _toupper((unsigned char)*cp);
}
if (c == 'L') /* lowercase */
*cp = _tolower((unsigned char)*cp);
else /* uppercase, capitalise */
*cp = _toupper((unsigned char)*cp);
cp++;
}
/*
* now for the rest of the word
*/
while (cp != xep && !is_mfs(*cp)) {
if (c == 'U') { /* uppercase */
if (islower((unsigned char)*cp))
*cp = _toupper((unsigned char)*cp);
} else { /* lowercase, capitalise */
if (isupper((unsigned char)*cp))
*cp = _tolower((unsigned char)*cp);
}
if (c == 'U') /* uppercase */
*cp = _toupper((unsigned char)*cp);
else /* lowercase, capitalise */
*cp = _tolower((unsigned char)*cp);
cp++;
}
}
@ -3661,7 +3655,7 @@ vi_hook(int ch)
break;
case VARG1:
if (isdigit((unsigned char)ch))
if (ksh_isdigit(ch))
argc1 = argc1 * 10 + ch - '0';
else {
curcmd[cmdlen++] = ch;
@ -3687,7 +3681,7 @@ vi_hook(int ch)
break;
case VARG2:
if (isdigit((unsigned char)ch))
if (ksh_isdigit(ch))
argc2 = argc2 * 10 + ch - '0';
else {
if (argc1 == 0)
@ -4431,11 +4425,11 @@ vi_cmd(int argcnt, const char *cmd)
return -1;
for (i = 0; i < argcnt; i++) {
p = &es->cbuf[es->cursor];
if (islower((unsigned char)*p)) {
if (ksh_islower((unsigned char)*p)) {
modified = 1;
hnum = hlast;
*p = _toupper((unsigned char)*p);
} else if (isupper((unsigned char)*p)) {
} else if (ksh_isupper((unsigned char)*p)) {
modified = 1;
hnum = hlast;
*p = _tolower((unsigned char)*p);

View File

@ -5,7 +5,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.34 2006/11/10 06:16:24 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.35 2006/11/10 06:53:26 tg Exp $");
int
c_cd(char **wp)
@ -1104,7 +1104,7 @@ c_kill(char **wp)
/* assume old style options if -digits or -UPPERCASE */
if ((p = wp[1]) && *p == '-' && (digit(p[1]) ||
isupper((unsigned char)p[1]))) {
ksh_isupper((unsigned char)p[1]))) {
if (!(t = gettrap(p + 1, true))) {
bi_errorf("bad signal '%s'", p + 1);
return 1;

4
main.c
View File

@ -13,7 +13,7 @@
#include <locale.h>
#endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.58 2006/11/10 06:31:47 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.59 2006/11/10 06:53:26 tg Exp $");
extern char **environ;
@ -954,7 +954,7 @@ check_fd(char *name, int mode, const char **emsgp)
{
int fd, fl;
if (isdigit((unsigned char)name[0]) && !name[1]) {
if (ksh_isdigit(name[0]) && !name[1]) {
fd = name[0] - '0';
if ((fl = fcntl(fd = name[0] - '0', F_GETFL, 0)) < 0) {
if (emsgp)

4
misc.c
View File

@ -3,7 +3,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.35 2006/11/10 06:27:09 tg Exp $\t"
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.36 2006/11/10 06:53:27 tg Exp $\t"
MKSH_SH_H_ID);
#undef USE_CHVT
@ -437,7 +437,7 @@ getn(const char *s, int *ai)
c = *s++;
*ai = i = 0;
do {
if (!isdigit(c))
if (!ksh_isdigit(c))
goto getn_out;
i *= 10;
if (i < *ai)

View File

@ -1,4 +1,4 @@
/** $MirOS: src/bin/mksh/setmode.c,v 1.6 2006/11/09 22:51:49 tg Exp $ */
/** $MirOS: src/bin/mksh/setmode.c,v 1.7 2006/11/10 06:53:27 tg Exp $ */
/** _MirOS: src/lib/libc/gen/setmode.c,v 1.6 2006/11/08 23:18:04 tg Exp $ */
/* $OpenBSD: setmode.c,v 1.17 2005/08/08 08:05:34 espie Exp $ */
/* $NetBSD: setmode.c,v 1.15 1997/02/07 22:21:06 christos Exp $ */
@ -58,7 +58,7 @@
#endif
__SCCSID("@(#)setmode.c 8.2 (Berkeley) 3/25/94");
__RCSID("$MirOS: src/bin/mksh/setmode.c,v 1.6 2006/11/09 22:51:49 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/setmode.c,v 1.7 2006/11/10 06:53:27 tg Exp $");
#define SET_LEN 6 /* initial # of bitcmd struct to malloc */
#define SET_LEN_INCR 4 /* # of bitcmd structs to add as needed */
@ -210,7 +210,7 @@ setmode(const char *p)
* If an absolute number, get it and return; disallow non-octal digits
* or illegal bits.
*/
if (isdigit((unsigned char)*p)) {
if (ksh_isdigit((unsigned char)*p)) {
perml = strtoul(p, &ep, 8);
/* The test on perml will also catch overflow. */
if (*ep != '\0' || (perml & ~(STANDARD_BITS|S_ISTXT))) {

13
sh.h
View File

@ -8,7 +8,7 @@
/* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */
/* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.77 2006/11/10 06:45:28 tg Exp $"
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.78 2006/11/10 06:53:27 tg Exp $"
#define MKSH_VERSION "R29 2006/11/10"
#if HAVE_SYS_PARAM_H
@ -99,12 +99,11 @@
} while (0)
#endif
#ifndef _tolower
#define _tolower(c) (((c) >= 'A') && ((c) <= 'Z') ? (c) - 'A' + 'a' : (c))
#endif
#ifndef _toupper
#define _toupper(c) (((c) >= 'a') && ((c) <= 'z') ? (c) - 'a' + 'A' : (c))
#endif
#define ksh_isdigit(c) (((c) >= '0') && ((c) <= '9'))
#define ksh_islower(c) (((c) >= 'a') && ((c) <= 'z'))
#define ksh_isupper(c) (((c) >= 'A') && ((c) <= 'Z'))
#define ksh_tolower(c) (((c) >= 'A') && ((c) <= 'Z') ? (c) - 'A' + 'a' : (c))
#define ksh_toupper(c) (((c) >= 'a') && ((c) <= 'z') ? (c) - 'a' + 'A' : (c))
#ifndef S_ISTXT
#define S_ISTXT 0001000

18
var.c
View File

@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.28 2006/11/10 06:45:28 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.29 2006/11/10 06:53:27 tg Exp $");
/*
* Variables
@ -439,12 +439,12 @@ getint(struct tbl *vp, long int *nump, bool arith)
num = 0;
have_base = 1;
} else if (letnum(c)) {
if (isdigit(c))
if (ksh_isdigit(c))
c -= '0';
else if (islower(c))
c -= 'a' - 10; /* todo: assumes ascii */
else if (isupper(c))
c -= 'A' - 10; /* todo: assumes ascii */
else if (ksh_islower(c))
c -= 'a' - 10;
else if (ksh_isupper(c))
c -= 'A' - 10;
else
c = -1; /* _: force error */
if (c < 0 || c >= base)
@ -533,12 +533,10 @@ formatstr(struct tbl *vp, const char *s)
if (vp->flag & UCASEV_AL) {
for (q = p; *q; q++)
if (islower((unsigned char)*q))
*q = _toupper((unsigned char)*q);
*q = _toupper((unsigned char)*q);
} else if (vp->flag & LCASEV) {
for (q = p; *q; q++)
if (isupper((unsigned char)*q))
*q = _tolower((unsigned char)*q);
*q = _tolower((unsigned char)*q);
}
return p;