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
|
2009-06-06 17:39:04 +00:00
|
|
|
* Transmission project are granted a special exemption to clause 2(b)
|
|
|
|
* 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
|
|
|
|
{
|
2009-02-13 18:23:56 +00:00
|
|
|
int val; /* the value to return from tr_getopt() */
|
2009-01-23 18:44:15 +00:00
|
|
|
const char * longName; /* --long-form */
|
|
|
|
const char * description; /* option's description for tr_getopt_usage() */
|
|
|
|
const char * shortName; /* short form */
|
2009-02-13 18:23:56 +00:00
|
|
|
int has_arg; /* 0 for no argument, 1 for argument */
|
2009-01-23 18:44:15 +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
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2010-01-01 22:13:27 +00:00
|
|
|
* @brief similar to getopt()
|
|
|
|
* @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
|
|
|
*/
|
2010-01-01 22:13:27 +00:00
|
|
|
int tr_getopt( const char * summary,
|
|
|
|
int argc,
|
|
|
|
const char ** argv,
|
|
|
|
const tr_option * opts,
|
|
|
|
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 */
|
|
|
|
void tr_getopt_usage( const char * appName,
|
|
|
|
const char * description,
|
|
|
|
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 */
|