argpar.{c,h}: fix clang-tidy issues
[argpar.git] / argpar / argpar.c
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright (c) 2019-2021 Philippe Proulx <pproulx@efficios.com>
5 * Copyright (c) 2020-2021 Simon Marchi <simon.marchi@efficios.com>
6 */
7
8 #include <stdbool.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12
13 #include "argpar.h"
14
15 /*
16 * If argpar is used in some shared library, we don't want said library
17 * to export its symbols, so mark them as "hidden".
18 *
19 * On Windows, symbols are local unless explicitly exported; see
20 * <https://gcc.gnu.org/wiki/Visibility>.
21 */
22 #if defined(_WIN32) || defined(__CYGWIN__)
23 # define ARGPAR_HIDDEN
24 #else
25 # define ARGPAR_HIDDEN __attribute__((visibility("hidden")))
26 #endif
27
28 #define ARGPAR_REALLOC(_ptr, _type, _nmemb) ((_type *) realloc(_ptr, (_nmemb) * sizeof(_type)))
29
30 #define ARGPAR_CALLOC(_type, _nmemb) ((_type *) calloc((_nmemb), sizeof(_type)))
31
32 #define ARGPAR_ZALLOC(_type) ARGPAR_CALLOC(_type, 1)
33
34 #ifdef NDEBUG
35 /*
36 * Force usage of the assertion condition to prevent unused variable
37 * warnings when `assert()` are disabled by the `NDEBUG` definition.
38 */
39 # define ARGPAR_ASSERT(_cond) ((void) sizeof((void) (_cond), 0))
40 #else
41 # include <assert.h>
42 # define ARGPAR_ASSERT(_cond) assert(_cond)
43 #endif
44
45 /*
46 * An argpar iterator.
47 *
48 * Such a structure contains the state of an iterator between calls to
49 * argpar_iter_next().
50 */
51 struct argpar_iter
52 {
53 /*
54 * Data provided by the user to argpar_iter_create(); immutable
55 * afterwards.
56 */
57 struct
58 {
59 unsigned int argc;
60 const char * const *argv;
61 const argpar_opt_descr_t *descrs;
62 } user;
63
64 /*
65 * Index of the argument to process in the next
66 * argpar_iter_next() call.
67 */
68 unsigned int i;
69
70 /* Counter of non-option arguments */
71 int non_opt_index;
72
73 /*
74 * Current character within the current short option group: if
75 * it's not `NULL`, the parser is within a short option group,
76 * therefore it must resume there in the next argpar_iter_next()
77 * call.
78 */
79 const char *short_opt_group_ch;
80
81 /* Temporary character buffer which only grows */
82 struct
83 {
84 size_t size;
85 char *data;
86 } tmp_buf;
87 };
88
89 /* Base parsing item */
90 struct argpar_item
91 {
92 argpar_item_type_t type;
93 };
94
95 /* Option parsing item */
96 typedef struct argpar_item_opt
97 {
98 argpar_item_t base;
99
100 /* Corresponding descriptor */
101 const argpar_opt_descr_t *descr;
102
103 /* Argument, or `NULL` if none; owned by this */
104 char *arg;
105 } argpar_item_opt_t;
106
107 /* Non-option parsing item */
108 typedef struct argpar_item_non_opt
109 {
110 argpar_item_t base;
111
112 /*
113 * Complete argument, pointing to one of the entries of the
114 * original arguments (`argv`).
115 */
116 const char *arg;
117
118 /*
119 * Index of this argument amongst all original arguments
120 * (`argv`).
121 */
122 unsigned int orig_index;
123
124 /* Index of this argument amongst other non-option arguments */
125 unsigned int non_opt_index;
126 } argpar_item_non_opt_t;
127
128 /* Parsing error */
129 struct argpar_error
130 {
131 /* Error type */
132 argpar_error_type_t type;
133
134 /* Original argument index */
135 unsigned int orig_index;
136
137 /* Name of unknown option; owned by this */
138 char *unknown_opt_name;
139
140 /* Option descriptor */
141 const argpar_opt_descr_t *opt_descr;
142
143 /* `true` if a short option caused the error */
144 bool is_short;
145 };
146
147 ARGPAR_HIDDEN argpar_item_type_t argpar_item_type(const argpar_item_t * const item)
148 {
149 ARGPAR_ASSERT(item);
150 return item->type;
151 }
152
153 ARGPAR_HIDDEN const argpar_opt_descr_t *argpar_item_opt_descr(const argpar_item_t * const item)
154 {
155 ARGPAR_ASSERT(item);
156 ARGPAR_ASSERT(item->type == ARGPAR_ITEM_TYPE_OPT);
157 return ((const argpar_item_opt_t *) item)->descr;
158 }
159
160 ARGPAR_HIDDEN const char *argpar_item_opt_arg(const argpar_item_t * const item)
161 {
162 ARGPAR_ASSERT(item);
163 ARGPAR_ASSERT(item->type == ARGPAR_ITEM_TYPE_OPT);
164 return ((const argpar_item_opt_t *) item)->arg;
165 }
166
167 ARGPAR_HIDDEN const char *argpar_item_non_opt_arg(const argpar_item_t * const item)
168 {
169 ARGPAR_ASSERT(item);
170 ARGPAR_ASSERT(item->type == ARGPAR_ITEM_TYPE_NON_OPT);
171 return ((const argpar_item_non_opt_t *) item)->arg;
172 }
173
174 ARGPAR_HIDDEN unsigned int argpar_item_non_opt_orig_index(const argpar_item_t * const item)
175 {
176 ARGPAR_ASSERT(item);
177 ARGPAR_ASSERT(item->type == ARGPAR_ITEM_TYPE_NON_OPT);
178 return ((const argpar_item_non_opt_t *) item)->orig_index;
179 }
180
181 ARGPAR_HIDDEN unsigned int argpar_item_non_opt_non_opt_index(const argpar_item_t * const item)
182 {
183 ARGPAR_ASSERT(item);
184 ARGPAR_ASSERT(item->type == ARGPAR_ITEM_TYPE_NON_OPT);
185 return ((const argpar_item_non_opt_t *) item)->non_opt_index;
186 }
187
188 ARGPAR_HIDDEN void argpar_item_destroy(const argpar_item_t * const item)
189 {
190 if (!item) {
191 goto end;
192 }
193
194 if (item->type == ARGPAR_ITEM_TYPE_OPT) {
195 argpar_item_opt_t * const opt_item = (argpar_item_opt_t *) item;
196
197 free(opt_item->arg);
198 }
199
200 free((void *) item);
201
202 end:
203 return;
204 }
205
206 /*
207 * Creates and returns an option parsing item for the descriptor `descr`
208 * and having the argument `arg` (copied; may be `NULL`).
209 *
210 * Returns `NULL` on memory error.
211 */
212 static argpar_item_opt_t *create_opt_item(const argpar_opt_descr_t * const descr,
213 const char * const arg)
214 {
215 argpar_item_opt_t *opt_item = ARGPAR_ZALLOC(argpar_item_opt_t);
216
217 if (!opt_item) {
218 goto end;
219 }
220
221 opt_item->base.type = ARGPAR_ITEM_TYPE_OPT;
222 opt_item->descr = descr;
223
224 if (arg) {
225 opt_item->arg = strdup(arg);
226 if (!opt_item->arg) {
227 goto error;
228 }
229 }
230
231 goto end;
232
233 error:
234 argpar_item_destroy(&opt_item->base);
235 opt_item = NULL;
236
237 end:
238 return opt_item;
239 }
240
241 /*
242 * Creates and returns a non-option parsing item for the original
243 * argument `arg` having the original index `orig_index` and the
244 * non-option index `non_opt_index`.
245 *
246 * Returns `NULL` on memory error.
247 */
248 static argpar_item_non_opt_t *create_non_opt_item(const char * const arg,
249 const unsigned int orig_index,
250 const unsigned int non_opt_index)
251 {
252 argpar_item_non_opt_t * const non_opt_item = ARGPAR_ZALLOC(argpar_item_non_opt_t);
253
254 if (!non_opt_item) {
255 goto end;
256 }
257
258 non_opt_item->base.type = ARGPAR_ITEM_TYPE_NON_OPT;
259 non_opt_item->arg = arg;
260 non_opt_item->orig_index = orig_index;
261 non_opt_item->non_opt_index = non_opt_index;
262
263 end:
264 return non_opt_item;
265 }
266
267 /*
268 * If `error` is not `NULL`, sets the error `error` to a new parsing
269 * error object, setting its `unknown_opt_name`, `opt_descr`, and
270 * `is_short` members from the parameters.
271 *
272 * `unknown_opt_name` is the unknown option name without any `-` or `--`
273 * prefix: `is_short` controls which type of unknown option it is.
274 *
275 * Returns 0 on success (including if `error` is `NULL`) or -1 on memory
276 * error.
277 */
278 static int set_error(argpar_error_t ** const error, argpar_error_type_t type,
279 const char * const unknown_opt_name,
280 const argpar_opt_descr_t * const opt_descr, const bool is_short)
281 {
282 int ret = 0;
283
284 if (!error) {
285 goto end;
286 }
287
288 *error = ARGPAR_ZALLOC(argpar_error_t);
289 if (!*error) {
290 goto error;
291 }
292
293 (*error)->type = type;
294
295 if (unknown_opt_name) {
296 (*error)->unknown_opt_name =
297 ARGPAR_CALLOC(char, strlen(unknown_opt_name) + 1 + (is_short ? 1 : 2));
298 if (!(*error)->unknown_opt_name) {
299 goto error;
300 }
301
302 if (is_short) {
303 strcpy((*error)->unknown_opt_name, "-");
304 } else {
305 strcpy((*error)->unknown_opt_name, "--");
306 }
307
308 strcat((*error)->unknown_opt_name, unknown_opt_name);
309 }
310
311 (*error)->opt_descr = opt_descr;
312 (*error)->is_short = is_short;
313 goto end;
314
315 error:
316 argpar_error_destroy(*error);
317 ret = -1;
318
319 end:
320 return ret;
321 }
322
323 ARGPAR_HIDDEN argpar_error_type_t argpar_error_type(const argpar_error_t * const error)
324 {
325 ARGPAR_ASSERT(error);
326 return error->type;
327 }
328
329 ARGPAR_HIDDEN unsigned int argpar_error_orig_index(const argpar_error_t * const error)
330 {
331 ARGPAR_ASSERT(error);
332 return error->orig_index;
333 }
334
335 ARGPAR_HIDDEN const char *argpar_error_unknown_opt_name(const argpar_error_t * const error)
336 {
337 ARGPAR_ASSERT(error);
338 ARGPAR_ASSERT(error->type == ARGPAR_ERROR_TYPE_UNKNOWN_OPT);
339 ARGPAR_ASSERT(error->unknown_opt_name);
340 return error->unknown_opt_name;
341 }
342
343 ARGPAR_HIDDEN const argpar_opt_descr_t *argpar_error_opt_descr(const argpar_error_t * const error,
344 bool * const is_short)
345 {
346 ARGPAR_ASSERT(error);
347 ARGPAR_ASSERT(error->type == ARGPAR_ERROR_TYPE_MISSING_OPT_ARG ||
348 error->type == ARGPAR_ERROR_TYPE_UNEXPECTED_OPT_ARG);
349 ARGPAR_ASSERT(error->opt_descr);
350
351 if (is_short) {
352 *is_short = error->is_short;
353 }
354
355 return error->opt_descr;
356 }
357
358 ARGPAR_HIDDEN void argpar_error_destroy(const argpar_error_t * const error)
359 {
360 if (error) {
361 free(error->unknown_opt_name);
362 free((void *) error);
363 }
364 }
365
366 /*
367 * Finds and returns the _first_ descriptor having the short option name
368 * `short_name` or the long option name `long_name` within the option
369 * descriptors `descrs`.
370 *
371 * `short_name` may be `'\0'` to not consider it.
372 *
373 * `long_name` may be `NULL` to not consider it.
374 *
375 * Returns `NULL` if no descriptor is found.
376 */
377 static const argpar_opt_descr_t *find_descr(const argpar_opt_descr_t * const descrs,
378 const char short_name, const char * const long_name)
379 {
380 const argpar_opt_descr_t *descr;
381
382 for (descr = descrs; descr->short_name || descr->long_name; descr++) {
383 if (short_name && descr->short_name && short_name == descr->short_name) {
384 goto end;
385 }
386
387 if (long_name && descr->long_name && strcmp(long_name, descr->long_name) == 0) {
388 goto end;
389 }
390 }
391
392 end:
393 return !descr->short_name && !descr->long_name ? NULL : descr;
394 }
395
396 /* Return type of parse_short_opt_group() and parse_long_opt() */
397 typedef enum parse_orig_arg_opt_ret
398 {
399 PARSE_ORIG_ARG_OPT_RET_OK,
400 PARSE_ORIG_ARG_OPT_RET_ERROR = -1,
401 PARSE_ORIG_ARG_OPT_RET_ERROR_MEMORY = -2,
402 } parse_orig_arg_opt_ret_t;
403
404 /*
405 * Parses the short option group argument `short_opt_group`, starting
406 * where needed depending on the state of `iter`.
407 *
408 * On success, sets `*item`.
409 *
410 * On error (except for `PARSE_ORIG_ARG_OPT_RET_ERROR_MEMORY`), sets
411 * `*error`.
412 */
413 static parse_orig_arg_opt_ret_t
414 parse_short_opt_group(const char * const short_opt_group, const char * const next_orig_arg,
415 const argpar_opt_descr_t * const descrs, argpar_iter_t * const iter,
416 argpar_error_t ** const error, argpar_item_t ** const item)
417 {
418 parse_orig_arg_opt_ret_t ret = PARSE_ORIG_ARG_OPT_RET_OK;
419 bool used_next_orig_arg = false;
420 const char *opt_arg = NULL;
421 const argpar_opt_descr_t *descr;
422 argpar_item_opt_t *opt_item;
423
424 ARGPAR_ASSERT(strlen(short_opt_group) != 0);
425
426 if (!iter->short_opt_group_ch) {
427 iter->short_opt_group_ch = short_opt_group;
428 }
429
430 /* Find corresponding option descriptor */
431 descr = find_descr(descrs, *iter->short_opt_group_ch, NULL);
432 if (!descr) {
433 const char unknown_opt_name[] = {*iter->short_opt_group_ch, '\0'};
434
435 ret = PARSE_ORIG_ARG_OPT_RET_ERROR;
436
437 if (set_error(error, ARGPAR_ERROR_TYPE_UNKNOWN_OPT, unknown_opt_name, NULL, true)) {
438 ret = PARSE_ORIG_ARG_OPT_RET_ERROR_MEMORY;
439 }
440
441 goto error;
442 }
443
444 if (descr->with_arg) {
445 if (iter->short_opt_group_ch[1]) {
446 /* `-oarg` form */
447 opt_arg = &iter->short_opt_group_ch[1];
448 } else {
449 /* `-o arg` form */
450 opt_arg = next_orig_arg;
451 used_next_orig_arg = true;
452 }
453
454 /*
455 * We accept `-o ''` (empty option argument), but not
456 * `-o` alone if an option argument is expected.
457 */
458 if (!opt_arg || (iter->short_opt_group_ch[1] && strlen(opt_arg) == 0)) {
459 ret = PARSE_ORIG_ARG_OPT_RET_ERROR;
460
461 if (set_error(error, ARGPAR_ERROR_TYPE_MISSING_OPT_ARG, NULL, descr, true)) {
462 ret = PARSE_ORIG_ARG_OPT_RET_ERROR_MEMORY;
463 }
464
465 goto error;
466 }
467 }
468
469 /* Create and append option argument */
470 opt_item = create_opt_item(descr, opt_arg);
471 if (!opt_item) {
472 ret = PARSE_ORIG_ARG_OPT_RET_ERROR_MEMORY;
473 goto error;
474 }
475
476 *item = &opt_item->base;
477 iter->short_opt_group_ch++;
478
479 if (descr->with_arg || !*iter->short_opt_group_ch) {
480 /* Option has an argument: no more options */
481 iter->short_opt_group_ch = NULL;
482
483 if (used_next_orig_arg) {
484 iter->i += 2;
485 } else {
486 iter->i++;
487 }
488 }
489
490 goto end;
491
492 error:
493 ARGPAR_ASSERT(ret != PARSE_ORIG_ARG_OPT_RET_OK);
494
495 end:
496 return ret;
497 }
498
499 /*
500 * Parses the long option argument `long_opt_arg`.
501 *
502 * On success, sets `*item`.
503 *
504 * On error (except for `PARSE_ORIG_ARG_OPT_RET_ERROR_MEMORY`), sets
505 * `*error`.
506 */
507 static parse_orig_arg_opt_ret_t
508 parse_long_opt(const char * const long_opt_arg, const char * const next_orig_arg,
509 const argpar_opt_descr_t * const descrs, argpar_iter_t * const iter,
510 argpar_error_t ** const error, argpar_item_t ** const item)
511 {
512 parse_orig_arg_opt_ret_t ret = PARSE_ORIG_ARG_OPT_RET_OK;
513 const argpar_opt_descr_t *descr;
514 argpar_item_opt_t *opt_item;
515 bool used_next_orig_arg = false;
516
517 /* Option's argument, if any */
518 const char *opt_arg = NULL;
519
520 /* Position of first `=`, if any */
521 const char *eq_pos;
522
523 /* Option name */
524 const char *long_opt_name = long_opt_arg;
525
526 ARGPAR_ASSERT(strlen(long_opt_arg) != 0);
527
528 /* Find the first `=` in original argument */
529 eq_pos = strchr(long_opt_arg, '=');
530 if (eq_pos) {
531 const size_t long_opt_name_size = eq_pos - long_opt_arg;
532
533 /* Isolate the option name */
534 while (long_opt_name_size > iter->tmp_buf.size - 1) {
535 const size_t new_size = iter->tmp_buf.size * 2;
536 char * const new_data = ARGPAR_REALLOC(iter->tmp_buf.data, char, new_size);
537
538 if (!new_data) {
539 ret = PARSE_ORIG_ARG_OPT_RET_ERROR_MEMORY;
540 goto error;
541 }
542
543 iter->tmp_buf.size = new_size;
544 iter->tmp_buf.data = new_data;
545 }
546
547 memcpy(iter->tmp_buf.data, long_opt_arg, long_opt_name_size);
548 iter->tmp_buf.data[long_opt_name_size] = '\0';
549 long_opt_name = iter->tmp_buf.data;
550 }
551
552 /* Find corresponding option descriptor */
553 descr = find_descr(descrs, '\0', long_opt_name);
554 if (!descr) {
555 ret = PARSE_ORIG_ARG_OPT_RET_ERROR;
556
557 if (set_error(error, ARGPAR_ERROR_TYPE_UNKNOWN_OPT, long_opt_name, NULL, false)) {
558 ret = PARSE_ORIG_ARG_OPT_RET_ERROR_MEMORY;
559 }
560
561 goto error;
562 }
563
564 /* Find option's argument if any */
565 if (descr->with_arg) {
566 if (eq_pos) {
567 /* `--long-opt=arg` style */
568 opt_arg = eq_pos + 1;
569 } else {
570 /* `--long-opt arg` style */
571 if (!next_orig_arg) {
572 ret = PARSE_ORIG_ARG_OPT_RET_ERROR;
573
574 if (set_error(error, ARGPAR_ERROR_TYPE_MISSING_OPT_ARG, NULL, descr, false)) {
575 ret = PARSE_ORIG_ARG_OPT_RET_ERROR_MEMORY;
576 }
577
578 goto error;
579 }
580
581 opt_arg = next_orig_arg;
582 used_next_orig_arg = true;
583 }
584 } else if (eq_pos) {
585 /*
586 * Unexpected `--opt=arg` style for a long option which
587 * doesn't accept an argument.
588 */
589 ret = PARSE_ORIG_ARG_OPT_RET_ERROR;
590
591 if (set_error(error, ARGPAR_ERROR_TYPE_UNEXPECTED_OPT_ARG, NULL, descr, false)) {
592 ret = PARSE_ORIG_ARG_OPT_RET_ERROR_MEMORY;
593 }
594
595 goto error;
596 }
597
598 /* Create and append option argument */
599 opt_item = create_opt_item(descr, opt_arg);
600 if (!opt_item) {
601 goto error;
602 }
603
604 if (used_next_orig_arg) {
605 iter->i += 2;
606 } else {
607 iter->i++;
608 }
609
610 *item = &opt_item->base;
611 goto end;
612
613 error:
614 ARGPAR_ASSERT(ret != PARSE_ORIG_ARG_OPT_RET_OK);
615
616 end:
617 return ret;
618 }
619
620 /*
621 * Parses the original argument `orig_arg`.
622 *
623 * On success, sets `*item`.
624 *
625 * On error (except for `PARSE_ORIG_ARG_OPT_RET_ERROR_MEMORY`), sets
626 * `*error`.
627 */
628 static parse_orig_arg_opt_ret_t
629 parse_orig_arg_opt(const char * const orig_arg, const char * const next_orig_arg,
630 const argpar_opt_descr_t * const descrs, argpar_iter_t * const iter,
631 argpar_error_t ** const error, argpar_item_t ** const item)
632 {
633 parse_orig_arg_opt_ret_t ret = PARSE_ORIG_ARG_OPT_RET_OK;
634
635 ARGPAR_ASSERT(orig_arg[0] == '-');
636
637 if (orig_arg[1] == '-') {
638 /* Long option */
639 ret = parse_long_opt(&orig_arg[2], next_orig_arg, descrs, iter, error, item);
640 } else {
641 /* Short option */
642 ret = parse_short_opt_group(&orig_arg[1], next_orig_arg, descrs, iter, error, item);
643 }
644
645 return ret;
646 }
647
648 ARGPAR_HIDDEN argpar_iter_t *argpar_iter_create(const unsigned int argc,
649 const char * const * const argv,
650 const argpar_opt_descr_t * const descrs)
651 {
652 argpar_iter_t *iter = ARGPAR_ZALLOC(argpar_iter_t);
653
654 if (!iter) {
655 goto end;
656 }
657
658 iter->user.argc = argc;
659 iter->user.argv = argv;
660 iter->user.descrs = descrs;
661 iter->tmp_buf.size = 128;
662 iter->tmp_buf.data = ARGPAR_CALLOC(char, iter->tmp_buf.size);
663 if (!iter->tmp_buf.data) {
664 argpar_iter_destroy(iter);
665 iter = NULL;
666 goto end;
667 }
668
669 end:
670 return iter;
671 }
672
673 ARGPAR_HIDDEN void argpar_iter_destroy(argpar_iter_t * const iter)
674 {
675 if (iter) {
676 free(iter->tmp_buf.data);
677 free(iter);
678 }
679 }
680
681 ARGPAR_HIDDEN argpar_iter_next_status_t argpar_iter_next(argpar_iter_t * const iter,
682 const argpar_item_t ** const item,
683 const argpar_error_t ** const error)
684 {
685 argpar_iter_next_status_t status;
686 parse_orig_arg_opt_ret_t parse_orig_arg_opt_ret;
687 const char *orig_arg;
688 const char *next_orig_arg;
689 argpar_error_t ** const nc_error = (argpar_error_t **) error;
690
691 ARGPAR_ASSERT(iter->i <= iter->user.argc);
692
693 if (error) {
694 *nc_error = NULL;
695 }
696
697 if (iter->i == iter->user.argc) {
698 status = ARGPAR_ITER_NEXT_STATUS_END;
699 goto end;
700 }
701
702 orig_arg = iter->user.argv[iter->i];
703 next_orig_arg = iter->i < (iter->user.argc - 1) ? iter->user.argv[iter->i + 1] : NULL;
704
705 if (strcmp(orig_arg, "-") == 0 || strcmp(orig_arg, "--") == 0 || orig_arg[0] != '-') {
706 /* Non-option argument */
707 const argpar_item_non_opt_t * const non_opt_item =
708 create_non_opt_item(orig_arg, iter->i, iter->non_opt_index);
709
710 if (!non_opt_item) {
711 status = ARGPAR_ITER_NEXT_STATUS_ERROR_MEMORY;
712 goto end;
713 }
714
715 iter->non_opt_index++;
716 iter->i++;
717 *item = &non_opt_item->base;
718 status = ARGPAR_ITER_NEXT_STATUS_OK;
719 goto end;
720 }
721
722 /* Option argument */
723 parse_orig_arg_opt_ret = parse_orig_arg_opt(orig_arg, next_orig_arg, iter->user.descrs, iter,
724 nc_error, (argpar_item_t **) item);
725 switch (parse_orig_arg_opt_ret) {
726 case PARSE_ORIG_ARG_OPT_RET_OK:
727 status = ARGPAR_ITER_NEXT_STATUS_OK;
728 break;
729 case PARSE_ORIG_ARG_OPT_RET_ERROR:
730 if (error) {
731 ARGPAR_ASSERT(*error);
732 (*nc_error)->orig_index = iter->i;
733 }
734 status = ARGPAR_ITER_NEXT_STATUS_ERROR;
735 break;
736 case PARSE_ORIG_ARG_OPT_RET_ERROR_MEMORY:
737 status = ARGPAR_ITER_NEXT_STATUS_ERROR_MEMORY;
738 break;
739 default:
740 abort();
741 }
742
743 end:
744 return status;
745 }
746
747 ARGPAR_HIDDEN unsigned int argpar_iter_ingested_orig_args(const argpar_iter_t * const iter)
748 {
749 return iter->i;
750 }
This page took 0.04308 seconds and 5 git commands to generate.