From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 06/13] hush: run_pipe_real: bail out early to safe an indention level
Date: Mon, 30 Apr 2012 13:19:21 +0200 [thread overview]
Message-ID: <1335784768-9189-7-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1335784768-9189-1-git-send-email-s.hauer@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/hush.c | 98 +++++++++++++++++++++++++++------------------------------
1 file changed, 47 insertions(+), 51 deletions(-)
diff --git a/common/hush.c b/common/hush.c
index 362f544..cd2afef 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -614,67 +614,67 @@ static int run_pipe_real(struct p_context *ctx, struct pipe *pi)
return rcode;
}
- if (pi->progs[0].argv != NULL) {
-
- for (i = 0; is_assignment(child->argv[i]); i++)
- { /* nothing */ }
+ if (!pi->progs[0].argv)
+ return -1;
- if (i != 0 && child->argv[i] == NULL) {
- /* assignments, but no command: set the local environment */
- for (i = 0; child->argv[i] != NULL; i++) {
+ for (i = 0; is_assignment(child->argv[i]); i++)
+ { /* nothing */ }
- /* Ok, this case is tricky. We have to decide if this is a
- * local variable, or an already exported variable. If it is
- * already exported, we have to export the new value. If it is
- * not exported, we need only set this as a local variable.
- * This junk is all to decide whether or not to export this
- * variable. */
- int export_me = 0;
- char *name, *value;
+ if (i != 0 && child->argv[i] == NULL) {
+ /* assignments, but no command: set the local environment */
+ for (i = 0; child->argv[i] != NULL; i++) {
- name = xstrdup(child->argv[i]);
- debug("Local environment set: %s\n", name);
- value = strchr(name, '=');
+ /* Ok, this case is tricky. We have to decide if this is a
+ * local variable, or an already exported variable. If it is
+ * already exported, we have to export the new value. If it is
+ * not exported, we need only set this as a local variable.
+ * This junk is all to decide whether or not to export this
+ * variable. */
+ int export_me = 0;
+ char *name, *value;
- if (value)
- *value = 0;
+ name = xstrdup(child->argv[i]);
+ debug("Local environment set: %s\n", name);
+ value = strchr(name, '=');
- free(name);
- p = insert_var_value(child->argv[i]);
- set_local_var(p, export_me);
+ if (value)
+ *value = 0;
- if (p != child->argv[i])
- free(p);
- }
- return EXIT_SUCCESS; /* don't worry about errors in set_local_var() yet */
- }
- for (i = 0; is_assignment(child->argv[i]); i++) {
+ free(name);
p = insert_var_value(child->argv[i]);
- set_local_var(p, 0);
+ set_local_var(p, export_me);
- if (p != child->argv[i]) {
- child->sp--;
+ if (p != child->argv[i])
free(p);
- }
}
- if (child->sp) {
- char * str = NULL;
- struct p_context ctx1;
-
- str = make_string((child->argv + i));
- parse_string_outer(&ctx1, str, FLAG_EXIT_FROM_LOOP | FLAG_REPARSING);
- release_context(&ctx1);
- free(str);
+ return EXIT_SUCCESS; /* don't worry about errors in set_local_var() yet */
+ }
+ for (i = 0; is_assignment(child->argv[i]); i++) {
+ p = insert_var_value(child->argv[i]);
+ set_local_var(p, 0);
- return last_return_code;
+ if (p != child->argv[i]) {
+ child->sp--;
+ free(p);
}
+ }
+ if (child->sp) {
+ char * str = NULL;
+ struct p_context ctx1;
+
+ str = make_string((child->argv + i));
+ parse_string_outer(&ctx1, str, FLAG_EXIT_FROM_LOOP | FLAG_REPARSING);
+ release_context(&ctx1);
+ free(str);
+
+ return last_return_code;
+ }
+
#ifdef CONFIG_HUSH_GETOPT
- if (!strcmp(child->argv[i], "getopt"))
- return builtin_getopt(ctx, child);
+ if (!strcmp(child->argv[i], "getopt"))
+ return builtin_getopt(ctx, child);
#endif
- return execute_binfmt(child->argc - i, &child->argv[i]);
- }
- return -1;
+ return execute_binfmt(child->argc - i, &child->argv[i]);
}
static int run_list_real(struct p_context *ctx, struct pipe *pi)
@@ -1234,13 +1234,9 @@ static int done_pipe(struct p_context *ctx, pipe_style type)
struct pipe *new_p;
done_command(ctx); /* implicit closure of previous command */
-<<<<<<< HEAD
debug("%s: type %d\n", __func__, type);
-=======
- debug("%s: type %d\n", __func__, type);
->>>>>>> f5c1f0c... hush use func
ctx->pipe->followup = type;
ctx->pipe->r_mode = ctx->w;
--
1.7.10
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2012-04-30 11:19 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-30 11:19 hush fixes and cleanups Sascha Hauer
2012-04-30 11:19 ` [PATCH 01/13] hush: safe indention level by continueing a loop Sascha Hauer
2012-04-30 11:19 ` [PATCH 02/13] hush: safe an " Sascha Hauer
2012-04-30 11:19 ` [PATCH 03/13] hush: cleanup coding style Sascha Hauer
2012-04-30 11:19 ` [PATCH 04/13] hush: remove bogus 'else' Sascha Hauer
2012-04-30 11:19 ` [PATCH 05/13] hush: run_pipe_real must have num_progs == 1 Sascha Hauer
2012-04-30 11:19 ` Sascha Hauer [this message]
2012-04-30 11:19 ` [PATCH 07/13] hush: remove quotes at end of processing Sascha Hauer
2012-04-30 11:19 ` [PATCH 08/13] hush: simplify globhack Sascha Hauer
2012-04-30 11:19 ` [PATCH 09/13] hush: pass GLOB_NOCHECK to glob Sascha Hauer
2012-04-30 11:19 ` [PATCH 10/13] glob: activate GLOB_NOCHECK flag Sascha Hauer
2012-04-30 11:19 ` [PATCH 11/13] hush: Fix globbing Sascha Hauer
2012-04-30 11:19 ` [PATCH 12/13] hush: allow to run interactive shell in do_sh Sascha Hauer
2012-04-30 11:19 ` [PATCH 13/13] defaultenv: remove now unnecessary hush-hack Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1335784768-9189-7-git-send-email-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox