Fixed compile warnings from stricmp in indtext module on Windows.

This commit is contained in:
Steve Karg
2024-07-16 17:46:38 -05:00
parent 544075f5fd
commit 2e222b70c4
+65 -9
View File
@@ -33,13 +33,18 @@
####COPYRIGHTEND####*/
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
#include "bacnet/indtext.h"
/** @file indtext.c Maps text strings and indices of type INDTEXT_DATA */
#if !defined(__BORLANDC__) && !defined(_MSC_VER)
#include <ctype.h>
int stricmp(const char *s1, const char *s2)
/**
* @brief Compare two strings ignoring case
* @param s1 - first string
* @param s2 - second string
* @return 0 if the strings are equal, otherwise non-zero
*/
static int indtext_stricmp(const char *s1, const char *s2)
{
unsigned char c1, c2;
@@ -54,11 +59,14 @@ int stricmp(const char *s1, const char *s2)
return (int)c1 - c2;
}
#endif
#if defined(_MSC_VER)
#define stricmp _stricmp
#endif
/**
* @brief Search a list of strings to find a matching string
* @param data_list - list of strings and indices
* @param search_name - string to search for
* @param found_index - index of the string found
* @return true if the string is found
*/
bool indtext_by_string(
INDTEXT_DATA *data_list, const char *search_name, unsigned *found_index)
{
@@ -83,7 +91,13 @@ bool indtext_by_string(
return found;
}
/* case insensitive version */
/**
* @brief Search a list of strings to find a matching string, case insensitive
* @param data_list - list of strings and indices
* @param search_name - string to search for
* @param found_index - index of the string found
* @return true if the string is found
*/
bool indtext_by_istring(
INDTEXT_DATA *data_list, const char *search_name, unsigned *found_index)
{
@@ -92,7 +106,7 @@ bool indtext_by_istring(
if (data_list && search_name) {
while (data_list->pString) {
if (stricmp(data_list->pString, search_name) == 0) {
if (indtext_stricmp(data_list->pString, search_name) == 0) {
index = data_list->index;
found = true;
break;
@@ -108,6 +122,14 @@ bool indtext_by_istring(
return found;
}
/**
* @brief Search a list of strings to find a matching string,
* or return a default index
* @param data_list - list of strings and indices
* @param search_name - string to search for
* @param default_index - index to return if the string is not found
* @return index of the string found, or the default index
*/
unsigned indtext_by_string_default(
INDTEXT_DATA *data_list, const char *search_name, unsigned default_index)
{
@@ -120,6 +142,14 @@ unsigned indtext_by_string_default(
return index;
}
/**
* @brief Search a list of strings to find a matching string, case insensitive
* or return a default index
* @param data_list - list of strings and indices
* @param search_name - string to search for
* @param default_index - index to return if the string is not found
* @return index of the string found, or the default index
*/
unsigned indtext_by_istring_default(
INDTEXT_DATA *data_list, const char *search_name, unsigned default_index)
{
@@ -132,6 +162,12 @@ unsigned indtext_by_istring_default(
return index;
}
/**
* @brief Return the string for a given index
* @param data_list - list of strings and indices
* @param index - index to search for
* @return the string found, or NULL if not found
*/
const char *indtext_by_index_default(
INDTEXT_DATA *data_list, unsigned index, const char *default_string)
{
@@ -150,6 +186,15 @@ const char *indtext_by_index_default(
return pString ? pString : default_string;
}
/**
* @brief Return the string for a given index, or a default string
* @param data_list - list of strings and indices
* @param index - index to search for
* @param before_split_default_name - default string to return if the index
* is before the split_index
* @param default_name - default string to return if the index is not found
* @return the string found, or a default string
*/
const char *indtext_by_index_split_default(INDTEXT_DATA *data_list,
unsigned index,
unsigned split_index,
@@ -164,11 +209,22 @@ const char *indtext_by_index_split_default(INDTEXT_DATA *data_list,
}
}
/**
* @brief Return the string for a given index
* @param data_list - list of strings and indices
* @param index - index to search for
* @return the string found, or NULL if not found
*/
const char *indtext_by_index(INDTEXT_DATA *data_list, unsigned index)
{
return indtext_by_index_default(data_list, index, NULL);
}
/**
* @brief Return the number of elements in the list
* @param data_list - list of strings and indices
* @return the number of elements in the list
*/
unsigned indtext_count(INDTEXT_DATA *data_list)
{
unsigned count = 0; /* return value */