-/* $NetBSD: main.c,v 1.4 1995/04/22 10:59:10 cgd Exp $ */
+/* $NetBSD: main.c,v 1.23 2011/08/29 20:30:37 joerg Exp $ */
/*
* Copyright (c) 1980, 1993
* 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 copyright[] =
-"@(#) Copyright (c) 1980, 1993\n\
- The Regents of the University of California. All rights reserved.\n";
+__COPYRIGHT("@(#) Copyright (c) 1980, 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
-static char rcsid[] = "$NetBSD: main.c,v 1.4 1995/04/22 10:59:10 cgd Exp $";
+__RCSID("$NetBSD: main.c,v 1.23 2011/08/29 20:30:37 joerg Exp $");
#endif
#endif /* not lint */
-# include "trek.h"
-# include <stdio.h>
-# include <setjmp.h>
-# include <termios.h>
+#include <stdio.h>
+#include <setjmp.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <err.h>
+#include <time.h>
+#include <sys/types.h>
+#include "trek.h"
+#include "getpar.h"
-# define PRIO 00 /* default priority */
-
-int Mother = 51 + (51 << 8);
/*
** #### ##### # #### ##### #### ##### # #
**
** Many things in trek are not as clear as they might be, but are
** done to reduce space. I compile with the -f and -O flags. I
-** am constrained to running with non-seperated I/D space, since
+** am constrained to running with non-separated I/D space, since
** we don't have doubleing point hardware here; even if we did, I
** would like trek to be available to the large number of people
** who either have an 11/40 or do not have FP hardware. I also
jmp_buf env;
-main(argc, argv)
-int argc;
-char **argv;
+__dead static void
+usage(const char *av0)
{
- long vect;
- /* extern FILE *f_log; */
- register char opencode;
- int prio;
- register int ac;
- register char **av;
- struct termios argp;
-
- av = argv;
- ac = argc;
- av++;
- time(&vect);
- srand(vect);
- opencode = 'w';
- prio = PRIO;
-
- if (tcgetattr(1, &argp) == 0)
- {
- if (cfgetispeed(&argp) < B1200)
- Etc.fast++;
- }
+ errx(1, "Usage: %s [-fs]", av0);
+}
- while (ac > 1 && av[0][0] == '-')
- {
- switch (av[0][1])
- {
- case 'a': /* append to log file */
- opencode = 'a';
- break;
+int
+main(int argc, char **argv)
+{
+ int ch;
+
+ /* Revoke setgid privileges */
+ setgid(getgid());
+ /* Default to fast mode */
+ Etc.fast = 1;
+
+ srandom((long) time(NULL));
+
+ while ((ch = getopt(argc, argv, "fst")) != -1) {
+ switch (ch) {
case 'f': /* set fast mode */
Etc.fast++;
break;
Etc.fast = 0;
break;
-# ifdef xTRACE
+#ifdef xTRACE
case 't': /* trace */
- if (getuid() != Mother)
- goto badflag;
Trace++;
break;
-# endif
-
- case 'p': /* set priority */
- if (getuid() != Mother)
- goto badflag;
- prio = atoi(av[0] + 2);
- break;
+#endif
default:
- badflag:
- printf("Invalid option: %s\n", av[0]);
-
+ usage(argv[0]);
}
- ac--;
- av++;
}
- if (ac > 2)
- syserr(0, "arg count");
- /*
- if (ac > 1)
- f_log = fopen(av[0], opencode);
- */
+ if (optind < argc)
+ usage(argv[0]);
- printf("\n * * * S T A R T R E K * * *\n\nPress return to continue.\n");
+ printf("\n * * * S T A R T R E K * * *\n\n"
+ "Press return to continue.\n");
- if (setjmp(env))
- {
+ if (setjmp(env)) {
if ( !getynpar("Another game") )
exit(0);
}
- do
- {
+
+ do {
setup();
play();
} while (getynpar("Another game"));
fflush(stdout);
+ return 0;
}