]> andersk Git - moira.git/blob - lib/fixname.c
eliminate use of the `register' keyword: let the compiler decide
[moira.git] / lib / fixname.c
1 /*
2  *      $Source$
3  *      $Author$
4  *      $Header$
5  *
6  *      Copyright (C) 1987 by the Massachusetts Institute of Technology
7  *      For copying and distribution information, please see the file
8  *      <mit-copyright.h>.
9  */
10
11 #ifndef lint
12 static char *rcsid_fixname_c = "$Header$";
13 #endif
14
15 #include <mit-copyright.h>
16 #include <string.h>
17 #include <ctype.h>
18
19 #define LAST_LEN                100
20 #define FIRST_LEN               100
21
22 void FixName(char *ilnm, char *ifnm, char *last, char *first, char *middle)
23 {
24   int ends_jr = 0, ends_iii = 0, ends_iv = 0, ends_ii = 0, ends_v = 0;
25
26   uppercase(ilnm);
27   uppercase(ifnm);
28
29   /* Last name ... */
30
31   TrimTrailingSpace(ilnm);
32   LookForJrAndIII(ilnm, &ends_jr, &ends_ii, &ends_iii, &ends_iv, &ends_v);
33   LookForSt(ilnm);
34   LookForO(ilnm);
35   FixCase(ilnm);
36   strncpy(last, ilnm, LAST_LEN);
37
38   /* First name  & middle initial ... */
39
40   TrimTrailingSpace(ifnm);
41   LookForJrAndIII(ifnm, &ends_jr, &ends_ii, &ends_iii, &ends_iv, &ends_v);
42
43   GetMidInit(ifnm, middle);
44
45   FixCase(ifnm);
46 #ifdef notdef
47   /* okay, finish up first name */
48   AppendJrOrIII(ifnm, &ends_jr, &ends_ii, &ends_iii, &ends_iv, &ends_v);
49 #endif
50   strncpy(first, ifnm, FIRST_LEN);
51 }
52
53 FixCase(char *p)
54 {
55   int cflag;    /* convert to lcase, unless at start or following */
56                 /* a space or punctuation mark (e.g., '-') */
57
58   for (cflag = 0; *p; p++)
59     {
60       if (cflag && isupper(*p))
61         *p = tolower(*p);
62       else if (!cflag && islower(*p))
63         *p = toupper(*p);
64       if (isalpha(*p))
65         cflag = 1;
66       else
67         cflag = 0;
68     }
69 }
70
71 LookForJrAndIII(char *nm, int *pends_jr, int *pends_ii, int *pends_iii,
72                 int *pends_iv, int *pends_v)
73 {
74   int len = strlen(nm);
75
76   if (len >= 4 && !strcmp(nm + len - 3, " JR"))
77     {
78       *pends_jr = 1;
79       nm[len - 3] = '\0';
80     }
81   else if (len >= 4 && !strcmp(nm + len - 3, " IV"))
82     {
83       *pends_iv = 1;
84       nm[len - 3] = '\0';
85     }
86   else if (len >= 5 && !strcmp(nm + len - 4, " JR."))
87     {
88       *pends_jr = 1;
89       nm[len - 4] = '\0';
90     }
91   else if (len >= 5 && !strcmp(nm + len - 4, " III"))
92     {
93       *pends_iii = 1;
94       nm[len - 4] = '\0';
95     }
96   else if (len >= 4 && !strcmp(nm + len - 3, " II"))
97     {
98       *pends_ii = 1;
99       nm[len - 3] = '\0';
100     }
101   else if (len >= 3 && !strcmp(nm + len - 2, " V"))
102     {
103       *pends_v = 1;
104       nm[len - 2] = '\0';
105     }
106 }
107
108 LookForSt(char *nm)             /* ST PIERRE, etc. */
109 {
110   char temp[256];
111
112   if (!strcmp(nm, "ST "))
113     {
114       strcpy(temp, nm + 3);
115       strcpy(nm, "ST. ");
116       strcat(nm, temp);
117     }
118 }
119
120 LookForO(char *nm)              /* O BRIEN, etc. */
121 {
122   if (!strcmp(nm, "O ") && isalpha(nm[2]))
123     nm[1] = '\'';
124 }
125
126 TrimTrailingSpace(char *ip)
127 {
128   char *p;
129   for (p = ip + strlen(ip) - 1; p >= ip && isspace(*p); p--)
130     *p = '\0';
131 }
132
133 GetMidInit(char *nm, char *mi)
134 {
135   while (*nm && !isspace(*nm))
136     nm++;
137   if (*nm)
138     *nm++ = '\0';
139   while (*nm && isspace(*nm))
140     nm++;
141   if (*nm)
142     *mi++ = *nm;
143   *mi = '\0';
144 }
This page took 0.045378 seconds and 5 git commands to generate.