Add and use type definitions for structures and enumerations
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 15 Mar 2024 17:25:00 +0000 (13:25 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 15 Mar 2024 19:00:50 +0000 (15:00 -0400)
Using the `_t` suffix to avoid changing the current API because `enum
argpar_item_type` has the same name as the argpar_item_type() function.

Using those new type definitions everywhere to make sure they work.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I87bcd2abd40ff91779b9c82b4b9b8a7afb535fb3

argpar/argpar.c
argpar/argpar.h
tests/test-argpar.c

index 82b561ceaae707002f36754c55e828d35b882206..008d10b91a18c01e2b99f9f3b1596ef1f91b4bc0 100644 (file)
@@ -46,7 +46,7 @@ struct argpar_iter {
        struct {
                unsigned int argc;
                const char * const *argv;
-               const struct argpar_opt_descr *descrs;
+               const argpar_opt_descr_t *descrs;
        } user;
 
        /*
@@ -75,23 +75,23 @@ struct argpar_iter {
 
 /* Base parsing item */
 struct argpar_item {
-       enum argpar_item_type type;
+       argpar_item_type_t type;
 };
 
 /* Option parsing item */
-struct argpar_item_opt {
-       struct argpar_item base;
+typedef struct argpar_item_opt {
+       argpar_item_t base;
 
        /* Corresponding descriptor */
-       const struct argpar_opt_descr *descr;
+       const argpar_opt_descr_t *descr;
 
        /* Argument, or `NULL` if none; owned by this */
        char *arg;
-};
+} argpar_item_opt_t;
 
 /* Non-option parsing item */
-struct argpar_item_non_opt {
-       struct argpar_item base;
+typedef struct argpar_item_non_opt {
+       argpar_item_t base;
 
        /*
         * Complete argument, pointing to one of the entries of the
@@ -107,12 +107,12 @@ struct argpar_item_non_opt {
 
        /* Index of this argument amongst other non-option arguments */
        unsigned int non_opt_index;
-};
+} argpar_item_non_opt_t;
 
 /* Parsing error */
 struct argpar_error {
        /* Error type */
-       enum argpar_error_type type;
+       argpar_error_type_t type;
 
        /* Original argument index */
        unsigned int orig_index;
@@ -121,72 +121,71 @@ struct argpar_error {
        char *unknown_opt_name;
 
        /* Option descriptor */
-       const struct argpar_opt_descr *opt_descr;
+       const argpar_opt_descr_t *opt_descr;
 
        /* `true` if a short option caused the error */
        bool is_short;
 };
 
 ARGPAR_HIDDEN
-enum argpar_item_type argpar_item_type(const struct argpar_item * const item)
+argpar_item_type_t argpar_item_type(const argpar_item_t * const item)
 {
        ARGPAR_ASSERT(item);
        return item->type;
 }
 
 ARGPAR_HIDDEN
-const struct argpar_opt_descr *argpar_item_opt_descr(
-               const struct argpar_item * const item)
+const argpar_opt_descr_t *argpar_item_opt_descr(
+               const argpar_item_t * const item)
 {
        ARGPAR_ASSERT(item);
        ARGPAR_ASSERT(item->type == ARGPAR_ITEM_TYPE_OPT);
-       return ((const struct argpar_item_opt *) item)->descr;
+       return ((const argpar_item_opt_t *) item)->descr;
 }
 
 ARGPAR_HIDDEN
-const char *argpar_item_opt_arg(const struct argpar_item * const item)
+const char *argpar_item_opt_arg(const argpar_item_t * const item)
 {
        ARGPAR_ASSERT(item);
        ARGPAR_ASSERT(item->type == ARGPAR_ITEM_TYPE_OPT);
-       return ((const struct argpar_item_opt *) item)->arg;
+       return ((const argpar_item_opt_t *) item)->arg;
 }
 
 ARGPAR_HIDDEN
-const char *argpar_item_non_opt_arg(const struct argpar_item * const item)
+const char *argpar_item_non_opt_arg(const argpar_item_t * const item)
 {
        ARGPAR_ASSERT(item);
        ARGPAR_ASSERT(item->type == ARGPAR_ITEM_TYPE_NON_OPT);
-       return ((const struct argpar_item_non_opt *) item)->arg;
+       return ((const argpar_item_non_opt_t *) item)->arg;
 }
 
 ARGPAR_HIDDEN
 unsigned int argpar_item_non_opt_orig_index(
-               const struct argpar_item * const item)
+               const argpar_item_t * const item)
 {
        ARGPAR_ASSERT(item);
        ARGPAR_ASSERT(item->type == ARGPAR_ITEM_TYPE_NON_OPT);
-       return ((const struct argpar_item_non_opt *) item)->orig_index;
+       return ((const argpar_item_non_opt_t *) item)->orig_index;
 }
 
 ARGPAR_HIDDEN
 unsigned int argpar_item_non_opt_non_opt_index(
-               const struct argpar_item * const item)
+               const argpar_item_t * const item)
 {
        ARGPAR_ASSERT(item);
        ARGPAR_ASSERT(item->type == ARGPAR_ITEM_TYPE_NON_OPT);
-       return ((const struct argpar_item_non_opt *) item)->non_opt_index;
+       return ((const argpar_item_non_opt_t *) item)->non_opt_index;
 }
 
 ARGPAR_HIDDEN
-void argpar_item_destroy(const struct argpar_item * const item)
+void argpar_item_destroy(const argpar_item_t * const item)
 {
        if (!item) {
                goto end;
        }
 
        if (item->type == ARGPAR_ITEM_TYPE_OPT) {
-               struct argpar_item_opt * const opt_item =
-                       (struct argpar_item_opt *) item;
+               argpar_item_opt_t * const opt_item = (argpar_item_opt_t *) item;
 
                free(opt_item->arg);
        }
@@ -204,12 +203,10 @@ end:
  * Returns `NULL` on memory error.
  */
 static
-struct argpar_item_opt *create_opt_item(
-               const struct argpar_opt_descr * const descr,
+argpar_item_opt_t *create_opt_item(const argpar_opt_descr_t * const descr,
                const char * const arg)
 {
-       struct argpar_item_opt *opt_item =
-               ARGPAR_ZALLOC(struct argpar_item_opt);
+       argpar_item_opt_t *opt_item = ARGPAR_ZALLOC(argpar_item_opt_t);
 
        if (!opt_item) {
                goto end;
@@ -243,12 +240,12 @@ end:
  * Returns `NULL` on memory error.
  */
 static
-struct argpar_item_non_opt *create_non_opt_item(const char * const arg,
+argpar_item_non_opt_t *create_non_opt_item(const char * const arg,
                const unsigned int orig_index,
                const unsigned int non_opt_index)
 {
-       struct argpar_item_non_opt * const non_opt_item =
-               ARGPAR_ZALLOC(struct argpar_item_non_opt);
+       argpar_item_non_opt_t * const non_opt_item =
+               ARGPAR_ZALLOC(argpar_item_non_opt_t);
 
        if (!non_opt_item) {
                goto end;
@@ -275,11 +272,9 @@ end:
  * error.
  */
 static
-int set_error(struct argpar_error ** const error,
-               enum argpar_error_type type,
+int set_error(argpar_error_t ** const error, argpar_error_type_t type,
                const char * const unknown_opt_name,
-               const struct argpar_opt_descr * const opt_descr,
-               const bool is_short)
+               const argpar_opt_descr_t * const opt_descr, const bool is_short)
 {
        int ret = 0;
 
@@ -287,7 +282,7 @@ int set_error(struct argpar_error ** const error,
                goto end;
        }
 
-       *error = ARGPAR_ZALLOC(struct argpar_error);
+       *error = ARGPAR_ZALLOC(argpar_error_t);
        if (!*error) {
                goto error;
        }
@@ -323,15 +318,15 @@ end:
 }
 
 ARGPAR_HIDDEN
-enum argpar_error_type argpar_error_type(
-               const struct argpar_error * const error)
+argpar_error_type_t argpar_error_type(
+               const argpar_error_t * const error)
 {
        ARGPAR_ASSERT(error);
        return error->type;
 }
 
 ARGPAR_HIDDEN
-unsigned int argpar_error_orig_index(const struct argpar_error * const error)
+unsigned int argpar_error_orig_index(const argpar_error_t * const error)
 {
        ARGPAR_ASSERT(error);
        return error->orig_index;
@@ -339,7 +334,7 @@ unsigned int argpar_error_orig_index(const struct argpar_error * const error)
 
 ARGPAR_HIDDEN
 const char *argpar_error_unknown_opt_name(
-               const struct argpar_error * const error)
+               const argpar_error_t * const error)
 {
        ARGPAR_ASSERT(error);
        ARGPAR_ASSERT(error->type == ARGPAR_ERROR_TYPE_UNKNOWN_OPT);
@@ -348,8 +343,8 @@ const char *argpar_error_unknown_opt_name(
 }
 
 ARGPAR_HIDDEN
-const struct argpar_opt_descr *argpar_error_opt_descr(
-               const struct argpar_error * const error, bool * const is_short)
+const argpar_opt_descr_t *argpar_error_opt_descr(
+               const argpar_error_t * const error, bool * const is_short)
 {
        ARGPAR_ASSERT(error);
        ARGPAR_ASSERT(error->type == ARGPAR_ERROR_TYPE_MISSING_OPT_ARG ||
@@ -364,7 +359,7 @@ const struct argpar_opt_descr *argpar_error_opt_descr(
 }
 
 ARGPAR_HIDDEN
-void argpar_error_destroy(const struct argpar_error * const error)
+void argpar_error_destroy(const argpar_error_t * const error)
 {
        if (error) {
                free(error->unknown_opt_name);
@@ -384,11 +379,10 @@ void argpar_error_destroy(const struct argpar_error * const error)
  * Returns `NULL` if no descriptor is found.
  */
 static
-const struct argpar_opt_descr *find_descr(
-               const struct argpar_opt_descr * const descrs,
+const argpar_opt_descr_t *find_descr(const argpar_opt_descr_t * const descrs,
                const char short_name, const char * const long_name)
 {
-       const struct argpar_opt_descr *descr;
+       const argpar_opt_descr_t *descr;
 
        for (descr = descrs; descr->short_name || descr->long_name; descr++) {
                if (short_name && descr->short_name &&
@@ -407,11 +401,11 @@ end:
 }
 
 /* Return type of parse_short_opt_group() and parse_long_opt() */
-enum parse_orig_arg_opt_ret {
+typedef enum parse_orig_arg_opt_ret {
        PARSE_ORIG_ARG_OPT_RET_OK,
        PARSE_ORIG_ARG_OPT_RET_ERROR = -1,
        PARSE_ORIG_ARG_OPT_RET_ERROR_MEMORY = -2,
-};
+} parse_orig_arg_opt_ret_t;
 
 /*
  * Parses the short option group argument `short_opt_group`, starting
@@ -423,19 +417,18 @@ enum parse_orig_arg_opt_ret {
  * `*error`.
  */
 static
-enum parse_orig_arg_opt_ret parse_short_opt_group(
+parse_orig_arg_opt_ret_t parse_short_opt_group(
                const char * const short_opt_group,
                const char * const next_orig_arg,
-               const struct argpar_opt_descr * const descrs,
-               struct argpar_iter * const iter,
-               struct argpar_error ** const error,
-               struct argpar_item ** const item)
+               const argpar_opt_descr_t * const descrs,
+               argpar_iter_t * const iter, argpar_error_t ** const error,
+               argpar_item_t ** const item)
 {
-       enum parse_orig_arg_opt_ret ret = PARSE_ORIG_ARG_OPT_RET_OK;
+       parse_orig_arg_opt_ret_t ret = PARSE_ORIG_ARG_OPT_RET_OK;
        bool used_next_orig_arg = false;
        const char *opt_arg = NULL;
-       const struct argpar_opt_descr *descr;
-       struct argpar_item_opt *opt_item;
+       const argpar_opt_descr_t *descr;
+       argpar_item_opt_t *opt_item;
 
        ARGPAR_ASSERT(strlen(short_opt_group) != 0);
 
@@ -525,16 +518,15 @@ end:
  * `*error`.
  */
 static
-enum parse_orig_arg_opt_ret parse_long_opt(const char * const long_opt_arg,
+parse_orig_arg_opt_ret_t parse_long_opt(const char * const long_opt_arg,
                const char * const next_orig_arg,
-               const struct argpar_opt_descr * const descrs,
-               struct argpar_iter * const iter,
-               struct argpar_error ** const error,
-               struct argpar_item ** const item)
+               const argpar_opt_descr_t * const descrs,
+               argpar_iter_t * const iter, argpar_error_t ** const error,
+               argpar_item_t ** const item)
 {
-       enum parse_orig_arg_opt_ret ret = PARSE_ORIG_ARG_OPT_RET_OK;
-       const struct argpar_opt_descr *descr;
-       struct argpar_item_opt *opt_item;
+       parse_orig_arg_opt_ret_t ret = PARSE_ORIG_ARG_OPT_RET_OK;
+       const argpar_opt_descr_t *descr;
+       argpar_item_opt_t *opt_item;
        bool used_next_orig_arg = false;
 
        /* Option's argument, if any */
@@ -649,36 +641,35 @@ end:
  * `*error`.
  */
 static
-enum parse_orig_arg_opt_ret parse_orig_arg_opt(const char * const orig_arg,
+parse_orig_arg_opt_ret_t parse_orig_arg_opt(const char * const orig_arg,
                const char * const next_orig_arg,
-               const struct argpar_opt_descr * const descrs,
-               struct argpar_iter * const iter,
-               struct argpar_error ** const error,
-               struct argpar_item ** const item)
+               const argpar_opt_descr_t * const descrs,
+               argpar_iter_t * const iter, argpar_error_t ** const error,
+               argpar_item_t ** const item)
 {
-       enum parse_orig_arg_opt_ret ret = PARSE_ORIG_ARG_OPT_RET_OK;
+       parse_orig_arg_opt_ret_t ret = PARSE_ORIG_ARG_OPT_RET_OK;
 
        ARGPAR_ASSERT(orig_arg[0] == '-');
 
        if (orig_arg[1] == '-') {
                /* Long option */
-               ret = parse_long_opt(&orig_arg[2],
-                       next_orig_arg, descrs, iter, error, item);
+               ret = parse_long_opt(&orig_arg[2], next_orig_arg, descrs, iter,
+                       error, item);
        } else {
                /* Short option */
-               ret = parse_short_opt_group(&orig_arg[1],
-                       next_orig_arg, descrs, iter, error, item);
+               ret = parse_short_opt_group(&orig_arg[1], next_orig_arg, descrs,
+                       iter, error, item);
        }
 
        return ret;
 }
 
 ARGPAR_HIDDEN
-struct argpar_iter *argpar_iter_create(const unsigned int argc,
+argpar_iter_t *argpar_iter_create(const unsigned int argc,
                const char * const * const argv,
-               const struct argpar_opt_descr * const descrs)
+               const argpar_opt_descr_t * const descrs)
 {
-       struct argpar_iter *iter = ARGPAR_ZALLOC(struct argpar_iter);
+       argpar_iter_t *iter = ARGPAR_ZALLOC(argpar_iter_t);
 
        if (!iter) {
                goto end;
@@ -700,7 +691,7 @@ end:
 }
 
 ARGPAR_HIDDEN
-void argpar_iter_destroy(struct argpar_iter * const iter)
+void argpar_iter_destroy(argpar_iter_t * const iter)
 {
        if (iter) {
                free(iter->tmp_buf.data);
@@ -709,16 +700,15 @@ void argpar_iter_destroy(struct argpar_iter * const iter)
 }
 
 ARGPAR_HIDDEN
-enum argpar_iter_next_status argpar_iter_next(
-               struct argpar_iter * const iter,
-               const struct argpar_item ** const item,
-               const struct argpar_error ** const error)
+argpar_iter_next_status_t argpar_iter_next(argpar_iter_t * const iter,
+               const argpar_item_t ** const item,
+               const argpar_error_t ** const error)
 {
-       enum argpar_iter_next_status status;
-       enum parse_orig_arg_opt_ret parse_orig_arg_opt_ret;
+       argpar_iter_next_status_t status;
+       parse_orig_arg_opt_ret_t parse_orig_arg_opt_ret;
        const char *orig_arg;
        const char *next_orig_arg;
-       struct argpar_error ** const nc_error = (struct argpar_error **) error;
+       argpar_error_t ** const nc_error = (argpar_error_t **) error;
 
        ARGPAR_ASSERT(iter->i <= iter->user.argc);
 
@@ -739,7 +729,7 @@ enum argpar_iter_next_status argpar_iter_next(
        if (strcmp(orig_arg, "-") == 0 || strcmp(orig_arg, "--") == 0 ||
                        orig_arg[0] != '-') {
                /* Non-option argument */
-               const struct argpar_item_non_opt * const non_opt_item =
+               const argpar_item_non_opt_t * const non_opt_item =
                        create_non_opt_item(orig_arg, iter->i,
                                iter->non_opt_index);
 
@@ -758,7 +748,7 @@ enum argpar_iter_next_status argpar_iter_next(
        /* Option argument */
        parse_orig_arg_opt_ret = parse_orig_arg_opt(orig_arg,
                next_orig_arg, iter->user.descrs, iter, nc_error,
-               (struct argpar_item **) item);
+               (argpar_item_t **) item);
        switch (parse_orig_arg_opt_ret) {
        case PARSE_ORIG_ARG_OPT_RET_OK:
                status = ARGPAR_ITER_NEXT_STATUS_OK;
@@ -782,8 +772,7 @@ end:
 }
 
 ARGPAR_HIDDEN
-unsigned int argpar_iter_ingested_orig_args(
-               const struct argpar_iter * const iter)
+unsigned int argpar_iter_ingested_orig_args(const argpar_iter_t * const iter)
 {
        return iter->i;
 }
index 4698c2dd660052388241fb0addcf11008f19fad0..4060470f805626b4dc8b62b80931fbb0737c48e7 100644 (file)
@@ -87,7 +87,7 @@ A parsing item (the result of argpar_iter_next()) has the type
 #argpar_item.
 
 Get the type (option or non-option) of an item with
-\link argpar_item_type(const struct argpar_item *) argpar_item_type()\endlink.
+\link argpar_item_type(const argpar_item_t *) argpar_item_type()\endlink.
 Each item type has its set of dedicated functions
 (\c argpar_item_opt_ and \c argpar_item_non_opt_ prefixes).
 
@@ -131,7 +131,7 @@ argpar_iter_next() produces the following items, in this order:
 # define ARGPAR_NOEXCEPT
 #endif
 
-struct argpar_opt_descr;
+typedef struct argpar_opt_descr argpar_opt_descr_t;
 
 /*!
 @name Item API
@@ -141,15 +141,15 @@ struct argpar_opt_descr;
 /*!
 @brief
     Type of a parsing item, as returned by
-    \link argpar_item_type(const struct argpar_item *) argpar_item_type()\endlink.
+    \link argpar_item_type(const argpar_item *) argpar_item_type()\endlink.
 */
-enum argpar_item_type {
+typedef enum argpar_item_type {
        /// Option
        ARGPAR_ITEM_TYPE_OPT,
 
        /// Non-option
        ARGPAR_ITEM_TYPE_NON_OPT,
-};
+} argpar_item_type_t;
 
 /*!
 @struct argpar_item
@@ -159,7 +159,7 @@ enum argpar_item_type {
 
 argpar_iter_next() sets a pointer to such a type.
 */
-struct argpar_item;
+typedef struct argpar_item argpar_item_t;
 
 /*!
 @brief
@@ -177,8 +177,7 @@ struct argpar_item;
 /// @cond hidden_macro
 ARGPAR_HIDDEN
 /// @endcond
-enum argpar_item_type argpar_item_type(
-               const struct argpar_item *item) ARGPAR_NOEXCEPT;
+argpar_item_type_t argpar_item_type(const argpar_item_t *item) ARGPAR_NOEXCEPT;
 
 /*!
 @brief
@@ -198,8 +197,8 @@ enum argpar_item_type argpar_item_type(
 /// @cond hidden_macro
 ARGPAR_HIDDEN
 /// @endcond
-const struct argpar_opt_descr *argpar_item_opt_descr(
-               const struct argpar_item *item) ARGPAR_NOEXCEPT;
+const argpar_opt_descr_t *argpar_item_opt_descr(
+               const argpar_item_t *item) ARGPAR_NOEXCEPT;
 
 /*!
 @brief
@@ -220,7 +219,7 @@ const struct argpar_opt_descr *argpar_item_opt_descr(
 /// @cond hidden_macro
 ARGPAR_HIDDEN
 /// @endcond
-const char *argpar_item_opt_arg(const struct argpar_item *item) ARGPAR_NOEXCEPT;
+const char *argpar_item_opt_arg(const argpar_item_t *item) ARGPAR_NOEXCEPT;
 
 /*!
 @brief
@@ -244,7 +243,7 @@ const char *argpar_item_opt_arg(const struct argpar_item *item) ARGPAR_NOEXCEPT;
 ARGPAR_HIDDEN
 /// @endcond
 const char *argpar_item_non_opt_arg(
-               const struct argpar_item *item) ARGPAR_NOEXCEPT;
+               const argpar_item_t *item) ARGPAR_NOEXCEPT;
 
 /*!
 @brief
@@ -281,7 +280,7 @@ argument index of \c mix is&nbsp;4.
 ARGPAR_HIDDEN
 /// @endcond
 unsigned int argpar_item_non_opt_orig_index(
-               const struct argpar_item *item) ARGPAR_NOEXCEPT;
+               const argpar_item_t *item) ARGPAR_NOEXCEPT;
 
 /*!
 @brief
@@ -317,7 +316,7 @@ argument index of \c mix is&nbsp;1.
 ARGPAR_HIDDEN
 /// @endcond
 unsigned int argpar_item_non_opt_non_opt_index(
-               const struct argpar_item *item) ARGPAR_NOEXCEPT;
+               const argpar_item_t *item) ARGPAR_NOEXCEPT;
 
 /*!
 @brief
@@ -329,7 +328,7 @@ unsigned int argpar_item_non_opt_non_opt_index(
 /// @cond hidden_macro
 ARGPAR_HIDDEN
 /// @endcond
-void argpar_item_destroy(const struct argpar_item *item) ARGPAR_NOEXCEPT;
+void argpar_item_destroy(const argpar_item_t *item) ARGPAR_NOEXCEPT;
 
 /*!
 @def ARGPAR_ITEM_DESTROY_AND_RESET(_item)
@@ -340,7 +339,7 @@ void argpar_item_destroy(const struct argpar_item *item) ARGPAR_NOEXCEPT;
 
 @param[in] _item
     Item to destroy and variable to reset
-    (<code>const struct argpar_item *</code> type).
+    (<code>const argpar_item_t *</code> type).
 */
 #define ARGPAR_ITEM_DESTROY_AND_RESET(_item)                           \
        {                                                               \
@@ -358,9 +357,9 @@ void argpar_item_destroy(const struct argpar_item *item) ARGPAR_NOEXCEPT;
 /*!
 @brief
     Parsing error type, as returned by
-    \link argpar_error_type(const struct argpar_error *) argpar_error_type()\endlink.
+    \link argpar_error_type(const argpar_error_t *) argpar_error_type()\endlink.
 */
-enum argpar_error_type {
+typedef enum argpar_error_type {
        /// Unknown option error
        ARGPAR_ERROR_TYPE_UNKNOWN_OPT,
 
@@ -369,7 +368,7 @@ enum argpar_error_type {
 
        /// Unexpected option argument error
        ARGPAR_ERROR_TYPE_UNEXPECTED_OPT_ARG,
-};
+} argpar_error_type_t;
 
 /*!
 @struct argpar_error
@@ -377,7 +376,7 @@ enum argpar_error_type {
 @brief
     Opaque parsing error type
 */
-struct argpar_error;
+typedef struct argpar_error argpar_error_t;
 
 /*!
 @brief
@@ -395,8 +394,8 @@ struct argpar_error;
 /// @cond hidden_macro
 ARGPAR_HIDDEN
 /// @endcond
-enum argpar_error_type argpar_error_type(
-               const struct argpar_error *error) ARGPAR_NOEXCEPT;
+argpar_error_type_t argpar_error_type(
+               const argpar_error_t *error) ARGPAR_NOEXCEPT;
 
 /*!
 @brief
@@ -417,7 +416,7 @@ enum argpar_error_type argpar_error_type(
 ARGPAR_HIDDEN
 /// @endcond
 unsigned int argpar_error_orig_index(
-               const struct argpar_error *error) ARGPAR_NOEXCEPT;
+               const argpar_error_t *error) ARGPAR_NOEXCEPT;
 
 /*!
 @brief
@@ -441,14 +440,14 @@ part (<code>\--mireille</code> in the last example).
     \p error is not \c NULL.
 @pre
     The type of \p error, as returned by
-    \link argpar_error_type(const struct argpar_error *) argpar_error_type()\endlink,
+    \link argpar_error_type(const argpar_error_t *) argpar_error_type()\endlink,
     is #ARGPAR_ERROR_TYPE_UNKNOWN_OPT.
 */
 /// @cond hidden_macro
 ARGPAR_HIDDEN
 /// @endcond
 const char *argpar_error_unknown_opt_name(
-               const struct argpar_error *error) ARGPAR_NOEXCEPT;
+               const argpar_error_t *error) ARGPAR_NOEXCEPT;
 
 /*!
 @brief
@@ -475,15 +474,14 @@ const char *argpar_error_unknown_opt_name(
     \p error is not \c NULL.
 @pre
     The type of \p error, as returned by
-    \link argpar_error_type(const struct argpar_error *) argpar_error_type()\endlink,
+    \link argpar_error_type(const argpar_error_t *) argpar_error_type()\endlink,
     is #ARGPAR_ERROR_TYPE_MISSING_OPT_ARG or
     #ARGPAR_ERROR_TYPE_UNEXPECTED_OPT_ARG.
 */
 /// @cond hidden_macro
 ARGPAR_HIDDEN
 /// @endcond
-const struct argpar_opt_descr *argpar_error_opt_descr(
-               const struct argpar_error *error,
+const argpar_opt_descr_t *argpar_error_opt_descr(const argpar_error_t *error,
                bool *is_short) ARGPAR_NOEXCEPT;
 
 /*!
@@ -496,7 +494,7 @@ const struct argpar_opt_descr *argpar_error_opt_descr(
 /// @cond hidden_macro
 ARGPAR_HIDDEN
 /// @endcond
-void argpar_error_destroy(const struct argpar_error *error) ARGPAR_NOEXCEPT;
+void argpar_error_destroy(const argpar_error_t *error) ARGPAR_NOEXCEPT;
 
 /// @}
 
@@ -515,7 +513,7 @@ terminated with #ARGPAR_OPT_DESCR_SENTINEL, as its \p descrs parameter.
 The typical usage is, for example:
 
 @code
-const struct argpar_opt_descr descrs[] = {
+const argpar_opt_descr_t descrs[] = {
     { 0, 'd', NULL, false },
     { 1, '\0', "squeeze", true },
     { 2, 'm', "meow", true },
@@ -523,7 +521,7 @@ const struct argpar_opt_descr descrs[] = {
 };
 @endcode
 */
-struct argpar_opt_descr {
+typedef struct argpar_opt_descr {
        /// Numeric ID, to uniquely identify this descriptor
        const int id;
 
@@ -535,7 +533,7 @@ struct argpar_opt_descr {
 
        /// \c true if this option has an argument
        const bool with_arg;
-};
+} argpar_opt_descr_t;
 
 /*!
 @brief
@@ -544,7 +542,7 @@ struct argpar_opt_descr {
 The typical usage is, for example:
 
 @code
-const struct argpar_opt_descr descrs[] = {
+const argpar_opt_descr_t descrs[] = {
     { 0, 'd', NULL, false },
     { 1, '\0', "squeeze", true },
     { 2, 'm', "meow", true },
@@ -562,7 +560,7 @@ const struct argpar_opt_descr descrs[] = {
 
 argpar_iter_create() returns a pointer to such a type.
 */
-struct argpar_iter;
+typedef struct argpar_iter argpar_iter_t;
 
 /*!
 @brief
@@ -621,9 +619,8 @@ argpar_iter_next().
 /// @cond hidden_macro
 ARGPAR_HIDDEN
 /// @endcond
-struct argpar_iter *argpar_iter_create(unsigned int argc,
-               const char * const *argv,
-               const struct argpar_opt_descr *descrs) ARGPAR_NOEXCEPT;
+argpar_iter_t *argpar_iter_create(unsigned int argc, const char * const *argv,
+               const argpar_opt_descr_t *descrs) ARGPAR_NOEXCEPT;
 
 /*!
 @brief
@@ -638,7 +635,7 @@ struct argpar_iter *argpar_iter_create(unsigned int argc,
 /// @cond hidden_macro
 ARGPAR_HIDDEN
 /// @endcond
-void argpar_iter_destroy(struct argpar_iter *iter) ARGPAR_NOEXCEPT;
+void argpar_iter_destroy(argpar_iter_t *iter) ARGPAR_NOEXCEPT;
 
 /*!
 @brief
@@ -646,7 +643,7 @@ void argpar_iter_destroy(struct argpar_iter *iter) ARGPAR_NOEXCEPT;
 
 Error status enumerators have a negative value.
 */
-enum argpar_iter_next_status {
+typedef enum argpar_iter_next_status {
        /// Success
        ARGPAR_ITER_NEXT_STATUS_OK,
 
@@ -658,7 +655,7 @@ enum argpar_iter_next_status {
 
        /// Memory error
        ARGPAR_ITER_NEXT_STATUS_ERROR_MEMORY = -12,
-};
+} argpar_iter_next_status_t;
 
 /*!
 @brief
@@ -696,9 +693,9 @@ If there are no more original arguments to parse, this function returns
 /// @cond hidden_macro
 ARGPAR_HIDDEN
 /// @endcond
-enum argpar_iter_next_status argpar_iter_next(
-               struct argpar_iter *iter, const struct argpar_item **item,
-               const struct argpar_error **error) ARGPAR_NOEXCEPT;
+argpar_iter_next_status_t argpar_iter_next(argpar_iter_t *iter,
+               const argpar_item_t **item,
+               const argpar_error_t **error) ARGPAR_NOEXCEPT;
 
 /*
  * Returns the number of ingested elements from `argv`, as passed to
@@ -726,7 +723,7 @@ enum argpar_iter_next_status argpar_iter_next(
 ARGPAR_HIDDEN
 /// @endcond
 unsigned int argpar_iter_ingested_orig_args(
-               const struct argpar_iter *iter) ARGPAR_NOEXCEPT;
+               const argpar_iter_t *iter) ARGPAR_NOEXCEPT;
 
 /// @}
 
index 87646a9a0a9d99fcc28a6ededbc035eee4eddeae..cb510324340a46ca9d787f581083a0fe09b12c38 100644 (file)
@@ -39,7 +39,7 @@
  */
 static
 void append_to_res_str(GString * const res_str,
-               const struct argpar_item * const item)
+               const argpar_item_t * const item)
 {
        if (res_str->len > 0) {
                g_string_append_c(res_str, ' ');
@@ -48,7 +48,7 @@ void append_to_res_str(GString * const res_str,
        switch (argpar_item_type(item)) {
        case ARGPAR_ITEM_TYPE_OPT:
        {
-               const struct argpar_opt_descr * const descr =
+               const argpar_opt_descr_t * const descr =
                        argpar_item_opt_descr(item);
                const char * const arg = argpar_item_opt_arg(item);
 
@@ -102,12 +102,12 @@ void append_to_res_str(GString * const res_str,
 static
 void test_succeed(const char * const cmdline,
                const char * const expected_cmd_line,
-               const struct argpar_opt_descr * const descrs,
+               const argpar_opt_descr_t * const descrs,
                const unsigned int expected_ingested_orig_args)
 {
-       struct argpar_iter *iter = NULL;
-       const struct argpar_item *item = NULL;
-       const struct argpar_error *error = NULL;
+       argpar_iter_t *iter = NULL;
+       const argpar_item_t *item = NULL;
+       const argpar_error_t *error = NULL;
        GString * const res_str = g_string_new(NULL);
        gchar ** const argv = g_strsplit(cmdline, " ", 0);
        unsigned int i, actual_ingested_orig_args;
@@ -119,7 +119,7 @@ void test_succeed(const char * const cmdline,
        assert(iter);
 
        for (i = 0; ; i++) {
-               enum argpar_iter_next_status status;
+               argpar_iter_next_status_t status;
 
                ARGPAR_ITEM_DESTROY_AND_RESET(item);
                status = argpar_iter_next(iter, &item, &error);
@@ -178,7 +178,7 @@ void succeed_tests(void)
 {
        /* No arguments */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        ARGPAR_OPT_DESCR_SENTINEL
                };
 
@@ -190,7 +190,7 @@ void succeed_tests(void)
 
        /* Single long option */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, '\0', "salut", false },
                        ARGPAR_OPT_DESCR_SENTINEL
                };
@@ -203,7 +203,7 @@ void succeed_tests(void)
 
        /* Single short option */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, 'f', NULL, false },
                        ARGPAR_OPT_DESCR_SENTINEL
                };
@@ -216,7 +216,7 @@ void succeed_tests(void)
 
        /* Short and long option (aliases) */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, 'f', "flaw", false },
                        ARGPAR_OPT_DESCR_SENTINEL
                };
@@ -229,7 +229,7 @@ void succeed_tests(void)
 
        /* Long option with argument (space form) */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, '\0', "tooth", true },
                        ARGPAR_OPT_DESCR_SENTINEL
                };
@@ -242,7 +242,7 @@ void succeed_tests(void)
 
        /* Long option with argument (equal form) */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, '\0', "polish", true },
                        ARGPAR_OPT_DESCR_SENTINEL
                };
@@ -255,7 +255,7 @@ void succeed_tests(void)
 
        /* Short option with argument (space form) */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, 'c', NULL, true },
                        ARGPAR_OPT_DESCR_SENTINEL
                };
@@ -268,7 +268,7 @@ void succeed_tests(void)
 
        /* Short option with argument (glued form) */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, 'c', NULL, true },
                        ARGPAR_OPT_DESCR_SENTINEL
                };
@@ -281,7 +281,7 @@ void succeed_tests(void)
 
        /* Short and long option (aliases) with argument (all forms) */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, 'd', "dry", true },
                        ARGPAR_OPT_DESCR_SENTINEL
                };
@@ -294,7 +294,7 @@ void succeed_tests(void)
 
        /* Many short options, last one with argument (glued form) */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, 'd', NULL, false },
                        { 0, 'e', NULL, false },
                        { 0, 'f', NULL, true },
@@ -309,7 +309,7 @@ void succeed_tests(void)
 
        /* Many options */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, 'd', NULL, false },
                        { 0, 'e', "east", true },
                        { 0, '\0', "mind", false },
@@ -324,7 +324,7 @@ void succeed_tests(void)
 
        /* Single non-option argument */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        ARGPAR_OPT_DESCR_SENTINEL
                };
 
@@ -336,7 +336,7 @@ void succeed_tests(void)
 
        /* Two non-option arguments */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        ARGPAR_OPT_DESCR_SENTINEL
                };
 
@@ -348,7 +348,7 @@ void succeed_tests(void)
 
        /* Single non-option argument mixed with options */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, 'd', NULL, false },
                        { 0, '\0', "squeeze", true },
                        ARGPAR_OPT_DESCR_SENTINEL
@@ -362,7 +362,7 @@ void succeed_tests(void)
 
        /* Valid `---opt` */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, '\0', "-fuel", true },
                        ARGPAR_OPT_DESCR_SENTINEL
                };
@@ -375,7 +375,7 @@ void succeed_tests(void)
 
        /* Long option containing `=` in argument (equal form) */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, '\0', "zebra", true },
                        ARGPAR_OPT_DESCR_SENTINEL
                };
@@ -388,7 +388,7 @@ void succeed_tests(void)
 
        /* Short option's argument starting with `-` (glued form) */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, 'z', NULL, true },
                        ARGPAR_OPT_DESCR_SENTINEL
                };
@@ -401,7 +401,7 @@ void succeed_tests(void)
 
        /* Short option's argument starting with `-` (space form) */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, 'z', NULL, true },
                        ARGPAR_OPT_DESCR_SENTINEL
                };
@@ -414,7 +414,7 @@ void succeed_tests(void)
 
        /* Long option's argument starting with `-` (space form) */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, '\0', "janine", true },
                        ARGPAR_OPT_DESCR_SENTINEL
                };
@@ -427,7 +427,7 @@ void succeed_tests(void)
 
        /* Long option's argument starting with `-` (equal form) */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, '\0', "janine", true },
                        ARGPAR_OPT_DESCR_SENTINEL
                };
@@ -440,7 +440,7 @@ void succeed_tests(void)
 
        /* Long option's empty argument (equal form) */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, 'f', NULL, false },
                        { 0, '\0', "yeah", true },
                        ARGPAR_OPT_DESCR_SENTINEL
@@ -454,7 +454,7 @@ void succeed_tests(void)
 
        /* `-` non-option argument */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, 'f', NULL, false },
                        ARGPAR_OPT_DESCR_SENTINEL
                };
