mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 01/13] hush: safe indention level by continueing a loop
Date: Mon, 30 Apr 2012 13:19:16 +0200	[thread overview]
Message-ID: <1335784768-9189-2-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 |  160 +++++++++++++++++++++++++++++----------------------------
 1 file changed, 81 insertions(+), 79 deletions(-)

diff --git a/common/hush.c b/common/hush.c
index 2d89f2b..091938d 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -1284,95 +1284,97 @@ static int parse_stream(o_string *dest, struct p_context *ctx,
 			ch >= ' ' ? ch : '.', ch, m,
 			dest->quote, ctx->stack == NULL ? '*' : '.');
 
-		if (m==0 || ((m==1 || m==2) && dest->quote)) {
+		if (m == 0 || ((m == 1 || m == 2) && dest->quote)) {
 			b_addqchr(dest, ch, dest->quote);
-		} else {
-			if (m==2) {  /* unquoted IFS */
-				if (done_word(dest, ctx)) {
-					return 1;
-				}
-				/* If we aren't performing a substitution, treat a newline as a
-				 * command separator.  */
-				if (end_trigger != '\0' && ch=='\n')
-					done_pipe(ctx,PIPE_SEQ);
-			}
-			if (ch == end_trigger && !dest->quote && ctx->w==RES_NONE) {
-				debug("leaving parse_stream (triggered)\n");
-				return 0;
+			continue;
+		}
+
+		if (m == 2) {  /* unquoted IFS */
+			if (done_word(dest, ctx)) {
+				return 1;
 			}
-			if (m!=2) {
-				switch (ch) {
-				case '#':
-					if (dest->length == 0 && !dest->quote) {
-						while(ch=b_peek(input),ch!=EOF && ch!='\n') {
-							b_getch(input);
-						}
-					} else {
-						b_addqchr(dest, ch, dest->quote);
-					}
-					break;
-				case '\\':
-					if (next == EOF) {
-						syntax();
-						return 1;
-					}
-					b_addqchr(dest, '\\', dest->quote);
-					b_addqchr(dest, b_getch(input), dest->quote);
-					break;
-				case '$':
-					if (handle_dollar(dest, ctx, input)!=0)
-						return 1;
-					break;
-				case '\'':
-					dest->nonnull = 1;
-					while(ch=b_getch(input),ch!=EOF && ch!='\'') {
-						if(input->__promptme == 0)
-							return 1;
-						b_addchr(dest,ch);
-					}
-					if (ch==EOF) {
-						syntax();
-						return 1;
-					}
-					break;
-				case '"':
-					dest->nonnull = 1;
-					dest->quote = !dest->quote;
-					break;
-				case ';':
-					done_word(dest, ctx);
-					done_pipe(ctx,PIPE_SEQ);
-					break;
-				case '&':
-					done_word(dest, ctx);
-					if (next=='&') {
+			/* If we aren't performing a substitution, treat a newline as a
+			 * command separator.  */
+			if (end_trigger != '\0' && ch=='\n')
+				done_pipe(ctx,PIPE_SEQ);
+		}
+		if (ch == end_trigger && !dest->quote && ctx->w==RES_NONE) {
+			debug("leaving parse_stream (triggered)\n");
+			return 0;
+		}
+		if (m != 2) {
+			switch (ch) {
+			case '#':
+				if (dest->length == 0 && !dest->quote) {
+					while (ch = b_peek(input), ch != EOF && ch!='\n') {
 						b_getch(input);
-						done_pipe(ctx,PIPE_AND);
-					} else {
-						syntax_err();
-						return 1;
 					}
-					break;
-				case '|':
-					done_word(dest, ctx);
-					if (next=='|') {
-						b_getch(input);
-						done_pipe(ctx,PIPE_OR);
-					} else {
-						/* we could pick up a file descriptor choice here
-						 * with redirect_opt_num(), but bash doesn't do it.
-						 * "echo foo 2| cat" yields "foo 2". */
-						syntax_err();
+				} else {
+					b_addqchr(dest, ch, dest->quote);
+				}
+				break;
+			case '\\':
+				if (next == EOF) {
+					syntax();
+					return 1;
+				}
+				b_addqchr(dest, '\\', dest->quote);
+				b_addqchr(dest, b_getch(input), dest->quote);
+				break;
+			case '$':
+				if (handle_dollar(dest, ctx, input)!=0)
+					return 1;
+				break;
+			case '\'':
+				dest->nonnull = 1;
+				while (ch = b_getch(input), ch!=EOF && ch != '\'') {
+					if (input->__promptme == 0)
 						return 1;
-					}
-					break;
-				default:
-					syntax();   /* this is really an internal logic error */
+					b_addchr(dest,ch);
+				}
+				if (ch == EOF) {
+					syntax();
+					return 1;
+				}
+				break;
+			case '"':
+				dest->nonnull = 1;
+				dest->quote = !dest->quote;
+				break;
+			case ';':
+				done_word(dest, ctx);
+				done_pipe(ctx, PIPE_SEQ);
+				break;
+			case '&':
+				done_word(dest, ctx);
+				if (next == '&') {
+					b_getch(input);
+					done_pipe(ctx, PIPE_AND);
+				} else {
+					syntax_err();
 					return 1;
 				}
+				break;
+			case '|':
+				done_word(dest, ctx);
+				if (next == '|') {
+					b_getch(input);
+					done_pipe(ctx, PIPE_OR);
+				} else {
+					/* we could pick up a file descriptor choice here
+					 * with redirect_opt_num(), but bash doesn't do it.
+					 * "echo foo 2| cat" yields "foo 2". */
+					syntax_err();
+					return 1;
+				}
+				break;
+			default:
+				syntax();   /* this is really an internal logic error */
+				return 1;
 			}
 		}
 	}
+
 	/* complain if quote?  No, maybe we just finished a command substitution
 	 * that was quoted.  Example:
 	 * $ echo "`cat foo` plus more"
-- 
1.7.10


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  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 ` Sascha Hauer [this message]
2012-04-30 11:19 ` [PATCH 02/13] hush: safe an indention level by continueing a loop 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 ` [PATCH 06/13] hush: run_pipe_real: bail out early to safe an indention level Sascha Hauer
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-2-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