home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff256.lzh / Stevie / bsd.c < prev    next >
C/C++ Source or Header  |  1989-10-19  |  2KB  |  155 lines

  1. /*
  2.  * System-dependent routines for BSD 4.3 UNIX 
  3.  */
  4.  
  5. #include "stevie.h"
  6. #include <sgtty.h>
  7.  
  8. #ifdef OLD_IO
  9. #define BSIZE   2048
  10. static char     outbuf[BSIZE];
  11. static int      bpos = 0;
  12.  
  13. void
  14. flushbuf()
  15. {
  16.     if (bpos != 0)
  17.     fwrite(outbuf, sizeof(*outbuf), bpos, stdout);
  18.     fflush(stdout);
  19.     bpos = 0;
  20. }
  21.  
  22. void
  23. outchar(c)
  24.     char            c;
  25. {
  26.     outbuf[bpos++] = c;
  27.     if (bpos >= BSIZE)
  28.     flushbuf();
  29. }
  30.  
  31. void
  32. outstr(s)
  33.     char           *s;
  34. {
  35.     while (*s) {
  36.     outbuf[bpos++] = *s++;
  37.     if (bpos >= BSIZE)
  38.         flushbuf();
  39.     }
  40. }
  41. #endif
  42.  
  43. /*
  44.  * inchar() - get a character from the keyboard 
  45.  */
  46. int
  47. inchar()
  48. {
  49.     int             c;
  50.  
  51.     flushbuf();            /* flush any pending output */
  52.  
  53.     c = getchar();
  54.  
  55.     return c;
  56. }
  57.  
  58. void
  59. beep()
  60. {
  61.     if (RedrawingDisabled)
  62.     return;
  63.  
  64.     outchar('\007');
  65. }
  66.  
  67. void
  68. delay()
  69. {
  70.     sleep(1);
  71. }
  72.  
  73. static struct sgttyb ostate;
  74. static struct sgttyb nstate;
  75.  
  76. void
  77. set_ostate()
  78. {
  79.     ioctl(0, (long) TIOCSETP, (char *) &ostate);
  80. }
  81.  
  82. void
  83. set_nstate()
  84. {
  85.     ioctl(1, (long) TIOCSETP, (char *) &nstate);
  86. }
  87.  
  88. void
  89. windinit()
  90. {
  91.     char           *getenv();
  92. #ifdef CHECK_TERM
  93.     char           *term;
  94.  
  95.     term = getenv("TERM");
  96.     if (!term) {
  97.     fprintf(stderr, "Invalid terminal type '%s'\n", term);
  98.     exit(1);
  99.     }
  100.     if ((strncmp(term, "vt", 2) != 0) && (strncmp(term, "kd", 2) != 0)) {
  101.     fprintf(stderr, "Invalid terminal type '%s'\n", term);
  102.     exit(1);
  103.     }
  104. #endif
  105.  
  106.     Columns = 80;
  107.     P(P_LI) = Rows = 24;
  108.  
  109.     /*
  110.      * Go into cbreak mode 
  111.      */
  112.     ioctl(1, (long) TIOCGETP, (char *) &ostate);
  113.     nstate = ostate;
  114.     nstate.sg_flags = nstate.sg_flags & ~(ECHO | CRMOD) | CBREAK;
  115.     ioctl(1, (long) TIOCSETP, (char *) &nstate);
  116. }
  117.  
  118. void
  119. windexit(r)
  120.     int             r;
  121. {
  122.     flushbuf();
  123.  
  124.     ioctl(0, (long) TIOCSETP, (char *) &ostate);
  125.  
  126.     exit(r);
  127. }
  128.  
  129. void
  130. windgoto(r, c)
  131.     int             c;
  132.     int             r;
  133. {
  134.     r++;
  135.     c++;
  136.  
  137.     outstr("\033[");
  138.     if (r >= 10)
  139.     outchar((char) (r / 10 + '0'));
  140.     outchar((char) (r % 10 + '0'));
  141.     outchar(';');
  142.     if (c >= 10)
  143.     outchar((char) (c / 10 + '0'));
  144.     outchar((char) (c % 10 + '0'));
  145.     outchar('H');
  146. }
  147.  
  148. FILE           *
  149. fopenb(fname, mode)
  150.     char           *fname;
  151.     char           *mode;
  152. {
  153.     return fopen(fname, mode);
  154. }
  155.