Apply clang-format code style to all source files

This commit is contained in:
icex2
2019-10-20 00:50:40 +02:00
parent c600e1a423
commit c3bc8782f4
401 changed files with 13844 additions and 11361 deletions
+19 -14
View File
@@ -9,14 +9,16 @@
#include "util/cmdline.h"
#include "util/log.h"
bool cconfig_hook_config_init(struct cconfig* config, const char* usage_header,
enum cconfig_cmd_usage_out cmd_usage_out)
bool cconfig_hook_config_init(
struct cconfig *config,
const char *usage_header,
enum cconfig_cmd_usage_out cmd_usage_out)
{
bool success;
int argc;
char **argv;
enum cconfig_conf_error conf_error;
char* config_path;
char *config_path;
success = true;
@@ -33,36 +35,39 @@ bool cconfig_hook_config_init(struct cconfig* config, const char* usage_header,
for (int i = 0; i < argc; i++) {
if (!strcmp(argv[i], "--config")) {
if (i + 1 >= argc) {
log_fatal("--config parameter not followed by a config file "
log_fatal(
"--config parameter not followed by a config file "
"path param");
goto failure;
}
}
config_path = argv[i + 1];
break;
}
}
if (config_path) {
log_misc("Loading config file: %s", config_path);
conf_error = cconfig_conf_load_from_file(config, config_path, false);
if (conf_error == CCONFIG_CONF_ERROR_NO_SUCH_FILE) {
/* Create default config */
if (cconfig_conf_save_to_file(config, config_path) !=
CCONFIG_CONF_SUCCESS) {
log_fatal("Creating default config file '%s' failed",
config_path);
if (cconfig_conf_save_to_file(config, config_path) !=
CCONFIG_CONF_SUCCESS) {
log_fatal(
"Creating default config file '%s' failed", config_path);
goto failure;
} else {
log_info("Default configuration '%s' created. Restart "
"application", config_path);
log_info(
"Default configuration '%s' created. Restart "
"application",
config_path);
goto failure;
}
} else if (conf_error != CCONFIG_CONF_SUCCESS) {
log_fatal("Error loading config file '%s': %d", config_path,
conf_error);
log_fatal(
"Error loading config file '%s': %d", config_path, conf_error);
goto failure;
}
+4 -2
View File
@@ -4,7 +4,9 @@
#include "cconfig/cconfig.h"
#include "cconfig/cmd.h"
bool cconfig_hook_config_init(struct cconfig* config, const char* usage_header,
enum cconfig_cmd_usage_out cmd_usage_out);
bool cconfig_hook_config_init(
struct cconfig *config,
const char *usage_header,
enum cconfig_cmd_usage_out cmd_usage_out);
#endif
+51 -30
View File
@@ -9,10 +9,13 @@
#include "util/log.h"
#include "util/mem.h"
bool cconfig_util_get_int(struct cconfig* config, const char* key, int32_t* ret,
int32_t default_value)
bool cconfig_util_get_int(
struct cconfig *config,
const char *key,
int32_t *ret,
int32_t default_value)
{
struct cconfig_entry* entry;
struct cconfig_entry *entry;
log_assert(config);
log_assert(key);
@@ -29,10 +32,10 @@ bool cconfig_util_get_int(struct cconfig* config, const char* key, int32_t* ret,
return false;
}
bool cconfig_util_get_float(struct cconfig* config, const char* key, float* ret,
float default_value)
bool cconfig_util_get_float(
struct cconfig *config, const char *key, float *ret, float default_value)
{
struct cconfig_entry* entry;
struct cconfig_entry *entry;
log_assert(config);
log_assert(key);
@@ -49,10 +52,10 @@ bool cconfig_util_get_float(struct cconfig* config, const char* key, float* ret,
return false;
}
bool cconfig_util_get_bool(struct cconfig* config, const char* key, bool* ret,
bool default_value)
bool cconfig_util_get_bool(
struct cconfig *config, const char *key, bool *ret, bool default_value)
{
struct cconfig_entry* entry;
struct cconfig_entry *entry;
log_assert(config);
log_assert(key);
@@ -73,10 +76,14 @@ bool cconfig_util_get_bool(struct cconfig* config, const char* key, bool* ret,
return false;
}
bool cconfig_util_get_str(struct cconfig* config, const char* key,
char* buffer, size_t len, const char* default_value)
bool cconfig_util_get_str(
struct cconfig *config,
const char *key,
char *buffer,
size_t len,
const char *default_value)
{
struct cconfig_entry* entry;
struct cconfig_entry *entry;
size_t str_len;
log_assert(config);
@@ -97,11 +104,15 @@ bool cconfig_util_get_str(struct cconfig* config, const char* key,
return false;
}
bool cconfig_util_get_data(struct cconfig* config, const char* key,
uint8_t* buffer, size_t len, const uint8_t* default_value)
bool cconfig_util_get_data(
struct cconfig *config,
const char *key,
uint8_t *buffer,
size_t len,
const uint8_t *default_value)
{
size_t res_len;
struct cconfig_entry* entry;
struct cconfig_entry *entry;
log_assert(config);
log_assert(key);
@@ -124,10 +135,10 @@ bool cconfig_util_get_data(struct cconfig* config, const char* key,
return false;
}
void cconfig_util_set_int(struct cconfig* config, const char* key,
int32_t value, const char* desc)
void cconfig_util_set_int(
struct cconfig *config, const char *key, int32_t value, const char *desc)
{
char* str;
char *str;
size_t str_len;
log_assert(config);
@@ -143,10 +154,10 @@ void cconfig_util_set_int(struct cconfig* config, const char* key,
free(str);
}
void cconfig_util_set_float(struct cconfig* config, const char* key,
float value, const char* desc)
void cconfig_util_set_float(
struct cconfig *config, const char *key, float value, const char *desc)
{
char* str;
char *str;
size_t str_len;
log_assert(config);
@@ -162,8 +173,8 @@ void cconfig_util_set_float(struct cconfig* config, const char* key,
free(str);
}
void cconfig_util_set_bool(struct cconfig* config, const char* key, bool value,
const char* desc)
void cconfig_util_set_bool(
struct cconfig *config, const char *key, bool value, const char *desc)
{
log_assert(config);
log_assert(key);
@@ -172,8 +183,11 @@ void cconfig_util_set_bool(struct cconfig* config, const char* key, bool value,
cconfig_set(config, key, value ? "true" : "false", desc);
}
void cconfig_util_set_str(struct cconfig* config, const char* key,
const char* value, const char* desc)
void cconfig_util_set_str(
struct cconfig *config,
const char *key,
const char *value,
const char *desc)
{
log_assert(config);
log_assert(key);
@@ -183,10 +197,14 @@ void cconfig_util_set_str(struct cconfig* config, const char* key,
cconfig_set(config, key, value, desc);
}
void cconfig_util_set_data(struct cconfig* config, const char* key,
const uint8_t* value, size_t len, const char* desc)
void cconfig_util_set_data(
struct cconfig *config,
const char *key,
const uint8_t *value,
size_t len,
const char *desc)
{
char* str;
char *str;
size_t str_len;
log_assert(config);
@@ -202,10 +220,13 @@ void cconfig_util_set_data(struct cconfig* config, const char* key,
free(str);
}
void cconfig_util_log(struct cconfig* config, log_formatter_t log_formatter)
void cconfig_util_log(struct cconfig *config, log_formatter_t log_formatter)
{
for (uint32_t i = 0; i < config->nentries; i++) {
log_formatter(LOG_MODULE, "%s=%s", config->entries[i].key,
log_formatter(
LOG_MODULE,
"%s=%s",
config->entries[i].key,
config->entries[i].value);
}
}
+39 -21
View File
@@ -9,36 +9,54 @@
#include "util/log.h"
bool cconfig_util_get_int(struct cconfig* config, const char* key, int32_t* ret,
int32_t default_value);
bool cconfig_util_get_int(
struct cconfig *config,
const char *key,
int32_t *ret,
int32_t default_value);
bool cconfig_util_get_float(struct cconfig* config, const char* key, float* ret,
float default_value);
bool cconfig_util_get_float(
struct cconfig *config, const char *key, float *ret, float default_value);
bool cconfig_util_get_bool(struct cconfig* config, const char* key, bool* ret,
bool default_value);
bool cconfig_util_get_bool(
struct cconfig *config, const char *key, bool *ret, bool default_value);
bool cconfig_util_get_str(struct cconfig* config, const char* key,
char* buffer, size_t len, const char* default_value);
bool cconfig_util_get_str(
struct cconfig *config,
const char *key,
char *buffer,
size_t len,
const char *default_value);
bool cconfig_util_get_data(struct cconfig* config, const char* key,
uint8_t* buffer, size_t len, const uint8_t* default_value);
bool cconfig_util_get_data(
struct cconfig *config,
const char *key,
uint8_t *buffer,
size_t len,
const uint8_t *default_value);
void cconfig_util_set_int(struct cconfig* config, const char* key,
int32_t value, const char* desc);
void cconfig_util_set_int(
struct cconfig *config, const char *key, int32_t value, const char *desc);
void cconfig_util_set_float(struct cconfig* config, const char* key,
float value, const char* desc);
void cconfig_util_set_float(
struct cconfig *config, const char *key, float value, const char *desc);
void cconfig_util_set_bool(struct cconfig* config, const char* key, bool value,
const char* desc);
void cconfig_util_set_bool(
struct cconfig *config, const char *key, bool value, const char *desc);
void cconfig_util_set_str(struct cconfig* config, const char* key,
const char* value, const char* desc);
void cconfig_util_set_str(
struct cconfig *config,
const char *key,
const char *value,
const char *desc);
void cconfig_util_set_data(struct cconfig* config, const char* key,
const uint8_t* value, size_t len, const char* desc);
void cconfig_util_set_data(
struct cconfig *config,
const char *key,
const uint8_t *value,
size_t len,
const char *desc);
void cconfig_util_log(struct cconfig* config, log_formatter_t log_formatter);
void cconfig_util_log(struct cconfig *config, log_formatter_t log_formatter);
#endif
+20 -15
View File
@@ -6,21 +6,23 @@
#include "util/mem.h"
#include "util/str.h"
static struct cconfig_entry* cconfig_extend_config(struct cconfig* config)
static struct cconfig_entry *cconfig_extend_config(struct cconfig *config)
{
config->nentries++;
config->entries = xrealloc(config->entries,
config->nentries * sizeof(struct cconfig_entry));
memset(&config->entries[config->nentries - 1], 0,
config->entries = xrealloc(
config->entries, config->nentries * sizeof(struct cconfig_entry));
memset(
&config->entries[config->nentries - 1],
0,
sizeof(struct cconfig_entry));
return &config->entries[config->nentries - 1];
}
struct cconfig* cconfig_init()
struct cconfig *cconfig_init()
{
struct cconfig* config;
struct cconfig *config;
config = xmalloc(sizeof(struct cconfig));
memset(config, 0, sizeof(struct cconfig));
@@ -28,7 +30,7 @@ struct cconfig* cconfig_init()
return config;
}
struct cconfig_entry* cconfig_get(struct cconfig* config, const char* key)
struct cconfig_entry *cconfig_get(struct cconfig *config, const char *key)
{
log_assert(config);
log_assert(key);
@@ -42,10 +44,13 @@ struct cconfig_entry* cconfig_get(struct cconfig* config, const char* key)
return NULL;
}
void cconfig_set(struct cconfig* config, const char* key, const char* value,
const char* desc)
void cconfig_set(
struct cconfig *config,
const char *key,
const char *value,
const char *desc)
{
struct cconfig_entry* entry;
struct cconfig_entry *entry;
log_assert(config);
log_assert(key);
@@ -69,9 +74,9 @@ void cconfig_set(struct cconfig* config, const char* key, const char* value,
entry->value = str_dup(value);
}
void cconfig_set2(struct cconfig* config, const char* key, const char* value)
void cconfig_set2(struct cconfig *config, const char *key, const char *value)
{
struct cconfig_entry* entry;
struct cconfig_entry *entry;
log_assert(config);
log_assert(key);
@@ -89,14 +94,14 @@ void cconfig_set2(struct cconfig* config, const char* key, const char* value)
entry->key = str_dup(key);
entry->value = str_dup(value);
/* Description optional, but do not wipe previous description if
/* Description optional, but do not wipe previous description if
available */
if (!entry->desc) {
entry->desc = "";
}
}
void cconfig_finit(struct cconfig* config)
void cconfig_finit(struct cconfig *config)
{
for (uint32_t i = 0; i < config->nentries; i++) {
free(config->entries[i].key);
+13 -11
View File
@@ -6,26 +6,28 @@
#include <stdlib.h>
struct cconfig_entry {
char* key;
char* value;
char* desc;
char *key;
char *value;
char *desc;
};
struct cconfig {
uint32_t nentries;
struct cconfig_entry* entries;
struct cconfig_entry *entries;
};
struct cconfig* cconfig_init();
struct cconfig *cconfig_init();
struct cconfig_entry* cconfig_get(struct cconfig* config,
const char* key);
struct cconfig_entry *cconfig_get(struct cconfig *config, const char *key);
void cconfig_set(struct cconfig* config, const char* key, const char* value,
const char* desc);
void cconfig_set(
struct cconfig *config,
const char *key,
const char *value,
const char *desc);
void cconfig_set2(struct cconfig* config, const char* key, const char* value);
void cconfig_set2(struct cconfig *config, const char *key, const char *value);
void cconfig_finit(struct cconfig* config);
void cconfig_finit(struct cconfig *config);
#endif
+22 -13
View File
@@ -11,8 +11,8 @@
#include "util/log.h"
#include "util/str.h"
static void cconfig_cmd_usage_print(enum cconfig_cmd_usage_out output,
const char* fmt, ...)
static void
cconfig_cmd_usage_print(enum cconfig_cmd_usage_out output, const char *fmt, ...)
{
char buffer[32768];
va_list ap;
@@ -46,15 +46,19 @@ static void cconfig_cmd_usage_print(enum cconfig_cmd_usage_out output,
va_end(ap);
}
bool cconfig_cmd_parse(struct cconfig* config, const char* key_ident, int argc,
char** argv, bool add_params_if_absent)
bool cconfig_cmd_parse(
struct cconfig *config,
const char *key_ident,
int argc,
char **argv,
bool add_params_if_absent)
{
bool no_error;
struct cconfig_entry* entry;
char* tmp;
char* cur_tok;
struct cconfig_entry *entry;
char *tmp;
char *cur_tok;
int ntok;
char* toks[2];
char *toks[2];
no_error = true;
@@ -105,8 +109,10 @@ bool cconfig_cmd_parse(struct cconfig* config, const char* key_ident, int argc,
cconfig_set2(config, toks[0], toks[1]);
} else {
/* Ignore cmd params that are not found in config */
log_warning("Could not find cmd parameter with key '%s' in "
"config, ignored", toks[0]);
log_warning(
"Could not find cmd parameter with key '%s' in "
"config, ignored",
toks[0]);
}
free(tmp);
@@ -116,13 +122,16 @@ bool cconfig_cmd_parse(struct cconfig* config, const char* key_ident, int argc,
return no_error;
}
void cconfig_cmd_print_usage(struct cconfig* config, const char* usage_header,
enum cconfig_cmd_usage_out output)
void cconfig_cmd_print_usage(
struct cconfig *config,
const char *usage_header,
enum cconfig_cmd_usage_out output)
{
cconfig_cmd_usage_print(output, "%s\n", usage_header);
for (uint32_t i = 0; i < config->nentries; i++) {
cconfig_cmd_usage_print(output,
cconfig_cmd_usage_print(
output,
" %s: %s\n"
" default: %s\n",
config->entries[i].key,
+10 -4
View File
@@ -12,10 +12,16 @@ enum cconfig_cmd_usage_out {
CCONFIG_CMD_USAGE_OUT_LOG,
};
bool cconfig_cmd_parse(struct cconfig* config, const char* key_ident, int argc,
char** argv, bool add_params_if_absent);
bool cconfig_cmd_parse(
struct cconfig *config,
const char *key_ident,
int argc,
char **argv,
bool add_params_if_absent);
void cconfig_cmd_print_usage(struct cconfig* config, const char* usage_header,
enum cconfig_cmd_usage_out output);
void cconfig_cmd_print_usage(
struct cconfig *config,
const char *usage_header,
enum cconfig_cmd_usage_out output);
#endif
+28 -22
View File
@@ -10,17 +10,17 @@
#include "util/log.h"
#include "util/str.h"
enum cconfig_conf_error cconfig_conf_load_from_file(struct cconfig* config,
const char* path, bool add_params_if_absent)
enum cconfig_conf_error cconfig_conf_load_from_file(
struct cconfig *config, const char *path, bool add_params_if_absent)
{
char* pos_lines;
char* pos_key_val;
char* ctx_lines;
char* ctx_key_val;
char* data;
char *pos_lines;
char *pos_key_val;
char *ctx_lines;
char *ctx_key_val;
char *data;
size_t len;
if (!file_load(path, (void**) &data, &len, true)) {
if (!file_load(path, (void **) &data, &len, true)) {
/* If file does not exist, create one with default configuration
values */
if (path_exists(path)) {
@@ -33,11 +33,11 @@ enum cconfig_conf_error cconfig_conf_load_from_file(struct cconfig* config,
pos_lines = strtok_r(data, "\n", &ctx_lines);
while (pos_lines != NULL) {
char* pos_line_dup;
char* key = NULL;
char* val = NULL;
char *pos_line_dup;
char *key = NULL;
char *val = NULL;
int cnt = 0;
struct cconfig_entry* entry;
struct cconfig_entry *entry;
/* ignore comments and empty lines */
if (strlen(pos_lines) > 0 && pos_lines[0] != '#') {
@@ -47,7 +47,6 @@ enum cconfig_conf_error cconfig_conf_load_from_file(struct cconfig* config,
log_misc("Line: %s", pos_lines);
while (pos_key_val != NULL) {
if (cnt == 0) {
key = pos_key_val;
} else if (cnt == 1) {
@@ -60,8 +59,10 @@ enum cconfig_conf_error cconfig_conf_load_from_file(struct cconfig* config,
/* Key requiured, value can be NULL */
if (cnt != 1 && cnt != 2) {
log_warning("Invalid options line %s in options file %s",
pos_lines, path);
log_warning(
"Invalid options line %s in options file %s",
pos_lines,
path);
free(pos_line_dup);
free(data);
return CCONFIG_CONF_ERROR_PARSING;
@@ -80,8 +81,10 @@ enum cconfig_conf_error cconfig_conf_load_from_file(struct cconfig* config,
cconfig_set2(config, key, val);
} else {
/* Ignore cmd params that are not found in config */
log_warning("Could not find parameter with key '%s' in "
"config, ignored", key);
log_warning(
"Could not find parameter with key '%s' in "
"config, ignored",
key);
}
free(pos_line_dup);
@@ -92,13 +95,13 @@ enum cconfig_conf_error cconfig_conf_load_from_file(struct cconfig* config,
free(data);
return CCONFIG_CONF_SUCCESS;
return CCONFIG_CONF_SUCCESS;
}
enum cconfig_conf_error cconfig_conf_save_to_file(struct cconfig* config,
const char* path)
enum cconfig_conf_error
cconfig_conf_save_to_file(struct cconfig *config, const char *path)
{
FILE* file;
FILE *file;
file = fopen(path, "wb+");
@@ -108,7 +111,10 @@ enum cconfig_conf_error cconfig_conf_save_to_file(struct cconfig* config,
for (uint32_t i = 0; i < config->nentries; i++) {
fprintf(file, "# %s\n", config->entries[i].desc);
fprintf(file, "%s=%s\n\n", config->entries[i].key,
fprintf(
file,
"%s=%s\n\n",
config->entries[i].key,
config->entries[i].value);
}
+4 -4
View File
@@ -9,8 +9,8 @@ enum cconfig_conf_error {
CCONFIG_CONF_ERROR_PARSING = 3,
};
enum cconfig_conf_error cconfig_conf_load_from_file(struct cconfig* config,
const char* path, bool add_params_if_absent);
enum cconfig_conf_error cconfig_conf_load_from_file(
struct cconfig *config, const char *path, bool add_params_if_absent);
enum cconfig_conf_error cconfig_conf_save_to_file(struct cconfig* config,
const char* path);
enum cconfig_conf_error
cconfig_conf_save_to_file(struct cconfig *config, const char *path);