From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7490 invoked from network); 14 Dec 1998 02:19:46 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 14 Dec 1998 02:19:46 -0000 Received: (from list@localhost) by math.gatech.edu (8.9.1/8.9.1) id VAA23920; Sun, 13 Dec 1998 21:18:10 -0500 (EST) Resent-Date: Sun, 13 Dec 1998 21:18:10 -0500 (EST) From: "Bart Schaefer" Message-Id: <981213181706.ZM16878@candle.brasslantern.com> Date: Sun, 13 Dec 1998 18:17:06 -0800 X-Mailer: Z-Mail (4.0b.820 20aug96) To: zsh-workers@math.gatech.edu Subject: PATCH: 3.1.5 + associative arrays: printing of parameters MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Resent-Message-ID: <"uceVH1.0.er5.XL7Ts"@math> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/4764 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu This fixes the output of e.g. "typeset" (with no args) or "typeset -A" to print associative arrays in a format that can be fed back to the shell as an assignment. Previously, "typeset" output for AAs looked like association foo=(bambam=pebbles fred=wilma barney=betty ) which could be confusing for "typeset | grep" etc., besides being invalid syntax for an assignment. After this patch, it looks like association foo=(bambam pebbles fred wilma barney betty ) which in turn means that zsh% eval $(typeset -A) should correctly be an expensive no-op. It's trivial to alter this to produce bash-style foo=([bambam]=pebbles ...) should someone decide to add support for that syntax. I almost decided not to put PRINT_KV_PAIR in zsh.h, because theoretically it should never be used outside printparamnode(), but ... Index: Src/params.c =================================================================== --- params.c 1998/12/13 23:40:56 1.12 +++ params.c 1998/12/14 01:49:44 @@ -2583,24 +2583,28 @@ return; } + quotedzputs(p->nam, stdout); + if (printflags & PRINT_KV_PAIR) + putchar(' '); + else + putchar('='); + /* How the value is displayed depends * * on the type of the parameter */ - quotedzputs(p->nam, stdout); - putchar('='); switch (PM_TYPE(p->flags)) { case PM_SCALAR: /* string: simple output */ if (p->gets.cfn && (t = p->gets.cfn(p))) quotedzputs(t, stdout); - putchar('\n'); break; case PM_INTEGER: /* integer */ - printf("%ld\n", p->gets.ifn(p)); + printf("%ld", p->gets.ifn(p)); break; case PM_ARRAY: /* array */ - putchar('('); + if (!(printflags & PRINT_KV_PAIR)) + putchar('('); u = p->gets.afn(p); if(*u) { quotedzputs(*u++, stdout); @@ -2609,17 +2613,25 @@ quotedzputs(*u++, stdout); } } - printf(")\n"); + if (!(printflags & PRINT_KV_PAIR)) + putchar(')'); break; case PM_HASHED: /* association */ - putchar('('); + if (!(printflags & PRINT_KV_PAIR)) + putchar('('); { HashTable ht = p->gets.hfn(p); if (ht) - scanhashtable(ht, 0, 0, 0, ht->printnode, 0); + scanhashtable(ht, 0, 0, PM_UNSET, + ht->printnode, PRINT_KV_PAIR); } - printf(")\n"); + if (!(printflags & PRINT_KV_PAIR)) + putchar(')'); break; } + if (printflags & PRINT_KV_PAIR) + putchar(' '); + else + putchar('\n'); } Index: Src/zsh.h =================================================================== --- zsh.h 1998/12/12 07:25:54 1.7 +++ zsh.h 1998/12/14 02:09:01 @@ -929,13 +929,14 @@ #define PRINT_NAMEONLY (1<<0) #define PRINT_TYPE (1<<1) #define PRINT_LIST (1<<2) +#define PRINT_KV_PAIR (1<<3) /* flags for printing for the whence builtin */ -#define PRINT_WHENCE_CSH (1<<3) -#define PRINT_WHENCE_VERBOSE (1<<4) -#define PRINT_WHENCE_SIMPLE (1<<5) -#define PRINT_WHENCE_FUNCDEF (1<<6) -#define PRINT_WHENCE_WORD (1<<7) +#define PRINT_WHENCE_CSH (1<<4) +#define PRINT_WHENCE_VERBOSE (1<<5) +#define PRINT_WHENCE_SIMPLE (1<<6) +#define PRINT_WHENCE_FUNCDEF (1<<7) +#define PRINT_WHENCE_WORD (1<<8) /***********************************/ /* Definitions for history control */ -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com