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