Skip to content

Commit 435e6dd

Browse files
committed
astyle'ify
1 parent 7488180 commit 435e6dd

File tree

6 files changed

+167
-126
lines changed

6 files changed

+167
-126
lines changed

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ EXE=hatexmpp
99
CFLAGS+=$(shell pkg-config fuse loudmouth-1.0 --cflags)
1010
LDLIBS=$(shell pkg-config fuse loudmouth-1.0 --libs)
1111

12-
all: $(EXE)
12+
all: $(EXE) astyle
1313

1414
$(EXE): version.o hatexmpp.o fuse.o xmpp.o
1515

@@ -20,11 +20,13 @@ xmpp.o: xmpp.c common.h
2020
version.c:
2121
echo "char HateXMPP_ver[] = "\"0.2-`git log --no-show-signature -n1 --pretty=format:%H`\""; char * getversion(void) { return HateXMPP_ver; }" > version.c
2222

23-
.PHONY: clean
23+
.PHONY: clean astyle
2424

2525
clean:
2626
rm -rf *.o version.c $(EXE)
2727

2828
install: $(EXE)
2929
install $(EXE) $(DESTDIR)/usr/bin
3030

31+
astyle:
32+
astyle --style=linux --indent=tab *.c *.h

common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ extern void xmpp_add_to_roster(const gchar *jid);
9494
extern void xmpp_del_from_roster(const gchar *jid);
9595
extern void xmpp_muc_change_nick(const gchar *mucjid, const gchar *nick);
9696
extern void xmpp_send_presence();
97-
97+
9898
extern int fd_events;
9999
extern gchar * eventstr(gchar *str);
100100
#define eventf(FMT,ARGS...) g_free(eventstr(g_strdup_printf(FMT, ##ARGS)))

config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
Suckless configuration of HateXMPP
3-
3+
44
Uncomment #define to turn feature on.
55
66
If you adding testing/unstable/cludgy feature, please make possible

fuse.c

Lines changed: 70 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,24 @@ unsigned FDn;
55
static void * mainloopthread(void *loop);
66
pthread_t thr;
77

