|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T i
Length: 2963 (0xb93)
Types: TextFile
Names: »isoalias.c«
└─⟦3d0c2be1b⟧ Bits:30001254 ISODE-5.0 Tape
└─⟦eba4602b1⟧ »./isode-5.0.tar.Z«
└─⟦d3ac74d73⟧
└─⟦this⟧ »isode-5.0/acsap/isoalias.c«
/* isoalias.c - application entity info -- directory service utilities */
#ifndef lint
static char *rcsid = "$Header: /f/osi/acsap/RCS/isoalias.c,v 6.0 89/03/18 23:24:41 mrose Rel $";
#endif
/*
* $Header: /f/osi/acsap/RCS/isoalias.c,v 6.0 89/03/18 23:24:41 mrose Rel $
*
*
* $Log: isoalias.c,v $
* Revision 6.0 89/03/18 23:24:41 mrose
* Release 5.0
*
*/
/*
* NOTICE
*
* Acquisition, use, and distribution of this module and related
* materials are subject to the restrictions of a license agreement.
* Consult the Preface in the User's Manual for the full terms of
* this agreement.
*
*/
/* LINTLIBRARY */
#include <stdio.h>
#include "general.h"
#include "manifest.h"
#include "tailor.h"
/* \f
DATA */
static char *isoaliases = "isoaliases";
#define PBUCKETS 128
#define PHASH(nm) \
(((nm)[1]) ? (((((nm)[0]) - ((nm)[1])) & 0x1f) + (((nm)[2]) & 0x5f)) \
: ((nm)[0]) & 0x7f)
struct pair {
char *p_name;
char *p_value;
struct pair *p_chain;
};
static int inited = 0;
static struct pair *Pbuckets[PBUCKETS];
/* \f
*/
char *alias2name (name)
char *name;
{
register struct pair *p;
read_aliases ();
for (p = Pbuckets[PHASH (name)];
p && strcmp (p -> p_name, name);
p = p -> p_chain)
continue;
return (p ? p -> p_value : NULL);
}
/* \f
*/
static int read_aliases ()
{
register char *hp;
char buffer[BUFSIZ];
if (inited)
return;
inited = 1;
bzero ((char *) Pbuckets, sizeof Pbuckets);
read_file (isodefile (isoaliases));
if ((hp = getenv ("HOME")) == NULL)
hp = ".";
(void) sprintf (buffer, "%s/.isode_aliases", hp);
read_file (buffer);
}
/* \f
*/
static int read_file (file)
char *file;
{
register char *cp;
char buffer[BUFSIZ + 1],
*vec[NVEC + NSLACK + 1];
register FILE *fp;
if ((fp = fopen (file, "r")) == NULL)
return;
while (fgets (buffer, sizeof buffer, fp)) {
if (*buffer == '#')
continue;
if (cp = index (buffer, '\n'))
*cp = NULL;
if (str2vec (buffer, vec) < 2)
continue;
if (add_alias (vec[0], vec[1]) == NOTOK)
break;
}
(void) fclose (fp);
}
/* \f
*/
int add_alias (name, value)
char *name,
*value;
{
int i;
register struct pair *p;
if ((p = (struct pair *) calloc (1, sizeof *p)) == NULL) {
SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
("calloc of alias structure failed"));
return NOTOK;
}
if ((p -> p_name = malloc ((unsigned) (strlen (name) + 1))) == NULL
|| (p -> p_value = malloc ((unsigned) (strlen (value) + 1)))
== NULL) {
SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
("malloc of alias structure failed"));
if (p -> p_name)
free (p -> p_name);
free ((char *) p);
return NOTOK;
}
(void) strcpy (p -> p_name, name);
(void) strcpy (p -> p_value, value);
p -> p_chain = Pbuckets[i = PHASH (p -> p_name)];
Pbuckets[i] = p;
return OK;
}