ltunify: alias args to avoid constructs like (*args)[0]

(*args)[0] is not very obvious, introduce a new variable to avoid one
indirection.
This commit is contained in:
Peter Wu
2013-04-25 22:56:35 +02:00
parent 2cc2f450de
commit ab928522b1

View File

@@ -878,16 +878,17 @@ static void print_usage(const char *program_name) {
// Return number of commands and command arguments, -1 on error. If the program // Return number of commands and command arguments, -1 on error. If the program
// should not run (--help), then 0 is returned and args is NULL. // should not run (--help), then 0 is returned and args is NULL.
static int validate_args(int argc, char **argv, char ***args, char **hidraw_path) { static int validate_args(int argc, char **argv, char ***argsp, char **hidraw_path) {
int args_count; int args_count;
char *cmd; char *cmd;
int opt; int opt;
char **args;
struct option longopts[] = { struct option longopts[] = {
{ "device", 1, NULL, 'd' }, { "device", 1, NULL, 'd' },
{ "help", 0, NULL, 'h' }, { "help", 0, NULL, 'h' },
}; };
*args = NULL; *argsp = NULL;
while ((opt = getopt_long(argc, argv, "+Dd:h", longopts, NULL)) != -1) { while ((opt = getopt_long(argc, argv, "+Dd:h", longopts, NULL)) != -1) {
switch (opt) { switch (opt) {
@@ -910,17 +911,17 @@ static int validate_args(int argc, char **argv, char ***args, char **hidraw_path
print_usage(*argv); print_usage(*argv);
return -1; return -1;
} }
*args = &argv[optind]; *argsp = args = &argv[optind];
args_count = argc - optind - 1; args_count = argc - optind - 1;
cmd = (*args)[0]; cmd = args[0];
if (!strcmp(cmd, "list") || !strcmp(cmd, "receiver-info")) { if (!strcmp(cmd, "list") || !strcmp(cmd, "receiver-info")) {
/* nothing to check */ /* nothing to check */
} else if (!strcmp(cmd, "pair")) { } else if (!strcmp(cmd, "pair")) {
if (args_count >= 1) { if (args_count >= 1) {
char *end; char *end;
unsigned long int n; unsigned long int n;
n = strtoul((*args)[1], &end, 0); n = strtoul(args[1], &end, 0);
if (*end != '\0' || n > 0xFF) { if (*end != '\0' || n > 0xFF) {
fprintf(stderr, "Timeout must be a number between 0 and 255\n"); fprintf(stderr, "Timeout must be a number between 0 and 255\n");
return -1; return -1;
@@ -933,9 +934,9 @@ static int validate_args(int argc, char **argv, char ***args, char **hidraw_path
fprintf(stderr, "%s requires a device index\n", cmd); fprintf(stderr, "%s requires a device index\n", cmd);
return -1; return -1;
} }
device_index = strtoul((*args)[1], &end, 0); device_index = strtoul(args[1], &end, 0);
if (*end != '\0') { if (*end != '\0') {
if (device_type_from_str((*args)[1]) == -1) { if (device_type_from_str(args[1]) == -1) {
fprintf(stderr, "Invalid device type. Valid types are:\n"); fprintf(stderr, "Invalid device type. Valid types are:\n");
print_device_types(); print_device_types();
return -1; return -1;