home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / STEVIE.ZIP / OS2.C < prev    next >
C/C++ Source or Header  |  1988-06-09  |  2KB  |  133 lines

  1. /*
  2.  * OS/2 System-dependent routines.
  3.  */
  4.  
  5. #include "stevie.h"
  6.  
  7. /*
  8.  * inchar() - get a character from the keyboard
  9.  */
  10. int
  11. inchar()
  12. {
  13.     int    c;
  14.  
  15.     flushbuf();        /* flush any pending output */
  16.  
  17.     c = getch();
  18.  
  19.     if (c == 0x1e)        /* control-^ */
  20.         return K_CGRAVE;
  21.     else
  22.         return c;
  23. }
  24.  
  25. #define    BSIZE    2048
  26. static    char    outbuf[BSIZE];
  27. static    int    bpos = 0;
  28.  
  29. flushbuf()
  30. {
  31.     if (bpos != 0)
  32.         write(1, outbuf, bpos);
  33.     bpos = 0;
  34. }
  35.  
  36. /*
  37.  * Macro to output a character. Used within this file for speed.
  38.  */
  39. #define    outone(c)    outbuf[bpos++] = c; if (bpos >= BSIZE) flushbuf()
  40.  
  41. /*
  42.  * Function version for use outside this file.
  43.  */
  44. void
  45. outchar(c)
  46. register char    c;
  47. {
  48.     outbuf[bpos++] = c;
  49.     if (bpos >= BSIZE)
  50.         flushbuf();
  51. }
  52.  
  53. void
  54. outstr(s)
  55. register char    *s;
  56. {
  57.     while (*s) {
  58.         outone(*s++);
  59.     }
  60. }
  61.  
  62. void
  63. beep()
  64. {
  65.     outone('\007');
  66. }
  67.  
  68. sleep(n)
  69. int    n;
  70. {
  71.     extern    far pascal DOSSLEEP();
  72.  
  73.     DOSSLEEP(1000L * n);
  74. }
  75.  
  76. void
  77. delay()
  78. {
  79.     DOSSLEEP(500L);
  80. }
  81.  
  82. void
  83. windinit()
  84. {
  85.     Columns = 80;
  86.     P(P_LI) = Rows = 25;
  87. }
  88.  
  89. void
  90. windexit(r)
  91. int r;
  92. {
  93.     flushbuf();
  94.     exit(r);
  95. }
  96.  
  97. void
  98. windgoto(r, c)
  99. register int    r, c;
  100. {
  101.     r += 1;
  102.     c += 1;
  103.  
  104.     /*
  105.      * Check for overflow once, to save time.
  106.      */
  107.     if (bpos + 8 >= BSIZE)
  108.         flushbuf();
  109.  
  110.     outbuf[bpos++] = '\033';
  111.     outbuf[bpos++] = '[';
  112.     if (r >= 10)
  113.         outbuf[bpos++] = r/10 + '0';
  114.     outbuf[bpos++] = r%10 + '0';
  115.     outbuf[bpos++] = ';';
  116.     if (c >= 10)
  117.         outbuf[bpos++] = c/10 + '0';
  118.     outbuf[bpos++] = c%10 + '0';
  119.     outbuf[bpos++] = 'H';
  120. }
  121.  
  122. FILE *
  123. fopenb(fname, mode)
  124. char    *fname;
  125. char    *mode;
  126. {
  127.     FILE    *fopen();
  128.     char    modestr[16];
  129.  
  130.     sprintf(modestr, "%sb", mode);
  131.     return fopen(fname, modestr);
  132. }
  133.