Skip to content

Commit

Permalink
iio_utils: tweak context creation to split things better
Browse files Browse the repository at this point in the history
this allows better reporting and error codes.

Signed-off-by: Robin Getz <[email protected]>
  • Loading branch information
rgetz committed Jun 5, 2020
1 parent 0904524 commit beda517
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions tests/iio_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -307,14 +307,15 @@ struct iio_context * handle_common_opts(char * name, int argc,
fprintf(stderr, "uri options requires a uri\n");
return NULL;
}
backend = IIO_AUTO;
backend = IIO_URI;
arg = optarg;
break;
case 'a':
if (backend != IIO_LOCAL) {
fprintf(stderr, "-a, -x, -n and -u are mutually exclusive\n");
return NULL;
}
backend = IIO_AUTO;
detect_context = true;
if (optarg) {
arg = optarg;
Expand Down Expand Up @@ -343,15 +344,15 @@ struct iio_context * handle_common_opts(char * name, int argc,
if (do_scan) {
autodetect_context(false, name, arg);
return NULL;
} else if (detect_context)
} else if (detect_context || backend == IIO_AUTO)
ctx = autodetect_context(true, name, arg);
else if (!arg && backend != IIO_LOCAL)
fprintf(stderr, "argument parsing error\n");
else if (backend == IIO_XML)
ctx = iio_create_xml_context(arg);
else if (backend == IIO_NETWORK)
ctx = iio_create_network_context(arg);
else if (backend == IIO_AUTO)
else if (backend == IIO_URI)
ctx = iio_create_context_from_uri(arg);
else
ctx = iio_create_default_context();
Expand Down
3 changes: 2 additions & 1 deletion tests/iio_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ enum backend {
IIO_XML,
IIO_NETWORK,
IIO_USB,
IIO_AUTO
IIO_URI,
IIO_AUTO,
};

void * xmalloc(size_t n, const char *name);
Expand Down

0 comments on commit beda517

Please sign in to comment.