fixup the remaining issues and last optimisations

This commit is contained in:
tg 2017-04-27 23:12:49 +00:00
parent 8bd529a08c
commit 13e91621ca
7 changed files with 113 additions and 101 deletions

10
edit.c
View File

@ -28,7 +28,7 @@
#ifndef MKSH_NO_CMDLINE_EDITING
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.327 2017/04/27 20:22:22 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.328 2017/04/27 23:12:44 tg Exp $");
/*
* in later versions we might use libtermcap for this, but since external
@ -553,8 +553,7 @@ x_command_glob(int flags, char *toglob, char ***wordsp)
return (nwords);
}
#define IS_WORDC(c) (!ctype(c, C_LEX1 | C_QC) && \
(c) != '`' && (c) != '=' && (c) != ':')
#define IS_WORDC(c) (!ctype(c, C_EDNWC))
static int
x_locate_word(const char *buf, int buflen, int pos, int *startp,
@ -591,7 +590,7 @@ x_locate_word(const char *buf, int buflen, int pos, int *startp,
/* Figure out if this is a command */
while (p >= 0 && ctype(buf[p], C_SPACE))
p--;
iscmd = p < 0 || vstrchr(";|&()`", buf[p]);
iscmd = p < 0 || ctype(buf[p], C_EDCMD);
if (iscmd) {
/*
* If command has a /, path, etc. is not searched;
@ -859,8 +858,7 @@ x_escape(const char *s, size_t len, int (*putbuf_func)(const char *, size_t))
int rval = 0;
while (wlen - add > 0)
if (vstrchr("#*=?[\\`" ":{}", s[add]) || /*…1…*/
ctype(s[add], C_IFS | C_QC | C_DOLAR | CiQCL)) {
if (ctype(s[add], C_IFS | C_EDQ)) {
if (putbuf_func(s, add) != 0) {
rval = -1;
break;

4
eval.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.205 2017/04/27 19:33:47 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.206 2017/04/27 23:12:46 tg Exp $");
/*
* string expansion
@ -1728,7 +1728,7 @@ debunk(char *dp, const char *sp, size_t dlen)
memmove(dp, sp, s - sp);
for (d = dp + (s - sp); *s && (d - dp < (ssize_t)dlen); s++)
if (!ISMAGIC(*s) || !(*++s & 0x80) ||
!vstrchr("*+?@! ", *s & 0x7f))
!ctype(*s & 0x7F, C_PATMO))
*d++ = *s;
else {
/* extended pattern operators: *+?@! */

4
expr.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.95 2017/04/27 20:22:24 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.96 2017/04/27 23:12:46 tg Exp $");
#define EXPRTOK_DEFNS
#include "exprtok.h"
@ -618,7 +618,7 @@ exprtoken(Expr_state *es)
goto process_tvar;
#endif
} else if (ctype(c, C_DIGIT)) {
while (ctype(c, C_ALNUM) || c == '#')
while (ctype(c, C_ALNUM | C_HASH))
c = *cp++;
strndupx(tvar, es->tokp, --cp - es->tokp, ATEMP);
process_tvar:

View File

@ -38,7 +38,7 @@
#endif
#endif
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.344 2017/04/27 20:22:24 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.345 2017/04/27 23:12:46 tg Exp $");
#if HAVE_KILLPG
/*
@ -1456,7 +1456,7 @@ c_umask(const char **wp)
if (!positions)
/* default is a */
positions = 0111;
if (!vstrchr("=+-", op = *cp))
if (!ctype((op = *cp), C_EQUAL | C_MINUS | C_PLUS))
break;
cp++;
new_val = 0;
@ -1497,7 +1497,7 @@ c_umask(const char **wp)
if (*cp == ',') {
positions = 0;
cp++;
} else if (!vstrchr("=+-", *cp))
} else if (!ctype(*cp, C_EQUAL | C_MINUS | C_PLUS))
break;
}
if (*cp) {

6
misc.c
View File

@ -30,7 +30,7 @@
#include <grp.h>
#endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.261 2017/04/27 20:22:26 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.262 2017/04/27 23:12:47 tg Exp $");
#define KSH_CHVT_FLAG
#ifdef MKSH_SMALL
@ -703,7 +703,7 @@ has_globbing(const char *xp, const char *xpe)
return (0);
in_bracket = false;
}
} else if ((c & 0x80) && vstrchr("*+?@! ", c & 0x7f)) {
} else if ((c & 0x80) && ctype(c & 0x7F, C_PATMO)) {
saw_glob = true;
if (in_bracket)
bnest++;
@ -919,7 +919,7 @@ pat_scan(const unsigned char *p, const unsigned char *pe, bool match_sep)
if ((*++p == /*(*/ ')' && nest-- == 0) ||
(*p == '|' && match_sep && nest == 0))
return (p + 1);
if ((*p & 0x80) && vstrchr("*+?@! ", *p & 0x7f))
if ((*p & 0x80) && ctype(*p & 0x7F, C_PATMO))
nest++;
}
return (NULL);

