var.h revision 159632
1275988Sngie/*-
2240116Smarcel * Copyright (c) 1991, 1993
3240116Smarcel *	The Regents of the University of California.  All rights reserved.
4240116Smarcel *
5240116Smarcel * This code is derived from software contributed to Berkeley by
6240116Smarcel * Kenneth Almquist.
7240116Smarcel *
8240116Smarcel * Redistribution and use in source and binary forms, with or without
9240116Smarcel * modification, are permitted provided that the following conditions
10240116Smarcel * are met:
11240116Smarcel * 1. Redistributions of source code must retain the above copyright
12240116Smarcel *    notice, this list of conditions and the following disclaimer.
13240116Smarcel * 2. Redistributions in binary form must reproduce the above copyright
14240116Smarcel *    notice, this list of conditions and the following disclaimer in the
15240116Smarcel *    documentation and/or other materials provided with the distribution.
16240116Smarcel * 4. Neither the name of the University nor the names of its contributors
17240116Smarcel *    may be used to endorse or promote products derived from this software
18240116Smarcel *    without specific prior written permission.
19240116Smarcel *
20240116Smarcel * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21240116Smarcel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22240116Smarcel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23240116Smarcel * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24275988Sngie * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25240116Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26275988Sngie * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27275988Sngie * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28240116Smarcel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29240116Smarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30240116Smarcel * SUCH DAMAGE.
31275988Sngie *
32275988Sngie *	@(#)var.h	8.2 (Berkeley) 5/4/95
33275988Sngie * $FreeBSD: head/bin/sh/var.h 159632 2006-06-15 07:00:49Z stefanf $
34240116Smarcel */
35240116Smarcel
36240116Smarcel/*
37240116Smarcel * Shell variables.
38240116Smarcel */
39240116Smarcel
40240116Smarcel/* flags */
41240116Smarcel#define VEXPORT		0x01	/* variable is exported */
42275988Sngie#define VREADONLY	0x02	/* variable cannot be modified */
43240116Smarcel#define VSTRFIXED	0x04	/* variable struct is statically allocated */
44240116Smarcel#define VTEXTFIXED	0x08	/* text is statically allocated */
45240116Smarcel#define VSTACK		0x10	/* text is allocated on the stack */
46240116Smarcel#define VUNSET		0x20	/* the variable is not set */
47275988Sngie#define VNOFUNC		0x40	/* don't call the callback function */
48275988Sngie
49240116Smarcel
50240116Smarcelstruct var {
51240116Smarcel	struct var *next;		/* next entry in hash list */
52240116Smarcel	int flags;			/* flags are defined above */
53240116Smarcel	char *text;			/* name=value */
54240116Smarcel	void (*func)(const char *);
55240116Smarcel					/* function to be called when  */
56240116Smarcel					/* the variable gets set/unset */
57240116Smarcel};
58240116Smarcel
59240116Smarcel
60240116Smarcelstruct localvar {
61240116Smarcel	struct localvar *next;		/* next local variable in list */
62240116Smarcel	struct var *vp;			/* the variable that was made local */
63240116Smarcel	int flags;			/* saved flags */
64240116Smarcel	char *text;			/* saved text */
65240116Smarcel};
66240116Smarcel
67240116Smarcel
68240116Smarcelstruct localvar *localvars;
69240116Smarcel
70240116Smarcelextern struct var vifs;
71240116Smarcelextern struct var vmail;
72240116Smarcelextern struct var vmpath;
73240116Smarcelextern struct var vpath;
74240116Smarcelextern struct var vppid;
75240116Smarcelextern struct var vps1;
76240116Smarcelextern struct var vps2;
77240116Smarcelextern struct var vps4;
78240116Smarcel#ifndef NO_HISTORY
79240116Smarcelextern struct var vhistsize;
80240116Smarcel#endif
81240116Smarcel
82240116Smarcel/*
83240116Smarcel * The following macros access the values of the above variables.
84240116Smarcel * They have to skip over the name.  They return the null string
85240116Smarcel * for unset variables.
86240116Smarcel */
87240116Smarcel
88240116Smarcel#define ifsval()	(vifs.text + 4)
89240116Smarcel#define ifsset()	((vifs.flags & VUNSET) == 0)
90240116Smarcel#define mailval()	(vmail.text + 5)
91240116Smarcel#define mpathval()	(vmpath.text + 9)
92240116Smarcel#define pathval()	(vpath.text + 5)
93240116Smarcel#define ps1val()	(vps1.text + 4)
94240116Smarcel#define ps2val()	(vps2.text + 4)
95240116Smarcel#define ps4val()	(vps4.text + 4)
96240116Smarcel#define optindval()	(voptind.text + 7)
97240116Smarcel#ifndef NO_HISTORY
98240116Smarcel#define histsizeval()	(vhistsize.text + 9)
99240116Smarcel#endif
100240116Smarcel
101240116Smarcel#define mpathset()	((vmpath.flags & VUNSET) == 0)
102240116Smarcel
103240116Smarcelvoid initvar(void);
104240116Smarcelvoid setvar(char *, char *, int);
105240116Smarcelvoid setvareq(char *, int);
106240116Smarcelstruct strlist;
107240116Smarcelvoid listsetvar(struct strlist *);
108240116Smarcelchar *lookupvar(char *);
109240116Smarcelchar *bltinlookup(char *, int);
110240116Smarcelchar **environment(void);
111240116Smarcelvoid shprocvar(void);
112240116Smarcelint showvarscmd(int, char **);
113240116Smarcelint exportcmd(int, char **);
114240116Smarcelint localcmd(int, char **);
115240116Smarcelvoid mklocal(char *);
116240116Smarcelvoid poplocalvars(void);
117240116Smarcelint setvarcmd(int, char **);
118240116Smarcelint unsetcmd(int, char **);
119240116Smarcelint unsetvar(char *);
120240116Smarcelint setvarsafe(char *, char *, int);
121240116Smarcel