
#include "V.h"
/*
* Here's a routine like getenv, but we look for matches by
* ignoring underscores, so that the environment variables
* FOO_BAR and FOOBAR are considered identical.
*/
CP d_findenv(name)
	char *name;
{	char *n, *v;
	int  e;
extern char **environ;

	for (e=0; environ[e]; e++) {
		for (n=name, v=environ[e]; *n && *v; n++,v++) {	/* Compare names */
			while (*n == '_') ++n;	/* Ignore underscores */
			while (*v == '_') ++v;
			V7 "findenv: Compare %s and %s",Dspp(n),Dspp(v) D;
			if (*n != *v) Loop;		/* Different names */
		}
		if (*v == '=') {	/* Does env var have '=' at end of name? */
			V6 "findenv: %s matched %s",Dspp(name),Dspp(environ[e]) D;
			V5 "findenv(%s)=%s",Dspp(name),Dspp(v+1) D;
			return(v+1);
		}
loop:	;
		V7 "findenv: Rejected due to remainder %s",Dspp(v) D;
	}
	V6 "findenv(%s) not found.",Dspp(name) D;
	return(0);
}
