home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
STEVIE3.ZIP
/
OS2.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-03-31
|
4KB
|
182 lines
/*
* OS/2 System-dependent routines.
* Added support for "gray keys" David Landis (313) 698-1167
*/
#include "stevie.h"
#define INCL_SUB
#include <os2.h>
struct _VIOMODEINFO modedata;
/*
* inchar() - get a character from the keyboard
*/
int
inchar()
{
int c;
flushbuf(); /* flush any pending output */
c = getch();
if (c == 0x1e) /* control-^ */
return K_CGRAVE;
else {
switch(c) {
case 0xe0:
c = getch(); /* get next char of pair */
if ( c == 0x50 ) return K_DARROW; /* down arrow */
else if ( c == 0x48 ) return K_UARROW; /* up arrow */
else if ( c == 0x4d ) return K_RARROW; /* right arrow */
else if ( c == 0x4b ) return K_LARROW; /* left arrow */
else if ( c == 0x52 ) c = 'i'; /* insert key */
else if ( c == 0x53 ) c = 'x'; /* delete key */
else if ( c == 0x51 ) c = 0x06; /* page up key */
else if ( c == 0x49 ) c = 0x02; /* page down key */
else if ( c == 0x47 ) c = 'H'; /* home key */
else if ( c == 0x4f ) c = 'L'; /* end key */
break;
case 0x0: /* get identifier for function key */
c = getch();
if ( c == 0x3b ) return K_F1;
else if ( c == 0x3c ) return K_F2;
else if ( c == 0x3d ) return K_F3;
else if ( c == 0x3e ) return K_F4;
else if ( c == 0x3f ) return K_F5;
else if ( c == 0x40 ) return K_F6;
else if ( c == 0x41 ) return K_F7;
else if ( c == 0x42 ) return K_F8;
else if ( c == 0x43 ) return K_F9;
else if ( c == 0x44 ) return K_F10;
else if ( c == 0x54 ) return K_SF1;
else if ( c == 0x55 ) return K_SF2;
else if ( c == 0x56 ) return K_SF3;
else if ( c == 0x57 ) return K_SF4;
else if ( c == 0x58 ) return K_SF5;
else if ( c == 0x59 ) return K_SF6;
else if ( c == 0x5a ) return K_SF7;
else if ( c == 0x5b ) return K_SF8;
else if ( c == 0x5c ) return K_SF9;
else if ( c == 0x5d ) return K_SF10;
break;
default:
break;
}
return c;
}
}
#define BSIZE 2048
static char outbuf[BSIZE];
static int bpos = 0;
flushbuf()
{
if (bpos != 0)
write(1, outbuf, bpos);
bpos = 0;
}
/*
* Macro to output a character. Used within this file for speed.
*/
#define outone(c) outbuf[bpos++] = c; if (bpos >= BSIZE) flushbuf()
/*
* Function version for use outside this file.
*/
void
outchar(c)
register char c;
{
outbuf[bpos++] = c;
if (bpos >= BSIZE)
flushbuf();
}
void
outstr(s)
register char *s;
{
while (*s) {
outone(*s++);
}
}
void
beep()
{
outone('\007');
}
sleep(n)
int n;
{
extern far pascal DOSSLEEP();
DOSSLEEP(1000L * n);
}
void
delay()
{
DOSSLEEP(500L);
}
void
windinit()
{
modedata.cb = sizeof( modedata );
VioGetMode( &modedata, 0L );
Columns = modedata.col;
P(P_LI) = Rows = modedata.row;
}
void
windexit(r)
int r;
{
flushbuf();
exit(r);
}
void
windgoto(r, c)
register int r, c;
{
r += 1;
c += 1;
/*
* Check for overflow once, to save time.
*/
if (bpos + 8 >= BSIZE)
flushbuf();
outbuf[bpos++] = '\033';
outbuf[bpos++] = '[';
if (r >= 10)
outbuf[bpos++] = r/10 + '0';
outbuf[bpos++] = r%10 + '0';
outbuf[bpos++] = ';';
if (c >= 10)
outbuf[bpos++] = c/10 + '0';
outbuf[bpos++] = c%10 + '0';
outbuf[bpos++] = 'H';
}
FILE *
fopenb(fname, mode)
char *fname;
char *mode;
{
FILE *fopen();
char modestr[16];
sprintf(modestr, "%sb", mode);
return fopen(fname, modestr);
}