OpenTTD: src/misc/getoptdata.h Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

getoptdata.h
Go to the documentation of this file.
1 /* $Id: getoptdata.h 23245 2011-11-17 21:18:24Z rubidium $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
9
12 #ifndef GETOPTDATA_H
13 #define GETOPTDATA_H
14
16 enum OptionDataFlags {
17 ODF_NO_VALUE,
18 ODF_HAS_VALUE,
19 ODF_OPTIONAL_VALUE,
20 ODF_END,
21 };
22
24 struct OptionData {
25 byte id;
26 char shortname;
27 uint16 flags;
28 const char *longname;
29 };
30
32 struct GetOptData {
33 char *opt;
34 int numleft;
35 char **argv;
36 const OptionData *options;
37 char *cont;
38
45 GetOptData(int argc, char **argv, const OptionData *options) :
46 opt(NULL),
47 numleft(argc),
48 argv(argv),
49 options(options),
50 cont(NULL)
51 {
52 }
53
54 int GetOpt();
55 };
56
64 #define GETOPT_GENERAL(id, shortname, longname, flags) { id, shortname, flags, longname }
65
71 #define GETOPT_NOVAL(shortname, longname) GETOPT_GENERAL(shortname, shortname, longname, ODF_NO_VALUE)
72
78 #define GETOPT_VALUE(shortname, longname) GETOPT_GENERAL(shortname, shortname, longname, ODF_HAS_VALUE)
79
86 #define GETOPT_OPTVAL(shortname, longname) GETOPT_GENERAL(shortname, shortname, longname, ODF_OPTIONAL_VALUE)
87
88
93 #define GETOPT_SHORT_NOVAL(shortname) GETOPT_NOVAL(shortname, NULL)
94
99 #define GETOPT_SHORT_VALUE(shortname) GETOPT_VALUE(shortname, NULL)
100
106 #define GETOPT_SHORT_OPTVAL(shortname) GETOPT_OPTVAL(shortname, NULL)
107
109 #define GETOPT_END() { '\0', '\0', ODF_END, NULL}
110
111
112 #endif /* GETOPTDATA_H */