Krolyxon
Commit c627537

Branches

Refs →

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;
}
```
Author
N-R-K
Date
2021-11-20 09:51 +0600
Committer
GitHub · 2021-11-20 03:51 +0000
Parent
43fcd2e
Commit
c6275374b03ac4526a46f255f33ae2f81003d52b

+40 −41

7 files changed

  1. M autoreload_inotify.c +1 −1
  2. M image.c +7 −7
  3. M main.c +15 −15
  4. M nsxiv.h +0 −2
  5. M options.c +4 −3
  6. M thumbs.c +5 −5
  7. M window.c +8 −8
M autoreload_inotify.c View
@@ -24,7 +24,7 @@
2424 #include <unistd.h>
2525 #include <sys/inotify.h>
2626
27−union {
27+static union {
2828 char d[4096]; /* aligned buffer */
2929 struct inotify_event e;
3030 } buf;
M image.c View
@@ -114,7 +114,7 @@ void exif_auto_orientate(const fileinfo_t *file)
114114 #endif
115115
116116 #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)
118118 {
119119 GifFileType *gif;
120120 GifRowType *rows = NULL;
@@ -295,7 +295,7 @@ bool img_load_gif(img_t *img, const fileinfo_t *file)
295295
296296
297297 #if HAVE_LIBWEBP
298−bool is_webp(const char *path)
298+static bool is_webp(const char *path)
299299 {
300300 /* The size (in bytes) of the largest amount of data required to verify a WebP image. */
301301 enum { max = 30 };
@@ -316,7 +316,7 @@ bool is_webp(const char *path)
316316 * x NULL = load the first frame as an Imlib_Image
317317 * NULL x = load all frames into img->multi.
318318 */
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)
320320 {
321321 FILE *webp_file;
322322 WebPData data;
@@ -507,7 +507,7 @@ CLEANUP void img_close(img_t *img, bool decache)
507507 }
508508 }
509509
510−void img_check_pan(img_t *img, bool moved)
510+static void img_check_pan(img_t *img, bool moved)
511511 {
512512 win_t *win;
513513 float w, h, ox, oy;
@@ -535,7 +535,7 @@ void img_check_pan(img_t *img, bool moved)
535535 img->dirty = true;
536536 }
537537
538−bool img_fit(img_t *img)
538+static bool img_fit(img_t *img)
539539 {
540540 float z, zw, zh;
541541
@@ -723,7 +723,7 @@ bool img_pos(img_t *img, float x, float y)
723723 }
724724 }
725725
726−bool img_move(img_t *img, float dx, float dy)
726+static bool img_move(img_t *img, float dx, float dy)
727727 {
728728 return img_pos(img, img->x + dx, img->y + dy);
729729 }
@@ -873,7 +873,7 @@ bool img_change_gamma(img_t *img, int d)
873873 }
874874 }
875875
876−bool img_frame_goto(img_t *img, int n)
876+static bool img_frame_goto(img_t *img, int n)
877877 {
878878 if (n < 0 || n >= img->multi.cnt || n == img->multi.sel)
879879 return false;
M main.c View
@@ -67,7 +67,7 @@ int markidx;
6767 int prefix;
6868 bool extprefix;
6969
70−bool resized = false;
70+static bool resized = false;
7171
7272 typedef struct {
7373 int err;
@@ -97,7 +97,7 @@ timeout_t timeouts[] = {
9797 /**************************
9898 function implementations
9999 **************************/
100−void cleanup(void)
100+static void cleanup(void)
101101 {
102102 img_close(&img, false);
103103 arl_cleanup(&arl);
@@ -113,7 +113,7 @@ static bool xgetline(char **lineptr, size_t *n)
113113 return len > 0;
114114 }
115115
116−void check_add_file(char *filename, bool given)
116+static void check_add_file(char *filename, bool given)
117117 {
118118 char *path;
119119
@@ -203,7 +203,7 @@ void reset_timeout(timeout_f handler)
203203 }
204204 }
205205
206−bool check_timeouts(struct timeval *t)
206+static bool check_timeouts(struct timeval *t)
207207 {
208208 int i = 0, tdiff, tmin = -1;
209209 struct timeval now;
@@ -265,7 +265,7 @@ void open_info(void)
265265 }
266266 }
267267
268−void read_info(void)
268+static void read_info(void)
269269 {
270270 ssize_t i, n;
271271 char buf[BAR_L_LEN];
@@ -347,7 +347,7 @@ bool mark_image(int n, bool on)
347347 return false;
348348 }
349349
350−void bar_put(win_bar_t *bar, const char *fmt, ...)
350+static void bar_put(win_bar_t *bar, const char *fmt, ...)
351351 {
352352 size_t len = bar->size - (bar->p - bar->buf), n;
353353 va_list ap;
@@ -358,7 +358,7 @@ void bar_put(win_bar_t *bar, const char *fmt, ...)
358358 va_end(ap);
359359 }
360360
361−void update_info(void)
361+static void update_info(void)
362362 {
363363 unsigned int i, fn, fw;
364364 const char * mark;
@@ -507,7 +507,7 @@ void handle_key_handler(bool init)
507507 win_draw(&win);
508508 }
509509
510−void run_key_handler(const char *key, unsigned int mask)
510+static void run_key_handler(const char *key, unsigned int mask)
511511 {
512512 pid_t pid;
513513 FILE *pfs;
@@ -605,8 +605,8 @@ end:
605605 redraw();
606606 }
607607
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)
610610 {
611611 unsigned int i;
612612 bool dirty = false;
@@ -624,7 +624,7 @@ bool process_bindings(const keymap_t *keys, unsigned int len,
624624 return dirty;
625625 }
626626
627−void on_keypress(XKeyEvent *kev)
627+static void on_keypress(XKeyEvent *kev)
628628 {
629629 unsigned int sh = 0;
630630 KeySym ksym, shksym;
@@ -659,7 +659,7 @@ void on_keypress(XKeyEvent *kev)
659659 prefix = 0;
660660 }
661661
662−void on_buttonpress(XButtonEvent *bev)
662+static void on_buttonpress(XButtonEvent *bev)
663663 {
664664 int sel;
665665 bool dirty = false;
@@ -720,7 +720,7 @@ void on_buttonpress(XButtonEvent *bev)
720720 prefix = 0;
721721 }
722722
723−void run(void)
723+static void run(void)
724724 {
725725 int xfd;
726726 fd_set fds;
@@ -837,7 +837,7 @@ void run(void)
837837 }
838838 }
839839
840−int fncmp(const void *a, const void *b)
840+static int fncmp(const void *a, const void *b)
841841 {
842842 return strcoll(((fileinfo_t*) a)->name, ((fileinfo_t*) b)->name);
843843 }
@@ -847,7 +847,7 @@ void sigchld(int sig)
847847 while (waitpid(-1, NULL, WNOHANG) > 0);
848848 }
849849
850−void setup_signal(int sig, void (*handler)(int sig))
850+static void setup_signal(int sig, void (*handler)(int sig))
851851 {
852852 struct sigaction sa;
853853
M nsxiv.h View
@@ -233,7 +233,6 @@ bool img_fit_win(img_t*, scalemode_t);
233233 bool img_zoom(img_t*, int);
234234 bool img_zoom_to(img_t*, float);
235235 bool img_pos(img_t*, float, float);
236−bool img_move(img_t*, float, float);
237236 bool img_pan(img_t*, direction_t, int);
238237 bool img_pan_edge(img_t*, direction_t);
239238 void img_rotate(img_t*, degree_t);
@@ -283,7 +282,6 @@ struct opt {
283282 extern const opt_t *options;
284283
285284 void print_usage(void);
286−void print_version(void);
287285 void parse_options(int, char**);
288286
289287
M options.c View
@@ -26,8 +26,7 @@
2626 #include <string.h>
2727 #include <unistd.h>
2828
29−opt_t _options;
30−const opt_t *options = (const opt_t*) &_options;
29+const opt_t *options;
3130
3231 void print_usage(void)
3332 {
@@ -36,7 +35,7 @@ void print_usage(void)
3635 "[-z ZOOM] FILES...\n");
3736 }
3837
39−void print_version(void)
38+static void print_version(void)
4039 {
4140 puts("nsxiv " VERSION);
4241 }
@@ -46,6 +45,8 @@ void parse_options(int argc, char **argv)
4645 int n, opt;
4746 char *end, *s;
4847 const char *scalemodes = "dfFwh";
48+ static opt_t _options;
49+ options = &_options;
4950
5051 progname = strrchr(argv[0], '/');
5152 progname = progname ? progname + 1 : argv[0];
M thumbs.c View
@@ -38,7 +38,7 @@ Imlib_Image img_open(const fileinfo_t*);
3838 static char *cache_dir;
3939 extern const int fileidx;
4040
41−char* tns_cache_filepath(const char *filepath)
41+static char* tns_cache_filepath(const char *filepath)
4242 {
4343 size_t len;
4444 char *cfile = NULL;
@@ -55,7 +55,7 @@ char* tns_cache_filepath(const char *filepath)
5555 return cfile;
5656 }
5757
58−Imlib_Image tns_cache_load(const char *filepath, bool *outdated)
58+static Imlib_Image tns_cache_load(const char *filepath, bool *outdated)
5959 {
6060 char *cfile;
6161 struct stat cstats, fstats;
@@ -76,7 +76,7 @@ Imlib_Image tns_cache_load(const char *filepath, bool *outdated)
7676 return im;
7777 }
7878
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)
8080 {
8181 char *cfile, *dirend;
8282 struct stat cstats, fstats;
@@ -200,7 +200,7 @@ CLEANUP void tns_free(tns_t *tns)
200200 cache_dir = NULL;
201201 }
202202
203−Imlib_Image tns_scale_down(Imlib_Image im, int dim)
203+static Imlib_Image tns_scale_down(Imlib_Image im, int dim)
204204 {
205205 int w, h;
206206 float z, zw, zh;
@@ -374,7 +374,7 @@ void tns_unload(tns_t *tns, int n)
374374 }
375375 }
376376
377−void tns_check_view(tns_t *tns, bool scrolled)
377+static void tns_check_view(tns_t *tns, bool scrolled)
378378 {
379379 int r;
380380
M window.c View
@@ -63,7 +63,7 @@ static int barheight;
6363 Atom atoms[ATOM_COUNT];
6464
6565 #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)
6767 {
6868 int fontheight = 0;
6969 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)
7474 XftFontClose(e->dpy, font);
7575 }
7676
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)
7878 {
7979 if (!XftColorAllocName(e->dpy, e->vis, e->cmap, name, col))
8080 error(EXIT_FAILURE, 0, "Error allocating color '%s'", name);
8181 }
8282 #endif /* HAVE_LIBFONTS */
8383
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)
8585 {
8686 XColor screen;
8787 if (!XAllocNamedColor(e->dpy, e->cmap, name, &screen, col))
8888 error(EXIT_FAILURE, 0, "Error allocating color '%s'", name);
8989 }
9090
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)
9292 {
9393 char *type;
9494 XrmValue ret;
@@ -396,8 +396,8 @@ void win_clear(win_t *win)
396396 }
397397
398398 #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)
401401 {
402402 int err, tw = 0;
403403 char *t, *next;
@@ -430,7 +430,7 @@ int win_draw_text(win_t *win, XftDraw *d, const XftColor *color, int x, int y,
430430 return tw;
431431 }
432432
433−void win_draw_bar(win_t *win)
433+static void win_draw_bar(win_t *win)
434434 {
435435 int len, x, y, w, tw;
436436 win_env_t *e;
@@ -466,7 +466,7 @@ void win_draw_bar(win_t *win)
466466 XftDrawDestroy(d);
467467 }
468468 #else
469−void win_draw_bar(win_t *win){}
469+static void win_draw_bar(win_t *win){}
470470 #endif /* HAVE_LIBFONTS */
471471
472472 void win_draw(win_t *win)