]> andersk Git - moira.git/blame - lib/fixname.c
added uppercase()
[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>
de56407f 16#include <strings.h>
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{
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}
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
73LookForJrAndIII(nm, pends_jr, pends_iii, pends_iv)
74register char *nm;
75register int *pends_jr;
76register int *pends_iii;
77register int *pends_iv;
78{
79 register int len = strlen(nm);
80
81 if (len >= 4 && !strcmp(nm + len - 3, " JR")) {
82 *pends_jr = 1;
83 nm[len - 3] = '\0';
84 }
85 else if (len >= 4 && !strcmp(nm + len - 3, " IV")) {
86 *pends_iv = 1;
87 nm[len - 3] = '\0';
88 }
89 else if (len >= 5 && !strcmp(nm + len - 4, " JR.")) {
90 *pends_jr = 1;
91 nm[len - 4] = '\0';
92 }
93 else if (len >= 5 && !strcmp(nm + len - 4, " III")) {
94 *pends_iii = 1;
95 nm[len - 4] = '\0';
96 }
97}
98
99LookForSt(nm) /* ST PIERRE, etc. */
100register char *nm;
101{
102 char temp[256];
103
104 if (!strcmp(nm,"ST ")) {
105 strcpy(temp, nm + 3);
106 strcpy(nm, "ST. ");
107 strcat(nm, temp);
108 }
109}
110
111LookForO(nm) /* O BRIEN, etc. */
112register char *nm;
113{
114 if (!strcmp(nm, "O ") && isalpha(nm[2])) {
115 nm[1] = '\'';
116 }
117}
118
119TrimTrailingSpace(ip)
120register char *ip;
121{
122 register char *p;
123 for (p = ip + strlen(ip) - 1; p >= ip && isspace(*p); p--) {
124 *p = '\0';
125 }
126}
127
128Upcase(cp)
129 char *cp;
130{
131 register int c;
132
133 for ( ; c= *cp; cp++)
134 if (islower(c)) *cp = toupper(c);
135}
136
137GetMidInit(nm, mi)
138register char *nm; /* truncate at first space, if any such */
139register char *mi; /* set to first char after first space, if any such */
140{
141 while (*nm && !isspace(*nm)) {
142 nm++;
143 }
144 if (*nm) {
145 *nm++ = '\0';
146 }
147 while (*nm && isspace(*nm)) {
148 nm++;
149 }
150 if (*nm) {
151 *mi++ = *nm;
152 }
153 *mi = '\0';
154}
This page took 2.527102 seconds and 5 git commands to generate.