* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
static char *sccsid
= "@(#)vars.c 5.2 (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 ""
register char *top
, *cp
, *cp2
;
if ((top
= calloc(strlen(str
)+1, 1)) == NULL
)
* 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
[h
]; vp
!= NOVAR
; vp
= vp
->v_link
)
if (equal(vp
->v_name
, name
))
* Locate a group name and return it.
register struct grouphead
*gh
;
for (gh
= groups
[h
]; gh
!= NOGRP
; gh
= gh
->g_link
)
if (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.
for (cp
= name
, h
= 0; *cp
; h
= (h
<< 2) + *cp
++)