@@ -1020,9 +1020,28 @@ static int usage_argh(const struct option *opts, FILE *outfile)
1020
1020
return utf8_fprintf (outfile , s , opts -> argh ? _ (opts -> argh ) : _ ("..." ));
1021
1021
}
1022
1022
1023
+ static int usage_indent (FILE * outfile )
1024
+ {
1025
+ return fprintf (outfile , " " );
1026
+ }
1027
+
1023
1028
#define USAGE_OPTS_WIDTH 24
1024
1029
#define USAGE_GAP 2
1025
1030
1031
+ static void usage_padding (FILE * outfile , size_t pos )
1032
+ {
1033
+ int pad ;
1034
+ if (pos == USAGE_OPTS_WIDTH + 1 )
1035
+ pad = -1 ;
1036
+ else if (pos <= USAGE_OPTS_WIDTH )
1037
+ pad = USAGE_OPTS_WIDTH - pos ;
1038
+ else {
1039
+ fputc ('\n' , outfile );
1040
+ pad = USAGE_OPTS_WIDTH ;
1041
+ }
1042
+ fprintf (outfile , "%*s" , pad + USAGE_GAP , "" );
1043
+ }
1044
+
1026
1045
static enum parse_opt_result usage_with_options_internal (struct parse_opt_ctx_t * ctx ,
1027
1046
const char * const * usagestr ,
1028
1047
const struct option * opts ,
@@ -1108,7 +1127,6 @@ static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t
1108
1127
1109
1128
for (; opts -> type != OPTION_END ; opts ++ ) {
1110
1129
size_t pos ;
1111
- int pad ;
1112
1130
const char * cp , * np ;
1113
1131
1114
1132
if (opts -> type == OPTION_SUBCOMMAND )
@@ -1128,7 +1146,7 @@ static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t
1128
1146
need_newline = 0 ;
1129
1147
}
1130
1148
1131
- pos = fprintf (outfile , " " );
1149
+ pos = usage_indent (outfile );
1132
1150
if (opts -> short_name ) {
1133
1151
if (opts -> flags & PARSE_OPT_NODASH )
1134
1152
pos += fprintf (outfile , "%c" , opts -> short_name );
@@ -1152,29 +1170,20 @@ static enum parse_opt_result usage_with_options_internal(struct parse_opt_ctx_t
1152
1170
!(opts -> flags & PARSE_OPT_NOARG ))
1153
1171
pos += usage_argh (opts , outfile );
1154
1172
1155
- if (pos == USAGE_OPTS_WIDTH + 1 )
1156
- pad = -1 ;
1157
- else if (pos <= USAGE_OPTS_WIDTH )
1158
- pad = USAGE_OPTS_WIDTH - pos ;
1159
- else {
1160
- fputc ('\n' , outfile );
1161
- pad = USAGE_OPTS_WIDTH ;
1162
- }
1163
1173
if (opts -> type == OPTION_ALIAS ) {
1164
- fprintf (outfile , "%*s" , pad + USAGE_GAP , "" );
1174
+ usage_padding (outfile , pos );
1165
1175
fprintf_ln (outfile , _ ("alias of --%s" ),
1166
1176
(const char * )opts -> value );
1167
1177
continue ;
1168
1178
}
1169
1179
1170
1180
for (cp = _ (opts -> help ); * cp ; cp = np ) {
1171
1181
np = strchrnul (cp , '\n' );
1172
- fprintf (outfile ,
1173
- "%*s%.*s\n" , pad + USAGE_GAP , "" ,
1174
- (int )(np - cp ), cp );
1182
+ usage_padding (outfile , pos );
1183
+ fprintf (outfile , "%.*s\n" , (int )(np - cp ), cp );
1175
1184
if (* np )
1176
1185
np ++ ;
1177
- pad = USAGE_OPTS_WIDTH ;
1186
+ pos = 0 ;
1178
1187
}
1179
1188
}
1180
1189
fputc ('\n' , outfile );
0 commit comments