home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / c / cmdsys.zip / CMDMAIN.C < prev    next >
C/C++ Source or Header  |  1993-01-30  |  5KB  |  175 lines

  1. /*
  2.  *        cmdmain.c        Date=930130
  3.  *
  4.  *        Command line device driver.
  5.  *
  6.  *        Copyright (c) Richard Holm, 1993.
  7.  */
  8.  
  9. /*=====================================================================*/
  10.  
  11. #define INCL_KBD
  12. #define INCL_DOSFILEMGR
  13. #define INCL_DOSPROCESS
  14. #define INCL_DOSMISC
  15. #include <os2.h>
  16.  
  17. #include <stddd.h>
  18. #include <devhlp.h>
  19.  
  20. #include <string.h>
  21.  
  22. /*=====================================================================*/
  23.                     
  24. #define STDIN            0                                // standard in handle
  25. #define STDOUT            1                                // standard out handle
  26.  
  27. #define HKBD            0                                // default handle for keyboard
  28.  
  29. /*=====================================================================*/
  30.                     
  31. extern VOID _cdecl NEAR  CmdLineStrat( VOID );
  32.  
  33. USHORT NEAR CmdLineInit( REQ_PACKET FAR *pReqPak );
  34.  
  35. USHORT NEAR NoFunc( REQ_PACKET FAR *pReqPak );
  36.     
  37. /*=====================================================================*/
  38.  
  39. DEVICE_HDR  DevHdr[1] = {                        // device driver header
  40.                     { -1L,
  41.                     ( DAW_CHAR | DAW_OS2LEVEL | DAW_IOCTL ),
  42.                     (VOID NEAR *) CmdLineStrat,
  43.                     (VOID NEAR *) 0,
  44.                     "CMDLINE$"
  45.                     }};
  46.  
  47. /*=====================================================================*/
  48.  
  49. //        jump table for control/debug device
  50.  
  51. USHORT  (NEAR *CmdLineProc[])( REQ_PACKET FAR * ) = {
  52.                 CmdLineInit,                // init proc
  53.                 NoFunc,                        // media check proc
  54.                 NoFunc,                        // build BPB proc
  55.                 NoFunc,                        // unused
  56.                 NoFunc,                        // read proc
  57.                 NoFunc,                        // nondestructive read proc
  58.                 NoFunc,                        // input status proc
  59.                 NoFunc,                        // input flush proc
  60.                 NoFunc,                        // write proc
  61.                 NoFunc,                        // write with verify proc
  62.                 NoFunc,                        // output status proc
  63.                 NoFunc,                        // output flush proc
  64.                 NoFunc,                        // unused
  65.                 NoFunc,                        // open proc
  66.                 NoFunc,                        // close proc
  67.                 NoFunc,                        // removable media proc
  68.                 NoFunc,                        // generic IOCtl proc
  69.                 NoFunc,                        // reset media proc
  70.                 NoFunc,                        // get logical drive mapping proc
  71.                 NoFunc,                        // set logical drive mapping proc
  72.                 NoFunc,                        // deinstall proc
  73.                 NoFunc,                        // port access proc
  74.                 NoFunc,                        // partitionable fixed disks
  75.                 NoFunc,                        // get fixed disk/logical unit map
  76.                 NoFunc,                        // unused
  77.                 NoFunc,                        // unused
  78.                 NoFunc,                        // unused
  79.                 NoFunc,                        // unused
  80.                 NoFunc                        // shutdown
  81.                 };
  82.  
  83. #define NUM_CMDS        0x1c
  84.  
  85. /*=====================================================================*/
  86.  
  87. CHAR  InitMsg1[] = "\r\nOS/2 Command Line Device Driver.\r\n";
  88. CHAR  InitMsg2[] = "Version 1.00, (c) Copyright Richard Holm, 1993.\r\n";
  89. CHAR  InitMsg3[] = "All rights reserved.\r\n";
  90.  
  91. CHAR  PromptMsg[] = "\r\nPress ESC for command prompt...\n\r";
  92.  
  93. CHAR  KbdErrMsg[] = "\r\nERROR: Cannot read keyboard.\n\r";
  94.  
  95. CHAR  LineSkip[4] = "\r\n\r\n";
  96.  
  97. /*=====================================================================*/
  98.  
  99. USHORT CmdLineMain( REQ_PACKET FAR *pReqPak ) {
  100.     USHORT  status;
  101.  
  102.     if ( pReqPak->header.command <= NUM_CMDS )
  103.         status = (*CmdLineProc[pReqPak->header.command])( pReqPak );
  104.      else
  105.         status = NoFunc( pReqPak );
  106.  
  107.     return( status );
  108.     }
  109.  
  110. /*=====================================================================*/
  111.  
  112. USHORT NEAR CmdLineInit( REQ_PACKET FAR *pReqPak ) {
  113.     BOOL         done=FALSE;
  114.     KBDKEYINFO   key;
  115.     RESULTCODES  result;
  116.     USHORT       i;
  117.  
  118.     DosPutMessage( STDOUT, _fstrlen( InitMsg1 ), InitMsg1 );
  119.     DosPutMessage( STDOUT, _fstrlen( InitMsg2 ), InitMsg2 );
  120.     DosPutMessage( STDOUT, _fstrlen( InitMsg3 ), InitMsg3 );
  121.  
  122.     DevHelpInit( pReqPak->initPak.data.inData.devHlp );
  123.  
  124.     _fstrupr( pReqPak->initPak.data.inData.initArgs );
  125.  
  126.     KbdPeek( &key, HKBD );
  127.  
  128.     DosPutMessage( STDOUT, _fstrlen( PromptMsg ), PromptMsg );
  129.  
  130.     for ( i = 0; i < 20 && !done; i++ ) {
  131.         DosSleep( 250L );
  132.  
  133.         if ( KbdCharIn( &key, IO_NOWAIT, HKBD )) {
  134.             DosPutMessage( STDOUT, _fstrlen( KbdErrMsg ), KbdErrMsg );
  135.             break;
  136.             }
  137.  
  138.         if ( key.fbStatus & FINAL_CHAR_IN ) {
  139.             switch ( key.chChar ) {
  140.                 case '\x1b' :
  141.                      DosExecPgm( NULL, 0, EXEC_SYNC, "CMD\0", NULL, &result, 
  142.                         "C:\\OS2\\CMD.EXE" );
  143.                     done = TRUE;
  144.                     break;
  145.  
  146.                 case '\x0d' :                                // CR key
  147.                 case '\x20' :                                // space key
  148.                     done = TRUE;
  149.                     break;
  150.  
  151.                 default :
  152.                     DosBeep( 1000, 100 );
  153.                     break;
  154.                 }
  155.             }
  156.         }
  157.  
  158.     pReqPak->initPak.data.outData.logicalUnits = 0;
  159.     pReqPak->initPak.data.outData.endCS = 
  160.             SelectorLimit( HIUSHORT((VOID FAR *)CmdLineInit ));
  161.     pReqPak->initPak.data.outData.endDS = 
  162.             SelectorLimit( HIUSHORT((VOID FAR *)&DevHdr ));
  163.  
  164.     return( RC_DONE );
  165.     }
  166.  
  167. /*=====================================================================*/
  168.  
  169. USHORT NEAR NoFunc( REQ_PACKET FAR *pReqPak ) {
  170.     
  171.     return( RC_DONE | RC_ERROR | RC_UNKNOWN_CMD );
  172.     }
  173.  
  174. /*=====================================================================*/
  175.