]>
Commit | Line | Data |
---|---|---|
de56407f | 1 | /* |
2 | * $Source$ | |
3 | * $Author$ | |
4 | * $Header$ | |
5 | * | |
6 | * Copyright (C) 1987 by the Massachusetts Institute of Technology | |
babbc197 | 7 | * For copying and distribution information, please see the file |
8 | * <mit-copyright.h>. | |
de56407f | 9 | */ |
10 | ||
11 | #ifndef lint | |
12 | static char *rcsid_fixname_c = "$Header$"; | |
a43ce477 | 13 | #endif |
de56407f | 14 | |
babbc197 | 15 | #include <mit-copyright.h> |
f4c08abd | 16 | #include <string.h> |
de56407f | 17 | #include <ctype.h> |
18 | ||
965c2702 | 19 | #define LAST_LEN 100 |
20 | #define FIRST_LEN 100 | |
de56407f | 21 | |
22 | void FixName(ilnm, ifnm, last, first, middle) | |
23 | char *ilnm, *ifnm; | |
24 | char *first, *last, *middle; | |
25 | { | |
9d787e1c | 26 | int ends_jr=0, ends_iii=0, ends_iv=0, ends_ii=0, ends_v=0; |
de56407f | 27 | |
0a927b48 | 28 | uppercase(ilnm); |
29 | uppercase(ifnm); | |
de56407f | 30 | |
31 | /* Last name ... */ | |
32 | ||
33 | TrimTrailingSpace(ilnm); | |
9d787e1c | 34 | LookForJrAndIII(ilnm, &ends_jr, &ends_ii, &ends_iii, &ends_iv, &ends_v); |
de56407f | 35 | LookForSt(ilnm); |
36 | LookForO(ilnm); | |
37 | FixCase(ilnm); | |
38 | strncpy(last, ilnm, LAST_LEN); | |
39 | ||
40 | /* First name & middle initial ... */ | |
41 | ||
42 | TrimTrailingSpace(ifnm); | |
9d787e1c | 43 | LookForJrAndIII(ifnm, &ends_jr, &ends_ii, &ends_iii, &ends_iv, &ends_v); |
de56407f | 44 | |
45 | GetMidInit(ifnm, middle); | |
46 | ||
47 | FixCase(ifnm); | |
48 | #ifdef notdef | |
49 | /* okay, finish up first name */ | |
9d787e1c | 50 | AppendJrOrIII(ifnm, &ends_jr, &ends_ii, &ends_iii, &ends_iv, &ends_v); |
a43ce477 | 51 | #endif |
de56407f | 52 | strncpy(first, ifnm, FIRST_LEN); |
53 | } | |
0d8039b1 | 54 | |
de56407f | 55 | FixCase(p) |
56 | register char *p; | |
57 | { | |
58 | register int cflag; /* convert to lcase, unless at start or following */ | |
59 | /* a space or punctuation mark (e.g., '-') */ | |
60 | ||
61 | for (cflag = 0; *p; p++) { | |
0d8039b1 | 62 | if (cflag && isupper(*p)) |
63 | *p = tolower(*p); | |
64 | else if (!cflag && islower(*p)) | |
65 | *p = toupper(*p); | |
66 | if (isalpha(*p)) | |
67 | cflag = 1; | |
68 | else | |
69 | cflag = 0; | |
de56407f | 70 | } |
71 | } | |
72 | ||
9d787e1c | 73 | LookForJrAndIII(nm, pends_jr, pends_ii, pends_iii, pends_iv, pends_v) |
de56407f | 74 | register char *nm; |
75 | register int *pends_jr; | |
9d787e1c | 76 | int *pends_ii; |
de56407f | 77 | register int *pends_iii; |
78 | register int *pends_iv; | |
9d787e1c | 79 | int *pends_v; |
de56407f | 80 | { |
81 | register int len = strlen(nm); | |
82 | ||
83 | if (len >= 4 && !strcmp(nm + len - 3, " JR")) { | |
84 | *pends_jr = 1; | |
85 | nm[len - 3] = '\0'; | |
86 | } | |
87 | else if (len >= 4 && !strcmp(nm + len - 3, " IV")) { | |
88 | *pends_iv = 1; | |
89 | nm[len - 3] = '\0'; | |
90 | } | |
91 | else if (len >= 5 && !strcmp(nm + len - 4, " JR.")) { | |
92 | *pends_jr = 1; | |
93 | nm[len - 4] = '\0'; | |
94 | } | |
95 | else if (len >= 5 && !strcmp(nm + len - 4, " III")) { | |
96 | *pends_iii = 1; | |
97 | nm[len - 4] = '\0'; | |
98 | } | |
9d787e1c | 99 | else if (len >= 4 && !strcmp(nm + len - 3, " II")) { |
100 | *pends_ii = 1; | |
101 | nm[len - 3] = '\0'; | |
102 | } | |
103 | else if (len >= 3 && !strcmp(nm + len - 2, " V")) { | |
104 | *pends_v = 1; | |
105 | nm[len - 2] = '\0'; | |
106 | } | |
de56407f | 107 | } |
108 | ||
109 | LookForSt(nm) /* ST PIERRE, etc. */ | |
110 | register char *nm; | |
111 | { | |
112 | char temp[256]; | |
113 | ||
114 | if (!strcmp(nm,"ST ")) { | |
115 | strcpy(temp, nm + 3); | |
116 | strcpy(nm, "ST. "); | |
117 | strcat(nm, temp); | |
118 | } | |
119 | } | |
120 | ||
121 | LookForO(nm) /* O BRIEN, etc. */ | |
122 | register char *nm; | |
123 | { | |
124 | if (!strcmp(nm, "O ") && isalpha(nm[2])) { | |
125 | nm[1] = '\''; | |
126 | } | |
127 | } | |
128 | ||
129 | TrimTrailingSpace(ip) | |
130 | register char *ip; | |
131 | { | |
132 | register char *p; | |
133 | for (p = ip + strlen(ip) - 1; p >= ip && isspace(*p); p--) { | |
134 | *p = '\0'; | |
135 | } | |
136 | } | |
137 | ||
de56407f | 138 | GetMidInit(nm, mi) |
139 | register char *nm; /* truncate at first space, if any such */ | |
140 | register char *mi; /* set to first char after first space, if any such */ | |
141 | { | |
142 | while (*nm && !isspace(*nm)) { | |
143 | nm++; | |
144 | } | |
145 | if (*nm) { | |
146 | *nm++ = '\0'; | |
147 | } | |
148 | while (*nm && isspace(*nm)) { | |
149 | nm++; | |
150 | } | |
151 | if (*nm) { | |
152 | *mi++ = *nm; | |
153 | } | |
154 | *mi = '\0'; | |
155 | } |