install approved copyright notice
[unix-history] / usr / src / games / backgammon / teachgammon / teach.c
CommitLineData
e0bbfbf9
DF
1/*
2 * Copyright (c) 1980 Regents of the University of California.
69fb7db6
KB
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms are permitted
65c7d3b6
KB
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
e0bbfbf9
DF
16 */
17
18#ifndef lint
69fb7db6
KB
19char copyright[] =
20"@(#) Copyright (c) 1980 Regents of the University of California.\n\
21 All rights reserved.\n";
22#endif /* not lint */
23
24#ifndef lint
65c7d3b6 25static char sccsid[] = "@(#)teach.c 5.5 (Berkeley) %G%";
69fb7db6 26#endif /* not lint */
7b90fd84
RH
27
28#include "back.h"
29
30char *hello[];
31char *list[];
32char *intro1[];
33char *intro2[];
34char *moves[];
35char *remove[];
36char *hits[];
37char *endgame[];
38char *doubl[];
39char *stragy[];
40char *prog[];
41char *lastch[];
42
43extern char ospeed; /* tty output speed for termlib */
44
45char *helpm[] = {
46 "\nEnter a space or newline to roll, or",
47 " b to display the board",
48 " d to double",
49 " q to quit\n",
50 0
51};
52
53char *contin[] = {
54 "",
55 0
56};
57
58main (argc,argv)
59int argc;
60char **argv;
61
62{
7b90fd84
RH
63 register int i;
64
65 signal (2,getout);
66 if (gtty (0,&tty) == -1) /* get old tty mode */
67 errexit ("teachgammon(gtty)");
68 old = tty.sg_flags;
69#ifdef V7
70 raw = ((noech = old & ~ECHO) | CBREAK); /* set up modes */
71#else
72 raw = ((noech = old & ~ECHO) | RAW); /* set up modes */
73#endif
8aff2760 74 ospeed = tty.sg_ospeed; /* for termlib */
7b90fd84
RH
75 tflag = getcaps (getenv ("TERM"));
76#ifdef V7
77 while (*++argv != 0)
78#else
79 while (*++argv != -1)
80#endif
81 getarg (&argv);
82 if (tflag) {
83 noech &= ~(CRMOD|XTABS);
84 raw &= ~(CRMOD|XTABS);
85 clear();
86 }
87 text (hello);
88 text (list);
89 i = text (contin);
90 if (i == 0)
91 i = 2;
92 init();
93 while (i)
94 switch (i) {
95
96 case 1:
97 leave();
98
99 case 2:
100 if (i = text(intro1))
101 break;
102 wrboard();
103 if (i = text(intro2))
104 break;
105
106 case 3:
107 if (i = text(moves))
108 break;
109
110 case 4:
111 if (i = text(remove))
112 break;
113
114 case 5:
115 if (i = text(hits))
116 break;
117
118 case 6:
119 if (i = text(endgame))
120 break;
121
122 case 7:
123 if (i = text(doubl))
124 break;
125
126 case 8:
127 if (i = text(stragy))
128 break;
129
130 case 9:
131 if (i = text(prog))
132 break;
133
134 case 10:
135 if (i = text(lastch))
136 break;
137 }
138 tutor();
139}
140
141leave() {
142 if (tflag)
143 clear();
144 else
145 writec ('\n');
146 fixtty(old);
147 execl (EXEC,"backgammon",args,"n",0);
148 writel ("Help! Backgammon program is missing\007!!\n");
149 exit (-1);
150}