nsxivc627537
mark functions and vars as static (#146)
the goal here to mark functions and variables not used outside the
translation unit as static. main reason for this is cleanliness. however
as a side-effect this can help compilers optimize better as it now has
guarantee that a certain function won't be called outside of that
translation unit.
one other side-effect of this is that accessing these vars/function from
config.h is now different.
if one wants to access a static var/func from different translation unit
in config.h, he would have to create a wrapper function under the right
ifdef. for static functions one would also need to forward declare it.
here's a dummy example of accessing the function `run_key_handler` from
config.h under _MAPPINGS_CONFIG
```
static void run_key_handler(const char *, unsigned);
bool send_with_ctrl(arg_t key) {
run_key_handler(XKeysymToString(key), ControlMask);
return false;
}
```
+40 −41
7 files changed
- M autoreload_inotify.c +1 −1
- M image.c +7 −7
- M main.c +15 −15
- M nsxiv.h +0 −2
- M options.c +4 −3
- M thumbs.c +5 −5
- M window.c +8 −8
| @@ -24,7 +24,7 @@ | |||
| 24 | 24 | #include <unistd.h> | |
| 25 | 25 | #include <sys/inotify.h> | |
| 26 | 26 | ||
| 27 | − | union { | |
| 27 | + | static union { | |
| 28 | 28 | char d[4096]; /* aligned buffer */ | |
| 29 | 29 | struct inotify_event e; | |
| 30 | 30 | } buf; | |
| @@ -114,7 +114,7 @@ void exif_auto_orientate(const fileinfo_t *file) | |||
| 114 | 114 | #endif | |
| 115 | 115 | ||
| 116 | 116 | #if HAVE_LIBGIF | |
| 117 | − | bool img_load_gif(img_t *img, const fileinfo_t *file) | |
| 117 | + | static bool img_load_gif(img_t *img, const fileinfo_t *file) | |
| 118 | 118 | { | |
| 119 | 119 | GifFileType *gif; | |
| 120 | 120 | GifRowType *rows = NULL; | |
| @@ -295,7 +295,7 @@ bool img_load_gif(img_t *img, const fileinfo_t *file) | |||
| 295 | 295 | ||
| 296 | 296 | ||
| 297 | 297 | #if HAVE_LIBWEBP | |
| 298 | − | bool is_webp(const char *path) | |
| 298 | + | static bool is_webp(const char *path) | |
| 299 | 299 | { | |
| 300 | 300 | /* The size (in bytes) of the largest amount of data required to verify a WebP image. */ | |
| 301 | 301 | enum { max = 30 }; | |
| @@ -316,7 +316,7 @@ bool is_webp(const char *path) | |||
| 316 | 316 | * x NULL = load the first frame as an Imlib_Image | |
| 317 | 317 | * NULL x = load all frames into img->multi. | |
| 318 | 318 | */ | |
| 319 | − | bool img_load_webp(const fileinfo_t *file, Imlib_Image *fframe, img_t *img) | |
| 319 | + | static bool img_load_webp(const fileinfo_t *file, Imlib_Image *fframe, img_t *img) | |
| 320 | 320 | { | |
| 321 | 321 | FILE *webp_file; | |
| 322 | 322 | WebPData data; | |
| @@ -507,7 +507,7 @@ CLEANUP void img_close(img_t *img, bool decache) | |||
| 507 | 507 | } | |
| 508 | 508 | } | |
| 509 | 509 | ||
| 510 | − | void img_check_pan(img_t *img, bool moved) | |
| 510 | + | static void img_check_pan(img_t *img, bool moved) | |
| 511 | 511 | { | |
| 512 | 512 | win_t *win; | |
| 513 | 513 | float w, h, ox, oy; | |
| @@ -535,7 +535,7 @@ void img_check_pan(img_t *img, bool moved) | |||
| 535 | 535 | img->dirty = true; | |
| 536 | 536 | } | |
| 537 | 537 | ||
| 538 | − | bool img_fit(img_t *img) | |
| 538 | + | static bool img_fit(img_t *img) | |
| 539 | 539 | { | |
| 540 | 540 | float z, zw, zh; | |
| 541 | 541 | ||
| @@ -723,7 +723,7 @@ bool img_pos(img_t *img, float x, float y) | |||
| 723 | 723 | } | |
| 724 | 724 | } | |
| 725 | 725 | ||
| 726 | − | bool img_move(img_t *img, float dx, float dy) | |
| 726 | + | static bool img_move(img_t *img, float dx, float dy) | |
| 727 | 727 | { | |
| 728 | 728 | return img_pos(img, img->x + dx, img->y + dy); | |
| 729 | 729 | } | |
| @@ -873,7 +873,7 @@ bool img_change_gamma(img_t *img, int d) | |||
| 873 | 873 | } | |
| 874 | 874 | } | |
| 875 | 875 | ||
| 876 | − | bool img_frame_goto(img_t *img, int n) | |
| 876 | + | static bool img_frame_goto(img_t *img, int n) | |
| 877 | 877 | { | |
| 878 | 878 | if (n < 0 || n >= img->multi.cnt || n == img->multi.sel) | |
| 879 | 879 | return false; | |
| @@ -67,7 +67,7 @@ int markidx; | |||
| 67 | 67 | int prefix; | |
| 68 | 68 | bool extprefix; | |
| 69 | 69 | ||
| 70 | − | bool resized = false; | |
| 70 | + | static bool resized = false; | |
| 71 | 71 | ||
| 72 | 72 | typedef struct { | |
| 73 | 73 | int err; | |
| @@ -97,7 +97,7 @@ timeout_t timeouts[] = { | |||
| 97 | 97 | /************************** | |
| 98 | 98 | function implementations | |
| 99 | 99 | **************************/ | |
| 100 | − | void cleanup(void) | |
| 100 | + | static void cleanup(void) | |
| 101 | 101 | { | |
| 102 | 102 | img_close(&img, false); | |
| 103 | 103 | arl_cleanup(&arl); | |
| @@ -113,7 +113,7 @@ static bool xgetline(char **lineptr, size_t *n) | |||
| 113 | 113 | return len > 0; | |
| 114 | 114 | } | |
| 115 | 115 | ||
| 116 | − | void check_add_file(char *filename, bool given) | |
| 116 | + | static void check_add_file(char *filename, bool given) | |
| 117 | 117 | { | |
| 118 | 118 | char *path; | |
| 119 | 119 | ||
| @@ -203,7 +203,7 @@ void reset_timeout(timeout_f handler) | |||
| 203 | 203 | } | |
| 204 | 204 | } | |
| 205 | 205 | ||
| 206 | − | bool check_timeouts(struct timeval *t) | |
| 206 | + | static bool check_timeouts(struct timeval *t) | |
| 207 | 207 | { | |
| 208 | 208 | int i = 0, tdiff, tmin = -1; | |
| 209 | 209 | struct timeval now; | |
| @@ -265,7 +265,7 @@ void open_info(void) | |||
| 265 | 265 | } | |
| 266 | 266 | } | |
| 267 | 267 | ||
| 268 | − | void read_info(void) | |
| 268 | + | static void read_info(void) | |
| 269 | 269 | { | |
| 270 | 270 | ssize_t i, n; | |
| 271 | 271 | char buf[BAR_L_LEN]; | |
| @@ -347,7 +347,7 @@ bool mark_image(int n, bool on) | |||
| 347 | 347 | return false; | |
| 348 | 348 | } | |
| 349 | 349 | ||
| 350 | − | void bar_put(win_bar_t *bar, const char *fmt, ...) | |
| 350 | + | static void bar_put(win_bar_t *bar, const char *fmt, ...) | |
| 351 | 351 | { | |
| 352 | 352 | size_t len = bar->size - (bar->p - bar->buf), n; | |
| 353 | 353 | va_list ap; | |
| @@ -358,7 +358,7 @@ void bar_put(win_bar_t *bar, const char *fmt, ...) | |||
| 358 | 358 | va_end(ap); | |
| 359 | 359 | } | |
| 360 | 360 | ||
| 361 | − | void update_info(void) | |
| 361 | + | static void update_info(void) | |
| 362 | 362 | { | |
| 363 | 363 | unsigned int i, fn, fw; | |
| 364 | 364 | const char * mark; | |
| @@ -507,7 +507,7 @@ void handle_key_handler(bool init) | |||
| 507 | 507 | win_draw(&win); | |
| 508 | 508 | } | |
| 509 | 509 | ||
| 510 | − | void run_key_handler(const char *key, unsigned int mask) | |
| 510 | + | static void run_key_handler(const char *key, unsigned int mask) | |
| 511 | 511 | { | |
| 512 | 512 | pid_t pid; | |
| 513 | 513 | FILE *pfs; | |
| @@ -605,8 +605,8 @@ end: | |||
| 605 | 605 | redraw(); | |
| 606 | 606 | } | |
| 607 | 607 | ||
| 608 | − | bool process_bindings(const keymap_t *keys, unsigned int len, | |
| 609 | − | KeySym ksym_or_button, unsigned int state) | |
| 608 | + | static bool process_bindings(const keymap_t *keys, unsigned int len, | |
| 609 | + | KeySym ksym_or_button, unsigned int state) | |
| 610 | 610 | { | |
| 611 | 611 | unsigned int i; | |
| 612 | 612 | bool dirty = false; | |
| @@ -624,7 +624,7 @@ bool process_bindings(const keymap_t *keys, unsigned int len, | |||
| 624 | 624 | return dirty; | |
| 625 | 625 | } | |
| 626 | 626 | ||
| 627 | − | void on_keypress(XKeyEvent *kev) | |
| 627 | + | static void on_keypress(XKeyEvent *kev) | |
| 628 | 628 | { | |
| 629 | 629 | unsigned int sh = 0; | |
| 630 | 630 | KeySym ksym, shksym; | |
| @@ -659,7 +659,7 @@ void on_keypress(XKeyEvent *kev) | |||
| 659 | 659 | prefix = 0; | |
| 660 | 660 | } | |
| 661 | 661 | ||
| 662 | − | void on_buttonpress(XButtonEvent *bev) | |
| 662 | + | static void on_buttonpress(XButtonEvent *bev) | |
| 663 | 663 | { | |
| 664 | 664 | int sel; | |
| 665 | 665 | bool dirty = false; | |
| @@ -720,7 +720,7 @@ void on_buttonpress(XButtonEvent *bev) | |||
| 720 | 720 | prefix = 0; | |
| 721 | 721 | } | |
| 722 | 722 | ||
| 723 | − | void run(void) | |
| 723 | + | static void run(void) | |
| 724 | 724 | { | |
| 725 | 725 | int xfd; | |
| 726 | 726 | fd_set fds; | |
| @@ -837,7 +837,7 @@ void run(void) | |||
| 837 | 837 | } | |
| 838 | 838 | } | |
| 839 | 839 | ||
| 840 | − | int fncmp(const void *a, const void *b) | |
| 840 | + | static int fncmp(const void *a, const void *b) | |
| 841 | 841 | { | |
| 842 | 842 | return strcoll(((fileinfo_t*) a)->name, ((fileinfo_t*) b)->name); | |
| 843 | 843 | } | |
| @@ -847,7 +847,7 @@ void sigchld(int sig) | |||
| 847 | 847 | while (waitpid(-1, NULL, WNOHANG) > 0); | |
| 848 | 848 | } | |
| 849 | 849 | ||
| 850 | − | void setup_signal(int sig, void (*handler)(int sig)) | |
| 850 | + | static void setup_signal(int sig, void (*handler)(int sig)) | |
| 851 | 851 | { | |
| 852 | 852 | struct sigaction sa; | |
| 853 | 853 | ||
| @@ -233,7 +233,6 @@ bool img_fit_win(img_t*, scalemode_t); | |||
| 233 | 233 | bool img_zoom(img_t*, int); | |
| 234 | 234 | bool img_zoom_to(img_t*, float); | |
| 235 | 235 | bool img_pos(img_t*, float, float); | |
| 236 | − | bool img_move(img_t*, float, float); | |
| 237 | 236 | bool img_pan(img_t*, direction_t, int); | |
| 238 | 237 | bool img_pan_edge(img_t*, direction_t); | |
| 239 | 238 | void img_rotate(img_t*, degree_t); | |
| @@ -283,7 +282,6 @@ struct opt { | |||
| 283 | 282 | extern const opt_t *options; | |
| 284 | 283 | ||
| 285 | 284 | void print_usage(void); | |
| 286 | − | void print_version(void); | |
| 287 | 285 | void parse_options(int, char**); | |
| 288 | 286 | ||
| 289 | 287 | ||
| @@ -26,8 +26,7 @@ | |||
| 26 | 26 | #include <string.h> | |
| 27 | 27 | #include <unistd.h> | |
| 28 | 28 | ||
| 29 | − | opt_t _options; | |
| 30 | − | const opt_t *options = (const opt_t*) &_options; | |
| 29 | + | const opt_t *options; | |
| 31 | 30 | ||
| 32 | 31 | void print_usage(void) | |
| 33 | 32 | { | |
| @@ -36,7 +35,7 @@ void print_usage(void) | |||
| 36 | 35 | "[-z ZOOM] FILES...\n"); | |
| 37 | 36 | } | |
| 38 | 37 | ||
| 39 | − | void print_version(void) | |
| 38 | + | static void print_version(void) | |
| 40 | 39 | { | |
| 41 | 40 | puts("nsxiv " VERSION); | |
| 42 | 41 | } | |
| @@ -46,6 +45,8 @@ void parse_options(int argc, char **argv) | |||
| 46 | 45 | int n, opt; | |
| 47 | 46 | char *end, *s; | |
| 48 | 47 | const char *scalemodes = "dfFwh"; | |
| 48 | + | static opt_t _options; | |
| 49 | + | options = &_options; | |
| 49 | 50 | ||
| 50 | 51 | progname = strrchr(argv[0], '/'); | |
| 51 | 52 | progname = progname ? progname + 1 : argv[0]; | |
| @@ -38,7 +38,7 @@ Imlib_Image img_open(const fileinfo_t*); | |||
| 38 | 38 | static char *cache_dir; | |
| 39 | 39 | extern const int fileidx; | |
| 40 | 40 | ||
| 41 | − | char* tns_cache_filepath(const char *filepath) | |
| 41 | + | static char* tns_cache_filepath(const char *filepath) | |
| 42 | 42 | { | |
| 43 | 43 | size_t len; | |
| 44 | 44 | char *cfile = NULL; | |
| @@ -55,7 +55,7 @@ char* tns_cache_filepath(const char *filepath) | |||
| 55 | 55 | return cfile; | |
| 56 | 56 | } | |
| 57 | 57 | ||
| 58 | − | Imlib_Image tns_cache_load(const char *filepath, bool *outdated) | |
| 58 | + | static Imlib_Image tns_cache_load(const char *filepath, bool *outdated) | |
| 59 | 59 | { | |
| 60 | 60 | char *cfile; | |
| 61 | 61 | struct stat cstats, fstats; | |
| @@ -76,7 +76,7 @@ Imlib_Image tns_cache_load(const char *filepath, bool *outdated) | |||
| 76 | 76 | return im; | |
| 77 | 77 | } | |
| 78 | 78 | ||
| 79 | − | void tns_cache_write(Imlib_Image im, const char *filepath, bool force) | |
| 79 | + | static void tns_cache_write(Imlib_Image im, const char *filepath, bool force) | |
| 80 | 80 | { | |
| 81 | 81 | char *cfile, *dirend; | |
| 82 | 82 | struct stat cstats, fstats; | |
| @@ -200,7 +200,7 @@ CLEANUP void tns_free(tns_t *tns) | |||
| 200 | 200 | cache_dir = NULL; | |
| 201 | 201 | } | |
| 202 | 202 | ||
| 203 | − | Imlib_Image tns_scale_down(Imlib_Image im, int dim) | |
| 203 | + | static Imlib_Image tns_scale_down(Imlib_Image im, int dim) | |
| 204 | 204 | { | |
| 205 | 205 | int w, h; | |
| 206 | 206 | float z, zw, zh; | |
| @@ -374,7 +374,7 @@ void tns_unload(tns_t *tns, int n) | |||
| 374 | 374 | } | |
| 375 | 375 | } | |
| 376 | 376 | ||
| 377 | − | void tns_check_view(tns_t *tns, bool scrolled) | |
| 377 | + | static void tns_check_view(tns_t *tns, bool scrolled) | |
| 378 | 378 | { | |
| 379 | 379 | int r; | |
| 380 | 380 | ||
| @@ -63,7 +63,7 @@ static int barheight; | |||
| 63 | 63 | Atom atoms[ATOM_COUNT]; | |
| 64 | 64 | ||
| 65 | 65 | #if HAVE_LIBFONTS | |
| 66 | − | void win_init_font(const win_env_t *e, const char *fontstr) | |
| 66 | + | static void win_init_font(const win_env_t *e, const char *fontstr) | |
| 67 | 67 | { | |
| 68 | 68 | int fontheight = 0; | |
| 69 | 69 | if ((font = XftFontOpenName(e->dpy, e->scr, fontstr)) == NULL) | |
| @@ -74,21 +74,21 @@ void win_init_font(const win_env_t *e, const char *fontstr) | |||
| 74 | 74 | XftFontClose(e->dpy, font); | |
| 75 | 75 | } | |
| 76 | 76 | ||
| 77 | − | void xft_alloc_color(const win_env_t *e, const char *name, XftColor *col) | |
| 77 | + | static void xft_alloc_color(const win_env_t *e, const char *name, XftColor *col) | |
| 78 | 78 | { | |
| 79 | 79 | if (!XftColorAllocName(e->dpy, e->vis, e->cmap, name, col)) | |
| 80 | 80 | error(EXIT_FAILURE, 0, "Error allocating color '%s'", name); | |
| 81 | 81 | } | |
| 82 | 82 | #endif /* HAVE_LIBFONTS */ | |
| 83 | 83 | ||
| 84 | − | void win_alloc_color(const win_env_t *e, const char *name, XColor *col) | |
| 84 | + | static void win_alloc_color(const win_env_t *e, const char *name, XColor *col) | |
| 85 | 85 | { | |
| 86 | 86 | XColor screen; | |
| 87 | 87 | if (!XAllocNamedColor(e->dpy, e->cmap, name, &screen, col)) | |
| 88 | 88 | error(EXIT_FAILURE, 0, "Error allocating color '%s'", name); | |
| 89 | 89 | } | |
| 90 | 90 | ||
| 91 | − | const char* win_res(XrmDatabase db, const char *name, const char *def) | |
| 91 | + | static const char* win_res(XrmDatabase db, const char *name, const char *def) | |
| 92 | 92 | { | |
| 93 | 93 | char *type; | |
| 94 | 94 | XrmValue ret; | |
| @@ -396,8 +396,8 @@ void win_clear(win_t *win) | |||
| 396 | 396 | } | |
| 397 | 397 | ||
| 398 | 398 | #if HAVE_LIBFONTS | |
| 399 | − | int win_draw_text(win_t *win, XftDraw *d, const XftColor *color, int x, int y, | |
| 400 | − | char *text, int len, int w) | |
| 399 | + | static int win_draw_text(win_t *win, XftDraw *d, const XftColor *color, | |
| 400 | + | int x, int y, char *text, int len, int w) | |
| 401 | 401 | { | |
| 402 | 402 | int err, tw = 0; | |
| 403 | 403 | char *t, *next; | |
| @@ -430,7 +430,7 @@ int win_draw_text(win_t *win, XftDraw *d, const XftColor *color, int x, int y, | |||
| 430 | 430 | return tw; | |
| 431 | 431 | } | |
| 432 | 432 | ||
| 433 | − | void win_draw_bar(win_t *win) | |
| 433 | + | static void win_draw_bar(win_t *win) | |
| 434 | 434 | { | |
| 435 | 435 | int len, x, y, w, tw; | |
| 436 | 436 | win_env_t *e; | |
| @@ -466,7 +466,7 @@ void win_draw_bar(win_t *win) | |||
| 466 | 466 | XftDrawDestroy(d); | |
| 467 | 467 | } | |
| 468 | 468 | #else | |
| 469 | − | void win_draw_bar(win_t *win){} | |
| 469 | + | static void win_draw_bar(win_t *win){} | |
| 470 | 470 | #endif /* HAVE_LIBFONTS */ | |
| 471 | 471 | ||
| 472 | 472 | void win_draw(win_t *win) | |