Chromium Code Reviews| Index: utility/crossystem_main.c |
| diff --git a/utility/crossystem_main.c b/utility/crossystem_main.c |
| index 584de594106e03bf2497ac900a621e517effdf02..f29c9729f2aea59852c62535fa500cb78dbffe53 100644 |
| --- a/utility/crossystem_main.c |
| +++ b/utility/crossystem_main.c |
| @@ -70,8 +70,11 @@ void PrintHelp(const char *progname) { |
| " Prints the current value(s) of the parameter(s).\n" |
| " %s [param1=value1] [param2=value2 [...]]]\n" |
| " Sets the parameter(s) to the specified value(s).\n" |
| + " %s [param1?value1] [param2?value2 [...]]]\n" |
| + " Checks if the parameter(s) all contain the specified value(s).\n" |
| + "Stops at the first error." |
| "\n" |
| - "Valid parameters:\n", progname, progname, progname); |
| + "Valid parameters:\n", progname, progname, progname, progname); |
| for (p = sys_param_list; p->name; p++) |
| printf(" %-22s %s\n", p->name, p->desc); |
| } |
| @@ -109,6 +112,28 @@ int SetParam(const Param* p, const char* value) { |
| } |
| +/* Compares the parameter with the expected value. |
| + * |
| + * Returns 0 if success (match), non-zero if error (mismatch). */ |
| +int CheckParam(const Param* p, char* expect) { |
| + if (p->is_string) { |
| + char buf[256]; |
| + const char* v = VbGetSystemPropertyString(p->name, buf, sizeof(buf)); |
| + if (!v || 0 != strcmp(v, expect)) |
| + return 1; |
| + } else { |
| + char* e; |
| + int i = strtol(expect, &e, 0); |
|
Will Drewry
2011/03/11 02:47:17
nit: long != int, always.
this will likely throw
|
| + int v = VbGetSystemPropertyInt(p->name); |
| + if (!*expect || (e && *e)) |
| + return 1; |
| + if (v == -1 || i != v) |
|
gauravsh
2011/03/11 02:39:35
since you use yoda comparisons everywhere else, mi
|
| + return 1; |
| + } |
| + return 0; |
| +} |
| + |
| + |
| /* Print the specified parameter. |
| * |
| * Returns 0 if success, non-zero if error. */ |
| @@ -179,8 +204,10 @@ int main(int argc, char* argv[]) { |
| /* Otherwise, loop through params and get/set them */ |
| for (i = 1; i < argc && retval == 0; i++) { |
| - char* name = strtok(argv[i], "="); |
| - char* value = strtok(NULL, "="); |
| + int has_set = (NULL != strchr(argv[i], '=')); |
| + int has_expect = (NULL != strchr(argv[i], '?')); |
| + char* name = strtok(argv[i], "=?"); |
| + char* value = strtok(NULL, "=?"); |
| const Param* p = FindParam(name); |
| if (!p) { |
| fprintf(stderr, "Invalid parameter name: %s\n", name); |
| @@ -190,8 +217,10 @@ int main(int argc, char* argv[]) { |
| if (i > 1) |
| printf(" "); /* Output params space-delimited */ |
| - if (value) |
| + if (has_set) |
| retval = SetParam(p, value); |
| + else if (has_expect) |
|
Will Drewry
2011/03/11 02:47:17
Do you want a check for has_set && has_expect to b
|
| + retval = CheckParam(p, value); |
| else |
| retval = PrintParam(p); |
| } |