3 * Put a name into Moira-canonical form
5 * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology
6 * For copying and distribution information, please see the file
10 #include <mit-copyright.h>
21 void FixName(char *ilnm, char *ifnm, char *last, char *first, char *middle)
23 int ends_jr = 0, ends_sr = 0;
24 int ends_iii = 0, ends_iv = 0, ends_ii = 0, ends_v = 0;
31 TrimTrailingSpace(ilnm);
32 LookForJrAndIII(ilnm, &ends_jr, &ends_sr,
33 &ends_ii, &ends_iii, &ends_iv, &ends_v);
37 strncpy(last, ilnm, LAST_LEN);
39 /* First name & middle initial ... */
41 TrimTrailingSpace(ifnm);
42 LookForJrAndIII(ifnm, &ends_jr, &ends_sr,
43 &ends_ii, &ends_iii, &ends_iv, &ends_v);
45 GetMidInit(ifnm, middle);
48 strncpy(first, ifnm, FIRST_LEN);
51 void FixCase(unsigned char *p)
53 int up; /* Should next letter be uppercase */
54 int pos; /* Position within word */
56 for (up = 1, pos = 1; *p; p++, pos++)
58 if (!up && isupper(*p))
60 else if (up && islower(*p))
63 if (isalpha(*p)) /* If letter, next letter should be lower */
65 else if (isspace(*p)) /* If space, next letter should be upper */
70 else if (*p == '\'') /* If ', next letter should be upper only */
71 up = (pos == 2); /* if the ' is the 2nd char in the name */
72 else if (*p >= 0x80) /* If the high bit is set, don't touch it. */
75 up = 1; /* If other punctuation (eg, -), upper */
79 void LookForJrAndIII(char *nm, int *pends_jr, int *pends_sr, int *pends_ii,
80 int *pends_iii, int *pends_iv, int *pends_v)
84 if (len >= 4 && !strcmp(nm + len - 3, " JR"))
89 else if (len >= 4 && !strcmp(nm + len - 3, " SR"))
94 else if (len >= 4 && !strcmp(nm + len - 3, " IV"))
99 else if (len >= 5 && !strcmp(nm + len - 4, " JR."))
104 else if (len >= 5 && !strcmp(nm + len - 4, " III"))
109 else if (len >= 4 && !strcmp(nm + len - 3, " II"))
114 else if (len >= 3 && !strcmp(nm + len - 2, " V"))
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 */
123 void LookForSt(char *nm) /* ST PIERRE, etc. */
127 if (!strcmp(nm, "ST "))
129 strcpy(temp, nm + 3);
135 void LookForO(char *nm) /* O BRIEN, etc. */
137 if (!strcmp(nm, "O ") && isalpha(nm[2]))
141 void TrimTrailingSpace(char *ip)
144 for (p = ip + strlen(ip) - 1; p >= ip && isspace(*p); p--)
148 void GetMidInit(char *nm, char *mi)
150 while (*nm && !isspace(*nm))
154 while (*nm && isspace(*nm))
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
167 void RemoveHyphens(char *str)
171 while ((hyphen = strchr(str, '-')))
172 strcpy(hyphen, hyphen + 1);