diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2009-02-25 13:17:38 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2009-02-26 14:15:38 +1000 |
commit | 4e9689aa5fdae4b7bd81f416e475ebf92b7302e1 (patch) | |
tree | b45973f96ea740bb3e14e9008be731fbf4e4dd71 /tools/synclient.c | |
parent | e446f82cdd6ee01d4f1086add3e7a38541bbb93b (diff) |
synclient: split shm_set_value into a parse_cmd.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Christoph Brill <egore911@egore911.de>
Diffstat (limited to 'tools/synclient.c')
-rw-r--r-- | tools/synclient.c | 91 |
1 files changed, 54 insertions, 37 deletions
diff --git a/tools/synclient.c b/tools/synclient.c index 7e33a80..d0cc3c7 100644 --- a/tools/synclient.c +++ b/tools/synclient.c @@ -165,48 +165,65 @@ shm_show_settings(SynapticsSHM *synshm) } } +static double +parse_cmd(char* cmd, struct Parameter** par) +{ + char *eqp = index(cmd, '='); + *par = NULL; + + if (eqp) { + int j; + int found = 0; + *eqp = 0; + for (j = 0; params[j].name; j++) { + if (strcasecmp(cmd, params[j].name) == 0) { + found = 1; + break; + } + } + if (found) { + double val = atof(&eqp[1]); + *par = ¶ms[j]; + + if (val < (*par)->min_val) + val = (*par)->min_val; + if (val > (*par)->max_val) + val = (*par)->max_val; + + return val; + } else { + printf("Unknown parameter %s\n", cmd); + } + } else { + printf("Invalid command: %s\n", cmd); + } + + return 0; +} + static void shm_set_variables(SynapticsSHM *synshm, int argc, char *argv[], int first_cmd) { int i; + struct Parameter *par; + double val; + for (i = first_cmd; i < argc; i++) { - char *cmd = argv[i]; - char *eqp = index(cmd, '='); - if (eqp) { - int j; - int found = 0; - *eqp = 0; - for (j = 0; params[j].name; j++) { - if (strcasecmp(cmd, params[j].name) == 0) { - found = 1; - break; - } - } - if (found) { - double val = atof(&eqp[1]); - struct Parameter* par = ¶ms[j]; - - if (val < par->min_val) - val = par->min_val; - if (val > par->max_val) - val = par->max_val; - - switch (par->type) { - case PT_INT: - *(int*)((char*)synshm + par->offset) = (int)rint(val); - break; - case PT_BOOL: - *(Bool*)((char*)synshm + par->offset) = (Bool)rint(val); - break; - case PT_DOUBLE: - *(double*)((char*)synshm + par->offset) = val; - break; - } - } else { - printf("Unknown parameter %s\n", cmd); - } - } else { - printf("Invalid command: %s\n", cmd); + val = parse_cmd(argv[i], &par); + + if (!par) + continue; + + switch (par->type) { + case PT_INT: + *(int*)((char*)synshm + par->offset) = (int)rint(val); + break; + case PT_BOOL: + *(Bool*)((char*)synshm + par->offset) = (Bool)rint(val); + break; + case PT_DOUBLE: + *(double*)((char*)synshm + par->offset) = val; + break; } } } |