xref: /csrg-svn/bin/sh/var.h (revision 60698)
147148Sbostic /*-
2*60698Sbostic  * Copyright (c) 1991, 1993
3*60698Sbostic  *	The Regents of the University of California.  All rights reserved.
447148Sbostic  *
547148Sbostic  * This code is derived from software contributed to Berkeley by
647148Sbostic  * Kenneth Almquist.
747148Sbostic  *
847148Sbostic  * %sccs.include.redist.c%
947148Sbostic  *
10*60698Sbostic  *	@(#)var.h	8.1 (Berkeley) 05/31/93
1147148Sbostic  */
1247148Sbostic 
1347148Sbostic /*
1447148Sbostic  * Shell variables.
1547148Sbostic  */
1647148Sbostic 
1747148Sbostic /* flags */
1847148Sbostic #define VEXPORT		01	/* variable is exported */
1947148Sbostic #define VREADONLY	02	/* variable cannot be modified */
2047148Sbostic #define VSTRFIXED	04	/* variable struct is staticly allocated */
2147148Sbostic #define VTEXTFIXED	010	/* text is staticly allocated */
2247148Sbostic #define VSTACK		020	/* text is allocated on the stack */
2347148Sbostic #define VUNSET		040	/* the variable is not set */
2447148Sbostic 
2547148Sbostic 
2647148Sbostic struct var {
2747148Sbostic 	struct var *next;		/* next entry in hash list */
2847148Sbostic 	int flags;		/* flags are defined above */
2947148Sbostic 	char *text;		/* name=value */
3047148Sbostic };
3147148Sbostic 
3247148Sbostic 
3347148Sbostic struct localvar {
3447148Sbostic 	struct localvar *next;	/* next local variable in list */
3547148Sbostic 	struct var *vp;		/* the variable that was made local */
3647148Sbostic 	int flags;		/* saved flags */
3747148Sbostic 	char *text;		/* saved text */
3847148Sbostic };
3947148Sbostic 
4047148Sbostic 
4147148Sbostic struct localvar *localvars;
4247148Sbostic 
4347148Sbostic #if ATTY
4447148Sbostic extern struct var vatty;
4547148Sbostic #endif
4647148Sbostic extern struct var vifs;
4747148Sbostic extern struct var vmail;
4847148Sbostic extern struct var vmpath;
4947148Sbostic extern struct var vpath;
5047148Sbostic extern struct var vps1;
5147148Sbostic extern struct var vps2;
5247148Sbostic #if ATTY
5347148Sbostic extern struct var vterm;
5447148Sbostic #endif
5547148Sbostic 
5647148Sbostic /*
5747148Sbostic  * The following macros access the values of the above variables.
5847148Sbostic  * They have to skip over the name.  They return the null string
5947148Sbostic  * for unset variables.
6047148Sbostic  */
6147148Sbostic 
6247148Sbostic #define ifsval()	(vifs.text + 4)
6347148Sbostic #define mailval()	(vmail.text + 5)
6447148Sbostic #define mpathval()	(vmpath.text + 9)
6547148Sbostic #define pathval()	(vpath.text + 5)
6647148Sbostic #define ps1val()	(vps1.text + 4)
6747148Sbostic #define ps2val()	(vps2.text + 4)
6847148Sbostic #if ATTY
6947148Sbostic #define termval()	(vterm.text + 5)
7047148Sbostic #endif
7147148Sbostic 
7247148Sbostic #if ATTY
7347148Sbostic #define attyset()	((vatty.flags & VUNSET) == 0)
7447148Sbostic #endif
7547148Sbostic #define mpathset()	((vmpath.flags & VUNSET) == 0)
7647148Sbostic 
7747148Sbostic 
7847148Sbostic #ifdef __STDC__
7947148Sbostic void initvar();
8047148Sbostic void setvar(char *, char *, int);
8147148Sbostic void setvareq(char *, int);
8247148Sbostic struct strlist;
8347148Sbostic void listsetvar(struct strlist *);
8447148Sbostic char *lookupvar(char *);
8547148Sbostic char *bltinlookup(char *, int);
8647148Sbostic char **environment();
8747148Sbostic int showvarscmd(int, char **);
8847148Sbostic void mklocal(char *);
8947148Sbostic void poplocalvars(void);
9047148Sbostic #else
9147148Sbostic void initvar();
9247148Sbostic void setvar();
9347148Sbostic void setvareq();
9447148Sbostic void listsetvar();
9547148Sbostic char *lookupvar();
9647148Sbostic char *bltinlookup();
9747148Sbostic char **environment();
9847148Sbostic int showvarscmd();
9947148Sbostic void mklocal();
10047148Sbostic void poplocalvars();
10147148Sbostic #endif
102