diff options
| author | rburchell <rburchell@5417fbe8-f217-4b02-8779-1006273d7864> | 2008-11-14 20:57:20 +0000 |
|---|---|---|
| committer | rburchell <rburchell@5417fbe8-f217-4b02-8779-1006273d7864> | 2008-11-14 20:57:20 +0000 |
| commit | 6c55e0a529c7f1216ff6f63a4fc77ea06a2a3a38 (patch) | |
| tree | 91b0841faf23087ebe0c74dd4269d181a383f1e7 /src/misc.c | |
| parent | 069409cd99cf78ab8bf87a1fe69a833576414fd3 (diff) | |
Insane commit of doom: s/ \t/g
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1681 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src/misc.c')
| -rw-r--r-- | src/misc.c | 1962 |
1 files changed, 981 insertions, 981 deletions
diff --git a/src/misc.c b/src/misc.c index 091d83c51..df0b628f6 100644 --- a/src/misc.c +++ b/src/misc.c @@ -20,43 +20,43 @@ #define issp(c) ((c) == 32) struct arc4_stream { - u_int8_t i; - u_int8_t j; - u_int8_t s[256]; + u_int8_t i; + u_int8_t j; + u_int8_t s[256]; } rs; /*************************************************************************/ /** * toupper: Like the ANSI functions, but make sure we return an - * int instead of a (signed) char. + * int instead of a (signed) char. * @param c Char * @return int */ int toupper(char c) { - if (islower(c)) { - return (unsigned char) c - ('a' - 'A'); - } else { - return (unsigned char) c; - } + if (islower(c)) { + return (unsigned char) c - ('a' - 'A'); + } else { + return (unsigned char) c; + } } /*************************************************************************/ /** * tolower: Like the ANSI functions, but make sure we return an - * int instead of a (signed) char. + * int instead of a (signed) char. * @param c Char * @return int */ int tolower(char c) { - if (isupper(c)) { - return (unsigned char) c + ('a' - 'A'); - } else { - return (unsigned char) c; - } + if (isupper(c)) { + return (unsigned char) c + ('a' - 'A'); + } else { + return (unsigned char) c; + } } /*************************************************************************/ @@ -67,15 +67,15 @@ int tolower(char c) */ void binary_to_hex(unsigned char *bin, char *hex, int length) { - static const char trans[] = "0123456789ABCDEF"; - int i; + static const char trans[] = "0123456789ABCDEF"; + int i; - for (i = 0; i < length; i++) { - hex[i << 1] = trans[bin[i] >> 4]; - hex[(i << 1) + 1] = trans[bin[i] & 0xf]; - } + for (i = 0; i < length; i++) { + hex[i << 1] = trans[bin[i] >> 4]; + hex[(i << 1) + 1] = trans[bin[i] & 0xf]; + } - hex[i << 1] = '\0'; + hex[i << 1] = '\0'; } @@ -83,7 +83,7 @@ void binary_to_hex(unsigned char *bin, char *hex, int length) /** * strscpy: Copy at most len-1 characters from a string to a buffer, and - * add a null terminator after the last character copied. + * add a null terminator after the last character copied. * @param d Buffer to copy into * @param s Data to copy int * @param len Length of data @@ -91,51 +91,51 @@ void binary_to_hex(unsigned char *bin, char *hex, int length) */ char *strscpy(char *d, const char *s, size_t len) { - char *d_orig = d; - - if (!len) { - return d; - } - while (--len && (*d++ = *s++)); - *d = '\0'; - return d_orig; + char *d_orig = d; + + if (!len) { + return d; + } + while (--len && (*d++ = *s++)); + *d = '\0'; + return d_orig; } /*************************************************************************/ /** * stristr: Search case-insensitively for string s2 within string s1, - * returning the first occurrence of s2 or NULL if s2 was not - * found. + * returning the first occurrence of s2 or NULL if s2 was not + * found. * @param s1 String 1 * @param s2 String 2 * @return first occurrence of s2 */ char *stristr(char *s1, char *s2) { - register char *s = s1, *d = s2; - - while (*s1) { - if (tolower(*s1) == tolower(*d)) { - s1++; - d++; - if (*d == 0) - return s; - } else { - s = ++s1; - d = s2; - } - } - return NULL; + register char *s = s1, *d = s2; + + while (*s1) { + if (tolower(*s1) == tolower(*d)) { + s1++; + d++; + if (*d == 0) + return s; + } else { + s = ++s1; + d = s2; + } + } + return NULL; } /*************************************************************************/ /** * strnrepl: Replace occurrences of `old' with `new' in string `s'. Stop - * replacing if a replacement would cause the string to exceed - * `size' bytes (including the null terminator). Return the - * string. + * replacing if a replacement would cause the string to exceed + * `size' bytes (including the null terminator). Return the + * string. * @param s String * @param size size of s * @param old character to replace @@ -144,51 +144,51 @@ char *stristr(char *s1, char *s2) */ char *strnrepl(char *s, int32 size, const char *old, const char *newstr) { - char *ptr = s; - int32 left = strlen(s); - int32 avail = size - (left + 1); - int32 oldlen = strlen(old); - int32 newlen = strlen(newstr); - int32 diff = newlen - oldlen; - - while (left >= oldlen) { - if (strncmp(ptr, old, oldlen) != 0) { - left--; - ptr++; - continue; - } - if (diff > avail) - break; - if (diff != 0) - memmove(ptr + oldlen + diff, ptr + oldlen, left + 1 - oldlen); - strncpy(ptr, newstr, newlen); - ptr += newlen; - left -= oldlen; - } - return s; + char *ptr = s; + int32 left = strlen(s); + int32 avail = size - (left + 1); + int32 oldlen = strlen(old); + int32 newlen = strlen(newstr); + int32 diff = newlen - oldlen; + + while (left >= oldlen) { + if (strncmp(ptr, old, oldlen) != 0) { + left--; + ptr++; + continue; + } + if (diff > avail) + break; + if (diff != 0) + memmove(ptr + oldlen + diff, ptr + oldlen, left + 1 - oldlen); + strncpy(ptr, newstr, newlen); + ptr += newlen; + left -= oldlen; + } + return s; } /*************************************************************************/ /** * merge_args: Take an argument count and argument vector and merge them - * into a single string in which each argument is separated by - * a space. + * into a single string in which each argument is separated by + * a space. * @param int Number of Args * @param argv Array * @return string of the merged array */ const char *merge_args(int argc, const char **argv) { - int i; - static char s[4096]; - char *t; - - t = s; - for (i = 0; i < argc; i++) - t += snprintf(t, sizeof(s) - (t - s), "%s%s", *argv++, - (i < argc - 1) ? " " : ""); - return s; + int i; + static char s[4096]; + char *t; + + t = s; + for (i = 0; i < argc; i++) + t += snprintf(t, sizeof(s) - (t - s), "%s%s", *argv++, + (i < argc - 1) ? " " : ""); + return s; } /* @@ -196,23 +196,23 @@ const char *merge_args(int argc, const char **argv) */ const char *merge_args(int argc, char **argv) { - int i; - static char s[4096]; - char *t; - - t = s; - for (i = 0; i < argc; i++) - t += snprintf(t, sizeof(s) - (t - s), "%s%s", *argv++, - (i < argc - 1) ? " " : ""); - return s; + int i; + static char s[4096]; + char *t; + + t = s; + for (i = 0; i < argc; i++) + t += snprintf(t, sizeof(s) - (t - s), "%s%s", *argv++, + (i < argc - 1) ? " " : ""); + return s; } /*************************************************************************/ /** * do_match_wild: Attempt to match a string to a pattern which might contain - * '*' or '?' wildcards. Return 1 if the string matches the - * pattern, 0 if not. + * '*' or '?' wildcards. Return 1 if the string matches the + * pattern, 0 if not. * @param pattern To be matched * @param str String in which the pattern is to be matched * @param docase Case In/Senstive @@ -220,45 +220,45 @@ const char *merge_args(int argc, char **argv) */ static int do_match_wild(const char *pattern, const char *str, int docase) { - char c; - const char *s; - - if (!str || !*str || !pattern || !*pattern) { - return 0; - } - - /* This WILL eventually terminate: either by *pattern == 0, or by a - * trailing '*'. */ - - for (;;) { - switch (c = *pattern++) { - case 0: - if (!*str) - return 1; - return 0; - case '?': - if (!*str) - return 0; - str++; - break; - case '*': - if (!*pattern) - return 1; /* trailing '*' matches everything else */ - s = str; - while (*s) { - if ((docase ? (*s == *pattern) - : (tolower(*s) == tolower(*pattern))) - && do_match_wild(pattern, s, docase)) - return 1; - s++; - } - break; - default: - if (docase ? (*str++ != c) : (tolower(*str++) != tolower(c))) - return 0; - break; - } /* switch */ - } + char c; + const char *s; + + if (!str || !*str || !pattern || !*pattern) { + return 0; + } + + /* This WILL eventually terminate: either by *pattern == 0, or by a + * trailing '*'. */ + + for (;;) { + switch (c = *pattern++) { + case 0: + if (!*str) + return 1; + return 0; + case '?': + if (!*str) + return 0; + str++; + break; + case '*': + if (!*pattern) + return 1; /* trailing '*' matches everything else */ + s = str; + while (*s) { + if ((docase ? (*s == *pattern) + : (tolower(*s) == tolower(*pattern))) + && do_match_wild(pattern, s, docase)) + return 1; + s++; + } + break; + default: + if (docase ? (*str++ != c) : (tolower(*str++) != tolower(c))) + return 0; + break; + } /* switch */ + } } /*************************************************************************/ @@ -271,7 +271,7 @@ static int do_match_wild(const char *pattern, const char *str, int docase) */ int match_wild(const char *pattern, const char *str) { - return do_match_wild(pattern, str, 1); + return do_match_wild(pattern, str, 1); } /*************************************************************************/ @@ -284,7 +284,7 @@ int match_wild(const char *pattern, const char *str) */ int match_wild_nocase(const char *pattern, const char *str) { - return do_match_wild(pattern, str, 0); + return do_match_wild(pattern, str, 0); } /*************************************************************************/ @@ -307,102 +307,102 @@ int match_wild_nocase(const char *pattern, const char *str) * @return int */ int process_numlist(const char *numstr, int *count_ret, - range_callback_t callback, User * u, ...) + range_callback_t callback, User * u, ...) { - int n1, n2, i; - int res = 0, retval = 0, count = 0; - va_list args, preserve; - - if (!numstr || !*numstr) { - return -1; - } - - va_start(args, u); - - /* - * This algorithm ignores invalid characters, ignores a dash - * when it precedes a comma, and ignores everything from the - * end of a valid number or range to the next comma or null. - */ - for (;;) { - n1 = n2 = strtol(numstr, (char **) &numstr, 10); - numstr += strcspn(numstr, "0123456789,-"); - if (*numstr == '-') { - numstr++; - numstr += strcspn(numstr, "0123456789,"); - if (isdigit(*numstr)) { - n2 = strtol(numstr, (char **) &numstr, 10); - numstr += strcspn(numstr, "0123456789,-"); - } - } - for (i = n1; i <= n2 && i >= 0; i++) { - VA_COPY(preserve, args); - res = callback(u, i, preserve); - va_end(preserve); - count++; - if (res < 0) - break; - retval += res; - if (count >= 32767) { - if (count_ret) - *count_ret = count; - return retval; - } - } - if (res < -1) - break; - numstr += strcspn(numstr, ","); - if (*numstr) - numstr++; - else - break; - } - if (count_ret) - *count_ret = count; - - va_end(args); - - return retval; + int n1, n2, i; + int res = 0, retval = 0, count = 0; + va_list args, preserve; + + if (!numstr || !*numstr) { + return -1; + } + + va_start(args, u); + + /* + * This algorithm ignores invalid characters, ignores a dash + * when it precedes a comma, and ignores everything from the + * end of a valid number or range to the next comma or null. + */ + for (;;) { + n1 = n2 = strtol(numstr, (char **) &numstr, 10); + numstr += strcspn(numstr, "0123456789,-"); + if (*numstr == '-') { + numstr++; + numstr += strcspn(numstr, "0123456789,"); + if (isdigit(*numstr)) { + n2 = strtol(numstr, (char **) &numstr, 10); + numstr += strcspn(numstr, "0123456789,-"); + } + } + for (i = n1; i <= n2 && i >= 0; i++) { + VA_COPY(preserve, args); + res = callback(u, i, preserve); + va_end(preserve); + count++; + if (res < 0) + break; + retval += res; + if (count >= 32767) { + if (count_ret) + *count_ret = count; + return retval; + } + } + if (res < -1) + break; + numstr += strcspn(numstr, ","); + if (*numstr) + numstr++; + else + break; + } + if (count_ret) + *count_ret = count; + + va_end(args); + + return retval; } /*************************************************************************/ /** * dotime: Return the number of seconds corresponding to the given time - * string. If the given string does not represent a valid time, - * return -1. + * string. If the given string does not represent a valid time, + * return -1. * - * A time string is either a plain integer (representing a number - * of seconds), or an integer followed by one of these characters: - * "s" (seconds), "m" (minutes), "h" (hours), or "d" (days). + * A time string is either a plain integer (representing a number + * of seconds), or an integer followed by one of these characters: + * "s" (seconds), "m" (minutes), "h" (hours), or "d" (days). * @param s String to convert * @return int */ int dotime(const char *s) { - int amount; - - if (!s || !*s) { - return -1; - } - - amount = strtol(s, (char **) &s, 10); - if (*s) { - switch (*s) { - case 's': - return amount; - case 'm': - return amount * 60; - case 'h': - return amount * 3600; - case 'd': - return amount * 86400; - default: - return -1; - } - } else { - return amount; - } + int amount; + + if (!s || !*s) { + return -1; + } + + amount = strtol(s, (char **) &s, 10); + if (*s) { + switch (*s) { + case 's': + return amount; + case 'm': + return amount * 60; + case 'h': + return amount * 3600; + case 'd': + return amount * 86400; + default: + return -1; + } + } else { + return amount; + } } /*************************************************************************/ @@ -418,60 +418,60 @@ int dotime(const char *s) */ char *duration(NickAlias * na, char *buf, int bufsize, time_t seconds) { - int days = 0, hours = 0, minutes = 0; - int need_comma = 0; - - char buf2[64], *end; - char *comma = getstring(na, COMMA_SPACE); - - /* We first calculate everything */ - days = seconds / 86400; - seconds -= (days * 86400); - hours = seconds / 3600; - seconds -= (hours * 3600); - minutes = seconds / 60; - - if (!days && !hours && !minutes) { - snprintf(buf, bufsize, - getstring(na, - (seconds <= - 1 ? DURATION_SECOND : DURATION_SECONDS)), - seconds); - } else { - end = buf; - if (days) { - snprintf(buf2, sizeof(buf2), - getstring(na, - (days == 1 ? DURATION_DAY : DURATION_DAYS)), - days); - end += snprintf(end, bufsize - (end - buf), "%s", buf2); - need_comma = 1; - } - if (hours) { - snprintf(buf2, sizeof(buf2), - getstring(na, - (hours == - 1 ? DURATION_HOUR : DURATION_HOURS)), - hours); - end += - snprintf(end, bufsize - (end - buf), "%s%s", - (need_comma ? comma : ""), buf2); - need_comma = 1; - } - if (minutes) { - snprintf(buf2, sizeof(buf2), - getstring(na, - (minutes == - 1 ? DURATION_MINUTE : DURATION_MINUTES)), - minutes); - end += - snprintf(end, bufsize - (end - buf), "%s%s", - (need_comma ? comma : ""), buf2); - need_comma = 1; - } - } - - return buf; + int days = 0, hours = 0, minutes = 0; + int need_comma = 0; + + char buf2[64], *end; + char *comma = getstring(na, COMMA_SPACE); + + /* We first calculate everything */ + days = seconds / 86400; + seconds -= (days * 86400); + hours = seconds / 3600; + seconds -= (hours * 3600); + minutes = seconds / 60; + + if (!days && !hours && !minutes) { + snprintf(buf, bufsize, + getstring(na, + (seconds <= + 1 ? DURATION_SECOND : DURATION_SECONDS)), + seconds); + } else { + end = buf; + if (days) { + snprintf(buf2, sizeof(buf2), + getstring(na, + (days == 1 ? DURATION_DAY : DURATION_DAYS)), + days); + end += snprintf(end, bufsize - (end - buf), "%s", buf2); + need_comma = 1; + } + if (hours) { + snprintf(buf2, sizeof(buf2), + getstring(na, + (hours == + 1 ? DURATION_HOUR : DURATION_HOURS)), + hours); + end += + snprintf(end, bufsize - (end - buf), "%s%s", + (need_comma ? comma : ""), buf2); + need_comma = 1; + } + if (minutes) { + snprintf(buf2, sizeof(buf2), + getstring(na, + (minutes == + 1 ? DURATION_MINUTE : DURATION_MINUTES)), + minutes); + end += + snprintf(end, bufsize - (end - buf), "%s%s", + (need_comma ? comma : ""), buf2); + need_comma = 1; + } + } + + return buf; } /*************************************************************************/ @@ -486,49 +486,49 @@ char *duration(NickAlias * na, char *buf, int bufsize, time_t seconds) */ char *expire_left(NickAlias * na, char *buf, int len, time_t expires) { - time_t now = time(NULL); - - if (!expires) { - strncpy(buf, getstring(na, NO_EXPIRE), len); - } else if (expires <= now) { - strncpy(buf, getstring(na, EXPIRES_SOON), len); - } else { - time_t diff = expires - now + 59; - - if (diff >= 86400) { - int days = diff / 86400; - snprintf(buf, len, - getstring(na, (days == 1) ? EXPIRES_1D : EXPIRES_D), - days); - } else { - if (diff <= 3600) { - int minutes = diff / 60; - snprintf(buf, len, - getstring(na, - (minutes == - 1) ? EXPIRES_1M : EXPIRES_M), minutes); - } else { - int hours = diff / 3600, minutes; - diff -= (hours * 3600); - minutes = diff / 60; - snprintf(buf, len, - getstring(na, - ((hours == 1 - && minutes == - 1) ? EXPIRES_1H1M : ((hours == 1 - && minutes != - 1) ? EXPIRES_1HM - : ((hours != 1 - && minutes == - 1) ? - EXPIRES_H1M : - EXPIRES_HM)))), - hours, minutes); - } - } - } - - return buf; + time_t now = time(NULL); + + if (!expires) { + strncpy(buf, getstring(na, NO_EXPIRE), len); + } else if (expires <= now) { + strncpy(buf, getstring(na, EXPIRES_SOON), len); + } else { + time_t diff = expires - now + 59; + + if (diff >= 86400) { + int days = diff / 86400; + snprintf(buf, len, + getstring(na, (days == 1) ? EXPIRES_1D : EXPIRES_D), + days); + } else { + if (diff <= 3600) { + int minutes = diff / 60; + snprintf(buf, len, + getstring(na, + (minutes == + 1) ? EXPIRES_1M : EXPIRES_M), minutes); + } else { + int hours = diff / 3600, minutes; + diff -= (hours * 3600); + minutes = diff / 60; + snprintf(buf, len, + getstring(na, + ((hours == 1 + && minutes == + 1) ? EXPIRES_1H1M : ((hours == 1 + && minutes != + 1) ? EXPIRES_1HM + : ((hours != 1 + && minutes == + 1) ? + EXPIRES_H1M : + EXPIRES_HM)))), + hours, minutes); + } + } + } + + return buf; } @@ -538,86 +538,86 @@ char *expire_left(NickAlias * na, char *buf, int len, time_t expires) * Validate the host * shortname = ( letter / digit ) *( letter / digit / "-" ) *( letter / digit ) * hostname = shortname *( "." shortname ) - * ip4addr = 1*3digit "." 1*3digit "." 1*3digit "." 1*3digit + * ip4addr = 1*3digit "." 1*3digit "." 1*3digit "." 1*3digit * @param host = string to check * @param type = format, 1 = ip4addr, 2 = hostname * @return 1 if a host is valid, 0 if it isnt. */ int doValidHost(const char *host, int type) { - int idx = 0; - int len = 0; - int sec_len = 0; - int dots = 1; - if (type != 1 && type != 2) { - return 0; - } - if (!host) { - return 0; - } - - len = strlen(host); - - if (len > HOSTMAX) { - return 0; - } - - switch (type) { - case 1: - for (idx = 0; idx < len; idx++) { - if (isdigit(host[idx])) { - if (sec_len < 3) { - sec_len++; - } else { - return 0; - } - } else { - if (idx == 0) { - return 0; - } /* cant start with a non-digit */ - if (host[idx] != '.') { - return 0; - } /* only . is a valid non-digit */ - if (sec_len > 3) { - return 0; - } /* sections cant be more than 3 digits */ - sec_len = 0; - dots++; - } - } - if (dots != 4) { - return 0; - } - break; - case 2: - dots = 0; - for (idx = 0; idx < len; idx++) { - if (!isalnum(host[idx])) { - if (idx == 0) { - return 0; - } - if ((host[idx] != '.') && (host[idx] != '-')) { - return 0; - } - if (host[idx] == '.') { - dots++; - } - } - } - if (host[len - 1] == '.') { - return 0; - } - /** + int idx = 0; + int len = 0; + int sec_len = 0; + int dots = 1; + if (type != 1 && type != 2) { + return 0; + } + if (!host) { + return 0; + } + + len = strlen(host); + + if (len > HOSTMAX) { + return 0; + } + + switch (type) { + case 1: + for (idx = 0; idx < len; idx++) { + if (isdigit(host[idx])) { + if (sec_len < 3) { + sec_len++; + } else { + return 0; + } + } else { + if (idx == 0) { + return 0; + } /* cant start with a non-digit */ + if (host[idx] != '.') { + return 0; + } /* only . is a valid non-digit */ + if (sec_len > 3) { + return 0; + } /* sections cant be more than 3 digits */ + sec_len = 0; + dots++; + } + } + if (dots != 4) { + return 0; + } + break; + case 2: + dots = 0; + for (idx = 0; idx < len; idx++) { + if (!isalnum(host[idx])) { + if (idx == 0) { + return 0; + } + if ((host[idx] != '.') && (host[idx] != '-')) { + return 0; + } + if (host[idx] == '.') { + dots++; + } + } + } + if (host[len - 1] == '.') { + return 0; + } + /** * Ultimate3 dosnt like a non-dotted hosts at all, nor does unreal, * so just dont allow them. **/ - if (dots == 0) { - return 0; - } + if (dots == 0) { + return 0; + } - break; - } - return 1; + break; + } + return 1; } /*************************************************************************/ @@ -630,15 +630,15 @@ int doValidHost(const char *host, int type) */ int isValidHost(const char *host, int type) { - int status = 0; - if (type == 3) { - if (!(status = doValidHost(host, 1))) { - status = doValidHost(host, 2); - } - } else { - status = doValidHost(host, type); - } - return status; + int status = 0; + if (type == 3) { + if (!(status = doValidHost(host, 1))) { + status = doValidHost(host, 2); + } + } else { + status = doValidHost(host, type); + } + return status; } /*************************************************************************/ @@ -650,12 +650,12 @@ int isValidHost(const char *host, int type) */ int isvalidchar(const char c) { - if (((c >= 'A') && (c <= 'Z')) || - ((c >= 'a') && (c <= 'z')) || - ((c >= '0') && (c <= '9')) || (c == '.') || (c == '-')) - return 1; - else - return 0; + if (((c >= 'A') && (c <= 'Z')) || + ((c >= 'a') && (c <= 'z')) || + ((c >= '0') && (c <= '9')) || (c == '.') || (c == '-')) + return 1; + else + return 0; } @@ -670,24 +670,24 @@ int isvalidchar(const char c) */ char *myStrGetToken(const char *str, const char dilim, int token_number) { - int len, idx, counter = 0, start_pos = 0; - char *substring = NULL; - if (!str) { - return NULL; - } - len = strlen(str); - for (idx = 0; idx <= len; idx++) { - if ((str[idx] == dilim) || (idx == len)) { - if (counter == token_number) { - substring = myStrSubString(str, start_pos, idx); - counter++; - } else { - start_pos = idx + 1; - counter++; - } - } - } - return substring; + int len, idx, counter = 0, start_pos = 0; + char *substring = NULL; + if (!str) { + return NULL; + } + len = strlen(str); + for (idx = 0; idx <= len; idx++) { + if ((str[idx] == dilim) || (idx == len)) { + if (counter == token_number) { + substring = myStrSubString(str, start_pos, idx); + counter++; + } else { + start_pos = idx + 1; + counter++; + } + } + } + return substring; } /*************************************************************************/ @@ -700,29 +700,29 @@ char *myStrGetToken(const char *str, const char dilim, int token_number) * @return token */ char *myStrGetOnlyToken(const char *str, const char dilim, - int token_number) + int token_number) { - int len, idx, counter = 0, start_pos = 0; - char *substring = NULL; - if (!str) { - return NULL; - } - len = strlen(str); - for (idx = 0; idx <= len; idx++) { - if (str[idx] == dilim) { - if (counter == token_number) { - if (str[idx] == '\r') - substring = myStrSubString(str, start_pos, idx - 1); - else - substring = myStrSubString(str, start_pos, idx); - counter++; - } else { - start_pos = idx + 1; - counter++; - } - } - } - return substring; + int len, idx, counter = 0, start_pos = 0; + char *substring = NULL; + if (!str) { + return NULL; + } + len = strlen(str); + for (idx = 0; idx <= len; idx++) { + if (str[idx] == dilim) { + if (counter == token_number) { + if (str[idx] == '\r') + substring = myStrSubString(str, start_pos, idx - 1); + else + substring = myStrSubString(str, start_pos, idx); + counter++; + } else { + start_pos = idx + 1; + counter++; + } + } + } + return substring; } /*************************************************************************/ @@ -735,27 +735,27 @@ char *myStrGetOnlyToken(const char *str, const char dilim, * @return token */ char *myStrGetTokenRemainder(const char *str, const char dilim, - int token_number) + int token_number) { - int len, idx, counter = 0, start_pos = 0; - char *substring = NULL; - if (!str) { - return NULL; - } - len = strlen(str); - - for (idx = 0; idx <= len; idx++) { - if ((str[idx] == dilim) || (idx == len)) { - if (counter == token_number) { - substring = myStrSubString(str, start_pos, len); - counter++; - } else { - start_pos = idx + 1; - counter++; - } - } - } - return substring; + int len, idx, counter = 0, start_pos = 0; + char *substring = NULL; + if (!str) { + return NULL; + } + len = strlen(str); + + for (idx = 0; idx <= len; idx++) { + if ((str[idx] == dilim) || (idx == len)) { + if (counter == token_number) { + substring = myStrSubString(str, start_pos, len); + counter++; + } else { + start_pos = idx + 1; + counter++; + } + } + } + return substring; } /*************************************************************************/ @@ -769,20 +769,20 @@ char *myStrGetTokenRemainder(const char *str, const char dilim, */ char *myStrSubString(const char *src, int start, int end) { - char *substring = NULL; - int len, idx; - if (!src) { - return NULL; - } - len = strlen(src); - if (((start >= 0) && (end <= len)) && (end > start)) { - substring = (char *) malloc(sizeof(char) * ((end - start) + 1)); - for (idx = 0; idx <= end - start; idx++) { - substring[idx] = src[start + idx]; - } - substring[end - start] = '\0'; - } - return substring; + char *substring = NULL; + int len, idx; + if (!src) { + return NULL; + } + len = strlen(src); + if (((start >= 0) && (end <= len)) && (end > start)) { + substring = (char *) malloc(sizeof(char) * ((end - start) + 1)); + for (idx = 0; idx <= end - start; idx++) { + substring[idx] = src[start + idx]; + } + substring[end - start] = '\0'; + } + return substring; } /*************************************************************************/ @@ -794,31 +794,31 @@ char *myStrSubString(const char *src, int start, int end) */ void doCleanBuffer(char *str) { - char *in, *out; - char ch; - - if (!str) { - return; - } - - in = str; - out = str; - - while (issp(ch = *in++)); - if (ch != '\0') - for (;;) { - *out++ = ch; - ch = *in++; - if (ch == '\0') - break; - if (!issp(ch)) - continue; - while (issp(ch = *in++)); - if (ch == '\0') - break; - *out++ = ' '; - } - *out = ch; /* == '\0' */ + char *in, *out; + char ch; + + if (!str) { + retur |
