summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2011-02-18 20:51:05 +0000
committeralberth <alberth@openttd.org>2011-02-18 20:51:05 +0000
commit41a67a9b94a6bb17d7160c67e05aea01e3bb08a7 (patch)
treec94f8f76a1f5d2a2a920c16d1e522f0dab641ee9
parent8c2fc4515355b4bf89d8427694361851b54708da (diff)
downloadopenttd-41a67a9b94a6bb17d7160c67e05aea01e3bb08a7.tar.xz
(svn r22101) -Codechange (r22098): Unify a bit of code.
-rw-r--r--src/misc/getoptdata.cpp23
1 files changed, 8 insertions, 15 deletions
diff --git a/src/misc/getoptdata.cpp b/src/misc/getoptdata.cpp
index 818e90c17..6ca9a1bfc 100644
--- a/src/misc/getoptdata.cpp
+++ b/src/misc/getoptdata.cpp
@@ -56,30 +56,23 @@ set_optval: // Handle option value of *odata .
return odata->id;
case ODF_HAS_VALUE:
+ case ODF_OPTIONAL_VALUE:
if (this->cont != NULL) { // Remainder of the argument is the option value.
this->opt = this->cont;
this->cont = NULL;
return odata->id;
}
- if (this->numleft == 0) return -2; // Missing the option value.
- this->opt = this->argv[0];
+ /* No more arguments, either return an error or a value-less option. */
+ if (this->numleft == 0) return (odata->flags == ODF_HAS_VALUE) ? -2 : odata->id;
+
+ /* Next argument looks like another option, let's not return it as option value. */
+ if (odata->flags == ODF_OPTIONAL_VALUE && this->argv[0][0] == '-') return odata->id;
+
+ this->opt = this->argv[0]; // Next argument is the option value.
this->argv++;
this->numleft--;
return odata->id;
- case ODF_OPTIONAL_VALUE:
- if (this->cont != NULL) { // Remainder of the argument is the option value.
- this->opt = this->cont;
- this->cont = NULL;
- return odata->id;
- }
- if (this->numleft > 0 && this->argv[0][0] != '-') {
- this->opt = this->argv[0];
- this->argv++;
- this->numleft--;
- }
- return odata->id;
-
default: NOT_REACHED();
}
}