source: libfaim/util.c @ 453bd70

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