home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / rexx / api / devinfo / devinfo.cmd < prev    next >
OS/2 REXX Batch file  |  1999-05-11  |  6KB  |  132 lines

  1. /*******************************************************************/
  2. /*                                                                 */
  3. /* DEVINFO.CMD                                                     */
  4. /*                                                                 */
  5. /* This program will run the DEVINFO sample.                       */
  6. /* This sample will shows REXX subcommand handler written in C.    */
  7. /* The subcommand handler calls the OS/2 DosDevConfig function     */
  8. /* to get some system information, and then passes it to REXX      */
  9. /* through the REXX variable pool.                                 */
  10. /*                                                                 */
  11. /* Files used for this sample                                      */
  12. /*   DEVINFO.CMD    This program.  Performs the compile and        */
  13. /*                  link.  Also issues subcommands to the          */
  14. /*                  handler.                                       */
  15. /*   DEVINFO.C      The subcommand handler                         */
  16. /*   DEVINFO.DEF    DEF file for the C program                     */
  17. /*                                                                 */
  18. /* Files created by this sample                                    */
  19. /*   DEVINFO.OBJ    compiled version of DEVINFO.C                  */
  20. /*   DEVINFO.DLL    linked version of DEVINFO.C                    */
  21. /*                                                                 */
  22. /*******************************************************************/
  23.  
  24.  
  25. /* We assume the current directory is on the LIBPATH.              */
  26. /* To use the DLL, we first register it with REXX, and then        */
  27. /* name it on an ADDRESS instruction.                              */
  28.  
  29. 'RXSUBCOM REGISTER DEVINFO DEVINFO DevInfo'
  30. Select
  31.    When rc = 30 then
  32.       Say 'DEVINFO subcommand handler was already registered'
  33.    When rc = 0 then  Nop          /* rc = 0 means normal           */
  34.    otherwise
  35.       Say 'DEVINFO.CMD:  Some error on RXSUBCOM REGISTER,',
  36.           'return code is' rc
  37. end  /* select */
  38.  
  39.  
  40. /*******************************************************************/
  41. /* Now we are ready to go.  This subcommand handler will return    */
  42. /* numeric answers for the following commands.  The answers are    */
  43. /* automatically assigned to the variable of the same name.        */
  44. /* In addition, the command "ALL" will set all the variables.      */
  45. /*                                                                 */
  46. /*   Command    Meaning                                            */
  47. /*   -------    ---------------------------------------------------*/
  48. /*   PARALLEL   number of parallel ports                           */
  49. /*   RS232      number of serial ports                             */
  50. /*   DISKETTE   number of diskette drives                          */
  51. /*   MATH       whether a math coprocessor is available (1=yes)    */
  52. /*   SUBMODEL   system sub-model ID byte (returned in decimal)     */
  53. /*   MODEL      system model id byte (returned in decimal)         */
  54. /*   DISPLAY    display type (0=mono/printer, 1= other)            */
  55. /*                                                                 */
  56. /* The subcommand handler will return with RC=0 for success.       */
  57. /* If the command is not valid, it will raise the ERROR condition  */
  58. /* and put a message in the RC variable.                           */
  59. /* If the subcommand handler has a problem calling DosDevConfig    */
  60. /* or RexxVariablePool, it will raise the FAILURE condition        */
  61. /* and put the bad return code into the RC variable.               */
  62. /*******************************************************************/
  63.  
  64. Call On Error
  65. Call On Failure
  66.  
  67. Say 'Now checking on your parallel port(s)'
  68. Address DEVINFO 'PARALLEL'
  69. If rc = 0 Then Say 'Your number of parallel port(s) is' parallel
  70. Say ' '
  71.  
  72. Say 'Now checking on your diskette drive(s)'
  73. Address DEVINFO 'DISKETTE'
  74. If rc = 0 Then Say 'Your number of diskette drive(s) is' diskette
  75. Say ' '
  76.  
  77. Say 'Now you can try other commands.  The commands are:'
  78. Say 'PARALLEL, RS232, DISKETTE, MATH, SUBMODEL, MODEL, DISPLAY,'
  79. Say 'and ALL.'
  80. Say 'You may also enter an invalid command. ',
  81.     'Enter a null line to quit'
  82.  
  83. Do Forever
  84.    /* Drop all the variables, so the action of the subcommand      */
  85.    /* handler will be more visible.                                */
  86.    Drop parallel rs232 diskette math submodel model display
  87.  
  88.    /* Read in a line from the keyboard and make it upper case.     */
  89.    Parse Upper Linein input
  90.    If input = '' Then Leave       /* exit loop for null line       */
  91.    Address DEVINFO input
  92.  
  93.    If rc = 0 then Do
  94.       Say 'Now the value of the variable' input' is',
  95.           value(input)
  96.       If input = 'ALL' Then Do
  97.          Say 'Here are the values of all the variables set'
  98.          Say 'PARALLEL ="'parallel'"'
  99.          Say 'RS232    ="'rs232'"'
  100.          Say 'DISKETTE ="'diskette'"'
  101.          Say 'MATH     ="'math'"'
  102.          Say 'SUBMODEL ="'submodel'"'
  103.          Say 'MODEL    ="'model'"'
  104.          Say 'DISPLAY  ="'display'"'
  105.          End  /* listing ALL */
  106.       End /* rc = 0 */
  107.  
  108.    Say ' '
  109.    Say 'Enter another command, or null line to quit.'
  110. end /* Do Forever */
  111.  
  112. 'RXSUBCOM DROP DEVINFO'           /* Clean up after ourselves      */
  113. Say 'DEVINFO sample program complete.'
  114. '@PAUSE'
  115. exit
  116.  
  117.  
  118. /*******************************************************************/
  119. failure:
  120. Say '   FAILURE condition raised.'
  121. Say '   There was some problem calling OS/2 system services'
  122. Say '   The return code from OS/2 is' rc
  123. return
  124.  
  125.  
  126. /*******************************************************************/
  127. error:
  128. say '   ERROR condition raised, the command was invalid.'
  129. Say '   The command was "'Condition("D")'".'
  130. Say '   The error code set by DEVINFO.DLL is' rc
  131. return
  132.