* use only macros for ctype stuff any more

XXX one of these uses a gcc extension, ok for now tho
* don't include <ctype.h> any more at all
* don't try nl_langinfo in small mode, just check locale

saves 171 .text, 4 .data, 256 .bss, 1 import
This commit is contained in:
tg 2006-11-10 07:18:58 +00:00
parent 35b30679c7
commit feb7dddd44
7 changed files with 68 additions and 49 deletions

View File

@ -1,5 +1,5 @@
#!/bin/sh
# $MirOS: src/bin/mksh/Build.sh,v 1.74 2006/11/09 23:09:05 tg Exp $
# $MirOS: src/bin/mksh/Build.sh,v 1.75 2006/11/10 07:18:56 tg Exp $
#-
# Environment: CC, CFLAGS, CPPFLAGS, LDFLAGS, LIBS, NROFF
@ -18,8 +18,6 @@ ac_testn()
{
f=$1
fu=`upper $f`
test 0 = "$HAVE_$fu" && return
test 1 = "$HAVE_$fu" && return
if test x"$2" = x""; then
ft=1
else
@ -28,9 +26,21 @@ ac_testn()
fi
fd=$3
test x"$fd" = x"" && fd=$f
eval fv=\$HAVE_$fu
if test 0 = "$fv"; then
$e "==> $fd... no (cached)"
return
fi
if test 1 = "$fv"; then
$e "==> $fd... yes (cached)"
return
fi
if test 0 = "$ft"; then
eval HAVE_$fu=$2
$e "==> $fd... not checked ($2)"
fv=$2
eval HAVE_$fu=$fv
test 0 = "$fv" && fv=no
test 1 = "$fv" && fv=yes
$e "==> $fd... $fv (implied)"
return
fi
$e ... $fd
@ -190,6 +200,8 @@ if test 0 = $HAVE_MKSH_FULL; then
int main(void) { return (0); }
EOF
test 1 = $HAVE_CAN_FNOINLINE || CFLAGS=$save_CFLAGS
HAVE_LANGINFO_CODESET=0
fi
save_CFLAGS=$CFLAGS

63
edit.c
View File

@ -5,7 +5,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.70 2006/11/10 06:53:25 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.71 2006/11/10 07:18:56 tg Exp $");
/* tty driver characters we are interested in */
typedef struct {
@ -497,7 +497,7 @@ x_locate_word(const char *buf, int buflen, int pos, int *startp,
int iscmd;
/* Figure out if this is a command */
for (p = start - 1; p >= 0 && isspace((unsigned char)buf[p]);
for (p = start - 1; p >= 0 && ksh_isspace(buf[p]);
p--)
;
iscmd = p < 0 || strchr(";|&()`", buf[p]);
@ -1049,8 +1049,9 @@ struct x_defbindings {
/* Separator for completion */
#define is_cfs(c) ((c) == ' ' || (c) == '\t' || (c) == '"' || (c) == '\'')
#define is_mfs(c) (!(isalnum((unsigned char)(c)) || (c) == '_' || \
(c) == '$')) /* Separator for motion */
/* Separator for motion */
#define is_mfs(c) (!(ksh_isdigit(c) || ksh_islower(c) || \
ksh_isupper(c) || (c) == '_' || (c) == '$'))
#define CHARMASK 0xFF /* 8-bit character mask */
#define X_NTABS 3 /* normal, meta1, meta2 */
@ -3209,9 +3210,9 @@ x_fold_case(int c)
*/
if (cp != xep) {
if (c == 'L') /* lowercase */
*cp = _tolower((unsigned char)*cp);
*cp = ksh_tolower(*cp);
else /* uppercase, capitalise */
*cp = _toupper((unsigned char)*cp);
*cp = ksh_toupper(*cp);
cp++;
}
/*
@ -3219,9 +3220,9 @@ x_fold_case(int c)
*/
while (cp != xep && !is_mfs(*cp)) {
if (c == 'U') /* uppercase */
*cp = _toupper((unsigned char)*cp);
*cp = ksh_toupper(*cp);
else /* lowercase, capitalise */
*cp = _tolower((unsigned char)*cp);
*cp = ksh_tolower(*cp);
cp++;
}
}
@ -3744,9 +3745,9 @@ vi_hook(int ch)
int i;
int n = srchlen;
while (n > 0 && isspace((unsigned char)locpat[n - 1]))
while (n > 0 && ksh_isspace(locpat[n - 1]))
n--;
while (n > 0 && !isspace((unsigned char)locpat[n - 1]))
while (n > 0 && !ksh_isspace(locpat[n - 1]))
n--;
for (i = srchlen; --i >= n; )
es->linelen -= char_len((unsigned char)locpat[i]);
@ -4116,8 +4117,8 @@ vi_cmd(int argcnt, const char *cmd)
return -1;
if (*cmd == 'c' &&
(cmd[1] == 'w' || cmd[1] == 'W') &&
!isspace((unsigned char)(es->cbuf[es->cursor]))) {
while (isspace((unsigned char)(es->cbuf[--ncursor])))
!ksh_isspace(es->cbuf[es->cursor])) {
while (ksh_isspace(es->cbuf[--ncursor]))
;
ncursor++;
}
@ -4368,7 +4369,7 @@ vi_cmd(int argcnt, const char *cmd)
if (histnum(-1) < 0)
return -1;
p = *histpos();
#define issp(c) (isspace((unsigned char)(c)) || (c) == '\n')
#define issp(c) (ksh_isspace(c) || (c) == '\n')
if (argcnt) {
while (*p && issp(*p))
p++;
@ -4425,14 +4426,14 @@ vi_cmd(int argcnt, const char *cmd)
return -1;
for (i = 0; i < argcnt; i++) {
p = &es->cbuf[es->cursor];
if (ksh_islower((unsigned char)*p)) {
if (ksh_islower(*p)) {
modified = 1;
hnum = hlast;
*p = _toupper((unsigned char)*p);
} else if (ksh_isupper((unsigned char)*p)) {
*p = ksh_toupper(*p);
} else if (ksh_isupper(*p)) {
modified = 1;
hnum = hlast;
*p = _tolower((unsigned char)*p);
*p = ksh_tolower(*p);
}
if (es->cursor < es->linelen - 1)
es->cursor++;
@ -4577,7 +4578,7 @@ domove(int argcnt, const char *cmd, int sub)
case '^':
ncursor = 0;
while (ncursor < es->linelen - 1 &&
isspace((unsigned char)(es->cbuf[ncursor])))
ksh_isspace(es->cbuf[ncursor]))
ncursor++;
break;
@ -4844,12 +4845,12 @@ forwword(int argcnt)
while (is_wordch(es->cbuf[ncursor]) &&
ncursor < es->linelen)
ncursor++;
else if (!isspace((unsigned char)(es->cbuf[ncursor])))
else if (!ksh_isspace(es->cbuf[ncursor]))
while (!is_wordch(es->cbuf[ncursor]) &&
!isspace((unsigned char)(es->cbuf[ncursor])) &&
!ksh_isspace(es->cbuf[ncursor]) &&
ncursor < es->linelen)
ncursor++;
while (isspace((unsigned char)(es->cbuf[ncursor])) &&
while (ksh_isspace(es->cbuf[ncursor]) &&
ncursor < es->linelen)
ncursor++;
}
@ -4863,7 +4864,7 @@ backword(int argcnt)
ncursor = es->cursor;
while (ncursor > 0 && argcnt--) {
while (--ncursor > 0 && isspace((unsigned char)(es->cbuf[ncursor])))
while (--ncursor > 0 && ksh_isspace(es->cbuf[ncursor]))
;
if (ncursor > 0) {
if (is_wordch(es->cbuf[ncursor]))
@ -4873,7 +4874,7 @@ backword(int argcnt)
else
while (--ncursor >= 0 &&
!is_wordch(es->cbuf[ncursor]) &&
!isspace((unsigned char)(es->cbuf[ncursor])))
!ksh_isspace(es->cbuf[ncursor]))
;
ncursor++;
}
@ -4889,7 +4890,7 @@ endword(int argcnt)
ncursor = es->cursor;
while (ncursor < es->linelen && argcnt--) {
while (++ncursor < es->linelen - 1 &&
isspace((unsigned char)(es->cbuf[ncursor])))
ksh_isspace(es->cbuf[ncursor]))
;
if (ncursor < es->linelen - 1) {
if (is_wordch(es->cbuf[ncursor]))
@ -4899,7 +4900,7 @@ endword(int argcnt)
else
while (++ncursor < es->linelen &&
!is_wordch(es->cbuf[ncursor]) &&
!isspace((unsigned char)(es->cbuf[ncursor])))
!ksh_isspace(es->cbuf[ncursor]))
;
ncursor--;
}
@ -4914,10 +4915,10 @@ Forwword(int argcnt)
ncursor = es->cursor;
while (ncursor < es->linelen && argcnt--) {
while (!isspace((unsigned char)(es->cbuf[ncursor])) &&
while (!ksh_isspace(es->cbuf[ncursor]) &&
ncursor < es->linelen)
ncursor++;
while (isspace((unsigned char)(es->cbuf[ncursor])) &&
while (ksh_isspace(es->cbuf[ncursor]) &&
ncursor < es->linelen)
ncursor++;
}
@ -4932,10 +4933,10 @@ Backword(int argcnt)
ncursor = es->cursor;
while (ncursor > 0 && argcnt--) {
while (--ncursor >= 0 &&
isspace((unsigned char)(es->cbuf[ncursor])))
ksh_isspace(es->cbuf[ncursor]))
;
while (ncursor >= 0 &&
!isspace((unsigned char)(es->cbuf[ncursor])))
!ksh_isspace(es->cbuf[ncursor]))
ncursor--;
ncursor++;
}
@ -4950,11 +4951,11 @@ Endword(int argcnt)
ncursor = es->cursor;
while (ncursor < es->linelen - 1 && argcnt--) {
while (++ncursor < es->linelen - 1 &&
isspace((unsigned char)(es->cbuf[ncursor])))
ksh_isspace(es->cbuf[ncursor]))
;
if (ncursor < es->linelen - 1) {
while (++ncursor < es->linelen &&
!isspace((unsigned char)(es->cbuf[ncursor])))
!ksh_isspace(es->cbuf[ncursor]))
;
ncursor--;
}

