-/* $NetBSD: main.c,v 1.8 1999/05/15 23:56:36 christos Exp $ */
+/* $NetBSD: main.c,v 1.18 2001/12/06 12:17:57 blymn Exp $ */
/*
* Copyright (c) 1980, 1993
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: main.c,v 1.8 1999/05/15 23:56:36 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.18 2001/12/06 12:17:57 blymn Exp $");
#endif
#endif /* not lint */
int main __P((int, char **));
+extern const char *Scorefile;
+extern int Max_per_uid;
+
int
main(ac, av)
int ac;
char **av;
{
- char *sp;
+ const char *sp;
bool bad_arg;
bool show_only;
- extern char *Scorefile;
- extern int Max_per_uid;
+ int score_wfd; /* high score writable file descriptor */
+ int score_err = 0; /* hold errno from score file open */
+
+ score_wfd = open(Scorefile, O_RDWR);
+ if (score_wfd < 0)
+ score_err = errno;
+ else if (score_wfd < 3)
+ exit(1);
+
+ /* Revoke setgid privileges */
+ setgid(getgid());
show_only = FALSE;
Num_games = 1;
if (isdigit(av[0][0]))
Max_per_uid = atoi(av[0]);
else {
- setuid(getuid());
- setgid(getgid());
Scorefile = av[0];
+ if (score_wfd >= 0)
+ close(score_wfd);
+ score_wfd = open(Scorefile, O_RDWR);
+ if (score_wfd < 0)
+ score_err = errno;
# ifdef FANCY
sp = strrchr(Scorefile, '/');
if (sp == NULL)
break;
default:
- fprintf(stderr, "robots: uknown option: %c\n", *sp);
+ fprintf(stderr, "robots: unknown option: %c\n", *sp);
bad_arg = TRUE;
break;
}
/* NOTREACHED */
}
+ if (score_wfd < 0) {
+ errno = score_err;
+ warn("%s", Scorefile);
+ warnx("High scores will not be recorded!");
+ sleep(2);
+ }
+
initscr();
signal(SIGINT, quit);
- crmode();
+ cbreak();
noecho();
nonl();
if (LINES != Y_SIZE || COLS != X_SIZE) {
refresh();
if (Auto_bot)
sleep(1);
- score();
+ score(score_wfd);
if (Auto_bot)
sleep(1);
refresh();
}
+ Num_games = 1;
} while (!Auto_bot && another());
quit(0);
/* NOTREACHED */
return(0);
}
-void
-__cputchar(ch)
- int ch;
-{
- (void)putchar(ch);
-}
-
/*
* quit:
* Leave the program elegantly.
*/
void
quit(dummy)
- int dummy;
+ int dummy __attribute__((__unused__));
{
endwin();
exit(0);