]>
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 "stu-tape" | |
14 | ||
15 | #define MAX_ID_VALUE 32766 | |
16 | #define MIN_ID_VALUE 101 | |
17 | ||
18 | /* File format is: | |
19 | ||
20 | 0-29 name | |
21 | 30-38 id number | |
22 | 50-54 school code | |
23 | 55-79 year | |
24 | 80-109 address | |
25 | 110-124 room | |
26 | 125-144 city | |
27 | 145-158 state | |
28 | 159-168 dorm phone | |
29 | 169-212 home address | |
30 | 213-232 home city | |
31 | 243-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_DPHONE 155 | |
43 | #define LOC_MPHONE 243 | |
44 | ||
45 | #define LEN_NAME 30 | |
46 | #define LEN_ID 9 | |
47 | #define LEN_COURSE 5 | |
48 | #define LEN_YEAR 25 | |
49 | #define LEN_ADDRESS 30 | |
50 | #define LEN_DORM_ROOM 15 | |
51 | #define LEN_CITY 20 | |
52 | #define LEN_STATE 10 | |
53 | #define LEN_DPHONE 12 | |
54 | #define LEN_MPHONE 10 | |
55 | ||
56 | struct entry { | |
57 | char *name; | |
58 | char *last; | |
59 | char *first; | |
60 | char *middle; | |
61 | char *title; | |
62 | char *id; | |
63 | char *eid; | |
64 | char *course; | |
65 | char *year; | |
66 | char *address; | |
67 | char *dorm; | |
68 | char *city; | |
69 | char *state; | |
70 | char *dphone; | |
71 | char *mphone; | |
72 | char *class; | |
73 | }; | |
74 | ||
75 | ||
76 | char *whoami; | |
77 | int newfinger = 0; | |
78 | int addxuser = 0; | |
79 | ||
80 | ||
81 | main(argc, argv) | |
82 | int argc; | |
83 | char **argv; | |
84 | ##{ | |
85 | FILE *in; | |
86 | struct entry *e, *get_next_entry(); | |
87 | int i, wait = 0; | |
88 | char buf[BUFSIZ], *file = NULL; | |
89 | ||
90 | whoami = rindex(argv[0], '/'); | |
91 | if (whoami) | |
92 | whoami++; | |
93 | else | |
94 | whoami = argv[0]; | |
95 | ||
96 | for (i = 1; i < argc; i++) { | |
97 | if (!strcmp(argv[i], "-w")) | |
98 | wait++; | |
99 | else if (!strcmp(argv[i], "-D")) | |
100 | setenv("ING_SET", "set printqry"); | |
101 | else if (!strcmp(argv[i], "-n")) | |
102 | newfinger++; | |
103 | else if (!strcmp(argv[i], "-u")) | |
104 | addxuser++; | |
105 | else if (file != NULL) | |
106 | fprintf(stderr, "Usage: %s [-w] [-D] [-n] [-u] inputfile\n", whoami); | |
107 | else | |
108 | file = argv[i]; | |
109 | } | |
110 | ||
111 | in = fopen(file, "r"); | |
112 | if (in == NULL) { | |
113 | fprintf(stderr, "Unable to open %s for input\n", file); | |
114 | exit(1); | |
115 | } | |
116 | ||
117 | ## ingres sms | |
118 | ## range of u is users | |
119 | ||
120 | while (e = get_next_entry(in)) { | |
121 | process_entry(e); | |
122 | if (wait) { | |
123 | printf("Next"); | |
124 | fflush(stdout); | |
125 | gets(buf); | |
126 | } | |
127 | } | |
128 | ||
129 | ## exit | |
130 | exit(0); | |
131 | ##} | |
132 | ||
133 | ||
134 | struct entry *get_next_entry(in) | |
135 | FILE *in; | |
136 | { | |
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; | |
146 | char *p; | |
147 | ||
148 | if (nyear == 0) { | |
149 | struct tm *tm; | |
150 | struct timeval tv; | |
151 | ||
152 | gettimeofday(&tv, NULL); | |
153 | tm = localtime(&tv.tv_sec); | |
154 | nyear = tm->tm_year; | |
155 | if (tm->tm_mon > 5) | |
156 | nyear++; | |
157 | } | |
158 | ||
159 | if (fgets(buf, sizeof(buf), in) == NULL) | |
160 | return((struct entry *)NULL); | |
161 | ||
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; | |
172 | ||
173 | strcpy(sname, name); | |
174 | e.name = strtrim(sname); | |
175 | p = index(name, ','); | |
176 | if (p) | |
177 | *p = 0; | |
178 | e.last = strtrim(name); | |
179 | if (p) { | |
180 | p++; | |
181 | while (isspace(*p)) | |
182 | p++; | |
183 | e.first = p; | |
184 | if (p = index(e.first, ' ')) { | |
185 | *p = 0; | |
186 | e.first = strtrim(e.first); | |
187 | e.middle = strtrim(p + 1); | |
188 | } else { | |
189 | e.first = strtrim(e.first); | |
190 | e.middle = ""; | |
191 | } | |
192 | } else { | |
193 | e.first = ""; | |
194 | e.middle = ""; | |
195 | } | |
196 | ends_jr = ends_iii = ends_iv = ends_sr = 0; | |
197 | LookForSt(e.last); | |
198 | LookForO(e.last); | |
199 | LookForJrAndIII(e.last, &ends_sr, &ends_jr, &ends_iii, &ends_iv); | |
200 | LookForJrAndIII(e.first, &ends_sr, &ends_jr, &ends_iii, &ends_iv); | |
201 | FixCase(e.last); | |
202 | FixCase(e.first); | |
203 | FixCase(e.middle); | |
204 | ||
205 | e.id = id; | |
206 | e.id[LEN_ID] = 0; | |
207 | e.eid = eid; | |
208 | EncryptID(e.eid, e.id, e.first, e.last); | |
209 | ||
210 | e.year = strtrim(year); | |
211 | e.title = title; | |
212 | if (e.year[0] == 'G') { | |
213 | e.class = "G"; | |
214 | sprintf(title, "Grad Student"); | |
215 | } else { | |
216 | e.class = classbuf; | |
217 | sprintf(classbuf, "%d", nyear + 4 - atoi(e.year) + 1900); | |
218 | sprintf(title, "Undergrad (class of %s)", classbuf); | |
219 | } | |
220 | ||
221 | e.course = strtrim(course); | |
222 | e.address = strtrim(address); | |
223 | e.dorm = strtrim(dorm_room); | |
224 | e.city = strtrim(city); | |
225 | e.state = strtrim(state); | |
226 | e.dphone = strtrim(dphone); | |
227 | e.mphone = strtrim(mphone); | |
228 | return(&e); | |
229 | } | |
230 | ||
231 | ||
232 | process_entry(e) | |
233 | struct entry *e; | |
234 | ##{ | |
235 | int changed, nochange; | |
236 | char buf[BUFSIZ], *from, *to; | |
237 | ## char *first, *last, *eid, *title, *sid, *name; | |
238 | ## char class[9], haddr[128], hphone[17], ophone[13], dept[24]; | |
239 | ## int id, status; | |
240 | ||
241 | first = e->first; | |
242 | if (strlen(first) > 16) | |
243 | first[16] = 0; | |
244 | last = e->last; | |
245 | if (strlen(last) > 16) | |
246 | last[16] = 0; | |
247 | eid = e->eid; | |
248 | id = 0; | |
249 | ## repeat retrieve (id = u.users_id) | |
250 | ## where u.#last = @last and u.#first = @first and u.mit_id = @eid | |
251 | if (id == 0) { | |
252 | com_err(whoami, 0, "New user found: %s %s\n", first, last); | |
253 | return; | |
254 | } | |
255 | eid = e->id; | |
256 | ## repeat replace u (mit_id=@eid) where u.users_id = @id | |
257 | ||
258 | sid = e->id; | |
259 | name = e->name; | |
260 | strcpy(dept, e->course); | |
261 | title = e->title; | |
262 | strcpy(haddr, e->address); | |
263 | if (*e->dorm) { | |
264 | strcat(haddr, " "); | |
265 | strcat(haddr, e->dorm); | |
266 | } | |
267 | if (*e->city) { | |
268 | strcat(haddr, " "); | |
269 | strcat(haddr, e->city); | |
270 | } | |
271 | FixCase(haddr); | |
272 | if (*e->state) { | |
273 | strcat(haddr, " "); | |
274 | strcat(haddr, e->state); | |
275 | } | |
276 | strcpy(hphone, e->dphone); | |
277 | strcpy(ophone, e->mphone); | |
278 | ## repeat replace u (xname = @name, xdept = @dept, xtitle = @title, | |
279 | ## xaddress = @haddr, xphone1 = @hphone, xphone2 = @ophone, | |
280 | ## xmodtime = "now") | |
281 | ## where u.users_id = @id | |
282 | ##} | |
283 | ||
284 | ||
285 | set_next_object_id(object, limit) | |
286 | char *object; | |
287 | int limit; | |
288 | ##{ | |
289 | ## char *name; | |
290 | ## int rowcount, exists, value; | |
291 | ||
292 | name = object; | |
293 | ## begin transaction | |
294 | ## repeat retrieve (value = values.#value) where values.#name = @name | |
295 | ## inquire_equel(rowcount = "rowcount") | |
296 | if (rowcount != 1) { | |
297 | ## abort | |
298 | return(0); | |
299 | } | |
300 | ||
301 | ## retrieve (exists = any(users.name where users.name = value)) | |
302 | ## inquire_equel(rowcount = "rowcount") | |
303 | if (rowcount != 1) { | |
304 | ## abort | |
305 | return(0); | |
306 | } | |
307 | while (exists) { | |
308 | value++; | |
309 | if (limit && value > MAX_ID_VALUE) | |
310 | value = MIN_ID_VALUE; | |
311 | ## retrieve (exists = any(users.name where users.name = value)) | |
312 | } | |
313 | ||
314 | ## repeat replace values (#value = @value) where values.#name = @name | |
315 | ## end transaction | |
316 | return(value); | |
317 | ##} | |
318 | ||
319 |