var.h revision 249242
1218792Snp/*- 2218792Snp * Copyright (c) 1991, 1993 3218792Snp * The Regents of the University of California. All rights reserved. 4218792Snp * 5218792Snp * This code is derived from software contributed to Berkeley by 6218792Snp * Kenneth Almquist. 7218792Snp * 8218792Snp * Redistribution and use in source and binary forms, with or without 9218792Snp * modification, are permitted provided that the following conditions 10218792Snp * are met: 11218792Snp * 1. Redistributions of source code must retain the above copyright 12218792Snp * notice, this list of conditions and the following disclaimer. 13218792Snp * 2. Redistributions in binary form must reproduce the above copyright 14218792Snp * notice, this list of conditions and the following disclaimer in the 15218792Snp * documentation and/or other materials provided with the distribution. 16218792Snp * 4. Neither the name of the University nor the names of its contributors 17218792Snp * may be used to endorse or promote products derived from this software 18218792Snp * without specific prior written permission. 19218792Snp * 20218792Snp * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21218792Snp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22218792Snp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23218792Snp * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24218792Snp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25218792Snp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26218792Snp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27218792Snp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28218792Snp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29218792Snp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30218792Snp * SUCH DAMAGE. 31218792Snp * 32218792Snp * @(#)var.h 8.2 (Berkeley) 5/4/95 33218792Snp * $FreeBSD: stable/9/bin/sh/var.h 249242 2013-04-07 21:25:14Z jilles $ 34218792Snp */ 35218792Snp 36218792Snp/* 37218792Snp * Shell variables. 38218792Snp */ 39218792Snp 40237436Snp/* flags */ 41330307Snp#define VEXPORT 0x01 /* variable is exported */ 42237436Snp#define VREADONLY 0x02 /* variable cannot be modified */ 43218792Snp#define VSTRFIXED 0x04 /* variable struct is statically allocated */ 44218792Snp#define VTEXTFIXED 0x08 /* text is statically allocated */ 45296471Snp#define VSTACK 0x10 /* text is allocated on the stack */ 46296471Snp#define VUNSET 0x20 /* the variable is not set */ 47296471Snp#define VNOFUNC 0x40 /* don't call the callback function */ 48296471Snp#define VNOSET 0x80 /* do not set variable - just readonly test */ 49296471Snp#define VNOLOCAL 0x100 /* ignore forcelocal */ 50248925Snp 51218792Snp 52218792Snpstruct var { 53218792Snp struct var *next; /* next entry in hash list */ 54218792Snp int flags; /* flags are defined above */ 55218792Snp int name_len; /* length of name */ 56218792Snp char *text; /* name=value */ 57218792Snp void (*func)(const char *); 58218792Snp /* function to be called when */ 59218792Snp /* the variable gets set/unset */ 60218792Snp}; 61218792Snp 62311260Snp 63339399Snpstruct localvar { 64311260Snp struct localvar *next; /* next local variable in list */ 65311260Snp struct var *vp; /* the variable that was made local */ 66339399Snp int flags; /* saved flags */ 67311260Snp char *text; /* saved text */ 68311260Snp}; 69331769Shselasky 70331769Shselasky 71218792Snpstruct localvar *localvars; 72218792Snpextern int forcelocal; 73218792Snp 74218792Snpextern struct var vifs; 75218792Snpextern struct var vmail; 76218792Snpextern struct var vmpath; 77218792Snpextern struct var vpath; 78218792Snpextern struct var vppid; 79218792Snpextern struct var vps1; 80218792Snpextern struct var vps2; 81218792Snpextern struct var vps4; 82218792Snpextern struct var vdisvfork; 83218792Snp#ifndef NO_HISTORY 84218792Snpextern struct var vhistsize; 85218792Snpextern struct var vterm; 86218792Snp#endif 87218792Snp 88218792Snpextern int localeisutf8; 89218792Snp/* The parser uses the locale that was in effect at startup. */ 90218792Snpextern int initial_localeisutf8; 91218792Snp 92218792Snp/* 93218792Snp * The following macros access the values of the above variables. 94218792Snp * They have to skip over the name. They return the null string 95218792Snp * for unset variables. 96218792Snp */ 97218792Snp 98218792Snp#define ifsval() (vifs.text + 4) 99218792Snp#define ifsset() ((vifs.flags & VUNSET) == 0) 100218792Snp#define mailval() (vmail.text + 5) 101218792Snp#define mpathval() (vmpath.text + 9) 102218792Snp#define pathval() (vpath.text + 5) 103218792Snp#define ps1val() (vps1.text + 4) 104218792Snp#define ps2val() (vps2.text + 4) 105218792Snp#define ps4val() (vps4.text + 4) 106218792Snp#define optindval() (voptind.text + 7) 107218792Snp#ifndef NO_HISTORY 108218792Snp#define histsizeval() (vhistsize.text + 9) 109218792Snp#define termval() (vterm.text + 5) 110218792Snp#endif 111218792Snp 112218792Snp#define mpathset() ((vmpath.flags & VUNSET) == 0) 113218792Snp#define disvforkset() ((vdisvfork.flags & VUNSET) == 0) 114218792Snp 115218792Snpvoid initvar(void); 116218792Snpvoid setvar(const char *, const char *, int); 117218792Snpvoid setvareq(char *, int); 118218792Snpstruct strlist; 119218792Snpvoid listsetvar(struct strlist *, int); 120218792Snpchar *lookupvar(const char *); 121218792Snpchar *bltinlookup(const char *, int); 122218792Snpvoid bltinsetlocale(void); 123218792Snpvoid bltinunsetlocale(void); 124218792Snpvoid updatecharset(void); 125218792Snpvoid initcharset(void); 126218792Snpchar **environment(void); 127218792Snpint showvarscmd(int, char **); 128218792Snpvoid mklocal(char *); 129218792Snpvoid poplocalvars(void); 130218792Snpint unsetvar(const char *); 131218792Snpint setvarsafe(const char *, const char *, int); 132218792Snp