(svn r22101) -Codechange (r22098): Unify a bit of code.

This commit is contained in:
alberth 2011-02-18 20:51:05 +00:00
parent 8c2fc45153
commit 41a67a9b94

View File

@ -56,28 +56,21 @@ set_optval: // Handle option value of *odata .
return odata->id; return odata->id;
case ODF_HAS_VALUE: case ODF_HAS_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];
this->argv++;
this->numleft--;
return odata->id;
case ODF_OPTIONAL_VALUE: case ODF_OPTIONAL_VALUE:
if (this->cont != NULL) { // Remainder of the argument is the option value. if (this->cont != NULL) { // Remainder of the argument is the option value.
this->opt = this->cont; this->opt = this->cont;
this->cont = NULL; this->cont = NULL;
return odata->id; return odata->id;
} }
if (this->numleft > 0 && this->argv[0][0] != '-') { /* No more arguments, either return an error or a value-less option. */
this->opt = this->argv[0]; if (this->numleft == 0) return (odata->flags == ODF_HAS_VALUE) ? -2 : odata->id;
this->argv++;
this->numleft--; /* 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; return odata->id;
default: NOT_REACHED(); default: NOT_REACHED();