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