]> andersk Git - moira.git/blame - gen/mitdir.qc
Used /bin/sh format instead of /bin/csh format, by accident.
[moira.git] / gen / mitdir.qc
CommitLineData
f59a4f24 1/* $Header$
2 *
3 * This generates the input file for the mkdirdb program for the MIT.EDU
4 * mailhub.
5 *
6 * (c) Copyright 1989 by the Massachusetts Institute of Technology.
7 * For copying and distribution information, please see the file
8 * <mit-copyright.h>.
9 */
10
11
12#include <mit-copyright.h>
13#include <stdio.h>
14#include <string.h>
2ce085d2 15#include <moira.h>
16#include <moira_site.h>
f59a4f24 17#include <sys/types.h>
18#include <sys/stat.h>
19#include <sys/time.h>
20
21
22extern int errno;
23char *whoami = "finger.gen";
24char *ingres_date_and_time();
25
26
27main(argc, argv)
28int argc;
29char **argv;
30{
31 long tm = time(NULL);
32 FILE *out= stdout;
33 char filename[64], *targetfile;
34 struct stat sb;
35## int flag1;
36## char *filetime;
37 int ingerr();
38
39 IIseterr(ingerr);
40 initialize_sms_error_table();
41## ingres sms
42## set lockmode session where level = table
43
44 if (argc == 2) {
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"
49 if (flag1 < 0) {
50 fprintf(stderr, "File %s does not need to be rebuilt.\n",
51 argv[1]);
2ce085d2 52 exit(MR_NO_CHANGE);
f59a4f24 53 }
54 }
55 targetfile = argv[1];
56 sprintf(filename, "%s~", targetfile);
57 if ((out = fopen(filename, "w")) == NULL) {
58 fprintf(stderr, "unable to open %s for output\n", filename);
2ce085d2 59 exit(MR_OCONFIG);
f59a4f24 60 }
61 } else if (argc != 1) {
62 fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
2ce085d2 63 exit(MR_ARGS);
f59a4f24 64 }
65
66## begin transaction
67 get_info(out);
68## end transaction
69## exit
70
71 if (fclose(out)) {
72 perror("close failed");
2ce085d2 73 exit(MR_CCONFIG);
f59a4f24 74 }
75
76 if (argc == 2)
77 fix_file(targetfile);
2ce085d2 78 exit(MR_SUCCESS);
f59a4f24 79}
80
81
82/*
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.
86 */
87#define INGRES_DEADLOCK 4700
88
89static int ingerr(num)
90 int *num;
91{
92 char buf[256];
93 int ingres_errno;
94
95 switch (*num) {
96 case INGRES_DEADLOCK:
2ce085d2 97 ingres_errno = MR_DEADLOCK;
f59a4f24 98 break;
99 default:
2ce085d2 100 ingres_errno = MR_INGRES_ERR;
f59a4f24 101 }
2ce085d2 102 com_err(whoami, MR_INGRES_ERR, " code %d\n", *num);
f59a4f24 103 critical_alert("DCM", "Alias build encountered INGRES ERROR %d", *num);
104 exit(ingres_errno);
105}
106
107
108get_info(out)
109FILE *out;
110##{
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];
aee2b759 114## char affil[5];
115 int mitroom, mitphone;
116 char stuemp, *mhost, *uname, *pob, *tmp;
f59a4f24 117 struct hash *strings;
118
119 /* get locks */
120## retrieve (buf = users.modtime) where users.users_id = 0
121
122 strings = create_hash(2000);
123## retrieve (id = strings.string_id, name = strings.string) {
124 hash_store(strings, id, strsave(strtrim(name)));
125## }
126
127
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 {
136
137 if (id == 0)
138 continue;
139
140 strtrim(year);
141 if (atoi(year) || !strcmp(year, "G"))
142 stuemp = 'S';
143 else if (!strcmp(year, "FACULTY") || !strcmp(year, "MITS") ||
144 !strcmp(year, "STAFF"))
145 stuemp = 'E';
146 else if (!strcmp(year, "PROJECT") || !strcmp(year, "SYSTEM"))
147 continue;
148 else
149 stuemp = '?';
150
151 if (type[0] == 'S' & (pob = hash_lookup(strings, bid)) != NULL) {
152 uname = pob;
153 mhost = index(pob, '@');
154 if (mhost)
155 *mhost++ = 0;
156 else
157 mhost = &uname[strlen(uname) + 1];
158 } else if (type[0] == 'N') {
159 mhost = "";
160 uname = "";
161 } else {
162 mhost = "ATHENA.MIT.EDU";
163 uname = strtrim(name);
164 }
165
aee2b759 166 strtrim(oaddr);
167 if (oaddr[0] != ' ') {
168 tmp = &oaddr[strlen(oaddr) - 1];
169 if (*tmp == 'm' || *tmp == 'M') {
170 *tmp = 0;
171 }
172 }
173
174 if (tmp = index(ophone, '-')) {
175 bcopy(tmp+1, tmp, strlen(tmp)-1);
176 }
177 if (tmp = index(hphone, '-')) {
178 bcopy(tmp+1, tmp, strlen(tmp)-1);
179 }
180
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);
187 else
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);
193 else
194 fprintf(out, "%s:::::::::%s::0\n",
195 strtrim(haddr), year);
f59a4f24 196## }
197##}
This page took 0.198375 seconds and 5 git commands to generate.