diff --git a/funcs.c b/funcs.c index a9b7138..eb37fad 100644 --- a/funcs.c +++ b/funcs.c @@ -38,7 +38,7 @@ #endif #endif -__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.189 2011/06/11 03:14:49 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.190 2011/06/21 21:11:19 tg Exp $"); #if HAVE_KILLPG /* @@ -64,8 +64,6 @@ __RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.189 2011/06/11 03:14:49 tg Exp $"); static int c_android_lsmod(const char **); #endif -extern uint8_t set_refflag; - /* * A leading = means assignments before command are kept; * a leading * means a POSIX special builtin; @@ -691,7 +689,8 @@ c_typeset(const char **wp) flag = LCASEV; break; case 'n': - set_refflag = (builtin_opt.info & GI_PLUS) ? 2 : 1; + set_refflag = (builtin_opt.info & GI_PLUS) ? + SRF_DISABLE : SRF_ENABLE; break; /* export, readonly: POSIX -p flag */ case 'p': @@ -742,9 +741,10 @@ c_typeset(const char **wp) builtin_opt.optind++; } - if (func && (((fset|fclr) & ~(TRACE|UCASEV_AL|EXPORT)) || set_refflag)) { + if (func && (((fset|fclr) & ~(TRACE|UCASEV_AL|EXPORT)) || + set_refflag != SRF_NOP)) { bi_errorf("only -t, -u and -x options may be used with -f"); - set_refflag = 0; + set_refflag = SRF_NOP; return (1); } if (wp[builtin_opt.optind]) { @@ -769,7 +769,7 @@ c_typeset(const char **wp) * are also set in this command */ if ((fset & (LJUST | RJUST | ZEROFIL | UCASEV_AL | LCASEV | - INTEGER | INT_U | INT_L)) || set_refflag) + INTEGER | INT_U | INT_L)) || set_refflag != SRF_NOP) fclr |= ~fset & (LJUST | RJUST | ZEROFIL | UCASEV_AL | LCASEV | INTEGER | INT_U | INT_L); } @@ -801,11 +801,11 @@ c_typeset(const char **wp) } } else if (!typeset(wp[i], fset, fclr, field, base)) { bi_errorf("%s: %s", wp[i], "not identifier"); - set_refflag = 0; + set_refflag = SRF_NOP; return (1); } } - set_refflag = 0; + set_refflag = SRF_NOP; return (rv); } diff --git a/sh.h b/sh.h index f9b2397..9980900 100644 --- a/sh.h +++ b/sh.h @@ -151,7 +151,7 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.477 2011/06/21 21:10:12 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.478 2011/06/21 21:11:20 tg Exp $"); #endif #define MKSH_VERSION "R40 2011/06/12" @@ -1017,6 +1017,12 @@ struct tbl { /* table item */ #define arrayindex(vp) ((unsigned long)((vp)->flag & AINDEX ? \ (vp)->ua.index : 0)) +EXTERN enum { + SRF_NOP, + SRF_ENABLE, + SRF_DISABLE +} set_refflag I__(SRF_NOP); + /* command types */ #define CNONE 0 /* undefined */ #define CSHELL 1 /* built-in */ diff --git a/var.c b/var.c index bc7a203..8b7249e 100644 --- a/var.c +++ b/var.c @@ -26,7 +26,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/var.c,v 1.124 2011/06/21 21:08:50 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/var.c,v 1.125 2011/06/21 21:11:21 tg Exp $"); /*- * Variables @@ -53,8 +53,6 @@ static int getint(struct tbl *, mksh_ari_t *, bool); static mksh_ari_t intval(struct tbl *); static const char *array_index_calc(const char *, bool *, uint32_t *); -uint8_t set_refflag = 0; - /* * create a new block for function calls and simple commands * assume caller has allocated and set up e->loc @@ -179,7 +177,7 @@ array_index_calc(const char *n, bool *arrayp, uint32_t *valp) *arrayp = false; redo_from_ref: p = skip_varname(n, false); - if (!set_refflag && (p != n) && ksh_isalphx(n[0])) { + if (set_refflag == SRF_NOP && (p != n) && ksh_isalphx(n[0])) { struct tbl *vp; char *vn; @@ -713,7 +711,7 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base) mkssert(var != NULL); mkssert(*var != 0); if (*val == '[') { - if (set_refflag) + if (set_refflag != SRF_NOP) errorf("%s: %s", var, "reference variable can't be an array"); len = array_ref_len(val); @@ -760,9 +758,9 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base) vp = (set&LOCAL) ? local(tvar, tobool(set & LOCAL_COPY)) : global(tvar); - if (set_refflag == 2 && (vp->flag & (ARRAY|ASSOC)) == ASSOC) + if (set_refflag == SRF_DISABLE && (vp->flag & (ARRAY|ASSOC)) == ASSOC) vp->flag &= ~ASSOC; - else if (set_refflag == 1) { + else if (set_refflag == SRF_ENABLE) { if (vp->flag & ARRAY) { struct tbl *a, *tmp;