int main(int argc, char *argv[]) { AREXXCONTEXT RexxStuff = InitARexx("TEST", "test"); BOOL quit = FALSE; printf("running at port \"%s\" with mask %ld\n", ARexxName(RexxStuff), ARexxSignal(RexxStuff)); do { ULONG signals = ARexxSignal(RexxStuff); struct RexxMsg *message = NULL; STRPTR result = NULL; signals = Wait(signals); message = GetARexxMsg(RexxStuff); while (message != NULL) { STRPTR command = NULL; printf("message = %p\n", message); command = ARG0(message); printf("command = %p \"%s\"\n", command, command); if (!stricmp(command, "quit")) { printf("Quitting.\n"); quit = TRUE; } ReplyARexxMsg(RexxStuff, message, result, RC_OK); message = GetARexxMsg(RexxStuff); } } while (!quit); FreeARexx(RexxStuff); }
/* * This routine initializes an ARexx port for your process * This should only be done once per process. You must call it * with a valid application name and you must use the handle it * returns in all other calls... * * NOTE: The AppName should not have spaces in it... * Example AppNames: "MyWord" or "FastCalc" etc... * The name *MUST* be less that 16 characters... * If it is not, it will be trimmed... * The name will also be UPPER-CASED... * * NOTE: The Default file name extension, if NULL will be * "rexx" (the "." is automatic) */ AREXXCONTEXT InitARexx(char *AppName,char *Extension) { register AREXXCONTEXT RexxContext=NULL; register short loop; register short count; register char *tmp; if (RexxContext=AllocMem(sizeof(struct ARexxContext), MEMF_PUBLIC|MEMF_CLEAR)) { if (RexxContext->arc_RexxSysBase=OpenLibrary("rexxsyslib.library", NULL)) { /* * Set up the extension... */ if (!Extension) Extension="rexx"; tmp=RexxContext->Extension; for (loop=0;(loop<7)&&(Extension[loop]);loop++) { *tmp++=Extension[loop]; } *tmp='\0'; /* * Set up a port name... */ tmp=RexxContext->PortName; for (loop=0;(loop<16)&&(AppName[loop]);loop++) { *tmp++=toupper(AppName[loop]); } *tmp='\0'; /* We need to make a unique port name... */ Forbid(); for (count=1,RexxContext->ARexxPort=(VOID *)1; RexxContext->ARexxPort;count++) { stci_d(tmp,count); RexxContext->ARexxPort= FindPort(RexxContext->PortName); } RexxContext->ARexxPort=CreatePort( RexxContext->PortName,NULL); Permit(); /* * Set up the last error RVI name... * * This is <appname>.LASTERROR */ strcpy(RexxContext->ErrorName,RexxContext->PortName); strcat(RexxContext->ErrorName,".LASTERROR"); } if ( (!(RexxContext->arc_RexxSysBase)) || (!(RexxContext->ARexxPort)) ) { FreeARexx(RexxContext); RexxContext=NULL; } } return(RexxContext); }