xref: /freebsd/bin/sh/var.h (revision 8a16b7a18f5d0b031f09832fd7752fba717e2a97)
14b88c807SRodney W. Grimes /*-
2*8a16b7a1SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
3*8a16b7a1SPedro F. Giffuni  *
44b88c807SRodney W. Grimes  * Copyright (c) 1991, 1993
54b88c807SRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
64b88c807SRodney W. Grimes  *
74b88c807SRodney W. Grimes  * This code is derived from software contributed to Berkeley by
84b88c807SRodney W. Grimes  * Kenneth Almquist.
94b88c807SRodney W. Grimes  *
104b88c807SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
114b88c807SRodney W. Grimes  * modification, are permitted provided that the following conditions
124b88c807SRodney W. Grimes  * are met:
134b88c807SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
144b88c807SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
154b88c807SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
164b88c807SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
174b88c807SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
18fbbd9655SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
194b88c807SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
204b88c807SRodney W. Grimes  *    without specific prior written permission.
214b88c807SRodney W. Grimes  *
224b88c807SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
234b88c807SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
244b88c807SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
254b88c807SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
264b88c807SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
274b88c807SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
284b88c807SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
294b88c807SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
304b88c807SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
314b88c807SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
324b88c807SRodney W. Grimes  * SUCH DAMAGE.
334b88c807SRodney W. Grimes  *
34aa9caaf6SPeter Wemm  *	@(#)var.h	8.2 (Berkeley) 5/4/95
352a456239SPeter Wemm  * $FreeBSD$
364b88c807SRodney W. Grimes  */
374b88c807SRodney W. Grimes 
384b88c807SRodney W. Grimes /*
394b88c807SRodney W. Grimes  * Shell variables.
404b88c807SRodney W. Grimes  */
414b88c807SRodney W. Grimes 
424b88c807SRodney W. Grimes /* flags */
43ab0a2172SSteve Price #define VEXPORT		0x01	/* variable is exported */
44ab0a2172SSteve Price #define VREADONLY	0x02	/* variable cannot be modified */
45bbb2cc80SJens Schweikhardt #define VSTRFIXED	0x04	/* variable struct is statically allocated */
46bbb2cc80SJens Schweikhardt #define VTEXTFIXED	0x08	/* text is statically allocated */
47ab0a2172SSteve Price #define VSTACK		0x10	/* text is allocated on the stack */
48ab0a2172SSteve Price #define VUNSET		0x20	/* the variable is not set */
49ab0a2172SSteve Price #define VNOFUNC		0x40	/* don't call the callback function */
50850460c0SJilles Tjoelker #define VNOSET		0x80	/* do not set variable - just readonly test */
51c543e1aeSJilles Tjoelker #define VNOLOCAL	0x100	/* ignore forcelocal */
524b88c807SRodney W. Grimes 
534b88c807SRodney W. Grimes 
544b88c807SRodney W. Grimes struct var {
554b88c807SRodney W. Grimes 	struct var *next;		/* next entry in hash list */
564b88c807SRodney W. Grimes 	int flags;			/* flags are defined above */
573a99ed46SJilles Tjoelker 	int name_len;			/* length of name */
584b88c807SRodney W. Grimes 	char *text;			/* name=value */
595134c3f7SWarner Losh 	void (*func)(const char *);
60ab0a2172SSteve Price 					/* function to be called when  */
61ab0a2172SSteve Price 					/* the variable gets set/unset */
624b88c807SRodney W. Grimes };
634b88c807SRodney W. Grimes 
644b88c807SRodney W. Grimes 
654b88c807SRodney W. Grimes struct localvar {
664b88c807SRodney W. Grimes 	struct localvar *next;		/* next local variable in list */
674b88c807SRodney W. Grimes 	struct var *vp;			/* the variable that was made local */
684b88c807SRodney W. Grimes 	int flags;			/* saved flags */
694b88c807SRodney W. Grimes 	char *text;			/* saved text */
704b88c807SRodney W. Grimes };
714b88c807SRodney W. Grimes 
724b88c807SRodney W. Grimes 
7358bdb076SJilles Tjoelker extern struct localvar *localvars;
74c543e1aeSJilles Tjoelker extern int forcelocal;
754b88c807SRodney W. Grimes 
764b88c807SRodney W. Grimes extern struct var vifs;
774b88c807SRodney W. Grimes extern struct var vmail;
784b88c807SRodney W. Grimes extern struct var vmpath;
794b88c807SRodney W. Grimes extern struct var vpath;
804b88c807SRodney W. Grimes extern struct var vps1;
814b88c807SRodney W. Grimes extern struct var vps2;
82120c8e6cSStefan Farfeleder extern struct var vps4;
83caf29fabSJilles Tjoelker extern struct var vdisvfork;
84ab0a2172SSteve Price #ifndef NO_HISTORY
85ab0a2172SSteve Price extern struct var vhistsize;
86580eefdfSJilles Tjoelker extern struct var vterm;
87ab0a2172SSteve Price #endif
884b88c807SRodney W. Grimes 
896ed74a0aSJilles Tjoelker extern int localeisutf8;
9007eb7033SJilles Tjoelker /* The parser uses the locale that was in effect at startup. */
9107eb7033SJilles Tjoelker extern int initial_localeisutf8;
926ed74a0aSJilles Tjoelker 
934b88c807SRodney W. Grimes /*
944b88c807SRodney W. Grimes  * The following macros access the values of the above variables.
954b88c807SRodney W. Grimes  * They have to skip over the name.  They return the null string
964b88c807SRodney W. Grimes  * for unset variables.
974b88c807SRodney W. Grimes  */
984b88c807SRodney W. Grimes 
994b88c807SRodney W. Grimes #define ifsval()	(vifs.text + 4)
1006f47734fSTor Egge #define ifsset()	((vifs.flags & VUNSET) == 0)
1014b88c807SRodney W. Grimes #define mailval()	(vmail.text + 5)
1024b88c807SRodney W. Grimes #define mpathval()	(vmpath.text + 9)
1034b88c807SRodney W. Grimes #define pathval()	(vpath.text + 5)
1044b88c807SRodney W. Grimes #define ps1val()	(vps1.text + 4)
1054b88c807SRodney W. Grimes #define ps2val()	(vps2.text + 4)
106120c8e6cSStefan Farfeleder #define ps4val()	(vps4.text + 4)
107ab0a2172SSteve Price #define optindval()	(voptind.text + 7)
108ab0a2172SSteve Price #ifndef NO_HISTORY
109ab0a2172SSteve Price #define histsizeval()	(vhistsize.text + 9)
110580eefdfSJilles Tjoelker #define termval()	(vterm.text + 5)
111ab0a2172SSteve Price #endif
1124b88c807SRodney W. Grimes 
1134b88c807SRodney W. Grimes #define mpathset()	((vmpath.flags & VUNSET) == 0)
114caf29fabSJilles Tjoelker #define disvforkset()	((vdisvfork.flags & VUNSET) == 0)
1154b88c807SRodney W. Grimes 
1165134c3f7SWarner Losh void initvar(void);
1172cac6e36SJilles Tjoelker void setvar(const char *, const char *, int);
1185134c3f7SWarner Losh void setvareq(char *, int);
1198ef0ae8aSJilles Tjoelker struct arglist;
1208ef0ae8aSJilles Tjoelker void listsetvar(struct arglist *, int);
1212cac6e36SJilles Tjoelker char *lookupvar(const char *);
1222cac6e36SJilles Tjoelker char *bltinlookup(const char *, int);
123e4b50334SJilles Tjoelker void bltinsetlocale(void);
124e4b50334SJilles Tjoelker void bltinunsetlocale(void);
1256ed74a0aSJilles Tjoelker void updatecharset(void);
12607eb7033SJilles Tjoelker void initcharset(void);
1275134c3f7SWarner Losh char **environment(void);
1285134c3f7SWarner Losh int showvarscmd(int, char **);
1295134c3f7SWarner Losh void mklocal(char *);
1305134c3f7SWarner Losh void poplocalvars(void);
1312cac6e36SJilles Tjoelker int unsetvar(const char *);
1322cac6e36SJilles Tjoelker int setvarsafe(const char *, const char *, int);
133