home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / SAAREXX.ZIP / XMPSCDLL.C < prev    next >
Text File  |  1991-08-02  |  6KB  |  125 lines

  1. /*******************************************************************/
  2. /*                                                                 */
  3. /* Module Name:        XMPSCDLL                                    */
  4. /*                                                                 */
  5. /* Description:        Example subcommand environment for REXX/2.  */
  6. /*                                                                 */
  7. /* Function:           A REXX subcommand environment packaged as a */
  8. /*                     DLL.                                        */
  9. /*                                                                 */
  10. /* Notes:                                                          */
  11. /*                                                                 */
  12. /*   The entry points obey the calling conventions for REXX        */
  13. /*   external functions.  Please use the following switches        */
  14. /*   when you compile this module:                                 */
  15. /*                                                                 */
  16. /*       -Alfu -G2s                                                */
  17. /*                                                                 */
  18. /*******************************************************************/
  19. /*   Modifications:                                                */
  20. /*                                                                 */
  21. /*    Date    Who        Reason                                    */
  22. /*  --------  ---  ----------------------------------------------  */
  23. /*  08/01/91  WDA  Original issue.                                 */
  24. /*                                                                 */
  25. /*******************************************************************/
  26.  
  27. #define INCL_DOS
  28. #include    <os2.h>
  29. #include    <stdlib.h>
  30. #include    <string.h>
  31.  
  32. #define INCL_RXSUBCOM
  33. #include    <rexxsaa.h>
  34.  
  35. #include    "xmpscdll.h"
  36.  
  37.  
  38. /*******************************************************************/
  39. /*                                                                 */
  40. /* Internal prototypes follow.                                     */
  41. /*                                                                 */
  42. /*******************************************************************/
  43.  
  44. /* none */
  45.  
  46.  
  47. /*******************************************************************/
  48. /*                                                                 */
  49. /* Global variables and defines follow.                            */
  50. /*                                                                 */
  51. /*******************************************************************/
  52.  
  53. static PSZ   szVersion  = "1.00";
  54. static PSZ   szCompDate = __DATE__;
  55.  
  56.  
  57. /*******************************************************************/
  58. /*                                                                 */
  59. /* Function:            XmpSubcom()                                */
  60. /*                                                                 */
  61. /* Description:         This is the XMP subcommand environment for */
  62. /*                      our example environment.                   */
  63. /*                                                                 */
  64. /* Input Parms:         Command string                             */
  65. /*                      Pointer to return flags                    */
  66. /*                      Pointer to return string                   */
  67. /*                                                                 */
  68. /* Returns:             Error code                                 */
  69. /*                                                                 */
  70. /* References:                                                     */
  71. /*                                                                 */
  72. /* Notes:                                                          */
  73. /*                                                                 */
  74. /*     None.                                                       */
  75. /*                                                                 */
  76. /*******************************************************************/
  77.  
  78. SHORT APIENTRY XmpSubcom (
  79.          PRXSTRING cmd,                /* Command string           */
  80.          PUSHORT   flags,              /* Return flags             */
  81.          PRXSTRING retval) {           /* Return string            */
  82.  
  83.    SHORT       len;
  84.    CHAR        FailName [CCHMAXPATH];
  85.    PSZ         parm;
  86.    RESULTCODES rescode;
  87.    static CHAR cmdname[] = "CMD";
  88.    static CHAR cmdparm[] = "/C ";
  89.  
  90.    /*******************************************************************/
  91.    /* All we are going to do here is pass on the command passed to us */
  92.    /* to another copy of CMD.EXE and have it execute the command.     */
  93.    /*******************************************************************/
  94.  
  95.    parm = malloc ((USHORT) cmd -> strlength + 30);
  96.    if (parm == NULL) {
  97.       *flags = RXSUBCOM_ERROR;
  98.       retval -> strlength = 0L;
  99.       return (0);
  100.       }
  101.    strcpy (parm, cmdname);
  102.    len = strlen (cmdname) + 1;
  103.    strcpy (parm + len, cmdparm);
  104.    len += strlen (cmdparm);
  105.    memcpy (parm + len, cmd -> strptr, (USHORT) cmd -> strlength);
  106.    len += (USHORT) cmd -> strlength;
  107.    *(parm + len) = '\0';                  // 2 nulls
  108.    *(parm + len + 1) = '\0';              //   required
  109.  
  110.    DosExecPgm (FailName, sizeof (FailName), EXEC_SYNC, parm, NULL,
  111.                &rescode, "CMD.EXE");
  112.  
  113.    if (rescode.codeTerminate != TC_EXIT)
  114.       *flags = RXSUBCOM_ERROR;
  115.    else
  116.       *flags = RXSUBCOM_OK;
  117.  
  118.    free (parm);
  119.  
  120.    itoa (rescode.codeResult, retval -> strptr, 10);
  121.    retval -> strlength = (ULONG) strlen (retval -> strptr);
  122.  
  123.    return (rescode.codeResult);
  124.    }
  125.