* Copyright (c) 1980 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that this notice is preserved and that due credit is given
* to the University of California at Berkeley. The name of the University
* may not be used to endorse or promote products derived from this
* software without specific prior written permission. This software
* is provided ``as is'' without express or implied warranty.
static char sccsid
[] = "@(#)vars.c 5.4 (Berkeley) %G%";
* Variable handling stuff.
* Assign a value to a variable.
vp
= (struct var
*) calloc(sizeof *vp
, 1);
vp
->v_name
= vcopy(name
);
vp
->v_link
= variables
[h
];
vp
->v_value
= vcopy(value
);
* Free up a variable string. We do not bother to allocate
* strings whose value is "" since they are expected to be frequent.
* Thus, we cannot free same!
* Copy a variable value into permanent (ie, not collected after each
* command) space. Do not bother to alloc space for ""
if ((new = malloc(len
)) == NULL
)
bcopy(str
, new, (int) len
);
* Get the value of a variable and return it.
* Look in the environment if its not available locally.
if ((vp
= lookup(name
)) == NOVAR
)
* Locate a variable and return its variable
for (vp
= variables
[hash(name
)]; vp
!= NOVAR
; vp
= vp
->v_link
)
if (*vp
->v_name
== *name
&& equal(vp
->v_name
, name
))
* Locate a group name and return it.
register struct grouphead
*gh
;
for (gh
= groups
[hash(name
)]; gh
!= NOGRP
; gh
= gh
->g_link
)
if (*gh
->g_name
== *name
&& equal(gh
->g_name
, name
))
* Print a group out on stdout
register struct grouphead
*gh
;
register struct group
*gp
;
if ((gh
= findgroup(name
)) == NOGRP
) {
printf("\"%s\": not a group\n", name
);
printf("%s\t", gh
->g_name
);
for (gp
= gh
->g_list
; gp
!= NOGE
; gp
= gp
->ge_link
)
printf(" %s", gp
->ge_name
);
* Hash the passed string and return an index into
* the variable or group hash table.
if (h
< 0 && (h
= -h
) < 0)