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 */ 344b88c807SRodney W. Grimes 354b88c807SRodney W. Grimes /* 364b88c807SRodney W. Grimes * Shell variables. 374b88c807SRodney W. Grimes */ 384b88c807SRodney W. Grimes 394b88c807SRodney W. Grimes /* flags */ 40ab0a2172SSteve Price #define VEXPORT 0x01 /* variable is exported */ 41ab0a2172SSteve Price #define VREADONLY 0x02 /* variable cannot be modified */ 42bbb2cc80SJens Schweikhardt #define VSTRFIXED 0x04 /* variable struct is statically allocated */ 43bbb2cc80SJens Schweikhardt #define VTEXTFIXED 0x08 /* text is statically allocated */ 44ab0a2172SSteve Price #define VSTACK 0x10 /* text is allocated on the stack */ 45ab0a2172SSteve Price #define VUNSET 0x20 /* the variable is not set */ 46ab0a2172SSteve Price #define VNOFUNC 0x40 /* don't call the callback function */ 47850460c0SJilles Tjoelker #define VNOSET 0x80 /* do not set variable - just readonly test */ 48c543e1aeSJilles Tjoelker #define VNOLOCAL 0x100 /* ignore forcelocal */ 494b88c807SRodney W. Grimes 504b88c807SRodney W. Grimes 514b88c807SRodney W. Grimes struct var { 524b88c807SRodney W. Grimes struct var *next; /* next entry in hash list */ 534b88c807SRodney W. Grimes int flags; /* flags are defined above */ 543a99ed46SJilles Tjoelker int name_len; /* length of name */ 554b88c807SRodney W. Grimes char *text; /* name=value */ 565134c3f7SWarner Losh void (*func)(const char *); 57ab0a2172SSteve Price /* function to be called when */ 58ab0a2172SSteve Price /* the variable gets set/unset */ 594b88c807SRodney W. Grimes }; 604b88c807SRodney W. Grimes 614b88c807SRodney W. Grimes 624b88c807SRodney W. Grimes struct localvar { 634b88c807SRodney W. Grimes struct localvar *next; /* next local variable in list */ 644b88c807SRodney W. Grimes struct var *vp; /* the variable that was made local */ 654b88c807SRodney W. Grimes int flags; /* saved flags */ 664b88c807SRodney W. Grimes char *text; /* saved text */ 674b88c807SRodney W. Grimes }; 684b88c807SRodney W. Grimes 694b88c807SRodney W. Grimes 7058bdb076SJilles Tjoelker extern struct localvar *localvars; 71c543e1aeSJilles Tjoelker extern int forcelocal; 724b88c807SRodney W. Grimes 734b88c807SRodney W. Grimes extern struct var vifs; 744b88c807SRodney W. Grimes extern struct var vmail; 754b88c807SRodney W. Grimes extern struct var vmpath; 764b88c807SRodney W. Grimes extern struct var vpath; 774b88c807SRodney W. Grimes extern struct var vps1; 784b88c807SRodney W. Grimes extern struct var vps2; 79120c8e6cSStefan Farfeleder extern struct var vps4; 80caf29fabSJilles Tjoelker extern struct var vdisvfork; 81ab0a2172SSteve Price #ifndef NO_HISTORY 82ab0a2172SSteve Price extern struct var vhistsize; 83580eefdfSJilles Tjoelker extern struct var vterm; 84ab0a2172SSteve Price #endif 854b88c807SRodney W. Grimes 866ed74a0aSJilles Tjoelker extern int localeisutf8; 8707eb7033SJilles Tjoelker /* The parser uses the locale that was in effect at startup. */ 8807eb7033SJilles Tjoelker extern int initial_localeisutf8; 896ed74a0aSJilles Tjoelker 904b88c807SRodney W. Grimes /* 914b88c807SRodney W. Grimes * The following macros access the values of the above variables. 924b88c807SRodney W. Grimes * They have to skip over the name. They return the null string 934b88c807SRodney W. Grimes * for unset variables. 944b88c807SRodney W. Grimes */ 954b88c807SRodney W. Grimes 964b88c807SRodney W. Grimes #define ifsval() (vifs.text + 4) 976f47734fSTor Egge #define ifsset() ((vifs.flags & VUNSET) == 0) 984b88c807SRodney W. Grimes #define mailval() (vmail.text + 5) 994b88c807SRodney W. Grimes #define mpathval() (vmpath.text + 9) 1004b88c807SRodney W. Grimes #define pathval() (vpath.text + 5) 1014b88c807SRodney W. Grimes #define ps1val() (vps1.text + 4) 1024b88c807SRodney W. Grimes #define ps2val() (vps2.text + 4) 103120c8e6cSStefan Farfeleder #define ps4val() (vps4.text + 4) 104ab0a2172SSteve Price #define optindval() (voptind.text + 7) 105ab0a2172SSteve Price #ifndef NO_HISTORY 106ab0a2172SSteve Price #define histsizeval() (vhistsize.text + 9) 107580eefdfSJilles Tjoelker #define termval() (vterm.text + 5) 108ab0a2172SSteve Price #endif 1094b88c807SRodney W. Grimes 1104b88c807SRodney W. Grimes #define mpathset() ((vmpath.flags & VUNSET) == 0) 111caf29fabSJilles Tjoelker #define disvforkset() ((vdisvfork.flags & VUNSET) == 0) 1124b88c807SRodney W. Grimes 1135134c3f7SWarner Losh void initvar(void); 1142cac6e36SJilles Tjoelker void setvar(const char *, const char *, int); 1155134c3f7SWarner Losh void setvareq(char *, int); 1168ef0ae8aSJilles Tjoelker struct arglist; 1178ef0ae8aSJilles Tjoelker void listsetvar(struct arglist *, int); 1182cac6e36SJilles Tjoelker char *lookupvar(const char *); 1192cac6e36SJilles Tjoelker char *bltinlookup(const char *, int); 120e4b50334SJilles Tjoelker void bltinsetlocale(void); 121e4b50334SJilles Tjoelker void bltinunsetlocale(void); 1226ed74a0aSJilles Tjoelker void updatecharset(void); 12307eb7033SJilles Tjoelker void initcharset(void); 1245134c3f7SWarner Losh char **environment(void); 1255134c3f7SWarner Losh int showvarscmd(int, char **); 1265134c3f7SWarner Losh void mklocal(char *); 1275134c3f7SWarner Losh void poplocalvars(void); 1282cac6e36SJilles Tjoelker int unsetvar(const char *); 1292cac6e36SJilles Tjoelker int setvarsafe(const char *, const char *, int); 130