Bugfix/c89 compile fixes (#327)
* Fix code to be able to compile with older C89 ANSI compilers * Convert C++ comments to C89 comments. * default to std=gnu89 * Fix to enable CMake 3.1 to build on Centos7 Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
+2
-1
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
|
||||
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
|
||||
|
||||
project(
|
||||
bacnet-stack
|
||||
@@ -475,6 +475,7 @@ if(ZEPHYR_BASE)
|
||||
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
||||
message(STATUS "BACNET: building for linux")
|
||||
set(BACNET_PORT_DIRECTORY_PATH ${CMAKE_CURRENT_LIST_DIR}/ports/linux)
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC m)
|
||||
|
||||
target_sources(${PROJECT_NAME} PRIVATE
|
||||
ports/linux/bacport.h
|
||||
|
||||
+2
-2
@@ -96,9 +96,9 @@ BACNET_SRC_DIR = $(realpath ../src)
|
||||
# Compiler flag to set the C Standard level.
|
||||
# c89 - "ANSI" C
|
||||
# gnu89 - c89 plus GCC extensions
|
||||
# c99 - ISO C99 standard (not yet fully implemented)
|
||||
# c99 - ISO C99 standard
|
||||
# gnu99 - c99 plus GCC extensions
|
||||
CSTANDARD = -std=gnu99
|
||||
CSTANDARD = -std=gnu89
|
||||
|
||||
#build for release (default) or debug
|
||||
OPTIMIZATION ?= -Os
|
||||
|
||||
@@ -189,7 +189,7 @@ bool dl_ip_init(ROUTER_PORT *port, IP_DATA *ip_data)
|
||||
|
||||
/* bind the socket to the local port number */
|
||||
sin.sin_family = AF_INET;
|
||||
// sin.sin_addr.s_addr, ip_data->local_addr.s_addr;// = htonl(INADDR_ANY);
|
||||
/* sin.sin_addr.s_addr, ip_data->local_addr.s_addr;// = htonl(INADDR_ANY); */
|
||||
sin.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
sin.sin_port = ip_data->port;
|
||||
|
||||
|
||||
+3
-3
@@ -113,7 +113,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
// blocking dequeue here
|
||||
/* blocking dequeue here */
|
||||
bacmsg = recv_from_msgbox(head->main_id, &msg_storage, 0);
|
||||
if (bacmsg) {
|
||||
switch (bacmsg->type) {
|
||||
@@ -127,7 +127,7 @@ int main(int argc, char *argv[])
|
||||
break;
|
||||
}
|
||||
|
||||
// print_msg(bacmsg);
|
||||
/* print_msg(bacmsg); */
|
||||
|
||||
if (is_network_msg(bacmsg)) {
|
||||
buff_len =
|
||||
@@ -153,7 +153,7 @@ int main(int argc, char *argv[])
|
||||
msg_storage.type = DATA;
|
||||
msg_storage.data = msg_data;
|
||||
|
||||
// print_msg(bacmsg);
|
||||
/* print_msg(bacmsg); */
|
||||
|
||||
if (is_network_msg(bacmsg)) {
|
||||
msg_data->ref_count = 1;
|
||||
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
# This script converts any C++ comments to C comments
|
||||
# using the ccmtcnvt tool from the liwc package
|
||||
|
||||
CONVERTER=/usr/bin/ccmtcnvt
|
||||
# silent fail if the tool is not installed
|
||||
[ -x ${CONVERTER} ] || exit 0
|
||||
|
||||
directory=${1-`pwd`}
|
||||
for filename in $( find ${directory} -name '*.c' )
|
||||
do
|
||||
echo Converting ${filename}
|
||||
TEMPFILE="/tmp/ccmtcnvt.$RANDOM.txt"
|
||||
${CONVERTER} ${filename} > ${TEMPFILE}
|
||||
mv ${TEMPFILE} ${filename}
|
||||
done
|
||||
|
||||
for filename in $( find ${directory} -name '*.h' )
|
||||
do
|
||||
echo Converting ${filename}
|
||||
TEMPFILE="/tmp/ccmtcnvt.$RANDOM.txt"
|
||||
${CONVERTER} ${filename} > ${TEMPFILE}
|
||||
mv ${TEMPFILE} ${filename}
|
||||
done
|
||||
|
||||
+5
-5
@@ -1415,9 +1415,9 @@ static int bacapp_snprintf_date(char *str, size_t str_len, BACNET_DATE *bdate)
|
||||
int ret_val = 0;
|
||||
int slen = 0;
|
||||
|
||||
// false positive cppcheck - snprintf allows null pointers
|
||||
// cppcheck-suppress nullPointer
|
||||
// cppcheck-suppress ctunullpointer
|
||||
/* false positive cppcheck - snprintf allows null pointers */
|
||||
/* cppcheck-suppress nullPointer */
|
||||
/* cppcheck-suppress ctunullpointer */
|
||||
slen = snprintf(str, str_len, "%s, %s",
|
||||
bactext_day_of_week_name(bdate->wday),
|
||||
bactext_month_name(bdate->month));
|
||||
@@ -1471,8 +1471,8 @@ static int bacapp_snprintf_time(char *str, size_t str_len, BACNET_TIME *btime)
|
||||
if (btime->hour == 255) {
|
||||
slen = snprintf(str, str_len, "**:");
|
||||
} else {
|
||||
// false positive cppcheck - snprintf allows null pointers
|
||||
// cppcheck-suppress nullPointer
|
||||
/* false positive cppcheck - snprintf allows null pointers */
|
||||
/* cppcheck-suppress nullPointer */
|
||||
slen = snprintf(str, str_len, "%02u:",
|
||||
(unsigned)btime->hour);
|
||||
}
|
||||
|
||||
@@ -50,4 +50,4 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif // BACNET_STACK_EXPORTS_H
|
||||
#endif /* BACNET_STACK_EXPORTS_H */
|
||||
|
||||
@@ -302,7 +302,7 @@ bool address_mac_from_ascii(BACNET_MAC_ADDRESS *mac, const char *arg)
|
||||
{
|
||||
unsigned a[6] = { 0 }, p = 0;
|
||||
uint16_t port = 0;
|
||||
int c;
|
||||
int c, i;
|
||||
bool status = false;
|
||||
|
||||
if (!(mac && arg)) {
|
||||
@@ -327,7 +327,7 @@ bool address_mac_from_ascii(BACNET_MAC_ADDRESS *mac, const char *arg)
|
||||
&a[4], &a[5]);
|
||||
|
||||
if (c > 0) {
|
||||
for (int i = 0; i < c; i++) {
|
||||
for (i = 0; i < c; i++) {
|
||||
mac->adr[i] = a[i];
|
||||
}
|
||||
mac->len = c;
|
||||
|
||||
@@ -1521,11 +1521,11 @@ bool Channel_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
}
|
||||
break;
|
||||
case PROP_LIST_OF_OBJECT_PROPERTY_REFERENCES:
|
||||
// FIXME: add property handling
|
||||
// status =
|
||||
// Channel_List_Of_Object_Property_References_Set(
|
||||
// wp_data,
|
||||
// &value);
|
||||
/* FIXME: add property handling */
|
||||
/* status = */
|
||||
/* Channel_List_Of_Object_Property_References_Set( */
|
||||
/* wp_data, */
|
||||
/* &value); */
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code =
|
||||
ERROR_CODE_OPTIONAL_FUNCTIONALITY_NOT_SUPPORTED;
|
||||
|
||||
@@ -394,10 +394,10 @@ bool Lighting_Output_Lighting_Command_Set(
|
||||
|
||||
index = Lighting_Output_Instance_To_Index(object_instance);
|
||||
if (index < MAX_LIGHTING_OUTPUTS) {
|
||||
// FIXME: check lighting command member values
|
||||
/* FIXME: check lighting command member values */
|
||||
status = lighting_command_copy(
|
||||
&Lighting_Output[index].Lighting_Command, value);
|
||||
// FIXME: set all the other values, and get the light levels moving
|
||||
/* FIXME: set all the other values, and get the light levels moving */
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
@@ -86,6 +86,7 @@ void Notification_Class_Property_Lists(
|
||||
void Notification_Class_Init(void)
|
||||
{
|
||||
uint8_t NotifyIdx = 0;
|
||||
unsigned i;
|
||||
|
||||
for (NotifyIdx = 0; NotifyIdx < MAX_NOTIFICATION_CLASSES; NotifyIdx++) {
|
||||
/* init with zeros */
|
||||
@@ -99,7 +100,7 @@ void Notification_Class_Init(void)
|
||||
NC_Info[NotifyIdx].Priority[TRANSITION_TO_NORMAL] =
|
||||
255; /* PRINTF lowest priority for Normal message. */
|
||||
/* configure for every day, all day long */
|
||||
for (unsigned i = 0; i < MAX_BACNET_DAYS_OF_WEEK; i++) {
|
||||
for (i = 0; i < MAX_BACNET_DAYS_OF_WEEK; i++) {
|
||||
NC_Info[NotifyIdx].Recipient_List->ValidDays |= (1<<i);
|
||||
}
|
||||
NC_Info[NotifyIdx].Recipient_List->FromTime.hour = 0;
|
||||
|
||||
@@ -674,15 +674,15 @@ bool Trend_Log_Write_Property(BACNET_WRITE_PROPERTY_DATA *wp_data)
|
||||
len = bacapp_decode_device_obj_property_ref(
|
||||
wp_data->application_data, &TempSource);
|
||||
if ((len < 0) ||
|
||||
(len > wp_data->application_data_len)) // Hmm, that didn't go
|
||||
// as planned...
|
||||
(len > wp_data->application_data_len)) /* Hmm, that didn't go */
|
||||
/* as planned... */
|
||||
{
|
||||
wp_data->error_class = ERROR_CLASS_PROPERTY;
|
||||
wp_data->error_code = ERROR_CODE_OTHER;
|
||||
break;
|
||||
}
|
||||
|
||||
// We only support references to objects in ourself for now
|
||||
/* We only support references to objects in ourself for now */
|
||||
if ((TempSource.deviceIdentifier.type == OBJECT_DEVICE) &&
|
||||
(TempSource.deviceIdentifier.instance !=
|
||||
Device_Object_Instance_Number())) {
|
||||
|
||||
@@ -287,8 +287,8 @@ void handler_read_property_multiple(uint8_t *service_request,
|
||||
#endif
|
||||
error = len;
|
||||
berror = true;
|
||||
break; // The berror flag ensures that both loops will
|
||||
// be broken!
|
||||
break; /* The berror flag ensures that both loops will */
|
||||
/* be broken! */
|
||||
}
|
||||
decode_len += len;
|
||||
/* handle the special properties */
|
||||
@@ -320,8 +320,8 @@ void handler_read_property_multiple(uint8_t *service_request,
|
||||
ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
|
||||
error = BACNET_STATUS_ABORT;
|
||||
berror = true;
|
||||
break; // The berror flag ensures that both
|
||||
// loops will be broken!
|
||||
break; /* The berror flag ensures that both */
|
||||
/* loops will be broken! */
|
||||
}
|
||||
|
||||
apdu_len += len;
|
||||
@@ -342,8 +342,8 @@ void handler_read_property_multiple(uint8_t *service_request,
|
||||
ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
|
||||
error = BACNET_STATUS_ABORT;
|
||||
berror = true;
|
||||
break; // The berror flag ensures that both
|
||||
// loops will be broken!
|
||||
break; /* The berror flag ensures that both */
|
||||
/* loops will be broken! */
|
||||
}
|
||||
apdu_len += len;
|
||||
} else {
|
||||
@@ -379,8 +379,8 @@ void handler_read_property_multiple(uint8_t *service_request,
|
||||
#endif
|
||||
error = len;
|
||||
berror = true;
|
||||
break; // The berror flag ensures that
|
||||
// both loops will be broken!
|
||||
break; /* The berror flag ensures that */
|
||||
/* both loops will be broken! */
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -399,8 +399,8 @@ void handler_read_property_multiple(uint8_t *service_request,
|
||||
#endif
|
||||
error = len;
|
||||
berror = true;
|
||||
break; // The berror flag ensures that both loops
|
||||
// will be broken!
|
||||
break; /* The berror flag ensures that both loops */
|
||||
/* will be broken! */
|
||||
}
|
||||
}
|
||||
|
||||
@@ -421,14 +421,14 @@ void handler_read_property_multiple(uint8_t *service_request,
|
||||
ERROR_CODE_ABORT_SEGMENTATION_NOT_SUPPORTED;
|
||||
error = BACNET_STATUS_ABORT;
|
||||
berror = true;
|
||||
break; // The berror flag ensures that both loops
|
||||
// will be broken!
|
||||
break; /* The berror flag ensures that both loops */
|
||||
/* will be broken! */
|
||||
} else {
|
||||
apdu_len += copy_len;
|
||||
}
|
||||
break; /* finished with this property list */
|
||||
}
|
||||
} // for(;;)
|
||||
} /* for(;;) */
|
||||
if (berror) {
|
||||
break;
|
||||
}
|
||||
@@ -436,7 +436,7 @@ void handler_read_property_multiple(uint8_t *service_request,
|
||||
/* Reached the end so finish up */
|
||||
break;
|
||||
}
|
||||
} // for(;;)
|
||||
} /* for(;;) */
|
||||
|
||||
/* If not having an error so far, check the remaining space. */
|
||||
if (!berror) {
|
||||
|
||||
@@ -143,11 +143,11 @@ uint8_t Send_COV_Subscribe(
|
||||
&Handler_Transmit_Buffer[0], &dest, &my_address, &npdu_data);
|
||||
/* encode the APDU portion of the packet */
|
||||
if (cov_data->covSubscribeToProperty) {
|
||||
// subscribe to 1 property
|
||||
/* subscribe to 1 property */
|
||||
len = cov_subscribe_property_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||
sizeof(Handler_Transmit_Buffer) - pdu_len, invoke_id, cov_data);
|
||||
} else {
|
||||
// subscribe to object
|
||||
/* subscribe to object */
|
||||
len = cov_subscribe_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||
sizeof(Handler_Transmit_Buffer) - pdu_len, invoke_id, cov_data);
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ extern "C" {
|
||||
/* tail */
|
||||
BACNET_STACK_EXPORT
|
||||
volatile void *Ringbuf_Peek(RING_BUFFER const *b);
|
||||
BACNET_STACK_EXPORT
|
||||
bool Ringbuf_Pop(RING_BUFFER * b,
|
||||
uint8_t * data_element);
|
||||
BACNET_STACK_EXPORT
|
||||
@@ -85,6 +86,7 @@ extern "C" {
|
||||
/* pair of functions to use head memory directly */
|
||||
BACNET_STACK_EXPORT
|
||||
volatile void *Ringbuf_Data_Peek(RING_BUFFER * b);
|
||||
BACNET_STACK_EXPORT
|
||||
volatile void *Ringbuf_Peek_Next(RING_BUFFER const *b,
|
||||
uint8_t * data_element);
|
||||
BACNET_STACK_EXPORT
|
||||
|
||||
@@ -219,11 +219,11 @@ extern "C" {
|
||||
uint8_t * msg,
|
||||
uint32_t msg_len,
|
||||
uint8_t * signature);
|
||||
// BACNET_STACK_EXPORT
|
||||
// bool key_verify_sign_msg(BACNET_KEY_ENTRY * key,
|
||||
// uint8_t * msg,
|
||||
// uint32_t msg_len,
|
||||
// uint8_t * signature);
|
||||
/* BACNET_STACK_EXPORT */
|
||||
/* bool key_verify_sign_msg(BACNET_KEY_ENTRY * key, */
|
||||
/* uint8_t * msg, */
|
||||
/* uint32_t msg_len, */
|
||||
/* uint8_t * signature); */
|
||||
BACNET_STACK_EXPORT
|
||||
int key_encrypt_msg(BACNET_KEY_ENTRY * key,
|
||||
uint8_t * msg,
|
||||
@@ -241,10 +241,10 @@ extern "C" {
|
||||
uint8_t * padding);
|
||||
|
||||
/* encoders */
|
||||
// BACNET_STACK_EXPORT
|
||||
// int encode_security_wrapper(int bytes_before,
|
||||
// uint8_t * apdu,
|
||||
// BACNET_SECURITY_WRAPPER * wrapper);
|
||||
/* BACNET_STACK_EXPORT */
|
||||
/* int encode_security_wrapper(int bytes_before, */
|
||||
/* uint8_t * apdu, */
|
||||
/* BACNET_SECURITY_WRAPPER * wrapper); */
|
||||
BACNET_STACK_EXPORT
|
||||
int encode_challenge_request(uint8_t * apdu,
|
||||
BACNET_CHALLENGE_REQUEST * bc_req);
|
||||
@@ -274,11 +274,11 @@ extern "C" {
|
||||
BACNET_SET_MASTER_KEY * set_master_key);
|
||||
|
||||
/* safe decoders */
|
||||
// BACNET_STACK_EXPORT
|
||||
// int decode_security_wrapper_safe(int bytes_before,
|
||||
// uint8_t * apdu,
|
||||
// uint32_t apdu_len_remaining,
|
||||
// BACNET_SECURITY_WRAPPER * wrapper);
|
||||
/* BACNET_STACK_EXPORT */
|
||||
/* int decode_security_wrapper_safe(int bytes_before, */
|
||||
/* uint8_t * apdu, */
|
||||
/* uint32_t apdu_len_remaining, */
|
||||
/* BACNET_SECURITY_WRAPPER * wrapper); */
|
||||
BACNET_STACK_EXPORT
|
||||
int decode_challenge_request_safe(uint8_t * apdu,
|
||||
uint32_t apdu_len_remaining,
|
||||
|
||||
Reference in New Issue
Block a user