home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / TELECOM / stg_v4.lzh / key.c < prev    next >
C/C++ Source or Header  |  1994-11-11  |  4KB  |  187 lines

  1. /*
  2.  * 89/??/?? StG original concept and specs for DB9 format
  3.  * 90/09/?? StG coding began
  4.  * 91/05/27 StG updated to new naming conventions, fixed bugs
  5.  *
  6.  * DB9 keyboard input routines
  7.  * (c) 1990 by StG Computers inc.
  8.  * Unauthorized Reproduction Prohibited
  9.  *
  10.  * code=_Key(wait)
  11.  *
  12.  * wait= 0 - return key code or 0 for no key pressed yet
  13.  *       1 - wait for key pressed, return key code
  14.  *
  15.  * code= key code as defined in key.h
  16. */
  17.  
  18. #define ERR (-1)
  19. #include "key.h"
  20.  
  21. extern int errno;
  22.  
  23. /* path descriptor buffers for _Eko() */
  24. #ifdef _OSK
  25. char _pdsav[128];
  26. char _pdwrk[128];
  27. #endif
  28.  
  29. #ifdef _UNIX
  30. #include <termio.h>
  31. struct termio sTermIO;
  32. struct termio sTermSav;
  33. #endif
  34.  
  35. /* turn echo off when reading character from keyboard (internal) */
  36. _Eko(iTurnOff)
  37. int iTurnOff;
  38. {
  39.     static int iIsOff=0;
  40.  
  41.     /* dufus check */
  42.     if (!iTurnOff && !iIsOff) return(0);
  43.     if (iTurnOff && iIsOff) return(0);
  44.  
  45. #ifdef _OSK
  46.     if (iIsOff)
  47.     {
  48.         /* turn back on */
  49.         _ss_opt(0,_pdsav);
  50.         iIsOff=0;
  51.         return(0);
  52.     }
  53.  
  54.     /* turn off */
  55.     _gs_opt(0,_pdsav);
  56.     _gs_opt(0,_pdwrk);
  57.  
  58.     _pdwrk[0x04]=0;  /* no echo */
  59.     _pdwrk[0x07]=0;  /* no pause */
  60.     _pdwrk[0x0C]=0;  /* no ERR */
  61.     _pdwrk[0x10]=0;  /* no pause chr */
  62.     _pdwrk[0x11]=0;  /* no interrupt */
  63.     _pdwrk[0x12]=0;  /* no abort */
  64.  
  65.     _ss_opt(0,_pdwrk);
  66.     iIsOff=1;
  67.     return(0);
  68. #endif
  69.  
  70. #ifdef _UNIX
  71.     if (iIsOff)
  72.     {
  73.         /* turn back on */
  74.         ioctl(0,TCSETAF,&sTermSav);
  75.         iIsOff=0;
  76.         return(0);
  77.     }
  78.  
  79.     /* turn off */
  80.     ioctl(0,TCGETA,&sTermIO);
  81.     ioctl(0,TCGETA,&sTermSav);
  82.     sTermIO.c_lflag=0;        /* no echo, raw, etc. */
  83.     sTermIO.c_cc[4]=0;        /* minimum # of chars */
  84.     sTermIO.c_cc[5]=1;        /* maximum amt of time */
  85.     ioctl(0,TCSETAF,&sTermIO);
  86.     iIsOff=1;
  87.     return(0);
  88. #endif
  89. }
  90.  
  91.  
  92. _Key(iWait)
  93. int iWait;
  94. {
  95.     char cKey;
  96.  
  97. #ifdef _OSK
  98.     if (!iWait && _gs_rdy(0)==ERR)
  99.         return(0);
  100.  
  101.     _Eko(1);
  102. #endif
  103.     while (read(0,&cKey,1)!=1)
  104.         if (!iWait)
  105.             return(0);
  106. #ifdef _OSK
  107.     _Eko(0);
  108. #endif
  109.     if (cKey==27) goto keyesc;
  110.     if (cKey==24) goto keyfun;
  111.  
  112.     return(cKey);
  113.  
  114. keyesc:
  115. #ifdef _OSK
  116.     tsleep(15);
  117.     if (_gs_rdy(0)==ERR)
  118.         return(cKey);
  119. #endif
  120. keyfun:
  121.  
  122. #ifdef _OSK
  123.     _Eko(1);
  124. #endif
  125.     if (read(0,&cKey,1)!=1)
  126.         return(27);
  127. #ifdef _OSK    
  128.     _Eko(0);
  129. #endif
  130.     return(cKey+128);
  131. }
  132.  
  133. #ifdef BOGUS
  134. /* saved MSDOS routine */
  135.     unsigned int uKey;    /* msdos return code */
  136.     char cKey;
  137.  
  138.     if (!iWait && !bioskey(1)) return(0);
  139.  
  140.     uKey=bioskey(0);
  141.     cKey=uKey&0xFF;
  142.     uKey=(uKey>>8)&0xFF;
  143.  
  144.     if (cKey==24) goto keyfun;
  145.  
  146.     if (!cKey) switch(uKey)
  147.     {
  148.         /* keypad keys */
  149.         case 71: cKey=KY_HOME; break;
  150.         case 75: cKey=KY_LEFT; break;
  151.         case 82: cKey=KY_INS; break;
  152.         case 83: cKey=KY_DEL; break;
  153.         case 79: cKey=KY_END; break;
  154.         case 77: cKey=KY_RIGHT; break;
  155.         case 80: cKey=KY_DOWN; break;
  156.         case 72: cKey=KY_UP; break;
  157.         case 81: cKey=KY_PGDN; break;
  158.         case 73: cKey=KY_PGUP; break;
  159.  
  160.         /* Function Keys */
  161.         case 59: cKey=KY_FUN('1'); break;
  162.         case 60: cKey=KY_FUN('2'); break;
  163.         case 61: cKey=KY_FUN('3'); break;
  164.         case 62: cKey=KY_FUN('4'); break;
  165.         case 63: cKey=KY_FUN('5'); break;
  166.         case 64: cKey=KY_FUN('6'); break;
  167.         case 65: cKey=KY_FUN('7'); break;
  168.         case 66: cKey=KY_FUN('8'); break;
  169.         case 67: cKey=KY_FUN('9'); break;
  170.         case 68: cKey=KY_FUN('0'); break;
  171.  
  172.         /* put alt-letter keys here */
  173.  
  174.  
  175.         default: cKey=KY_ABORT; break;
  176.     }
  177.  
  178.     return(cKey);
  179.  
  180. keyfun:
  181.     uKey=bioskey(0);
  182.     cKey=uKey&0xFF;
  183.     uKey=(uKey>>8)&0xFF;
  184.     return(cKey+128);
  185. }
  186. #endif
  187.