home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
SAAREXX.ZIP
/
XMPMAIN.C
< prev
next >
Wrap
Text File
|
1991-08-03
|
13KB
|
306 lines
/*******************************************************************/
/* */
/* Module Name: XMPMAIN */
/* */
/* Description: Example program to invoke REXX/2. */
/* */
/* Function: Creates an example REXX subcommand */
/* environment and utilizes an external */
/* function package. */
/* */
/* Notes: */
/* */
/*******************************************************************/
/* Modifications: */
/* */
/* Date Who Reason */
/* -------- --- ---------------------------------------------- */
/* 08/01/91 WDA Original issue. */
/* */
/*******************************************************************/
#define INCL_DOS
#include <os2.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define INCL_RXFUNC
#define INCL_RXSYSEXIT
#define INCL_RXSUBCOM
#include <rexxsaa.h>
#include "xmpfxdll.h"
#include "xmpscdll.h"
/*******************************************************************/
/* */
/* Internal prototypes follow. */
/* */
/*******************************************************************/
static SHORT RegisterFuncs (VOID);
static SHORT DeRegisterFuncs (VOID);
SHORT APIENTRY XmpSysExitRXFNC (SHORT, SHORT, RXFNCCAL_PARM *);
SHORT APIENTRY XmpSysExitRXHLT (SHORT, SHORT, RXFNCCAL_PARM *);
SHORT APIENTRY CMDSubcom (PRXSTRING, PUSHORT, PRXSTRING);
/*******************************************************************/
/* */
/* Global variables and defines follow. */
/* */
/*******************************************************************/
static PSZ szXmpVersion = "0.02";
static PSZ szCompDate = __DATE__;
static RXSTRING rxResult;
static CHAR cResultBuffer[250];
static RXSYSEXIT rxSysExits[] = {{"XFNC", RXFNC},
{NULL, RXENDLST}};
static SCBLOCK XmpSCBLOCK = {NULL, "XMP", "", "", 0.,
(PFN) XmpSubcom, 0, 0, 0, 0};
static SCBLOCK SysExitSCBLOCK = {NULL, "XFNC", "", "", 0.,
(PFN) XmpSysExitRXFNC, 0, 0, 0, 0};
CHAR ExecName [CCHMAXPATH];
/*******************************************************************/
/* */
/* Function: main() */
/* */
/* Description: Main entry point to XmpMain from OS/2. */
/* */
/* Input Parms: Name of OS/2 file containg REXX procedure. */
/* */
/* Returns: Error code */
/* */
/* References: REXXSAA() */
/* */
/* Notes: */
/* */
/* This routine takes 1 parameter. The form of the call is: */
/* */
/* XMPMAIN REXXcmd[.cmd] */
/* */
/*******************************************************************/
SHORT _cdecl main (
SHORT argc, /* Number of arguments. */
PSZ argv[]) { /* Function arguments. */
SHORT sErrorCode = 0;
SHORT sRexxErrorCode;
RXSTRING rxsArg;
/* give banner information */
printf ("\nXmpMain - (c) W. David Ashley, 1991."
" All rights reserved.\n");
printf ("Example Version %s %s.\n", szXmpVersion,
szCompDate);
printf ("Written by W. David Ashley.\n\n");
/* arg count valid? */
if (argc == 3) {
/* set up REXX result buffer */
rxResult.strlength = 250;
rxResult.strptr = cResultBuffer;
/* set up XmpMain arguments */
rxsArg.strptr = argv[2];
rxsArg.strlength = strlen (argv[2]);
/* set up XmpMain REXX filename */
strcpy (ExecName, argv[1]);
if (strlen (ExecName) > 4) {
if (stricmp (ExecName + strlen (ExecName) - 4, ".cmd") != 0)
strcat (ExecName, ".cmd");
}
/* register our default environment with REXX */
sErrorCode = RxSubcomRegister (&XmpSCBLOCK);
if (sErrorCode == RXSUBCOM_DUP) {
RxSubcomDrop ("XMP", "");
sErrorCode = RxSubcomRegister (&SysExitSCBLOCK);
if (sErrorCode == RXSUBCOM_NOEMEM ||
sErrorCode == RXSUBCOM_BADTYPE) {
sErrorCode = -48;
printf ("Failure in system service.\n");
goto wrapup;
}
}
/* register our system exit handler with REXX */
sErrorCode = RxExitRegister (&SysExitSCBLOCK);
if (sErrorCode == RXSUBCOM_DUP) {
RxExitDrop ("XFNC", "");
sErrorCode = RxExitRegister (&SysExitSCBLOCK);
if (sErrorCode == RXSUBCOM_NOEMEM ||
sErrorCode == RXSUBCOM_BADTYPE) {
sErrorCode = -48;
printf ("Failure in system service.\n");
goto wrapup;
}
}
/* register our external functions with REXX */
if (RegisterFuncs() != RXFUNC_OK) {
sErrorCode = -48;
printf ("Failure in system service.\n");
goto wrapup;
}
/* call REXX */
sRexxErrorCode = REXXSAA (1, &rxsArg, ExecName, NULL, "XMP",
RXCOMMAND, rxSysExits, &sErrorCode,
&rxResult);
printf ("The return code from REXX was %d.\n", sRexxErrorCode);
if (sRexxErrorCode != 0)
sErrorCode = sRexxErrorCode;
/* drop our external functions with REXX */
DeRegisterFuncs();
/* drop our system exit handlers */
RxExitDrop ("XFNC", "");
/* drop our subcommand environment handler */
RxSubcomDrop ("XMP", "");
}
else {
printf ("XmpMain invocation incorrect. "
"One parameter (a file name) required.\n");
sErrorCode = -43;
}
wrapup:
printf ("XmpMain execution completed.\n");
return (sErrorCode);
}
/*******************************************************************/
/* */
/* Function: RegisterFuncs() */
/* */
/* Description: Register all our functions with REXX. */
/* */
/* Input Parms: None. */
/* */
/* Returns: Error code */
/* */
/* References: RxFunctionRegister() */
/* */
/* Notes: */
/* */
/* This routine takes 0 parameters. The form of the call is: */
/* */
/* retc = RegisterFuncs(); */
/* */
/*******************************************************************/
static SHORT RegisterFuncs (VOID) {
SHORT retc;
retc = RxFunctionRegister ("REXDIR", NULL, (PSZ) RexDir,
RXFUNC_CALLENTRY);
if (retc != RXFUNC_OK)
return (retc);
return (RXFUNC_OK);
}
/*******************************************************************/
/* */
/* Function: DeRegisterFuncs() */
/* */
/* Description: Deregister all our functions with REXX. */
/* */
/* Input Parms: None. */
/* */
/* Returns: Error code */
/* */
/* References: RxFunctionDeregister() */
/* */
/* Notes: */
/* */
/* This routine takes 0 parameters. The form of the call is: */
/* */
/* retc = DeRegisterFuncs(); */
/* */
/*******************************************************************/
static SHORT DeRegisterFuncs (VOID) {
SHORT retc = RXFUNC_OK;
retc |= RxFunctionDeregister ("REXDIR");
return (retc);
}
/*******************************************************************/
/* */
/* Function: XmpSysExitRXFNC() */
/* */
/* Description: System exit for REXX external function */
/* calls. This exit only checks to see if the */
/* function parameters are correct. REXX will */
/* actually attempt to execute the function */
/* only if this exit ok's the function parms. */
/* */
/* Input Parms: Function code */
/* Subfunction code */
/* Control block */
/* */
/* Returns: Error code 0 = function parameter error */
/* 1 = REXX should execute function*/
/* */
/* References: rx2i() */
/* */
/* Notes: */
/* */
/* None. */
/* */
/*******************************************************************/
SHORT APIENTRY XmpSysExitRXFNC (
SHORT func, /* Function code */
SHORT subfunc, /* Subfunction code */
RXFNCCAL_PARM * rxfnccal) { /* Parm control block */
SHORT sTemp;
if (func == RXFNC) {
switch (subfunc) {
case (RXFNCCAL):
if (memicmp ("REXDIR", rxfnccal -> rxfnc_name,
rxfnccal -> rxfnc_namel) == 0) {
if (rxfnccal -> rxfnc_argc < 2 ||
rxfnccal -> rxfnc_argc > 3) {
rxfnccal -> rxfnc_flags.rxfferr = 1;
return (0);
}
}
return (1);
default:
break;
}
}
/* If we get here either the function name was unknown or we */
/* did find it and successfully checked the function parms. */
/* REXX can now attempt to find and execute the function. */
return (1);
}