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

Last change on this file since 8071 was 8071, checked in by charles, 13 years ago

(trunk libT) make tr-getopt C++ friendly

File size: 2.5 KB
Line 
1/*
2 * This file Copyright (C) 2008-2009 Charles Kerr <charles@transmissionbt.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 * DEALINGS IN THE SOFTWARE.
21 *
22 * $Id:$
23 */
24
25#ifndef TR_GETOPT_H
26#define TR_GETOPT_H
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32extern int tr_optind;
33
34typedef struct tr_option
35{
36    int           val;          /* the value to return from tr_getopt() */
37    const char *  longName;     /* --long-form */
38    const char *  description;  /* option's description for tr_getopt_usage() */
39    const char *  shortName;    /* short form */
40    int           has_arg;      /* 0 for no argument, 1 for argument */
41    const char *  argName;      /* argument's description for tr_getopt_usage() */
42}
43tr_option;
44
45enum
46{
47    /* all options have been processed */
48    TR_OPT_DONE = 0,
49
50    /* a syntax error was detected, such as a missing
51     * argument for an option that requires one */
52    TR_OPT_ERR = -1,
53
54    /* an unknown option was reached */
55    TR_OPT_UNK = -2
56};
57
58/**
59 * @return TR_GETOPT_DONE, TR_GETOPT_ERR, TR_GETOPT_UNK,
60 *         or the matching tr_option's `val' field
61 */
62int  tr_getopt( const char *      summary,
63                int               argc,
64                const char **     argv,
65                const tr_option * opts,
66                const char **     setme_optarg );
67
68void tr_getopt_usage( const char *      appName,
69                      const char *      description,
70                      const tr_option * opts );
71
72#ifdef __cplusplus
73} /* extern "C" */
74#endif
75
76#endif /* TR_GETOPT_H */
Note: See TracBrowser for help on using the repository browser.