[5e53c4a] | 1 | /* |
---|
| 2 | * |
---|
| 3 | * |
---|
| 4 | * |
---|
| 5 | */ |
---|
| 6 | |
---|
| 7 | #define FAIM_INTERNAL |
---|
| 8 | #include <aim.h> |
---|
| 9 | #include <ctype.h> |
---|
| 10 | |
---|
| 11 | faim_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 | */ |
---|
| 22 | faim_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 | |
---|
| 46 | faim_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 | |
---|
| 63 | faim_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 | */ |
---|
| 111 | faim_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 | */ |
---|
| 141 | |
---|
| 142 | faim_export int aim_sncmp(const char *sn1, const char *sn2) |
---|
| 143 | { |
---|
| 144 | const char *curPtr1 = NULL, *curPtr2 = NULL; |
---|
| 145 | |
---|
| 146 | if (aim_snlen(sn1) != aim_snlen(sn2)) |
---|
| 147 | return 1; |
---|
| 148 | |
---|
| 149 | curPtr1 = sn1; |
---|
| 150 | curPtr2 = sn2; |
---|
| 151 | while ( (*curPtr1 != (char) NULL) && (*curPtr2 != (char) NULL) ) { |
---|
| 152 | if ( (*curPtr1 == ' ') || (*curPtr2 == ' ') ) { |
---|
| 153 | if (*curPtr1 == ' ') |
---|
| 154 | curPtr1++; |
---|
| 155 | if (*curPtr2 == ' ') |
---|
| 156 | curPtr2++; |
---|
| 157 | } else { |
---|
| 158 | if ( toupper(*curPtr1) != toupper(*curPtr2)) |
---|
| 159 | return 1; |
---|
| 160 | curPtr1++; |
---|
| 161 | curPtr2++; |
---|
| 162 | } |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | /* Should both be NULL */ |
---|
| 166 | if (*curPtr1 != *curPtr2) |
---|
| 167 | return 1; |
---|
| 168 | |
---|
| 169 | return 0; |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | /* strsep Copyright (C) 1992, 1993 Free Software Foundation, Inc. |
---|
| 173 | strsep is part of the GNU C Library. |
---|
| 174 | |
---|
| 175 | The GNU C Library is free software; you can redistribute it and/or |
---|
| 176 | modify it under the terms of the GNU Library General Public License as |
---|
| 177 | published by the Free Software Foundation; either version 2 of the |
---|
| 178 | License, or (at your option) any later version. |
---|
| 179 | |
---|
| 180 | The GNU C Library is distributed in the hope that it will be useful, |
---|
| 181 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 182 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 183 | Library General Public License for more details. |
---|
| 184 | |
---|
| 185 | You should have received a copy of the GNU Library General Public |
---|
| 186 | License along with the GNU C Library; see the file COPYING.LIB. If |
---|
| 187 | not, write to the Free Software Foundation, Inc., 675 Mass Ave, |
---|
| 188 | Cambridge, MA 02139, USA. */ |
---|
| 189 | |
---|
| 190 | /* Minor changes by and1000 on 15/1/97 to make it go under Nemesis */ |
---|
| 191 | |
---|
| 192 | faim_export char *aim_strsep(char **pp, const char *delim) |
---|
| 193 | { |
---|
| 194 | char *p, *q; |
---|
| 195 | |
---|
| 196 | if (!(p = *pp)) |
---|
| 197 | return 0; |
---|
| 198 | |
---|
| 199 | if ((q = strpbrk (p, delim))) { |
---|
| 200 | *pp = q + 1; |
---|
| 201 | *q = '\0'; |
---|
| 202 | } else |
---|
| 203 | *pp = 0; |
---|
| 204 | |
---|
| 205 | return p; |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | |
---|