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_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];
220 if (strlen(first) > 16)
223 if (strlen(last) > 16)
227 ## repeat retrieve (id = u.users_id, class = u.mit_year, haddr = u.home_addr,
228 ## hphone = u.home_phone, ophone = u.office_phone,
229 ## dept = u.mit_dept)
230 ## where u.#last = @last and u.#first = @first and u.mit_id = @eid
235 if (strcmp(e->class, strtrim(class)) &&
236 strcmp(class, "STAFF") && strcmp(class, "SIPB")) {
237 com_err(whoami, 0, "updating class for user %s %s from %s to %s",
238 first, last, class, e->class);
239 strcpy(class, e->class);
240 ## repeat replace u (mit_year = @class,
241 ## modtime = "now", modby = WHO, modwith = PROG)
242 ## where u.users_id = @id
244 changed = nochange = 0;
245 strcpy(buf, strtrim(e->address));
246 e->dorm = strtrim(e->dorm);
249 strcat(buf, e->dorm);
251 e->city = strtrim(e->city);
254 strcat(buf, e->city);
257 e->state = strtrim(e->state);
260 strcat(buf, e->state);
262 while (to = index(buf, ','))
264 while (to = index(buf, ':'))
267 if (haddr[0] == ' ') {
268 strncpy(haddr, buf, 80);
271 } else if (strncmp(strtrim(haddr), buf, 80))
274 if (strncmp(strtrim(haddr), buf, 80))
276 strncpy(haddr, buf, 80);
288 if (hphone[0] == ' ') {
289 strncpy(hphone, buf, 16);
291 } else if (strncmp(strtrim(hphone), buf, 16))
294 if (strncmp(strtrim(hphone), buf, 16))
296 strncpy(hphone, buf, 16);
308 if (ophone[0] == ' ') {
309 strncpy(ophone, buf, 12);
311 } else if (strncmp(strtrim(ophone), buf, 12))
314 if (strncmp(strtrim(ophone), buf, 12))
316 strncpy(ophone, buf, 12);
319 e->course = strtrim(e->course);
321 if (dept[0] == ' ') {
322 strncpy(dept, e->course, 12);
324 } else if (strncmp(strtrim(dept), e->course, 11))
327 if (strncmp(strtrim(dept), e->course, 11))
329 strncpy(dept, e->course, 12);
333 com_err(whoami, 0, "updating finger for %s %s", first, last);
334 ## repeat replace u (home_addr = @haddr, home_phone = @hphone,
335 ## office_phone = @ophone, #mit_dept = @dept,
336 ## fmodtime = "now", fmodby = WHO, fmodwith = PROG)
337 ## where u.users_id = @id
339 com_err(whoami, 0, "NOT updating finger for %s %s", first, last);
346 char buf[512], *from, *to;
348 ## char *last, *first, *class, *middle, login[9], *eid, fullname[65];
349 ## char haddr[81], hphone[17], ophone[13], dept[13];
352 strcpy(buf, strtrim(e->address));
355 strcat(buf, strtrim(e->dorm));
359 strcat(buf, strtrim(e->city));
363 strcat(buf, strtrim(e->state));
365 strncpy(haddr, buf, 80);
374 strncpy(hphone, buf, 16);
383 strncpy(ophone, buf, 12);
384 e->course = strtrim(e->course);
385 strncpy(dept, e->course, 12);
388 id = set_next_object_id("users_id");
389 uid = set_next_object_id("uid");
390 sprintf(login, "#%d", uid);
397 sprintf(fullname, "%s %s %s", first, middle, last);
399 sprintf(fullname, "%s %s", first, last);
401 ## append users (#login = login, users_id = id, #uid = uid, shell = "/bin/csh",
402 ## #last = last, #first = first, #middle = middle, status = 0,
403 ## #mit_id = eid, #mit_year = class,
404 ## modtime = "now", modby = WHO, modwith = PROG,
405 ## #fullname = fullname, home_addr = haddr, home_phone = hphone,
406 ## office_phone = ophone, #mit_dept = dept,
407 ## fmodtime = "now", fmodby = WHO, fmodwith = PROG,
409 com_err(whoami, 0, "adding user %s %s", e->first, e->last);
413 set_next_object_id(object)
417 ## int rowcount, exists, value;
421 ## repeat retrieve (value = values.#value) where values.#name = @name
422 ## inquire_equel(rowcount = "rowcount")
428 ## retrieve (exists = any(users.name where users.name = value))
429 ## inquire_equel(rowcount = "rowcount")
436 if (value > MAX_ID_VALUE)
437 value = MIN_ID_VALUE;
438 ## retrieve (exists = any(users.name where users.name = value))
441 ## repeat replace values (#value = @value) where values.#name = @name