help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] How to access environment variables ?


From: Mehul Sanghvi
Subject: Re: [Help-smalltalk] How to access environment variables ?
Date: Sat, 26 Mar 2011 19:41:21 -0400

On Sat, Mar 26, 2011 at 18:41, Mehul Sanghvi <address@hidden> wrote:
> On Sat, Mar 26, 2011 at 10:04, Mehul Sanghvi <address@hidden> wrote:
>> On Sat, Mar 26, 2011 at 03:10, Paolo Bonzini <address@hidden> wrote:
>>> On 03/26/2011 02:12 AM, Mehul Sanghvi wrote:
>>>>
>>>> OK so once I  modify kernel/CFuncs.st and I believe I need to also
>>>> modify libgst/cint.c what else do I need to do in order to get this to
>>>> work ?
>>>>
>>>>
>>>> In kernel/CFuncs.st
>>>>
>>>>     environ: aString [
>>>>        <category: 'c call-outs'>
>>>>        <cCall: 'environ' returning: #(#ptr #string) args: #()>
>>>>
>>>>     ]
>>>
>>> Where did you add this?
>>>
>>
>> I did that right below where there was a similar
>> bit of code for getenv.  I just copied that piece of
>> code and adjusted it based on the information
>> in this mailing list thread.
>>
>>
>>>> and in libgst/cint.c
>>>>
>>>>   _gst_define_cfunc ("getenv", getenv);
>>>>   _gst_define_cfunc ("environ", environ);
>>>
>>> You should do
>>>
>>> static char **get_environ(void)
>>> {
>>>  return environ;
>>> }
>>>
>>> ...
>>>
>>>  _gst_define_cfunc ("get_environ", get_environ);
>>>
>>> Paolo
>>>
>
>
> Below is the code I am running, the result I get, and the diff
> of what I've changed.  I'm pretty sure my code in the
> smalltalk script is wrong
>
>
> ------ BEGIN CODE -------
> #!/usr/local/bin/gst -f
>
> Transcript showCr: 'Content-type: text/html'; nl .
> '' displayNl .
> '<HTML>' displayNl .
> '<HEAD><TITLE>Testing CGI/Smalltalk</TITLE></HEAD>' displayNl .
> '<BODY>' displayNl .
> '<H2>Yo! Smalltalk,  Whats up ? </H2>' displayNl .
>
> Transcript nl ; showCr: '==== All Env Vars below ====== <br>'; nl.
> "pipe := FileStream popen: ('set', logFile) dir: FileStream read .
> Transcript showCr: pipe contents ."
> env := Smalltalk environ .
>
> "Transcript nl; showCr:  env ; nl ."
>
> '</BODY>' displayNl .
> '</HTML>' displayNl .
> --------- END CODE -------
>
> --------- BEGIN OUTPUT ----
> % gst test-cgi.st
> Content-type: text/html
>
>
> <HTML>
> <HEAD><TITLE>Testing CGI/Smalltalk</TITLE></HEAD>
> <BODY>
> <H2>Yo! Smalltalk,  Whats up ? </H2>
>
> ==== All Env Vars below ====== <br>
>
> Object: SystemDictionary new: 512 "<0x40290818>" error: did not
> understand #environ
> MessageNotUnderstood(Exception)>>signal (ExcHandling.st:254)
> SystemDictionary(Object)>>doesNotUnderstand: #environ (SysExcept.st:1407)
> SystemDictionary(BindingDictionary)>>doesNotUnderstand: #environ
> (BindingDict.st:181)
> UndefinedObject>>executeStatements (test-cgi.st:13)
> </BODY>
> </HTML>
>
>
> -------- END OUTPUT --------
>
> ------- BEGIN DIFF -------
> diff --git a/kernel/CFuncs.st b/kernel/CFuncs.st
> index 72b7ca2..ff2db72 100644
> --- a/kernel/CFuncs.st
> +++ b/kernel/CFuncs.st
> @@ -127,6 +127,12 @@ SystemDictionary extend [
>
>     ]
>
> +    environ: aString [
> +       <category: 'c call-outs'>
> +       <cCall: 'environ' returning: #(#ptr #string) args: #()>
> +
> +    ]
> +
>     putenv: aString [
>        <category: 'c call-outs'>
>        <cCall: 'putenv' returning: #int args: #(#string)>
>
>
> diff --git a/libgst/cint.c b/libgst/cint.c
> index 061a829..44c5369 100644
> --- a/libgst/cint.c
> +++ b/libgst/cint.c
> @@ -195,6 +195,7 @@ static int my_lstat (const char *name,
>                     OOP out);
>  #endif
>  static int my_putenv (const char *str);
> +static char **get_environ (void);
>  static int my_chdir (const char *str);
>  static int my_chown (const char *file, const char *owner, const char *group);
>  static int my_symlink (const char* oldpath, const char* newpath);
> @@ -392,6 +393,12 @@ my_putenv (const char *str)
>   return (putenv (clone));
>  }
>
> +static char **
> +get_environ (void)
> +{
> +  return environ;
> +}
> +
>
>  int
>  my_chdir (const char *dir)
> @@ -592,6 +599,7 @@ _gst_init_cfuncs (void)
>   /* Access to C library */
>   _gst_define_cfunc ("system", system);
>   _gst_define_cfunc ("getenv", getenv);
> +  _gst_define_cfunc ("environ", get_environ);
>   _gst_define_cfunc ("putenv", my_putenv);
>   _gst_define_cfunc ("printf", printf);
>
> ------------- END DIFF ----------------
> --
> Mehul N. Sanghvi
> email: address@hidden
>




OK so I changed the code, accidently discovering my mistake in the
previous code I had sent:

------ BEGIN CODE -----
#!/usr/local/bin/gst -f

Transcript showCr: 'Content-type: text/html'; nl .
'' displayNl .
'<HTML>' displayNl .
'<HEAD><TITLE>Testing CGI/Smalltalk</TITLE></HEAD>' displayNl .
'<BODY>' displayNl .
'<H2>Yo! Smalltalk,  Whats up ? </H2>' displayNl .

Transcript nl ; showCr: '==== All Env Vars below ====== <br>'; nl.
Transcript nl;  print: Smalltalk environ:  ; nl .

'</BODY>' displayNl .
'</HTML>' displayNl .

---- -END CODE -----


but now I get the following

------- BEGIN OUTPUT -----------

% gst test-cgi.st
Content-type: text/html


<HTML>
<HEAD><TITLE>Testing CGI/Smalltalk</TITLE></HEAD>
<BODY>
<H2>Yo! Smalltalk,  Whats up ? </H2>

==== All Env Vars below ====== <br>

test-cgi.st:11: expected object

------- END OUTPUT -------

I'm pretty sure I am messing up on something
pretty simple and basic.


cheers,

      mehul

-- 
Mehul N. Sanghvi
email: address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]