+ size_t x;
+ for (x=strlen(str); x<len-1; x++) {
+ str[x] = ' ';
+ }
+ str[len-1] = 0;
+}
+
+static
+void
+unpad_spaces(char *str)
+{
+ size_t x;
+ for (x=strlen(str); x>0 && str[x-1]==' '; x--);
+ str[x] = 0;
+}
+
+static
+int
+read_score_entry(struct score_entry *se, FILE *fp)
+{
+ char score_block[80];
+ char nickname_block[30];
+ size_t n, x;
+
+ n = fread(score_block, 1, sizeof(score_block), fp);
+ if (n==0) {
+ /* EOF */
+ return 0;
+ }
+ if (n != sizeof(score_block)) {
+ sf_error();
+ }
+
+ n = fread(nickname_block, 1, sizeof(nickname_block), fp);
+ if (n != sizeof(nickname_block)) {
+ sf_error();
+ }
+
+ xxxx(score_block, sizeof(score_block));
+ xxxx(nickname_block, sizeof(nickname_block));
+
+ /* Ensure null termination */
+ score_block[sizeof(score_block)-1] = 0;
+ nickname_block[sizeof(nickname_block)-1] = 0;
+
+ /* If there are other nulls in the score block, file is corrupt */
+ if (strlen(score_block)!=sizeof(score_block)-1) {
+ sf_error();
+ }
+ /* but this is NOT true of the nickname block */
+
+ /* quash trailing spaces */
+ unpad_spaces(score_block);
+ unpad_spaces(nickname_block);
+
+ for (x=5; score_block[x] == ' '; x++);
+ se->gold = lget_number(score_block+x);
+
+ for (x=15; score_block[x] != 0 && score_block[x] != ':'; x++);
+ if (score_block[x] == 0) {
+ sf_error();
+ }
+ score_block[x++] = 0;
+ strlcpy(se->username, score_block+15, sizeof(se->username));
+
+ strlcpy(se->death, score_block+x, sizeof(se->death));
+ strlcpy(se->nickname, nickname_block, sizeof(se->nickname));
+
+ return 1;
+}
+
+static
+void
+write_score_entry(const struct score_entry *se, int rank, FILE *fp)
+{
+ char score_block[80];
+ char nickname_block[30];
+
+ /* avoid writing crap to score file */
+ memset(score_block, 0, sizeof(score_block));
+ memset(nickname_block, 0, sizeof(nickname_block));
+
+ snprintf(score_block, sizeof(score_block),
+ "%2d %6ld %s: %s",
+ rank+1, se->gold, se->username, se->death);
+ strlcpy(nickname_block, se->nickname, sizeof(nickname_block));
+
+ /* pad blocks out with spaces */
+ pad_spaces(score_block, sizeof(score_block));
+ /*pad_spaces(nickname_block, sizeof(nickname_block)); -- wrong! */
+
+ xxxx(score_block, sizeof(score_block));
+ xxxx(nickname_block, sizeof(nickname_block));
+
+ fwrite(score_block, 1, sizeof(score_block), fp);
+ fwrite(nickname_block, 1, sizeof(nickname_block), fp);
+}
+
+void
+put_scores(const object *monster, short other)
+{
+ short i, rank=-1, found_player = -1, numscores = 0;
+ struct score_entry scores[NUM_SCORE_ENTRIES];
+ const char *name;