var.h revision 1556
1169691Skan/*- 2169691Skan * Copyright (c) 1991, 1993 3169691Skan * The Regents of the University of California. All rights reserved. 4169691Skan * 5169691Skan * This code is derived from software contributed to Berkeley by 6169691Skan * Kenneth Almquist. 7169691Skan * 8169691Skan * Redistribution and use in source and binary forms, with or without 9169691Skan * modification, are permitted provided that the following conditions 10169691Skan * are met: 11169691Skan * 1. Redistributions of source code must retain the above copyright 12169691Skan * notice, this list of conditions and the following disclaimer. 13169691Skan * 2. Redistributions in binary form must reproduce the above copyright 14169691Skan * notice, this list of conditions and the following disclaimer in the 15169691Skan * documentation and/or other materials provided with the distribution. 16169691Skan * 3. All advertising materials mentioning features or use of this software 17169691Skan * must display the following acknowledgement: 18169691Skan * This product includes software developed by the University of 19169691Skan * California, Berkeley and its contributors. 20169691Skan * 4. Neither the name of the University nor the names of its contributors 21169691Skan * may be used to endorse or promote products derived from this software 22169691Skan * without specific prior written permission. 23169691Skan * 24169691Skan * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25169691Skan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26169691Skan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27169691Skan * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28169691Skan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29169691Skan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30169691Skan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31169691Skan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32169691Skan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33169691Skan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34169691Skan * SUCH DAMAGE. 35169691Skan * 36169691Skan * @(#)var.h 8.1 (Berkeley) 5/31/93 37169691Skan */ 38169691Skan 39169691Skan/* 40169691Skan * Shell variables. 41169691Skan */ 42169691Skan 43169691Skan/* flags */ 44169691Skan#define VEXPORT 01 /* variable is exported */ 45169691Skan#define VREADONLY 02 /* variable cannot be modified */ 46169691Skan#define VSTRFIXED 04 /* variable struct is staticly allocated */ 47169691Skan#define VTEXTFIXED 010 /* text is staticly allocated */ 48169691Skan#define VSTACK 020 /* text is allocated on the stack */ 49169691Skan#define VUNSET 040 /* the variable is not set */ 50169691Skan 51169691Skan 52169691Skanstruct var { 53169691Skan struct var *next; /* next entry in hash list */ 54169691Skan int flags; /* flags are defined above */ 55169691Skan char *text; /* name=value */ 56169691Skan}; 57169691Skan 58169691Skan 59169691Skanstruct localvar { 60169691Skan struct localvar *next; /* next local variable in list */ 61169691Skan struct var *vp; /* the variable that was made local */ 62169691Skan int flags; /* saved flags */ 63169691Skan char *text; /* saved text */ 64169691Skan}; 65169691Skan 66169691Skan 67169691Skanstruct localvar *localvars; 68169691Skan 69169691Skan#if ATTY 70169691Skanextern struct var vatty; 71169691Skan#endif 72169691Skanextern struct var vifs; 73169691Skanextern struct var vmail; 74169691Skanextern struct var vmpath; 75169691Skanextern struct var vpath; 76169691Skanextern struct var vps1; 77169691Skanextern struct var vps2; 78169691Skan#if ATTY 79169691Skanextern struct var vterm; 80169691Skan#endif 81169691Skan 82169691Skan/* 83169691Skan * The following macros access the values of the above variables. 84169691Skan * They have to skip over the name. They return the null string 85169691Skan * for unset variables. 86169691Skan */ 87169691Skan 88169691Skan#define ifsval() (vifs.text + 4) 89169691Skan#define mailval() (vmail.text + 5) 90169691Skan#define mpathval() (vmpath.text + 9) 91169691Skan#define pathval() (vpath.text + 5) 92169691Skan#define ps1val() (vps1.text + 4) 93169691Skan#define ps2val() (vps2.text + 4) 94169691Skan#if ATTY 95169691Skan#define termval() (vterm.text + 5) 96169691Skan#endif 97169691Skan 98169691Skan#if ATTY 99169691Skan#define attyset() ((vatty.flags & VUNSET) == 0) 100169691Skan#endif 101169691Skan#define mpathset() ((vmpath.flags & VUNSET) == 0) 102169691Skan 103169691Skan 104169691Skan#ifdef __STDC__ 105169691Skanvoid initvar(); 106169691Skanvoid setvar(char *, char *, int); 107169691Skanvoid setvareq(char *, int); 108169691Skanstruct strlist; 109169691Skanvoid listsetvar(struct strlist *); 110169691Skanchar *lookupvar(char *); 111169691Skanchar *bltinlookup(char *, int); 112169691Skanchar **environment(); 113169691Skanint showvarscmd(int, char **); 114169691Skanvoid mklocal(char *); 115169691Skanvoid poplocalvars(void); 116169691Skan#else 117169691Skanvoid initvar(); 118169691Skanvoid setvar(); 119169691Skanvoid setvareq(); 120169691Skanvoid listsetvar(); 121169691Skanchar *lookupvar(); 122169691Skanchar *bltinlookup(); 123169691Skanchar **environment(); 124169691Skanint showvarscmd(); 125169691Skanvoid mklocal(); 126169691Skanvoid poplocalvars(); 127169691Skan#endif 128169691Skan