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"
38 #define FULL_NAME_LEN 31
40 #define REG_TAPE_LINE_LEN 77
43 #define LAST_NAME_OFFSET 10
44 #define LAST_NAME_MAX_ILEN 39
45 #define FIRST_NAME_OFFSET 49
46 #define FIRST_NAME_MAX_ILEN 25
47 #define MIT_YEAR_OFFSET 74
48 #define MIT_YEAR_ILEN 2
53 ReadAndFixNextUser(s, querc, querv)
59 char ibuf[BUFSIZE]; /* input line buffer */
60 static lno = 0; /* line number */
61 int len; /* line length */
62 char issn[SSN_ILEN + 1];
63 char ilnm[LAST_NAME_MAX_ILEN + 1];
64 char ifnm[FIRST_NAME_MAX_ILEN + 1 + 6]; /* extra for ", Jr.", et al */
65 char iyr[MIT_YEAR_ILEN + 1];
66 int ends_sr = 0; /* 1 if name ends in "SR" or "SR." */
67 int ends_jr = 0; /* 1 if name ends in "JR" or "JR." */
68 int ends_iii = 0; /* 1 if name ends in "III" */
69 int ends_iv = 0; /* 1 if name ends in "IV" */
77 for (;;) { /* ... well, at least until we get a good
79 if (fgets(ibuf, BUFSIZE, s) == NULL) {
80 fprintf(stderr, "Reached EOF after line %d.\n", lno);
81 return (EOF); /* reached EOF */
84 * POTENTIAL BUG!!! fgets will not remove \n from input stream
85 * May need to manually get that character off
89 if ((len = strlen(ibuf)) != REG_TAPE_LINE_LEN) {
90 fprintf(stderr, "bad length\n");
91 goto complain_and_continue;
94 /* grab and check input SSN */
96 issn[SSN_ILEN] = '\0';
97 (void) strncpy(issn, ibuf + SSN_OFFSET, SSN_ILEN);
98 for (p = issn; *p; p++) {
100 fprintf(stderr, "bad char \"%c\"\n", *p);
101 goto complain_and_continue;
105 /* check for blank before last name */
107 if (!isspace(ibuf[LAST_NAME_OFFSET - 1])) {
108 fprintf(stderr, "not space \"%c\"\n", ibuf[LAST_NAME_OFFSET - 1]);
109 goto complain_and_continue;
112 /* grab input last name */
114 ilnm[LAST_NAME_MAX_ILEN] = '\0';
115 (void) strncpy(ilnm, ibuf + LAST_NAME_OFFSET, LAST_NAME_MAX_ILEN);
116 for (p = ilnm; *p; p++) {
117 if (!isalpha(*p) && *p != '-' && *p != ' ' &&
118 *p != '.' && *p != '\'') {
119 fprintf(stderr, "bad char in name \"%c\"\n", *p);
120 goto complain_and_continue;
124 /* grab input first name */
126 ifnm[FIRST_NAME_MAX_ILEN] = '\0';
127 (void) strncpy(ifnm, ibuf + FIRST_NAME_OFFSET, FIRST_NAME_MAX_ILEN);
129 for (p = ifnm; *p; p++) {
130 if (!isalpha(*p) && *p != '-' && *p != ' ' && *p != '.') {
131 fprintf(stderr, "bad char in fname \"%c\"\n", *p);
132 goto complain_and_continue;
138 iyr[MIT_YEAR_ILEN] = '\0';
139 (void) strncpy(iyr, ibuf + MIT_YEAR_OFFSET, MIT_YEAR_ILEN);
140 if (strcmp(iyr, "GG") && strcmp(iyr, "90") && strcmp(iyr, "88")
141 && strcmp(iyr, "89") && strcmp(iyr, "91")) {
142 fprintf(stderr, "bad year \"%s\"\n", iyr);
143 goto complain_and_continue;
146 /* Okay, got everything, now hack on it */
150 TrimTrailingSpace(ilnm);
151 LookForJrAndIII(ilnm, &ends_sr, &ends_jr, &ends_iii, &ends_iv);
155 (void) strncpy(querv[4], ilnm, LAST_LEN);
157 /* First name & middle initial ... */
159 TrimTrailingSpace(ifnm);
160 LookForJrAndIII(ifnm, &ends_sr, &ends_jr, &ends_iii, &ends_iv);
162 GetMidInit(ifnm, querv[6]);
164 (void) strncpy(querv[5], ifnm, FIRST_LEN);
167 /* okay, finish up first name */
168 AppendJrOrIII(ifnm, &ends_sr, &ends_jr, &ends_iii, &ends_iv);
172 if (!strcmp(iyr, "GG")) {
173 (void) strcpy(querv[9], "G\0");
176 (void) strcpy(querv[9], iyr);
179 /* MIT-ID (Social Security Number) ... */
181 salt[0] = tolower(*ilnm);
182 salt[1] = tolower(*ifnm);
183 (void) strcpy(querv[8], crypt(issn + 2, salt)); /* last 7 digits only */
184 (void) strcat(querv[8], "\0");
185 /* That's all, folks */
190 complain_and_continue:
191 fprintf(stderr, "\007ERROR on input line no. %d, len %d:\n",
193 fprintf(stderr, "%s\n", ibuf);
197 TrimTrailingSpace(ip)
202 for (p = ip + strlen(ip) - 1; p >= ip && isspace(*p); p--) {
208 register char *nm; /* truncate at first space, if any such */
209 register char *mi; /* set to first char after first space, if
212 while (*nm && !isspace(*nm)) {
218 while (*nm && isspace(*nm)) {
227 AppendJrOrIII(nm, phas_sr, phas_jr, phas_iii, phas_iv)
229 register int *phas_sr;
230 register int *phas_jr;
231 register int *phas_iii;
232 register int *phas_iv;
235 (void) strcat(nm, ", Sr.");
238 (void) strcat(nm, ", Jr.");
240 else if (*phas_iii) {
241 (void) strcat(nm, " III");
244 (void) strcat(nm, " IV");
251 register int cflag; /* convert to lcase, unless at start or
254 /* a space or punctuation mark (e.g., '-') */
256 for (cflag = 0; *p; p++) {
257 if (cflag && isupper(*p)) {
260 else if (isspace(*p) || ispunct(*p)) {
269 LookForJrAndIII(nm, pends_sr, pends_jr, pends_iii, pends_iv)
271 register int *pends_sr;
272 register int *pends_jr;
273 register int *pends_iii;
274 register int *pends_iv;
276 register int len = strlen(nm);
278 if (len >= 4 && !strcmp(nm + len - 3, " SR")) {
282 else if (len >= 4 && !strcmp(nm + len - 3, " JR")) {
286 else if (len >= 4 && !strcmp(nm + len - 3, " IV")) {
290 else if (len >= 5 && !strcmp(nm + len - 4, " SR.")) {
294 else if (len >= 5 && !strcmp(nm + len - 4, " JR.")) {
298 else if (len >= 5 && !strcmp(nm + len - 4, " III")) {
304 LookForSt(nm) /* ST PIERRE, etc. */
309 if (!strcmp(nm, "ST ")) {
310 (void) strcpy(temp, nm + 3);
311 (void) strcpy(nm, "ST. ");
312 (void) strcat(nm, temp);
316 LookForO(nm) /* O BRIEN, etc. */
319 if (!strcmp(nm, "O ") && isalpha(nm[2])) {