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