# 2.11BSD#431 - /usr/src/ucb/Mail/vars.c

##### Functions

    assign            X
    findgroup         X
    hash              X
    lookup            X
    printgroup        X
    value             X
    vcopy             X
    vfree             X

       1: /*
       2:  * Copyright (c) 1980 Regents of the University of California.
       3:  * All rights reserved.
       4:  *
       5:  * Redistribution and use in source and binary forms, with or without
       6:  * modification, are permitted provided that the following conditions
       7:  * are met:
       8:  * 1. Redistributions of source code must retain the above copyright
       9:  *    notice, this list of conditions and the following disclaimer.
      10:  * 2. Redistributions in binary form must reproduce the above copyright
      11:  *    notice, this list of conditions and the following disclaimer in the
      12:  *    documentation and/or other materials provided with the distribution.
      13:  * 3. All advertising materials mentioning features or use of this software
      14:  *    must display the following acknowledgement:
      15:  *	This product includes software developed by the University of
      16:  *	California, Berkeley and its contributors.
      17:  * 4. Neither the name of the University nor the names of its contributors
      18:  *    may be used to endorse or promote products derived from this software
      19:  *    without specific prior written permission.
      20:  *
      21:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
      22:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
      23:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
      24:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
      25:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
      26:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
      27:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
      28:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
      29:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
      30:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
      31:  * SUCH DAMAGE.
      32:  */
      33:
      34: #if !defined(lint) && defined(DOSCCS)
      35: static char sccsid[] = "@(#)vars.c	5.6 (Berkeley) 6/1/90";
      36: #endif
      37:
      38: #include "rcv.h"
      39:
      40: /*
      41:  * Mail -- a mail program
      42:  *
      43:  * Variable handling stuff.
      44:  */
      45:
      46: /*
      47:  * Assign a value to a variable.
      48:  */
      49:
      50: assign(name, value)
      51:     char name[], value[];
      52: {
      53:     register struct var *vp;
      54:     register int h;
      55:
      56:     h = hash(name);
      57:     vp = lookup(name);
      58:     if (vp == NOVAR) {
      59:         vp = (struct var *) calloc(sizeof *vp, 1);
      60:         vp->v_name = vcopy(name);
      61:         vp->v_link = variables[h];
      62:         variables[h] = vp;
      63:     }
      64:     else
      65:         vfree(vp->v_value);
      66:     vp->v_value = vcopy(value);
      67: }
      68:
      69: /*
      70:  * Free up a variable string.  We do not bother to allocate
      71:  * strings whose value is "" since they are expected to be frequent.
      72:  * Thus, we cannot free same!
      73:  */
      74:
      75: vfree(cp)
      76:     char *cp;
      77: {
      78:     if (*cp)
      79:         free(cp);
      80: }
      81:
      82: /*
      83:  * Copy a variable value into permanent (ie, not collected after each
      84:  * command) space.  Do not bother to alloc space for ""
      85:  */
      86:
      87: char *
      88: vcopy(str)
      89:     char str[];
      90: {
      91:     char *new;
      92:     unsigned len;
      93:
      94:     if (*str == '\0')
      95:         return "";
      96:     len = strlen(str) + 1;
      97:     if ((new = malloc(len)) == NULL)
      98:         panic("Out of memory");
      99:     bcopy(str, new, (int) len);
     100:     return new;
     101: }
     102:
     103: /*
     104:  * Get the value of a variable and return it.
     105:  * Look in the environment if its not available locally.
     106:  */
     107:
     108: char *
     109: value(name)
     110:     char name[];
     111: {
     112:     register struct var *vp;
     113:
     114:     if ((vp = lookup(name)) == NOVAR)
     115:         return(getenv(name));
     116:     return(vp->v_value);
     117: }
     118:
     119: /*
     120:  * Locate a variable and return its variable
     121:  * node.
     122:  */
     123:
     124: struct var *
     125: lookup(name)
     126:     register char name[];
     127: {
     128:     register struct var *vp;
     129:
     130:     for (vp = variables[hash(name)]; vp != NOVAR; vp = vp->v_link)
     131:         if (*vp->v_name == *name && equal(vp->v_name, name))
     132:             return(vp);
     133:     return(NOVAR);
     134: }
     135:
     136: /*
     137:  * Locate a group name and return it.
     138:  */
     139:
     140: struct grouphead *
     141: findgroup(name)
     142:     register char name[];
     143: {
     144:     register struct grouphead *gh;
     145:
     146:     for (gh = groups[hash(name)]; gh != NOGRP; gh = gh->g_link)
     147:         if (*gh->g_name == *name && equal(gh->g_name, name))
     148:             return(gh);
     149:     return(NOGRP);
     150: }
     151:
     152: /*
     153:  * Print a group out on stdout
     154:  */
     155:
     156: printgroup(name)
     157:     char name[];
     158: {
     159:     register struct grouphead *gh;
     160:     register struct group *gp;
     161:
     162:     if ((gh = findgroup(name)) == NOGRP) {
     163:         printf("\"%s\": not a group\n", name);
     164:         return;
     165:     }
     166:     printf("%s\t", gh->g_name);
     167:     for (gp = gh->g_list; gp != NOGE; gp = gp->ge_link)
     168:         printf(" %s", gp->ge_name);
     169:     putchar('\n');
     170: }
     171:
     172: /*
     173:  * Hash the passed string and return an index into
     174:  * the variable or group hash table.
     175:  */
     176:
     177: hash(name)
     178:     register char *name;
     179: {
     180:     register h = 0;
     181:
     182:     while (*name) {
     183:         h <<= 2;
     184:         h += *name++;
     185:     }
     186:     if (h < 0 && (h = -h) < 0)
     187:         h = 0;
     188:     return (h % HSHSIZE);
     189: }

