diff tools/gfxconv.c @ 2079:9b6027d51f76

Move dm_strdup_fext() and dm_basefilename() to gfxconv, as they are only used there.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 10 Dec 2018 19:24:45 +0200
parents 838ed06b3927
children 4276b8c0fef0
line wrap: on
line diff
--- a/tools/gfxconv.c	Mon Dec 10 15:41:58 2018 +0200
+++ b/tools/gfxconv.c	Mon Dec 10 19:24:45 2018 +0200
@@ -262,6 +262,32 @@
 }
 
 
+/* Replace filename extension based on format pattern.
+ * Usage: res = dm_strdup_fext(orig_filename, "foo_%s.cmp");
+ */
+char *dm_strdup_fext(const char *filename, const char *fmt)
+{
+    char *result, *tmp, *fext;
+
+    if (filename == NULL ||
+        (tmp = dm_strdup(filename)) == NULL)
+        return NULL;
+
+    if ((fext = strrchr(tmp, '.')) != NULL)
+    {
+        char *fpath = strrchr(tmp, DM_DIR_SEPARATOR);
+        if (fpath == NULL || (fpath != NULL && fext > fpath))
+            *fext = 0;
+    }
+
+    result = dm_strdup_printf(fmt, tmp);
+
+    dmFree(tmp);
+
+    return result;
+}
+
+
 //
 // Return a "matching" ANSI colour code for given C64 palette index.
 // As the standard 16 ANSI colours are not exact match and some C64