4
expr.c
View File

@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.4 2006/05/10 18:54:10 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.5 2006/11/10 07:18:57 tg Exp $");
/* The order of these enums is constrained by the order of opinfo[] */
enum token {
@ -448,7 +448,7 @@ token(Expr_state *es)
char *tvar;
/* skip white space */
for (cp = es->tokp; (c = *cp), isspace(c); cp++)
for (cp = es->tokp; (c = *cp), ksh_isspace(c); cp++)
;
es->tokp = cp;

4
lex.c
View File

@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.22 2006/11/05 15:31:36 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.23 2006/11/10 07:18:57 tg Exp $");
/* Structure to keep track of the lexing state and the various pieces of info
* needed for each particular state. */
@ -899,7 +899,7 @@ getsc__(void)
source->flags |= s->flags & SF_ALIAS;
s = source;
} else if (*s->u.tblp->val.s &&
isspace((unsigned char)strchr(s->u.tblp->val.s, 0)[-1])) {
ksh_isspace(strchr(s->u.tblp->val.s, 0)[-1])) {
source = s = s->next; /* pop source stack */
/* Note that this alias ended with a space,
* enabling alias expansion on the following

4
misc.c
View File

@ -3,7 +3,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.36 2006/11/10 06:53:27 tg Exp $\t"
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.37 2006/11/10 07:18:57 tg Exp $\t"
MKSH_SH_H_ID);
#undef USE_CHVT
@ -429,7 +429,7 @@ getn(const char *s, int *ai)
do {
c = *s++;
} while (isspace(c));
} while (ksh_isspace(c));
if (c == '-') {
neg = true;
c = *s++;

10
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.78 2006/11/10 06:53:27 tg Exp $"
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.79 2006/11/10 07:18:57 tg Exp $"
#define MKSH_VERSION "R29 2006/11/10"
#if HAVE_SYS_PARAM_H
@ -40,7 +40,6 @@
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
@ -105,6 +104,13 @@
#define ksh_tolower(c) (((c) >= 'A') && ((c) <= 'Z') ? (c) - 'A' + 'a' : (c))
#define ksh_toupper(c) (((c) >= 'a') && ((c) <= 'z') ? (c) - 'a' + 'A' : (c))
/* this macro must not evaluate its arguments several times */
#define ksh_isspace(c) __extension__({ \
unsigned char ksh_isspace_c = (c); \
(ksh_isspace_c >= 0x09 && ksh_isspace_c <= 0x0D) || \
(ksh_isspace_c == 0x20); \
})
#ifndef S_ISTXT
#define S_ISTXT 0001000
#endif

