10 #ifdef AIMUTIL_USEMACROS
11 /* macros in faim/aim.h */
13 faim_shortfunc int aimutil_put8(u_char *buf, u_char data)
15 buf[0] = (u_char)data&0xff;
19 faim_shortfunc u_char aimutil_get8(u_char *buf)
25 * Endian-ness issues here?
27 faim_shortfunc int aimutil_put16(u_char *buf, u_short data)
29 buf[0] = (u_char)(data>>8)&0xff;
30 buf[1] = (u_char)(data)&0xff;
34 faim_shortfunc u_short aimutil_get16(u_char *buf)
37 val = (buf[0] << 8) & 0xff00;
38 val+= (buf[1]) & 0xff;
42 faim_shortfunc int aimutil_put32(u_char *buf, u_long data)
44 buf[0] = (u_char)(data>>24)&0xff;
45 buf[1] = (u_char)(data>>16)&0xff;
46 buf[2] = (u_char)(data>>8)&0xff;
47 buf[3] = (u_char)(data)&0xff;
51 faim_shortfunc u_long aimutil_get32(u_char *buf)
54 val = (buf[0] << 24) & 0xff000000;
55 val+= (buf[1] << 16) & 0x00ff0000;
56 val+= (buf[2] << 8) & 0x0000ff00;
57 val+= (buf[3] ) & 0x000000ff;
60 #endif /* AIMUTIL_USEMACROS */
62 faim_export faim_shortfunc int aimutil_putstr(u_char *dest, const char *src, int len)
64 memcpy(dest, src, len);
69 * Tokenizing functions. Used to portably replace strtok/sep.
73 faim_export int aimutil_tokslen(char *toSearch, int index, char dl)
81 next = strchr(toSearch, dl);
83 while(curCount < index && next != NULL)
87 next = strchr(last, dl);
90 if ((curCount < index) || (next == NULL))
91 toReturn = strlen(toSearch) - (curCount - 1);
93 toReturn = next - toSearch - (curCount - 1);
98 faim_export int aimutil_itemcnt(char *toSearch, char dl)
105 next = strchr(toSearch, dl);
110 next = strchr(next + 1, dl);
116 faim_export char *aimutil_itemidx(char *toSearch, int index, char dl)
126 next = strchr(toSearch, dl);
128 while(curCount < index && next != NULL)
132 next = strchr(last, dl);
135 if (curCount < index)
137 toReturn = malloc(sizeof(char));
140 next = strchr(last, dl);
142 if (curCount < index)
144 toReturn = malloc(sizeof(char));
151 toReturn = malloc((strlen(last) + 1) * sizeof(char));
152 strcpy(toReturn, last);
156 toReturn = malloc((next - last + 1) * sizeof(char));
157 memcpy(toReturn, last, (next - last));
158 toReturn[next - last] = '\0';
165 * int snlen(const char *)
167 * This takes a screen name and returns its length without
168 * spaces. If there are no spaces in the SN, then the
169 * return is equal to that of strlen().
172 faim_export int aim_snlen(const char *sn)
175 const char *curPtr = NULL;
181 while ( (*curPtr) != (char) NULL) {
182 if ((*curPtr) != ' ')
191 * int sncmp(const char *, const char *)
193 * This takes two screen names and compares them using the rules
194 * on screen names for AIM/AOL. Mainly, this means case and space
195 * insensitivity (all case differences and spacing differences are
203 faim_export int aim_sncmp(const char *sn1, const char *sn2)
205 const char *curPtr1 = NULL, *curPtr2 = NULL;
207 if (aim_snlen(sn1) != aim_snlen(sn2))
212 while ( (*curPtr1 != (char) NULL) && (*curPtr2 != (char) NULL) ) {
213 if ( (*curPtr1 == ' ') || (*curPtr2 == ' ') ) {
219 if ( toupper(*curPtr1) != toupper(*curPtr2))
229 /* strsep Copyright (C) 1992, 1993 Free Software Foundation, Inc.
230 strsep is part of the GNU C Library.
232 The GNU C Library is free software; you can redistribute it and/or
233 modify it under the terms of the GNU Library General Public License as
234 published by the Free Software Foundation; either version 2 of the
235 License, or (at your option) any later version.
237 The GNU C Library is distributed in the hope that it will be useful,
238 but WITHOUT ANY WARRANTY; without even the implied warranty of
239 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
240 Library General Public License for more details.
242 You should have received a copy of the GNU Library General Public
243 License along with the GNU C Library; see the file COPYING.LIB. If
244 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
245 Cambridge, MA 02139, USA. */
247 /* Minor changes by and1000 on 15/1/97 to make it go under Nemesis */
249 faim_export char *aim_strsep(char **pp, const char *delim)
256 if ((q = strpbrk (p, delim)))