aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2025-08-18 13:55:09 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2025-08-18 13:55:09 +0200
commit5d66c8a602a4604d5683ad42f692dbae19fc1693 (patch)
tree4a5921b2efef6f65474127885507698e7d521d50 /shell
parent5c2c2916fc9254793f711503030ba997112db6e4 (diff)
downloadbusybox-w32-5d66c8a602a4604d5683ad42f692dbae19fc1693.tar.gz
busybox-w32-5d66c8a602a4604d5683ad42f692dbae19fc1693.tar.bz2
busybox-w32-5d66c8a602a4604d5683ad42f692dbae19fc1693.zip
hush: shrink "function" code
function old new delta done_word 766 777 +11 static.reserved_match 16 12 -4 reserved_list 240 168 -72 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/2 up/down: 11/-76) Total: -65 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell')
-rw-r--r--shell/hush.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 1495db373..8aa923e2e 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -4213,7 +4213,7 @@ static void initialize_context(struct parse_context *ctx)
4213 */ 4213 */
4214#if HAS_KEYWORDS 4214#if HAS_KEYWORDS
4215struct reserved_combo { 4215struct reserved_combo {
4216 char literal[ENABLE_HUSH_FUNCTION_KEYWORD ? 9 : 6]; 4216 char literal[6];
4217 unsigned char res; 4217 unsigned char res;
4218 unsigned char assignment_flag; 4218 unsigned char assignment_flag;
4219 uint32_t flag; 4219 uint32_t flag;
@@ -4248,9 +4248,6 @@ enum {
4248 * FLAG_START means the word must start a new compound list. 4248 * FLAG_START means the word must start a new compound list.
4249 */ 4249 */
4250static const struct reserved_combo reserved_list[] ALIGN4 = { 4250static const struct reserved_combo reserved_list[] ALIGN4 = {
4251# if ENABLE_HUSH_FUNCTION_KEYWORD
4252 { "function", RES_NONE, NOT_ASSIGNMENT, 0 },
4253# endif
4254# if ENABLE_HUSH_IF 4251# if ENABLE_HUSH_IF
4255 { "!", RES_NONE, NOT_ASSIGNMENT , 0 }, 4252 { "!", RES_NONE, NOT_ASSIGNMENT , 0 },
4256 { "if", RES_IF, MAYBE_ASSIGNMENT, FLAG_THEN | FLAG_START }, 4253 { "if", RES_IF, MAYBE_ASSIGNMENT, FLAG_THEN | FLAG_START },
@@ -4293,6 +4290,15 @@ static const struct reserved_combo* reserved_word(struct parse_context *ctx)
4293# endif 4290# endif
4294 const struct reserved_combo *r; 4291 const struct reserved_combo *r;
4295 4292
4293# if ENABLE_HUSH_FUNCTION_KEYWORD
4294 /* This is ~60 bytes smaller than adding "function" to reserved_list[] */
4295 if (strcmp(ctx->word.data, "function") == 0) {
4296 ctx->command->cmd_type = CMD_FUNCTION_KWORD;
4297 /* Return something harmless !NULL */
4298 return &reserved_list[0];
4299 }
4300# endif
4301
4296 r = match_reserved_word(ctx->word.data); 4302 r = match_reserved_word(ctx->word.data);
4297 if (!r) 4303 if (!r)
4298 return r; /* NULL */ 4304 return r; /* NULL */
@@ -4317,13 +4323,7 @@ static const struct reserved_combo* reserved_word(struct parse_context *ctx)
4317 r = &reserved_match; 4323 r = &reserved_match;
4318 } else 4324 } else
4319# endif 4325# endif
4320 if (r->flag == 0) { /* 'function' or '!' */ 4326 if (r->flag == 0) { /* '!' */
4321# if ENABLE_HUSH_FUNCTION_KEYWORD
4322 if (r == &reserved_list[0]) {
4323 ctx->command->cmd_type = CMD_FUNCTION_KWORD;
4324 return r;
4325 }
4326# endif
4327 if (ctx->pipe->num_cmds != 0 /* bash disallows: nice | ! cat */ 4327 if (ctx->pipe->num_cmds != 0 /* bash disallows: nice | ! cat */
4328 /* || ctx->pipe->pi_inverted - bash used to disallow "! ! true" bash 5.2.15 allows it */ 4328 /* || ctx->pipe->pi_inverted - bash used to disallow "! ! true" bash 5.2.15 allows it */
4329 ) { 4329 ) {