8000 minix/bin/sh/var.c at master · sestissi16/minix · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
844 lines (726 loc) · 16.5 KB

var.c

File metadata and controls

844 lines (726 loc) · 16.5 KB
}
INTON;
return 0;
}
/*
* Returns true if the two strings specify the same varable. The first
* variable name is terminated by '='; the second may be terminated by
* either '=' or '\0'.
*/
STATIC int
strequal(const char *p, const char *q)
{
while (*p == *q++) {
if (*p++ == '=')
return 1;
}
if (*p == '=' && *(q - 1) == '\0')
return 1;
return 0;
}
/*
* Search for a variable.
* 'name' may be terminated by '=' or a NUL.
* vppp is set to the pointer to vp, or the list head if vp isn't found
* lenp is set to the number of charactets in 'name'
*/
STATIC struct var *
find_var(const char *name, struct var ***vppp, int *lenp)
{
unsigned int hashval;
int len;
struct var *vp, **vpp;
const char *p = name;
hashval = 0;
while (*p && *p != '=')
hashval = 2 * hashval + (unsigned char)*p++;
len = p - name;
if (lenp)
*lenp = len;
vpp = &vartab[hashval % VTABSIZE];
if (vppp)
*vppp = vpp;
for (vp = *vpp ; vp ; vpp = &vp->next, vp = *vpp) {
if (vp->name_len != len)
continue;
if (memcmp(vp->text, name, len) != 0)
continue;
if (vppp)
*vppp = vpp;
return vp;
}
return NULL;
}
0