source: trunk/third/moira/regtape/staff.pc @ 25455

Revision 25455, 5.8 KB checked in by jdreed, 13 years ago (diff)
In moira: * Re-snapshot moira at r4073 to pick up new changes to clients; the eunice issue described in the previous entry is no longer relevant
Line 
1/* $Id: staff.pc 4066 2012-01-19 21:44:57Z zacheiss $
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>.
8 */
9
10#include <mit-copyright.h>
11#include <moira.h>
12#include <moira_site.h>
13#include <moira_schema.h>
14#include "common.h"
15
16#include <ctype.h>
17#include <stdio.h>
18#include <string.h>
19
20EXEC SQL INCLUDE sqlca;
21
22RCSID("$HeadURL: svn+ssh://svn.mit.edu/moira/trunk/moira/regtape/staff.pc $ $Id: staff.pc 4066 2012-01-19 21:44:57Z zacheiss $");
23
24/* File format is:
25 *
26 * id number [9]
27 * last name [30]
28 * first name [30]
29 * middle name [30]
30 * office address [24]
31 * phone1 [12]
32 * phone2 [12]
33 * dept [50]
34 * title [50]
35 */
36
37#define LOC_ID 0
38#define LEN_ID 9
39#define LOC_LAST_NAME (LOC_ID + LEN_ID)
40#define LEN_LAST_NAME 30
41#define LOC_FIRST_NAME (LOC_LAST_NAME + LEN_LAST_NAME)
42#define LEN_FIRST_NAME 30
43#define LOC_MIDDLE_NAME (LOC_FIRST_NAME + LEN_FIRST_NAME)
44#define LEN_MIDDLE_NAME 30
45#define LOC_OFFICE (LOC_MIDDLE_NAME + LEN_MIDDLE_NAME)
46#define LEN_OFFICE 24
47#define LOC_PHONE (LOC_OFFICE + LEN_OFFICE)
48#define LEN_PHONE 12
49#define LOC_PHONE2 (LOC_PHONE + LEN_PHONE)
50#define LEN_PHONE2 12
51#define LOC_DEPT (LOC_PHONE2 + LEN_PHONE2)
52#define LEN_DEPT 50
53#define LOC_TITLE (LOC_DEPT + LEN_DEPT)
54#define LEN_TITLE 50
55
56struct entry *get_next_entry(FILE *in);
57void process_entry(struct entry *e, int secure);
58
59EXEC SQL BEGIN DECLARE SECTION;
60int who;
61char *prog = "stafload";
62EXEC SQL END DECLARE SECTION;
63
64char *whoami;
65
66int main(int argc, char **argv)
67{
68  FILE *in;
69  struct entry *e;
70  int i, wait = 0;
71  char buf[80], *file = NULL;
72  EXEC SQL BEGIN DECLARE SECTION;
73  char *db = "moira";
74  EXEC SQL END DECLARE SECTION;
75
76  whoami = strrchr(argv[0], '/');
77  if (whoami)
78    whoami++;
79  else
80    whoami = argv[0];
81
82  setvbuf(stdout, NULL, _IOLBF, BUFSIZ);
83  setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
84
85  for (i = 1; i < argc; i++)
86    {
87      if (!strcmp(argv[i], "-w"))
88        wait++;
89      else if (file)
90        {
91          fprintf(stderr, "Usage: %s [-w] inputfile\n", whoami);
92          exit(1);
93        }
94      else
95        file = argv[i];
96    }
97
98  if (!file)
99    {
100      fprintf(stderr, "Usage: %s [-w] inputfile\n", whoami);
101      exit(1);
102    }
103
104  in = fopen(file, "r");
105  if (!in)
106    {
107      fprintf(stderr, "Unable to open %s for input\n", file);
108      exit(1);
109    }
110
111  initialize_sms_error_table();
112
113  EXEC SQL CONNECT :db IDENTIFIED BY :db;
114  if (sqlca.sqlcode)
115    {
116      dbmserr("opening database", sqlca.sqlcode);
117      exit(1);
118    }
119
120  EXEC SQL SELECT users_id INTO :who FROM users WHERE login = 'root';
121
122  while ((e = get_next_entry(in)))
123    {
124      process_entry(e, 0);
125      EXEC SQL COMMIT WORK;
126      if (sqlca.sqlcode)
127        {
128          dbmserr("committing work", sqlca.sqlcode);
129          exit(1);
130        }
131      if (wait)
132        {
133          printf("Next");
134          fflush(stdout);
135          fgets(buf, sizeof(buf), stdin);
136        }
137    }
138
139  exit(0);
140}
141
142struct entry *get_next_entry(FILE *in)
143{
144  static struct entry e;
145  static char buf[BUFSIZ];
146  static char last_name[LEN_LAST_NAME + 1], id[LEN_ID + 1];
147  static char first_name[LEN_FIRST_NAME + 1], middle_name[LEN_MIDDLE_NAME + 1];
148  static char office[LEN_OFFICE + 1], phone[LEN_PHONE + 1];
149  static char phone2[LEN_PHONE2 + 1], dept[LEN_DEPT + 1], title[LEN_TITLE + 1];
150  int ends_sr, ends_jr, ends_iii, ends_iv, ends_ii, ends_v;
151  char *p, *q;
152
153  if (!fgets(buf, sizeof(buf), in))
154    return NULL;
155
156  strlcpy(id, &buf[LOC_ID], LEN_ID + 1);
157  strlcpy(last_name, &buf[LOC_LAST_NAME], LEN_LAST_NAME + 1);
158  strlcpy(first_name, &buf[LOC_FIRST_NAME], LEN_FIRST_NAME + 1);
159  strlcpy(middle_name, &buf[LOC_MIDDLE_NAME], LEN_MIDDLE_NAME + 1);
160  strlcpy(office, &buf[LOC_OFFICE], LEN_OFFICE + 1);
161  strlcpy(phone, &buf[LOC_PHONE], LEN_PHONE + 1);
162  strlcpy(phone2, &buf[LOC_PHONE2], LEN_PHONE2 + 1);
163  strlcpy(dept, &buf[LOC_DEPT], LEN_DEPT + 1);
164  strlcpy(title, &buf[LOC_TITLE], LEN_TITLE + 1);
165
166  e.last = strtrim(last_name);
167  e.first = strtrim(first_name);
168  e.middle = strtrim(middle_name);
169
170  ends_sr = ends_jr = ends_iii = ends_iv = ends_ii = ends_v = 0;
171  LookForSt(e.last);
172  LookForO(e.last);
173  LookForJrAndIII(e.last, &ends_jr, &ends_sr, &ends_ii, &ends_iii,
174                  &ends_iv, &ends_v);
175  LookForJrAndIII(e.first, &ends_jr, &ends_sr, &ends_ii, &ends_iii,
176                  &ends_iv, &ends_v);
177
178  e.name = buf;
179  if (*e.middle)
180    sprintf(e.name, "%s %s %s", e.first, e.middle, e.last);
181  else
182    sprintf(e.name, "%s %s", e.first, e.last);
183
184  e.id = id;
185  e.haddr = e.hphone = "";
186
187  /* Not used for employees. */
188  e.reg_type = "";
189
190  /* The following is really gross, but it happens to successfully convert
191   * new-style Warehouse office descriptions into (more-readable) old-style
192   * Personnel Office office descriptions.
193   */
194  e.oaddr = p = strtrim(office);
195  while (*p && !isspace(*p))
196    p++;
197  q = p;
198  while (isspace(*q))
199    q++;
200  if (*q && q < e.oaddr + LEN_OFFICE / 2)
201    {
202      *p++ = '-';
203      while (*q && q < e.oaddr + LEN_OFFICE / 2)
204        {
205          if (*q != ' ' && *q != '-')
206            *p++ = *q;
207          if (q > p)
208            *q = ' ';
209          q++;
210        }
211      memset(p, ' ', q - p);
212    }
213
214  p = e.oaddr + LEN_OFFICE / 2;
215  while (*p && !isspace(*p))
216    p++;
217  q = p;
218  while (isspace(*q))
219    q++;
220  if (*q)
221    {
222      *p++ = '-';
223      while (*q)
224        {
225          if (*q != ' ' && *q != '-')
226            *p++ = *q;
227          if (q > p)
228            *q = ' ';
229          q++;
230        }
231      memset(p, ' ', q - p);
232    }
233  strtrim(e.oaddr);
234  fixaddress(e.oaddr);
235  e.xaddress = e.oaddr;
236
237  e.ophone = e.xphone1 = strtrim(phone);
238  fixphone(e.ophone);
239  e.xphone2 = strtrim(phone2);
240  fixphone(e.xphone2);
241  e.dept = strtrim(dept);
242  e.xtitle = strtrim(title);
243
244  e.type = "MITS";
245  if ((strstr(uppercase(e.xtitle), "PROF") &&
246       !strstr(uppercase(e.xtitle), "PROFESSION")) ||
247      strstr(uppercase(e.xtitle), "LECTURE"))
248    e.type = "FACULTY";
249  if (strstr(uppercase(e.dept), "LINCOLN LAB"))
250    e.type = "LINCOLN";
251
252  FixCase(e.dept);
253  FixCase(e.xtitle);
254
255  return &e;
256}
Note: See TracBrowser for help on using the repository browser.