134
sh.h
View File

@ -175,7 +175,7 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.817 2017/04/27 20:22:27 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.818 2017/04/27 23:12:48 tg Exp $");
#endif
#define MKSH_VERSION "R55 2017/04/27"
@ -498,7 +498,7 @@ extern int __cdecl setegid(gid_t);
#endif
/* define bit in flag */
#define BIT(i) (1 << (i))
#define BIT(i) (1U << (i))
#define NELEM(a) (sizeof(a) / sizeof((a)[0]))
/*
@ -1288,30 +1288,40 @@ EXTERN bool really_exit;
*/
/* internal types, do not reference */
#define CiCNTRL BIT(0) /* \x00‥\x1F\x7F */
#define CiUPPER BIT(1) /* A‥Z */
#define CiLOWER BIT(2) /* a‥z */
#define CiHEXLT BIT(3) /* A‥Fa‥f */
#define CiDIGIT BIT(4) /* 0‥9 */
#define CiOCTAL BIT(5) /* 0‥7 */
#define CiQCX BIT(6) /* #*=?[\\]` */
#define CiQCM BIT(7) /* +/:^{}~ */
#define CiQCL BIT(8) /* &();<>| */
#define CiVAR1 BIT(9) /* !#$*-?@ */
#define CiALIAS BIT(10) /* !%,-.@ */
#define CiSUB1 BIT(11) /* +-=? */
#define CiSPX BIT(12) /* \x0B\x0C */
#define CiQC BIT(13) /* "' */
#define CiSUB2 BIT(14) /* #% */
#define CiUNDER BIT(15) /* _ */
#define CiNUL BIT(16) /* \x00 */
#define CiTAB BIT(17) /* \x09 */
#define CiNL BIT(18) /* \x0A */
#define CiSP BIT(19) /* \x20 */
#define CiSS BIT(20) /* $ */
#define CiCR BIT(21) /* \x0D */
/* initially emptyfilled at runtime from $IFS */
#define CiIFS BIT(30)
#define CiIFS BIT(0)
#define CiCNTRL BIT(1) /* \x01‥\x08\x0E‥\x1F\x7F */
#define CiUPPER BIT(2) /* A‥Z */
#define CiLOWER BIT(3) /* a‥z */
#define CiHEXLT BIT(4) /* A‥Fa‥f */
#define CiOCTAL BIT(5) /* 0‥7 */
#define CiQCL BIT(6) /* &();| */
#define CiALIAS BIT(7) /* !,.@ */
#define CiQCX BIT(8) /* *[\\ */
#define CiVAR1 BIT(9) /* !*@ */
#define CiQCM BIT(10) /* /^~ */
#define CiDIGIT BIT(11) /* 89 */
#define CiQC BIT(12) /* "' */
#define CiSPX BIT(13) /* \x0B\x0C */
#define CiCURLY BIT(14) /* {} */
#define CiANGLE BIT(15) /* <> */
#define CiNUL BIT(16) /* \x00 */
#define CiTAB BIT(17) /* \x09 */
#define CiNL BIT(18) /* \x0A */
#define CiCR BIT(19) /* \x0D */
#define CiSP BIT(20) /* \x20 */
#define CiHASH BIT(21) /* # */
#define CiSS BIT(22) /* $ */
#define CiPERCT BIT(23) /* % */
#define CiPLUS BIT(24) /* + */
#define CiMINUS BIT(25) /* - */
#define CiCOLON BIT(26) /* : */
#define CiEQUAL BIT(27) /* = */
#define CiQUEST BIT(28) /* ? */
#define CiCBRK BIT(29) /* ] */
#define CiUNDER BIT(30) /* _ */
#define CiGRAVE BIT(31) /* ` */
/* compile-time initialised, ASCII only */
extern const uint32_t tpl_ctypes[128];
@ -1322,68 +1332,81 @@ EXTERN char ifs0;
/* external types */
/* 0‥9A‥Za‥z!%,-.@ valid characters in alias name */
#define C_ALIAS (CiUPPER | CiLOWER | CiDIGIT | CiOCTAL | CiUNDER | CiALIAS)
/* !%,-.0‥9@A‥Z_a‥z valid characters in alias name */
#define C_ALIAS (CiALIAS | CiDIGIT | CiLOWER | CiMINUS | CiOCTAL | CiPERCT | CiUNDER | CiUPPER)
/* 0‥9A‥Za‥z alphanumerical */
#define C_ALNUM (CiUPPER | CiLOWER | CiDIGIT | CiOCTAL)
/* 0‥9A‥Za‥z_ alphanumerical plus underscore (“word character”) */
#define C_ALNUX (CiUPPER | CiLOWER | CiDIGIT | CiOCTAL | CiUNDER)
#define C_ALNUM (CiDIGIT | CiLOWER | CiOCTAL | CiUPPER)
/* 0‥9A‥Z_a‥z alphanumerical plus underscore (“word character”) */
#define C_ALNUX (CiDIGIT | CiLOWER | CiOCTAL | CiUNDER | CiUPPER)
/* A‥Za‥z alphabetical (upper plus lower) */
#define C_ALPHA (CiUPPER | CiLOWER)
/* A‥Za‥z_ alphabetical plus underscore (identifier lead) */
#define C_ALPHX (CiUPPER | CiLOWER | CiUNDER)
#define C_ALPHA (CiLOWER | CiUPPER)
/* A‥Z_a‥z alphabetical plus underscore (identifier lead) */
#define C_ALPHX (CiLOWER | CiUNDER | CiUPPER)
/* \x09\x20 tab and space */
#define C_BLANK (CiTAB | CiSP)
#define C_BLANK (CiSP | CiTAB)
/* \x09\x20"' separator for completion */
#define C_CFS (CiTAB | CiSP | CiQC)
#define C_CFS (CiQC | CiSP | CiTAB)
/* \x00‥\x1F\x7F POSIX control characters */
#define C_CNTRL CiCNTRL
#define C_CNTRL (CiCNTRL | CiCR | CiNL | CiNUL | CiSPX | CiTAB)
/* 0‥9 decimal digits */
#define C_DIGIT (CiDIGIT | CiOCTAL)
/* &();`| editor x_locate_word() command */
#define C_EDCMD (CiGRAVE | CiQCL)
/* \x09\x0A\x20"&'():;<=>`| editor non-word characters */
#define C_EDNWC (CiANGLE | CiCOLON | CiEQUAL | CiGRAVE | CiNL | CiQC | CiQCL | CiSP | CiTAB)
/* "#$&'()*:;<=>?[\\`{|} editor quotes for tab completion */
#define C_EDQ (CiANGLE | CiCOLON | CiCURLY | CiEQUAL | CiGRAVE | CiHASH | CiQC | CiQCL | CiQCX | CiQUEST | CiSS)
/* !‥~ POSIX graphical (alphanumerical plus punctuation) */
#define C_GRAPH (CiUPPER | CiLOWER | CiDIGIT | CiOCTAL | C_PUNCT)
#define C_GRAPH (C_PUNCT | CiDIGIT | CiLOWER | CiOCTAL | CiUPPER)
/* A‥Fa‥f hex letter */
#define C_HEXLT CiHEXLT
/* \x00 + $IFS IFS whitespace, IFS non-whitespace, NUL */
#define C_IFS (CiIFS | CiNUL)
/* \x09\x0A\x20 IFS whitespace */
#define C_IFSWS (CiTAB | CiSP | CiNL)
#define C_IFSWS (CiNL | CiSP | CiTAB)
/* \x09\x0A\x20&();<>| (for the lexer) */
#define C_LEX1 (CiTAB | CiSP | CiNL | CiQCL)
#define C_LEX1 (CiANGLE | CiNL | CiQCL | CiSP | CiTAB)
/* a‥z lowercase letters */
#define C_LOWER CiLOWER
/* not alnux or dollar separator for motion */
#define C_MFS (CiCNTRL | CiSP | CiQCM | CiALIAS | CiQC | CiQCL | CiQCX)
#define C_MFS (CiALIAS | CiANGLE | CiCBRK | CiCNTRL | CiCOLON | CiCR | CiCURLY | CiEQUAL | CiGRAVE | CiHASH | CiMINUS | CiNL | CiNUL | CiPERCT | CiPLUS | CiQC | CiQCL | CiQCM | CiQCX | CiQUEST | CiSP | CiSPX | CiTAB)
/* 0‥7 octal digit */
#define C_OCTAL CiOCTAL
/* \x20‥\x7E POSIX printable characters (graph plus space) */
/* \x20!*+?@ pattern magical operator */
#define C_PATMO (CiPLUS | CiQUEST | CiSP | CiVAR1)
/* \x20‥~ POSIX printable characters (graph plus space) */
#define C_PRINT (C_GRAPH | CiSP)
/* !"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ POSIX punctuation */
#define C_PUNCT (CiUNDER | CiALIAS | CiSS | CiQC | CiQCL | CiQCX)
#define C_PUNCT (CiALIAS | CiANGLE | CiCBRK | CiCOLON | CiCURLY | CiEQUAL | CiGRAVE | CiHASH | CiMINUS | CiPERCT | CiPLUS | CiQC | CiQCL | CiQCM | CiQCX | CiQUEST | CiSS | CiUNDER)
/* \x09\x0A"#$&'()*;<=>?[\\]`| characters requiring quoting, minus space */
#define C_QUOTE (CiTAB | CiNL | CiSS | CiQC | CiQCL | CiQCX)
#define C_QUOTE (CiANGLE | CiCBRK | CiEQUAL | CiGRAVE | CiHASH | CiNL | CiQC | CiQCL | CiQCX | CiQUEST | CiSS | CiTAB)
/* 0‥9A‥Fa‥f hexadecimal digit */
#define C_SEDEC (CiDIGIT | CiOCTAL | CiHEXLT)
#define C_SEDEC (CiDIGIT | CiHEXLT | CiOCTAL)
/* \x09‥\x0D\x20 POSIX space class */
#define C_SPACE (CiTAB | CiSP | CiNL | CiSPX | CiCR)
#define C_SPACE (CiCR | CiNL | CiSP | CiSPX | CiTAB)
/* +-=? substitution operations with word */
#define C_SUB1 CiSUB1
#define C_SUB1 (CiEQUAL | CiMINUS | CiPLUS | CiQUEST)
/* #% substitution operations with pattern */
#define C_SUB2 CiSUB2
#define C_SUB2 (CiHASH | CiPERCT)
/* A‥Z uppercase letters */
#define C_UPPER CiUPPER
/* !#$*-?@ substitution parameters, other than positional */
#define C_VAR1 CiVAR1
#define C_VAR1 (CiHASH | CiMINUS | CiQUEST | CiSS | CiVAR1)
/* individual chars you might like */
#define C_COLON CiCOLON /* : colon */
#define C_DOLAR CiSS /* $ dollar sign */
#define C_EQUAL CiEQUAL /* = equals sign */
#define C_HASH CiHASH /* # hash sign */
#define C_LF CiNL /* \x0A ASCII line feed */
#define C_MINUS CiMINUS /* - hyphen-minus */
#ifdef MKSH_WITH_TEXTMODE
#define C_NL (CiNL | CiCR) /* CR or LF under OS/2 TEXTMODE */
#define C_NL (CiNL | CiCR) /* CR or LF under OS/2 TEXTMODE */
#else
#define C_NL CiNL /* LF only like under Unix */
#define C_NL CiNL /* LF only like under Unix */
#endif
#define C_NUL CiNUL /* \x00 ASCII NUL */
#define C_PLUS CiPLUS /* + plus sign */
#define C_QC CiQC /* "' quote characters */
#define C_SPC CiSP /* \x20 ASCII space */
#define C_TAB CiTAB /* \x09 ASCII horizontal tabulator */
@ -1391,12 +1414,15 @@ EXTERN char ifs0;
/* identity transform of octet */
#define ord(c) ((unsigned int)(unsigned char)(c))
/* identity transformation in !EBCDIC; ASCII or high in EBCDIC */
#ifdef MKSH_EBCDIC
/* asc(c) must do a table lookup, non-ASCII map high */
#define ksh_eq(c,u,l) (ord(c) == ord(u) || ord(c) == ord(l))
#else
#define asc(c) ord(c)
/* EBCDIC needs to compare c with both u and l */
#define ksh_eq(c,u,l) (((c) | 0x20) == (l))
#define ksh_eq(c,u,l) ((ord(c) | 0x20) == ord(l))
#endif
/* new fast character classes */
#define ctype(c, t) tobool(ksh_ctypes[ord(c)] & (t))
#define ctype(c,t) tobool(ksh_ctypes[ord(c)] & (t))
/* helper functions */
#define ksh_isdash(s) tobool(ord((s)[0]) == '-' && ord((s)[1]) == '\0')
/* invariant distance even in EBCDIC */

