pretty tricky thing, IBM’s curses library does nameref foo=foo…

This commit is contained in:
tg
2011-06-21 21:50:26 +00:00
parent c57f8ede17
commit 43c8d8765f
3 changed files with 41 additions and 5 deletions

21
var.c
View File

@ -26,7 +26,7 @@
#include <sys/sysctl.h>
#endif
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.125 2011/06/21 21:11:21 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.126 2011/06/21 21:50:26 tg Exp $");
/*-
* Variables
@ -751,6 +751,25 @@ typeset(const char *var, Tflag set, Tflag clr, int field, int base)
tvar[len-3] = '\0';
}
if (set_refflag == SRF_ENABLE) {
const char *qval;
/* bail out on 'nameref foo+=bar' */
if (vappend)
errorfz();
/* find value if variable already exists */
if ((qval = val) == NULL) {
varsearch(e->loc, &vp, tvar, hash(tvar));
if (vp != NULL)
qval = str_val(vp);
}
/* silently ignore 'nameref foo=foo' */
if (qval != NULL && !strcmp(qval, tvar)) {
afree(tvar, ATEMP);
return (&vtemp);
}
}
/* prevent typeset from creating a local PATH/ENV/SHELL */
if (Flag(FRESTRICTED) && (strcmp(tvar, "PATH") == 0 ||
strcmp(tvar, "ENV") == 0 || strcmp(tvar, "SHELL") == 0))