Strip tabs and trailing white spaces, and fix end of files (#748)

* format: Strip trailing whitespaces

We want to get rid of trailing whitespaces completly as they make just git
noice. Much better to start using automated tools to get rid of them once and
not getting them back again. This way git history will be cleaner and review
easier.

Commit was generated with:

    pre-commit run --all-files trailing-whitespace

* format: Files should have exactly one new line end of them

It is good practice that every file has one new line. It is not now days so
mandatory but it also is not nice if file has lot of newlines end of it. We will
use pre-commit which takes automatically care about this so let's fix all.

Commit was generated with:

    pre-commit run --all-files end-of-file-fixer

* format: Convert tabs to spaces

Project mostly use spaces over tabs. When mixing tabs and spaces this usually
makes formatting issues and also when changing those in commits it will make lot
of git noise. We will force spaces most of the time and use pre-commit to fix.

Commit was generated with:

    pre-commit run --all-files remove-tabs

---------

Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
This commit is contained in:
Kari Argillander
2024-08-25 22:13:57 +03:00
committed by GitHub
parent 9e0657424e
commit 369da70f2a
455 changed files with 7147 additions and 7249 deletions
+74 -74
View File
@@ -19,48 +19,48 @@
* @return 0 on success, negative on failure
*/
static int cmd_key(BACNET_STORAGE_KEY *key, const struct shell *sh, size_t argc,
char **argv)
char **argv)
{
uint16_t object_type;
uint32_t object_instance;
uint32_t property_id = 77;
uint32_t array_index = BACNET_STORAGE_ARRAY_INDEX_NONE;
long value = 0;
uint16_t object_type;
uint32_t object_instance;
uint32_t property_id = 77;
uint32_t array_index = BACNET_STORAGE_ARRAY_INDEX_NONE;
long value = 0;
if (argc < 3) {
shell_error(
sh,
"Usage: %s <object-type> <instance> <property> [value]",
argv[0]);
return -EINVAL;
}
value = strtoul(argv[1], NULL, 0);
if ((value < 0) || (value >= UINT16_MAX)) {
shell_error(sh, "Invalid object-type: %s. Must be 0-65535.",
argv[1]);
return -EINVAL;
}
object_type = (uint16_t)value;
value = strtoul(argv[2], NULL, 0);
if (value > 4194303) {
shell_error(sh,
"Invalid object-instance: %s. Must be 0-4194303.",
argv[2]);
return -EINVAL;
}
object_instance = (uint32_t)value;
value = strtoul(argv[3], NULL, 0);
if (value > UINT32_MAX) {
shell_error(sh, "Invalid property: %s. Must be 0-4294967295.",
argv[3]);
return -EINVAL;
}
property_id = (uint32_t)value;
/* setup the storage key */
bacnet_storage_key_init(key, object_type, object_instance, property_id,
array_index);
if (argc < 3) {
shell_error(
sh,
"Usage: %s <object-type> <instance> <property> [value]",
argv[0]);
return -EINVAL;
}
value = strtoul(argv[1], NULL, 0);
if ((value < 0) || (value >= UINT16_MAX)) {
shell_error(sh, "Invalid object-type: %s. Must be 0-65535.",
argv[1]);
return -EINVAL;
}
object_type = (uint16_t)value;
value = strtoul(argv[2], NULL, 0);
if (value > 4194303) {
shell_error(sh,
"Invalid object-instance: %s. Must be 0-4194303.",
argv[2]);
return -EINVAL;
}
object_instance = (uint32_t)value;
value = strtoul(argv[3], NULL, 0);
if (value > UINT32_MAX) {
shell_error(sh, "Invalid property: %s. Must be 0-4294967295.",
argv[3]);
return -EINVAL;
}
property_id = (uint32_t)value;
/* setup the storage key */
bacnet_storage_key_init(key, object_type, object_instance, property_id,
array_index);
return 0;
return 0;
}
/**
@@ -72,45 +72,45 @@ static int cmd_key(BACNET_STORAGE_KEY *key, const struct shell *sh, size_t argc,
*/
static int cmd_string(const struct shell *sh, size_t argc, char **argv)
{
char key_name[BACNET_STORAGE_KEY_SIZE_MAX + 1] = { 0 };
uint8_t data[BACNET_STORAGE_VALUE_SIZE_MAX + 1] = { 0 };
BACNET_STORAGE_KEY key = { 0 };
size_t arg_len = 0;
int rc;
char key_name[BACNET_STORAGE_KEY_SIZE_MAX + 1] = { 0 };
uint8_t data[BACNET_STORAGE_VALUE_SIZE_MAX + 1] = { 0 };
BACNET_STORAGE_KEY key = { 0 };
size_t arg_len = 0;
int rc;
rc = cmd_key(&key, sh, argc, argv);
if (rc < 0) {
return rc;
}
/* convert the key to a string for the shell */
(void)bacnet_storage_key_encode(key_name, sizeof(key_name), &key);
if (argc > 4) {
arg_len = strlen(argv[4]);
rc = bacnet_storage_set(&key, argv[4], arg_len);
if (rc == 0) {
shell_print(sh, "Set %s = %s", key_name, argv[4]);
} else {
shell_error(sh, "Unable to set %s = %s", key_name,
argv[4]);
return -EINVAL;
}
} else {
rc = bacnet_storage_get(&key, data, sizeof(data));
if (rc < 0) {
shell_error(sh, "Unable to get %s", key_name);
return -EINVAL;
}
shell_print(sh, "Get %s = %s", key_name, data);
}
rc = cmd_key(&key, sh, argc, argv);
if (rc < 0) {
return rc;
}
/* convert the key to a string for the shell */
(void)bacnet_storage_key_encode(key_name, sizeof(key_name), &key);
if (argc > 4) {
arg_len = strlen(argv[4]);
rc = bacnet_storage_set(&key, argv[4], arg_len);
if (rc == 0) {
shell_print(sh, "Set %s = %s", key_name, argv[4]);
} else {
shell_error(sh, "Unable to set %s = %s", key_name,
argv[4]);
return -EINVAL;
}
} else {
rc = bacnet_storage_get(&key, data, sizeof(data));
if (rc < 0) {
shell_error(sh, "Unable to get %s", key_name);
return -EINVAL;
}
shell_print(sh, "Get %s = %s", key_name, data);
}
return 0;
return 0;
}
SHELL_STATIC_SUBCMD_SET_CREATE(sub_bacnet_settings_cmds,
SHELL_CMD(string, NULL,
"get or set BACnet storage string",
cmd_string),
SHELL_SUBCMD_SET_END);
SHELL_CMD(string, NULL,
"get or set BACnet storage string",
cmd_string),
SHELL_SUBCMD_SET_END);
SHELL_SUBCMD_ADD((bacnet), settings, &sub_bacnet_settings_cmds,
"BACnet settings commands", NULL, 1, 0);
"BACnet settings commands", NULL, 1, 0);