teach.c revision 1.21.6.1 1 /* $NetBSD: teach.c,v 1.21.6.1 2012/10/30 18:58:18 yamt 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. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 #ifndef lint
34 __COPYRIGHT("@(#) Copyright (c) 1980, 1993\
35 The Regents of the University of California. All rights reserved.");
36 #endif /* not lint */
37
38 #ifndef lint
39 #if 0
40 static char sccsid[] = "@(#)teach.c 8.1 (Berkeley) 5/31/93";
41 #else
42 __RCSID("$NetBSD: teach.c,v 1.21.6.1 2012/10/30 18:58:18 yamt Exp $");
43 #endif
44 #endif /* not lint */
45
46 #include "back.h"
47 #include "tutor.h"
48
49 static const char *const helpm[] = {
50 "\nEnter a space or newline to roll, or",
51 " b to display the board",
52 " d to double",
53 " q to quit\n",
54 0
55 };
56
57 static const char *const contin[] = {
58 "",
59 0
60 };
61
62 int
63 main(int argc __unused, char *argv[])
64 {
65 int i;
66 struct move mmstore, *mm;
67
68 /* revoke setgid privileges */
69 setgid(getgid());
70
71 signal(SIGINT, getout);
72 if (tcgetattr(0, &old) == -1) /* get old tty mode */
73 errexit("teachgammon(gtty)");
74 noech = old;
75 noech.c_lflag &= ~ECHO;
76 raw = noech;
77 raw.c_lflag &= ~ICANON; /* set up modes */
78 ospeed = cfgetospeed(&old); /* for termlib */
79 tflag = getcaps(getenv("TERM"));
80
81 /* need this now beceause getarg() may try to load a game */
82 mm = &mmstore;
83 move_init(mm);
84 while (*++argv != 0)
85 getarg(mm, &argv);
86 if (tflag) {
87 noech.c_oflag &= ~(ONLCR | OXTABS);
88 raw.c_oflag &= ~(ONLCR | OXTABS);
89 clear();
90 }
91 wrtext(hello);
92 wrtext(list);
93 i = wrtext(contin);
94 if (i == 0)
95 i = 2;
96 init();
97 while (i)
98 switch (i) {
99 case 1:
100 leave();
101
102 case 2:
103 if ((i = wrtext(intro1)) != 0)
104 break;
105 wrboard();
106 if ((i = wrtext(intro2)) != 0)
107 break;
108
109 case 3:
110 if ((i = wrtext(moves)) != 0)
111 break;
112
113 case 4:
114 if ((i = wrtext(removepiece)) != 0)
115 break;
116
117 case 5:
118 if ((i = wrtext(hits)) != 0)
119 break;
120
121 case 6:
122 if ((i = wrtext(endgame)) != 0)
123 break;
124
125 case 7:
126 if ((i = wrtext(doubl)) != 0)
127 break;
128
129 case 8:
130 if ((i = wrtext(stragy)) != 0)
131 break;
132
133 case 9:
134 if ((i = wrtext(prog)) != 0)
135 break;
136
137 case 10:
138 if ((i = wrtext(lastch)) != 0)
139 break;
140 }
141 tutor(mm);
142 /* NOTREACHED */
143 return (0);
144 }
145
146 void
147 leave(void)
148 {
149 if (tflag)
150 clear();
151 else
152 writec('\n');
153 fixtty(&old);
154 execl(EXEC, "backgammon", "-n", args[0]?args:0, (char *) 0);
155 writel("Help! Backgammon program is missing\007!!\n");
156 exit(1);
157 }
158