2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2008-2022 Mnemosyne LLC.
|
2022-08-08 18:05:39 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2008-07-08 14:29:05 +00:00
|
|
|
|
2016-03-29 16:37:21 +00:00
|
|
|
#pragma once
|
2008-07-08 14:29:05 +00:00
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/**
|
|
|
|
* @addtogroup utils Utilities
|
2009-08-12 14:40:32 +00:00
|
|
|
* @{
|
2009-05-29 19:17:12 +00:00
|
|
|
*/
|
|
|
|
|
2010-01-01 22:13:27 +00:00
|
|
|
/** @brief Similar to optind, this is the current index into argv */
|
2008-07-08 14:29:05 +00:00
|
|
|
extern int tr_optind;
|
|
|
|
|
2021-10-06 14:26:07 +00:00
|
|
|
struct tr_option
|
2008-07-08 14:29:05 +00:00
|
|
|
{
|
2017-04-21 07:40:57 +00:00
|
|
|
int val; /* the value to return from tr_getopt() */
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* longName; /* --long-form */
|
2017-04-21 07:40:57 +00:00
|
|
|
char const* description; /* option's description for tr_getopt_usage() */
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* shortName; /* short form */
|
2019-07-14 12:40:41 +00:00
|
|
|
bool has_arg; /* 0 for no argument, 1 for argument */
|
2017-04-21 07:40:57 +00:00
|
|
|
char const* argName; /* argument's description for tr_getopt_usage() */
|
2021-10-06 14:26:07 +00:00
|
|
|
};
|
2008-07-08 14:29:05 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
/* all options have been processed */
|
|
|
|
TR_OPT_DONE = 0,
|
|
|
|
/* a syntax error was detected, such as a missing
|
|
|
|
* argument for an option that requires one */
|
|
|
|
TR_OPT_ERR = -1,
|
|
|
|
/* an unknown option was reached */
|
|
|
|
TR_OPT_UNK = -2
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2017-04-21 07:40:57 +00:00
|
|
|
* @brief similar to getopt()
|
2010-01-01 22:13:27 +00:00
|
|
|
* @return TR_GETOPT_DONE, TR_GETOPT_ERR, TR_GETOPT_UNK, or the matching tr_option's `val' field
|
2008-07-08 14:29:05 +00:00
|
|
|
*/
|
2022-08-03 06:15:37 +00:00
|
|
|
int tr_getopt(char const* usage, int argc, char const* const* argv, tr_option const* opts, char const** setme_optarg);
|
2008-07-08 14:29:05 +00:00
|
|
|
|
2010-01-01 22:13:27 +00:00
|
|
|
/** @brief prints the `Usage' help section to stdout */
|
2017-04-20 16:02:19 +00:00
|
|
|
void tr_getopt_usage(char const* appName, char const* description, tr_option const* opts);
|
2008-07-08 14:29:05 +00:00
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/** @} */
|