X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Finput%2Finput.c;h=a6de80e5195cc87952cfbd6567b5481eec4d7572;hb=485a285abea07fa296ee56517cf95b4dbab69e29;hp=3c7fd516a309ea7e05aff2da1b3c16a592355d6a;hpb=640982114329b28aaca3390913037eddd8c6d550;p=libsigrok.git diff --git a/src/input/input.c b/src/input/input.c index 3c7fd516..a6de80e5 100644 --- a/src/input/input.c +++ b/src/input/input.c @@ -17,16 +17,19 @@ * along with this program. If not, see . */ +#include #include #include #include #include #include #include -#include "libsigrok.h" +#include #include "libsigrok-internal.h" +/** @cond PRIVATE */ #define LOG_PREFIX "input" +/** @endcond */ /** * @file @@ -89,14 +92,14 @@ SR_API const struct sr_input_module **sr_input_list(void) * * @since 0.4.0 */ -SR_API const char *sr_input_id_get(const struct sr_input_module *o) +SR_API const char *sr_input_id_get(const struct sr_input_module *imod) { - if (!o) { + if (!imod) { sr_err("Invalid input module NULL!"); return NULL; } - return o->id; + return imod->id; } /** @@ -104,14 +107,14 @@ SR_API const char *sr_input_id_get(const struct sr_input_module *o) * * @since 0.4.0 */ -SR_API const char *sr_input_name_get(const struct sr_input_module *o) +SR_API const char *sr_input_name_get(const struct sr_input_module *imod) { - if (!o) { + if (!imod) { sr_err("Invalid input module NULL!"); return NULL; } - return o->name; + return imod->name; } /** @@ -119,14 +122,33 @@ SR_API const char *sr_input_name_get(const struct sr_input_module *o) * * @since 0.4.0 */ -SR_API const char *sr_input_description_get(const struct sr_input_module *o) +SR_API const char *sr_input_description_get(const struct sr_input_module *imod) { - if (!o) { + if (!imod) { sr_err("Invalid input module NULL!"); return NULL; } - return o->desc; + return imod->desc; +} + +/** + * Returns the specified input module's file extensions typical for the file + * format, as a NULL terminated array, or returns a NULL pointer if there is + * no preferred extension. + * @note these are a suggestions only. + * + * @since 0.4.0 + */ +SR_API const char *const *sr_input_extensions_get( + const struct sr_input_module *imod) +{ + if (!imod) { + sr_err("Invalid input module NULL!"); + return NULL; + } + + return imod->exts; } /** @@ -210,8 +232,9 @@ SR_API void sr_input_options_free(const struct sr_option **options) * This function is used when a client wants to use a specific input * module to parse a stream. No effort is made to identify the format. * + * @param imod The input module to use. Must not be NULL. * @param options GHashTable consisting of keys corresponding with - * the module options \c id field. The values should be GVariant + * the module options @c id field. The values should be GVariant * pointers with sunk references, of the same GVariantType as the option's * default value. * @@ -241,7 +264,8 @@ SR_API struct sr_input *sr_input_new(const struct sr_input_module *imod, /* Option not given: insert the default value. */ gvt = g_variant_get_type(mod_opts[i].def); if (!g_variant_is_of_type(value, gvt)) { - sr_err("Invalid type for '%s' option.", key); + sr_err("Invalid type for '%s' option.", + (char *)key); g_free(in); return NULL; } @@ -259,7 +283,8 @@ SR_API struct sr_input *sr_input_new(const struct sr_input_module *imod, g_hash_table_iter_init(&iter, options); while (g_hash_table_iter_next(&iter, &key, &value)) { if (!g_hash_table_lookup(new_opts, key)) { - sr_err("Input module '%s' has no option '%s'", imod->id, key); + sr_err("Input module '%s' has no option '%s'", + imod->id, (char *)key); g_hash_table_destroy(new_opts); g_free(in); return NULL; @@ -409,7 +434,7 @@ SR_API int sr_input_scan_file(const char *filename, const struct sr_input **in) } if (stat(filename, &st) < 0) { - sr_err("%s", strerror(errno)); + sr_err("%s", g_strerror(errno)); return SR_ERR_ARG; } @@ -449,7 +474,7 @@ SR_API int sr_input_scan_file(const char *filename, const struct sr_input **in) GINT_TO_POINTER(st.st_size)); } else if (mitem == SR_INPUT_META_HEADER) { if ((fd = open(filename, O_RDONLY)) < 0) { - sr_err("%s", strerror(errno)); + sr_err("%s", g_strerror(errno)); return SR_ERR; } size = read(fd, header_buf->str, 128); @@ -457,7 +482,7 @@ SR_API int sr_input_scan_file(const char *filename, const struct sr_input **in) close(fd); if (size <= 0) { g_string_free(header_buf, TRUE); - sr_err("%s", strerror(errno)); + sr_err("%s", g_strerror(errno)); return SR_ERR; } g_hash_table_insert(meta, GINT_TO_POINTER(mitem), header_buf); @@ -527,7 +552,8 @@ SR_API struct sr_dev_inst *sr_input_dev_inst_get(const struct sr_input *in) */ SR_API int sr_input_send(const struct sr_input *in, GString *buf) { - sr_spew("Sending %d bytes to %s module.", buf->len, in->module->id); + sr_spew("Sending %" G_GSIZE_FORMAT " bytes to %s module.", + buf->len, in->module->id); return in->module->receive((struct sr_input *)in, buf); } @@ -561,12 +587,12 @@ SR_API void sr_input_free(const struct sr_input *in) sr_dev_inst_free(in->sdi); if (in->buf->len > 64) { /* That seems more than just some sub-unitsize leftover... */ - sr_warn("Found %d unprocessed bytes at free time.", in->buf->len); + sr_warn("Found %" G_GSIZE_FORMAT + " unprocessed bytes at free time.", in->buf->len); } g_string_free(in->buf, TRUE); g_free(in->priv); g_free((gpointer)in); } - /** @} */