Krolyxon
Commit 1449bfc

Branches

Refs →

nsxiv1449bfc

code-style: fix consistency issues all over the codebase (#94)

* remove duplicate comment
* remove empty tabs and blank lines
* move macros and globals ontop
* comment to seprate function implementation
* fix alignment
* switch to *argv[] similar to other suckless code
* kill all empty last lines
* append comment to endif
* reuse existing ARRLEN macro
* comment fall through
* use while (true) everywhere
Author
Berke Kocaoğlu
Date
2021-10-11 06:07 +0300
Committer
GitHub · 2021-10-11 09:07 +0600
Parent
675db4b
Commit
1449bfc5e960a61438c60a67c28da6d7c5bf2c7f

+45 −68

11 files changed

  1. M autoreload_inotify.c +6 −7
  2. M autoreload_nop.c +0 −1
  3. M commands.c +3 −5
  4. M commands.lst +0 −1
  5. M config.def.h +1 −1
  6. M image.c +2 −1
  7. M main.c +10 −8
  8. M nsxiv.h +0 −7
  9. M thumbs.c +2 −4
  10. M util.c +2 −3
  11. M window.c +19 −30
M autoreload_inotify.c View
@@ -24,6 +24,11 @@
2424 #include <unistd.h>
2525 #include <sys/inotify.h>
2626
27+union {
28+ char d[4096]; /* aligned buffer */
29+ struct inotify_event e;
30+} buf;
31+
2732 void arl_init(arl_t *arl)
2833 {
2934 arl->fd = inotify_init1(IN_CLOEXEC | IN_NONBLOCK);
@@ -76,18 +81,13 @@ void arl_setup(arl_t *arl, const char *filepath)
7681 }
7782 }
7883
79−union {
80− char d[4096]; /* aligned buffer */
81− struct inotify_event e;
82−} buf;
83−
8484 bool arl_handle(arl_t *arl)
8585 {
8686 bool reload = false;
8787 char *ptr;
8888 const struct inotify_event *e;
8989
90− for (;;) {
90+ while (true) {
9191 ssize_t len = read(arl->fd, buf.d, sizeof(buf.d));
9292
9393 if (len == -1) {
@@ -109,4 +109,3 @@ bool arl_handle(arl_t *arl)
109109 }
110110 return reload;
111111 }
112−
M autoreload_nop.c View
@@ -39,4 +39,3 @@ bool arl_handle(arl_t *arl)
3939 (void) arl;
4040 return false;
4141 }
42−
M commands.c View
@@ -233,7 +233,7 @@ bool cg_navigate_marked(arg_t n)
233233 {
234234 int d, i;
235235 int new = fileidx;
236−
236+
237237 if (prefix > 0)
238238 n *= prefix;
239239 d = n > 0 ? 1 : -1;
@@ -337,14 +337,13 @@ bool ci_drag(arg_t mode)
337337
338338 if ((int)(img.w * img.zoom) <= win.w && (int)(img.h * img.zoom) <= win.h)
339339 return false;
340−
341− win_set_cursor(&win, CURSOR_DRAG);
342340
341+ win_set_cursor(&win, CURSOR_DRAG);
343342 win_cursor_pos(&win, &x, &y);
344343 ox = x;
345344 oy = y;
346345
347− for (;;) {
346+ while (true) {
348347 if (mode == DRAG_ABSOLUTE) {
349348 px = MIN(MAX(0.0, x - win.w*0.1), win.w*0.8) / (win.w*0.8)
350349 * (win.w - img.w * img.zoom);
@@ -449,4 +448,3 @@ bool ct_reload_all(arg_t _)
449448 const cmd_t cmds[CMD_COUNT] = {
450449 #include "commands.lst"
451450 };
452−
M commands.lst View
@@ -34,4 +34,3 @@ I_CMD(slideshow)
3434
3535 T_CMD(move_sel)
3636 T_CMD(reload_all)
37−
M config.def.h View
@@ -63,7 +63,7 @@ static const int THUMB_SIZE = 3;
6363 #endif
6464 #ifdef _MAPPINGS_CONFIG
6565
66−/* Following modifiers (NumLock | CapsLock) will be ignored when processing keybindings */
66+/* following modifiers (NumLock | CapsLock) will be ignored when processing keybindings */
6767 static const int ignore_mask = Mod2Mask | LockMask;
6868
6969 /* abort the keyhandler */
M image.c View
@@ -89,6 +89,7 @@ void exif_auto_orientate(const fileinfo_t *file)
8989 switch (orientation) {
9090 case 5:
9191 imlib_image_orientate(1);
92+ /* fall through */
9293 case 2:
9394 imlib_image_flip_vertical();
9495 break;
@@ -97,6 +98,7 @@ void exif_auto_orientate(const fileinfo_t *file)
9798 break;
9899 case 7:
99100 imlib_image_orientate(1);
101+ /* fall through */
100102 case 4:
101103 imlib_image_flip_horizontal();
102104 break;
@@ -916,4 +918,3 @@ bool img_frame_animate(img_t *img)
916918 img->dirty = true;
917919 return true;
918920 }
919−
M main.c View
@@ -34,6 +34,9 @@
3434 #include <X11/keysym.h>
3535 #include <X11/XF86keysym.h>
3636
37+#define MODMASK(mask) ((mask) & ~ignore_mask)
38+#define BAR_SEP " "
39+
3740 typedef struct {
3841 struct timeval when;
3942 bool active;
@@ -93,6 +96,9 @@ cursor_t imgcursor[3] = {
9396 CURSOR_ARROW, CURSOR_ARROW, CURSOR_ARROW
9497 };
9598
99+/**************************
100+ function implementations
101+ **************************/
96102 void cleanup(void)
97103 {
98104 img_close(&img, false);
@@ -346,8 +352,6 @@ void bar_put(win_bar_t *bar, const char *fmt, ...)
346352 va_end(ap);
347353 }
348354
349−#define BAR_SEP " "
350−
351355 void update_info(void)
352356 {
353357 unsigned int i, fn, fw;
@@ -554,7 +558,7 @@ void run_key_handler(const char *key, unsigned int mask)
554558 for (f = i = 0; f < fcnt; i++) {
555559 if ((marked && (files[i].flags & FF_MARK)) || (!marked && i == fileidx)) {
556560 if (stat(files[i].path, &st) != 0 ||
557− memcmp(&oldst[f].st_mtime, &st.st_mtime, sizeof(st.st_mtime)) != 0)
561+ memcmp(&oldst[f].st_mtime, &st.st_mtime, sizeof(st.st_mtime)) != 0)
558562 {
559563 if (tns.thumbs != NULL) {
560564 tns_unload(&tns, i);
@@ -582,8 +586,6 @@ end:
582586 redraw();
583587 }
584588
585−#define MODMASK(mask) ((mask) & ~ignore_mask)
586−
587589 void on_keypress(XKeyEvent *kev)
588590 {
589591 int i;
@@ -607,7 +609,7 @@ void on_keypress(XKeyEvent *kev)
607609 handle_key_handler(false);
608610 } else if (extprefix) {
609611 run_key_handler(XKeysymToString(ksym), kev->state & ~sh);
610− extprefix = False;
612+ extprefix = false;
611613 } else if (key >= '0' && key <= '9') {
612614 /* number prefix for commands */
613615 prefix = prefix * 10 + (int) (key - '0');
@@ -675,7 +677,7 @@ void on_buttonpress(XButtonEvent *bev)
675677 bool on = !(files[sel].flags & FF_MARK);
676678 XEvent e;
677679
678− for (;;) {
680+ while (true) {
679681 if (sel >= 0 && mark_image(sel, on))
680682 redraw();
681683 XMaskEvent(win.env.dpy,
@@ -836,7 +838,7 @@ void setup_signal(int sig, void (*handler)(int sig))
836838 error(EXIT_FAILURE, errno, "signal %d", sig);
837839 }
838840
839−int main(int argc, char **argv)
841+int main(int argc, char *argv[])
840842 {
841843 int i, start;
842844 size_t n;
M nsxiv.h View
@@ -33,15 +33,9 @@
3333 */
3434 #define CLEANUP
3535
36−#ifndef MIN
3736 #define MIN(a,b) ((a) < (b) ? (a) : (b))
38−#endif
39−#ifndef MAX
4037 #define MAX(a,b) ((a) > (b) ? (a) : (b))
41−#endif
42−#ifndef ABS
4338 #define ABS(a) ((a) > 0 ? (a) : -(a))
44−#endif
4539
4640 #define ARRLEN(a) (sizeof(a) / sizeof((a)[0]))
4741
@@ -465,4 +459,3 @@ void win_set_cursor(win_t*, cursor_t);
465459 void win_cursor_pos(win_t*, int*, int*);
466460
467461 #endif /* NSXIV_H */
468−
M thumbs.c View
@@ -143,9 +143,7 @@ void tns_clean_cache(tns_t *tns)
143143 r_closedir(&dir);
144144 }
145145
146−
147−void tns_init(tns_t *tns, fileinfo_t *files, const int *cnt, int *sel,
148− win_t *win)
146+void tns_init(tns_t *tns, fileinfo_t *files, const int *cnt, int *sel, win_t *win)
149147 {
150148 int len;
151149 const char *homedir, *dsuffix = "";
@@ -320,7 +318,7 @@ bool tns_load(tns_t *tns, int n, bool force, bool cache_only)
320318 }
321319 exif_data_unref(ed);
322320 }
323−#endif
321+#endif /* HAVE_LIBEXIF */
324322 }
325323 }
326324
M util.c View
@@ -30,7 +30,7 @@ const char *progname;
3030 void* emalloc(size_t size)
3131 {
3232 void *ptr;
33−
33+
3434 ptr = malloc(size);
3535 if (ptr == NULL)
3636 error(EXIT_FAILURE, errno, NULL);
@@ -172,7 +172,7 @@ char* r_readdir(r_dir_t *rdir, bool skip_dotfiles)
172172 }
173173 return filename;
174174 }
175−
175+
176176 if (rdir->recursive && rdir->stlen > 0) {
177177 /* open next subdirectory */
178178 closedir(rdir->dir);
@@ -210,4 +210,3 @@ int r_mkdir(char *path)
210210 }
211211 return 0;
212212 }
213−
M window.c View
@@ -33,10 +33,15 @@
3333 #include "utf8.h"
3434 static XftFont *font;
3535 static double fontsize;
36+#define TEXTWIDTH(win, text, len) \
37+ win_draw_text(win, NULL, NULL, 0, 0, text, len, 0)
3638 #endif
3739
3840 #define RES_CLASS "Nsxiv"
3941
42+#define INIT_ATOM_(atom) \
43+ atoms[ATOM_##atom] = XInternAtom(e->dpy, #atom, False);
44+
4045 enum {
4146 H_TEXT_PAD = 5,
4247 V_TEXT_PAD = 1
@@ -98,9 +103,6 @@ const char* win_res(XrmDatabase db, const char *name, const char *def)
98103 }
99104 }
100105
101−#define INIT_ATOM_(atom) \
102− atoms[ATOM_##atom] = XInternAtom(e->dpy, #atom, False);
103−
104106 void win_init(win_t *win)
105107 {
106108 win_env_t *e;
@@ -194,7 +196,7 @@ void win_open(win_t *win)
194196 XSizeHints sizehints;
195197 XWMHints hints;
196198 pid_t pid;
197− char hostname[255];
199+ char hostname[256];
198200
199201 e = &win->env;
200202 parent = options->embed != 0 ? options->embed : RootWindow(e->dpy, e->scr);
@@ -229,30 +231,26 @@ void win_open(win_t *win)
229231 if ((gmask & YNegative) != 0) {
230232 win->y += e->scrh - win->h;
231233 sizehints.win_gravity = sizehints.win_gravity == NorthEastGravity
232− ? SouthEastGravity : SouthWestGravity;
234+ ? SouthEastGravity : SouthWestGravity;
233235 }
234236 sizehints.flags |= USPosition;
235237 } else {
236238 win->y = 0;
237239 }
238240
239− win->xwin = XCreateWindow(e->dpy, parent,
240− win->x, win->y, win->w, win->h, 0,
241+ win->xwin = XCreateWindow(e->dpy, parent, win->x, win->y, win->w, win->h, 0,
241242 e->depth, InputOutput, e->vis, 0, NULL);
242243 if (win->xwin == None)
243244 error(EXIT_FAILURE, 0, "Error creating X window");
244245
245246 /* set the _NET_WM_PID */
246247 pid = getpid();
247− XChangeProperty(e->dpy, win->xwin,
248− atoms[ATOM__NET_WM_PID], XA_CARDINAL, sizeof(pid_t) * 8,
249− PropModeReplace, (unsigned char *) &pid, 1);
250−
251− /* set the _NET_WM_PID */
252− if (gethostname(hostname, sizeof(hostname)) == 0) {
248+ XChangeProperty(e->dpy, win->xwin, atoms[ATOM__NET_WM_PID], XA_CARDINAL,
249+ sizeof(pid_t) * 8, PropModeReplace, (unsigned char *) &pid, 1);
250+ if (gethostname(hostname, ARRLEN(hostname)) == 0) {
253251 XTextProperty tp;
254252 tp.value = (unsigned char *)hostname;
255− tp.nitems = strnlen(hostname, sizeof(hostname));
253+ tp.nitems = strnlen(hostname, ARRLEN(hostname));
256254 tp.encoding = XA_STRING;
257255 tp.format = 8;
258256 XSetWMClientMachine(e->dpy, win->xwin, &tp);
@@ -266,11 +264,9 @@ void win_open(win_t *win)
266264 if (i != CURSOR_NONE)
267265 cursors[i].icon = XCreateFontCursor(e->dpy, cursors[i].name);
268266 }
269− if (XAllocNamedColor(e->dpy, e->cmap, "black",
270− &col, &col) == 0)
271− {
267+ if (XAllocNamedColor(e->dpy, e->cmap, "black", &col, &col) == 0)
272268 error(EXIT_FAILURE, 0, "Error allocating color 'black'");
273− }
269+
274270 none = XCreateBitmapFromData(e->dpy, win->xwin, none_data, 8, 8);
275271 *cnone = XCreatePixmapCursor(e->dpy, none, none, &col, &col, 0, 0);
276272
@@ -288,8 +284,7 @@ void win_open(win_t *win)
288284 for (c = icons[i].data[j] >> 4; c >= 0; c--)
289285 icon_data[n++] = icon_colors[icons[i].data[j] & 0x0F];
290286 }
291− XChangeProperty(e->dpy, win->xwin,
292− atoms[ATOM__NET_WM_ICON], XA_CARDINAL, 32,
287+ XChangeProperty(e->dpy, win->xwin, atoms[ATOM__NET_WM_ICON], XA_CARDINAL, 32,
293288 i == 0 ? PropModeReplace : PropModeAppend,
294289 (unsigned char *) icon_data, n);
295290 }
@@ -320,12 +315,11 @@ void win_open(win_t *win)
320315
321316 win->buf.w = e->scrw;
322317 win->buf.h = e->scrh;
323− win->buf.pm = XCreatePixmap(e->dpy, win->xwin,
324− win->buf.w, win->buf.h, e->depth);
318+ win->buf.pm = XCreatePixmap(e->dpy, win->xwin, win->buf.w, win->buf.h, e->depth);
319+
325320 XSetForeground(e->dpy, gc, win->win_bg);
326321 XFillRectangle(e->dpy, win->buf.pm, gc, 0, 0, win->buf.w, win->buf.h);
327322 XSetWindowBackgroundPixmap(e->dpy, win->xwin, win->buf.pm);
328−
329323 XMapWindow(e->dpy, win->xwin);
330324 XFlush(e->dpy);
331325
@@ -409,9 +403,6 @@ void win_clear(win_t *win)
409403 }
410404
411405 #if HAVE_LIBFONTS
412−#define TEXTWIDTH(win, text, len) \
413− win_draw_text(win, NULL, NULL, 0, 0, text, len, 0)
414−
415406 int win_draw_text(win_t *win, XftDraw *d, const XftColor *color, int x, int y,
416407 char *text, int len, int w)
417408 {
@@ -459,8 +450,7 @@ void win_draw_bar(win_t *win)
459450 e = &win->env;
460451 y = win->h + font->ascent + V_TEXT_PAD;
461452 w = win->w - 2*H_TEXT_PAD;
462− d = XftDrawCreate(e->dpy, win->buf.pm, e->vis,
463− e->cmap);
453+ d = XftDrawCreate(e->dpy, win->buf.pm, e->vis, e->cmap);
464454
465455 XSetForeground(e->dpy, gc, win->bar_bg.pixel);
466456 XFillRectangle(e->dpy, win->buf.pm, gc, 0, win->h, win->w, win->bar.h);
@@ -522,7 +512,7 @@ void win_set_title(win_t *win, const char *path)
522512 return;
523513
524514 snprintf(title, title_max, "%s%s", options->title_prefix,
525− (options->title_suffixmode == SUFFIX_BASENAME) ? basename : path);
515+ options->title_suffixmode == SUFFIX_BASENAME ? basename : path);
526516 if (options->title_suffixmode == SUFFIX_EMPTY)
527517 *(title+strlen(options->title_prefix)) = '\0';
528518
@@ -551,4 +541,3 @@ void win_cursor_pos(win_t *win, int *x, int *y)
551541 if (!XQueryPointer(win->env.dpy, win->xwin, &w, &w, &i, &i, x, y, &ui))
552542 *x = *y = 0;
553543 }
554−