comparison 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
comparison
equal deleted inserted replaced
2078:b2f1ce24f81b 2079:9b6027d51f76
260 "\n" 260 "\n"
261 ); 261 );
262 } 262 }
263 263
264 264
265 /* Replace filename extension based on format pattern.
266 * Usage: res = dm_strdup_fext(orig_filename, "foo_%s.cmp");
267 */
268 char *dm_strdup_fext(const char *filename, const char *fmt)
269 {
270 char *result, *tmp, *fext;
271
272 if (filename == NULL ||
273 (tmp = dm_strdup(filename)) == NULL)
274 return NULL;
275
276 if ((fext = strrchr(tmp, '.')) != NULL)
277 {
278 char *fpath = strrchr(tmp, DM_DIR_SEPARATOR);
279 if (fpath == NULL || (fpath != NULL && fext > fpath))
280 *fext = 0;
281 }
282
283 result = dm_strdup_printf(fmt, tmp);
284
285 dmFree(tmp);
286
287 return result;
288 }
289
290
265 // 291 //
266 // Return a "matching" ANSI colour code for given C64 palette index. 292 // Return a "matching" ANSI colour code for given C64 palette index.
267 // As the standard 16 ANSI colours are not exact match and some C64 293 // As the standard 16 ANSI colours are not exact match and some C64
268 // colours cant be represented, this is an imperfect conversion. 294 // colours cant be represented, this is an imperfect conversion.
269 // 295 //