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

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

(trunk) update the GPL code's copyright dates

File size: 2.4 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
28extern int tr_optind;
29
30typedef struct tr_option
31{
32    int     val;          /* the value to return from tr_getopt() */
33    char *  longName;     /* --long-form */
34    char *  description;  /* option's description for tr_getopt_usage() */
35    char *  shortName;    /* short form */
36    int     has_arg;      /* 0 for no argument, 1 for argument */
37    char *  argName;      /* argument's description for tr_getopt_usage() */
38}
39tr_option;
40
41enum
42{
43    /* all options have been processed */
44    TR_OPT_DONE = 0,
45
46    /* a syntax error was detected, such as a missing
47     * argument for an option that requires one */
48    TR_OPT_ERR = -1,
49
50    /* an unknown option was reached */
51    TR_OPT_UNK = -2
52};
53
54/**
55 * @return TR_GETOPT_DONE, TR_GETOPT_ERR, TR_GETOPT_UNK,
56 *         or the matching tr_option's `val' field
57 */
58int  tr_getopt( const char *      summary,
59                int               argc,
60                const char **     argv,
61                const tr_option * opts,
62                const char **     setme_optarg );
63
64void tr_getopt_usage( const char *      appName,
65                      const char *      description,
66                      const tr_option * opts );
67
68#endif /* TR_GETOPT_H */
Note: See TracBrowser for help on using the repository browser.