[PATCH] hush.c - simple support to return from functions
Bayram Kurumahmut
kbayram at ubicom.com
Fri Apr 17 17:27:12 UTC 2009
add builtin return function
if flag_return_function is true, break current run_list() execution
Regards,
Bayram
Index: hush.c
===================================================================
--- hush.c (revision 26130)
+++ hush.c (working copy)
@@ -459,6 +459,7 @@
struct variable shell_ver;
#if ENABLE_HUSH_FUNCTIONS
struct function *top_func;
+ bool flag_function_return;
#endif
/* Signal and trap handling */
// unsigned count_SIGCHLD;
@@ -515,6 +516,9 @@
static int builtin_break(char **argv);
static int builtin_continue(char **argv);
#endif
+#if ENABLE_HUSH_FUNCTIONS
+static int builtin_return(char **argv);
+#endif
/* Table of built-in functions. They can be forked or not, depending on
* context: within pipes, they fork. As simple commands, they do not.
@@ -568,7 +572,7 @@
#endif
BLTIN("pwd" , builtin_pwd , "Print current directory"),
BLTIN("read" , builtin_read , "Input environment variable"),
-// BLTIN("return" , builtin_return , "Return from a function"),
+ BLTIN("return" , builtin_return , "Return from a function"),
BLTIN("set" , builtin_set , "Set/unset shell local variables"),
BLTIN("shift" , builtin_shift , "Shift positional parameters"),
BLTIN("test" , builtin_test , "Test condition"),
@@ -3841,6 +3845,9 @@
#if ENABLE_HUSH_LOOPS
G.flag_break_continue = 0;
#endif
+#if ENABLE_HUSH_FUNCTIONS
+ G.flag_function_return = false;
+#endif
rcode = r = run_pipe(pi); /* NB: rcode is a smallint */
if (r != -1) {
/* We only ran a builtin: rcode is already known
@@ -3867,6 +3874,10 @@
continue;
}
#endif
+#if ENABLE_HUSH_FUNCTIONS
+ if (G.flag_function_return == true)
+ goto check_jobs_and_break;
+#endif
} else if (pi->followup == PIPE_BG) {
/* What does bash do with attempts to background builtins? */
/* even bash 3.2 doesn't do that well with nested bg:
@@ -6819,3 +6830,11 @@
return builtin_break(argv);
}
#endif
+
+#if ENABLE_HUSH_FUNCTIONS
+static int builtin_return(char **argv)
+{
+ G.flag_function_return = true;
+ return EXIT_SUCCESS;
+}
+#endif
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20090417/427bd7ae/attachment.htm>
More information about the busybox
mailing list