nsxiv8dcf682
Made all conditionals more precise
+236 −234
8 files changed
- M commands.c +9 −15
- M config.c +4 −3
- M image.c +31 −29
- M main.c +56 −52
- M options.c +2 −2
- M thumbs.c +61 −62
- M util.c +47 −45
- M window.c +26 −26
| @@ -53,7 +53,7 @@ bool it_quit(arg_t a) { | |||
| 53 | 53 | ||
| 54 | 54 | bool it_switch_mode(arg_t a) { | |
| 55 | 55 | if (mode == MODE_IMAGE) { | |
| 56 | − | if (!tns.thumbs) | |
| 56 | + | if (tns.thumbs == NULL) | |
| 57 | 57 | tns_init(&tns, filecnt, &win); | |
| 58 | 58 | img_close(&img, false); | |
| 59 | 59 | reset_timeout(reset_cursor); | |
| @@ -273,21 +273,19 @@ bool i_zoom(arg_t a) { | |||
| 273 | 273 | } | |
| 274 | 274 | ||
| 275 | 275 | bool i_fit_to_win(arg_t a) { | |
| 276 | − | bool ret; | |
| 276 | + | bool ret = false; | |
| 277 | 277 | ||
| 278 | 278 | if (mode == MODE_IMAGE) { | |
| 279 | 279 | if ((ret = img_fit_win(&img))) | |
| 280 | 280 | img_center(&img); | |
| 281 | − | return ret; | |
| 282 | − | } else { | |
| 283 | − | return false; | |
| 284 | 281 | } | |
| 282 | + | return ret; | |
| 285 | 283 | } | |
| 286 | 284 | ||
| 287 | 285 | bool i_fit_to_img(arg_t a) { | |
| 288 | 286 | int x, y; | |
| 289 | 287 | unsigned int w, h; | |
| 290 | − | bool ret; | |
| 288 | + | bool ret = false; | |
| 291 | 289 | ||
| 292 | 290 | if (mode == MODE_IMAGE) { | |
| 293 | 291 | x = MAX(0, win.x + img.x); | |
| @@ -298,10 +296,8 @@ bool i_fit_to_img(arg_t a) { | |||
| 298 | 296 | img.x = x - win.x; | |
| 299 | 297 | img.y = y - win.y; | |
| 300 | 298 | } | |
| 301 | − | return ret; | |
| 302 | − | } else { | |
| 303 | − | return false; | |
| 304 | 299 | } | |
| 300 | + | return ret; | |
| 305 | 301 | } | |
| 306 | 302 | ||
| 307 | 303 | bool i_rotate(arg_t a) { | |
| @@ -381,7 +377,7 @@ bool it_open_with(arg_t a) { | |||
| 381 | 377 | const char *prog = (const char*) a; | |
| 382 | 378 | pid_t pid; | |
| 383 | 379 | ||
| 384 | − | if (!prog || !*prog) | |
| 380 | + | if (prog == NULL || *prog == '\0') | |
| 385 | 381 | return false; | |
| 386 | 382 | ||
| 387 | 383 | if ((pid = fork()) == 0) { | |
| @@ -392,7 +388,6 @@ bool it_open_with(arg_t a) { | |||
| 392 | 388 | } else if (pid < 0) { | |
| 393 | 389 | warn("could not fork. program was: %s", prog); | |
| 394 | 390 | } | |
| 395 | − | ||
| 396 | 391 | return false; | |
| 397 | 392 | } | |
| 398 | 393 | ||
| @@ -401,8 +396,8 @@ bool it_shell_cmd(arg_t a) { | |||
| 401 | 396 | const char *cmdline = (const char*) a; | |
| 402 | 397 | pid_t pid; | |
| 403 | 398 | ||
| 404 | − | if (!cmdline || !*cmdline) | |
| 405 | − | return 0; | |
| 399 | + | if (cmdline == NULL || *cmdline == '\0') | |
| 400 | + | return false; | |
| 406 | 401 | ||
| 407 | 402 | n = mode == MODE_IMAGE ? fileidx : tns.sel; | |
| 408 | 403 | ||
| @@ -424,7 +419,7 @@ bool it_shell_cmd(arg_t a) { | |||
| 424 | 419 | win_set_cursor(&win, CURSOR_WATCH); | |
| 425 | 420 | ||
| 426 | 421 | waitpid(pid, &status, 0); | |
| 427 | − | if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) | |
| 422 | + | if (WIFEXITED(status) == 0 || WEXITSTATUS(status) != 0) | |
| 428 | 423 | warn("child exited with non-zero return value: %d. command line was: %s", | |
| 429 | 424 | WEXITSTATUS(status), cmdline); | |
| 430 | 425 | ||
| @@ -440,6 +435,5 @@ bool it_shell_cmd(arg_t a) { | |||
| 440 | 435 | if (tns.sel >= tns.cnt) | |
| 441 | 436 | tns.sel = tns.cnt - 1; | |
| 442 | 437 | } | |
| 443 | − | ||
| 444 | 438 | return true; | |
| 445 | 439 | } | |
| @@ -14,10 +14,11 @@ inline int puts_if(const char *s, int c) { | |||
| 14 | 14 | } | |
| 15 | 15 | ||
| 16 | 16 | int main(int argc, char **argv) { | |
| 17 | − | int i, n = 0; | |
| 17 | + | int i; | |
| 18 | + | unsigned int n = 0; | |
| 18 | 19 | ||
| 19 | 20 | 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]) { | |
| 21 | 22 | case 'D': | |
| 22 | 23 | n += PUT_MACRO(EXIF_SUPPORT); | |
| 23 | 24 | n += PUT_MACRO(GIF_SUPPORT); | |
| @@ -31,7 +32,7 @@ int main(int argc, char **argv) { | |||
| 31 | 32 | return 1; | |
| 32 | 33 | } | |
| 33 | 34 | } | |
| 34 | − | if (n) | |
| 35 | + | if (n > 0) | |
| 35 | 36 | printf("\n"); | |
| 36 | 37 | return 0; | |
| 37 | 38 | } | |
| @@ -49,7 +49,7 @@ void img_init(img_t *img, win_t *win) { | |||
| 49 | 49 | zoom_min = zoom_levels[0] / 100.0; | |
| 50 | 50 | zoom_max = zoom_levels[ARRLEN(zoom_levels) - 1] / 100.0; | |
| 51 | 51 | ||
| 52 | − | if (!img || !win) | |
| 52 | + | if (img == NULL || win == NULL) | |
| 53 | 53 | return; | |
| 54 | 54 | ||
| 55 | 55 | imlib_context_set_display(win->env.dpy); | |
| @@ -77,15 +77,15 @@ void exif_auto_orientate(const fileinfo_t *file) { | |||
| 77 | 77 | ExifEntry *entry; | |
| 78 | 78 | int byte_order, orientation; | |
| 79 | 79 | ||
| 80 | − | if (!(ed = exif_data_new_from_file(file->path))) | |
| 80 | + | if ((ed = exif_data_new_from_file(file->path)) == NULL) | |
| 81 | 81 | return; | |
| 82 | 82 | entry = exif_content_get_entry(ed->ifd[EXIF_IFD_0], EXIF_TAG_ORIENTATION); | |
| 83 | − | if (entry) { | |
| 83 | + | if (entry != NULL) { | |
| 84 | 84 | byte_order = exif_data_get_byte_order(ed); | |
| 85 | 85 | orientation = exif_get_short(entry->data, byte_order); | |
| 86 | 86 | } | |
| 87 | 87 | exif_data_unref(ed); | |
| 88 | − | if (!entry) | |
| 88 | + | if (entry == NULL) | |
| 89 | 89 | return; | |
| 90 | 90 | ||
| 91 | 91 | switch (orientation) { | |
| @@ -145,7 +145,7 @@ bool img_load_gif(img_t *img, const fileinfo_t *file) { | |||
| 145 | 145 | img->multi.sel = 0; | |
| 146 | 146 | ||
| 147 | 147 | gif = DGifOpenFileName(file->path); | |
| 148 | − | if (!gif) { | |
| 148 | + | if (gif == NULL) { | |
| 149 | 149 | warn("could not open gif file: %s", file->name); | |
| 150 | 150 | return false; | |
| 151 | 151 | } | |
| @@ -215,7 +215,7 @@ bool img_load_gif(img_t *img, const fileinfo_t *file) { | |||
| 215 | 215 | if (i < y || i >= y + h || j < x || j >= x + w || | |
| 216 | 216 | rows[i-y][j-x] == transp) | |
| 217 | 217 | { | |
| 218 | − | if (prev_frame) | |
| 218 | + | if (prev_frame != NULL) | |
| 219 | 219 | *ptr = prev_frame[i * sw + j]; | |
| 220 | 220 | else | |
| 221 | 221 | *ptr = bgpixel; | |
| @@ -236,7 +236,7 @@ bool img_load_gif(img_t *img, const fileinfo_t *file) { | |||
| 236 | 236 | free(rows); | |
| 237 | 237 | free(data); | |
| 238 | 238 | ||
| 239 | − | if (!im) { | |
| 239 | + | if (im == NULL) { | |
| 240 | 240 | err = true; | |
| 241 | 241 | break; | |
| 242 | 242 | } | |
| @@ -286,10 +286,12 @@ bool img_load_gif(img_t *img, const fileinfo_t *file) { | |||
| 286 | 286 | bool img_load(img_t *img, const fileinfo_t *file) { | |
| 287 | 287 | const char *fmt; | |
| 288 | 288 | ||
| 289 | − | if (!img || !file || !file->name || !file->path) | |
| 289 | + | if (img == NULL || file == NULL || file->name == NULL || file->path == NULL) | |
| 290 | 290 | return false; | |
| 291 | 291 | ||
| 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 | + | { | |
| 293 | 295 | warn("could not open image: %s", file->name); | |
| 294 | 296 | return false; | |
| 295 | 297 | } | |
| @@ -324,17 +326,17 @@ bool img_load(img_t *img, const fileinfo_t *file) { | |||
| 324 | 326 | void img_close(img_t *img, bool decache) { | |
| 325 | 327 | int i; | |
| 326 | 328 | ||
| 327 | − | if (!img) | |
| 329 | + | if (img == NULL) | |
| 328 | 330 | return; | |
| 329 | 331 | ||
| 330 | − | if (img->multi.cnt) { | |
| 332 | + | if (img->multi.cnt > 0) { | |
| 331 | 333 | for (i = 0; i < img->multi.cnt; i++) { | |
| 332 | 334 | imlib_context_set_image(img->multi.frames[i].im); | |
| 333 | 335 | imlib_free_image(); | |
| 334 | 336 | } | |
| 335 | 337 | img->multi.cnt = 0; | |
| 336 | 338 | img->im = NULL; | |
| 337 | − | } else if (img->im) { | |
| 339 | + | } else if (img->im != NULL) { | |
| 338 | 340 | imlib_context_set_image(img->im); | |
| 339 | 341 | if (decache) | |
| 340 | 342 | imlib_free_image_and_decache(); | |
| @@ -348,7 +350,7 @@ void img_check_pan(img_t *img, bool moved) { | |||
| 348 | 350 | win_t *win; | |
| 349 | 351 | int ox, oy; | |
| 350 | 352 | ||
| 351 | − | if (!img || !img->im || !img->win) | |
| 353 | + | if (img == NULL || img->im == NULL || img->win == NULL) | |
| 352 | 354 | return; | |
| 353 | 355 | ||
| 354 | 356 | win = img->win; | |
| @@ -379,7 +381,7 @@ void img_check_pan(img_t *img, bool moved) { | |||
| 379 | 381 | bool img_fit(img_t *img) { | |
| 380 | 382 | float z, zmax, zw, zh; | |
| 381 | 383 | ||
| 382 | − | if (!img || !img->im || !img->win) | |
| 384 | + | if (img == NULL || img->im == NULL || img->win == NULL) | |
| 383 | 385 | return false; | |
| 384 | 386 | if (img->scalemode == SCALE_ZOOM) | |
| 385 | 387 | return false; | |
| @@ -406,7 +408,7 @@ void img_render(img_t *img) { | |||
| 406 | 408 | int sx, sy, sw, sh; | |
| 407 | 409 | int dx, dy, dw, dh; | |
| 408 | 410 | ||
| 409 | − | if (!img || !img->im || !img->win) | |
| 411 | + | if (img == NULL || img->im == NULL || img->win == NULL) | |
| 410 | 412 | return; | |
| 411 | 413 | ||
| 412 | 414 | win = img->win; | |
| @@ -461,7 +463,7 @@ void img_render(img_t *img) { | |||
| 461 | 463 | ||
| 462 | 464 | imlib_context_set_image(img->im); | |
| 463 | 465 | ||
| 464 | − | if (imlib_image_has_alpha() && !img->alpha) | |
| 466 | + | if (!img->alpha && imlib_image_has_alpha()) | |
| 465 | 467 | win_draw_rect(win, win->pm, dx, dy, dw, dh, True, 0, win->white); | |
| 466 | 468 | ||
| 467 | 469 | imlib_context_set_drawable(win->pm); | |
| @@ -473,7 +475,7 @@ void img_render(img_t *img) { | |||
| 473 | 475 | } | |
| 474 | 476 | ||
| 475 | 477 | bool img_fit_win(img_t *img) { | |
| 476 | − | if (!img || !img->im) | |
| 478 | + | if (img == NULL || img->im == NULL) | |
| 477 | 479 | return false; | |
| 478 | 480 | ||
| 479 | 481 | img->scalemode = SCALE_FIT; | |
| @@ -483,7 +485,7 @@ bool img_fit_win(img_t *img) { | |||
| 483 | 485 | bool img_center(img_t *img) { | |
| 484 | 486 | int ox, oy; | |
| 485 | 487 | ||
| 486 | − | if (!img || !img->im || !img->win) | |
| 488 | + | if (img == NULL || img->im == NULL || img->win == NULL) | |
| 487 | 489 | return false; | |
| 488 | 490 | ||
| 489 | 491 | ox = img->x; | |
| @@ -501,7 +503,7 @@ bool img_center(img_t *img) { | |||
| 501 | 503 | } | |
| 502 | 504 | ||
| 503 | 505 | 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) | |
| 505 | 507 | return false; | |
| 506 | 508 | ||
| 507 | 509 | z = MAX(z, zoom_min); | |
| @@ -524,7 +526,7 @@ bool img_zoom(img_t *img, float z) { | |||
| 524 | 526 | bool img_zoom_in(img_t *img) { | |
| 525 | 527 | int i; | |
| 526 | 528 | ||
| 527 | − | if (!img || !img->im) | |
| 529 | + | if (img == NULL || img->im == NULL) | |
| 528 | 530 | return false; | |
| 529 | 531 | ||
| 530 | 532 | for (i = 1; i < ARRLEN(zoom_levels); i++) { | |
| @@ -537,7 +539,7 @@ bool img_zoom_in(img_t *img) { | |||
| 537 | 539 | bool img_zoom_out(img_t *img) { | |
| 538 | 540 | int i; | |
| 539 | 541 | ||
| 540 | − | if (!img || !img->im) | |
| 542 | + | if (img == NULL || img->im == NULL) | |
| 541 | 543 | return false; | |
| 542 | 544 | ||
| 543 | 545 | for (i = ARRLEN(zoom_levels) - 2; i >= 0; i--) { | |
| @@ -550,7 +552,7 @@ bool img_zoom_out(img_t *img) { | |||
| 550 | 552 | bool img_move(img_t *img, int dx, int dy) { | |
| 551 | 553 | int ox, oy; | |
| 552 | 554 | ||
| 553 | − | if (!img || !img->im) | |
| 555 | + | if (img == NULL || img->im == NULL) | |
| 554 | 556 | return false; | |
| 555 | 557 | ||
| 556 | 558 | ox = img->x; | |
| @@ -570,7 +572,7 @@ bool img_move(img_t *img, int dx, int dy) { | |||
| 570 | 572 | } | |
| 571 | 573 | ||
| 572 | 574 | 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) | |
| 574 | 576 | return false; | |
| 575 | 577 | ||
| 576 | 578 | switch (dir) { | |
| @@ -589,7 +591,7 @@ bool img_pan(img_t *img, direction_t dir, bool screen) { | |||
| 589 | 591 | bool img_pan_edge(img_t *img, direction_t dir) { | |
| 590 | 592 | int ox, oy; | |
| 591 | 593 | ||
| 592 | − | if (!img || !img->im || !img->win) | |
| 594 | + | if (img == NULL || img->im == NULL || img->win == NULL) | |
| 593 | 595 | return false; | |
| 594 | 596 | ||
| 595 | 597 | ox = img->x; | |
| @@ -624,7 +626,7 @@ void img_rotate(img_t *img, int d) { | |||
| 624 | 626 | win_t *win; | |
| 625 | 627 | int ox, oy, tmp; | |
| 626 | 628 | ||
| 627 | − | if (!img || !img->im || !img->win) | |
| 629 | + | if (img == NULL || img->im == NULL || img->win == NULL) | |
| 628 | 630 | return; | |
| 629 | 631 | ||
| 630 | 632 | win = img->win; | |
| @@ -654,7 +656,7 @@ void img_rotate_right(img_t *img) { | |||
| 654 | 656 | } | |
| 655 | 657 | ||
| 656 | 658 | void img_toggle_antialias(img_t *img) { | |
| 657 | − | if (!img || !img->im) | |
| 659 | + | if (img == NULL || img->im == NULL) | |
| 658 | 660 | return; | |
| 659 | 661 | ||
| 660 | 662 | img->aa = !img->aa; | |
| @@ -664,7 +666,7 @@ void img_toggle_antialias(img_t *img) { | |||
| 664 | 666 | } | |
| 665 | 667 | ||
| 666 | 668 | bool img_frame_goto(img_t *img, int n) { | |
| 667 | − | if (!img || !img->im) | |
| 669 | + | if (img == NULL || img->im == NULL) | |
| 668 | 670 | return false; | |
| 669 | 671 | if (n < 0 || n >= img->multi.cnt || n == img->multi.sel) | |
| 670 | 672 | return false; | |
| @@ -682,7 +684,7 @@ bool img_frame_goto(img_t *img, int n) { | |||
| 682 | 684 | } | |
| 683 | 685 | ||
| 684 | 686 | 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) | |
| 686 | 688 | return false; | |
| 687 | 689 | ||
| 688 | 690 | d += img->multi.sel; | |
| @@ -695,7 +697,7 @@ bool img_frame_navigate(img_t *img, int d) { | |||
| 695 | 697 | } | |
| 696 | 698 | ||
| 697 | 699 | 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) | |
| 699 | 701 | return false; | |
| 700 | 702 | ||
| 701 | 703 | if (img->multi.sel + 1 >= img->multi.cnt) { | |
| @@ -73,9 +73,10 @@ timeout_t timeouts[] = { | |||
| 73 | 73 | }; | |
| 74 | 74 | ||
| 75 | 75 | void cleanup() { | |
| 76 | − | static int in = 0; | |
| 76 | + | static bool in = false; | |
| 77 | 77 | ||
| 78 | − | if (!in++) { | |
| 78 | + | if (!in) { | |
| 79 | + | in = true; | |
| 79 | 80 | img_close(&img, false); | |
| 80 | 81 | tns_free(&tns); | |
| 81 | 82 | win_close(&win); | |
| @@ -83,10 +84,10 @@ void cleanup() { | |||
| 83 | 84 | } | |
| 84 | 85 | ||
| 85 | 86 | void check_add_file(char *filename) { | |
| 86 | − | if (!filename || !*filename) | |
| 87 | + | if (filename == NULL || *filename == '\0') | |
| 87 | 88 | return; | |
| 88 | 89 | ||
| 89 | − | if (access(filename, R_OK)) { | |
| 90 | + | if (access(filename, R_OK) < 0) { | |
| 90 | 91 | warn("could not open file: %s", filename); | |
| 91 | 92 | return; | |
| 92 | 93 | } | |
| @@ -97,7 +98,7 @@ void check_add_file(char *filename) { | |||
| 97 | 98 | } | |
| 98 | 99 | if (*filename != '/') { | |
| 99 | 100 | files[fileidx].path = absolute_path(filename); | |
| 100 | − | if (!files[fileidx].path) { | |
| 101 | + | if (files[fileidx].path == NULL) { | |
| 101 | 102 | warn("could not get absolute path of file: %s\n", filename); | |
| 102 | 103 | return; | |
| 103 | 104 | } | |
| @@ -173,7 +174,7 @@ bool check_timeouts(struct timeval *t) { | |||
| 173 | 174 | tdiff = tv_diff(&timeouts[i].when, &now); | |
| 174 | 175 | if (tdiff <= 0) { | |
| 175 | 176 | timeouts[i].active = false; | |
| 176 | − | if (timeouts[i].handler) | |
| 177 | + | if (timeouts[i].handler != NULL) | |
| 177 | 178 | timeouts[i].handler(); | |
| 178 | 179 | i = tmin = -1; | |
| 179 | 180 | } else if (tmin < 0 || tdiff < tmin) { | |
| @@ -182,7 +183,7 @@ bool check_timeouts(struct timeval *t) { | |||
| 182 | 183 | } | |
| 183 | 184 | i++; | |
| 184 | 185 | } | |
| 185 | − | if (tmin > 0 && t) | |
| 186 | + | if (tmin > 0 && t != NULL) | |
| 186 | 187 | tv_set_msec(t, tmin); | |
| 187 | 188 | return tmin > 0; | |
| 188 | 189 | } | |
| @@ -204,12 +205,12 @@ void load_image(int new) { | |||
| 204 | 205 | ||
| 205 | 206 | files[new].loaded = true; | |
| 206 | 207 | fileidx = new; | |
| 207 | − | if (!stat(files[new].path, &fstats)) | |
| 208 | + | if (stat(files[new].path, &fstats) == 0) | |
| 208 | 209 | filesize = fstats.st_size; | |
| 209 | 210 | else | |
| 210 | 211 | filesize = 0; | |
| 211 | 212 | ||
| 212 | − | if (img.multi.cnt && img.multi.animate) | |
| 213 | + | if (img.multi.cnt > 0 && img.multi.animate) | |
| 213 | 214 | set_timeout(animate, img.multi.frames[img.multi.sel].delay, true); | |
| 214 | 215 | else | |
| 215 | 216 | reset_timeout(animate); | |
| @@ -238,7 +239,7 @@ void update_title() { | |||
| 238 | 239 | } else { | |
| 239 | 240 | sshow_info[0] = '\0'; | |
| 240 | 241 | } | |
| 241 | − | if (img.multi.cnt) | |
| 242 | + | if (img.multi.cnt > 0) | |
| 242 | 243 | snprintf(frame_info, sizeof(frame_info), "{%d/%d} ", | |
| 243 | 244 | img.multi.sel + 1, img.multi.cnt); | |
| 244 | 245 | else | |
| @@ -329,14 +330,14 @@ void on_keypress(XKeyEvent *kev) { | |||
| 329 | 330 | KeySym ksym; | |
| 330 | 331 | char key; | |
| 331 | 332 | ||
| 332 | − | if (!kev) | |
| 333 | + | if (kev == NULL) | |
| 333 | 334 | return; | |
| 334 | 335 | ||
| 335 | 336 | XLookupString(kev, &key, 1, &ksym, NULL); | |
| 336 | 337 | ||
| 337 | 338 | for (i = 0; i < ARRLEN(keys); i++) { | |
| 338 | 339 | 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)) | |
| 340 | 341 | redraw(); | |
| 341 | 342 | return; | |
| 342 | 343 | } | |
| @@ -346,7 +347,7 @@ void on_keypress(XKeyEvent *kev) { | |||
| 346 | 347 | void on_buttonpress(XButtonEvent *bev) { | |
| 347 | 348 | int i, sel; | |
| 348 | 349 | ||
| 349 | − | if (!bev) | |
| 350 | + | if (bev == NULL) | |
| 350 | 351 | return; | |
| 351 | 352 | ||
| 352 | 353 | if (mode == MODE_IMAGE) { | |
| @@ -357,7 +358,7 @@ void on_buttonpress(XButtonEvent *bev) { | |||
| 357 | 358 | if (buttons[i].button == bev->button && | |
| 358 | 359 | buttonmask(&buttons[i], bev->state)) | |
| 359 | 360 | { | |
| 360 | − | if (buttons[i].cmd && buttons[i].cmd(buttons[i].arg)) | |
| 361 | + | if (buttons[i].cmd != NULL && buttons[i].cmd(buttons[i].arg)) | |
| 361 | 362 | redraw(); | |
| 362 | 363 | return; | |
| 363 | 364 | } | |
| @@ -397,9 +398,9 @@ void run() { | |||
| 397 | 398 | ||
| 398 | 399 | redraw(); | |
| 399 | 400 | ||
| 400 | − | while (1) { | |
| 401 | + | while (true) { | |
| 401 | 402 | while (mode == MODE_THUMB && tns.cnt < filecnt && | |
| 402 | − | !XPending(win.env.dpy)) | |
| 403 | + | XPending(win.env.dpy) == 0) | |
| 403 | 404 | { | |
| 404 | 405 | /* load thumbnails */ | |
| 405 | 406 | set_timeout(redraw, TO_REDRAW_THUMBS, false); | |
| @@ -413,7 +414,7 @@ void run() { | |||
| 413 | 414 | check_timeouts(NULL); | |
| 414 | 415 | } | |
| 415 | 416 | ||
| 416 | − | while (!XPending(win.env.dpy) && check_timeouts(&timeout)) { | |
| 417 | + | while (XPending(win.env.dpy) == 0 && check_timeouts(&timeout)) { | |
| 417 | 418 | /* wait for timeouts */ | |
| 418 | 419 | xfd = ConnectionNumber(win.env.dpy); | |
| 419 | 420 | FD_ZERO(&fds); | |
| @@ -421,35 +422,34 @@ void run() { | |||
| 421 | 422 | select(xfd + 1, &fds, 0, 0, &timeout); | |
| 422 | 423 | } | |
| 423 | 424 | ||
| 424 | − | if (!XNextEvent(win.env.dpy, &ev)) { | |
| 425 | + | XNextEvent(win.env.dpy, &ev); | |
| 426 | + | switch (ev.type) { | |
| 425 | 427 | /* 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; | |
| 453 | 453 | } | |
| 454 | 454 | } | |
| 455 | 455 | } | |
| @@ -474,7 +474,7 @@ int main(int argc, char **argv) { | |||
| 474 | 474 | exit(EXIT_SUCCESS); | |
| 475 | 475 | } | |
| 476 | 476 | ||
| 477 | − | if (!options->filecnt) { | |
| 477 | + | if (options->filecnt == 0) { | |
| 478 | 478 | print_usage(); | |
| 479 | 479 | exit(EXIT_FAILURE); | |
| 480 | 480 | } | |
| @@ -495,25 +495,29 @@ int main(int argc, char **argv) { | |||
| 495 | 495 | filename[len-1] = '\0'; | |
| 496 | 496 | check_add_file(filename); | |
| 497 | 497 | } | |
| 498 | − | if (filename) | |
| 498 | + | if (filename != NULL) | |
| 499 | 499 | free(filename); | |
| 500 | 500 | } else { | |
| 501 | 501 | for (i = 0; i < options->filecnt; i++) { | |
| 502 | 502 | filename = options->filenames[i]; | |
| 503 | 503 | ||
| 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)) { | |
| 505 | 509 | check_add_file(filename); | |
| 506 | 510 | } else { | |
| 507 | 511 | if (!options->recursive) { | |
| 508 | 512 | warn("ignoring directory: %s", filename); | |
| 509 | 513 | continue; | |
| 510 | 514 | } | |
| 511 | − | if (r_opendir(&dir, filename)) { | |
| 515 | + | if (r_opendir(&dir, filename) < 0) { | |
| 512 | 516 | warn("could not open directory: %s", filename); | |
| 513 | 517 | continue; | |
| 514 | 518 | } | |
| 515 | 519 | start = fileidx; | |
| 516 | − | while ((filename = r_readdir(&dir))) { | |
| 520 | + | while ((filename = r_readdir(&dir)) != NULL) { | |
| 517 | 521 | check_add_file(filename); | |
| 518 | 522 | free((void*) filename); | |
| 519 | 523 | } | |
| @@ -524,7 +528,7 @@ int main(int argc, char **argv) { | |||
| 524 | 528 | } | |
| 525 | 529 | } | |
| 526 | 530 | ||
| 527 | − | if (!fileidx) { | |
| 531 | + | if (fileidx == 0) { | |
| 528 | 532 | fprintf(stderr, "sxiv: no valid image file given, aborting\n"); | |
| 529 | 533 | exit(EXIT_FAILURE); | |
| 530 | 534 | } | |
| @@ -548,7 +552,7 @@ int main(int argc, char **argv) { | |||
| 548 | 552 | } | |
| 549 | 553 | ||
| 550 | 554 | win_open(&win); | |
| 551 | − | ||
| 555 | + | ||
| 552 | 556 | run(); | |
| 553 | 557 | cleanup(); | |
| 554 | 558 | ||
| @@ -95,7 +95,7 @@ void parse_options(int argc, char **argv) { | |||
| 95 | 95 | print_usage(); | |
| 96 | 96 | exit(EXIT_SUCCESS); | |
| 97 | 97 | case 'n': | |
| 98 | − | if (!sscanf(optarg, "%d", &t) || t < 1) { | |
| 98 | + | if (sscanf(optarg, "%d", &t) <= 0 || t < 1) { | |
| 99 | 99 | fprintf(stderr, "sxiv: invalid argument for option -n: %s\n", | |
| 100 | 100 | optarg); | |
| 101 | 101 | exit(EXIT_FAILURE); | |
| @@ -127,7 +127,7 @@ void parse_options(int argc, char **argv) { | |||
| 127 | 127 | break; | |
| 128 | 128 | case 'z': | |
| 129 | 129 | _options.scalemode = SCALE_ZOOM; | |
| 130 | − | if (!sscanf(optarg, "%d", &t) || t <= 0) { | |
| 130 | + | if (sscanf(optarg, "%d", &t) <= 0 || t <= 0) { | |
| 131 | 131 | fprintf(stderr, "sxiv: invalid argument for option -z: %s\n", | |
| 132 | 132 | optarg); | |
| 133 | 133 | exit(EXIT_FAILURE); | |
| @@ -41,23 +41,23 @@ char *cache_dir = NULL; | |||
| 41 | 41 | bool tns_cache_enabled() { | |
| 42 | 42 | struct stat stats; | |
| 43 | 43 | ||
| 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; | |
| 46 | 46 | } | |
| 47 | 47 | ||
| 48 | 48 | char* tns_cache_filepath(const char *filepath) { | |
| 49 | 49 | size_t len; | |
| 50 | 50 | char *cfile = NULL; | |
| 51 | 51 | ||
| 52 | − | if (!cache_dir || !filepath || *filepath != '/') | |
| 52 | + | if (cache_dir == NULL || filepath == NULL || *filepath != '/') | |
| 53 | 53 | return NULL; | |
| 54 | 54 | ||
| 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! */ | |
| 56 | 57 | len = strlen(cache_dir) + strlen(filepath) + 6; | |
| 57 | 58 | cfile = (char*) s_malloc(len); | |
| 58 | 59 | snprintf(cfile, len, "%s/%s.png", cache_dir, filepath + 1); | |
| 59 | 60 | } | |
| 60 | − | ||
| 61 | 61 | return cfile; | |
| 62 | 62 | } | |
| 63 | 63 | ||
| @@ -66,18 +66,16 @@ Imlib_Image* tns_cache_load(const char *filepath) { | |||
| 66 | 66 | struct stat cstats, fstats; | |
| 67 | 67 | Imlib_Image *im = NULL; | |
| 68 | 68 | ||
| 69 | − | if (!filepath) | |
| 69 | + | if (filepath == NULL) | |
| 70 | 70 | return NULL; | |
| 71 | − | ||
| 72 | − | if (stat(filepath, &fstats)) | |
| 71 | + | if (stat(filepath, &fstats) < 0) | |
| 73 | 72 | return NULL; | |
| 74 | 73 | ||
| 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) | |
| 77 | 76 | im = imlib_load_image(cfile); | |
| 78 | 77 | free(cfile); | |
| 79 | 78 | } | |
| 80 | − | ||
| 81 | 79 | return im; | |
| 82 | 80 | } | |
| 83 | 81 | ||
| @@ -87,32 +85,35 @@ void tns_cache_write(thumb_t *t, bool force) { | |||
| 87 | 85 | struct utimbuf times; | |
| 88 | 86 | Imlib_Load_Error err = 0; | |
| 89 | 87 | ||
| 90 | − | if (!t || !t->im || !t->file || !t->file->name || !t->file->path) | |
| 88 | + | if (t == NULL || t->im == NULL) | |
| 91 | 89 | 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) | |
| 94 | 93 | return; | |
| 95 | 94 | ||
| 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) { | |
| 99 | 100 | *dirend = '\0'; | |
| 100 | 101 | err = r_mkdir(cfile); | |
| 101 | 102 | *dirend = '/'; | |
| 102 | 103 | } | |
| 103 | 104 | ||
| 104 | − | if (!err) { | |
| 105 | + | if (err == 0) { | |
| 105 | 106 | imlib_context_set_image(t->im); | |
| 106 | 107 | imlib_image_set_format("png"); | |
| 107 | 108 | imlib_save_image_with_error_return(cfile, &err); | |
| 108 | 109 | } | |
| 109 | 110 | ||
| 110 | − | if (err) { | |
| 111 | − | warn("could not cache thumbnail: %s", t->file->name); | |
| 112 | − | } else { | |
| 111 | + | if (err == 0) { | |
| 113 | 112 | times.actime = fstats.st_atime; | |
| 114 | 113 | times.modtime = fstats.st_mtime; | |
| 115 | 114 | utime(cfile, ×); | |
| 115 | + | } else { | |
| 116 | + | warn("could not cache thumbnail: %s", t->file->name); | |
| 116 | 117 | } | |
| 117 | 118 | } | |
| 118 | 119 | free(cfile); | |
| @@ -125,33 +126,32 @@ void tns_clean_cache(tns_t *tns) { | |||
| 125 | 126 | char *cfile, *filename, *tpos; | |
| 126 | 127 | r_dir_t dir; | |
| 127 | 128 | ||
| 128 | − | if (!cache_dir) | |
| 129 | + | if (cache_dir == NULL) | |
| 129 | 130 | return; | |
| 130 | 131 | ||
| 131 | − | if (r_opendir(&dir, cache_dir)) { | |
| 132 | + | if (r_opendir(&dir, cache_dir) < 0) { | |
| 132 | 133 | warn("could not open thumbnail cache directory: %s", cache_dir); | |
| 133 | 134 | return; | |
| 134 | 135 | } | |
| 135 | 136 | ||
| 136 | 137 | dirlen = strlen(cache_dir); | |
| 137 | 138 | ||
| 138 | − | while ((cfile = r_readdir(&dir))) { | |
| 139 | + | while ((cfile = r_readdir(&dir)) != NULL) { | |
| 139 | 140 | filename = cfile + dirlen; | |
| 140 | 141 | delete = false; | |
| 141 | 142 | ||
| 142 | − | if ((tpos = strrchr(filename, '.'))) { | |
| 143 | + | if ((tpos = strrchr(filename, '.')) != NULL) { | |
| 143 | 144 | *tpos = '\0'; | |
| 144 | − | if (access(filename, F_OK)) | |
| 145 | + | if (access(filename, F_OK) < 0) | |
| 145 | 146 | delete = true; | |
| 146 | 147 | *tpos = '.'; | |
| 147 | 148 | } | |
| 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 | + | } | |
| 152 | 153 | free(cfile); | |
| 153 | 154 | } | |
| 154 | − | ||
| 155 | 155 | r_closedir(&dir); | |
| 156 | 156 | } | |
| 157 | 157 | ||
| @@ -160,10 +160,10 @@ void tns_init(tns_t *tns, int cnt, win_t *win) { | |||
| 160 | 160 | int len; | |
| 161 | 161 | char *homedir; | |
| 162 | 162 | ||
| 163 | − | if (!tns) | |
| 163 | + | if (tns == NULL) | |
| 164 | 164 | return; | |
| 165 | 165 | ||
| 166 | − | if (cnt) { | |
| 166 | + | if (cnt > 0) { | |
| 167 | 167 | tns->thumbs = (thumb_t*) s_malloc(cnt * sizeof(thumb_t)); | |
| 168 | 168 | memset(tns->thumbs, 0, cnt * sizeof(thumb_t)); | |
| 169 | 169 | } else { | |
| @@ -176,8 +176,8 @@ void tns_init(tns_t *tns, int cnt, win_t *win) { | |||
| 176 | 176 | tns->alpha = true; | |
| 177 | 177 | tns->dirty = false; | |
| 178 | 178 | ||
| 179 | − | if ((homedir = getenv("HOME"))) { | |
| 180 | − | if (cache_dir) | |
| 179 | + | if ((homedir = getenv("HOME")) != NULL) { | |
| 180 | + | if (cache_dir != NULL) | |
| 181 | 181 | free(cache_dir); | |
| 182 | 182 | len = strlen(homedir) + 10; | |
| 183 | 183 | cache_dir = (char*) s_malloc(len * sizeof(char)); | |
| @@ -190,12 +190,12 @@ void tns_init(tns_t *tns, int cnt, win_t *win) { | |||
| 190 | 190 | void tns_free(tns_t *tns) { | |
| 191 | 191 | int i; | |
| 192 | 192 | ||
| 193 | − | if (!tns) | |
| 193 | + | if (tns != NULL) | |
| 194 | 194 | return; | |
| 195 | 195 | ||
| 196 | − | if (tns->thumbs) { | |
| 196 | + | if (tns->thumbs != NULL) { | |
| 197 | 197 | for (i = 0; i < tns->cnt; i++) { | |
| 198 | − | if (tns->thumbs[i].im) { | |
| 198 | + | if (tns->thumbs[i].im != NULL) { | |
| 199 | 199 | imlib_context_set_image(tns->thumbs[i].im); | |
| 200 | 200 | imlib_free_image(); | |
| 201 | 201 | } | |
| @@ -204,7 +204,7 @@ void tns_free(tns_t *tns) { | |||
| 204 | 204 | tns->thumbs = NULL; | |
| 205 | 205 | } | |
| 206 | 206 | ||
| 207 | − | if (cache_dir) { | |
| 207 | + | if (cache_dir != NULL) { | |
| 208 | 208 | free(cache_dir); | |
| 209 | 209 | cache_dir = NULL; | |
| 210 | 210 | } | |
| @@ -220,31 +220,34 @@ bool tns_load(tns_t *tns, int n, const fileinfo_t *file, | |||
| 220 | 220 | Imlib_Image *im; | |
| 221 | 221 | const char *fmt; | |
| 222 | 222 | ||
| 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) | |
| 224 | 226 | return false; | |
| 225 | − | ||
| 226 | 227 | if (n < 0 || n >= tns->cap) | |
| 227 | 228 | return false; | |
| 228 | 229 | ||
| 229 | 230 | t = &tns->thumbs[n]; | |
| 230 | 231 | t->file = file; | |
| 231 | 232 | ||
| 232 | − | if (t->im) { | |
| 233 | + | if (t->im != NULL) { | |
| 233 | 234 | imlib_context_set_image(t->im); | |
| 234 | 235 | imlib_free_image(); | |
| 235 | 236 | } | |
| 236 | 237 | ||
| 237 | 238 | 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) | |
| 239 | 240 | cache_hit = true; | |
| 240 | 241 | } | |
| 241 | 242 | ||
| 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 | + | } | |
| 248 | 251 | } | |
| 249 | 252 | ||
| 250 | 253 | imlib_context_set_image(im); | |
| @@ -267,7 +270,8 @@ bool tns_load(tns_t *tns, int n, const fileinfo_t *file, | |||
| 267 | 270 | t->w = z * w; | |
| 268 | 271 | t->h = z * h; | |
| 269 | 272 | ||
| 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) | |
| 271 | 275 | die("could not allocate memory"); | |
| 272 | 276 | ||
| 273 | 277 | imlib_free_image_and_decache(); | |
| @@ -282,7 +286,7 @@ bool tns_load(tns_t *tns, int n, const fileinfo_t *file, | |||
| 282 | 286 | void tns_check_view(tns_t *tns, bool scrolled) { | |
| 283 | 287 | int r; | |
| 284 | 288 | ||
| 285 | − | if (!tns) | |
| 289 | + | if (tns == NULL) | |
| 286 | 290 | return; | |
| 287 | 291 | ||
| 288 | 292 | tns->first -= tns->first % tns->cols; | |
| @@ -311,7 +315,7 @@ void tns_render(tns_t *tns) { | |||
| 311 | 315 | win_t *win; | |
| 312 | 316 | int i, cnt, r, x, y; | |
| 313 | 317 | ||
| 314 | − | if (!tns || !tns->thumbs || !tns->win) | |
| 318 | + | if (tns == NULL || tns->thumbs == NULL || tns->win == NULL) | |
| 315 | 319 | return; | |
| 316 | 320 | if (!tns->dirty) | |
| 317 | 321 | return; | |
| @@ -345,7 +349,7 @@ void tns_render(tns_t *tns) { | |||
| 345 | 349 | t->y = y + (THUMB_SIZE - t->h) / 2; | |
| 346 | 350 | imlib_context_set_image(t->im); | |
| 347 | 351 | ||
| 348 | − | if (imlib_image_has_alpha() && !tns->alpha) | |
| 352 | + | if (!tns->alpha && imlib_image_has_alpha()) | |
| 349 | 353 | win_draw_rect(win, win->pm, t->x, t->y, t->w, t->h, true, 0, win->white); | |
| 350 | 354 | ||
| 351 | 355 | imlib_render_image_part_on_drawable_at_size(0, 0, t->w, t->h, | |
| @@ -357,7 +361,6 @@ void tns_render(tns_t *tns) { | |||
| 357 | 361 | x += thumb_dim; | |
| 358 | 362 | } | |
| 359 | 363 | } | |
| 360 | − | ||
| 361 | 364 | tns->dirty = false; | |
| 362 | 365 | tns_highlight(tns, tns->sel, true); | |
| 363 | 366 | } | |
| @@ -368,7 +371,7 @@ void tns_highlight(tns_t *tns, int n, bool hl) { | |||
| 368 | 371 | int x, y; | |
| 369 | 372 | unsigned long col; | |
| 370 | 373 | ||
| 371 | − | if (!tns || !tns->thumbs || !tns->win) | |
| 374 | + | if (tns == NULL || tns->thumbs == NULL || tns->win == NULL) | |
| 372 | 375 | return; | |
| 373 | 376 | ||
| 374 | 377 | win = tns->win; | |
| @@ -388,14 +391,13 @@ void tns_highlight(tns_t *tns, int n, bool hl) { | |||
| 388 | 391 | win_draw_rect(win, win->pm, x - 3, y - 3, THUMB_SIZE + 6, THUMB_SIZE + 6, | |
| 389 | 392 | false, 2, col); | |
| 390 | 393 | } | |
| 391 | − | ||
| 392 | 394 | win_draw(win); | |
| 393 | 395 | } | |
| 394 | 396 | ||
| 395 | 397 | bool tns_move_selection(tns_t *tns, direction_t dir) { | |
| 396 | 398 | int old; | |
| 397 | 399 | ||
| 398 | − | if (!tns || !tns->thumbs) | |
| 400 | + | if (tns == NULL || tns->thumbs == NULL) | |
| 399 | 401 | return false; | |
| 400 | 402 | ||
| 401 | 403 | old = tns->sel; | |
| @@ -425,14 +427,13 @@ bool tns_move_selection(tns_t *tns, direction_t dir) { | |||
| 425 | 427 | if (!tns->dirty) | |
| 426 | 428 | tns_highlight(tns, tns->sel, true); | |
| 427 | 429 | } | |
| 428 | − | ||
| 429 | 430 | return tns->sel != old; | |
| 430 | 431 | } | |
| 431 | 432 | ||
| 432 | 433 | bool tns_scroll(tns_t *tns, direction_t dir) { | |
| 433 | 434 | int old; | |
| 434 | 435 | ||
| 435 | − | if (!tns) | |
| 436 | + | if (tns == NULL) | |
| 436 | 437 | return false; | |
| 437 | 438 | ||
| 438 | 439 | old = tns->first; | |
| @@ -446,16 +447,14 @@ bool tns_scroll(tns_t *tns, direction_t dir) { | |||
| 446 | 447 | tns_check_view(tns, true); | |
| 447 | 448 | tns->dirty = true; | |
| 448 | 449 | } | |
| 449 | − | ||
| 450 | 450 | return tns->first != old; | |
| 451 | 451 | } | |
| 452 | 452 | ||
| 453 | 453 | int tns_translate(tns_t *tns, int x, int y) { | |
| 454 | 454 | int n; | |
| 455 | 455 | ||
| 456 | − | if (!tns || !tns->thumbs) | |
| 456 | + | if (tns == NULL || tns->thumbs == NULL) | |
| 457 | 457 | return -1; | |
| 458 | − | ||
| 459 | 458 | if (x < tns->x || y < tns->y) | |
| 460 | 459 | return -1; | |
| 461 | 460 | ||
| @@ -39,13 +39,15 @@ void cleanup(); | |||
| 39 | 39 | void* s_malloc(size_t size) { | |
| 40 | 40 | void *ptr; | |
| 41 | 41 | ||
| 42 | − | if (!(ptr = malloc(size))) | |
| 42 | + | ptr = malloc(size); | |
| 43 | + | if (ptr == NULL) | |
| 43 | 44 | die("could not allocate memory"); | |
| 44 | 45 | return ptr; | |
| 45 | 46 | } | |
| 46 | 47 | ||
| 47 | 48 | void* s_realloc(void *ptr, size_t size) { | |
| 48 | − | if (!(ptr = realloc(ptr, size))) | |
| 49 | + | ptr = realloc(ptr, size); | |
| 50 | + | if (ptr == NULL) | |
| 49 | 51 | die("could not allocate memory"); | |
| 50 | 52 | return ptr; | |
| 51 | 53 | } | |
| @@ -53,8 +55,9 @@ void* s_realloc(void *ptr, size_t size) { | |||
| 53 | 55 | char* s_strdup(char *s) { | |
| 54 | 56 | char *d = NULL; | |
| 55 | 57 | ||
| 56 | − | if (s) { | |
| 57 | − | if (!(d = malloc(strlen(s) + 1))) | |
| 58 | + | if (s != NULL) { | |
| 59 | + | d = malloc(strlen(s) + 1); | |
| 60 | + | if (d == NULL) | |
| 58 | 61 | die("could not allocate memory"); | |
| 59 | 62 | strcpy(d, s); | |
| 60 | 63 | } | |
| @@ -64,7 +67,7 @@ char* s_strdup(char *s) { | |||
| 64 | 67 | void warn(const char* fmt, ...) { | |
| 65 | 68 | va_list args; | |
| 66 | 69 | ||
| 67 | − | if (!fmt || options->quiet) | |
| 70 | + | if (fmt == NULL || options->quiet) | |
| 68 | 71 | return; | |
| 69 | 72 | ||
| 70 | 73 | va_start(args, fmt); | |
| @@ -77,7 +80,7 @@ void warn(const char* fmt, ...) { | |||
| 77 | 80 | void die(const char* fmt, ...) { | |
| 78 | 81 | va_list args; | |
| 79 | 82 | ||
| 80 | − | if (!fmt) | |
| 83 | + | if (fmt == NULL) | |
| 81 | 84 | return; | |
| 82 | 85 | ||
| 83 | 86 | va_start(args, fmt); | |
| @@ -94,17 +97,17 @@ ssize_t get_line(char **buf, size_t *n, FILE *stream) { | |||
| 94 | 97 | size_t len; | |
| 95 | 98 | char *s; | |
| 96 | 99 | ||
| 97 | − | if (!stream || feof(stream) || ferror(stream)) | |
| 100 | + | if (stream == NULL || feof(stream) || ferror(stream)) | |
| 98 | 101 | return -1; | |
| 99 | 102 | ||
| 100 | − | if (!*buf || !*n) { | |
| 103 | + | if (*buf == NULL || *n == 0) { | |
| 101 | 104 | *n = BUF_SIZE; | |
| 102 | 105 | *buf = (char*) s_malloc(*n); | |
| 103 | 106 | } | |
| 104 | 107 | s = *buf; | |
| 105 | 108 | ||
| 106 | − | while (1) { | |
| 107 | − | if (!fgets(s, *n - (s - *buf), stream)) | |
| 109 | + | while (true) { | |
| 110 | + | if (fgets(s, *n - (s - *buf), stream) == NULL) | |
| 108 | 111 | return -1; | |
| 109 | 112 | len = strlen(s); | |
| 110 | 113 | if (feof(stream)) | |
| @@ -119,7 +122,6 @@ ssize_t get_line(char **buf, size_t *n, FILE *stream) { | |||
| 119 | 122 | s += len; | |
| 120 | 123 | } | |
| 121 | 124 | } | |
| 122 | − | ||
| 123 | 125 | return s - *buf + len; | |
| 124 | 126 | } | |
| 125 | 127 | ||
| @@ -147,41 +149,41 @@ char* absolute_path(const char *filename) { | |||
| 147 | 149 | char *dir, *dirname = NULL, *path = NULL, *s; | |
| 148 | 150 | char *cwd = NULL, *twd = NULL; | |
| 149 | 151 | ||
| 150 | − | if (!filename || *filename == '\0' || *filename == '/') | |
| 152 | + | if (filename == NULL || *filename == '\0' || *filename == '/') | |
| 151 | 153 | return NULL; | |
| 152 | 154 | ||
| 153 | 155 | len = FNAME_LEN; | |
| 154 | 156 | cwd = (char*) s_malloc(len); | |
| 155 | − | while (!(s = getcwd(cwd, len)) && errno == ERANGE) { | |
| 157 | + | while ((s = getcwd(cwd, len)) == NULL && errno == ERANGE) { | |
| 156 | 158 | len *= 2; | |
| 157 | 159 | cwd = (char*) s_realloc(cwd, len); | |
| 158 | 160 | } | |
| 159 | − | if (!s) | |
| 161 | + | if (s == NULL) | |
| 160 | 162 | goto error; | |
| 161 | 163 | ||
| 162 | 164 | s = strrchr(filename, '/'); | |
| 163 | − | if (s) { | |
| 165 | + | if (s != NULL) { | |
| 164 | 166 | len = s - filename; | |
| 165 | 167 | dirname = (char*) s_malloc(len + 1); | |
| 166 | 168 | strncpy(dirname, filename, len); | |
| 167 | 169 | dirname[len] = '\0'; | |
| 168 | 170 | basename = s + 1; | |
| 169 | 171 | ||
| 170 | − | if (chdir(cwd)) | |
| 172 | + | if (chdir(cwd) < 0) | |
| 171 | 173 | /* we're not able to come back afterwards */ | |
| 172 | 174 | goto error; | |
| 173 | − | if (chdir(dirname)) | |
| 175 | + | if (chdir(dirname) < 0) | |
| 174 | 176 | goto error; | |
| 175 | 177 | ||
| 176 | 178 | len = FNAME_LEN; | |
| 177 | 179 | twd = (char*) s_malloc(len); | |
| 178 | − | while (!(s = getcwd(twd, len)) && errno == ERANGE) { | |
| 180 | + | while ((s = getcwd(twd, len)) == NULL && errno == ERANGE) { | |
| 179 | 181 | len *= 2; | |
| 180 | 182 | twd = (char*) s_realloc(twd, len); | |
| 181 | 183 | } | |
| 182 | − | if (chdir(cwd)) | |
| 184 | + | if (chdir(cwd) < 0) | |
| 183 | 185 | die("could not revert to prior working directory"); | |
| 184 | − | if (!s) | |
| 186 | + | if (s == NULL) | |
| 185 | 187 | goto error; | |
| 186 | 188 | dir = twd; | |
| 187 | 189 | } else { | |
| @@ -197,27 +199,27 @@ char* absolute_path(const char *filename) { | |||
| 197 | 199 | goto end; | |
| 198 | 200 | ||
| 199 | 201 | error: | |
| 200 | − | if (path) { | |
| 202 | + | if (path != NULL) { | |
| 201 | 203 | free(path); | |
| 202 | 204 | path = NULL; | |
| 203 | 205 | } | |
| 204 | 206 | ||
| 205 | 207 | end: | |
| 206 | − | if (dirname) | |
| 208 | + | if (dirname != NULL) | |
| 207 | 209 | free(dirname); | |
| 208 | − | if (cwd) | |
| 210 | + | if (cwd != NULL) | |
| 209 | 211 | free(cwd); | |
| 210 | − | if (twd) | |
| 212 | + | if (twd != NULL) | |
| 211 | 213 | free(twd); | |
| 212 | 214 | ||
| 213 | 215 | return path; | |
| 214 | 216 | } | |
| 215 | 217 | ||
| 216 | 218 | int r_opendir(r_dir_t *rdir, const char *dirname) { | |
| 217 | − | if (!rdir || !dirname || !*dirname) | |
| 219 | + | if (rdir == NULL || dirname == NULL || *dirname == '\0') | |
| 218 | 220 | return -1; | |
| 219 | 221 | ||
| 220 | − | if (!(rdir->dir = opendir(dirname))) { | |
| 222 | + | if ((rdir->dir = opendir(dirname)) == NULL) { | |
| 221 | 223 | rdir->name = NULL; | |
| 222 | 224 | rdir->stack = NULL; | |
| 223 | 225 | return -1; | |
| @@ -236,22 +238,22 @@ int r_opendir(r_dir_t *rdir, const char *dirname) { | |||
| 236 | 238 | int r_closedir(r_dir_t *rdir) { | |
| 237 | 239 | int ret = 0; | |
| 238 | 240 | ||
| 239 | − | if (!rdir) | |
| 241 | + | if (rdir == NULL) | |
| 240 | 242 | return -1; | |
| 241 | 243 | ||
| 242 | − | if (rdir->stack) { | |
| 244 | + | if (rdir->stack != NULL) { | |
| 243 | 245 | while (rdir->stlen > 0) | |
| 244 | 246 | free(rdir->stack[--rdir->stlen]); | |
| 245 | 247 | free(rdir->stack); | |
| 246 | 248 | rdir->stack = NULL; | |
| 247 | 249 | } | |
| 248 | 250 | ||
| 249 | − | if (rdir->dir) { | |
| 250 | − | if (!(ret = closedir(rdir->dir))) | |
| 251 | + | if (rdir->dir != NULL) { | |
| 252 | + | if ((ret = closedir(rdir->dir)) == 0) | |
| 251 | 253 | rdir->dir = NULL; | |
| 252 | 254 | } | |
| 253 | 255 | ||
| 254 | − | if (rdir->d && rdir->name) { | |
| 256 | + | if (rdir->d != 0 && rdir->name != NULL) { | |
| 255 | 257 | free(rdir->name); | |
| 256 | 258 | rdir->name = NULL; | |
| 257 | 259 | } | |
| @@ -265,11 +267,11 @@ char* r_readdir(r_dir_t *rdir) { | |||
| 265 | 267 | struct dirent *dentry; | |
| 266 | 268 | struct stat fstats; | |
| 267 | 269 | ||
| 268 | − | if (!rdir || !rdir->dir || !rdir->name) | |
| 270 | + | if (rdir == NULL || rdir->dir == NULL || rdir->name == NULL) | |
| 269 | 271 | return NULL; | |
| 270 | 272 | ||
| 271 | − | while (1) { | |
| 272 | − | if (rdir->dir && (dentry = readdir(rdir->dir))) { | |
| 273 | + | while (true) { | |
| 274 | + | if (rdir->dir != NULL && (dentry = readdir(rdir->dir)) != NULL) { | |
| 273 | 275 | if (streq(dentry->d_name, ".") || streq(dentry->d_name, "..")) | |
| 274 | 276 | continue; | |
| 275 | 277 | ||
| @@ -279,7 +281,9 @@ char* r_readdir(r_dir_t *rdir) { | |||
| 279 | 281 | rdir->name[strlen(rdir->name)-1] == '/' ? "" : "/", | |
| 280 | 282 | dentry->d_name); | |
| 281 | 283 | ||
| 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)) { | |
| 283 | 287 | /* put subdirectory on the stack */ | |
| 284 | 288 | if (rdir->stlen == rdir->stcap) { | |
| 285 | 289 | rdir->stcap *= 2; | |
| @@ -295,19 +299,17 @@ char* r_readdir(r_dir_t *rdir) { | |||
| 295 | 299 | if (rdir->stlen > 0) { | |
| 296 | 300 | /* open next subdirectory */ | |
| 297 | 301 | closedir(rdir->dir); | |
| 298 | − | if (rdir->d) | |
| 302 | + | if (rdir->d != 0) | |
| 299 | 303 | free(rdir->name); | |
| 300 | 304 | rdir->name = rdir->stack[--rdir->stlen]; | |
| 301 | 305 | rdir->d = 1; | |
| 302 | − | if (!(rdir->dir = opendir(rdir->name))) | |
| 306 | + | if ((rdir->dir = opendir(rdir->name)) == NULL) | |
| 303 | 307 | warn("could not open directory: %s", rdir->name); | |
| 304 | 308 | continue; | |
| 305 | 309 | } | |
| 306 | − | ||
| 307 | 310 | /* no more entries */ | |
| 308 | 311 | break; | |
| 309 | 312 | } | |
| 310 | − | ||
| 311 | 313 | return NULL; | |
| 312 | 314 | } | |
| 313 | 315 | ||
| @@ -316,10 +318,10 @@ int r_mkdir(const char *path) { | |||
| 316 | 318 | struct stat stats; | |
| 317 | 319 | int err = 0; | |
| 318 | 320 | ||
| 319 | − | if (!path || !*path) | |
| 321 | + | if (path == NULL || *path == '\0') | |
| 320 | 322 | return -1; | |
| 321 | 323 | ||
| 322 | − | if (!stat(path, &stats)) { | |
| 324 | + | if (stat(path, &stats) == 0) { | |
| 323 | 325 | if (S_ISDIR(stats.st_mode)) { | |
| 324 | 326 | return 0; | |
| 325 | 327 | } else { | |
| @@ -331,16 +333,16 @@ int r_mkdir(const char *path) { | |||
| 331 | 333 | d = dir = (char*) s_malloc(strlen(path) + 1); | |
| 332 | 334 | strcpy(dir, path); | |
| 333 | 335 | ||
| 334 | − | while (d != NULL && !err) { | |
| 336 | + | while (d != NULL && err == 0) { | |
| 335 | 337 | d = strchr(d + 1, '/'); | |
| 336 | 338 | if (d != NULL) | |
| 337 | 339 | *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) { | |
| 340 | 342 | warn("could not create directory: %s", dir); | |
| 341 | 343 | err = -1; | |
| 342 | 344 | } | |
| 343 | − | } else if (stat(dir, &stats) || !S_ISDIR(stats.st_mode)) { | |
| 345 | + | } else if (stat(dir, &stats) < 0 || !S_ISDIR(stats.st_mode)) { | |
| 344 | 346 | warn("not a directory: %s", dir); | |
| 345 | 347 | err = -1; | |
| 346 | 348 | } | |
| @@ -40,11 +40,11 @@ void win_init(win_t *win) { | |||
| 40 | 40 | win_env_t *e; | |
| 41 | 41 | XColor col; | |
| 42 | 42 | ||
| 43 | − | if (!win) | |
| 43 | + | if (win == NULL) | |
| 44 | 44 | return; | |
| 45 | 45 | ||
| 46 | 46 | e = &win->env; | |
| 47 | − | if (!(e->dpy = XOpenDisplay(NULL))) | |
| 47 | + | if ((e->dpy = XOpenDisplay(NULL)) == NULL) | |
| 48 | 48 | die("could not open display"); | |
| 49 | 49 | ||
| 50 | 50 | e->scr = DefaultScreen(e->dpy); | |
| @@ -58,7 +58,7 @@ void win_init(win_t *win) { | |||
| 58 | 58 | win->white = WhitePixel(e->dpy, e->scr); | |
| 59 | 59 | ||
| 60 | 60 | if (XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), BG_COLOR, | |
| 61 | − | &col, &col)) | |
| 61 | + | &col, &col) != 0) | |
| 62 | 62 | { | |
| 63 | 63 | win->bgcol = col.pixel; | |
| 64 | 64 | } else { | |
| @@ -66,7 +66,7 @@ void win_init(win_t *win) { | |||
| 66 | 66 | } | |
| 67 | 67 | ||
| 68 | 68 | if (XAllocNamedColor(e->dpy, DefaultColormap(e->dpy, e->scr), SEL_COLOR, | |
| 69 | − | &col, &col)) | |
| 69 | + | &col, &col) != 0) | |
| 70 | 70 | { | |
| 71 | 71 | win->selcol = col.pixel; | |
| 72 | 72 | } else { | |
| @@ -81,7 +81,7 @@ void win_init(win_t *win) { | |||
| 81 | 81 | void win_set_sizehints(win_t *win) { | |
| 82 | 82 | XSizeHints sizehints; | |
| 83 | 83 | ||
| 84 | − | if (!win || !win->xwin) | |
| 84 | + | if (win == NULL || win->xwin == None) | |
| 85 | 85 | return; | |
| 86 | 86 | ||
| 87 | 87 | sizehints.flags = PMinSize | PMaxSize; | |
| @@ -100,32 +100,32 @@ void win_open(win_t *win) { | |||
| 100 | 100 | Pixmap none; | |
| 101 | 101 | int gmask; | |
| 102 | 102 | ||
| 103 | − | if (!win) | |
| 103 | + | if (win == NULL) | |
| 104 | 104 | return; | |
| 105 | 105 | ||
| 106 | 106 | e = &win->env; | |
| 107 | 107 | ||
| 108 | 108 | /* determine window offsets, width & height */ | |
| 109 | − | if (!options->geometry) | |
| 109 | + | if (options->geometry == NULL) | |
| 110 | 110 | gmask = 0; | |
| 111 | 111 | else | |
| 112 | 112 | gmask = XParseGeometry(options->geometry, &win->x, &win->y, | |
| 113 | 113 | &win->w, &win->h); | |
| 114 | − | if (!(gmask & WidthValue)) | |
| 114 | + | if ((gmask & WidthValue) == 0) | |
| 115 | 115 | win->w = WIN_WIDTH; | |
| 116 | 116 | if (win->w > e->scrw) | |
| 117 | 117 | win->w = e->scrw; | |
| 118 | − | if (!(gmask & HeightValue)) | |
| 118 | + | if ((gmask & HeightValue) == 0) | |
| 119 | 119 | win->h = WIN_HEIGHT; | |
| 120 | 120 | if (win->h > e->scrh) | |
| 121 | 121 | win->h = e->scrh; | |
| 122 | − | if (!(gmask & XValue)) | |
| 122 | + | if ((gmask & XValue) == 0) | |
| 123 | 123 | win->x = (e->scrw - win->w) / 2; | |
| 124 | − | else if (gmask & XNegative) | |
| 124 | + | else if ((gmask & XNegative) != 0) | |
| 125 | 125 | win->x += e->scrw - win->w; | |
| 126 | − | if (!(gmask & YValue)) | |
| 126 | + | if ((gmask & YValue) == 0) | |
| 127 | 127 | win->y = (e->scrh - win->h) / 2; | |
| 128 | − | else if (gmask & YNegative) | |
| 128 | + | else if ((gmask & YNegative) != 0) | |
| 129 | 129 | win->y += e->scrh - win->h; | |
| 130 | 130 | ||
| 131 | 131 | win->xwin = XCreateWindow(e->dpy, RootWindow(e->dpy, e->scr), | |
| @@ -141,8 +141,8 @@ void win_open(win_t *win) { | |||
| 141 | 141 | chand = XCreateFontCursor(e->dpy, XC_fleur); | |
| 142 | 142 | cwatch = XCreateFontCursor(e->dpy, XC_watch); | |
| 143 | 143 | ||
| 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) | |
| 146 | 146 | { | |
| 147 | 147 | die("could not allocate color: black"); | |
| 148 | 148 | } | |
| @@ -171,7 +171,7 @@ void win_open(win_t *win) { | |||
| 171 | 171 | } | |
| 172 | 172 | ||
| 173 | 173 | void win_close(win_t *win) { | |
| 174 | − | if (!win || !win->xwin) | |
| 174 | + | if (win == NULL || win->xwin == None) | |
| 175 | 175 | return; | |
| 176 | 176 | ||
| 177 | 177 | XFreeCursor(win->env.dpy, carrow); | |
| @@ -188,7 +188,7 @@ void win_close(win_t *win) { | |||
| 188 | 188 | bool win_configure(win_t *win, XConfigureEvent *c) { | |
| 189 | 189 | bool changed; | |
| 190 | 190 | ||
| 191 | − | if (!win) | |
| 191 | + | if (win == NULL) | |
| 192 | 192 | return false; | |
| 193 | 193 | ||
| 194 | 194 | changed = win->w != c->width || win->h != c->height; | |
| @@ -203,7 +203,7 @@ bool win_configure(win_t *win, XConfigureEvent *c) { | |||
| 203 | 203 | } | |
| 204 | 204 | ||
| 205 | 205 | 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) | |
| 207 | 207 | return false; | |
| 208 | 208 | ||
| 209 | 209 | x = MAX(0, x); | |
| @@ -231,7 +231,7 @@ void win_toggle_fullscreen(win_t *win) { | |||
| 231 | 231 | XEvent ev; | |
| 232 | 232 | XClientMessageEvent *cm; | |
| 233 | 233 | ||
| 234 | − | if (!win || !win->xwin) | |
| 234 | + | if (win == NULL || win->xwin == None) | |
| 235 | 235 | return; | |
| 236 | 236 | ||
| 237 | 237 | win->fullscreen = !win->fullscreen; | |
| @@ -255,13 +255,13 @@ void win_clear(win_t *win) { | |||
| 255 | 255 | win_env_t *e; | |
| 256 | 256 | XGCValues gcval; | |
| 257 | 257 | ||
| 258 | − | if (!win || !win->xwin) | |
| 258 | + | if (win == NULL || win->xwin == None) | |
| 259 | 259 | return; | |
| 260 | 260 | ||
| 261 | 261 | e = &win->env; | |
| 262 | 262 | gcval.foreground = win->fullscreen ? win->black : win->bgcol; | |
| 263 | 263 | ||
| 264 | − | if (win->pm) | |
| 264 | + | if (win->pm != None) | |
| 265 | 265 | XFreePixmap(e->dpy, win->pm); | |
| 266 | 266 | win->pm = XCreatePixmap(e->dpy, win->xwin, e->scrw, e->scrh, e->depth); | |
| 267 | 267 | ||
| @@ -270,7 +270,7 @@ void win_clear(win_t *win) { | |||
| 270 | 270 | } | |
| 271 | 271 | ||
| 272 | 272 | void win_draw(win_t *win) { | |
| 273 | − | if (!win || !win->xwin) | |
| 273 | + | if (win == NULL || win->xwin == None) | |
| 274 | 274 | return; | |
| 275 | 275 | ||
| 276 | 276 | 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, | |||
| 281 | 281 | bool fill, int lw, unsigned long col) { | |
| 282 | 282 | XGCValues gcval; | |
| 283 | 283 | ||
| 284 | − | if (!win || !pm) | |
| 284 | + | if (win == NULL || pm == None) | |
| 285 | 285 | return; | |
| 286 | 286 | ||
| 287 | 287 | 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, | |||
| 295 | 295 | } | |
| 296 | 296 | ||
| 297 | 297 | void win_set_title(win_t *win, const char *title) { | |
| 298 | − | if (!win || !win->xwin) | |
| 298 | + | if (win == NULL || win->xwin == None) | |
| 299 | 299 | return; | |
| 300 | 300 | ||
| 301 | − | if (!title) | |
| 301 | + | if (title == NULL) | |
| 302 | 302 | title = "sxiv"; | |
| 303 | 303 | ||
| 304 | 304 | XStoreName(win->env.dpy, win->xwin, title); | |
| @@ -315,7 +315,7 @@ void win_set_title(win_t *win, const char *title) { | |||
| 315 | 315 | } | |
| 316 | 316 | ||
| 317 | 317 | void win_set_cursor(win_t *win, cursor_t cursor) { | |
| 318 | − | if (!win || !win->xwin) | |
| 318 | + | if (win == NULL || win->xwin == None) | |
| 319 | 319 | return; | |
| 320 | 320 | ||
| 321 | 321 | switch (cursor) { | |