9 #include <moira_site.h>
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_DPHONE 159
43 #define LOC_MPHONE 243
49 #define LEN_ADDRESS 30
50 #define LEN_DORM_ROOM 15
86 struct entry *e, *get_next_entry();
88 char buf[BUFSIZ], *file = NULL;
90 whoami = rindex(argv[0], '/');
96 for (i = 1; i < argc; i++) {
97 if (!strcmp(argv[i], "-w"))
99 else if (!strcmp(argv[i], "-D"))
100 setenv("ING_SET", "set printqry");
101 else if (!strcmp(argv[i], "-n"))
103 else if (!strcmp(argv[i], "-u"))
105 else if (file != NULL)
106 fprintf(stderr, "Usage: %s [-w] [-D] [-n] [-u] inputfile\n", whoami);
111 in = fopen(file, "r");
113 fprintf(stderr, "Unable to open %s for input\n", file);
118 ## range of u is users
120 while (e = get_next_entry(in)) {
134 struct entry *get_next_entry(in)
137 static struct entry e;
138 static char buf[BUFSIZ], eid[16], classbuf[10], titlebuf[12];
139 static char name[LEN_NAME+1], id[LEN_ID+1], course[LEN_COURSE+1];
140 static char year[LEN_YEAR+1], address[LEN_ADDRESS+1];
141 static char dorm_room[LEN_DORM_ROOM+1], city[LEN_CITY+1];
142 static char state[LEN_STATE+1], dphone[LEN_DPHONE+1], mphone[LEN_MPHONE+1];
143 static char sname[LEN_NAME+1], title[128];
144 static int nyear = 0;
145 int ends_jr, ends_iii, ends_iv, ends_sr;
152 gettimeofday(&tv, NULL);
153 tm = localtime(&tv.tv_sec);
159 if (fgets(buf, sizeof(buf), in) == NULL)
160 return((struct entry *)NULL);
162 strncpy(name, &buf[LOC_NAME], LEN_NAME); name[LEN_NAME] = 0;
163 strncpy(id, &buf[LOC_ID], LEN_ID); id[LEN_ID] = 0;
164 strncpy(course, &buf[LOC_COURSE], LEN_COURSE); course[LEN_COURSE] = 0;
165 strncpy(year, &buf[LOC_YEAR], LEN_YEAR); year[LEN_YEAR] = 0;
166 strncpy(address, &buf[LOC_ADDRESS], LEN_ADDRESS); address[LEN_ADDRESS] = 0;
167 strncpy(dorm_room, &buf[LOC_DORM_ROOM], LEN_DORM_ROOM); dorm_room[LEN_DORM_ROOM] = 0;
168 strncpy(city, &buf[LOC_CITY], LEN_CITY); city[LEN_CITY] = 0;
169 strncpy(state, &buf[LOC_STATE], LEN_STATE); state[LEN_STATE] = 0;
170 strncpy(dphone, &buf[LOC_DPHONE], LEN_DPHONE); dphone[LEN_DPHONE] = 0;
171 strncpy(mphone, &buf[LOC_MPHONE], LEN_MPHONE); mphone[LEN_MPHONE] = 0;
174 e.name = strtrim(sname);
175 p = index(name, ',');
178 e.last = strtrim(name);
184 if (p = index(e.first, ' ')) {
186 e.first = strtrim(e.first);
187 e.middle = strtrim(p + 1);
189 e.first = strtrim(e.first);
195 ends_jr = ends_iii = ends_iv = ends_sr = 0;
198 LookForJrAndIII(e.last, &ends_sr, &ends_jr, &ends_iii, &ends_iv);
199 LookForJrAndIII(e.first, &ends_sr, &ends_jr, &ends_iii, &ends_iv);
207 EncryptID(e.eid, e.id, e.first, e.last);
209 e.year = strtrim(year);
211 if (e.year[0] == 'G') {
213 sprintf(title, "Grad Student");
216 sprintf(classbuf, "%d", nyear + 4 - atoi(e.year) + 1900);
217 sprintf(title, "Undergrad (class of %s)", classbuf);
220 e.course = strtrim(course);
221 e.address = strtrim(address);
222 e.dorm = strtrim(dorm_room);
223 e.city = strtrim(city);
224 e.state = strtrim(state);
225 e.dphone = strtrim(dphone);
226 e.mphone = strtrim(mphone);
234 int changed, nochange;
235 char buf[BUFSIZ], *from, *to;
236 ## char *first, *last, *eid, *title, *sid, *name;
237 ## char class[9], haddr[128], hphone[17], ophone[13], dept[24];
241 if (strlen(first) > 16)
244 if (strlen(last) > 16)
248 ## repeat retrieve (id = u.users_id, class = u.mit_year, haddr = u.home_addr,
249 ## hphone = u.home_phone, ophone = u.office_phone,
250 ## status = u.#status, dept = u.mit_dept)
251 ## where u.#last = @last and u.#first = @first and u.mit_id = @eid
256 if (strcmp(e->class, strtrim(class)) &&
257 strcmp(class, "STAFF") && strcmp(class, "SIPB")) {
258 com_err(whoami, 0, "updating class for user %s %s from %s to %s",
259 first, last, class, e->class);
260 if (status == US_NOT_ALLOWED) status = US_NO_LOGIN_YET;
261 if (status == US_ENROLL_NOT_ALLOWED) status = US_ENROLLED;
262 strcpy(class, e->class);
263 ## repeat replace u (mit_year = @class, #status = @status, ugdefault = 1,
264 ## modtime = "now", modby = WHO, modwith = PROG)
265 ## where u.users_id = @id
267 changed = nochange = 0;
268 strcpy(buf, e->address);
271 strcat(buf, e->dorm);
275 strcat(buf, e->city);
280 strcat(buf, e->state);
282 while (to = index(buf, ','))
284 while (to = index(buf, ':'))
287 if (haddr[0] == ' ') {
288 strncpy(haddr, buf, 80);
291 } else if (strncmp(strtrim(haddr), buf, 80))
294 if (strncmp(strtrim(haddr), buf, 80))
296 strncpy(haddr, buf, 80);
308 if (hphone[0] == ' ') {
309 strncpy(hphone, buf, 16);
311 } else if (strncmp(strtrim(hphone), buf, 16))
314 if (strncmp(strtrim(hphone), buf, 16))
316 strncpy(hphone, buf, 16);
328 if (ophone[0] == ' ') {
329 strncpy(ophone, buf, 12);
331 } else if (strncmp(strtrim(ophone), buf, 12))
334 if (strncmp(strtrim(ophone), buf, 12))
336 strncpy(ophone, buf, 12);
339 e->course = e->course;
341 if (dept[0] == ' ') {
342 strncpy(dept, e->course, 12);
344 } else if (strncmp(strtrim(dept), e->course, 11))
347 if (strncmp(strtrim(dept), e->course, 11))
349 strncpy(dept, e->course, 12);
353 com_err(whoami, 0, "updating finger for %s %s", first, last);
354 ## repeat replace u (home_addr = @haddr, home_phone = @hphone,
355 ## office_phone = @ophone, #mit_dept = @dept, ugdefault = 1,
356 ## fmodtime = "now", fmodby = WHO, fmodwith = PROG)
357 ## where u.users_id = @id
358 } /* else if (nochange)
359 com_err(whoami, 0, "NOT updating finger for %s %s", first, last);
361 if (!changed && !strcmp(e->class, class)) {
362 ## repeat replace u (ugdefault = 1) where u.users_id = @id
367 strcpy(dept, e->course);
369 strcpy(haddr, e->address);
372 strcat(haddr, e->dorm);
376 strcat(haddr, e->city);
381 strcat(haddr, e->state);
384 ## append xuser (users_id = id, #id = sid, #name = name, #dept = dept,
385 ## #title = title, address = haddr, #phone1 = hphone,
386 ## #phone2 = ophone, modtime = "now")
394 char buf[512], *from, *to;
396 ## char *last, *first, *class, *middle, login[9], *eid, fullname[65];
397 ## char haddr[81], hphone[17], ophone[13], dept[24], *sid, *title;
400 strcpy(buf, e->address);
403 strcat(buf, e->dorm);
407 strcat(buf, e->city);
411 strcat(buf, e->state);
413 strncpy(haddr, buf, 80);
422 strncpy(hphone, buf, 16);
431 strncpy(ophone, buf, 12);
432 strncpy(dept, e->course, 12);
434 id = set_next_object_id("users_id");
435 uid = set_next_object_id("uid");
436 sprintf(login, "#%d", uid);
443 sprintf(fullname, "%s %s %s", first, middle, last);
445 sprintf(fullname, "%s %s", first, last);
447 ## append users (#login = login, users_id = id, #uid = uid, shell = "/bin/csh",
448 ## #last = last, #first = first, #middle = middle, status = 0,
449 ## #mit_id = eid, #mit_year = class, ugdefault = 1,
450 ## modtime = "now", modby = WHO, modwith = PROG,
451 ## #fullname = fullname, home_addr = haddr, home_phone = hphone,
452 ## office_phone = ophone, #mit_dept = dept,
453 ## fmodtime = "now", fmodby = WHO, fmodwith = PROG,
457 strcpy(fullname, e->name);
458 strcpy(dept, e->course);
460 strcpy(haddr, e->address);
463 strcat(haddr, e->dorm);
467 strcat(haddr, e->city);
472 strcat(haddr, e->state);
476 ## append xuser (users_id = id, #id = sid, #name = fullname, #dept = dept,
477 ## #title = title, address = haddr, #phone1 = hphone,
478 ## #phone2 = ophone, modtime = "now")
480 com_err(whoami, 0, "adding user %s %s", e->first, e->last);
484 set_next_object_id(object)
488 ## int rowcount, exists, value;
492 ## repeat retrieve (value = values.#value) where values.#name = @name
493 ## inquire_equel(rowcount = "rowcount")
499 ## retrieve (exists = any(users.name where users.name = value))
500 ## inquire_equel(rowcount = "rowcount")
507 if (value > MAX_ID_VALUE)
508 value = MIN_ID_VALUE;
509 ## retrieve (exists = any(users.name where users.name = value))
512 ## repeat replace values (#value = @value) where values.#name = @name