]> andersk Git - moira.git/blob - lib/fixname.c
sms -> moira
[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 lint
14
15 #include <mit-copyright.h>
16 #include <strings.h>
17 #include <ctype.h>
18
19 #define LAST_LEN                100
20 #define FIRST_LEN               100
21
22 void FixName(ilnm, ifnm, last, first, middle)
23         char *ilnm, *ifnm;
24         char *first, *last, *middle;
25 {
26         int ends_jr=0, ends_iii=0, ends_iv=0;
27
28         Upcase(ilnm);
29         Upcase(ifnm);
30         
31         /* Last name ... */
32
33         TrimTrailingSpace(ilnm);
34         LookForJrAndIII(ilnm, &ends_jr, &ends_iii, &ends_iv);
35         LookForSt(ilnm);
36         LookForO(ilnm);
37         FixCase(ilnm);
38         strncpy(last, ilnm, LAST_LEN);
39
40                 /* First name  & middle initial ... */
41
42         TrimTrailingSpace(ifnm);
43         LookForJrAndIII(ifnm, &ends_jr, &ends_iii, &ends_iv);
44
45         GetMidInit(ifnm, middle);
46
47         FixCase(ifnm);
48 #ifdef notdef
49                 /* okay, finish up first name */
50         AppendJrOrIII(ifnm, &ends_jr, &ends_iii, &ends_iv);
51 #endif notdef
52         strncpy(first, ifnm, FIRST_LEN);
53 }
54 #ifdef notdef
55 AppendJrOrIII(nm, phas_jr, phas_iii, phas_iv)
56 register char *nm;
57 register int *phas_jr;
58 register int *phas_iii;
59 register int *phas_iv;
60 {
61     if (*phas_jr) {
62         strcat(nm, ", Jr.");
63     }
64     else if (*phas_iii) {
65         strcat(nm, " III");
66     }
67     else if (*phas_iv) {
68         strcat(nm, " IV");
69     }
70 }
71 #endif notdef
72 FixCase(p)
73 register char *p;
74 {
75     register int cflag; /* convert to lcase, unless at start or following */
76                         /* a space or punctuation mark (e.g., '-') */
77
78     for (cflag = 0; *p; p++) {
79         if (cflag && isupper(*p)) {
80             *p = tolower(*p);
81         }
82         else if (isspace(*p) || ispunct(*p)) {
83             cflag = 0;
84         }
85         else {
86             cflag = 1;
87         }
88     }
89 }
90
91 LookForJrAndIII(nm, pends_jr, pends_iii, pends_iv)
92 register char *nm;
93 register int *pends_jr;
94 register int *pends_iii;
95 register int *pends_iv;
96 {
97     register int len = strlen(nm);
98
99     if (len >= 4 && !strcmp(nm + len - 3, " JR")) {
100         *pends_jr = 1;
101         nm[len - 3] = '\0';
102     }
103     else if (len >= 4 && !strcmp(nm + len - 3, " IV")) {
104         *pends_iv = 1;
105         nm[len - 3] = '\0';
106     }
107     else if (len >= 5 && !strcmp(nm + len - 4, " JR.")) {
108         *pends_jr = 1;
109         nm[len - 4] = '\0';
110     }
111     else if (len >= 5 && !strcmp(nm + len - 4, " III")) {
112         *pends_iii = 1;
113         nm[len - 4] = '\0';
114     }
115 }
116
117 LookForSt(nm)           /* ST PIERRE, etc. */
118 register char *nm;
119 {
120     char temp[256];
121
122     if (!strcmp(nm,"ST ")) {
123         strcpy(temp, nm + 3);
124         strcpy(nm, "ST. ");
125         strcat(nm, temp);
126     }
127 }
128
129 LookForO(nm)            /* O BRIEN, etc. */
130 register char *nm;
131 {
132     if (!strcmp(nm, "O ") && isalpha(nm[2])) {
133         nm[1] = '\'';
134     }
135 }
136
137 TrimTrailingSpace(ip)
138 register char *ip;
139 {
140     register char *p;
141     for (p = ip + strlen(ip) - 1; p >= ip && isspace(*p); p--) {
142         *p = '\0';
143     }
144 }
145
146 Upcase(cp)
147         char *cp;
148 {
149         register int c;
150         
151         for ( ; c= *cp; cp++)
152                 if (islower(c)) *cp = toupper(c);
153 }
154
155 GetMidInit(nm, mi)
156 register char *nm;      /* truncate at first space, if any such */
157 register char *mi;      /* set to first char after first space, if any such */
158 {
159     while (*nm && !isspace(*nm)) {
160         nm++;
161     }
162     if (*nm) {
163         *nm++ = '\0';
164     }
165     while (*nm && isspace(*nm)) {
166         nm++;
167     }
168     if (*nm) {
169         *mi++ = *nm;
170     }
171     *mi = '\0';
172 }
This page took 0.409299 seconds and 5 git commands to generate.