|
|
1.1 root 1: # include <stdio.h>
2: # include <ctype.h>
3: # include "dlvrmail.h"
4:
5: static char SccsId[] = "@(#)newaliases.c 1.2 10/18/80";
6:
7: typedef struct { char *dptr; int dsize; } datum;
8: char *aliases = ALIASFILE;
9: char dirbuf[100];
10: char pagbuf[100];
11: int LineNo;
12: char *To;
13: int ExitStat;
14: int Errors;
15: # ifdef DEBUG
16: bool Debug;
17: # endif DEBUG
18:
19: main(argc, argv)
20: int argc;
21: char *argv[];
22: {
23: int f;
24: char line[BUFSIZ];
25: char line2[MAXLINE];
26: register char *p;
27: char *cp, *p2;
28: char *rhs;
29: int naliases, bytes, longest;
30: datum key, content;
31: bool skipping;
32: addrq al, bl;
33: extern char *prescan();
34: extern addrq *parse();
35: bool contin;
36:
37: # ifdef DEBUG
38: if (argc > 1 && strcmp(argv[1], "-T") == 0)
39: {
40: Debug++;
41: argc--;
42: argv++;
43: }
44: # endif DEBUG
45: if (argc > 1)
46: aliases = argv[1];
47:
48: strcpy(dirbuf, aliases);
49: strcat(dirbuf, ".dir");
50: strcpy(pagbuf, aliases);
51: strcat(pagbuf, ".pag");
52: f = creat(dirbuf, 0666);
53: if (f < 0) {
54: perror(dirbuf);
55: exit(1);
56: }
57: close(f);
58: f = creat(pagbuf, 0666);
59: if (f < 0) {
60: perror(pagbuf);
61: exit(1);
62: }
63: close(f);
64: if (dbminit(aliases) < 0)
65: exit(1);
66: if (freopen(aliases, "r", stdin) == 0) {
67: perror(aliases);
68: exit(1);
69: }
70:
71: /* read and interpret lines */
72: LineNo = 0;
73: naliases = 0;
74: bytes = 0;
75: longest = 0;
76: skipping = FALSE;
77: while (fgets(line, sizeof (line), stdin) != NULL)
78: {
79: LineNo++;
80: switch (line[0])
81: {
82: case '#':
83: case '\n':
84: case '\0':
85: skipping = FALSE;
86: continue;
87:
88: case ' ':
89: case '\t':
90: if (!skipping)
91: usrerr("Non-continuation line starts with space");
92: skipping = TRUE;
93: continue;
94: }
95: skipping = FALSE;
96:
97: /* process the LHS */
98: for (p = line; *p != '\0' && *p != ':' && *p != '\n'; p++)
99: continue;
100: if (*p == '\0' || *p == '\n')
101: {
102: syntaxerr:
103: usrerr("missing colon");
104: continue;
105: }
106: *p++ = '\0';
107: if (parse(line, &al, 1) == NULL)
108: {
109: *--p = ':';
110: goto syntaxerr;
111: }
112: rhs = cp = p;
113: contin = FALSE;
114: for (;;)
115: {
116: register char c;
117:
118: /* do parsing & compression of addresses */
119: c = *p;
120: while (c != '\0')
121: {
122: p2 = p;
123: while (*p != '\n' && *p != ',' && *p != '\0')
124: p++;
125: c = *p;
126: *p++ = '\0';
127: if (prescan(p2, cp, &line[sizeof line - 1], ',') == NULL)
128: continue;
129: contin = FALSE;
130: if (parse(cp, &bl, -1) != NULL)
131: cp += strlen(cp);
132: if (c == ',')
133: {
134: *cp++ = ',';
135: contin = TRUE;
136: }
137: }
138:
139: /* see if there should be a continuation line */
140: if (!contin)
141: break;
142:
143: /* read continuation line */
144: if (fgets(line2, sizeof (line2), stdin) == NULL)
145: break;
146: LineNo++;
147:
148: if (!isspace(line2[0]))
149: usrerr("continuation line missing");
150:
151: p = line2;
152: }
153: if (al.q_mailer != &Mailer[0])
154: {
155: usrerr("cannot alias non-local names");
156: continue;
157: }
158: naliases++;
159: key.dsize = strlen(al.q_user) + 1;
160: key.dptr = al.q_user;
161: content.dsize = strlen(rhs) + 1;
162: if (content.dsize > longest)
163: longest = content.dsize;
164: content.dptr = rhs;
165: bytes += key.dsize + content.dsize;
166: if (store(key, content), 0)
167: /* if (f = store(key, content)) */
168: usrerr("Dbm internal error return %d from store\n", f);
169: }
170: fprintf(stderr, "%d aliases, %d bytes, longest %d bytes, %d errors\n",
171: naliases, bytes, longest, Errors);
172:
173: exit(ExitStat);
174: }
175:
176: usrerr(fmt, a, b, c, d, e)
177: char *fmt;
178: {
179: Errors++;
180: fprintf(stderr, "line %d: ", LineNo);
181: fprintf(stderr, fmt, a, b, c, d, e);
182: fprintf(stderr, "\n");
183: return (-1);
184: }
185:
186: syserr(fmt, a, b, c, d, e)
187: char *fmt;
188: {
189: return (usrerr(fmt, a, b, c, d, e));
190: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.