10
var.c
View File

@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.29 2006/11/10 06:53:27 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.30 2006/11/10 07:18:58 tg Exp $");
/*
* Variables
@ -505,7 +505,7 @@ formatstr(struct tbl *vp, const char *s)
if (vp->flag & RJUST) {
const char *qq = s + olen;
/* strip trailing spaces (at&t uses qq[-1] == ' ') */
while (qq > s && isspace((unsigned char)qq[-1]))
while (qq > s && ksh_isspace(qq[-1]))
--qq;
slen = qq - s;
if (slen > vp->u2.field) {
@ -520,7 +520,7 @@ formatstr(struct tbl *vp, const char *s)
"%.*s", slen, s);
} else {
/* strip leading spaces/zeros */
while (isspace((unsigned char)*s))
while (ksh_isspace(*s))
s++;
if (vp->flag & ZEROFIL)
while (*s == '0')
@ -533,10 +533,10 @@ formatstr(struct tbl *vp, const char *s)
if (vp->flag & UCASEV_AL) {
for (q = p; *q; q++)
*q = _toupper((unsigned char)*q);
*q = ksh_toupper(*q);
} else if (vp->flag & LCASEV) {
for (q = p; *q; q++)
*q = _tolower((unsigned char)*q);
*q = ksh_tolower(*q);
}
return p;