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

fixed the getenv problem



I just grabbed the freebsd getenv and called that stdgetenv.  changes
the es getenv to esgetenv and made getenv call something that is
initialized to stdgetenv and is changed to esgetenv after the
initialization of the variables.

it seems to work fine on FreeBSD with readline now.

Soren

*** 1.1	1996/07/01 23:03:40
--- input.c	1996/07/01 23:34:02
***************
*** 1,4 ****
! /* input.c -- read input from files or strings ($Revision: 1.1 $) */
  
  #include "es.h"
  #include "input.h"
--- 1,5 ----
! /* input.c -- read input from files or strings ($Revision: 1.2 $) */
! /* stdgetenv is based on the FreeBSD getenv */
  
  #include "es.h"
  #include "input.h"
***************
*** 35,40 ****
--- 36,45 ----
  extern char *readline(char *);
  extern void add_history(char *);
  extern void rl_reset_terminal(char *);
+ 
+ static char *stdgetenv(const char *);
+ static char *esgetenv(const char *);
+ static char *(*realgetenv)(const char *) = stdgetenv;
  #endif
  
  
***************
*** 207,213 ****
  }
  
  /* getenv -- fake version of getenv for readline (or other libraries) */
! extern char *getenv(const char *name) {
  	List *value = varlookup(name, NULL);
  	if (value == NULL)
  		return NULL;
--- 212,218 ----
  }
  
  /* getenv -- fake version of getenv for readline (or other libraries) */
! static char *esgetenv(const char *name) {
  	List *value = varlookup(name, NULL);
  	if (value == NULL)
  		return NULL;
***************
*** 237,242 ****
--- 242,282 ----
  		RefReturn(string);
  	}
  }
+ 
+ 
+ static char *
+ stdgetenv(name)
+ 	register const char *name;
+ {
+ 	extern char **environ;
+ 	register int len;
+ 	register const char *np;
+ 	register char **p, *c;
+ 
+ 	if (name == NULL || environ == NULL)
+ 		return (NULL);
+ 	for (np = name; *np && *np != '='; ++np)
+ 		continue;
+ 	len = np - name;
+ 	for (p = environ; (c = *p) != NULL; ++p)
+ 		if (strncmp(c, name, len) == 0 && c[len] == '=') {
+ 			return (c + len + 1);
+ 		}
+ 	return (NULL);
+ }
+ 
+ char *
+ getenv(char *name)
+ {
+ 	return realgetenv(name);
+ }
+ 
+ extern void
+ initgetenv(void)
+ {
+ 	realgetenv = esgetenv;
+ }
+ 
  #endif	/* READLINE */
  
  /* fdfill -- fill input buffer by reading from a file descriptor */
*** 1.1	1996/07/01 23:14:16
--- var.c	1996/07/01 23:14:32
***************
*** 1,4 ****
! /* var.c -- es variables ($Revision: 1.1 $) */
  
  #include "es.h"
  #include "gc.h"
--- 1,4 ----
! /* var.c -- es variables ($Revision: 1.24 $) */
  
  #include "es.h"
  #include "gc.h"
***************
*** 348,353 ****
--- 348,357 ----
  	vars = mkdict();
  	noexport = NULL;
  	env = mkvector(10);
+ #if READLINE
+ 	initgetenv();
+ #endif
+ 	
  }
  
  /* importvar -- import a single environment variable */
*** 1.1	1996/07/01 23:16:14
--- es.h	1996/07/01 23:18:19
***************
*** 288,293 ****
--- 288,296 ----
  
  extern List *runfd(int fd, const char *name, int flags);
  extern List *runstring(const char *str, const char *name, int flags);
+ #if READLINE
+ extern void initgetenv(void);
+ #endif
  
  /* eval_* flags are also understood as runflags */
  #define	run_interactive		 4	/* -i or $0[0] = '-' */