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

Re: fixed the getenv problem



I am sorry.  That was horrible. here is the patch

*** 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.22 $) */
  
  #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 */
*** es.h	Mon Jul  1 19:17:57 1996
--- es.h.orig	Mon Jul  1 19:16:25 1996
***************
*** 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] = '-' */
*** var.c.orig	Tue May 30 06:13:52 1995
--- var.c	Mon Jul  1 19:16:44 1996
***************
*** 348,353 ****
--- 348,356 ----
  	vars = mkdict();
  	noexport = NULL;
  	env = mkvector(10);
+ #if READLINE
+ 	initgetenv();
+ #endif
  }
  
  /* importvar -- import a single environment variable */