8 static char *rcsid_rafnu_c = "$Header$";
13 /* ReadAndFixNextUser reads in a student record line in the format
14 * of the registrar's tape and hacks on the info to make it conform
15 * to athenareg's standards. For example, the line
17 123321123 ALBERGHETTI III JOANNA MARIA 97
19 * gets processed into:
22 * {nil, nil, nil, nil,
23 * last -> "Alberghetti",
24 * first -> "Joanna III",
27 * crypt_ssn -> "aj7.NBbasJbn8" ; encrypted with salt "aj"
43 #define FULL_NAME_LEN 31
45 #define REG_TAPE_LINE_LEN 77
48 #define LAST_NAME_OFFSET 10
49 #define LAST_NAME_MAX_ILEN 39
50 #define FIRST_NAME_OFFSET 49
51 #define FIRST_NAME_MAX_ILEN 25
52 #define MIT_YEAR_OFFSET 74
53 #define MIT_YEAR_ILEN 2
58 ReadAndFixNextUser(s, querc, querv)
64 char ibuf[BUFSIZE]; /* input line buffer */
65 static lno = 0; /* line number */
66 int len; /* line length */
67 char issn[SSN_ILEN + 1];
68 char ilnm[LAST_NAME_MAX_ILEN + 1];
69 char ifnm[FIRST_NAME_MAX_ILEN + 1 + 6]; /* extra for ", Jr.", et al */
70 char iyr[MIT_YEAR_ILEN + 1];
71 int ends_sr = 0; /* 1 if name ends in "SR" or "SR." */
72 int ends_jr = 0; /* 1 if name ends in "JR" or "JR." */
73 int ends_iii = 0; /* 1 if name ends in "III" */
74 int ends_iv = 0; /* 1 if name ends in "IV" */
78 for (;;) { /* ... well, at least until we get a good
80 if (fgets(ibuf, BUFSIZE, s) == NULL) {
81 fprintf(stderr, "Reached EOF after line %d.\n", lno);
82 return (EOF); /* reached EOF */
85 * POTENTIAL BUG!!! fgets will not remove \n from input stream
86 * May need to manually get that character off
90 if ((len = strlen(ibuf)) != REG_TAPE_LINE_LEN) {
91 fprintf(stderr, "bad length\n");
92 goto complain_and_continue;
95 /* grab and check input SSN */
97 issn[SSN_ILEN] = '\0';
98 (void) strncpy(issn, ibuf + SSN_OFFSET, SSN_ILEN);
99 for (p = issn; *p; p++) {
101 fprintf(stderr, "bad char \"%c\"\n", *p);
102 goto complain_and_continue;
106 /* check for blank before last name */
108 if (!isspace(ibuf[LAST_NAME_OFFSET - 1])) {
109 fprintf(stderr, "not space \"%c\"\n", ibuf[LAST_NAME_OFFSET - 1]);
110 goto complain_and_continue;
113 /* grab input last name */
115 ilnm[LAST_NAME_MAX_ILEN] = '\0';
116 (void) strncpy(ilnm, ibuf + LAST_NAME_OFFSET, LAST_NAME_MAX_ILEN);
117 for (p = ilnm; *p; p++) {
118 if (!isalpha(*p) && *p != '-' && *p != ' ' &&
119 *p != '.' && *p != '\'') {
120 fprintf(stderr, "bad char in name \"%c\"\n", *p);
121 goto complain_and_continue;
125 /* grab input first name */
127 ifnm[FIRST_NAME_MAX_ILEN] = '\0';
128 (void) strncpy(ifnm, ibuf + FIRST_NAME_OFFSET, FIRST_NAME_MAX_ILEN);
130 for (p = ifnm; *p; p++) {
131 if (!isalpha(*p) && *p != '-' && *p != ' ' && *p != '.') {
132 fprintf(stderr, "bad char in fname \"%c\"\n", *p);
133 goto complain_and_continue;
139 iyr[MIT_YEAR_ILEN] = '\0';
140 (void) strncpy(iyr, ibuf + MIT_YEAR_OFFSET, MIT_YEAR_ILEN);
141 if (strcmp(iyr, "GG") && strcmp(iyr, "90") && strcmp(iyr, "88")
142 && strcmp(iyr, "89") && strcmp(iyr, "91")) {
143 fprintf(stderr, "bad year \"%s\"\n", iyr);
144 goto complain_and_continue;
147 /* Okay, got everything, now hack on it */
151 TrimTrailingSpace(ilnm);
152 LookForJrAndIII(ilnm, &ends_sr, &ends_jr, &ends_iii, &ends_iv);
156 (void) strncpy(querv[4], ilnm, LAST_LEN);
158 /* First name & middle initial ... */
160 TrimTrailingSpace(ifnm);
161 LookForJrAndIII(ifnm, &ends_sr, &ends_jr, &ends_iii, &ends_iv);
163 GetMidInit(ifnm, querv[6]);
165 (void) strncpy(querv[5], ifnm, FIRST_LEN);
168 /* okay, finish up first name */
169 AppendJrOrIII(ifnm, &ends_sr, &ends_jr, &ends_iii, &ends_iv);
173 if (!strcmp(iyr, "GG")) {
174 (void) strcpy(querv[9], "G\0");
177 (void) strcpy(querv[9], iyr);
180 /* MIT-ID (Social Security Number) ... */
182 salt[0] = tolower(*ilnm);
183 salt[1] = tolower(*ifnm);
184 (void) strcpy(querv[8], crypt(issn + 2, salt)); /* last 7 digits only */
185 (void) strcat(querv[8], "\0");
186 /* That's all, folks */
191 complain_and_continue:
192 fprintf(stderr, "\007ERROR on input line no. %d, len %d:\n",
194 fprintf(stderr, "%s\n", ibuf);
198 TrimTrailingSpace(ip)
203 for (p = ip + strlen(ip) - 1; p >= ip && isspace(*p); p--) {
209 register char *nm; /* truncate at first space, if any such */
210 register char *mi; /* set to first char after first space, if
213 while (*nm && !isspace(*nm)) {
219 while (*nm && isspace(*nm)) {
228 AppendJrOrIII(nm, phas_sr, phas_jr, phas_iii, phas_iv)
230 register int *phas_sr;
231 register int *phas_jr;
232 register int *phas_iii;
233 register int *phas_iv;
236 (void) strcat(nm, ", Sr.");
239 (void) strcat(nm, ", Jr.");
241 else if (*phas_iii) {
242 (void) strcat(nm, " III");
245 (void) strcat(nm, " IV");
252 register int cflag; /* convert to lcase, unless at start or
255 /* a space or punctuation mark (e.g., '-') */
257 for (cflag = 0; *p; p++) {
258 if (cflag && isupper(*p)) {
261 else if (isspace(*p) || ispunct(*p)) {
270 LookForJrAndIII(nm, pends_sr, pends_jr, pends_iii, pends_iv)
272 register int *pends_sr;
273 register int *pends_jr;
274 register int *pends_iii;
275 register int *pends_iv;
277 register int len = strlen(nm);
279 if (len >= 4 && !strcmp(nm + len - 3, " SR")) {
283 else if (len >= 4 && !strcmp(nm + len - 3, " JR")) {
287 else if (len >= 4 && !strcmp(nm + len - 3, " IV")) {
291 else if (len >= 5 && !strcmp(nm + len - 4, " SR.")) {
295 else if (len >= 5 && !strcmp(nm + len - 4, " JR.")) {
299 else if (len >= 5 && !strcmp(nm + len - 4, " III")) {
305 LookForSt(nm) /* ST PIERRE, etc. */
310 if (!strcmp(nm, "ST ")) {
311 (void) strcpy(temp, nm + 3);
312 (void) strcpy(nm, "ST. ");
313 (void) strcat(nm, temp);
317 LookForO(nm) /* O BRIEN, etc. */
320 if (!strcmp(nm, "O ") && isalpha(nm[2])) {