From b5198b10a1d1b6a15c583eecf12fda0c08b19ad6 Mon Sep 17 00:00:00 2001
From: Peter Stephenson
Date: Fri, 13 Jun 2014 21:39:44 +0100
Subject: 32768 with further modifications: LOCAL_LOOPS option.
---
Src/exec.c | 17 +++++++++++++++--
Src/options.c | 1 +
Src/zsh.h | 1 +
3 files changed, 17 insertions(+), 2 deletions(-)
(limited to 'Src')
diff --git a/Src/exec.c b/Src/exec.c
index 8249deff2..5ad957f98 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -4614,7 +4614,7 @@ doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval)
char *name = shfunc->node.nam;
int flags = shfunc->node.flags, ooflags;
char *fname = dupstring(name);
- int obreaks, saveemulation, restore_sticky;
+ int obreaks, ocontflag, oloops, saveemulation, restore_sticky;
Eprog prog;
struct funcstack fstack;
static int oflags;
@@ -4626,7 +4626,9 @@ doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval)
pushheap();
oargv0 = NULL;
- obreaks = breaks;;
+ obreaks = breaks;
+ ocontflag = contflag;
+ oloops = loops;
if (trap_state == TRAP_STATE_PRIMED)
trap_return--;
oldlastval = lastval;
@@ -4814,6 +4816,17 @@ doshfunc(Shfunc shfunc, LinkList doshargs, int noreturnval)
opts[XTRACE] = saveopts[XTRACE];
opts[PRINTEXITVALUE] = saveopts[PRINTEXITVALUE];
opts[LOCALOPTIONS] = saveopts[LOCALOPTIONS];
+ opts[LOCALLOOPS] = saveopts[LOCALLOOPS];
+ }
+
+ if (opts[LOCALLOOPS]) {
+ if (contflag)
+ zwarn("`continue' active at end of function scope");
+ if (breaks)
+ zwarn("`break' active at end of function scope");
+ breaks = obreaks;
+ contflag = ocontflag;
+ loops = oloops;
}
endtrapscope();
diff --git a/Src/options.c b/Src/options.c
index 2163bff4d..6e4e7b911 100644
--- a/Src/options.c
+++ b/Src/options.c
@@ -180,6 +180,7 @@ static struct optname optns[] = {
{{NULL, "listrowsfirst", 0}, LISTROWSFIRST},
{{NULL, "listtypes", OPT_ALL}, LISTTYPES},
{{NULL, "localoptions", OPT_EMULATE|OPT_KSH}, LOCALOPTIONS},
+{{NULL, "localloops", OPT_EMULATE}, LOCALLOOPS},
{{NULL, "localpatterns", OPT_EMULATE}, LOCALPATTERNS},
{{NULL, "localtraps", OPT_EMULATE|OPT_KSH}, LOCALTRAPS},
{{NULL, "login", OPT_SPECIAL}, LOGINSHELL},
diff --git a/Src/zsh.h b/Src/zsh.h
index 05d582cda..fa7396112 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -2129,6 +2129,7 @@ enum {
LISTPACKED,
LISTROWSFIRST,
LISTTYPES,
+ LOCALLOOPS,
LOCALOPTIONS,
LOCALPATTERNS,
LOCALTRAPS,
--
cgit 1.4.1