Commit cf00b353 authored by Georg Neis's avatar Georg Neis Committed by Commit Bot

[cleanup] Give better name to a variable and remove bogus comment.

R=sigurds@chromium.org

Change-Id: Ieb73e6b573f2721e62b1c2bc216c26f8b9d38837
Reviewed-on: https://chromium-review.googlesource.com/1065970Reviewed-by: 's avatarSigurd Schneider <sigurds@chromium.org>
Commit-Queue: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53257}
parent 6d87fbc7
...@@ -312,18 +312,15 @@ inline char NormalizeChar(char ch) { ...@@ -312,18 +312,15 @@ inline char NormalizeChar(char ch) {
} }
// Helper function to parse flags: Takes an argument arg and splits it into // Helper function to parse flags: Takes an argument arg and splits it into
// a flag name and flag value (or nullptr if they are missing). is_bool is set // a flag name and flag value (or nullptr if they are missing). negated is set
// if the arg started with "-no" or "--no". The buffer may be used to NUL- // if the arg started with "-no" or "--no". The buffer may be used to NUL-
// terminate the name, it must be large enough to hold any possible name. // terminate the name, it must be large enough to hold any possible name.
static void SplitArgument(const char* arg, static void SplitArgument(const char* arg, char* buffer, int buffer_size,
char* buffer, const char** name, const char** value,
int buffer_size, bool* negated) {
const char** name,
const char** value,
bool* is_bool) {
*name = nullptr; *name = nullptr;
*value = nullptr; *value = nullptr;
*is_bool = false; *negated = false;
if (arg != nullptr && *arg == '-') { if (arg != nullptr && *arg == '-') {
// find the begin of the flag name // find the begin of the flag name
...@@ -339,7 +336,7 @@ static void SplitArgument(const char* arg, ...@@ -339,7 +336,7 @@ static void SplitArgument(const char* arg,
if (arg[0] == 'n' && arg[1] == 'o') { if (arg[0] == 'n' && arg[1] == 'o') {
arg += 2; // remove "no" arg += 2; // remove "no"
if (NormalizeChar(arg[0]) == '-') arg++; // remove dash after "no". if (NormalizeChar(arg[0]) == '-') arg++; // remove dash after "no".
*is_bool = true; *negated = true;
} }
*name = arg; *name = arg;
...@@ -416,8 +413,8 @@ int FlagList::SetFlagsFromCommandLine(int* argc, ...@@ -416,8 +413,8 @@ int FlagList::SetFlagsFromCommandLine(int* argc,
char buffer[1*KB]; char buffer[1*KB];
const char* name; const char* name;
const char* value; const char* value;
bool is_bool; bool negated;
SplitArgument(arg, buffer, sizeof buffer, &name, &value, &is_bool); SplitArgument(arg, buffer, sizeof buffer, &name, &value, &negated);
if (name != nullptr) { if (name != nullptr) {
// lookup the flag // lookup the flag
...@@ -457,10 +454,10 @@ int FlagList::SetFlagsFromCommandLine(int* argc, ...@@ -457,10 +454,10 @@ int FlagList::SetFlagsFromCommandLine(int* argc,
char* endp = const_cast<char*>(""); // *endp is only read char* endp = const_cast<char*>(""); // *endp is only read
switch (flag->type()) { switch (flag->type()) {
case Flag::TYPE_BOOL: case Flag::TYPE_BOOL:
*flag->bool_variable() = !is_bool; *flag->bool_variable() = !negated;
break; break;
case Flag::TYPE_MAYBE_BOOL: case Flag::TYPE_MAYBE_BOOL:
*flag->maybe_bool_variable() = MaybeBoolFlag::Create(true, !is_bool); *flag->maybe_bool_variable() = MaybeBoolFlag::Create(true, !negated);
break; break;
case Flag::TYPE_INT: case Flag::TYPE_INT:
*flag->int_variable() = static_cast<int>(strtol(value, &endp, 10)); *flag->int_variable() = static_cast<int>(strtol(value, &endp, 10));
...@@ -502,7 +499,7 @@ int FlagList::SetFlagsFromCommandLine(int* argc, ...@@ -502,7 +499,7 @@ int FlagList::SetFlagsFromCommandLine(int* argc,
// handle errors // handle errors
bool is_bool_type = flag->type() == Flag::TYPE_BOOL || bool is_bool_type = flag->type() == Flag::TYPE_BOOL ||
flag->type() == Flag::TYPE_MAYBE_BOOL; flag->type() == Flag::TYPE_MAYBE_BOOL;
if ((is_bool_type && value != nullptr) || (!is_bool_type && is_bool) || if ((is_bool_type && value != nullptr) || (!is_bool_type && negated) ||
*endp != '\0') { *endp != '\0') {
PrintF(stderr, "Error: illegal value for flag %s of type %s\n" PrintF(stderr, "Error: illegal value for flag %s of type %s\n"
"Try --help for options\n", "Try --help for options\n",
...@@ -537,7 +534,7 @@ int FlagList::SetFlagsFromCommandLine(int* argc, ...@@ -537,7 +534,7 @@ int FlagList::SetFlagsFromCommandLine(int* argc,
PrintHelp(); PrintHelp();
exit(0); exit(0);
} }
// parsed all flags successfully
return return_code; return return_code;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment