--- os2sdk/demos/apps/sse/dispatch.c 2018/08/09 12:25:13 1.1 +++ os2sdk/demos/apps/sse/dispatch.c 2018/08/09 12:26:05 1.1.1.2 @@ -1,3 +1,5 @@ +/* Created by Microsoft Corp. 1987 */ + /*** dispatch() - accepts keyboard input and dispatches control to * the appropriate function. * @@ -10,11 +12,12 @@ * EFFECTS: No global variables are directly effected by this function */ +#define INCL_SUB +#define INCL_DOSPROCESS +#include +#include #include -#include -#include -#include #include "ssedefs.h" #include "keydefs.h" @@ -22,13 +25,13 @@ void dispatch() { - struct KeyData keydata; /* data structure from subcalls.h */ - struct KbdStatus kbdstatus; /* data structure from subcalls.h */ + KBDKEYINFO keydata; /* data structure from bsesub.h */ + KBDINFO kbdstatus; /* data structure from bsesub.h */ - kbdstatus.length = sizeof( kbdstatus ); - KBDGETSTATUS( &kbdstatus, 0 ); /* set keyboard mode */ - kbdstatus.bit_mask |= 4; - KBDSETSTATUS( &kbdstatus, 0 ); + kbdstatus.cb = sizeof( kbdstatus ); + KbdGetStatus( &kbdstatus, 0 ); /* set keyboard mode */ + kbdstatus.fsMask |= 4; + KbdSetStatus( &kbdstatus, 0 ); /* the following section waits for keyboard input */ @@ -39,23 +42,23 @@ void dispatch() while(1) { - KBDCHARIN( &keydata, 0, 0 ); /* get a character from KBD */ + KbdCharIn( &keydata, 0, 0 ); /* get a character from KBD */ - switch( keydata.char_code ) { + switch( keydata.chChar ) { - default: /* default is not */ - if ( isprint( keydata.char_code ) ) /* a control key. */ - insert( keydata.char_code ); /* check validity */ - else badkey(); /* and if good, */ - break; /* call insert() */ + default: /* default is not */ + if ( isprint( keydata.chChar ) ) /* a control key. */ + insert( keydata.chChar ); /* check validity */ + else badkey(); /* and if good, */ + break; /* call insert() */ /* "special keys", those with character codes of 00, must */ /* be sent to another dispatcher that checks scan codes. */ case SPECIAL_KEYS_CHAR: - special_dispatch( keydata.scan_code, - keydata.shift_state ); + special_dispatch( keydata.chScan, + keydata.fsState ); break; /* all others keys we can dispatch from here. some */ @@ -90,45 +93,45 @@ void dispatch() /* also as the char code may be shared with another key. */ case SHIFT_END_CHAR: - if ( keydata.scan_code == END_SCAN && - keydata.shift_state < 3 ) + if ( keydata.chScan == END_SCAN && + keydata.fsState < 3 ) shift_end(); - else insert( keydata.char_code ); + else insert( keydata.chChar ); break; case SHIFT_DOWN_CHAR: - if ( keydata.scan_code == DOWN_SCAN && - keydata.shift_state < 3 ) + if ( keydata.chScan == DOWN_SCAN && + keydata.fsState < 3 ) shift_down(); - else insert( keydata.char_code ); + else insert( keydata.chChar ); break; case SHIFT_LEFT_CHAR: - if ( keydata.scan_code == LEFT_SCAN && - keydata.shift_state < 3 ) + if ( keydata.chScan == LEFT_SCAN && + keydata.fsState < 3 ) shift_left(); - else insert( keydata.char_code ); + else insert( keydata.chChar ); break; case SHIFT_RIGHT_CHAR: - if ( keydata.scan_code == RIGHT_SCAN && - keydata.shift_state < 3 ) + if ( keydata.chScan == RIGHT_SCAN && + keydata.fsState < 3 ) shift_right(); - else insert( keydata.char_code ); + else insert( keydata.chChar ); break; case SHIFT_HOME_CHAR: - if ( keydata.scan_code == HOME_SCAN && - keydata.shift_state < 3 ) + if ( keydata.chScan == HOME_SCAN && + keydata.fsState < 3 ) shift_home(); - else insert( keydata.char_code ); + else insert( keydata.chChar ); break; case SHIFT_UP_CHAR: - if ( keydata.scan_code == UP_SCAN && - keydata.shift_state < 3 ) + if ( keydata.chScan == UP_SCAN && + keydata.fsState < 3 ) shift_up(); - else insert( keydata.char_code ); + else insert( keydata.chChar ); break; /* There's one other possibility, that the char code is 0xE0 */ @@ -136,8 +139,8 @@ void dispatch() /* We will treat these in the same manner as special keys. */ case ARROW_CHAR: - special_dispatch( keydata.scan_code, - keydata.shift_state ); + special_dispatch( keydata.chScan, + keydata.fsState ); break; @@ -177,8 +180,8 @@ void dispatch() special_dispatch(scan,shift) /* dispatcher for "special keys" based on */ /* the scan code and shift code from KBD */ - unsigned char scan; /* scan code - must be unsigned */ - unsigned shift; /* shift code */ + UCHAR scan; /* scan code - must be unsigned */ + unsigned shift; /* shift code */ { @@ -205,7 +208,7 @@ special_dispatch(scan,shift) /* dispa if ( CurCol > 0 ) { CurCol -= 1; /* move cursor left 1 */ - VIOSETCURPOS( CurRow, CurCol, 0 ); /* if there's room */ + VioSetCurPos( CurRow, CurCol, 0 ); /* if there's room */ } } @@ -233,7 +236,7 @@ special_dispatch(scan,shift) /* dispa if (CurCol < (LINESIZE -1)) { /* move cursor right one */ CurCol += 1; /* column if there's room */ - VIOSETCURPOS( CurRow, CurCol, 0 ); + VioSetCurPos( CurRow, CurCol, 0 ); } } @@ -321,7 +324,7 @@ special_dispatch(scan,shift) /* dispa badkey() { - DOSBEEP (500, 50); /* frequency = 500 Hertz */ + DosBeep (500, 50); /* frequency = 500 Hertz */ } /* duration = 50 milliseconds */ @@ -340,7 +343,7 @@ void clearscr() buff[0] = ' '; /* cell to replicate is a blank */ buff[1] = BackNorm + ForeNorm; /* with normal attributes */ - VIOSCROLLUP(0, 0, -1, -1, -1, (char far *)buff, 0); + VioScrollUp(0, 0, -1, -1, -1, (PBYTE)buff, 0); /* when the first 5 parameters are */ /* set as above, the entire screen */ @@ -364,10 +367,10 @@ void clearscr() void drawscr(startline) - unsigned short startline; + USHORT startline; { - register unsigned short i, j; /* indexing variables */ + register USHORT i, j; /* indexing variables */ char normal = BackNorm + ForeNorm; /* normal attributes */ @@ -375,7 +378,7 @@ void drawscr(startline) getline( i, &ScrBuff[j][0] ); /* load ScrBuff[][] with the */ /* part of the screen we want */ - VIOWRTCHARSTRATT ( (char far *)ScrBuff, ( PageSize * LINESIZE ), 0, 0, + VioWrtCharStrAtt ( (PCH)ScrBuff, ( PageSize * LINESIZE ), 0, 0, &normal, 0 ); /* write it out to the screen */ } @@ -398,25 +401,25 @@ void drawscr(startline) drawline() { - unsigned short i; /* indexing variables */ - unsigned short j; + USHORT i; /* indexing variables */ + USHORT j; char hilite = BackHilite + ForeHilite; /* attributes for marked */ char normal = BackNorm + ForeNorm; /* attributes for not marked */ if( MarkedLine[TopRow+CurRow] ) - VIOWRTCHARSTRATT( EditBuff, LINESIZE, CurRow, 0, &hilite, 0); + VioWrtCharStrAtt( EditBuff, LINESIZE, CurRow, 0, &hilite, 0); /* if line is marked, do this */ else if (CharsMarked) { for( i = 0; !MarkedChar[i] & (i < LINESIZE); i++ ); for( j = i; MarkedChar[j] & (j < LINESIZE); j++ ); - VIOWRTCHARSTRATT( &EditBuff[0], i, CurRow, 0, &normal, 0); - VIOWRTCHARSTRATT( &EditBuff[i], (j - i), CurRow, i, &hilite, 0); - VIOWRTCHARSTRATT( &EditBuff[j], (LINESIZE - j), CurRow, j, + VioWrtCharStrAtt( &EditBuff[0], i, CurRow, 0, &normal, 0); + VioWrtCharStrAtt( &EditBuff[i], (j - i), CurRow, i, &hilite, 0); + VioWrtCharStrAtt( &EditBuff[j], (LINESIZE - j), CurRow, j, &normal, 0); } /* else if characters marked, do this */ - else VIOWRTCHARSTRATT( EditBuff, LINESIZE, CurRow, 0, &normal, 0); + else VioWrtCharStrAtt( EditBuff, LINESIZE, CurRow, 0, &normal, 0); } /* else if neither marked, do this */ @@ -454,7 +457,7 @@ void line25() buff[0] = i + 0x30; } else buff[0] = ' '; - VIOWRTCHARSTRATT( buff, 1, PageSize, col, &attrib, 0 ); + VioWrtCharStrAtt( buff, 1, PageSize, col, &attrib, 0 ); col += 1; for( i = 0; n > 999; n -= 1000, i++ ); @@ -464,7 +467,7 @@ void line25() } else if( flag0 ) buff[0] = '0'; else buff[0] = ' '; - VIOWRTCHARSTRATT( buff, 1, PageSize, col, &attrib, 0 ); + VioWrtCharStrAtt( buff, 1, PageSize, col, &attrib, 0 ); col += 1; for( i = 0; n > 99; n -= 100, i++ ); @@ -474,7 +477,7 @@ void line25() } else if( flag0 ) buff[0] = '0'; else buff[0] = ' '; - VIOWRTCHARSTRATT( buff, 1, PageSize, col, &attrib, 0 ); + VioWrtCharStrAtt( buff, 1, PageSize, col, &attrib, 0 ); col += 1; for( i = 0; n > 9; n -= 10, i++ ); @@ -484,17 +487,17 @@ void line25() } else if( flag0 ) buff[0] = '0'; else buff[0] = ' '; - VIOWRTCHARSTRATT( buff, 1, PageSize, col, &attrib, 0 ); + VioWrtCharStrAtt( buff, 1, PageSize, col, &attrib, 0 ); col += 1; buff[0] = n + 0x30; /* 1's place of current line */ - VIOWRTCHARSTRATT( buff, 1, PageSize, col, &attrib, 0 ); + VioWrtCharStrAtt( buff, 1, PageSize, col, &attrib, 0 ); col += 1; buff[0] = ' '; buff[1] = '/'; /* delimiting characters */ buff[2] = ' '; - VIOWRTCHARSTRATT( buff, 3, PageSize, col, &attrib, 0 ); + VioWrtCharStrAtt( buff, 3, PageSize, col, &attrib, 0 ); col += 3; flag0 = 0; @@ -504,7 +507,7 @@ void line25() if( i > 0 ) { flag0 = 1; /* 10,000's place of total lines */ buff[0] = i + 0x30; - VIOWRTCHARSTRATT( buff, 1, PageSize, col, &attrib, 0 ); + VioWrtCharStrAtt( buff, 1, PageSize, col, &attrib, 0 ); col += 1; } @@ -512,12 +515,12 @@ void line25() if( i > 0 ) { flag0 = 1; /* 1,000's place of total lines */ buff[0] = i + 0x30; - VIOWRTCHARSTRATT( buff, 1, PageSize, col, &attrib, 0 ); + VioWrtCharStrAtt( buff, 1, PageSize, col, &attrib, 0 ); col += 1; } else if( flag0 ) { buff[0] = '0'; - VIOWRTCHARSTRATT( buff, 1, PageSize, col, &attrib, 0 ); + VioWrtCharStrAtt( buff, 1, PageSize, col, &attrib, 0 ); col += 1; } @@ -525,12 +528,12 @@ void line25() if( i > 0 ) { flag0 = 1; /* 100's place of total lines */ buff[0] = i + 0x30; - VIOWRTCHARSTRATT( buff, 1, PageSize, col, &attrib, 0 ); + VioWrtCharStrAtt( buff, 1, PageSize, col, &attrib, 0 ); col += 1; } else if( flag0 ) { buff[0] = '0'; - VIOWRTCHARSTRATT( buff, 1, PageSize, col, &attrib, 0 ); + VioWrtCharStrAtt( buff, 1, PageSize, col, &attrib, 0 ); col += 1; } @@ -538,22 +541,22 @@ void line25() if( i > 0 ) { flag0 = 1; /* 10's place of total lines */ buff[0] = i + 0x30; - VIOWRTCHARSTRATT( buff, 1, PageSize, col, &attrib, 0 ); + VioWrtCharStrAtt( buff, 1, PageSize, col, &attrib, 0 ); col += 1; } else if( flag0 ) { buff[0] = '0'; - VIOWRTCHARSTRATT( buff, 1, PageSize, col, &attrib, 0 ); + VioWrtCharStrAtt( buff, 1, PageSize, col, &attrib, 0 ); col += 1; } buff[0] = n + 0x30; /* 1's place of total lines */ - VIOWRTCHARSTRATT( buff, 1, PageSize, col, &attrib, 0 ); + VioWrtCharStrAtt( buff, 1, PageSize, col, &attrib, 0 ); col +=1; n = LINESIZE - col; /* fill rest of line with blanks; n is how many */ for( i = 0; i < LINESIZE; buff[i] = ' ', i++ ); - VIOWRTCHARSTRATT( buff, n, PageSize, col, &attrib, 0 ); + VioWrtCharStrAtt( buff, n, PageSize, col, &attrib, 0 ); } @@ -585,7 +588,7 @@ void name25() /* first, print usage message */ - VIOWRTCHARSTRATT( message, 51, PageSize, 0, &attrib, 0 ); + VioWrtCharStrAtt( message, 51, PageSize, 0, &attrib, 0 ); /* build filename string */ @@ -607,7 +610,7 @@ void name25() for( ; k >= 0; name[k] = ' ', k-- ); /* if any room left, blank fill */ - VIOWRTCHARSTRATT( name, 16, PageSize, 51, &attrib, 0 ); /* write it */ + VioWrtCharStrAtt( name, 16, PageSize, 51, &attrib, 0 ); /* write it */ line25(); /* call the line number routine */ @@ -632,7 +635,7 @@ void name25() */ void error25(error) - unsigned short error; + USHORT error; { static char message1[51] = "ERROR: Out of memory or can't read file "; static char message2[51] = "ERROR: Unable to create backup. Continue? (y/n) "; @@ -646,32 +649,32 @@ void error25(error) static char message10[51] = "ERROR: Too many parameters on command line "; static char message11[51] = "ERROR: Unable to save file. C = continue "; static char message99[51] = "ERROR: Unknown error. Continue? (y/n) "; - struct KeyData keydata; + KBDKEYINFO keydata; char attrib = Back25 + Fore25; /* attributes for our messages */ switch( error ) { /* take the appropriate action for the error */ case 1: - VIOWRTCHARSTRATT( message1, 51, PageSize, 0, &attrib, 0 ); + VioWrtCharStrAtt( message1, 51, PageSize, 0, &attrib, 0 ); quit(1); break; /* 1 -> print message and quit */ case 2: - VIOWRTCHARSTRATT( message2, 51, PageSize, 0, &attrib, 0 ); - VIOSETCURPOS( PageSize, 50, 0 ); + VioWrtCharStrAtt( message2, 51, PageSize, 0, &attrib, 0 ); + VioSetCurPos( PageSize, 50, 0 ); while( 1 ) { /* 2 -> get a character from KBD */ - KBDCHARIN( &keydata, 0, 0 ); + KbdCharIn( &keydata, 0, 0 ); - if( (keydata.char_code == 'y') || (keydata.char_code == 'Y') ) { + if( (keydata.chChar == 'y') || (keydata.chChar == 'Y') ) { name25(); break; /* if Y, go ahead */ } - else if( (keydata.char_code == 'n') || (keydata.char_code == 'N') ) { - VIOWRTCHARSTRATT( &keydata.char_code, 1, PageSize, 50, &attrib, 0 ); + else if( (keydata.chChar == 'n') || (keydata.chChar == 'N') ) { + VioWrtCharStrAtt( &keydata.chChar, 1, PageSize, 50, &attrib, 0 ); quit(1); /* if N, quit with error */ break; } @@ -682,20 +685,20 @@ void error25(error) break; case 3: - VIOWRTCHARSTRATT( message3, 51, PageSize, 0, &attrib, 0 ); - VIOSETCURPOS( PageSize, 32, 0 ); + VioWrtCharStrAtt( message3, 51, PageSize, 0, &attrib, 0 ); + VioSetCurPos( PageSize, 32, 0 ); while( 1 ) { /* 3 -> get a character from KBD */ - KBDCHARIN( &keydata, 0, 0 ); + KbdCharIn( &keydata, 0, 0 ); - if( (keydata.char_code == 'y') || (keydata.char_code == 'Y') ) { + if( (keydata.chChar == 'y') || (keydata.chChar == 'Y') ) { name25(); break; /* if Y, go ahead */ } - else if( (keydata.char_code == 'n') || (keydata.char_code == 'N') ) { - VIOWRTCHARSTRATT( &keydata.char_code, 1, PageSize, 50, &attrib, 0 ); + else if( (keydata.chChar == 'n') || (keydata.chChar == 'N') ) { + VioWrtCharStrAtt( &keydata.chChar, 1, PageSize, 50, &attrib, 0 ); quit(1); /* if N, quit with error */ break; } @@ -706,41 +709,41 @@ void error25(error) break; case 4: - VIOWRTCHARSTRATT( message4, 51, PageSize, 0, &attrib, 0 ); + VioWrtCharStrAtt( message4, 51, PageSize, 0, &attrib, 0 ); quit(1); break; /* 4 -> print message and quit */ case 5: - VIOWRTCHARSTRATT( message5, 51, PageSize, 0, &attrib, 0 ); + VioWrtCharStrAtt( message5, 51, PageSize, 0, &attrib, 0 ); quit(1); break; /* 5 -> print message and quit */ case 6: - VIOWRTCHARSTRATT( message6, 51, PageSize, 0, &attrib, 0 ); + VioWrtCharStrAtt( message6, 51, PageSize, 0, &attrib, 0 ); quit(1); break; /* 6 -> print message and quit */ case 7: - VIOWRTCHARSTRATT( message7, 51, PageSize, 0, &attrib, 0 ); - VIOSETCURPOS( PageSize, 44, 0 ); + VioWrtCharStrAtt( message7, 51, PageSize, 0, &attrib, 0 ); + VioSetCurPos( PageSize, 44, 0 ); while( 1 ) { /* 7 -> get a character from KBD */ - KBDCHARIN( &keydata, 0, 0 ); + KbdCharIn( &keydata, 0, 0 ); - if( (keydata.char_code == 's') || (keydata.char_code == 'S') ) { - VIOWRTCHARSTRATT( &keydata.char_code, 1, PageSize, 50, &attrib, 0 ); + if( (keydata.chChar == 's') || (keydata.chChar == 'S') ) { + VioWrtCharStrAtt( &keydata.chChar, 1, PageSize, 50, &attrib, 0 ); if ( !savefile(fhandle)) { /* if S, save file and quit */ freesegs(); - VIOSETCURPOS( PageSize, 0, 0 ); + VioSetCurPos( PageSize, 0, 0 ); quit(1); } else error25(11); /* call error 11 if can't save */ } - else if( (keydata.char_code == 'q') || (keydata.char_code == 'Q') ) { - VIOWRTCHARSTRATT( &keydata.char_code, 1, PageSize, 50, &attrib, 0 ); + else if( (keydata.chChar == 'q') || (keydata.chChar == 'Q') ) { + VioWrtCharStrAtt( &keydata.chChar, 1, PageSize, 50, &attrib, 0 ); quit(1); /* if Q, quit with error */ break; } @@ -751,29 +754,29 @@ void error25(error) break; case 8: - VIOWRTCHARSTRATT( message8, 51, PageSize, 0, &attrib, 0 ); + VioWrtCharStrAtt( message8, 51, PageSize, 0, &attrib, 0 ); quit(1); break; /* 8 -> print message and quit */ case 9: - VIOWRTCHARSTRATT( message9, 51, PageSize, 0, &attrib, 0 ); + VioWrtCharStrAtt( message9, 51, PageSize, 0, &attrib, 0 ); quit(1); break; /* 9 -> print message and quit */ case 10: - VIOWRTCHARSTRATT( message10, 51, PageSize, 0, &attrib, 0 ); + VioWrtCharStrAtt( message10, 51, PageSize, 0, &attrib, 0 ); quit(1); break; /* 10 -> print message and quit */ case 11: - VIOWRTCHARSTRATT( message11, 51, PageSize, 0, &attrib, 0 ); - VIOSETCURPOS( PageSize, 45, 0 ); + VioWrtCharStrAtt( message11, 51, PageSize, 0, &attrib, 0 ); + VioSetCurPos( PageSize, 45, 0 ); while( 1 ) { /* 11 -> get a character from KBD */ - KBDCHARIN( &keydata, 0, 0 ); + KbdCharIn( &keydata, 0, 0 ); - if( (keydata.char_code == 'c') || (keydata.char_code == 'C') ) { + if( (keydata.chChar == 'c') || (keydata.chChar == 'C') ) { name25(); break; /* C means continue */ } @@ -783,20 +786,20 @@ void error25(error) break; default: - VIOWRTCHARSTRATT( message99, 51, PageSize, 0, &attrib, 0 ); - VIOSETCURPOS( PageSize, 40, 0 ); + VioWrtCharStrAtt( message99, 51, PageSize, 0, &attrib, 0 ); + VioSetCurPos( PageSize, 40, 0 ); while( 1 ) { /* UNKNOWN error number! */ /* get a character from KBD */ - KBDCHARIN( &keydata, 0, 0 ); + KbdCharIn( &keydata, 0, 0 ); - if( (keydata.char_code == 'y') || (keydata.char_code == 'Y') ) { + if( (keydata.chChar == 'y') || (keydata.chChar == 'Y') ) { name25(); break; /* if Y, go ahead */ } - else if( (keydata.char_code == 'n') || (keydata.char_code == 'N') ) { - VIOWRTCHARSTRATT( &keydata.char_code, 1, PageSize, 50, &attrib, 0 ); + else if( (keydata.chChar == 'n') || (keydata.chChar == 'N') ) { + VioWrtCharStrAtt( &keydata.chChar, 1, PageSize, 50, &attrib, 0 ); quit(1); /* if N, quit with error */ break; }