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
+131 -131
View File
@@ -41,38 +41,38 @@ LOG_MODULE_DECLARE(bacnet, CONFIG_BACNETSTACK_LOG_LEVEL);
*/
void bacnet_storage_init(void)
{
int rc;
int rc;
#if defined(CONFIG_SETTINGS_FILE) && defined(CONFIG_FILE_SYSTEM_LITTLEFS)
FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(cstorage);
FS_LITTLEFS_DECLARE_DEFAULT_CONFIG(cstorage);
/* mounting info */
static struct fs_mount_t littlefs_mnt = {
.type = FS_LITTLEFS,
.fs_data = &cstorage,
.storage_dev = (void *)STORAGE_PARTITION_ID,
.mnt_point = "/ff"
};
/* mounting info */
static struct fs_mount_t littlefs_mnt = {
.type = FS_LITTLEFS,
.fs_data = &cstorage,
.storage_dev = (void *)STORAGE_PARTITION_ID,
.mnt_point = "/ff"
};
rc = fs_mount(&littlefs_mnt);
if (rc != 0) {
LOG_INF("mounting littlefs error: [%d]", rc);
} else {
rc = fs_unlink(CONFIG_SETTINGS_FILE_PATH);
if ((rc != 0) && (rc != -ENOENT)) {
H("can't delete config file%d", rc);
} else {
LOG_INF("FS initialized: OK");
}
}
rc = fs_mount(&littlefs_mnt);
if (rc != 0) {
LOG_INF("mounting littlefs error: [%d]", rc);
} else {
rc = fs_unlink(CONFIG_SETTINGS_FILE_PATH);
if ((rc != 0) && (rc != -ENOENT)) {
H("can't delete config file%d", rc);
} else {
LOG_INF("FS initialized: OK");
}
}
#endif
rc = settings_subsys_init();
if (rc) {
LOG_INF("settings subsys initialization: fail (err %d)", rc);
return;
}
rc = settings_subsys_init();
if (rc) {
LOG_INF("settings subsys initialization: fail (err %d)", rc);
return;
}
LOG_INF("settings subsys initialization: OK.");
LOG_INF("settings subsys initialization: OK.");
}
/**
@@ -84,15 +84,15 @@ void bacnet_storage_init(void)
* @param array_index BACnet array index
*/
void bacnet_storage_key_init(BACNET_STORAGE_KEY *key, uint16_t object_type,
uint32_t object_instance, uint32_t property_id,
uint32_t array_index)
uint32_t object_instance, uint32_t property_id,
uint32_t array_index)
{
if (key) {
key->object_type = object_type;
key->object_instance = object_instance;
key->property_id = property_id;
key->array_index = array_index;
}
if (key) {
key->object_type = object_type;
key->object_instance = object_instance;
key->property_id = property_id;
key->array_index = array_index;
}
}
/**
@@ -103,35 +103,35 @@ void bacnet_storage_key_init(BACNET_STORAGE_KEY *key, uint16_t object_type,
* @return length of the string
*/
int bacnet_storage_key_encode(char *buffer, size_t buffer_size,
BACNET_STORAGE_KEY *key)
BACNET_STORAGE_KEY *key)
{
int rc = 0;
const char base_name[] = CONFIG_BACNET_STORAGE_BASE_NAME;
int rc = 0;
const char base_name[] = CONFIG_BACNET_STORAGE_BASE_NAME;
if (buffer) {
memset(buffer, 0, buffer_size);
}
if (key->array_index == BACNET_STORAGE_ARRAY_INDEX_NONE) {
rc = snprintf(buffer, buffer_size, "%s%c%u%c%lu%c%lu",
base_name, SETTINGS_NAME_SEPARATOR,
(unsigned short)key->object_type,
SETTINGS_NAME_SEPARATOR,
(unsigned long)key->object_instance,
SETTINGS_NAME_SEPARATOR,
(unsigned long)key->property_id);
} else {
rc = snprintf(buffer, buffer_size, "%s%c%u%c%lu%c%lu%c%lu",
base_name, SETTINGS_NAME_SEPARATOR,
(unsigned short)key->object_type,
SETTINGS_NAME_SEPARATOR,
(unsigned long)key->object_instance,
SETTINGS_NAME_SEPARATOR,
(unsigned long)key->property_id,
SETTINGS_NAME_SEPARATOR,
(unsigned long)key->array_index);
}
if (buffer) {
memset(buffer, 0, buffer_size);
}
if (key->array_index == BACNET_STORAGE_ARRAY_INDEX_NONE) {
rc = snprintf(buffer, buffer_size, "%s%c%u%c%lu%c%lu",
base_name, SETTINGS_NAME_SEPARATOR,
(unsigned short)key->object_type,
SETTINGS_NAME_SEPARATOR,
(unsigned long)key->object_instance,
SETTINGS_NAME_SEPARATOR,
(unsigned long)key->property_id);
} else {
rc = snprintf(buffer, buffer_size, "%s%c%u%c%lu%c%lu%c%lu",
base_name, SETTINGS_NAME_SEPARATOR,
(unsigned short)key->object_type,
SETTINGS_NAME_SEPARATOR,
(unsigned long)key->object_instance,
SETTINGS_NAME_SEPARATOR,
(unsigned long)key->property_id,
SETTINGS_NAME_SEPARATOR,
(unsigned long)key->array_index);
}
return rc;
return rc;
}
/**
@@ -142,31 +142,31 @@ int bacnet_storage_key_encode(char *buffer, size_t buffer_size,
* @return 0 on success, non-zero on failure.
*/
int bacnet_storage_set(BACNET_STORAGE_KEY *key, const void *data,
size_t data_len)
size_t data_len)
{
char name[SETTINGS_MAX_NAME_LEN + 1] = { 0 };
int rc;
char name[SETTINGS_MAX_NAME_LEN + 1] = { 0 };
int rc;
rc = bacnet_storage_key_encode(name, sizeof(name), key);
LOG_INF("Set a key-value pair. Key=%s", name);
rc = settings_save_one(name, data, data_len);
if (rc) {
LOG_INF(FAIL_MSG, rc);
} else {
LOG_HEXDUMP_INF(data, data_len, "value");
}
rc = bacnet_storage_key_encode(name, sizeof(name), key);
LOG_INF("Set a key-value pair. Key=%s", name);
rc = settings_save_one(name, data, data_len);
if (rc) {
LOG_INF(FAIL_MSG, rc);
} else {
LOG_HEXDUMP_INF(data, data_len, "value");
}
return rc;
return rc;
}
/**
/**
* @brief Structure to hold immediate values
*/
struct direct_immediate_value {
size_t value_size;
size_t value_len;
void *value;
bool fetched;
size_t value_size;
size_t value_len;
void *value;
bool fetched;
};
/**
@@ -179,33 +179,33 @@ struct direct_immediate_value {
* @return 0 on success, non-zero on failure.
*/
static int direct_loader_immediate_value(const char *name, size_t len,
settings_read_cb read_cb, void *cb_arg,
void *param)
settings_read_cb read_cb, void *cb_arg,
void *param)
{
const char *next;
size_t name_len;
int rc;
struct direct_immediate_value *context =
(struct direct_immediate_value *)param;
const char *next;
size_t name_len;
int rc;
struct direct_immediate_value *context =
(struct direct_immediate_value *)param;
/* only the exact match and ignore descendants of the searched name */
name_len = settings_name_next(name, &next);
if (name_len == 0) {
rc = read_cb(cb_arg, context->value, len);
if ((rc >= 0) && (rc <= context->value_size)) {
context->fetched = true;
context->value_len = rc;
LOG_INF("immediate load: OK.");
return 0;
}
return -EINVAL;
}
/* only the exact match and ignore descendants of the searched name */
name_len = settings_name_next(name, &next);
if (name_len == 0) {
rc = read_cb(cb_arg, context->value, len);
if ((rc >= 0) && (rc <= context->value_size)) {
context->fetched = true;
context->value_len = rc;
LOG_INF("immediate load: OK.");
return 0;
}
return -EINVAL;
}
/* other keys aren't served by the callback
* Return success in order to skip them
* and keep storage processing.
*/
return 0;
/* other keys aren't served by the callback
* Return success in order to skip them
* and keep storage processing.
*/
return 0;
}
/**
@@ -216,25 +216,25 @@ static int direct_loader_immediate_value(const char *name, size_t len,
* @return value length in bytes on success 0..N, negative on failure.
*/
static int load_immediate_value(const char *name, void *value,
size_t value_size)
size_t value_size)
{
int rc;
struct direct_immediate_value context;
int rc;
struct direct_immediate_value context;
context.fetched = false;
context.value_size = value_size;
context.value_len = 0;
context.value = value;
context.fetched = false;
context.value_size = value_size;
context.value_len = 0;
context.value = value;
rc = settings_load_subtree_direct(name, direct_loader_immediate_value,
(void *)&context);
if (rc == 0) {
if (!context.fetched) {
rc = -ENOENT;
}
}
rc = settings_load_subtree_direct(name, direct_loader_immediate_value,
(void *)&context);
if (rc == 0) {
if (!context.fetched) {
rc = -ENOENT;
}
}
return context.value_len;
return context.value_len;
}
/**
@@ -246,21 +246,21 @@ static int load_immediate_value(const char *name, void *value,
*/
int bacnet_storage_get(BACNET_STORAGE_KEY *key, void *data, size_t data_size)
{
char name[SETTINGS_MAX_NAME_LEN + 1] = { 0 };
int rc;
char name[SETTINGS_MAX_NAME_LEN + 1] = { 0 };
int rc;
rc = bacnet_storage_key_encode(name, sizeof(name), key);
LOG_INF("Get a key-value pair. Key=<%s>", name);
rc = load_immediate_value(name, data, data_size);
if (rc == 0) {
LOG_INF("empty entry");
} else if (rc > 0) {
LOG_HEXDUMP_INF(data, rc, "value");
} else if (rc == -ENOENT) {
LOG_INF("no entry");
} else {
LOG_INF("unexpected" FAIL_MSG, rc);
}
rc = bacnet_storage_key_encode(name, sizeof(name), key);
LOG_INF("Get a key-value pair. Key=<%s>", name);
rc = load_immediate_value(name, data, data_size);
if (rc == 0) {
LOG_INF("empty entry");
} else if (rc > 0) {
LOG_HEXDUMP_INF(data, rc, "value");
} else if (rc == -ENOENT) {
LOG_INF("no entry");
} else {
LOG_INF("unexpected" FAIL_MSG, rc);
}
return rc;
return rc;
}