8-
gchar *filter_str(gchar *str) {
8+
gchar *filter_str(gchar *str)
9+
{
910
gchar *ch = strchr(str, '\n');
10-
if (ch)
11+
if (ch)
1112
str[ch-str] = 0;
1213
g_strstrip(str);
1314
return str;
1415
}
1516

16-
int fileexists(const char *path) { /* TODO remove/rewrite */
17+
int fileexists(const char *path) /* TODO remove/rewrite */
18+
{
1719
if (strcmp(path, "/log") == 0) return 1;
1820
if (strncmp(path, "/roster/", 8) == 0) return 1;
1921
return 0;
2022
}
2123

22-
rosteritem * getri(const char *path) {
24+
rosteritem * getri(const char *path)
25+
{
2326
char *p;
2427
rosteritem *ri;
2528

@@ -36,7 +39,8 @@ rosteritem * getri(const char *path) {
3639
return ri;
3740
}
3841

39-
FD * addfd(rosteritem *ri) {
42+
FD * addfd(rosteritem *ri)
43+
{
4044
FD *fd;
4145
int *id;
4246

@@ -50,19 +54,22 @@ FD * addfd(rosteritem *ri) {
5054
return fd;
5155
}
5256

53-
void destroyfd(FD *fd) {
57+
void destroyfd(FD *fd)
58+
{
5459
// g_array_free(fd->readbuf, TRUE); /* TODO? */
5560
g_array_free(fd->writebuf, TRUE);
5661
g_free(fd);
5762
}
5863

5964
/* FS calls */
6065

61-
static int fstruncate(const char *path, off_t size) {
66+
static int fstruncate(const char *path, off_t size)
67+
{
6268
return 0;
6369
}
6470

65-
static int fsrmdir(const char *path) {
71+
static int fsrmdir(const char *path)
72+
{
6673
if (strcmp(path, "/config") == 0) {
6774
g_hash_table_destroy(config);
6875
config = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free);
@@ -81,17 +88,17 @@ static int fsrmdir(const char *path) {
8188
ri = getri(path);
8289
if(ri) {
8390
if(ri->type == MUC) {
84-
partmuc(path, NULL, "TODO here must be default leave message :-)");
85-
g_hash_table_remove(roster, path);
86-
}
87-
else logstr("Roster items removal isn't implemented\n");; /* TODO */
91+
partmuc(path, NULL, "TODO here must be default leave message :-)");
92+
g_hash_table_remove(roster, path);
93+
} else logstr("Roster items removal isn't implemented\n");; /* TODO */
8894
return 0;
8995
} else return -ENOENT;
9096
}
9197
return -EPERM;
9298
}
9399

94-
static int fscreate(const char *path, mode_t mode, struct fuse_file_info *fi) {
100+
static int fscreate(const char *path, mode_t mode, struct fuse_file_info *fi)
101+
{
95102
/* TODO add roster items */
96103
if (strncmp(path, "/roster/", 8) == 0) {
97104
path += 8;
@@ -100,12 +107,14 @@ static int fscreate(const char *path, mode_t mode, struct fuse_file_info *fi) {
100107
return 0;
101108
}
102109

103-
static int fsmknod(const char *path, mode_t mode, dev_t type) {
110+
static int fsmknod(const char *path, mode_t mode, dev_t type)
111+
{
104112
/* TODO */
105113
return 0;
106114
}
107115

108-
static int fsmkdir(const char *path, mode_t mode) {
116+
static int fsmkdir(const char *path, mode_t mode)
117+
{
109118
if (strcmp(path, "/roster") == 0) {
110119
logstr("Make roster!\n");
111120
if(connection && lm_connection_is_open(connection)) {
@@ -135,7 +144,7 @@ static int fsgetattr(const char *path, struct stat *stbuf)
135144
return 0;
136145
}
137146
if (strcmp(path, "/log") == 0) {
138-
stbuf->st_mode = S_IFREG | 0666;
147+
stbuf->st_mode = S_IFREG | 0666;
139148
stbuf->st_nlink = 1;
140149
stbuf->st_size = LogBuf->len;
141150
return 0;
@@ -147,10 +156,10 @@ static int fsgetattr(const char *path, struct stat *stbuf)
147156
return 0;
148157
}
149158
if (strcmp(path, "/rawxmpp") == 0) {
150-
stbuf->st_mode = S_IFREG | 0222;
159+
stbuf->st_mode = S_IFREG | 0222;
151160
stbuf->st_nlink = 1;
152161
return 0;
153-
}
162+
}
154163
}
155164
if ((strcmp(path, "/config") == 0) ||
156165
(strcmp(path, "/") == 0)) {
@@ -187,7 +196,7 @@ static int fsgetattr(const char *path, struct stat *stbuf)
187196
}
188197

189198
static int fsreaddir(const char *path, void *buf, fuse_fill_dir_t filler,
190-
off_t offset, struct fuse_file_info *fi)
199+
off_t offset, struct fuse_file_info *fi)
191200
{
192201
(void) offset;
193202
(void) fi;
@@ -218,11 +227,10 @@ static int fsreaddir(const char *path, void *buf, fuse_fill_dir_t filler,
218227
filler(buf, "ssl", NULL, 0);
219228

220229
}
221-
if (strcmp(path, "/roster") == 0)
222-
{
230+
if (strcmp(path, "/roster") == 0) {
223231
filler(buf, ".", NULL, 0);
224232
filler(buf, "..", NULL, 0);
225-
233+
226234
GHashTableIter iter;
227235
rosteritem *ri;
228236
g_hash_table_iter_init (&iter, roster);
@@ -233,7 +241,7 @@ static int fsreaddir(const char *path, void *buf, fuse_fill_dir_t filler,
233241
if (strncmp(path, "/roster/", 8) == 0) {
234242
path += 8;
235243
rosteritem *ri;
236-
244+
237245
ri = getri(path);
238246
if (ri) {
239247
filler(buf, ".", NULL, 0);
@@ -244,7 +252,7 @@ static int fsreaddir(const char *path, void *buf, fuse_fill_dir_t filler,
244252
GHashTableIter iter;
245253
gchar *res;
246254
g_hash_table_iter_init (&iter, ri->resources);
247-
while (g_hash_table_iter_next(&iter, (gpointer) &res, NULL))
255+
while (g_hash_table_iter_next(&iter, (gpointer) &res, NULL))
248256
filler(buf, res, NULL, 0);
249257
}
250258
}
@@ -256,24 +264,25 @@ static int fsopen(const char *path, struct fuse_file_info *fi)
256264
{
257265
/* FDs are introduced only for writing ops */
258266
if ((fi->flags & O_WRONLY) || (fi->flags & O_RDWR)) {
259-
if (strncmp(path, "/roster/", 8) == 0) {
267+
if (strncmp(path, "/roster/", 8) == 0) {
260268
rosteritem *ri;
261269

262-
path += 8;
263-
ri = getri(path);
270+
path += 8;
271+
ri = getri(path);
264272
if (ri) {
265273
/* TODO */
266-
}
274+
}
267275
}
268276
}
269277
/* TODO */
270278
return 0;
271279
}
272280

273-
static char *get_option(const char *option) {
281+
static char *get_option(const char *option)
282+
{
274283
if (strcmp(option, "server") == 0) {
275284
const char *r = lm_connection_get_server(connection);
276-
if (r)
285+
if (r)
277286
return strdup(r);
278287
} else if (strcmp(option, "ssl") == 0) {
279288
if (ssl) {
@@ -301,7 +310,7 @@ static char *get_option(const char *option) {
301310
}
302311

303312
static int fsread(const char *path, char *buf, size_t size, off_t offset,
304-
struct fuse_file_info *fi)
313+
struct fuse_file_info *fi)
305314
{
306315
if (strcmp(path, "/log") == 0) {
307316
// write(fi->fh, LogBuf->data+offset, size);
@@ -362,23 +371,24 @@ static int fsread(const char *path, char *buf, size_t size, off_t offset,
362371
}
363372

364373
// FIXME fuse with set_option
365-
static char *prepare_option(const char *option, const char *buf, size_t size) {
374+
static char *prepare_option(const char *option, const char *buf, size_t size)
375+
{
366376
char *val;
367377

368378
// bool options
369379
if ((strcmp(option, "events") == 0) ||
370-
(strcmp(option, "raw_logs")== 0)) {
380+
(strcmp(option, "raw_logs")== 0)) {
371381
val = strdup("1"); // just something :)
372382
} else {
373383
val = filter_str(strndup(buf, size));
374-
384+
375385
bool pr;
376-
if (strcmp(option, "show") == 0 &&
377-
strcmp(val, "") &&
378-
strcmp(val, "away") &&
379-
strcmp(val, "chat") &&
380-
strcmp(val, "dnd") &&
381-
strcmp(val, "xa")) {
386+
if (strcmp(option, "show") == 0 &&
387+
strcmp(val, "") &&
388+
strcmp(val, "away") &&
389+
strcmp(val, "chat") &&
390+
strcmp(val, "dnd") &&
391+
strcmp(val, "xa")) {
382392
logf("Failed to set %s to incorrect value %s\n", option, val);
383393
return 0;
384394
} else if (strcmp(option, "ssl") == 0) {
@@ -392,7 +402,7 @@ static char *prepare_option(const char *option, const char *buf, size_t size) {
392402
return 0;
393403
}
394404
} else if ((pr = (strcmp(option, "priority") == 0)) ||
395-
((strcmp(option, "port") == 0))) {
405+
((strcmp(option, "port") == 0))) {
396406
/* Suggest a better way to validate the integer */
397407
char *not_ok;
398408
long long i = strtoll(val, &not_ok, 10);
@@ -417,7 +427,8 @@ static char *prepare_option(const char *option, const char *buf, size_t size) {
417427
return val;
418428
}
419429

420-
static void set_option(char *option, char *val) {
430+
static void set_option(char *option, char *val)
431+
{
421432
bool used = false;
422433

423434
// FIXME: in the case of ssl, the argument is not a string but a number
@@ -451,9 +462,9 @@ static void set_option(char *option, char *val) {
451462
used = true;
452463
}
453464
if (connection_state == ONLINE && (
454-
strcmp(option, "priority") == 0 ||
455-
strcmp(option, "show") == 0 ||
456-
strcmp(option, "status") == 0))
465+
strcmp(option, "priority") == 0 ||
466+
strcmp(option, "show") == 0 ||
467+
strcmp(option, "status") == 0))
457468
xmpp_send_presence();
458469
if (!used) {
459470
if (strcmp(option, "ssl")) {
@@ -478,7 +489,7 @@ static int fswrite(const char *path, const char *buf, size_t size, off_t offset,
478489
msg = g_malloc(msg_len + 1);
479490
memcpy(msg, buf, msg_len);
480491
msg[msg_len] = 0;
481-
if (res && (strncmp(res, "__nick", 6) == 0 ))
492+
if (res && (strncmp(res, "__nick", 6) == 0 ))
482493
xmpp_muc_change_nick(get_jid(path), msg);
483494
else
484495
xmpp_send(path, msg);
@@ -503,12 +514,14 @@ static int fswrite(const char *path, const char *buf, size_t size, off_t offset,
503514
return 0;
504515
}
505516

506-
static int fssetxattr(const char *path, const char *a, const char *aa, size_t size, int aaa) {
517+
static int fssetxattr(const char *path, const char *a, const char *aa, size_t size, int aaa)
518+
{
507519
/* Stub. Do we need this? */
508520
return 0;
509521
}
510522

511-
static int fsunlink(const char *path) {
523+
static int fsunlink(const char *path)
524+
{
512525
if (strncmp(path, "/roster/", 8) == 0) {
513526
path += 8;
514527
char *sl = strchr(path, '/');
@@ -532,8 +545,9 @@ static int fsunlink(const char *path) {
532545
return 0;
533546
}
534547

535-
static void fsdestroy(void *privdata) {
536-
if (connection)
548+
static void fsdestroy(void *privdata)
549+
{
550+
if (connection)
537551
xmpp_disconnect();
538552
free_all();
539553
if(main_loop) {
@@ -543,18 +557,21 @@ static void fsdestroy(void *privdata) {
543557
return;
544558
}
545559

546-
static void * mainloopthread(void *loop) {
560+
static void * mainloopthread(void *loop)
561+
{
547562
xmpp_connect();
548563
g_main_loop_run(main_loop);
549564
return NULL;
550565
}
551566

552-
static void * fsinit(struct fuse_conn_info *conn) {
567+
static void * fsinit(struct fuse_conn_info *conn)
568+
{
553569
FDt = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, (GDestroyNotify)destroyfd); //TODO check the cast
554570
return NULL;
555571
}
556572

557-
int fuseinit(int argc, char **argv) {
573+
int fuseinit(int argc, char **argv)
574+
{
558575
int ret;
559576
// fifo = open("fs/log", O_WRONLY | O_NONBLOCK);
560577
ret = fuse_main(argc, argv, &fuseoper, NULL);

0 commit comments

Comments
 (0)