|
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 s
Length: 4206 (0x106e) Types: TextFile Names: »scores.c.orig«
└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987 └─⟦this⟧ »EUUGD18/X/Xwanderer/scores.c.orig«
#include "wand_head.h" /* MFC- lockfiles fixed: tries 5 times to get lock, with 1 second between * tries, if after 5 seconds, no lock is gained, the lockfile is blown * away. */ #define LOCK { lc=5; \ while((lock = creat(LOCKPATH,0)<0 && lc)) { \ sleep(1); lc--; } \ } #define UNLOCK (void) unlink(LOCKPATH) #define ENTRIES 15 typedef struct { char howdead[25]; char name[20]; int score; int level; } score_entry; #ifdef XWANDER extern endgame; win_show_scores(table,num) score_entry *table; int num; { int tot = num; table_message(0,"No. Score Level Names How they died"); table_message(1,"-----------------------------------------------------------------------------"); while(num > 0) { num--; table_message((tot-num)+1,"%2d %5d %3d %-20s killed by %-s",(tot - num),table->score,table->level,table->name,table->howdead); table++; } } #endif void show_scores(table,num) score_entry *table; int num; { int tot = num; #ifdef XWANDER if (!endgame) { win_show_scores(table, num); return; } #endif printf("\nNo. Score Level Names How they died\n"); printf("=============================================================================\n"); while(num > 0) { num--; printf("%2d %5d %3d %-20s killed by %-s\n",(tot - num),table->score,table->level,table->name,table->howdead); table++; } printf("\n\n"); } int readtable(table_ptr) score_entry *table_ptr; { FILE *fp; int numread; if((fp = fopen(HISCOREPATH,"r")) == NULL) { numread = 0; } else { numread = fread(table_ptr, sizeof(score_entry), ENTRIES, fp); fclose(fp); } return numread; } int savescore(howdead,score,level,name) char *howdead, *name; int score,level; { int lc; score_entry table[ENTRIES + 2], *table_ptr = table, *from_ptr, new_entry,temp_entry; int numread,index = 1, numsaved, lock, already = 0, output_value = 1; FILE *fp; strncpy(new_entry.howdead,howdead,25); strncpy(new_entry.name,name,20); new_entry.score = score; new_entry.level = level; lock = (-1); while (lock == (-1)) { LOCK; if (lock==(-1)) { UNLOCK; } } numread = readtable(table_ptr); if (numread > 0) if(table[numread-1].score > 99999) /* stop system errors messing it up*/ { numread--; printf("\007Erasing spurious entry in table.\n"); } if(score == 0) { show_scores(table,numread); UNLOCK; return 0; } if (numread > 0) { numread++; /* scan through until correct insertion point */ while((table_ptr->score > score)&&(index < numread)) { if(strcmp(table_ptr->name,name)==0) { already= 1; break; } table_ptr++; index++; } if(table_ptr->score == score) while((table_ptr->level>level)&&(index<=numread)&&(table_ptr->score == score)) { if((already == 1)||(strcmp(table_ptr->name,name)==0)) { already= 1; break; } table_ptr++; index++; }; if(already == 0) { /* provided no previous hiscore */ temp_entry = *table_ptr; /* insert new entry */ *table_ptr = new_entry; from_ptr = table_ptr; if (strcmp(temp_entry.name, name) == 0) numread--; /* new entry directly replaces old one */ } else { numread--; from_ptr = table_ptr--; temp_entry = *from_ptr; } while(index++ < numread) { table_ptr++; from_ptr++; if(strcmp(from_ptr->name,name)==0 && index<numread) { from_ptr++; numread--; } new_entry = *from_ptr; *table_ptr = temp_entry; temp_entry = new_entry; } } else { printf("\007\nCreating new hiscore table.\n\n"); *table_ptr = new_entry; numread++; } numread = ( (numread > ENTRIES) ? ENTRIES : numread ); fp = fopen(HISCOREPATH,"w"); table_ptr = table; numsaved = fwrite(table_ptr, sizeof(score_entry), numread, fp); chmod(HISCOREPATH,0666); if(numsaved < numread) { printf("ERROR! Only %d items saved from %d !\n",numsaved,numread); output_value = 0; } fclose(fp); UNLOCK; show_scores(table,numsaved); return output_value; }