]>
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 | |
5eaef520 | 22 | void FixName(char *ilnm, char *ifnm, char *last, char *first, char *middle) |
de56407f | 23 | { |
5eaef520 | 24 | int ends_jr = 0, ends_iii = 0, ends_iv = 0, ends_ii = 0, ends_v = 0; |
de56407f | 25 | |
5eaef520 | 26 | uppercase(ilnm); |
27 | uppercase(ifnm); | |
de56407f | 28 | |
5eaef520 | 29 | /* Last name ... */ |
de56407f | 30 | |
5eaef520 | 31 | TrimTrailingSpace(ilnm); |
32 | LookForJrAndIII(ilnm, &ends_jr, &ends_ii, &ends_iii, &ends_iv, &ends_v); | |
33 | LookForSt(ilnm); | |
34 | LookForO(ilnm); | |
35 | FixCase(ilnm); | |
36 | strncpy(last, ilnm, LAST_LEN); | |
de56407f | 37 | |
5eaef520 | 38 | /* First name & middle initial ... */ |
de56407f | 39 | |
5eaef520 | 40 | TrimTrailingSpace(ifnm); |
41 | LookForJrAndIII(ifnm, &ends_jr, &ends_ii, &ends_iii, &ends_iv, &ends_v); | |
de56407f | 42 | |
5eaef520 | 43 | GetMidInit(ifnm, middle); |
44 | ||
45 | FixCase(ifnm); | |
de56407f | 46 | #ifdef notdef |
5eaef520 | 47 | /* okay, finish up first name */ |
48 | AppendJrOrIII(ifnm, &ends_jr, &ends_ii, &ends_iii, &ends_iv, &ends_v); | |
a43ce477 | 49 | #endif |
5eaef520 | 50 | strncpy(first, ifnm, FIRST_LEN); |
de56407f | 51 | } |
0d8039b1 | 52 | |
5eaef520 | 53 | FixCase(register char *p) |
de56407f | 54 | { |
5eaef520 | 55 | register int cflag; /* convert to lcase, unless at start or following */ |
de56407f | 56 | /* a space or punctuation mark (e.g., '-') */ |
57 | ||
5eaef520 | 58 | for (cflag = 0; *p; p++) |
59 | { | |
60 | if (cflag && isupper(*p)) | |
61 | *p = tolower(*p); | |
62 | else if (!cflag && islower(*p)) | |
63 | *p = toupper(*p); | |
64 | if (isalpha(*p)) | |
65 | cflag = 1; | |
66 | else | |
67 | cflag = 0; | |
de56407f | 68 | } |
69 | } | |
70 | ||
5eaef520 | 71 | LookForJrAndIII(register char *nm, register int *pends_jr, int *pends_ii, |
72 | register int *pends_iii, register int *pends_iv, | |
73 | int *pends_v) | |
de56407f | 74 | { |
5eaef520 | 75 | register int len = strlen(nm); |
de56407f | 76 | |
5eaef520 | 77 | if (len >= 4 && !strcmp(nm + len - 3, " JR")) |
78 | { | |
79 | *pends_jr = 1; | |
80 | nm[len - 3] = '\0'; | |
de56407f | 81 | } |
5eaef520 | 82 | else if (len >= 4 && !strcmp(nm + len - 3, " IV")) |
83 | { | |
84 | *pends_iv = 1; | |
85 | nm[len - 3] = '\0'; | |
de56407f | 86 | } |
5eaef520 | 87 | else if (len >= 5 && !strcmp(nm + len - 4, " JR.")) |
88 | { | |
89 | *pends_jr = 1; | |
90 | nm[len - 4] = '\0'; | |
de56407f | 91 | } |
5eaef520 | 92 | else if (len >= 5 && !strcmp(nm + len - 4, " III")) |
93 | { | |
94 | *pends_iii = 1; | |
95 | nm[len - 4] = '\0'; | |
de56407f | 96 | } |
5eaef520 | 97 | else if (len >= 4 && !strcmp(nm + len - 3, " II")) |
98 | { | |
99 | *pends_ii = 1; | |
100 | nm[len - 3] = '\0'; | |
9d787e1c | 101 | } |
5eaef520 | 102 | else if (len >= 3 && !strcmp(nm + len - 2, " V")) |
103 | { | |
104 | *pends_v = 1; | |
105 | nm[len - 2] = '\0'; | |
9d787e1c | 106 | } |
de56407f | 107 | } |
108 | ||
5eaef520 | 109 | LookForSt(register char *nm) /* ST PIERRE, etc. */ |
de56407f | 110 | { |
5eaef520 | 111 | char temp[256]; |
de56407f | 112 | |
5eaef520 | 113 | if (!strcmp(nm, "ST ")) |
114 | { | |
115 | strcpy(temp, nm + 3); | |
116 | strcpy(nm, "ST. "); | |
117 | strcat(nm, temp); | |
de56407f | 118 | } |
119 | } | |
120 | ||
5eaef520 | 121 | LookForO(register char *nm) /* O BRIEN, etc. */ |
de56407f | 122 | { |
5eaef520 | 123 | if (!strcmp(nm, "O ") && isalpha(nm[2])) |
124 | nm[1] = '\''; | |
de56407f | 125 | } |
126 | ||
5eaef520 | 127 | TrimTrailingSpace(register char *ip) |
de56407f | 128 | { |
5eaef520 | 129 | register char *p; |
130 | for (p = ip + strlen(ip) - 1; p >= ip && isspace(*p); p--) | |
131 | *p = '\0'; | |
de56407f | 132 | } |
133 | ||
5eaef520 | 134 | GetMidInit(register char *nm, register char *mi) |
de56407f | 135 | { |
5eaef520 | 136 | while (*nm && !isspace(*nm)) |
137 | nm++; | |
138 | if (*nm) | |
139 | *nm++ = '\0'; | |
140 | while (*nm && isspace(*nm)) | |
141 | nm++; | |
142 | if (*nm) | |
143 | *mi++ = *nm; | |
144 | *mi = '\0'; | |
de56407f | 145 | } |