]>
Commit | Line | Data |
---|---|---|
9de3ca7e | 1 | /* |
2 | * | |
3 | * | |
4 | * | |
5 | */ | |
6 | ||
dd60ff8b | 7 | #include <aim.h> |
e6b05d80 | 8 | #include <ctype.h> |
9de3ca7e | 9 | |
78b3fb13 | 10 | faim_export faim_shortfunc int aimutil_putstr(u_char *dest, const char *src, int len) |
9de3ca7e | 11 | { |
d410cf58 | 12 | memcpy(dest, src, len); |
13 | return len; | |
9de3ca7e | 14 | } |
15 | ||
16 | /* | |
17 | * Tokenizing functions. Used to portably replace strtok/sep. | |
18 | * -- DMP. | |
19 | * | |
20 | */ | |
78b3fb13 | 21 | faim_export int aimutil_tokslen(char *toSearch, int index, char dl) |
9de3ca7e | 22 | { |
d410cf58 | 23 | int curCount = 1; |
24 | char *next; | |
25 | char *last; | |
26 | int toReturn; | |
27 | ||
28 | last = toSearch; | |
29 | next = strchr(toSearch, dl); | |
30 | ||
31 | while(curCount < index && next != NULL) { | |
32 | curCount++; | |
33 | last = next + 1; | |
34 | next = strchr(last, dl); | |
35 | } | |
36 | ||
37 | if ((curCount < index) || (next == NULL)) | |
38 | toReturn = strlen(toSearch) - (curCount - 1); | |
39 | else | |
40 | toReturn = next - toSearch - (curCount - 1); | |
41 | ||
42 | return toReturn; | |
9de3ca7e | 43 | } |
44 | ||
78b3fb13 | 45 | faim_export int aimutil_itemcnt(char *toSearch, char dl) |
9de3ca7e | 46 | { |
d410cf58 | 47 | int curCount; |
48 | char *next; | |
49 | ||
50 | curCount = 1; | |
51 | ||
52 | next = strchr(toSearch, dl); | |
53 | ||
54 | while(next != NULL) { | |
55 | curCount++; | |
56 | next = strchr(next + 1, dl); | |
57 | } | |
58 | ||
59 | return curCount; | |
9de3ca7e | 60 | } |
61 | ||
78b3fb13 | 62 | faim_export char *aimutil_itemidx(char *toSearch, int index, char dl) |
9de3ca7e | 63 | { |
d410cf58 | 64 | int curCount; |
65 | char *next; | |
66 | char *last; | |
67 | char *toReturn; | |
68 | ||
69 | curCount = 0; | |
70 | ||
71 | last = toSearch; | |
72 | next = strchr(toSearch, dl); | |
73 | ||
74 | while (curCount < index && next != NULL) { | |
75 | curCount++; | |
76 | last = next + 1; | |
77 | next = strchr(last, dl); | |
9de3ca7e | 78 | } |
d410cf58 | 79 | |
80 | if (curCount < index) { | |
81 | toReturn = malloc(sizeof(char)); | |
82 | *toReturn = '\0'; | |
9de3ca7e | 83 | } |
d410cf58 | 84 | next = strchr(last, dl); |
85 | ||
86 | if (curCount < index) { | |
87 | toReturn = malloc(sizeof(char)); | |
88 | *toReturn = '\0'; | |
89 | } else { | |
90 | if (next == NULL) { | |
91 | toReturn = malloc((strlen(last) + 1) * sizeof(char)); | |
92 | strcpy(toReturn, last); | |
93 | } else { | |
94 | toReturn = malloc((next - last + 1) * sizeof(char)); | |
95 | memcpy(toReturn, last, (next - last)); | |
96 | toReturn[next - last] = '\0'; | |
97 | } | |
98 | } | |
99 | return toReturn; | |
9de3ca7e | 100 | } |
e6b05d80 | 101 | |
102 | /* | |
d410cf58 | 103 | * int snlen(const char *) |
104 | * | |
105 | * This takes a screen name and returns its length without | |
106 | * spaces. If there are no spaces in the SN, then the | |
107 | * return is equal to that of strlen(). | |
108 | * | |
109 | */ | |
78b3fb13 | 110 | faim_export int aim_snlen(const char *sn) |
e6b05d80 | 111 | { |
d410cf58 | 112 | int i = 0; |
113 | const char *curPtr = NULL; | |
e6b05d80 | 114 | |
d410cf58 | 115 | if (!sn) |
116 | return 0; | |
e6b05d80 | 117 | |
d410cf58 | 118 | curPtr = sn; |
119 | while ( (*curPtr) != (char) NULL) { | |
120 | if ((*curPtr) != ' ') | |
121 | i++; | |
122 | curPtr++; | |
123 | } | |
e6b05d80 | 124 | |
d410cf58 | 125 | return i; |
e6b05d80 | 126 | } |
127 | ||
128 | /* | |
d410cf58 | 129 | * int sncmp(const char *, const char *) |
130 | * | |
131 | * This takes two screen names and compares them using the rules | |
132 | * on screen names for AIM/AOL. Mainly, this means case and space | |
133 | * insensitivity (all case differences and spacing differences are | |
134 | * ignored). | |
135 | * | |
136 | * Return: 0 if equal | |
137 | * non-0 if different | |
138 | * | |
139 | */ | |
e6b05d80 | 140 | |
78b3fb13 | 141 | faim_export int aim_sncmp(const char *sn1, const char *sn2) |
e6b05d80 | 142 | { |
d410cf58 | 143 | const char *curPtr1 = NULL, *curPtr2 = NULL; |
144 | ||
145 | if (aim_snlen(sn1) != aim_snlen(sn2)) | |
146 | return 1; | |
147 | ||
148 | curPtr1 = sn1; | |
149 | curPtr2 = sn2; | |
150 | while ( (*curPtr1 != (char) NULL) && (*curPtr2 != (char) NULL) ) { | |
151 | if ( (*curPtr1 == ' ') || (*curPtr2 == ' ') ) { | |
152 | if (*curPtr1 == ' ') | |
153 | curPtr1++; | |
154 | if (*curPtr2 == ' ') | |
155 | curPtr2++; | |
156 | } else { | |
157 | if ( toupper(*curPtr1) != toupper(*curPtr2)) | |
158 | return 1; | |
159 | curPtr1++; | |
160 | curPtr2++; | |
161 | } | |
162 | } | |
163 | ||
164 | return 0; | |
e6b05d80 | 165 | } |
a3619f23 | 166 | |
167 | /* strsep Copyright (C) 1992, 1993 Free Software Foundation, Inc. | |
d410cf58 | 168 | strsep is part of the GNU C Library. |
169 | ||
170 | The GNU C Library is free software; you can redistribute it and/or | |
171 | modify it under the terms of the GNU Library General Public License as | |
172 | published by the Free Software Foundation; either version 2 of the | |
173 | License, or (at your option) any later version. | |
174 | ||
175 | The GNU C Library is distributed in the hope that it will be useful, | |
176 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
177 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
178 | Library General Public License for more details. | |
179 | ||
180 | You should have received a copy of the GNU Library General Public | |
181 | License along with the GNU C Library; see the file COPYING.LIB. If | |
182 | not, write to the Free Software Foundation, Inc., 675 Mass Ave, | |
183 | Cambridge, MA 02139, USA. */ | |
a3619f23 | 184 | |
185 | /* Minor changes by and1000 on 15/1/97 to make it go under Nemesis */ | |
186 | ||
78b3fb13 | 187 | faim_export char *aim_strsep(char **pp, const char *delim) |
a3619f23 | 188 | { |
d410cf58 | 189 | char *p, *q; |
190 | ||
191 | if (!(p = *pp)) | |
192 | return 0; | |
193 | ||
194 | if ((q = strpbrk (p, delim))) { | |
195 | *pp = q + 1; | |
196 | *q = '\0'; | |
197 | } else | |
198 | *pp = 0; | |
199 | ||
200 | return p; | |
a3619f23 | 201 | } |
d410cf58 | 202 | |
203 |