static int set_rexx_variable( char *name, int suffix, char *value, int value_length ) { SHVBLOCK shv; char variable_name[250]; int rc=0; shv.shvnext=NULL; /* only one block */ shv.shvcode=RXSHV_SET; /* use direct set */ sprintf( variable_name, "%s.%-d", name, suffix ); (void)make_upper( variable_name );/* make variable name uppercase */ /* * Now (attempt to) set the REXX variable * Add name/value to SHVBLOCK */ MAKERXSTRING( shv.shvname, variable_name, strlen( variable_name) ); MAKERXSTRING( shv.shvvalue, value, value_length ); /* * One or both of these is needed, too <sigh> */ shv.shvnamelen = strlen( variable_name ); shv.shvvaluelen = value_length; rc = RexxVariablePool( &shv ); /* Set the REXX variable */ if ( rc != RXSHV_OK && rc != RXSHV_NEWV) { rc = 1; } else rc = 0; return rc; }
unsigned long SetRexxVar ( char * pszVar, /* Variable name to be set */ char * pValue, /* Ptr to new value */ size_t ulLen) /* Value length */ { /* local function data */ SHVBLOCK RxVarBlock; unsigned long ulRetc; /* initialize RxVarBlock */ RxVarBlock.shvnext = NULL; RxVarBlock.shvname.strptr = pszVar; RxVarBlock.shvname.strlength = strlen(pszVar); RxVarBlock.shvnamelen = RxVarBlock.shvname.strlength; RxVarBlock.shvvalue.strptr = pValue; RxVarBlock.shvvalue.strlength = ulLen; RxVarBlock.shvvaluelen = ulLen; RxVarBlock.shvcode = RXSHV_SYSET; RxVarBlock.shvret = RXSHV_OK; /* set variable in pool */ ulRetc = RexxVariablePool(&RxVarBlock); /* test return code */ if (ulRetc == RXSHV_NEWV) { ulRetc = RXSHV_OK; } return ulRetc; }
int FetchStem (RXSTEMDATA stemin, float *dati) { sprintf (stemin.varname + stemin.stemlen, "%d", stemin.count); stemin.shvb.shvnext = NULL; stemin.shvb.shvvalue.strptr = stemin.ibuf; stemin.shvb.shvvalue.strlength = MAX; stemin.shvb.shvname.strptr = stemin.varname; stemin.shvb.shvname.strlength = strlen (stemin.varname); stemin.shvb.shvcode = RXSHV_FETCH; stemin.shvb.shvret = 0; if (RexxVariablePool (&stemin.shvb) == RXSHV_BADN) { SendMsg (0, ERR_REXXPOOL); return 0; } if (stemin.shvb.shvret) return stemin.shvb.shvret; strcpy (stemin.ibuf, stemin.shvb.shvvalue.strptr); *dati = atof (stemin.ibuf); return 0; }
LONG REXX_GetStemVariable (PCHAR DestPtr, ULONG DestMaxLength, PSZ VarNameBase, USHORT VarNameID) { ULONG VarNameBaseLen = strlen(VarNameBase); CHAR VarWorker[256]; PCHAR TmpPos = (PCHAR)((ULONG)&VarWorker+VarNameBaseLen); SHVBLOCK SharedVarBlock; if (DestMaxLength==0) return -1; // No destination space... *DestPtr = 0; // Set NUL-string if ((VarNameBaseLen==0) || (VarNameBaseLen>250)) return -1; // Buffer-overflow or no variable memcpy(&VarWorker, VarNameBase, VarNameBaseLen); if (*(TmpPos-1)!=0x2E) return -1; // No stem variable itoa(VarNameID, TmpPos, 10); SharedVarBlock.shvnext = NULL; SharedVarBlock.shvname.strptr = (PCHAR)&VarWorker; SharedVarBlock.shvname.strlength = strlen(VarWorker); SharedVarBlock.shvvalue.strptr = DestPtr; SharedVarBlock.shvvalue.strlength = DestMaxLength-1; SharedVarBlock.shvcode = RXSHV_FETCH; if ((RexxVariablePool(&SharedVarBlock)) && (SharedVarBlock.shvret==0)) return -1; TmpPos = DestPtr+SharedVarBlock.shvvaluelen; *TmpPos = 0; // Set terminating NUL return SharedVarBlock.shvvaluelen; }
char *FetchRexxVariable(char *name) //, char *value) { unsigned long rc; SHVBLOCK block; // memset(block, '\0', sizeof(block)); block.shvcode = RXSHV_SYFET; block.shvret = 0; block.shvnext = NULL; MAKERXSTRING(block.shvname, name, strlen(name)); block.shvnamelen = block.shvname.strlength; block.shvvalue.strptr = NULL; block.shvvalue.strlength = 0; rc = RexxVariablePool(&block); // value = block.shvvalue.strptr; // memcpy(value, block.shvvalue.strptr, block.shvvalue.strlength); // value[block.shvvalue.strlength+1] = '\0'; // DosFreeMem(block.shvvalue.strptr); // do I need this? return block.shvvalue.strptr; }
unsigned long FetchRexxVar ( char * pszVar, /* Variable name */ PRXSTRING prxVar) /* REXX variable contents */ { /* local function variables */ SHVBLOCK RxVarBlock; unsigned long ulRetc; char * pszTemp; /* initialize the shared variable block */ RxVarBlock.shvnext = NULL; RxVarBlock.shvname.strptr = pszVar; RxVarBlock.shvname.strlength = strlen(pszVar); RxVarBlock.shvnamelen = RxVarBlock.shvname.strlength; RxVarBlock.shvvalue.strptr = NULL; RxVarBlock.shvvalue.strlength = 0; RxVarBlock.shvvaluelen = 0; RxVarBlock.shvcode = RXSHV_SYFET; RxVarBlock.shvret = RXSHV_OK; /* fetch variable from pool */ ulRetc = RexxVariablePool(&RxVarBlock); /* test return code */ if (ulRetc != RXSHV_OK && ulRetc != RXSHV_NEWV) { prxVar -> strptr = NULL; prxVar -> strlength = 0; } else { /* allocate a new buffer for the Rexx variable pool value */ pszTemp = (char *) RexxAllocateMemory(RxVarBlock.shvvalue.strlength + 1); if (pszTemp == NULL) { /* no buffer available so return a NULL Rexx value */ prxVar -> strptr = NULL; prxVar -> strlength = 0; ulRetc = RXSHV_MEMFL; } else { /* copy to new buffer and zero-terminate */ memmove(pszTemp, RxVarBlock.shvvalue.strptr, RxVarBlock.shvvalue.strlength); *(pszTemp + RxVarBlock.shvvalue.strlength) = '\0'; prxVar -> strptr = pszTemp; prxVar -> strlength = RxVarBlock.shvvalue.strlength; } // free memory returned from RexxVariablePool API RexxFreeMemory(RxVarBlock.shvvalue.strptr); } return ulRetc; }
BOOL REXX_SetVariable (PSZ VarName, PCHAR StringPtr, ULONG StringLen) { SHVBLOCK SharedVarBlock; SharedVarBlock.shvnext = NULL; SharedVarBlock.shvname.strptr = VarName; SharedVarBlock.shvname.strlength = strlen(VarName); SharedVarBlock.shvvalue.strptr = StringPtr; SharedVarBlock.shvvalue.strlength = StringLen; SharedVarBlock.shvcode = RXSHV_SET; if ((RexxVariablePool(&SharedVarBlock)) && (SharedVarBlock.shvret==0)) return FALSE; return TRUE; }
/* * DeleteRexxVariable - Set the value of a REXX variable * * Easy way to delete stem variables * * name - stem name and index <ex: test.0> */ unsigned long DropRexxVariable(char *name) { unsigned long rc; SHVBLOCK block; block.shvcode = RXSHV_DROPV; block.shvret = 0; block.shvnext = NULL; MAKERXSTRING(block.shvname, name, strlen(name)); block.shvnamelen = block.shvname.strlength; rc = RexxVariablePool(&block); // DosFreeMem(block.shvvalue.strptr); // do I need this? return rc; }
// RxVariableToRxString -- Get a REXX string from a REXX variable. // // Return: REXX Variable Pool return code // ULONG RxVariableToRxString( const RXSTRING *rxVariable, PRXSTRING rxString) { SHVBLOCK block; ULONG cc; block.shvcode = RXSHV_SYFET; block.shvret = RXSHV_OK; block.shvnext = NULL; block.shvname = *rxVariable; block.shvnamelen = block.shvname.strlength; block.shvvalue = *rxString; block.shvvaluelen = 0; cc = RexxVariablePool(&block); if (cc == REXXAPI_OK) *rxString = block.shvvalue; return cc; }
// StringToRxVariable -- Store a string into a REXX variable. // // Return: REXX Variable Pool return code // ULONG StringToRxVariable( const char *string, LONG length, PRXSTRING rxName) { SHVBLOCK block; ULONG cc; if (string != NULL && length < 0) length = strlen(string); block.shvcode = RXSHV_SYSET; block.shvret = RXSHV_OK; block.shvnext = NULL; block.shvname = *rxName; block.shvnamelen = block.shvname.strlength; block.shvvalue.strptr = (PCH)string; block.shvvalue.strlength = (USHORT)length; block.shvvaluelen = (USHORT)length; cc = RexxVariablePool(&block) & ~RXSHV_NEWV; return cc; }
BOOL REXX_SetStemVariable (PSZ VarNameBase, USHORT VarNameID, PCHAR StringPtr, ULONG StringLen) { ULONG VarNameBaseLen = strlen(VarNameBase); CHAR VarWorker[256]; PCHAR TmpPos = (PCHAR)((ULONG)&VarWorker+VarNameBaseLen); SHVBLOCK SharedVarBlock; if ((VarNameBaseLen==0) || (VarNameBaseLen>250)) return FALSE; // Buffer-overflow or no variable memcpy(&VarWorker, VarNameBase, VarNameBaseLen); if (*(TmpPos-1)!=0x2E) return FALSE; // No stem variable itoa(VarNameID, TmpPos, 10); SharedVarBlock.shvnext = NULL; SharedVarBlock.shvname.strptr = (PCHAR)&VarWorker; SharedVarBlock.shvname.strlength = strlen(VarWorker); SharedVarBlock.shvvalue.strptr = StringPtr; SharedVarBlock.shvvalue.strlength = StringLen; SharedVarBlock.shvcode = RXSHV_SET; if ((RexxVariablePool(&SharedVarBlock)) && (SharedVarBlock.shvret==0)) return FALSE; return TRUE; }
unsigned long SysGetEA(unsigned char *name, unsigned long numargs, RXSTRING args[], char *queuename, RXSTRING *retstr) { long rc; /* Ret code */ unsigned char geabuff[300]; /* buffer for GEA */ unsigned long act; /* open action */ void *fealist; /* fealist buffer */ EAOP2 eaop; /* eaop structure */ PGEA2 pgea; /* pgea structure */ PFEA2 pfea; /* pfea structure */ HFILE handle; /* file handle */ RXSTEMDATA ldp; /* stem data */ if (numargs != 3 || !RXVALIDSTRING(args[0]) || !RXVALIDSTRING(args[1]) || !RXVALIDSTRING(args[2])) return INVALID_ROUTINE; ldp.count = 0; /* get the stem variable name */ strcpy(ldp.varname, args[2].strptr); ldp.stemlen = args[2].strlength; strupr(ldp.varname); /* uppercase the name */ if (rc = DosOpen(args[0].strptr, &handle, &act, 0L, 0, OPEN_ACTION_OPEN_IF_EXISTS, OPEN_ACCESS_READONLY + OPEN_SHARE_DENYREADWRITE + OPEN_FLAGS_FAIL_ON_ERROR + OPEN_FLAGS_WRITE_THROUGH, NULL)) { RETVAL(rc) } /* get the file status info */ if (DosAllocMem((PPVOID)&fealist, 0x00010000L, AllocFlag)) { BUILDRXSTRING(retstr, ERROR_NOMEM); return VALID_ROUTINE; } /* FEA and GEA lists */ eaop.fpGEA2List = (PGEA2LIST)geabuff; eaop.fpFEA2List = (PFEA2LIST)fealist; eaop.oError = 0; /* no error occurred yet */ pgea = &eaop.fpGEA2List->list[0]; /* point to first GEA */ eaop.fpGEA2List->cbList = sizeof(ULONG) + sizeof(GEA2) + args[1].strlength; eaop.fpFEA2List->cbList = (ULONG)0xffff; /* fill in the EA name length */ pgea->cbName = (BYTE)args[1].strlength; strcpy(pgea->szName, args[1].strptr);/* fill in the name */ pgea->oNextEntryOffset = 0; /* fill in the next offset */ /* read the extended attribute*/ rc = DosQueryFileInfo(handle, 3, (PSZ)&eaop, sizeof(EAOP2)); DosClose(handle); /* close the file */ if (eaop.fpFEA2List->cbList <= sizeof(ULONG)) rc = ERROR_EAS_NOT_SUPPORTED; /* this is error also */ sprintf(retstr->strptr, "%d", rc); /* format return code */ retstr->strlength = strlen(retstr->strptr); if (rc) { /* failure? */ DosFreeMem(fealist); /* error, get out */ return VALID_ROUTINE; } pfea = &(eaop.fpFEA2List->list[0]); /* point to the first FEA */ ldp.shvb.shvnext = NULL; ldp.shvb.shvname.strptr = ldp.varname; ldp.shvb.shvname.strlength = ldp.stemlen; ldp.shvb.shvnamelen = ldp.stemlen; ldp.shvb.shvvalue.strptr = ((PSZ)pfea->szName+(pfea->cbName+1)); ldp.shvb.shvvalue.strlength = pfea->cbValue; ldp.shvb.shvvaluelen = ldp.shvb.shvvalue.strlength; ldp.shvb.shvcode = RXSHV_SET; ldp.shvb.shvret = 0; if (RexxVariablePool(&ldp.shvb) == RXSHV_BADN) { DosFreeMem(fealist); /* free our buffer */ return INVALID_ROUTINE; /* error on non-zero */ } DosFreeMem(fealist); /* free our buffer */ return VALID_ROUTINE; }
LONG REXXENTRY Api_Read_All_Elements_Of_A_Specific_Stem_From_REXX_VP( PSZ name, /* Function name */ LONG numargs, /* Number of arguments */ RXSTRING args[], /* Argument array */ PSZ queuename, /* Current queue */ PRXSTRING retstr ) /* Return RXSTRING */ { SHVBLOCK rxshv; SHVBLOCK *prxshv = &rxshv, *temp, *interim; RexxReturnCode rc; char array[20], value[10]; char pch[64], *result; char *varName; int chars; int j, k = 0; if (numargs != 1 ) /* validate arg count */ return INVALID_ROUTINE; strcpy(retstr->strptr, "0"); retstr->strlength = strlen(retstr->strptr); strncpy(pch, args[0].strptr, 64); prxshv->shvnext = NULL; prxshv->shvname.strptr = pch; /* here we use our own buffer that is limited to 64 characters */ prxshv->shvname.strlength = strlen(pch); prxshv->shvvalue.strptr = NULL; /* let rexx allocate for me */ prxshv->shvcode = RXSHV_SYFET; rc = RexxVariablePool(prxshv); if (rc) { strcpy(retstr->strptr, "ApiFETCH failed \n"); retstr->strlength = strlen(retstr->strptr); return VALID_ROUTINE; } j = atoi(prxshv->shvvalue.strptr); chars = '.'; result = strrchr(pch, chars); result++; *result = 0x00; temp = prxshv; memset(array, 0x00, sizeof(array)); memset(value, 0x00, sizeof(value)); for (k = 1;k <= j; k++) { temp->shvnext = (PSHVBLOCK)malloc(sizeof(SHVBLOCK)); /* allocate a new node */ temp = temp->shvnext; if (!temp) { strcpy(retstr->strptr, "Allocation error occured"); retstr->strlength = strlen(retstr->strptr); return VALID_ROUTINE; } strcpy(array, pch); sprintf(value, "%d", k); strcat(array, value); temp->shvnext = NULL; temp->shvname.strlength = strlen(array); varName = malloc(strlen(array)+1); strcpy(varName, array); temp->shvname.strptr = varName; temp->shvvalue.strptr = NULL; /* let rexx allocate it for me */ temp->shvcode = RXSHV_SYFET; } temp = prxshv->shvnext; /* first allocated one */ rc = RexxVariablePool(temp); if (rc) { if (rc== RXSHV_MEMFL) { strcpy(retstr->strptr, "Allocation error occured"); retstr->strlength = strlen(retstr->strptr); return VALID_ROUTINE; } else if (rc != RXSHV_LVAR) { printf("ERROR: shvret is %x hex after var nr. %d\n",rc,k); return INVALID_ROUTINE; } } for (k = 1;k <= j; k++) { printf("Name of the Stem-variable from the Variable Pool: %s, Value: %s \n", temp->shvname.strptr,temp->shvvalue.strptr); free((void *)temp->shvname.strptr); /* allocated by us and therefore freed with free */ RexxFreeMemory(temp->shvvalue.strptr); /* allocated by REXX and therefore freed by RexxFreeMemory */ interim = temp; temp = temp->shvnext; /* process next in list */ free(interim); /* free current node */ } RexxFreeMemory(prxshv->shvvalue.strptr); /* allocated by REXX and freed by RexxFreeMemory */ return VALID_ROUTINE; }
LONG REXXENTRY Api_Read_All_Variables_From_REXX_VP( PSZ name, /* Function name */ LONG numargs, /* Number of arguments */ RXSTRING args[], /* Argument array */ PSZ queuename, /* Current queue */ PRXSTRING retstr ) /* Return RXSTRING */ { SHVBLOCK rxshv; SHVBLOCK *prxshv = &rxshv; RexxReturnCode rc; int i = 1; strcpy(retstr->strptr, "0"); retstr->strlength = strlen(retstr->strptr); prxshv->shvnext = NULL; prxshv->shvname.strlength = 0; prxshv->shvname.strptr = NULL; /* let rexx allocate it for me */ prxshv->shvvalue.strptr = NULL; /* let rexx allocate it for me */ /* Another way would be to assign an existing buffer and specify its max. length */ prxshv->shvcode = RXSHV_NEXTV; /* Now reading all variables from the REXX-variable pool ***********/ rc = RexxVariablePool(prxshv); if (rc) { if (rc != RXSHV_LVAR) { printf("ERROR: shvret is %x hex after var nr. %d \n",rc,i); return INVALID_ROUTINE; } } if (prxshv->shvvalue.strlength) printf("Name of the variable from the Variable Pool: %s, Value: %s \n", prxshv->shvname.strptr, prxshv->shvvalue.strptr); else printf("Name of the variable from the Variable Pool: %s, Empty\n", prxshv->shvname.strptr); i++; RexxFreeMemory((void *)prxshv->shvname.strptr); /* free pointers allocated by REXX */ RexxFreeMemory(prxshv->shvvalue.strptr); /* free pointers allocated by REXX */ while (!prxshv->shvret) { prxshv->shvret = 0; prxshv->shvnext = NULL; prxshv->shvname.strlength = 0; prxshv->shvname.strptr = NULL; /* let rexx allocate it for me */ prxshv->shvvalue.strptr = NULL; /* let rexx allocate it for me */ prxshv->shvcode = RXSHV_NEXTV; rc = RexxVariablePool(prxshv); if (rc) { if (rc== RXSHV_MEMFL) { strcpy(retstr->strptr, "Allocation error occured"); retstr->strlength = strlen(retstr->strptr); return VALID_ROUTINE; } else if (rc != RXSHV_LVAR) { printf("ERROR: shvret is %x hex after var nr. %d\n",rc,i); return INVALID_ROUTINE; } } i++; if (!prxshv->shvret) { if (prxshv->shvvalue.strlength) printf("Name of the variable from the Variable Pool: %s, Value: %s \n", prxshv->shvname.strptr, prxshv->shvvalue.strptr); else printf("Name of the variable from the Variable Pool: %s, Empty\n", prxshv->shvname.strptr); RexxFreeMemory((void *)prxshv->shvname.strptr); /* free pointers allocated by REXX */ RexxFreeMemory(prxshv->shvvalue.strptr); /* free pointers allocated by REXX */ } } return VALID_ROUTINE; }