From: Joakim Tjernlund Date: Mon, 21 Apr 2008 09:38:38 +0200 Subject: [U-Boot-Users] [PATCH] fw_printenv: Add -v and -q options. In-Reply-To: <20080420232327.DF45E248A6@gemini.denx.de> References: <20080420232327.DF45E248A6@gemini.denx.de> Message-ID: <1208763518.23644.44.camel@gentoo-jocke.transmode.se> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Mon, 2008-04-21 at 01:23 +0200, Wolfgang Denk wrote: > In message <1208527021-16460-1-git-send-email-Joakim.Tjernlund@transmode.se> you wrote: > > Add -v for verbose output, "Unlocking flash...", "Done" etc. > > Add -q for quiet operation, do not print error and verbose > > messages. > > This seems kind of redundandant to me. > > And not printing error messages seems an error to me. Perhaps a little overkill. How about removing the -v printouts "Unlocking flash...", "Done" etc. and removing the "## Error: \"%s\" not defined\n", name); message? The verbose messages are a bit annoying when using it interactively and the error message when it can't find a variable too. Note that this particular error message is only printed when using the -n option. > > > Add a --help(-help, -?) option too. > > > > The -q option is intended for scripting. > > Feel free to add "2>/dev/null" to your scripts when you think this is > really what you want to have. Yes, can do that too, just figured I could add a -q while I was at it. > > > +int check_option(int *argc, char *argv[], const char *option) > > +{ > > + int i,j; > > + > > + for (i = 1; i < *argc; i++) > > + if (strcmp (argv[i], option) == 0) { > > + for (j=i; j < *argc; j++) > > + argv[j] = argv[j+1]; /* remove option */ > > + *argc -= 1; > > + return 1; > > + } > > + return 0; > > +} > > + > > +void check_quiet(int *argc, char *argv[]) > > +{ > > + if (check_option(argc, argv, "-q")) > > + fw_quiet = 1; > > +} > > + > > +void check_verbose(int *argc, char *argv[]) > > +{ > > + if (check_option(argc, argv, "-v")) > > + fw_verbose = 1; > > +} > > I've seen many diffeent versions of argument checking code. This is > not a nice one. See for example "tools/mkimage.c" for the "classic" > approach. :), I figured it was creative so I didn't have to touch so much of the existing code.