3 * This generates the input file for the mkdirdb program for the MIT.EDU
6 * (c) Copyright 1989, 1990 by the Massachusetts Institute of Technology.
7 * For copying and distribution information, please see the file
12 #include <mit-copyright.h>
16 #include <moira_site.h>
17 #include <sys/types.h>
20 EXEC SQL INCLUDE sqlca;
24 char *whoami = "mitdir.gen";
33 char filename[64], *targetfile;
35 EXEC SQL BEGIN DECLARE SECTION;
37 EXEC SQL END DECLARE SECTION;
40 initialize_sms_error_table();
46 EXEC SQL DATABASE sms;
50 if (stat(argv[1], &sb) == 0) {
51 if (ModDiff (&flag1, "users", sb.st_mtime))
54 fprintf(stderr, "File %s does not need to be rebuilt.\n",
60 sprintf(filename, "%s~", targetfile);
61 if ((out = fopen(filename, "w")) == NULL) {
62 fprintf(stderr, "unable to open %s for output\n", filename);
65 } else if (argc != 1) {
66 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
76 EXEC SQL CLOSE DATABASE;
80 perror("close failed");
93 int mitroom, mitphone;
94 char stuemp, *mhost, *uname, *pob, *tmp;
96 EXEC SQL BEGIN DECLARE SECTION;
97 int id, pid, bid, mid;
98 char name[129], type[9], buf[257], fname[17], mname[17], lname[17];
99 char year[9], dept[13], oaddr[17], ophone[13], haddr[81], hphone[17];
101 EXEC SQL END DECLARE SECTION;
103 EXEC SQL WHENEVER SQLERROR GOTO sqlerr;
106 EXEC SQL SELECT modtime INTO :buf FROM users WHERE users_id = 0;
108 strings = create_hash(2000);
109 EXEC SQL DECLARE s_lock CURSOR FOR
110 SELECT string_id, string
112 EXEC SQL OPEN s_lock;
114 EXEC SQL FETCH s_lock INTO :id, :name;
115 if (sqlca.sqlcode != 0) break;
116 hash_store(strings, id, strsave(strtrim(name)));
118 EXEC SQL CLOSE s_lock;
120 EXEC SQL DECLARE u_cursor1 CURSOR FOR
121 SELECT users_id, login, first, middle, last,
122 mit_year, mit_dept, office_addr, office_phone,
123 home_addr, home_phone, potype, box_id
126 EXEC SQL OPEN u_cursor1;
128 EXEC SQL FETCH u_cursor1 INTO :id, :name, :fname, :mname, :lname,
129 :year, :dept, :oaddr, :ophone, :haddr, :hphone, :type, :bid;
130 if (sqlca.sqlcode != 0) break;
136 if (atoi(year) || !strcmp(year, "G"))
138 else if (!strcmp(year, "FACULTY") || !strcmp(year, "MITS") ||
139 !strcmp(year, "STAFF"))
141 else if (!strcmp(year, "PROJECT") || !strcmp(year, "SYSTEM"))
146 if (type[0] == 'S' & (pob = hash_lookup(strings, bid)) != NULL) {
148 mhost = index(pob, '@');
152 mhost = &uname[strlen(uname) + 1];
153 } else if (type[0] == 'N') {
157 mhost = "ATHENA.MIT.EDU";
158 uname = strtrim(name);
162 if (oaddr[0] != ' ') {
163 tmp = &oaddr[strlen(oaddr) - 1];
164 if (*tmp == 'm' || *tmp == 'M') {
169 if (tmp = index(ophone, '-')) {
170 bcopy(tmp+1, tmp, strlen(tmp)-1);
172 if (tmp = index(hphone, '-')) {
173 bcopy(tmp+1, tmp, strlen(tmp)-1);
176 fprintf(out, "%c:%s, %s %s:",
177 stuemp, strtrim(lname), strtrim(fname), strtrim(mname));
178 fprintf(out, "%s:%s:%s:%s::", lname, fname, mname, oaddr);
179 if (ophone[0] != ' ')
180 fprintf(out, "%010d:::%s:%s:%s:",
181 atoi(ophone), strtrim(dept), uname, mhost);
183 fprintf(out, ":::%s:%s:%s:",
184 strtrim(dept), uname, mhost);
185 if (hphone[0] != ' ')
186 fprintf(out, "%s:::::%010d::::%s::0\n",
187 strtrim(haddr), atoi(hphone), year);
189 fprintf(out, "%s:::::::::%s::0\n",
190 strtrim(haddr), year);
192 EXEC SQL CLOSE u_cursor1;
195 com_err(whoami, MR_INGRES_ERR, " code %d\n", sqlca.sqlcode);
196 critical_alert("DCM", "Mitdir build encountered INGRES ERROR %d",