From: <bi...@us...> - 2008-07-04 12:51:26
|
Revision: 2649 http://oorexx.svn.sourceforge.net/oorexx/?rev=2649&view=rev Author: bigrixx Date: 2008-07-04 05:51:34 -0700 (Fri, 04 Jul 2008) Log Message: ----------- platform interface cleanup Modified Paths: -------------- interpreter-3.x/trunk/kernel/api/InterpreterAPI.cpp interpreter-3.x/trunk/kernel/classes/RoutineClass.cpp interpreter-3.x/trunk/kernel/classes/StringClass.cpp interpreter-3.x/trunk/kernel/expression/BuiltinFunctions.cpp interpreter-3.x/trunk/kernel/platform/unix/ErrorMessages.cpp interpreter-3.x/trunk/kernel/platform/unix/ExternalFunctions.cpp interpreter-3.x/trunk/kernel/platform/unix/MemorySupport.cpp interpreter-3.x/trunk/kernel/platform/unix/MiscSystem.cpp interpreter-3.x/trunk/kernel/platform/unix/PlatformDefinitions.h interpreter-3.x/trunk/kernel/platform/unix/SysInterpreterInstance.cpp interpreter-3.x/trunk/kernel/platform/unix/SystemCommands.cpp interpreter-3.x/trunk/kernel/platform/unix/SystemInterpreter.hpp interpreter-3.x/trunk/kernel/platform/unix/ThreadSupport.cpp interpreter-3.x/trunk/kernel/platform/unix/TimeSupport.cpp interpreter-3.x/trunk/kernel/platform/unix/UseridFunction.cpp interpreter-3.x/trunk/kernel/platform/unix/ValueFunction.cpp interpreter-3.x/trunk/kernel/platform/windows/ErrorMessages.cpp interpreter-3.x/trunk/kernel/platform/windows/ExternalFunctions.cpp interpreter-3.x/trunk/kernel/platform/windows/MemorySupport.cpp interpreter-3.x/trunk/kernel/platform/windows/MiscSystem.cpp interpreter-3.x/trunk/kernel/platform/windows/PlatformDefinitions.h interpreter-3.x/trunk/kernel/platform/windows/SysFile.cpp interpreter-3.x/trunk/kernel/platform/windows/SysInterpreterInstance.cpp interpreter-3.x/trunk/kernel/platform/windows/SystemCommands.cpp interpreter-3.x/trunk/kernel/platform/windows/SystemInterpreter.hpp interpreter-3.x/trunk/kernel/platform/windows/TimeSupport.cpp interpreter-3.x/trunk/kernel/platform/windows/UseridFunction.cpp interpreter-3.x/trunk/kernel/platform/windows/ValueFunction.cpp interpreter-3.x/trunk/kernel/runtime/ProgramMetaData.cpp interpreter-3.x/trunk/kernel/runtime/ProgramMetaData.hpp interpreter-3.x/trunk/kernel/runtime/RexxActivation.cpp interpreter-3.x/trunk/kernel/runtime/RexxActivity.cpp interpreter-3.x/trunk/kernel/runtime/RexxNativeActivation.cpp interpreter-3.x/trunk/kernel/runtime/Setup.cpp interpreter-3.x/trunk/lib/RexxPlatformInterface.h interpreter-3.x/trunk/platform/windows/oodialog/oovutil.cpp interpreter-3.x/trunk/rexxapi/windows/QueuesAPI.c Modified: interpreter-3.x/trunk/kernel/api/InterpreterAPI.cpp =================================================================== --- interpreter-3.x/trunk/kernel/api/InterpreterAPI.cpp 2008-07-04 04:09:49 UTC (rev 2648) +++ interpreter-3.x/trunk/kernel/api/InterpreterAPI.cpp 2008-07-04 12:51:34 UTC (rev 2649) @@ -59,6 +59,7 @@ #include "InterpreterInstance.hpp" #include "RexxNativeActivation.hpp" #include "RexxInternalApis.h" +#include "SystemInterpreter.hpp" int REXXENTRY RexxTerminate() @@ -231,7 +232,7 @@ size_t s6 = strlen(vbuf6); size_t sd = strlen(__DATE__); size_t sv = strlen(ver); - char *ptr = (char *)SysAllocateResultMemory(sv+s0+s1+s2+s3+s4+s5+s6+sd+1); + char *ptr = (char *)SystemInterpreter::allocateResultMemory(sv+s0+s1+s2+s3+s4+s5+s6+sd+1); if (ptr) { sprintf(ptr, "%s%s%s%s%s%s%s%s%s", vbuf0, ver, vbuf1, __DATE__, vbuf2, vbuf3, vbuf4, vbuf5, vbuf6); Modified: interpreter-3.x/trunk/kernel/classes/RoutineClass.cpp =================================================================== --- interpreter-3.x/trunk/kernel/classes/RoutineClass.cpp 2008-07-04 04:09:49 UTC (rev 2648) +++ interpreter-3.x/trunk/kernel/classes/RoutineClass.cpp 2008-07-04 12:51:34 UTC (rev 2649) @@ -61,6 +61,7 @@ #include "RexxSmartBuffer.hpp" #include "ProgramMetaData.hpp" #include "Utilities.hpp" +#include "SystemInterpreter.hpp" #include <ctype.h> @@ -651,7 +652,7 @@ /* unflatten the method now */ RoutineClass *routine = restore(&buffer, name); // release the buffer memory - SysReleaseResultMemory(buffer.strptr); + SystemInterpreter::releaseResultMemory(buffer.strptr); return routine; } Modified: interpreter-3.x/trunk/kernel/classes/StringClass.cpp =================================================================== --- interpreter-3.x/trunk/kernel/classes/StringClass.cpp 2008-07-04 04:09:49 UTC (rev 2648) +++ interpreter-3.x/trunk/kernel/classes/StringClass.cpp 2008-07-04 12:51:34 UTC (rev 2649) @@ -55,6 +55,7 @@ #include "ProtectedObject.hpp" #include "StringUtil.hpp" #include "RexxCompoundTail.hpp" +#include "SystemInterpreter.hpp" // singleton class instance RexxClass *RexxString::classInstance = OREF_NULL; @@ -1773,7 +1774,7 @@ size_t result_length = getLength() + 1; if (r.strptr == NULL || r.strlength < result_length) { - r.strptr = (char *)SysAllocateResultMemory(result_length); + r.strptr = (char *)SystemInterpreter::allocateResultMemory(result_length); } // copy all of the data + the terminating null memcpy(r.strptr, getStringData(), result_length); Modified: interpreter-3.x/trunk/kernel/expression/BuiltinFunctions.cpp =================================================================== --- interpreter-3.x/trunk/kernel/expression/BuiltinFunctions.cpp 2008-07-04 04:09:49 UTC (rev 2648) +++ interpreter-3.x/trunk/kernel/expression/BuiltinFunctions.cpp 2008-07-04 12:51:34 UTC (rev 2649) @@ -901,7 +901,7 @@ BUILTIN(USERID) { check_args(USERID); - return SysUserid(); + return SystemInterpreter::getUserid(); } #define ERRORTEXT_MIN 1 @@ -909,21 +909,22 @@ #define ERRORTEXT_n 1 BUILTIN(ERRORTEXT) { - wholenumber_t error_number; /* requested error number */ - RexxString *result; /* function result */ - - check_args(ERRORTEXT); /* check on required number of args */ - /* get the error number */ - error_number = (required_integer(ERRORTEXT, n))->getValue(); - /* outside allowed range? */ - if (error_number < 0 || error_number > 99) - /* this is an error */ - reportException(Error_Incorrect_call_range, CHAR_ERRORTEXT, IntegerOne, error_number); - /* retrieve the major error message */ - result = (RexxString *)SysMessageText(error_number * 1000); - if (result == OREF_NULL) /* not found? */ - result = OREF_NULLSTRING; /* this is a null string result */ - return result; /* finished */ + check_args(ERRORTEXT); /* check on required number of args */ + /* get the error number */ + wholenumber_t error_number = (required_integer(ERRORTEXT, n))->getValue(); + /* outside allowed range? */ + if (error_number < 0 || error_number > 99) + { + /* this is an error */ + reportException(Error_Incorrect_call_range, CHAR_ERRORTEXT, IntegerOne, error_number); + } + /* retrieve the major error message */ + RexxString *result = SystemInterpreter::getMessageText(error_number * 1000); + if (result == OREF_NULL) /* not found? */ + { + result = OREF_NULLSTRING; /* this is a null string result */ + } + return result; /* finished */ } #define ARG_MIN 0 @@ -1269,7 +1270,7 @@ case 'L': /* 'L'ocal */ { /* get the month name */ - RexxString *month_name = (RexxString *)SysMessageText(Message_Translations_January + month - 1); + RexxString *month_name = SystemInterpreter::getMessageText(Message_Translations_January + month - 1); /* format as a date */ sprintf(work, "%u %s %4.4u", day, month_name->getStringData(), year); break; @@ -1706,7 +1707,7 @@ else /* external value function */ { // try the platform defined selectors. - if (SysValue(variable, newvalue, selector, result)) + if (SystemInterpreter::valueFunction(variable, newvalue, selector, result)) { return result; } Modified: interpreter-3.x/trunk/kernel/platform/unix/ErrorMessages.cpp =================================================================== --- interpreter-3.x/trunk/kernel/platform/unix/ErrorMessages.cpp 2008-07-04 04:09:49 UTC (rev 2648) +++ interpreter-3.x/trunk/kernel/platform/unix/ErrorMessages.cpp 2008-07-04 12:51:34 UTC (rev 2649) @@ -89,73 +89,75 @@ #define SECOND_PARAMETER 0 /* 0 for no NL_CAT_LOCALE */ #endif -RexxString * SysMessageText( /* simplified whole code */ - wholenumber_t code ) /* message code to extract */ -/****************************************************************************/ -/* Function: Return a message from the message catalog, including header. */ -/****************************************************************************/ + +/** + * Retrieve the message text for a give error code. + * + * @param code The Rexx error code + * + * @return The error message associated with that code. + */ +RexxString *SystemInterpreter::getMessageText(wholenumber_t code ) { #if defined( HAVE_NL_TYPES_H ) - nl_catd catd; /* catalog descriptor from catopen() */ + nl_catd catd; /* catalog descriptor from catopen() */ #endif - int set_num = 1; /* message set 1 from catalog */ - ERROR_MESSAGE *p; /* message table scan pointer */ - int msgid; /* message number */ - char DataArea[256]; /* buf to return message */ - char *message; - /* loop through looking for the */ - /* error code */ + int set_num = 1; /* message set 1 from catalog */ + ERROR_MESSAGE *p; /* message table scan pointer */ + int msgid; /* message number */ + char DataArea[256]; /* buf to return message */ + char *message; + /* loop through looking for the */ + /* error code */ #if defined( HAVE_CATOPEN ) - for (p = Message_table; p->code != 0; p++) { - if (p->code == code) { /* found the target code? */ + for (p = Message_table; p->code != 0; p++) + { + if (p->code == code) + { /* found the target code? */ - msgid = p->msgid; /* get msg number associated w/ error*/ - /* open message catalog in NLSPATH */ - if ((catd = catopen(REXXMESSAGEFILE, SECOND_PARAMETER)) == (nl_catd)CATD_ERR) - { - sprintf(DataArea, "%s/%s", ORX_CATDIR, REXXMESSAGEFILE); - if ((catd = catopen(DataArea, SECOND_PARAMETER)) == (nl_catd)CATD_ERR) - { - sprintf(DataArea, "\nCannot open REXX message catalog %s.\nNot in NLSPATH or %s.\n", - REXXMESSAGEFILE, ORX_CATDIR); - return new_string((char *)&DataArea, strlen(DataArea)); - } - } /* retrieve message from repository */ - message = catgets(catd, set_num, msgid, NULL); - if(!message) /* got a message ? */ - { -# if defined(OPSYS_LINUX) && !defined(OPSYS_SUN) - sprintf(DataArea, "%s/%s", ORX_CATDIR, REXXMESSAGEFILE); - if ((catd = catopen(DataArea, SECOND_PARAMETER)) == (nl_catd)CATD_ERR) - { - sprintf(DataArea, "\nCannot open REXX message catalog %s.\nNot in NLSPATH or %s.\n", - REXXMESSAGEFILE, ORX_CATDIR); - return new_string((char *)&DataArea, strlen(DataArea)); - } - else - { - message = catgets(catd, set_num, msgid, NULL); - if(!message) /* got a message ? */ - strcpy(DataArea,"Error message not found!"); - else - strcpy(DataArea, message); - } -# else - strcpy(DataArea,"Error message not found!"); -# endif - } - else - strcpy(DataArea, message); - catclose(catd); /* close the catalog */ - /* convert and return the message */ - return new_string((char *)&DataArea, strlen(DataArea)); - } - } - return OREF_NULL; /* no message retrieved */ + msgid = p->msgid; /* get msg number associated w/ error*/ + /* open message catalog in NLSPATH */ + if ((catd = catopen(REXXMESSAGEFILE, SECOND_PARAMETER)) == (nl_catd)CATD_ERR) + { + sprintf(DataArea, "%s/%s", ORX_CATDIR, REXXMESSAGEFILE); + if ((catd = catopen(DataArea, SECOND_PARAMETER)) == (nl_catd)CATD_ERR) + { + sprintf(DataArea, "\nCannot open REXX message catalog %s.\nNot in NLSPATH or %s.\n", + REXXMESSAGEFILE, ORX_CATDIR); + return new_string((char *)&DataArea, strlen(DataArea)); + } + } /* retrieve message from repository */ + message = catgets(catd, set_num, msgid, NULL); + if (!message) /* got a message ? */ + { +#if defined(OPSYS_LINUX) && !defined(OPSYS_SUN) + sprintf(DataArea, "%s/%s", ORX_CATDIR, REXXMESSAGEFILE); + if ((catd = catopen(DataArea, SECOND_PARAMETER)) == (nl_catd)CATD_ERR) + { + sprintf(DataArea, "\nCannot open REXX message catalog %s.\nNot in NLSPATH or %s.\n", + REXXMESSAGEFILE, ORX_CATDIR); + return new_string((char *)&DataArea, strlen(DataArea)); + } + else + { + message = catgets(catd, set_num, msgid, NULL); + if (!message) /* got a message ? */ + strcpy(DataArea,"Error message not found!"); + else + strcpy(DataArea, message); + } #else - sprintf(DataArea,"Cannot get description for error %d",msgid); - return new_string((char *)&DataArea, strlen(DataArea)); + strcpy(DataArea,"Error message not found!"); #endif +<<<<<<< .mine + } + else + strcpy(DataArea, message); + catclose(catd); /* close the catalog */ + /* convert and return the message */ + return new_string((char *)&DataArea, strlen(DataArea)); + } +======= } @@ -198,187 +200,73 @@ void SystemInterpreter::restoreEnvironment( void *CurrentEnv) /* saved environment */ { - char *current; /* ptr to saved environment */ - unsigned long size; /* size of the saved space */ - unsigned long length; /* string length */ - char *begin; /* begin of saved space */ - char **Environment; /* environment pointer */ + char *current; /* ptr to saved environment */ + unsigned long size; /* size of the saved space */ + unsigned long length; /* string length */ + char *begin; /* begin of saved space */ + char **Environment; /* environment pointer */ - char * del = NULL; /* ptr to old unused memory */ - char * Env_Var_String; /* enviornment entry */ - char namebufsave[256],namebufcurr[256]; - char * np; - int i; + char * del = NULL; /* ptr to old unused memory */ + char * Env_Var_String; /* enviornment entry */ + char namebufsave[256],namebufcurr[256]; + char * np; + int i; - Environment = environ; /* get the current environment*/ + Environment = environ; /* get the current environment*/ - begin = current = (char *)CurrentEnv; /* get the saved space */ - size = ((ENVENTRY*)current)->size; /* first read out the size */ - current += 4; /* update the pointer */ - if (chdir(current) == -1) /* restore the curr dir */ - { - reportException(Error_System_service_service, (const stringchar_t *)"ERROR CHANGING DIRECTORY"); - } - current += strlen(current); /* update the pointer */ - current++; /* jump over '\0' */ - if(!putflag){ /* first change in the */ - /* environment ? */ - /* copy all entries to dynamic memory */ - /*for all entries in the env */ - for(;*Environment != NULL;Environment++){ - length = strlen(*Environment)+1; /* get the size of the string */ - /* and alloc space for it */ - Env_Var_String = (char *)malloc(length); - memcpy(Env_Var_String,*Environment,length);/* copy the string */ - putenv(Env_Var_String); /* and make it part of env */ + begin = current = (char *)CurrentEnv; /* get the saved space */ + size = ((ENVENTRY*)current)->size; /* first read out the size */ + current += 4; /* update the pointer */ + if (chdir(current) == -1) /* restore the curr dir */ + { + reportException(Error_System_service_service, "ERROR CHANGING DIRECTORY"); } - putflag = 1; /* prevent do it again */ - } - /* Loop through the saved env */ - /* entries and restore them */ - for(;((unsigned long)(current-begin))<size;current+=(strlen(current)+1)){ - Environment = environ; /* get the environment */ - del = NULL; - np = current; - /* extract the the name */ - /* from the saved enviroment */ - for(i=0;(*np!='=')&&(i<255);np++,i++){ - memcpy(&(namebufsave[i]),np,1); /* copy the character */ + current += strlen(current); /* update the pointer */ + current++; /* jump over '\0' */ + if (!putflag) + { /* first change in the */ + /* environment ? */ + /* copy all entries to dynamic memory */ + /*for all entries in the env */ + for (;*Environment != NULL;Environment++) + { + length = strlen(*Environment)+1; /* get the size of the string */ + /* and alloc space for it */ + Env_Var_String = (char *)malloc(length); + memcpy(Env_Var_String,*Environment,length);/* copy the string */ + putenv(Env_Var_String); /* and make it part of env */ + } + return OREF_NULL; /* no message retrieved */ } - memcpy(&(namebufsave[i]),"\0",1); /* copy the terminator */ - /* find the entry in the env */ - for(;*Environment != NULL;Environment++){ - np = *Environment; - /* extract the the name */ - /* from the current env */ - for(i=0;(*np!='=')&&(i<255);np++,i++){ - memcpy(&(namebufcurr[i]),np,1);/* copy the character */ - } - memcpy(&(namebufcurr[i]),"\0",1);/* copy the terminator */ - - if(!strcmp(namebufsave,namebufcurr)){/* have a match ? */ - del = *Environment; /* remember it for deletion */ - break; /* found, so get out of here */ - } - } - if(putenv(current) == -1) - reportException(Error_System_service_service, (const stringchar_t *)"ERROR RESTORING ENVIRONMENT VARIABLE"); - if(del) /* if there was an old entry */ - free(del); /* free it */ - } } -/*********************************************************************/ -/* */ -/* Subroutine Name: BuildEnvlist */ -/* */ -/* Descriptive Name: Build saved environment block */ -/* */ -/* Function: Builds a block containing all of the */ -/* environment variables, the current drive */ -/* and the current directory. */ -/* */ -/*********************************************************************/ -RexxObject * SystemInterpreter::buildEnvlist() -{ - RexxObject *newBuffer; /* Buffer object to hold env */ - char **Environment; /* environment pointer */ - size_t size = 0; /* size of the new buffer */ - char *curr_dir; /* current directory */ - char *New; /* starting address of buffer */ - - Environment = environ; /* get the ptr to the environ */ - - for(;*Environment != NULL;Environment++){ - size += strlen(*Environment); /* calculate the size for all */ - size++; /* environment variables+'\0' */ - } /* now get current dir */ - if(!size) - return NULLOBJECT; /* this worked ok */ - if (!(curr_dir=(char *)malloc(CCHMAXPATH+2)))/* malloc storage for cwd*/ - reportException(Error_System_service); - - if (!getcwd(curr_dir,CCHMAXPATH)) /* get current directory */ - { - strncpy( achRexxCurDir, getenv("PWD"), CCHMAXPATH); - achRexxCurDir[CCHMAXPATH - 1] = '\0'; - if (achRexxCurDir[0] != '/' ) - reportException(Error_System_service);/* Complain if it fails*/ - } - size += strlen(curr_dir); /* add the space for curr dir */ - size++; /* and its terminating '\0' */ - size += 4; /* this is for the size itself*/ - /* Now we have the size for */ - /* allocating the new buffer */ - newBuffer = (RexxObject *)new_buffer(NULL, size); /* let's do it */ - /* Get starting address of buf*/ - New = (char*)newBuffer; - ((ENVENTRY*)New)->size = size; /* first write the size */ - New +=4; /* update the pointer */ - /* now write the curr dir */ - memcpy(New,curr_dir,strlen(curr_dir)); - New += strlen(curr_dir); /* update the pointer */ - memcpy(New,"\0",1); /* write the terminator */ - New++; /* update the pointer */ - Environment = environ; /* reset to begin of environ */ - /* Loop through environment */ - /* and copy all entries to the*/ - /* buffer, each terminating */ - /* with '\0' */ - for(;*Environment != NULL;Environment++){ - /* copy the entry */ - memcpy(New,*Environment,strlen(*Environment)); - New += strlen(*Environment); /* update the pointer */ - memcpy(New,"\0",1); /* write the terminator */ - New++; /* update the pointer */ - } - free(curr_dir); /* free curr dir buffer */ - return newBuffer; /* return the pointer */ -} - - /** - * Push a new environment for the SysSetLocal() BIF. + * Return a message header for a given error message. * - * @param context The current activation context. + * @param code The error code * - * @return Returns TRUE if the environment was successfully pushed. + * @return The formatted message header */ -RexxObject *SystemInterpreter::pushEnvironment(RexxActivation *context) +RexxString *SystemInterpreter::getMessageHeader(wholenumber_t code ) { - RexxObject *Current; /* new save block */ - - Current = BuildEnvlist(); /* build the new save block */ - if (NULLOBJECT == Current) /* if unsuccessful return zero */ - return TheFalseObject; - else { - /* Have Native Actiovation */ - context->pushEnvironment(Current); /* update environemnt list */ - return TheTrueObject; /* this returns one */ + ERROR_MESSAGE *p; /* table scan pointer */ + int msgid; /* message number */ + char DataArea[20]; /* buf addr to return message */ + /* loop through looking for the */ + /* error code */ + for (p = Message_table; p->code != 0; p++) + { + if (p->code == code) + { /* found the target code? */ + msgid = p->msgid; /* get msg number associated w/ error*/ + /* format as a message header */ + sprintf(DataArea, "REX%4.4dE: ", msgid); + return new_string(DataArea); /* return as a string object */ + } } + return OREF_NULL; /* no message retrieved */ } -/** - * Pop an environment for the SysEndLocal() BIF. - * - * @param context The current activation context. - * - * @return Always returns FALSE. This is a NOP on Windows. - */ -RexxObject *SystemInterpreter::popEnvironment(RexxActivation *context) -{ - RexxObject *Current; /* new save block */ - Current = context->popEnvironment();/* block, if ixisted. */ - if (TheNilObject == Current) /* nothing saved? */ - return TheFalseObject; /* return failure value */ - else { - /* restore everything */ - restoreEnvironment(Current); - return TheTrueObject; /* this worked ok */ - } -} - - Modified: interpreter-3.x/trunk/kernel/platform/unix/ExternalFunctions.cpp =================================================================== --- interpreter-3.x/trunk/kernel/platform/unix/ExternalFunctions.cpp 2008-07-04 04:09:49 UTC (rev 2648) +++ interpreter-3.x/trunk/kernel/platform/unix/ExternalFunctions.cpp 2008-07-04 12:51:34 UTC (rev 2649) @@ -118,9 +118,6 @@ int putflag = 0; /* static or dynamic env memory */ -REXXOBJECT BuildEnvlist(void); -void RestoreEnvironment( void * ); - /*********************************************************************/ /* */ /* Subroutine Name: sysBeep */ @@ -350,6 +347,50 @@ } +/** + * Push a new environment for the SysSetLocal() BIF. + * + * @param context The current activation context. + * + * @return Returns TRUE if the environment was successfully pushed. + */ +RexxObject *SystemInterpreter::pushEnvironment(RexxActivation *context) +{ + RexxObject *Current = buildEnvlist(); /* build the new save block */ + if (Current == OREF_NULL) /* if unsuccessful return zero */ + { + return TheFalseObject; + } + else + { + /* Have Native Actiovation */ + context->pushEnvironment(Current); /* update environemnt list */ + return TheTrueObject; /* this returns one */ + } +} + +/** + * Pop an environment for the SysEndLocal() BIF. + * + * @param context The current activation context. + * + * @return Always returns FALSE. This is a NOP on Windows. + */ +RexxObject *SystemInterpreter::popEnvironment(RexxActivation *context) +{ + RexxObject *Current; /* new save block */ + + Current = context->popEnvironment();/* block, if ixisted. */ + if (TheNilObject == Current) /* nothing saved? */ + return TheFalseObject; /* return failure value */ + else { + /* restore everything */ + restoreEnvironment(Current); + return TheTrueObject; /* this worked ok */ + } +} + + /*********************************************************************/ /* */ /* Subroutine Name: BuildEnvlist */ @@ -362,56 +403,62 @@ /* */ /*********************************************************************/ -REXXOBJECT BuildEnvlist() +RexxObject *SystemInterpreter::buildEnvlist() { - REXXOBJECT newBuffer; /* Buffer object to hold env */ - char **Environment; /* environment pointer */ - size_t size = 0; /* size of the new buffer */ - char *curr_dir; /* current directory */ - char *New; /* starting address of buffer */ - Environment = getEnvironment(); /* get the ptr to the environ */ + RexxBuffer *newBuffer; /* Buffer object to hold env */ + char **Environment; /* environment pointer */ + size_t size = 0; /* size of the new buffer */ + char *curr_dir; /* current directory */ + char *New; /* starting address of buffer */ + Environment = getEnvironment(); /* get the ptr to the environ */ - for(;*Environment != NULL;Environment++){ - size += strlen(*Environment); /* calculate the size for all */ - size++; /* environment variables+'\0' */ - } /* now get current dir */ - if(!size) - return OREF_NULL; /* no envrionment ! */ - if (!(curr_dir=(char *)malloc(CCHMAXPATH+2)))/* malloc storage for cwd*/ - reportException(Error_System_service); + for (;*Environment != NULL;Environment++) + { + size += strlen(*Environment); /* calculate the size for all */ + size++; /* environment variables+'\0' */ + } /* now get current dir */ + if (!size) + { + return OREF_NULL; /* no envrionment ! */ + } + if (!(curr_dir=(char *)malloc(CCHMAXPATH+2)))/* malloc storage for cwd*/ + { + reportException(Error_System_service); + } - // start with a copy of the current working directory - SystemInterpreter::getCurrentWorkingDirectory(curr_dir); + // start with a copy of the current working directory + SystemInterpreter::getCurrentWorkingDirectory(curr_dir); - size += strlen(curr_dir); /* add the space for curr dir */ - size++; /* and its terminating '\0' */ - size += 4; /* this is for the size itself*/ - /* Now we have the size for */ - /* allocating the new buffer */ - newBuffer = ooRexxBuffer(size); /* let's do it */ - /* Get starting address of buf*/ - New = (char*)buffer_address(newBuffer); - ((ENVENTRY*)New)->size = size; /* first write the size */ - New +=4; /* update the pointer */ - /* now write the curr dir */ - memcpy(New,curr_dir,strlen(curr_dir)); - New += strlen(curr_dir); /* update the pointer */ - memcpy(New,"\0",1); /* write the terminator */ - New++; /* update the pointer */ - Environment = getEnvironment(); /* reset to begin of environ */ - /* Loop through environment */ - /* and copy all entries to the*/ - /* buffer, each terminating */ - /* with '\0' */ - for(;*Environment != NULL;Environment++){ - /* copy the entry */ - memcpy(New,*Environment,strlen(*Environment)); - New += strlen(*Environment); /* update the pointer */ - memcpy(New,"\0",1); /* write the terminator */ - New++; /* update the pointer */ - } - free(curr_dir); /* free curr dir buffer */ - return newBuffer; /* return the pointer */ + size += strlen(curr_dir); /* add the space for curr dir */ + size++; /* and its terminating '\0' */ + size += 4; /* this is for the size itself*/ + /* Now we have the size for */ + /* allocating the new buffer */ + newBuffer = new_buffer(size); /* let's do it */ + /* Get starting address of buf*/ + New = newBuffer->address(); + ((ENVENTRY*)New)->size = size; /* first write the size */ + New +=4; /* update the pointer */ + /* now write the curr dir */ + memcpy(New,curr_dir,strlen(curr_dir)); + New += strlen(curr_dir); /* update the pointer */ + memcpy(New,"\0",1); /* write the terminator */ + New++; /* update the pointer */ + Environment = getEnvironment(); /* reset to begin of environ */ + /* Loop through environment */ + /* and copy all entries to the*/ + /* buffer, each terminating */ + /* with '\0' */ + for (;*Environment != NULL;Environment++) + { + /* copy the entry */ + memcpy(New,*Environment,strlen(*Environment)); + New += strlen(*Environment); /* update the pointer */ + memcpy(New,"\0",1); /* write the terminator */ + New++; /* update the pointer */ + } + free(curr_dir); /* free curr dir buffer */ + return newBuffer; /* return the pointer */ } @@ -426,74 +473,86 @@ /* */ /*********************************************************************/ -void RestoreEnvironment( +void SystemInterpreter::restoreEnvironment( void *CurrentEnv) /* saved environment */ { - char *current; /* ptr to saved environment */ - size_t size; /* size of the saved space */ - size_t length; /* string length */ - char *begin; /* begin of saved space */ - char **Environment; /* environment pointer */ + char *current; /* ptr to saved environment */ + size_t size; /* size of the saved space */ + size_t length; /* string length */ + char *begin; /* begin of saved space */ + char **Environment; /* environment pointer */ - char *del = NULL; /* ptr to old unused memory */ - char *Env_Var_String; /* enviornment entry */ - char namebufsave[256],namebufcurr[256]; - char *np; - int i; + char *del = NULL; /* ptr to old unused memory */ + char *Env_Var_String; /* enviornment entry */ + char namebufsave[256],namebufcurr[256]; + char *np; + int i; Environment = getEnvironment(); /* get the current environment*/ - begin = current = (char *)CurrentEnv;/* get the saved space */ - size = ((ENVENTRY*)current)->size; /* first read out the size */ - current += 4; /* update the pointer */ - if(chdir(current) == -1) /* restore the curr dir */ - rexx_exception1(Error_System_service_service, ooRexxString("ERROR CHANGING DIRECTORY")); - current += strlen(current); /* update the pointer */ - current++; /* jump over '\0' */ - if(!putflag){ /* first change in the */ - /* environment ? */ - /* copy all entries to dynamic memory */ - /*for all entries in the env */ - for(;*Environment != NULL;Environment++){ - length = strlen(*Environment)+1; /* get the size of the string */ - /* and alloc space for it */ - Env_Var_String = (char *)malloc(length); - memcpy(Env_Var_String,*Environment,length);/* copy the string */ - putenv(Env_Var_String); /* and make it part of env */ + begin = current = (char *)CurrentEnv;/* get the saved space */ + size = ((ENVENTRY*)current)->size; /* first read out the size */ + current += 4; /* update the pointer */ + if (chdir(current) == -1) /* restore the curr dir */ + { + rexx_exception1(Error_System_service_service, ooRexxString("ERROR CHANGING DIRECTORY")); } - putflag = 1; /* prevent do it again */ - } - /* Loop through the saved env */ - /* entries and restore them */ - for(;(size_t)(current-begin)<size;current+=(strlen(current)+1)){ - Environment = getEnvironment(); /* get the environment */ - del = NULL; - np = current; - /* extract the the name */ - /* from the saved enviroment */ - for(i=0;(*np!='=')&&(i<255);np++,i++){ - memcpy(&(namebufsave[i]),np,1); /* copy the character */ + current += strlen(current); /* update the pointer */ + current++; /* jump over '\0' */ + if (!putflag) + { /* first change in the */ + /* environment ? */ + /* copy all entries to dynamic memory */ + /*for all entries in the env */ + for (;*Environment != NULL;Environment++) + { + length = strlen(*Environment)+1; /* get the size of the string */ + /* and alloc space for it */ + Env_Var_String = (char *)malloc(length); + memcpy(Env_Var_String,*Environment,length);/* copy the string */ + putenv(Env_Var_String); /* and make it part of env */ + } + putflag = 1; /* prevent do it again */ } - memcpy(&(namebufsave[i]),"\0",1); /* copy the terminator */ - /* find the entry in the env */ - for(;*Environment != NULL;Environment++){ - np = *Environment; - /* extract the the name */ - /* from the current env */ - for(i=0;(*np!='=')&&(i<255);np++,i++){ - memcpy(&(namebufcurr[i]),np,1);/* copy the character */ - } - memcpy(&(namebufcurr[i]),"\0",1);/* copy the terminator */ + /* Loop through the saved env */ + /* entries and restore them */ + for (;(size_t)(current-begin)<size;current+=(strlen(current)+1)) + { + Environment = getEnvironment(); /* get the environment */ + del = NULL; + np = current; + /* extract the the name */ + /* from the saved enviroment */ + for (i=0;(*np!='=')&&(i<255);np++,i++) + { + memcpy(&(namebufsave[i]),np,1); /* copy the character */ + } + memcpy(&(namebufsave[i]),"\0",1); /* copy the terminator */ + /* find the entry in the env */ + for (;*Environment != NULL;Environment++) + { + np = *Environment; + /* extract the the name */ + /* from the current env */ + for (i=0;(*np!='=')&&(i<255);np++,i++) + { + memcpy(&(namebufcurr[i]),np,1);/* copy the character */ + } + memcpy(&(namebufcurr[i]),"\0",1);/* copy the terminator */ - if(!strcmp(namebufsave,namebufcurr)){/* have a match ? */ - del = *Environment; /* remember it for deletion */ - break; /* found, so get out of here */ - } + if (!strcmp(namebufsave,namebufcurr)) + {/* have a match ? */ + del = *Environment; /* remember it for deletion */ + break; /* found, so get out of here */ + } + } + if (putenv(current) == -1) + { + rexx_exception1(Error_System_service_service, ooRexxString("ERROR RESTORING ENVIRONMENT VARIABLE")); + } + if (del) /* if there was an old entry */ + { + free(del); /* free it */ + } } - if(putenv(current) == -1) - rexx_exception1(Error_System_service_service, ooRexxString("ERROR RESTORING ENVIRONMENT VARIABLE")); - if(del) /* if there was an old entry */ - free(del); /* free it */ - } - } Modified: interpreter-3.x/trunk/kernel/platform/unix/MemorySupport.cpp =================================================================== --- interpreter-3.x/trunk/kernel/platform/unix/MemorySupport.cpp 2008-07-04 04:09:49 UTC (rev 2648) +++ interpreter-3.x/trunk/kernel/platform/unix/MemorySupport.cpp 2008-07-04 12:51:34 UTC (rev 2649) @@ -47,6 +47,7 @@ #include "RexxCore.h" #include "RexxMemory.hpp" #include "ActivityManager.hpp" +#include "SystemInterpreter.hpp" #define MEMSIZE 4194304 /* memory pool */ #ifdef LINUX @@ -59,7 +60,7 @@ /* another program as a return result */ /* */ /*********************************************************************/ -void * SysAllocateResultMemory( +void * SystemInterpreter::allocateResultMemory( size_t Size ) /* size to allocate */ { return malloc(Size); @@ -71,7 +72,7 @@ /* agent as a return result */ /* */ /*********************************************************************/ -void SysReleaseResultMemory( +void SystemInterpreter::releaseResultMemory( void *MemoryBlock) /* pointer to the result memory */ { free(MemoryBlock); /* release this block */ Modified: interpreter-3.x/trunk/kernel/platform/unix/MiscSystem.cpp =================================================================== --- interpreter-3.x/trunk/kernel/platform/unix/MiscSystem.cpp 2008-07-04 04:09:49 UTC (rev 2648) +++ interpreter-3.x/trunk/kernel/platform/unix/MiscSystem.cpp 2008-07-04 12:51:34 UTC (rev 2649) @@ -60,6 +60,7 @@ #include "ThreadSupport.hpp" #include "ActivityManager.hpp" #include "PointerClass.hpp" +#include "SystemInterpreter.hpp" #include <stdlib.h> #include <unistd.h> #include <errno.h> @@ -93,26 +94,40 @@ unsigned int iClauseCounter=0; // count of clauses #define LOADED_OBJECTS 100 -void SysTermination(void) +RexxString *SystemInterpreter::getInternalSystemName() +{ + return getSystemName(); // this is the same +} + +RexxString *SystemInterpreter::getSystemName() /******************************************************************************/ -/* Function: Perform system specific termination. */ +/* Function: Get System Name */ /******************************************************************************/ { +#if defined(AIX) + return new_string("AIX") +#elif defined(OPSYS_SUN) + return new_string("SUNOS") +#else + return new_string("LINUX") +#endif } -RexxString *SysVersion(void) + +RexxString *SystemInterpreter::getSystemVersion() /******************************************************************************/ /* Function: Return the system specific version identifier that is stored */ /* in the image. */ /******************************************************************************/ { - struct utsname info; /* info structur */ + struct utsname info; /* info structur */ - uname(&info); /* get the info */ + uname(&info); /* get the info */ - return new_string(info.release); /* return as a string */ + return new_string(info.release); /* return as a string */ } + void *SysLoadProcedure( RexxPointer * LibraryHandle, /* library load handle */ RexxString * Procedure) /* required procedure name */ @@ -190,28 +205,28 @@ #endif } -RexxString * SysSourceString( +RexxString * SystemInerpreter::getSourceString( RexxString * callType, /* type of call token */ RexxString * programName ) /* program name token */ /******************************************************************************/ /* Function: Produce a system specific source string */ /******************************************************************************/ { - RexxString * source_string; /* final source string */ - char * outPtr; - source_string = raw_string(1+sizeof(ORX_SYS_STR)+callType->getLength()+programName->getLength()); - outPtr = source_string->getWritableData(); /* point to result Data. */ + RexxString * source_string; /* final source string */ + char * outPtr; + source_string = raw_string(1+sizeof(ORX_SYS_STR)+callType->getLength()+programName->getLength()); + outPtr = source_string->getWritableData(); /* point to result Data. */ - strcpy(outPtr, ORX_SYS_STR); /* copy the system name */ - outPtr +=sizeof(ORX_SYS_STR) - 1; /* step past the name */ - *outPtr++ = ' '; /* put a blank between */ - /* copy the call type */ - memcpy(outPtr, callType->getStringData(), callType->getLength()); - outPtr += callType->getLength(); /* step over the call type */ - *outPtr++ = ' '; /* put a blank between */ - /* copy the system name */ - memcpy(outPtr, programName->getStringData(), programName->getLength()); - return source_string; /* return the source string */ + strcpy(outPtr, ORX_SYS_STR); /* copy the system name */ + outPtr +=sizeof(ORX_SYS_STR) - 1; /* step past the name */ + *outPtr++ = ' '; /* put a blank between */ + /* copy the call type */ + memcpy(outPtr, callType->getStringData(), callType->getLength()); + outPtr += callType->getLength(); /* step over the call type */ + *outPtr++ = ' '; /* put a blank between */ + /* copy the system name */ + memcpy(outPtr, programName->getStringData(), programName->getLength()); + return source_string; /* return the source string */ } // these routines are NOPs Modified: interpreter-3.x/trunk/kernel/platform/unix/PlatformDefinitions.h =================================================================== --- interpreter-3.x/trunk/kernel/platform/unix/PlatformDefinitions.h 2008-07-04 04:09:49 UTC (rev 2648) +++ interpreter-3.x/trunk/kernel/platform/unix/PlatformDefinitions.h 2008-07-04 12:51:34 UTC (rev 2649) @@ -323,19 +323,6 @@ #define SysRelinquish() -#if defined(AIX) -#define SysName() new_string("AIX", 3) -#define SysINTName() new_string("AIX",3) -#elif defined(OPSYS_SUN) -#define SysName() new_string("SUNOS", 5) -#define SysINTName() new_string("SUNOS",5) -#else -#define SysName() new_string("LINUX", 5) -#define SysINTName() new_string("LINUX",5) - // Thread yielding functions in - // threading package -#endif - #define SysThreadArg(a) a->args #define SysInitialAddressName() OREF_INITIALADDRESS Modified: interpreter-3.x/trunk/kernel/platform/unix/SysInterpreterInstance.cpp =================================================================== --- interpreter-3.x/trunk/kernel/platform/unix/SysInterpreterInstance.cpp 2008-07-04 04:09:49 UTC (rev 2648) +++ interpreter-3.x/trunk/kernel/platform/unix/SysInterpreterInstance.cpp 2008-07-04 12:51:34 UTC (rev 2649) @@ -97,7 +97,7 @@ // enough room for separators and a terminating null - path = SysAllocateResultMemory(pathSize + parentSize + extensionSize + 16); + path = SystemInterpreter::allocateResultMemory(pathSize + parentSize + extensionSize + 16); *path = '\0'; // add a null character so strcat can work if (parentDir != NULL) { @@ -144,5 +144,5 @@ */ SysSearchPath::~SysSearchPath() { - SysReleaseResultMemory(path); + SystemInterpreter::releaseResultMemory(path); } Modified: interpreter-3.x/trunk/kernel/platform/unix/SystemCommands.cpp =================================================================== --- interpreter-3.x/trunk/kernel/platform/unix/SystemCommands.cpp 2008-07-04 04:09:49 UTC (rev 2648) +++ interpreter-3.x/trunk/kernel/platform/unix/SystemCommands.cpp 2008-07-04 12:51:34 UTC (rev 2649) @@ -221,7 +221,7 @@ /* user give us a new buffer? */ if (retstr.strptr != default_return_buffer) - SysReleaseResultMemory(retstr.strptr); /* free it... */ + SystemInterpreter::releaseResultMemory(retstr.strptr); /* free it... */ } else result = IntegerZero; /* got a zero return code */ Modified: interpreter-3.x/trunk/kernel/platform/unix/SystemInterpreter.hpp =================================================================== --- interpreter-3.x/trunk/kernel/platform/unix/SystemInterpreter.hpp 2008-07-04 04:09:49 UTC (rev 2648) +++ interpreter-3.x/trunk/kernel/platform/unix/SystemInterpreter.hpp 2008-07-04 12:51:34 UTC (rev 2649) @@ -55,6 +55,7 @@ class InterpreterInstance; class RexxActivation; +class RexxDateTime; class SystemInterpreter { @@ -77,9 +78,23 @@ static RexxString *extractFile(RexxString *file); static RexxObject *popEnvironment(RexxActivation *context); static RexxObject *pushEnvironment(RexxActivation *context); + static void restoreEnvironment(void *CurrentEnv); static RexxObject *buildEnvlist(); static void restoreEnvironment(void *); static RexxString *qualifyFileSystemName(RexxString *name); + static void getCurrentTime(RexxDateTime *Date ); + static RexxString *getSystemName(); + static RexxString *getSystemVersion(); + static RexxString *getInternalSystemName(); + static RexxString *getSourceString(RexxString *callType, RexxString * programName); + static RexxString *getUserid(); + static void releaseResultMemory(void *); + static void *allocateResultMemory(size_t); + static RexxString *getMessageHeader(wholenumber_t code); + static RexxString *getMessageText(wholenumber_t code); + static RexxString *getUserid(); + static bool valueFunction(RexxString *name, RexxObject *newValue, RexxString *selector, RexxObject *&result); + }; #endif Modified: interpreter-3.x/trunk/kernel/platform/unix/ThreadSupport.cpp =================================================================== --- interpreter-3.x/trunk/kernel/platform/unix/ThreadSupport.cpp 2008-07-04 04:09:49 UTC (rev 2648) +++ interpreter-3.x/trunk/kernel/platform/unix/ThreadSupport.cpp 2008-07-04 12:51:34 UTC (rev 2649) @@ -136,8 +136,6 @@ return (thread_id_t)newThread; } - - void SysInitializeThread() { } Modified: interpreter-3.x/trunk/kernel/platform/unix/TimeSupport.cpp =================================================================== --- interpreter-3.x/trunk/kernel/platform/unix/TimeSupport.cpp 2008-07-04 04:09:49 UTC (rev 2648) +++ interpreter-3.x/trunk/kernel/platform/unix/TimeSupport.cpp 2008-07-04 12:51:34 UTC (rev 2649) @@ -53,6 +53,7 @@ #include "IntegerClass.hpp" #include "RexxNativeAPI.h" /* Method macros */ #include "RexxDateTime.hpp" +#include "SystemInterpreter.hpp" #ifdef AIX #include <time.h> @@ -61,27 +62,26 @@ #endif -void SysGetCurrentTime( - RexxDateTime *Date ) /* returned data structure */ +void SystemInterpreter::getCurrentTime(RexxDateTime *Date ) { - struct tm *SystemDate; /* system date structure ptr */ - struct timeval tv; - gettimeofday(&tv, NULL); + struct tm *SystemDate; /* system date structure ptr */ + struct timeval tv; + gettimeofday(&tv, NULL); #ifdef AIX - struct tm SD; /* system date area */ - SystemDate = localtime_r((time_t *)&tv.tv_sec, &SD); + struct tm SD; /* system date area */ + SystemDate = localtime_r((time_t *)&tv.tv_sec, &SD); #else - SystemDate = localtime((time_t *)&tv.tv_sec); /* convert */ + SystemDate = localtime((time_t *)&tv.tv_sec); /* convert */ #endif - Date->hours = SystemDate->tm_hour; - Date->minutes = SystemDate->tm_min; - Date->seconds = SystemDate->tm_sec; - Date->microseconds = tv.tv_usec; - Date->day = SystemDate->tm_mday; - Date->month = ++SystemDate->tm_mon; - Date->year = SystemDate->tm_year + 1900; + Date->hours = SystemDate->tm_hour; + Date->minutes = SystemDate->tm_min; + Date->seconds = SystemDate->tm_sec; + Date->microseconds = tv.tv_usec; + Date->day = SystemDate->tm_mday; + Date->month = ++SystemDate->tm_mon; + Date->year = SystemDate->tm_year + 1900; } typedef struct { Modified: interpreter-3.x/trunk/kernel/platform/unix/UseridFunction.cpp =================================================================== --- interpreter-3.x/trunk/kernel/platform/unix/UseridFunction.cpp 2008-07-04 04:09:49 UTC (rev 2648) +++ interpreter-3.x/trunk/kernel/platform/unix/UseridFunction.cpp 2008-07-04 12:51:34 UTC (rev 2649) @@ -35,14 +35,6 @@ /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* */ /*----------------------------------------------------------------------------*/ -/*********************************************************************/ -/* */ -/* Subroutine Name: SysUserid */ -/* */ -/* Function: process the Userid function */ -/* function */ -/* */ -/*********************************************************************/ #ifdef HAVE_CONFIG_H # include "config.h" #endif @@ -57,6 +49,7 @@ #include "RexxCore.h" #include "StringClass.hpp" +#include "SystemInterpreter.hpp" #define ACCOUNT_BUFFER_SIZE 256 @@ -68,7 +61,7 @@ /* */ /*********************************************************************/ -RexxObject * SysUserid() +RexxString *SystemInterpreter::getUserid() { char account_buffer[ACCOUNT_BUFFER_SIZE]; #if defined( HAVE_GETPWUID ) Modified: interpreter-3.x/trunk/kernel/platform/unix/ValueFunction.cpp =================================================================== --- interpreter-3.x/trunk/kernel/platform/unix/ValueFunction.cpp 2008-07-04 04:09:49 UTC (rev 2648) +++ interpreter-3.x/trunk/kernel/platform/unix/ValueFunction.cpp 2008-07-04 12:51:34 UTC (rev 2649) @@ -42,18 +42,10 @@ /* */ /******************************************************************************/ -/*********************************************************************/ -/* */ -/* Subroutine Name: SysValue */ -/* */ -/* Function: process the VALUE function selector */ -/* function */ -/* ... [truncated message content] |