xref: /original-bsd/bin/sh/var.h (revision 817cfbae)
1 /*-
2  * Copyright (c) 1991 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Kenneth Almquist.
7  *
8  * %sccs.include.redist.c%
9  *
10  *	@(#)var.h	5.1 (Berkeley) 03/07/91
11  */
12 
13 /*
14  * Shell variables.
15  */
16 
17 /* flags */
18 #define VEXPORT		01	/* variable is exported */
19 #define VREADONLY	02	/* variable cannot be modified */
20 #define VSTRFIXED	04	/* variable struct is staticly allocated */
21 #define VTEXTFIXED	010	/* text is staticly allocated */
22 #define VSTACK		020	/* text is allocated on the stack */
23 #define VUNSET		040	/* the variable is not set */
24 
25 
26 struct var {
27 	struct var *next;		/* next entry in hash list */
28 	int flags;		/* flags are defined above */
29 	char *text;		/* name=value */
30 };
31 
32 
33 struct localvar {
34 	struct localvar *next;	/* next local variable in list */
35 	struct var *vp;		/* the variable that was made local */
36 	int flags;		/* saved flags */
37 	char *text;		/* saved text */
38 };
39 
40 
41 struct localvar *localvars;
42 
43 #if ATTY
44 extern struct var vatty;
45 #endif
46 extern struct var vifs;
47 extern struct var vmail;
48 extern struct var vmpath;
49 extern struct var vpath;
50 extern struct var vps1;
51 extern struct var vps2;
52 #if ATTY
53 extern struct var vterm;
54 #endif
55 
56 /*
57  * The following macros access the values of the above variables.
58  * They have to skip over the name.  They return the null string
59  * for unset variables.
60  */
61 
62 #define ifsval()	(vifs.text + 4)
63 #define mailval()	(vmail.text + 5)
64 #define mpathval()	(vmpath.text + 9)
65 #define pathval()	(vpath.text + 5)
66 #define ps1val()	(vps1.text + 4)
67 #define ps2val()	(vps2.text + 4)
68 #if ATTY
69 #define termval()	(vterm.text + 5)
70 #endif
71 
72 #if ATTY
73 #define attyset()	((vatty.flags & VUNSET) == 0)
74 #endif
75 #define mpathset()	((vmpath.flags & VUNSET) == 0)
76 
77 
78 #ifdef __STDC__
79 void initvar();
80 void setvar(char *, char *, int);
81 void setvareq(char *, int);
82 struct strlist;
83 void listsetvar(struct strlist *);
84 char *lookupvar(char *);
85 char *bltinlookup(char *, int);
86 char **environment();
87 int showvarscmd(int, char **);
88 void mklocal(char *);
89 void poplocalvars(void);
90 #else
91 void initvar();
92 void setvar();
93 void setvareq();
94 void listsetvar();
95 char *lookupvar();
96 char *bltinlookup();
97 char **environment();
98 int showvarscmd();
99 void mklocal();
100 void poplocalvars();
101 #endif
102