some ord() debugging; CORD for case, ORD evaluates twice, for debugging

This commit is contained in:
tg
2018-01-13 23:55:15 +00:00
parent a0b1179db3
commit dde8500a24
11 changed files with 502 additions and 464 deletions

42
var.c
View File

@@ -28,7 +28,7 @@
#include <sys/sysctl.h>
#endif
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.222 2018/01/13 21:38:10 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.223 2018/01/13 23:55:15 tg Exp $");
/*-
* Variables
@@ -204,7 +204,7 @@ array_index_calc(const char *n, bool *arrayp, uint32_t *valp)
}
innermost_refflag = SRF_NOP;
if (p != n && ord(*p) == ord('[') && (len = array_ref_len(p))) {
if (p != n && ord(*p) == ORD('[') && (len = array_ref_len(p))) {
char *sub, *tmp;
mksh_ari_t rval;
@@ -780,7 +780,7 @@ typeset(const char *var, uint32_t set, uint32_t clr, int field, int base)
/* no variable name given */
return (NULL);
}
if (ord(*val) == ord('[')) {
if (ord(*val) == ORD('[')) {
if (new_refflag != SRF_NOP)
errorf(Tf_sD_s, var,
"reference variable can't be an array");
@@ -803,13 +803,13 @@ typeset(const char *var, uint32_t set, uint32_t clr, int field, int base)
}
val += len;
}
if (ord(val[0]) == ord('=')) {
if (ord(val[0]) == ORD('=')) {
strndupx(tvar, var, val - var, ATEMP);
++val;
} else if (set & IMPORT) {
/* environment invalid variable name or no assignment */
return (NULL);
} else if (ord(val[0]) == ord('+') && ord(val[1]) == ord('=')) {
} else if (ord(val[0]) == ORD('+') && ord(val[1]) == ORD('=')) {
strndupx(tvar, var, val - var, ATEMP);
val += 2;
vappend = true;
@@ -822,9 +822,9 @@ typeset(const char *var, uint32_t set, uint32_t clr, int field, int base)
val = NULL;
/* handle foo[*] => foo (whole array) mapping for R39b */
len = strlen(tvar);
if (len > 3 && ord(tvar[len - 3]) == ord('[') &&
ord(tvar[len - 2]) == ord('*') &&
ord(tvar[len - 1]) == ord(']'))
if (len > 3 && ord(tvar[len - 3]) == ORD('[') &&
ord(tvar[len - 2]) == ORD('*') &&
ord(tvar[len - 1]) == ORD(']'))
tvar[len - 3] = '\0';
}
@@ -861,7 +861,7 @@ typeset(const char *var, uint32_t set, uint32_t clr, int field, int base)
nameref_empty:
errorf(Tf_sD_s, var, "empty nameref target");
}
len = (ord(*ccp) == ord('[')) ? array_ref_len(ccp) : 0;
len = (ord(*ccp) == ORD('[')) ? array_ref_len(ccp) : 0;
if (ccp[len]) {
/*
* works for cases "no array", "valid array with
@@ -1071,7 +1071,7 @@ skip_varname(const char *s, bool aok)
do {
++s;
} while (ctype(*s, C_ALNUX));
if (aok && ord(*s) == ord('[') && (alen = array_ref_len(s)))
if (aok && ord(*s) == ORD('[') && (alen = array_ref_len(s)))
s += alen;
}
return (s);
@@ -1087,7 +1087,7 @@ skip_wdvarname(const char *s,
do {
s += 2;
} while (s[0] == CHAR && ctype(s[1], C_ALNUX));
if (aok && s[0] == CHAR && ord(s[1]) == ord('[')) {
if (aok && s[0] == CHAR && ord(s[1]) == ORD('[')) {
/* skip possible array de-reference */
const char *p = s;
char c;
@@ -1098,9 +1098,9 @@ skip_wdvarname(const char *s,
break;
c = p[1];
p += 2;
if (ord(c) == ord('['))
if (ord(c) == ORD('['))
depth++;
else if (ord(c) == ord(']') && --depth == 0) {
else if (ord(c) == ORD(']') && --depth == 0) {
s = p;
break;
}
@@ -1308,7 +1308,7 @@ setspec(struct tbl *vp)
if (!(vp->flag&INTEGER)) {
s = str_val(vp);
do {
if (*s == ord('\\'))
if (*s == ORD('\\'))
*s = '/';
} while (*s++);
}
@@ -1562,8 +1562,8 @@ array_ref_len(const char *cp)
char c;
int depth = 0;
while ((c = *s++) && (ord(c) != ord(']') || --depth))
if (ord(c) == ord('['))
while ((c = *s++) && (ord(c) != ORD(']') || --depth))
if (ord(c) == ORD('['))
depth++;
if (!c)
return (0);
@@ -1635,18 +1635,18 @@ set_array(const char *var, bool reset, const char **vals)
}
while ((ccp = vals[i])) {
#if 0 /* temporarily taken out due to regression */
if (ord(*ccp) == ord('[')) {
if (ord(*ccp) == ORD('[')) {
int level = 0;
while (*ccp) {
if (ord(*ccp) == ord(']') && --level == 0)
if (ord(*ccp) == ORD(']') && --level == 0)
break;
if (ord(*ccp) == ord('['))
if (ord(*ccp) == ORD('['))
++level;
++ccp;
}
if (ord(*ccp) == ord(']') && level == 0 &&
ord(ccp[1]) == ord('=')) {
if (ord(*ccp) == ORD(']') && level == 0 &&
ord(ccp[1]) == ORD('=')) {
strndupx(cp, vals[i] + 1, ccp - (vals[i] + 1),
ATEMP);
evaluate(substitute(cp, 0), (mksh_ari_t *)&j,