Update .clang-format

Align with wlroots style
This commit is contained in:
Johan Malm 2020-09-28 20:41:41 +01:00
parent 96b5ab1fc1
commit 96e05057a3
32 changed files with 669 additions and 515 deletions

View file

@ -1,6 +1,7 @@
#include "common/buf.h"
void buf_init(struct buf *s)
void
buf_init(struct buf *s)
{
s->alloc = 256;
s->buf = malloc(s->alloc);
@ -8,10 +9,12 @@ void buf_init(struct buf *s)
s->len = 0;
}
void buf_add(struct buf *s, const char *data)
void
buf_add(struct buf *s, const char *data)
{
if (!data || data[0] == '\0')
if (!data || data[0] == '\0') {
return;
}
int len = strlen(data);
if (s->alloc <= s->len + len + 1) {
s->alloc = s->alloc + len;

View file

@ -4,11 +4,11 @@
* Copyright Johan Malm 2020
*/
#include <glib.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <stdbool.h>
#include <glib.h>
#include "common/dir.h"
#include "common/log.h"
@ -39,7 +39,8 @@ static struct dir theme_dirs[] = {
};
/* clang-format on */
static bool isdir(const char *path)
static bool
isdir(const char *path)
{
struct stat st;
return (!stat(path, &st) && S_ISDIR(st.st_mode));
@ -53,25 +54,30 @@ struct ctx {
const char *theme_name;
};
static void build_config_path(struct ctx *ctx, char *prefix, const char *path)
static void
build_config_path(struct ctx *ctx, char *prefix, const char *path)
{
if (!prefix)
if (!prefix) {
snprintf(ctx->buf, ctx->len, "%s", path);
else
} else {
snprintf(ctx->buf, ctx->len, "%s/%s", prefix, path);
}
}
static void build_theme_path(struct ctx *ctx, char *prefix, const char *path)
static void
build_theme_path(struct ctx *ctx, char *prefix, const char *path)
{
if (!prefix)
if (!prefix) {
snprintf(ctx->buf, ctx->len, "%s/%s/openbox-3", path,
ctx->theme_name);
else
} else {
snprintf(ctx->buf, ctx->len, "%s/%s/%s/openbox-3", prefix, path,
ctx->theme_name);
}
}
char *find_dir(struct ctx *ctx)
char *
find_dir(struct ctx *ctx)
{
char *debug = getenv("LABWC_DEBUG_DIR_CONFIG_AND_THEME");
@ -80,20 +86,24 @@ char *find_dir(struct ctx *ctx)
if (!d.prefix) {
/* handle /etc/xdg... */
ctx->build_path_fn(ctx, NULL, d.path);
if (debug)
if (debug) {
info("%s", ctx->buf);
if (isdir(ctx->buf))
}
if (isdir(ctx->buf)) {
return ctx->buf;
}
} else {
/* handle $HOME/.config/... and $XDG_* */
char *prefix = getenv(d.prefix);
if (!prefix)
if (!prefix) {
continue;
}
gchar **prefixes = g_strsplit(prefix, ":", -1);
for (gchar **p = prefixes; *p; p++) {
ctx->build_path_fn(ctx, *p, d.path);
if (debug)
if (debug) {
info("%s", ctx->buf);
}
if (isdir(ctx->buf)) {
g_strfreev(prefixes);
return ctx->buf;
@ -107,11 +117,13 @@ char *find_dir(struct ctx *ctx)
return ctx->buf;
}
char *config_dir(void)
char *
config_dir(void)
{
static char buf[4096] = { 0 };
if (buf[0] != '\0')
if (buf[0] != '\0') {
return buf;
}
struct ctx ctx = { .build_path_fn = build_config_path,
.buf = buf,
.len = sizeof(buf),
@ -119,7 +131,8 @@ char *config_dir(void)
return find_dir(&ctx);
}
char *theme_dir(const char *theme_name)
char *
theme_dir(const char *theme_name)
{
static char buf[4096] = { 0 };
struct ctx ctx = { .build_path_fn = build_theme_path,

View file

@ -3,8 +3,8 @@
#include "common/font.h"
static PangoRectangle font_extents(const char *font_description,
const char *string)
static PangoRectangle
font_extents(const char *font_description, const char *string)
{
PangoRectangle rect;
cairo_surface_t *surface;
@ -35,7 +35,8 @@ static PangoRectangle font_extents(const char *font_description,
return rect;
}
int font_height(const char *font_description)
int
font_height(const char *font_description)
{
PangoRectangle rectangle;
rectangle = font_extents(font_description, "abcdefg");

View file

@ -10,19 +10,22 @@
#include <stdio.h>
char *grab_file(const char *filename)
char *
grab_file(const char *filename)
{
char *line = NULL;
size_t len = 0;
FILE *stream = fopen(filename, "r");
if (!stream)
if (!stream) {
return NULL;
}
struct buf buffer;
buf_init(&buffer);
while ((getline(&line, &len, stream) != -1)) {
char *p = strrchr(line, '\n');
if (p)
if (p) {
*p = '\0';
}
buf_add(&buffer, line);
}
free(line);

View file

@ -1,13 +1,14 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#define LABWC_COLOR_YELLOW "\033[0;33m"
#define LABWC_COLOR_RED "\033[0;31m"
#define LABWC_COLOR_RESET "\033[0m"
void info(const char *msg, ...)
void
info(const char *msg, ...)
{
va_list params;
fprintf(stderr, LABWC_COLOR_YELLOW);
@ -19,7 +20,8 @@ void info(const char *msg, ...)
fprintf(stderr, "\n");
}
void warn(const char *err, ...)
void
warn(const char *err, ...)
{
va_list params;
fprintf(stderr, LABWC_COLOR_RED);

View file

@ -1,6 +1,7 @@
#include <glib.h>
void spawn_async_no_shell(char const *command)
void
spawn_async_no_shell(char const *command)
{
GError *err = NULL;
gchar **argv = NULL;