2008-07-08 14:29:05 +00:00
|
|
|
/*
|
2011-01-19 13:48:47 +00:00
|
|
|
* This file Copyright (C) Mnemosyne LLC
|
2008-07-08 14:29:05 +00:00
|
|
|
*
|
2010-12-27 19:18:17 +00:00
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
2012-12-05 17:29:46 +00:00
|
|
|
* Transmission project are granted a special exemption to clause 2 (b)
|
2009-06-06 17:39:04 +00:00
|
|
|
* so that the bulk of its code can remain under the MIT license.
|
|
|
|
* This exemption does not extend to derived works not owned by
|
|
|
|
* the Transmission project.
|
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 */
|