var.h revision 97689
1178515Srwatson/*-
2178515Srwatson * Copyright (c) 1991, 1993
3178515Srwatson *	The Regents of the University of California.  All rights reserved.
4178515Srwatson *
5178515Srwatson * This code is derived from software contributed to Berkeley by
6178515Srwatson * Kenneth Almquist.
7178515Srwatson *
8178515Srwatson * Redistribution and use in source and binary forms, with or without
9178515Srwatson * modification, are permitted provided that the following conditions
10178515Srwatson * are met:
11178515Srwatson * 1. Redistributions of source code must retain the above copyright
12178515Srwatson *    notice, this list of conditions and the following disclaimer.
13178515Srwatson * 2. Redistributions in binary form must reproduce the above copyright
14178515Srwatson *    notice, this list of conditions and the following disclaimer in the
15178515Srwatson *    documentation and/or other materials provided with the distribution.
16178515Srwatson * 3. All advertising materials mentioning features or use of this software
17178515Srwatson *    must display the following acknowledgement:
18178515Srwatson *	This product includes software developed by the University of
19178515Srwatson *	California, Berkeley and its contributors.
20178515Srwatson * 4. Neither the name of the University nor the names of its contributors
21178515Srwatson *    may be used to endorse or promote products derived from this software
22178515Srwatson *    without specific prior written permission.
23178515Srwatson *
24178515Srwatson * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25178515Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26178515Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27178515Srwatson * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28178515Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29178515Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30178515Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31178515Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32178515Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33178515Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34178515Srwatson * SUCH DAMAGE.
35178515Srwatson *
36178515Srwatson *	@(#)var.h	8.2 (Berkeley) 5/4/95
37178515Srwatson * $FreeBSD: head/bin/sh/var.h 97689 2002-06-01 02:14:48Z tjr $
38178515Srwatson */
39178515Srwatson
40178515Srwatson/*
41178515Srwatson * Shell variables.
42178515Srwatson */
43178515Srwatson
44178515Srwatson/* flags */
45178515Srwatson#define VEXPORT		0x01	/* variable is exported */
46178515Srwatson#define VREADONLY	0x02	/* variable cannot be modified */
47178515Srwatson#define VSTRFIXED	0x04	/* variable struct is staticly allocated */
48178515Srwatson#define VTEXTFIXED	0x08	/* text is staticly allocated */
49178515Srwatson#define VSTACK		0x10	/* text is allocated on the stack */
50178515Srwatson#define VUNSET		0x20	/* the variable is not set */
51178515Srwatson#define VNOFUNC		0x40	/* don't call the callback function */
52178515Srwatson
53178515Srwatson
54178515Srwatsonstruct var {
55178515Srwatson	struct var *next;		/* next entry in hash list */
56178515Srwatson	int flags;			/* flags are defined above */
57178515Srwatson	char *text;			/* name=value */
58178515Srwatson	void (*func)(const char *);
59178515Srwatson					/* function to be called when  */
60178515Srwatson					/* the variable gets set/unset */
61178515Srwatson};
62178515Srwatson
63178515Srwatson
64178515Srwatsonstruct localvar {
65178515Srwatson	struct localvar *next;		/* next local variable in list */
66178515Srwatson	struct var *vp;			/* the variable that was made local */
67178515Srwatson	int flags;			/* saved flags */
68178515Srwatson	char *text;			/* saved text */
69178515Srwatson};
70178515Srwatson
71178515Srwatson
72178515Srwatsonstruct localvar *localvars;
73178515Srwatson
74178515Srwatson#if ATTY
75178515Srwatsonextern struct var vatty;
76178515Srwatson#endif
77178515Srwatsonextern struct var vifs;
78178515Srwatsonextern struct var vmail;
79178515Srwatsonextern struct var vmpath;
80178515Srwatsonextern struct var vpath;
81178515Srwatsonextern struct var vppid;
82178515Srwatsonextern struct var vps1;
83178515Srwatsonextern struct var vps2;
84178515Srwatson#if ATTY
85178515Srwatsonextern struct var vterm;
86178515Srwatson#endif
87178515Srwatson#ifndef NO_HISTORY
88178515Srwatsonextern struct var vhistsize;
89178515Srwatson#endif
90178515Srwatson
91178515Srwatson/*
92178515Srwatson * The following macros access the values of the above variables.
93178515Srwatson * They have to skip over the name.  They return the null string
94178515Srwatson * for unset variables.
95178515Srwatson */
96178515Srwatson
97178515Srwatson#define ifsval()	(vifs.text + 4)
98178515Srwatson#define ifsset()	((vifs.flags & VUNSET) == 0)
99178515Srwatson#define mailval()	(vmail.text + 5)
100178515Srwatson#define mpathval()	(vmpath.text + 9)
101178515Srwatson#define pathval()	(vpath.text + 5)
102178515Srwatson#define ps1val()	(vps1.text + 4)
103178515Srwatson#define ps2val()	(vps2.text + 4)
104178515Srwatson#if ATTY
105178515Srwatson#define termval()	(vterm.text + 5)
106178515Srwatson#endif
107178515Srwatson#define optindval()	(voptind.text + 7)
108178515Srwatson#ifndef NO_HISTORY
109178515Srwatson#define histsizeval()	(vhistsize.text + 9)
110178515Srwatson#endif
111178515Srwatson
112178515Srwatson#if ATTY
113178515Srwatson#define attyset()	((vatty.flags & VUNSET) == 0)
114178515Srwatson#endif
115178515Srwatson#define mpathset()	((vmpath.flags & VUNSET) == 0)
116178515Srwatson
117178515Srwatsonvoid initvar(void);
118178515Srwatsonvoid setvar(char *, char *, int);
119178515Srwatsonvoid setvareq(char *, int);
120178515Srwatsonstruct strlist;
121178515Srwatsonvoid listsetvar(struct strlist *);
122178515Srwatsonchar *lookupvar(char *);
123178515Srwatsonchar *bltinlookup(char *, int);
124178515Srwatsonchar **environment(void);
125178515Srwatsonvoid shprocvar(void);
126178515Srwatsonint showvarscmd(int, char **);
127178515Srwatsonint exportcmd(int, char **);
128178515Srwatsonint localcmd(int, char **);
129178515Srwatsonvoid mklocal(char *);
130178515Srwatsonvoid poplocalvars(void);
131178515Srwatsonint setvarcmd(int, char **);
132178515Srwatsonint unsetcmd(int, char **);
133178515Srwatsonint unsetvar(char *);
134178515Srwatsonint setvarsafe(char *, char *, int);
135178515Srwatson