Skip to content
This repository has been archived by the owner on Feb 2, 2024. It is now read-only.

Commit

Permalink
Allow to select a device by its index
Browse files Browse the repository at this point in the history
  • Loading branch information
jmaselbas committed Jan 6, 2024
1 parent 197a0b3 commit 3c0ab5f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions wch-isp.c
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,22 @@ dev_by_uid(const char *uid)
return NULL;
}

static struct isp_dev *
dev_by_index(const char *s)
{
char *e = NULL;
unsigned long i;

i = strtoul(s, &e, 0);
if (i == ULONG_MAX || (e != NULL && *e != '\0'))
return NULL;

if (i < dev_count)
return &dev_list[i];

return NULL;
}

static void
print_dev(struct isp_dev *dev)
{
Expand Down Expand Up @@ -973,6 +989,8 @@ main(int argc, char **argv)
dev = &dev_list[0];
if (do_match) {
dev = dev_by_uid(do_match);
if (!dev)
dev = dev_by_index(do_match);
if (!dev)
die("no device match for '%s'\n", do_match);
}
Expand Down

0 comments on commit 3c0ab5f

Please sign in to comment.