# getoptdata.h

Go to the documentation of this file.

    00001 /* $Id$ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    00008  */
    00009
    00012 #ifndef GETOPTDATA_H
    00013 #define GETOPTDATA_H
    00014
    00016 enum OptionDataFlags {
    00017   ODF_NO_VALUE,
    00018   ODF_HAS_VALUE,
    00019   ODF_OPTIONAL_VALUE,
    00020   ODF_END,
    00021 };
    00022
    00024 struct OptionData {
    00025   byte id;
    00026   char shortname;
    00027   uint16 flags;
    00028   const char *longname;
    00029 };
    00030
    00032 struct GetOptData {
    00033   char *opt;
    00034   int numleft;
    00035   char **argv;
    00036   const OptionData *options;
    00037   char *cont;
    00038
    00045   GetOptData(int argc, char **argv, const OptionData *options) :
    00046       opt(NULL),
    00047       numleft(argc),
    00048       argv(argv),
    00049       options(options),
    00050       cont(NULL)
    00051   {
    00052   }
    00053
    00054   int GetOpt();
    00055 };
    00056
    00064 #define GETOPT_GENERAL(id, shortname, longname, flags) { id, shortname, flags, longname }
    00065
    00071 #define GETOPT_NOVAL(shortname, longname) GETOPT_GENERAL(shortname, shortname, longname, ODF_NO_VALUE)
    00072
    00078 #define GETOPT_VALUE(shortname, longname) GETOPT_GENERAL(shortname, shortname, longname, ODF_HAS_VALUE)
    00079
    00086 #define GETOPT_OPTVAL(shortname, longname) GETOPT_GENERAL(shortname, shortname, longname, ODF_OPTIONAL_VALUE)
    00087
    00088
    00093 #define GETOPT_SHORT_NOVAL(shortname) GETOPT_NOVAL(shortname, NULL)
    00094
    00099 #define GETOPT_SHORT_VALUE(shortname) GETOPT_VALUE(shortname, NULL)
    00100
    00106 #define GETOPT_SHORT_OPTVAL(shortname) GETOPT_OPTVAL(shortname, NULL)
    00107
    00109 #define GETOPT_END() { '\0', '\0', ODF_END, NULL}
    00110
    00111
    00112 #endif /* GETOPTDATA_H */