[U-Boot] [PATCH v2 8/8] sandbox: Add basic command line parsing

Mike Frysinger vapier at gentoo.org
Fri Jan 20 20:05:22 CET 2012


On Tuesday 10 January 2012 19:45:52 Simon Glass wrote:
> --- a/arch/sandbox/cpu/os.c
> +++ b/arch/sandbox/cpu/os.c
>
> +static struct option long_options[] = {

constify

> +void os_usage(int err)
> +{
> +	if (err < 0)
> +		fprintf(stderr, "Try `--help' for more information.\n");
> +	fprintf(stderr, "u-boot, "
> +		"a command line test interface to U-Boot\n\n"
> +		"usage:\tu-boot [-ch]\n"
> +		"Options:\n"
> +		"\t-h\tDisplay help\n"
> +		"\t-c <command>\tExecute U-Boot command\n");
> +	exit(1);
> +}

os_usage() should only write to stderr/exit(1) if it's an error, otherwise it 
should use stdout/exit(0)

> +int os_parse_args(struct sandbox_state *state, int argc, char *argv[])
> +{
> ...
> +	while ((c = getopt_long(argc, argv, "c:h",
> +		long_options, NULL)) != EOF) {

pull the optstring ("c:h") out of the getopt_long call and put it into a const 
next to the long_options[] variable

and next to opts array

> +	/* Execute command if required */
> +	if (state->cmd) {
> +		/* TODO: redo this when cmd tidy-up series lands */
> +#ifdef CONFIG_SYS_HUSH_PARSER
> +		run_command(state->cmd, 0);
> +#else
> +		parse_string_outer(state->cmd, FLAG_PARSE_SEMICOLON |
> +				    FLAG_EXIT_FROM_LOOP);
> +#endif

i'm not sure how useful -c is since we can already do:
          ./u-boot <<<"some command"

each to their own i guess ...
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120120/24202753/attachment.pgp>


More information about the U-Boot mailing list