#### Defined functions

assign defined in line 50; used 6 times

- in /usr/src/ucb/Mail/cmd3.c line 388
- in /usr/src/ucb/Mail/main.c line 73, 113, 150, 156, 162

findgroup defined in line 140; used 5 times

- in line 162
- in /usr/src/ucb/Mail/cmd3.c line 464
- in /usr/src/ucb/Mail/def.h line 312
- in /usr/src/ucb/Mail/names.c line 384, 423

hash defined in line 177; used 7 times

- in line 56, 130, 146
- in /usr/src/ucb/Mail/aux.c line 646
- in /usr/src/ucb/Mail/cmd2.c line 468
- in /usr/src/ucb/Mail/cmd3.c line 413, 463

lookup defined in line 124; used 4 times

- in line 57, 114
- in /usr/src/ucb/Mail/cmd3.c line 406
- in /usr/src/ucb/Mail/def.h line 322

printgroup defined in line 156; used 2 times

- in /usr/src/ucb/Mail/cmd3.c line 455-459(2)

value defined in line 108; used 58 times

- in line 50-51(2), 66
- in /usr/src/ucb/Mail/cmd1.c line 136, 194, 297-298(2), 305, 320, 363, 374, 436
- in /usr/src/ucb/Mail/cmd3.c line 60, 78, 182, 369, 568
- in /usr/src/ucb/Mail/collect.c line 118-119(3), 125, 156-157(2), 166-169(4), 524, 574, 584
- in /usr/src/ucb/Mail/def.h line 306
- in /usr/src/ucb/Mail/edit.c line 185
- in /usr/src/ucb/Mail/fio.c line 326, 346, 392, 409
- in /usr/src/ucb/Mail/head.c line 82
- in /usr/src/ucb/Mail/lex.c line 183, 216-217(2), 417, 552
- in /usr/src/ucb/Mail/main.c line 234
- in /usr/src/ucb/Mail/names.c line 286, 376, 486-489(2)
- in /usr/src/ucb/Mail/quit.c line 137-140(2), 199, 234, 258
- in /usr/src/ucb/Mail/send.c line 303-304(2), 351, 377, 385
- in /usr/src/ucb/Mail/v7.local.c line 64

vcopy defined in line 87; used 5 times

- in line 60, 66
- in /usr/src/ucb/Mail/cmd3.c line 466, 480
- in /usr/src/ucb/Mail/def.h line 307

vfree defined in line 75; used 5 times

- in line 65
- in /usr/src/ucb/Mail/cmd3.c line 416-417(2), 424-425(2)

#### Defined variables

sccsid defined in line 35; never used

Last modified: 1992-10-22 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 900 |