-/* $NetBSD: main.c,v 1.15 2005/08/10 17:53:28 rpaulo Exp $ */
+/* $NetBSD: main.c,v 1.20 2009/08/12 04:48:03 dholland Exp $ */
/*-
* Copyright (c) 1990, 1993
#include <sys/cdefs.h>
#ifndef lint
-__COPYRIGHT("@(#) Copyright (c) 1990, 1993\n\
- The Regents of the University of California. All rights reserved.\n");
+__COPYRIGHT("@(#) Copyright (c) 1990, 1993\
+ The Regents of the University of California. All rights reserved.");
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: main.c,v 1.15 2005/08/10 17:53:28 rpaulo Exp $");
+__RCSID("$NetBSD: main.c,v 1.20 2009/08/12 04:48:03 dholland Exp $");
#endif
#endif /* not lint */
extern FILE *yyin;
+static int read_file(const char *);
+static const char *default_game(void);
+static const char *okay_game(const char *);
+static int list_games(void);
+
int
main(int argc, char *argv[])
{
- int seed;
+ unsigned long seed;
int f_usage = 0, f_list = 0, f_showscore = 0;
int f_printpath = 0;
const char *file = NULL;
open_score_file();
(void)setgid(getgid());
- start_time = seed = time(NULL);
+ start_time = time(NULL);
+ seed = start_time;
- while ((ch = getopt(argc, argv, "ulstpg:f:r:")) != -1) {
+ while ((ch = getopt(argc, argv, ":u?lstpg:f:r:")) != -1) {
switch (ch) {
case '?':
case 'u':
}
if (optind < argc)
f_usage++;
- srandom((unsigned long)seed);
+ srandom(seed);
if (f_usage)
(void)fprintf(stderr,
if (f_printpath) {
char buf[100];
- (void)strcpy(buf, _PATH_GAMES);
- buf[strlen(buf) - 1] = '\0';
+ (void)strlcpy(buf, _PATH_GAMES, 100);
(void)puts(buf);
}
(void)signal(SIGQUIT, quit);
#ifdef BSD
(void)signal(SIGTSTP, SIG_IGN);
- (void)signal(SIGSTOP, SIG_IGN);
#endif
(void)signal(SIGHUP, log_score_quit);
(void)signal(SIGTERM, log_score_quit);
}
}
-int
+static int
read_file(const char *s)
{
int retval;
return (0);
}
-const char *
+static const char *
default_game(void)
{
FILE *fp;
static char file[256];
char line[256], games[256];
- (void)strcpy(games, _PATH_GAMES);
- (void)strcat(games, GAMES);
+ (void)strlcpy(games, _PATH_GAMES, 256);
+ (void)strlcat(games, GAMES, 256);
if ((fp = fopen(games, "r")) == NULL) {
warn("fopen %s", games);
}
if (fgets(line, sizeof(line), fp) == NULL) {
(void)fprintf(stderr, "%s: no default game available\n", games);
+ fclose(fp);
return (NULL);
}
(void)fclose(fp);
line[strlen(line) - 1] = '\0';
- (void)strcpy(file, _PATH_GAMES);
- (void)strcat(file, line);
+ (void)strlcpy(file, _PATH_GAMES, 256);
+ (void)strlcat(file, line, 256);
return (file);
}
-const char *
+static const char *
okay_game(const char *s)
{
FILE *fp;
const char *ret = NULL;
char line[256], games[256];
- (void)strcpy(games, _PATH_GAMES);
- (void)strcat(games, GAMES);
+ (void)strlcpy(games, _PATH_GAMES, 256);
+ (void)strlcat(games, GAMES, 256);
if ((fp = fopen(games, "r")) == NULL) {
warn("fopen %s", games);
while (fgets(line, sizeof(line), fp) != NULL) {
line[strlen(line) - 1] = '\0';
if (strcmp(s, line) == 0) {
- (void)strcpy(file, _PATH_GAMES);
- (void)strcat(file, line);
+ (void)strlcpy(file, _PATH_GAMES, 256);
+ (void)strlcat(file, line, 256);
ret = file;
break;
}
return (ret);
}
-int
+static int
list_games(void)
{
FILE *fp;
char line[256], games[256];
int num_games = 0;
- (void)strcpy(games, _PATH_GAMES);
- (void)strcat(games, GAMES);
+ (void)strlcpy(games, _PATH_GAMES, 256);
+ (void)strlcat(games, GAMES, 256);
if ((fp = fopen(games, "r")) == NULL) {
warn("fopen %s", games);