unsigned long SysAddRexxMacro(unsigned char *name, unsigned long numargs, RXSTRING args[], char *queuename, RXSTRING *retstr) { unsigned long position; /* added position */ if (numargs < 2 || numargs > 3 || /* wrong number? */ !RXVALIDSTRING(args[0]) || /* first is omitted */ !RXVALIDSTRING(args[1])) /* second is omitted */ return INVALID_ROUTINE; /* raise error condition */ position = RXMACRO_SEARCH_BEFORE; /* set default search position*/ if (numargs == 3) { /* have an option? */ if (RXZEROLENSTRING(args[2])) return INVALID_ROUTINE; else if (toupper(args[2].strptr[0]) == 'B') position = RXMACRO_SEARCH_BEFORE; else if (toupper(args[2].strptr[0]) == 'A') position = RXMACRO_SEARCH_AFTER; else return INVALID_ROUTINE; /* raise an error */ } /* try to add the macro */ RETVAL(RexxAddMacro(args[0].strptr, args[1].strptr, position)) }
unsigned long SysPutEA(unsigned char *name, unsigned long numargs, RXSTRING args[], char *queuename, RXSTRING *retstr) { unsigned long rc; /* Ret code */ unsigned long act; /* open action */ void *fealist; /* fealist buffer */ EAOP2 eaop; /* eaop structure */ PFEA2 pfea; /* pfea structure */ HFILE handle; /* file handle */ if (numargs != 3 || !RXVALIDSTRING(args[0]) || !RXVALIDSTRING(args[1])) return INVALID_ROUTINE; if (rc = DosOpen2(args[0].strptr, &handle, &act, 0L, 0, OPEN_ACTION_OPEN_IF_EXISTS, OPEN_ACCESS_READWRITE + OPEN_SHARE_DENYWRITE + OPEN_FLAGS_FAIL_ON_ERROR + OPEN_FLAGS_WRITE_THROUGH, NULL)) { RETVAL(rc) } if (DosAllocMem((PPVOID)&fealist, 0x00010000L, AllocFlag)) { BUILDRXSTRING(retstr, ERROR_NOMEM); return VALID_ROUTINE; } eaop.fpFEA2List = (PFEA2LIST)fealist;/* Set memory for the FEA */ eaop.fpGEA2List = NULL; /* GEA is unused */ pfea = &eaop.fpFEA2List->list[0]; /* point to first FEA */ pfea->fEA = '\0'; /* set the flags */ /* Size of FEA name field */ pfea->cbName = (BYTE)args[1].strlength; /* Size of Value for this one */ pfea->cbValue = (SHORT)args[2].strlength; /* Set the name of this FEA */ strcpy((PSZ)pfea->szName, args[1].strptr); /* Set the EA value */ memcpy((PSZ)pfea->szName+(pfea->cbName+1), args[2].strptr, args[2].strlength); pfea->oNextEntryOffset = 0; /* no next entry */ eaop.fpFEA2List->cbList = /* Set the total size var */ sizeof(ULONG) + sizeof(FEA2) + pfea->cbName + pfea->cbValue; /* set the file info */ rc = DosSetFileInfo(handle, 2, (PSZ)&eaop, sizeof(EAOP2)); DosClose(handle); /* Close the File */ DosFreeMem(fealist); /* Free the memory */ RETVAL(rc) }
unsigned long SysWaitEventSem(unsigned char *name, unsigned long numargs, RXSTRING args[], char *queuename, RXSTRING *retstr) { unsigned long rc; unsigned long timeout = SEM_INDEFINITE_WAIT; /* timeout value default */ HEV handle = NULL; /* mutex handle */ #ifdef DLOGGING logmessage(__func__); #endif if (numargs < 1 || numargs > 2 || !RXVALIDSTRING(args[0])) return INVALID_ROUTINE; if (numargs == 2) { if (!string2ulong(args[1].strptr, &timeout)) return INVALID_ROUTINE; } if (!string2ulong(args[0].strptr, &handle)) return INVALID_ROUTINE; rc = DosWaitEventSem(handle, timeout); RETVAL(rc) }
ULONG EVRloadDialog(CHAR *name, ULONG numargs, RXSTRING args[], CHAR *queuename, RXSTRING *retstr) { ULONG pcount; CHAR *pChar; APIRET RC; BOOL rc; if (numargs < 1 || numargs > 3 || !RXVALIDSTRING(args[0])) return INVALID_ROUTINE; /* copy arguments to shared memory object ------------------------------- */ *(ULONG *) EVRsharedMem = strtoul(args[0].strptr,NULL,10); pChar = (CHAR*) (EVRsharedMem + sizeof(ULONG)); if (numargs>1 && RXVALIDSTRING(args[1])) strcpy(pChar,args[1].strptr); else *pChar = '\0'; pChar += strlen(pChar)+1; *pChar = '\0'; if (numargs>2 && RXVALIDSTRING(args[2])) { RC = DosSearchPath(SEARCH_CUR_DIRECTORY|SEARCH_ENVIRONMENT,"PATH", args[2].strptr,pChar,CCHMAXPATH); if (RC == 0) TRACE(4,"%x: REXX dialog-proc name: %s\n",EVRpid,pChar); } /* reset semaphore, broadcast message and wait until user responded ----- */ SetBroadcastWait(EVR_LOAD_DIALOG,"EVR_LOAD_DIALOG"); /* return result -------------------------------------------------------- */ return_rc(*(ULONG*) EVRsharedMem); }
/* * GCI_migrateRxString converts a RXSTRING into a GCI_str. No further memory * allocation is done and it is STRONGLY forbidden to use GCI_strfree. * The return value shall be used for further operations. */ static const GCI_str *GCI_migrateRxString( GCI_str *str, const RXSTRING *string ) { if ( !RXVALIDSTRING( *string ) && !RXZEROLENSTRING( *string ) ) { str->val = NULL; str->used = str->max = 0; } else { str->val = (char *) RXSTRPTR( *string ); str->used = str->max = (int) RXSTRLEN( *string ); } return str; }
unsigned long SysReorderRexxMacro(unsigned char *name, unsigned long numargs, RXSTRING args[], char *queuename, RXSTRING *retstr) { unsigned long position; /* added position */ if (numargs != 2 || !RXVALIDSTRING(args[0]) || RXZEROLENSTRING(args[1])) return INVALID_ROUTINE; /* raise error condition */ /* 'B'efore? */ if (toupper(args[1].strptr[0]) == 'B') position = RXMACRO_SEARCH_BEFORE; else if (toupper(args[1].strptr[0]) == 'A') position = RXMACRO_SEARCH_AFTER; else return INVALID_ROUTINE; /* try to add the macro */ RETVAL(RexxReorderMacro(args[0].strptr, position)) }
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; }
unsigned long SysQueryEAList(unsigned char *name, unsigned long numargs, RXSTRING args[], char *queuename, RXSTRING *retstr) { int countEA = 0; unsigned long rc; unsigned long act; unsigned long numberEA; unsigned long offset = 0; char szStemName[256] = {0}; char fileName[512] = {0}; char *pszStemIdx = NULL; char buffer[EABUFFER]; char eanum[5]; FEA2 *ptrBuffer; FILESTATUS3 status; HFILE handle; /* Only two arguments accepted */ if (numargs != 2 || !RXVALIDSTRING(args[0]) || !RXVALIDSTRING(args[1]) || args[0].strlength > 255) return INVALID_ROUTINE; /* remember stem name */ strcpy(szStemName, args[1].strptr); strupr(szStemName); strcpy(fileName, args[0].strptr); // check for '.' and if not there make it so if (szStemName[args[1].strlength-1] != '.') szStemName[args[1].strlength] = '.'; // pointer to the index part of stem pszStemIdx = &(szStemName[strlen(szStemName)]); // query to find if it is a file or directory if(DosQueryPathInfo(fileName, FIL_STANDARD, (void *)&status, sizeof(status))) return INVALID_ROUTINE; // if it is a file open it if(!(status.attrFile&FILE_DIRECTORY)) { if(DosOpen(fileName, &handle, &act, 0L, 0, FILE_OPEN, OPEN_ACCESS_READONLY + OPEN_SHARE_DENYWRITE + OPEN_FLAGS_FAIL_ON_ERROR, NULL)) return INVALID_ROUTINE; } numberEA = (ULONG)-1; rc = DosEnumAttribute(ENUMEA_REFTYPE_PATH, fileName, 1, (PVOID)&buffer, EABUFFER, (ULONG *)&numberEA, ENUMEA_LEVEL_NO_VALUE); if(rc) RETVAL(0) // if it is a file - close it if (!(status.attrFile&FILE_DIRECTORY)) DosClose(handle); ptrBuffer = (FEA2 *)&buffer; // set pointer to statrt of buffer if(numberEA != 0) { // if there are EAs found do { ptrBuffer = (PDENA2)((char *)ptrBuffer + offset); itoa(++countEA, pszStemIdx, 10); rc = SetRexxVariable(szStemName, ptrBuffer->szName); offset = ptrBuffer->oNextEntryOffset; } while ( ptrBuffer->oNextEntryOffset != 0 ); } // end of handling EAs // setup the 0 index with number of classes strcpy(pszStemIdx, "0"); sprintf(eanum, "%d", numberEA); rc = SetRexxVariable(szStemName, eanum); RETVAL(1); }
unsigned long SysIni(unsigned char *name, unsigned long numargs, RXSTRING args[], char *queuename, RXSTRING *retstr) { HINI hini; unsigned long x; unsigned long len; unsigned long lSize; char *IniFile = ""; char *App; char *Key = ""; char *Val; char Temp[256]; char UserName[256]; char SysName[256]; PRFPROFILE PrfInfo; long Error = FALSE; bool WildCard = FALSE; bool QueryApps; RXSTEMDATA ldp; // initialize PM HAB AnchBlk = NULLHANDLE; bool WinIntial = TRUE; #ifdef DLOGGING logmessage(__func__); #endif /* validate arguments */ if (numargs < 2 || numargs > 4 || !RXVALIDSTRING(args[1])) return INVALID_ROUTINE; /* get pointers to args */ IniFile = args[0].strptr; App = args[1].strptr; if (numargs >= 3 && args[2].strptr) Key = args[2].strptr; if (numargs == 4) Val = args[3].strptr; /* Check KEY and APP values for "WildCard" */ if (!stricmp(App, "ALL:")) { App = ""; QueryApps = TRUE; WildCard = TRUE; if (numargs != 3) return INVALID_ROUTINE; /* Error - Not enough args */ else x = 2; /* Arg number of STEM variable*/ } else if (!stricmp(Key, "ALL:")) { Key = ""; Val = ""; QueryApps = FALSE; WildCard = TRUE; if (numargs != 4) return INVALID_ROUTINE; /* Error - Not enough args */ else x = 3; /* Arg number of STEM variable*/ } /* * If this is a "WildCard search, then allocate mem * for stem struct and get the stem name */ if (WildCard == TRUE) { ldp.count = 0; /* get the stem variable name */ strcpy(ldp.varname, args[x].strptr); ldp.stemlen = args[x].strlength; strupr(ldp.varname); /* uppercase the name */ if (ldp.varname[ldp.stemlen-1] != '.') ldp.varname[ldp.stemlen++] = '.'; } WININIT(WinIntial,AnchBlk) /************************************************************** * The following section of code gets the INI file handle * * given the INI file spec (IniFile). * * * * Possible Ini file specs: * * * * NULL - Same as USERPROFILE ( OS2.INI ) * * "BOTH" - Same as PROFILE ( OS2.INI & OS2SYS.INI ) * * "USER" - Same as USERPROFILE ( OS2.INI ) * * "SYSTEM" - Same as SYSTEMPROFILE ( OS2SYS.INI) * * other - Filespec of INI file. * **************************************************************/ hini = NULLHANDLE; if (!IniFile) hini = HINI_USERPROFILE; else if (!stricmp(IniFile, "BOTH")) hini = HINI_PROFILE; else if (!stricmp(IniFile, "USER")) hini = HINI_USERPROFILE; else if (!stricmp(IniFile, "SYSTEM")) hini = HINI_SYSTEMPROFILE; /*********************************************************** * If Ini file spec is 'other' then make sure it does not * * specify the current USER or SYSTEM profiles. * * * * Trying to open the current USER or SYSTEM ini file via * * PrfOpenProfile() will fail. Therefore, use the function * * PrfQueryProfile() to query the current USER and SYSTEM * * ini file specs. If the IniFile string matches either * * the current USER or SYSTEM file specs, then use either * * HINI_USERPROFILE or HINI_SYSTEMPROFILE as appropriate. * * * * If IniFile does not specify the current USER or SYSTEM * * ini file then use PrfOpenProfile() to get the ini file * * handle. * ***********************************************************/ else { PrfInfo.pszUserName = UserName; PrfInfo.cchUserName = sizeof(UserName); PrfInfo.pszSysName = SysName; PrfInfo.cchSysName = sizeof(SysName); if (PrfQueryProfile(AnchBlk, &PrfInfo)) { if (!stricmp(IniFile, PrfInfo.pszUserName)) hini = HINI_USERPROFILE; else if (!stricmp(IniFile, PrfInfo.pszSysName)) hini = HINI_SYSTEMPROFILE; else hini = PrfOpenProfile(AnchBlk, IniFile); } else hini = PrfOpenProfile(AnchBlk, IniFile); /************************************************** * Exit with INI FILE error if the ini file handle * * is NULL at this point (and if IniFile != BOTH, * * as that would make the handle NULL also). * **************************************************/ if (hini == NULLHANDLE && stricmp(IniFile, "BOTH")) { BUILDRXSTRING(retstr, ERROR_RETSTR); WINTERM(WinIntial,AnchBlk) return VALID_ROUTINE; } }