=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mail/vars.c,v retrieving revision 1.6 retrieving revision 1.7 diff -c -r1.6 -r1.7 *** src/usr.bin/mail/vars.c 2001/01/16 05:36:09 1.6 --- src/usr.bin/mail/vars.c 2001/11/21 15:26:39 1.7 *************** *** 1,4 **** ! /* $OpenBSD: vars.c,v 1.6 2001/01/16 05:36:09 millert Exp $ */ /* $NetBSD: vars.c,v 1.4 1996/06/08 19:48:45 christos Exp $ */ /* --- 1,4 ---- ! /* $OpenBSD: vars.c,v 1.7 2001/11/21 15:26:39 millert Exp $ */ /* $NetBSD: vars.c,v 1.4 1996/06/08 19:48:45 christos Exp $ */ /* *************** *** 36,44 **** #ifndef lint #if 0 ! static char sccsid[] = "@(#)vars.c 8.1 (Berkeley) 6/6/93"; #else ! static char rcsid[] = "$OpenBSD: vars.c,v 1.6 2001/01/16 05:36:09 millert Exp $"; #endif #endif /* not lint */ --- 36,44 ---- #ifndef lint #if 0 ! static const char sccsid[] = "@(#)vars.c 8.1 (Berkeley) 6/6/93"; #else ! static const char rcsid[] = "$OpenBSD: vars.c,v 1.7 2001/11/21 15:26:39 millert Exp $"; #endif #endif /* not lint */ *************** *** 55,69 **** * Assign a value to a variable. */ void ! assign(name, value) ! char name[], value[]; { struct var *vp; int h; h = hash(name); vp = lookup(name); ! if (vp == NOVAR) { vp = (struct var *)calloc(sizeof(*vp), 1); vp->v_name = vcopy(name); vp->v_link = variables[h]; --- 55,68 ---- * Assign a value to a variable. */ void ! assign(char *name, char *value) { struct var *vp; int h; h = hash(name); vp = lookup(name); ! if (vp == NULL) { vp = (struct var *)calloc(sizeof(*vp), 1); vp->v_name = vcopy(name); vp->v_link = variables[h]; *************** *** 80,88 **** * Thus, we cannot free same! */ void ! vfree(cp) ! char *cp; { if (*cp) (void)free(cp); } --- 79,87 ---- * Thus, we cannot free same! */ void ! vfree(char *cp) { + if (*cp) (void)free(cp); } *************** *** 91,110 **** * Copy a variable value into permanent (ie, not collected after each * command) space. Do not bother to alloc space for "" */ - char * ! vcopy(str) ! char str[]; { char *new; - unsigned len; if (*str == '\0') return(""); ! len = strlen(str) + 1; ! if ((new = (char *)malloc(len)) == NULL) errx(1, "Out of memory"); - (void)memcpy(new, str, len); return(new); } --- 90,104 ---- * Copy a variable value into permanent (ie, not collected after each * command) space. Do not bother to alloc space for "" */ char * ! vcopy(char *str) { char *new; if (*str == '\0') return(""); ! if ((new = strdup(str)) == NULL) errx(1, "Out of memory"); return(new); } *************** *** 114,126 **** */ char * ! value(name) ! char name[]; { struct var *vp; char *env; ! if ((vp = lookup(name)) != NOVAR) return(vp->v_value); else if ((env = getenv(name))) return(env); --- 108,119 ---- */ char * ! value(char *name) { struct var *vp; char *env; ! if ((vp = lookup(name)) != NULL) return(vp->v_value); else if ((env = getenv(name))) return(env); *************** *** 139,189 **** * Locate a variable and return its variable * node. */ - struct var * ! lookup(name) ! char name[]; { struct var *vp; ! for (vp = variables[hash(name)]; vp != NOVAR; vp = vp->v_link) if (*vp->v_name == *name && equal(vp->v_name, name)) return(vp); ! return(NOVAR); } /* * Locate a group name and return it. */ - struct grouphead * ! findgroup(name) ! char name[]; { struct grouphead *gh; ! for (gh = groups[hash(name)]; gh != NOGRP; gh = gh->g_link) if (*gh->g_name == *name && equal(gh->g_name, name)) return(gh); ! return(NOGRP); } /* * Print a group out on stdout */ void ! printgroup(name) ! char name[]; { struct grouphead *gh; struct group *gp; ! if ((gh = findgroup(name)) == NOGRP) { printf("\"%s\": not a group\n", name); return; } printf("%s\t", gh->g_name); ! for (gp = gh->g_list; gp != NOGE; gp = gp->ge_link) printf(" %s", gp->ge_name); putchar('\n'); } --- 132,177 ---- * Locate a variable and return its variable * node. */ struct var * ! lookup(char *name) { struct var *vp; ! for (vp = variables[hash(name)]; vp != NULL; vp = vp->v_link) if (*vp->v_name == *name && equal(vp->v_name, name)) return(vp); ! return(NULL); } /* * Locate a group name and return it. */ struct grouphead * ! findgroup(char *name) { struct grouphead *gh; ! for (gh = groups[hash(name)]; gh != NULL; gh = gh->g_link) if (*gh->g_name == *name && equal(gh->g_name, name)) return(gh); ! return(NULL); } /* * Print a group out on stdout */ void ! printgroup(char *name) { struct grouphead *gh; struct group *gp; ! if ((gh = findgroup(name)) == NULL) { printf("\"%s\": not a group\n", name); return; } printf("%s\t", gh->g_name); ! for (gp = gh->g_list; gp != NULL; gp = gp->ge_link) printf(" %s", gp->ge_name); putchar('\n'); } *************** *** 193,200 **** * the variable or group hash table. */ int ! hash(name) ! char *name; { int h = 0; --- 181,187 ---- * the variable or group hash table. */ int ! hash(char *name) { int h = 0;