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 / os9.c < prev    next >
C/C++ Source or Header  |  1989-10-19  |  2KB  |  154 lines

  1. /*
  2.  * System-dependent routines for OS9 v2.2
  3.  */
  4.  
  5. #include "stevie.h"
  6. #include <sgstat.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 sgbuf ostate;
  74. static struct sgbuf nstate;
  75.  
  76. void
  77. windinit()
  78. {
  79.     char           *getenv();
  80.  
  81.     Columns = 80;
  82.     P(P_LI) = Rows = 24;
  83.  
  84.     /*
  85.      * Go into cbreak mode 
  86.      */
  87.     _gs_opt(1, &ostate);
  88.     _gs_opt(1, &nstate);
  89.     nstate.sg_echo = 0;   /* no echo */
  90. /*    nstate.sg_alf = 0;    /* auto line feed */
  91.     nstate.sg_pause = 0;  /* no end of page pause */
  92.     nstate.sg_dlnch = 0;  /* delete line char */
  93.     nstate.sg_eorch = 0;  /* end of record char */
  94.     nstate.sg_eofch = 0;  /* end of file char */
  95.     nstate.sg_rlnch = 0;  /* reprint line char */
  96.     nstate.sg_dulnch = 0; /* duplicate last line char */
  97.     nstate.sg_psch = 0;   /* pause char */
  98.     nstate.sg_kbich = 0;  /* interrupt char */
  99.     nstate.sg_kbach = 0;  /* abort char */
  100.     _ss_opt(1, &nstate);
  101.  
  102.     stdin->_flag |= _UNBUF;
  103.  
  104. }
  105.  
  106. void
  107. windexit(r)
  108.     int             r;
  109. {
  110.     flushbuf();
  111.  
  112.     stdin->_flag &= ~_UNBUF;
  113.     _ss_opt(1, &ostate);
  114.  
  115.     exit(r);
  116. }
  117.  
  118. void
  119. windgoto(r, c)
  120.     int             c;
  121.     int             r;
  122. {
  123.     r++;
  124.     c++;
  125.  
  126.     outstr("\033[");
  127.     if (r >= 10)
  128.     outchar((char) (r / 10 + '0'));
  129.     outchar((char) (r % 10 + '0'));
  130.     outchar(';');
  131.     if (c >= 10)
  132.     outchar((char) (c / 10 + '0'));
  133.     outchar((char) (c % 10 + '0'));
  134.     outchar('H');
  135. }
  136.  
  137. FILE           *
  138. fopenb(fname, mode)
  139.     char           *fname;
  140.     char           *mode;
  141. {
  142.     return fopen(fname, mode);
  143. }
  144.  
  145. void rename(of,nf)
  146. char *of, *nf;
  147. {
  148. char buffer[128];
  149.  
  150.     sprintf(buffer, "rename >>>/nil %s %s", of, nf);
  151.     system (buffer);
  152. }
  153.  
  154.