147148Sbostic /*- 260698Sbostic * Copyright (c) 1991, 1993 360698Sbostic * The Regents of the University of California. All rights reserved. 447148Sbostic * 547148Sbostic * This code is derived from software contributed to Berkeley by 647148Sbostic * Kenneth Almquist. 747148Sbostic * 847148Sbostic * %sccs.include.redist.c% 947148Sbostic * 10*69272Schristos * @(#)var.h 8.2 (Berkeley) 05/04/95 1147148Sbostic */ 1247148Sbostic 1347148Sbostic /* 1447148Sbostic * Shell variables. 1547148Sbostic */ 1647148Sbostic 1747148Sbostic /* flags */ 1847148Sbostic #define VEXPORT 01 /* variable is exported */ 1947148Sbostic #define VREADONLY 02 /* variable cannot be modified */ 2047148Sbostic #define VSTRFIXED 04 /* variable struct is staticly allocated */ 2147148Sbostic #define VTEXTFIXED 010 /* text is staticly allocated */ 2247148Sbostic #define VSTACK 020 /* text is allocated on the stack */ 2347148Sbostic #define VUNSET 040 /* the variable is not set */ 2447148Sbostic 2547148Sbostic 2647148Sbostic struct var { 2747148Sbostic struct var *next; /* next entry in hash list */ 2847148Sbostic int flags; /* flags are defined above */ 2947148Sbostic char *text; /* name=value */ 3047148Sbostic }; 3147148Sbostic 3247148Sbostic 3347148Sbostic struct localvar { 3447148Sbostic struct localvar *next; /* next local variable in list */ 3547148Sbostic struct var *vp; /* the variable that was made local */ 3647148Sbostic int flags; /* saved flags */ 3747148Sbostic char *text; /* saved text */ 3847148Sbostic }; 3947148Sbostic 4047148Sbostic 4147148Sbostic struct localvar *localvars; 4247148Sbostic 4347148Sbostic #if ATTY 4447148Sbostic extern struct var vatty; 4547148Sbostic #endif 4647148Sbostic extern struct var vifs; 4747148Sbostic extern struct var vmail; 4847148Sbostic extern struct var vmpath; 4947148Sbostic extern struct var vpath; 5047148Sbostic extern struct var vps1; 5147148Sbostic extern struct var vps2; 5247148Sbostic #if ATTY 5347148Sbostic extern struct var vterm; 5447148Sbostic #endif 5547148Sbostic 5647148Sbostic /* 5747148Sbostic * The following macros access the values of the above variables. 5847148Sbostic * They have to skip over the name. They return the null string 5947148Sbostic * for unset variables. 6047148Sbostic */ 6147148Sbostic 6247148Sbostic #define ifsval() (vifs.text + 4) 6347148Sbostic #define mailval() (vmail.text + 5) 6447148Sbostic #define mpathval() (vmpath.text + 9) 6547148Sbostic #define pathval() (vpath.text + 5) 6647148Sbostic #define ps1val() (vps1.text + 4) 6747148Sbostic #define ps2val() (vps2.text + 4) 6847148Sbostic #if ATTY 6947148Sbostic #define termval() (vterm.text + 5) 7047148Sbostic #endif 7147148Sbostic 7247148Sbostic #if ATTY 7347148Sbostic #define attyset() ((vatty.flags & VUNSET) == 0) 7447148Sbostic #endif 7547148Sbostic #define mpathset() ((vmpath.flags & VUNSET) == 0) 7647148Sbostic 77*69272Schristos void initvar __P((void)); 78*69272Schristos void setvar __P((char *, char *, int)); 79*69272Schristos void setvareq __P((char *, int)); 8047148Sbostic struct strlist; 81*69272Schristos void listsetvar __P((struct strlist *)); 82*69272Schristos char *lookupvar __P((char *)); 83*69272Schristos char *bltinlookup __P((char *, int)); 84*69272Schristos char **environment __P((void)); 85*69272Schristos void shprocvar __P((void)); 86*69272Schristos int showvarscmd __P((int, char **)); 87*69272Schristos int exportcmd __P((int, char **)); 88*69272Schristos int localcmd __P((int, char **)); 89*69272Schristos void mklocal __P((char *)); 90*69272Schristos void poplocalvars __P((void)); 91*69272Schristos int setvarcmd __P((int, char **)); 92*69272Schristos int unsetcmd __P((int, char **)); 93