1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
25 * AT&T Bell Laboratories
27 * generate 14 char lookup key for lang path in key
28 * based on 32-bit checksum on path
30 * if key==0 then space is malloc'd
31 * if attr != 0 then attribute var assignments placed here:
32 * ATTRIBUTES list of attribute names
41 pathkey(char* key
, char* attr
, const char* lang
, const char* tool
, const char* apath
)
43 register char* path
= (char*)apath
;
53 char* env
[elementsof(usr
) + 3];
57 static char let
[] = "ABCDEFGHIJKLMNOP";
61 if (tool
&& streq(tool
, "mam"))
63 for (n
= 0; *path
; path
++)
64 n
= n
* 0x63c63cd9L
+ *path
+ 0x9c39c33dL
;
66 for (n
&= 0xffffffffL
; n
; n
>>= 4)
72 for (c
= 0; c
< elementsof(env
); c
++)
77 * trailing flags in path
80 if (flags
= strchr(path
, ' '))
87 *(flags
= tmp
+ (flags
- path
)) = 0;
96 if (fs3d(FS3D_TEST
) && (c
= mount(path
, tmp
, FS3D_GET
|FS3D_ALL
|FS3D_SIZE(PATH_MAX
), NiL
)) > 1 && c
< PATH_MAX
)
104 attr
= strcopy(attr
, "PREROOT='");
106 if (k
= getenv(PR_BASE
))
108 if (s
= strrchr(k
, '/'))
110 n
= memsum(k
, strlen(k
), n
);
112 if (attr
&& (getpreroot(attr
, path
) || getpreroot(attr
, NiL
)))
113 attr
+= strlen(attr
);
115 if ((k
= getenv("VIRTUAL_ROOT")) && *k
== '/')
117 n
= memsum(k
, strlen(k
), n
);
119 attr
= strcopy(attr
, k
);
128 attr
= strcopy(attr
, "' UNIVERSE='");
129 if (k
= astconf("UNIVERSE", NiL
, NiL
))
131 n
= memsum(k
, strlen(k
), n
);
133 attr
= strcopy(attr
, k
);
139 * ${PROBE_ATTRIBUTES} || ${VERSION_ENVIRONMENT} : list of alternate env vars
140 * ${VERSION_ENVIRONMENT} : list of alternate env vars
142 * ${VERSION_<base(path)>}
143 * ${<toupper(base(path))>VER}
150 usr
[c
++] = "OBJTYPE";
151 if (!(k
= getenv("PROBE_ATTRIBUTES")))
152 k
= getenv("VERSION_ENVIRONMENT");
154 while (c
< (elementsof(usr
) - 1))
156 while (*k
&& (*k
== ':' || *k
== ' '))
161 while (*k
&& *k
!= ':' && *k
!= ' ')
165 ver
[0] = (char*)lang
;
166 ver
[1] = k
= (s
= strrchr(path
, '/')) ? s
+ 1 : path
;
170 if (*k
== '3' && *(k
+ 1) == 'b')
173 * cuteness never pays
184 for (; (c
= *k
) && s
< &buf
[sizeof(buf
) - 1]; k
++)
193 for (p
= environ
; *p
; p
++)
196 for (k
= *p
; *k
&& *k
== *s
; k
++, s
++);
199 for (c
= 0; c
< elementsof(ver
); c
++)
200 if (!env
[c
] && (s
= ver
[c
]))
202 for (t
= k
; *t
&& *t
!= '=' && *t
++ == *s
; s
++);
203 if (*t
== '=' && (!*s
|| (s
- ver
[c
]) > 1))
213 for (k
= *p
; *k
&& *s
++ == *k
; k
++);
214 if ((s
- buf
) > 2 && k
[0] == 'V' && k
[1] == 'E' && k
[2] == 'R' && k
[3] == '=')
220 for (c
= 0; c
< elementsof(usr
) && (s
= usr
[c
]); c
++)
221 if (!env
[c
+ elementsof(env
) - elementsof(usr
)])
223 for (k
= *p
; *k
&& *k
== *s
; k
++, s
++);
224 if (*k
== '=' && (!*s
|| *s
== ':' || *s
== ' '))
226 env
[c
+ elementsof(env
) - elementsof(usr
)] = *p
;
232 for (c
= 0; c
< elementsof(env
); c
++)
238 while ((*attr
++ = *k
++) != '=');
240 attr
= strcopy(attr
, k
);
244 while (*k
&& *k
++ != '=');
245 n
= memsum(k
, strlen(k
), n
);
249 attr
= strcopy(attr
, " ATTRIBUTES='PREROOT UNIVERSE");
250 for (c
= 0; c
< elementsof(env
); c
++)
254 while ((*attr
= *k
++) != '=')
262 * now the normal stuff
267 s
= path
+ strlen(path
);
268 sfsprintf(key
, 15, "%08lX", memsum(path
, s
- path
, n
));
273 else if ((t
= s
- 4) < flags
)
284 if (*s
!= '/' && *s
!= ' ')
294 return key
== buf
? strdup(key
) : key
;