]> andersk Git - moira.git/blob - regtape/students.pc
.dc -> .pc
[moira.git] / regtape / students.pc
1 /* $Header$
2  */
3
4 #include <stdio.h>
5 #include <string.h>
6 #include <ctype.h>
7 #include <sys/time.h>
8 #include <moira.h>
9 #include <moira_site.h>
10 EXEC SQL INCLUDE sqlca;
11
12
13 #define WHO 11859               /* root */
14 #define PROG "stu-tape"
15
16 #define MAX_ID_VALUE    31999
17 #define MIN_ID_VALUE    101
18
19 /* File format is:
20
21 0-29    name
22 30-38   id number
23 50-54   school code
24 55-79   year
25 80-109  address
26 110-124 room
27 125-144 city
28 145-158 state
29 159-168 dorm phone
30 169-212 home address
31 213-232 home city
32 243-251 mit phone (?)
33 */
34
35 #define LOC_NAME 0
36 #define LOC_ID 30
37 #define LOC_COURSE 50
38 #define LOC_YEAR 55
39 #define LOC_ADDRESS 80
40 #define LOC_DORM_ROOM 110
41 #define LOC_CITY 125
42 #define LOC_STATE 145
43 #define LOC_DPHONE 155
44 #define LOC_MPHONE 243
45
46 #define LEN_NAME 30
47 #define LEN_ID 9
48 #define LEN_COURSE 5
49 #define LEN_YEAR 25
50 #define LEN_ADDRESS 30
51 #define LEN_DORM_ROOM 15
52 #define LEN_CITY 20
53 #define LEN_STATE 10
54 #define LEN_DPHONE 12
55 #define LEN_MPHONE 12
56
57 struct entry {
58     char *name;
59     char *last;
60     char *first;
61     char *middle;
62     char *title;
63     char *id;
64     char *eid;
65     char *course;
66     char *year;
67     char *address;
68     char *dorm;
69     char *city;
70     char *state;
71     char *dphone;
72     char *mphone;
73     char *class;
74 };
75
76
77 char *whoami;
78 int newfinger = 0;
79
80 #define SQL_DUPLICATE 1422
81 #define sqlfail() (sqlca.sqlcode && sqlca.sqlcode != 1403)
82
83 main(argc, argv)
84 int argc;
85 char **argv;
86 {
87     FILE *in;
88     struct entry *e, *get_next_entry();
89     int i, wait = 0;
90     char buf[BUFSIZ], *file = NULL;
91 EXEC SQL BEGIN DECLARE SECTION;
92     char *db="moira";
93 EXEC SQL END DECLARE SECTION;
94
95     whoami = strrchr(argv[0], '/');
96     if (whoami)
97       whoami++;
98     else
99       whoami = argv[0];
100
101     setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
102     setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
103
104     for (i = 1; i < argc; i++) {
105         if (!strcmp(argv[i], "-w"))
106           wait++;
107         else if (!strcmp(argv[i], "-D"))
108           setenv("ING_SET", "set printqry");
109         else if (!strcmp(argv[i], "-n"))
110           newfinger++;
111         else if (file != NULL)
112           fprintf(stderr, "Usage: %s [-w] [-D] [-n] inputfile\n", whoami);
113         else
114           file = argv[i];
115     }
116
117     in = fopen(file, "r");
118     if (in == NULL) {
119         fprintf(stderr, "Unable to open %s for input\n", file);
120         exit(1);
121     }
122
123     initialize_sms_error_table();
124
125     EXEC SQL CONNECT :db IDENTIFIED BY :db;
126     if (sqlca.sqlcode != 0) {
127         dbmserr("connecting", sqlca.sqlcode);
128         exit(1);
129     }
130
131     while (e = get_next_entry(in)) {
132     again:
133         process_entry(e);
134         EXEC SQL COMMIT WORK;
135         if (sqlca.sqlcode != 0) {
136           dbmserr("committing work", sqlca.sqlcode);
137           exit(1);
138         }
139         if (wait) {
140             printf("Next");
141             fflush(stdout);
142             gets(buf);
143         }
144     }
145
146     exit(0);
147 }
148
149
150 struct entry *get_next_entry(in)
151 FILE *in;
152 {
153     static struct entry e;
154     static char buf[BUFSIZ], eid[16], classbuf[10], titlebuf[12];
155     static char name[LEN_NAME+1], id[LEN_ID+1], course[LEN_COURSE+1];
156     static char year[LEN_YEAR+1], address[LEN_ADDRESS+1];
157     static char dorm_room[LEN_DORM_ROOM+1], city[LEN_CITY+1];
158     static char state[LEN_STATE+1], dphone[LEN_DPHONE+1], mphone[LEN_MPHONE+1];
159     static char sname[LEN_NAME+1], title[128];
160     static int nyear = 0;
161     int ends_jr, ends_iii, ends_iv, ends_sr, ends_ii, ends_v;
162     char *p;
163
164     if (nyear == 0) {
165         struct tm *tm;
166         struct timeval tv;
167
168         gettimeofday(&tv, NULL);
169         tm = localtime(&tv.tv_sec);
170         nyear = tm->tm_year;
171         if (tm->tm_mon > 5)
172           nyear++;
173     }
174
175     if (fgets(buf, sizeof(buf), in) == NULL)
176       return((struct entry *)NULL);
177
178     strncpy(name, &buf[LOC_NAME], LEN_NAME); name[LEN_NAME] = 0;
179     strncpy(id, &buf[LOC_ID], LEN_ID); id[LEN_ID] = 0;
180     strncpy(course, &buf[LOC_COURSE], LEN_COURSE); course[LEN_COURSE] = 0;
181     strncpy(year, &buf[LOC_YEAR], LEN_YEAR); year[LEN_YEAR] = 0;
182     strncpy(address, &buf[LOC_ADDRESS], LEN_ADDRESS); address[LEN_ADDRESS] = 0;
183     strncpy(dorm_room, &buf[LOC_DORM_ROOM], LEN_DORM_ROOM); dorm_room[LEN_DORM_ROOM] = 0;
184     strncpy(city, &buf[LOC_CITY], LEN_CITY); city[LEN_CITY] = 0;
185     strncpy(state, &buf[LOC_STATE], LEN_STATE); state[LEN_STATE] = 0;
186     strncpy(dphone, &buf[LOC_DPHONE], LEN_DPHONE); dphone[LEN_DPHONE] = 0;
187     strncpy(mphone, &buf[LOC_MPHONE], LEN_MPHONE); mphone[LEN_MPHONE] = 0;
188
189     strcpy(sname, name);
190     e.name = strtrim(sname);
191     p = strchr(name, ',');
192     if (p)
193       *p = 0;
194     e.last = strtrim(name);
195     if (p) {
196         p++;
197         while (isspace(*p))
198           p++;
199         e.first = p;    
200         if (p = strchr(e.first, ' ')) {
201             *p = 0;
202             e.first = strtrim(e.first);
203             e.middle = strtrim(p + 1);
204         } else {
205             e.first = strtrim(e.first);
206             e.middle = "";
207         }
208     } else {
209         e.first = "";
210         e.middle = "";
211     }
212     ends_jr = ends_iii = ends_iv = ends_sr = ends_ii = ends_v = 0;
213     LookForSt(e.last);
214     LookForO(e.last);
215     LookForJrAndIII(e.last, &ends_sr, &ends_jr, &ends_iii, &ends_iv,
216                     &ends_ii, &ends_v);
217     LookForJrAndIII(e.first, &ends_sr, &ends_jr, &ends_iii, &ends_iv,
218                     &ends_ii, &ends_v);
219     FixCase(e.last);
220     FixCase(e.first);
221     FixCase(e.middle);
222
223     e.id = id;
224     e.id[LEN_ID] = 0;
225     e.eid = eid;
226     EncryptID(e.eid, e.id, e.first, e.last);
227
228     e.year = strtrim(year);
229     e.title = title;
230     if (e.year[0] == 'G') {
231         e.class = "G";
232         sprintf(title, "Grad Student");
233     } else {
234         e.class = classbuf;
235         sprintf(classbuf, "%d", nyear + 4 - atoi(e.year) + 1900);
236         sprintf(title, "Undergrad (class of %s)", classbuf);
237     }
238
239     e.course = strtrim(course);
240     e.address = strtrim(address);
241     e.dorm = strtrim(dorm_room);
242     e.city = strtrim(city);
243     e.state = strtrim(state);
244     e.dphone = strtrim(dphone);
245     e.mphone = strtrim(mphone);
246     return(&e);
247 }
248
249
250 process_entry(e)
251 struct entry *e;
252 {
253     int changed, nochange, encrypted;
254     char buf[BUFSIZ], *from, *to;
255     EXEC SQL BEGIN DECLARE SECTION;
256     char *first, *last, *middle, *eid, *title, *sid, *name, *rname, *rdept, *rtitle;
257     char *rophone, *rhphone, *prog;
258     char class[9], haddr[128], hphone[33], ophone[33], dept[33], raddr[128];
259     char dfirst[17], dlast[17], dmiddle[17];
260     int id, status, who;
261     EXEC SQL END DECLARE SECTION;
262
263     who = WHO;
264     prog = PROG;
265     first = e->first;
266     if (strlen(first) > 16)
267       first[16] = 0;
268     last = e->last;
269     if (strlen(last) > 16)
270       last[16] = 0;
271     middle = e->middle;
272     eid = e->eid;
273     sid = e->id;
274     id = 0;
275     encrypted = 0;
276
277     /* Get user info */
278     EXEC SQL SELECT users_id, first, last, middle, type, home_addr, home_phone, office_phone, status, department
279       INTO :id, :dfirst, :dlast, :dmiddle, :class, :haddr, :hphone, :ophone, :status, :dept
280       FROM users
281       WHERE clearid = :sid;
282     if (sqlfail()) {
283         if (sqlca.sqlcode == SQL_DUPLICATE) {
284             com_err(whoami, 0, "duplicate ID number %s on user %s %s", sid, first, last);
285             return;
286         } else
287           sqlexit();
288     }
289     if (id == 0) {
290         EXEC SQL SELECT users_id, first, last, middle, type, home_addr, home_phone, office_phone, status, department
291           INTO :id, :dfirst, :dlast, :dmiddle, :class, :haddr, :hphone, :ophone, :status, :dept
292           FROM users
293           WHERE last = :last and first = :first and clearid = :eid;
294         if (sqlfail()) sqlexit();
295         encrypted++;
296         if (id == 0) {
297             newuser(e);
298             return;
299         }
300     }
301
302     /* See if class changed: if it's different, and the value in the database
303      * is not STAFF or SIPB, then update the database.  Since they were on the
304      * students tape, make the account usable.
305      */
306     if (strcmp(e->class, strtrim(class)) &&
307         strcmp(class, "STAFF") && strcmp(class, "SIPB")) {
308         com_err(whoami, 0, "updating class for user %s %s from %s to %s",
309                 first, last, class, e->class);
310         if (status == US_NOT_ALLOWED) status = US_NO_LOGIN_YET;
311         if (status == US_ENROLL_NOT_ALLOWED) status = US_ENROLLED;
312         strcpy(class, e->class);
313         EXEC SQL UPDATE users
314           SET type = NVL(:class,CHR(0)), status = :status, modtime = SYSDATE,
315             modby = :who, modwith = :prog
316           WHERE users_id = :id;   
317         if (sqlca.sqlcode != 0) {
318             dbmserr("updating class", sqlca.sqlcode);
319             exit(1);
320         }
321     }
322
323     /* Update name if necessary */
324     if (strcmp(first, strtrim(dfirst)) ||
325         strcmp(last, strtrim(dlast)) ||
326         strcmp(middle, strtrim(dmiddle))) {
327         com_err(whoami, 0, "updating real name for %s %s", first, last);
328         EXEC SQL UPDATE users
329           SET first = NVL(:first,CHR(0)), last = NVL(:last,CHR(0)),
330           middle = NVL(:middle,CHR(0)), modby = :who, modwith = :prog,
331           modtime = SYSDATE
332           WHERE users_id = :id;
333         if (sqlca.sqlcode != 0) {
334             dbmserr("updating name", sqlca.sqlcode);
335             exit(1);
336         }
337     }
338
339     /* Deal with updating the finger info if necessary */
340     changed = nochange = 0;
341     if (encrypted) changed++;
342     strcpy(buf, e->address);
343     if (*e->dorm) {
344         strcat(buf, " ");
345         strcat(buf, e->dorm);
346     }
347     if (*e->city) {
348         strcat(buf, " ");
349         strcat(buf, e->city);
350     }
351     FixCase(buf);
352     if (*e->state) {
353         strcat(buf, " ");
354         strcat(buf, e->state);
355     }
356     while (to = strchr(buf, ','))
357       *to = ';';
358     while (to = strchr(buf, ':'))
359       *to = ';';
360     if (newfinger) {
361         if (haddr[0] == ' ') {
362             strncpy(haddr, buf, 80);
363             haddr[80] = 0;
364             changed++;
365         } else if (strncmp(strtrim(haddr), buf, 80))
366           nochange++;
367     } else {
368         if (strncmp(strtrim(haddr), buf, 80))
369           changed++;
370         strncpy(haddr, buf, 80);
371         haddr[80] = 0;
372     }
373     from = e->dphone;
374     to = buf;
375     while (*from) {
376         if (isdigit(*from))
377           *to++ = *from;
378         from++;
379     }
380     *to = 0;
381     if (newfinger) {
382         if (hphone[0] == ' ') {
383             strncpy(hphone, buf, 16);
384             hphone[16] = 0;
385         } else if (strncmp(strtrim(hphone), buf, 16))
386           nochange++;
387     } else {
388         if (strncmp(strtrim(hphone), buf, 16))
389           changed++;
390         strncpy(hphone, buf, 16);
391         hphone[16] = 0;
392     }
393     from = e->mphone;
394     to = buf;
395     while (*from) {
396         if (isdigit(*from))
397           *to++ = *from;
398         from++;
399     }
400     *to = 0;
401     if (newfinger) {
402         if (ophone[0] == ' ') {
403             strncpy(ophone, buf, 12);
404             ophone[12] = 0;
405         } else if (strncmp(strtrim(ophone), buf, 12))
406           nochange++;
407     } else {
408         if (strncmp(strtrim(ophone), buf, 12))
409           changed++;
410         strncpy(ophone, buf, 12);
411         ophone[12] = 0;
412     }
413     e->course = e->course;
414     if (newfinger) {
415         if (dept[0] == ' ') {
416             strncpy(dept, e->course, 12);
417             dept[12] = 0;
418         } else if (strncmp(strtrim(dept), e->course, 11))
419           nochange++;
420     } else {
421         if (strncmp(strtrim(dept), e->course, 11))
422           changed++;
423         strncpy(dept, e->course, 12);
424         dept[12] = 0;
425     }
426     sid = e->id;
427     name = e->name;
428     rdept = e->course;
429     rtitle = e->title;
430     rophone = e->mphone;
431     rhphone = e->dphone;
432     strcpy(raddr, e->address);
433     if (*e->dorm) {
434         strcat(raddr, " ");
435         strcat(raddr, e->dorm);
436     }
437     strcat(raddr, "|");
438     if (*e->city) {
439         strcat(raddr, e->city);
440         FixCase(raddr);
441         if (*e->state) {
442             strcat(raddr, " ");
443             if (isupper(e->state[0]) && isupper(e->state[1]) &&
444                 isdigit(e->state[2]) && isdigit(e->state[3]) &&
445                 isdigit(e->state[4]) && isdigit(e->state[5]) &&
446                 isdigit(e->state[6])) {
447                 sprintf(buf, "%c%c  %s", e->state[0],e->state[1],
448                         &(e->state[2]));
449                 strcat(raddr, buf);
450             } else
451               strcat(raddr, e->state);
452         }
453     } else {
454         FixCase(raddr);
455         strcat(raddr, "MIT INTERDEPARTMENTAL MAIL");
456     }
457     if (changed) {
458         com_err(whoami, 0, "updating finger for %s %s", first, last);
459         EXEC SQL UPDATE users
460           SET home_addr = NVL(:haddr,CHR(0)), home_phone = NVL(:hphone,CHR(0)),
461           office_phone = NVL(:ophone,CHR(0)), department = NVL(:dept,CHR(0)),
462           fmodtime = SYSDATE, fmodby = :who, fmodwith = :prog,
463           xname = NVL(:name,CHR(0)), xdept = NVL(:rdept,CHR(0)),
464           xtitle = NVL(:rtitle,CHR(0)), xaddress = NVL(:raddr,CHR(0)),
465           xphone1 = NVL(:rhphone,CHR(0)), xphone2 = NVL(:rophone,CHR(0)),
466           xmodtime = SYSDATE, clearid = NVL(:sid,CHR(0))
467           WHERE users_id = :id;
468         if (sqlca.sqlcode != 0) {
469           dbmserr(NULL, sqlca.sqlcode);
470           exit(1);
471         }
472     }  else {
473         EXEC SQL UPDATE users
474           SET xname = NVL(:name,CHR(0)), xdept = NVL(:rdept,CHR(0)),
475           xtitle = NVL(:rtitle,CHR(0)), xaddress = NVL(:raddr,CHR(0)),
476           xphone1 = NVL(:rhphone,CHR(0)), xphone2 = NVL(:rophone,CHR(0)),
477           xmodtime = SYSDATE, clearid = NVL(:sid,CHR(0))
478           WHERE users_id = :id;
479         if (sqlca.sqlcode != 0) {
480           dbmserr(NULL, sqlca.sqlcode);
481           exit(1);
482         }
483     }
484 }
485
486
487 newuser(e)
488 struct entry *e;
489 {
490     char buf[512], *from, *to;
491     EXEC SQL BEGIN DECLARE SECTION;
492     int id, uid, who;
493     char *last, *first, *class, *middle, login[9], *sid, fullname[65], *prog;
494     char haddr[81], hphone[17], ophone[13], dept[24], *title, raddr[81], *name;
495     EXEC SQL END DECLARE SECTION;
496
497     who = WHO;
498     prog = PROG;
499     strcpy(buf, e->address);
500     if (*e->dorm) {
501         strcat(buf, " ");
502         strcat(buf, e->dorm);
503     }
504     if (*e->city) {
505         strcat(buf, " ");
506         strcat(buf, e->city);
507     }
508     if (*e->state) {
509         strcat(buf, " ");
510         strcat(buf, e->state);
511     }
512     strncpy(haddr, buf, 80);
513     from = e->dphone;
514     to = buf;
515     while (*from) {
516         if (isdigit(*from))
517           *to++ = *from;
518         from++;
519     }
520     *to = 0;
521     strncpy(hphone, buf, 16);
522     from = e->mphone;
523     to = buf;
524     while (*from) {
525         if (isdigit(*from))
526           *to++ = *from;
527         from++;
528     }
529     *to = 0;
530     strncpy(ophone, buf, 12);
531     strncpy(dept, e->course, 12);
532     
533     id = set_next_users_id(0);
534     uid = set_next_uid(1);
535     sprintf(login, "#%d", uid);
536     last = e->last;
537     first = e->first;
538     middle = e->middle;
539     sid = e->id;
540     class = e->class;
541     title = e->title;
542     if (*middle)
543       sprintf(fullname, "%s %s %s", first, middle, last);
544     else
545       sprintf(fullname, "%s %s", first, last);
546     name = e->name;
547     strcpy(raddr, e->address);
548     if (*e->dorm) {
549         strcat(raddr, " ");
550         strcat(raddr, e->dorm);
551     }
552     strcat(raddr, "|");
553     if (*e->city) {
554         strcat(raddr, e->city);
555         FixCase(raddr);
556         if (*e->state) {
557             strcat(raddr, " ");
558             if (isupper(e->state[0]) && isupper(e->state[1]) &&
559                 isdigit(e->state[2]) && isdigit(e->state[3]) &&
560                 isdigit(e->state[4]) && isdigit(e->state[5]) &&
561                 isdigit(e->state[6])) {
562                 sprintf(buf, "%c%c  %s", e->state[0],e->state[1],
563                         &(e->state[2]));
564                 strcat(raddr, buf);
565             } else
566               strcat(raddr, e->state);
567         }
568     } else {
569         FixCase(raddr);
570         strcat(raddr, "MIT INTERDEPARTMENTAL MAIL");
571     }
572     EXEC SQL INSERT INTO users
573       (login, users_id, unix_uid, shell, last, first, middle, status,
574        clearid, type, modtime, modby, modwith, fullname, home_addr,
575        home_phone, office_phone, department, fmodtime, fmodby, fmodwith,
576        potype, xname, xdept, xtitle, xaddress, xphone1, xphone2, xmodtime)
577       VALUES (:login, :id, :uid, '/bin/athena/tcsh', NVL(:last,CHR(0)),
578               NVL(:first,CHR(0)), NVL(:middle,CHR(0)), 0, NVL(:sid,CHR(0)),
579               NVL(:class,CHR(0)), SYSDATE, :who, :prog, NVL(:fullname,CHR(0)),
580               NVL(:haddr,CHR(0)), NVL(:hphone,CHR(0)), NVL(:ophone,CHR(0)),
581               NVL(:dept,CHR(0)), SYSDATE, :who, :prog, 'NONE',
582               NVL(:name,CHR(0)), NVL(:dept,CHR(0)), NVL(:title,CHR(0)),
583               NVL(:raddr,CHR(0)), NVL(:hphone,CHR(0)), NVL(:ophone,CHR(0)),
584               SYSDATE);
585     if (sqlca.sqlcode != 0) {
586       dbmserr("adding user", sqlca.sqlcode);
587       exit(1);
588     } else
589       com_err(whoami, 0, "adding user %s %s", e->first, e->last);
590 }
591
592
593
594 set_next_users_id(limit)
595     int limit;
596 {
597     EXEC SQL BEGIN DECLARE SECTION;
598     int rowcount, flag, value, retval;
599     EXEC SQL END DECLARE SECTION;
600
601     EXEC SQL SELECT value INTO :value FROM numvalues 
602       WHERE name = 'users_id';
603     if (sqlfail()) sqlexit();
604     if (sqlca.sqlerrd[2] != 1) {
605         EXEC SQL ROLLBACK;
606         com_err(whoami, MR_INTERNAL, "values table inconsistancy");
607         exit(1);
608     }
609
610     flag = 0;
611     EXEC SQL SELECT users_id INTO :flag FROM users
612       WHERE users_id = :value;
613     if (sqlfail()) sqlexit();
614     if (sqlca.sqlerrd[2] == 0)
615       flag = 0;
616     while (flag) {
617         value++;
618         if (limit && value > MAX_ID_VALUE)
619             value = MIN_ID_VALUE;
620         flag = 0;
621         EXEC SQL SELECT users_id INTO :flag FROM users 
622           WHERE users_id = :value;
623         if (sqlfail()) sqlexit();
624         if (sqlca.sqlerrd[2] == 0)
625           flag = 0;
626     }
627
628     retval = value++;
629     if (limit && value > MAX_ID_VALUE)
630       value = MIN_ID_VALUE;
631     EXEC SQL UPDATE numvalues SET value = :value
632       WHERE name = 'users_id';
633     if (sqlca.sqlcode != 0) {
634         dbmserr("updating numvalues", sqlca.sqlcode);
635         exit(1);
636     }
637     return(retval);
638 }
639
640 set_next_uid(limit)
641     int limit;
642 {
643     EXEC SQL BEGIN DECLARE SECTION;
644     int rowcount, flag, value, retval;
645     EXEC SQL END DECLARE SECTION;
646
647     EXEC SQL SELECT value INTO :value FROM numvalues 
648       WHERE name = 'unix_uid';
649     if (sqlfail()) sqlexit();
650     if (sqlca.sqlerrd[2] != 1) {
651         EXEC SQL ROLLBACK;
652         com_err(whoami, MR_INTERNAL, "values table inconsistancy");
653         exit(1);
654     }
655
656     flag = 0;
657     EXEC SQL SELECT unix_uid INTO :flag FROM users WHERE unix_uid = :value;
658     if (sqlfail()) sqlexit();
659     if (sqlca.sqlerrd[2] == 0)
660       flag = 0;
661     while (flag) {
662         value++;
663         if (limit && value > MAX_ID_VALUE)
664             value = MIN_ID_VALUE;
665         flag = 0;
666         EXEC SQL SELECT unix_uid INTO :flag FROM users WHERE unix_uid = :value;
667         if (sqlfail()) sqlexit();
668         if (sqlca.sqlerrd[2] == 0)
669           flag = 0;
670     }
671
672     retval = value++;
673     if (limit && value > MAX_ID_VALUE)
674       value = MIN_ID_VALUE;
675     EXEC SQL UPDATE numvalues SET value = :value WHERE name = 'unix_uid';
676     if (sqlca.sqlcode != 0) {
677         dbmserr("updating numvalues", sqlca.sqlcode);
678         exit(1);
679     }
680     return(retval);
681 }
682
683
684 sqlexit()
685 {
686     dbmserr(NULL, sqlca.sqlcode);
687     EXEC SQL ROLLBACK WORK;
688     exit(1);
689 }
690
691 dbmserr(char *where, int what)
692 {
693   char err_msg[256];
694   int bufsize=256, msglength=0;
695
696   sqlglm(err_msg, &bufsize, &msglength);
697   err_msg[msglength]=0;
698
699   if(where)
700     com_err(whoami, 0, "DBMS error %swhile %s", err_msg, where);
701   else
702     com_err(whoami, 0, "DBMS error %s", err_msg);
703 }
This page took 0.098988 seconds and 5 git commands to generate.