]> andersk Git - moira.git/blame - lib/fixname.c
eliminate use of the `register' keyword: let the compiler decide
[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$";
a43ce477 13#endif
de56407f 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
5eaef520 22void FixName(char *ilnm, char *ifnm, char *last, char *first, char *middle)
de56407f 23{
5eaef520 24 int ends_jr = 0, ends_iii = 0, ends_iv = 0, ends_ii = 0, ends_v = 0;
de56407f 25
5eaef520 26 uppercase(ilnm);
27 uppercase(ifnm);
de56407f 28
5eaef520 29 /* Last name ... */
de56407f 30
5eaef520 31 TrimTrailingSpace(ilnm);
32 LookForJrAndIII(ilnm, &ends_jr, &ends_ii, &ends_iii, &ends_iv, &ends_v);
33 LookForSt(ilnm);
34 LookForO(ilnm);
35 FixCase(ilnm);
36 strncpy(last, ilnm, LAST_LEN);
de56407f 37
5eaef520 38 /* First name & middle initial ... */
de56407f 39
5eaef520 40 TrimTrailingSpace(ifnm);
41 LookForJrAndIII(ifnm, &ends_jr, &ends_ii, &ends_iii, &ends_iv, &ends_v);
de56407f 42
5eaef520 43 GetMidInit(ifnm, middle);
44
45 FixCase(ifnm);
de56407f 46#ifdef notdef
5eaef520 47 /* okay, finish up first name */
48 AppendJrOrIII(ifnm, &ends_jr, &ends_ii, &ends_iii, &ends_iv, &ends_v);
a43ce477 49#endif
5eaef520 50 strncpy(first, ifnm, FIRST_LEN);
de56407f 51}
0d8039b1 52
44d12d58 53FixCase(char *p)
de56407f 54{
44d12d58 55 int cflag; /* convert to lcase, unless at start or following */
56 /* a space or punctuation mark (e.g., '-') */
de56407f 57
5eaef520 58 for (cflag = 0; *p; p++)
59 {
60 if (cflag && isupper(*p))
61 *p = tolower(*p);
62 else if (!cflag && islower(*p))
63 *p = toupper(*p);
64 if (isalpha(*p))
65 cflag = 1;
66 else
67 cflag = 0;
de56407f 68 }
69}
70
44d12d58 71LookForJrAndIII(char *nm, int *pends_jr, int *pends_ii, int *pends_iii,
72 int *pends_iv, int *pends_v)
de56407f 73{
44d12d58 74 int len = strlen(nm);
de56407f 75
5eaef520 76 if (len >= 4 && !strcmp(nm + len - 3, " JR"))
77 {
78 *pends_jr = 1;
79 nm[len - 3] = '\0';
de56407f 80 }
5eaef520 81 else if (len >= 4 && !strcmp(nm + len - 3, " IV"))
82 {
83 *pends_iv = 1;
84 nm[len - 3] = '\0';
de56407f 85 }
5eaef520 86 else if (len >= 5 && !strcmp(nm + len - 4, " JR."))
87 {
88 *pends_jr = 1;
89 nm[len - 4] = '\0';
de56407f 90 }
5eaef520 91 else if (len >= 5 && !strcmp(nm + len - 4, " III"))
92 {
93 *pends_iii = 1;
94 nm[len - 4] = '\0';
de56407f 95 }
5eaef520 96 else if (len >= 4 && !strcmp(nm + len - 3, " II"))
97 {
98 *pends_ii = 1;
99 nm[len - 3] = '\0';
9d787e1c 100 }
5eaef520 101 else if (len >= 3 && !strcmp(nm + len - 2, " V"))
102 {
103 *pends_v = 1;
104 nm[len - 2] = '\0';
9d787e1c 105 }
de56407f 106}
107
44d12d58 108LookForSt(char *nm) /* ST PIERRE, etc. */
de56407f 109{
5eaef520 110 char temp[256];
de56407f 111
5eaef520 112 if (!strcmp(nm, "ST "))
113 {
114 strcpy(temp, nm + 3);
115 strcpy(nm, "ST. ");
116 strcat(nm, temp);
de56407f 117 }
118}
119
44d12d58 120LookForO(char *nm) /* O BRIEN, etc. */
de56407f 121{
5eaef520 122 if (!strcmp(nm, "O ") && isalpha(nm[2]))
123 nm[1] = '\'';
de56407f 124}
125
44d12d58 126TrimTrailingSpace(char *ip)
de56407f 127{
44d12d58 128 char *p;
5eaef520 129 for (p = ip + strlen(ip) - 1; p >= ip && isspace(*p); p--)
130 *p = '\0';
de56407f 131}
132
44d12d58 133GetMidInit(char *nm, char *mi)
de56407f 134{
5eaef520 135 while (*nm && !isspace(*nm))
136 nm++;
137 if (*nm)
138 *nm++ = '\0';
139 while (*nm && isspace(*nm))
140 nm++;
141 if (*nm)
142 *mi++ = *nm;
143 *mi = '\0';
de56407f 144}
This page took 0.11848 seconds and 5 git commands to generate.