From 54fef8e0939a21d447388c2be6fd1851906ed1d3 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Sun, 18 Mar 2018 10:43:14 +0100 Subject: [PATCH] Add support for using an optional device descriptor The device descriptor is either mandatory for a certain command (with DCTOOL_CONFIG_DESCRIPTOR) or always NULL. But for some commands it will be useful to support an optional descriptor as well. To support this, we always try to lookup the device descriptor whenever the corresponding command-line options are set. --- examples/dctool.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/examples/dctool.c b/examples/dctool.c index f62b13c..52eb67b 100644 --- a/examples/dctool.c +++ b/examples/dctool.c @@ -275,14 +275,7 @@ main (int argc, char *argv[]) dc_context_set_loglevel (context, loglevel); dc_context_set_logfunc (context, logfunc, NULL); - if (command->config & DCTOOL_CONFIG_DESCRIPTOR) { - // Check mandatory arguments. - if (device == NULL && family == DC_FAMILY_NULL) { - message ("No device name or family type specified.\n"); - exitcode = EXIT_FAILURE; - goto cleanup; - } - + if (device != NULL || family != DC_FAMILY_NULL) { // Search for a matching device descriptor. status = dctool_descriptor_search (&descriptor, device, family, model); if (status != DC_STATUS_SUCCESS) { @@ -304,6 +297,13 @@ main (int argc, char *argv[]) } } + // Check mandatory descriptor arguments. + if (command->config & DCTOOL_CONFIG_DESCRIPTOR && descriptor == NULL) { + message ("No device name or family type specified.\n"); + exitcode = EXIT_FAILURE; + goto cleanup; + } + // Execute the command. exitcode = command->run (argc, argv, context, descriptor);