12 ##define WHO 11859 /* root */
13 ##define PROG "stu-tape"
15 #define MAX_ID_VALUE 32766
16 #define MIN_ID_VALUE 101
38 #define LOC_ADDRESS 80
39 #define LOC_DORM_ROOM 110
42 #define LOC_DORM_PHONE 159
43 #define LOC_MIT_PHONE1 243
49 #define LEN_ADDRESS 26
50 #define LEN_DORM_ROOM 14
84 struct entry *e, *get_next_entry();
86 char buf[BUFSIZ], *file = NULL;
88 whoami = rindex(argv[0], '/');
94 for (i = 1; i < argc; i++) {
95 if (!strcmp(argv[i], "-w"))
97 else if (!strcmp(argv[i], "-D"))
98 setenv("ING_SET", "set printqry");
99 else if (!strcmp(argv[i], "-n"))
101 else if (file != NULL)
102 fprintf(stderr, "Usage: %s [-w] [-D] [-n] inputfile\n", whoami);
107 in = fopen(file, "r");
109 fprintf(stderr, "Unable to open %s for input\n", file);
114 ## range of u is users
116 while (e = get_next_entry(in)) {
130 struct entry *get_next_entry(in)
133 static struct entry e;
134 static char buf[BUFSIZ], eid[16], classbuf[10], titlebuf[12];
136 int ends_jr, ends_iii, ends_iv, ends_sr;
143 gettimeofday(&tv, NULL);
144 tm = localtime(&tv.tv_sec);
150 if (fgets(buf, sizeof(buf), in) == NULL)
151 return((struct entry *)NULL);
153 p = index(&buf[LOC_NAME], ',');
156 e.last = strtrim(&buf[LOC_NAME]);
159 if (p = index(e.first, ' ')) {
161 e.middle = strtrim(p + 1);
166 e.first = strtrim(e.first);
167 ends_jr = ends_iii = ends_iv = ends_sr = 0;
170 LookForJrAndIII(e.last, &ends_sr, &ends_jr, &ends_iii, &ends_iv);
171 LookForJrAndIII(e.first, &ends_sr, &ends_jr, &ends_iii, &ends_iv);
177 AppendJrOrIII(titlebuf, &ends_sr, &ends_jr, &ends_iii, &ends_iv);
182 EncryptID(e.eid, e.id, e.first, e.last);
184 e.course = &buf[LOC_COURSE];
185 e.course[LEN_COURSE] = 0;
186 e.year = &buf[LOC_YEAR];
187 e.year[LEN_YEAR] = 0;
188 if (e.year[0] == 'G')
192 sprintf(classbuf, "%d", year + 4 - atoi(e.year) + 1900);
194 e.address = &buf[LOC_ADDRESS];
195 e.address[LEN_ADDRESS] = 0;
196 e.dorm = &buf[LOC_DORM_ROOM];
197 e.dorm[LEN_DORM_ROOM] = 0;
198 e.city = &buf[LOC_CITY];
199 e.city[LEN_CITY] = 0;
200 e.state = &buf[LOC_STATE];
201 e.state[LEN_STATE] = 0;
202 e.dphone = &buf[LOC_DORM_PHONE];
203 e.dphone[LEN_DPHONE] = 0;
204 e.mphone = &buf[LOC_MIT_PHONE1];
205 e.mphone[LEN_MPHONE] = 0;
213 int changed, nochange;
214 char buf[BUFSIZ], *from, *to;
215 ## char *first, *last, *eid;
216 ## char class[9], haddr[81], hphone[17], ophone[13], dept[13];
223 ## repeat retrieve (id = u.users_id, class = u.mit_year, haddr = u.home_addr,
224 ## hphone = u.home_phone, ophone = u.office_phone,
225 ## dept = u.mit_dept)
226 ## where u.#last = @last and u.#first = @first and u.mit_id = @eid
231 if (strcmp(e->class, strtrim(class)) &&
232 strcmp(class, "STAFF") && strcmp(class, "SIPB")) {
233 com_err(whoami, 0, "updating class for user %s %s from %s to %s",
234 first, last, class, e->class);
235 strcpy(class, e->class);
236 ## repeat replace u (mit_year = @class,
237 ## modtime = "now", modby = WHO, modwith = PROG)
238 ## where u.users_id = @id
240 changed = nochange = 0;
241 strcpy(buf, strtrim(e->address));
242 e->dorm = strtrim(e->dorm);
245 strcat(buf, e->dorm);
247 e->city = strtrim(e->city);
250 strcat(buf, e->city);
253 e->state = strtrim(e->state);
256 strcat(buf, e->state);
258 while (to = index(buf, ','))
260 while (to = index(buf, ':'))
263 if (haddr[0] == ' ') {
264 strncpy(haddr, buf, 80);
267 } else if (strncmp(strtrim(haddr), buf, 80))
270 if (strncmp(strtrim(haddr), buf, 80))
272 strncpy(haddr, buf, 80);
284 if (hphone[0] == ' ') {
285 strncpy(hphone, buf, 16);
287 } else if (strncmp(strtrim(hphone), buf, 16))
290 if (strncmp(strtrim(hphone), buf, 16))
292 strncpy(hphone, buf, 16);
304 if (ophone[0] == ' ') {
305 strncpy(ophone, buf, 12);
307 } else if (strncmp(strtrim(ophone), buf, 12))
310 if (strncmp(strtrim(ophone), buf, 12))
312 strncpy(ophone, buf, 12);
315 e->course = strtrim(e->course);
317 if (dept[0] == ' ') {
318 strncpy(dept, e->course, 12);
320 } else if (strncmp(strtrim(dept), e->course, 11))
323 if (strncmp(strtrim(dept), e->course, 11))
325 strncpy(dept, e->course, 12);
329 com_err(whoami, 0, "updating finger for %s %s", first, last);
330 ## repeat replace u (home_addr = @haddr, home_phone = @hphone,
331 ## office_phone = @ophone, #mit_dept = @dept,
332 ## fmodtime = "now", fmodby = WHO, fmodwith = PROG)
333 ## where u.users_id = @id
335 com_err(whoami, 0, "NOT updating finger for %s %s", first, last);
342 char buf[512], *from, *to;
344 ## char *last, *first, *class, *middle, login[9], *eid, fullname[65];
345 ## char haddr[81], hphone[17], ophone[13], dept[13];
348 strcpy(buf, strtrim(e->address));
351 strcat(buf, strtrim(e->dorm));
355 strcat(buf, strtrim(e->city));
359 strcat(buf, strtrim(e->state));
361 strncpy(haddr, buf, 80);
370 strncpy(hphone, buf, 16);
379 strncpy(ophone, buf, 12);
380 e->course = strtrim(e->course);
381 strncpy(dept, e->course, 12);
384 id = set_next_object_id("users_id");
385 uid = set_next_object_id("uid");
386 sprintf(login, "#%d", uid);
393 sprintf(fullname, "%s %s %s", first, middle, last);
395 sprintf(fullname, "%s %s", first, last);
397 ## append users (#login = login, users_id = id, #uid = uid, shell = "/bin/csh",
398 ## #last = last, #first = first, #middle = middle, status = 0,
399 ## #mit_id = eid, #mit_year = class,
400 ## modtime = "now", modby = WHO, modwith = PROG,
401 ## #fullname = fullname, home_addr = haddr, home_phone = hphone,
402 ## office_phone = ophone, #mit_dept = dept,
403 ## fmodtime = "now", fmodby = WHO, fmodwith = PROG,
405 com_err(whoami, 0, "adding user %s %s", e->first, e->last);
409 set_next_object_id(object)
413 ## int rowcount, exists, value;
417 ## repeat retrieve (value = values.#value) where values.#name = @name
418 ## inquire_equel(rowcount = "rowcount")
424 ## retrieve (exists = any(users.name where users.name = value))
425 ## inquire_equel(rowcount = "rowcount")
432 if (value > MAX_ID_VALUE)
433 value = MIN_ID_VALUE;
434 ## retrieve (exists = any(users.name where users.name = value))
437 ## repeat replace values (#value = @value) where values.#name = @name