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 * 4. Neither the name of the University nor the names of its contributors
171556Srgrimes *    may be used to endorse or promote products derived from this software
181556Srgrimes *    without specific prior written permission.
191556Srgrimes *
201556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
211556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
221556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
231556Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
241556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
251556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
261556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
271556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
281556Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
291556Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
301556Srgrimes * SUCH DAMAGE.
311556Srgrimes *
3217987Speter *	@(#)var.h	8.2 (Berkeley) 5/4/95
3350471Speter * $FreeBSD$
341556Srgrimes */
351556Srgrimes
361556Srgrimes/*
371556Srgrimes * Shell variables.
381556Srgrimes */
391556Srgrimes
401556Srgrimes/* flags */
4120425Ssteve#define VEXPORT		0x01	/* variable is exported */
4220425Ssteve#define VREADONLY	0x02	/* variable cannot be modified */
43155303Sschweikh#define VSTRFIXED	0x04	/* variable struct is statically allocated */
44155303Sschweikh#define VTEXTFIXED	0x08	/* text is statically allocated */
4520425Ssteve#define VSTACK		0x10	/* text is allocated on the stack */
4620425Ssteve#define VUNSET		0x20	/* the variable is not set */
4720425Ssteve#define VNOFUNC		0x40	/* don't call the callback function */
48216870Sjilles#define VNOSET		0x80	/* do not set variable - just readonly test */
49223024Sjilles#define VNOLOCAL	0x100	/* ignore forcelocal */
501556Srgrimes
511556Srgrimes
521556Srgrimesstruct var {
531556Srgrimes	struct var *next;		/* next entry in hash list */
5420425Ssteve	int flags;			/* flags are defined above */
55221668Sjilles	int name_len;			/* length of name */
5620425Ssteve	char *text;			/* name=value */
5790111Simp	void (*func)(const char *);
5820425Ssteve					/* function to be called when  */
5920425Ssteve					/* the variable gets set/unset */
601556Srgrimes};
611556Srgrimes
621556Srgrimes
631556Srgrimesstruct localvar {
6420425Ssteve	struct localvar *next;		/* next local variable in list */
6520425Ssteve	struct var *vp;			/* the variable that was made local */
6620425Ssteve	int flags;			/* saved flags */
6720425Ssteve	char *text;			/* saved text */
681556Srgrimes};
691556Srgrimes
701556Srgrimes
711556Srgrimesstruct localvar *localvars;
72223024Sjillesextern int forcelocal;
731556Srgrimes
741556Srgrimesextern struct var vifs;
751556Srgrimesextern struct var vmail;
761556Srgrimesextern struct var vmpath;
771556Srgrimesextern struct var vpath;
781556Srgrimesextern struct var vps1;
791556Srgrimesextern struct var vps2;
80159632Sstefanfextern struct var vps4;
81230998Sjillesextern struct var vdisvfork;
8220425Ssteve#ifndef NO_HISTORY
8320425Ssteveextern struct var vhistsize;
84208755Sjillesextern struct var vterm;
8520425Ssteve#endif
861556Srgrimes
87221559Sjillesextern int localeisutf8;
88221669Sjilles/* The parser uses the locale that was in effect at startup. */
89221669Sjillesextern int initial_localeisutf8;
90221559Sjilles
911556Srgrimes/*
921556Srgrimes * The following macros access the values of the above variables.
931556Srgrimes * They have to skip over the name.  They return the null string
941556Srgrimes * for unset variables.
951556Srgrimes */
961556Srgrimes
971556Srgrimes#define ifsval()	(vifs.text + 4)
9838887Stegge#define ifsset()	((vifs.flags & VUNSET) == 0)
991556Srgrimes#define mailval()	(vmail.text + 5)
1001556Srgrimes#define mpathval()	(vmpath.text + 9)
1011556Srgrimes#define pathval()	(vpath.text + 5)
1021556Srgrimes#define ps1val()	(vps1.text + 4)
1031556Srgrimes#define ps2val()	(vps2.text + 4)
104159632Sstefanf#define ps4val()	(vps4.text + 4)
10520425Ssteve#define optindval()	(voptind.text + 7)
10620425Ssteve#ifndef NO_HISTORY
10720425Ssteve#define histsizeval()	(vhistsize.text + 9)
108208755Sjilles#define termval()	(vterm.text + 5)
10920425Ssteve#endif
1101556Srgrimes
1111556Srgrimes#define mpathset()	((vmpath.flags & VUNSET) == 0)
112230998Sjilles#define disvforkset()	((vdisvfork.flags & VUNSET) == 0)
1131556Srgrimes
11490111Simpvoid initvar(void);
115200956Sjillesvoid setvar(const char *, const char *, int);
11690111Simpvoid setvareq(char *, int);
1171556Srgrimesstruct strlist;
118216870Sjillesvoid listsetvar(struct strlist *, int);
119200956Sjilleschar *lookupvar(const char *);
120200956Sjilleschar *bltinlookup(const char *, int);
121207678Sjillesvoid bltinsetlocale(void);
122207678Sjillesvoid bltinunsetlocale(void);
123221559Sjillesvoid updatecharset(void);
124221669Sjillesvoid initcharset(void);
12590111Simpchar **environment(void);
12690111Simpint showvarscmd(int, char **);
12790111Simpvoid mklocal(char *);
12890111Simpvoid poplocalvars(void);
129200956Sjillesint unsetvar(const char *);
130200956Sjillesint setvarsafe(const char *, const char *, int);
131