- if (fmtargs)
- g_hash_table_remove(fmtargs, "sigrok_key");
-
- if (stat(opt_input_file, &st) == -1) {
- g_critical("Failed to load %s: %s", opt_input_file,
- strerror(errno));
- exit(1);
+ buf = g_string_sized_new(BUFSIZE);
+ if (mod_id) {
+ /* User specified an input module to use. */
+ if (!(imod = sr_input_find(mod_id)))
+ g_critical("Error: unknown input module '%s'.", mod_id);
+ g_hash_table_remove(mod_args, "sigrok_key");
+ if ((options = sr_input_options_get(imod))) {
+ mod_opts = generic_arg_to_opt(options, mod_args);
+ sr_output_options_free(options);
+ } else
+ mod_opts = NULL;
+ if (!(in = sr_input_new(imod, mod_opts)))
+ g_critical("Error: failed to initialize input module.");
+ if (mod_opts)
+ g_hash_table_destroy(mod_opts);
+ if (mod_args)
+ g_hash_table_destroy(mod_args);
+ if ((fd = open(opt_input_file, O_RDONLY)) == -1)
+ g_critical("Failed to load %s: %s.", opt_input_file,
+ strerror(errno));
+ } else {
+ /* Let the input modules try to identify the file. */
+ if ((fd = open(opt_input_file, O_RDONLY)) == -1)
+ g_critical("Failed to load %s: %s.", opt_input_file,
+ strerror(errno));
+ if ((len = read(fd, buf->str, BUFSIZE)) < 1)
+ g_critical("Failed to read %s: %s.", opt_input_file,
+ strerror(errno));
+ buf->len = len;
+ if (!(in = sr_input_scan_buffer(buf)))
+ g_critical("Error: no input module found for this file.");