]> andersk Git - moira.git/blobdiff - lib/fixname.c
Don't all-capsify unrecognized hostnames in non-MIT.EDU domains.
[moira.git] / lib / fixname.c
index 02e9d254146ff2b33012956fad567c7ac09377df..dc37c0e597c0a65167962cc11c8136775ff95fb6 100644 (file)
@@ -1,27 +1,27 @@
-/*
- *     $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);
@@ -29,7 +29,8 @@ void FixName(char *ilnm, char *ifnm, char *last, char *first, char *middle)
   /* 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);
@@ -38,38 +39,43 @@ void FixName(char *ilnm, char *ifnm, char *last, char *first, char *middle)
   /* 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(char *p)
+void FixCase(char *p)
 {
-  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(char *nm, int *pends_jr, int *pends_ii, int *pends_iii,
-               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)
 {
   int len = strlen(nm);
 
@@ -78,6 +84,11 @@ LookForJrAndIII(char *nm, int *pends_jr, int *pends_ii, int *pends_iii,
       *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;
@@ -105,7 +116,9 @@ LookForJrAndIII(char *nm, int *pends_jr, int *pends_ii, int *pends_iii,
     }
 }
 
-LookForSt(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];
 
@@ -117,20 +130,20 @@ LookForSt(char *nm)               /* ST PIERRE, etc. */
     }
 }
 
-LookForO(char *nm)             /* O BRIEN, etc. */
+void LookForO(char *nm)                /* O BRIEN, etc. */
 {
   if (!strcmp(nm, "O ") && isalpha(nm[2]))
     nm[1] = '\'';
 }
 
-TrimTrailingSpace(char *ip)
+void TrimTrailingSpace(char *ip)
 {
   char *p;
   for (p = ip + strlen(ip) - 1; p >= ip && isspace(*p); p--)
     *p = '\0';
 }
 
-GetMidInit(char *nm, char *mi)
+void GetMidInit(char *nm, char *mi)
 {
   while (*nm && !isspace(*nm))
     nm++;
@@ -142,3 +155,17 @@ GetMidInit(char *nm, char *mi)
     *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);
+}
This page took 0.740492 seconds and 4 git commands to generate.