diff options
author | Martin Szulecki | 2021-03-19 00:06:18 +0100 |
---|---|---|
committer | Martin Szulecki | 2021-06-05 17:15:57 +0200 |
commit | 8fafdc3a17477e2c2fd48fa233c014300f70574c (patch) | |
tree | 326c6e5f79623497a416de95d4b0d5d5323cace3 | |
parent | 47934949e0015165a4562b08e824adb3f664c0ea (diff) | |
download | libirecovery-8fafdc3a17477e2c2fd48fa233c014300f70574c.tar.gz libirecovery-8fafdc3a17477e2c2fd48fa233c014300f70574c.tar.bz2 |
irecovery: Add new "--devices" option to list internal device data
Let's get rid of all the copy/paste out there...
-rw-r--r-- | tools/irecovery.c | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/tools/irecovery.c b/tools/irecovery.c index 5cc454a..244f961 100644 --- a/tools/irecovery.c +++ b/tools/irecovery.c @@ -55,7 +55,8 @@ enum { kSendScript, kShowMode, kRebootToNormalMode, - kQueryInfo + kQueryInfo, + kListDevices }; static unsigned int quit = 0; @@ -178,6 +179,18 @@ static void print_device_info(irecv_client_t client) } } +static void print_devices() { + struct irecv_device *devices = irecv_devices_get_all(); + struct irecv_device *device = NULL; + int i = 0; + + for (i = 0; devices[i].product_type != NULL; i++) { + device = &devices[i]; + + printf("%s %s 0x%02x 0x%04x %s\n", device->product_type, device->hardware_model, device->board_id, device->chip_id, device->display_name); + } +} + static void parse_command(irecv_client_t client, unsigned char* command, unsigned int size) { char* cmd = strdup((char*)command); char* action = strtok(cmd, " "); @@ -371,6 +384,7 @@ static void print_usage(int argc, char **argv) { printf(" -e, --script FILE\texecutes recovery script from FILE\n"); printf(" -s, --shell\t\tstart an interactive shell\n"); printf(" -q, --query\t\tquery device info\n"); + printf(" -a, --devices\t\tlist information for all known devices\n"); printf(" -v, --verbose\t\tenable verbose output, repeat for higher verbosity\n"); printf(" -h, --help\t\tprints this usage information\n"); printf(" -V, --version\t\tprints version information\n"); @@ -391,6 +405,7 @@ int main(int argc, char* argv[]) { { "script", required_argument, NULL, 'e' }, { "shell", no_argument, NULL, 's' }, { "query", no_argument, NULL, 'q' }, + { "devices", no_argument, NULL, 'a' }, { "verbose", no_argument, NULL, 'v' }, { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'V' }, @@ -412,7 +427,7 @@ int main(int argc, char* argv[]) { return 0; } - while ((opt = getopt_long(argc, argv, "i:vVhrsmnc:f:e:k:q", longopts, NULL)) > 0) { + while ((opt = getopt_long(argc, argv, "i:vVhrsmnc:f:e:k:qa", longopts, NULL)) > 0) { switch (opt) { case 'i': if (optarg) { @@ -476,6 +491,11 @@ int main(int argc, char* argv[]) { action = kQueryInfo; break; + case 'a': + action = kListDevices; + print_devices(); + return 0; + case 'V': printf("%s %s\n", TOOL_NAME, PACKAGE_VERSION); return 0; |