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 / unix.c < prev    next >
C/C++ Source or Header  |  1989-10-19  |  3KB  |  183 lines

  1. /*
  2.  * System-dependent routines for UNIX System V Release 3. 
  3.  */
  4.  
  5. #include "stevie.h"
  6. /* #include <termio.h> /* System V */
  7. #include <curses.h>        /* BSD */
  8.  
  9. /*
  10.  * inchar() - get a character from the keyboard 
  11.  */
  12. int
  13. inchar()
  14. {
  15.     char            c;
  16.  
  17.     flushbuf();            /* flush any pending output */
  18.  
  19.     while (read(0, &c, 1) != 1);
  20.  
  21.     return (int) c;
  22. }
  23.  
  24. #define BSIZE   2048
  25. static char     outbuf[BSIZE];
  26. static int      bpos = 0;
  27.  
  28. flushbuf()
  29. {
  30.     if (bpos != 0)
  31.     write(1, outbuf, bpos);
  32.     bpos = 0;
  33. }
  34.  
  35. /*
  36.  * Macro to output a character. Used within this file for speed. 
  37.  */
  38. #define outone(c)       outbuf[bpos++] = c; if (bpos >= BSIZE) flushbuf()
  39.  
  40. /*
  41.  * Function version for use outside this file. 
  42.  */
  43. void
  44. outchar(c)
  45.     char            c;
  46. {
  47.     outbuf[bpos++] = c;
  48.     if (bpos >= BSIZE)
  49.     flushbuf();
  50. }
  51.  
  52. void
  53. outstr(s)
  54.     char           *s;
  55. {
  56.     while (*s) {
  57.     outone(*s++);
  58.     }
  59. }
  60.  
  61. void
  62. beep()
  63. {
  64.     if (RedrawingDisabled)
  65.     return;
  66.  
  67.     outone('\007');
  68. }
  69.  
  70. /*
  71.  * remove(file) - remove a file 
  72.  */
  73. void
  74. remove(file)
  75.     char           *file;
  76. {
  77.     unlink(file);
  78. }
  79.  
  80. /*
  81.  * rename(of, nf) - rename existing file 'of' to 'nf' 
  82.  */
  83. void
  84. rename(of, nf)
  85.     char           *of, *nf;
  86. {
  87.     unlink(nf);
  88.     link(of, nf);
  89.     unlink(of);
  90. }
  91.  
  92. void
  93. delay()
  94. {
  95.     /* not implemented */
  96. }
  97.  
  98. static struct termio ostate;
  99. static struct termio nstate;
  100.  
  101. void
  102. set_ostate()
  103. {
  104.     ioctl(0, TCSETAW, &ostate);
  105. }
  106.  
  107. void
  108. set_nstate()
  109. {
  110.     ioctl(0, TCSETAW, &nstate);
  111. }
  112.  
  113. void
  114. windinit()
  115. {
  116.     char           *getenv();
  117.     char           *term;
  118.  
  119.     if ((term = getenv("TERM")) == NULL || strcmp(term, "vt100") != 0) {
  120.     fprintf(stderr, "Invalid terminal type '%s'\n", term);
  121.     exit(1);
  122.     }
  123.     Columns = 80;
  124.     P(P_LI) = Rows = 24;
  125.  
  126.     /*
  127.      * Go into cbreak mode 
  128.      */
  129.     ioctl(0, TCGETA, &ostate);
  130.     nstate = ostate;
  131.     nstate.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL);
  132.     nstate.c_cc[VMIN] = 1;
  133.     nstate.c_cc[VTIME] = 0;
  134.     ioctl(0, TCSETAW, &nstate);
  135. }
  136.  
  137. void
  138. windexit(r)
  139.     int             r;
  140. {
  141.     /*
  142.      * Restore terminal modes 
  143.      */
  144.     ioctl(0, TCSETAW, &ostate);
  145.  
  146.     exit(r);
  147. }
  148.  
  149. #define outone(c)       outbuf[bpos++] = c; if (bpos >= BSIZE) flushbuf()
  150.  
  151. void
  152. windgoto(r, c)
  153.     int             r, c;
  154. {
  155.     r += 1;
  156.     c += 1;
  157.  
  158.     /*
  159.      * Check for overflow once, to save time. 
  160.      */
  161.     if (bpos + 8 >= BSIZE)
  162.     flushbuf();
  163.  
  164.     outbuf[bpos++] = '\033';
  165.     outbuf[bpos++] = '[';
  166.     if (r >= 10)
  167.     outbuf[bpos++] = r / 10 + '0';
  168.     outbuf[bpos++] = r % 10 + '0';
  169.     outbuf[bpos++] = ';';
  170.     if (c >= 10)
  171.     outbuf[bpos++] = c / 10 + '0';
  172.     outbuf[bpos++] = c % 10 + '0';
  173.     outbuf[bpos++] = 'H';
  174. }
  175.  
  176. FILE           *
  177. fopenb(fname, mode)
  178.     char           *fname;
  179.     char           *mode;
  180. {
  181.     return fopen(fname, mode);
  182. }
  183.