home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 100-199 / ff197.lzh / Stevie / bsd.c < prev    next >
C/C++ Source or Header  |  1989-03-28  |  2KB  |  113 lines

  1. /*
  2.  * System-dependent routines for BSD 4.3 UNIX 
  3.  */
  4.  
  5. #include "stevie.h"
  6. #include <sgtty.h>
  7.  
  8. /*
  9.  * inchar() - get a character from the keyboard 
  10.  */
  11. int
  12. inchar()
  13. {
  14.     int             c;
  15.  
  16.     fflush(stdout);        /* flush any pending output */
  17.  
  18.     c = getchar();
  19.  
  20.     return c;
  21. }
  22.  
  23. void
  24. outstr(s)
  25.     char           *s;
  26. {
  27.     while (*s)
  28.     outchar(*s++);
  29. }
  30.  
  31. void
  32. beep()
  33. {
  34.     if (RedrawingDisabled)
  35.     return;
  36.  
  37.     outchar('\007');
  38. }
  39.  
  40. void
  41. delay()
  42. {
  43.     sleep(1);
  44. }
  45.  
  46. static struct sgttyb ostate;
  47.  
  48. void
  49. windinit()
  50. {
  51.     char           *getenv();
  52.     char           *term;
  53.     struct sgttyb   nstate;
  54.  
  55.     term = getenv("TERM");
  56.     if (!term) {
  57.     fprintf(stderr, "Invalid terminal type '%s'\n", term);
  58.     exit(1);
  59.     }
  60.     if ((strncmp(term, "vt", 2) != 0) && (strncmp(term, "kd", 2) != 0)) {
  61.     fprintf(stderr, "Invalid terminal type '%s'\n", term);
  62.     exit(1);
  63.     }
  64.     Columns = 80;
  65.     P(P_LI) = Rows = 24;
  66.  
  67.     /*
  68.      * Go into cbreak mode 
  69.      */
  70.     ioctl(1, (long) TIOCGETP, (char *) &ostate);
  71.     nstate = ostate;
  72.     nstate.sg_flags = nstate.sg_flags & ~(ECHO | CRMOD) | CBREAK;
  73.     ioctl(1, (long) TIOCSETP, (char *) &nstate);
  74. }
  75.  
  76. void
  77. windexit(r)
  78.     int             r;
  79. {
  80.     fflush(stdout);
  81.  
  82.     ioctl(0, (long) TIOCSETP, (char *) &ostate);
  83.  
  84.     exit(r);
  85. }
  86.  
  87. void
  88. windgoto(r, c)
  89.     int             c;
  90.     int             r;
  91. {
  92.     r++;
  93.     c++;
  94.  
  95.     outstr("\033[");
  96.     if (r >= 10)
  97.     outchar((char) (r / 10 + '0'));
  98.     outchar((char) (r % 10 + '0'));
  99.     outchar(';');
  100.     if (c >= 10)
  101.     outchar((char) (c / 10 + '0'));
  102.     outchar((char) (c % 10 + '0'));
  103.     outchar('H');
  104. }
  105.  
  106. FILE           *
  107. fopenb(fname, mode)
  108.     char           *fname;
  109.     char           *mode;
  110. {
  111.     return fopen(fname, mode);
  112. }
  113.