supp.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /* supp.c -- support routines for dungeon */
  2. #include <stdio.h>
  3. #ifdef unix
  4. #include <sys/types.h>
  5. #endif
  6. #ifdef BSD4_2
  7. #include <sys/time.h>
  8. #else /* ! BSD4_2 */
  9. #include <time.h>
  10. #endif /* ! BSD4_2 */
  11. #include "funcs.h"
  12. /* Define these here to avoid using <stdlib.h> */
  13. extern void exit P((int));
  14. extern int rand P((void));
  15. /* We should have a definition for time_t and struct tm by now. Make
  16. * sure we have definitions for the functions we want to call.
  17. * The argument to localtime should be P((const time_t *)), but Ultrix
  18. * 4.0 leaves out the const in their prototype. Damn them.
  19. */
  20. extern time_t time P((time_t *));
  21. extern struct tm *localtime ();
  22. /* Terminate the game */
  23. void exit_()
  24. {
  25. fprintf(stderr, "The game is over.\n");
  26. exit(0);
  27. }
  28. /* Get time in hours, minutes and seconds */
  29. void itime_(hrptr, minptr, secptr)
  30. integer *hrptr;
  31. integer *minptr;
  32. integer *secptr;
  33. {
  34. time_t timebuf;
  35. struct tm *tmptr;
  36. time(&timebuf);
  37. tmptr = localtime(&timebuf);
  38. *hrptr = tmptr->tm_hour;
  39. *minptr = tmptr->tm_min;
  40. *secptr = tmptr->tm_sec;
  41. }
  42. /* Random number generator */
  43. integer rnd_(maxval)
  44. integer maxval;
  45. {
  46. return rand() % maxval;
  47. }
  48. /* Terminal support routines for dungeon */
  49. /* By Ian Lance Taylor ian@airs.com or uunet!airs!ian */
  50. /* The dungeon game can often output long strings, more than enough
  51. * to overwhelm a typical 24 row terminal (I assume that back when
  52. * dungeon was written people generally used paper terminals (I know
  53. * I did) so this was not a problem). The functions in this file
  54. * provide a very simplistic ``more'' facility. They are necessarily
  55. * somewhat operating system dependent, although I have tried to
  56. * minimize it as much as I could.
  57. */
  58. /* The following macro definitions may be used to control how these
  59. * functions work:
  60. *
  61. * MORE_NONE Don't use the more facility at all
  62. * MORE_24 Always assume a 24 row terminal
  63. * MORE_TERMCAP Use termcap routines to get rows of terminal
  64. * MORE_TERMINFO Use terminfo routines to get rows of terminal
  65. * MORE_AMOS Use AMOS monitor calls to get rows of terminal
  66. *
  67. * If none of these are defined then this will use termcap routines on
  68. * unix and AMOS routines on AMOS.
  69. */
  70. #ifndef MORE_NONE
  71. #ifndef MORE_24
  72. #ifndef MORE_TERMCAP
  73. #ifndef MORE_TERMINFO
  74. #ifndef MORE_AMOS
  75. #ifdef __AMOS__
  76. #define MORE_AMOS
  77. #else /* ! __AMOS__ */
  78. #ifdef unix
  79. #define MORE_TERMCAP
  80. #else /* ! unix */
  81. #define MORE_NONE
  82. #endif /* ! unix */
  83. #endif /* ! __AMOS__ */
  84. #endif /* ! MORE_AMOS */
  85. #endif /* ! MORE_TERMINFO */
  86. #endif /* ! MORE_TERMCAP */
  87. #endif /* ! MORE_24 */
  88. #endif /* ! MORE_NONE */
  89. #ifdef MORE_TERMCAP
  90. extern char *getenv P((const char *));
  91. extern void tgetent P((char *, const char *));
  92. extern int tgetnum P((const char *));
  93. #else /* ! MORE_TERMCAP */
  94. #ifdef MORE_TERMINFO
  95. #include <cursesX.h>
  96. #include <term.h>
  97. extern void setupterm P((const char *, int, int));
  98. #else /* ! MORE_TERMINFO */
  99. #ifdef MORE_AMOS
  100. #include <moncal.h>
  101. #include <unistd.h>
  102. #endif /* MORE_AMOS */
  103. #endif /* ! MORE_TERMINFO */
  104. #endif /* ! MORE_TERMCAP */
  105. /* Initialize the more waiting facility (determine how many rows the
  106. * terminal has).
  107. */
  108. static integer crows;
  109. static integer coutput;
  110. void more_init()
  111. {
  112. #ifdef MORE_NONE
  113. crows = 0;
  114. #else /* ! MORE_NONE */
  115. #ifdef MORE_24
  116. crows = 24;
  117. #else /* ! MORE_24 */
  118. #ifdef MORE_TERMCAP
  119. char buf[2048];
  120. char *term;
  121. term = getenv("TERM");
  122. if (term == NULL)
  123. crows = 0;
  124. else {
  125. tgetent(buf, term);
  126. crows = tgetnum("li");
  127. }
  128. #else /* ! MORE_TERMCAP */
  129. #ifdef MORE_TERMINFO
  130. int i;
  131. setupterm(NULL, 1, &i);
  132. if (i != 1)
  133. crows = 0;
  134. else
  135. crows = lines;
  136. #else /* ! MORE_TERMINFO */
  137. #ifdef MORE_AMOS
  138. trm_char st;
  139. if (isatty(fileno(stdin)) == 0)
  140. crows = 0;
  141. else {
  142. trmchr(&st, 0);
  143. crows = st.row;
  144. }
  145. #else /* ! MORE_AMOS */
  146. This should be impossible
  147. #endif /* ! MORE_AMOS */
  148. #endif /* ! MORE_TERMINFO */
  149. #endif /* ! MORE_TERMCAP */
  150. #endif /* ! MORE_24 */
  151. #endif /* ! MORE_NONE */
  152. }
  153. /* The program wants to output a line to the terminal. If z is not
  154. * NULL it is a simple string which is output here; otherwise it
  155. * needs some sort of formatting, and is output after this function
  156. * returns (if all computers had vprintf I would just it, but they
  157. * probably don't).
  158. */
  159. void more_output(z)
  160. const char *z;
  161. {
  162. /* pager code remarked out to allow streamed input and output */
  163. /*
  164. if (crows > 0 && coutput > crows - 2) {
  165. printf("Press return to continue: ");
  166. (void) fflush(stdout);
  167. while (getchar() != '\n')
  168. ;
  169. coutput = 0;
  170. }
  171. */
  172. if (z != NULL)
  173. printf("%s\n", z);
  174. coutput++;
  175. }
  176. /* The terminal is waiting for input (clear the number of output lines) */
  177. void more_input()
  178. {
  179. coutput = 0;
  180. }