source: trunk/libtransmission/tr-getopt.h @ 6297

Last change on this file since 6297 was 6297, checked in by charles, 14 years ago

fold the rewritten getopt code into libT

File size: 1.6 KB
Line 
1/*
2 * This file Copyright (C) 2008 Charles Kerr <charles@rebelbase.com>
3 *
4 * This file is licensed by the GPL version 2.  Works owned by the
5 * Transmission project are granted a special exemption to clause 2(b)
6 * so that the bulk of its code can remain under the MIT license.
7 * This exemption does not extend to derived works not owned by
8 * the Transmission project.
9 *
10 * $Id:$
11 */
12
13#ifndef TR_GETOPT_H
14#define TR_GETOPT_H
15
16extern int tr_optind;
17
18typedef struct tr_option
19{
20    int     val;          /* the value to return from tr_getopt() */
21    char  * longName;     /* --long-form */
22    char  * description;  /* option's description for tr_getopt_usage() */
23    char  * shortName;    /* short form */
24    int     has_arg;      /* 0 for no argument, 1 for argument */
25    char  * argName;      /* argument's description for tr_getopt_usage() */
26}
27tr_option;
28
29enum
30{
31    /* all options have been processed */
32    TR_OPT_DONE = 0,
33
34    /* a syntax error was detected, such as a missing
35     * argument for an option that requires one */
36    TR_OPT_ERR = -1,
37
38    /* an unknown option was reached */
39    TR_OPT_UNK = -2
40};
41
42/**
43 * @return TR_GETOPT_DONE, TR_GETOPT_ERR, TR_GETOPT_UNK,
44 *         or the matching tr_option's `value' field
45 */
46int tr_getopt( const char        * summary,
47               int                 argc,
48               const char       ** argv,
49               const tr_option   * opts,
50               const char       ** setme_optarg );
51
52void tr_getopt_usage( const char       * appName,
53                      const char       * description,
54                      const tr_option  * opts );
55
56#endif /* TR_GETOPT_H */
Note: See TracBrowser for help on using the repository browser.