]>
Commit | Line | Data |
---|---|---|
3fb06882 | 1 | /* $Header$ |
2 | */ | |
3 | ||
4 | #include <stdio.h> | |
5 | #include <strings.h> | |
6 | #include <ctype.h> | |
7 | #include <sys/time.h> | |
8 | #include <moira.h> | |
9 | #include <moira_site.h> | |
10 | ||
11 | ||
12 | ##define WHO 11859 /* root */ | |
13 | ##define PROG "emp-tape" | |
14 | ||
15 | #define MAX_ID_VALUE 32766 | |
16 | #define MIN_ID_VALUE 101 | |
17 | ||
18 | /* File format is: | |
19 | ||
20 | 0-8 id number | |
21 | 9-38 name | |
22 | 39-62 office address | |
23 | 63-74 phone1 | |
24 | 75-86 phone2 | |
25 | 87-106 dept | |
26 | 107-156 title | |
27 | 157-186 username | |
28 | 187-241 host | |
29 | ||
30 | */ | |
31 | ||
32 | #define LOC_ID 0 | |
33 | #define LOC_NAME 9 | |
34 | #define LOC_OFFICE 39 | |
35 | #define LOC_PHONE 63 | |
36 | #define LOC_PHONE2 75 | |
37 | #define LOC_DEPT 87 | |
38 | #define LOC_TITLE 107 | |
39 | #define LOC_USERNAME 157 | |
40 | #define LOC_HOST 187 | |
41 | ||
42 | #define LEN_ID 9 | |
43 | #define LEN_NAME 30 | |
44 | #define LEN_OFFICE 24 | |
45 | #define LEN_PHONE 12 | |
46 | #define LEN_PHONE2 12 | |
47 | #define LEN_DEPT 20 | |
48 | #define LEN_TITLE 50 | |
49 | #define LEN_USERNAME 30 | |
50 | #define LEN_HOST 55 | |
51 | ||
52 | ||
53 | struct entry { | |
54 | char *name; | |
55 | char *last; | |
56 | char *first; | |
57 | char *middle; | |
58 | char *title; | |
59 | char *class; | |
60 | char *id; | |
61 | char *eid; | |
62 | char *dept; | |
63 | char *address; | |
64 | char *phone; | |
65 | char *phone2; | |
66 | char *email; | |
67 | }; | |
68 | ||
69 | ||
70 | char *whoami; | |
71 | int newfinger = 0; | |
72 | int addxuser = 0; | |
73 | ||
74 | ||
75 | main(argc, argv) | |
76 | int argc; | |
77 | char **argv; | |
78 | ##{ | |
79 | FILE *in; | |
80 | struct entry *e, *get_next_entry(); | |
81 | int i, wait = 0; | |
82 | char buf[BUFSIZ], *file = NULL; | |
83 | ||
84 | whoami = rindex(argv[0], '/'); | |
85 | if (whoami) | |
86 | whoami++; | |
87 | else | |
88 | whoami = argv[0]; | |
89 | ||
90 | for (i = 1; i < argc; i++) { | |
91 | if (!strcmp(argv[i], "-w")) | |
92 | wait++; | |
93 | else if (!strcmp(argv[i], "-D")) | |
94 | setenv("ING_SET", "set printqry"); | |
95 | else if (!strcmp(argv[i], "-n")) | |
96 | newfinger++; | |
97 | else if (!strcmp(argv[i], "-u")) | |
98 | addxuser++; | |
99 | else if (file != NULL) | |
100 | fprintf(stderr, "Usage: %s [-w] [-D] [-n] [-u] inputfile\n", whoami); | |
101 | else | |
102 | file = argv[i]; | |
103 | } | |
104 | ||
105 | in = fopen(file, "r"); | |
106 | if (in == NULL) { | |
107 | fprintf(stderr, "Unable to open %s for input\n", file); | |
108 | exit(1); | |
109 | } | |
110 | ||
111 | ## ingres sms | |
112 | ## range of u is users | |
113 | ||
114 | while (e = get_next_entry(in)) { | |
115 | process_entry(e); | |
116 | if (wait) { | |
117 | printf("Next"); | |
118 | fflush(stdout); | |
119 | gets(buf); | |
120 | } | |
121 | } | |
122 | ||
123 | ## exit | |
124 | exit(0); | |
125 | ##} | |
126 | ||
127 | ||
128 | char *substr(buf, key) | |
129 | char *buf; | |
130 | char *key; | |
131 | { | |
132 | int l; | |
133 | ||
134 | for (l = strlen(key); *buf; buf++) | |
135 | if (!strncmp(buf, key, l)) | |
136 | return(buf); | |
137 | return(NULL); | |
138 | } | |
139 | ||
140 | ||
141 | struct entry *get_next_entry(in) | |
142 | FILE *in; | |
143 | { | |
144 | static struct entry e; | |
145 | static char buf[BUFSIZ], mid[16], eid[16], email[256]; | |
146 | static char name[LEN_NAME+1], sname[LEN_NAME+1], id[LEN_ID+1]; | |
147 | static char office[LEN_OFFICE+1], phone[LEN_PHONE+1], phone2[LEN_PHONE2+1]; | |
148 | static char dept[LEN_DEPT+1], title[LEN_TITLE+1], username[LEN_USERNAME+1]; | |
149 | static char host[LEN_HOST+1]; | |
150 | int ends_sr, ends_jr, ends_iii, ends_iv; | |
151 | char *p; | |
152 | ||
153 | if (fgets(buf, sizeof(buf), in) == NULL) | |
154 | return((struct entry *)NULL); | |
155 | ||
156 | strncpy(id, &buf[LOC_ID], LEN_ID); id[LEN_ID] = 0; | |
157 | strncpy(name, &buf[LOC_NAME], LEN_NAME); name[LEN_NAME] = 0; | |
158 | strncpy(office, &buf[LOC_OFFICE], LEN_OFFICE); office[LEN_OFFICE] = 0; | |
159 | strncpy(phone, &buf[LOC_PHONE], LEN_PHONE); phone[LEN_PHONE] = 0; | |
160 | strncpy(phone2, &buf[LOC_PHONE2], LEN_PHONE2); phone2[LEN_PHONE2] = 0; | |
161 | strncpy(dept, &buf[LOC_DEPT], LEN_DEPT); dept[LEN_DEPT] = 0; | |
162 | strncpy(title, &buf[LOC_TITLE], LEN_TITLE); title[LEN_TITLE] = 0; | |
163 | strncpy(username, &buf[LOC_USERNAME], LEN_USERNAME); username[LEN_USERNAME] = 0; | |
164 | strncpy(host, &buf[LOC_HOST], LEN_HOST); host[LEN_HOST] = 0; | |
165 | ||
166 | strcpy(sname, name); | |
167 | e.name = strtrim(sname); | |
168 | p = index(name, ','); | |
169 | if (p) | |
170 | *p = 0; | |
171 | e.last = strtrim(name); | |
172 | if (p) { | |
173 | p++; | |
174 | while (isspace(*p)) | |
175 | p++; | |
176 | e.first = p; | |
177 | if (p = index(e.first, ' ')) { | |
178 | *p = 0; | |
179 | e.first = strtrim(e.first); | |
180 | e.middle = strtrim(p + 1); | |
181 | } else { | |
182 | e.first = strtrim(e.first); | |
183 | e.middle = ""; | |
184 | } | |
185 | } else { | |
186 | e.first = ""; | |
187 | e.middle = ""; | |
188 | } | |
189 | ends_sr = ends_jr = ends_iii = ends_iv = 0; | |
190 | LookForSt(e.last); | |
191 | LookForO(e.last); | |
192 | LookForJrAndIII(e.last, &ends_sr, &ends_jr, &ends_iii, &ends_iv); | |
193 | LookForJrAndIII(e.first, &ends_sr, &ends_jr, &ends_iii, &ends_iv); | |
194 | FixCase(e.last); | |
195 | FixCase(e.first); | |
196 | FixCase(e.middle); | |
197 | ||
198 | e.id = id; | |
199 | e.eid = eid; | |
200 | EncryptID(e.eid, e.id, e.first, e.last); | |
201 | ||
202 | e.address = strtrim(office); | |
203 | e.phone = strtrim(phone); | |
204 | e.phone2 = strtrim(phone2); | |
205 | e.dept = strtrim(dept); | |
206 | e.title = strtrim(title); | |
207 | ||
208 | e.class = "MITS"; | |
209 | if (!strcmp(e.dept, "PROJECT ATHENA")) | |
210 | e.class = "STAFF"; | |
211 | else if (substr(e.title, "PROF") || substr(e.title, "LECTURE")) | |
212 | e.class = "FACULTY"; | |
213 | else if (!strcmp(e.title, "VISITING SCIENTIST")) | |
214 | e.class = "VSCIENTI"; | |
215 | ||
216 | strcpy(email, strtrim(username)); | |
217 | if (host[0] == '@') | |
218 | strncat(email, strtrim(host)); | |
219 | e.email = email; | |
220 | ||
221 | return(&e); | |
222 | } | |
223 | ||
224 | ||
225 | process_entry(e) | |
226 | struct entry *e; | |
227 | ##{ | |
228 | int changed, nochange; | |
229 | char buf[BUFSIZ], *from, *to; | |
230 | ## char *first, *last, *eid, *sid, *name, *title, *phone2; | |
231 | ## char class[9], oaddr[25], ophone[17], dept[128]; | |
232 | ## int id, status; | |
233 | ||
234 | first = e->first; | |
235 | if (strlen(first) > 16) | |
236 | first[16] = 0; | |
237 | last = e->last; | |
238 | if (strlen(last) > 16) | |
239 | last[16] = 0; | |
240 | eid = e->eid; | |
241 | id = 0; | |
242 | ## repeat retrieve (id = u.users_id, class = u.mit_year, oaddr = u.office_addr, | |
243 | ## ophone = u.office_phone, dept = u.mit_dept, status = u.#status) | |
244 | ## where u.#last = @last and u.#first = @first and u.mit_id = @eid | |
245 | if (id == 0) { | |
246 | com_err(whoami, 0, "New user found: %s %s\n", first, last); | |
247 | return; | |
248 | } | |
249 | eid = e->id; | |
250 | ## repeat replace u (mit_id=@eid) where u.users_id = @id | |
251 | sid = e->id; | |
252 | name = e->name; | |
253 | strcpy(dept, e->dept); | |
254 | title = e->title; | |
255 | strcpy(oaddr, e->address); | |
256 | phone2 = e->phone2; | |
257 | ## repeat replace u (xname = @name, xdept = @dept, xtitle = @title, | |
258 | ## xaddress = @oaddr, xphone1 = @ophone, xphone2 = @phone2, | |
259 | ## xmodtime = "now") | |
260 | ## where u.users_id = @id | |
261 | ##} | |
262 |