Parse `-` and `--` as non-option arguments
[argpar.git] / argpar / argpar.h
index bfcc42241f9fd7d6bb5a88e32d5e5d46774cb00d..be715131d5628c3018393a7d436b92ae2744e4e7 100644 (file)
@@ -18,8 +18,8 @@
  *
  * Iterator API:
  *     Create a parsing iterator with argpar_iter_create(), then
- *     repeatedly call argpar_iter_parse_next() to access the parsing
- *     results, until one of:
+ *     repeatedly call argpar_iter_next() to access the parsing results,
+ *     until one of:
  *
  *     * There are no more arguments.
  *
  *
  * * Non-option arguments (anything else).
  *
- * The argpar parsers don't accept `-` or `--` as arguments. The latter
- * means "end of options" for many command-line tools, but this library
- * is all about keeping the order of the arguments, so it doesn't mean
- * much to put them at the end. This has the side effect that a
+ * The argpar parsers parse `-` and `--` as non-option arguments. A
  * non-option argument cannot have the form of an option, for example if
  * you need to pass the exact relative path `--component`. In that case,
  * you would need to pass `./--component`. There's no generic way to
@@ -128,7 +125,7 @@ struct argpar_opt_descr {
        /* Short option character, or `\0` */
        const char short_name;
 
-       /* Long option name (without `--`), or `NULL` */
+       /* Long option name (without the `--` prefix), or `NULL` */
        const char * const long_name;
 
        /* True if this option has an argument */
@@ -144,7 +141,7 @@ enum argpar_item_type {
        ARGPAR_ITEM_TYPE_NON_OPT,
 };
 
-/* Parsing item, as created by argpar_parse() and argpar_iter_parse_next() */
+/* Parsing item, as created by argpar_parse() and argpar_iter_next() */
 struct argpar_item;
 
 /*
@@ -188,6 +185,12 @@ unsigned int argpar_item_non_opt_orig_index(const struct argpar_item *item);
 ARGPAR_HIDDEN
 unsigned int argpar_item_non_opt_non_opt_index(const struct argpar_item *item);
 
+/*
+ * Destroys `item`, as created by argpar_iter_next().
+ */
+ARGPAR_HIDDEN
+void argpar_item_destroy(const struct argpar_item *item);
+
 struct argpar_item_array {
        const struct argpar_item **items;
 
@@ -284,10 +287,12 @@ void argpar_parse_ret_fini(struct argpar_parse_ret *ret);
  * actually start parsing the arguments.
  *
  * `*argv` and `*descrs` must NOT change for the lifetime of the
- * returned iterator (until you call argpar_iter_destroy()).
+ * returned iterator (until you call argpar_iter_destroy()) and for the
+ * lifetime of any parsing item (until you call argpar_item_destroy())
+ * argpar_iter_next() creates for the returned iterator.
  *
- * Call argpar_iter_parse_next() with the returned iterator to obtain
- * the next parsing result (item).
+ * Call argpar_iter_next() with the returned iterator to obtain the next
+ * parsing result (item).
  */
 ARGPAR_HIDDEN
 struct argpar_iter *argpar_iter_create(unsigned int argc,
@@ -301,16 +306,16 @@ ARGPAR_HIDDEN
 void argpar_iter_destroy(struct argpar_iter *iter);
 
 /*
- * Return type of argpar_iter_parse_next().
+ * Return type of argpar_iter_next().
  */
-enum argpar_iter_parse_next_status {
-       ARGPAR_ITER_PARSE_NEXT_STATUS_OK,
-       ARGPAR_ITER_PARSE_NEXT_STATUS_END,
-       ARGPAR_ITER_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT,
-       ARGPAR_ITER_PARSE_NEXT_STATUS_ERROR_MISSING_OPT_ARG,
-       ARGPAR_ITER_PARSE_NEXT_STATUS_ERROR_INVALID_ARG,
-       ARGPAR_ITER_PARSE_NEXT_STATUS_ERROR_UNEXPECTED_OPT_ARG,
-       ARGPAR_ITER_PARSE_NEXT_STATUS_ERROR_MEMORY,
+enum argpar_iter_next_status {
+       ARGPAR_ITER_NEXT_STATUS_OK,
+       ARGPAR_ITER_NEXT_STATUS_END,
+       ARGPAR_ITER_NEXT_STATUS_ERROR_UNKNOWN_OPT,
+       ARGPAR_ITER_NEXT_STATUS_ERROR_MISSING_OPT_ARG,
+       ARGPAR_ITER_NEXT_STATUS_ERROR_INVALID_ARG,
+       ARGPAR_ITER_NEXT_STATUS_ERROR_UNEXPECTED_OPT_ARG,
+       ARGPAR_ITER_NEXT_STATUS_ERROR_MEMORY,
 };
 
 /*
@@ -323,36 +328,36 @@ enum argpar_iter_parse_next_status {
  *
  *   Destroy `*item` with argpar_item_destroy().
  *
- * * Returns `ARGPAR_ITER_PARSE_NEXT_STATUS_OK`.
+ * * Returns `ARGPAR_ITER_NEXT_STATUS_OK`.
  *
  * If there are no more items to return, this function returns
- * `ARGPAR_ITER_PARSE_NEXT_STATUS_END`.
+ * `ARGPAR_ITER_NEXT_STATUS_END`.
  *
  * On failure, this function:
  *
  * * Returns one of:
  *
- *   `ARGPAR_ITER_PARSE_NEXT_STATUS_ERROR_UNKNOWN_OPT`:
+ *   `ARGPAR_ITER_NEXT_STATUS_ERROR_UNKNOWN_OPT`:
  *       Unknown option (not found in `descrs` as passed to
  *       argpar_iter_create() to create `iter`).
  *
- *   `ARGPAR_ITER_PARSE_NEXT_STATUS_ERROR_MISSING_OPT_ARG`:
+ *   `ARGPAR_ITER_NEXT_STATUS_ERROR_MISSING_OPT_ARG`:
  *       Missing option argument.
  *
- *   `ARGPAR_ITER_PARSE_NEXT_STATUS_ERROR_INVALID_ARG`:
+ *   `ARGPAR_ITER_NEXT_STATUS_ERROR_INVALID_ARG`:
  *       Invalid argument.
  *
- *   `ARGPAR_ITER_PARSE_NEXT_STATUS_ERROR_UNEXPECTED_OPT_ARG`:
+ *   `ARGPAR_ITER_NEXT_STATUS_ERROR_UNEXPECTED_OPT_ARG`:
  *       Unexpected option argument.
  *
- *   `ARGPAR_ITER_PARSE_NEXT_STATUS_ERROR_MEMORY`:
+ *   `ARGPAR_ITER_NEXT_STATUS_ERROR_MEMORY`:
  *       Memory error.
  *
- * * Except for the `ARGPAR_ITER_PARSE_NEXT_STATUS_ERROR_MEMORY` status,
+ * * Except for the `ARGPAR_ITER_NEXT_STATUS_ERROR_MEMORY` status,
  *   sets `*error`, if not `NULL`, to a descriptive error string.
  *   Free `*error` with free().
  */
-enum argpar_iter_parse_next_status argpar_iter_parse_next(
+enum argpar_iter_next_status argpar_iter_next(
                struct argpar_iter *iter, const struct argpar_item **item,
                char **error);
 
@@ -362,13 +367,7 @@ enum argpar_iter_parse_next_status argpar_iter_parse_next(
  * the previously returned items.
  */
 ARGPAR_HIDDEN
-unsigned int argpar_iter_get_ingested_orig_args(const struct argpar_iter *iter);
-
-/*
- * Destroys `item`, as created by argpar_iter_parse_next().
- */
-ARGPAR_HIDDEN
-void argpar_item_destroy(const struct argpar_item *item);
+unsigned int argpar_iter_ingested_orig_args(const struct argpar_iter *iter);
 
 /*
  * Destroys `_item` (`const struct argpar_item *`) and sets it to
This page took 0.024819 seconds and 4 git commands to generate.