On Mon, Mar 28, 2011 at 09:57, Mehul Sanghvi <mehul.sang...@gmail.com> wrote:
> On Mon, Mar 28, 2011 at 09:52, Paolo Bonzini <bonz...@gnu.org> wrote:
>> On 03/28/2011 03:42 PM, Mehul Sanghvi wrote:
>>>
>>>      gst>  Smalltalk getenv: 'SHELL'
>>>      '/bin/bash'
>>>      gst>
>>>
>>> I didn't think I needed it when I was doing the environ statement.
>>
>> You didn't need it for "Smalltalk environ" indeed.  But here,
>>
>>> which is different from
>>>
>>>      gst>   Smalltalk environ:
>>>
>>> the last one needing a '.' to make it a complete statement or an object.
>>
>> adding a "." would only make a syntax error, because you need an argument
>> after "environ:", just like you had one above "getenv:".
>>
>> Tip: if you think it's complicated, you aren't understanding it. :)
>>
>> Paolo
>>
>
> More like not paying attention to it.  :)
>
>
> --
> Mehul N. Sanghvi
> email: mehul.sang...@gmail.com
>



I've attached a patch so that environ can be supported from GST.


And this is what my final test-cgi.st script looks like :)
Just ignore the fact that I use GNU style for naming my variables
rather then the CamelCase style that is the convention in Smalltalk.


------ 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 .

env := Smalltalk environ .
env_dict := Dictionary new.

[ (env_string := env value) isNil ] whileFalse: [
           match := env_string =~ '(.*?)=(.*)'.
           env_dict at: (match at: 1) put: (match at: 2).
           env incr ].

env_sorted := env_dict keys asSortedCollection.

Transcript nl ; showCr: '==== All Env Vars below ====== <br>'; nl.
env_sorted do: [ :a_key |
         Transcript show: a_key .
         ans := env_dict at: a_key.
         Transcript show: ' = '; show: ans; cr.
      ].

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

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


Thanks for the help Paolo and the patience.  Hopefully the patch makes it in.


cheers,

     mehul

-- 
Mehul N. Sanghvi
email: mehul.sang...@gmail.com
diff --git a/kernel/CFuncs.st b/kernel/CFuncs.st
index 72b7ca2..f9ca606 100644
--- a/kernel/CFuncs.st
+++ b/kernel/CFuncs.st
@@ -127,6 +127,12 @@ SystemDictionary extend [
 	
     ]
 
+    environ [
+	<category: 'c call-outs'>
+	<cCall: 'environ' returning: #{CString} 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);
 
_______________________________________________
help-smalltalk mailing list
help-smalltalk@gnu.org
http://lists.gnu.org/mailman/listinfo/help-smalltalk

Reply via email to