-/*
- * $Source$
- * $Author$
- * $Header$
+/* $Id$
*
- * Copyright (C) 1987 by the Massachusetts Institute of Technology
- * For copying and distribution information, please see the file
- * <mit-copyright.h>.
+ * Put a name into Moira-canonical form
+ *
+ * Copyright (C) 1987-1998 by the Massachusetts Institute of Technology
+ * For copying and distribution information, please see the file
+ * <mit-copyright.h>.
*/
-#ifndef lint
-static char *rcsid_fixname_c = "$Header$";
-#endif
-
#include <mit-copyright.h>
-#include <string.h>
+#include <moira.h>
+
#include <ctype.h>
+#include <string.h>
+
+RCSID("$Header$");
#define LAST_LEN 100
#define FIRST_LEN 100
void FixName(char *ilnm, char *ifnm, char *last, char *first, char *middle)
{
- int ends_jr = 0, ends_iii = 0, ends_iv = 0, ends_ii = 0, ends_v = 0;
+ int ends_jr = 0, ends_sr = 0;
+ int ends_iii = 0, ends_iv = 0, ends_ii = 0, ends_v = 0;
uppercase(ilnm);
uppercase(ifnm);
/* Last name ... */
TrimTrailingSpace(ilnm);
- LookForJrAndIII(ilnm, &ends_jr, &ends_ii, &ends_iii, &ends_iv, &ends_v);
+ LookForJrAndIII(ilnm, &ends_jr, &ends_sr,
+ &ends_ii, &ends_iii, &ends_iv, &ends_v);
LookForSt(ilnm);
LookForO(ilnm);
FixCase(ilnm);
/* First name & middle initial ... */
TrimTrailingSpace(ifnm);
- LookForJrAndIII(ifnm, &ends_jr, &ends_ii, &ends_iii, &ends_iv, &ends_v);
+ LookForJrAndIII(ifnm, &ends_jr, &ends_sr,
+ &ends_ii, &ends_iii, &ends_iv, &ends_v);
GetMidInit(ifnm, middle);
FixCase(ifnm);
-#ifdef notdef
- /* okay, finish up first name */
- AppendJrOrIII(ifnm, &ends_jr, &ends_ii, &ends_iii, &ends_iv, &ends_v);
-#endif
strncpy(first, ifnm, FIRST_LEN);
}
-FixCase(register char *p)
+void FixCase(char *p)
{
- register int cflag; /* convert to lcase, unless at start or following */
- /* a space or punctuation mark (e.g., '-') */
+ int up; /* Should next letter be uppercase */
+ int pos; /* Position within word */
- for (cflag = 0; *p; p++)
+ for (up = 1, pos = 1; *p; p++, pos++)
{
- if (cflag && isupper(*p))
+ if (!up && isupper(*p))
*p = tolower(*p);
- else if (!cflag && islower(*p))
+ else if (up && islower(*p))
*p = toupper(*p);
- if (isalpha(*p))
- cflag = 1;
+
+ if (isalpha(*p)) /* If letter, next letter should be lower */
+ up = 0;
+ else if (isspace(*p)) /* If space, next letter should be upper */
+ {
+ pos = 0;
+ up = 1;
+ }
+ else if (*p == '\'') /* If ', next letter should be upper only */
+ up = (pos == 2); /* if the ' is the 2nd char in the name */
else
- cflag = 0;
+ up = 1; /* If other punctuation (eg, -), upper */
}
}
-LookForJrAndIII(register char *nm, register int *pends_jr, int *pends_ii,
- register int *pends_iii, register int *pends_iv,
- int *pends_v)
+void LookForJrAndIII(char *nm, int *pends_jr, int *pends_sr, int *pends_ii,
+ int *pends_iii, int *pends_iv, int *pends_v)
{
- register int len = strlen(nm);
+ int len = strlen(nm);
if (len >= 4 && !strcmp(nm + len - 3, " JR"))
{
*pends_jr = 1;
nm[len - 3] = '\0';
}
+ else if (len >= 4 && !strcmp(nm + len - 3, " SR"))
+ {
+ *pends_sr = 1;
+ nm[len - 3] = '\0';
+ }
else if (len >= 4 && !strcmp(nm + len - 3, " IV"))
{
*pends_iv = 1;
}
}
-LookForSt(register char *nm) /* ST PIERRE, etc. */
+/* XXX no way to avoid possible buffer overrun here since we don't know
+ how long nm is and we're trying to make it one longer */
+void LookForSt(char *nm) /* ST PIERRE, etc. */
{
char temp[256];
}
}
-LookForO(register char *nm) /* O BRIEN, etc. */
+void LookForO(char *nm) /* O BRIEN, etc. */
{
if (!strcmp(nm, "O ") && isalpha(nm[2]))
nm[1] = '\'';
}
-TrimTrailingSpace(register char *ip)
+void TrimTrailingSpace(char *ip)
{
- register char *p;
+ char *p;
for (p = ip + strlen(ip) - 1; p >= ip && isspace(*p); p--)
*p = '\0';
}
-GetMidInit(register char *nm, register char *mi)
+void GetMidInit(char *nm, char *mi)
{
while (*nm && !isspace(*nm))
nm++;
*mi++ = *nm;
*mi = '\0';
}
+
+/* Function Name: RemoveHyphens
+ * Description: Removes all hyphens from the string passed to it.
+ * Arguments: str - the string to remove the hyphens from
+ * Returns: none
+ */
+
+void RemoveHyphens(char *str)
+{
+ char *hyphen;
+
+ while ((hyphen = strchr(str, '-')))
+ strcpy(hyphen, hyphen + 1);
+}