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
+42 -31
View File
@@ -63,8 +63,8 @@ static void MyAbortHandler(
* @param invoke_id [in] the invokeID from the rejected message
* @param reject_reason [in] the reason for the rejection
*/
static void MyRejectHandler(
BACNET_ADDRESS *src, uint8_t invoke_id, uint8_t reject_reason)
static void
MyRejectHandler(BACNET_ADDRESS *src, uint8_t invoke_id, uint8_t reject_reason)
{
/* FIXME: verify src and invoke id */
(void)src;
@@ -79,7 +79,8 @@ static void MyRejectHandler(
* @param npdu - NPDU data
* @param npdu_len - NPDU data length
*/
static void My_Router_Handler(BACNET_ADDRESS *src,
static void My_Router_Handler(
BACNET_ADDRESS *src,
BACNET_NPDU_DATA *npdu_data,
uint8_t *npdu,
uint16_t npdu_len)
@@ -120,7 +121,8 @@ static void My_Router_Handler(BACNET_ADDRESS *src,
that are sent with a local unicast address. */
if (npdu_len >= 2) {
len += decode_unsigned16(npdu, &dnet);
printf(": network number = %u. SNET=%u\n", (unsigned)dnet,
printf(
": network number = %u. SNET=%u\n", (unsigned)dnet,
(unsigned)src->net);
} else {
printf(": network number = missing! SNET=%u\n", src->net);
@@ -142,7 +144,8 @@ static void My_Router_Handler(BACNET_ADDRESS *src,
}
}
static void My_NPDU_Handler(BACNET_ADDRESS *src, /* source address */
static void My_NPDU_Handler(
BACNET_ADDRESS *src, /* source address */
uint8_t *pdu, /* PDU data */
uint16_t pdu_len)
{ /* length PDU */
@@ -152,7 +155,8 @@ static void My_NPDU_Handler(BACNET_ADDRESS *src, /* source address */
apdu_offset = bacnet_npdu_decode(pdu, pdu_len, &dest, src, &npdu_data);
if (npdu_data.network_layer_message) {
My_Router_Handler(src, &npdu_data, &pdu[apdu_offset],
My_Router_Handler(
src, &npdu_data, &pdu[apdu_offset],
(uint16_t)(pdu_len - apdu_offset));
} else if ((apdu_offset > 0) && (apdu_offset <= pdu_len)) {
if ((npdu_data.protocol_version == BACNET_PROTOCOL_VERSION) &&
@@ -166,7 +170,8 @@ static void My_NPDU_Handler(BACNET_ADDRESS *src, /* source address */
if (dest.net) {
debug_printf("NPDU: DNET=%d. Discarded!\n", dest.net);
} else {
debug_printf("NPDU: BACnet Protocol Version=%d. Discarded!\n",
debug_printf(
"NPDU: BACnet Protocol Version=%d. Discarded!\n",
npdu_data.protocol_version);
}
}
@@ -202,8 +207,9 @@ static void address_parse(BACNET_ADDRESS *dst, int argc, char *argv[])
int index = 0;
if (argc > 0) {
count = sscanf(argv[0], "%x:%x:%x:%x:%x:%x", &mac[0], &mac[1], &mac[2],
&mac[3], &mac[4], &mac[5]);
count = sscanf(
argv[0], "%x:%x:%x:%x:%x:%x", &mac[0], &mac[1], &mac[2], &mac[3],
&mac[4], &mac[5]);
dst->mac_len = count;
for (index = 0; index < MAX_MAC_LEN; index++) {
if (index < count) {
@@ -219,8 +225,9 @@ static void address_parse(BACNET_ADDRESS *dst, int argc, char *argv[])
}
if (dnet) {
if (argc > 2) {
count = sscanf(argv[2], "%x:%x:%x:%x:%x:%x", &mac[0], &mac[1],
&mac[2], &mac[3], &mac[4], &mac[5]);
count = sscanf(
argv[2], "%x:%x:%x:%x:%x:%x", &mac[0], &mac[1], &mac[2],
&mac[3], &mac[4], &mac[5]);
dst->len = count;
for (index = 0; index < MAX_MAC_LEN; index++) {
if (index < count) {
@@ -257,23 +264,24 @@ int main(int argc, char *argv[])
return 0;
}
if ((argc > 1) && (strcmp(argv[1], "--help") == 0)) {
printf("Send BACnet What-Is-Network-Number message to a network.\r\n"
"\r\n"
"DNET:\r\n"
"BACnet destination network number 0-65535\r\n"
"To omit the BACnet destination network number, use -1.\r\n"
"Network Number Status:\r\n"
"0=learned\r\n"
"1=configured\r\n"
"MAC:\r\n"
"Optional MAC address of router for unicast message\r\n"
"Format: xx[:xx:xx:xx:xx:xx] [dnet xx[:xx:xx:xx:xx:xx]]\r\n"
"Use hexidecimal MAC addresses.\r\n"
"\r\n"
"To send a What-Is-Network-Number request to DNET 86:\r\n"
"%s 86\r\n"
"To send a What-Is-Network-Number request to all devices:\r\n"
"%s -1\r\n",
printf(
"Send BACnet What-Is-Network-Number message to a network.\r\n"
"\r\n"
"DNET:\r\n"
"BACnet destination network number 0-65535\r\n"
"To omit the BACnet destination network number, use -1.\r\n"
"Network Number Status:\r\n"
"0=learned\r\n"
"1=configured\r\n"
"MAC:\r\n"
"Optional MAC address of router for unicast message\r\n"
"Format: xx[:xx:xx:xx:xx:xx] [dnet xx[:xx:xx:xx:xx:xx]]\r\n"
"Use hexidecimal MAC addresses.\r\n"
"\r\n"
"To send a What-Is-Network-Number request to DNET 86:\r\n"
"%s 86\r\n"
"To send a What-Is-Network-Number request to all devices:\r\n"
"%s -1\r\n",
filename_remove_path(argv[0]), filename_remove_path(argv[0]));
return 0;
}
@@ -281,7 +289,8 @@ int main(int argc, char *argv[])
if (argc > 1) {
Target_Network_Number = strtol(argv[1], NULL, 0);
if (Target_Network_Number > UINT16_MAX) {
fprintf(stderr, "DNET=%d - it must be 0 to 65535\r\n",
fprintf(
stderr, "DNET=%d - it must be 0 to 65535\r\n",
Target_Network_Number);
return 1;
}
@@ -289,7 +298,8 @@ int main(int argc, char *argv[])
if (argc > 2) {
Target_Network_Number_Status = strtol(argv[2], NULL, 0);
if (Target_Network_Number_Status > UINT8_MAX) {
fprintf(stderr, "status=%d - it must be 0 to 255\r\n",
fprintf(
stderr, "status=%d - it must be 0 to 255\r\n",
Target_Network_Number_Status);
return 1;
}
@@ -309,7 +319,8 @@ int main(int argc, char *argv[])
last_seconds = time(NULL);
timeout_seconds = apdu_timeout() / 1000;
/* send the request */
Send_Network_Number_Is(&Target_Router_Address, Target_Network_Number,
Send_Network_Number_Is(
&Target_Router_Address, Target_Network_Number,
Target_Network_Number_Status);
/* loop forever */
for (;;) {