mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Remove abandoned SHOPT_ENV experiment
SHOPT_ENV is an undocumented compile-time option implementing an experimental method for handling environment variables, which is implemented in env.h and env.c. There is no mention in the docs or Makefile, and no mention in the mailing list archives. It adds no new functionality, but at first glance it's a clean-looking interface. However, unfortunately, it's broken. Compiling with -DSHOPT_ENV added to CCFLAGS causes bin/shtests to show these regressions: functions.sh[341]: export not restored name=value function call -- expected 'base', got '' functions.sh[1274]: Environment variable is not passed to a function substring.sh[236]: export not restored name=value function call variables.sh[782]: SHLVL should be 3 not 2 In addition, 'export' stops working on unset variables. In the 93v- beta this code is still present, unchanged, though 93v- made lots of incompatible changes. By the time ksh2020 noticed it, it was no longer compiling, so it probably wasn't compiling in the 93v- beta either. Discussion: https://github.com/att/ast/issues/504 So the experiment was already abandoned by D. Korn and his team. Meanwhile it was leaving sh/name.c with two versions of several enviornment-related functions, and it's not clear which one is actually compiled without doing detective work tracing header files (most of the code was made conditional on _ENV_H, which is defined in env.h, which is included by defs.h if SHOPT_ENV is defined). This actively hinders understanding of the codebase. And any changes to these functions would need to be implemented twice. src/cmd/ksh93/include/env.h, src/cmd/ksh93/sh/env.c: - Removed. src/cmd/ksh93/DESIGN, src/cmd/ksh93/Makefile, src/cmd/ksh93/Mamfile: - Update accordingly. All other changed files: - Remove deactivated code behind SHOPT_ENV and _ENV_H.
This commit is contained in:
parent
bc4dbe0627
commit
8d7f616e75
10 changed files with 57 additions and 488 deletions
|
@ -59,46 +59,44 @@ Include directory:
|
|||
function data, sh.st.
|
||||
4. edit.h contains definitions that are common to both
|
||||
vi and emacs edit modes.
|
||||
5. env.h contains an alternative interfaces for creating and
|
||||
modifying environment variables.
|
||||
6. fault.h contains prototypes for signal related
|
||||
5. fault.h contains prototypes for signal related
|
||||
functions and trap and fault handling.
|
||||
7. fcin.h contains macro and function definitions for
|
||||
6. fcin.h contains macro and function definitions for
|
||||
reading from a file or string.
|
||||
8. history.h contains macros and functions definitions
|
||||
7. history.h contains macros and functions definitions
|
||||
related to history file processing.
|
||||
9. jobs.h contains the definitions relating to job
|
||||
8. jobs.h contains the definitions relating to job
|
||||
processing and control.
|
||||
10. lexstates.h contains the states associated with
|
||||
9. lexstates.h contains the states associated with
|
||||
lexical processing.
|
||||
11. name.h contains the internal definitions related
|
||||
10. name.h contains the internal definitions related
|
||||
to name-value pair processing.
|
||||
12. national.h contains a few I18N definitions, mostly
|
||||
11. national.h contains a few I18N definitions, mostly
|
||||
obsolete.
|
||||
13. nval.h is the public interface to the name-value
|
||||
12. nval.h is the public interface to the name-value
|
||||
pair library that is documented with nval.3.
|
||||
14. path.h contains the interface for pathname processing
|
||||
13. path.h contains the interface for pathname processing
|
||||
and pathname searching.
|
||||
15. shell.h is the public interface for shell functions
|
||||
14. shell.h is the public interface for shell functions
|
||||
that are documented int shell.3.
|
||||
16. shlex.h contains the lexical token definitions and
|
||||
15. shlex.h contains the lexical token definitions and
|
||||
interfaces for lexical analysis.
|
||||
17. shnodes.h contains the definition of the structures
|
||||
16. shnodes.h contains the definition of the structures
|
||||
for each of the parse nodes and flags for the attributes.
|
||||
18. shtable.h contains some interfaces and functions for
|
||||
17. shtable.h contains some interfaces and functions for
|
||||
table lookup.
|
||||
19. streval.h contains the interface to the arithmetic
|
||||
18. streval.h contains the interface to the arithmetic
|
||||
functions.
|
||||
20. terminal.h is a header file that includes the appropriate
|
||||
19. terminal.h is a header file that includes the appropriate
|
||||
terminal include.
|
||||
21. test.h contains the definitions for the test and [[...]]
|
||||
20. test.h contains the definitions for the test and [[...]]
|
||||
commands.
|
||||
22. timeout.h contains the define constant for the maximum
|
||||
21. timeout.h contains the define constant for the maximum
|
||||
shell timeout.
|
||||
23. ulimit.h includes the appropriate resource header.
|
||||
24. variables.h contains symbolic constants for the built-in
|
||||
22. ulimit.h includes the appropriate resource header.
|
||||
23. variables.h contains symbolic constants for the built-in
|
||||
shell variables.
|
||||
25. version.h contains the version string for this release.
|
||||
24. version.h contains the version string for this release.
|
||||
|
||||
sh directory:
|
||||
1. args.c contains functions for parsing shell options
|
||||
|
@ -107,63 +105,61 @@ sh directory:
|
|||
library and the interface to shell arithmetic.
|
||||
3. array.c contains the code for indexed and associative
|
||||
arrays.
|
||||
4. (removed)
|
||||
5. defs.c contains the data definitions for global symbols.
|
||||
6. deparse.c contains code to generate shell script from
|
||||
4. defs.c contains the data definitions for global symbols.
|
||||
5. deparse.c contains code to generate shell script from
|
||||
a parse tree.
|
||||
7. env.c contains code to add and delete environment variables
|
||||
to an environment list.
|
||||
8. expand.c contains code for file name expansion and
|
||||
6. expand.c contains code for file name expansion and
|
||||
file name generation.
|
||||
9. fault.c contains code for signal processing, trap
|
||||
7. fault.c contains code for signal processing, trap
|
||||
handling and termination.
|
||||
10. fcin.c contains code for reading and writing a character
|
||||
8. fcin.c contains code for reading and writing a character
|
||||
at a time from a file or string.
|
||||
11. init.c contains initialization code and callbacks
|
||||
9. init.c contains initialization code and callbacks
|
||||
for get and set functions for built-in variables.
|
||||
12. io.o contains code for redirections and managing file
|
||||
10. io.o contains code for redirections and managing file
|
||||
descriptors and file streams.
|
||||
13. jobs.c contains the code for job management.
|
||||
14. lex.c contains the code for the lexical analyzer.
|
||||
15. macro.c contains code for the $ macro expansions, including
|
||||
11. jobs.c contains the code for job management.
|
||||
12. lex.c contains the code for the lexical analyzer.
|
||||
13. macro.c contains code for the $ macro expansions, including
|
||||
here-documents.
|
||||
16. main.c contains the calls to initialization, profile
|
||||
14. main.c contains the calls to initialization, profile
|
||||
processing and the main evaluation loop as well as
|
||||
mail processing.
|
||||
17. name.c contains the name-value pair routines that are
|
||||
15. name.c contains the name-value pair routines that are
|
||||
built on the hash library in libast.
|
||||
18. nvdisc.c contains code related to name-value pair disciplines.
|
||||
19. nvtree.c contains code for compound variables and for
|
||||
16. nvdisc.c contains code related to name-value pair disciplines.
|
||||
17. nvtree.c contains code for compound variables and for
|
||||
walking the namespace.
|
||||
20. nvtype.c contains most of the code related to types that
|
||||
18. nvtype.c contains most of the code related to types that
|
||||
are created with typeset -T.
|
||||
21. parse.c contains the code for the shell parser.
|
||||
22. path.c contains the code for pathname lookup and
|
||||
19. parse.c contains the code for the shell parser.
|
||||
20. path.c contains the code for pathname lookup and
|
||||
some path functions. It also contains the code
|
||||
that executes commands and scripts.
|
||||
23. pmain.c is just a calls sh_main() so that all of the
|
||||
21. pmain.c is just a calls sh_main() so that all of the
|
||||
rest of the shell can be in a shared library.
|
||||
24. shcomp.c contains the main program to the shell
|
||||
22. shcomp.c contains the main program to the shell
|
||||
compiler. This program parses a script and creates
|
||||
a file that the shell can read containing the parse tree.
|
||||
25. streval.c is an C arithmetic evaluator.
|
||||
26. string.c contains some string related functions.
|
||||
27. subshell.c contains the code to save and restore
|
||||
23. streval.c is an C arithmetic evaluator.
|
||||
24. string.c contains some string related functions.
|
||||
25. subshell.c contains the code to save and restore
|
||||
environments so that subshells can run without creating
|
||||
a new process.
|
||||
28. suid_exec.c contains the program from running execute
|
||||
26. suid_exec.c contains the program from running execute
|
||||
only and/or setuid/setgid scripts.
|
||||
29. tdump.c contains the code to dump a parse tree into
|
||||
27. tdump.c contains the code to dump a parse tree into
|
||||
a file.
|
||||
30. timers.c contains code for multiple event timeouts.
|
||||
31. trestore contains the code for restoring the parse
|
||||
28. timers.c contains code for multiple event timeouts.
|
||||
29. trestore contains the code for restoring the parse
|
||||
tree from the file created by tdump.
|
||||
32. userinit.c contains a dummy userinit() function.
|
||||
30. userinit.c contains a dummy userinit() function.
|
||||
This is now obsolete with the new version of sh_main().
|
||||
33. waitevent.c contains the sh_waitnotify function so
|
||||
31. waitevent.c contains the sh_waitnotify function so
|
||||
that builtins can handle processing events when the
|
||||
shell is waiting for input or for process completion.
|
||||
34. xec.c is the main shell execution loop.
|
||||
32. xec.c is the main shell execution loop.
|
||||
|
||||
edit directory:
|
||||
1. completion.c contains code for command and file generation and
|
||||
completion.
|
||||
|
|
|
@ -153,7 +153,7 @@ shell$(RELEASE) $(VERSION) id=shell :LIBRARY: shell.3 nval.3 alarm.c cd_pwd.c cf
|
|||
arith.c args.c array.c completion.c defs.c edit.c expand.c regress.c \
|
||||
fault.c fcin.c history.c init.c io.c jobs.c lex.c macro.c name.c \
|
||||
nvtree.c parse.c path.c string.c streval.c subshell.c tdump.c timers.c \
|
||||
trestore.c waitevent.c xec.c env.c $(DATAFILES) $(FILES_opt) \
|
||||
trestore.c waitevent.c xec.c $(DATAFILES) $(FILES_opt) \
|
||||
-lcmd -last -lm
|
||||
|
||||
"sol*.i386*" :NOOPTIMIZE: main.c
|
||||
|
|
|
@ -248,8 +248,6 @@ make include/regress.h implicit
|
|||
done include/regress.h dontcare
|
||||
prev include/shtable.h implicit
|
||||
prev include/shell.h implicit
|
||||
make include/env.h implicit
|
||||
done include/env.h dontcare
|
||||
prev ${PACKAGE_ast_INCLUDE}/endian.h implicit
|
||||
prev include/name.h implicit
|
||||
make include/argnod.h implicit
|
||||
|
@ -1134,16 +1132,6 @@ meta xec.o %.c>%.o sh/xec.c xec
|
|||
prev sh/xec.c
|
||||
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -Iinclude -I${PACKAGE_ast_INCLUDE} -DSHOPT_BGX -DSHOPT_TYPEDEF -DSHOPT_PFSH -DSHOPT_FILESCAN -DSHOPT_NAMESPACE -DSHOPT_OPTIMIZE -D_API_ast=20100309 -D_PACKAGE_ast -DSHOPT_STATS -DSHOPT_HISTEXPAND -D_BLD_shell -DERROR_CONTEXT_T=Error_context_t -DSHOPT_FIXEDARRAY -DSHOPT_ESH -DSHOPT_MULTIBYTE -DSHOPT_DYNAMIC -DKSHELL -DSHOPT_SUID_EXEC -DSHOPT_BRACEPAT -c sh/xec.c
|
||||
done xec.o generated
|
||||
make env.o
|
||||
make sh/env.c
|
||||
prev include/env.h implicit
|
||||
prev ${PACKAGE_ast_INCLUDE}/cdt.h implicit
|
||||
prev ${PACKAGE_ast_INCLUDE}/ast.h implicit
|
||||
done sh/env.c
|
||||
meta env.o %.c>%.o sh/env.c env
|
||||
prev sh/env.c
|
||||
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -Iinclude -I${PACKAGE_ast_INCLUDE} -D_API_ast=20100309 -D_PACKAGE_ast -c sh/env.c
|
||||
done env.o generated
|
||||
make limits.o
|
||||
make data/limits.c
|
||||
prev include/ulimit.h implicit
|
||||
|
@ -1310,7 +1298,7 @@ prev edit/hexpand.c
|
|||
exec - ${CC} ${mam_cc_FLAGS} ${CCFLAGS} -I. -Iinclude -I${PACKAGE_ast_INCLUDE} -DSHOPT_HISTEXPAND -DSHOPT_EDPREDICT -DSHOPT_MULTIBYTE -DKSHELL -DSHOPT_ESH -DSHOPT_VSH -D_PACKAGE_ast -DSHOPT_PFSH -DSHOPT_STATS -DSHOPT_NAMESPACE -D_BLD_shell -D_API_ast=20100309 -DERROR_CONTEXT_T=Error_context_t -DSHOPT_FIXEDARRAY -c edit/hexpand.c
|
||||
done hexpand.o generated
|
||||
exec - ${AR} rc libshell.a alarm.o cd_pwd.o cflow.o deparse.o enum.o getopts.o hist.o misc.o print.o read.o sleep.o trap.o test.o typeset.o ulimit.o umask.o whence.o main.o nvdisc.o nvtype.o arith.o args.o array.o completion.o defs.o edit.o expand.o regress.o fault.o fcin.o
|
||||
exec - ${AR} rc libshell.a history.o init.o io.o jobs.o lex.o macro.o name.o nvtree.o parse.o path.o string.o streval.o subshell.o tdump.o timers.o trestore.o waitevent.o xec.o env.o limits.o msg.o strdata.o testops.o keywords.o options.o signals.o builtins.o variables.o lexstates.o emacs.o vi.o hexpand.o
|
||||
exec - ${AR} rc libshell.a history.o init.o io.o jobs.o lex.o macro.o name.o nvtree.o parse.o path.o string.o streval.o subshell.o tdump.o timers.o trestore.o waitevent.o xec.o limits.o msg.o strdata.o testops.o keywords.o options.o signals.o builtins.o variables.o lexstates.o emacs.o vi.o hexpand.o
|
||||
exec - (ranlib libshell.a) >/dev/null 2>&1 || true
|
||||
done libshell.a generated
|
||||
bind -lshell
|
||||
|
|
|
@ -126,14 +126,7 @@ int b_exec(int argc,char *argv[], Shbltin_t *context)
|
|||
if(logdata.sh->subshell && !logdata.sh->subshare)
|
||||
sh_subfork();
|
||||
if(logdata.clear)
|
||||
{
|
||||
#ifdef _ENV_H
|
||||
env_close(logdata.sh->env);
|
||||
logdata.sh->env = env_open((char**)0,3);
|
||||
#else
|
||||
nv_scan(logdata.sh->var_tree,noexport,0,NV_EXPORT,NV_EXPORT);
|
||||
#endif
|
||||
}
|
||||
while(arg)
|
||||
{
|
||||
if((cp=strchr(arg->argval,'=')) &&
|
||||
|
|
|
@ -111,19 +111,6 @@ int b_readonly(int argc,char *argv[],Shbltin_t *context)
|
|||
argv += (opt_info.index-1);
|
||||
if(*command=='r')
|
||||
flag = (NV_ASSIGN|NV_RDONLY|NV_VARNAME);
|
||||
#ifdef _ENV_H
|
||||
else if(!argv[1])
|
||||
{
|
||||
char *cp,**env=env_get(tdata.sh->env);
|
||||
while(cp = *env++)
|
||||
{
|
||||
if(tdata.prefix)
|
||||
sfputr(sfstdout,tdata.prefix,' ');
|
||||
sfprintf(sfstdout,"%s\n",sh_fmtq(cp));
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
#endif
|
||||
else
|
||||
flag = (NV_ASSIGN|NV_EXPORT|NV_IDENT);
|
||||
if(!tdata.sh->prefix)
|
||||
|
|
|
@ -53,13 +53,9 @@
|
|||
#define Empty ((char*)(e_sptbnl+3))
|
||||
|
||||
#define env_change() (++ast.env_serial)
|
||||
#if SHOPT_ENV
|
||||
# include <env.h>
|
||||
#else
|
||||
# define Env_t void
|
||||
# define sh_envput(e,p) env_change()
|
||||
# define env_delete(e,p) env_change()
|
||||
#endif
|
||||
#define Env_t void
|
||||
#define sh_envput(e,p) env_change()
|
||||
#define env_delete(e,p) env_change()
|
||||
|
||||
extern char* sh_getenv(const char*);
|
||||
extern char* sh_setenviron(const char*);
|
||||
|
@ -371,9 +367,6 @@ extern int sh_debug(Shell_t *shp,const char*,const char*,const char*,char *cons
|
|||
extern int sh_echolist(Shell_t*,Sfio_t*, int, char**);
|
||||
extern struct argnod *sh_endword(Shell_t*,int);
|
||||
extern char **sh_envgen(void);
|
||||
#if SHOPT_ENV
|
||||
extern void sh_envput(Env_t*, Namval_t*);
|
||||
#endif
|
||||
extern void sh_envnolocal(Namval_t*,void*);
|
||||
extern Sfdouble_t sh_arith(Shell_t*,const char*);
|
||||
extern void *sh_arithcomp(Shell_t *,char*);
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
/***********************************************************************
|
||||
* *
|
||||
* This software is part of the ast package *
|
||||
* Copyright (c) 1982-2011 AT&T Intellectual Property *
|
||||
* and is licensed under the *
|
||||
* Eclipse Public License, Version 1.0 *
|
||||
* by AT&T Intellectual Property *
|
||||
* *
|
||||
* A copy of the License is available at *
|
||||
* http://www.eclipse.org/org/documents/epl-v10.html *
|
||||
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
|
||||
* *
|
||||
* Information and Software Systems Research *
|
||||
* AT&T Research *
|
||||
* Florham Park NJ *
|
||||
* *
|
||||
* David Korn <dgk@research.att.com> *
|
||||
* *
|
||||
***********************************************************************/
|
||||
#pragma prototyped
|
||||
#ifndef _ENV_H
|
||||
#define _ENV_H 1
|
||||
|
||||
#ifdef _BLD_env
|
||||
# ifdef __EXPORT__
|
||||
# define export __EXPORT__
|
||||
# endif
|
||||
#else
|
||||
typedef void *Env_t;
|
||||
#endif
|
||||
|
||||
/* for use with env_open */
|
||||
#define ENV_STABLE (-1)
|
||||
|
||||
/* for third argument to env_add */
|
||||
#define ENV_MALLOCED 1
|
||||
#define ENV_STRDUP 2
|
||||
|
||||
extern void env_close(Env_t*);
|
||||
extern int env_add(Env_t*, const char*, int);
|
||||
extern int env_delete(Env_t*, const char*);
|
||||
extern char **env_get(Env_t*);
|
||||
extern Env_t *env_open(char**,int);
|
||||
extern Env_t *env_scope(Env_t*,int);
|
||||
|
||||
#undef extern
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -1,255 +0,0 @@
|
|||
/***********************************************************************
|
||||
* *
|
||||
* This software is part of the ast package *
|
||||
* Copyright (c) 1982-2011 AT&T Intellectual Property *
|
||||
* and is licensed under the *
|
||||
* Eclipse Public License, Version 1.0 *
|
||||
* by AT&T Intellectual Property *
|
||||
* *
|
||||
* A copy of the License is available at *
|
||||
* http://www.eclipse.org/org/documents/epl-v10.html *
|
||||
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
|
||||
* *
|
||||
* Information and Software Systems Research *
|
||||
* AT&T Research *
|
||||
* Florham Park NJ *
|
||||
* *
|
||||
* David Korn <dgk@research.att.com> *
|
||||
* *
|
||||
***********************************************************************/
|
||||
#pragma prototyped
|
||||
|
||||
#include <ast.h>
|
||||
#include <cdt.h>
|
||||
|
||||
#define env_change() (++ast.env_serial)
|
||||
|
||||
typedef struct _venv_ Evar_t;
|
||||
struct _venv_
|
||||
{
|
||||
union
|
||||
{
|
||||
Evar_t *next;
|
||||
char *ptr;
|
||||
} un;
|
||||
Dtlink_t link;
|
||||
int index;
|
||||
};
|
||||
|
||||
typedef struct _env_
|
||||
{
|
||||
Dt_t *dt;
|
||||
Evar_t *freelist;
|
||||
char **env;
|
||||
int count;
|
||||
int extra;
|
||||
int max;
|
||||
int flags;
|
||||
} Env_t;
|
||||
|
||||
#define _BLD_env 1
|
||||
#include <env.h>
|
||||
|
||||
#define ENV_VALID 2 /* set if env is valid */
|
||||
#define ENV_PMALLOC 1 /* set if Evar_t->un.ptr *s malloced */
|
||||
#define ENV_VMALLOC 2 /* set of Evar_t was malloced */
|
||||
#define ENV_BITS 3
|
||||
|
||||
/*
|
||||
* Compares the name portion of name=... only.
|
||||
*/
|
||||
static int compare(Dt_t *dt, Void_t* key1, Void_t* key2, Dtdisc_t* disc)
|
||||
{
|
||||
register int c,d;
|
||||
const unsigned char *s1=(unsigned const char*)key1;
|
||||
const unsigned char *s2=(unsigned const char*)key2;
|
||||
while((c= *s1++) && c!='=' && c==*s2)
|
||||
s2++;
|
||||
if(c=='=')
|
||||
c = 0;
|
||||
if((d=*s2)=='=')
|
||||
d = 0;
|
||||
return(c-d);
|
||||
}
|
||||
|
||||
static Dtdisc_t env_disc =
|
||||
{
|
||||
0, -1,
|
||||
sizeof(char*),
|
||||
0,
|
||||
0,
|
||||
compare
|
||||
};
|
||||
|
||||
/*
|
||||
* return a pointer to the environment in sorted order
|
||||
* NULL is returned if there if there is nospace
|
||||
*/
|
||||
char **env_get(Env_t* ep)
|
||||
{
|
||||
register Evar_t *vp;
|
||||
register int n=ep->extra;
|
||||
if(ep->flags&ENV_VALID)
|
||||
return(ep->env+n);
|
||||
if(ep->count > ep->max)
|
||||
{
|
||||
if(ep->flags&ENV_MALLOCED)
|
||||
free((void*)ep->env);
|
||||
if(!(ep->env = (char**)malloc(sizeof(char*)*(ep->count+1))))
|
||||
return(0);
|
||||
ep->flags |= ENV_MALLOCED;
|
||||
ep->max = ep->count;
|
||||
}
|
||||
for(vp=(Evar_t*)dtfirst(ep->dt);vp; vp=(Evar_t*)dtnext(ep->dt,vp))
|
||||
{
|
||||
vp->index = (n<<ENV_BITS) | (vp->index&((1<<ENV_BITS)-1));
|
||||
ep->env[n++] = vp->un.ptr;
|
||||
}
|
||||
ep->env[n] = 0;
|
||||
ep->flags |= ENV_VALID;
|
||||
environ = ep->env+ep->extra;
|
||||
return(ep->env+ep->extra);
|
||||
}
|
||||
|
||||
/*
|
||||
* add name=value pair given by <str> to <ep>
|
||||
* if malloced is set, the variable will be freed when reassigned
|
||||
* The environment list may become invalidated
|
||||
* Returns 1 for success, 0 for failure
|
||||
*/
|
||||
int env_add(Env_t *ep, const char *str, int flags)
|
||||
{
|
||||
Evar_t *vp = (Evar_t*)dtmatch(ep->dt,(void*)str);
|
||||
if(vp && strcmp(str,vp->un.ptr)==0)
|
||||
return(1);
|
||||
if(flags&ENV_STRDUP)
|
||||
str = strdup(str);
|
||||
if(vp)
|
||||
{
|
||||
if(vp->index&ENV_PMALLOC)
|
||||
free((void*)vp->un.ptr);
|
||||
vp->un.ptr = (char*)str;
|
||||
if(ep->env && (ep->flags&ENV_VALID))
|
||||
ep->env[vp->index>>ENV_BITS] = vp->un.ptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
ep->flags &= ~ENV_VALID;
|
||||
if(vp = ep->freelist)
|
||||
ep->freelist = vp->un.next;
|
||||
else if(vp = newof((Evar_t*)0,Evar_t,2,0))
|
||||
{
|
||||
vp->index = ENV_VMALLOC;
|
||||
ep->freelist = (vp+1);
|
||||
ep->freelist->un.next = 0;
|
||||
}
|
||||
else
|
||||
return(0);
|
||||
vp->un.ptr = (void*)str;
|
||||
if(!(vp=dtinsert(ep->dt,vp)))
|
||||
return(0);
|
||||
ep->count++;
|
||||
}
|
||||
if(flags)
|
||||
vp->index |= ENV_PMALLOC;
|
||||
else
|
||||
vp->index &= ~ENV_PMALLOC;
|
||||
env_change();
|
||||
return(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* delete name from <ep>
|
||||
* The environment list may become invalidated
|
||||
* Returns 1 for success, 0 for if name is not present
|
||||
*/
|
||||
int env_delete(Env_t *ep, const char *str)
|
||||
{
|
||||
Evar_t *vp = (Evar_t*)dtmatch(ep->dt,(void*)str);
|
||||
if(!vp)
|
||||
return(0);
|
||||
ep->flags &= ~ENV_VALID;
|
||||
if(vp->index&ENV_PMALLOC)
|
||||
free((void*)vp->un.ptr);
|
||||
dtdelete(ep->dt,vp);
|
||||
vp->un.next = ep->freelist;
|
||||
ep->freelist = vp;
|
||||
env_change();
|
||||
return(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* open up a structure to support environment variables
|
||||
* initialize with environment give by <envp>
|
||||
* If <extra> > 0, <extra> slots will be left at beginning of
|
||||
* environment list when env_get() is involed.
|
||||
* If <extra>==ENV_USABLE, then the original environ can be
|
||||
* used and returned. Otherwise, a new one will be returned
|
||||
*/
|
||||
Env_t *env_open(char **envp, int extra)
|
||||
{
|
||||
char **env;
|
||||
Env_t *ep;
|
||||
Evar_t *vp;
|
||||
int n=2;
|
||||
if(!(ep = newof((Env_t*)0,Env_t,1,0)))
|
||||
return(0);
|
||||
if(!(ep->dt = dtopen(&env_disc,Dtoset)))
|
||||
return(0);
|
||||
if(env=envp)
|
||||
{
|
||||
while(*env++);
|
||||
n = (env+2)-envp;
|
||||
}
|
||||
if(extra==ENV_STABLE)
|
||||
{
|
||||
ep->env = envp;
|
||||
ep->max = n-1;
|
||||
}
|
||||
else
|
||||
ep->count = ep->extra = extra;
|
||||
ep->freelist = vp = newof((Evar_t*)0,Evar_t,n,0);
|
||||
vp->index = ENV_VMALLOC;
|
||||
while(--n>0)
|
||||
{
|
||||
vp->un.next = (vp+1);
|
||||
vp++;
|
||||
}
|
||||
vp->un.next = 0;
|
||||
if(env)
|
||||
{
|
||||
for(env=envp; *env; env++)
|
||||
env_add(ep,*env,0);
|
||||
}
|
||||
return(ep);
|
||||
}
|
||||
|
||||
/*
|
||||
* close <ep> and free up all space used by it
|
||||
*/
|
||||
void env_close(Env_t *ep)
|
||||
{
|
||||
Evar_t *vp, *vpnext,*top;
|
||||
if(ep->env && (ep->flags&ENV_MALLOCED))
|
||||
free((void*)ep->env);
|
||||
for(vp=(Evar_t*)dtfirst(ep->dt);vp; vp=vpnext)
|
||||
{
|
||||
vpnext = (Evar_t*)dtnext(ep->dt,vp);
|
||||
env_delete(ep,vp->un.ptr);
|
||||
}
|
||||
for(top=0,vp = ep->freelist; vp; vp = vpnext)
|
||||
{
|
||||
vpnext = vp->un.next;
|
||||
if(vp->index&ENV_VMALLOC)
|
||||
{
|
||||
vp->un.next = top;
|
||||
top = vp;
|
||||
}
|
||||
}
|
||||
for(vp=top; vp; vp = vpnext)
|
||||
{
|
||||
vpnext = vp->un.next;
|
||||
free((void*)vp);
|
||||
}
|
||||
dtclose(ep->dt);
|
||||
}
|
|
@ -1911,10 +1911,6 @@ static void env_init(Shell_t *shp)
|
|||
char *dp,*next=0;
|
||||
int nenv=0,k=0,size=0;
|
||||
Namval_t *np0;
|
||||
#ifdef _ENV_H
|
||||
shp->env = env_open(environ,3);
|
||||
env_delete(shp->env,"_");
|
||||
#endif
|
||||
if(!ep)
|
||||
goto skip;
|
||||
while(*ep++)
|
||||
|
@ -2008,9 +2004,6 @@ static void env_init(Shell_t *shp)
|
|||
cp += 2;
|
||||
}
|
||||
skip:
|
||||
#ifdef _ENV_H
|
||||
env_delete(shp->env,e_envmarker);
|
||||
#endif
|
||||
if(nv_isnull(PWDNOD) || nv_isattr(PWDNOD,NV_TAGGED))
|
||||
{
|
||||
nv_offattr(PWDNOD,NV_TAGGED);
|
||||
|
|
|
@ -59,10 +59,8 @@ pathnative(const char* path, char* buf, size_t siz)
|
|||
#endif /* _lib_pathnative */
|
||||
|
||||
static void attstore(Namval_t*,void*);
|
||||
#ifndef _ENV_H
|
||||
static void pushnam(Namval_t*,void*);
|
||||
static char *staknam(Namval_t*, char*);
|
||||
#endif
|
||||
static void pushnam(Namval_t*,void*);
|
||||
static char *staknam(Namval_t*, char*);
|
||||
static void rightjust(char*, int, int);
|
||||
static char *lastdot(char*, int);
|
||||
|
||||
|
@ -109,9 +107,7 @@ struct adata
|
|||
#endif
|
||||
|
||||
char nv_local = 0;
|
||||
#ifndef _ENV_H
|
||||
static void(*nullscan)(Namval_t*,void*);
|
||||
#endif
|
||||
|
||||
#if ( SFIO_VERSION <= 20010201L )
|
||||
# define _data data
|
||||
|
@ -137,29 +133,6 @@ static char *getbuf(size_t len)
|
|||
return(buf);
|
||||
}
|
||||
|
||||
#ifdef _ENV_H
|
||||
void sh_envput(Env_t* ep,Namval_t *np)
|
||||
{
|
||||
int offset = staktell();
|
||||
Namarr_t *ap = nv_arrayptr(np);
|
||||
char *val;
|
||||
if(ap)
|
||||
{
|
||||
if(ap->nelem&ARRAY_UNDEF)
|
||||
nv_putsub(np,"0",0L);
|
||||
else if(!(val=nv_getsub(np)) || strcmp(val,"0"))
|
||||
return;
|
||||
}
|
||||
if(!(val = nv_getval(np)))
|
||||
return;
|
||||
stakputs(nv_name(np));
|
||||
stakputc('=');
|
||||
stakputs(val);
|
||||
stakseek(offset);
|
||||
env_add(ep,stakptr(offset),ENV_STRDUP);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* output variable name in format for re-input
|
||||
*/
|
||||
|
@ -2120,7 +2093,6 @@ static void rightjust(char *str, int size, int fill)
|
|||
}
|
||||
#endif /* SHOPT_MULTIBYTE */
|
||||
|
||||
#ifndef _ENV_H
|
||||
static char *staknam(register Namval_t *np, char *value)
|
||||
{
|
||||
register char *p,*q;
|
||||
|
@ -2133,35 +2105,10 @@ static char *staknam(register Namval_t *np, char *value)
|
|||
}
|
||||
return(q);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* put the name and attribute into value of attributes variable
|
||||
*/
|
||||
#ifdef _ENV_H
|
||||
static void attstore(register Namval_t *np, void *data)
|
||||
{
|
||||
register int flag, c = ' ';
|
||||
NOT_USED(data);
|
||||
if(!(nv_isattr(np,NV_EXPORT)))
|
||||
return;
|
||||
flag = nv_isattr(np,NV_RDONLY|NV_UTOL|NV_LTOU|NV_RJUST|NV_LJUST|NV_ZFILL|NV_INTEGER);
|
||||
stakputc('=');
|
||||
if((flag&NV_DOUBLE) == NV_DOUBLE)
|
||||
{
|
||||
/* export doubles as integers for ksh88 compatibility */
|
||||
stakputc(c+NV_INTEGER|(flag&~(NV_DOUBLE|NV_EXPNOTE)));
|
||||
}
|
||||
else
|
||||
{
|
||||
stakputc(c+flag);
|
||||
if(flag&NV_INTEGER)
|
||||
c += nv_size(np);
|
||||
}
|
||||
stakputc(c);
|
||||
stakputs(nv_name(np));
|
||||
}
|
||||
#else
|
||||
static void attstore(register Namval_t *np, void *data)
|
||||
{
|
||||
register int flag = np->nvflag;
|
||||
|
@ -2194,9 +2141,7 @@ static void attstore(register Namval_t *np, void *data)
|
|||
}
|
||||
ap->attval = strcopy(++ap->attval,nv_name(np));
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef _ENV_H
|
||||
static void pushnam(Namval_t *np, void *data)
|
||||
{
|
||||
register char *value;
|
||||
|
@ -2210,31 +2155,11 @@ static void pushnam(Namval_t *np, void *data)
|
|||
if(nv_isattr(np,NV_RDONLY|NV_UTOL|NV_LTOU|NV_RJUST|NV_LJUST|NV_ZFILL|NV_INTEGER))
|
||||
ap->attsize += (strlen(nv_name(np))+4);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Generate the environment list for the child.
|
||||
*/
|
||||
|
||||
#ifdef _ENV_H
|
||||
char **sh_envgen(void)
|
||||
{
|
||||
Shell_t *shp = sh_getinterp();
|
||||
int offset,tell;
|
||||
register char **er;
|
||||
env_delete(shp->env,"_");
|
||||
er = env_get(shp->env);
|
||||
offset = staktell();
|
||||
stakputs(e_envmarker);
|
||||
tell = staktell();
|
||||
nv_scan(shp->var_tree, attstore,(void*)0,0,(NV_RDONLY|NV_UTOL|NV_LTOU|NV_RJUST|NV_LJUST|NV_ZFILL|NV_INTEGER));
|
||||
if(tell ==staktell())
|
||||
stakseek(offset);
|
||||
else
|
||||
*--er = stakfreeze(1)+offset;
|
||||
return(er);
|
||||
}
|
||||
#else
|
||||
char **sh_envgen(void)
|
||||
{
|
||||
register char **er;
|
||||
|
@ -2264,7 +2189,6 @@ char **sh_envgen(void)
|
|||
*data.argnam = 0;
|
||||
return(er);
|
||||
}
|
||||
#endif
|
||||
|
||||
struct scan
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue