home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgLangD.iso / C++-7 / DISK4 / SAMPLES / PWBEXTEN / TWOKEY.C$ / TWOKEY
Encoding:
Text File  |  1992-01-15  |  4.2 KB  |  139 lines

  1. /* TWOKEY.C -- Popular two-keystroke editor sequences.
  2.  *
  3.  * Functions illustrated include:
  4.  *
  5.  *      ReadChar    DoMessage    fExecute    SetKey
  6.  *
  7.  */
  8.  
  9. #pragma warning( disable:4001 )  //Allow single-line comments
  10. #pragma warning( disable:4100 )  //Allow unused arguments
  11.  
  12. #include <stdlib.h>
  13. #include <ext.h>
  14.  
  15. void _cdecl EXTERNAL WhenLoaded( void );
  16.  
  17. PWBFUNC CtrlQ( unsigned argData, ARG _far *pArg, flagType fMeta );
  18. PWBFUNC CtrlK( unsigned argData, ARG _far *pArg, flagType fMeta );
  19. flagType DoSecondKey( char *table[] );
  20.  
  21. // Handle second key of sequence.
  22. flagType DoSecondKey( char *table[] )
  23. {
  24.     int c;
  25.  
  26.     // Get key and clear status bar
  27.     c = toupper( (unsigned char)ReadChar() );
  28.     DoMessage( NULL );
  29.  
  30.     // Adjust so that CTRL+A, 'A', and 'a' are the same index.
  31.     if( c < 27 )
  32.         --c;
  33.     else if( (c < 'A') || (c > 'Z') )
  34.         return FALSE;
  35.     else
  36.         c -= 'A';
  37.  
  38.     // Look up the command in a table of command strings and execute it.
  39.     if( table[c] )
  40.         return fExecute( table[c] );
  41.     return TRUE;
  42. }
  43.  
  44. // Handle CTRL+Q commands
  45. PWBFUNC CtrlQ( unsigned argData, ARG _far *pArg, flagType fMeta )
  46. {
  47.     static char *CtrlQKeys[] =
  48.     {
  49.     /* A Query replace    */ "qreplace",
  50.     /* B                  */ "",
  51.     /* C End of file      */ "endfile",
  52.     /* D End of line      */ "endline",
  53.     /* E Top of window    */ "meta up",
  54.     /* F Query search     */ "arg \"Search String\" prompt -> psearch",
  55.     /* G                  */ "",
  56.     /* H                  */ "",
  57.     /* I                  */ "",
  58.     /* J                  */ "",
  59.     /* K                  */ "",
  60.     /* L                  */ "",
  61.     /* M                  */ "",
  62.     /* N Goto mark        */ "restcur",
  63.     /* O                  */ "",
  64.     /* P                  */ "",
  65.     /* Q                  */ "",
  66.     /* R Start of file    */ "begfile",
  67.     /* S Left of window   */ "meta left",
  68.     /* T                  */ "",
  69.     /* U                  */ "",
  70.     /* V                  */ "",
  71.     /* W                  */ "",
  72.     /* X Bottom of window */ "meta down",
  73.     /* Y Delete to EOL    */ "arg ldelete",
  74.     /* Z                  */ ""
  75.     };
  76.  
  77.     DoMessage( "Second key: A C D E F N R S X Y" );
  78.     return DoSecondKey( CtrlQKeys );
  79. }
  80.  
  81. // Handle CTRL+K sequence.
  82. PWBFUNC CtrlK( unsigned argData, ARG _far *pArg, flagType fMeta )
  83. {
  84.     static char *CtrlKKeys[] =
  85.     {
  86.     /* A                       */ "",
  87.     /* B Begin selection       */ "arg",
  88.     /* C                       */ "copy paste",
  89.     /* D Exit, no autosave     */ "meta exit <",
  90.     /* E                       */ "",
  91.     /* F                       */ "",
  92.     /* G                       */ "",
  93.     /* H                       */ "",
  94.     /* I                       */ "",
  95.     /* J                       */ "",
  96.     /* K                       */ "",
  97.     /* L                       */ "",
  98.     /* M                       */ "",
  99.     /* N Set mark              */ "savecur",
  100.     /* O                       */ "",
  101.     /* P Print current file    */ "print",
  102.     /* Q Exit all, no autosave */ "arg meta exit <",
  103.     /* R Insert file           */ "arg arg \"Filename: \" prompt -> paste",
  104.     /* S Save file             */ "arg arg setfile <",
  105.     /* T Select word           */ "pword ->e mword arg meta pword => :>e mword pword arg meta pword",
  106.     /* U                       */ "",
  107.     /* V                       */ "",
  108.     /* W                       */ "",
  109.     /* X Save all and exit     */ "_pwbsaveall exit",
  110.     /* Y Yank                  */ "delete",
  111.     /* Z                       */ ""
  112.     };
  113.  
  114.     DoMessage( "Second key: B C D N P Q R S T X Y" );
  115.     return DoSecondKey( CtrlKKeys );
  116. }
  117.  
  118. // Initialize the command keys.
  119. void _cdecl EXTERNAL WhenLoaded( void )
  120. {
  121.     DoStatusBox( "TwoKey Sample Extensions", NULL );
  122.  
  123.     SetKey( "CtrlQ", "ctrl+q" );
  124.     SetKey( "CtrlK", "ctrl+k" );
  125.  
  126.     DoStatusBox( NULL, NULL );
  127. }
  128.  
  129. // No switches
  130. struct swiDesc swiTable[] = { { NULL, NULL, 0 } };
  131.  
  132. // Commands
  133. struct cmdDesc cmdTable[] =
  134. {
  135.     { "CtrlQ", CtrlQ, 0, CURSORFUNC },
  136.     { "CtrlK", CtrlK, 0, CURSORFUNC },
  137.     { NULL,    NULL,  0, 0 }
  138. };
  139.