@@ -467,7 +467,7 @@ void succeed_tests(void)
 
        /* `--` non-option argument */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, 'f', NULL, false },
                        ARGPAR_OPT_DESCR_SENTINEL
                };
@@ -496,7 +496,7 @@ void succeed_tests(void)
                        "cornhole-cliche-tattooed-green-juice-adaptogen-"
                        "kitsch-lo-fi-vexillologist-migas-gentrify-"
                        "viral-raw-denim";
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, '\0', opt_name, true },
                        ARGPAR_OPT_DESCR_SENTINEL
                };
@@ -528,25 +528,25 @@ void succeed_tests(void)
  */
 static
 void test_fail(const char * const cmdline,
-               const enum argpar_error_type expected_error_type,
+               const argpar_error_type_t expected_error_type,
                const unsigned int expected_orig_index,
                const char * const expected_unknown_opt_name,
                const unsigned int expected_opt_descr_index,
                const bool expected_is_short,
-               const struct argpar_opt_descr * const descrs)
+               const argpar_opt_descr_t * const descrs)
 {
-       struct argpar_iter *iter = NULL;
-       const struct argpar_item *item = NULL;
+       argpar_iter_t *iter = NULL;
+       const argpar_item_t *item = NULL;
        gchar ** const argv = g_strsplit(cmdline, " ", 0);
        unsigned int i;
-       const struct argpar_error *error = NULL;
+       const argpar_error_t *error = NULL;
 
        iter = argpar_iter_create(g_strv_length(argv),
                (const char * const *) argv, descrs);
        assert(iter);
 
        for (i = 0; ; i++) {
-               enum argpar_iter_next_status status;
+               argpar_iter_next_status_t status;
 
                ARGPAR_ITEM_DESTROY_AND_RESET(item);
                status = argpar_iter_next(iter, &item, &error);
@@ -637,7 +637,7 @@ void fail_tests(void)
 
        /* Unknown short option (space form) */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, 'd', NULL, true },
                        ARGPAR_OPT_DESCR_SENTINEL
                };
