]> andersk Git - libfaim.git/blame_incremental - src/util.c
- Sun Oct 14 19:45:54 PDT 2001
[libfaim.git] / src / util.c
... / ...
CommitLineData
1/*
2 *
3 *
4 *
5 */
6
7#include <aim.h>
8#include <ctype.h>
9
10faim_export faim_shortfunc int aimutil_putstr(u_char *dest, const char *src, int len)
11{
12 memcpy(dest, src, len);
13 return len;
14}
15
16/*
17 * Tokenizing functions. Used to portably replace strtok/sep.
18 * -- DMP.
19 *
20 */
21faim_export int aimutil_tokslen(char *toSearch, int index, char dl)
22{
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;
43}
44
45faim_export int aimutil_itemcnt(char *toSearch, char dl)
46{
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;
60}
61
62faim_export char *aimutil_itemidx(char *toSearch, int index, char dl)
63{
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);
78 }
79
80 if (curCount < index) {
81 toReturn = malloc(sizeof(char));
82 *toReturn = '\0';
83 }
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;
100}
101
102/*
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*/
110faim_export int aim_snlen(const char *sn)
111{
112 int i = 0;
113 const char *curPtr = NULL;
114
115 if (!sn)
116 return 0;
117
118 curPtr = sn;
119 while ( (*curPtr) != (char) NULL) {
120 if ((*curPtr) != ' ')
121 i++;
122 curPtr++;
123 }
124
125 return i;
126}
127
128/*
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*/
140
141faim_export int aim_sncmp(const char *sn1, const char *sn2)
142{
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;
165}
166
167/* strsep Copyright (C) 1992, 1993 Free Software Foundation, Inc.
168strsep is part of the GNU C Library.
169
170The GNU C Library is free software; you can redistribute it and/or
171modify it under the terms of the GNU Library General Public License as
172published by the Free Software Foundation; either version 2 of the
173License, or (at your option) any later version.
174
175The GNU C Library is distributed in the hope that it will be useful,
176but WITHOUT ANY WARRANTY; without even the implied warranty of
177MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
178Library General Public License for more details.
179
180You should have received a copy of the GNU Library General Public
181License along with the GNU C Library; see the file COPYING.LIB. If
182not, write to the Free Software Foundation, Inc., 675 Mass Ave,
183Cambridge, MA 02139, USA. */
184
185/* Minor changes by and1000 on 15/1/97 to make it go under Nemesis */
186
187faim_export char *aim_strsep(char **pp, const char *delim)
188{
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;
201}
202
203
This page took 0.030625 seconds and 5 git commands to generate.