Rev | Line | |
---|
[b7d3cc34] | 1 | #include <aim.h> |
---|
| 2 | #include <ctype.h> |
---|
| 3 | |
---|
| 4 | /* |
---|
| 5 | * int snlen(const char *) |
---|
| 6 | * |
---|
| 7 | * This takes a screen name and returns its length without |
---|
| 8 | * spaces. If there are no spaces in the SN, then the |
---|
| 9 | * return is equal to that of strlen(). |
---|
| 10 | * |
---|
| 11 | */ |
---|
| 12 | static int aim_snlen(const char *sn) |
---|
| 13 | { |
---|
| 14 | int i = 0; |
---|
| 15 | const char *curPtr = NULL; |
---|
| 16 | |
---|
| 17 | if (!sn) |
---|
| 18 | return 0; |
---|
| 19 | |
---|
| 20 | curPtr = sn; |
---|
[5d6c178] | 21 | while ( (*curPtr) != (char) '\0') { |
---|
[b7d3cc34] | 22 | if ((*curPtr) != ' ') |
---|
| 23 | i++; |
---|
| 24 | curPtr++; |
---|
| 25 | } |
---|
| 26 | |
---|
| 27 | return i; |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | /* |
---|
| 31 | * int sncmp(const char *, const char *) |
---|
| 32 | * |
---|
| 33 | * This takes two screen names and compares them using the rules |
---|
| 34 | * on screen names for AIM/AOL. Mainly, this means case and space |
---|
| 35 | * insensitivity (all case differences and spacing differences are |
---|
| 36 | * ignored). |
---|
| 37 | * |
---|
| 38 | * Return: 0 if equal |
---|
| 39 | * non-0 if different |
---|
| 40 | * |
---|
| 41 | */ |
---|
| 42 | |
---|
| 43 | int aim_sncmp(const char *sn1, const char *sn2) |
---|
| 44 | { |
---|
| 45 | const char *curPtr1 = NULL, *curPtr2 = NULL; |
---|
| 46 | |
---|
| 47 | if (aim_snlen(sn1) != aim_snlen(sn2)) |
---|
| 48 | return 1; |
---|
| 49 | |
---|
| 50 | curPtr1 = sn1; |
---|
| 51 | curPtr2 = sn2; |
---|
[5d6c178] | 52 | while ( (*curPtr1 != (char) '\0') && (*curPtr2 != (char) '\0') ) { |
---|
[b7d3cc34] | 53 | if ( (*curPtr1 == ' ') || (*curPtr2 == ' ') ) { |
---|
| 54 | if (*curPtr1 == ' ') |
---|
| 55 | curPtr1++; |
---|
| 56 | if (*curPtr2 == ' ') |
---|
| 57 | curPtr2++; |
---|
| 58 | } else { |
---|
| 59 | if ( toupper(*curPtr1) != toupper(*curPtr2)) |
---|
| 60 | return 1; |
---|
| 61 | curPtr1++; |
---|
| 62 | curPtr2++; |
---|
| 63 | } |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | /* Should both be NULL */ |
---|
| 67 | if (*curPtr1 != *curPtr2) |
---|
| 68 | return 1; |
---|
| 69 | |
---|
| 70 | return 0; |
---|
| 71 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.