@@ -651,7 +651,7 @@ void fail_tests(void)
 
        /* Unknown short option (glued form) */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, 'd', 0, true },
                        ARGPAR_OPT_DESCR_SENTINEL
                };
@@ -665,7 +665,7 @@ void fail_tests(void)
 
        /* Unknown long option (space form) */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, '\0', "sink", true },
                        ARGPAR_OPT_DESCR_SENTINEL
                };
@@ -679,7 +679,7 @@ void fail_tests(void)
 
        /* Unknown long option (equal form) */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, '\0', "sink", true },
                        ARGPAR_OPT_DESCR_SENTINEL
                };
@@ -693,7 +693,7 @@ void fail_tests(void)
 
        /* Unknown option before non-option argument */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, '\0', "thumb", true },
                        ARGPAR_OPT_DESCR_SENTINEL
                };
@@ -707,7 +707,7 @@ void fail_tests(void)
 
        /* Unknown option after non-option argument */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, '\0', "thumb", true },
                        ARGPAR_OPT_DESCR_SENTINEL
                };
@@ -721,7 +721,7 @@ void fail_tests(void)
 
        /* Missing long option argument */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, '\0', "thumb", true },
                        ARGPAR_OPT_DESCR_SENTINEL
                };
@@ -735,7 +735,7 @@ void fail_tests(void)
 
        /* Missing short option argument */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, 'k', NULL, true },
                        ARGPAR_OPT_DESCR_SENTINEL
                };
@@ -749,7 +749,7 @@ void fail_tests(void)
 
        /* Missing short option argument (multiple glued) */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, 'a', NULL, false },
                        { 0, 'b', NULL, false },
                        { 0, 'c', NULL, true },
@@ -765,7 +765,7 @@ void fail_tests(void)
 
        /* Unexpected long option argument */
        {
-               const struct argpar_opt_descr descrs[] = {
+               const argpar_opt_descr_t descrs[] = {
                        { 0, 'c', "chevre", false },
                        ARGPAR_OPT_DESCR_SENTINEL
                };
This page took 0.041772 seconds and 4 git commands to generate.