63 #include <sys/ioctl.h>
66 #include <sys/types.h>
85 #define CMDBUFSIZE 1024
87 #define CMDDEFNAME "/bin/ksh"
90 #elif defined(OPSYS_SUN)
91 #define CMDDEFNAME "/bin/sh"
95 #define CMDDEFNAME "/bin/bash"
96 #define COMSPEC "bash"
102 #define FULLSEG 65536L
104 #define FILESPEC_PATH 'P'
105 #define FILESPEC_NAME 'N'
106 #define FILESPEC_LOCATION 'L'
107 #define FILESPEC_EXTENSION 'E'
108 #define FILESPEC_DRIVE 'D'
110 #define KIOCSOUND 0x4B2F
147 const char *home_dir = NULL;
148 char *dir_buf = NULL;
155 if (*(st) ==
'~' && (*(st+1) ==
'\0' || *(st+1) ==
'/'|| *(st+1) ==
' ' ))
161 home_dir = getenv(
"HOME");
165 size_t size = strlen(home_dir)+strlen(st)+2;
166 dir_buf = (
char *)malloc(size);
170 snprintf(dir_buf, size,
"%s/%s", home_dir, st);
176 home_dir = getenv(
"HOME");
178 size_t size = strlen(home_dir)+2;
179 dir_buf = (
char *)malloc(size);
182 snprintf(dir_buf, size,
"%s/", home_dir);
186 else if (*(st) ==
'~')
189 slash = strchr(st,
'/');
199 size_t size = strlen(ppwd->pw_dir)+2;
200 dir_buf = (
char *)malloc(size);
204 snprintf(dir_buf, size,
"%s/", ppwd->pw_dir);
212 memcpy(username, st, slash-st);
213 username[slash-st] =
'\0';
214 ppwd = getpwnam(username);
217 size_t size = strlen(ppwd->pw_dir)+strlen(slash)+2;
218 dir_buf = (
char *)malloc(size);
222 snprintf(dir_buf, size,
"%s/%s", ppwd->pw_dir, slash);
255 return context->NullString();
260 char temp[PATH_MAX + 3];
262 return context->NewStringFromAsciiz(temp);
272 const char *endPtr = name + strlen(name);
273 const char *pathEnd = strrchr(name,
'/');
275 const char *pathStart = name;
279 pathEnd = pathEnd == NULL ? pathStart : pathEnd + 1;
281 const char *nameStart = pathEnd == name ? name : pathEnd;
283 switch (toupper(*option))
287 return context->String(pathStart, pathEnd - pathStart);
292 return context->String(nameStart, endPtr - nameStart);
297 return context->NullString();
302 return context->String(name, pathEnd - name);
308 const char *lastDot = strrchr(name,
'.');
310 if (lastDot >= nameStart)
314 return context->String(lastDot, endPtr - lastDot);
318 return context->NullString();
325 optionChar[0] = *option;
326 optionChar[1] =
'\0';
329 context->String(
"ELNP"), context->String(optionChar));
355 size_t named_argcount,
369 if (activation->
callExternalRexx(target, arguments, argcount, named_argcount, calltype, result))
450 for (;*Environment != NULL;Environment++)
452 size += strlen(*Environment);
459 if (!(curr_dir=(
char *)malloc(PATH_MAX + 3)))
466 size += strlen(curr_dir);
468 size +=
sizeof(size_t);
475 New +=
sizeof(size_t);
477 memcpy(New,curr_dir,strlen(curr_dir));
478 New += strlen(curr_dir);
486 for (;*Environment != NULL;Environment++)
489 memcpy(New,*Environment,strlen(*Environment));
490 New += strlen(*Environment);
520 char *Env_Var_String;
521 char namebufsave[256],namebufcurr[256];
527 begin = current = (
char *)CurrentEnv;
529 current +=
sizeof(size_t);
530 if (chdir(current) == -1)
533 snprintf(msg,
sizeof msg,
"Error restoring current directory: %s", current);
536 current += strlen(current);
543 for (;*Environment != NULL;Environment++)
545 length = strlen(*Environment)+1;
547 Env_Var_String = (
char *)malloc(length);
548 memcpy(Env_Var_String,*Environment,length);
549 putenv(Env_Var_String);
555 for (;(size_t)(current-begin)<size;current+=(strlen(current)+1))
562 for (i=0;(*np!=
'=')&&(i<255);np++,i++)
564 memcpy(&(namebufsave[i]),np,1);
566 memcpy(&(namebufsave[i]),
"\0",1);
568 for (;*Environment != NULL;Environment++)
573 for (i=0;(*np!=
'=')&&(i<255);np++,i++)
575 memcpy(&(namebufcurr[i]),np,1);
577 memcpy(&(namebufcurr[i]),
"\0",1);
579 if (!strcmp(namebufsave,namebufcurr))
585 if (putenv(current) == -1)
void reportException(wholenumber_t error)
RexxBuffer * new_buffer(size_t s)
#define Error_System_service
#define Error_System_service_service
static bool callNativeRoutine(RexxActivity *activity, RexxString *name, RexxObject **arguments, size_t argcount, size_t named_argcount, ProtectedObject &result)
bool callExternalRexx(RexxString *, RexxObject **, size_t, size_t, RexxString *, ProtectedObject &)
void pushEnvironment(RexxObject *)
bool callMacroSpaceFunction(RexxString *, RexxObject **, size_t, size_t, RexxString *, int, ProtectedObject &)
RexxObject * popEnvironment()
static RexxObject * buildEnvlist()
static bool invokeExternalFunction(RexxActivation *, RexxActivity *, RexxString *, RexxObject **, size_t, size_t, RexxString *, ProtectedObject &)
static RexxObject * popEnvironment(RexxActivation *context)
static RexxObject * pushEnvironment(RexxActivation *context)
static void restoreEnvironment(void *CurrentEnv)
static void getCurrentWorkingDirectory(char *)
#define Rexx_Error_Incorrect_call_list
struct _RexxStringObject * RexxStringObject
struct _RexxArrayObject * RexxArrayObject
RexxRoutine1(RexxStringObject, sysDirectory, OPTIONAL_CSTRING, dir)
RexxRoutine2(CSTRING, sysBeep, OPTIONAL_wholenumber_t, Frequency, OPTIONAL_wholenumber_t, Duration)
char * resolve_tilde(const char *path)
#define FILESPEC_LOCATION
struct _ENVENTRY ENVENTRY
#define FILESPEC_EXTENSION