00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <stdlib.h>
00021 #include <stdio.h>
00022 #include <string.h>
00023
00024 #include "../command.h"
00025
00026 #ifdef __DARWIN__
00027 #define _environ environ
00028 #endif
00029
00030 extern char **_environ;
00031
00069 COMMAND(ENVIRON)
00070 #if NOTIMP_ENVIRON
00071 NOTIMPLEMENTED;
00072 #else
00073
00074 NODE nItem;
00075 VARIABLE Op1;
00076 #define MAX_ENVIRV_LEN 256
00077 char *s,buffer[MAX_ENVIRV_LEN];
00078 size_t sLen;
00079 char **EnvironmentPointer;
00080 long index;
00081 char *(*EnvirFunc)(void *, char *, long );
00082
00083 USE_CALLER_MORTALS;
00084
00085
00086 nItem = PARAMETERLIST;
00087 Op1 = _EVALUATEEXPRESSION(CAR(nItem));
00088 ASSERTOKE;
00089
00090 if( memory_IsUndef(Op1) ){
00091 RESULT = NULL;
00092 RETURN;
00093 }
00094
00095 EnvirFunc = pEo->fpEnvirFunction;
00096 if( TYPE(Op1) == VTYPE_LONG ){
00097 index = LONGVALUE(Op1);
00098 if( EnvirFunc ){
00099 s = EnvirFunc(pEo->pEmbedder,NULL,index);
00100 }else{
00101 EnvironmentPointer = _environ;
00102 if( index < 0 ){
00103 RESULT = NULL;
00104 RETURN;
00105 }
00106
00107
00108 while( index && *EnvironmentPointer ){
00109 index--;
00110 EnvironmentPointer++;
00111 }
00112 s = *EnvironmentPointer;
00113 }
00114 }else{
00115
00116 Op1 = CONVERT2STRING(Op1);
00117 if( (sLen=STRLEN(Op1)) > MAX_ENVIRV_LEN -1 )sLen = MAX_ENVIRV_LEN-1;
00118 memcpy(buffer,STRINGVALUE(Op1),sLen);
00119 buffer[sLen] = (char)0;
00120 if( EnvirFunc )
00121 s = EnvirFunc(pEo->pEmbedder,buffer,0);
00122 else
00123 s = getenv( buffer );
00124 }
00125
00126 if( s == NULL ){
00127 RESULT = NULL;
00128 RETURN;
00129 }
00130 sLen=strlen(s);
00131 RESULT = NEWMORTALSTRING(sLen);
00132 ASSERTNULL(RESULT)
00133 memcpy(STRINGVALUE(RESULT),s,sLen);
00134
00135 #endif
00136 END
00137
00151 COMMAND(COMMANDF)
00152 #if NOTIMP_COMMANDF
00153 NOTIMPLEMENTED;
00154 #else
00155
00156 int q;
00157
00158
00159 USE_CALLER_MORTALS;
00160
00161 if( pEo->CmdLineArgument == NULL ){
00162 RESULT = NULL;
00163 RETURN;
00164 }
00165
00166 RESULT = NEWMORTALSTRING(q=strlen(pEo->CmdLineArgument));
00167 ASSERTNULL(RESULT)
00168 memcpy(STRINGVALUE(RESULT),pEo->CmdLineArgument,q);
00169
00170 #endif
00171 END