OpenTTD
getoptdata.h
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * 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.
4  * 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.
5  * 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/>.
6  */
7 
10 #ifndef GETOPTDATA_H
11 #define GETOPTDATA_H
12 
19 };
20 
22 struct OptionData {
23  byte id;
24  char shortname;
25  uint16 flags;
26  const char *longname;
27 };
28 
30 struct GetOptData {
31  char *opt;
32  int numleft;
33  char **argv;
35  char *cont;
36 
43  GetOptData(int argc, char **argv, const OptionData *options) :
44  opt(nullptr),
45  numleft(argc),
46  argv(argv),
47  options(options),
48  cont(nullptr)
49  {
50  }
51 
52  int GetOpt();
53 };
54 
62 #define GETOPT_GENERAL(id, shortname, longname, flags) { id, shortname, flags, longname }
63 
69 #define GETOPT_NOVAL(shortname, longname) GETOPT_GENERAL(shortname, shortname, longname, ODF_NO_VALUE)
70 
76 #define GETOPT_VALUE(shortname, longname) GETOPT_GENERAL(shortname, shortname, longname, ODF_HAS_VALUE)
77 
84 #define GETOPT_OPTVAL(shortname, longname) GETOPT_GENERAL(shortname, shortname, longname, ODF_OPTIONAL_VALUE)
85 
86 
91 #define GETOPT_SHORT_NOVAL(shortname) GETOPT_NOVAL(shortname, nullptr)
92 
97 #define GETOPT_SHORT_VALUE(shortname) GETOPT_VALUE(shortname, nullptr)
98 
104 #define GETOPT_SHORT_OPTVAL(shortname) GETOPT_OPTVAL(shortname, nullptr)
105 
107 #define GETOPT_END() { '\0', '\0', ODF_END, nullptr}
108 
109 
110 #endif /* GETOPTDATA_H */
A plain option (no value attached to it).
Definition: getoptdata.h:15
char ** argv
Remaining command line arguments.
Definition: getoptdata.h:33
const char * longname
Long option name including &#39;-&#39;/&#39;–&#39; prefix, use nullptr if not available.
Definition: getoptdata.h:26
Data of an option.
Definition: getoptdata.h:22
Terminator (data is not parsed further).
Definition: getoptdata.h:18
An option with an optional value.
Definition: getoptdata.h:17
const OptionData * options
Command line option descriptions.
Definition: getoptdata.h:34
char * opt
Option value, if available (else nullptr).
Definition: getoptdata.h:31
uint16 flags
Option data flags.
Definition: getoptdata.h:25
Data storage for parsing command line options.
Definition: getoptdata.h:30
char * cont
Next call to GetOpt should start here (in the middle of an argument).
Definition: getoptdata.h:35
OptionDataFlags
Flags of an option.
Definition: getoptdata.h:14
byte id
Unique identification of this option data, often the same as shortname.
Definition: getoptdata.h:23
GetOptData(int argc, char **argv, const OptionData *options)
Constructor of the data store.
Definition: getoptdata.h:43
char shortname
Short option letter if available, else use &#39;\0&#39;.
Definition: getoptdata.h:24
int numleft
Number of arguments left in argv.
Definition: getoptdata.h:32
An option with a value.
Definition: getoptdata.h:16