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