install correct aliases file
[unix-history] / usr / src / usr.bin / mail / vars.c
index 63c7a96..5bb5abd 100644 (file)
@@ -1,4 +1,23 @@
-#
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, 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'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#ifndef lint
+static char sccsid[] = "@(#)vars.c     5.5 (Berkeley) %G%";
+#endif /* not lint */
 
 #include "rcv.h"
 
 
 #include "rcv.h"
 
@@ -8,8 +27,6 @@
  * Variable handling stuff.
  */
 
  * Variable handling stuff.
  */
 
-static char *SccsId = "@(#)vars.c      2.1 %G%";
-
 /*
  * Assign a value to a variable.
  */
 /*
  * Assign a value to a variable.
  */
@@ -40,10 +57,10 @@ assign(name, value)
  */
 
 vfree(cp)
  */
 
 vfree(cp)
-       register char *cp;
+       char *cp;
 {
 {
-       if (!equal(cp, ""))
-               cfree(cp);
+       if (*cp)
+               free(cp);
 }
 
 /*
 }
 
 /*
@@ -55,16 +72,16 @@ char *
 vcopy(str)
        char str[];
 {
 vcopy(str)
        char str[];
 {
-       register char *top, *cp, *cp2;
-
-       if (equal(str, ""))
-               return("");
-       top = calloc(strlen(str)+1, 1);
-       cp = top;
-       cp2 = str;
-       while (*cp++ = *cp2++)
-               ;
-       return(top);
+       char *new;
+       unsigned len;
+
+       if (*str == '\0')
+               return "";
+       len = strlen(str) + 1;
+       if ((new = malloc(len)) == NULL)
+               panic("Out of memory");
+       bcopy(str, new, (int) len);
+       return new;
 }
 
 /*
 }
 
 /*
@@ -90,14 +107,12 @@ value(name)
 
 struct var *
 lookup(name)
 
 struct var *
 lookup(name)
-       char name[];
+       register char name[];
 {
        register struct var *vp;
 {
        register struct var *vp;
-       register int h;
 
 
-       h = hash(name);
-       for (vp = variables[h]; vp != NOVAR; vp = vp->v_link)
-               if (equal(vp->v_name, name))
+       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);
 }
                        return(vp);
        return(NOVAR);
 }
@@ -108,14 +123,12 @@ lookup(name)
 
 struct grouphead *
 findgroup(name)
 
 struct grouphead *
 findgroup(name)
-       char name[];
+       register char name[];
 {
        register struct grouphead *gh;
 {
        register struct grouphead *gh;
-       register int h;
 
 
-       h = hash(name);
-       for (gh = groups[h]; gh != NOGRP; gh = gh->g_link)
-               if (equal(gh->g_name, name))
+       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);
 }
                        return(gh);
        return(NOGRP);
 }
@@ -137,7 +150,7 @@ printgroup(name)
        printf("%s\t", gh->g_name);
        for (gp = gh->g_list; gp != NOGE; gp = gp->ge_link)
                printf(" %s", gp->ge_name);
        printf("%s\t", gh->g_name);
        for (gp = gh->g_list; gp != NOGE; gp = gp->ge_link)
                printf(" %s", gp->ge_name);
-       printf("\n");
+       putchar('\n');
 }
 
 /*
 }
 
 /*
@@ -146,13 +159,15 @@ printgroup(name)
  */
 
 hash(name)
  */
 
 hash(name)
-       char name[];
+       register char *name;
 {
 {
-       register int h;
-       register char *cp;
+       register h = 0;
 
 
-       for (cp = name, h = 0; *cp; h = (h << 2) + *cp++)
-               ;
-       h &= ~0100000;
-       return(h % HSHSIZE);
+       while (*name) {
+               h <<= 2;
+               h += *name++;
+       }
+       if (h < 0 && (h = -h) < 0)
+               h = 0;
+       return (h % HSHSIZE);
 }
 }