home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / STEVIE3.ZIP / OS2.C < prev    next >
C/C++ Source or Header  |  1991-03-31  |  4KB  |  182 lines

  1. /*
  2.  * OS/2 System-dependent routines.
  3.  * Added support for "gray keys"                  David Landis (313) 698-1167
  4.  */
  5.  
  6. #include "stevie.h"
  7.  
  8. #define  INCL_SUB
  9. #include <os2.h>
  10.  
  11. struct _VIOMODEINFO modedata;
  12.  
  13. /*
  14.  * inchar() - get a character from the keyboard
  15.  */
  16. int
  17. inchar()
  18. {
  19.     int    c;
  20.  
  21.     flushbuf();        /* flush any pending output */
  22.  
  23.     c = getch();
  24.  
  25.     if (c == 0x1e)        /* control-^ */
  26.         return K_CGRAVE;
  27.     else {
  28.         switch(c) {
  29.         case 0xe0:
  30.             c = getch();            /* get next char of pair */
  31.             if ( c == 0x50 ) return K_DARROW;       /* down    arrow */
  32.             else if ( c == 0x48 ) return K_UARROW;  /* up      arrow */
  33.             else if ( c == 0x4d ) return K_RARROW;  /* right   arrow */
  34.             else if ( c == 0x4b ) return K_LARROW;  /* left    arrow */
  35.             else if ( c == 0x52 ) c = 'i';  /* insert    key */
  36.             else if ( c == 0x53 ) c = 'x';  /* delete    key */
  37.             else if ( c == 0x51 ) c = 0x06; /* page up   key */
  38.             else if ( c == 0x49 ) c = 0x02; /* page down key */
  39.             else if ( c == 0x47 ) c = 'H';  /* home      key */
  40.             else if ( c == 0x4f ) c = 'L';  /* end       key */
  41.             break;
  42.         case 0x0:        /* get identifier for function key */
  43.             c = getch();
  44.             if      ( c == 0x3b ) return K_F1;
  45.             else if ( c == 0x3c ) return K_F2;
  46.             else if ( c == 0x3d ) return K_F3;
  47.             else if ( c == 0x3e ) return K_F4;
  48.             else if ( c == 0x3f ) return K_F5;
  49.             else if ( c == 0x40 ) return K_F6;
  50.             else if ( c == 0x41 ) return K_F7;
  51.             else if ( c == 0x42 ) return K_F8;
  52.             else if ( c == 0x43 ) return K_F9;
  53.             else if ( c == 0x44 ) return K_F10;
  54.             else if ( c == 0x54 ) return K_SF1;
  55.             else if ( c == 0x55 ) return K_SF2;
  56.             else if ( c == 0x56 ) return K_SF3;
  57.             else if ( c == 0x57 ) return K_SF4;
  58.             else if ( c == 0x58 ) return K_SF5;
  59.             else if ( c == 0x59 ) return K_SF6;
  60.             else if ( c == 0x5a ) return K_SF7;
  61.             else if ( c == 0x5b ) return K_SF8;
  62.             else if ( c == 0x5c ) return K_SF9;
  63.             else if ( c == 0x5d ) return K_SF10;
  64.             break;
  65.         default:
  66.             break;
  67.         }
  68.         return c;
  69.     }
  70. }
  71.  
  72. #define    BSIZE    2048
  73. static    char    outbuf[BSIZE];
  74. static    int    bpos = 0;
  75.  
  76. flushbuf()
  77. {
  78.     if (bpos != 0)
  79.         write(1, outbuf, bpos);
  80.     bpos = 0;
  81. }
  82.  
  83. /*
  84.  * Macro to output a character. Used within this file for speed.
  85.  */
  86. #define    outone(c)    outbuf[bpos++] = c; if (bpos >= BSIZE) flushbuf()
  87.  
  88. /*
  89.  * Function version for use outside this file.
  90.  */
  91. void
  92. outchar(c)
  93. register char    c;
  94. {
  95.     outbuf[bpos++] = c;
  96.     if (bpos >= BSIZE)
  97.         flushbuf();
  98. }
  99.  
  100. void
  101. outstr(s)
  102. register char    *s;
  103. {
  104.     while (*s) {
  105.         outone(*s++);
  106.     }
  107. }
  108.  
  109. void
  110. beep()
  111. {
  112.     outone('\007');
  113. }
  114.  
  115. sleep(n)
  116. int    n;
  117. {
  118.     extern    far pascal DOSSLEEP();
  119.  
  120.     DOSSLEEP(1000L * n);
  121. }
  122.  
  123. void
  124. delay()
  125. {
  126.     DOSSLEEP(500L);
  127. }
  128.  
  129. void
  130. windinit()
  131. {
  132.     modedata.cb = sizeof( modedata );
  133.     VioGetMode( &modedata, 0L );
  134.     Columns = modedata.col;
  135.     P(P_LI) = Rows = modedata.row;
  136. }
  137.  
  138. void
  139. windexit(r)
  140. int r;
  141. {
  142.     flushbuf();
  143.     exit(r);
  144. }
  145.  
  146. void
  147. windgoto(r, c)
  148. register int    r, c;
  149. {
  150.     r += 1;
  151.     c += 1;
  152.  
  153.     /*
  154.      * Check for overflow once, to save time.
  155.      */
  156.     if (bpos + 8 >= BSIZE)
  157.         flushbuf();
  158.  
  159.     outbuf[bpos++] = '\033';
  160.     outbuf[bpos++] = '[';
  161.     if (r >= 10)
  162.         outbuf[bpos++] = r/10 + '0';
  163.     outbuf[bpos++] = r%10 + '0';
  164.     outbuf[bpos++] = ';';
  165.     if (c >= 10)
  166.         outbuf[bpos++] = c/10 + '0';
  167.     outbuf[bpos++] = c%10 + '0';
  168.     outbuf[bpos++] = 'H';
  169. }
  170.  
  171. FILE *
  172. fopenb(fname, mode)
  173. char    *fname;
  174. char    *mode;
  175. {
  176.     FILE    *fopen();
  177.     char    modestr[16];
  178.  
  179.     sprintf(modestr, "%sb", mode);
  180.     return fopen(fname, modestr);
  181. }
  182.