From 1e3783f0306634c48b3ff2783e6a8c737bb916e1 Mon Sep 17 00:00:00 2001 From: tg Date: Sun, 19 Aug 2007 23:12:23 +0000 Subject: [PATCH] =?UTF-8?q?employ=20string=20pooling=20techniques=20to=20s?= =?UTF-8?q?ave=20off=20a=20few=20more=20bytes=20(probably=20more=20than=20?= =?UTF-8?q?the=20new=20=E2=80=9Crename=E2=80=9D=20builtin=20ever=20require?= =?UTF-8?q?d=E2=80=A6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- funcs.c | 4 ++-- lex.c | 27 +++++++++++++++++---------- sh.h | 6 ++++-- syn.c | 6 +++--- 4 files changed, 26 insertions(+), 17 deletions(-) diff --git a/funcs.c b/funcs.c index 1263d5c..4d1e965 100644 --- a/funcs.c +++ b/funcs.c @@ -5,7 +5,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.63 2007/08/19 22:06:26 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.64 2007/08/19 23:12:21 tg Exp $"); /* A leading = means assignments before command are kept; * a leading * means a POSIX special builtin; @@ -3033,7 +3033,7 @@ c_rename(const char **wp) wp[1] == NULL /* first argument */ || wp[2] == NULL /* second argument */ || wp[3] != NULL /* no further args please */) - bi_errorf("syntax error"); + bi_errorf(T_synerr); else if ((rv = rename(wp[1], wp[2])) != 0) { rv = errno; bi_errorf("failed: %s", strerror(rv)); diff --git a/lex.c b/lex.c index 549e892..5362a12 100644 --- a/lex.c +++ b/lex.c @@ -2,7 +2,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.46 2007/07/23 14:28:52 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.47 2007/08/19 23:12:22 tg Exp $"); /* Structure to keep track of the lexing state and the various pieces of info * needed for each particular state. */ @@ -182,22 +182,29 @@ yylex(int cf) if (statep->ls_sadelim.style == SADELIM_MAKE && statep->ls_sadelim.num == 1) { if (c == /*{*/'}') - yyerror("syntax error: expected" - /* { */ " '%c' before '}'\n", - statep->ls_sadelim.delimiter); + yyerror("%s: expected '%c' %s\n", + T_synerr, + statep->ls_sadelim.delimiter, + /*{*/ "before '}'"); else { *wp++ = ADELIM; *wp++ = c; /* .delimiter */ while ((c = getsc()) != /*{*/ '}') { if (!c) { - yyerror("syntax error: expected" - /* { */ " '}' before end of input\n"); + yyerror("%s: expected '%c' %s\n", + T_synerr, + /*{*/ '}', "at end of input"); } else if (strchr(sadelim_flags[statep->ls_sadelim.flags], c)) { *wp++ = CHAR; *wp++ = c; - } else - yyerror("syntax error: expected" - /* { */ " '}' instead of '%c'\n", c); + } else { + char Ttmp[15] = "instead of ' '"; + + Ttmp[12] = c; + yyerror("%s: expected '%c' %s\n", + T_synerr, + /*{*/ '}', Ttmp); + } } } } @@ -709,7 +716,7 @@ yylex(int cf) yyerror("no closing quote\n"); if (state == SLETARRAY && statep->ls_sletarray.nparen != -1) - yyerror("syntax error: ')' missing\n"); + yyerror("%s: ')' missing\n", T_synerr); /* This done to avoid tests for SHEREDELIM wherever SBASE tested */ if (state == SHEREDELIM) diff --git a/sh.h b/sh.h index 4aa6ba2..88efbf7 100644 --- a/sh.h +++ b/sh.h @@ -8,7 +8,7 @@ /* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */ /* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */ -#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.172 2007/08/19 22:06:27 tg Exp $" +#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.173 2007/08/19 23:12:22 tg Exp $" #define MKSH_VERSION "R31 2007/08/19" #if HAVE_SYS_PARAM_H @@ -439,7 +439,9 @@ enum sh_flag { EXTERN char shell_flags[FNFLAGS]; /* null value for variable; comparision pointer for unset */ -EXTERN char null[] I__(""); +EXTERN char null[] I__(""); +/* helpers for string pooling */ +EXTERN const char T_synerr[] I__("syntax error"); enum temp_type { TT_HEREDOC_EXP, /* expanded heredoc */ diff --git a/syn.c b/syn.c index 25a75ca..debc16b 100644 --- a/syn.c +++ b/syn.c @@ -2,7 +2,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.16 2007/07/01 21:10:29 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.17 2007/08/19 23:12:23 tg Exp $"); struct nesting_state { int start_token; /* token than began nesting (eg, FOR) */ @@ -729,7 +729,7 @@ syntaxerr(const char *what) goto Again; } /* don't quote the EOF */ - yyerror("syntax error: unexpected EOF\n"); + yyerror("%s: unexpected EOF\n", T_synerr); /* NOTREACHED */ case LWORD: @@ -756,7 +756,7 @@ syntaxerr(const char *what) s = redir; } } - yyerror("syntax error: '%s' %s\n", s, what); + yyerror("%s: '%s' %s\n", T_synerr, s, what); } static void