X-Git-Url: http://git.efficios.com/?p=argpar.git;a=blobdiff_plain;f=argpar%2Fargpar.h;h=00334cd6fb9d6f0c14a7fc08f5a21d114e778e65;hp=5732a88dd8671d15444f25a54b23cda0d75cf8ce;hb=03e1579f42a13b5e8ccf26bcc55fa5c23ba9f313;hpb=7ac57709d4964e2c59c9b0592632c374056caa00 diff --git a/argpar/argpar.h b/argpar/argpar.h index 5732a88..00334cd 100644 --- a/argpar/argpar.h +++ b/argpar/argpar.h @@ -1,32 +1,16 @@ -#ifndef BABELTRACE_ARGPAR_H -#define BABELTRACE_ARGPAR_H - /* - * Copyright 2019 Philippe Proulx + * SPDX-License-Identifier: MIT * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. + * Copyright 2019 Philippe Proulx */ +#ifndef BABELTRACE_ARGPAR_H +#define BABELTRACE_ARGPAR_H + #include /* Sentinel for an option descriptor array */ -#define BT_ARGPAR_OPT_DESCR_SENTINEL { -1, '\0', NULL, false } +#define ARGPAR_OPT_DESCR_SENTINEL { -1, '\0', NULL, false } /* * ARGPAR_HIDDEN: if argpar is used in some shared library, we don't want them @@ -42,7 +26,7 @@ #endif /* Option descriptor */ -struct bt_argpar_opt_descr { +struct argpar_opt_descr { /* Numeric ID for this option */ const int id; @@ -57,33 +41,33 @@ struct bt_argpar_opt_descr { }; /* Item type */ -enum bt_argpar_item_type { +enum argpar_item_type { /* Option */ - BT_ARGPAR_ITEM_TYPE_OPT, + ARGPAR_ITEM_TYPE_OPT, /* Non-option */ - BT_ARGPAR_ITEM_TYPE_NON_OPT, + ARGPAR_ITEM_TYPE_NON_OPT, }; /* Base item */ -struct bt_argpar_item { - enum bt_argpar_item_type type; +struct argpar_item { + enum argpar_item_type type; }; /* Option item */ -struct bt_argpar_item_opt { - struct bt_argpar_item base; +struct argpar_item_opt { + struct argpar_item base; /* Corresponding descriptor */ - const struct bt_argpar_opt_descr *descr; + const struct argpar_opt_descr *descr; /* Argument, or `NULL` if none */ const char *arg; }; /* Non-option item */ -struct bt_argpar_item_non_opt { - struct bt_argpar_item base; +struct argpar_item_non_opt { + struct argpar_item base; /* * Complete argument, pointing to one of the entries of the @@ -98,21 +82,21 @@ struct bt_argpar_item_non_opt { unsigned int non_opt_index; }; -struct bt_argpar_item_array { - /* Array of `struct bt_argpar_item *`, or `NULL` on error */ - struct bt_argpar_item **items; +struct argpar_item_array { + /* Array of `struct argpar_item *`, or `NULL` on error */ + struct argpar_item **items; - /* Number of used slots in `data`. */ + /* Number of used slots in `items`. */ unsigned int n_items; - /* Number of allocated slots in `data`. */ + /* Number of allocated slots in `items`. */ unsigned int n_alloc; }; -/* What is returned by bt_argpar_parse() */ -struct bt_argpar_parse_ret { - /* Array of `struct bt_argpar_item *`, or `NULL` on error */ - struct bt_argpar_item_array *items; +/* What is returned by argpar_parse() */ +struct argpar_parse_ret { + /* Array of `struct argpar_item *`, or `NULL` on error */ + struct argpar_item_array *items; /* Error string, or `NULL` if none */ char *error; @@ -123,7 +107,7 @@ struct bt_argpar_parse_ret { /* * Parses the arguments `argv` of which the count is `argc` using the - * sentinel-terminated (use `BT_ARGPAR_OPT_DESCR_SENTINEL`) option + * sentinel-terminated (use `ARGPAR_OPT_DESCR_SENTINEL`) option * descriptor array `descrs`. * * This function considers ALL the elements of `argv`, including the @@ -163,9 +147,9 @@ struct bt_argpar_parse_ret { * contains one entry for each instance). * * On success, this function returns an array of items - * (`struct bt_argpar_item *`). Each item is to be casted to the - * appropriate type (`struct bt_argpar_item_opt *` or - * `struct bt_argpar_item_non_opt *`) depending on its type. + * (`struct argpar_item *`). Each item is to be casted to the + * appropriate type (`struct argpar_item_opt *` or + * `struct argpar_item_non_opt *`) depending on its type. * * The returned array contains the items in the same order that the * arguments were parsed, including non-option arguments. This means, @@ -213,21 +197,21 @@ struct bt_argpar_parse_ret { * the `error` string member contains details about the error. * * You can finalize the returned structure with - * bt_argpar_parse_ret_fini(). + * argpar_parse_ret_fini(). */ ARGPAR_HIDDEN -struct bt_argpar_parse_ret bt_argpar_parse(unsigned int argc, +struct argpar_parse_ret argpar_parse(unsigned int argc, const char * const *argv, - const struct bt_argpar_opt_descr *descrs, + const struct argpar_opt_descr *descrs, bool fail_on_unknown_opt); /* - * Finalizes what is returned by bt_argpar_parse(). + * Finalizes what is returned by argpar_parse(). * - * It is safe to call bt_argpar_parse() multiple times with the same + * It is safe to call argpar_parse() multiple times with the same * structure. */ ARGPAR_HIDDEN -void bt_argpar_parse_ret_fini(struct bt_argpar_parse_ret *ret); +void argpar_parse_ret_fini(struct argpar_parse_ret *ret); #endif /* BABELTRACE_ARGPAR_H */