]> andersk Git - moira.git/blame - regtape/students.dc
sms -> moira
[moira.git] / regtape / students.dc
CommitLineData
093c49c9 1/* $Header$
2 */
3
4#include <stdio.h>
5#include <strings.h>
6#include <ctype.h>
7#include <sys/time.h>
932028de 8#include <moira.h>
9#include <moira_site.h>
093c49c9 10
11
5e2b5b5f 12##define WHO 11859 /* root */
13##define PROG "stu-tape"
14
15#define MAX_ID_VALUE 32766
16#define MIN_ID_VALUE 101
17
093c49c9 18/* File format is:
19
200-29 name
2130-38 id number
2250-54 school code
2355-79 year
2480-109 address
25110-124 room
26125-144 city
27145-158 state
28159-168 dorm phone
29169-212 home address
30213-232 home city
31243-251 mit phone (?)
32*/
33
34#define LOC_NAME 0
35#define LOC_ID 30
36#define LOC_COURSE 50
37#define LOC_YEAR 55
38#define LOC_ADDRESS 80
39#define LOC_DORM_ROOM 110
40#define LOC_CITY 125
41#define LOC_STATE 145
42#define LOC_DORM_PHONE 159
43#define LOC_MIT_PHONE1 243
44
45#define LEN_NAME 29
46#define LEN_ID 9
47#define LEN_COURSE 3
48#define LEN_YEAR 23
5e2b5b5f 49#define LEN_ADDRESS 26
093c49c9 50#define LEN_DORM_ROOM 14
5e2b5b5f 51#define LEN_CITY 19
093c49c9 52#define LEN_STATE 12
53#define LEN_DPHONE 9
54#define LEN_MPHONE 9
55
56struct entry {
57 char *last;
58 char *first;
59 char *middle;
60 char *title;
61 char *id;
62 char *eid;
63 char *course;
64 char *year;
65 char *address;
66 char *dorm;
67 char *city;
68 char *state;
69 char *dphone;
70 char *mphone;
71 char *class;
093c49c9 72};
73
74
75char *whoami;
a97bc039 76int newfinger = 0;
093c49c9 77
78
79main(argc, argv)
80int argc;
81char **argv;
5e2b5b5f 82##{
093c49c9 83 FILE *in;
84 struct entry *e, *get_next_entry();
a97bc039 85 int i, wait = 0;
86 char buf[BUFSIZ], *file = NULL;
093c49c9 87
88 whoami = rindex(argv[0], '/');
89 if (whoami)
90 whoami++;
91 else
92 whoami = argv[0];
93
a97bc039 94 for (i = 1; i < argc; i++) {
95 if (!strcmp(argv[i], "-w"))
96 wait++;
97 else if (!strcmp(argv[i], "-D"))
98 setenv("ING_SET", "set printqry");
99 else if (!strcmp(argv[i], "-n"))
100 newfinger++;
101 else if (file != NULL)
102 fprintf(stderr, "Usage: %s [-w] [-D] [-n] inputfile\n", whoami);
103 else
104 file = argv[i];
105 }
093c49c9 106
a97bc039 107 in = fopen(file, "r");
093c49c9 108 if (in == NULL) {
a97bc039 109 fprintf(stderr, "Unable to open %s for input\n", file);
093c49c9 110 exit(1);
111 }
112
5e2b5b5f 113## ingres sms
114## range of u is users
115
093c49c9 116 while (e = get_next_entry(in)) {
117 process_entry(e);
118 if (wait) {
119 printf("Next");
120 fflush(stdout);
121 gets(buf);
122 }
123 }
124
5e2b5b5f 125## exit
093c49c9 126 exit(0);
5e2b5b5f 127##}
093c49c9 128
129
130struct entry *get_next_entry(in)
131FILE *in;
132{
133 static struct entry e;
134 static char buf[BUFSIZ], eid[16], classbuf[10], titlebuf[12];
135 static int year = 0;
b2916c40 136 int ends_jr, ends_iii, ends_iv, ends_sr;
093c49c9 137 char *p;
138
139 if (year == 0) {
140 struct tm *tm;
141 struct timeval tv;
142
143 gettimeofday(&tv, NULL);
144 tm = localtime(&tv.tv_sec);
145 year = tm->tm_year;
146 if (tm->tm_mon > 5)
147 year++;
148 }
149
22a6d0dc 150 if (fgets(buf, sizeof(buf), in) == NULL)
151 return((struct entry *)NULL);
093c49c9 152 buf[LEN_NAME] = 0;
153 p = index(&buf[LOC_NAME], ',');
154 if (p)
155 *p = 0;
156 e.last = strtrim(&buf[LOC_NAME]);
157 if (p) {
158 e.first = p + 2;
159 if (p = index(e.first, ' ')) {
160 *p = 0;
161 e.middle = strtrim(p + 1);
162 } else
163 e.middle = "";
164 } else
165 e.first = "";
166 e.first = strtrim(e.first);
b2916c40 167 ends_jr = ends_iii = ends_iv = ends_sr = 0;
093c49c9 168 LookForSt(e.last);
169 LookForO(e.last);
b2916c40 170 LookForJrAndIII(e.last, &ends_sr, &ends_jr, &ends_iii, &ends_iv);
171 LookForJrAndIII(e.first, &ends_sr, &ends_jr, &ends_iii, &ends_iv);
093c49c9 172 FixCase(e.last);
173 FixCase(e.first);
174 FixCase(e.middle);
175 e.title = titlebuf;
176 titlebuf[0] = 0;
b2916c40 177 AppendJrOrIII(titlebuf, &ends_sr, &ends_jr, &ends_iii, &ends_iv);
093c49c9 178
179 e.id = &buf[LOC_ID];
180 e.id[LEN_ID] = 0;
181 e.eid = eid;
182 EncryptID(e.eid, e.id, e.first, e.last);
183
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')
189 e.class = "G";
190 else {
191 e.class = classbuf;
192 sprintf(classbuf, "%d", year + 4 - atoi(e.year) + 1900);
193 }
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;
206 return(&e);
207}
208
209
093c49c9 210process_entry(e)
211struct entry *e;
5e2b5b5f 212##{
a97bc039 213 int changed, nochange;
5e2b5b5f 214 char buf[BUFSIZ], *from, *to;
215## char *first, *last, *eid;
216## char class[9], haddr[81], hphone[17], ophone[13], dept[13];
217## int id;
218
219 first = e->first;
9e4455c2 220 if (strlen(first) > 16)
221 first[16] = 0;
5e2b5b5f 222 last = e->last;
9e4455c2 223 if (strlen(last) > 16)
224 last[16] = 0;
5e2b5b5f 225 eid = e->eid;
226 id = 0;
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
231 if (id == 0) {
232 newuser(e);
093c49c9 233 return;
234 }
a262e022 235 if (strcmp(e->class, strtrim(class)) &&
236 strcmp(class, "STAFF") && strcmp(class, "SIPB")) {
a97bc039 237 com_err(whoami, 0, "updating class for user %s %s from %s to %s",
238 first, last, class, e->class);
5e2b5b5f 239 strcpy(class, e->class);
240## repeat replace u (mit_year = @class,
241## modtime = "now", modby = WHO, modwith = PROG)
fac211e8 242## where u.users_id = @id
093c49c9 243 }
a97bc039 244 changed = nochange = 0;
093c49c9 245 strcpy(buf, strtrim(e->address));
5e2b5b5f 246 e->dorm = strtrim(e->dorm);
093c49c9 247 if (*e->dorm) {
248 strcat(buf, " ");
5e2b5b5f 249 strcat(buf, e->dorm);
093c49c9 250 }
5e2b5b5f 251 e->city = strtrim(e->city);
093c49c9 252 if (*e->city) {
253 strcat(buf, " ");
5e2b5b5f 254 strcat(buf, e->city);
093c49c9 255 }
5e2b5b5f 256 FixCase(buf);
257 e->state = strtrim(e->state);
093c49c9 258 if (*e->state) {
259 strcat(buf, " ");
5e2b5b5f 260 strcat(buf, e->state);
093c49c9 261 }
5e2b5b5f 262 while (to = index(buf, ','))
263 *to = ';';
264 while (to = index(buf, ':'))
265 *to = ';';
a97bc039 266 if (newfinger) {
267 if (haddr[0] == ' ') {
268 strncpy(haddr, buf, 80);
269 haddr[80] = 0;
270 changed++;
271 } else if (strncmp(strtrim(haddr), buf, 80))
272 nochange++;
273 } else {
274 if (strncmp(strtrim(haddr), buf, 80))
275 changed++;
5e2b5b5f 276 strncpy(haddr, buf, 80);
a97bc039 277 haddr[80] = 0;
093c49c9 278 }
279 from = e->dphone;
280 to = buf;
281 while (*from) {
282 if (isdigit(*from))
283 *to++ = *from;
284 from++;
285 }
286 *to = 0;
a97bc039 287 if (newfinger) {
288 if (hphone[0] == ' ') {
289 strncpy(hphone, buf, 16);
290 hphone[16] = 0;
291 } else if (strncmp(strtrim(hphone), buf, 16))
292 nochange++;
293 } else {
294 if (strncmp(strtrim(hphone), buf, 16))
295 changed++;
5e2b5b5f 296 strncpy(hphone, buf, 16);
a97bc039 297 hphone[16] = 0;
093c49c9 298 }
299 from = e->mphone;
300 to = buf;
301 while (*from) {
302 if (isdigit(*from))
303 *to++ = *from;
304 from++;
305 }
306 *to = 0;
a97bc039 307 if (newfinger) {
308 if (ophone[0] == ' ') {
309 strncpy(ophone, buf, 12);
310 ophone[12] = 0;
311 } else if (strncmp(strtrim(ophone), buf, 12))
312 nochange++;
313 } else {
314 if (strncmp(strtrim(ophone), buf, 12))
315 changed++;
5e2b5b5f 316 strncpy(ophone, buf, 12);
a97bc039 317 ophone[12] = 0;
093c49c9 318 }
319 e->course = strtrim(e->course);
a97bc039 320 if (newfinger) {
321 if (dept[0] == ' ') {
322 strncpy(dept, e->course, 12);
323 dept[12] = 0;
324 } else if (strncmp(strtrim(dept), e->course, 11))
325 nochange++;
326 } else {
327 if (strncmp(strtrim(dept), e->course, 11))
328 changed++;
5e2b5b5f 329 strncpy(dept, e->course, 12);
a97bc039 330 dept[12] = 0;
093c49c9 331 }
332 if (changed) {
5e2b5b5f 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
a97bc039 338 } else if (nochange)
339 com_err(whoami, 0, "NOT updating finger for %s %s", first, last);
5e2b5b5f 340##}
093c49c9 341
5e2b5b5f 342
343newuser(e)
093c49c9 344struct entry *e;
5e2b5b5f 345##{
346 char buf[512], *from, *to;
347## int id, uid;
348## char *last, *first, *class, *middle, login[9], *eid, fullname[65];
349## char haddr[81], hphone[17], ophone[13], dept[13];
350
351
352 strcpy(buf, strtrim(e->address));
353 if (*e->dorm) {
354 strcat(buf, " ");
355 strcat(buf, strtrim(e->dorm));
356 }
357 if (*e->city) {
358 strcat(buf, " ");
359 strcat(buf, strtrim(e->city));
360 }
361 if (*e->state) {
362 strcat(buf, " ");
363 strcat(buf, strtrim(e->state));
364 }
365 strncpy(haddr, buf, 80);
366 from = e->dphone;
367 to = buf;
368 while (*from) {
369 if (isdigit(*from))
370 *to++ = *from;
371 from++;
372 }
373 *to = 0;
374 strncpy(hphone, buf, 16);
375 from = e->mphone;
376 to = buf;
377 while (*from) {
378 if (isdigit(*from))
379 *to++ = *from;
380 from++;
381 }
382 *to = 0;
383 strncpy(ophone, buf, 12);
384 e->course = strtrim(e->course);
385 strncpy(dept, e->course, 12);
386
387
388 id = set_next_object_id("users_id");
389 uid = set_next_object_id("uid");
390 sprintf(login, "#%d", uid);
391 last = e->last;
392 first = e->first;
393 middle = e->middle;
394 eid = e->eid;
395 class = e->class;
396 if (*middle)
397 sprintf(fullname, "%s %s %s", first, middle, last);
398 else
399 sprintf(fullname, "%s %s", first, last);
400
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,
408## potype = "NONE")
093c49c9 409 com_err(whoami, 0, "adding user %s %s", e->first, e->last);
5e2b5b5f 410##}
411
412
413set_next_object_id(object)
414 char *object;
415##{
416## char *name;
417## int rowcount, exists, value;
418
419 name = object;
420## begin transaction
421## repeat retrieve (value = values.#value) where values.#name = @name
422## inquire_equel(rowcount = "rowcount")
423 if (rowcount != 1) {
424## abort
425 return(0);
093c49c9 426 }
5e2b5b5f 427
428## retrieve (exists = any(users.name where users.name = value))
429## inquire_equel(rowcount = "rowcount")
430 if (rowcount != 1) {
431## abort
432 return(0);
433 }
434 while (exists) {
435 value++;
436 if (value > MAX_ID_VALUE)
437 value = MIN_ID_VALUE;
438## retrieve (exists = any(users.name where users.name = value))
439 }
440
441## repeat replace values (#value = @value) where values.#name = @name
442## end transaction
443 return(value);
444##}
445
446
This page took 0.266469 seconds and 5 git commands to generate.