source: protocols/oscar/oscar_util.c @ 68198e9

Last change on this file since 68198e9 was 5d6c178, checked in by Jelmer Vernooij <jelmer@…>, at 2006-05-10T12:47:55Z

Fix compilation with tcc

  • Property mode set to 100644
File size: 2.8 KB
Line 
1#include <aim.h>
2#include <ctype.h>
3
4int aimutil_putstr(u_char *dest, const char *src, int len)
5{
6        memcpy(dest, src, len);
7        return len;
8}
9
10/*
11 * Tokenizing functions.  Used to portably replace strtok/sep.
12 *   -- DMP.
13 *
14 */
15int aimutil_tokslen(char *toSearch, int index, char dl)
16{
17        int curCount = 1;
18        char *next;
19        char *last;
20        int toReturn;
21
22        last = toSearch;
23        next = strchr(toSearch, dl);
24
25        while(curCount < index && next != NULL) {
26                curCount++;
27                last = next + 1;
28                next = strchr(last, dl);
29        }
30
31        if ((curCount < index) || (next == NULL))
32                toReturn = strlen(toSearch) - (curCount - 1);
33        else
34                toReturn = next - toSearch - (curCount - 1);
35
36        return toReturn;
37}
38
39int aimutil_itemcnt(char *toSearch, char dl)
40{
41        int curCount;
42        char *next;
43
44        curCount = 1;
45
46        next = strchr(toSearch, dl);
47
48        while(next != NULL) {
49                curCount++;
50                next = strchr(next + 1, dl);
51        }
52
53        return curCount;
54}
55
56char *aimutil_itemidx(char *toSearch, int index, char dl)
57{
58        int curCount;
59        char *next;
60        char *last;
61        char *toReturn;
62
63        curCount = 0;
64
65        last = toSearch;
66        next = strchr(toSearch, dl);
67
68        while (curCount < index && next != NULL) {
69                curCount++;
70                last = next + 1;
71                next = strchr(last, dl);
72        }
73
74        if (curCount < index) {
75                toReturn = g_strdup("");
76        }
77        next = strchr(last, dl);
78
79        if (curCount < index) {
80                toReturn = g_strdup("");
81        } else {
82                if (next == NULL) {
83                        toReturn = g_malloc((strlen(last) + 1) * sizeof(char));
84                        strcpy(toReturn, last);
85                } else {
86                        toReturn = g_malloc((next - last + 1) * sizeof(char));
87                        memcpy(toReturn, last, (next - last));
88                        toReturn[next - last] = '\0';
89                }
90        }
91        return toReturn;
92}
93
94/*
95* int snlen(const char *)
96*
97* This takes a screen name and returns its length without
98* spaces.  If there are no spaces in the SN, then the
99* return is equal to that of strlen().
100*
101*/
102static int aim_snlen(const char *sn)
103{
104        int i = 0;
105        const char *curPtr = NULL;
106
107        if (!sn)
108                return 0;
109
110        curPtr = sn;
111        while ( (*curPtr) != (char) '\0') {
112                if ((*curPtr) != ' ')
113                i++;
114                curPtr++;
115        }
116
117        return i;
118}
119
120/*
121* int sncmp(const char *, const char *)
122*
123* This takes two screen names and compares them using the rules
124* on screen names for AIM/AOL.  Mainly, this means case and space
125* insensitivity (all case differences and spacing differences are
126* ignored).
127*
128* Return: 0 if equal
129*     non-0 if different
130*
131*/
132
133int aim_sncmp(const char *sn1, const char *sn2)
134{
135        const char *curPtr1 = NULL, *curPtr2 = NULL;
136
137        if (aim_snlen(sn1) != aim_snlen(sn2))
138                return 1;
139
140        curPtr1 = sn1;
141        curPtr2 = sn2;
142        while ( (*curPtr1 != (char) '\0') && (*curPtr2 != (char) '\0') ) {
143                if ( (*curPtr1 == ' ') || (*curPtr2 == ' ') ) {
144                        if (*curPtr1 == ' ')
145                                curPtr1++;
146                        if (*curPtr2 == ' ')
147                                curPtr2++;
148                } else {
149                        if ( toupper(*curPtr1) != toupper(*curPtr2))
150                                return 1;
151                        curPtr1++;
152                        curPtr2++;
153                }
154        }
155
156        /* Should both be NULL */
157        if (*curPtr1 != *curPtr2)
158                return 1;
159
160        return 0;
161}
Note: See TracBrowser for help on using the repository browser.