var.h revision 21673
1139825Simp/*-
21541Srgrimes * Copyright (c) 1991, 1993
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * This code is derived from software contributed to Berkeley by
61541Srgrimes * Kenneth Almquist.
71541Srgrimes *
81541Srgrimes * Redistribution and use in source and binary forms, with or without
91541Srgrimes * modification, are permitted provided that the following conditions
101541Srgrimes * are met:
111541Srgrimes * 1. Redistributions of source code must retain the above copyright
121541Srgrimes *    notice, this list of conditions and the following disclaimer.
131541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
141541Srgrimes *    notice, this list of conditions and the following disclaimer in the
151541Srgrimes *    documentation and/or other materials provided with the distribution.
161541Srgrimes * 3. All advertising materials mentioning features or use of this software
171541Srgrimes *    must display the following acknowledgement:
181541Srgrimes *	This product includes software developed by the University of
191541Srgrimes *	California, Berkeley and its contributors.
201541Srgrimes * 4. Neither the name of the University nor the names of its contributors
211541Srgrimes *    may be used to endorse or promote products derived from this software
221541Srgrimes *    without specific prior written permission.
231541Srgrimes *
241541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
251541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
261541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
271541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
281541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
291541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
301541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
311541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
321541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
331541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
341549Srgrimes * SUCH DAMAGE.
351541Srgrimes *
361541Srgrimes *	@(#)var.h	8.2 (Berkeley) 5/4/95
37116226Sobrien *	$FreeBSD: head/bin/sh/var.h 21673 1997-01-14 07:20:47Z jkh $
38116226Sobrien */
39116226Sobrien
401541Srgrimes/*
411541Srgrimes * Shell variables.
421541Srgrimes */
4376166Smarkm
4479224Sdillon/* flags */
4576166Smarkm#define VEXPORT		0x01	/* variable is exported */
461541Srgrimes#define VREADONLY	0x02	/* variable cannot be modified */
4775675Salfred#define VSTRFIXED	0x04	/* variable struct is staticly allocated */
481541Srgrimes#define VTEXTFIXED	0x08	/* text is staticly allocated */
491541Srgrimes#define VSTACK		0x10	/* text is allocated on the stack */
50240238Skib#define VUNSET		0x20	/* the variable is not set */
5112662Sdg#define VNOFUNC		0x40	/* don't call the callback function */
521541Srgrimes
539507Sdg
5492748Sjeffstruct var {
551541Srgrimes	struct var *next;		/* next entry in hash list */
5692727Salfred	int flags;			/* flags are defined above */
5792727Salfred	char *text;			/* name=value */
58194766Skib	void (*func) __P((const char *));
5992727Salfred					/* function to be called when  */
6092727Salfred					/* the variable gets set/unset */
6192727Salfred};
6292727Salfred
6392727Salfred
6492727Salfredstruct localvar {
65236925Skib	struct localvar *next;		/* next local variable in list */
661541Srgrimes	struct var *vp;			/* the variable that was made local */
6712820Sphk	int flags;			/* saved flags */
6812820Sphk	char *text;			/* saved text */
6975675Salfred};
7075675Salfred
7112820Sphk
721541Srgrimesstruct localvar *localvars;
73118466Sphk
74118466Sphk#if ATTY
75118466Sphkextern struct var vatty;
76118466Sphk#endif
77118466Sphkextern struct var vifs;
78118466Sphkextern struct var vmail;
791541Srgrimesextern struct var vmpath;
801541Srgrimesextern struct var vpath;
81236925Skibextern struct var vps1;
82236925Skibextern struct var vps2;
83236925Skib#if ATTY
84236925Skibextern struct var vterm;
85236925Skib#endif
86236925Skib#ifndef NO_HISTORY
87236925Skibextern struct var vhistsize;
88236925Skib#endif
89229383Skib
90229383Skib/*
91229383Skib * The following macros access the values of the above variables.
92229383Skib * They have to skip over the name.  They return the null string
93229383Skib * for unset variables.
94229383Skib */
95229383Skib
96229383Skib#define ifsval()	(vifs.text + 4)
97229383Skib#define mailval()	(vmail.text + 5)
98229383Skib#define mpathval()	(vmpath.text + 9)
99229383Skib#define pathval()	(vpath.text + 5)
100229383Skib#define ps1val()	(vps1.text + 4)
10112820Sphk#define ps2val()	(vps2.text + 4)
1021541Srgrimes#if ATTY
1031541Srgrimes#define termval()	(vterm.text + 5)
1049507Sdg#endif
10593818Sjhb#define optindval()	(voptind.text + 7)
1061541Srgrimes#ifndef NO_HISTORY
1071541Srgrimes#define histsizeval()	(vhistsize.text + 9)
108229383Skib#endif
109229383Skib
1101541Srgrimes#if ATTY
111229383Skib#define attyset()	((vatty.flags & VUNSET) == 0)
112229383Skib#endif
113229383Skib#define mpathset()	((vmpath.flags & VUNSET) == 0)
114229383Skib
115229383Skibvoid initvar __P((void));
116229383Skibvoid setvar __P((char *, char *, int));
117229383Skibvoid setvareq __P((char *, int));
118229383Skibstruct strlist;
119229383Skibvoid listsetvar __P((struct strlist *));
120229383Skibchar *lookupvar __P((char *));
121229383Skibchar *bltinlookup __P((char *, int));
122229383Skibchar **environment __P((void));
123171779Skibvoid shprocvar __P((void));
124124133Salcint showvarscmd __P((int, char **));
125229383Skibint exportcmd __P((int, char **));
1261541Srgrimesint localcmd __P((int, char **));
127236925Skibvoid mklocal __P((char *));
128229383Skibvoid poplocalvars __P((void));
129229383Skibint setvarcmd __P((int, char **));
1301541Srgrimesint unsetcmd __P((int, char **));
13198630Salcint unsetvar __P((char *));
13298630Salcint setvarsafe __P((char *, char *, int));
13398630Salc