2008-07-08 14:29:05 +00:00
|
|
|
/*
|
2014-01-19 01:09:44 +00:00
|
|
|
* This file Copyright (C) 2008-2014 Mnemosyne LLC
|
2008-07-08 14:29:05 +00:00
|
|
|
*
|
2014-01-21 03:10:30 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2008-07-09 15:31:35 +00:00
|
|
|
*
|
2009-06-06 17:39:04 +00:00
|
|
|
* $Id$
|
2008-07-08 14:29:05 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TR_GETOPT_H
|
|
|
|
#define TR_GETOPT_H
|
|
|
|
|
2009-03-17 18:08:02 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
typedef struct tr_option
|
|
|
|
{
|
2012-12-05 17:29:46 +00:00
|
|
|
int val; /* the value to return from tr_getopt () */
|
2009-01-23 18:44:15 +00:00
|
|
|
const char * longName; /* --long-form */
|
2012-12-05 17:29:46 +00:00
|
|
|
const char * description; /* option's description for tr_getopt_usage () */
|
2009-01-23 18:44:15 +00:00
|
|
|
const char * shortName; /* short form */
|
2009-02-13 18:23:56 +00:00
|
|
|
int has_arg; /* 0 for no argument, 1 for argument */
|
2012-12-05 17:29:46 +00:00
|
|
|
const char * argName; /* argument's description for tr_getopt_usage () */
|
2008-07-08 14:29:05 +00:00
|
|
|
}
|
|
|
|
tr_option;
|
|
|
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2012-12-05 17:29:46 +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
|
|
|
*/
|
2012-12-05 17:29:46 +00:00
|
|
|
int tr_getopt (const char * summary,
|
2010-01-01 22:13:27 +00:00
|
|
|
int argc,
|
|
|
|
const char ** argv,
|
|
|
|
const tr_option * opts,
|
2012-12-05 17:29:46 +00:00
|
|
|
const char ** 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 */
|
2012-12-05 17:29:46 +00:00
|
|
|
void tr_getopt_usage (const char * appName,
|
2010-01-01 22:13:27 +00:00
|
|
|
const char * description,
|
2012-12-05 17:29:46 +00:00
|
|
|
const tr_option * opts);
|
2008-07-08 14:29:05 +00:00
|
|
|
|
2009-03-17 18:08:02 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} /* extern "C" */
|
|
|
|
#endif
|
|
|
|
|
2009-05-29 19:17:12 +00:00
|
|
|
/** @} */
|
|
|
|
|
2008-07-08 14:29:05 +00:00
|
|
|
#endif /* TR_GETOPT_H */
|