From: "Bart Schaefer" <schaefer@brasslantern.com>
To: zsh-workers@math.gatech.edu
Subject: PATCH: 3.1.5 + associative arrays: printing of parameters
Date: Sun, 13 Dec 1998 18:17:06 -0800 [thread overview]
Message-ID: <981213181706.ZM16878@candle.brasslantern.com> (raw)
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
reply other threads:[~1998-12-14 2:19 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=981213181706.ZM16878@candle.brasslantern.com \
--to=schaefer@brasslantern.com \
--cc=zsh-workers@math.gatech.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).