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
+33 -25
View File
@@ -50,8 +50,8 @@ static void MyAbortHandler(
Error_Detected = true;
}
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;
@@ -60,7 +60,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, /* PDU data */
uint16_t npdu_len)
@@ -108,7 +109,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 */
@@ -118,7 +120,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) &&
@@ -132,7 +135,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);
}
}
@@ -168,8 +172,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) {
@@ -185,8 +190,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) {
@@ -222,20 +228,21 @@ int main(int argc, char *argv[])
return 0;
}
if ((argc > 1) && (strcmp(argv[1], "--help") == 0)) {
printf("Send BACnet Who-Is-Router-To-Network 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"
"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 Who-Is-Router-To-Network request to DNET 86:\r\n"
"%s 86\r\n"
"To send a Who-Is-Router-To-Network request to all devices:\r\n"
"%s -1\r\n",
printf(
"Send BACnet Who-Is-Router-To-Network 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"
"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 Who-Is-Router-To-Network request to DNET 86:\r\n"
"%s 86\r\n"
"To send a Who-Is-Router-To-Network request to all devices:\r\n"
"%s -1\r\n",
filename_remove_path(argv[0]), filename_remove_path(argv[0]));
return 0;
}
@@ -243,7 +250,8 @@ int main(int argc, char *argv[])
if (argc > 1) {
Target_Router_Network = strtol(argv[1], NULL, 0);
if (Target_Router_Network > 65535) {
fprintf(stderr, "DNET=%u - it must be 0 to 65535\r\n",
fprintf(
stderr, "DNET=%u - it must be 0 to 65535\r\n",
Target_Router_Network);
return 1;
}