3 * This generates the input file for the mkdirdb program for the MIT.EDU
6 * (c) Copyright 1989 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>
23 char *whoami = "finger.gen";
24 char *ingres_date_and_time();
33 char filename[64], *targetfile;
40 initialize_sms_error_table();
42 ## set lockmode session where level = table
45 if (stat(argv[1], &sb) == 0) {
46 filetime = ingres_date_and_time(sb.st_mtime);
47 ## retrieve (flag1 = int4(interval("min",tblstats.modtime - filetime)))
48 ## where tblstats.table = "users"
50 fprintf(stderr, "File %s does not need to be rebuilt.\n",
56 sprintf(filename, "%s~", targetfile);
57 if ((out = fopen(filename, "w")) == NULL) {
58 fprintf(stderr, "unable to open %s for output\n", filename);
61 } else if (argc != 1) {
62 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
72 perror("close failed");
83 * ingerr: (supposedly) called when Ingres indicates an error.
84 * I have not yet been able to get this to work to intercept a
85 * database open error.
87 #define INGRES_DEADLOCK 4700
89 static int ingerr(num)
97 ingres_errno = MR_DEADLOCK;
100 ingres_errno = MR_INGRES_ERR;
102 com_err(whoami, MR_INGRES_ERR, " code %d\n", *num);
103 critical_alert("DCM", "Alias build encountered INGRES ERROR %d", *num);
111 ## int id, pid, bid, mid;
112 ## char name[129], type[9], buf[257], fname[17], mname[17], lname[17];
113 ## char year[9], dept[13], oaddr[17], ophone[13], haddr[81], hphone[17];
115 int mitroom, mitphone;
116 char stuemp, *mhost, *uname, *pob, *tmp;
117 struct hash *strings;
120 ## retrieve (buf = users.modtime) where users.users_id = 0
122 strings = create_hash(2000);
123 ## retrieve (id = strings.string_id, name = strings.string) {
124 hash_store(strings, id, strsave(strtrim(name)));
128 ## range of u is users
129 ## retrieve (id = u.users_id, name = u.login,
130 ## fname = u.first, mname = u.middle, lname = u.last,
131 ## year = u.mit_year, dept = u.mit_dept,
132 ## oaddr = u.office_addr, ophone = u.office_phone,
133 ## haddr = u.home_addr, hphone = u.home_phone,
134 ## type = u.potype, bid = u.box_id)
135 ## where u.status != 3 {
141 if (atoi(year) || !strcmp(year, "G"))
143 else if (!strcmp(year, "FACULTY") || !strcmp(year, "MITS") ||
144 !strcmp(year, "STAFF"))
146 else if (!strcmp(year, "PROJECT") || !strcmp(year, "SYSTEM"))
151 if (type[0] == 'S' & (pob = hash_lookup(strings, bid)) != NULL) {
153 mhost = index(pob, '@');
157 mhost = &uname[strlen(uname) + 1];
158 } else if (type[0] == 'N') {
162 mhost = "ATHENA.MIT.EDU";
163 uname = strtrim(name);
167 if (oaddr[0] != ' ') {
168 tmp = &oaddr[strlen(oaddr) - 1];
169 if (*tmp == 'm' || *tmp == 'M') {
174 if (tmp = index(ophone, '-')) {
175 bcopy(tmp+1, tmp, strlen(tmp)-1);
177 if (tmp = index(hphone, '-')) {
178 bcopy(tmp+1, tmp, strlen(tmp)-1);
181 fprintf(out, "%c:%s, %s %s:",
182 stuemp, strtrim(lname), strtrim(fname), strtrim(mname));
183 fprintf(out, "%s:%s:%s:%s::", lname, fname, mname, oaddr);
184 if (ophone[0] != ' ')
185 fprintf(out, "%010d:::%s:%s:%s:",
186 atoi(ophone), strtrim(dept), uname, mhost);
188 fprintf(out, ":::%s:%s:%s:",
189 strtrim(dept), uname, mhost);
190 if (hphone[0] != ' ')
191 fprintf(out, "%s:::::%010d::::%s::0\n",
192 strtrim(haddr), atoi(hphone), year);
194 fprintf(out, "%s:::::::::%s::0\n",
195 strtrim(haddr), year);