2008-07-08 14:29:05 +00:00
|
|
|
/*
|
2009-01-10 23:09:07 +00:00
|
|
|
* This file Copyright (C) 2008-2009 Charles Kerr <charles@transmissionbt.com>
|
2008-07-08 14:29:05 +00:00
|
|
|
*
|
2009-06-06 17:39:04 +00:00
|
|
|
* This file is licensed by the GPL version 2. Works owned by the
|
|
|
|
* 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
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return TR_GETOPT_DONE, TR_GETOPT_ERR, TR_GETOPT_UNK,
|
2008-07-09 15:31:35 +00:00
|
|
|
* or the matching tr_option's `val' field
|
2008-07-08 14:29:05 +00:00
|
|
|
*/
|
2008-09-23 19:11:04 +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
|
|
|
|
2008-09-23 19:11:04 +00:00
|
|
|
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 */
|