|
|
1.1 root 1: /* isoalias.c - application entity info -- directory service utilities */
2:
3: #ifndef lint
4: static char *rcsid = "$Header: /f/osi/acsap/RCS/isoalias.c,v 7.1 90/01/11 18:35:01 mrose Exp $";
5: #endif
6:
7: /*
8: * $Header: /f/osi/acsap/RCS/isoalias.c,v 7.1 90/01/11 18:35:01 mrose Exp $
9: *
10: *
11: * $Log: isoalias.c,v $
12: * Revision 7.1 90/01/11 18:35:01 mrose
13: * real-sync
14: *
15: * Revision 7.0 89/11/23 21:22:12 mrose
16: * Release 6.0
17: *
18: */
19:
20: /*
21: * NOTICE
22: *
23: * Acquisition, use, and distribution of this module and related
24: * materials are subject to the restrictions of a license agreement.
25: * Consult the Preface in the User's Manual for the full terms of
26: * this agreement.
27: *
28: */
29:
30:
31: /* LINTLIBRARY */
32:
33: #include <stdio.h>
34: #include "general.h"
35: #include "manifest.h"
36: #include "tailor.h"
37:
38: /* DATA */
39:
40: static char *isoaliases = "isoaliases";
41:
42:
43: #define PBUCKETS 128
44: #define PHASH(nm) \
45: (((nm)[1]) ? (((chrcnv[((nm)[0])] - chrcnv[((nm)[1])]) & 0x1f) \
46: + ((chrcnv[(nm)[2]]) & 0x5f)) \
47: : (chrcnv[(nm)[0]]) & 0x7f)
48:
49: struct pair {
50: char *p_name;
51: char *p_value;
52:
53: struct pair *p_chain;
54: };
55:
56: static int inited = 0;
57: static struct pair *Pbuckets[PBUCKETS];
58:
59: /* */
60:
61: char *alias2name (name)
62: char *name;
63: {
64: register struct pair *p;
65:
66: if (!inited)
67: read_aliases ();
68:
69: for (p = Pbuckets[PHASH (name)];
70: p && lexequ (p -> p_name, name);
71: p = p -> p_chain)
72: continue;
73:
74: return (p ? p -> p_value : NULL);
75: }
76:
77: /* */
78:
79: static int read_aliases ()
80: {
81: register char *hp;
82: char buffer[BUFSIZ];
83:
84: if (inited)
85: return;
86: inited = 1;
87:
88: bzero ((char *) Pbuckets, sizeof Pbuckets);
89:
90: read_file (isodefile (isoaliases, 0));
91:
92: if ((hp = getenv ("HOME")) == NULL)
93: hp = ".";
94: (void) sprintf (buffer, "%s/.isode_aliases", hp);
95: read_file (buffer);
96: }
97:
98: /* */
99:
100: static int read_file (file)
101: char *file;
102: {
103: register char *cp;
104: char buffer[BUFSIZ + 1],
105: *vec[NVEC + NSLACK + 1];
106: register FILE *fp;
107:
108: if ((fp = fopen (file, "r")) == NULL)
109: return;
110:
111: while (fgets (buffer, sizeof buffer, fp)) {
112: if (*buffer == '#')
113: continue;
114: if (cp = index (buffer, '\n'))
115: *cp = NULL;
116: if (str2vec (buffer, vec) < 2)
117: continue;
118:
119: if (add_alias (vec[0], vec[1]) == NOTOK)
120: break;
121: }
122:
123: (void) fclose (fp);
124: }
125:
126: /* */
127:
128: int add_alias (name, value)
129: char *name,
130: *value;
131: {
132: int i;
133: register struct pair *p;
134:
135: if (!inited)
136: read_aliases ();
137:
138: if ((p = (struct pair *) calloc (1, sizeof *p)) == NULL) {
139: SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
140: ("calloc of alias structure failed"));
141: return NOTOK;
142: }
143:
144: if ((p -> p_name = malloc ((unsigned) (strlen (name) + 1))) == NULL
145: || (p -> p_value = malloc ((unsigned) (strlen (value) + 1)))
146: == NULL) {
147: SLOG (addr_log, LLOG_EXCEPTIONS, NULLCP,
148: ("malloc of alias structure failed"));
149: if (p -> p_name)
150: free (p -> p_name);
151: free ((char *) p);
152: return NOTOK;
153: }
154: (void) strcpy (p -> p_name, name);
155: (void) strcpy (p -> p_value, value);
156:
157: p -> p_chain = Pbuckets[i = PHASH (p -> p_name)];
158: Pbuckets[i] = p;
159:
160: return OK;
161: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.