Run clang-format and enable CI check for it (#755)

* pre-commit: Update and enable clang-format check

There is newer version from clang-format so use that. We do not yet want
18 as that is little bit too new.

* Format some thing by hand which clang-format "breaks"

Clang-format will format some things little bit off in some cases.
Format some things by hand so we get cleaner end result.

* Run clang-format with

```
pre-commit run --all-files clang-format
```

We have already in previously checked places where clang-format does not
make good format and ignored those (hopefully most of the things).

---------

Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
This commit is contained in:
Kari Argillander
2024-08-30 19:20:58 +03:00
committed by GitHub
parent 622a9e609e
commit f806c5829b
547 changed files with 18286 additions and 16575 deletions
+28 -18
View File
@@ -45,7 +45,8 @@
* @param service_data [in] The BACNET_CONFIRMED_SERVICE_DATA information
* decoded from the APDU header of this message.
*/
void handler_write_property(uint8_t *service_request,
void handler_write_property(
uint8_t *service_request,
uint16_t service_len,
BACNET_ADDRESS *src,
BACNET_CONFIRMED_SERVICE_DATA *service_data)
@@ -67,9 +68,9 @@ void handler_write_property(uint8_t *service_request,
fprintf(stderr, "WP: Received Request!\n");
#endif
if (service_data->segmented_message) {
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
true);
len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
#if PRINT_ENABLED
fprintf(stderr, "WP: Segmented message. Sending Abort!\n");
#endif
@@ -80,21 +81,24 @@ void handler_write_property(uint8_t *service_request,
/* decode the service request only */
len = wp_decode_service_request(service_request, service_len, &wp_data);
#if PRINT_ENABLED
if (len > 0)
fprintf(stderr,
if (len > 0) {
fprintf(
stderr,
"WP: type=%lu instance=%lu property=%lu priority=%lu "
"index=%ld\n",
(unsigned long)wp_data.object_type,
(unsigned long)wp_data.object_instance,
(unsigned long)wp_data.object_property,
(unsigned long)wp_data.priority, (long)wp_data.array_index);
else
} else {
fprintf(stderr, "WP: Unable to decode Request!\n");
}
#endif
/* bad decoding or something we didn't understand - send an abort */
if (len <= 0) {
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, ABORT_REASON_OTHER, true);
len = abort_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
ABORT_REASON_OTHER, true);
#if PRINT_ENABLED
fprintf(stderr, "WP: Bad Encoding. Sending Abort!\n");
#endif
@@ -103,15 +107,17 @@ void handler_write_property(uint8_t *service_request,
if (bcontinue) {
if (Device_Write_Property(&wp_data)) {
len = encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY);
len = encode_simple_ack(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY);
#if PRINT_ENABLED
fprintf(stderr, "WP: Sending Simple Ack!\n");
#endif
} else {
len = bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
service_data->invoke_id, SERVICE_CONFIRMED_WRITE_PROPERTY,
wp_data.error_class, wp_data.error_code);
len = bacerror_encode_apdu(
&Handler_Transmit_Buffer[pdu_len], service_data->invoke_id,
SERVICE_CONFIRMED_WRITE_PROPERTY, wp_data.error_class,
wp_data.error_code);
#if PRINT_ENABLED
fprintf(stderr, "WP: Sending Error!\n");
#endif
@@ -146,7 +152,8 @@ void handler_write_property(uint8_t *service_request,
*
* @return True on success, false otherwise.
*/
bool WPValidateString(const BACNET_APPLICATION_DATA_VALUE *pValue,
bool WPValidateString(
const BACNET_APPLICATION_DATA_VALUE *pValue,
int iMaxLen,
bool bEmptyAllowed,
BACNET_ERROR_CLASS *pErrorClass,
@@ -167,11 +174,13 @@ bool WPValidateString(const BACNET_APPLICATION_DATA_VALUE *pValue,
if ((bEmptyAllowed == false) &&
(characterstring_length(&pValue->type.Character_String) == 0)) {
*pErrorCode = ERROR_CODE_VALUE_OUT_OF_RANGE;
} else if ((bEmptyAllowed == false) &&
} else if (
(bEmptyAllowed == false) &&
(!characterstring_printable(&pValue->type.Character_String))) {
/* assumption: non-empty also means must be "printable" */
*pErrorCode = ERROR_CODE_VALUE_OUT_OF_RANGE;
} else if (characterstring_length(&pValue->type.Character_String) >
} else if (
characterstring_length(&pValue->type.Character_String) >
(uint16_t)iMaxLen) {
*pErrorClass = ERROR_CLASS_RESOURCES;
*pErrorCode = ERROR_CODE_NO_SPACE_TO_WRITE_PROPERTY;
@@ -193,7 +202,8 @@ bool WPValidateString(const BACNET_APPLICATION_DATA_VALUE *pValue,
* validation fails. Cuts out reams of repeated code in the object code.
*/
bool WPValidateArgType(const BACNET_APPLICATION_DATA_VALUE *pValue,
bool WPValidateArgType(
const BACNET_APPLICATION_DATA_VALUE *pValue,
uint8_t ucExpectedTag,
BACNET_ERROR_CLASS *pErrorClass,
BACNET_ERROR_CODE *pErrorCode)