-FILE *hs_fopen(char *mode) {
- FILE *f;
- mode_t mask;
- mask = umask(0111);
- if(f = fopen("/usr/share/vor/.highscore",mode)) {
- umask(mask);
- return f;
- }
- else {
- char s[1024];
- umask(0177);
- sprintf(s,"%s/.vor-high",getenv("HOME"));
- if(f = fopen(s,mode)) {
- umask(mask);
- return f;
- }
- else {
- umask(mask);
- return 0;
- }
- }
-}
-void read_high_score_table() {
- FILE *f;
- int i;
- if(f = hs_fopen("r")) {
- // If the file exists, read from it
- for(i = 0; i<8; i++) {
- char s[1024];
- int highscore;
- if(fscanf (f, "%d %[^\n]", &highscore, s) != 2) {
- break;
- }
- if(high[i].allocated) {
- free(high[i].name);
- }
- high[i].name = strdup(s);
- high[i].score = highscore;
- high[i].allocated = 1;
- }
- fclose(f);
- }
-}
-void write_high_score_table() {
- FILE *f;
- int i;
- if(f = hs_fopen("w")) {
- // If the file exists, write to it
- for(i = 0; i<8; i++) {
- fprintf (f, "%d %s\n", high[i].score, high[i].name);
- }
- fclose(f);
- }
-}
-void snprintscore(char *s, size_t n, int score) {
- int min = score/60000;
- int sec = score/1000%60;
- int tenths = score%1000/100;
- if(min) {
- snprintf(s, n, "%2d:%.2d.%d", min, sec, tenths);
- } else {
- snprintf(s, n, " %2d.%d", sec, tenths);
- }
-}
-float rnd() {