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