diff --git a/apps/ptransfer/main.c b/apps/ptransfer/main.c index b3909fa7..f79a9240 100644 --- a/apps/ptransfer/main.c +++ b/apps/ptransfer/main.c @@ -21,6 +21,7 @@ #include "bacnet/bacdef.h" /* BACnet Stack API */ #include "bacnet/bactext.h" +#include "bacnet/bacstr.h" #include "bacnet/bacerror.h" #include "bacnet/iam.h" #include "bacnet/arf.h" @@ -36,11 +37,6 @@ #include "bacnet/datalink/datalink.h" #include "bacnet/datalink/dlenv.h" -#if defined(__BORLANDC__) -#define _kbhit kbhit -#define _stricmp stricmp -#endif - #define MY_MAX_STR 32 #define MY_MAX_BLOCK 8 @@ -215,7 +211,7 @@ int main(int argc, char *argv[]) return 0; } /* decode the command line parameters */ - if (_stricmp(argv[1], "server") == 0) { + if (bacnet_stricmp(argv[1], "server") == 0) { Target_Mode = 1; } else { Target_Mode = 0; diff --git a/src/bacnet/bacstr.c b/src/bacnet/bacstr.c index 12053b86..5ff9c065 100644 --- a/src/bacnet/bacstr.c +++ b/src/bacnet/bacstr.c @@ -393,31 +393,6 @@ bool characterstring_init( return status; } -/** - * @brief Return the length of a string, within a maximum length - * @note The strnlen function is non-standard and not available in - * all libc implementations. This function is a workaround for that. - * @details The strnlen function computes the smaller of the number - * of characters in the array pointed to by s, not including any - * terminating null character, or the value of the maxlen argument. - * The strnlen function examines no more than maxlen bytes of the - * array pointed to by s. - * @param s - string to check - * @param maxlen - maximum length to check - * @return The strnlen function returns the number of bytes that - * precede the first null character in the array pointed to by s, - * if s contains a null character within the first maxlen characters; - * otherwise, it returns maxlen. - */ -size_t characterstring_strnlen(const char *str, size_t maxlen) -{ - const char *p = memchr(str, 0, maxlen); - if (p == NULL) { - return maxlen; - } - return (p - str); -} - /** * Initialize a BACnet character string. * Returns false if the string exceeds capacity. @@ -434,7 +409,7 @@ bool characterstring_init_ansi_safe( { return characterstring_init( char_string, CHARACTER_ANSI_X34, value, - value ? characterstring_strnlen(value, tmax) : 0); + value ? bacnet_strnlen(value, tmax) : 0); } /** @@ -1246,3 +1221,51 @@ bool octetstring_value_same( return false; } #endif + +/** + * @brief Compare two strings, case insensitive + * @param a - first string + * @param b - second string + * @return 0 if the strings are equal, non-zero if not + * @note The stricmp() function is not included C standard. + */ +int bacnet_stricmp(const char *a, const char *b) +{ + int twin_a, twin_b; + + do { + twin_a = *(const unsigned char *)a; + twin_b = *(const unsigned char *)b; + twin_a = tolower(toupper(twin_a)); + twin_b = tolower(toupper(twin_b)); + a++; + b++; + } while ((twin_a == twin_b) && (twin_a != '\0')); + + return twin_a - twin_b; +} + +/** + * @brief Return the length of a string, within a maximum length + * @note The strnlen function is non-standard and not available in + * all libc implementations. This function is a workaround for that. + * @details The strnlen function computes the smaller of the number + * of characters in the array pointed to by s, not including any + * terminating null character, or the value of the maxlen argument. + * The strnlen function examines no more than maxlen bytes of the + * array pointed to by s. + * @param s - string to check + * @param maxlen - maximum length to check + * @return The strnlen function returns the number of bytes that + * precede the first null character in the array pointed to by s, + * if s contains a null character within the first maxlen characters; + * otherwise, it returns maxlen. + */ +size_t bacnet_strnlen(const char *str, size_t maxlen) +{ + const char *p = memchr(str, 0, maxlen); + if (p == NULL) { + return maxlen; + } + return (p - str); +} diff --git a/src/bacnet/bacstr.h b/src/bacnet/bacstr.h index 3ceedead..e6a4d17e 100644 --- a/src/bacnet/bacstr.h +++ b/src/bacnet/bacstr.h @@ -81,8 +81,6 @@ BACNET_STACK_EXPORT bool characterstring_init_ansi( BACNET_CHARACTER_STRING *char_string, const char *value); BACNET_STACK_EXPORT -size_t characterstring_strnlen(const char *str, size_t maxlen); -BACNET_STACK_EXPORT bool characterstring_init_ansi_safe( BACNET_CHARACTER_STRING *char_string, const char *value, size_t tmax); BACNET_STACK_EXPORT @@ -169,6 +167,11 @@ bool octetstring_value_same( const BACNET_OCTET_STRING *octet_string1, const BACNET_OCTET_STRING *octet_string2); +BACNET_STACK_EXPORT +int bacnet_stricmp(const char *a, const char *b); +BACNET_STACK_EXPORT +size_t bacnet_strnlen(const char *str, size_t maxlen); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/bacnet/basic/sys/lighting_command.c b/src/bacnet/basic/sys/lighting_command.c index 92869410..17d8e02d 100644 --- a/src/bacnet/basic/sys/lighting_command.c +++ b/src/bacnet/basic/sys/lighting_command.c @@ -37,11 +37,14 @@ static void lighting_command_tracking_value_notify( } data->Tracking_Value_Callback(data->Key, old_value, value); } else { - debug_printf("Lighting-Command[%lu]-Out-of-Service\n", data->Key); + debug_printf( + "Lighting-Command[%lu]-Out-of-Service\n", + (unsigned long)data->Key); } } else { debug_printf( - "Lighting-Command[%lu]-Tracking-Value=%f\n", data->Key, value); + "Lighting-Command[%lu]-Tracking-Value=%f\n", + (unsigned long)data->Key, (double)value); } } diff --git a/src/bacnet/indtext.c b/src/bacnet/indtext.c index 8ad207f1..75afd018 100644 --- a/src/bacnet/indtext.c +++ b/src/bacnet/indtext.c @@ -9,31 +9,9 @@ #include #include #include "bacnet/bacdef.h" +#include "bacnet/bacstr.h" #include "bacnet/indtext.h" -/** - * @brief Compare two strings, case insensitive - * @param a - first string - * @param b - second string - * @return 0 if the strings are equal, non-zero if not - * @note The stricmp() function is not included C standard. - */ -int indtext_stricmp(const char *a, const char *b) -{ - int twin_a, twin_b; - - do { - twin_a = *(const unsigned char *)a; - twin_b = *(const unsigned char *)b; - twin_a = tolower(toupper(twin_a)); - twin_b = tolower(toupper(twin_b)); - a++; - b++; - } while ((twin_a == twin_b) && (twin_a != '\0')); - - return twin_a - twin_b; -} - /** * @brief Search a list of strings to find a matching string * @param data_list - list of strings and indices @@ -80,7 +58,7 @@ bool indtext_by_istring( if (data_list && search_name) { while (data_list->pString) { - if (indtext_stricmp(data_list->pString, search_name) == 0) { + if (bacnet_stricmp(data_list->pString, search_name) == 0) { index = data_list->index; found = true; break; diff --git a/src/bacnet/indtext.h b/src/bacnet/indtext.h index 4f68b253..1ab2af7c 100644 --- a/src/bacnet/indtext.h +++ b/src/bacnet/indtext.h @@ -24,9 +24,6 @@ typedef const struct { extern "C" { #endif /* __cplusplus */ -BACNET_STACK_EXPORT -int indtext_stricmp(const char *a, const char *b); - /* Searches for a matching string and returns the index to the string in the parameter found_index. If the string is not found, false is returned diff --git a/test/bacnet/indtext/CMakeLists.txt b/test/bacnet/indtext/CMakeLists.txt index dc673c6a..0235bb8c 100644 --- a/test/bacnet/indtext/CMakeLists.txt +++ b/test/bacnet/indtext/CMakeLists.txt @@ -34,6 +34,7 @@ add_executable(${PROJECT_NAME} # File(s) under test ${SRC_DIR}/bacnet/indtext.c # Support files and stubs (pathname alphabetical) + ${SRC_DIR}/bacnet/bacstr.c # Test and test library files ./src/main.c ${ZTST_DIR}/ztest_mock.c