From 7f72596ab5b61e32066ed00e36feb71bef49dbb5 Mon Sep 17 00:00:00 2001 From: Brian Koropoff Date: Fri, 28 Feb 2003 05:07:15 +0000 Subject: [PATCH] Fix a bug with embedded commands and make the parser more anal about what can be embedded. --- libs/gib/gib_execute.c | 14 +++++++------- libs/gib/gib_parse.c | 8 +++++++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/libs/gib/gib_execute.c b/libs/gib/gib_execute.c index fc53053c9..435ad467c 100644 --- a/libs/gib/gib_execute.c +++ b/libs/gib/gib_execute.c @@ -204,12 +204,6 @@ GIB_Execute (cbuf_t * cbuf) return; g->ip = g->ip ? g->ip->next : g->program; while (g->ip) { - if (g->ip->flags & TREE_L_EMBED) { - // Get ready for return values - g->waitret = true; - GIB_Buffer_Push_Sstack (cbuf); - } else - g->waitret = false; switch (g->ip->type) { case TREE_T_JUMP: g->ip = g->ip->jump; @@ -241,7 +235,13 @@ GIB_Execute (cbuf_t * cbuf) case TREE_T_CMD: if (GIB_Execute_Prepare_Line (cbuf, g->ip)) return; - else if (cbuf->args->argc) { + if (g->ip->flags & TREE_L_EMBED) { + // Get ready for return values + g->waitret = true; + GIB_Buffer_Push_Sstack (cbuf); + } else + g->waitret = false; + if (cbuf->args->argc) { if ((b = GIB_Builtin_Find (cbuf->args->argv[0]->str))) b->func (); else if ((f = GIB_Function_Find (cbuf->args->argv[0]->str))) { diff --git a/libs/gib/gib_parse.c b/libs/gib/gib_parse.c index 3d4cc3234..0d59ad777 100644 --- a/libs/gib/gib_parse.c +++ b/libs/gib/gib_parse.c @@ -509,6 +509,9 @@ GIB_Parse_Semantic_Preprocess (gib_tree_t * line) || !line->children->next->next->next->next) { GIB_Parse_Error ("Malformed 'for' statement.", line->start); return line; + } else if (line->flags & TREE_L_EMBED) { + GIB_Parse_Error ("'for' statements may not be used in embedded commands.", line->start); + return line; } // Find last token in line (contains program block) for (tmp = line->children->next->next->next->next; tmp->next; @@ -552,8 +555,11 @@ GIB_Parse_Semantic_Preprocess (gib_tree_t * line) !(line->children->next->flags & TREE_A_CONCAT) && line->children->next->delim == ' ' && !strcmp (line->children->next->str, "=") - ) + ) { + if (line->flags & TREE_L_EMBED) + GIB_Parse_Error ("Assignment may not be used as an embedded command.", line->start); line->type = TREE_T_ASSIGN; + } return line; }