@@ -193,13 +193,14 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,
193193 arg_end = arg + strlen (arg );
194194
195195 for (; options -> type != OPTION_END ; options ++ ) {
196- const char * rest ;
197- int flags = 0 ;
196+ const char * rest , * long_name = options -> long_name ;
197+ int flags = 0 , opt_flags = 0 ;
198198
199- if (!options -> long_name )
199+ if (!long_name )
200200 continue ;
201201
202- rest = skip_prefix (arg , options -> long_name );
202+ again :
203+ rest = skip_prefix (arg , long_name );
203204 if (options -> type == OPTION_ARGUMENT ) {
204205 if (!rest )
205206 continue ;
@@ -212,7 +213,7 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,
212213 }
213214 if (!rest ) {
214215 /* abbreviated? */
215- if (!strncmp (options -> long_name , arg , arg_end - arg )) {
216+ if (!strncmp (long_name , arg , arg_end - arg )) {
216217is_abbreviated :
217218 if (abbrev_option ) {
218219 /*
@@ -227,7 +228,7 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,
227228 if (!(flags & OPT_UNSET ) && * arg_end )
228229 p -> opt = arg_end + 1 ;
229230 abbrev_option = options ;
230- abbrev_flags = flags ;
231+ abbrev_flags = flags ^ opt_flags ;
231232 continue ;
232233 }
233234 /* negation allowed? */
@@ -239,12 +240,18 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,
239240 goto is_abbreviated ;
240241 }
241242 /* negated? */
242- if (strncmp (arg , "no-" , 3 ))
243+ if (prefixcmp (arg , "no-" )) {
244+ if (!prefixcmp (long_name , "no-" )) {
245+ long_name += 3 ;
246+ opt_flags |= OPT_UNSET ;
247+ goto again ;
248+ }
243249 continue ;
250+ }
244251 flags |= OPT_UNSET ;
245- rest = skip_prefix (arg + 3 , options -> long_name );
252+ rest = skip_prefix (arg + 3 , long_name );
246253 /* abbreviated and negated? */
247- if (!rest && !prefixcmp (options -> long_name , arg + 3 ))
254+ if (!rest && !prefixcmp (long_name , arg + 3 ))
248255 goto is_abbreviated ;
249256 if (!rest )
250257 continue ;
@@ -254,7 +261,7 @@ static int parse_long_opt(struct parse_opt_ctx_t *p, const char *arg,
254261 continue ;
255262 p -> opt = rest + 1 ;
256263 }
257- return get_value (p , options , flags );
264+ return get_value (p , options , flags ^ opt_flags );
258265 }
259266
260267 if (ambiguous_option )
@@ -526,7 +533,7 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,
526533 continue ;
527534
528535 pos = fprintf (outfile , " " );
529- if (opts -> short_name && !( opts -> flags & PARSE_OPT_NEGHELP ) ) {
536+ if (opts -> short_name ) {
530537 if (opts -> flags & PARSE_OPT_NODASH )
531538 pos += fprintf (outfile , "%c" , opts -> short_name );
532539 else
@@ -535,9 +542,7 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,
535542 if (opts -> long_name && opts -> short_name )
536543 pos += fprintf (outfile , ", " );
537544 if (opts -> long_name )
538- pos += fprintf (outfile , "--%s%s" ,
539- (opts -> flags & PARSE_OPT_NEGHELP ) ? "no-" : "" ,
540- opts -> long_name );
545+ pos += fprintf (outfile , "--%s" , opts -> long_name );
541546 if (opts -> type == OPTION_NUMBER )
542547 pos += fprintf (outfile , "-NUM" );
543548
0 commit comments