All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tom Rini <trini@konsulko.com>
To: u-boot@lists.denx.de
Subject: [PATCH] squash! Remove some ifndef __U_BOOT__ checks in new hush
Date: Thu,  9 Nov 2023 14:12:00 -0500	[thread overview]
Message-ID: <20231109191200.3229267-1-trini@konsulko.com> (raw)
In-Reply-To: <20231107214121.132079-9-francis.laniel@amarulasolutions.com>

Looking at the code, we had a number of places where the blocks were:
#ifndef __U_BOOT__
...
#endif /* !__U_BOOT__ */

#ifndef __U_BOOT__
...
#endif /* !__U_BOOT__ */

And so we can just remove the center endif/ifndef. If the enclosed
functionality gets ported to U-Boot at some point in the future, then we
can re-enclose things as needed. In a similar manner, we sometimes had:

#ifndef __U_BOOT__
void foo(void)
{
...
#ifndef __U_BOOT__
...
#endif /* !__U_BOOT__ */
...
}
#endif /* !__U_BOOT__ */

And we can remove those inner tests, along the same thinking. If
appropriate later, we can add them when we do whatever else is needed
for that particular hush feature to be functional.

After this it would be good to compare the file with the upstream base
and ensure we don't have any extra empty lines, etc, anywhere.

Signed-off-by: Tom Rini <trini@konsulko.com>
---
 common/cli_hush_upstream.c | 58 +-------------------------------------
 1 file changed, 1 insertion(+), 57 deletions(-)

diff --git a/common/cli_hush_upstream.c b/common/cli_hush_upstream.c
index 709c055d2fdd..de9253c44aac 100644
--- a/common/cli_hush_upstream.c
+++ b/common/cli_hush_upstream.c
@@ -794,14 +794,12 @@ enum {
 	WORD_IS_KEYWORD       = 3,
 };
 
-#ifndef __U_BOOT__
 /* On program start, environ points to initial environment.
  * putenv adds new pointers into it, unsetenv removes them.
  * Neither of these (de)allocates the strings.
  * setenv allocates new strings in malloc space and does putenv,
  * and thus setenv is unusable (leaky) for shell's purposes */
 #define setenv(...) setenv_is_leaky_dont_use()
-#endif /* !__U_BOOT__ */
 struct variable {
 	struct variable *next;
 	char *varstr;        /* points to "name=" portion */
@@ -1004,11 +1002,9 @@ struct globals {
 #endif /* !__U_BOOT__ */
 	unsigned depth_of_loop;
 #endif
-#ifndef __U_BOOT__
 #if ENABLE_HUSH_GETOPTS
 	unsigned getopt_count;
 #endif
-#endif /* !__U_BOOT__ */
 	const char *ifs;
 #ifdef __U_BOOT__
 	int flag_repeat;
@@ -1881,10 +1877,8 @@ static void restore_G_args(save_arg_t *sv, char **argv)
 	G.global_argc = sv->sv_g_argc;
 	IF_HUSH_SET(G.global_args_malloced = sv->sv_g_malloced;)
 }
-#endif /* !__U_BOOT__ */
 
 
-#ifndef __U_BOOT__
 /* Basic theory of signal handling in shell
  * ========================================
  * This does not describe what hush does, rather, it is current understanding
@@ -2077,9 +2071,7 @@ static sighandler_t install_sighandler(int sig, sighandler_t handler)
 	sigaction(sig, &G.sa, &old_sa);
 	return old_sa.sa_handler;
 }
-#endif /* !__U_BOOT__ */
 
-#ifndef __U_BOOT__
 static void hush_exit(int exitcode) NORETURN;
 
 static void restore_ttypgrp_and__exit(void) NORETURN;
@@ -2178,9 +2170,7 @@ static sighandler_t pick_sighandler(unsigned sig)
 	}
 	return handler;
 }
-#endif /* !__U_BOOT__ */
 
-#ifndef __U_BOOT__
 /* Restores tty foreground process group, and exits. */
 static void hush_exit(int exitcode)
 {
@@ -2416,7 +2406,6 @@ static const char* FAST_FUNC get_local_var_value(const char *name)
 	return NULL;
 }
 
