employ string pooling techniques to save off a few more bytes

(probably more than the new “rename” builtin ever required…)
This commit is contained in:
tg
2007-08-19 23:12:23 +00:00
parent ca46f3dc98
commit 1e3783f030
4 changed files with 26 additions and 17 deletions

View File

@ -5,7 +5,7 @@
#include "sh.h" #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 assignments before command are kept;
* a leading * means a POSIX special builtin; * a leading * means a POSIX special builtin;
@ -3033,7 +3033,7 @@ c_rename(const char **wp)
wp[1] == NULL /* first argument */ || wp[1] == NULL /* first argument */ ||
wp[2] == NULL /* second argument */ || wp[2] == NULL /* second argument */ ||
wp[3] != NULL /* no further args please */) wp[3] != NULL /* no further args please */)
bi_errorf("syntax error"); bi_errorf(T_synerr);
else if ((rv = rename(wp[1], wp[2])) != 0) { else if ((rv = rename(wp[1], wp[2])) != 0) {
rv = errno; rv = errno;
bi_errorf("failed: %s", strerror(rv)); bi_errorf("failed: %s", strerror(rv));

27
lex.c
View File

@ -2,7 +2,7 @@
#include "sh.h" #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 /* Structure to keep track of the lexing state and the various pieces of info
* needed for each particular state. */ * needed for each particular state. */
@ -182,22 +182,29 @@ yylex(int cf)
if (statep->ls_sadelim.style == SADELIM_MAKE && if (statep->ls_sadelim.style == SADELIM_MAKE &&
statep->ls_sadelim.num == 1) { statep->ls_sadelim.num == 1) {
if (c == /*{*/'}') if (c == /*{*/'}')
yyerror("syntax error: expected" yyerror("%s: expected '%c' %s\n",
/* { */ " '%c' before '}'\n", T_synerr,
statep->ls_sadelim.delimiter); statep->ls_sadelim.delimiter,
/*{*/ "before '}'");
else { else {
*wp++ = ADELIM; *wp++ = ADELIM;
*wp++ = c; /* .delimiter */ *wp++ = c; /* .delimiter */
while ((c = getsc()) != /*{*/ '}') { while ((c = getsc()) != /*{*/ '}') {
if (!c) { if (!c) {
yyerror("syntax error: expected" yyerror("%s: expected '%c' %s\n",
/* { */ " '}' before end of input\n"); T_synerr,
/*{*/ '}', "at end of input");
} else if (strchr(sadelim_flags[statep->ls_sadelim.flags], c)) { } else if (strchr(sadelim_flags[statep->ls_sadelim.flags], c)) {
*wp++ = CHAR; *wp++ = CHAR;
*wp++ = c; *wp++ = c;
} else } else {
yyerror("syntax error: expected" char Ttmp[15] = "instead of ' '";
/* { */ " '}' instead of '%c'\n", c);
Ttmp[12] = c;
yyerror("%s: expected '%c' %s\n",
T_synerr,
/*{*/ '}', Ttmp);
}
} }
} }
} }
@ -709,7 +716,7 @@ yylex(int cf)
yyerror("no closing quote\n"); yyerror("no closing quote\n");
if (state == SLETARRAY && statep->ls_sletarray.nparen != -1) 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 */ /* This done to avoid tests for SHEREDELIM wherever SBASE tested */
if (state == SHEREDELIM) if (state == SHEREDELIM)

6
sh.h
View File

@ -8,7 +8,7 @@
/* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */ /* $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 $ */ /* $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" #define MKSH_VERSION "R31 2007/08/19"
#if HAVE_SYS_PARAM_H #if HAVE_SYS_PARAM_H
@ -439,7 +439,9 @@ enum sh_flag {
EXTERN char shell_flags[FNFLAGS]; EXTERN char shell_flags[FNFLAGS];
/* null value for variable; comparision pointer for unset */ /* 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 { enum temp_type {
TT_HEREDOC_EXP, /* expanded heredoc */ TT_HEREDOC_EXP, /* expanded heredoc */

6
syn.c
View File

@ -2,7 +2,7 @@
#include "sh.h" #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 { struct nesting_state {
int start_token; /* token than began nesting (eg, FOR) */ int start_token; /* token than began nesting (eg, FOR) */
@ -729,7 +729,7 @@ syntaxerr(const char *what)
goto Again; goto Again;
} }
/* don't quote the EOF */ /* don't quote the EOF */
yyerror("syntax error: unexpected EOF\n"); yyerror("%s: unexpected EOF\n", T_synerr);
/* NOTREACHED */ /* NOTREACHED */
case LWORD: case LWORD:
@ -756,7 +756,7 @@ syntaxerr(const char *what)
s = redir; s = redir;
} }
} }
yyerror("syntax error: '%s' %s\n", s, what); yyerror("%s: '%s' %s\n", T_synerr, s, what);
} }
static void static void