Commit e7513ef5 authored by Jari Aalto's avatar Jari Aalto

xonix.man,flyer.xpm,x11.c,Imakefile: restore original

Signed-off-by: 's avatarJari Aalto <jari.aalto@cante.net>
parent fee3b10f
......@@ -26,7 +26,7 @@ UnsharedLibReferences(XPM,Xpm,$(XPMSRC))
CUTE = -DSEND_MAIL /* cute feature :-) */
DEPLIBS = XawClientDepLibs XpmDepLib
LOCAL_LIBRARIES = XawClientLibs XpmLib
LOCAL_LIBRARIES = XawClientLibs XpmLib MathLibrary
EXTRA_DEFINES = -DUSE_X11 -DXONIXDIR=\"$(XONIXDIR)\" $(CUTE)
/* CDEBUGFLAGS = DebuggableCDebugFlags */
......
......@@ -2,7 +2,7 @@
static char * flyer_xpm[] = {
"8 8 3 1",
" c forest green",
". c yellow",
". g4 yellow c tomato",
"X c black",
" .. ",
" .XX. ",
......
......@@ -52,7 +52,8 @@
#ifdef __unix
#define MAXSCORES 10 /* number of entries in high score table */
#define PATH_HIGHSCORE "/var/games/xonix.scores"
#define PATH_HIGHSCORE XONIXDIR "/scores"
#define PATH_TEMPSCORE XONIXDIR "/score_tmp"
#if defined(__unix) && !defined PATH_RMAIL
#define PATH_RMAIL "rmail" /* rely on the $PATH */
......@@ -60,7 +61,6 @@
#include <sys/types.h>
#include <sys/time.h>
#include <sys/file.h>
#include <pwd.h>
#include <string.h>
#include <stdlib.h>
......@@ -898,6 +898,7 @@ DisplayHighScore(void)
char *fullname = 0, *cp;
struct score_rec score_rec[MAXSCORES];
int i, numentries = 0;
char tempname[sizeof(PATH_TEMPSCORE) + 15];
char hugestring[MAXSCORES * 100];
Widget box1, box2, msg, headl, done, area;
......@@ -925,62 +926,53 @@ DisplayHighScore(void)
}
else
fullname = strdup(pw->pw_gecos);
cp = strchr(fullname, ',');
if (cp == fullname) {
free(fullname);
fullname = strdup("(No name)");
}
else if (cp != NULL)
*cp = 0; /* remove trailing garbage */
if((cp = strchr(fullname, ','))) *cp = 0; /* remove trailing garbage */
}
else
fullname = strdup("(No name)"); /* the strdup() allows to free() it */
/* try opening high score file, and read it */
if((high=fopen(PATH_HIGHSCORE, "r")) && (flock(fileno(high),LOCK_EX)==0)){
for(i = 0; i < MAXSCORES; i++) {
if((high = fopen(PATH_HIGHSCORE, "r"))) {
for(i = 0; i < 10; i++) {
char line[100];
if(fgets(line, 100, high) == NULL)
break;
if(sscanf(line, "%u%*[\t]%u%*[\t]%10[^\t]%*[\t]%64[^\t]%*[\t]%ld",
if(sscanf(line, " %u %u%*[\t]%10[^\t]%*[\t]%64[^\t] %ld",
&score_rec[i].score, &score_rec[i].level,
score_rec[i].login, score_rec[i].full,
&score_rec[i].tstamp)
<3 ) break; /* mangled entry */
!= 5) break; /* mangled entry */
}
numentries = i;
fclose(high);
}
else
{
if (high != NULL) {
fprintf(stderr, "xonix: cannot lock high score file\n");
fclose(high);
}
else
fprintf(stderr, "xonix: cannot open high score file\n");
if(numentries)
qsort(score_rec, numentries, sizeof(struct score_rec), compare);
/* make sure the new list will be world-readable */
(void)umask(umask(0) & ~0644);
sprintf(tempname, "%s.%d", PATH_TEMPSCORE, (int)getpid());
if((high = fopen(tempname, "w")) == NULL) {
fprintf(stderr, "xonix: cannot rewrite high score file\n");
free(fullname);
gameover_pending = 0;
return;
}
if(numentries)
qsort(score_rec, numentries, sizeof(struct score_rec), compare);
if(numentries >= MAXSCORES && gHighScore <= score_rec[0].score) {
if(numentries >= MAXSCORES && gHighScore < score_rec[0].score) {
/* sorry, not among top ten */
free(fullname);
if(flock(fileno(high),LOCK_UN) != 0)
fprintf(stderr, "xonix: cannot unlock high score file\n");
fclose(high);
(void)unlink(tempname);
free(fullname);
gameover_pending = 0;
return;
}
for(i = 0; i < numentries; i++) {
/* look where to put entry */
if(score_rec[i].score >= gHighScore) break;
if(score_rec[i].score > gHighScore) break;
}
#ifdef SEND_MAIL
......@@ -1001,32 +993,19 @@ DisplayHighScore(void)
tm = localtime(&sp->tstamp);
strftime(tbuf, 20, "%d-%b-%y", tm);
/* format a text - fork and exec the processes so we can drop privileges */
switch( fork() ) {
case -1: /* Error */
perror(fork);
exit(1);
break;
case 0: /* Child */
setgid(pw->pw_gid);
setuid(pw->pw_uid);
if((mail = popen(cmd, "w")) != NULL) {
fprintf(mail,
"To: %s (%s)\n"
"Subject: Lost xonix championship\n\n"
"Your previously held first rank in the local xonix score\n"
"table (%u points, level %u, dated %s) has been\n"
"vanished today by me with %u points.\n\n"
"\t\tpitying you\t%s (%s)\n",
sp->login, sp->full,
sp->score, sp->level, tbuf,
gHighScore,
pw->pw_name, fullname);
(void)pclose(mail);
break;
default: /* parent */
break;
}
if((mail = popen(cmd, "w")) != NULL) {
fprintf(mail,
"To: %s (%s)\n"
"Subject: Lost xonix championship\n\n"
"Your previously held first rank in the local xonix score\n"
"table (%u points, level %u, dated %s) has been\n"
"vanished today by me with %u points.\n\n"
"\t\tpitying you\t%s (%s)\n",
sp->login, sp->full,
sp->score, sp->level, tbuf,
gHighScore,
pw->pw_name, fullname);
(void)pclose(mail);
}
}
......@@ -1057,23 +1036,16 @@ DisplayHighScore(void)
score_rec[i].tstamp = time(NULL);
free(fullname);
if((high = freopen(PATH_HIGHSCORE, "w",high)) == NULL) {
fprintf(stderr, "xonix: cannot reopen high score file\n");
free(fullname);
gameover_pending = 0;
return;
}
for(i = 0; i < numentries; i++)
(void)fprintf(high, "%u\t%u\t%s\t%s\t%ld\n",
score_rec[i].score, score_rec[i].level,
score_rec[i].login, score_rec[i].full,
score_rec[i].tstamp);
if(flock(fileno(high),LOCK_UN) != 0)
fprintf(stderr, "xonix: cannot unlock high score file\n");
fclose(high);
if(rename(tempname, PATH_HIGHSCORE))
fprintf(stderr, "xonix: cannot install new highscore file\n");
/* create hugestring for highscore label */
hugestring[0] = 0;
for(i = 0; i < numentries; i++) {
......
......@@ -71,10 +71,11 @@ The default keys to immediately quit the game are `Q' and `Escape'.
Hitting `P' or iconizing the window with the window manager will pause
the game; de-iconizing will continue it.
There is also a high-score file, \fI/var/games/xonix.scores\fP. It
records the top ten xonix players for that machine. As a special
compile-time option, a mail is sent to the previous xonix score leader
when he's lost his first rank.
On Posix-compliant systems, there is also a high-score file,
\fB$PROJECTROOT/\fP\fIlib/X11/xonix/scores\fP. It records the top ten
xonix players for that machine. As a special compile-time option,
a mail is sent to the previous xonix score leader when he's lost
his first rank.
.SH WIDGETS
\fIXonix\fP uses the X Toolkit and the Athena Widget Set.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment