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