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
6 * provided that this notice is preserved and that due credit is given
7 * to the University of California at Berkeley. The name of the University
8 * may not be used to endorse or promote products derived from this
9 * software without specific prior written permission. This software
10 * is provided ``as is'' without express or implied warranty.
e0bbfbf9
DF
11 */
12
13#ifndef lint
69fb7db6
KB
14char copyright[] =
15"@(#) Copyright (c) 1980 Regents of the University of California.\n\
16 All rights reserved.\n";
17#endif /* not lint */
18
19#ifndef lint
20static char sccsid[] = "@(#)teach.c 5.4 (Berkeley) %G%";
21#endif /* not lint */
7b90fd84
RH
22
23#include "back.h"
24
25char *hello[];
26char *list[];
27char *intro1[];
28char *intro2[];
29char *moves[];
30char *remove[];
31char *hits[];
32char *endgame[];
33char *doubl[];
34char *stragy[];
35char *prog[];
36char *lastch[];
37
38extern char ospeed; /* tty output speed for termlib */
39
40char *helpm[] = {
41 "\nEnter a space or newline to roll, or",
42 " b to display the board",
43 " d to double",
44 " q to quit\n",
45 0
46};
47
48char *contin[] = {
49 "",
50 0
51};
52
53main (argc,argv)
54int argc;
55char **argv;
56
57{
7b90fd84
RH
58 register int i;
59
60 signal (2,getout);
61 if (gtty (0,&tty) == -1) /* get old tty mode */
62 errexit ("teachgammon(gtty)");
63 old = tty.sg_flags;
64#ifdef V7
65 raw = ((noech = old & ~ECHO) | CBREAK); /* set up modes */
66#else
67 raw = ((noech = old & ~ECHO) | RAW); /* set up modes */
68#endif
8aff2760 69 ospeed = tty.sg_ospeed; /* for termlib */
7b90fd84
RH
70 tflag = getcaps (getenv ("TERM"));
71#ifdef V7
72 while (*++argv != 0)
73#else
74 while (*++argv != -1)
75#endif
76 getarg (&argv);
77 if (tflag) {
78 noech &= ~(CRMOD|XTABS);
79 raw &= ~(CRMOD|XTABS);
80 clear();
81 }
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
91 case 1:
92 leave();
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(remove))
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}
135
136leave() {
137 if (tflag)
138 clear();
139 else
140 writec ('\n');
141 fixtty(old);
142 execl (EXEC,"backgammon",args,"n",0);
143 writel ("Help! Backgammon program is missing\007!!\n");
144 exit (-1);
145}