X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/098ef9272dbfc3deff7afcd768ea90836e72a163..9531e8dcad1d2c4c906171b67ac58bb4a6fbd5a4:/atc/main.c diff --git a/atc/main.c b/atc/main.c index 8ef87974..73508872 100644 --- a/atc/main.c +++ b/atc/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.6 1997/10/11 02:01:05 lukem Exp $ */ +/* $NetBSD: main.c,v 1.12 2001/02/05 00:22:52 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -55,13 +55,14 @@ __COPYRIGHT("@(#) Copyright (c) 1990, 1993\n\ #if 0 static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: main.c,v 1.6 1997/10/11 02:01:05 lukem Exp $"); +__RCSID("$NetBSD: main.c,v 1.12 2001/02/05 00:22:52 christos Exp $"); #endif #endif /* not lint */ #include "include.h" #include "pathnames.h" +extern FILE *yyin; int main(ac, av) @@ -71,63 +72,53 @@ main(ac, av) int seed; int f_usage = 0, f_list = 0, f_showscore = 0; int f_printpath = 0; - char *file = NULL; - char *name, *ptr; + const char *file = NULL; + int ch; struct sigaction sa; #ifdef BSD struct itimerval itv; #endif - start_time = seed = time(0); + /* Open the score file then revoke setgid privileges */ + open_score_file(); + setgid(getgid()); - name = *av++; - while (*av) { -#ifndef SAVEDASH - if (**av == '-') - ++*av; - else + start_time = seed = time(NULL); + + while ((ch = getopt(ac, av, "ulstpg:f:r:")) != -1) { + switch (ch) { + case '?': + case 'u': + default: + f_usage++; + break; + case 'l': + f_list++; + break; + case 's': + case 't': + f_showscore++; + break; + case 'p': + f_printpath++; + break; + case 'r': + seed = atoi(optarg); + break; + case 'f': + case 'g': + file = optarg; break; -#endif - ptr = *av++; - while (*ptr) { - switch (*ptr) { - case '?': - case 'u': - f_usage++; - break; - case 'l': - f_list++; - break; - case 's': - case 't': - f_showscore++; - break; - case 'p': - f_printpath++; - break; - case 'r': - seed = atoi(*av); - av++; - break; - case 'f': - case 'g': - file = *av; - av++; - break; - default: - warnx("unknown option '%c'\n", *ptr); - f_usage++; - break; - } - ptr++; } } + if (optind < ac) + f_usage++; srandom(seed); if (f_usage) fprintf(stderr, "Usage: %s -[u?lstp] [-[gf] game_name] [-r random seed]\n", - name); + av[0]); if (f_showscore) log_score(1); if (f_list) @@ -168,6 +159,7 @@ main(ac, av) tcgetattr(fileno(stdin), &tty_start); tty_new = tty_start; tty_new.c_lflag &= ~(ICANON|ECHO); + tty_new.c_iflag |= ICRNL; tty_new.c_cc[VMIN] = 1; tty_new.c_cc[VTIME] = 0; tcsetattr(fileno(stdin), TCSADRAIN, &tty_new); @@ -221,9 +213,8 @@ main(ac, av) int read_file(s) - char *s; + const char *s; { - extern FILE *yyin; int retval; file = s; @@ -241,7 +232,7 @@ read_file(s) return (0); } -char * +const char * default_game() { FILE *fp; @@ -266,13 +257,14 @@ default_game() return (file); } -char * +const char * okay_game(s) - char *s; + const char *s; { FILE *fp; static char file[256]; - char *ret = NULL, line[256], games[256]; + const char *ret = NULL; + char line[256], games[256]; strcpy(games, _PATH_GAMES); strcat(games, GAMES);