teach.c revision 1.10
1/*	$OpenBSD: teach.c,v 1.10 2001/07/09 07:04:28 deraadt Exp $	*/
2
3/*
4 * Copyright (c) 1980, 1993
5 *	The Regents of the University of California.  All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 *    must display the following acknowledgement:
17 *	This product includes software developed by the University of
18 *	California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 *    may be used to endorse or promote products derived from this software
21 *    without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36#ifndef lint
37static char copyright[] =
38"@(#) Copyright (c) 1980, 1993\n\
39	The Regents of the University of California.  All rights reserved.\n";
40#endif /* not lint */
41
42#ifndef lint
43#if 0
44static char sccsid[] = "@(#)teach.c	8.1 (Berkeley) 5/31/93";
45#else
46static char rcsid[] = "$OpenBSD: teach.c,v 1.10 2001/07/09 07:04:28 deraadt Exp $";
47#endif
48#endif /* not lint */
49
50#include <err.h>
51#include "back.h"
52#include "tutor.h"
53
54extern speed_t ospeed;		/* tty output speed for termlib */
55
56const char   *const helpm[] = {
57	"\nEnter a space or newline to roll, or",
58	"     b   to display the board",
59	"     d   to double",
60	"     q   to quit\n",
61	0
62};
63
64const char   *const contin[] = {
65	"",
66	0
67};
68
69int
70main(argc, argv)
71	int     argc;
72	char   *argv[];
73{
74	int     i;
75
76	/* revoke privs */
77	setegid(getgid());
78	setgid(getgid());
79
80	signal(SIGINT, getout);
81	initcurses();
82	text(hello);
83	text(list);
84	i = text(contin);
85	if (i == 0)
86		i = 2;
87	init();
88	while (i)
89		switch (i) {
90		case 1:
91			leave();	/* Does not return */
92			break;
93
94		case 2:
95			if ((i = text(intro1)))
96				break;
97			wrboard();
98			if ((i = text(intro2)))
99				break;
100
101		case 3:
102			if ((i = text(moves)))
103				break;
104
105		case 4:
106			if ((i = text(removepiece)))
107				break;
108
109		case 5:
110			if ((i = text(hits)))
111				break;
112
113		case 6:
114			if ((i = text(endgame)))
115				break;
116
117		case 7:
118			if ((i = text(doubl)))
119				break;
120
121		case 8:
122			if ((i = text(stragy)))
123				break;
124
125		case 9:
126			if ((i = text(prog)))
127				break;
128
129		case 10:
130			if ((i = text(lastch)))
131				break;
132		}
133	tutor();
134	/* NOT REACHED */
135}
136
137void
138leave()
139{
140	clear();
141	endwin();
142	execl(EXEC, "backgammon", "-n", args, (char *)NULL);
143	errx(1, "help! Backgammon program is missing!!");
144}
145