]> andersk Git - moira.git/blob - lib/fixname.c
added the function lowercase()
[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
55 FixCase(p)
56 register 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++) {
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;
70     }
71 }
72
73 LookForJrAndIII(nm, pends_jr, pends_iii, pends_iv)
74 register char *nm;
75 register int *pends_jr;
76 register int *pends_iii;
77 register 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
99 LookForSt(nm)           /* ST PIERRE, etc. */
100 register 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
111 LookForO(nm)            /* O BRIEN, etc. */
112 register char *nm;
113 {
114     if (!strcmp(nm, "O ") && isalpha(nm[2])) {
115         nm[1] = '\'';
116     }
117 }
118
119 TrimTrailingSpace(ip)
120 register 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
128 Upcase(cp)
129         char *cp;
130 {
131         register int c;
132         
133         for ( ; c= *cp; cp++)
134                 if (islower(c)) *cp = toupper(c);
135 }
136
137 GetMidInit(nm, mi)
138 register char *nm;      /* truncate at first space, if any such */
139 register 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 0.056122 seconds and 5 git commands to generate.