Skip to content

Commit c4523f7

Browse files
committed
Update to loops
JerryScript-DCO-1.0-Signed-off-by: Akos Kiss [email protected]
1 parent dd1eb0b commit c4523f7

File tree

1 file changed

+57
-57
lines changed

1 file changed

+57
-57
lines changed

jerry-main/cli.c

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ cli_print_prefix (const char *str, /**< string to print */
7272
static void
7373
cli_print_help (const char *help) /**< the help message to print */
7474
{
75-
for (; help != NULL && *help != 0;)
75+
while (help != NULL && *help != 0)
7676
{
7777
int length = -1;
7878
int i = 0;
@@ -148,24 +148,24 @@ cli_opt_process (cli_opt_state_t *state) /**< state of the command line option p
148148

149149
state->arg = state->argv;
150150

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++)
152152
{
153-
state->opt = opts;
153+
state->opt = o;
154154

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], "-")))
156156
{
157157
state->argc--;
158158
state->argv++;
159159
return CLI_OPT_POSITIONAL;
160160
}
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])))
163163
{
164-
if (state->argc > opts->argc)
164+
if (state->argc > o->argc)
165165
{
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;
169169
}
170170
else
171171
{
@@ -192,18 +192,18 @@ cli_opt_usage (const char *progname, /**< program name, typically argv[0] */
192192
int length = (int) strlen (progname);
193193
printf ("%s", progname);
194194

195-
for (; opts->id != CLI_OPT_END; opts++)
195+
for (const cli_opt_t *o = opts; o->id != CLI_OPT_END; o++)
196196
{
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;
199199

200200
int opt_length = (int) strlen (opt);
201-
if (opts->argc > 0)
201+
if (o->argc > 0)
202202
{
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;
204204
}
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;
207207

208208
if (length + 1 + opt_length >= CLI_LINE_LENGTH)
209209
{
@@ -215,34 +215,34 @@ cli_opt_usage (const char *progname, /**< program name, typically argv[0] */
215215

216216
printf (" ");
217217

218-
if (opts->quant == CLI_QUANT_Q || opts->quant == CLI_QUANT_A)
218+
if (o->quant == CLI_QUANT_Q || o->quant == CLI_QUANT_A)
219219
{
220220
printf ("[");
221221
}
222222

223223
printf ("%s", opt);
224224

225-
if (opts->argc > 0)
225+
if (o->argc > 0)
226226
{
227-
if (opts->meta != NULL)
227+
if (o->meta != NULL)
228228
{
229-
printf (" %s", opts->meta);
229+
printf (" %s", o->meta);
230230
}
231231
else
232232
{
233-
for (int argi = 0; argi < opts->argc; argi++)
233+
for (int i = 0; i < o->argc; i++)
234234
{
235235
printf (" _");
236236
}
237237
}
238238
}
239239

240-
if (opts->quant == CLI_QUANT_Q || opts->quant == CLI_QUANT_A)
240+
if (o->quant == CLI_QUANT_Q || o->quant == CLI_QUANT_A)
241241
{
242242
printf ("]");
243243
}
244244

245-
if (opts->quant == CLI_QUANT_P || opts->quant == CLI_QUANT_A)
245+
if (o->quant == CLI_QUANT_P || o->quant == CLI_QUANT_A)
246246
{
247247
printf ("...");
248248
}
@@ -257,52 +257,52 @@ cli_opt_usage (const char *progname, /**< program name, typically argv[0] */
257257
void
258258
cli_opt_help (const cli_opt_t *opts) /**< array of command line option definitions, terminated by CLI_OPT_END */
259259
{
260-
for (; opts->id != CLI_OPT_END; opts++)
260+
for (const cli_opt_t *o = opts; o->id != CLI_OPT_END; o++)
261261
{
262262
int length = CLI_LINE_INDENT;
263263
cli_print_pad (length);
264264

265-
if (opts->opt != NULL)
265+
if (o->opt != NULL)
266266
{
267-
printf ("%s", opts->opt);
268-
length += (int) strlen (opts->opt);
267+
printf ("%s", o->opt);
268+
length += (int) strlen (o->opt);
269269
}
270270

271-
if (opts->opt != NULL && opts->longopt != NULL)
271+
if (o->opt != NULL && o->longopt != NULL)
272272
{
273273
printf (", ");
274274
length += 2;
275275
}
276276

277-
if (opts->longopt != NULL)
277+
if (o->longopt != NULL)
278278
{
279-
printf ("%s", opts->longopt);
280-
length += (int) strlen (opts->longopt);
279+
printf ("%s", o->longopt);
280+
length += (int) strlen (o->longopt);
281281
}
282282

283-
if (opts->opt == NULL && opts->longopt == NULL)
283+
if (o->opt == NULL && o->longopt == NULL)
284284
{
285-
printf ("%s", opts->meta);
286-
length += (int) strlen (opts->meta);
285+
printf ("%s", o->meta);
286+
length += (int) strlen (o->meta);
287287
}
288-
else if (opts->argc > 0)
288+
else if (o->argc > 0)
289289
{
290-
if (opts->meta != NULL)
290+
if (o->meta != NULL)
291291
{
292-
printf (" %s", opts->meta);
293-
length += 1 + (int) strlen (opts->meta);
292+
printf (" %s", o->meta);
293+
length += 1 + (int) strlen (o->meta);
294294
}
295295
else
296296
{
297-
for (int argi = 0; argi < opts->argc; argi++)
297+
for (int i = 0; i < o->argc; i++)
298298
{
299299
printf (" _");
300300
}
301-
length += opts->argc * 2;
301+
length += o->argc * 2;
302302
}
303303
}
304304

305-
if (opts->help != NULL)
305+
if (o->help != NULL)
306306
{
307307
if (length >= CLI_LINE_TAB)
308308
{
@@ -312,7 +312,7 @@ cli_opt_help (const cli_opt_t *opts) /**< array of command line option definitio
312312
cli_print_pad (CLI_LINE_TAB - length);
313313
length = CLI_LINE_TAB;
314314

315-
cli_print_help (opts->help);
315+
cli_print_help (o->help);
316316
}
317317

318318
printf ("\n");
@@ -361,16 +361,16 @@ cli_cmd_process (cli_cmd_state_t *state) /**< state of the sub-command processor
361361

362362
state->arg = state->argv;
363363

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++)
365365
{
366-
state->cmd = cmds;
366+
state->cmd = c;
367367

368-
if (!strcmp (cmds->cmd, state->argv[0]))
368+
if (!strcmp (c->cmd, state->argv[0]))
369369
{
370370
state->argc--;
371371
state->argv++;
372-
state->cmd = cmds;
373-
return cmds->id;
372+
state->cmd = c;
373+
return c->id;
374374
}
375375
}
376376

@@ -387,12 +387,12 @@ void
387387
cli_cmd_usage (const char *progname, /**< program name, typically argv[0] */
388388
const cli_cmd_t *cmds) /**< array of sub-command definitions, terminated by CLI_CMD_END */
389389
{
390-
for (; cmds->id != CLI_CMD_END; cmds++)
390+
for (const cli_cmd_t *c = cmds; c->id != CLI_CMD_END; c++)
391391
{
392-
if (cmds->cmd != NULL)
392+
if (c->cmd != NULL)
393393
{
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);
396396
}
397397
}
398398
} /* cli_cmd_usage */
@@ -403,15 +403,15 @@ cli_cmd_usage (const char *progname, /**< program name, typically argv[0] */
403403
void
404404
cli_cmd_help (const cli_cmd_t *cmds) /**< array of sub-command definitions, terminated by CLI_CMD_END */
405405
{
406-
for (; cmds->id != CLI_CMD_END; cmds++)
406+
for (const cli_cmd_t *c = cmds; c->id != CLI_CMD_END; c++)
407407
{
408408
int length = CLI_LINE_INDENT;
409409
cli_print_pad (length);
410410

411-
printf ("%s", cmds->cmd);
412-
length += (int) strlen (cmds->cmd);
411+
printf ("%s", c->cmd);
412+
length += (int) strlen (c->cmd);
413413

414-
if (cmds->help != NULL)
414+
if (c->help != NULL)
415415
{
416416
if (length >= CLI_LINE_TAB)
417417
{
@@ -421,7 +421,7 @@ cli_cmd_help (const cli_cmd_t *cmds) /**< array of sub-command definitions, term
421421
cli_print_pad (CLI_LINE_TAB - length);
422422
length = CLI_LINE_TAB;
423423

424-
cli_print_help (cmds->help);
424+
cli_print_help (c->help);
425425
}
426426

427427
printf ("\n");

0 commit comments

Comments
 (0)