]> andersk Git - moira.git/blame - regtape/staff.pc
Make the install rule up to date.
[moira.git] / regtape / staff.pc
CommitLineData
7ac48069 1/* $Id$
2 *
3 * Load data into Moira from Personnel Office data file
4 *
5 * Copyright (C) 1990-1998 by the Massachusetts Institute of Technology
6 * For copying and distribution information, please see the file
7 * <mit-copyright.h>.
469f80df 8 */
9
7ac48069 10#include <mit-copyright.h>
932028de 11#include <moira.h>
12#include <moira_site.h>
dfaf9b68 13#include <moira_schema.h>
f0df8832 14#include "common.h"
7ac48069 15
16#include <ctype.h>
17#include <stdio.h>
18#include <string.h>
19
02cd9ede 20EXEC SQL INCLUDE sqlca;
469f80df 21
7ac48069 22RCSID("$Header$");
469f80df 23
469f80df 24/* File format is:
f0df8832 25 *
26 * id number [9]
27 * name (last, first middle) [30]
28 * office address [24]
29 * phone1 [12]
30 * phone2 [12]
31 * dept [50]
32 * title [50]
33 */
469f80df 34
35#define LOC_ID 0
469f80df 36#define LEN_ID 9
f0df8832 37#define LOC_NAME (LOC_ID + LEN_ID)
a6e9fead 38#define LEN_NAME 30
f0df8832 39#define LOC_OFFICE (LOC_NAME + LEN_NAME)
a6e9fead 40#define LEN_OFFICE 24
f0df8832 41#define LOC_PHONE (LOC_OFFICE + LEN_OFFICE)
469f80df 42#define LEN_PHONE 12
f0df8832 43#define LOC_PHONE2 (LOC_PHONE + LEN_PHONE)
469f80df 44#define LEN_PHONE2 12
f0df8832 45#define LOC_DEPT (LOC_PHONE2 + LEN_PHONE2)
e5843fe8 46#define LEN_DEPT 50
f0df8832 47#define LOC_TITLE (LOC_DEPT + LEN_DEPT)
a6e9fead 48#define LEN_TITLE 50
469f80df 49
7ac48069 50struct entry *get_next_entry(FILE *in);
f0df8832 51void process_entry(struct entry *e, int secure);
469f80df 52
f0df8832 53EXEC SQL BEGIN DECLARE SECTION;
54int who;
55char *prog = "stafload";
56EXEC SQL END DECLARE SECTION;
3e77c6a3 57
f0df8832 58char *whoami;
469f80df 59
5eaef520 60int main(int argc, char **argv)
02cd9ede 61{
5eaef520 62 FILE *in;
7ac48069 63 struct entry *e;
5eaef520 64 int i, wait = 0;
dfaf9b68 65 char buf[80], *file = NULL;
5eaef520 66 EXEC SQL BEGIN DECLARE SECTION;
67 char *db = "moira";
68 EXEC SQL END DECLARE SECTION;
69
70 whoami = strrchr(argv[0], '/');
71 if (whoami)
72 whoami++;
73 else
74 whoami = argv[0];
75
76 setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
77 setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
78
79 for (i = 1; i < argc; i++)
80 {
81 if (!strcmp(argv[i], "-w"))
82 wait++;
5eaef520 83 else if (file)
15e28a76 84 {
85 fprintf(stderr, "Usage: %s [-w] inputfile\n", whoami);
86 exit(1);
87 }
5eaef520 88 else
89 file = argv[i];
469f80df 90 }
91
15e28a76 92 if (!file)
93 {
94 fprintf(stderr, "Usage: %s [-w] inputfile\n", whoami);
95 exit(1);
96 }
97
5eaef520 98 in = fopen(file, "r");
99 if (!in)
100 {
101 fprintf(stderr, "Unable to open %s for input\n", file);
102 exit(1);
469f80df 103 }
104
5eaef520 105 initialize_sms_error_table();
325821e4 106
5eaef520 107 EXEC SQL CONNECT :db IDENTIFIED BY :db;
108 if (sqlca.sqlcode)
109 {
110 dbmserr("opening database", sqlca.sqlcode);
111 exit(1);
3e77c6a3 112 }
469f80df 113
f0df8832 114 EXEC SQL SELECT users_id INTO :who FROM users WHERE login = 'root';
115
5eaef520 116 while ((e = get_next_entry(in)))
117 {
f0df8832 118 process_entry(e, 0);
5eaef520 119 EXEC SQL COMMIT WORK;
120 if (sqlca.sqlcode)
121 {
9f5e5c05 122 dbmserr("committing work", sqlca.sqlcode);
123 exit(1);
3e77c6a3 124 }
5eaef520 125 if (wait)
126 {
127 printf("Next");
128 fflush(stdout);
dfaf9b68 129 fgets(buf, sizeof(buf), stdin);
469f80df 130 }
131 }
132
5eaef520 133 exit(0);
02cd9ede 134}
469f80df 135
5eaef520 136struct entry *get_next_entry(FILE *in)
469f80df 137{
5eaef520 138 static struct entry e;
0e5cfe5f 139 static char buf[BUFSIZ];
a16e134b 140 static char name[LEN_NAME + 1], id[LEN_ID + 1];
5eaef520 141 static char office[LEN_OFFICE + 1], phone[LEN_PHONE + 1];
142 static char phone2[LEN_PHONE2 + 1], dept[LEN_DEPT + 1], title[LEN_TITLE + 1];
5eaef520 143 int ends_sr, ends_jr, ends_iii, ends_iv, ends_ii, ends_v;
b92021f7 144 char *p, *q;
5eaef520 145
146 if (!fgets(buf, sizeof(buf), in))
147 return NULL;
148
f0df8832 149 strlcpy(id, &buf[LOC_ID], LEN_ID + 1);
150 strlcpy(name, &buf[LOC_NAME], LEN_NAME + 1);
151 strlcpy(office, &buf[LOC_OFFICE], LEN_OFFICE + 1);
152 strlcpy(phone, &buf[LOC_PHONE], LEN_PHONE + 1);
153 strlcpy(phone2, &buf[LOC_PHONE2], LEN_PHONE2 + 1);
154 strlcpy(dept, &buf[LOC_DEPT], LEN_DEPT + 1);
155 strlcpy(title, &buf[LOC_TITLE], LEN_TITLE + 1);
5eaef520 156
5eaef520 157 p = strchr(name, ',');
158 if (p)
159 *p = '\0';
160 e.last = strtrim(name);
161 if (p)
162 {
163 p++;
164 while (isspace(*p))
a6e9fead 165 p++;
5eaef520 166 e.first = p;
f0df8832 167 p = strchr(e.first, ' ');
168 if (p)
5eaef520 169 {
170 *p = '\0';
171 e.first = strtrim(e.first);
172 e.middle = strtrim(p + 1);
a6e9fead 173 }
5eaef520 174 else
175 {
176 e.first = strtrim(e.first);
177 e.middle = "";
178 }
179 }
180 else
181 {
182 e.first = "";
183 e.middle = "";
a6e9fead 184 }
5eaef520 185 ends_sr = ends_jr = ends_iii = ends_iv = ends_ii = ends_v = 0;
186 LookForSt(e.last);
187 LookForO(e.last);
7ac48069 188 LookForJrAndIII(e.last, &ends_jr, &ends_sr, &ends_ii, &ends_iii,
189 &ends_iv, &ends_v);
190 LookForJrAndIII(e.first, &ends_jr, &ends_sr, &ends_ii, &ends_iii,
191 &ends_iv, &ends_v);
5eaef520 192 FixCase(e.last);
193 FixCase(e.first);
194 FixCase(e.middle);
195
a16e134b 196 e.name = buf;
197 if (*e.middle)
198 sprintf(e.name, "%s %s %s", e.first, e.middle, e.last);
199 else
200 sprintf(e.name, "%s %s", e.first, e.last);
201
5eaef520 202 e.id = id;
f0df8832 203 e.haddr = e.hphone = "";
5eaef520 204
b92021f7 205 /* The following is really gross, but it happens to successfully convert
206 * new-style Warehouse office descriptions into (more-readable) old-style
207 * Personnel Office office descriptions.
208 */
f0df8832 209 e.oaddr = p = strtrim(office);
b92021f7 210 while (*p && !isspace(*p))
211 p++;
212 q = p;
213 while (isspace(*q))
214 q++;
f0df8832 215 if (*q && q < e.oaddr + LEN_OFFICE / 2)
b92021f7 216 {
217 *p++ = '-';
f0df8832 218 while (*q && q < e.oaddr + LEN_OFFICE / 2)
b92021f7 219 {
220 if (*q != ' ' && *q != '-')
221 *p++ = *q;
222 if (q > p)
223 *q = ' ';
224 q++;
225 }
226 memset(p, ' ', q - p);
227 }
228
f0df8832 229 p = e.oaddr + LEN_OFFICE / 2;
b92021f7 230 while (*p && !isspace(*p))
231 p++;
232 q = p;
233 while (isspace(*q))
234 q++;
235 if (*q)
236 {
237 *p++ = '-';
238 while (*q)
239 {
240 if (*q != ' ' && *q != '-')
241 *p++ = *q;
242 if (q > p)
243 *q = ' ';
244 q++;
245 }
246 memset(p, ' ', q - p);
247 }
f0df8832 248 strtrim(e.oaddr);
249 fixaddress(e.oaddr);
250 e.xaddress = e.oaddr;
251
252 e.ophone = e.xphone1 = strtrim(phone);
253 fixphone(e.ophone);
254 e.xphone2 = strtrim(phone2);
255 fixphone(e.xphone2);
5eaef520 256 e.dept = strtrim(dept);
f0df8832 257 e.xtitle = strtrim(title);
5eaef520 258
f0df8832 259 e.type = "MITS";
260 if (strstr(e.xtitle, "PROF") || strstr(e.xtitle, "LECTURE"))
261 e.type = "FACULTY";
5eaef520 262 if (!strcmp(e.dept, "LINCOLN LAB"))
f0df8832 263 e.type = "LINCOLN";
6c4dab06 264
f0df8832 265 FixCase(e.dept);
266 FixCase(e.xtitle);
6c4dab06 267
f0df8832 268 return &e;
9f5e5c05 269}
This page took 0.128845 seconds and 5 git commands to generate.