From cc59adb1f527d18aa946e5aa287f457f232a1c52 Mon Sep 17 00:00:00 2001 From: tg Date: Sun, 14 Jan 2018 01:29:47 +0000 Subject: [PATCH] =?UTF-8?q?write=20ord=E2=80=99ed=20into=20c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eval.c | 32 ++++++++++++++++---------------- expr.c | 10 ++++++---- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/eval.c b/eval.c index 4bcc2fe..6aa1844 100644 --- a/eval.c +++ b/eval.c @@ -23,7 +23,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.218 2018/01/14 00:22:27 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.219 2018/01/14 01:29:47 tg Exp $"); /* * string expansion @@ -582,7 +582,7 @@ expand( while (p >= sbeg) { bool gotmatch; - c = *p; + c = ord(*p); *p = '\0'; gotmatch = tobool(gmatchx(sbeg, pat, false)); *p = c; @@ -791,19 +791,19 @@ expand( /* open pattern: *(foo|bar) */ /* Next char is the type of pattern */ make_magic = true; - c = *sp++ | 0x80; + c = ord(*sp++) | 0x80U; break; case SPAT: /* pattern separator (|) */ make_magic = true; - c = '|'; + c = ORD('|'); break; case CPAT: /* close pattern */ make_magic = true; - c = /*(*/ ')'; + c = ORD(/*(*/ ')'); break; } break; @@ -824,7 +824,7 @@ expand( case XSUB: case XSUBMID: - if ((c = *x.str++) == 0) { + if ((c = ord(*x.str++)) == 0) { type = XBASE; if (f & DOBLANK) doblank--; @@ -837,7 +837,7 @@ expand( quote = 1; /* FALLTHROUGH */ case XARG: - if ((c = *x.str++) == '\0') { + if ((c = ord(*x.str++)) == '\0') { /* * force null words to be created so * set -- "" 2 ""; echo "$@" will do @@ -855,13 +855,13 @@ expand( if ((f & DOHEREDOC)) { /* pseudo-field-split reliably */ if (c == 0) - c = ' '; + c = ORD(' '); break; } if ((f & DOSCALAR)) { /* do not field-split */ if (x.split) { - c = ' '; + c = ORD(' '); break; } if (c == 0) @@ -873,7 +873,7 @@ expand( if (!quote && word == IFS_WS) continue; /* this is so we don't terminate */ - c = ' '; + c = ORD(' '); /* now force-emit a word */ goto emit_word; } @@ -893,33 +893,33 @@ expand( c = -1; } else if (newlines) { /* spit out saved NLs */ - c = '\n'; + c = ORD('\n'); --newlines; } else { while ((c = shf_getc(x.u.shf)) == 0 || cinttype(c, C_NL)) { #ifdef MKSH_WITH_TEXTMODE - if (c == '\r') { + if (c == ORD('\r')) { c = shf_getc(x.u.shf); switch (c) { - case '\n': + case ORD('\n'): break; default: shf_ungetc(c, x.u.shf); /* FALLTHROUGH */ case -1: - c = '\r'; + c = ORD('\r'); break; } } #endif - if (c == '\n') + if (c == ORD('\n')) /* save newlines */ newlines++; } if (newlines && c != -1) { shf_ungetc(c, x.u.shf); - c = '\n'; + c = ORD('\n'); --newlines; } } diff --git a/expr.c b/expr.c index 9a9eeba..499b961 100644 --- a/expr.c +++ b/expr.c @@ -2,7 +2,7 @@ /*- * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, - * 2011, 2012, 2013, 2014, 2016, 2017 + * 2011, 2012, 2013, 2014, 2016, 2017, 2018 * mirabilos * * Provided that these terms and disclaimer and all copyright notices @@ -23,7 +23,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.102 2018/01/13 23:55:10 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.103 2018/01/14 01:29:47 tg Exp $"); #define EXPRTOK_DEFNS #include "exprtok.h" @@ -558,8 +558,10 @@ exprtoken(Expr_state *es) /* skip whitespace */ skip_spaces: - while (ctype((c = *cp), C_SPACE)) - ++cp; + --cp; + do { + c = ord(*++cp); + } while (ctype(c, C_SPACE)); if (es->tokp == es->expression && (unsigned int)c == ORD('#')) { /* expression begins with # */ /* switch to unsigned */