xref: /original-bsd/bin/sh/var.h (revision 14dedd6e)
1 /*-
2  * Copyright (c) 1991, 1993
3  *	The Regents of the University of California.  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	8.2 (Berkeley) 05/04/95
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 void initvar __P((void));
78 void setvar __P((char *, char *, int));
79 void setvareq __P((char *, int));
80 struct strlist;
81 void listsetvar __P((struct strlist *));
82 char *lookupvar __P((char *));
83 char *bltinlookup __P((char *, int));
84 char **environment __P((void));
85 void shprocvar __P((void));
86 int showvarscmd __P((int, char **));
87 int exportcmd __P((int, char **));
88 int localcmd __P((int, char **));
89 void mklocal __P((char *));
90 void poplocalvars __P((void));
91 int setvarcmd __P((int, char **));
92 int unsetcmd __P((int, char **));
93