svn commit: [26048] trunk/busybox/shell

vda at busybox.net vda at busybox.net
Thu Apr 9 20:41:34 UTC 2009


Author: vda
Date: 2009-04-09 20:41:34 +0000 (Thu, 09 Apr 2009)
New Revision: 26048

Log:
hush: shrink and make more versatile error-reporting machinery

function                                             old     new   delta
syntax_error_unterm_ch                                 -      31     +31
syntax_error_unterm_str                                -      14     +14
parse_stream                                        2356    2361      +5
syntax_error_at                                       12      14      +2
syntax_error                                          25      27      +2
syntax_error_unterminated                             28       -     -28
expand_variables                                    2063    2031     -32
------------------------------------------------------------------------------
(add/remove: 2/1 grow/shrink: 3/1 up/down: 54/-60)             Total: -6 bytes
   text    data     bss     dec     hex filename
  67278     197    3184   70659   11403 busybox_old
  67228     197    3184   70609   113d1 busybox_unstripped



Modified:
   trunk/busybox/shell/hush.c


Changeset:
Modified: trunk/busybox/shell/hush.c
===================================================================
--- trunk/busybox/shell/hush.c	2009-04-09 19:16:15 UTC (rev 26047)
+++ trunk/busybox/shell/hush.c	2009-04-09 20:41:34 UTC (rev 26048)
@@ -663,23 +663,25 @@
  * HUSH_DEBUG >= 2 prints line number in this file where it was detected.
  */
 #if HUSH_DEBUG < 2
-# define die_if_script(lineno, fmt, msg)       die_if_script(fmt, msg)
-# define syntax_error(lineno, msg)             syntax_error(msg)
-# define syntax_error_at(lineno, msg)          syntax_error_at(msg)
-# define syntax_error_unterminated(lineno, ch) syntax_error_unterminated(ch)
+# define die_if_script(lineno, fmt...)      die_if_script(fmt)
+# define syntax_error(lineno, msg)          syntax_error(msg)
+# define syntax_error_at(lineno, msg)       syntax_error_at(msg)
+# define syntax_error_unterm_ch(lineno, ch) syntax_error_unterm_ch(ch)
+# define syntax_error_unterm_str(lineno, s) syntax_error_unterm_str(s)
 #endif
 
-static void die_if_script(unsigned lineno, const char *fmt, const char *msg)
+static void die_if_script(unsigned lineno, const char *fmt, ...)
 {
-	void FAST_FUNC (*fp)(const char *s, ...) = bb_error_msg_and_die;
-#if ENABLE_HUSH_INTERACTIVE
-	if (G_interactive_fd)
-		fp = bb_error_msg;
-#endif
+	va_list p;
+
 #if HUSH_DEBUG >= 2
 	bb_error_msg("hush.c:%u", lineno);
 #endif
-	fp(fmt, msg);
+	va_start(p, fmt);
+	bb_verror_msg(fmt, p, NULL);
+	va_end(p);
+	if (!G_interactive_fd)
+		xfunc_die();
 }
 
 static void syntax_error(unsigned lineno, const char *msg)
@@ -695,7 +697,7 @@
 	die_if_script(lineno, "syntax error at '%s'", msg);
 }
 
-static void syntax_error_unterminated(unsigned lineno, char ch)
+static void syntax_error_unterm_ch(unsigned lineno, char ch)
 {
 	char msg[2];
 	msg[0] = ch;
@@ -703,16 +705,23 @@
 	die_if_script(lineno, "syntax error: unterminated %s", msg);
 }
 
+static void syntax_error_unterm_str(unsigned lineno, const char *s)
+{
+	die_if_script(lineno, "syntax error: unterminated %s", s);
+}
+
 #if HUSH_DEBUG < 2
 # undef die_if_script
 # undef syntax_error
 # undef syntax_error_at
-# undef syntax_error_unterminated
+# undef syntax_error_unterm_ch
+# undef syntax_error_unterm_str
 #else
-# define die_if_script(fmt, msg)       die_if_script(__LINE__, fmt, msg)
-# define syntax_error(msg)             syntax_error(__LINE__, msg)
-# define syntax_error_at(msg)          syntax_error_at(__LINE__, msg)
-# define syntax_error_unterminated(ch) syntax_error_unterminated(__LINE__, ch)
+# define die_if_script(fmt...)      die_if_script(__LINE__, fmt)
+# define syntax_error(msg)          syntax_error(__LINE__, msg)
+# define syntax_error_at(msg)       syntax_error_at(__LINE__, msg)
+# define syntax_error_unterm_ch(ch) syntax_error_unterm_ch(__LINE__, ch)
+# define syntax_error_unterm_str(s) syntax_error_unterm_str(__LINE__, s)
 #endif
 
 
