121219Sdist /*
2*60748Sbostic  * Copyright (c) 1980, 1993
3*60748Sbostic  *	The Regents of the University of California.  All rights reserved.
433487Sbostic  *
542567Sbostic  * %sccs.include.redist.c%
621219Sdist  */
76768Srrh 
821219Sdist #ifndef lint
9*60748Sbostic static char copyright[] =
10*60748Sbostic "@(#) Copyright (c) 1980, 1993\n\
11*60748Sbostic 	The Regents of the University of California.  All rights reserved.\n";
1233487Sbostic #endif /* not lint */
1321219Sdist 
1433487Sbostic #ifndef lint
15*60748Sbostic static char sccsid[] = "@(#)teach.c	8.1 (Berkeley) 05/31/93";
1633487Sbostic #endif /* not lint */
1733487Sbostic 
186768Srrh #include "back.h"
196768Srrh 
206768Srrh char	*hello[];
216768Srrh char	*list[];
226768Srrh char	*intro1[];
236768Srrh char	*intro2[];
246768Srrh char	*moves[];
256768Srrh char	*remove[];
266768Srrh char	*hits[];
276768Srrh char	*endgame[];
286768Srrh char	*doubl[];
296768Srrh char	*stragy[];
306768Srrh char	*prog[];
316768Srrh char	*lastch[];
326768Srrh 
336768Srrh extern char	ospeed;			/* tty output speed for termlib */
346768Srrh 
356768Srrh char *helpm[] = {
366768Srrh 	"\nEnter a space or newline to roll, or",
376768Srrh 	"     b   to display the board",
386768Srrh 	"     d   to double",
396768Srrh 	"     q   to quit\n",
406768Srrh 	0
416768Srrh };
426768Srrh 
436768Srrh char *contin[] = {
446768Srrh 	"",
456768Srrh 	0
466768Srrh };
476768Srrh 
main(argc,argv)486768Srrh main (argc,argv)
496768Srrh int	argc;
506768Srrh char	**argv;
516768Srrh 
526768Srrh {
536768Srrh 	register int	i;
546768Srrh 
556768Srrh 	signal (2,getout);
566768Srrh 	if (gtty (0,&tty) == -1)			/* get old tty mode */
576768Srrh 		errexit ("teachgammon(gtty)");
586768Srrh 	old = tty.sg_flags;
596768Srrh #ifdef V7
606768Srrh 	raw = ((noech = old & ~ECHO) | CBREAK);		/* set up modes */
616768Srrh #else
626768Srrh 	raw = ((noech = old & ~ECHO) | RAW);		/* set up modes */
636768Srrh #endif
6433148Sbostic 	ospeed = tty.sg_ospeed;				/* for termlib */
656768Srrh 	tflag = getcaps (getenv ("TERM"));
666768Srrh #ifdef V7
676768Srrh 	while (*++argv != 0)
686768Srrh #else
696768Srrh 	while (*++argv != -1)
706768Srrh #endif
716768Srrh 		getarg (&argv);
726768Srrh 	if (tflag)  {
736768Srrh 		noech &= ~(CRMOD|XTABS);
746768Srrh 		raw &= ~(CRMOD|XTABS);
756768Srrh 		clear();
766768Srrh 	}
776768Srrh 	text (hello);
786768Srrh 	text (list);
796768Srrh 	i = text (contin);
806768Srrh 	if (i == 0)
816768Srrh 		i = 2;
826768Srrh 	init();
836768Srrh 	while (i)
846768Srrh 		switch (i)  {
856768Srrh 
866768Srrh 		case 1:
876768Srrh 			leave();
886768Srrh 
896768Srrh 		case 2:
906768Srrh 			if (i = text(intro1))
916768Srrh 				break;
926768Srrh 			wrboard();
936768Srrh 			if (i = text(intro2))
946768Srrh 				break;
956768Srrh 
966768Srrh 		case 3:
976768Srrh 			if (i = text(moves))
986768Srrh 				break;
996768Srrh 
1006768Srrh 		case 4:
1016768Srrh 			if (i = text(remove))
1026768Srrh 				break;
1036768Srrh 
1046768Srrh 		case 5:
1056768Srrh 			if (i = text(hits))
1066768Srrh 				break;
1076768Srrh 
1086768Srrh 		case 6:
1096768Srrh 			if (i = text(endgame))
1106768Srrh 				break;
1116768Srrh 
1126768Srrh 		case 7:
1136768Srrh 			if (i = text(doubl))
1146768Srrh 				break;
1156768Srrh 
1166768Srrh 		case 8:
1176768Srrh 			if (i = text(stragy))
1186768Srrh 				break;
1196768Srrh 
1206768Srrh 		case 9:
1216768Srrh 			if (i = text(prog))
1226768Srrh 				break;
1236768Srrh 
1246768Srrh 		case 10:
1256768Srrh 			if (i = text(lastch))
1266768Srrh 				break;
1276768Srrh 		}
1286768Srrh 	tutor();
1296768Srrh }
1306768Srrh 
leave()1316768Srrh leave()  {
1326768Srrh 	if (tflag)
1336768Srrh 		clear();
1346768Srrh 	else
1356768Srrh 		writec ('\n');
1366768Srrh 	fixtty(old);
1376768Srrh 	execl (EXEC,"backgammon",args,"n",0);
1386768Srrh 	writel ("Help! Backgammon program is missing\007!!\n");
1396768Srrh 	exit (-1);
1406768Srrh }
141