fix the "char subscripts" issue, bump version

This commit is contained in:
tg 2006-07-03 12:16:31 +00:00
parent c9953f0ace
commit bc93d1c90d
7 changed files with 509 additions and 49 deletions

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.43 2006/06/21 19:27:35 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.44 2006/07/03 12:16:29 tg 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: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -3782,5 +3782,5 @@ category: pdksh
stdin:
echo $KSH_VERSION
expected-stdout:
@(#)MIRBSD KSH R27 2006/06/21
@(#)MIRBSD KSH R27 2006/07/03
---

78
edit.c
View File

@ -5,7 +5,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.21 2006/05/10 18:54:09 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.22 2006/07/03 12:16:29 tg Exp $");
/* tty driver characters we are interested in */
typedef struct {
@ -592,7 +592,8 @@ 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(buf[p]); p--)
for (p = start - 1; p >= 0 && isspace((unsigned char)buf[p]);
p--)
;
iscmd = p < 0 || strchr(";|&()`", buf[p]);
if (iscmd) {
@ -897,12 +898,13 @@ struct x_defbindings {
#define XF_PREFIX 4 /* function sets prefix */
/* Separator for completion */
#define is_cfs(c) (c == ' ' || c == '\t' || c == '"' || c == '\'')
#define is_mfs(c) (!(isalnum(c) || c == '_' || c == '$')) /* Separator for motion */
#define is_cfs(c) ((c) == ' ' || (c) == '\t' || (c) == '"' || (c) == '\'')
#define is_mfs(c) (!(isalnum((unsigned char)(c)) || (c) == '_' || \
(c) == '$')) /* Separator for motion */
# define CHARMASK 0xFF /* 8-bit character mask */
# define X_NTABS 3 /* normal, meta1, meta2 */
#define X_TABSZ (CHARMASK+1) /* size of keydef tables etc */
#define CHARMASK 0xFF /* 8-bit character mask */
#define X_NTABS 3 /* normal, meta1, meta2 */
#define X_TABSZ (CHARMASK+1) /* size of keydef tables etc */
/* Arguments for do_complete()
* 0 = enumerate M-= complete as much as possible and then list
@ -2666,7 +2668,7 @@ x_set_arg(int c)
int first = 1;
c &= CHARMASK; /* strip command prefix */
for (; c >= 0 && isdigit(c); c = x_e_getc(), first = 0)
for (; c >= 0 && isdigit((unsigned char)c); c = x_e_getc(), first = 0)
n = n * 10 + (c - '0');
if (c < 0 || first) {
x_e_putc(7);
@ -2818,10 +2820,10 @@ x_fold_case(int c)
*/
if (cp != xep) {
if (c == 'L') { /* lowercase */
if (isupper(*cp))
if (isupper((unsigned char)*cp))
*cp = tolower(*cp);
} else { /* uppercase, capitalize */
if (islower(*cp))
if (islower((unsigned char)*cp))
*cp = toupper(*cp);
}
cp++;
@ -2831,10 +2833,10 @@ x_fold_case(int c)
*/
while (cp != xep && !is_mfs(*cp)) {
if (c == 'U') { /* uppercase */
if (islower(*cp))
if (islower((unsigned char)*cp))
*cp = toupper(*cp);
} else { /* lowercase, capitalize */
if (isupper(*cp))
if (isupper((unsigned char)*cp))
*cp = tolower(*cp);
}
cp++;
@ -3181,7 +3183,7 @@ vi_hook(int ch)
break;
case VARG1:
if (isdigit(ch))
if (isdigit((unsigned char)ch))
argc1 = argc1 * 10 + ch - '0';
else {
curcmd[cmdlen++] = ch;
@ -3207,7 +3209,7 @@ vi_hook(int ch)
break;
case VARG2:
if (isdigit(ch))
if (isdigit((unsigned char)ch))
argc2 = argc2 * 10 + ch - '0';
else {
if (argc1 == 0)
@ -3270,9 +3272,9 @@ vi_hook(int ch)
int i;
int n = srchlen;
while (n > 0 && isspace(locpat[n - 1]))
while (n > 0 && isspace((unsigned char)locpat[n - 1]))
n--;
while (n > 0 && !isspace(locpat[n - 1]))
while (n > 0 && !isspace((unsigned char)locpat[n - 1]))
n--;
for (i = srchlen; --i >= n; )
es->linelen -= char_len((unsigned char)locpat[i]);
@ -3640,8 +3642,8 @@ vi_cmd(int argcnt, const char *cmd)
return -1;
if (*cmd == 'c' &&
(cmd[1] == 'w' || cmd[1] == 'W') &&
!isspace(es->cbuf[es->cursor])) {
while (isspace(es->cbuf[--ncursor]))
!isspace((unsigned char)(es->cbuf[es->cursor]))) {
while (isspace((unsigned char)(es->cbuf[--ncursor])))
;
ncursor++;
}
@ -3892,7 +3894,7 @@ vi_cmd(int argcnt, const char *cmd)
if (histnum(-1) < 0)
return -1;
p = *histpos();
#define issp(c) (isspace((c)) || (c) == '\n')
#define issp(c) (isspace((unsigned char)(c)) || (c) == '\n')
if (argcnt) {
while (*p && issp(*p))
p++;
@ -3949,11 +3951,11 @@ vi_cmd(int argcnt, const char *cmd)
return -1;
for (i = 0; i < argcnt; i++) {
p = &es->cbuf[es->cursor];
if (islower(*p)) {
if (islower((unsigned char)*p)) {
modified = 1;
hnum = hlast;
*p = toupper(*p);
} else if (isupper(*p)) {
} else if (isupper((unsigned char)*p)) {
modified = 1;
hnum = hlast;
*p = tolower(*p);
@ -4100,7 +4102,8 @@ domove(int argcnt, const char *cmd, int sub)
case '^':
ncursor = 0;
while (ncursor < es->linelen - 1 && isspace(es->cbuf[ncursor]))
while (ncursor < es->linelen - 1 &&
isspace((unsigned char)(es->cbuf[ncursor])))
ncursor++;
break;
@ -4369,12 +4372,13 @@ forwword(int argcnt)
while (is_wordch(es->cbuf[ncursor]) &&
ncursor < es->linelen)
ncursor++;
else if (!isspace(es->cbuf[ncursor]))
else if (!isspace((unsigned char)(es->cbuf[ncursor])))
while (!is_wordch(es->cbuf[ncursor]) &&
!isspace(es->cbuf[ncursor]) &&
!isspace((unsigned char)(es->cbuf[ncursor])) &&
ncursor < es->linelen)
ncursor++;
while (isspace(es->cbuf[ncursor]) && ncursor < es->linelen)
while (isspace((unsigned char)(es->cbuf[ncursor])) &&
ncursor < es->linelen)
ncursor++;
}
return ncursor;
@ -4387,7 +4391,7 @@ backword(int argcnt)
ncursor = es->cursor;
while (ncursor > 0 && argcnt--) {
while (--ncursor > 0 && isspace(es->cbuf[ncursor]))
while (--ncursor > 0 && isspace((unsigned char)(es->cbuf[ncursor])))
;
if (ncursor > 0) {
if (is_wordch(es->cbuf[ncursor]))
@ -4397,7 +4401,7 @@ backword(int argcnt)
else
while (--ncursor >= 0 &&
!is_wordch(es->cbuf[ncursor]) &&
!isspace(es->cbuf[ncursor]))
!isspace((unsigned char)(es->cbuf[ncursor])))
;
ncursor++;
}
@ -4413,7 +4417,7 @@ endword(int argcnt)
ncursor = es->cursor;
while (ncursor < es->linelen && argcnt--) {
while (++ncursor < es->linelen - 1 &&
isspace(es->cbuf[ncursor]))
isspace((unsigned char)(es->cbuf[ncursor])))
;
if (ncursor < es->linelen - 1) {
if (is_wordch(es->cbuf[ncursor]))
@ -4423,7 +4427,7 @@ endword(int argcnt)
else
while (++ncursor < es->linelen &&
!is_wordch(es->cbuf[ncursor]) &&
!isspace(es->cbuf[ncursor]))
!isspace((unsigned char)(es->cbuf[ncursor])))
;
ncursor--;
}
@ -4438,9 +4442,11 @@ Forwword(int argcnt)
ncursor = es->cursor;
while (ncursor < es->linelen && argcnt--) {
while (!isspace(es->cbuf[ncursor]) && ncursor < es->linelen)
while (!isspace((unsigned char)(es->cbuf[ncursor])) &&
ncursor < es->linelen)
ncursor++;
while (isspace(es->cbuf[ncursor]) && ncursor < es->linelen)
while (isspace((unsigned char)(es->cbuf[ncursor])) &&
ncursor < es->linelen)
ncursor++;
}
return ncursor;
@ -4453,9 +4459,11 @@ Backword(int argcnt)
ncursor = es->cursor;
while (ncursor > 0 && argcnt--) {
while (--ncursor >= 0 && isspace(es->cbuf[ncursor]))
while (--ncursor >= 0 &&
isspace((unsigned char)(es->cbuf[ncursor])))
;
while (ncursor >= 0 && !isspace(es->cbuf[ncursor]))
while (ncursor >= 0 &&
!isspace((unsigned char)(es->cbuf[ncursor])))
ncursor--;
ncursor++;
}
@ -4470,11 +4478,11 @@ Endword(int argcnt)
ncursor = es->cursor;
while (ncursor < es->linelen - 1 && argcnt--) {
while (++ncursor < es->linelen - 1 &&
isspace(es->cbuf[ncursor]))
isspace((unsigned char)(es->cbuf[ncursor])))
;
if (ncursor < es->linelen - 1) {
while (++ncursor < es->linelen &&
!isspace(es->cbuf[ncursor]))
!isspace((unsigned char)(es->cbuf[ncursor])))
;
ncursor--;
}

View File

@ -5,7 +5,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.27 2006/05/10 18:54:10 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.28 2006/07/03 12:16:30 tg Exp $");
int
c_cd(char **wp)
@ -1107,7 +1107,8 @@ c_kill(char **wp)
int i, n, rv, sig;
/* assume old style options if -digits or -UPPERCASE */
if ((p = wp[1]) && *p == '-' && (digit(p[1]) || isupper(p[1]))) {
if ((p = wp[1]) && *p == '-' && (digit(p[1]) ||
isupper((unsigned char)p[1]))) {
if (!(t = gettrap(p + 1, true))) {
bi_errorf("bad signal '%s'", p + 1);
return 1;

4
lex.c
View File

@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.12 2006/05/10 18:54:11 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.13 2006/07/03 12:16:30 tg Exp $");
/* Structure to keep track of the lexing state and the various pieces of info
* needed for each particular state. */
@ -898,7 +898,7 @@ getsc__(void)
source->flags |= s->flags & SF_ALIAS;
s = source;
} else if (*s->u.tblp->val.s &&
isspace(strchr(s->u.tblp->val.s, 0)[-1])) {
isspace((unsigned char)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

6
main.c
View File

@ -6,9 +6,9 @@
#define EXTERN /* define EXTERNs in sh.h */
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.39 2006/06/21 19:27:35 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.40 2006/07/03 12:16:30 tg Exp $");
#define MKSH_VERSION "@(#)MIRBSD KSH R27 2006/06/21"
#define MKSH_VERSION "@(#)MIRBSD KSH R27 2006/07/03"
extern char **environ;
@ -936,7 +936,7 @@ check_fd(char *name, int mode, const char **emsgp)
{
int fd, fl;
if (isdigit(name[0]) && !name[1]) {
if (isdigit((unsigned char)name[0]) && !name[1]) {
fd = name[0] - '0';
if ((fl = fcntl(fd = name[0] - '0', F_GETFL, 0)) < 0) {
if (emsgp)

451
setmode.c Normal file
View File

@ -0,0 +1,451 @@
/** _MirOS: src/lib/libc/gen/setmode.c,v 1.5 2006/07/03 12:13:52 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 $ */
/*
* Copyright (c) 1989, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Dave Borman at Cray Research, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <ctype.h>
#include <errno.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#ifdef SETMODE_DEBUG
#include <stdio.h>
#endif
__SCCSID("@(#)setmode.c 8.2 (Berkeley) 3/25/94");
__RCSID("$MirOS: src/bin/mksh/setmode.c,v 1.2 2006/07/03 12:16:31 tg Exp $");
#define SET_LEN 6 /* initial # of bitcmd struct to malloc */
#define SET_LEN_INCR 4 /* # of bitcmd structs to add as needed */
typedef struct bitcmd {
char cmd;
char cmd2;
mode_t bits;
} BITCMD;
#define CMD2_CLR 0x01
#define CMD2_SET 0x02
#define CMD2_GBITS 0x04
#define CMD2_OBITS 0x08
#define CMD2_UBITS 0x10
static BITCMD *addcmd(BITCMD *, int, int, int, u_int);
static void compress_mode(BITCMD *);
#ifdef SETMODE_DEBUG
static void dumpmode(BITCMD *);
#endif
/*
* Given the old mode and an array of bitcmd structures, apply the operations
* described in the bitcmd structures to the old mode, and return the new mode.
* Note that there is no '=' command; a strict assignment is just a '-' (clear
* bits) followed by a '+' (set bits).
*/
mode_t
getmode(const void *bbox, mode_t omode)
{
const BITCMD *set;
mode_t clrval, newmode, value;
set = (const BITCMD *)bbox;
newmode = omode;
for (value = 0;; set++)
switch(set->cmd) {
/*
* When copying the user, group or other bits around, we "know"
* where the bits are in the mode so that we can do shifts to
* copy them around. If we don't use shifts, it gets real
* grundgy with lots of single bit checks and bit sets.
*/
case 'u':
value = (newmode & S_IRWXU) >> 6;
goto common;
case 'g':
value = (newmode & S_IRWXG) >> 3;
goto common;
case 'o':
value = newmode & S_IRWXO;
common: if (set->cmd2 & CMD2_CLR) {
clrval =
(set->cmd2 & CMD2_SET) ? S_IRWXO : value;
if (set->cmd2 & CMD2_UBITS)
newmode &= ~((clrval<<6) & set->bits);
if (set->cmd2 & CMD2_GBITS)
newmode &= ~((clrval<<3) & set->bits);
if (set->cmd2 & CMD2_OBITS)
newmode &= ~(clrval & set->bits);
}
if (set->cmd2 & CMD2_SET) {
if (set->cmd2 & CMD2_UBITS)
newmode |= (value<<6) & set->bits;
if (set->cmd2 & CMD2_GBITS)
newmode |= (value<<3) & set->bits;
if (set->cmd2 & CMD2_OBITS)
newmode |= value & set->bits;
}
break;
case '+':
newmode |= set->bits;
break;
case '-':
newmode &= ~set->bits;
break;
case 'X':
if (omode & (S_IFDIR|S_IXUSR|S_IXGRP|S_IXOTH))
newmode |= set->bits;
break;
case '\0':
default:
#ifdef SETMODE_DEBUG
(void)printf("getmode:%04o -> %04o\n", omode, newmode);
#endif
return (newmode);
}
}
#define ADDCMD(a, b, c, d) \
if (set >= endset) { \
BITCMD *newset; \
setlen += SET_LEN_INCR; \
newset = realloc(saveset, sizeof(BITCMD) * setlen); \
if (newset == NULL) { \
free(saveset); \
return (NULL); \
} \
set = newset + (set - saveset); \
saveset = newset; \
endset = newset + (setlen - 2); \
} \
set = addcmd(set, (a), (b), (c), (d))
#define STANDARD_BITS (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO)
void *
setmode(const char *p)
{
int perm, who;
char op, *ep;
BITCMD *set, *saveset, *endset;
sigset_t sigset, sigoset;
mode_t mask;
int equalopdone = 0, permXbits, setlen;
u_long perml;
if (!*p)
return (NULL);
/*
* Get a copy of the mask for the permissions that are mask relative.
* Flip the bits, we want what's not set. Since it's possible that
* the caller is opening files inside a signal handler, protect them
* as best we can.
*/
sigfillset(&sigset);
(void)sigprocmask(SIG_BLOCK, &sigset, &sigoset);
(void)umask(mask = umask(0));
mask = ~mask;
(void)sigprocmask(SIG_SETMASK, &sigoset, NULL);
setlen = SET_LEN + 2;
if ((set = malloc((u_int)(sizeof(BITCMD) * setlen))) == NULL)
return (NULL);
saveset = set;
endset = set + (setlen - 2);
/*
* If an absolute number, get it and return; disallow non-octal digits
* or illegal bits.
*/
if (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))) {
free(saveset);
errno = ERANGE;
return (NULL);
}
perm = (mode_t)perml;
ADDCMD('=', (STANDARD_BITS|S_ISTXT), perm, mask);
set->cmd = 0;
return (saveset);
}
/*
* Build list of structures to set/clear/copy bits as described by
* each clause of the symbolic mode.
*/
for (;;) {
/* First, find out which bits might be modified. */
for (who = 0;; ++p) {
switch (*p) {
case 'a':
who |= STANDARD_BITS;
break;
case 'u':
who |= S_ISUID|S_IRWXU;
break;
case 'g':
who |= S_ISGID|S_IRWXG;
break;
case 'o':
who |= S_IRWXO;
break;
default:
goto getop;
}
}
getop: if ((op = *p++) != '+' && op != '-' && op != '=') {
free(saveset);
return (NULL);
}
if (op == '=')
equalopdone = 0;
who &= ~S_ISTXT;
for (perm = 0, permXbits = 0;; ++p) {
switch (*p) {
case 'r':
perm |= S_IRUSR|S_IRGRP|S_IROTH;
break;
case 's':
/*
* If specific bits where requested and
* only "other" bits ignore set-id.
*/
if (who == 0 || (who & ~S_IRWXO))
perm |= S_ISUID|S_ISGID;
break;
case 't':
/*
* If specific bits where requested and
* only "other" bits ignore sticky.
*/
if (who == 0 || (who & ~S_IRWXO)) {
who |= S_ISTXT;
perm |= S_ISTXT;
}
break;
case 'w':
perm |= S_IWUSR|S_IWGRP|S_IWOTH;
break;
case 'X':
permXbits = S_IXUSR|S_IXGRP|S_IXOTH;
break;
case 'x':
perm |= S_IXUSR|S_IXGRP|S_IXOTH;
break;
case 'u':
case 'g':
case 'o':
/*
* When ever we hit 'u', 'g', or 'o', we have
* to flush out any partial mode that we have,
* and then do the copying of the mode bits.
*/
if (perm) {
ADDCMD(op, who, perm, mask);
perm = 0;
}
if (op == '=')
equalopdone = 1;
if (op == '+' && permXbits) {
ADDCMD('X', who, permXbits, mask);
permXbits = 0;
}
ADDCMD(*p, who, op, mask);
break;
default:
/*
* Add any permissions that we haven't already
* done.
*/
if (perm || (op == '=' && !equalopdone)) {
if (op == '=')
equalopdone = 1;
ADDCMD(op, who, perm, mask);
perm = 0;
}
if (permXbits) {
ADDCMD('X', who, permXbits, mask);
permXbits = 0;
}
goto apply;
}
}
apply: if (!*p)
break;
if (*p != ',')
goto getop;
++p;
}
set->cmd = 0;
#ifdef SETMODE_DEBUG
(void)printf("Before compress_mode()\n");
dumpmode(saveset);
#endif
compress_mode(saveset);
#ifdef SETMODE_DEBUG
(void)printf("After compress_mode()\n");
dumpmode(saveset);
#endif
return (saveset);
}
static BITCMD *
addcmd(BITCMD *set, int op, int who, int oparg, u_int mask)
{
switch (op) {
case '=':
set->cmd = '-';
set->bits = who ? who : STANDARD_BITS;
set++;
op = '+';
/* FALLTHROUGH */
case '+':
case '-':
case 'X':
set->cmd = op;
set->bits = (who ? who : (int)mask) & oparg;
break;
case 'u':
case 'g':
case 'o':
set->cmd = op;
if (who) {
set->cmd2 = ((who & S_IRUSR) ? CMD2_UBITS : 0) |
((who & S_IRGRP) ? CMD2_GBITS : 0) |
((who & S_IROTH) ? CMD2_OBITS : 0);
set->bits = (mode_t)~0;
} else {
set->cmd2 = CMD2_UBITS | CMD2_GBITS | CMD2_OBITS;
set->bits = mask;
}
if (oparg == '+')
set->cmd2 |= CMD2_SET;
else if (oparg == '-')
set->cmd2 |= CMD2_CLR;
else if (oparg == '=')
set->cmd2 |= CMD2_SET|CMD2_CLR;
break;
}
return (set + 1);
}
#ifdef SETMODE_DEBUG
static void
dumpmode(BITCMD *set)
{
for (; set->cmd; ++set)
(void)printf("cmd: '%c' bits %04o%s%s%s%s%s%s\n",
set->cmd, set->bits, set->cmd2 ? " cmd2:" : "",
set->cmd2 & CMD2_CLR ? " CLR" : "",
set->cmd2 & CMD2_SET ? " SET" : "",
set->cmd2 & CMD2_UBITS ? " UBITS" : "",
set->cmd2 & CMD2_GBITS ? " GBITS" : "",
set->cmd2 & CMD2_OBITS ? " OBITS" : "");
}
#endif
/*
* Given an array of bitcmd structures, compress by compacting consecutive
* '+', '-' and 'X' commands into at most 3 commands, one of each. The 'u',
* 'g' and 'o' commands continue to be separate. They could probably be
* compacted, but it's not worth the effort.
*/
static void
compress_mode(BITCMD *set)
{
BITCMD *nset;
int setbits, clrbits, Xbits, op;
for (nset = set;;) {
/* Copy over any 'u', 'g' and 'o' commands. */
while ((op = nset->cmd) != '+' && op != '-' && op != 'X') {
*set++ = *nset++;
if (!op)
return;
}
for (setbits = clrbits = Xbits = 0;; nset++) {
if ((op = nset->cmd) == '-') {
clrbits |= nset->bits;
setbits &= ~nset->bits;
Xbits &= ~nset->bits;
} else if (op == '+') {
setbits |= nset->bits;
clrbits &= ~nset->bits;
Xbits &= ~nset->bits;
} else if (op == 'X')
Xbits |= nset->bits & ~setbits;
else
break;
}
if (clrbits) {
set->cmd = '-';
set->cmd2 = 0;
set->bits = clrbits;
set++;
}
if (setbits) {
set->cmd = '+';
set->cmd2 = 0;
set->bits = setbits;
set++;
}
if (Xbits) {
set->cmd = 'X';
set->cmd2 = 0;
set->bits = Xbits;
set++;
}
}
}

10
var.c
View File

@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.19 2006/06/21 19:35:38 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.20 2006/07/03 12:16:31 tg Exp $");
/*
* Variables
@ -503,7 +503,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(qq[-1]))
while (qq > s && isspace((unsigned char)qq[-1]))
--qq;
slen = qq - s;
if (slen > vp->u2.field) {
@ -516,7 +516,7 @@ formatstr(struct tbl *vp, const char *s)
vp->u2.field - slen, null, slen, s);
} else {
/* strip leading spaces/zeros */
while (isspace(*s))
while (isspace((unsigned char)*s))
s++;
if (vp->flag & ZEROFIL)
while (*s == '0')
@ -529,11 +529,11 @@ formatstr(struct tbl *vp, const char *s)
if (vp->flag & UCASEV_AL) {
for (q = p; *q; q++)
if (islower(*q))
if (islower((unsigned char)*q))
*q = toupper(*q);
} else if (vp->flag & LCASEV) {
for (q = p; *q; q++)
if (isupper(*q))
if (isupper((unsigned char)*q))
*q = tolower(*q);
}