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 */ 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 */ 54*3a99ed46SJilles 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 704b88c807SRodney W. Grimes struct localvar *localvars; 714b88c807SRodney W. Grimes 724b88c807SRodney W. Grimes extern struct var vifs; 734b88c807SRodney W. Grimes extern struct var vmail; 744b88c807SRodney W. Grimes extern struct var vmpath; 754b88c807SRodney W. Grimes extern struct var vpath; 7639dccc6fSTim J. Robbins extern struct var vppid; 774b88c807SRodney W. Grimes extern struct var vps1; 784b88c807SRodney W. Grimes extern struct var vps2; 79120c8e6cSStefan Farfeleder extern struct var vps4; 80ab0a2172SSteve Price #ifndef NO_HISTORY 81ab0a2172SSteve Price extern struct var vhistsize; 82580eefdfSJilles Tjoelker extern struct var vterm; 83ab0a2172SSteve Price #endif 844b88c807SRodney W. Grimes 856ed74a0aSJilles Tjoelker extern int localeisutf8; 866ed74a0aSJilles Tjoelker 874b88c807SRodney W. Grimes /* 884b88c807SRodney W. Grimes * The following macros access the values of the above variables. 894b88c807SRodney W. Grimes * They have to skip over the name. They return the null string 904b88c807SRodney W. Grimes * for unset variables. 914b88c807SRodney W. Grimes */ 924b88c807SRodney W. Grimes 934b88c807SRodney W. Grimes #define ifsval() (vifs.text + 4) 946f47734fSTor Egge #define ifsset() ((vifs.flags & VUNSET) == 0) 954b88c807SRodney W. Grimes #define mailval() (vmail.text + 5) 964b88c807SRodney W. Grimes #define mpathval() (vmpath.text + 9) 974b88c807SRodney W. Grimes #define pathval() (vpath.text + 5) 984b88c807SRodney W. Grimes #define ps1val() (vps1.text + 4) 994b88c807SRodney W. Grimes #define ps2val() (vps2.text + 4) 100120c8e6cSStefan Farfeleder #define ps4val() (vps4.text + 4) 101ab0a2172SSteve Price #define optindval() (voptind.text + 7) 102ab0a2172SSteve Price #ifndef NO_HISTORY 103ab0a2172SSteve Price #define histsizeval() (vhistsize.text + 9) 104580eefdfSJilles Tjoelker #define termval() (vterm.text + 5) 105ab0a2172SSteve Price #endif 1064b88c807SRodney W. Grimes 1074b88c807SRodney W. Grimes #define mpathset() ((vmpath.flags & VUNSET) == 0) 1084b88c807SRodney W. Grimes 1095134c3f7SWarner Losh void initvar(void); 1102cac6e36SJilles Tjoelker void setvar(const char *, const char *, int); 1115134c3f7SWarner Losh void setvareq(char *, int); 1124b88c807SRodney W. Grimes struct strlist; 113850460c0SJilles Tjoelker void listsetvar(struct strlist *, int); 1142cac6e36SJilles Tjoelker char *lookupvar(const char *); 1152cac6e36SJilles Tjoelker char *bltinlookup(const char *, int); 116e4b50334SJilles Tjoelker void bltinsetlocale(void); 117e4b50334SJilles Tjoelker void bltinunsetlocale(void); 1186ed74a0aSJilles Tjoelker void updatecharset(void); 1195134c3f7SWarner Losh char **environment(void); 1205134c3f7SWarner Losh int showvarscmd(int, char **); 1215134c3f7SWarner Losh int exportcmd(int, char **); 1225134c3f7SWarner Losh int localcmd(int, char **); 1235134c3f7SWarner Losh void mklocal(char *); 1245134c3f7SWarner Losh void poplocalvars(void); 1255134c3f7SWarner Losh int setvarcmd(int, char **); 1265134c3f7SWarner Losh int unsetcmd(int, char **); 1272cac6e36SJilles Tjoelker int unsetvar(const char *); 1282cac6e36SJilles Tjoelker int setvarsafe(const char *, const char *, int); 129