diff options
| author | 2021-03-19 00:06:18 +0100 | |
|---|---|---|
| committer | 2021-06-13 02:01:11 +0200 | |
| commit | c3e1048f25c5bca7cea5b05b480013d1b3a3d89b (patch) | |
| tree | d8d341927273906146ad6b5bcc2d9dcae6ee39ac | |
| parent | b99adcc228829d22fa81b928190c9de485fbb354 (diff) | |
| download | libirecovery-c3e1048f25c5bca7cea5b05b480013d1b3a3d89b.tar.gz libirecovery-c3e1048f25c5bca7cea5b05b480013d1b3a3d89b.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 { | |||
| 55 | kSendScript, | 55 | kSendScript, |
| 56 | kShowMode, | 56 | kShowMode, |
| 57 | kRebootToNormalMode, | 57 | kRebootToNormalMode, |
| 58 | kQueryInfo | 58 | kQueryInfo, |
| 59 | kListDevices | ||
| 59 | }; | 60 | }; |
| 60 | 61 | ||
| 61 | static unsigned int quit = 0; | 62 | static unsigned int quit = 0; |
| @@ -178,6 +179,18 @@ static void print_device_info(irecv_client_t client) | |||
| 178 | } | 179 | } |
| 179 | } | 180 | } |
| 180 | 181 | ||
| 182 | static void print_devices() { | ||
| 183 | struct irecv_device *devices = irecv_devices_get_all(); | ||
| 184 | struct irecv_device *device = NULL; | ||
| 185 | int i = 0; | ||
| 186 | |||
| 187 | for (i = 0; devices[i].product_type != NULL; i++) { | ||
| 188 | device = &devices[i]; | ||
| 189 | |||
| 190 | printf("%s %s 0x%02x 0x%04x %s\n", device->product_type, device->hardware_model, device->board_id, device->chip_id, device->display_name); | ||
| 191 | } | ||
| 192 | } | ||
| 193 | |||
| 181 | static void parse_command(irecv_client_t client, unsigned char* command, unsigned int size) { | 194 | static void parse_command(irecv_client_t client, unsigned char* command, unsigned int size) { |
| 182 | char* cmd = strdup((char*)command); | 195 | char* cmd = strdup((char*)command); |
| 183 | char* action = strtok(cmd, " "); | 196 | char* action = strtok(cmd, " "); |
| @@ -371,6 +384,7 @@ static void print_usage(int argc, char **argv) { | |||
| 371 | printf(" -e, --script FILE\texecutes recovery script from FILE\n"); | 384 | printf(" -e, --script FILE\texecutes recovery script from FILE\n"); |
| 372 | printf(" -s, --shell\t\tstart an interactive shell\n"); | 385 | printf(" -s, --shell\t\tstart an interactive shell\n"); |
| 373 | printf(" -q, --query\t\tquery device info\n"); | 386 | printf(" -q, --query\t\tquery device info\n"); |
| 387 | printf(" -a, --devices\t\tlist information for all known devices\n"); | ||
| 374 | printf(" -v, --verbose\t\tenable verbose output, repeat for higher verbosity\n"); | 388 | printf(" -v, --verbose\t\tenable verbose output, repeat for higher verbosity\n"); |
| 375 | printf(" -h, --help\t\tprints this usage information\n"); | 389 | printf(" -h, --help\t\tprints this usage information\n"); |
| 376 | printf(" -V, --version\t\tprints version information\n"); | 390 | printf(" -V, --version\t\tprints version information\n"); |
| @@ -391,6 +405,7 @@ int main(int argc, char* argv[]) { | |||
| 391 | { "script", required_argument, NULL, 'e' }, | 405 | { "script", required_argument, NULL, 'e' }, |
| 392 | { "shell", no_argument, NULL, 's' }, | 406 | { "shell", no_argument, NULL, 's' }, |
| 393 | { "query", no_argument, NULL, 'q' }, | 407 | { "query", no_argument, NULL, 'q' }, |
| 408 | { "devices", no_argument, NULL, 'a' }, | ||
| 394 | { "verbose", no_argument, NULL, 'v' }, | 409 | { "verbose", no_argument, NULL, 'v' }, |
| 395 | { "help", no_argument, NULL, 'h' }, | 410 | { "help", no_argument, NULL, 'h' }, |
| 396 | { "version", no_argument, NULL, 'V' }, | 411 | { "version", no_argument, NULL, 'V' }, |
| @@ -412,7 +427,7 @@ int main(int argc, char* argv[]) { | |||
| 412 | return 0; | 427 | return 0; |
| 413 | } | 428 | } |
| 414 | 429 | ||
| 415 | while ((opt = getopt_long(argc, argv, "i:vVhrsmnc:f:e:k:q", longopts, NULL)) > 0) { | 430 | while ((opt = getopt_long(argc, argv, "i:vVhrsmnc:f:e:k:qa", longopts, NULL)) > 0) { |
| 416 | switch (opt) { | 431 | switch (opt) { |
| 417 | case 'i': | 432 | case 'i': |
| 418 | if (optarg) { | 433 | if (optarg) { |
| @@ -476,6 +491,11 @@ int main(int argc, char* argv[]) { | |||
| 476 | action = kQueryInfo; | 491 | action = kQueryInfo; |
| 477 | break; | 492 | break; |
| 478 | 493 | ||
| 494 | case 'a': | ||
| 495 | action = kListDevices; | ||
| 496 | print_devices(); | ||
| 497 | return 0; | ||
| 498 | |||
| 479 | case 'V': | 499 | case 'V': |
| 480 | printf("%s %s\n", TOOL_NAME, PACKAGE_VERSION); | 500 | printf("%s %s\n", TOOL_NAME, PACKAGE_VERSION); |
| 481 | return 0; | 501 | return 0; |
