[comp.sys.atari.st] getenv

csch@tub.UUCP (04/03/87)

> Mark Williams C has a *working* getenv(). I assume you have sources to ME.
> Just add a call to getenv("LIBDIR") to your ME and look in the directory
> given to you by the call for your emacsrc file. Of course you have to define
> 'setenv LIBDIR=c:\usr\lib' (or wherever your libraries are) to the profile
> for msh.prg.
> 		Michael Doerr

Right! BUT: The MWC getenv() does NOT work together with Beckemeyer's C Shell!
(He announced his new version 2.7, which I ordered, but not yet received - 
 which should be compatible with the MWC package)

The problem is: 

BDT puts a \0 behind the '=', as does MWC NOT !

So: Take this short routine, I wrote for uEmacs38b, which handles BOTH!

Have fun, Clemens

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Contact via:

csch@tub.uucp 

from the US: ...!pyramid!tub!csch
from Europe: ...!unido!tub!csch
Bitnet:      csch@db0tui6 = tub.bitnet

tel.: +49-30-393-3574
      +49-30-332-4015

tlx.: (west-germany) + 186672 rdt d
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-------------------------- cut here ------------------------------

/* for use with MWC --- csch@tub.uucp */

#include <basepage.h>

#define TRUE	1
#define FALSE	0
#define NULL	(char *) (0)

/* locate variable name in environment string */

static char *findenv(s)
char *s;
{
static	char name[32];
char *p;

	if (! s)
		return(NULL);

	strcpy(name, s);
	strcat(name, "=");

	for (p = (char *) (BP->p_env); *p; p++) {
		if (strncmp(p, name, strlen(name)) == 0)
				break;
		while (*p)
			p++;
			
		if (! *(p+1))
			return(NULL);
	}
	return(p);
}

char *getenv(name)
char *name;
{
char *p;

	p = findenv(name);
	if (p == NULL)
		return(NULL);
		
	while (*p && *p != '=')
		p++;
	return(*++p ? p : p+1);
}