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