-#ifndef __U_BOOT__
 #if ENABLE_HUSH_GETOPTS
 static void handle_changed_special_names(const char *name)
 {
@@ -2429,19 +2418,13 @@ static void handle_changed_special_names(const char *name)
 /* Do not even bother evaluating arguments */
 # define handle_changed_special_names(...) ((void)0)
 #endif
-#else /* __U_BOOT__ */
-/* Do not even bother evaluating arguments */
-# define handle_changed_special_names(...) ((void)0)
-#endif /* __U_BOOT__ */
 
 /* str holds "NAME=VAL" and is expected to be malloced.
  * We take ownership of it.
  */
-#ifndef __U_BOOT__
 #define SETFLAG_EXPORT   (1 << 0)
 #define SETFLAG_UNEXPORT (1 << 1)
 #define SETFLAG_MAKE_RO  (1 << 2)
-#endif /* !__U_BOOT__ */
 #define SETFLAG_VARLVL_SHIFT   3
 #ifndef __U_BOOT__
 static int set_local_var(char *str, unsigned flags)
@@ -2926,11 +2909,7 @@ static void get_user_input(struct in_str *i)
 		G.flag_repeat = 0;
 	clear_ctrlc();
 	G.do_repeat = 0;
-#ifndef __U_BOOT__
-	if (G.promptmode == 1) {
-#else /* __U_BOOT__ */
 	if (!G.promptmode) {
-#endif /* __U_BOOT__ */
 		if (console_buffer[0] == '\n'&& G.flag_repeat == 0) {
 			strcpy(the_command, console_buffer);
 		}
@@ -2950,7 +2929,6 @@ static void get_user_input(struct in_str *i)
 			if (strlen(the_command) + strlen(console_buffer)
 				< CONFIG_SYS_CBSIZE) {
 				n = strlen(the_command);
-#ifdef __U_BOOT__
 				/*
 				 * To avoid writing to bad places, we check if
 				 * n is greater than 0.
@@ -2959,10 +2937,6 @@ static void get_user_input(struct in_str *i)
 				if (n > 0)
 					the_command[n-1] = ' ';
 				strcpy(&the_command[n], console_buffer);
-#else /* !__U_BOOT__ */
-			the_command[n-1] = ' ';
-			strcpy(&the_command[n], console_buffer);
-#endif /* !__U_BOOT__ */
 				}
 				else {
 					the_command[0] = '\n';
@@ -3014,14 +2988,12 @@ static int fgetc_interactive(struct in_str *i)
 	return ch;
 }
 #else  /* !INTERACTIVE */
-#ifndef __U_BOOT__
 static ALWAYS_INLINE int fgetc_interactive(struct in_str *i)
 {
 	int ch;
 	do ch = hfgetc(i->file); while (ch == '\0');
 	return ch;
 }
-#endif /* !__U_BOOT__ */
 #endif  /* !INTERACTIVE */
 
 static int i_getch(struct in_str *i)
@@ -3323,7 +3295,6 @@ static void nommu_addchr(o_string *o, int ch)
 # define nommu_addchr(o, str) ((void)0)
 #endif
 
-#ifndef __U_BOOT__
 #if ENABLE_HUSH_MODE_X
 static void x_mode_addchr(int ch)
 {
@@ -3354,7 +3325,6 @@ static void x_mode_flush(void)
 	G.x_mode_buf.length = 0;
 }
 #endif
-#endif /* !__U_BOOT__ */
 
 /*
  * HUSH_BRACE_EXPANSION code needs corresponding quoting on variable expansion side.
@@ -3975,12 +3945,10 @@ static struct pipe *free_pipe(struct pipe *pi)
 	}
 	free(pi->cmds);   /* children are an array, they get freed all at once */
 	//pi->cmds = NULL;
-#ifndef __U_BOOT__
 #if ENABLE_HUSH_JOB
 	free(pi->cmdtext);
 	//pi->cmdtext = NULL;
 #endif
-#endif /* !__U_BOOT__ */
 
 	next = pi->next;
 	free(pi);
@@ -4834,11 +4802,7 @@ static char *fetch_till_str(o_string *as_string,
 			nommu_addchr(as_string, ch);
 		if (ch == '\n' || ch == EOF) {
  check_heredoc_end:
-#ifndef __U_BOOT__
 			if ((heredoc_flags & HEREDOC_QUOTED) || prev != '\\') {
-#else /* __U_BOOT__ */
-			if (prev != '\\') {
-#endif
 				/* End-of-line, and not a line continuation */
 				if (strcmp(heredoc.data + past_EOL, word) == 0) {
 					heredoc.data[past_EOL] = '\0';
@@ -4858,11 +4822,7 @@ static char *fetch_till_str(o_string *as_string,
 						ch = i_getch(input);
 						if (ch != EOF)
 							nommu_addchr(as_string, ch);
-#ifndef __U_BOOT__
 					} while ((heredoc_flags & HEREDOC_SKIPTABS) && ch == '\t');
-#else /* __U_BOOT__ */
-				} while (ch == '\t');
-#endif
 					/* If this immediately ended the line,
 					 * go back to end-of-line checks.
 					 */
@@ -6913,7 +6873,6 @@ static NOINLINE int encode_then_append_var_plusminus(o_string *output, int n,
 }
 #endif /* !__U_BOOT__ */
 
-#ifndef __U_BOOT__
 #if ENABLE_FEATURE_SH_MATH
 static arith_t expand_and_evaluate_arith(const char *arg, const char **errmsg_p)
 {
@@ -6934,9 +6893,7 @@ static arith_t expand_and_evaluate_arith(const char *arg, const char **errmsg_p)
 	return res;
 }
 #endif
-#endif /* !__U_BOOT__ */
 
-#ifndef __U_BOOT__
 #if BASH_PATTERN_SUBST
 /* ${var/[/]pattern[/repl]} helpers */
 static char *strstr_pattern(char *val, const char *pattern, int *size)
@@ -7009,7 +6966,6 @@ static char *replace_pattern(char *val, const char *pattern, const char *repl, c
 	return result;
 }
 #endif /* BASH_PATTERN_SUBST */
-#endif /* !__U_BOOT__ */
 
 static int append_str_maybe_ifs_split(o_string *output, int n,
 		int first_ch, const char *val)
@@ -7800,9 +7756,7 @@ static void switch_off_special_sigs(unsigned mask)
 		install_sighandler(sig, SIG_DFL);
 	}
 }
-#endif /* !__U_BOOT__ */
 
-#ifndef __U_BOOT__
 #if BB_MMU
 /* never called */
 void re_execute_shell(char ***to_free, const char *s,
@@ -8153,7 +8107,6 @@ void parse_and_run_file(void)
 #endif /* !__U_BOOT__ */
 }
 
-#ifndef __U_BOOT__
 #if ENABLE_HUSH_TICK
 static int generate_stream_from_string(const char *s, pid_t *pid_p)
 {
@@ -8299,6 +8252,7 @@ static int process_command_subs(o_string *dest, const char *s)
 #endif /* ENABLE_HUSH_TICK */
 
 
+#ifndef __U_BOOT__
 static void setup_heredoc(struct redir_struct *redir)
 {
 	struct fd_pair pair;
@@ -8769,9 +8723,7 @@ static const char * FAST_FUNC hush_command_name(int i)
 	return NULL;
 }
 #endif
-#endif /* !__U_BOOT__ */
 
-#ifndef __U_BOOT__
 static void remove_nested_vars(void)
 {
 	struct variable *cur;
@@ -9041,10 +8993,8 @@ static void exec_builtin(char ***to_free,
 			argv);
 #endif
 }
-#endif /* !__U_BOOT__ */
 
 
-#ifndef __U_BOOT__
 static void execvp_or_die(char **argv) NORETURN;
 static void execvp_or_die(char **argv)
 {
@@ -9126,9 +9076,7 @@ static void dump_cmd_in_x_mode(char **argv)
 #else
 # define dump_cmd_in_x_mode(argv) ((void)0)
 #endif
-#endif /* !__U_BOOT__ */
 
-#ifndef __U_BOOT__
 #if ENABLE_HUSH_COMMAND
 static void if_command_vV_print_and_exit(char opt_vV, char *cmd, const char *explanation)
 {
@@ -9154,7 +9102,6 @@ static void if_command_vV_print_and_exit(char opt_vV, char *cmd, const char *exp
 #else
 # define if_command_vV_print_and_exit(a,b,c) ((void)0)
 #endif
-#endif /* !__U_BOOT__ */
 
 #if BB_MMU
 #define pseudo_exec_argv(nommu_save, argv, assignment_cnt, argv_expanded) \
@@ -9163,7 +9110,6 @@ static void if_command_vV_print_and_exit(char opt_vV, char *cmd, const char *exp
 	pseudo_exec(command, argv_expanded)
 #endif
 
-#ifndef __U_BOOT__
 /* Called after [v]fork() in run_pipe, or from builtin_exec.
  * Never returns.
  * Don't exit() here.  If you don't exec, use _exit instead.
@@ -11300,7 +11246,6 @@ int hush_main(int argc, char **argv)
 		}
 	}
 
-#ifndef __U_BOOT__
 	/* -c takes effect *after* -l */
 	if (G.opt_c) {
 		/* Possibilities:
@@ -11377,7 +11322,6 @@ int hush_main(int argc, char **argv)
 	/* "implicit" -s: bare interactive hush shows 's' in $- */
 	G.opt_s = 1;
 
-#endif /* __U_BOOT__ */
 	/* Up to here, shell was non-interactive. Now it may become one.
 	 * NB: don't forget to (re)run install_special_sighandlers() as needed.
 	 */
-- 
2.34.1


  parent reply	other threads:[~2023-11-09 19:12 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-07 21:40 [PATCH v11 00/24] Modernize U-Boot shell Francis Laniel
2023-11-07 21:40 ` [PATCH v11 01/24] test: Add framework to test hush behavior Francis Laniel
2023-11-07 21:40 ` [PATCH v11 02/24] test: hush: Test hush if/else Francis Laniel
2023-11-07 21:41 ` [PATCH v11 03/24] test/py: hush_if_test: Remove the test file Francis Laniel
2023-11-07 21:41 ` [PATCH v11 04/24] test: hush: Test hush variable expansion Francis Laniel
2023-11-07 21:41 ` [PATCH v11 05/24] test: hush: Test hush commands list Francis Laniel
2023-11-07 21:41 ` [PATCH v11 06/24] test: hush: Test hush loops Francis Laniel
2023-11-07 21:41 ` [PATCH v11 07/24] cli: Add Busybox upstream hush.c file Francis Laniel
2023-11-07 21:41 ` [PATCH v11 08/24] cli: Port Busybox 2021 hush to U-Boot Francis Laniel
2023-11-09 13:37   ` Tom Rini
2023-11-09 19:12   ` Tom Rini [this message]
2023-11-07 21:41 ` [PATCH v11 09/24] cli: Add menu for hush parser Francis Laniel
2023-11-09 13:38   ` Tom Rini
2023-11-07 21:41 ` [PATCH v11 10/24] global_data.h: add GD_FLG_HUSH_OLD_PARSER flag Francis Laniel
2023-11-07 21:41 ` [PATCH v11 11/24] cmd: Add new cli command Francis Laniel
2023-11-07 21:41 ` [PATCH v11 12/24] cli: Enables using hush 2021 parser as command line parser Francis Laniel
2023-11-07 21:41 ` [PATCH v11 13/24] cli: hush_2021: Enable variables expansion for hush 2021 Francis Laniel
2023-11-07 21:41 ` [PATCH v11 14/24] cli: hush_2021: Add functions to be called from run_command() Francis Laniel
2023-11-07 21:41 ` [PATCH v11 15/24] cli: add hush 2021 as parser for run_command*() Francis Laniel
2023-11-07 21:41 ` [PATCH v11 16/24] test: hush: Fix instructions list tests for hush 2021 Francis Laniel
2023-11-07 21:41 ` [PATCH v11 17/24] test: hush: Fix variable expansion " Francis Laniel
2023-11-07 21:41 ` [PATCH v11 18/24] cli: hush_2021: Enable using < and > as string compare operators Francis Laniel
2023-11-07 21:41 ` [PATCH v11 19/24] cli: hush_2021: Enable if keyword Francis Laniel
2023-11-07 21:41 ` [PATCH v11 20/24] cli: hush_2021: Enable loops Francis Laniel
2023-11-07 21:41 ` [PATCH v11 21/24] test: hush: Fix loop tests for hush 2021 Francis Laniel
2023-11-07 21:41 ` [PATCH v11 22/24] cli: hush_2021: Add upstream commits up to 2nd October 2023 Francis Laniel
2023-11-07 21:41 ` [PATCH v11 23/24] DO NOT MERGE: only to make CI happy Francis Laniel
2023-11-09 13:37   ` Tom Rini
2023-11-07 21:41 ` [PATCH v11 24/24] DO NOT MERGE: ci: Build the world in any case Francis Laniel
2023-11-08 22:56   ` Tom Rini
2023-11-08 12:14 ` [PATCH v11 00/24] Modernize U-Boot shell Peter Robinson
2023-11-09  1:15   ` Simon Glass
2023-11-09  2:42   ` Tom Rini
2023-11-09 13:37   ` Tom Rini

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=20231109191200.3229267-1-trini@konsulko.com \
    --to=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.