source: protocols/oscar/oscar_util.c @ b7d3cc34

0.99
Last change on this file since b7d3cc34 was b7d3cc34, checked in by Wilmer van der Gaast <wilmer@…>, at 2005-11-06T18:23:18Z

Initial repository (0.99 release tree)

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 *
3 *
4 *
5 */
6
7#include <aim.h>
8#include <ctype.h>
9
10int 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 */
21int 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
45int 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
62char *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 = g_strdup("");
82        }
83        next = strchr(last, dl);
84
85        if (curCount < index) {
86                toReturn = g_strdup("");
87        } else {
88                if (next == NULL) {
89                        toReturn = g_malloc((strlen(last) + 1) * sizeof(char));
90                        strcpy(toReturn, last);
91                } else {
92                        toReturn = g_malloc((next - last + 1) * sizeof(char));
93                        memcpy(toReturn, last, (next - last));
94                        toReturn[next - last] = '\0';
95                }
96        }
97        return toReturn;
98}
99
100/*
101* int snlen(const char *)
102*
103* This takes a screen name and returns its length without
104* spaces.  If there are no spaces in the SN, then the
105* return is equal to that of strlen().
106*
107*/
108static int aim_snlen(const char *sn)
109{
110        int i = 0;
111        const char *curPtr = NULL;
112
113        if (!sn)
114                return 0;
115
116        curPtr = sn;
117        while ( (*curPtr) != (char) NULL) {
118                if ((*curPtr) != ' ')
119                i++;
120                curPtr++;
121        }
122
123        return i;
124}
125
126/*
127* int sncmp(const char *, const char *)
128*
129* This takes two screen names and compares them using the rules
130* on screen names for AIM/AOL.  Mainly, this means case and space
131* insensitivity (all case differences and spacing differences are
132* ignored).
133*
134* Return: 0 if equal
135*     non-0 if different
136*
137*/
138
139int aim_sncmp(const char *sn1, const char *sn2)
140{
141        const char *curPtr1 = NULL, *curPtr2 = NULL;
142
143        if (aim_snlen(sn1) != aim_snlen(sn2))
144                return 1;
145
146        curPtr1 = sn1;
147        curPtr2 = sn2;
148        while ( (*curPtr1 != (char) NULL) && (*curPtr2 != (char) NULL) ) {
149                if ( (*curPtr1 == ' ') || (*curPtr2 == ' ') ) {
150                        if (*curPtr1 == ' ')
151                                curPtr1++;
152                        if (*curPtr2 == ' ')
153                                curPtr2++;
154                } else {
155                        if ( toupper(*curPtr1) != toupper(*curPtr2))
156                                return 1;
157                        curPtr1++;
158                        curPtr2++;
159                }
160        }
161
162        /* Should both be NULL */
163        if (*curPtr1 != *curPtr2)
164                return 1;
165
166        return 0;
167}
Note: See TracBrowser for help on using the repository browser.