Krolyxon
Commit 8dcf682

Branches

Refs →

nsxiv8dcf682

Made all conditionals more precise

Author
Bert Münnich
Date
2011-09-29 12:43 +0200
Parent
22d4e99
Commit
8dcf682de9dc9bf5fe4a98205acfa2835499baf2

+236 −234

8 files changed

  1. M commands.c +9 −15
  2. M config.c +4 −3
  3. M image.c +31 −29
  4. M main.c +56 −52
  5. M options.c +2 −2
  6. M thumbs.c +61 −62
  7. M util.c +47 −45
  8. M window.c +26 −26
M commands.c View
@@ -53,7 +53,7 @@ bool it_quit(arg_t a) {
5353
5454 bool it_switch_mode(arg_t a) {
5555 if (mode == MODE_IMAGE) {
56− if (!tns.thumbs)
56+ if (tns.thumbs == NULL)
5757 tns_init(&tns, filecnt, &win);
5858 img_close(&img, false);
5959 reset_timeout(reset_cursor);
@@ -273,21 +273,19 @@ bool i_zoom(arg_t a) {
273273 }
274274
275275 bool i_fit_to_win(arg_t a) {
276− bool ret;
276+ bool ret = false;
277277
278278 if (mode == MODE_IMAGE) {
279279 if ((ret = img_fit_win(&img)))
280280 img_center(&img);
281− return ret;
282− } else {
283− return false;
284281 }
282+ return ret;
285283 }
286284
287285 bool i_fit_to_img(arg_t a) {
288286 int x, y;
289287 unsigned int w, h;
290− bool ret;
288+ bool ret = false;
291289
292290 if (mode == MODE_IMAGE) {
293291 x = MAX(0, win.x + img.x);
@@ -298,10 +296,8 @@ bool i_fit_to_img(arg_t a) {
298296 img.x = x - win.x;
299297 img.y = y - win.y;
300298 }
301− return ret;
302− } else {
303− return false;
304299 }
300+ return ret;
305301 }
306302
307303 bool i_rotate(arg_t a) {
@@ -381,7 +377,7 @@ bool it_open_with(arg_t a) {
381377 const char *prog = (const char*) a;
382378 pid_t pid;
383379
384− if (!prog || !*prog)
380+ if (prog == NULL || *prog == '\0')
385381 return false;
386382
387383 if ((pid = fork()) == 0) {
@@ -392,7 +388,6 @@ bool it_open_with(arg_t a) {
392388 } else if (pid < 0) {
393389 warn("could not fork. program was: %s", prog);
394390 }
395−
396391 return false;
397392 }
398393
@@ -401,8 +396,8 @@ bool it_shell_cmd(arg_t a) {
401396 const char *cmdline = (const char*) a;
402397 pid_t pid;
403398
404− if (!cmdline || !*cmdline)
405− return 0;
399+ if (cmdline == NULL || *cmdline == '\0')
400+ return false;
406401
407402 n = mode == MODE_IMAGE ? fileidx : tns.sel;
408403
@@ -424,7 +419,7 @@ bool it_shell_cmd(arg_t a) {
424419 win_set_cursor(&win, CURSOR_WATCH);
425420
426421 waitpid(pid, &status, 0);
427− if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
422+ if (WIFEXITED(status) == 0 || WEXITSTATUS(status) != 0)
428423 warn("child exited with non-zero return value: %d. command line was: %s",
429424 WEXITSTATUS(status), cmdline);
430425
@@ -440,6 +435,5 @@ bool it_shell_cmd(arg_t a) {
440435 if (tns.sel >= tns.cnt)
441436 tns.sel = tns.cnt - 1;
442437 }
443−
444438 return true;
445439 }
M config.c View
@@ -14,10 +14,11 @@ inline int puts_if(const char *s, int c) {
1414 }
1515
1616 int main(int argc, char **argv) {
17− int i, n = 0;
17+ int i;
18+ unsigned int n = 0;
1819
1920 for (i = 1; i < argc; i++) {
20− switch (argv[i][0] != '-' || argv[i][2] ? -1 : argv[i][1]) {
21+ switch ((argv[i][0] != '-' || argv[i][2] != '\0') ? -1 : argv[i][1]) {
2122 case 'D':
2223 n += PUT_MACRO(EXIF_SUPPORT);
2324 n += PUT_MACRO(GIF_SUPPORT);
@@ -31,7 +32,7 @@ int main(int argc, char **argv) {
3132 return 1;
3233 }
3334 }
34− if (n)
35+ if (n > 0)
3536 printf("\n");
3637 return 0;
3738 }
M image.c View
@@ -49,7 +49,7 @@ void img_init(img_t *img, win_t *win) {
4949 zoom_min = zoom_levels[0] / 100.0;
5050 zoom_max = zoom_levels[ARRLEN(zoom_levels) - 1] / 100.0;
5151
52− if (!img || !win)
52+ if (img == NULL || win == NULL)
5353 return;
5454
5555 imlib_context_set_display(win->env.dpy);
@@ -77,15 +77,15 @@ void exif_auto_orientate(const fileinfo_t *file) {
7777 ExifEntry *entry;
7878 int byte_order, orientation;
7979
80− if (!(ed = exif_data_new_from_file(file->path)))
80+ if ((ed = exif_data_new_from_file(file->path)) == NULL)
8181 return;
8282 entry = exif_content_get_entry(ed->ifd[EXIF_IFD_0], EXIF_TAG_ORIENTATION);
83− if (entry) {
83+ if (entry != NULL) {
8484 byte_order = exif_data_get_byte_order(ed);
8585 orientation = exif_get_short(entry->data, byte_order);
8686 }
8787 exif_data_unref(ed);
88− if (!entry)
88+ if (entry == NULL)
8989 return;
9090
9191 switch (orientation) {
@@ -145,7 +145,7 @@ bool img_load_gif(img_t *img, const fileinfo_t *file) {
145145 img->multi.sel = 0;
146146
147147 gif = DGifOpenFileName(file->path);
148− if (!gif) {
148+ if (gif == NULL) {
149149 warn("could not open gif file: %s", file->name);
150150 return false;
151151 }
@@ -215,7 +215,7 @@ bool img_load_gif(img_t *img, const fileinfo_t *file) {
215215 if (i < y || i >= y + h || j < x || j >= x + w ||
216216 rows[i-y][j-x] == transp)
217217 {
218− if (prev_frame)
218+ if (prev_frame != NULL)
219219 *ptr = prev_frame[i * sw + j];
220220 else
221221 *ptr = bgpixel;
@@ -236,7 +236,7 @@ bool img_load_gif(img_t *img, const fileinfo_t *file) {
236236 free(rows);
237237 free(data);
238238
239− if (!im) {
239+ if (im == NULL) {
240240 err = true;
241241 break;
242242 }
@@ -286,10 +286,12 @@ bool img_load_gif(img_t *img, const fileinfo_t *file) {
286286 bool img_load(img_t *img, const fileinfo_t *file) {
287287 const char *fmt;
288288
289− if (!img || !file || !file->name || !file->path)
289+ if (img == NULL || file == NULL || file->name == NULL || file->path == NULL)
290290 return false;
291291
292− if (access(file->path, R_OK) || !(img->im = imlib_load_image(file->path))) {
292+ if (access(file->path, R_OK) < 0 ||
293+ (img->im = imlib_load_image(file->path)) == NULL)
294+ {
293295 warn("could not open image: %s", file->name);
294296 return false;
295297 }
@@ -324,17 +326,17 @@ bool img_load(img_t *img, const fileinfo_t *file) {
324326 void img_close(img_t *img, bool decache) {
325327 int i;
326328
327− if (!img)
329+ if (img == NULL)
328330 return;
329331
330− if (img->multi.cnt) {
332+ if (img->multi.cnt > 0) {
331333 for (i = 0; i < img->multi.cnt; i++) {
332334 imlib_context_set_image(img->multi.frames[i].im);
333335 imlib_free_image();
334336 }
335337 img->multi.cnt = 0;
336338 img->im = NULL;
337− } else if (img->im) {
339+ } else if (img->im != NULL) {
338340 imlib_context_set_image(img->im);
339341 if (decache)
340342 imlib_free_image_and_decache();
@@ -348,7 +350,7 @@ void img_check_pan(img_t *img, bool moved) {
348350 win_t *win;
349351 int ox, oy;
350352
351− if (!img || !img->im || !img->win)
353+ if (img == NULL || img->im == NULL || img->win == NULL)
352354 return;
353355
354356 win = img->win;
@@ -379,7 +381,7 @@ void img_check_pan(img_t *img, bool moved) {
379381 bool img_fit(img_t *img) {
380382 float z, zmax, zw, zh;
381383
382− if (!img || !img->im || !img->win)
384+ if (img == NULL || img->im == NULL || img->win == NULL)
383385 return false;
384386 if (img->scalemode == SCALE_ZOOM)
385387 return false;
@@ -406,7 +408,7 @@ void img_render(img_t *img) {
406408 int sx, sy, sw, sh;
407409 int dx, dy, dw, dh;
408410
409− if (!img || !img->im || !img->win)
411+ if (img == NULL || img->im == NULL || img->win == NULL)
410412 return;
411413
412414 win = img->win;
@@ -461,7 +463,7 @@ void img_render(img_t *img) {
461463
462464 imlib_context_set_image(img->im);
463465
464− if (imlib_image_has_alpha() && !img->alpha)
466+ if (!img->alpha && imlib_image_has_alpha())
465467 win_draw_rect(win, win->pm, dx, dy, dw, dh, True, 0, win->white);
466468
467469 imlib_context_set_drawable(win->pm);
@@ -473,7 +475,7 @@ void img_render(img_t *img) {
473475 }
474476
475477 bool img_fit_win(img_t *img) {
476− if (!img || !img->im)
478+ if (img == NULL || img->im == NULL)
477479 return false;
478480
479481 img->scalemode = SCALE_FIT;
@@ -483,7 +485,7 @@ bool img_fit_win(img_t *img) {
483485 bool img_center(img_t *img) {
484486 int ox, oy;
485487
486− if (!img || !img->im || !img->win)
488+ if (img == NULL || img->im == NULL || img->win == NULL)
487489 return false;
488490
489491 ox = img->x;
@@ -501,7 +503,7 @@ bool img_center(img_t *img) {
501503 }
502504
503505 bool img_zoom(img_t *img, float z) {
504− if (!img || !img->im || !img->win)
506+ if (img == NULL || img->im == NULL || img->win == NULL)
505507 return false;
506508
507509 z = MAX(z, zoom_min);
@@ -524,7 +526,7 @@ bool img_zoom(img_t *img, float z) {
524526 bool img_zoom_in(img_t *img) {
525527 int i;
526528
527− if (!img || !img->im)
529+ if (img == NULL || img->im == NULL)
528530 return false;
529531
530532 for (i = 1; i < ARRLEN(zoom_levels); i++) {
@@ -537,7 +539,7 @@ bool img_zoom_in(img_t *img) {
537539 bool img_zoom_out(img_t *img) {
538540 int i;
539541
540− if (!img || !img->im)
542+ if (img == NULL || img->im == NULL)
541543 return false;
542544
543545 for (i = ARRLEN(zoom_levels) - 2; i >= 0; i--) {
@@ -550,7 +552,7 @@ bool img_zoom_out(img_t *img) {
550552 bool img_move(img_t *img, int dx, int dy) {
551553 int ox, oy;
552554
553− if (!img || !img->im)
555+ if (img == NULL || img->im == NULL)
554556 return false;
555557
556558 ox = img->x;
@@ -570,7 +572,7 @@ bool img_move(img_t *img, int dx, int dy) {
570572 }
571573
572574 bool img_pan(img_t *img, direction_t dir, bool screen) {
573− if (!img || !img->im || !img->win)
575+ if (img == NULL || img->im == NULL || img->win == NULL)
574576 return false;
575577
576578 switch (dir) {
@@ -589,7 +591,7 @@ bool img_pan(img_t *img, direction_t dir, bool screen) {
589591 bool img_pan_edge(img_t *img, direction_t dir) {
590592 int ox, oy;
591593
592− if (!img || !img->im || !img->win)
594+ if (img == NULL || img->im == NULL || img->win == NULL)
593595 return false;
594596
595597 ox = img->x;
@@ -624,7 +626,7 @@ void img_rotate(img_t *img, int d) {
624626 win_t *win;
625627 int ox, oy, tmp;
626628
627− if (!img || !img->im || !img->win)
629+ if (img == NULL || img->im == NULL || img->win == NULL)
628630 return;
629631
630632 win = img->win;
@@ -654,7 +656,7 @@ void img_rotate_right(img_t *img) {
654656 }
655657
656658 void img_toggle_antialias(img_t *img) {
657− if (!img || !img->im)
659+ if (img == NULL || img->im == NULL)
658660 return;
659661
660662 img->aa = !img->aa;
@@ -664,7 +666,7 @@ void img_toggle_antialias(img_t *img) {
664666 }
665667
666668 bool img_frame_goto(img_t *img, int n) {
667− if (!img || !img->im)
669+ if (img == NULL || img->im == NULL)
668670 return false;
669671 if (n < 0 || n >= img->multi.cnt || n == img->multi.sel)
670672 return false;
@@ -682,7 +684,7 @@ bool img_frame_goto(img_t *img, int n) {
682684 }
683685
684686 bool img_frame_navigate(img_t *img, int d) {
685− if (!img || !img->im || !img->multi.cnt || !d)
687+ if (img == NULL|| img->im == NULL || img->multi.cnt == 0 || d == 0)
686688 return false;
687689
688690 d += img->multi.sel;
@@ -695,7 +697,7 @@ bool img_frame_navigate(img_t *img, int d) {
695697 }
696698
697699 bool img_frame_animate(img_t *img, bool restart) {
698− if (!img || !img->im || !img->multi.cnt)
700+ if (img == NULL || img->im == NULL || img->multi.cnt == 0)
699701 return false;
700702
701703 if (img->multi.sel + 1 >= img->multi.cnt) {
M main.c View
@@ -73,9 +73,10 @@ timeout_t timeouts[] = {
7373 };
7474
7575 void cleanup() {
76− static int in = 0;
76+ static bool in = false;
7777
78− if (!in++) {
78+ if (!in) {
79+ in = true;
7980 img_close(&img, false);
8081 tns_free(&tns);
8182 win_close(&win);
@@ -83,10 +84,10 @@ void cleanup() {
8384 }
8485
8586 void check_add_file(char *filename) {
86− if (!filename || !*filename)
87+ if (filename == NULL || *filename == '\0')
8788 return;
8889
89− if (access(filename, R_OK)) {
90+ if (access(filename, R_OK) < 0) {
9091 warn("could not open file: %s", filename);
9192 return;
9293 }
@@ -97,7 +98,7 @@ void check_add_file(char *filename) {
9798 }
9899 if (*filename != '/') {
99100 files[fileidx].path = absolute_path(filename);
100− if (!files[fileidx].path) {
101+ if (files[fileidx].path == NULL) {
101102 warn("could not get absolute path of file: %s\n", filename);
102103 return;
103104 }
@@ -173,7 +174,7 @@ bool check_timeouts(struct timeval *t) {
173174 tdiff = tv_diff(&timeouts[i].when, &now);
174175 if (tdiff <= 0) {
175176 timeouts[i].active = false;
176− if (timeouts[i].handler)
177+ if (timeouts[i].handler != NULL)
177178 timeouts[i].handler();
178179 i = tmin = -1;
179180 } else if (tmin < 0 || tdiff < tmin) {
@@ -182,7 +183,7 @@ bool check_timeouts(struct timeval *t) {
182183 }
183184 i++;
184185 }
185− if (tmin > 0 && t)
186+ if (tmin > 0 && t != NULL)
186187 tv_set_msec(t, tmin);
187188 return tmin > 0;
188189 }
@@ -204,12 +205,12 @@ void load_image(int new) {
204205
205206 files[new].loaded = true;
206207 fileidx = new;
207− if (!stat(files[new].path, &fstats))
208+ if (stat(files[new].path, &fstats) == 0)
208209 filesize = fstats.st_size;
209210 else
210211 filesize = 0;
211212
212− if (img.multi.cnt && img.multi.animate)
213+ if (img.multi.cnt > 0 && img.multi.animate)
213214 set_timeout(animate, img.multi.frames[img.multi.sel].delay, true);
214215 else
215216 reset_timeout(animate);
@@ -238,7 +239,7 @@ void update_title() {
238239 } else {
239240 sshow_info[0] = '\0';
240241 }
241− if (img.multi.cnt)
242+ if (img.multi.cnt > 0)
242243 snprintf(frame_info, sizeof(frame_info), "{%d/%d} ",
243244 img.multi.sel + 1, img.multi.cnt);
244245 else
@@ -329,14 +330,14 @@ void on_keypress(XKeyEvent *kev) {
329330 KeySym ksym;
330331 char key;
331332
332− if (!kev)
333+ if (kev == NULL)
333334 return;
334335
335336 XLookupString(kev, &key, 1, &ksym, NULL);
336337
337338 for (i = 0; i < ARRLEN(keys); i++) {
338339 if (keys[i].ksym == ksym && keymask(&keys[i], kev->state)) {
339− if (keys[i].cmd && keys[i].cmd(keys[i].arg))
340+ if (keys[i].cmd != NULL && keys[i].cmd(keys[i].arg))
340341 redraw();
341342 return;
342343 }
@@ -346,7 +347,7 @@ void on_keypress(XKeyEvent *kev) {
346347 void on_buttonpress(XButtonEvent *bev) {
347348 int i, sel;
348349
349− if (!bev)
350+ if (bev == NULL)
350351 return;
351352
352353 if (mode == MODE_IMAGE) {
@@ -357,7 +358,7 @@ void on_buttonpress(XButtonEvent *bev) {
357358 if (buttons[i].button == bev->button &&
358359 buttonmask(&buttons[i], bev->state))
359360 {
360− if (buttons[i].cmd && buttons[i].cmd(buttons[i].arg))
361+ if (buttons[i].cmd != NULL && buttons[i].cmd(buttons[i].arg))
361362 redraw();
362363 return;
363364 }
@@ -397,9 +398,9 @@ void run() {
397398
398399 redraw();
399400
400− while (1) {
401+ while (true) {
401402 while (mode == MODE_THUMB && tns.cnt < filecnt &&
402− !XPending(win.env.dpy))
403+ XPending(win.env.dpy) == 0)
403404 {
404405 /* load thumbnails */
405406 set_timeout(redraw, TO_REDRAW_THUMBS, false);
@@ -413,7 +414,7 @@ void run() {
413414 check_timeouts(NULL);
414415 }
415416
416− while (!XPending(win.env.dpy) && check_timeouts(&timeout)) {
417+ while (XPending(win.env.dpy) == 0 && check_timeouts(&timeout)) {
417418 /* wait for timeouts */
418419 xfd = ConnectionNumber(win.env.dpy);
419420 FD_ZERO(&fds);
@@ -421,35 +422,34 @@ void run() {
421422 select(xfd + 1, &fds, 0, 0, &timeout);
422423 }
423424
424− if (!XNextEvent(win.env.dpy, &ev)) {
425+ XNextEvent(win.env.dpy, &ev);
426+ switch (ev.type) {
425427 /* handle events */
426− switch (ev.type) {
427− case ButtonPress:
428− on_buttonpress(&ev.xbutton);
429− break;
430− case ClientMessage:
431− if ((Atom) ev.xclient.data.l[0] == wm_delete_win)
432− return;
433− break;
434− case ConfigureNotify:
435− if (win_configure(&win, &ev.xconfigure)) {
436− set_timeout(redraw, TO_REDRAW_RESIZE, false);
437− if (mode == MODE_IMAGE)
438− img.checkpan = true;
439− else
440− tns.dirty = true;
441− }
442− break;
443− case KeyPress:
444− on_keypress(&ev.xkey);
445− break;
446− case MotionNotify:
447− if (mode == MODE_IMAGE) {
448− win_set_cursor(&win, CURSOR_ARROW);
449− set_timeout(reset_cursor, TO_CURSOR_HIDE, true);
450− }
451− break;
452− }
428+ case ButtonPress:
429+ on_buttonpress(&ev.xbutton);
430+ break;
431+ case ClientMessage:
432+ if ((Atom) ev.xclient.data.l[0] == wm_delete_win)
433+ return;
434+ break;
435+ case ConfigureNotify:
436+ if (win_configure(&win, &ev.xconfigure)) {
437+ set_timeout(redraw, TO_REDRAW_RESIZE, false);
438+ if (mode == MODE_IMAGE)
439+ img.checkpan = true;
440+ else
441+ tns.dirty = true;
442+ }
443+ break;
444+ case KeyPress:
445+ on_keypress(&ev.xkey);
446+ break;
447+ case MotionNotify:
448+ if (mode == MODE_IMAGE) {
449+ win_set_cursor(&win, CURSOR_ARROW);
450+ set_timeout(reset_cursor, TO_CURSOR_HIDE, true);
451+ }
452+ break;
453453 }
454454 }
455455 }
@@ -474,7 +474,7 @@ int main(int argc, char **argv) {
474474 exit(EXIT_SUCCESS);
475475 }
476476
477− if (!options->filecnt) {
477+ if (options->filecnt == 0) {
478478 print_usage();
479479 exit(EXIT_FAILURE);
480480 }
@@ -495,25 +495,29 @@ int main(int argc, char **argv) {
495495 filename[len-1] = '\0';
496496 check_add_file(filename);
497497 }
498− if (filename)
498+ if (filename != NULL)
499499 free(filename);
500500 } else {
501501 for (i = 0; i < options->filecnt; i++) {
502502 filename = options->filenames[i];
503503
504− if (stat(filename, &fstats) || !S_ISDIR(fstats.st_mode)) {
504+ if (stat(filename, &fstats) < 0) {
505+ warn("could not stat file: %s", filename);
506+ continue;
507+ }
508+ if (!S_ISDIR(fstats.st_mode)) {
505509 check_add_file(filename);
506510 } else {
507511 if (!options->recursive) {
508512 warn("ignoring directory: %s", filename);
509513 continue;
510514 }
511− if (r_opendir(&dir, filename)) {
515+ if (r_opendir(&dir, filename) < 0) {
512516 warn("could not open directory: %s", filename);
513517 continue;
514518 }
515519 start = fileidx;
516− while ((filename = r_readdir(&dir))) {
520+ while ((filename = r_readdir(&dir)) != NULL) {
517521 check_add_file(filename);
518522 free((void*) filename);
519523 }
@@ -524,7 +528,7 @@ int main(int argc, char **argv) {
524528 }
525529 }
526530
527− if (!fileidx) {
531+ if (fileidx == 0) {
528532 fprintf(stderr, "sxiv: no valid image file given, aborting\n");
529533 exit(EXIT_FAILURE);
530534 }
@@ -548,7 +552,7 @@ int main(int argc, char **argv) {
548552 }
549553
550554 win_open(&win);
551−
555+
552556 run();
553557 cleanup();
554558
M options.c View
@@ -95,7 +95,7 @@ void parse_options(int argc, char **argv) {
9595 print_usage();
9696 exit(EXIT_SUCCESS);
9797 case 'n':
98− if (!sscanf(optarg, "%d", &t) || t < 1) {
98+ if (sscanf(optarg, "%d", &t) <= 0 || t < 1) {
9999 fprintf(stderr, "sxiv: invalid argument for option -n: %s\n",
100100 optarg);
101101 exit(EXIT_FAILURE);
@@ -127,7 +127,7 @@ void parse_options(int argc, char **argv) {
127127 break;
128128 case 'z':
129129 _options.scalemode = SCALE_ZOOM;
130− if (!sscanf(optarg, "%d", &t) || t <= 0) {
130+ if (sscanf(optarg, "%d", &t) <= 0 || t <= 0) {
131131 fprintf(stderr, "sxiv: invalid argument for option -z: %s\n",
132132 optarg);
133133 exit(EXIT_FAILURE);
M thumbs.c View
@@ -41,23 +41,23 @@ char *cache_dir = NULL;
4141 bool tns_cache_enabled() {
4242 struct stat stats;
4343
44− return cache_dir && !stat(cache_dir, &stats) && S_ISDIR(stats.st_mode) &&
45− !access(cache_dir, W_OK);
44+ return cache_dir != NULL && stat(cache_dir, &stats) == 0 &&
45+ S_ISDIR(stats.st_mode) && access(cache_dir, W_OK) == 0;
4646 }
4747
4848 char* tns_cache_filepath(const char *filepath) {
4949 size_t len;
5050 char *cfile = NULL;
5151
52− if (!cache_dir || !filepath || *filepath != '/')
52+ if (cache_dir == NULL || filepath == NULL || *filepath != '/')
5353 return NULL;
5454
55− if (strncmp(filepath, cache_dir, strlen(cache_dir))) {
55+ if (strncmp(filepath, cache_dir, strlen(cache_dir)) != 0) {
56+ /* don't cache images inside the cache directory! */
5657 len = strlen(cache_dir) + strlen(filepath) + 6;
5758 cfile = (char*) s_malloc(len);
5859 snprintf(cfile, len, "%s/%s.png", cache_dir, filepath + 1);
5960 }
60−
6161 return cfile;
6262 }
6363
@@ -66,18 +66,16 @@ Imlib_Image* tns_cache_load(const char *filepath) {
6666 struct stat cstats, fstats;
6767 Imlib_Image *im = NULL;
6868
69− if (!filepath)
69+ if (filepath == NULL)
7070 return NULL;
71−
72− if (stat(filepath, &fstats))
71+ if (stat(filepath, &fstats) < 0)
7372 return NULL;
7473
75− if ((cfile = tns_cache_filepath(filepath))) {
76− if (!stat(cfile, &cstats) && cstats.st_mtime == fstats.st_mtime)
74+ if ((cfile = tns_cache_filepath(filepath)) != NULL) {
75+ if (stat(cfile, &cstats) == 0 && cstats.st_mtime == fstats.st_mtime)
7776 im = imlib_load_image(cfile);
7877 free(cfile);
7978 }
80−
8179 return im;
8280 }
8381
@@ -87,32 +85,35 @@ void tns_cache_write(thumb_t *t, bool force) {
8785 struct utimbuf times;
8886 Imlib_Load_Error err = 0;
8987
90− if (!t || !t->im || !t->file || !t->file->name || !t->file->path)
88+ if (t == NULL || t->im == NULL)
9189 return;
92−
93− if (stat(t->file->path, &fstats))
90+ if (t->file == NULL || t->file->name == NULL || t->file->path == NULL)
91+ return;
92+ if (stat(t->file->path, &fstats) < 0)
9493 return;
9594
96− if ((cfile = tns_cache_filepath(t->file->path))) {
97− if (force || stat(cfile, &cstats) || cstats.st_mtime != fstats.st_mtime) {
98− if ((dirend = strrchr(cfile, '/'))) {
95+ if ((cfile = tns_cache_filepath(t->file->path)) != NULL) {
96+ if (force || stat(cfile, &cstats) < 0 ||
97+ cstats.st_mtime != fstats.st_mtime)
98+ {
99+ if ((dirend = strrchr(cfile, '/')) != NULL) {
99100 *dirend = '\0';
100101 err = r_mkdir(cfile);
101102 *dirend = '/';
102103 }
103104
104− if (!err) {
105+ if (err == 0) {
105106 imlib_context_set_image(t->im);
106107 imlib_image_set_format("png");
107108 imlib_save_image_with_error_return(cfile, &err);
108109 }
109110
110− if (err) {
111− warn("could not cache thumbnail: %s", t->file->name);
112− } else {
111+ if (err == 0) {
113112 times.actime = fstats.st_atime;
114113 times.modtime = fstats.st_mtime;
115114 utime(cfile, &times);
115+ } else {
116+ warn("could not cache thumbnail: %s", t->file->name);
116117 }
117118 }
118119 free(cfile);
@@ -125,33 +126,32 @@ void tns_clean_cache(tns_t *tns) {
125126 char *cfile, *filename, *tpos;
126127 r_dir_t dir;
127128
128− if (!cache_dir)
129+ if (cache_dir == NULL)
129130 return;
130131
131− if (r_opendir(&dir, cache_dir)) {
132+ if (r_opendir(&dir, cache_dir) < 0) {
132133 warn("could not open thumbnail cache directory: %s", cache_dir);
133134 return;
134135 }
135136
136137 dirlen = strlen(cache_dir);
137138
138− while ((cfile = r_readdir(&dir))) {
139+ while ((cfile = r_readdir(&dir)) != NULL) {
139140 filename = cfile + dirlen;
140141 delete = false;
141142
142− if ((tpos = strrchr(filename, '.'))) {
143+ if ((tpos = strrchr(filename, '.')) != NULL) {
143144 *tpos = '\0';
144− if (access(filename, F_OK))
145+ if (access(filename, F_OK) < 0)
145146 delete = true;
146147 *tpos = '.';
147148 }
148−
149− if (delete && unlink(cfile))
150− warn("could not delete cache file: %s", cfile);
151−
149+ if (delete) {
150+ if (unlink(cfile) < 0)
151+ warn("could not delete cache file: %s", cfile);
152+ }
152153 free(cfile);
153154 }
154−
155155 r_closedir(&dir);
156156 }
157157
@@ -160,10 +160,10 @@ void tns_init(tns_t *tns, int cnt, win_t *win) {
160160 int len;
161161 char *homedir;
162162
163− if (!tns)
163+ if (tns == NULL)
164164 return;
165165
166− if (cnt) {
166+ if (cnt > 0) {
167167 tns->thumbs = (thumb_t*) s_malloc(cnt * sizeof(thumb_t));
168168 memset(tns->thumbs, 0, cnt * sizeof(thumb_t));
169169 } else {
@@ -176,8 +176,8 @@ void tns_init(tns_t *tns, int cnt, win_t *win) {
176176 tns->alpha = true;
177177 tns->dirty = false;
178178
179− if ((homedir = getenv("HOME"))) {
180− if (cache_dir)
179+ if ((homedir = getenv("HOME")) != NULL) {
180+ if (cache_dir != NULL)
181181 free(cache_dir);
182182 len = strlen(homedir) + 10;
183183 cache_dir = (char*) s_malloc(len * sizeof(char));
@@ -190,12 +190,12 @@ void tns_init(tns_t *tns, int cnt, win_t *win) {
190190 void tns_free(tns_t *tns) {
191191 int i;
192192
193− if (!tns)
193+ if (tns != NULL)
194194 return;
195195
196− if (tns->thumbs) {
196+ if (tns->thumbs != NULL) {
197197 for (i = 0; i < tns->cnt; i++) {
198− if (tns->thumbs[i].im) {
198+ if (tns->thumbs[i].im != NULL) {
199199 imlib_context_set_image(tns->thumbs[i].im);
200200 imlib_free_image();
201201 }
@@ -204,7 +204,7 @@ void tns_free(tns_t *tns) {
204204 tns->thumbs = NULL;
205205 }
206206
207− if (cache_dir) {
207+ if (cache_dir != NULL) {
208208 free(cache_dir);
209209 cache_dir = NULL;
210210 }
@@ -220,31 +220,34 @@ bool tns_load(tns_t *tns, int n, const fileinfo_t *file,
220220 Imlib_Image *im;
221221 const char *fmt;
222222
223− if (!tns || !tns->thumbs || !file || !file->name || !file->path)
223+ if (tns == NULL || tns->thumbs == NULL)
224+ return false;
225+ if (file == NULL || file->name == NULL || file->path == NULL)
224226 return false;
225−
226227 if (n < 0 || n >= tns->cap)
227228 return false;
228229
229230 t = &tns->thumbs[n];
230231 t->file = file;
231232
232− if (t->im) {
233+ if (t->im != NULL) {
233234 imlib_context_set_image(t->im);
234235 imlib_free_image();
235236 }
236237
237238 if ((use_cache = tns_cache_enabled())) {
238− if (!force && (im = tns_cache_load(file->path)))
239+ if (!force && (im = tns_cache_load(file->path)) != NULL)
239240 cache_hit = true;
240241 }
241242
242− if (!cache_hit &&
243− (access(file->path, R_OK) || !(im = imlib_load_image(file->path))))
244− {
245− if (!silent)
246− warn("could not open image: %s", file->name);
247− return false;
243+ if (!cache_hit) {
244+ if (access(file->path, R_OK) < 0 ||
245+ (im = imlib_load_image(file->path)) == NULL)
246+ {
247+ if (!silent)
248+ warn("could not open image: %s", file->name);
249+ return false;
250+ }
248251 }
249252
250253 imlib_context_set_image(im);
@@ -267,7 +270,8 @@ bool tns_load(tns_t *tns, int n, const fileinfo_t *file,
267270 t->w = z * w;
268271 t->h = z * h;
269272
270− if (!(t->im = imlib_create_cropped_scaled_image(0, 0, w, h, t->w, t->h)))
273+ t->im = imlib_create_cropped_scaled_image(0, 0, w, h, t->w, t->h);
274+ if (t->im == NULL)
271275 die("could not allocate memory");
272276
273277 imlib_free_image_and_decache();
@@ -282,7 +286,7 @@ bool tns_load(tns_t *tns, int n, const fileinfo_t *file,
282286 void tns_check_view(tns_t *tns, bool scrolled) {
283287 int r;
284288
285− if (!tns)
289+ if (tns == NULL)
286290 return;
287291
288292 tns->first -= tns->first % tns->cols;
@@ -311,7 +315,7 @@ void tns_render(tns_t *tns) {
311315 win_t *win;
312316 int i, cnt, r, x, y;
313317
314− if (!tns || !tns->thumbs || !tns->win)
318+ if (tns == NULL || tns->thumbs == NULL || tns->win == NULL)
315319 return;
316320 if (!tns->dirty)
317321 return;
@@ -345,7 +349,7 @@ void tns_render(tns_t *tns) {
345349 t->y = y + (THUMB_SIZE - t->h) / 2;
346350 imlib_context_set_image(t->im);
347351
348− if (imlib_image_has_alpha() && !tns->alpha)
352+ if (!tns->alpha && imlib_image_has_alpha())
349353 win_draw_rect(win, win->pm, t->x, t->y, t->w, t->h, true, 0, win->white);
350354
351355 imlib_render_image_part_on_drawable_at_size(0, 0, t->w, t->h,
@@ -357,7 +361,6 @@ void tns_render(tns_t *tns) {
357361 x += thumb_dim;
358362 }
359363 }
360−
361364 tns->dirty = false;
362365 tns_highlight(tns, tns->sel, true);
363366 }
@@ -368,7 +371,7 @@ void tns_highlight(tns_t *tns, int n, bool hl) {
368371 int x, y;
369372 unsigned long col;
370373
371− if (!tns || !tns->thumbs || !tns->win)
374+ if (tns == NULL || tns->thumbs == NULL || tns->win == NULL)
372375 return;
373376
374377 win = tns->win;
@@ -388,14 +391,13 @@ void tns_highlight(tns_t *tns, int n, bool hl) {
388391 win_draw_rect(win, win->pm, x - 3, y - 3, THUMB_SIZE + 6, THUMB_SIZE + 6,
389392 false, 2, col);
390393 }
391−
392394 win_draw(win);
393395 }
394396
395397 bool tns_move_selection(tns_t *tns, direction_t dir) {
396398 int old;
397399
398− if (!tns || !tns->thumbs)
400+ if (tns == NULL || tns->thumbs == NULL)
399401 return false;
400402
401403 old = tns->sel;
@@ -425,14 +427,13 @@ bool tns_move_selection(tns_t *tns, direction_t dir) {
425427 if (!tns->dirty)
426428 tns_highlight(tns, tns->sel, true);
427429 }
428−
429430 return tns->sel != old;
430431 }
431432
432433 bool tns_scroll(tns_t *tns, direction_t dir) {
433434 int old;
434435
435− if (!tns)
436+ if (tns == NULL)
436437 return false;
437438
438439 old = tns->first;
@@ -446,16 +447,14 @@ bool tns_scroll(tns_t *tns, direction_t dir) {
446447 tns_check_view(tns, true);
447448 tns->dirty = true;
448449 }
449−
450450 return tns->first != old;
451451 }
452452
453453 int tns_translate(tns_t *tns, int x, int y) {
454454 int n;
455455
456− if (!tns || !tns->thumbs)
456+ if (tns == NULL || tns->thumbs == NULL)
457457 return -1;
458−
459458 if (x < tns->x || y < tns->y)
460459 return -1;
461460
M util.c View
@@ -39,13 +39,15 @@ void cleanup();
3939 void* s_malloc(size_t size) {
4040 void *ptr;
4141
42− if (!(ptr = malloc(size)))
42+ ptr = malloc(size);
43+ if (ptr == NULL)
4344 die("could not allocate memory");
4445 return ptr;
4546 }
4647
4748 void* s_realloc(void *ptr, size_t size) {
48− if (!(ptr = realloc(ptr, size)))
49+ ptr = realloc(ptr, size);
50+ if (ptr == NULL)
4951 die("could not allocate memory");
5052 return ptr;
5153 }
@@ -53,8 +55,9 @@ void* s_realloc(void *ptr, size_t size) {
5355 char* s_strdup(char *s) {
5456 char *d = NULL;
5557
56− if (s) {
57− if (!(d = malloc(strlen(s) + 1)))
58+ if (s != NULL) {
59+ d = malloc(strlen(s) + 1);
60+ if (d == NULL)
5861 die("could not allocate memory");
5962 strcpy(d, s);
6063 }
@@ -64,7 +67,7 @@ char* s_strdup(char *s) {
6467 void warn(const char* fmt, ...) {
6568 va_list args;
6669
67− if (!fmt || options->quiet)
70+ if (fmt == NULL || options->quiet)
6871 return;
6972
7073 va_start(args, fmt);
@@ -77,7 +80,7 @@ void warn(const char* fmt, ...) {
7780 void die(const char* fmt, ...) {
7881 va_list args;
7982
80− if (!fmt)
83+ if (fmt == NULL)
8184 return;
8285
8386 va_start(args, fmt);
@@ -94,17 +97,17 @@ ssize_t get_line(char **buf, size_t *n, FILE *stream) {
9497 size_t len;
9598 char *s;
9699
97− if (!stream || feof(stream) || ferror(stream))
100+ if (stream == NULL || feof(stream) || ferror(stream))
98101 return -1;
99102
100− if (!*buf || !*n) {
103+ if (*buf == NULL || *n == 0) {
101104 *n = BUF_SIZE;
102105 *buf = (char*) s_malloc(*n);
103106 }
104107 s = *buf;
105108
106− while (1) {
107− if (!fgets(s, *n - (s - *buf), stream))
109+ while (true) {
110+ if (fgets(s, *n - (s - *buf), stream) == NULL)
108111 return -1;
109112 len = strlen(s);
110113 if (feof(stream))
@@ -119,7 +122,6 @@ ssize_t get_line(char **buf, size_t *n, FILE *stream) {
119122 s += len;
120123 }
121124 }
122−
123125 return s - *buf + len;
124126 }
125127
@@ -147,41 +149,41 @@ char* absolute_path(const char *filename) {
147149 char *dir, *dirname = NULL, *path = NULL, *s;
148150 char *cwd = NULL, *twd = NULL;
149151
150− if (!filename || *filename == '\0' || *filename == '/')
152+ if (filename == NULL || *filename == '\0' || *filename == '/')
151153 return NULL;
152154
153155 len = FNAME_LEN;
154156 cwd = (char*) s_malloc(len);
155− while (!(s = getcwd(cwd, len)) && errno == ERANGE) {
157+ while ((s = getcwd(cwd, len)) == NULL && errno == ERANGE) {
156158 len *= 2;
157159 cwd = (char*) s_realloc(cwd, len);
158160 }
159− if (!s)
161+ if (s == NULL)
160162 goto error;
161163
162164 s = strrchr(filename, '/');
163− if (s) {
165+ if (s != NULL) {
164166 len = s - filename;
165167 dirname = (char*) s_malloc(len + 1);
166168 strncpy(dirname, filename, len);
167169 dirname[len] = '\0';
168170 basename = s + 1;
169171
170− if (chdir(cwd))
172+ if (chdir(cwd) < 0)
171173 /* we're not able to come back afterwards */
172174 goto error;
173− if (chdir(dirname))
175+ if (chdir(dirname) < 0)
174176 goto error;
175177
176178 len = FNAME_LEN;
177179 twd = (char*) s_malloc(len);
178− while (!(s = getcwd(twd, len)) && errno == ERANGE) {
180+ while ((s = getcwd(twd, len)) == NULL && errno == ERANGE) {
179181 len *= 2;
180182 twd = (char*) s_realloc(twd, len);
181183 }
182− if (chdir(cwd))
184+ if (chdir(cwd) < 0)
183185 die("could not revert to prior working directory");
184− if (!s)
186+ if (s == NULL)
185187 goto error;
186188 dir = twd;
187189 } else {
@@ -197,27 +199,27 @@ char* absolute_path(const char *filename) {
197199 goto end;
198200
199201 error:
200− if (path) {
202+ if (path != NULL) {
201203 free(path);
202204 path = NULL;
203205 }
204206
205207 end:
206− if (dirname)
208+ if (dirname != NULL)
207209 free(dirname);
208− if (cwd)
210+ if (cwd != NULL)
209211 free(cwd);
210− if (twd)
212+ if (twd != NULL)
211213 free(twd);
212214
213215 return path;
214216 }
215217
216218 int r_opendir(r_dir_t *rdir, const char *dirname) {
217− if (!rdir || !dirname || !*dirname)
219+ if (rdir == NULL || dirname == NULL || *dirname == '\0')
218220 return -1;
219221
220− if (!(rdir->dir = opendir(dirname))) {
222+ if ((rdir->dir = opendir(dirname)) == NULL) {
221223 rdir->name = NULL;
222224 rdir->stack = NULL;
223225 return -1;
@@ -236,22 +238,22 @@ int r_opendir(r_dir_t *rdir, const char *dirname) {
236238 int r_closedir(r_dir_t *rdir) {
237239 int ret = 0;
238240
239− if (!rdir)
241+ if (rdir == NULL)
240242 return -1;
241243
242− if (rdir->stack) {
244+ if (rdir->stack != NULL) {
243245 while (rdir->stlen > 0)
244246 free(rdir->stack[--rdir->stlen]);
245247 free(rdir->stack);
246248 rdir->stack = NULL;
247249 }
248250
249− if (rdir->dir) {
250− if (!(ret = closedir(rdir->dir)))
251+ if (rdir->dir != NULL) {
252+ if ((ret = closedir(rdir->dir)) == 0)
251253 rdir->dir = NULL;
252254 }
253255
254− if (rdir->d && rdir->name) {
256+ if (rdir->d != 0 && rdir->name != NULL) {
255257 free(rdir->name);
256258 rdir->name = NULL;
257259 }
@@ -265,11 +267,11 @@ char* r_readdir(r_dir_t *rdir) {
265267 struct dirent *dentry;
266268 struct stat fstats;
267269
268− if (!rdir || !rdir->dir || !rdir->name)
270+ if (rdir == NULL || rdir->dir == NULL || rdir->name == NULL)
269271 return NULL;
270272
271− while (1) {
272− if (rdir->dir && (dentry = readdir(rdir->dir))) {
273+ while (true) {
274+ if (rdir->dir != NULL && (dentry = readdir(rdir->dir)) != NULL) {
273275 if (streq(dentry->d_name, ".") || streq(dentry->d_name, ".."))
274276 continue;
275277
@@ -279,7 +281,9 @@ char* r_readdir(r_dir_t *rdir) {
279281 rdir->name[strlen(rdir->name)-1] == '/' ? "" : "/",
280282 dentry->d_name);
281283
282− if (!stat(filename, &fstats) && S_ISDIR(fstats.st_mode)) {
284+ if (stat(filename, &fstats) < 0)
285+ continue;
286+ if (S_ISDIR(fstats.st_mode)) {
283287 /* put subdirectory on the stack */
284288 if (rdir->stlen == rdir->stcap) {
285289 rdir->stcap *= 2;
@@ -295,19 +299,17 @@ char* r_readdir(r_dir_t *rdir) {
295299 if (rdir->stlen > 0) {
296300 /* open next subdirectory */
297301 closedir(rdir->dir);
298− if (rdir->d)
302+ if (rdir->d != 0)
299303 free(rdir->name);
300304 rdir->name = rdir->stack[--rdir->stlen];
301305 rdir->d = 1;
302− if (!(rdir->dir = opendir(rdir->name)))
306+ if ((rdir->dir = opendir(rdir->name)) == NULL)
303307 warn("could not open directory: %s", rdir->name);
304308 continue;
305309 }
306−
307310 /* no more entries */
308311 break;
309312 }
310−
311313 return NULL;
312314 }
313315
@@ -316,10 +318,10 @@ int r_mkdir(const char *path) {
316318 struct stat stats;
317319 int err = 0;
318320
319− if (!path || !*path)
321+ if (path == NULL || *path == '\0')
320322 return -1;
321323
322− if (!stat(path, &stats)) {
324+ if (stat(path, &stats) == 0) {
323325 if (S_ISDIR(stats.st_mode)) {
324326 return 0;
325327 } else {
@@ -331,16 +333,16 @@ int r_mkdir(const char *path) {
331333 d = dir = (char*) s_malloc(strlen(path) + 1);
332334 strcpy(dir, path);
333335
334− while (d != NULL && !err) {
336+ while (d != NULL && err == 0) {
335337 d = strchr(d + 1, '/');
336338 if (d != NULL)
337339 *d = '\0';
338− if (access(dir, F_OK) && errno == ENOENT) {
339− if (mkdir(dir, 0755)) {
340+ if (access(dir, F_OK) < 0 && errno == ENOENT) {
341+ if (mkdir(dir, 0755) < 0) {
340342 warn("could not create directory: %s", dir);
341343 err = -1;
342344 }
343− } else if (stat(dir, &stats) || !S_ISDIR(stats.st_mode)) {
345+ } else if (stat(dir, &stats) < 0 || !S_ISDIR(stats.st_mode)) {
344346 warn("not a directory: %s", dir);
345347 err = -1;
346348 }
M window.c View
@@ -40,11 +40,11 @@ void win_init(win_t *win) {
4040 win_env_t *e;
4141 XColor col;
4242
43− if (!win)
43+ if (win == NULL)
4444 return;
4545
4646 e = &win->env;
47− if (!(e->dpy = XOpenDisplay(NULL)))
47+ if ((e->dpy = XOpenDisplay(NULL)) == NULL)
4848 die("could not open display");
4949
5050 e->scr = DefaultScreen(e->dpy);
@@ -58,7 +58,7 @@ void win_init(win_t *win) {
5858 win->white = WhitePixel(e->dpy, e->scr);
5959
6060 if (XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), BG_COLOR,
61− &col, &col))
61+ &col, &col) != 0)
6262 {
6363 win->bgcol = col.pixel;
6464 } else {
@@ -66,7 +66,7 @@ void win_init(win_t *win) {
6666 }
6767
6868 if (XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), SEL_COLOR,
69− &col, &col))
69+ &col, &col) != 0)
7070 {
7171 win->selcol = col.pixel;
7272 } else {
@@ -81,7 +81,7 @@ void win_init(win_t *win) {
8181 void win_set_sizehints(win_t *win) {
8282 XSizeHints sizehints;
8383
84− if (!win || !win->xwin)
84+ if (win == NULL || win->xwin == None)
8585 return;
8686
8787 sizehints.flags = PMinSize | PMaxSize;
@@ -100,32 +100,32 @@ void win_open(win_t *win) {
100100 Pixmap none;
101101 int gmask;
102102
103− if (!win)
103+ if (win == NULL)
104104 return;
105105
106106 e = &win->env;
107107
108108 /* determine window offsets, width & height */
109− if (!options->geometry)
109+ if (options->geometry == NULL)
110110 gmask = 0;
111111 else
112112 gmask = XParseGeometry(options->geometry, &win->x, &win->y,
113113 &win->w, &win->h);
114− if (!(gmask & WidthValue))
114+ if ((gmask & WidthValue) == 0)
115115 win->w = WIN_WIDTH;
116116 if (win->w > e->scrw)
117117 win->w = e->scrw;
118− if (!(gmask & HeightValue))
118+ if ((gmask & HeightValue) == 0)
119119 win->h = WIN_HEIGHT;
120120 if (win->h > e->scrh)
121121 win->h = e->scrh;
122− if (!(gmask & XValue))
122+ if ((gmask & XValue) == 0)
123123 win->x = (e->scrw - win->w) / 2;
124− else if (gmask & XNegative)
124+ else if ((gmask & XNegative) != 0)
125125 win->x += e->scrw - win->w;
126− if (!(gmask & YValue))
126+ if ((gmask & YValue) == 0)
127127 win->y = (e->scrh - win->h) / 2;
128− else if (gmask & YNegative)
128+ else if ((gmask & YNegative) != 0)
129129 win->y += e->scrh - win->h;
130130
131131 win->xwin = XCreateWindow(e->dpy, RootWindow(e->dpy, e->scr),
@@ -141,8 +141,8 @@ void win_open(win_t *win) {
141141 chand = XCreateFontCursor(e->dpy, XC_fleur);
142142 cwatch = XCreateFontCursor(e->dpy, XC_watch);
143143
144− if (!XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), "black",
145− &col, &col))
144+ if (XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), "black",
145+ &col, &col) == 0)
146146 {
147147 die("could not allocate color: black");
148148 }
@@ -171,7 +171,7 @@ void win_open(win_t *win) {
171171 }
172172
173173 void win_close(win_t *win) {
174− if (!win || !win->xwin)
174+ if (win == NULL || win->xwin == None)
175175 return;
176176
177177 XFreeCursor(win->env.dpy, carrow);
@@ -188,7 +188,7 @@ void win_close(win_t *win) {
188188 bool win_configure(win_t *win, XConfigureEvent *c) {
189189 bool changed;
190190
191− if (!win)
191+ if (win == NULL)
192192 return false;
193193
194194 changed = win->w != c->width || win->h != c->height;
@@ -203,7 +203,7 @@ bool win_configure(win_t *win, XConfigureEvent *c) {
203203 }
204204
205205 bool win_moveresize(win_t *win, int x, int y, unsigned int w, unsigned int h) {
206− if (!win || !win->xwin)
206+ if (win == NULL || win->xwin == None)
207207 return false;
208208
209209 x = MAX(0, x);
@@ -231,7 +231,7 @@ void win_toggle_fullscreen(win_t *win) {
231231 XEvent ev;
232232 XClientMessageEvent *cm;
233233
234− if (!win || !win->xwin)
234+ if (win == NULL || win->xwin == None)
235235 return;
236236
237237 win->fullscreen = !win->fullscreen;
@@ -255,13 +255,13 @@ void win_clear(win_t *win) {
255255 win_env_t *e;
256256 XGCValues gcval;
257257
258− if (!win || !win->xwin)
258+ if (win == NULL || win->xwin == None)
259259 return;
260260
261261 e = &win->env;
262262 gcval.foreground = win->fullscreen ? win->black : win->bgcol;
263263
264− if (win->pm)
264+ if (win->pm != None)
265265 XFreePixmap(e->dpy, win->pm);
266266 win->pm = XCreatePixmap(e->dpy, win->xwin, e->scrw, e->scrh, e->depth);
267267
@@ -270,7 +270,7 @@ void win_clear(win_t *win) {
270270 }
271271
272272 void win_draw(win_t *win) {
273− if (!win || !win->xwin)
273+ if (win == NULL || win->xwin == None)
274274 return;
275275
276276 XSetWindowBackgroundPixmap(win->env.dpy, win->xwin, win->pm);
@@ -281,7 +281,7 @@ void win_draw_rect(win_t *win, Pixmap pm, int x, int y, int w, int h,
281281 bool fill, int lw, unsigned long col) {
282282 XGCValues gcval;
283283
284− if (!win || !pm)
284+ if (win == NULL || pm == None)
285285 return;
286286
287287 gcval.line_width = lw;
@@ -295,10 +295,10 @@ void win_draw_rect(win_t *win, Pixmap pm, int x, int y, int w, int h,
295295 }
296296
297297 void win_set_title(win_t *win, const char *title) {
298− if (!win || !win->xwin)
298+ if (win == NULL || win->xwin == None)
299299 return;
300300
301− if (!title)
301+ if (title == NULL)
302302 title = "sxiv";
303303
304304 XStoreName(win->env.dpy, win->xwin, title);
@@ -315,7 +315,7 @@ void win_set_title(win_t *win, const char *title) {
315315 }
316316
317317 void win_set_cursor(win_t *win, cursor_t cursor) {
318− if (!win || !win->xwin)
318+ if (win == NULL || win->xwin == None)
319319 return;
320320
321321 switch (cursor) {