var.h revision 225736
121259Swollman/*-
221259Swollman * Copyright (c) 1991, 1993
321259Swollman *	The Regents of the University of California.  All rights reserved.
421259Swollman *
521259Swollman * This code is derived from software contributed to Berkeley by
621259Swollman * Kenneth Almquist.
721259Swollman *
821259Swollman * Redistribution and use in source and binary forms, with or without
921259Swollman * modification, are permitted provided that the following conditions
1021259Swollman * are met:
1121259Swollman * 1. Redistributions of source code must retain the above copyright
1221259Swollman *    notice, this list of conditions and the following disclaimer.
1321259Swollman * 2. Redistributions in binary form must reproduce the above copyright
1421259Swollman *    notice, this list of conditions and the following disclaimer in the
1521259Swollman *    documentation and/or other materials provided with the distribution.
1621259Swollman * 4. Neither the name of the University nor the names of its contributors
1721259Swollman *    may be used to endorse or promote products derived from this software
1821259Swollman *    without specific prior written permission.
1921259Swollman *
2021259Swollman * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2121259Swollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2221259Swollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2321259Swollman * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2421259Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2521259Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2621259Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2721259Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2821259Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2921259Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3021259Swollman * SUCH DAMAGE.
3121259Swollman *
3221259Swollman *	@(#)var.h	8.2 (Berkeley) 5/4/95
3321259Swollman * $FreeBSD: stable/9/bin/sh/var.h 223060 2011-06-13 21:03:27Z jilles $
3450477Speter */
3521259Swollman
3621259Swollman/*
3721259Swollman * Shell variables.
3821259Swollman */
3921259Swollman
4021259Swollman/* flags */
4121259Swollman#define VEXPORT		0x01	/* variable is exported */
4221259Swollman#define VREADONLY	0x02	/* variable cannot be modified */
4321259Swollman#define VSTRFIXED	0x04	/* variable struct is statically allocated */
4421259Swollman#define VTEXTFIXED	0x08	/* text is statically allocated */
4521259Swollman#define VSTACK		0x10	/* text is allocated on the stack */
4621259Swollman#define VUNSET		0x20	/* the variable is not set */
4721259Swollman#define VNOFUNC		0x40	/* don't call the callback function */
4821259Swollman#define VNOSET		0x80	/* do not set variable - just readonly test */
4921259Swollman#define VNOLOCAL	0x100	/* ignore forcelocal */
5021259Swollman
5121259Swollman
5221259Swollmanstruct var {
5321259Swollman	struct var *next;		/* next entry in hash list */
5421259Swollman	int flags;			/* flags are defined above */
5521259Swollman	int name_len;			/* length of name */
5621259Swollman	char *text;			/* name=value */
5721259Swollman	void (*func)(const char *);
5821259Swollman					/* function to be called when  */
5921259Swollman					/* the variable gets set/unset */
6021259Swollman};
6121259Swollman
6221259Swollman
6321259Swollmanstruct localvar {
6421259Swollman	struct localvar *next;		/* next local variable in list */
6521259Swollman	struct var *vp;			/* the variable that was made local */
6621259Swollman	int flags;			/* saved flags */
6721259Swollman	char *text;			/* saved text */
6821259Swollman};
6921259Swollman
7083366Sjulian
7121259Swollmanstruct localvar *localvars;
7285074Sruextern int forcelocal;
7321259Swollman
7421259Swollmanextern struct var vifs;
7521259Swollmanextern struct var vmail;
7621259Swollmanextern struct var vmpath;
77101849Srwatsonextern struct var vpath;
7821259Swollmanextern struct var vppid;
7921259Swollmanextern struct var vps1;
8069224Sjlemonextern struct var vps2;
8169152Sjlemonextern struct var vps4;
8269224Sjlemon#ifndef NO_HISTORY
8374914Sjhbextern struct var vhistsize;
8474914Sjhbextern struct var vterm;
8583130Sjlemon#endif
8669152Sjlemon
8760938Sjakeextern int localeisutf8;
8860938Sjake/* The parser uses the locale that was in effect at startup. */
8960938Sjakeextern int initial_localeisutf8;
9072084Sphk
9121259Swollman/*
9221259Swollman * The following macros access the values of the above variables.
9321259Swollman * They have to skip over the name.  They return the null string
9421259Swollman * for unset variables.
9521259Swollman */
9621259Swollman
9721259Swollman#define ifsval()	(vifs.text + 4)
9821259Swollman#define ifsset()	((vifs.flags & VUNSET) == 0)
9921259Swollman#define mailval()	(vmail.text + 5)
10021259Swollman#define mpathval()	(vmpath.text + 9)
10169152Sjlemon#define pathval()	(vpath.text + 5)
10221259Swollman#define ps1val()	(vps1.text + 4)
10321259Swollman#define ps2val()	(vps2.text + 4)
10421259Swollman#define ps4val()	(vps4.text + 4)
10521259Swollman#define optindval()	(voptind.text + 7)
10621259Swollman#ifndef NO_HISTORY
10721259Swollman#define histsizeval()	(vhistsize.text + 9)
10821259Swollman#define termval()	(vterm.text + 5)
10984380Smjacob#endif
11084380Smjacob
11184380Smjacob#define mpathset()	((vmpath.flags & VUNSET) == 0)
11284380Smjacob
11386797Sluigivoid initvar(void);
11486797Sluigivoid setvar(const char *, const char *, int);
11586797Sluigivoid setvareq(char *, int);
11686797Sluigistruct strlist;
11786797Sluigivoid listsetvar(struct strlist *, int);
11886797Sluigichar *lookupvar(const char *);
11986797Sluigichar *bltinlookup(const char *, int);
12086797Sluigivoid bltinsetlocale(void);
12186797Sluigivoid bltinunsetlocale(void);
12286797Sluigivoid updatecharset(void);
12386797Sluigivoid initcharset(void);
12486797Sluigichar **environment(void);
12586797Sluigiint showvarscmd(int, char **);
12686797Sluigivoid mklocal(char *);
12786797Sluigivoid poplocalvars(void);
12884380Smjacobint unsetvar(const char *);
12921259Swollmanint setvarsafe(const char *, const char *, int);
13021259Swollman