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

@@ -28,15 +28,17 @@
* @return an allocated string with the full JID or NULL if no domain
* is specified
*/
char *xmpp_jid_new(xmpp_ctx_t *ctx, const char *node,
const char *domain,
const char *resource)
char *xmpp_jid_new(xmpp_ctx_t *ctx,
const char *node,
const char *domain,
const char *resource)
{
char *result;
size_t len, nlen, dlen, rlen;
/* jid must at least have a domain */
if (domain == NULL) return NULL;
if (domain == NULL)
return NULL;
/* accumulate lengths */
dlen = strlen(domain);
@@ -47,16 +49,16 @@ char *xmpp_jid_new(xmpp_ctx_t *ctx, const char *node,
/* concat components */
result = xmpp_alloc(ctx, len + 1);
if (result != NULL) {
if (node != NULL) {
memcpy(result, node, nlen - 1);
result[nlen-1] = '@';
}
if (node != NULL) {
memcpy(result, node, nlen - 1);
result[nlen - 1] = '@';
}
memcpy(result + nlen, domain, dlen);
if (resource != NULL) {
result[nlen+dlen] = '/';
memcpy(result+nlen+dlen+1, resource, rlen - 1);
}
result[len] = '\0';
if (resource != NULL) {
result[nlen + dlen] = '/';
memcpy(result + nlen + dlen + 1, resource, rlen - 1);
}
result[len] = '\0';
}
return result;
@@ -77,8 +79,8 @@ char *xmpp_jid_bare(xmpp_ctx_t *ctx, const char *jid)
len = strcspn(jid, "/");
result = xmpp_alloc(ctx, len + 1);
if (result != NULL) {
memcpy(result, jid, len);
result[len] = '\0';
memcpy(result, jid, len);
result[len] = '\0';
}
return result;
@@ -99,11 +101,11 @@ char *xmpp_jid_node(xmpp_ctx_t *ctx, const char *jid)
c = strchr(jid, '@');
if (c != NULL) {
result = xmpp_alloc(ctx, (c-jid) + 1);
if (result != NULL) {
memcpy(result, jid, (c-jid));
result[c-jid] = '\0';
}
result = xmpp_alloc(ctx, (c - jid) + 1);
if (result != NULL) {
memcpy(result, jid, (c - jid));
result[c - jid] = '\0';
}
}
return result;
@@ -124,17 +126,17 @@ char *xmpp_jid_domain(xmpp_ctx_t *ctx, const char *jid)
c = strchr(jid, '@');
if (c == NULL) {
/* no node, assume domain */
c = jid;
/* no node, assume domain */
c = jid;
} else {
/* advance past the separator */
c++;
/* advance past the separator */
c++;
}
dlen = strcspn(c, "/"); /* do not include resource */
result = xmpp_alloc(ctx, dlen + 1);
if (result != NULL) {
memcpy(result, c, dlen);
result[dlen] = '\0';
memcpy(result, c, dlen);
result[dlen] = '\0';
}
return result;