1 /*
2  * Copyright (c) 1980 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  */
6 
7 #ifndef lint
8 static char sccsid[] = "@(#)teach.c	5.2 (Berkeley) 03/17/87";
9 #endif not lint
10 
11 #include "back.h"
12 
13 char	*hello[];
14 char	*list[];
15 char	*intro1[];
16 char	*intro2[];
17 char	*moves[];
18 char	*remove[];
19 char	*hits[];
20 char	*endgame[];
21 char	*doubl[];
22 char	*stragy[];
23 char	*prog[];
24 char	*lastch[];
25 
26 extern char	ospeed;			/* tty output speed for termlib */
27 
28 char *helpm[] = {
29 	"\nEnter a space or newline to roll, or",
30 	"     b   to display the board",
31 	"     d   to double",
32 	"     q   to quit\n",
33 	0
34 };
35 
36 char *contin[] = {
37 	"",
38 	0
39 };
40 
41 main (argc,argv)
42 int	argc;
43 char	**argv;
44 
45 {
46 	register int	i;
47 
48 	signal (2,getout);
49 	if (gtty (0,&tty) == -1)			/* get old tty mode */
50 		errexit ("teachgammon(gtty)");
51 	old = tty.sg_flags;
52 #ifdef V7
53 	raw = ((noech = old & ~ECHO) | CBREAK);		/* set up modes */
54 #else
55 	raw = ((noech = old & ~ECHO) | RAW);		/* set up modes */
56 #endif
57 	ospeed = old.sg_ospeed;				/* for termlib */
58 	tflag = getcaps (getenv ("TERM"));
59 #ifdef V7
60 	while (*++argv != 0)
61 #else
62 	while (*++argv != -1)
63 #endif
64 		getarg (&argv);
65 	if (tflag)  {
66 		noech &= ~(CRMOD|XTABS);
67 		raw &= ~(CRMOD|XTABS);
68 		clear();
69 	}
70 	text (hello);
71 	text (list);
72 	i = text (contin);
73 	if (i == 0)
74 		i = 2;
75 	init();
76 	while (i)
77 		switch (i)  {
78 
79 		case 1:
80 			leave();
81 
82 		case 2:
83 			if (i = text(intro1))
84 				break;
85 			wrboard();
86 			if (i = text(intro2))
87 				break;
88 
89 		case 3:
90 			if (i = text(moves))
91 				break;
92 
93 		case 4:
94 			if (i = text(remove))
95 				break;
96 
97 		case 5:
98 			if (i = text(hits))
99 				break;
100 
101 		case 6:
102 			if (i = text(endgame))
103 				break;
104 
105 		case 7:
106 			if (i = text(doubl))
107 				break;
108 
109 		case 8:
110 			if (i = text(stragy))
111 				break;
112 
113 		case 9:
114 			if (i = text(prog))
115 				break;
116 
117 		case 10:
118 			if (i = text(lastch))
119 				break;
120 		}
121 	tutor();
122 }
123 
124 leave()  {
125 	if (tflag)
126 		clear();
127 	else
128 		writec ('\n');
129 	fixtty(old);
130 	execl (EXEC,"backgammon",args,"n",0);
131 	writel ("Help! Backgammon program is missing\007!!\n");
132 	exit (-1);
133 }
134