]> andersk Git - moira.git/blob - lib/fixname.c
Code style cleanup. (No functional changes)
[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(register char *p)
54 {
55   register 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(register char *nm, register int *pends_jr, int *pends_ii,
72                 register int *pends_iii, register int *pends_iv,
73                 int *pends_v)
74 {
75   register int len = strlen(nm);
76
77   if (len >= 4 && !strcmp(nm + len - 3, " JR"))
78     {
79       *pends_jr = 1;
80       nm[len - 3] = '\0';
81     }
82   else if (len >= 4 && !strcmp(nm + len - 3, " IV"))
83     {
84       *pends_iv = 1;
85       nm[len - 3] = '\0';
86     }
87   else if (len >= 5 && !strcmp(nm + len - 4, " JR."))
88     {
89       *pends_jr = 1;
90       nm[len - 4] = '\0';
91     }
92   else if (len >= 5 && !strcmp(nm + len - 4, " III"))
93     {
94       *pends_iii = 1;
95       nm[len - 4] = '\0';
96     }
97   else if (len >= 4 && !strcmp(nm + len - 3, " II"))
98     {
99       *pends_ii = 1;
100       nm[len - 3] = '\0';
101     }
102   else if (len >= 3 && !strcmp(nm + len - 2, " V"))
103     {
104       *pends_v = 1;
105       nm[len - 2] = '\0';
106     }
107 }
108
109 LookForSt(register char *nm)            /* ST PIERRE, etc. */
110 {
111   char temp[256];
112
113   if (!strcmp(nm, "ST "))
114     {
115       strcpy(temp, nm + 3);
116       strcpy(nm, "ST. ");
117       strcat(nm, temp);
118     }
119 }
120
121 LookForO(register char *nm)             /* O BRIEN, etc. */
122 {
123   if (!strcmp(nm, "O ") && isalpha(nm[2]))
124     nm[1] = '\'';
125 }
126
127 TrimTrailingSpace(register char *ip)
128 {
129   register char *p;
130   for (p = ip + strlen(ip) - 1; p >= ip && isspace(*p); p--)
131     *p = '\0';
132 }
133
134 GetMidInit(register char *nm, register char *mi)
135 {
136   while (*nm && !isspace(*nm))
137     nm++;
138   if (*nm)
139     *nm++ = '\0';
140   while (*nm && isspace(*nm))
141     nm++;
142   if (*nm)
143     *mi++ = *nm;
144   *mi = '\0';
145 }
This page took 0.044573 seconds and 5 git commands to generate.