A patch against libgnome/gnome-score.c



A patch against libgnome/gnome-score.c proposed.
This makes possible to save and restore in score files users real names 
instead logins if possible. If the user name field in /etc/passwd will be 
empty his(her) login will be saved.
This patch uses glib's functions.


-- 
Andrey Panov
http://canopus.iacp.dvo.ru/~panov/
E-mail: panov iacp dvo ru
--- gnome-score.c	Sun Jun 18 03:53:33 2000
+++ gnome-score.c.new	Fri Mar 16 13:59:05 2001
@@ -97,7 +97,7 @@
 {
    FILE *infile;
    FILE *outfile;
-   gchar buf[512], name[512];
+   gchar buf[512], *buf2;
    GList *scores = NULL, *anode;
    gchar *game_score_file;
    gfloat ascore;
@@ -121,12 +121,22 @@
 	     while (isspace (buf[i]))
 	       buf[i--] = '\0';
 
-	     if(sscanf(buf, "%f %ld %s", &ascore, &ltime, name) != 3)
-	       break;
+  	     {
+	        char *tokp;
+
+	        if((buf2 = strtok_r (buf, " ", &tokp)) == NULL)
+		  break;
+	        ascore = atof (buf2);
+	        if((buf2 = strtok_r (NULL, " ", &tokp)) == NULL)
+		  break;
+	        ltime = atoi (buf2);
+	        if((buf2 = strtok_r (NULL, "\n", &tokp)) == NULL)
+		  break;
+	     }
 
 	     anitem = g_new(struct ascore_t, 1);
 	     anitem->score = ascore;
-	     anitem->username = g_strdup (name);
+	     anitem->username = g_strdup (buf2);
 	     anitem->scoretime = (time_t)ltime;
 	     scores = g_list_append (scores, (gpointer) anitem);
 	  }
@@ -196,7 +206,7 @@
 {
    struct command cmd;
    gchar *level;
-   struct passwd *pwd;
+   gchar *realname;
    gint retval;
 #ifdef HAVE_SETFSGID
    gid_t gid;
@@ -205,8 +215,10 @@
    setgid (getgid ());
    setfsgid (gid);
 #endif
-   pwd = getpwuid (getuid ());
-
+   realname = g_get_real_name ();
+   if (strlen (realname) == 0)
+     realname = g_get_user_name ();
+		    
    while (read (STDIN_FILENO, &cmd, sizeof cmd) == sizeof(cmd))
      {
 	level = g_new (char, cmd.level);
@@ -216,13 +228,15 @@
 	   g_free(level);
 	   level = NULL;
 	}
-	retval = log_score (defgamename, level, pwd->pw_name, cmd.score,
+	retval = log_score (defgamename, level, realname, cmd.score,
 			    cmd.ordering);
 	if (write(STDOUT_FILENO, &retval, sizeof retval) != sizeof retval)
 	  return EXIT_FAILURE;
 	if (level)
 	  g_free(level);
-     }
+        if (realname)
+          g_free (realname);
+           }
    return EXIT_SUCCESS;
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]