File tint-0.04-per-user-highscore.patch of Package tint
diff -urN tint-0.04.orig/tint.c tint-0.04/tint.c
--- tint-0.04.orig/tint.c 2010-06-23 13:16:32.000000000 +0200
+++ tint-0.04/tint.c 2010-07-21 19:25:49.000000000 +0200
@@ -32,13 +32,13 @@
#include <string.h>
#include <time.h>
#include <pwd.h>
+#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include "typedefs.h"
#include "utils.h"
#include "io.h"
-#include "config.h"
#include "engine.h"
/*
@@ -69,10 +69,14 @@
/* This calculates the real (displayed) value of the score */
#define GETSCORE(score) ((score) / SCOREFACTOR)
+/* Name of the scorefile */
+#define SCOREFILENAME "tint.scores"
+
static bool shownext;
static bool dottedlines;
static int level = MINLEVEL - 1,shapecount[NUMSHAPES];
static char blockchar = ' ';
+static char *scorefile;
/*
* Functions
@@ -568,8 +572,21 @@
bool finished;
int ch;
engine_t engine;
+ char *scorefile_path;
/* Initialize */
rand_init (); /* must be called before engine_init () */
+ scorefile_path = get_scorefile_path ();
+ if (scorefile_path == NULL) exit (EXIT_FAILURE);
+ scorefile = malloc (strlen (scorefile_path) + strlen ("/" SCOREFILENAME) + 1);
+ if (scorefile == NULL)
+ {
+ free (scorefile_path);
+ exit (EXIT_FAILURE);
+ }
+ strcpy (scorefile,scorefile_path);
+ strcat (scorefile,"/" SCOREFILENAME);
+ mkdir (scorefile_path, 0755);
+ free (scorefile_path);
engine_init (&engine,score_function); /* must be called before using engine.curshape */
finished = shownext = FALSE;
memset (shapecount,0,NUMSHAPES * sizeof (int));
@@ -678,6 +695,7 @@
showplayerstats (&engine);
savescores (GETSCORE (engine.score));
}
+ free (scorefile);
exit (EXIT_SUCCESS);
}
diff -urN tint-0.04.orig/utils.c tint-0.04/utils.c
--- tint-0.04.orig/utils.c 2001-12-07 16:49:19.000000000 +0100
+++ tint-0.04/utils.c 2010-07-21 19:26:42.000000000 +0200
@@ -28,6 +28,7 @@
*/
#include <stdlib.h>
+#include <string.h>
#include <time.h>
#include <limits.h>
@@ -69,3 +70,42 @@
return TRUE;
}
+/*
+ * Get the scorefile path. Returns the path to the scorefile or NULL
+ * on error.
+ */
+char* get_scorefile_path (void)
+{
+ char *env_xdg_data_home;
+ char *env_home;
+ char *xdg_data_home;
+ char *scorefile_path;
+
+ env_xdg_data_home = getenv ("XDG_DATA_HOME");
+ if (env_xdg_data_home != NULL)
+ {
+ xdg_data_home = malloc (strlen (env_xdg_data_home) + 1);
+ strcpy (xdg_data_home, env_xdg_data_home);
+ }
+ else
+ {
+ env_home = getenv ("HOME");
+ if (env_home == NULL) return NULL;
+
+ xdg_data_home = malloc (strlen (env_home) + strlen ("/.local/share") + 1);
+ if (xdg_data_home == NULL) return NULL;
+ strcpy (xdg_data_home,env_home);
+ strcat (xdg_data_home,"/.local/share");
+ }
+
+ scorefile_path = malloc (strlen (xdg_data_home) + strlen ("/tint") + 1);
+ if (scorefile_path != NULL)
+ {
+ strcpy (scorefile_path,xdg_data_home);
+ strcat (scorefile_path,"/tint");
+ }
+ free (xdg_data_home);
+
+ return scorefile_path;
+}
+
diff -urN tint-0.04.orig/utils.h tint-0.04/utils.h
--- tint-0.04.orig/utils.h 2001-12-07 16:49:35.000000000 +0100
+++ tint-0.04/utils.h 2010-07-21 19:00:45.000000000 +0200
@@ -47,4 +47,10 @@
*/
bool str2int (int *i,const char *str);
+/*
+ * Get the scorefile path. Returns the path to the scorefile or NULL
+ * on error.
+ */
+char* get_scorefile_path (void);
+
#endif /* #ifndef UTILS_H */