aboutsummaryrefslogtreecommitdiff
path: root/misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc.c')
-rw-r--r--misc.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/misc.c b/misc.c
index 6b85533..f0c4abd 100644
--- a/misc.c
+++ b/misc.c
@@ -3,6 +3,7 @@
*/
#include <assert.h>
+#include <ctype.h>
#ifdef NO_TGMATH_H
# include <math.h>
#else
@@ -500,4 +501,34 @@ char *button2label(int button)
return NULL;
}
+char *make_prefs_path(const char *dir, const char *sep,
+ const game *game, const char *suffix)
+{
+ size_t dirlen = strlen(dir);
+ size_t seplen = strlen(sep);
+ size_t gamelen = strlen(game->name);
+ size_t suffixlen = strlen(suffix);
+ char *path, *p;
+ const char *q;
+
+ path = snewn(dirlen + seplen + gamelen + suffixlen + 1, char);
+ p = path;
+
+ memcpy(p, dir, dirlen);
+ p += dirlen;
+
+ memcpy(p, sep, seplen);
+ p += seplen;
+
+ for (q = game->name; *q; q++)
+ if (*q != ' ')
+ *p++ = tolower((unsigned char)*q);
+
+ memcpy(p, suffix, suffixlen);
+ p += suffixlen;
+
+ *p = '\0';
+ return path;
+}
+
/* vim: set shiftwidth=4 tabstop=8: */