format: Add function to get format by name

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
diff --git a/src/formats.c b/src/formats.c
index 9e8da5e..8f51c2d 100644
--- a/src/formats.c
+++ b/src/formats.c
@@ -18,6 +18,7 @@
  */
 
 #include <stdio.h>	/* for NULL */
+#include <string.h>
 
 #include <gapk/formats.h>
 
@@ -49,3 +50,17 @@
 		return NULL;
 	return supported_formats[type];
 }
+
+const struct format_desc *
+fmt_get_from_name(const char *name)
+{
+	int i;
+	for (i=FMT_INVALID+1; i<_FMT_MAX; i++) {
+		const struct format_desc *fmt = supported_formats[i];
+		if (!fmt)
+			continue;
+		if (!strcmp(fmt->name, name))
+			return fmt;
+	}
+	return NULL;
+}