make set_refflag an enum to get easier to understand code
This commit is contained in:
parent
fab3be3584
commit
c57f8ede17
18
funcs.c
18
funcs.c
@ -38,7 +38,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#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
|
#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 **);
|
static int c_android_lsmod(const char **);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern uint8_t set_refflag;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A leading = means assignments before command are kept;
|
* A leading = means assignments before command are kept;
|
||||||
* a leading * means a POSIX special builtin;
|
* a leading * means a POSIX special builtin;
|
||||||
@ -691,7 +689,8 @@ c_typeset(const char **wp)
|
|||||||
flag = LCASEV;
|
flag = LCASEV;
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
set_refflag = (builtin_opt.info & GI_PLUS) ? 2 : 1;
|
set_refflag = (builtin_opt.info & GI_PLUS) ?
|
||||||
|
SRF_DISABLE : SRF_ENABLE;
|
||||||
break;
|
break;
|
||||||
/* export, readonly: POSIX -p flag */
|
/* export, readonly: POSIX -p flag */
|
||||||
case 'p':
|
case 'p':
|
||||||
@ -742,9 +741,10 @@ c_typeset(const char **wp)
|
|||||||
builtin_opt.optind++;
|
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");
|
bi_errorf("only -t, -u and -x options may be used with -f");
|
||||||
set_refflag = 0;
|
set_refflag = SRF_NOP;
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
if (wp[builtin_opt.optind]) {
|
if (wp[builtin_opt.optind]) {
|
||||||
@ -769,7 +769,7 @@ c_typeset(const char **wp)
|
|||||||
* are also set in this command
|
* are also set in this command
|
||||||
*/
|
*/
|
||||||
if ((fset & (LJUST | RJUST | ZEROFIL | UCASEV_AL | LCASEV |
|
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 |
|
fclr |= ~fset & (LJUST | RJUST | ZEROFIL | UCASEV_AL |
|
||||||
LCASEV | INTEGER | INT_U | INT_L);
|
LCASEV | INTEGER | INT_U | INT_L);
|
||||||
}
|
}
|
||||||
@ -801,11 +801,11 @@ c_typeset(const char **wp)
|
|||||||
}
|
}
|
||||||
} else if (!typeset(wp[i], fset, fclr, field, base)) {
|
} else if (!typeset(wp[i], fset, fclr, field, base)) {
|
||||||
bi_errorf("%s: %s", wp[i], "not identifier");
|
bi_errorf("%s: %s", wp[i], "not identifier");
|
||||||
set_refflag = 0;
|
set_refflag = SRF_NOP;
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
set_refflag = 0;
|
set_refflag = SRF_NOP;
|
||||||
return (rv);
|
return (rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
8
sh.h
8
sh.h
@ -151,7 +151,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EXTERN
|
#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
|
#endif
|
||||||
#define MKSH_VERSION "R40 2011/06/12"
|
#define MKSH_VERSION "R40 2011/06/12"
|
||||||
|
|
||||||
@ -1017,6 +1017,12 @@ struct tbl { /* table item */
|
|||||||
#define arrayindex(vp) ((unsigned long)((vp)->flag & AINDEX ? \
|
#define arrayindex(vp) ((unsigned long)((vp)->flag & AINDEX ? \
|
||||||
(vp)->ua.index : 0))
|
(vp)->ua.index : 0))
|
||||||
|
|
||||||
|
EXTERN enum {
|
||||||
|
SRF_NOP,
|
||||||
|
SRF_ENABLE,
|
||||||
|
SRF_DISABLE
|
||||||
|
} set_refflag I__(SRF_NOP);
|
||||||
|
|
||||||
/* command types */
|
/* command types */
|
||||||
#define CNONE 0 /* undefined */
|
#define CNONE 0 /* undefined */
|
||||||
#define CSHELL 1 /* built-in */
|
#define CSHELL 1 /* built-in */
|
||||||
|
12
var.c
12
var.c
@ -26,7 +26,7 @@
|
|||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
#endif
|
#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
|
* Variables
|
||||||
@ -53,8 +53,6 @@ static int getint(struct tbl *, mksh_ari_t *, bool);
|
|||||||
static mksh_ari_t intval(struct tbl *);
|
static mksh_ari_t intval(struct tbl *);
|
||||||
static const char *array_index_calc(const char *, bool *, uint32_t *);
|
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
|
* create a new block for function calls and simple commands
|
||||||
* assume caller has allocated and set up e->loc
|
* 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;
|
*arrayp = false;
|
||||||
redo_from_ref:
|
redo_from_ref:
|
||||||
p = skip_varname(n, false);
|
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;
|
struct tbl *vp;
|
||||||
char *vn;
|
char *vn;
|
||||||
|
|
||||||
@ -713,7 +711,7 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base)
|
|||||||
mkssert(var != NULL);
|
mkssert(var != NULL);
|
||||||
mkssert(*var != 0);
|
mkssert(*var != 0);
|
||||||
if (*val == '[') {
|
if (*val == '[') {
|
||||||
if (set_refflag)
|
if (set_refflag != SRF_NOP)
|
||||||
errorf("%s: %s", var,
|
errorf("%s: %s", var,
|
||||||
"reference variable can't be an array");
|
"reference variable can't be an array");
|
||||||
len = array_ref_len(val);
|
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)) :
|
vp = (set&LOCAL) ? local(tvar, tobool(set & LOCAL_COPY)) :
|
||||||
global(tvar);
|
global(tvar);
|
||||||
if (set_refflag == 2 && (vp->flag & (ARRAY|ASSOC)) == ASSOC)
|
if (set_refflag == SRF_DISABLE && (vp->flag & (ARRAY|ASSOC)) == ASSOC)
|
||||||
vp->flag &= ~ASSOC;
|
vp->flag &= ~ASSOC;
|
||||||
else if (set_refflag == 1) {
|
else if (set_refflag == SRF_ENABLE) {
|
||||||
if (vp->flag & ARRAY) {
|
if (vp->flag & ARRAY) {
|
||||||
struct tbl *a, *tmp;
|
struct tbl *a, *tmp;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user