teach.c 3.7 KB

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