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
+30 -22
View File
@@ -61,8 +61,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;
@@ -71,7 +71,8 @@ static void MyRejectHandler(
Error_Detected = true;
}
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)
@@ -104,7 +105,8 @@ static void My_Router_Handler(BACNET_ADDRESS *src,
that are sent with a local unicast address. */
if (npdu_len >= 2) {
(void)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);
@@ -126,7 +128,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 */
@@ -136,7 +139,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) &&
@@ -150,7 +154,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);
}
}
@@ -186,8 +191,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) {
@@ -203,8 +209,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) {
@@ -236,17 +243,18 @@ int main(int argc, char *argv[])
time_t timeout_seconds = 0;
if ((argc > 1) && (strcmp(argv[1], "--help") == 0)) {
printf("Send BACnet What-Is-Network-Number message to a network.\r\n"
"\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"
"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;
}