[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] Changes to emacs/lib-src/update-game-score.c
From: |
Colin Walters |
Subject: |
[Emacs-diffs] Changes to emacs/lib-src/update-game-score.c |
Date: |
Sun, 07 Apr 2002 00:46:03 -0500 |
Index: emacs/lib-src/update-game-score.c
diff -c emacs/lib-src/update-game-score.c:1.3
emacs/lib-src/update-game-score.c:1.4
*** emacs/lib-src/update-game-score.c:1.3 Fri Apr 5 04:18:57 2002
--- emacs/lib-src/update-game-score.c Sun Apr 7 00:46:03 2002
***************
*** 40,46 ****
#include <config.h>
#define MAX_ATTEMPTS 5
! #define SCORE_FILE_PREFIX "/var/games/emacs/"
int
usage(int err)
--- 40,51 ----
#include <config.h>
#define MAX_ATTEMPTS 5
!
! #ifdef HAVE_SHARED_GAME_DIR
! #define SCORE_FILE_PREFIX HAVE_SHARED_GAME_DIR
! #else
! #define SCORE_FILE_PREFIX "$HOME"
! #endif
int
usage(int err)
***************
*** 78,87 ****
int count);
char *
! get_user_id()
{
char *name;
- struct passwd *buf = getpwuid(getuid());
if (!buf)
{
int count = 1;
--- 83,91 ----
int count);
char *
! get_user_id(struct passwd *buf)
{
char *name;
if (!buf)
{
int count = 1;
***************
*** 95,110 ****
return buf->pw_name;
}
int
main(int argc, char **argv)
{
int c;
void *lockstate;
! char *scorefile;
struct stat buf;
struct score_entry *scores;
int newscore, scorecount, reverse = 0, max = -1;
char *newdata;
srand(time(0));
--- 99,123 ----
return buf->pw_name;
}
+ char *
+ get_home_dir(struct passwd *buf)
+ {
+ if (!buf)
+ return NULL;
+ return buf->pw_dir;
+ }
+
int
main(int argc, char **argv)
{
int c;
void *lockstate;
! char *scorefile, *prefix;
struct stat buf;
struct score_entry *scores;
int newscore, scorecount, reverse = 0, max = -1;
char *newdata;
+ struct passwd *passwdbuf;
srand(time(0));
***************
*** 126,139 ****
if (optind+3 != argc)
usage(1);
! scorefile = malloc(strlen(SCORE_FILE_PREFIX) + strlen(argv[optind]) + 1);
if (!scorefile)
{
fprintf(stderr, "Couldn't create score file name: %s\n",
strerror(errno));
goto fail;
}
! strcpy(scorefile, SCORE_FILE_PREFIX);
strcat(scorefile, argv[optind]);
newscore = atoi(argv[optind+1]);
newdata = argv[optind+2];
--- 139,167 ----
if (optind+3 != argc)
usage(1);
!
! passwdbuf = getpwuid(getuid());
!
! if (!strcmp(SCORE_FILE_PREFIX, "$HOME"))
! {
! prefix = get_home_dir(passwdbuf);
! if (!prefix)
! {
! fprintf(stderr, "Unable to determine home directory\n");
! exit(1);
! }
! }
! else
! prefix = SCORE_FILE_PREFIX;
!
! scorefile = malloc(strlen(prefix) + strlen(argv[optind]) + 1);
if (!scorefile)
{
fprintf(stderr, "Couldn't create score file name: %s\n",
strerror(errno));
goto fail;
}
! strcpy(scorefile, prefix);
strcat(scorefile, argv[optind]);
newscore = atoi(argv[optind+1]);
newdata = argv[optind+2];
***************
*** 156,162 ****
scorefile, strerror(errno));
goto fail_unlock;
}
! push_score(&scores, &scorecount, newscore, get_user_id(), newdata);
sort_scores(scores, scorecount, reverse);
if (write_scores(scorefile, scores, scorecount) < 0)
{
--- 184,190 ----
scorefile, strerror(errno));
goto fail_unlock;
}
! push_score(&scores, &scorecount, newscore, get_user_id(passwdbuf), newdata);
sort_scores(scores, scorecount, reverse);
if (write_scores(scorefile, scores, scorecount) < 0)
{
***************
*** 229,234 ****
--- 257,263 ----
int len;
if (getline(&score->data, &len, f) < 0)
return -1;
+ score->data[strlen(score->data)-1] = '\0';
}
#else
{
***************
*** 249,258 ****
cur++;
}
score->data = buf;
}
#endif
- /* Trim the newline */
- score->data[strlen(score->data)-1] = '\0';
return 0;
}
--- 278,286 ----
cur++;
}
score->data = buf;
+ score->data[cur] = '\0';
}
#endif
return 0;
}
- [Emacs-diffs] Changes to emacs/lib-src/update-game-score.c, Colin Walters, 2002/04/05
- [Emacs-diffs] Changes to emacs/lib-src/update-game-score.c, Colin Walters, 2002/04/05
- [Emacs-diffs] Changes to emacs/lib-src/update-game-score.c,
Colin Walters <=
- [Emacs-diffs] Changes to emacs/lib-src/update-game-score.c, Colin Walters, 2002/04/10
- [Emacs-diffs] Changes to emacs/lib-src/update-game-score.c, Andreas Schwab, 2002/04/13
- [Emacs-diffs] Changes to emacs/lib-src/update-game-score.c, Colin Walters, 2002/04/14
- [Emacs-diffs] Changes to emacs/lib-src/update-game-score.c, Eli Zaretskii, 2002/04/16
- [Emacs-diffs] Changes to emacs/lib-src/update-game-score.c, Colin Walters, 2002/04/23
- [Emacs-diffs] Changes to emacs/lib-src/update-game-score.c, Colin Walters, 2002/04/29