14b88c807SRodney W. Grimes /*- 24b88c807SRodney W. Grimes * Copyright (c) 1991, 1993 34b88c807SRodney W. Grimes * The Regents of the University of California. All rights reserved. 44b88c807SRodney W. Grimes * 54b88c807SRodney W. Grimes * This code is derived from software contributed to Berkeley by 64b88c807SRodney W. Grimes * Kenneth Almquist. 74b88c807SRodney W. Grimes * 84b88c807SRodney W. Grimes * Redistribution and use in source and binary forms, with or without 94b88c807SRodney W. Grimes * modification, are permitted provided that the following conditions 104b88c807SRodney W. Grimes * are met: 114b88c807SRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 124b88c807SRodney W. Grimes * notice, this list of conditions and the following disclaimer. 134b88c807SRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 144b88c807SRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 154b88c807SRodney W. Grimes * documentation and/or other materials provided with the distribution. 164b88c807SRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 174b88c807SRodney W. Grimes * may be used to endorse or promote products derived from this software 184b88c807SRodney W. Grimes * without specific prior written permission. 194b88c807SRodney W. Grimes * 204b88c807SRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 214b88c807SRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 224b88c807SRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 234b88c807SRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 244b88c807SRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 254b88c807SRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 264b88c807SRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 274b88c807SRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 284b88c807SRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 294b88c807SRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 304b88c807SRodney W. Grimes * SUCH DAMAGE. 314b88c807SRodney W. Grimes * 32aa9caaf6SPeter Wemm * @(#)var.h 8.2 (Berkeley) 5/4/95 332a456239SPeter Wemm * $FreeBSD$ 344b88c807SRodney W. Grimes */ 354b88c807SRodney W. Grimes 364b88c807SRodney W. Grimes /* 374b88c807SRodney W. Grimes * Shell variables. 384b88c807SRodney W. Grimes */ 394b88c807SRodney W. Grimes 404b88c807SRodney W. Grimes /* flags */ 41ab0a2172SSteve Price #define VEXPORT 0x01 /* variable is exported */ 42ab0a2172SSteve Price #define VREADONLY 0x02 /* variable cannot be modified */ 43bbb2cc80SJens Schweikhardt #define VSTRFIXED 0x04 /* variable struct is statically allocated */ 44bbb2cc80SJens Schweikhardt #define VTEXTFIXED 0x08 /* text is statically allocated */ 45ab0a2172SSteve Price #define VSTACK 0x10 /* text is allocated on the stack */ 46ab0a2172SSteve Price #define VUNSET 0x20 /* the variable is not set */ 47ab0a2172SSteve Price #define VNOFUNC 0x40 /* don't call the callback function */ 48850460c0SJilles Tjoelker #define VNOSET 0x80 /* do not set variable - just readonly test */ 49*c543e1aeSJilles Tjoelker #define VNOLOCAL 0x100 /* ignore forcelocal */ 504b88c807SRodney W. Grimes 514b88c807SRodney W. Grimes 524b88c807SRodney W. Grimes struct var { 534b88c807SRodney W. Grimes struct var *next; /* next entry in hash list */ 544b88c807SRodney W. Grimes int flags; /* flags are defined above */ 553a99ed46SJilles Tjoelker int name_len; /* length of name */ 564b88c807SRodney W. Grimes char *text; /* name=value */ 575134c3f7SWarner Losh void (*func)(const char *); 58ab0a2172SSteve Price /* function to be called when */ 59ab0a2172SSteve Price /* the variable gets set/unset */ 604b88c807SRodney W. Grimes }; 614b88c807SRodney W. Grimes 624b88c807SRodney W. Grimes 634b88c807SRodney W. Grimes struct localvar { 644b88c807SRodney W. Grimes struct localvar *next; /* next local variable in list */ 654b88c807SRodney W. Grimes struct var *vp; /* the variable that was made local */ 664b88c807SRodney W. Grimes int flags; /* saved flags */ 674b88c807SRodney W. Grimes char *text; /* saved text */ 684b88c807SRodney W. Grimes }; 694b88c807SRodney W. Grimes 704b88c807SRodney W. Grimes 714b88c807SRodney W. Grimes struct localvar *localvars; 72*c543e1aeSJilles Tjoelker extern int forcelocal; 734b88c807SRodney W. Grimes 744b88c807SRodney W. Grimes extern struct var vifs; 754b88c807SRodney W. Grimes extern struct var vmail; 764b88c807SRodney W. Grimes extern struct var vmpath; 774b88c807SRodney W. Grimes extern struct var vpath; 7839dccc6fSTim J. Robbins extern struct var vppid; 794b88c807SRodney W. Grimes extern struct var vps1; 804b88c807SRodney W. Grimes extern struct var vps2; 81120c8e6cSStefan Farfeleder extern struct var vps4; 82ab0a2172SSteve Price #ifndef NO_HISTORY 83ab0a2172SSteve Price extern struct var vhistsize; 84580eefdfSJilles Tjoelker extern struct var vterm; 85ab0a2172SSteve Price #endif 864b88c807SRodney W. Grimes 876ed74a0aSJilles Tjoelker extern int localeisutf8; 8807eb7033SJilles Tjoelker /* The parser uses the locale that was in effect at startup. */ 8907eb7033SJilles Tjoelker extern int initial_localeisutf8; 906ed74a0aSJilles Tjoelker 914b88c807SRodney W. Grimes /* 924b88c807SRodney W. Grimes * The following macros access the values of the above variables. 934b88c807SRodney W. Grimes * They have to skip over the name. They return the null string 944b88c807SRodney W. Grimes * for unset variables. 954b88c807SRodney W. Grimes */ 964b88c807SRodney W. Grimes 974b88c807SRodney W. Grimes #define ifsval() (vifs.text + 4) 986f47734fSTor Egge #define ifsset() ((vifs.flags & VUNSET) == 0) 994b88c807SRodney W. Grimes #define mailval() (vmail.text + 5) 1004b88c807SRodney W. Grimes #define mpathval() (vmpath.text + 9) 1014b88c807SRodney W. Grimes #define pathval() (vpath.text + 5) 1024b88c807SRodney W. Grimes #define ps1val() (vps1.text + 4) 1034b88c807SRodney W. Grimes #define ps2val() (vps2.text + 4) 104120c8e6cSStefan Farfeleder #define ps4val() (vps4.text + 4) 105ab0a2172SSteve Price #define optindval() (voptind.text + 7) 106ab0a2172SSteve Price #ifndef NO_HISTORY 107ab0a2172SSteve Price #define histsizeval() (vhistsize.text + 9) 108580eefdfSJilles Tjoelker #define termval() (vterm.text + 5) 109ab0a2172SSteve Price #endif 1104b88c807SRodney W. Grimes 1114b88c807SRodney W. Grimes #define mpathset() ((vmpath.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); 1164b88c807SRodney W. Grimes struct strlist; 117850460c0SJilles Tjoelker void listsetvar(struct strlist *, 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 int exportcmd(int, char **); 1275134c3f7SWarner Losh int localcmd(int, char **); 1285134c3f7SWarner Losh void mklocal(char *); 1295134c3f7SWarner Losh void poplocalvars(void); 1305134c3f7SWarner Losh int setvarcmd(int, char **); 1315134c3f7SWarner Losh int unsetcmd(int, char **); 1322cac6e36SJilles Tjoelker int unsetvar(const char *); 1332cac6e36SJilles Tjoelker int setvarsafe(const char *, const char *, int); 134