Fix return builtin to work like it does in ksh:

When not in a function, it skips the rest of the current input file.
Instances of `return' outside function definitions were previously ignored.
What does joe posix have to say about this?
[fixes PR/1444]
This commit is contained in:
christos 1995-09-11 17:05:41 +00:00
parent 23366c17ff
commit f9382bca1a
3 changed files with 23 additions and 12 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: eval.c,v 1.26 1995/06/09 01:53:44 christos Exp $ */
/* $NetBSD: eval.c,v 1.27 1995/09/11 17:05:41 christos Exp $ */
/*-
* Copyright (c) 1993
@ -40,7 +40,7 @@
#if 0
static char sccsid[] = "@(#)eval.c 8.9 (Berkeley) 6/8/95";
#else
static char sccsid[] = "$NetBSD: eval.c,v 1.26 1995/06/09 01:53:44 christos Exp $";
static char sccsid[] = "$NetBSD: eval.c,v 1.27 1995/09/11 17:05:41 christos Exp $";
#endif
#endif /* not lint */
@ -80,12 +80,6 @@ static char sccsid[] = "$NetBSD: eval.c,v 1.26 1995/06/09 01:53:44 christos Exp
#define EV_TESTED 02 /* exit status is checked; ignore -e flag */
#define EV_BACKCMD 04 /* command executing within back quotes */
/* reasons for skipping commands (see comment on breakcmd routine) */
#define SKIPBREAK 1
#define SKIPCONT 2
#define SKIPFUNC 3
MKINIT int evalskip; /* set if we are skipping commands */
STATIC int skipcount; /* number of levels to skip */
MKINIT int loopnest; /* current loop nesting level */
@ -965,8 +959,14 @@ returncmd(argc, argv)
if (funcnest) {
evalskip = SKIPFUNC;
skipcount = 1;
return ret;
}
else {
/* Do what ksh does; skip the rest of the file */
evalskip = SKIPFILE;
skipcount = 1;
return ret;
}
return ret;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: eval.h,v 1.8 1995/05/11 21:28:58 christos Exp $ */
/* $NetBSD: eval.h,v 1.9 1995/09/11 17:05:43 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
@ -65,3 +65,10 @@ int execcmd __P((int, char **));
/* in_function returns nonzero if we are currently evaluating a function */
#define in_function() funcnest
extern int funcnest;
extern int evalskip;
/* reasons for skipping commands (see comment on breakcmd routine) */
#define SKIPBREAK 1
#define SKIPCONT 2
#define SKIPFUNC 3
#define SKIPFILE 4

View File

@ -1,4 +1,4 @@
/* $NetBSD: main.c,v 1.21 1995/07/20 15:04:16 christos Exp $ */
/* $NetBSD: main.c,v 1.22 1995/09/11 17:05:44 christos Exp $ */
/*-
* Copyright (c) 1991, 1993
@ -46,7 +46,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)main.c 8.7 (Berkeley) 7/19/95";
#else
static char rcsid[] = "$NetBSD: main.c,v 1.21 1995/07/20 15:04:16 christos Exp $";
static char rcsid[] = "$NetBSD: main.c,v 1.22 1995/09/11 17:05:44 christos Exp $";
#endif
#endif /* not lint */
@ -235,6 +235,10 @@ cmdloop(top)
evaltree(n, 0);
}
popstackmark(&smark);
if (evalskip == SKIPFILE) {
evalskip = 0;
break;
}
}
popstackmark(&smark); /* unnecessary */
}