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