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