50
shf.c
View File

@ -25,7 +25,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.82 2017/04/27 19:33:53 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.83 2017/04/27 23:12:49 tg Exp $");
/* flags to shf_emptybuf() */
#define EB_READSW 0x01 /* about to switch to reading */
@ -1162,61 +1162,49 @@ cstrerror(int errnum)
/* fast character classes */
const uint32_t tpl_ctypes[128] = {
/* 0x00 */
CiCNTRL | CiNUL, CiCNTRL,
CiCNTRL, CiCNTRL,
CiCNTRL, CiCNTRL,
CiCNTRL, CiCNTRL,
CiCNTRL, CiCNTRL | CiTAB,
CiCNTRL | CiNL, CiCNTRL | CiSPX,
CiCNTRL | CiSPX, CiCNTRL | CiCR,
CiCNTRL, CiCNTRL,
CiNUL, CiCNTRL, CiCNTRL, CiCNTRL,
CiCNTRL, CiCNTRL, CiCNTRL, CiCNTRL,
CiCNTRL, CiTAB, CiNL, CiSPX,
CiSPX, CiCR, CiCNTRL, CiCNTRL,
/* 0x10 */
CiCNTRL, CiCNTRL, CiCNTRL, CiCNTRL,
CiCNTRL, CiCNTRL, CiCNTRL, CiCNTRL,
CiCNTRL, CiCNTRL, CiCNTRL, CiCNTRL,
CiCNTRL, CiCNTRL, CiCNTRL, CiCNTRL,
/* 0x20 */
CiSP, CiALIAS | CiVAR1,
CiQC, CiQCX | CiVAR1 | CiSUB2,
CiVAR1 | CiSS, CiALIAS | CiSUB2,
CiQCL, CiQC,
CiQCL, CiQCL,
CiQCX | CiVAR1, CiQCM | CiSUB1,
CiALIAS, CiALIAS | CiVAR1 | CiSUB1,
CiALIAS, CiQCM,
CiSP, CiALIAS | CiVAR1, CiQC, CiHASH,
CiSS, CiPERCT, CiQCL, CiQC,
CiQCL, CiQCL, CiQCX | CiVAR1, CiPLUS,
CiALIAS, CiMINUS, CiALIAS, CiQCM,
/* 0x30 */
CiOCTAL, CiOCTAL, CiOCTAL, CiOCTAL,
CiOCTAL, CiOCTAL, CiOCTAL, CiOCTAL,
CiDIGIT, CiDIGIT, CiQCM, CiQCL,
CiQCL, CiQCX | CiSUB1, CiQCL, CiQCX | CiVAR1 | CiSUB1,
CiDIGIT, CiDIGIT, CiCOLON, CiQCL,
CiANGLE, CiEQUAL, CiANGLE, CiQUEST,
/* 0x40 */
CiALIAS | CiVAR1, CiUPPER | CiHEXLT,
CiUPPER | CiHEXLT, CiUPPER | CiHEXLT,
CiUPPER | CiHEXLT, CiUPPER | CiHEXLT,
CiUPPER | CiHEXLT, CiUPPER,
CiUPPER, CiUPPER,
CiUPPER, CiUPPER,
CiUPPER, CiUPPER,
CiUPPER, CiUPPER,
CiUPPER, CiUPPER, CiUPPER, CiUPPER,
CiUPPER, CiUPPER, CiUPPER, CiUPPER,
/* 0x50 */
CiUPPER, CiUPPER, CiUPPER, CiUPPER,
CiUPPER, CiUPPER, CiUPPER, CiUPPER,
CiUPPER, CiUPPER, CiUPPER, CiQCX,
CiQCX, CiQCX, CiQCM, CiUNDER,
CiQCX, CiCBRK, CiQCM, CiUNDER,
/* 0x60 */
CiQCX, CiLOWER | CiHEXLT,
CiGRAVE, CiLOWER | CiHEXLT,
CiLOWER | CiHEXLT, CiLOWER | CiHEXLT,
CiLOWER | CiHEXLT, CiLOWER | CiHEXLT,
CiLOWER | CiHEXLT, CiLOWER,
CiLOWER, CiLOWER,
CiLOWER, CiLOWER,
CiLOWER, CiLOWER,
CiLOWER, CiLOWER,
CiLOWER, CiLOWER, CiLOWER, CiLOWER,
CiLOWER, CiLOWER, CiLOWER, CiLOWER,
/* 0x70 */
CiLOWER, CiLOWER, CiLOWER, CiLOWER,
CiLOWER, CiLOWER, CiLOWER, CiLOWER,
CiLOWER, CiLOWER, CiLOWER, CiQCM,
CiQCL, CiQCM, CiQCM, CiCNTRL
CiLOWER, CiLOWER, CiLOWER, CiCURLY,
CiQCL, CiCURLY, CiQCM, CiCNTRL
};
void