diff --git a/check.t b/check.t index d11ba95..bd7f483 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.778 2017/04/20 20:50:09 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.779 2017/04/28 00:38:25 tg Exp $ # -*- mode: sh -*- #- # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, @@ -30,25 +30,43 @@ # (2013/12/02 20:39:44) http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date expected-stdout: - @(#)MIRBSD KSH R55 2017/04/20 + @(#)MIRBSD KSH R55 2017/04/27 description: Check version of shell. stdin: echo $KSH_VERSION name: KSH_VERSION -category: !shell:legacy-yes,!shell:textmode-yes +category: !shell:legacy-yes,!shell:textmode-yes,!shell:ebcdic-yes --- expected-stdout: - @(#)LEGACY KSH R55 2017/04/20 + @(#)LEGACY KSH R55 2017/04/27 description: Check version of legacy shell. stdin: echo $KSH_VERSION name: KSH_VERSION-legacy -category: !shell:legacy-no,!shell:textmode-yes +category: !shell:legacy-no,!shell:textmode-yes,!shell:ebcdic-yes --- expected-stdout: - @(#)MIRBSD KSH R55 2017/04/20 +TEXTMODE + @(#)MIRBSD KSH R55 2017/04/27 +EBCDIC +description: + Check version of shell. +stdin: + echo $KSH_VERSION +name: KSH_VERSION-ebcdic +category: !shell:legacy-yes,!shell:textmode-yes,!shell:ebcdic-no +--- +expected-stdout: + @(#)LEGACY KSH R55 2017/04/27 +EBCDIC +description: + Check version of legacy shell. +stdin: + echo $KSH_VERSION +name: KSH_VERSION-legacy-ebcdic +category: !shell:legacy-no,!shell:textmode-yes,!shell:ebcdic-no +--- +expected-stdout: + @(#)MIRBSD KSH R55 2017/04/27 +TEXTMODE description: Check version of shell. stdin: @@ -57,7 +75,7 @@ name: KSH_VERSION-textmode category: !shell:legacy-yes,!shell:textmode-no --- expected-stdout: - @(#)LEGACY KSH R55 2017/04/20 +TEXTMODE + @(#)LEGACY KSH R55 2017/04/27 +TEXTMODE description: Check version of legacy shell. stdin: @@ -11498,19 +11516,19 @@ expected-stdout: echo $(true) $((1+ 2)) ${ :;} ${| REPLY=x;} } inline_COMSUB_EXPRSUB_FUNSUB_VALSUB() { - \echo $(\true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;} + \echo $(\true ) $((1+ 2)) ${ \: ;} ${|REPLY=x ;} } function comsub_COMSUB_EXPRSUB_FUNSUB_VALSUB { x=$( echo $(true) $((1+ 2)) ${ :;} ${| REPLY=x;} ); } function comsub_COMSUB_EXPRSUB_FUNSUB_VALSUB { - x=$(\echo $(\true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;} ) + x=$(\echo $(\true ) $((1+ 2)) ${ \: ;} ${|REPLY=x ;} ) } function reread_COMSUB_EXPRSUB_FUNSUB_VALSUB { x=$(( echo $(true) $((1+ 2)) ${ :;} ${| REPLY=x;} )|tr u x); } function reread_COMSUB_EXPRSUB_FUNSUB_VALSUB { - x=$( ( \echo $(\true ) $((1+ 2)) ${ : ;} ${|REPLY=x ;} ) | \tr u x ) + x=$( ( \echo $(\true ) $((1+ 2)) ${ \: ;} ${|REPLY=x ;} ) | \tr u x ) } inline_QCHAR_OQUOTE_CQUOTE() { echo fo\ob\"a\`r\'b\$az diff --git a/edit.c b/edit.c index 5102ab0..c13053c 100644 --- a/edit.c +++ b/edit.c @@ -28,7 +28,7 @@ #ifndef MKSH_NO_CMDLINE_EDITING -__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.328 2017/04/27 23:12:44 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.329 2017/04/28 00:38:28 tg Exp $"); /* * in later versions we might use libtermcap for this, but since external @@ -649,8 +649,8 @@ x_cf_glob(int *flagsp, const char *buf, int buflen, int pos, int *startp, for (s = toglob; *s; s++) { if (*s == '\\' && s[1]) s++; - else if (*s == '?' || *s == '*' || *s == '[' || - *s == '$' || + else if (ctype(*s, C_QUEST | C_DOLAR) || + *s == '*' || *s == '[' || /* ?() *() +() @() !() but two already checked */ (s[1] == '(' /*)*/ && (*s == '+' || *s == '@' || *s == '!'))) { @@ -2901,7 +2901,7 @@ x_e_putc2(int c) { int width = 1; - if (c == '\r' || c == '\n') + if (ctype(c, C_CR | C_LF)) x_col = 0; if (x_col < xx_cols) { if (UTFMODE && (c > 0x7F)) { @@ -2942,7 +2942,7 @@ x_e_putc3(const char **cp) { int width = 1, c = **(const unsigned char **)cp; - if (c == '\r' || c == '\n') + if (ctype(c, C_CR | C_LF)) x_col = 0; if (x_col < xx_cols) { if (UTFMODE && (c > 0x7F)) { @@ -3674,7 +3674,7 @@ vi_hook(int ch) return (1); } } else { - if (ch == '\r' || ch == '\n') + if (ctype(ch, C_CR | C_LF)) return (1); cmdlen = 0; argc1 = 0; @@ -3776,7 +3776,7 @@ vi_hook(int ch) break; case VSEARCH: - if (ch == '\r' || ch == '\n' /*|| ch == CTRL('[')*/ ) { + if (ctype(ch, C_CR | C_LF) /* || ch == CTRL('[') */ ) { restore_cbuf(); /* Repeat last search? */ if (srchlen == 0) { @@ -3910,8 +3910,8 @@ vi_hook(int ch) break; case 0: if (insert != 0) { - if (lastcmd[0] == 's' || lastcmd[0] == 'c' || - lastcmd[0] == 'C') { + if (lastcmd[0] == 's' || + ksh_eq(lastcmd[0], 'C', 'c')) { if (redo_insert(1) != 0) vi_error(); } else { @@ -4040,8 +4040,7 @@ vi_insert(int ch) lastcmd[0] = 'a'; lastac = 1; } - if (lastcmd[0] == 's' || lastcmd[0] == 'c' || - lastcmd[0] == 'C') + if (lastcmd[0] == 's' || ksh_eq(lastcmd[0], 'C', 'c')) return (redo_insert(0)); else return (redo_insert(lastac - 1)); @@ -4200,8 +4199,7 @@ vi_cmd(int argcnt, const char *cmd) else { if ((ncursor = domove(argcnt, &cmd[1], 1)) < 0) return (-1); - if (*cmd == 'c' && - (cmd[1] == 'w' || cmd[1] == 'W') && + if (*cmd == 'c' && ksh_eq(cmd[1], 'W', 'w') && !ctype(vs->cbuf[vs->cursor], C_SPACE)) { do { --ncursor; @@ -4642,7 +4640,7 @@ domove(int argcnt, const char *cmd, int sub) case ';': if (fsavecmd == ' ') return (-1); - i = fsavecmd == 'f' || fsavecmd == 'F'; + i = ksh_eq(fsavecmd, 'F', 'f'); t = fsavecmd > 'a'; if (*cmd == ',') t = !t; diff --git a/eval.c b/eval.c index 615cd87..52390dc 100644 --- a/eval.c +++ b/eval.c @@ -23,7 +23,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.206 2017/04/27 23:12:46 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.207 2017/04/28 00:38:29 tg Exp $"); /* * string expansion @@ -507,7 +507,7 @@ expand( sp += (d ? d : p) - s - 1; if (!(stype & 0x180) && s[0] == CHAR && - (s[1] == '#' || s[1] == '%')) + ctype(s[1], C_SUB2)) fpat = s[1]; wpat = s + (fpat ? 2 : 0); wrep = d ? p : NULL; @@ -891,10 +891,7 @@ expand( --newlines; } else { while ((c = shf_getc(x.u.shf)) == 0 || -#ifdef MKSH_WITH_TEXTMODE - c == '\r' || -#endif - c == '\n') { + ctype(c, C_NL)) { #ifdef MKSH_WITH_TEXTMODE if (c == '\r') { c = shf_getc(x.u.shf); @@ -1131,7 +1128,7 @@ varsub(Expand *xp, const char *sp, const char *word, c = sp[1]; if (stype == '%' && c == '\0') return (-1); - if ((stype == '#' || stype == '%') && c != '\0') { + if (ctype(stype, C_SUB2) && c != '\0') { /* Can't have any modifiers for ${#...} or ${%...} */ if (*word != CSUBST) return (-1); @@ -1339,7 +1336,7 @@ varsub(Expand *xp, const char *sp, const char *word, (((stype & 0x80) ? *xp->str == '\0' : xp->str == null) && (state != XARG || (ifs0 || xp->split ? (xp->u.strv[0] == NULL) : !hasnonempty(xp->u.strv))) ? - c == '=' || c == '-' || c == '?' : c == '+'))) || + ctype(c, C_EQUAL | C_MINUS | C_QUEST) : c == '+'))) || stype == (0x80 | '0') || stype == (0x100 | '#') || stype == (0x100 | 'Q') || (stype & 0x7F) == '/') /* expand word instead of variable value */ @@ -1728,7 +1725,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) || - !ctype(*s & 0x7F, C_PATMO)) + !ctype(*s & 0x7F, C_PATMO | C_SPC)) *d++ = *s; else { /* extended pattern operators: *+?@! */ diff --git a/exec.c b/exec.c index 6307bce..f0149eb 100644 --- a/exec.c +++ b/exec.c @@ -23,7 +23,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.196 2017/04/12 16:46:21 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.197 2017/04/28 00:38:29 tg Exp $"); #ifndef MKSH_DEFAULT_EXECSHELL #define MKSH_DEFAULT_EXECSHELL MKSH_UNIXROOT "/bin/sh" @@ -885,7 +885,9 @@ scriptexec(struct op *tp, const char **ap) #ifndef MKSH_SMALL if ((fd = binopen2(tp->str, O_RDONLY)) >= 0) { unsigned char *cp; +#ifndef MKSH_EBCDIC unsigned short m; +#endif ssize_t n; #if defined(__OS2__) && defined(MKSH_WITH_TEXTMODE) @@ -905,7 +907,7 @@ scriptexec(struct op *tp, const char **ap) (buf[2] == 0xBF)) ? 3 : 0); /* scan for newline or NUL (end of buffer) */ - while (*cp && *cp != '\n') + while (!ctype(*cp, C_NL | C_NUL)) ++cp; /* if the shebang line is longer than MAXINTERP, bail out */ if (!*cp) @@ -920,13 +922,13 @@ scriptexec(struct op *tp, const char **ap) cp += 2; #ifdef __OS2__ else if (!strncmp(cp, Textproc, 7) && - (cp[7] == ' ' || cp[7] == '\t')) + ctype(cp[7], C_BLANK)) cp += 8; #endif else goto noshebang; /* skip whitespace before shell name */ - while (*cp == ' ' || *cp == '\t') + while (ctype(*cp, C_BLANK)) ++cp; /* just whitespace on the line? */ if (*cp == '\0') @@ -934,13 +936,13 @@ scriptexec(struct op *tp, const char **ap) /* no, we actually found an interpreter name */ sh = (char *)cp; /* look for end of shell/interpreter name */ - while (*cp != ' ' && *cp != '\t' && *cp != '\0') + while (!ctype(*cp, C_BLANK | C_NUL)) ++cp; /* any arguments? */ if (*cp) { *cp++ = '\0'; /* skip spaces before arguments */ - while (*cp == ' ' || *cp == '\t') + while (ctype(*cp, C_BLANK)) ++cp; /* pass it all in ONE argument (historic reasons) */ if (*cp) @@ -959,6 +961,7 @@ scriptexec(struct op *tp, const char **ap) #endif goto nomagic; noshebang: +#ifndef MKSH_EBCDIC m = buf[0] << 8 | buf[1]; if (m == 0x7F45 && buf[2] == 'L' && buf[3] == 'F') errorf("%s: not executable: %d-bit ELF file", tp->str, @@ -977,6 +980,7 @@ scriptexec(struct op *tp, const char **ap) buf[4] == 'Z') || (m == /* 7zip */ 0x377A) || (m == /* gzip */ 0x1F8B) || (m == /* .Z */ 0x1F9D)) errorf("%s: not executable: magic %04X", tp->str, m); +#endif #ifdef __OS2__ cp = _getext(tp->str); if (cp && (!stricmp(cp, ".cmd") || !stricmp(cp, ".bat"))) { diff --git a/funcs.c b/funcs.c index 635220f..c5fc184 100644 --- a/funcs.c +++ b/funcs.c @@ -38,7 +38,7 @@ #endif #endif -__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.347 2017/04/27 23:33:18 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.348 2017/04/28 00:38:30 tg Exp $"); #if HAVE_KILLPG /* @@ -807,7 +807,7 @@ c_alias(const char **wp) wp += builtin_opt.optind; if (!(builtin_opt.info & GI_MINUSMINUS) && *wp && - (wp[0][0] == '-' || wp[0][0] == '+') && wp[0][1] == '\0') { + ctype(wp[0][0], C_MINUS | C_PLUS) && wp[0][1] == '\0') { prefix = wp[0][0]; wp++; } diff --git a/lex.c b/lex.c index 69e8e6a..987f547 100644 --- a/lex.c +++ b/lex.c @@ -23,7 +23,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.236 2017/04/27 20:22:25 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.237 2017/04/28 00:38:31 tg Exp $"); /* * states while lexing word @@ -220,11 +220,11 @@ yylex(int cf) } else { /* normal lexing */ state = (cf & HEREDELIM) ? SHEREDELIM : SBASE; - while ((c = getsc()) == ' ' || c == '\t') + while (ctype((c = getsc()), C_BLANK)) ; if (c == '#') { ignore_backslash_newline++; - while ((c = getsc()) != '\0' && c != '\n') + while (!ctype((c = getsc()), C_NUL | C_LF)) ; ignore_backslash_newline--; } @@ -301,8 +301,7 @@ yylex(int cf) } /* FALLTHROUGH */ Sbase1: /* includes *(...|...) pattern (*+?@!) */ - if (c == '*' || c == '@' || c == '+' || c == '?' || - c == '!') { + if (ctype(c, C_PATMO)) { c2 = getsc(); if (c2 == '(' /*)*/ ) { *wp++ = OPAT; @@ -676,7 +675,7 @@ yylex(int cf) * emitted (in heredocquote:) */ if ((c = getsc()) == '"' || c == '\\' || - c == '$' || c == '`' || c == /*{*/'}') + ctype(c, C_DOLAR | C_GRAVE) || c == /*{*/'}') goto store_qchar; goto heredocquote; } @@ -893,7 +892,7 @@ yylex(int cf) dp = Xstring(ws, wp); if (state == SBASE && ( (c == '&' && !Flag(FSH) && !Flag(FPOSIX)) || - c == '<' || c == '>') && ((c2 = Xlength(ws, wp)) == 0 || + ctype(c, C_ANGLE)) && ((c2 = Xlength(ws, wp)) == 0 || (c2 == 2 && dp[0] == CHAR && ctype(dp[1], C_DIGIT)))) { struct ioword *iop = alloc(sizeof(struct ioword), ATEMP); @@ -1037,7 +1036,7 @@ yylex(int cf) const char *cp = source->str; /* prefer POSIX but not Korn functions over aliases */ - while (*cp == ' ' || *cp == '\t') + while (ctype(*cp, C_BLANK)) /* * this is like getsc() without skipping * over Source boundaries (including not @@ -1527,7 +1526,7 @@ pprompt(const char *cp, int ntruncate) for (; *cp; cp++) { if (indelimit && *cp != delimiter) ; - else if (*cp == '\n' || *cp == '\r') { + else if (ctype(*cp, C_CR | C_LF)) { lines += columns / x_cols + ((*cp == '\n') ? 1 : 0); columns = 0; } else if (*cp == '\t') { diff --git a/misc.c b/misc.c index 31685f4..00f880b 100644 --- a/misc.c +++ b/misc.c @@ -30,7 +30,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.263 2017/04/27 23:34:20 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.264 2017/04/28 00:38:31 tg Exp $"); #define KSH_CHVT_FLAG #ifdef MKSH_SMALL @@ -116,7 +116,7 @@ option(const char *n) { size_t i = 0; - if ((n[0] == '-' || n[0] == '+') && n[1] && !n[2]) + if (ctype(n[0], C_MINUS | C_PLUS) && n[1] && !n[2]) while (i < NELEM(options)) { if (OFC(i) == n[1]) return (i); @@ -452,7 +452,7 @@ parse_args(const char **argv, } } if (!(go.info & GI_MINUSMINUS) && argv[go.optind] && - (argv[go.optind][0] == '-' || argv[go.optind][0] == '+') && + ctype(argv[go.optind][0], C_MINUS | C_PLUS) && argv[go.optind][1] == '\0') { /* lone - clears -v and -x flags */ if (argv[go.optind][0] == '-') { @@ -703,7 +703,7 @@ has_globbing(const char *xp, const char *xpe) return (0); in_bracket = false; } - } else if ((c & 0x80) && ctype(c & 0x7F, C_PATMO)) { + } else if ((c & 0x80) && ctype(c & 0x7F, C_PATMO | C_SPC)) { 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) && ctype(*p & 0x7F, C_PATMO)) + if ((*p & 0x80) && ctype(*p & 0x7F, C_PATMO | C_SPC)) nest++; } return (NULL); @@ -1012,7 +1012,7 @@ ksh_getopt(const char **argv, Getopt *go, const char *optionsp) go->info |= flag == '-' ? GI_MINUS : GI_PLUS; } go->p++; - if (c == '?' || c == ':' || c == ';' || c == ',' || c == '#' || + if (ctype(c, C_QUEST | C_COLON | C_HASH) || c == ';' || c == ',' || !(o = cstrchr(optionsp, c))) { if (optionsp[0] == ':') { go->buf[0] = c; diff --git a/sh.h b/sh.h index 19ba4c5..8cb35dc 100644 --- a/sh.h +++ b/sh.h @@ -175,7 +175,7 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.819 2017/04/27 23:33:20 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.820 2017/04/28 00:38:32 tg Exp $"); #endif #define MKSH_VERSION "R55 2017/04/27" @@ -524,11 +524,17 @@ EXTERN const char *safe_prompt; /* safe prompt if PS1 substitution fails */ #else #define KSH_VERSIONNAME_TEXTMODE "" #endif +#ifdef MKSH_EBCDIC +#define KSH_VERSIONNAME_EBCDIC " +EBCDIC" +#else +#define KSH_VERSIONNAME_EBCDIC "" +#endif #ifndef KSH_VERSIONNAME_VENDOR_EXT #define KSH_VERSIONNAME_VENDOR_EXT "" #endif EXTERN const char initvsn[] E_INIT("KSH_VERSION=@(#)" KSH_VERSIONNAME_ISLEGACY \ - " KSH " MKSH_VERSION KSH_VERSIONNAME_TEXTMODE KSH_VERSIONNAME_VENDOR_EXT); + " KSH " MKSH_VERSION KSH_VERSIONNAME_EBCDIC KSH_VERSIONNAME_TEXTMODE \ + KSH_VERSIONNAME_VENDOR_EXT); #define KSH_VERSION (initvsn + /* "KSH_VERSION=@(#)" */ 16) EXTERN const char digits_uc[] E_INIT("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); @@ -1322,6 +1328,7 @@ EXTERN bool really_exit; #define CiBRACK BIT(29) /* ] */ #define CiUNDER BIT(30) /* _ */ #define CiGRAVE BIT(31) /* ` */ +/* out of space, but one for *@ would make sense, possibly others */ /* compile-time initialised, ASCII only */ extern const uint32_t tpl_ctypes[128]; @@ -1372,8 +1379,8 @@ EXTERN char ifs0; #define C_MFS (CiALIAS | CiANGLE | CiBRACK | 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!*+?@ pattern magical operator */ -#define C_PATMO (CiPLUS | CiQUEST | CiSP | CiVAR1) +/* !*+?@ pattern magical operator, except space */ +#define C_PATMO (CiPLUS | CiQUEST | CiVAR1) /* \x20‥~ POSIX printable characters (graph plus space) */ #define C_PRINT (C_GRAPH | CiSP) /* !"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ POSIX punctuation */ @@ -1394,9 +1401,12 @@ EXTERN char ifs0; #define C_VAR1 (CiHASH | CiMINUS | CiQUEST | CiSS | CiVAR1) /* individual chars you might like */ +#define C_ANGLE CiANGLE /* <> angle brackets */ #define C_COLON CiCOLON /* : colon */ +#define C_CR CiCR /* \x0D ASCII carriage return */ #define C_DOLAR CiSS /* $ dollar sign */ #define C_EQUAL CiEQUAL /* = equals sign */ +#define C_GRAVE CiGRAVE /* ` accent gravis */ #define C_HASH CiHASH /* # hash sign */ #define C_LF CiNL /* \x0A ASCII line feed */ #define C_MINUS CiMINUS /* - hyphen-minus */ @@ -1408,6 +1418,7 @@ EXTERN char ifs0; #define C_NUL CiNUL /* \x00 ASCII NUL */ #define C_PLUS CiPLUS /* + plus sign */ #define C_QC CiQC /* "' quote characters */ +#define C_QUEST CiQUEST /* ? question mark */ #define C_SPC CiSP /* \x20 ASCII space */ #define C_TAB CiTAB /* \x09 ASCII horizontal tabulator */ #define C_UNDER CiUNDER /* _ underscore */ @@ -2613,8 +2624,8 @@ extern int tty_init_fd(void); /* initialise tty_fd, tty_devtty */ }) #define mksh_vdirsep(s) (mksh_sdirsep((s)) != NULL) #else -#define mksh_abspath(s) ((s)[0] == '/') -#define mksh_cdirsep(c) ((c) == '/') +#define mksh_abspath(s) (ord((s)[0]) == ord('/')) +#define mksh_cdirsep(c) (ord(c) == ord('/')) #define mksh_sdirsep(s) strchr((s), '/') #define mksh_vdirsep(s) vstrchr((s), '/') #endif diff --git a/shf.c b/shf.c index c6bc45c..8e1c0a8 100644 --- a/shf.c +++ b/shf.c @@ -25,7 +25,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.84 2017/04/27 23:33:22 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.85 2017/04/28 00:38:33 tg Exp $"); /* flags to shf_emptybuf() */ #define EB_READSW 0x01 /* about to switch to reading */ @@ -1029,8 +1029,7 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args) if (!(flags & FL_RIGHT)) { /* skip past sign or 0x when padding with 0 */ if ((flags & FL_ZERO) && (flags & FL_NUMBER)) { - if (*s == '+' || *s == '-' || - *s == ' ') { + if (ctype(*s, C_SPC | C_PLUS | C_MINUS)) { shf_putc(*s, shf); s++; precision--; diff --git a/syn.c b/syn.c index 86dec5f..1a78aed 100644 --- a/syn.c +++ b/syn.c @@ -23,7 +23,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.122 2017/04/27 20:22:28 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.123 2017/04/28 00:38:33 tg Exp $"); struct nesting_state { int start_token; /* token than began nesting (eg, FOR) */ @@ -91,7 +91,7 @@ yyparse(bool doalias) c = tpeek(0); if (c == 0 && !outtree) outtree = newtp(TEOF); - else if (c != '\n' && c != 0) + else if (!ctype(c, C_LF | C_NUL)) syntaxerr(NULL); } diff --git a/tree.c b/tree.c index 1fd8f2a..04f64fe 100644 --- a/tree.c +++ b/tree.c @@ -23,7 +23,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.89 2017/04/12 16:46:23 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/tree.c,v 1.90 2017/04/28 00:38:33 tg Exp $"); #define INDENT 8 @@ -856,8 +856,8 @@ dumpwdvar_i(struct shf *shf, const char *wp, int quotelevel) case QCHAR: shf_puts("QCHAR<", shf); c = *wp++; - if (quotelevel == 0 || - (c == '"' || c == '`' || c == '$' || c == '\\')) + if (quotelevel == 0 || c == '"' || c == '\\' || + ctype(c, C_DOLAR | C_GRAVE)) shf_putc('\\', shf); dumpchar(shf, c); goto closeandout;