File tint-0.04-per-user-highscore.patch of Package tint

diff -Nur tint-0.07/tint.c new/tint.c
--- tint-0.07/tint.c	2022-02-06 17:57:02.000000000 +0100
+++ new/tint.c	2022-04-18 15:02:10.167998669 +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"
 
 /*
@@ -76,10 +76,14 @@
       while (((ch = getchar()) != EOF) && (ch != '\n')); \
    }
 
+/* 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
@@ -582,8 +586,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));
@@ -693,6 +710,7 @@
 		showplayerstats (&engine);
 		savescores (GETSCORE (engine.score));
 	 }
+   free (scorefile);
    exit (EXIT_SUCCESS);
 }
 
diff -Nur tint-0.07/utils.c new/utils.c
--- tint-0.07/utils.c	2022-02-06 17:57:02.000000000 +0100
+++ new/utils.c	2022-04-18 15:02:10.167998669 +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 -Nur tint-0.07/utils.h new/utils.h
--- tint-0.07/utils.h	2022-02-06 17:57:02.000000000 +0100
+++ new/utils.h	2022-04-18 15:02:10.167998669 +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 */
openSUSE Build Service is sponsored by