write ord’ed into c

This commit is contained in:
tg 2018-01-14 01:29:47 +00:00
parent f7b0277504
commit cc59adb1f5
2 changed files with 22 additions and 20 deletions

32
eval.c
View File

@ -23,7 +23,7 @@
#include "sh.h" #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 * string expansion
@ -582,7 +582,7 @@ expand(
while (p >= sbeg) { while (p >= sbeg) {
bool gotmatch; bool gotmatch;
c = *p; c = ord(*p);
*p = '\0'; *p = '\0';
gotmatch = tobool(gmatchx(sbeg, pat, false)); gotmatch = tobool(gmatchx(sbeg, pat, false));
*p = c; *p = c;
@ -791,19 +791,19 @@ expand(
/* open pattern: *(foo|bar) */ /* open pattern: *(foo|bar) */
/* Next char is the type of pattern */ /* Next char is the type of pattern */
make_magic = true; make_magic = true;
c = *sp++ | 0x80; c = ord(*sp++) | 0x80U;
break; break;
case SPAT: case SPAT:
/* pattern separator (|) */ /* pattern separator (|) */
make_magic = true; make_magic = true;
c = '|'; c = ORD('|');
break; break;
case CPAT: case CPAT:
/* close pattern */ /* close pattern */
make_magic = true; make_magic = true;
c = /*(*/ ')'; c = ORD(/*(*/ ')');
break; break;
} }
break; break;
@ -824,7 +824,7 @@ expand(
case XSUB: case XSUB:
case XSUBMID: case XSUBMID:
if ((c = *x.str++) == 0) { if ((c = ord(*x.str++)) == 0) {
type = XBASE; type = XBASE;
if (f & DOBLANK) if (f & DOBLANK)
doblank--; doblank--;
@ -837,7 +837,7 @@ expand(
quote = 1; quote = 1;
/* FALLTHROUGH */ /* FALLTHROUGH */
case XARG: case XARG:
if ((c = *x.str++) == '\0') { if ((c = ord(*x.str++)) == '\0') {
/* /*
* force null words to be created so * force null words to be created so
* set -- "" 2 ""; echo "$@" will do * set -- "" 2 ""; echo "$@" will do
@ -855,13 +855,13 @@ expand(
if ((f & DOHEREDOC)) { if ((f & DOHEREDOC)) {
/* pseudo-field-split reliably */ /* pseudo-field-split reliably */
if (c == 0) if (c == 0)
c = ' '; c = ORD(' ');
break; break;
} }
if ((f & DOSCALAR)) { if ((f & DOSCALAR)) {
/* do not field-split */ /* do not field-split */
if (x.split) { if (x.split) {
c = ' '; c = ORD(' ');
break; break;
} }
if (c == 0) if (c == 0)
@ -873,7 +873,7 @@ expand(
if (!quote && word == IFS_WS) if (!quote && word == IFS_WS)
continue; continue;
/* this is so we don't terminate */ /* this is so we don't terminate */
c = ' '; c = ORD(' ');
/* now force-emit a word */ /* now force-emit a word */
goto emit_word; goto emit_word;
} }
@ -893,33 +893,33 @@ expand(
c = -1; c = -1;
} else if (newlines) { } else if (newlines) {
/* spit out saved NLs */ /* spit out saved NLs */
c = '\n'; c = ORD('\n');
--newlines; --newlines;
} else { } else {
while ((c = shf_getc(x.u.shf)) == 0 || while ((c = shf_getc(x.u.shf)) == 0 ||
cinttype(c, C_NL)) { cinttype(c, C_NL)) {
#ifdef MKSH_WITH_TEXTMODE #ifdef MKSH_WITH_TEXTMODE
if (c == '\r') { if (c == ORD('\r')) {
c = shf_getc(x.u.shf); c = shf_getc(x.u.shf);
switch (c) { switch (c) {
case '\n': case ORD('\n'):
break; break;
default: default:
shf_ungetc(c, x.u.shf); shf_ungetc(c, x.u.shf);
/* FALLTHROUGH */ /* FALLTHROUGH */
case -1: case -1:
c = '\r'; c = ORD('\r');
break; break;
} }
} }
#endif #endif
if (c == '\n') if (c == ORD('\n'))
/* save newlines */ /* save newlines */
newlines++; newlines++;
} }
if (newlines && c != -1) { if (newlines && c != -1) {
shf_ungetc(c, x.u.shf); shf_ungetc(c, x.u.shf);
c = '\n'; c = ORD('\n');
--newlines; --newlines;
} }
} }

10
expr.c
View File

@ -2,7 +2,7 @@
/*- /*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
* 2011, 2012, 2013, 2014, 2016, 2017 * 2011, 2012, 2013, 2014, 2016, 2017, 2018
* mirabilos <m@mirbsd.org> * mirabilos <m@mirbsd.org>
* *
* Provided that these terms and disclaimer and all copyright notices * Provided that these terms and disclaimer and all copyright notices
@ -23,7 +23,7 @@
#include "sh.h" #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 #define EXPRTOK_DEFNS
#include "exprtok.h" #include "exprtok.h"
@ -558,8 +558,10 @@ exprtoken(Expr_state *es)
/* skip whitespace */ /* skip whitespace */
skip_spaces: 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('#')) { if (es->tokp == es->expression && (unsigned int)c == ORD('#')) {
/* expression begins with # */ /* expression begins with # */
/* switch to unsigned */ /* switch to unsigned */