|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T m
Length: 2564 (0xa04)
Types: TextFile
Names: »mex_scores.c«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
└─⟦this⟧ »EUUGD18/Sun/Mex/mex_scores.c«
/* ALL code in this program may be used for personal use */
/* and this program may be distributed as long as this copyright */
/* heading is attached to each source code file. Distribution must */
/* be done FREE of charge................ */
/* Glenn Kreisel */
/* glenn@midget.towson.edu */
#include "mex.h"
#include <unistd.h>
extern char *get_player_name();
extern update_hiscore_window();
extern Frame show_scores_frame;
struct each_player hiscore_list[KEEP_SCORES];
FILE *hi_file;
read_in_scores()
{
if((hi_file=fopen(HISCORE_FILE,"r+"))==NULL)
clear_hiscores();
else read_in();
}
write_out_scores()
{
if((hi_file=fopen(HISCORE_FILE,"w"))==NULL)
printf("Error writing hiscore file!!!!!\n");
else write_out();
}
clear_hiscores()
{
int i=0;
for(i=0;i<KEEP_SCORES;i++)
hiscore_list[i].score=(-1);
write_out_scores();
chmod(HISCORE_FILE,S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
}
write_out()
{
int i=0;
/*lockf(fileno(hi_file),F_LOCK,0); */
while(hiscore_list[i].score!=-1 && i<KEEP_SCORES)
{
fprintf(hi_file,"\02");
fprintf(hi_file,"%s\02%d %d%s",hiscore_list[i].name,hiscore_list[i].score, hiscore_list[i].rows,
hiscore_list[i].date);
i++;
}
fprintf(hi_file,"\01\n\n");
fclose(hi_file);
close(fileno(hi_file));
}
read_in()
{
char c;
int x,i=0,i1;
/* lockf(fileno(hi_file),F_LOCK,0); */
c=fgetc(hi_file);
do
{
if(c=='\01'|| feof(hi_file)) break;
hiscore_list[i].name[0]='\0';
for(i1=0;(c=fgetc(hi_file))!='\02' && (!feof(hi_file));i1++)
{
hiscore_list[i].name[i1]=c;
}
hiscore_list[i].name[i1]='\0';
fscanf(hi_file,"%d %d",&hiscore_list[i].score,&hiscore_list[i].rows);
hiscore_list[i].date[0]='\0';
for(i1=0;(c=fgetc(hi_file))!='\02' && (c!='\01') && (!feof(hi_file));i1++)
{
hiscore_list[i].date[i1]=c;
}
i++;
} while((!feof(hi_file)) && (i<KEEP_SCORES));
if(i<KEEP_SCORES)
hiscore_list[i].score=(-1);
fclose(hi_file);
close(fileno(hi_file));
}
insert_score(score,rows)
int score,rows;
{
char *name;
int i=0,x;
long t;
read_in_scores();
if(score!=0)
{
while(hiscore_list[i].score>score && i++<KEEP_SCORES);
if(i<KEEP_SCORES)
{
name=get_player_name();
for(x=KEEP_SCORES-1;x!=i;x--)
{
hiscore_list[x]=hiscore_list[x-1];
}
hiscore_list[i].rows=rows;
strcpy(hiscore_list[i].name,name,strlen(name));
hiscore_list[i].score=score;
t=time(0);
strcpy(hiscore_list[i].date,ctime(&t),strlen(ctime(&t)));
if((int)window_get(show_scores_frame,WIN_SHOW))
update_hiscore_window();
write_out_scores();
}
}
}