git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] parse-options: make OPT_NUMBER's argh explicit

From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
Date
Jun 3, 2009, 20:22 UTC
Message-ID
<4A26DBA3.90604@lsrfire.ath.cx>
In-Reply-To
<780e0a6b0906031235q1438b76cyba1172556c94d1d0@mail.gmail.com>
Stephen Boyd schrieb:
Show 8 quoted lines
> On Wed, Jun 3, 2009 at 3:18 AM, René Scharfe<rene.scharfe@lsrfire.ath.cx> wrote:
>> By the way, can the switch be replaced by a simple check for
>> PARSE_OPT_NOARG now?
>>
> 
> This looks possible. I think just set PARSE_OPT_NOARG as the flag of
> the appropriate OPT_* macros. I'll have to grep the tree for custom
> uses of OPTION_* though.

Yes, it's only worthwhile if there aren't too many special cases that require explicit setting of PARSE_OPT_NOARG.

> 
> Should that be all squashed together? Or maybe that could be a follow up patch?

Your existing patch looks fine as is, I'd keep additional changes separate.

Hmm, and how about the following in between them?
 parse-options.c |   16 +++-------------
 1 files changed, 3 insertions(+), 13 deletions(-)
diff --git a/parse-options.c b/parse-options.c
index b85cab2..dda36b1 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -440,7 +440,7 @@ int parse_options(int argc, const char **argv, const char *prefix,
 static int usage_argh(const struct option *opts)
 {
 	const char *s;
-	int literal = opts->flags & PARSE_OPT_LITERAL_ARGHELP;
+	int literal = (opts->flags & PARSE_OPT_LITERAL_ARGHELP) || !opt->argh;
 	if (opts->flags & PARSE_OPT_OPTARG)
 		if (opts->long_name)
 			s = literal ? "[=%s]" : "[=<%s>]";
@@ -448,7 +448,7 @@ static int usage_argh(const struct option *opts)
 			s = literal ? "[%s]" : "[<%s>]";
 	else
 		s = literal ? " %s" : " <%s>";
-	return fprintf(stderr, s, opts->argh);
+	return fprintf(stderr, s, opt->argh ? opt->argh : "...");
 }
 
 #define USAGE_OPTS_WIDTH 24
@@ -519,17 +519,7 @@ int usage_with_options_internal(const char * const *usagestr,
 		case OPTION_FILENAME:
 			/* FALLTHROUGH */
 		case OPTION_STRING:
-			if (opts->argh)
-				pos += usage_argh(opts);
-			else {
-				if (opts->flags & PARSE_OPT_OPTARG)
-					if (opts->long_name)
-						pos += fprintf(stderr, "[=...]");
-					else
-						pos += fprintf(stderr, "[...]");
-				else
-					pos += fprintf(stderr, " ...");
-			}
+			pos += usage_argh(opts);
 			break;
 		default: /* OPTION_{BIT,BOOLEAN,NUMBER,SET_INT,SET_PTR} */
 			break;
Previous: Stephen BoydNext: Stephen Boyd
Message 4 of 7 in “parse-options: make OPT_NUMBER's argh explicit”
  1. parse-options: make OPT_NUMBER's argh explicitStephen Boyd, Jun 3, 2009
  2. René ScharfeJun 3, 2009
  3. Stephen BoydJun 3, 2009
  4. René ScharfeJun 3, 2009
  5. 1/2 parse-options: make OPT_INTEGER's argh explicitStephen Boyd, Jun 4, 2009
  6. 2/2 parse-options: simplify usage argh handlingStephen Boyd, Jun 4, 2009
  7. René ScharfeJun 6, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.