var.h revision 50471
11556Srgrimes/*- 21556Srgrimes * Copyright (c) 1991, 1993 31556Srgrimes * The Regents of the University of California. All rights reserved. 41556Srgrimes * 51556Srgrimes * This code is derived from software contributed to Berkeley by 61556Srgrimes * Kenneth Almquist. 71556Srgrimes * 81556Srgrimes * Redistribution and use in source and binary forms, with or without 91556Srgrimes * modification, are permitted provided that the following conditions 101556Srgrimes * are met: 111556Srgrimes * 1. Redistributions of source code must retain the above copyright 121556Srgrimes * notice, this list of conditions and the following disclaimer. 131556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 141556Srgrimes * notice, this list of conditions and the following disclaimer in the 151556Srgrimes * documentation and/or other materials provided with the distribution. 161556Srgrimes * 3. All advertising materials mentioning features or use of this software 171556Srgrimes * must display the following acknowledgement: 181556Srgrimes * This product includes software developed by the University of 191556Srgrimes * California, Berkeley and its contributors. 201556Srgrimes * 4. Neither the name of the University nor the names of its contributors 211556Srgrimes * may be used to endorse or promote products derived from this software 221556Srgrimes * without specific prior written permission. 231556Srgrimes * 241556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 251556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 261556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 271556Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 281556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 291556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 301556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 311556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 321556Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 331556Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 341556Srgrimes * SUCH DAMAGE. 351556Srgrimes * 3617987Speter * @(#)var.h 8.2 (Berkeley) 5/4/95 3750471Speter * $FreeBSD: head/bin/sh/var.h 50471 1999-08-27 23:15:48Z peter $ 381556Srgrimes */ 391556Srgrimes 401556Srgrimes/* 411556Srgrimes * Shell variables. 421556Srgrimes */ 431556Srgrimes 441556Srgrimes/* flags */ 4520425Ssteve#define VEXPORT 0x01 /* variable is exported */ 4620425Ssteve#define VREADONLY 0x02 /* variable cannot be modified */ 4720425Ssteve#define VSTRFIXED 0x04 /* variable struct is staticly allocated */ 4820425Ssteve#define VTEXTFIXED 0x08 /* text is staticly allocated */ 4920425Ssteve#define VSTACK 0x10 /* text is allocated on the stack */ 5020425Ssteve#define VUNSET 0x20 /* the variable is not set */ 5120425Ssteve#define VNOFUNC 0x40 /* don't call the callback function */ 521556Srgrimes 531556Srgrimes 541556Srgrimesstruct var { 551556Srgrimes struct var *next; /* next entry in hash list */ 5620425Ssteve int flags; /* flags are defined above */ 5720425Ssteve char *text; /* name=value */ 5820425Ssteve void (*func) __P((const char *)); 5920425Ssteve /* function to be called when */ 6020425Ssteve /* the variable gets set/unset */ 611556Srgrimes}; 621556Srgrimes 631556Srgrimes 641556Srgrimesstruct localvar { 6520425Ssteve struct localvar *next; /* next local variable in list */ 6620425Ssteve struct var *vp; /* the variable that was made local */ 6720425Ssteve int flags; /* saved flags */ 6820425Ssteve char *text; /* saved text */ 691556Srgrimes}; 701556Srgrimes 711556Srgrimes 721556Srgrimesstruct localvar *localvars; 731556Srgrimes 741556Srgrimes#if ATTY 751556Srgrimesextern struct var vatty; 761556Srgrimes#endif 771556Srgrimesextern struct var vifs; 781556Srgrimesextern struct var vmail; 791556Srgrimesextern struct var vmpath; 801556Srgrimesextern struct var vpath; 811556Srgrimesextern struct var vps1; 821556Srgrimesextern struct var vps2; 831556Srgrimes#if ATTY 841556Srgrimesextern struct var vterm; 851556Srgrimes#endif 8620425Ssteve#ifndef NO_HISTORY 8720425Ssteveextern struct var vhistsize; 8820425Ssteve#endif 891556Srgrimes 901556Srgrimes/* 911556Srgrimes * The following macros access the values of the above variables. 921556Srgrimes * They have to skip over the name. They return the null string 931556Srgrimes * for unset variables. 941556Srgrimes */ 951556Srgrimes 961556Srgrimes#define ifsval() (vifs.text + 4) 9738887Stegge#define ifsset() ((vifs.flags & VUNSET) == 0) 981556Srgrimes#define mailval() (vmail.text + 5) 991556Srgrimes#define mpathval() (vmpath.text + 9) 1001556Srgrimes#define pathval() (vpath.text + 5) 1011556Srgrimes#define ps1val() (vps1.text + 4) 1021556Srgrimes#define ps2val() (vps2.text + 4) 1031556Srgrimes#if ATTY 1041556Srgrimes#define termval() (vterm.text + 5) 1051556Srgrimes#endif 10620425Ssteve#define optindval() (voptind.text + 7) 10720425Ssteve#ifndef NO_HISTORY 10820425Ssteve#define histsizeval() (vhistsize.text + 9) 10920425Ssteve#endif 1101556Srgrimes 1111556Srgrimes#if ATTY 1121556Srgrimes#define attyset() ((vatty.flags & VUNSET) == 0) 1131556Srgrimes#endif 1141556Srgrimes#define mpathset() ((vmpath.flags & VUNSET) == 0) 1151556Srgrimes 11617987Spetervoid initvar __P((void)); 11717987Spetervoid setvar __P((char *, char *, int)); 11817987Spetervoid setvareq __P((char *, int)); 1191556Srgrimesstruct strlist; 12020425Sstevevoid listsetvar __P((struct strlist *)); 12117987Speterchar *lookupvar __P((char *)); 12217987Speterchar *bltinlookup __P((char *, int)); 12317987Speterchar **environment __P((void)); 12417987Spetervoid shprocvar __P((void)); 12517987Speterint showvarscmd __P((int, char **)); 12617987Speterint exportcmd __P((int, char **)); 12717987Speterint localcmd __P((int, char **)); 12820425Sstevevoid mklocal __P((char *)); 12917987Spetervoid poplocalvars __P((void)); 13017987Speterint setvarcmd __P((int, char **)); 13117987Speterint unsetcmd __P((int, char **)); 13220425Ssteveint unsetvar __P((char *)); 13320425Ssteveint setvarsafe __P((char *, char *, int)); 134