From 39b28980f38e83e15cdeb19a489b5659af97fe93 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Thu, 18 Jun 2015 14:54:41 +0100 Subject: various posts: Implement assignment parsing for typeset. Typeset assignments now work like raw assignments except for no "+=" and no GLOB_ASSIGN. Documented in typeset builtin doc and mentioned in release notes. Tests to ensure basic sanity. Enabled by default, can be turned off by "disable -r" with typeset family of commands. --- Src/text.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 11 deletions(-) (limited to 'Src/text.c') diff --git a/Src/text.c b/Src/text.c index 850879699..a72ab33e6 100644 --- a/Src/text.c +++ b/Src/text.c @@ -155,6 +155,46 @@ taddlist(Estate state, int num) } } +/* add an assignment */ + +static void +taddassign(wordcode code, Estate state, int typeset) +{ + /* name */ + taddstr(ecgetstr(state, EC_NODUP, NULL)); + /* value... maybe */ + if (WC_ASSIGN_TYPE2(code) == WC_ASSIGN_INC) { + if (typeset) { + /* dummy assignment --- just var name */ + (void)ecgetstr(state, EC_NODUP, NULL); + taddchr(' '); + return; + } + taddchr('+'); + } + taddchr('='); + if (WC_ASSIGN_TYPE(code) == WC_ASSIGN_ARRAY) { + taddchr('('); + taddlist(state, WC_ASSIGN_NUM(code)); + taddstr(") "); + } else { + taddstr(ecgetstr(state, EC_NODUP, NULL)); + taddchr(' '); + } +} + +/* add a number of assignments from typeset */ + +/**/ +static void +taddassignlist(Estate state, wordcode count) +{ + while (count--) { + wordcode code = *state->pc++; + taddassign(code, state, 1); + } +} + /* add a newline, or something equivalent, to the text buffer */ /**/ @@ -439,22 +479,17 @@ gettext2(Estate state) } break; case WC_ASSIGN: - taddstr(ecgetstr(state, EC_NODUP, NULL)); - if (WC_ASSIGN_TYPE2(code) == WC_ASSIGN_INC) taddchr('+'); - taddchr('='); - if (WC_ASSIGN_TYPE(code) == WC_ASSIGN_ARRAY) { - taddchr('('); - taddlist(state, WC_ASSIGN_NUM(code)); - taddstr(") "); - } else { - taddstr(ecgetstr(state, EC_NODUP, NULL)); - taddchr(' '); - } + taddassign(code, state, 0); break; case WC_SIMPLE: taddlist(state, WC_SIMPLE_ARGC(code)); stack = 1; break; + case WC_TYPESET: + taddlist(state, WC_TYPESET_ARGC(code)); + taddassignlist(state, *state->pc++); + stack = 1; + break; case WC_SUBSH: if (!s) { taddstr("("); -- cgit v1.2.3