summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2012-03-10 02:26:51 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2012-03-10 02:29:39 (GMT)
commit47b2164019c7e7a89cdcfc294313118214c10492 (patch)
tree13cb61296d2c83e4031406570ce13cdb31da4d1c
parent7fb6ab0a73c36a9d79f7607652b4194e389a70a0 (diff)
downloadgrv-47b2164019c7e7a89cdcfc294313118214c10492.zip
grv-47b2164019c7e7a89cdcfc294313118214c10492.tar.gz
grv-47b2164019c7e7a89cdcfc294313118214c10492.tar.bz2
grv-47b2164019c7e7a89cdcfc294313118214c10492.tar.xz
Move system-specific directory setting to a separate file
Move setting up a separate directory to a separate file; we could add support for Win32 to this file too.
-rw-r--r--Makefile3
-rw-r--r--Makefile.darwinx4
-rw-r--r--Makefile.w323
-rw-r--r--grv.c19
-rw-r--r--grv.h3
-rw-r--r--homedir.c29
6 files changed, 40 insertions, 21 deletions
diff --git a/Makefile b/Makefile
index e24de2f..b5dcc53 100644
--- a/Makefile
+++ b/Makefile
@@ -12,7 +12,8 @@ ALL = grv grvscored
OBJS = grv.o drawlevel.o play.o action.o bullets.o mystery.o \
prefs.o intro.o \
utils.o scoretbl.o highscore.o \
- netopen.o keyboard.o graphics.o grvfont.o random.o
+ netopen.o keyboard.o graphics.o grvfont.o random.o \
+ homedir.o
SCORED = grvscored.o scoretbl.o
diff --git a/Makefile.darwinx b/Makefile.darwinx
index 6b6ae8f..6891b91 100644
--- a/Makefile.darwinx
+++ b/Makefile.darwinx
@@ -26,7 +26,9 @@ APP = Grv.app
OBJS = grv.o drawlevel.o play.o action.o bullets.o mystery.o \
prefs.o intro.o \
utils.o scoretbl.o highscore.o \
- netopen.o keyboard.o graphics.o grvfont.o random.o SDLMain.o
+ netopen.o keyboard.o graphics.o grvfont.o random.o \
+ homedir.o \
+ SDLMain.o
SCORED = grvscored.o scoretbl.o
diff --git a/Makefile.w32 b/Makefile.w32
index ae9b810..9a80353 100644
--- a/Makefile.w32
+++ b/Makefile.w32
@@ -32,7 +32,8 @@ ALL = grv$(X)
OBJS = grv.o drawlevel.o play.o action.o bullets.o mystery.o \
prefs.o intro.o \
utils.o scoretbl.o highscore.o \
- netopen.o keyboard.o graphics.o grvfont.o random.o
+ netopen.o keyboard.o graphics.o grvfont.o random.o \
+ homedir.o
SCORED = grvscored.o scoretbl.o
diff --git a/grv.c b/grv.c
index 9e3bdc9..6ef8289 100644
--- a/grv.c
+++ b/grv.c
@@ -172,24 +172,7 @@ int main(int argc, char *argv[])
opt.debug = 1;
}
- /* On Unix, save stuff in a ~/.grv directory */
-#ifdef __unix__
- {
- char *home = getenv("HOME");
- char *grvd = getenv("GRV_DIR");
-
- if ( !grvd ) {
- grvd = alloca(strlen(home)+6);
- if ( grvd ) {
- sprintf(grvd, "%s/.grv", home);
- mkdir(grvd, 0777); /* Make .grv directory if missing */
- }
- }
-
- if ( grvd )
- chdir(grvd); /* Change to .grv directory */
- }
-#endif
+ goto_grv_dir();
/* Init the highscore data structures */
/* This is done here because it's a destructive operation and must
diff --git a/grv.h b/grv.h
index 1b64ee2..59272ea 100644
--- a/grv.h
+++ b/grv.h
@@ -190,4 +190,7 @@ void intro(void);
void load_prefs(void);
void set_keys(void);
+/* homedir.c */
+void goto_grv_dir(void);
+
#endif /* GRV_H */
diff --git a/homedir.c b/homedir.c
new file mode 100644
index 0000000..89766d6
--- /dev/null
+++ b/homedir.c
@@ -0,0 +1,29 @@
+#include "grv.h"
+
+#ifdef __unix__
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#endif
+
+void goto_grv_dir(void)
+{
+ /* On Unix, save stuff in a ~/.grv directory */
+#ifdef __unix__
+ {
+ char *home = getenv("HOME");
+ char *grvd = getenv("GRV_DIR");
+
+ if ( !grvd ) {
+ grvd = alloca(strlen(home)+6);
+ if ( grvd ) {
+ sprintf(grvd, "%s/.grv", home);
+ mkdir(grvd, 0777); /* Make .grv directory if missing */
+ }
+ }
+
+ if ( grvd )
+ chdir(grvd); /* Change to .grv directory */
+ }
+#endif
+}