From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25098 invoked from network); 14 Dec 1998 22:44:37 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 14 Dec 1998 22:44:37 -0000 Received: (from list@localhost) by math.gatech.edu (8.9.1/8.9.1) id RAA21239; Mon, 14 Dec 1998 17:43:02 -0500 (EST) Resent-Date: Mon, 14 Dec 1998 17:43:02 -0500 (EST) From: "Bart Schaefer" Message-Id: <981214144133.ZM31396@candle.brasslantern.com> Date: Mon, 14 Dec 1998 14:41:33 -0800 X-Mailer: Z-Mail (4.0b.820 20aug96) To: zsh-workers@math.gatech.edu Subject: PATCH: 3.1.5-pws-3: Misc. associative array cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Resent-Message-ID: <"SlF6a1.0.oB5.sHPTs"@math> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/4789 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu This patch moves the set of SCANPM flags into zsh.h, renumbers all the PM flags to put PM_HASHED in a more sensible spot, and fixes up Phil Pennock's sethparam() to cover all the cases handled by setaparam(). Note that I'm further propagating the zerr();errflag=1; paranoia. Index: Src/builtin.c =================================================================== RCS file: /extra/cvsroot/zsh/zsh-3.1/Src/builtin.c,v retrieving revision 1.1.1.5 diff -u -r1.1.1.5 builtin.c --- builtin.c 1998/12/14 17:00:25 1.1.1.5 +++ builtin.c 1998/12/14 09:17:41 @@ -1469,7 +1469,7 @@ Param pm; Asgment asg; Comp com; - char *optstr = "aiLRZlurtxU----A"; + char *optstr = "aiALRZlurtxU"; int on = 0, off = 0, roff, bit = PM_ARRAY; int initon, initoff, of, i; int returnval = 0, printflags = 0; Index: Src/params.c =================================================================== RCS file: /extra/cvsroot/zsh/zsh-3.1/Src/params.c,v retrieving revision 1.1.1.4 diff -u -r1.1.1.4 params.c --- params.c 1998/12/14 17:00:28 1.1.1.4 +++ params.c 1998/12/14 09:17:44 @@ -301,14 +301,6 @@ return nht; } -#define SCANPM_WANTVALS (1<<0) -#define SCANPM_WANTKEYS (1<<1) -#define SCANPM_WANTINDEX (1<<2) /* Useful only if nested arrays */ -#define SCANPM_MATCHKEY (1<<3) -#define SCANPM_MATCHVAL (1<<4) -#define SCANPM_MATCHMANY (1<<5) -#define SCANPM_ISVAR_AT ((-1)<<15) /* Only sign bit is significant */ - static unsigned numparamvals; /**/ @@ -1546,35 +1538,37 @@ /**/ Param -sethparam(char *s, char **kvarr) +sethparam(char *s, char **val) { Value v; - Param pm; - char *t; + char *t = s; if (!isident(s)) { zerr("not an identifier: %s", s, 0); - freearray(kvarr); + freearray(val); errflag = 1; return NULL; } - t=ztrdup(s); /* Is this a memory leak? */ - /* Why does getvalue(s, 1) set s to empty string? */ - if ((v = getvalue(&t, 1))) - if (v->pm->flags & PM_SPECIAL) { - zerr("not overriding a special: %s", s, 0); - freearray(kvarr); - errflag = 1; + if (strchr(s, '[')) { + freearray(val); + zerr("attempt to set slice of associative array", NULL, 0); + errflag = 1; + return NULL; + } else { + if (!(v = getvalue(&s, 1))) + createparam(t, PM_HASHED); + else if (!(PM_TYPE(v->pm->flags) & (PM_ARRAY|PM_HASHED)) && + !(v->pm->flags & PM_SPECIAL)) { + unsetparam(t); + createparam(t, PM_HASHED); + v = NULL; + } + } + if (!v) + if (!(v = getvalue(&t, 1))) return NULL; - } else - unsetparam(s); - - pm = createparam(s, PM_HASHED); - DPUTS(!pm, "BUG: parameter not created"); - - arrhashsetfn(pm, kvarr); - - return pm; + setarrvalue(v, val); + return v->pm; } /**/ Index: Src/zsh.h =================================================================== RCS file: /extra/cvsroot/zsh/zsh-3.1/Src/zsh.h,v retrieving revision 1.1.1.5 diff -u -r1.1.1.5 zsh.h --- zsh.h 1998/12/14 17:00:31 1.1.1.5 +++ zsh.h 1998/12/14 22:22:55 @@ -890,28 +890,37 @@ #define PM_SCALAR 0 /* scalar */ #define PM_ARRAY (1<<0) /* array */ #define PM_INTEGER (1<<1) /* integer */ -#define PM_HASHED (1<<15) /* association */ +#define PM_HASHED (1<<2) /* association */ #define PM_TYPE(X) (X & (PM_SCALAR|PM_INTEGER|PM_ARRAY|PM_HASHED)) -#define PM_LEFT (1<<2) /* left justify and remove leading blanks */ -#define PM_RIGHT_B (1<<3) /* right justify and fill with leading blanks */ -#define PM_RIGHT_Z (1<<4) /* right justify and fill with leading zeros */ -#define PM_LOWER (1<<5) /* all lower case */ +#define PM_LEFT (1<<3) /* left justify and remove leading blanks */ +#define PM_RIGHT_B (1<<4) /* right justify and fill with leading blanks */ +#define PM_RIGHT_Z (1<<5) /* right justify and fill with leading zeros */ +#define PM_LOWER (1<<6) /* all lower case */ /* The following are the same since they * * both represent -u option to typeset */ -#define PM_UPPER (1<<6) /* all upper case */ -#define PM_UNDEFINED (1<<6) /* undefined (autoloaded) shell function */ +#define PM_UPPER (1<<7) /* all upper case */ +#define PM_UNDEFINED (1<<7) /* undefined (autoloaded) shell function */ -#define PM_READONLY (1<<7) /* readonly */ -#define PM_TAGGED (1<<8) /* tagged */ -#define PM_EXPORTED (1<<9) /* exported */ -#define PM_UNIQUE (1<<10) /* remove duplicates */ -#define PM_SPECIAL (1<<11) /* special builtin parameter */ -#define PM_DONTIMPORT (1<<12) /* do not import this variable */ -#define PM_RESTRICTED (1<<13) /* cannot be changed in restricted mode */ -#define PM_UNSET (1<<14) /* has null value */ +#define PM_READONLY (1<<8) /* readonly */ +#define PM_TAGGED (1<<9) /* tagged */ +#define PM_EXPORTED (1<<10) /* exported */ +#define PM_UNIQUE (1<<11) /* remove duplicates */ +#define PM_SPECIAL (1<<12) /* special builtin parameter */ +#define PM_DONTIMPORT (1<<13) /* do not import this variable */ +#define PM_RESTRICTED (1<<14) /* cannot be changed in restricted mode */ +#define PM_UNSET (1<<15) /* has null value */ + +/* Flags for extracting elements of arrays and associative arrays */ +#define SCANPM_WANTVALS (1<<0) +#define SCANPM_WANTKEYS (1<<1) +#define SCANPM_WANTINDEX (1<<2) /* Presently unused */ +#define SCANPM_MATCHKEY (1<<3) +#define SCANPM_MATCHVAL (1<<4) +#define SCANPM_MATCHMANY (1<<5) +#define SCANPM_ISVAR_AT ((-1)<<15) /* Only sign bit is significant */ /* * Flags for doing matches inside parameter substitutions, i.e. -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com