OpenTTD
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 
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;
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 */
A plain option (no value attached to it).
Definition: getoptdata.h:17
char ** argv
Remaining command line arguments.
Definition: getoptdata.h:35
const char * longname
Long option name including &#39;-&#39;/&#39;–&#39; prefix, use NULL if not available.
Definition: getoptdata.h:28
Data of an option.
Definition: getoptdata.h:24
Terminator (data is not parsed further).
Definition: getoptdata.h:20
An option with an optional value.
Definition: getoptdata.h:19
const OptionData * options
Command line option descriptions.
Definition: getoptdata.h:36
char * opt
Option value, if available (else NULL).
Definition: getoptdata.h:33
uint16 flags
Option data flags.
Definition: getoptdata.h:27
Data storage for parsing command line options.
Definition: getoptdata.h:32
char * cont
Next call to #MyGetOpt should start here (in the middle of an argument).
Definition: getoptdata.h:37
OptionDataFlags
Flags of an option.
Definition: getoptdata.h:16
byte id
Unique identification of this option data, often the same as shortname.
Definition: getoptdata.h:25
GetOptData(int argc, char **argv, const OptionData *options)
Constructor of the data store.
Definition: getoptdata.h:45
char shortname
Short option letter if available, else use &#39;\0&#39;.
Definition: getoptdata.h:26
int numleft
Number of arguments left in argv.
Definition: getoptdata.h:34
An option with a value.
Definition: getoptdata.h:18