Unify coding style

@sjaeckel integrated clang-format with formal coding style. Run his
script and commit changes.

There are pros and cons of this commit.

Mixed coding style is a "broken window". A good single style simplifies
reading and writing code.

On the other hand, this is a big change which will lead to conflicts.
This commit is contained in:
Dmitry Podgorny
2020-01-03 22:02:22 +02:00
parent eef07cef36
commit 562a06425b
62 changed files with 3972 additions and 3746 deletions

106
src/ctx.c
View File

@@ -52,7 +52,7 @@
/* Workaround for visual studio without va_copy support. */
#if defined(_MSC_VER) && _MSC_VER < 1800 || defined(__HAIKU__)
#define va_copy(d,s) ((d) = (s))
#define va_copy(d, s) ((d) = (s))
#endif
/** Initialize the Strophe library.
@@ -61,7 +61,7 @@
*
* @ingroup Init
*/
void xmpp_initialize(void)
void xmpp_initialize(void)
{
sock_initialize();
resolver_initialize();
@@ -113,8 +113,7 @@ void xmpp_shutdown(void)
*/
int xmpp_version_check(int major, int minor)
{
return (major == LIBXMPP_VERSION_MAJOR) &&
(minor >= LIBXMPP_VERSION_MINOR);
return (major == LIBXMPP_VERSION_MAJOR) && (minor >= LIBXMPP_VERSION_MINOR);
}
/* We define the global default allocator, logger, and context here. */
@@ -122,17 +121,17 @@ int xmpp_version_check(int major, int minor)
/* Wrap stdlib routines malloc, free, and realloc for default memory
* management.
*/
static void *_malloc(const size_t size, void * const userdata)
static void *_malloc(const size_t size, void *const userdata)
{
return malloc(size);
}
static void _free(void *p, void * const userdata)
static void _free(void *p, void *const userdata)
{
free(p);
}
static void *_realloc(void *p, const size_t size, void * const userdata)
static void *_realloc(void *p, const size_t size, void *const userdata)
{
return realloc(p, size);
}
@@ -140,17 +139,13 @@ static void *_realloc(void *p, const size_t size, void * const userdata)
/* default memory function map */
static xmpp_mem_t xmpp_default_mem = {
_malloc, /* use the thinly wrapped stdlib routines by default */
_free,
_realloc,
NULL
};
_free, _realloc, NULL};
/* log levels and names */
static const char * const _xmpp_log_level_name[4] = {"DEBUG", "INFO", "WARN", "ERROR"};
static const xmpp_log_level_t _xmpp_default_logger_levels[] = {XMPP_LEVEL_DEBUG,
XMPP_LEVEL_INFO,
XMPP_LEVEL_WARN,
XMPP_LEVEL_ERROR};
static const char *const _xmpp_log_level_name[4] = {"DEBUG", "INFO", "WARN",
"ERROR"};
static const xmpp_log_level_t _xmpp_default_logger_levels[] = {
XMPP_LEVEL_DEBUG, XMPP_LEVEL_INFO, XMPP_LEVEL_WARN, XMPP_LEVEL_ERROR};
/** Log a message.
* The default logger writes to stderr.
@@ -161,22 +156,25 @@ static const xmpp_log_level_t _xmpp_default_logger_levels[] = {XMPP_LEVEL_DEBUG,
* @param area the area the log message is for
* @param msg the log message
*/
static void xmpp_default_logger(void * const userdata,
const xmpp_log_level_t level,
const char * const area,
const char * const msg)
static void xmpp_default_logger(void *const userdata,
const xmpp_log_level_t level,
const char *const area,
const char *const msg)
{
xmpp_log_level_t filter_level = * (xmpp_log_level_t*)userdata;
xmpp_log_level_t filter_level = *(xmpp_log_level_t *)userdata;
if (level >= filter_level)
fprintf(stderr, "%s %s %s\n", area, _xmpp_log_level_name[level], msg);
}
static const xmpp_log_t _xmpp_default_loggers[] = {
{&xmpp_default_logger, (void*)&_xmpp_default_logger_levels[XMPP_LEVEL_DEBUG]},
{&xmpp_default_logger, (void*)&_xmpp_default_logger_levels[XMPP_LEVEL_INFO]},
{&xmpp_default_logger, (void*)&_xmpp_default_logger_levels[XMPP_LEVEL_WARN]},
{&xmpp_default_logger, (void*)&_xmpp_default_logger_levels[XMPP_LEVEL_ERROR]}
};
{&xmpp_default_logger,
(void *)&_xmpp_default_logger_levels[XMPP_LEVEL_DEBUG]},
{&xmpp_default_logger,
(void *)&_xmpp_default_logger_levels[XMPP_LEVEL_INFO]},
{&xmpp_default_logger,
(void *)&_xmpp_default_logger_levels[XMPP_LEVEL_WARN]},
{&xmpp_default_logger,
(void *)&_xmpp_default_logger_levels[XMPP_LEVEL_ERROR]}};
/** Get a default logger with filtering.
* The default logger provides a basic logging setup which writes log
@@ -192,12 +190,13 @@ static const xmpp_log_t _xmpp_default_loggers[] = {
xmpp_log_t *xmpp_get_default_logger(xmpp_log_level_t level)
{
/* clamp to the known range */
if (level > XMPP_LEVEL_ERROR) level = XMPP_LEVEL_ERROR;
if (level > XMPP_LEVEL_ERROR)
level = XMPP_LEVEL_ERROR;
return (xmpp_log_t*)&_xmpp_default_loggers[level];
return (xmpp_log_t *)&_xmpp_default_loggers[level];
}
static xmpp_log_t xmpp_default_log = { NULL, NULL };
static xmpp_log_t xmpp_default_log = {NULL, NULL};
/* convenience functions for accessing the context */
@@ -209,7 +208,7 @@ static xmpp_log_t xmpp_default_log = { NULL, NULL };
*
* @return a pointer to the allocated memory or NULL on an error
*/
void *xmpp_alloc(const xmpp_ctx_t * const ctx, const size_t size)
void *xmpp_alloc(const xmpp_ctx_t *const ctx, const size_t size)
{
return ctx->mem->alloc(size, ctx->mem->userdata);
}
@@ -220,7 +219,7 @@ void *xmpp_alloc(const xmpp_ctx_t * const ctx, const size_t size)
* @param ctx a Strophe context object
* @param p a pointer referencing memory to be freed
*/
void xmpp_free(const xmpp_ctx_t * const ctx, void *p)
void xmpp_free(const xmpp_ctx_t *const ctx, void *p)
{
ctx->mem->free(p, ctx->mem->userdata);
}
@@ -234,8 +233,7 @@ void xmpp_free(const xmpp_ctx_t * const ctx, void *p)
*
* @return a pointer to the reallocated memory or NULL on an error
*/
void *xmpp_realloc(const xmpp_ctx_t * const ctx, void *p,
const size_t size)
void *xmpp_realloc(const xmpp_ctx_t *const ctx, void *p, const size_t size)
{
return ctx->mem->realloc(p, size, ctx->mem->userdata);
}
@@ -253,10 +251,10 @@ void *xmpp_realloc(const xmpp_ctx_t * const ctx, void *p,
* @param fmt a printf-style format string for the message
* @param ap variable argument list supplied for the format string
*/
void xmpp_log(const xmpp_ctx_t * const ctx,
void xmpp_log(const xmpp_ctx_t *const ctx,
const xmpp_log_level_t level,
const char * const area,
const char * const fmt,
const char *const area,
const char *const fmt,
va_list ap)
{
int oldret, ret;
@@ -304,9 +302,9 @@ void xmpp_log(const xmpp_ctx_t * const ctx,
* @param fmt a printf-style format string followed by a variable list of
* arguments to format
*/
void xmpp_error(const xmpp_ctx_t * const ctx,
const char * const area,
const char * const fmt,
void xmpp_error(const xmpp_ctx_t *const ctx,
const char *const area,
const char *const fmt,
...)
{
va_list ap;
@@ -326,10 +324,10 @@ void xmpp_error(const xmpp_ctx_t * const ctx,
* @param fmt a printf-style format string followed by a variable list of
* arguments to format
*/
void xmpp_warn(const xmpp_ctx_t * const ctx,
const char * const area,
const char * const fmt,
...)
void xmpp_warn(const xmpp_ctx_t *const ctx,
const char *const area,
const char *const fmt,
...)
{
va_list ap;
@@ -348,10 +346,10 @@ void xmpp_warn(const xmpp_ctx_t * const ctx,
* @param fmt a printf-style format string followed by a variable list of
* arguments to format
*/
void xmpp_info(const xmpp_ctx_t * const ctx,
const char * const area,
const char * const fmt,
...)
void xmpp_info(const xmpp_ctx_t *const ctx,
const char *const area,
const char *const fmt,
...)
{
va_list ap;
@@ -370,9 +368,9 @@ void xmpp_info(const xmpp_ctx_t * const ctx,
* @param fmt a printf-style format string followed by a variable list of
* arguments to format
*/
void xmpp_debug(const xmpp_ctx_t * const ctx,
const char * const area,
const char * const fmt,
void xmpp_debug(const xmpp_ctx_t *const ctx,
const char *const area,
const char *const fmt,
...)
{
va_list ap;
@@ -396,8 +394,8 @@ void xmpp_debug(const xmpp_ctx_t * const ctx,
*
* @ingroup Context
*/
xmpp_ctx_t *xmpp_ctx_new(const xmpp_mem_t * const mem,
const xmpp_log_t * const log)
xmpp_ctx_t *xmpp_ctx_new(const xmpp_mem_t *const mem,
const xmpp_log_t *const log)
{
xmpp_ctx_t *ctx = NULL;
@@ -436,7 +434,7 @@ xmpp_ctx_t *xmpp_ctx_new(const xmpp_mem_t * const mem,
*
* @ingroup Context
*/
void xmpp_ctx_free(xmpp_ctx_t * const ctx)
void xmpp_ctx_free(xmpp_ctx_t *const ctx)
{
/* mem and log are owned by their suppliers */
xmpp_rand_free(ctx, ctx->rand);
@@ -450,7 +448,7 @@ void xmpp_ctx_free(xmpp_ctx_t * const ctx)
*
* @ingroup Context
*/
void xmpp_ctx_set_timeout(xmpp_ctx_t * const ctx, const unsigned long timeout)
void xmpp_ctx_set_timeout(xmpp_ctx_t *const ctx, const unsigned long timeout)
{
ctx->timeout = timeout;
}