summaryrefslogtreecommitdiffstats
path: root/source/ap/ksh93/patches/ksh-20120801-oldenvinit.patch
blob: 8ee086314a43b2c47869d6b57409984588c9c2c7 (about) (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
diff -up ksh-20120801/src/cmd/ksh93/sh/init.c.fixset ksh-20120801/src/cmd/ksh93/sh/init.c
--- ksh-20120801/src/cmd/ksh93/sh/init.c.fixset	2014-11-03 15:45:36.510997271 +0100
+++ ksh-20120801/src/cmd/ksh93/sh/init.c	2014-11-03 16:20:44.398917280 +0100
@@ -2003,8 +2003,91 @@ static Dt_t *inittree(Shell_t *shp,const
  * skip over items that are not name-value pairs
  */
 
+
 static void env_init(Shell_t *shp)
 {
+	register char *cp;
+	register Namval_t	*np;
+	register char **ep=environ;
+	register char *next=0;
+#ifdef _ENV_H
+	shp->env = env_open(environ,3);
+	env_delete(shp->env,"_");
+#endif
+	if(ep)
+	{
+		while(cp= *ep++)
+		{
+			if(*cp=='A' && cp[1]=='_' && cp[2]=='_' && cp[3]=='z' && cp[4]=='=')
+				next = cp+4;
+			else if(np=nv_open(cp,shp->var_tree,(NV_EXPORT|NV_IDENT|NV_ASSIGN|NV_NOFAIL))) 
+			{
+				nv_onattr(np,NV_IMPORT);
+				np->nvenv = cp;
+				nv_close(np);
+			}
+			else  /* swap with front */
+			{
+				ep[-1] = environ[shp->nenv];
+				environ[shp->nenv++] = cp;
+			}
+		}
+		while(cp=next)
+		{
+			if(next = strchr(++cp,'='))
+				*next = 0;
+			np = nv_search(cp+2,shp->var_tree,NV_ADD);
+			if(np!=SHLVL && nv_isattr(np,NV_IMPORT|NV_EXPORT))
+			{
+				int flag = *(unsigned char*)cp-' ';
+				int size = *(unsigned char*)(cp+1)-' ';
+				if((flag&NV_INTEGER) && size==0)
+				{
+					/* check for floating*/
+					char *ep,*val = nv_getval(np);
+					strtol(val,&ep,10);
+					if(*ep=='.' || *ep=='e' || *ep=='E')
+					{
+						char *lp;
+						flag |= NV_DOUBLE;
+						if(*ep=='.')
+						{
+							strtol(ep+1,&lp,10);
+							if(*lp)
+								ep = lp;
+						}
+						if(*ep && *ep!='.')
+						{
+							flag |= NV_EXPNOTE;
+							size = ep-val;
+						}
+						else
+							size = strlen(ep);
+						size--;
+					}
+				}
+				nv_newattr(np,flag|NV_IMPORT|NV_EXPORT,size);
+			}
+			else
+				cp += 2;
+		}
+	}
+#ifdef _ENV_H
+	env_delete(shp->env,e_envmarker);
+#endif
+	if(nv_isnull(PWDNOD) || nv_isattr(PWDNOD,NV_TAGGED))
+	{
+		nv_offattr(PWDNOD,NV_TAGGED);
+		path_pwd(shp,0);
+	}
+	if((cp = nv_getval(SHELLNOD)) && (sh_type(cp)&SH_TYPE_RESTRICTED))
+		sh_onoption(SH_RESTRICTED); /* restricted shell */
+	return;
+}
+
+
+static void env_init_backup(Shell_t *shp)
+{
 	register char		*cp;
 	register Namval_t	*np,*mp;
 	register char		**ep=environ;