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

View File

@@ -38,7 +38,7 @@ struct _parser_t {
void *userdata;
int depth;
xmpp_stanza_t *stanza;
char* inner_text;
char *inner_text;
/* number of allocated bytes */
int inner_text_size;
/* excluding terminal '\0' */
@@ -94,14 +94,15 @@ static char *_xml_name(xmpp_ctx_t *ctx, const char *nsname)
size_t len;
c = strchr(nsname, namespace_sep);
if (c == NULL) return xmpp_strdup(ctx, nsname);
if (c == NULL)
return xmpp_strdup(ctx, nsname);
c++;
len = strlen(c);
result = xmpp_alloc(ctx, len + 1);
if (result != NULL) {
memcpy(result, c, len);
result[len] = '\0';
memcpy(result, c, len);
result[len] = '\0';
}
return result;
@@ -115,11 +116,11 @@ static char *_xml_namespace(xmpp_ctx_t *ctx, const char *nsname)
c = strchr(nsname, namespace_sep);
if (c != NULL) {
result = xmpp_alloc(ctx, (c-nsname) + 1);
if (result != NULL) {
memcpy(result, nsname, (c-nsname));
result[c-nsname] = '\0';
}
result = xmpp_alloc(ctx, (c - nsname) + 1);
if (result != NULL) {
memcpy(result, nsname, (c - nsname));
result[c - nsname] = '\0';
}
}
return result;
@@ -130,12 +131,13 @@ static void _set_attributes(xmpp_stanza_t *stanza, const XML_Char **attrs)
char *attr;
int i;
if (!attrs) return;
if (!attrs)
return;
for (i = 0; attrs[i]; i += 2) {
/* namespaced attributes aren't used in xmpp, discard namespace */
attr = _xml_name(stanza->ctx, attrs[i]);
xmpp_stanza_set_attribute(stanza, attr, attrs[i+1]);
xmpp_stanza_set_attribute(stanza, attr, attrs[i + 1]);
xmpp_free(stanza->ctx, attr);
}
}
@@ -160,9 +162,8 @@ static void complete_inner_text(parser_t *parser)
}
}
static void _start_element(void *userdata,
const XML_Char *nsname,
const XML_Char **attrs)
static void
_start_element(void *userdata, const XML_Char *nsname, const XML_Char **attrs)
{
parser_t *parser = (parser_t *)userdata;
xmpp_stanza_t *child;
@@ -174,8 +175,7 @@ static void _start_element(void *userdata,
if (parser->depth == 0) {
/* notify the owner */
if (parser->startcb)
parser->startcb(name, (char **)attrs,
parser->userdata);
parser->startcb(name, (char **)attrs, parser->userdata);
} else {
/* build stanzas at depth 1 */
if (!parser->stanza && parser->depth != 1) {
@@ -201,8 +201,10 @@ static void _start_element(void *userdata,
}
}
if (ns) xmpp_free(parser->ctx, ns);
if (name) xmpp_free(parser->ctx, name);
if (ns)
xmpp_free(parser->ctx, ns);
if (name)
xmpp_free(parser->ctx, name);
parser->depth++;
}
@@ -224,8 +226,7 @@ static void _end_element(void *userdata, const XML_Char *name)
parser->stanza = parser->stanza->parent;
} else {
if (parser->stanzacb)
parser->stanzacb(parser->stanza,
parser->userdata);
parser->stanzacb(parser->stanza, parser->userdata);
xmpp_stanza_release(parser->stanza);
parser->stanza = NULL;
}
@@ -237,13 +238,14 @@ static void _characters(void *userdata, const XML_Char *s, int len)
parser_t *parser = (parser_t *)userdata;
char *p;
if (parser->depth < 2) return;
if (parser->depth < 2)
return;
/* Join all parts to a single resulting string. Stanza is created in
* _start_element() and _end_element(). */
if (parser->inner_text_used + len >= parser->inner_text_size) {
parser->inner_text_size = parser->inner_text_used + len + 1 +
INNER_TEXT_PADDING;
parser->inner_text_size =
parser->inner_text_used + len + 1 + INNER_TEXT_PADDING;
p = xmpp_realloc(parser->ctx, parser->inner_text,
parser->inner_text_size);
if (p == NULL) {
@@ -288,7 +290,7 @@ parser_t *parser_new(xmpp_ctx_t *ctx,
return parser;
}
char* parser_attr_name(xmpp_ctx_t *ctx, char *nsname)
char *parser_attr_name(xmpp_ctx_t *ctx, char *nsname)
{
return _xml_name(ctx, nsname);
}
@@ -300,7 +302,7 @@ void parser_free(parser_t *parser)
XML_ParserFree(parser->expat);
if (parser->inner_text) {
xmpp_free (parser->ctx, parser->inner_text);
xmpp_free(parser->ctx, parser->inner_text);
parser->inner_text = NULL;
}