@@ -1957,7 +1966,7 @@
 					msg = "expression recursion loop detected";
 					break;
 				}
-				die_if_script(msg, NULL);
+				die_if_script(msg);
 			}
 			debug_printf_subst("ARITH RES '"arith_t_fmt"'\n", res);
 			sprintf(arith_buf, arith_t_fmt, res);
@@ -2036,20 +2045,18 @@
 					debug_printf_expand("expand: op:%c (null:%s) test:%i\n", exp_op,
 						exp_null ? "true" : "false", exp_test);
 					if (exp_test) {
-						if (exp_op == '?')
-//TODO: what does interactive bash
+						if (exp_op == '?') {
+//TODO: how interactive bash aborts expansion mid-command?
 							/* ${var?[error_msg_if_unset]} */
 							/* ${var:?[error_msg_if_unset_or_null]} */
 							/* mimic bash message */
-							if (*exp_word) {
-								char *msg = xasprintf("%s: %s", var, exp_word);
-								die_if_script("%s", msg);
-								free(msg);
-							} else {
-								die_if_script("%s: parameter null or not set", var);
-							}
-						else
+							die_if_script("%s: %s",
+								var,
+								exp_word[0] ? exp_word : "parameter null or not set"
+							);
+						} else {
 							val = exp_word;
+						}
 
 						if (exp_op == '=') {
 							/* ${var=[word]} or ${var:=[word]} */
@@ -4487,7 +4494,7 @@
 	while (1) {
 		int ch = i_getch(input);
 		if (ch == EOF) {
-			syntax_error_unterminated('\'');
+			syntax_error_unterm_ch('\'');
 			return 1;
 		}
 		if (ch == '\'')
@@ -4501,7 +4508,7 @@
 	while (1) {
 		int ch = i_getch(input);
 		if (ch == EOF) {
-			syntax_error_unterminated('"');
+			syntax_error_unterm_ch('"');
 			return 1;
 		}
 		if (ch == '"')
@@ -4539,7 +4546,7 @@
 	while (1) {
 		int ch = i_getch(input);
 		if (ch == EOF) {
-			syntax_error_unterminated('`');
+			syntax_error_unterm_ch('`');
 			return 1;
 		}
 		if (ch == '`')
@@ -4548,7 +4555,7 @@
 			/* \x. Copy both chars unless it is \` */
 			int ch2 = i_getch(input);
 			if (ch2 == EOF) {
-				syntax_error_unterminated('`');
+				syntax_error_unterm_ch('`');
 				return 1;
 			}
 			if (ch2 != '`' && ch2 != '$' && ch2 != '\\')
@@ -4576,7 +4583,7 @@
 	while (1) {
 		int ch = i_getch(input);
 		if (ch == EOF) {
-			syntax_error_unterminated(')');
+			syntax_error_unterm_ch(')');
 			return 1;
 		}
 		if (ch == '(')
@@ -4608,7 +4615,7 @@
 			/* \x. Copy verbatim. Important for  \(, \) */
 			ch = i_getch(input);
 			if (ch == EOF) {
-				syntax_error_unterminated(')');
+				syntax_error_unterm_ch(')');
 				return 1;
 			}
 			o_addchr(dest, ch);
@@ -4726,7 +4733,7 @@
 					break;
 				default:
 				case_default:
-					syntax_error("unterminated ${name}");
+					syntax_error_unterm_str("${name}");
 					debug_printf_parse("handle_dollar return 1: unterminated ${name}\n");
 					return 1;
 				}
@@ -4831,7 +4838,7 @@
 	}
 	/* note: can't move it above ch == dquote_end check! */
 	if (ch == EOF) {
-		syntax_error_unterminated('"');
+		syntax_error_unterm_ch('"');
 		debug_printf_parse("parse_stream_dquoted return 1: unterminated \"\n");
 		return 1;
 	}
@@ -4954,7 +4961,7 @@
 			struct pipe *pi;
 
 			if (heredoc_cnt) {
-				syntax_error("unterminated here document");
+				syntax_error_unterm_str("here document");
 				goto parse_error;
 			}
 			if (done_word(&dest, &ctx)) {
@@ -5043,7 +5050,7 @@
 				 * We require heredoc to be in enclosing {}/(),
 				 * if any.
 				 */
-				syntax_error("unterminated here document");
+				syntax_error_unterm_str("here document");
 				goto parse_error;
 			}
 			if (done_word(&dest, &ctx)) {
@@ -5123,7 +5130,7 @@
 			while (1) {
 				ch = i_getch(input);
 				if (ch == EOF) {
-					syntax_error_unterminated('\'');
+					syntax_error_unterm_ch('\'');
 					goto parse_error;
 				}
 				nommu_addchr(&ctx.as_string, ch);



More information about the busybox-cvs mailing list