rochus-keller / Oberon

Oberon parser, code model & browser, compiler and IDE with debugger, and an implementation of the Oberon+ programming language
GNU General Public License v2.0
453 stars 30 forks source link

"Env" like module - access to shell environment variables? #28

Closed packetrhino closed 2 years ago

packetrhino commented 2 years ago

Hi,

I am trying to figure out the analogue to the "Env" module which allows access to shell environment variables.

For instance, assume in a Linux bash shell that I have "SPECIALVAR=myvalue" and then I start an Oberon program ; how do I access that environment variable from within the program? I don't see it in the Oakwood set nor in either the In or Out modules which can be imported, which only seems to concern itself with Linux' stdin and stdout streams.

rochus-keller commented 2 years ago

There is no built-in library which can do this yet, I'm afraid. But you can access e.g. the C standard library using the FFI.

Where did you see the Env module? Just had a look at the Oakwood guidelines and V3, V4 and the project Oberon System and didn't see one.

packetrhino commented 2 years ago

It is in FreeOberon, and in the obnc (the extended library) version; however it is not in the original Oakwood and also, not in the original Oberon sources (nor in blackbox component builder, either).

If you feel the FFI tool is useful at this point, I will try the C based libcgi library at: https://github.com/boutell/cgic and see if I can map what I need into Oberon+ . I was thinking that if I can get access to the environment variables then I can write CGI programs easily, since forking a compiled program will be very fast and Apache, NGINX, etc. pass along CGI variables as strings in the environment.

rochus-keller commented 2 years ago

Ok, I see.

I had a quick look at the cgic library and converted the header file to an external library module using my c2obx tool. Here it is: CGIC.obx.zip

The FFI doesn't support global variables defined in libraries, such as cgiServerSoftware or cgiServerName (just to name a few). If you need access to these you have to add functions to the cgic source code which return the value of the global variables (such as const char* getCgiServerSoftware(), etc.).

But maybe it is easier to map the standard C getenv() function into an external library module.