-/**
- * Return the input file format which the CLI tool should use.
- *
- * If the user specified -I / --input-format, use that one. Otherwise, try to
- * autodetect the format as good as possible. Failing that, return NULL.
- *
- * @param filename The filename of the input file. Must not be NULL.
- * @param opt The -I / --input-file option the user specified (or NULL).
- *
- * @return A pointer to the 'struct sr_input_format' that should be used,
- * or NULL if no input format was selected or auto-detected.
- */
-static struct sr_input_format *determine_input_file_format(
- const char *filename, const char *opt)
-{
- int i;
- struct sr_input_format **inputs;
-
- /* If there are no input formats, return NULL right away. */
- inputs = sr_input_list();
- if (!inputs) {
- g_critical("No supported input formats available.");
- return NULL;
- }
-
- /* If the user specified -I / --input-format, use that one. */
- if (opt) {
- for (i = 0; inputs[i]; i++) {
- if (strcasecmp(inputs[i]->id, opt))
- continue;
- g_debug("Using user-specified input file format '%s'.",
- inputs[i]->id);
- return inputs[i];
- }
-
- /* The user specified an unknown input format, return NULL. */
- g_critical("Error: specified input file format '%s' is "
- "unknown.", opt);
- return NULL;
- }
-
- /* Otherwise, try to find an input module that can handle this file. */
- for (i = 0; inputs[i]; i++) {
- if (inputs[i]->format_match(filename))
- break;
- }
-
- /* Return NULL if no input module wanted to touch this. */
- if (!inputs[i]) {
- g_critical("Error: no matching input module found.");
- return NULL;
- }
-
- g_debug("cli: Autodetected '%s' input format for file '%s'.",
- inputs[i]->id, filename);
-
- return inputs[i];
-}