Author: mturk Date: Sat Dec 12 09:25:38 2009 New Revision: 889902 URL: http://svn.apache.org/viewvc?rev=889902&view=rev Log: Add functions for array sorting. Used for sorting the environment blocks
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr.h commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h commons/sandbox/runtime/trunk/src/main/native/shared/string.c Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr.h?rev=889902&r1=889901&r2=889902&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/acr.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/acr.h Sat Dec 12 09:25:38 2009 @@ -253,7 +253,9 @@ /* Define synonims for some common posix functions */ #define snprintf _snprintf #define strcasecmp _stricmp +#define wcscasecmp _wcsicmp #define strncasecmp _strnicmp +#define wcsncasecmp _wcsnicmp #define vsnprintf _vsnprintf typedef ptrdiff_t acr_ssize_t; Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h?rev=889902&r1=889901&r2=889902&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/acr_string.h Sat Dec 12 09:25:38 2009 @@ -439,8 +439,21 @@ */ ACR_DECLARE(size_t) ACR_StrTokenize(char *s, char **args, size_t maxargs); +/** + * Sort the array of string using case insensitive order + * @param pointer to char array to sort. + */ +ACR_DECLARE(void) ACR_StrSortA(char ***args); + +/** + * Sort the array of wide string using case insensitive order + * @param pointer to the wide char array to sort. + */ +ACR_DECLARE(void) ACR_StrSortW(wchar_t ***args); + #ifdef __cplusplus } #endif #endif /* _ACR_STRING_H */ + Modified: commons/sandbox/runtime/trunk/src/main/native/shared/string.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/string.c?rev=889902&r1=889901&r2=889902&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/shared/string.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/shared/string.c Sat Dec 12 09:25:38 2009 @@ -2031,3 +2031,36 @@ return nargs; } + +static int _strcompare(const void *arg1, const void *arg2) +{ + /* Compare all of both strings: */ + return strcasecmp(*(char **)arg1, *(char **)arg2); +} + +static int _wcscompare(const void *arg1, const void *arg2) +{ + /* Compare all of both strings: */ + return wcscasecmp(*(wchar_t **)arg1, *(wchar_t **)arg2); +} + +ACR_DECLARE(void) ACR_StrSortA(char ***args) +{ + size_t len = 0; + char **sa = *args; + + while (sa[len]) + len++; + qsort((void *)&args, len, sizeof(char *), _strcompare); +} + +ACR_DECLARE(void) ACR_StrSortW(wchar_t ***args) +{ + size_t len = 0; + wchar_t **sa = *args; + + while (sa[len]) + len++; + qsort((void *)&args, len, sizeof(wchar_t *), _wcscompare); +} +