121466Smckusick /*
2*60840Sbostic * Copyright (c) 1980, 1993
3*60840Sbostic * The Regents of the University of California. All rights reserved.
433690Sbostic *
542589Sbostic * %sccs.include.redist.c%
621466Smckusick */
721466Smckusick
821466Smckusick #ifndef lint
9*60840Sbostic static char copyright[] =
10*60840Sbostic "@(#) Copyright (c) 1980, 1993\n\
11*60840Sbostic The Regents of the University of California. All rights reserved.\n";
1233690Sbostic #endif /* not lint */
1321466Smckusick
1421466Smckusick #ifndef lint
15*60840Sbostic static char sccsid[] = "@(#)main.c 8.1 (Berkeley) 05/31/93";
1633690Sbostic #endif /* not lint */
1721466Smckusick
1821466Smckusick # include "robots.h"
1921466Smckusick # include <signal.h>
2021466Smckusick # include <ctype.h>
2121466Smckusick
main(ac,av)2221466Smckusick main(ac, av)
2321466Smckusick int ac;
2421466Smckusick char **av;
2521466Smckusick {
2621466Smckusick register char *sp;
2721466Smckusick register bool bad_arg;
2821466Smckusick register bool show_only;
2921466Smckusick extern char *Scorefile;
3021466Smckusick extern int Max_per_uid;
3146757Sbostic void quit();
3221466Smckusick
3321466Smckusick show_only = FALSE;
3421466Smckusick if (ac > 1) {
3521466Smckusick bad_arg = FALSE;
3621466Smckusick for (++av; ac > 1 && *av[0]; av++, ac--)
3721466Smckusick if (av[0][0] != '-')
3821466Smckusick if (isdigit(av[0][0]))
3921466Smckusick Max_per_uid = atoi(av[0]);
4021466Smckusick else {
4121466Smckusick setuid(getuid());
4221466Smckusick setgid(getgid());
4321466Smckusick Scorefile = av[0];
4421466Smckusick # ifdef FANCY
4521466Smckusick sp = rindex(Scorefile, '/');
4621466Smckusick if (sp == NULL)
4721466Smckusick sp = Scorefile;
4821466Smckusick if (strcmp(sp, "pattern_roll") == 0)
4921466Smckusick Pattern_roll = TRUE;
5021466Smckusick else if (strcmp(sp, "stand_still") == 0)
5121466Smckusick Stand_still = TRUE;
5221466Smckusick if (Pattern_roll || Stand_still)
5321466Smckusick Teleport = TRUE;
5421466Smckusick # endif
5521466Smckusick }
5621466Smckusick else
5721466Smckusick for (sp = &av[0][1]; *sp; sp++)
5821466Smckusick switch (*sp) {
5921466Smckusick case 's':
6021466Smckusick show_only = TRUE;
6121466Smckusick break;
6221466Smckusick case 'r':
6321466Smckusick Real_time = TRUE;
6421466Smckusick break;
6521466Smckusick case 'a':
6621466Smckusick Start_level = 4;
6721466Smckusick break;
6821466Smckusick case 'j':
6921466Smckusick Jump = TRUE;
7021466Smckusick break;
7121466Smckusick case 't':
7221466Smckusick Teleport = TRUE;
7321466Smckusick break;
7421466Smckusick default:
7521466Smckusick fprintf(stderr, "robots: uknown option: %c\n", *sp);
7621466Smckusick bad_arg = TRUE;
7721466Smckusick break;
7821466Smckusick }
7921466Smckusick if (bad_arg) {
8021466Smckusick exit(1);
8121466Smckusick /* NOTREACHED */
8221466Smckusick }
8321466Smckusick }
8421466Smckusick
8521466Smckusick if (show_only) {
8621466Smckusick show_score();
8721466Smckusick exit(0);
8821466Smckusick /* NOTREACHED */
8921466Smckusick }
9021466Smckusick
9121466Smckusick initscr();
9221466Smckusick signal(SIGINT, quit);
9321466Smckusick crmode();
9421466Smckusick noecho();
9521466Smckusick nonl();
9621466Smckusick if (LINES != Y_SIZE || COLS != X_SIZE) {
9721466Smckusick if (LINES < Y_SIZE || COLS < X_SIZE) {
9821466Smckusick endwin();
9946757Sbostic printf("Need at least a %dx%d screen\n",
10046757Sbostic Y_SIZE, X_SIZE);
10121466Smckusick exit(1);
10221466Smckusick }
10321466Smckusick delwin(stdscr);
10421466Smckusick stdscr = newwin(Y_SIZE, X_SIZE, 0, 0);
10521466Smckusick }
10621466Smckusick
10721466Smckusick srand(getpid());
10821466Smckusick if (Real_time)
10921466Smckusick signal(SIGALRM, move_robots);
11021466Smckusick do {
11121466Smckusick init_field();
11221466Smckusick for (Level = Start_level; !Dead; Level++) {
11321466Smckusick make_level();
11421466Smckusick play_level();
11521466Smckusick }
11621466Smckusick move(My_pos.y, My_pos.x);
11721466Smckusick printw("AARRrrgghhhh....");
11821466Smckusick refresh();
11921466Smckusick score();
12021466Smckusick } while (another());
12121466Smckusick quit();
12221466Smckusick }
12321466Smckusick
12456099Selan void
__cputchar(ch)12556099Selan __cputchar(ch)
12656099Selan int ch;
12756099Selan {
12856099Selan (void)putchar(ch);
12956099Selan }
13056099Selan
13121466Smckusick /*
13221466Smckusick * quit:
13321466Smckusick * Leave the program elegantly.
13421466Smckusick */
13546757Sbostic void
quit()13621466Smckusick quit()
13721466Smckusick {
13857471Sbostic endwin();
13921466Smckusick exit(0);
14021466Smckusick /* NOTREACHED */
14121466Smckusick }
14221466Smckusick
14321466Smckusick /*
14421466Smckusick * another:
14521466Smckusick * See if another game is desired
14621466Smckusick */
another()14721466Smckusick another()
14821466Smckusick {
14921466Smckusick register int y;
15021466Smckusick
15121466Smckusick #ifdef FANCY
15221466Smckusick if ((Stand_still || Pattern_roll) && !Newscore)
15321466Smckusick return TRUE;
15421466Smckusick #endif
15521466Smckusick
15621466Smckusick if (query("Another game?")) {
15721466Smckusick if (Full_clear) {
15821466Smckusick for (y = 1; y <= Num_scores; y++) {
15921466Smckusick move(y, 1);
16021466Smckusick clrtoeol();
16121466Smckusick }
16221466Smckusick refresh();
16321466Smckusick }
16421466Smckusick return TRUE;
16521466Smckusick }
16621466Smckusick return FALSE;
16721466Smckusick }
168