Skip to content

Commit 1172c7e

Browse files
committed
iio_attr: enable code gen for local contexts
Now that we have the uri in the context, we use it, which simplifies the codegen, and ensures that things work with both local and remote contexts. This fixes #529 Signed-off-by: Robin Getz <[email protected]>
1 parent 3f32d4e commit 1172c7e

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

tests/gen_code.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,11 @@ void gen_context (const char *uri_in)
163163
if (!fd)
164164
return;
165165

166-
uri = cmn_strndup(uri_in, NAME_MAX);
166+
if (uri_in)
167+
uri = cmn_strndup(uri_in, NAME_MAX);
168+
else
169+
uri = cmn_strndup("unknown:", NAME_MAX);
170+
167171
if (lang == C_LANG) {
168172
fprintf(fd, "\t/* Create IIO Context */\n"
169173
"\tIIO_ASSERT(ctx = iio_create_context_from_uri(\"%s\"));\n\n", uri);
@@ -289,7 +293,7 @@ void gen_function(const char* prefix, const char* target,
289293
prefix, rw, target, attr);
290294
fprintf(fd, "\t *******************************************************************/\n");
291295
if (wbuf) {
292-
fprintf(fd, "\tprintf(\"Wrote %%li bytes\\n\", ret);\n\n");
296+
fprintf(fd, "\tprintf(\"Wrote %%zi bytes\\n\", ret);\n\n");
293297
} else {
294298
fprintf(fd, "\tprintf(\"%s : %%s\\n\", buf);\n\n", attr);
295299
}

tests/iio_attr.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ int main(int argc, char **argv)
554554

555555
if (gen_code) {
556556
gen_start(gen_file);
557+
gen_context(iio_context_get_attr_value(ctx, "uri"));
557558
}
558559

559560
if (search_context) {

tests/iio_common.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ char *cmn_strndup(const char *str, size_t n)
7070
#endif
7171
}
7272

73-
74-
75-
struct iio_context * autodetect_context(bool rtn, bool gen_code, const char * name, const char * scan)
73+
struct iio_context * autodetect_context(bool rtn, const char * name, const char * scan)
7674
{
7775
struct iio_scan_context *scan_ctx;
7876
struct iio_context_info **info;
@@ -104,8 +102,6 @@ struct iio_context * autodetect_context(bool rtn, bool gen_code, const char * na
104102
printf("Using auto-detected IIO context at URI \"%s\"\n",
105103
iio_context_info_get_uri(info[0]));
106104
ctx = iio_create_context_from_uri(iio_context_info_get_uri(info[0]));
107-
if (gen_code)
108-
gen_context(iio_context_info_get_uri(info[0]));
109105
} else {
110106
if (rtn) {
111107
out = stderr;
@@ -285,10 +281,10 @@ struct iio_context * handle_common_opts(char * name, int argc, char * const argv
285281
opterr = 1;
286282

287283
if (do_scan) {
288-
autodetect_context(false, false, name, arg);
284+
autodetect_context(false, name, arg);
289285
exit(0);
290286
} else if (detect_context)
291-
ctx = autodetect_context(true, false, name, arg);
287+
ctx = autodetect_context(true, name, arg);
292288
else if (!arg && backend != IIO_LOCAL)
293289
fprintf(stderr, "argument parsing error\n");
294290
else if (backend == IIO_XML)

tests/iio_common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ enum backend {
4242
void * xmalloc(size_t n, const char *name);
4343
char *cmn_strndup(const char *str, size_t n);
4444

45-
struct iio_context * autodetect_context(bool rtn, bool gen_code, const char *name, const char *scan);
45+
struct iio_context * autodetect_context(bool rtn, const char *name, const char *scan);
4646
unsigned long int sanitize_clamp(const char *name, const char *argv,
4747
uint64_t min, uint64_t max);
4848

tests/iio_info.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ int main(int argc, char **argv)
9393
optind++;
9494
break;
9595
case 's':
96-
autodetect_context(false, false, MY_NAME, NULL);
96+
autodetect_context(false, MY_NAME, NULL);
9797
return EXIT_SUCCESS;
9898
case '?':
9999
printf("Unknown argument '%c'\n", c);

0 commit comments

Comments
 (0)