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);
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 */
73 up = 1; /* If other punctuation (eg, -), upper */
77 void LookForJrAndIII(char *nm, int *pends_jr, int *pends_sr, int *pends_ii,
78 int *pends_iii, int *pends_iv, int *pends_v)
82 if (len >= 4 && !strcmp(nm + len - 3, " JR"))
87 else if (len >= 4 && !strcmp(nm + len - 3, " SR"))
92 else if (len >= 4 && !strcmp(nm + len - 3, " IV"))
97 else if (len >= 5 && !strcmp(nm + len - 4, " JR."))
102 else if (len >= 5 && !strcmp(nm + len - 4, " III"))
107 else if (len >= 4 && !strcmp(nm + len - 3, " II"))
112 else if (len >= 3 && !strcmp(nm + len - 2, " V"))
119 /* XXX no way to avoid possible buffer overrun here since we don't know
120 how long nm is and we're trying to make it one longer */
121 void LookForSt(char *nm) /* ST PIERRE, etc. */
125 if (!strcmp(nm, "ST "))
127 strcpy(temp, nm + 3);
133 void LookForO(char *nm) /* O BRIEN, etc. */
135 if (!strcmp(nm, "O ") && isalpha(nm[2]))
139 void TrimTrailingSpace(char *ip)
142 for (p = ip + strlen(ip) - 1; p >= ip && isspace(*p); p--)
146 void GetMidInit(char *nm, char *mi)
148 while (*nm && !isspace(*nm))
152 while (*nm && isspace(*nm))
159 /* Function Name: RemoveHyphens
160 * Description: Removes all hyphens from the string passed to it.
161 * Arguments: str - the string to remove the hyphens from
165 void RemoveHyphens(char *str)
169 while ((hyphen = strchr(str, '-')))
170 strcpy(hyphen, hyphen + 1);