diff options
author | Paul Janzen <pjanzen@cvs.openbsd.org> | 1998-07-09 04:34:26 +0000 |
---|---|---|
committer | Paul Janzen <pjanzen@cvs.openbsd.org> | 1998-07-09 04:34:26 +0000 |
commit | 421fa4553e0a54a294d9a3f290caf2a4ac9f42f4 (patch) | |
tree | 3f60c3f41ff4c536bcc103fc740f9079253d7e33 /games | |
parent | 6bd989631ae6970561e987ef8c300c88e29f0cef (diff) |
Scorefile bugfix and minor code cleaning, some from NetBSD
Diffstat (limited to 'games')
-rw-r--r-- | games/robots/extern.c | 7 | ||||
-rw-r--r-- | games/robots/flush_in.c | 7 | ||||
-rw-r--r-- | games/robots/init_field.c | 10 | ||||
-rw-r--r-- | games/robots/main.c | 85 | ||||
-rw-r--r-- | games/robots/make_level.c | 9 | ||||
-rw-r--r-- | games/robots/move.c | 24 | ||||
-rw-r--r-- | games/robots/move_robs.c | 17 | ||||
-rw-r--r-- | games/robots/play_level.c | 7 | ||||
-rw-r--r-- | games/robots/query.c | 8 | ||||
-rw-r--r-- | games/robots/rnd_pos.c | 16 | ||||
-rw-r--r-- | games/robots/robots.h | 92 | ||||
-rw-r--r-- | games/robots/score.c | 48 |
12 files changed, 186 insertions, 144 deletions
diff --git a/games/robots/extern.c b/games/robots/extern.c index 88cbac1a69f..5f49b465f4e 100644 --- a/games/robots/extern.c +++ b/games/robots/extern.c @@ -1,3 +1,4 @@ +/* $OpenBSD: extern.c,v 1.2 1998/07/09 04:34:12 pjanzen Exp $ */ /* $NetBSD: extern.c,v 1.3 1995/04/22 10:08:49 cgd Exp $ */ /* @@ -37,11 +38,11 @@ #if 0 static char sccsid[] = "@(#)extern.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: extern.c,v 1.3 1995/04/22 10:08:49 cgd Exp $"; +static char rcsid[] = "$OpenBSD: extern.c,v 1.2 1998/07/09 04:34:12 pjanzen Exp $"; #endif #endif /* not lint */ -# include "robots.h" +#include "robots.h" bool Dead; /* Player is now dead */ bool Full_clear = TRUE; /* Lots of junk for init_field to clear */ @@ -60,7 +61,7 @@ bool Waiting; /* Player is waiting for end */ bool Was_bonus = FALSE; /* Was a bonus last level */ char Cnt_move; /* Command which has preceded the count */ -char Field[Y_FIELDSIZE][X_FIELDSIZE]; /* the playing field itslef */ +char Field[Y_FIELDSIZE][X_FIELDSIZE]; /* the playing field itself */ char *Next_move; /* Next move to be used in the pattern */ char *Move_list = "YHBJNLUK";/* List of moves in the pattern */ char Run_ch; /* Character for the direction we are running */ diff --git a/games/robots/flush_in.c b/games/robots/flush_in.c index fecc483858b..22ce94186df 100644 --- a/games/robots/flush_in.c +++ b/games/robots/flush_in.c @@ -1,3 +1,4 @@ +/* $OpenBSD: flush_in.c,v 1.2 1998/07/09 04:34:13 pjanzen Exp $ */ /* $NetBSD: flush_in.c,v 1.4 1995/04/28 23:09:08 mycroft Exp $ */ /* @@ -37,17 +38,17 @@ #if 0 static char sccsid[] = "@(#)flush_in.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: flush_in.c,v 1.4 1995/04/28 23:09:08 mycroft Exp $"; +static char rcsid[] = "$OpenBSD: flush_in.c,v 1.2 1998/07/09 04:34:13 pjanzen Exp $"; #endif #endif /* not lint */ -# include <stdio.h> -# include <termios.h> +#include "robots.h" /* * flush_in: * Flush all pending input. */ +void flush_in() { tcflush(fileno(stdin), TCIFLUSH); diff --git a/games/robots/init_field.c b/games/robots/init_field.c index 2db36857b67..8f6e31f19c4 100644 --- a/games/robots/init_field.c +++ b/games/robots/init_field.c @@ -1,3 +1,4 @@ +/* $OpenBSD: init_field.c,v 1.3 1998/07/09 04:34:15 pjanzen Exp $ */ /* $NetBSD: init_field.c,v 1.3 1995/04/22 10:08:52 cgd Exp $ */ /* @@ -37,22 +38,21 @@ #if 0 static char sccsid[] = "@(#)init_field.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: init_field.c,v 1.3 1995/04/22 10:08:52 cgd Exp $"; +static char rcsid[] = "$OpenBSD: init_field.c,v 1.3 1998/07/09 04:34:15 pjanzen Exp $"; #endif #endif /* not lint */ -# include "robots.h" +#include "robots.h" /* * init_field: - * Lay down the initial pattern whih is constant across all levels, + * Lay down the initial pattern which is constant across all levels, * and initialize all the global variables. */ +void init_field() { register int i; - register WINDOW *wp; - register int j; static bool first = TRUE; static char *desc[] = { "Directions:", diff --git a/games/robots/main.c b/games/robots/main.c index 2969cd85d3b..a2adddc02cf 100644 --- a/games/robots/main.c +++ b/games/robots/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.5 1997/02/05 18:28:35 kstailey Exp $ */ +/* $OpenBSD: main.c,v 1.6 1998/07/09 04:34:16 pjanzen Exp $ */ /* $NetBSD: main.c,v 1.5 1995/04/22 10:08:54 cgd Exp $ */ /* @@ -44,29 +44,26 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: main.c,v 1.5 1995/04/22 10:08:54 cgd Exp $"; +static char rcsid[] = "$OpenBSD: main.c,v 1.6 1998/07/09 04:34:16 pjanzen Exp $"; #endif #endif /* not lint */ -# include "robots.h" -# include <signal.h> -# include <ctype.h> +#include "robots.h" +int main(ac, av) -int ac; -char **av; + int ac; + char **av; { register char *sp; register bool bad_arg; register bool show_only; extern char *Scorefile; - extern int Max_per_uid; - int score_wfd; /* high score writable file descriptor */ - void quit(); + int score_wfd; /* high score writable file descriptor */ + int score_err = 0; /* hold errno from score file open */ - if ((score_wfd = open(Scorefile, 2)) < 0) { - perror(Scorefile); - exit(1); + if ((score_wfd = open(Scorefile, O_RDWR)) < 0) { + score_err = errno; } /* revoke */ @@ -77,33 +74,26 @@ char **av; if (ac > 1) { bad_arg = FALSE; for (++av; ac > 1 && *av[0]; av++, ac--) - if (av[0][0] != '-') - if (isdigit(av[0][0])) - Max_per_uid = atoi(av[0]); - else { - Scorefile = av[0]; -# ifdef FANCY - sp = strrchr(Scorefile, '/'); - if (sp == NULL) - sp = Scorefile; + if (av[0][0] != '-') { + Scorefile = av[0]; + sp = strrchr(Scorefile, '/'); + if (sp == NULL) + sp = Scorefile; + if (score_wfd >= 0) close(score_wfd); - /* This file is in the current directory */ - /* and requires no special privileges: */ - if ((score_wfd = - open(Scorefile, 2)) < 0) { - perror(Scorefile); - exit(1); - } - - if (strcmp(sp, "pattern_roll") == 0) - Pattern_roll = TRUE; - else if (strcmp(sp, "stand_still") == 0) - Stand_still = TRUE; - if (Pattern_roll || Stand_still) - Teleport = TRUE; -# endif - } - else + /* This file is in the current directory */ + /* and requires no special privileges: */ + if ((score_wfd = open(Scorefile, O_RDWR)) < 0) + score_err = errno; +#ifdef FANCY + if (strcmp(sp, "pattern_roll") == 0) + Pattern_roll = TRUE; + else if (strcmp(sp, "stand_still") == 0) + Stand_still = TRUE; + if (Pattern_roll || Stand_still) + Teleport = TRUE; +#endif + } else for (sp = &av[0][1]; *sp; sp++) switch (*sp) { case 's': @@ -122,7 +112,7 @@ char **av; Teleport = TRUE; break; default: - fprintf(stderr, "robots: uknown option: %c\n", *sp); + fprintf(stderr, "robots: unknown option: %c\n", *sp); bad_arg = TRUE; break; } @@ -135,7 +125,11 @@ char **av; if (show_only) { show_score(); exit(0); - /* NOTREACHED */ + } + + if (score_wfd < 0) { + fprintf(stderr, "%s: %s\n", Scorefile, strerror(score_err)); + exit(1); } initscr(); @@ -154,7 +148,7 @@ char **av; stdscr = newwin(Y_SIZE, X_SIZE, 0, 0); } - srand(getpid()); + srandom(getpid()); if (Real_time) signal(SIGALRM, move_robots); do { @@ -168,7 +162,8 @@ char **av; refresh(); score(score_wfd); } while (another()); - quit(); + quit(0); + /* NOT REACHED */ } void @@ -183,7 +178,8 @@ __cputchar(ch) * Leave the program elegantly. */ void -quit() +quit(dummy) + int dummy; { endwin(); exit(0); @@ -194,6 +190,7 @@ quit() * another: * See if another game is desired */ +bool another() { register int y; diff --git a/games/robots/make_level.c b/games/robots/make_level.c index 998155db943..f93534d911f 100644 --- a/games/robots/make_level.c +++ b/games/robots/make_level.c @@ -1,3 +1,4 @@ +/* $OpenBSD: make_level.c,v 1.2 1998/07/09 04:34:17 pjanzen Exp $ */ /* $NetBSD: make_level.c,v 1.3 1995/04/22 10:08:56 cgd Exp $ */ /* @@ -37,22 +38,22 @@ #if 0 static char sccsid[] = "@(#)make_level.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: make_level.c,v 1.3 1995/04/22 10:08:56 cgd Exp $"; +static char rcsid[] = "$OpenBSD: make_level.c,v 1.2 1998/07/09 04:34:17 pjanzen Exp $"; #endif #endif /* not lint */ -# include "robots.h" +#include "robots.h" /* * make_level: * Make the current level */ +void make_level() { register int i; register COORD *cp; - register WINDOW *wp; - register int x, *endp; + register int x; reset_count(); for (i = 1; i < Y_FIELDSIZE; i++) diff --git a/games/robots/move.c b/games/robots/move.c index 787a23fc630..5af6b3933d2 100644 --- a/games/robots/move.c +++ b/games/robots/move.c @@ -1,3 +1,4 @@ +/* $OpenBSD: move.c,v 1.3 1998/07/09 04:34:18 pjanzen Exp $ */ /* $NetBSD: move.c,v 1.4 1995/04/22 10:08:58 cgd Exp $ */ /* @@ -37,25 +38,25 @@ #if 0 static char sccsid[] = "@(#)move.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: move.c,v 1.4 1995/04/22 10:08:58 cgd Exp $"; +static char rcsid[] = "$OpenBSD: move.c,v 1.3 1998/07/09 04:34:18 pjanzen Exp $"; #endif #endif /* not lint */ -#include <sys/ttydefaults.h> -#include <ctype.h> #include "robots.h" -# define ESC '\033' +#define ESC '\033' /* * get_move: * Get and execute a move from the player */ +void get_move() { register int c; - register int y, x, lastmove; - static COORD newpos; +#ifdef FANCY + int lastmove; +#endif if (Waiting) return; @@ -156,7 +157,7 @@ over: case 'q': case 'Q': if (query("Really quit?")) - quit(); + quit(0); refresh(); break; case 'w': @@ -201,6 +202,7 @@ ret: * Must I teleport; i.e., is there anywhere I can move without * being eaten? */ +bool must_telep() { register int x, y; @@ -232,8 +234,9 @@ must_telep() * do_move: * Execute a move */ +bool do_move(dy, dx) -int dy, dx; + int dy, dx; { static COORD newpos; @@ -268,8 +271,9 @@ int dy, dx; * eaten: * Player would get eaten at this place */ +bool eaten(pos) -register COORD *pos; + register COORD *pos; { register int x, y; @@ -290,6 +294,7 @@ register COORD *pos; * reset_count: * Reset the count variables */ +void reset_count() { Count = 0; @@ -302,6 +307,7 @@ reset_count() * jumping: * See if we are jumping, i.e., we should not refresh. */ +bool jumping() { return (Jump && (Count || Running || Waiting)); diff --git a/games/robots/move_robs.c b/games/robots/move_robs.c index 27bfb354404..ac2cf3eca83 100644 --- a/games/robots/move_robs.c +++ b/games/robots/move_robs.c @@ -1,3 +1,4 @@ +/* $OpenBSD: move_robs.c,v 1.2 1998/07/09 04:34:19 pjanzen Exp $ */ /* $NetBSD: move_robs.c,v 1.3 1995/04/22 10:08:59 cgd Exp $ */ /* @@ -37,12 +38,11 @@ #if 0 static char sccsid[] = "@(#)move_robs.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: move_robs.c,v 1.3 1995/04/22 10:08:59 cgd Exp $"; +static char rcsid[] = "$OpenBSD: move_robs.c,v 1.2 1998/07/09 04:34:19 pjanzen Exp $"; #endif #endif /* not lint */ -# include "robots.h" -# include <signal.h> +#include "robots.h" /* * move_robots: @@ -50,12 +50,9 @@ static char rcsid[] = "$NetBSD: move_robs.c,v 1.3 1995/04/22 10:08:59 cgd Exp $" */ void move_robots(was_sig) -bool was_sig; + bool was_sig; { register COORD *rp; - register int y, x; - register int mindist, d; - static COORD newpos; if (Real_time) signal(SIGALRM, move_robots); @@ -134,8 +131,9 @@ bool was_sig; * add_score: * Add a score to the overall point total */ +void add_score(add) -int add; + int add; { Score += add; move(Y_SCORE, X_SCORE); @@ -146,8 +144,9 @@ int add; * sign: * Return the sign of the number */ +int sign(n) -int n; + int n; { if (n < 0) return -1; diff --git a/games/robots/play_level.c b/games/robots/play_level.c index 8f5e1d405e8..07450f00f2a 100644 --- a/games/robots/play_level.c +++ b/games/robots/play_level.c @@ -1,3 +1,4 @@ +/* $OpenBSD: play_level.c,v 1.2 1998/07/09 04:34:20 pjanzen Exp $ */ /* $NetBSD: play_level.c,v 1.3 1995/04/22 10:09:03 cgd Exp $ */ /* @@ -47,10 +48,10 @@ static char rcsid[] = "$NetBSD: play_level.c,v 1.3 1995/04/22 10:09:03 cgd Exp $ * play_level: * Let the player play the current level */ +void play_level() { register COORD *cp; - register int y, x, bonus; move(My_pos.y, My_pos.x); addch(PLAYER); @@ -62,14 +63,14 @@ play_level() addch(ROBOT); } refresh(); -# ifdef DEBUG +#ifdef DEBUG standout(); move(Min.y, Min.x); addch(inch()); move(Max.y, Max.x); addch(inch()); standend(); -# endif DEBUG +#endif DEBUG setjmp(End_move); flush_in(); while (!Dead && Num_robots > 0) { diff --git a/games/robots/query.c b/games/robots/query.c index b33ed63cb33..65f116a68f1 100644 --- a/games/robots/query.c +++ b/games/robots/query.c @@ -1,3 +1,4 @@ +/* $OpenBSD: query.c,v 1.2 1998/07/09 04:34:21 pjanzen Exp $ */ /* $NetBSD: query.c,v 1.3 1995/04/22 10:09:05 cgd Exp $ */ /* @@ -37,18 +38,19 @@ #if 0 static char sccsid[] = "@(#)query.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: query.c,v 1.3 1995/04/22 10:09:05 cgd Exp $"; +static char rcsid[] = "$OpenBSD: query.c,v 1.2 1998/07/09 04:34:21 pjanzen Exp $"; #endif #endif /* not lint */ -# include "robots.h" +#include "robots.h" /* * query: * Ask a question and get a yes or no answer. Default is "no". */ +int query(prompt) -char *prompt; + char *prompt; { register int c, retval; register int y, x; diff --git a/games/robots/rnd_pos.c b/games/robots/rnd_pos.c index a08171bb758..e8f3ad5dbf8 100644 --- a/games/robots/rnd_pos.c +++ b/games/robots/rnd_pos.c @@ -1,4 +1,4 @@ -/* $NetBSD: rnd_pos.c,v 1.3 1995/04/22 10:09:07 cgd Exp $ */ +/* $OpenBSD: rnd_pos.c,v 1.2 1998/07/09 04:34:23 pjanzen Exp $ */ /* * Copyright (c) 1980, 1993 @@ -37,13 +37,13 @@ #if 0 static char sccsid[] = "@(#)rnd_pos.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: rnd_pos.c,v 1.3 1995/04/22 10:09:07 cgd Exp $"; +static char rcsid[] = "$OpenBSD: rnd_pos.c,v 1.2 1998/07/09 04:34:23 pjanzen Exp $"; #endif #endif /* not lint */ -# include "robots.h" +#include "robots.h" -# define IS_SAME(p,y,x) ((p).y != -1 && (p).y == y && (p).x == x) +#define IS_SAME(p,y,x) ((p).y != -1 && (p).y == y && (p).x == x) /* * rnd_pos: @@ -54,7 +54,6 @@ rnd_pos() { static COORD pos; static int call = 0; - register int i = 0; do { pos.y = rnd(Y_FIELDSIZE - 1) + 1; @@ -65,10 +64,9 @@ rnd_pos() return &pos; } +int rnd(range) -int range; + int range; { - unsigned int rand(); - - return rand() % range; + return (int)random() % range; } diff --git a/games/robots/robots.h b/games/robots/robots.h index 15261c50623..38f4aac49b3 100644 --- a/games/robots/robots.h +++ b/games/robots/robots.h @@ -1,3 +1,4 @@ +/* $OpenBSD: robots.h,v 1.2 1998/07/09 04:34:24 pjanzen Exp $ */ /* $NetBSD: robots.h,v 1.5 1995/04/24 12:24:54 cgd Exp $ */ /* @@ -35,37 +36,48 @@ * @(#)robots.h 8.1 (Berkeley) 5/31/93 */ -# include <curses.h> -# include <setjmp.h> -# include <string.h> +#include <sys/ttydefaults.h> +#include <sys/types.h> +#include <ctype.h> +#include <curses.h> +#include <err.h> +#include <errno.h> +#include <fcntl.h> +#include <pwd.h> +#include <setjmp.h> +#include <signal.h> +#include <string.h> +#include <stdlib.h> +#include <termios.h> +#include <unistd.h> /* * miscellaneous constants */ -# define Y_FIELDSIZE 23 -# define X_FIELDSIZE 60 -# define Y_SIZE 24 -# define X_SIZE 80 -# define MAXLEVELS 4 -# define MAXROBOTS (MAXLEVELS * 10) -# define ROB_SCORE 10 -# define S_BONUS (60 * ROB_SCORE) -# define Y_SCORE 21 -# define X_SCORE (X_FIELDSIZE + 9) -# define Y_PROMPT (Y_FIELDSIZE - 1) -# define X_PROMPT (X_FIELDSIZE + 2) -# define MAXSCORES (Y_SIZE - 2) -# define MAXNAME 16 -# define MS_NAME "Ten" +#define Y_FIELDSIZE 23 +#define X_FIELDSIZE 60 +#define Y_SIZE 24 +#define X_SIZE 80 +#define MAXLEVELS 4 +#define MAXROBOTS (MAXLEVELS * 10) +#define ROB_SCORE 10 +#define S_BONUS (60 * ROB_SCORE) +#define Y_SCORE 21 +#define X_SCORE (X_FIELDSIZE + 9) +#define Y_PROMPT (Y_FIELDSIZE - 1) +#define X_PROMPT (X_FIELDSIZE + 2) +#define MAXSCORES (Y_SIZE - 2) +#define MAXNAME 16 +#define MS_NAME "Ten" /* * characters on screen */ -# define ROBOT '+' -# define HEAP '*' -# define PLAYER '@' +#define ROBOT '+' +#define HEAP '*' +#define PLAYER '@' /* * type definitions @@ -75,6 +87,14 @@ typedef struct { int y, x; } COORD; +typedef struct { + uid_t s_uid; + int s_score; + char s_name[MAXNAME]; +} SCORE; + +typedef struct passwd PASSWD; + /* * global variables */ @@ -100,11 +120,25 @@ extern jmp_buf End_move; * functions types */ -int cmp_sc(); -void move_robots(); - -COORD *rnd_pos(); - - - - +void add_score __P((int)); +bool another __P((void)); +int cmp_sc __P((const void *, const void *)); +bool do_move __P((int, int)); +bool eaten __P((COORD *)); +void flush_in __P((void)); +void get_move __P((void)); +void init_field __P((void)); +bool jumping __P((void)); +void make_level __P((void)); +void move_robots __P((int)); +bool must_telep __P((void)); +void play_level __P((void)); +int query __P((char *)); +void quit __P((int)); +void reset_count __P((void)); +int rnd __P((int)); +COORD *rnd_pos __P((void)); +void score __P((int)); +void set_name __P((SCORE *)); +void show_score __P((void)); +int sign __P((int)); diff --git a/games/robots/score.c b/games/robots/score.c index 955831881f4..46b4d20c217 100644 --- a/games/robots/score.c +++ b/games/robots/score.c @@ -1,4 +1,4 @@ -/* $OpenBSD: score.c,v 1.3 1997/02/05 18:28:36 kstailey Exp $ */ +/* $OpenBSD: score.c,v 1.4 1998/07/09 04:34:25 pjanzen Exp $ */ /* $NetBSD: score.c,v 1.3 1995/04/22 10:09:12 cgd Exp $ */ /* @@ -38,25 +38,19 @@ #if 0 static char sccsid[] = "@(#)score.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: score.c,v 1.3 1995/04/22 10:09:12 cgd Exp $"; +static char rcsid[] = "$OpenBSD: score.c,v 1.4 1998/07/09 04:34:25 pjanzen Exp $"; #endif #endif /* not lint */ -# include "robots.h" -# include <sys/types.h> -# include <pwd.h> -# include "pathnames.h" - -typedef struct { - int s_uid; - int s_score; - char s_name[MAXNAME]; -} SCORE; - -typedef struct passwd PASSWD; +#include "robots.h" +#include "pathnames.h" char *Scorefile = _PATH_SCORE; +#ifndef MAX_PER_UID +#define MAX_PER_UID 5 +#endif + int Max_per_uid = MAX_PER_UID; static SCORE Top[MAXSCORES]; @@ -66,12 +60,13 @@ static SCORE Top[MAXSCORES]; * Post the player's score, if reasonable, and then print out the * top list. */ +void score(score_wfd) int score_wfd; { register int inf = score_wfd; register SCORE *scp; - register int uid; + uid_t uid; register bool done_show = FALSE; static int numscores, max_uid; @@ -112,6 +107,7 @@ score(score_wfd) if (!Newscore) { Full_clear = FALSE; fsync(inf); + lseek(inf, 0, SEEK_SET); return; } else @@ -123,7 +119,8 @@ score(score_wfd) move((scp - Top) + 1, 15); if (!done_show && scp->s_uid == uid && scp->s_score == Score) standout(); - printw(" %d\t%d\t%-8.8s ", (scp - Top) + 1, scp->s_score, scp->s_name); + printw(" %d\t%d\t%-*s ", (scp - Top) + 1, scp->s_score, + (int)(sizeof scp->s_name), scp->s_name); if (!done_show && scp->s_uid == uid && scp->s_score == Score) { standend(); done_show = TRUE; @@ -133,17 +130,19 @@ score(score_wfd) refresh(); if (Newscore) { - lseek(inf, 0L, 0); + lseek(inf, 0L, SEEK_SET); write(inf, &max_uid, sizeof max_uid); write(inf, Top, sizeof Top); } fsync(inf); + lseek(inf, 0, SEEK_SET); } +void set_name(scp) -register SCORE *scp; + SCORE *scp; { - register PASSWD *pp; + PASSWD *pp; if ((pp = getpwuid(scp->s_uid)) == NULL) pp->pw_name = "???"; @@ -154,23 +153,25 @@ register SCORE *scp; * cmp_sc: * Compare two scores. */ +int cmp_sc(s1, s2) -register SCORE *s1, *s2; + const void *s1, *s2; { - return s2->s_score - s1->s_score; + return ((SCORE *)s2)->s_score - ((SCORE *)s1)->s_score; } /* * show_score: * Show the score list for the '-s' option. */ +void show_score() { register SCORE *scp; register int inf; static int max_score; - if ((inf = open(Scorefile, 0)) < 0) { + if ((inf = open(Scorefile, O_RDONLY)) < 0) { perror(Scorefile); return; } @@ -184,5 +185,6 @@ show_score() inf = 1; for (scp = Top; scp < &Top[MAXSCORES]; scp++) if (scp->s_score >= 0) - printf("%d\t%d\t%.*s\n", inf++, scp->s_score, sizeof scp->s_name, scp->s_name); + printf("%d\t%d\t%.*s\n", inf++, scp->s_score, + (int)(sizeof scp->s_name), scp->s_name); } |