@@ -72,7 +72,7 @@ cli_print_prefix (const char *str, /**< string to print */
72
72
static void
73
73
cli_print_help (const char * help ) /**< the help message to print */
74
74
{
75
- for (; help != NULL && * help != 0 ; )
75
+ while ( help != NULL && * help != 0 )
76
76
{
77
77
int length = -1 ;
78
78
int i = 0 ;
@@ -148,24 +148,24 @@ cli_opt_process (cli_opt_state_t *state) /**< state of the command line option p
148
148
149
149
state -> arg = state -> argv ;
150
150
151
- for (const cli_opt_t * opts = state -> opts ; opts -> id != CLI_OPT_END ; opts ++ )
151
+ for (const cli_opt_t * o = state -> opts ; o -> id != CLI_OPT_END ; o ++ )
152
152
{
153
- state -> opt = opts ;
153
+ state -> opt = o ;
154
154
155
- if (opts -> id == CLI_OPT_POSITIONAL && (state -> arg [0 ][0 ] != '-' || !strcmp (state -> arg [0 ], "-" )))
155
+ if (o -> id == CLI_OPT_POSITIONAL && (state -> arg [0 ][0 ] != '-' || !strcmp (state -> arg [0 ], "-" )))
156
156
{
157
157
state -> argc -- ;
158
158
state -> argv ++ ;
159
159
return CLI_OPT_POSITIONAL ;
160
160
}
161
- else if ((opts -> opt != NULL && !strcmp (opts -> opt , state -> arg [0 ]))
162
- || (opts -> longopt != NULL && !strcmp (opts -> longopt , state -> arg [0 ])))
161
+ else if ((o -> opt != NULL && !strcmp (o -> opt , state -> arg [0 ]))
162
+ || (o -> longopt != NULL && !strcmp (o -> longopt , state -> arg [0 ])))
163
163
{
164
- if (state -> argc > opts -> argc )
164
+ if (state -> argc > o -> argc )
165
165
{
166
- state -> argc -= 1 + opts -> argc ;
167
- state -> argv += 1 + opts -> argc ;
168
- return opts -> id ;
166
+ state -> argc -= 1 + o -> argc ;
167
+ state -> argv += 1 + o -> argc ;
168
+ return o -> id ;
169
169
}
170
170
else
171
171
{
@@ -192,18 +192,18 @@ cli_opt_usage (const char *progname, /**< program name, typically argv[0] */
192
192
int length = (int ) strlen (progname );
193
193
printf ("%s" , progname );
194
194
195
- for (; opts -> id != CLI_OPT_END ; opts ++ )
195
+ for (const cli_opt_t * o = opts ; o -> id != CLI_OPT_END ; o ++ )
196
196
{
197
- const char * opt = opts -> opt != NULL ? opts -> opt : opts -> longopt ;
198
- opt = opt != NULL ? opt : opts -> meta ;
197
+ const char * opt = o -> opt != NULL ? o -> opt : o -> longopt ;
198
+ opt = opt != NULL ? opt : o -> meta ;
199
199
200
200
int opt_length = (int ) strlen (opt );
201
- if (opts -> argc > 0 )
201
+ if (o -> argc > 0 )
202
202
{
203
- opt_length += opts -> meta != NULL ? 1 + (int ) strlen (opts -> meta ) : opts -> argc * 2 ;
203
+ opt_length += o -> meta != NULL ? 1 + (int ) strlen (opts -> meta ) : o -> argc * 2 ;
204
204
}
205
- opt_length += opts -> quant == CLI_QUANT_Q || opts -> quant == CLI_QUANT_A ? 2 : 0 ;
206
- opt_length += opts -> quant == CLI_QUANT_P || opts -> quant == CLI_QUANT_A ? 3 : 0 ;
205
+ opt_length += o -> quant == CLI_QUANT_Q || o -> quant == CLI_QUANT_A ? 2 : 0 ;
206
+ opt_length += o -> quant == CLI_QUANT_P || o -> quant == CLI_QUANT_A ? 3 : 0 ;
207
207
208
208
if (length + 1 + opt_length >= CLI_LINE_LENGTH )
209
209
{
@@ -215,34 +215,34 @@ cli_opt_usage (const char *progname, /**< program name, typically argv[0] */
215
215
216
216
printf (" " );
217
217
218
- if (opts -> quant == CLI_QUANT_Q || opts -> quant == CLI_QUANT_A )
218
+ if (o -> quant == CLI_QUANT_Q || o -> quant == CLI_QUANT_A )
219
219
{
220
220
printf ("[" );
221
221
}
222
222
223
223
printf ("%s" , opt );
224
224
225
- if (opts -> argc > 0 )
225
+ if (o -> argc > 0 )
226
226
{
227
- if (opts -> meta != NULL )
227
+ if (o -> meta != NULL )
228
228
{
229
- printf (" %s" , opts -> meta );
229
+ printf (" %s" , o -> meta );
230
230
}
231
231
else
232
232
{
233
- for (int argi = 0 ; argi < opts -> argc ; argi ++ )
233
+ for (int i = 0 ; i < o -> argc ; i ++ )
234
234
{
235
235
printf (" _" );
236
236
}
237
237
}
238
238
}
239
239
240
- if (opts -> quant == CLI_QUANT_Q || opts -> quant == CLI_QUANT_A )
240
+ if (o -> quant == CLI_QUANT_Q || o -> quant == CLI_QUANT_A )
241
241
{
242
242
printf ("]" );
243
243
}
244
244
245
- if (opts -> quant == CLI_QUANT_P || opts -> quant == CLI_QUANT_A )
245
+ if (o -> quant == CLI_QUANT_P || o -> quant == CLI_QUANT_A )
246
246
{
247
247
printf ("..." );
248
248
}
@@ -257,52 +257,52 @@ cli_opt_usage (const char *progname, /**< program name, typically argv[0] */
257
257
void
258
258
cli_opt_help (const cli_opt_t * opts ) /**< array of command line option definitions, terminated by CLI_OPT_END */
259
259
{
260
- for (; opts -> id != CLI_OPT_END ; opts ++ )
260
+ for (const cli_opt_t * o = opts ; o -> id != CLI_OPT_END ; o ++ )
261
261
{
262
262
int length = CLI_LINE_INDENT ;
263
263
cli_print_pad (length );
264
264
265
- if (opts -> opt != NULL )
265
+ if (o -> opt != NULL )
266
266
{
267
- printf ("%s" , opts -> opt );
268
- length += (int ) strlen (opts -> opt );
267
+ printf ("%s" , o -> opt );
268
+ length += (int ) strlen (o -> opt );
269
269
}
270
270
271
- if (opts -> opt != NULL && opts -> longopt != NULL )
271
+ if (o -> opt != NULL && o -> longopt != NULL )
272
272
{
273
273
printf (", " );
274
274
length += 2 ;
275
275
}
276
276
277
- if (opts -> longopt != NULL )
277
+ if (o -> longopt != NULL )
278
278
{
279
- printf ("%s" , opts -> longopt );
280
- length += (int ) strlen (opts -> longopt );
279
+ printf ("%s" , o -> longopt );
280
+ length += (int ) strlen (o -> longopt );
281
281
}
282
282
283
- if (opts -> opt == NULL && opts -> longopt == NULL )
283
+ if (o -> opt == NULL && o -> longopt == NULL )
284
284
{
285
- printf ("%s" , opts -> meta );
286
- length += (int ) strlen (opts -> meta );
285
+ printf ("%s" , o -> meta );
286
+ length += (int ) strlen (o -> meta );
287
287
}
288
- else if (opts -> argc > 0 )
288
+ else if (o -> argc > 0 )
289
289
{
290
- if (opts -> meta != NULL )
290
+ if (o -> meta != NULL )
291
291
{
292
- printf (" %s" , opts -> meta );
293
- length += 1 + (int ) strlen (opts -> meta );
292
+ printf (" %s" , o -> meta );
293
+ length += 1 + (int ) strlen (o -> meta );
294
294
}
295
295
else
296
296
{
297
- for (int argi = 0 ; argi < opts -> argc ; argi ++ )
297
+ for (int i = 0 ; i < o -> argc ; i ++ )
298
298
{
299
299
printf (" _" );
300
300
}
301
- length += opts -> argc * 2 ;
301
+ length += o -> argc * 2 ;
302
302
}
303
303
}
304
304
305
- if (opts -> help != NULL )
305
+ if (o -> help != NULL )
306
306
{
307
307
if (length >= CLI_LINE_TAB )
308
308
{
@@ -312,7 +312,7 @@ cli_opt_help (const cli_opt_t *opts) /**< array of command line option definitio
312
312
cli_print_pad (CLI_LINE_TAB - length );
313
313
length = CLI_LINE_TAB ;
314
314
315
- cli_print_help (opts -> help );
315
+ cli_print_help (o -> help );
316
316
}
317
317
318
318
printf ("\n" );
@@ -361,16 +361,16 @@ cli_cmd_process (cli_cmd_state_t *state) /**< state of the sub-command processor
361
361
362
362
state -> arg = state -> argv ;
363
363
364
- for (const cli_cmd_t * cmds = state -> cmds ; cmds -> id != CLI_CMD_END ; cmds ++ )
364
+ for (const cli_cmd_t * c = state -> cmds ; c -> id != CLI_CMD_END ; c ++ )
365
365
{
366
- state -> cmd = cmds ;
366
+ state -> cmd = c ;
367
367
368
- if (!strcmp (cmds -> cmd , state -> argv [0 ]))
368
+ if (!strcmp (c -> cmd , state -> argv [0 ]))
369
369
{
370
370
state -> argc -- ;
371
371
state -> argv ++ ;
372
- state -> cmd = cmds ;
373
- return cmds -> id ;
372
+ state -> cmd = c ;
373
+ return c -> id ;
374
374
}
375
375
}
376
376
@@ -387,12 +387,12 @@ void
387
387
cli_cmd_usage (const char * progname , /**< program name, typically argv[0] */
388
388
const cli_cmd_t * cmds ) /**< array of sub-command definitions, terminated by CLI_CMD_END */
389
389
{
390
- for (; cmds -> id != CLI_CMD_END ; cmds ++ )
390
+ for (const cli_cmd_t * c = cmds ; c -> id != CLI_CMD_END ; c ++ )
391
391
{
392
- if (cmds -> cmd != NULL )
392
+ if (c -> cmd != NULL )
393
393
{
394
- CLI_CMD_NAME (cmdname , progname , cmds -> cmd );
395
- cli_opt_usage (cmdname , cmds -> opts );
394
+ CLI_CMD_NAME (cmdname , progname , c -> cmd );
395
+ cli_opt_usage (cmdname , c -> opts );
396
396
}
397
397
}
398
398
} /* cli_cmd_usage */
@@ -403,15 +403,15 @@ cli_cmd_usage (const char *progname, /**< program name, typically argv[0] */
403
403
void
404
404
cli_cmd_help (const cli_cmd_t * cmds ) /**< array of sub-command definitions, terminated by CLI_CMD_END */
405
405
{
406
- for (; cmds -> id != CLI_CMD_END ; cmds ++ )
406
+ for (const cli_cmd_t * c = cmds ; c -> id != CLI_CMD_END ; c ++ )
407
407
{
408
408
int length = CLI_LINE_INDENT ;
409
409
cli_print_pad (length );
410
410
411
- printf ("%s" , cmds -> cmd );
412
- length += (int ) strlen (cmds -> cmd );
411
+ printf ("%s" , c -> cmd );
412
+ length += (int ) strlen (c -> cmd );
413
413
414
- if (cmds -> help != NULL )
414
+ if (c -> help != NULL )
415
415
{
416
416
if (length >= CLI_LINE_TAB )
417
417
{
@@ -421,7 +421,7 @@ cli_cmd_help (const cli_cmd_t *cmds) /**< array of sub-command definitions, term
421
421
cli_print_pad (CLI_LINE_TAB - length );
422
422
length = CLI_LINE_TAB ;
423
423
424
- cli_print_help (cmds -> help );
424
+ cli_print_help (c -> help );
425
425
}
426
426
427
427
printf ("\n" );
0 commit comments