]>
Commit | Line | Data |
---|---|---|
fa59b86f | 1 | /* $Id$ |
de56407f | 2 | * |
7ac48069 | 3 | * Put a name into Moira-canonical form |
4 | * | |
5 | * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology | |
6 | * For copying and distribution information, please see the file | |
7 | * <mit-copyright.h>. | |
de56407f | 8 | */ |
9 | ||
babbc197 | 10 | #include <mit-copyright.h> |
7ac48069 | 11 | #include <moira.h> |
12 | ||
de56407f | 13 | #include <ctype.h> |
7ac48069 | 14 | #include <string.h> |
15 | ||
16 | RCSID("$Header$"); | |
de56407f | 17 | |
965c2702 | 18 | #define LAST_LEN 100 |
19 | #define FIRST_LEN 100 | |
de56407f | 20 | |
5eaef520 | 21 | void FixName(char *ilnm, char *ifnm, char *last, char *first, char *middle) |
de56407f | 22 | { |
7ac48069 | 23 | int ends_jr = 0, ends_sr = 0; |
24 | int 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); |
7ac48069 | 32 | LookForJrAndIII(ilnm, &ends_jr, &ends_sr, |
33 | &ends_ii, &ends_iii, &ends_iv, &ends_v); | |
5eaef520 | 34 | LookForSt(ilnm); |
35 | LookForO(ilnm); | |
36 | FixCase(ilnm); | |
37 | strncpy(last, ilnm, LAST_LEN); | |
de56407f | 38 | |
5eaef520 | 39 | /* First name & middle initial ... */ |
de56407f | 40 | |
5eaef520 | 41 | TrimTrailingSpace(ifnm); |
7ac48069 | 42 | LookForJrAndIII(ifnm, &ends_jr, &ends_sr, |
43 | &ends_ii, &ends_iii, &ends_iv, &ends_v); | |
de56407f | 44 | |
5eaef520 | 45 | GetMidInit(ifnm, middle); |
46 | ||
47 | FixCase(ifnm); | |
5eaef520 | 48 | strncpy(first, ifnm, FIRST_LEN); |
de56407f | 49 | } |
0d8039b1 | 50 | |
428a496c | 51 | void FixCase(unsigned char *p) |
de56407f | 52 | { |
3f9c37b0 | 53 | int up; /* Should next letter be uppercase */ |
54 | int pos; /* Position within word */ | |
de56407f | 55 | |
3f9c37b0 | 56 | for (up = 1, pos = 1; *p; p++, pos++) |
5eaef520 | 57 | { |
3f9c37b0 | 58 | if (!up && isupper(*p)) |
5eaef520 | 59 | *p = tolower(*p); |
3f9c37b0 | 60 | else if (up && islower(*p)) |
5eaef520 | 61 | *p = toupper(*p); |
3f9c37b0 | 62 | |
63 | if (isalpha(*p)) /* If letter, next letter should be lower */ | |
64 | up = 0; | |
65 | else if (isspace(*p)) /* If space, next letter should be upper */ | |
66 | { | |
67 | pos = 0; | |
68 | up = 1; | |
69 | } | |
70 | else if (*p == '\'') /* If ', next letter should be upper only */ | |
71 | up = (pos == 2); /* if the ' is the 2nd char in the name */ | |
428a496c | 72 | else if (*p >= 0x80) /* If the high bit is set, don't touch it. */ |
73 | up = 0; | |
5eaef520 | 74 | else |
3f9c37b0 | 75 | up = 1; /* If other punctuation (eg, -), upper */ |
de56407f | 76 | } |
77 | } | |
78 | ||
7ac48069 | 79 | void LookForJrAndIII(char *nm, int *pends_jr, int *pends_sr, int *pends_ii, |
80 | int *pends_iii, int *pends_iv, int *pends_v) | |
de56407f | 81 | { |
44d12d58 | 82 | int len = strlen(nm); |
de56407f | 83 | |
5eaef520 | 84 | if (len >= 4 && !strcmp(nm + len - 3, " JR")) |
85 | { | |
86 | *pends_jr = 1; | |
87 | nm[len - 3] = '\0'; | |
de56407f | 88 | } |
7ac48069 | 89 | else if (len >= 4 && !strcmp(nm + len - 3, " SR")) |
90 | { | |
91 | *pends_sr = 1; | |
92 | nm[len - 3] = '\0'; | |
93 | } | |
5eaef520 | 94 | else if (len >= 4 && !strcmp(nm + len - 3, " IV")) |
95 | { | |
96 | *pends_iv = 1; | |
97 | nm[len - 3] = '\0'; | |
de56407f | 98 | } |
5eaef520 | 99 | else if (len >= 5 && !strcmp(nm + len - 4, " JR.")) |
100 | { | |
101 | *pends_jr = 1; | |
102 | nm[len - 4] = '\0'; | |
de56407f | 103 | } |
5eaef520 | 104 | else if (len >= 5 && !strcmp(nm + len - 4, " III")) |
105 | { | |
106 | *pends_iii = 1; | |
107 | nm[len - 4] = '\0'; | |
de56407f | 108 | } |
5eaef520 | 109 | else if (len >= 4 && !strcmp(nm + len - 3, " II")) |
110 | { | |
111 | *pends_ii = 1; | |
112 | nm[len - 3] = '\0'; | |
9d787e1c | 113 | } |
5eaef520 | 114 | else if (len >= 3 && !strcmp(nm + len - 2, " V")) |
115 | { | |
116 | *pends_v = 1; | |
117 | nm[len - 2] = '\0'; | |
9d787e1c | 118 | } |
de56407f | 119 | } |
120 | ||
a3bbcc2b | 121 | /* XXX no way to avoid possible buffer overrun here since we don't know |
122 | how long nm is and we're trying to make it one longer */ | |
7ac48069 | 123 | void LookForSt(char *nm) /* ST PIERRE, etc. */ |
de56407f | 124 | { |
5eaef520 | 125 | char temp[256]; |
de56407f | 126 | |
5eaef520 | 127 | if (!strcmp(nm, "ST ")) |
128 | { | |
129 | strcpy(temp, nm + 3); | |
130 | strcpy(nm, "ST. "); | |
131 | strcat(nm, temp); | |
de56407f | 132 | } |
133 | } | |
134 | ||
7ac48069 | 135 | void LookForO(char *nm) /* O BRIEN, etc. */ |
de56407f | 136 | { |
5eaef520 | 137 | if (!strcmp(nm, "O ") && isalpha(nm[2])) |
138 | nm[1] = '\''; | |
de56407f | 139 | } |
140 | ||
7ac48069 | 141 | void TrimTrailingSpace(char *ip) |
de56407f | 142 | { |
44d12d58 | 143 | char *p; |
5eaef520 | 144 | for (p = ip + strlen(ip) - 1; p >= ip && isspace(*p); p--) |
145 | *p = '\0'; | |
de56407f | 146 | } |
147 | ||
7ac48069 | 148 | void GetMidInit(char *nm, char *mi) |
de56407f | 149 | { |
5eaef520 | 150 | while (*nm && !isspace(*nm)) |
151 | nm++; | |
152 | if (*nm) | |
153 | *nm++ = '\0'; | |
154 | while (*nm && isspace(*nm)) | |
155 | nm++; | |
156 | if (*nm) | |
157 | *mi++ = *nm; | |
158 | *mi = '\0'; | |
de56407f | 159 | } |
33b0f7c3 | 160 | |
161 | /* Function Name: RemoveHyphens | |
162 | * Description: Removes all hyphens from the string passed to it. | |
163 | * Arguments: str - the string to remove the hyphens from | |
164 | * Returns: none | |
165 | */ | |
166 | ||
167 | void RemoveHyphens(char *str) | |
168 | { | |
169 | char *hyphen; | |
170 | ||
171 | while ((hyphen = strchr(str, '-'))) | |
172 | strcpy(hyphen, hyphen + 1); | |
173 | } |