]> git.cameronkatri.com Git - bsdgames-darwin.git/blobdiff - rogue/score.c
off-by-one. aaron@openbsd
[bsdgames-darwin.git] / rogue / score.c
index 4b4f06918117e9cd9942548f2b638926cf6078d8..070329a4019d471deee06bce9b580972b3a24433 100644 (file)
@@ -1,6 +1,8 @@
+/*     $NetBSD: score.c,v 1.11 2003/08/07 09:37:40 agc Exp $   */
+
 /*
- * Copyright (c) 1988 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1988, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  * This code is derived from software contributed to Berkeley by
  * Timothy C. Stoehr.
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
+ * 3. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
  *
  * SUCH DAMAGE.
  */
 
+#include <sys/cdefs.h>
 #ifndef lint
-/*static char sccsid[] = "from: @(#)score.c    5.5 (Berkeley) 6/1/90";*/
-static char rcsid[] = "$Id: score.c,v 1.4 1993/11/10 10:02:20 cgd Exp $";
+#if 0
+static char sccsid[] = "@(#)score.c    8.1 (Berkeley) 5/31/93";
+#else
+__RCSID("$NetBSD: score.c,v 1.11 2003/08/07 09:37:40 agc Exp $");
+#endif
 #endif /* not lint */
 
 /*
@@ -55,15 +57,10 @@ static char rcsid[] = "$Id: score.c,v 1.4 1993/11/10 10:02:20 cgd Exp $";
 #include "rogue.h"
 #include "pathnames.h"
 
-extern char login_name[];
-extern char *m_names[];
-extern short max_level;
-extern boolean score_only, no_skull, msg_cleared;
-extern char *byebye_string, *nick_name;
-
+void
 killed_by(monster, other)
-object *monster;
-short other;
+       const object *monster;
+       short other;
 {
        char buf[128];
 
@@ -129,6 +126,7 @@ short other;
        put_scores(monster, other);
 }
 
+void
 win()
 {
        unwield(rogue.weapon);          /* disarm and relax */
@@ -152,13 +150,16 @@ win()
        put_scores((object *) 0, WIN);
 }
 
+void
 quit(from_intrpt)
-boolean from_intrpt;
+       boolean from_intrpt;
 {
        char buf[128];
        short i, orow, ocol;
        boolean mc;
 
+       orow = ocol = 0;
+       mc = FALSE;
        md_ignore_signals();
 
        if (from_intrpt) {
@@ -193,9 +194,10 @@ boolean from_intrpt;
        killed_by((object *) 0, QUIT);
 }
 
+void
 put_scores(monster, other)
-object *monster;
-short other;
+       const object *monster;
+       short other;
 {
        short i, n, rank = 10, x, ne = 0, found_player = -1;
        char scores[10][82];
@@ -203,15 +205,18 @@ short other;
        char buf[128];
        FILE *fp;
        long s;
-       boolean pause = score_only;
+       boolean dopause = score_only;
 
        md_lock(1);
 
+       setegid(egid);
        if ((fp = fopen(_PATH_SCOREFILE, "r+")) == NULL &&
            (fp = fopen(_PATH_SCOREFILE, "w+")) == NULL) {
+               setegid(gid);
                message("cannot read/write/create score file", 0);
                sf_error();
        }
+       setegid(gid);
        rewind(fp);
        (void) xxx(1);
 
@@ -269,8 +274,8 @@ short other;
                        rank = ne;
                }
                if (rank < 10) {
-                       insert_score(scores, n_names, nick_name, rank, ne, monster,
-                               other);
+                       insert_score(scores, n_names, nick_name, rank, ne,
+                           monster, other);
                        if (ne < 10) {
                                ne++;
                        }
@@ -313,18 +318,20 @@ short other;
        refresh();
        fclose(fp);
        message("", 0);
-       if (pause) {
+       if (dopause) {
                message("", 0);
        }
        clean_up("");
 }
 
+void
 insert_score(scores, n_names, n_name, rank, n, monster, other)
-char scores[][82];
-char n_names[][30];
-char *n_name;
-short rank, n;
-object *monster;
+       char scores[][82];
+       char n_names[][30];
+       const char *n_name;
+       short rank, n;
+       const object *monster;
+       int other;
 {
        short i;
        char buf[128];
@@ -337,7 +344,8 @@ object *monster;
                        }
                }
        }
-       sprintf(buf, "%2d    %6d   %s: ", rank+1, rogue.gold, login_name);
+       sprintf(buf, "%2d    %6ld   %s: ", rank+1, (long)rogue.gold,
+           login_name);
 
        if (other) {
                switch(other) {
@@ -357,7 +365,7 @@ object *monster;
                        (void) strcat(buf, "a total winner");
                        break;
                case KFIRE:
-                       (void) strcpy(buf, "killed by fire");
+                       (void) strcat(buf, "killed by fire");
                        break;
                }
        } else {
@@ -381,8 +389,9 @@ object *monster;
        (void) strcpy(n_names[rank], n_name);
 }
 
+boolean
 is_vowel(ch)
-short ch;
+       short ch;
 {
        return( (ch == 'a') ||
                (ch == 'e') ||
@@ -391,6 +400,7 @@ short ch;
                (ch == 'u') );
 }
 
+void
 sell_pack()
 {
        object *obj;
@@ -423,12 +433,14 @@ sell_pack()
        message("", 0);
 }
 
+int
 get_value(obj)
-object *obj;
+       const object *obj;
 {
        short wc;
        int val;
 
+       val = 0;
        wc = obj->which_kind;
 
        switch(obj->what_is) {
@@ -470,6 +482,7 @@ object *obj;
        return(val);
 }
 
+void
 id_all()
 {
        short i;
@@ -491,8 +504,10 @@ id_all()
        }
 }
 
+int
 name_cmp(s1, s2)
-char *s1, *s2;
+       char *s1;
+       const char *s2;
 {
        short i = 0;
        int r;
@@ -506,9 +521,10 @@ char *s1, *s2;
        return(r);
 }
 
+void
 xxxx(buf, n)
-char *buf;
-short n;
+       char *buf;
+       short n;
 {
        short i;
        unsigned char c;
@@ -524,7 +540,7 @@ short n;
 
 long
 xxx(st)
-boolean st;
+       boolean st;
 {
        static long f, s;
        long r;
@@ -540,8 +556,10 @@ boolean st;
        return(r);
 }
 
+void
 nickize(buf, score, n_name)
-char *buf, *score, *n_name;
+       char *buf;
+       const char *score, *n_name;
 {
        short i = 15, j;
 
@@ -565,9 +583,10 @@ char *buf, *score, *n_name;
        }
 }
 
+void
 center(row, buf)
-short row;
-char *buf;
+       short row;
+       const char *buf;
 {
        short margin;
 
@@ -575,6 +594,7 @@ char *buf;
        mvaddstr(row, margin, buf);
 }
 
+void
 sf_error()
 {
        md_lock(0);