From 9d0ff9d69202fccc6414f7356faa1ab22c7a14b7 Mon Sep 17 00:00:00 2001 From: alberth Date: Fri, 18 Feb 2011 20:14:30 +0000 Subject: (svn r22096) -Codechange: Move openttd getopt implementation to its own file. --- projects/openttd_vs100.vcxproj | 2 + projects/openttd_vs100.vcxproj.filters | 6 +++ projects/openttd_vs80.vcproj | 8 ++++ projects/openttd_vs90.vcproj | 8 ++++ source.list | 2 + src/openttd.cpp | 72 ++-------------------------------- 6 files changed, 29 insertions(+), 69 deletions(-) diff --git a/projects/openttd_vs100.vcxproj b/projects/openttd_vs100.vcxproj index edfda1945..98a1be706 100644 --- a/projects/openttd_vs100.vcxproj +++ b/projects/openttd_vs100.vcxproj @@ -1022,6 +1022,8 @@ + + diff --git a/projects/openttd_vs100.vcxproj.filters b/projects/openttd_vs100.vcxproj.filters index 5e009c208..dece30451 100644 --- a/projects/openttd_vs100.vcxproj.filters +++ b/projects/openttd_vs100.vcxproj.filters @@ -2286,6 +2286,12 @@ Misc + + Misc + + + Misc + Misc diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj index 8b531142a..ca82ba786 100644 --- a/projects/openttd_vs80.vcproj +++ b/projects/openttd_vs80.vcproj @@ -3438,6 +3438,14 @@ RelativePath=".\..\src\misc\fixedsizearray.hpp" > + + + + diff --git a/projects/openttd_vs90.vcproj b/projects/openttd_vs90.vcproj index 4df272e64..634330007 100644 --- a/projects/openttd_vs90.vcproj +++ b/projects/openttd_vs90.vcproj @@ -3435,6 +3435,14 @@ RelativePath=".\..\src\misc\fixedsizearray.hpp" > + + + + diff --git a/source.list b/source.list index 3370af3cf..aa56688bd 100644 --- a/source.list +++ b/source.list @@ -815,6 +815,8 @@ misc/countedptr.hpp misc/dbg_helpers.cpp misc/dbg_helpers.h misc/fixedsizearray.hpp +misc/getoptdata.cpp +misc/getoptdata.h misc/hashtable.hpp misc/str.hpp diff --git a/src/openttd.cpp b/src/openttd.cpp index c0780241c..f331aab7a 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -59,6 +59,7 @@ #include "core/backup_type.hpp" #include "hotkeys.h" #include "newgrf.h" +#include "misc/getoptdata.h" #include "town.h" @@ -215,73 +216,6 @@ static void ShowHelp() } -struct MyGetOptData { - char *opt; - int numleft; - char **argv; - const char *options; - char *cont; - - MyGetOptData(int argc, char **argv, const char *options) - { - opt = NULL; - numleft = argc; - this->argv = argv; - this->options = options; - cont = NULL; - } -}; - -static int MyGetOpt(MyGetOptData *md) -{ - char *s = md->cont; - if (s != NULL) { - goto md_continue_here; - } - - for (;;) { - if (--md->numleft < 0) return -1; - - s = *md->argv++; - if (*s == '-') { -md_continue_here:; - s++; - if (*s != 0) { - const char *r; - /* Found argument, try to locate it in options. */ - if (*s == ':' || (r = strchr(md->options, *s)) == NULL) { - /* ERROR! */ - return -2; - } - if (r[1] == ':') { - char *t; - /* Item wants an argument. Check if the argument follows, or if it comes as a separate arg. */ - if (!*(t = s + 1)) { - /* It comes as a separate arg. Check if out of args? */ - if (--md->numleft < 0 || *(t = *md->argv) == '-') { - /* Check if item is optional? */ - if (r[2] != ':') return -2; - md->numleft++; - t = NULL; - } else { - md->argv++; - } - } - md->opt = t; - md->cont = NULL; - return *s; - } - md->opt = NULL; - md->cont = s; - return *s; - } - } else { - /* This is currently not supported. */ - return -2; - } - } -} - /** * Extract the resolution from the given string and store * it in the 'res' parameter. @@ -452,9 +386,9 @@ int ttd_main(int argc, char *argv[]) #endif ; - MyGetOptData mgo(argc - 1, argv + 1, optformat); + GetOptData mgo(argc - 1, argv + 1, optformat); - while ((i = MyGetOpt(&mgo)) != -1) { + while ((i = mgo.GetOpt()) != -1) { switch (i) { case 'I': free(graphics_set); graphics_set = strdup(mgo.opt); break; case 'S': free(sounds_set); sounds_set = strdup(mgo.opt); break; -- cgit v1.2.3-54-g00ecf