home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 9.ddi / TVSRC.ZIP / DRIVERS2.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  4.5 KB  |  89 lines

  1. /*------------------------------------------------------------------------*/
  2. /*                                                                        */
  3. /*  filename - drivers2.cpp                                               */
  4. /*                                                                        */
  5. /*  function(s)                                                           */
  6. /*      ctrlToArrow -- map control keys to arrow keys                     */
  7. /*      cstrlen     -- calculate length of a control string               */
  8. /*                                                                        */
  9. /*------------------------------------------------------------------------*/
  10.  
  11. /*------------------------------------------------------------------------*/
  12. /*                                                                        */
  13. /*    Turbo Vision -  Version 1.0                                         */
  14. /*                                                                        */
  15. /*                                                                        */
  16. /*    Copyright (c) 1991 by Borland International                         */
  17. /*    All Rights Reserved.                                                */
  18. /*                                                                        */
  19. /*------------------------------------------------------------------------*/
  20.  
  21. #define Uses_TKeys
  22. #include <tv.h>
  23.  
  24. /*------------------------------------------------------------------------*/
  25. /*                                                                        */
  26. /*  ctrlToArrow                                                           */
  27. /*                                                                        */
  28. /*  argument:                                                             */
  29. /*                                                                        */
  30. /*      keyCode - scan code to be mapped to keypad arrow code             */
  31. /*                                                                        */
  32. /*  returns:                                                              */
  33. /*                                                                        */
  34. /*      scan code for arrow key corresponding to Wordstar key,            */
  35. /*      or original key code if no correspondence exists                  */
  36. /*                                                                        */
  37. /*------------------------------------------------------------------------*/
  38. ushort ctrlToArrow(ushort keyCode)
  39. {
  40.  
  41. const uchar ctrlCodes[] =
  42.     {
  43.     kbCtrlS, kbCtrlD, kbCtrlE, kbCtrlX, kbCtrlA,
  44.     kbCtrlF, kbCtrlG, kbCtrlV, kbCtrlR, kbCtrlC, kbCtrlH
  45.     };
  46.  
  47. const ushort arrowCodes[] =
  48.     {
  49.     kbLeft, kbRight, kbUp, kbDown, kbHome,
  50.     kbEnd,  kbDel,   kbIns,kbPgUp, kbPgDn, kbBack
  51.     };
  52.  
  53.     for( int i = 0; i < sizeof(ctrlCodes); i++ )
  54.         if( (keyCode & 0x00ff) == ctrlCodes[i] )
  55.             return arrowCodes[i];
  56.     return keyCode;
  57. }
  58.  
  59. /*------------------------------------------------------------------------*/
  60. /*                                                                        */
  61. /*  cstrlen                                                               */
  62. /*                                                                        */
  63. /*  argument:                                                             */
  64. /*                                                                        */
  65. /*      s       - pointer to 0-terminated string                          */
  66. /*                                                                        */
  67. /*  returns                                                               */
  68. /*                                                                        */
  69. /*      length of string, ignoring '~' characters.                        */
  70. /*                                                                        */
  71. /*  Comments:                                                             */
  72. /*                                                                        */
  73. /*      Used in determining the displayed length of command strings,      */
  74. /*      which use '~' to toggle between display attributes                */
  75. /*                                                                        */
  76. /*------------------------------------------------------------------------*/
  77.  
  78. int cstrlen( const char *s )
  79. {
  80.     int len = 0;
  81.     while( *s != EOS )
  82.         {
  83.         if( *s++ != '~' )
  84.             len++;
  85.         }
  86.     return len;
  87. }
  88.  
  89.