var.h revision 104255
150479Speter/*- 21553Srgrimes * Copyright (c) 1991, 1993 380029Sobrien * The Regents of the University of California. All rights reserved. 480029Sobrien * 580029Sobrien * This code is derived from software contributed to Berkeley by 61553Srgrimes * Kenneth Almquist. 774816Sru * 880029Sobrien * Redistribution and use in source and binary forms, with or without 983391Sru * modification, are permitted provided that the following conditions 101553Srgrimes * are met: 1180029Sobrien * 1. Redistributions of source code must retain the above copyright 1280029Sobrien * notice, this list of conditions and the following disclaimer. 1380029Sobrien * 2. Redistributions in binary form must reproduce the above copyright 1480029Sobrien * notice, this list of conditions and the following disclaimer in the 1580029Sobrien * documentation and/or other materials provided with the distribution. 1658904Sshin * 3. All advertising materials mentioning features or use of this software 1780029Sobrien * must display the following acknowledgement: 1858904Sshin * This product includes software developed by the University of 1917637Speter * California, Berkeley and its contributors. 2017637Speter * 4. Neither the name of the University nor the names of its contributors 2117637Speter * may be used to endorse or promote products derived from this software 2280029Sobrien * without specific prior written permission. 2317637Speter * 2458904Sshin * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2558804Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2658804Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2758904Sshin * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2818584Sfenner * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2942624Ssimokawa * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3042624Ssimokawa * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3180029Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3242624Ssimokawa * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3342624Ssimokawa * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3480029Sobrien * SUCH DAMAGE. 3518584Sfenner * 3618584Sfenner * @(#)var.h 8.2 (Berkeley) 5/4/95 3736799Simp * $FreeBSD: head/bin/sh/var.h 104255 2002-10-01 00:54:14Z tjr $ 3880029Sobrien */ 3980029Sobrien 4018584Sfenner/* 411553Srgrimes * Shell variables. 42 */ 43 44/* flags */ 45#define VEXPORT 0x01 /* variable is exported */ 46#define VREADONLY 0x02 /* variable cannot be modified */ 47#define VSTRFIXED 0x04 /* variable struct is staticly allocated */ 48#define VTEXTFIXED 0x08 /* text is staticly allocated */ 49#define VSTACK 0x10 /* text is allocated on the stack */ 50#define VUNSET 0x20 /* the variable is not set */ 51#define VNOFUNC 0x40 /* don't call the callback function */ 52 53 54struct var { 55 struct var *next; /* next entry in hash list */ 56 int flags; /* flags are defined above */ 57 char *text; /* name=value */ 58 void (*func)(const char *); 59 /* function to be called when */ 60 /* the variable gets set/unset */ 61}; 62 63 64struct localvar { 65 struct localvar *next; /* next local variable in list */ 66 struct var *vp; /* the variable that was made local */ 67 int flags; /* saved flags */ 68 char *text; /* saved text */ 69}; 70 71 72struct localvar *localvars; 73 74extern struct var vifs; 75extern struct var vmail; 76extern struct var vmpath; 77extern struct var vpath; 78extern struct var vppid; 79extern struct var vps1; 80extern struct var vps2; 81#ifndef NO_HISTORY 82extern struct var vhistsize; 83#endif 84 85/* 86 * The following macros access the values of the above variables. 87 * They have to skip over the name. They return the null string 88 * for unset variables. 89 */ 90 91#define ifsval() (vifs.text + 4) 92#define ifsset() ((vifs.flags & VUNSET) == 0) 93#define mailval() (vmail.text + 5) 94#define mpathval() (vmpath.text + 9) 95#define pathval() (vpath.text + 5) 96#define ps1val() (vps1.text + 4) 97#define ps2val() (vps2.text + 4) 98#define optindval() (voptind.text + 7) 99#ifndef NO_HISTORY 100#define histsizeval() (vhistsize.text + 9) 101#endif 102 103#define mpathset() ((vmpath.flags & VUNSET) == 0) 104 105void initvar(void); 106void setvar(char *, char *, int); 107void setvareq(char *, int); 108struct strlist; 109void listsetvar(struct strlist *); 110char *lookupvar(char *); 111char *bltinlookup(char *, int); 112char **environment(void); 113void shprocvar(void); 114int showvarscmd(int, char **); 115int exportcmd(int, char **); 116int localcmd(int, char **); 117void mklocal(char *); 118void poplocalvars(void); 119int setvarcmd(int, char **); 120int unsetcmd(int, char **); 121int unsetvar(char *); 122int setvarsafe(char *, char *, int); 123