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