var.h revision 17987
138889Sjdp/*- 289857Sobrien * Copyright (c) 1991, 1993 338889Sjdp * The Regents of the University of California. All rights reserved. 438889Sjdp * 538889Sjdp * This code is derived from software contributed to Berkeley by 638889Sjdp * Kenneth Almquist. 738889Sjdp * 838889Sjdp * Redistribution and use in source and binary forms, with or without 938889Sjdp * modification, are permitted provided that the following conditions 1038889Sjdp * are met: 1138889Sjdp * 1. Redistributions of source code must retain the above copyright 1238889Sjdp * notice, this list of conditions and the following disclaimer. 1338889Sjdp * 2. Redistributions in binary form must reproduce the above copyright 1438889Sjdp * notice, this list of conditions and the following disclaimer in the 1538889Sjdp * documentation and/or other materials provided with the distribution. 1638889Sjdp * 3. All advertising materials mentioning features or use of this software 1738889Sjdp * must display the following acknowledgement: 1838889Sjdp * This product includes software developed by the University of 1938889Sjdp * California, Berkeley and its contributors. 2038889Sjdp * 4. Neither the name of the University nor the names of its contributors 2138889Sjdp * may be used to endorse or promote products derived from this software 2238889Sjdp * without specific prior written permission. 2338889Sjdp * 2438889Sjdp * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2538889Sjdp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2638889Sjdp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2738889Sjdp * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2838889Sjdp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2989857Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3038889Sjdp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3138889Sjdp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3238889Sjdp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3338889Sjdp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3438889Sjdp * SUCH DAMAGE. 3538889Sjdp * 3638889Sjdp * @(#)var.h 8.2 (Berkeley) 5/4/95 3738889Sjdp * $Id: var.h,v 1.2 1994/09/24 02:58:23 davidg Exp $ 3838889Sjdp */ 3938889Sjdp 4038889Sjdp/* 4138889Sjdp * Shell variables. 4238889Sjdp */ 4338889Sjdp 4438889Sjdp/* flags */ 4538889Sjdp#define VEXPORT 01 /* variable is exported */ 4638889Sjdp#define VREADONLY 02 /* variable cannot be modified */ 4738889Sjdp#define VSTRFIXED 04 /* variable struct is staticly allocated */ 4838889Sjdp#define VTEXTFIXED 010 /* text is staticly allocated */ 4938889Sjdp#define VSTACK 020 /* text is allocated on the stack */ 5038889Sjdp#define VUNSET 040 /* the variable is not set */ 5138889Sjdp 5238889Sjdp 5338889Sjdpstruct var { 5438889Sjdp struct var *next; /* next entry in hash list */ 5538889Sjdp int flags; /* flags are defined above */ 5638889Sjdp char *text; /* name=value */ 5738889Sjdp}; 5838889Sjdp 5938889Sjdp 6038889Sjdpstruct localvar { 6138889Sjdp struct localvar *next; /* next local variable in list */ 6238889Sjdp struct var *vp; /* the variable that was made local */ 6338889Sjdp int flags; /* saved flags */ 6438889Sjdp char *text; /* saved text */ 6538889Sjdp}; 6638889Sjdp 6738889Sjdp 6838889Sjdpstruct localvar *localvars; 6938889Sjdp 7038889Sjdp#if ATTY 7138889Sjdpextern struct var vatty; 7238889Sjdp#endif 7338889Sjdpextern struct var vifs; 7438889Sjdpextern struct var vmail; 7538889Sjdpextern struct var vmpath; 7638889Sjdpextern struct var vpath; 7738889Sjdpextern struct var vps1; 7838889Sjdpextern struct var vps2; 7938889Sjdp#if ATTY 8038889Sjdpextern struct var vterm; 8138889Sjdp#endif 8238889Sjdp 8338889Sjdp/* 8438889Sjdp * The following macros access the values of the above variables. 8538889Sjdp * They have to skip over the name. They return the null string 8638889Sjdp * for unset variables. 8738889Sjdp */ 8838889Sjdp 8938889Sjdp#define ifsval() (vifs.text + 4) 9038889Sjdp#define mailval() (vmail.text + 5) 9138889Sjdp#define mpathval() (vmpath.text + 9) 9238889Sjdp#define pathval() (vpath.text + 5) 9338889Sjdp#define ps1val() (vps1.text + 4) 9438889Sjdp#define ps2val() (vps2.text + 4) 9538889Sjdp#if ATTY 9638889Sjdp#define termval() (vterm.text + 5) 9738889Sjdp#endif 9838889Sjdp 9938889Sjdp#if ATTY 10038889Sjdp#define attyset() ((vatty.flags & VUNSET) == 0) 10138889Sjdp#endif 10238889Sjdp#define mpathset() ((vmpath.flags & VUNSET) == 0) 10338889Sjdp 10438889Sjdpvoid initvar __P((void)); 10538889Sjdpvoid setvar __P((char *, char *, int)); 10638889Sjdpvoid setvareq __P((char *, int)); 10738889Sjdpstruct strlist; 10838889Sjdpvoid listsetvar __P((struct strlist *)); 10938889Sjdpchar *lookupvar __P((char *)); 11038889Sjdpchar *bltinlookup __P((char *, int)); 11138889Sjdpchar **environment __P((void)); 11238889Sjdpvoid shprocvar __P((void)); 11338889Sjdpint showvarscmd __P((int, char **)); 11438889Sjdpint exportcmd __P((int, char **)); 11538889Sjdpint localcmd __P((int, char **)); 11638889Sjdpvoid mklocal __P((char *)); 11738889Sjdpvoid poplocalvars __P((void)); 11838889Sjdpint setvarcmd __P((int, char **)); 11938889Sjdpint unsetcmd __P((int, char **)); 12038889Sjdp