Refactored function definitions to use dangling brace

This commit is contained in:
Bert Münnich 2013-02-08 22:05:31 +01:00
parent 6d3bbc6d5e
commit 08ae25da22
9 changed files with 247 additions and 124 deletions

View File

@ -1,4 +1,4 @@
VERSION = git-20130129
VERSION = git-20130208
PREFIX = /usr/local
MANPREFIX = $(PREFIX)/share/man

View File

@ -54,12 +54,14 @@ const int ss_delays[] = {
1, 2, 3, 5, 10, 15, 20, 30, 60, 120, 180, 300, 600
};
bool it_quit(arg_t a) {
bool it_quit(arg_t a)
{
cleanup();
exit(EXIT_SUCCESS);
}
bool it_switch_mode(arg_t a) {
bool it_switch_mode(arg_t a)
{
if (mode == MODE_IMAGE) {
if (tns.thumbs == NULL)
tns_init(&tns, filecnt, &win);
@ -75,7 +77,8 @@ bool it_switch_mode(arg_t a) {
return true;
}
bool it_toggle_fullscreen(arg_t a) {
bool it_toggle_fullscreen(arg_t a)
{
win_toggle_fullscreen(&win);
/* redraw after next ConfigureNotify event */
set_timeout(redraw, TO_REDRAW_RESIZE, false);
@ -86,7 +89,8 @@ bool it_toggle_fullscreen(arg_t a) {
return false;
}
bool it_toggle_bar(arg_t a) {
bool it_toggle_bar(arg_t a)
{
win_toggle_bar(&win);
if (mode == MODE_IMAGE)
img.checkpan = img.dirty = true;
@ -95,7 +99,8 @@ bool it_toggle_bar(arg_t a) {
return true;
}
bool t_reload_all(arg_t a) {
bool t_reload_all(arg_t a)
{
if (mode == MODE_THUMB) {
tns_free(&tns);
tns_init(&tns, filecnt, &win);
@ -105,7 +110,8 @@ bool t_reload_all(arg_t a) {
}
}
bool it_reload_image(arg_t a) {
bool it_reload_image(arg_t a)
{
if (mode == MODE_IMAGE) {
load_image(fileidx);
} else {
@ -120,7 +126,8 @@ bool it_reload_image(arg_t a) {
return true;
}
bool it_remove_image(arg_t a) {
bool it_remove_image(arg_t a)
{
if (mode == MODE_IMAGE) {
remove_file(fileidx, true);
load_image(fileidx >= filecnt ? filecnt - 1 : fileidx);
@ -136,7 +143,8 @@ bool it_remove_image(arg_t a) {
}
}
bool i_navigate(arg_t a) {
bool i_navigate(arg_t a)
{
long n = (long) a;
if (mode == MODE_IMAGE) {
@ -156,7 +164,8 @@ bool i_navigate(arg_t a) {
return false;
}
bool i_alternate(arg_t a) {
bool i_alternate(arg_t a)
{
if (mode == MODE_IMAGE) {
load_image(alternate);
return true;
@ -165,7 +174,8 @@ bool i_alternate(arg_t a) {
}
}
bool it_first(arg_t a) {
bool it_first(arg_t a)
{
if (mode == MODE_IMAGE && fileidx != 0) {
load_image(0);
return true;
@ -178,7 +188,8 @@ bool it_first(arg_t a) {
}
}
bool it_n_or_last(arg_t a) {
bool it_n_or_last(arg_t a)
{
int n = prefix != 0 && prefix - 1 < filecnt ? prefix - 1 : filecnt - 1;
if (mode == MODE_IMAGE && fileidx != n) {
@ -193,14 +204,16 @@ bool it_n_or_last(arg_t a) {
}
}
bool i_navigate_frame(arg_t a) {
bool i_navigate_frame(arg_t a)
{
if (mode == MODE_IMAGE && !img.multi.animate)
return img_frame_navigate(&img, (long) a);
else
return false;
}
bool i_toggle_animation(arg_t a) {
bool i_toggle_animation(arg_t a)
{
if (mode != MODE_IMAGE)
return false;
@ -213,7 +226,8 @@ bool i_toggle_animation(arg_t a) {
return true;
}
bool it_scroll_move(arg_t a) {
bool it_scroll_move(arg_t a)
{
direction_t dir = (direction_t) a;
if (mode == MODE_IMAGE)
@ -222,7 +236,8 @@ bool it_scroll_move(arg_t a) {
return tns_move_selection(&tns, dir, prefix);
}
bool it_scroll_screen(arg_t a) {
bool it_scroll_screen(arg_t a)
{
direction_t dir = (direction_t) a;
if (mode == MODE_IMAGE)
@ -231,7 +246,8 @@ bool it_scroll_screen(arg_t a) {
return tns_scroll(&tns, dir, true);
}
bool i_scroll_to_edge(arg_t a) {
bool i_scroll_to_edge(arg_t a)
{
direction_t dir = (direction_t) a;
if (mode == MODE_IMAGE)
@ -241,11 +257,13 @@ bool i_scroll_to_edge(arg_t a) {
}
/* Xlib helper function for i_drag() */
Bool is_motionnotify(Display *d, XEvent *e, XPointer a) {
Bool is_motionnotify(Display *d, XEvent *e, XPointer a)
{
return e != NULL && e->type == MotionNotify;
}
bool i_drag(arg_t a) {
bool i_drag(arg_t a)
{
int dx = 0, dy = 0, i, ox, oy, x, y;
unsigned int ui;
bool dragging = true, next = false;
@ -297,7 +315,8 @@ bool i_drag(arg_t a) {
return false;
}
bool i_zoom(arg_t a) {
bool i_zoom(arg_t a)
{
long scale = (long) a;
if (mode != MODE_IMAGE)
@ -311,14 +330,16 @@ bool i_zoom(arg_t a) {
return false;
}
bool i_set_zoom(arg_t a) {
bool i_set_zoom(arg_t a)
{
if (mode == MODE_IMAGE)
return img_zoom(&img, (prefix ? prefix : (long) a) / 100.0);
else
return false;
}
bool i_fit_to_win(arg_t a) {
bool i_fit_to_win(arg_t a)
{
bool ret = false;
scalemode_t sm = (scalemode_t) a;
@ -329,7 +350,8 @@ bool i_fit_to_win(arg_t a) {
return ret;
}
bool i_fit_to_img(arg_t a) {
bool i_fit_to_img(arg_t a)
{
int x, y;
unsigned int w, h;
bool ret = false;
@ -348,7 +370,8 @@ bool i_fit_to_img(arg_t a) {
return ret;
}
bool i_rotate(arg_t a) {
bool i_rotate(arg_t a)
{
direction_t dir = (direction_t) a;
if (mode == MODE_IMAGE) {
@ -363,7 +386,8 @@ bool i_rotate(arg_t a) {
return false;
}
bool i_flip(arg_t a) {
bool i_flip(arg_t a)
{
flipdir_t dir = (flipdir_t) a;
if (mode == MODE_IMAGE) {
@ -374,7 +398,8 @@ bool i_flip(arg_t a) {
}
}
bool i_toggle_antialias(arg_t a) {
bool i_toggle_antialias(arg_t a)
{
if (mode == MODE_IMAGE) {
img_toggle_antialias(&img);
return true;
@ -383,7 +408,8 @@ bool i_toggle_antialias(arg_t a) {
}
}
bool it_toggle_alpha(arg_t a) {
bool it_toggle_alpha(arg_t a)
{
img.alpha = tns.alpha = !img.alpha;
if (mode == MODE_IMAGE)
img.dirty = true;
@ -392,7 +418,8 @@ bool it_toggle_alpha(arg_t a) {
return true;
}
bool it_open_with(arg_t a) {
bool it_open_with(arg_t a)
{
const char *prog = (const char*) a;
pid_t pid;
@ -410,7 +437,8 @@ bool it_open_with(arg_t a) {
return false;
}
bool it_shell_cmd(arg_t a) {
bool it_shell_cmd(arg_t a)
{
int n, status;
const char *cmdline = (const char*) a;
pid_t pid;

12
exif.c
View File

@ -26,7 +26,8 @@
#include "exif.h"
#include "util.h"
ssize_t s_read(int fd, const char *fn, void *buf, size_t n) {
ssize_t s_read(int fd, const char *fn, void *buf, size_t n)
{
ssize_t ret;
ret = read(fd, buf, n);
@ -38,7 +39,8 @@ ssize_t s_read(int fd, const char *fn, void *buf, size_t n) {
}
}
unsigned short btous(unsigned char *buf, byteorder_t order) {
unsigned short btous(unsigned char *buf, byteorder_t order)
{
if (buf == NULL)
return 0;
if (order == BO_BIG_ENDIAN)
@ -47,7 +49,8 @@ unsigned short btous(unsigned char *buf, byteorder_t order) {
return buf[1] << 8 | buf[0];
}
unsigned int btoui(unsigned char *buf, byteorder_t order) {
unsigned int btoui(unsigned char *buf, byteorder_t order)
{
if (buf == NULL)
return 0;
if (order == BO_BIG_ENDIAN)
@ -56,7 +59,8 @@ unsigned int btoui(unsigned char *buf, byteorder_t order) {
return buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0];
}
int exif_orientation(const fileinfo_t *file) {
int exif_orientation(const fileinfo_t *file)
{
int fd;
unsigned char data[EXIF_MAX_LEN];
byteorder_t order = BO_BIG_ENDIAN;

75
image.c
View File

@ -38,11 +38,13 @@ enum { MIN_GIF_DELAY = 25 };
float zoom_min;
float zoom_max;
int zoomdiff(float z1, float z2) {
int zoomdiff(float z1, float z2)
{
return (int) (z1 * 1000.0 - z2 * 1000.0);
}
void img_init(img_t *img, win_t *win) {
void img_init(img_t *img, win_t *win)
{
zoom_min = zoom_levels[0] / 100.0;
zoom_max = zoom_levels[ARRLEN(zoom_levels) - 1] / 100.0;
@ -66,7 +68,8 @@ void img_init(img_t *img, win_t *win) {
img->multi.animate = false;
}
void exif_auto_orientate(const fileinfo_t *file) {
void exif_auto_orientate(const fileinfo_t *file)
{
switch (exif_orientation(file)) {
case 5:
imlib_image_orientate(1);
@ -95,7 +98,8 @@ void exif_auto_orientate(const fileinfo_t *file) {
}
#if HAVE_GIFLIB
bool img_load_gif(img_t *img, const fileinfo_t *file) {
bool img_load_gif(img_t *img, const fileinfo_t *file)
{
GifFileType *gif;
GifRowType *rows = NULL;
GifRecordType rec;
@ -266,7 +270,8 @@ bool img_load_gif(img_t *img, const fileinfo_t *file) {
}
#endif /* HAVE_GIFLIB */
bool img_load(img_t *img, const fileinfo_t *file) {
bool img_load(img_t *img, const fileinfo_t *file)
{
const char *fmt;
if (img == NULL || file == NULL || file->name == NULL || file->path == NULL)
@ -303,7 +308,8 @@ bool img_load(img_t *img, const fileinfo_t *file) {
return true;
}
void img_close(img_t *img, bool decache) {
void img_close(img_t *img, bool decache)
{
int i;
if (img == NULL)
@ -326,7 +332,8 @@ void img_close(img_t *img, bool decache) {
}
}
void img_check_pan(img_t *img, bool moved) {
void img_check_pan(img_t *img, bool moved)
{
win_t *win;
int ox, oy;
@ -358,7 +365,8 @@ void img_check_pan(img_t *img, bool moved) {
img->dirty = true;
}
bool img_fit(img_t *img) {
bool img_fit(img_t *img)
{
float z, zmax, zw, zh;
if (img == NULL || img->im == NULL || img->win == NULL)
@ -394,7 +402,8 @@ bool img_fit(img_t *img) {
}
}
void img_render(img_t *img) {
void img_render(img_t *img)
{
win_t *win;
int sx, sy, sw, sh;
int dx, dy, dw, dh;
@ -464,7 +473,8 @@ void img_render(img_t *img) {
img->dirty = false;
}
bool img_fit_win(img_t *img, scalemode_t sm) {
bool img_fit_win(img_t *img, scalemode_t sm)
{
if (img == NULL || img->im == NULL)
return false;
@ -472,7 +482,8 @@ bool img_fit_win(img_t *img, scalemode_t sm) {
return img_fit(img);
}
bool img_center(img_t *img) {
bool img_center(img_t *img)
{
int ox, oy;
if (img == NULL || img->im == NULL || img->win == NULL)
@ -492,7 +503,8 @@ bool img_center(img_t *img) {
}
}
bool img_zoom(img_t *img, float z) {
bool img_zoom(img_t *img, float z)
{
if (img == NULL || img->im == NULL || img->win == NULL)
return false;
@ -513,7 +525,8 @@ bool img_zoom(img_t *img, float z) {
}
}
bool img_zoom_in(img_t *img) {
bool img_zoom_in(img_t *img)
{
int i;
float z;
@ -528,7 +541,8 @@ bool img_zoom_in(img_t *img) {
return false;
}
bool img_zoom_out(img_t *img) {
bool img_zoom_out(img_t *img)
{
int i;
float z;
@ -543,7 +557,8 @@ bool img_zoom_out(img_t *img) {
return false;
}
bool img_move(img_t *img, float dx, float dy) {
bool img_move(img_t *img, float dx, float dy)
{
float ox, oy;
if (img == NULL || img->im == NULL)
@ -565,7 +580,8 @@ bool img_move(img_t *img, float dx, float dy) {
}
}
bool img_pan(img_t *img, direction_t dir, int d) {
bool img_pan(img_t *img, direction_t dir, int d)
{
/* d < 0: screen-wise
* d = 0: 1/5 of screen
* d > 0: num of pixels
@ -595,7 +611,8 @@ bool img_pan(img_t *img, direction_t dir, int d) {
return false;
}
bool img_pan_edge(img_t *img, direction_t dir) {
bool img_pan_edge(img_t *img, direction_t dir)
{
int ox, oy;
if (img == NULL || img->im == NULL || img->win == NULL)
@ -629,7 +646,8 @@ bool img_pan_edge(img_t *img, direction_t dir) {
}
}
void img_rotate(img_t *img, int d) {
void img_rotate(img_t *img, int d)
{
win_t *win;
int ox, oy, tmp;
@ -654,15 +672,18 @@ void img_rotate(img_t *img, int d) {
img->dirty = true;
}
void img_rotate_left(img_t *img) {
void img_rotate_left(img_t *img)
{
img_rotate(img, 3);
}
void img_rotate_right(img_t *img) {
void img_rotate_right(img_t *img)
{
img_rotate(img, 1);
}
void img_flip(img_t *img, flipdir_t d) {
void img_flip(img_t *img, flipdir_t d)
{
if (img == NULL || img->im == NULL)
return;
@ -679,7 +700,8 @@ void img_flip(img_t *img, flipdir_t d) {
img->dirty = true;
}
void img_toggle_antialias(img_t *img) {
void img_toggle_antialias(img_t *img)
{
if (img == NULL || img->im == NULL)
return;
@ -689,7 +711,8 @@ void img_toggle_antialias(img_t *img) {
img->dirty = true;
}
bool img_frame_goto(img_t *img, int n) {
bool img_frame_goto(img_t *img, int n)
{
if (img == NULL || img->im == NULL)
return false;
if (n < 0 || n >= img->multi.cnt || n == img->multi.sel)
@ -707,7 +730,8 @@ bool img_frame_goto(img_t *img, int n) {
return true;
}
bool img_frame_navigate(img_t *img, int d) {
bool img_frame_navigate(img_t *img, int d)
{
if (img == NULL|| img->im == NULL || img->multi.cnt == 0 || d == 0)
return false;
@ -720,7 +744,8 @@ bool img_frame_navigate(img_t *img, int d) {
return img_frame_goto(img, d);
}
bool img_frame_animate(img_t *img, bool restart) {
bool img_frame_animate(img_t *img, bool restart)
{
if (img == NULL || img->im == NULL || img->multi.cnt == 0)
return false;

60
main.c
View File

@ -85,7 +85,8 @@ timeout_t timeouts[] = {
{ { 0, 0 }, false, clear_resize },
};
void cleanup(void) {
void cleanup(void)
{
static bool in = false;
if (!in) {
@ -96,7 +97,8 @@ void cleanup(void) {
}
}
void check_add_file(char *filename) {
void check_add_file(char *filename)
{
const char *bn;
if (filename == NULL || *filename == '\0')
@ -129,7 +131,8 @@ void check_add_file(char *filename) {
fileidx++;
}
void remove_file(int n, bool manual) {
void remove_file(int n, bool manual)
{
if (n < 0 || n >= filecnt)
return;
@ -157,7 +160,8 @@ void remove_file(int n, bool manual) {
tns.cnt--;
}
void set_timeout(timeout_f handler, int time, bool overwrite) {
void set_timeout(timeout_f handler, int time, bool overwrite)
{
int i;
for (i = 0; i < ARRLEN(timeouts); i++) {
@ -172,7 +176,8 @@ void set_timeout(timeout_f handler, int time, bool overwrite) {
}
}
void reset_timeout(timeout_f handler) {
void reset_timeout(timeout_f handler)
{
int i;
for (i = 0; i < ARRLEN(timeouts); i++) {
@ -183,7 +188,8 @@ void reset_timeout(timeout_f handler) {
}
}
bool check_timeouts(struct timeval *t) {
bool check_timeouts(struct timeval *t)
{
int i = 0, tdiff, tmin = -1;
struct timeval now;
@ -207,7 +213,8 @@ bool check_timeouts(struct timeval *t) {
return tmin > 0;
}
void read_info(void) {
void read_info(void)
{
char cmd[4096];
FILE *outp;
int c, i = 0, n = sizeof(bar.l) - 1;
@ -237,7 +244,8 @@ end:
bar.l[i] = '\0';
}
void load_image(int new) {
void load_image(int new)
{
if (new < 0 || new >= filecnt)
return;
@ -262,7 +270,8 @@ void load_image(int new) {
reset_timeout(animate);
}
void update_info(void) {
void update_info(void)
{
unsigned int i, fn, fw, n, len = sizeof(bar.r);
int sel;
char *t = bar.r, title[TITLE_LEN];
@ -310,7 +319,8 @@ void update_info(void) {
win_set_bar_info(&win, bar.l, bar.r);
}
void redraw(void) {
void redraw(void)
{
if (mode == MODE_IMAGE)
img_render(&img);
else
@ -321,7 +331,8 @@ void redraw(void) {
reset_cursor();
}
void reset_cursor(void) {
void reset_cursor(void)
{
int i;
cursor_t cursor = CURSOR_NONE;
@ -342,27 +353,32 @@ void reset_cursor(void) {
win_set_cursor(&win, cursor);
}
void animate(void) {
void animate(void)
{
if (img_frame_animate(&img, false)) {
redraw();
set_timeout(animate, img.multi.frames[img.multi.sel].delay, true);
}
}
void clear_resize(void) {
void clear_resize(void)
{
resized = false;
}
bool keymask(const keymap_t *k, unsigned int state) {
bool keymask(const keymap_t *k, unsigned int state)
{
return (k->ctrl ? ControlMask : 0) == (state & ControlMask);
}
bool buttonmask(const button_t *b, unsigned int state) {
bool buttonmask(const button_t *b, unsigned int state)
{
return ((b->ctrl ? ControlMask : 0) | (b->shift ? ShiftMask : 0)) ==
(state & (ControlMask | ShiftMask));
}
void on_keypress(XKeyEvent *kev) {
void on_keypress(XKeyEvent *kev)
{
int i;
KeySym ksym;
char key;
@ -390,7 +406,8 @@ void on_keypress(XKeyEvent *kev) {
}
}
void on_buttonpress(XButtonEvent *bev) {
void on_buttonpress(XButtonEvent *bev)
{
int i, sel;
if (bev == NULL)
@ -437,7 +454,8 @@ void on_buttonpress(XButtonEvent *bev) {
}
}
void run(void) {
void run(void)
{
int xfd;
fd_set fds;
struct timeval timeout;
@ -532,11 +550,13 @@ void run(void) {
}
}
int fncmp(const void *a, const void *b) {
int fncmp(const void *a, const void *b)
{
return strcoll(((fileinfo_t*) a)->name, ((fileinfo_t*) b)->name);
}
int main(int argc, char **argv) {
int main(int argc, char **argv)
{
int i, start;
size_t n;
ssize_t len;

View File

@ -31,16 +31,19 @@
options_t _options;
const options_t *options = (const options_t*) &_options;
void print_usage(void) {
void print_usage(void)
{
printf("usage: sxiv [-bcdFfhpqrstvZ] [-g GEOMETRY] [-n NUM] "
"[-N name] [-z ZOOM] FILES...\n");
}
void print_version(void) {
void print_version(void)
{
printf("sxiv %s - Simple X Image Viewer\n", VERSION);
}
void parse_options(int argc, char **argv) {
void parse_options(int argc, char **argv)
{
int opt, t;
_options.recursive = false;

View File

@ -36,14 +36,16 @@ static const int thumb_dim = THUMB_SIZE + 10;
static const char * const CACHE_DIR = ".sxiv/cache";
static char *cache_dir = NULL;
bool tns_cache_enabled(void) {
bool tns_cache_enabled(void)
{
struct stat stats;
return cache_dir != NULL && stat(cache_dir, &stats) == 0 &&
S_ISDIR(stats.st_mode) && access(cache_dir, W_OK) == 0;
}
char* tns_cache_filepath(const char *filepath) {
char* tns_cache_filepath(const char *filepath)
{
size_t len;
char *cfile = NULL;
@ -59,7 +61,8 @@ char* tns_cache_filepath(const char *filepath) {
return cfile;
}
Imlib_Image* tns_cache_load(const char *filepath) {
Imlib_Image* tns_cache_load(const char *filepath)
{
char *cfile;
struct stat cstats, fstats;
Imlib_Image *im = NULL;
@ -77,7 +80,8 @@ Imlib_Image* tns_cache_load(const char *filepath) {
return im;
}
void tns_cache_write(thumb_t *t, bool force) {
void tns_cache_write(thumb_t *t, bool force)
{
char *cfile, *dirend;
struct stat cstats, fstats;
struct utimbuf times;
@ -118,7 +122,8 @@ void tns_cache_write(thumb_t *t, bool force) {
}
}
void tns_clean_cache(tns_t *tns) {
void tns_clean_cache(tns_t *tns)
{
int dirlen;
bool delete;
char *cfile, *filename, *tpos;
@ -154,7 +159,8 @@ void tns_clean_cache(tns_t *tns) {
}
void tns_init(tns_t *tns, int cnt, win_t *win) {
void tns_init(tns_t *tns, int cnt, win_t *win)
{
int len;
char *homedir;
@ -185,7 +191,8 @@ void tns_init(tns_t *tns, int cnt, win_t *win) {
}
}
void tns_free(tns_t *tns) {
void tns_free(tns_t *tns)
{
int i;
if (tns == NULL)
@ -282,7 +289,8 @@ bool tns_load(tns_t *tns, int n, const fileinfo_t *file,
return true;
}
void tns_check_view(tns_t *tns, bool scrolled) {
void tns_check_view(tns_t *tns, bool scrolled)
{
int r;
if (tns == NULL)
@ -309,7 +317,8 @@ void tns_check_view(tns_t *tns, bool scrolled) {
}
}
void tns_render(tns_t *tns) {
void tns_render(tns_t *tns)
{
thumb_t *t;
win_t *win;
int i, cnt, r, x, y;
@ -364,7 +373,8 @@ void tns_render(tns_t *tns) {
tns_highlight(tns, tns->sel, true);
}
void tns_highlight(tns_t *tns, int n, bool hl) {
void tns_highlight(tns_t *tns, int n, bool hl)
{
thumb_t *t;
win_t *win;
int x, y;
@ -392,7 +402,8 @@ void tns_highlight(tns_t *tns, int n, bool hl) {
}
}
bool tns_move_selection(tns_t *tns, direction_t dir, int cnt) {
bool tns_move_selection(tns_t *tns, direction_t dir, int cnt)
{
int old, max;
if (tns == NULL || tns->thumbs == NULL)
@ -427,7 +438,8 @@ bool tns_move_selection(tns_t *tns, direction_t dir, int cnt) {
return tns->sel != old;
}
bool tns_scroll(tns_t *tns, direction_t dir, bool screen) {
bool tns_scroll(tns_t *tns, direction_t dir, bool screen)
{
int d, max, old;
if (tns == NULL)
@ -452,7 +464,8 @@ bool tns_scroll(tns_t *tns, direction_t dir, bool screen) {
return tns->first != old;
}
int tns_translate(tns_t *tns, int x, int y) {
int tns_translate(tns_t *tns, int x, int y)
{
int n;
if (tns == NULL || tns->thumbs == NULL)

36
util.c
View File

@ -36,7 +36,8 @@ enum {
void cleanup(void);
void* s_malloc(size_t size) {
void* s_malloc(size_t size)
{
void *ptr;
ptr = malloc(size);
@ -45,14 +46,16 @@ void* s_malloc(size_t size) {
return ptr;
}
void* s_realloc(void *ptr, size_t size) {
void* s_realloc(void *ptr, size_t size)
{
ptr = realloc(ptr, size);
if (ptr == NULL)
die("could not allocate memory");
return ptr;
}
char* s_strdup(char *s) {
char* s_strdup(char *s)
{
char *d = NULL;
if (s != NULL) {
@ -64,7 +67,8 @@ char* s_strdup(char *s) {
return d;
}
void warn(const char* fmt, ...) {
void warn(const char* fmt, ...)
{
va_list args;
if (fmt == NULL || options->quiet)
@ -77,7 +81,8 @@ void warn(const char* fmt, ...) {
va_end(args);
}
void die(const char* fmt, ...) {
void die(const char* fmt, ...)
{
va_list args;
if (fmt == NULL)
@ -93,7 +98,8 @@ void die(const char* fmt, ...) {
exit(EXIT_FAILURE);
}
ssize_t get_line(char **buf, size_t *n, FILE *stream) {
ssize_t get_line(char **buf, size_t *n, FILE *stream)
{
size_t len;
char *s;
@ -125,7 +131,8 @@ ssize_t get_line(char **buf, size_t *n, FILE *stream) {
return s - *buf + len;
}
void size_readable(float *size, const char **unit) {
void size_readable(float *size, const char **unit)
{
const char *units[] = { "", "K", "M", "G" };
int i;
@ -134,7 +141,8 @@ void size_readable(float *size, const char **unit) {
*unit = units[MIN(i, ARRLEN(units) - 1)];
}
char* absolute_path(const char *filename) {
char* absolute_path(const char *filename)
{
size_t len;
const char *basename;
char *dir, *dirname = NULL, *path = NULL, *s;
@ -206,7 +214,8 @@ end:
return path;
}
int r_opendir(r_dir_t *rdir, const char *dirname) {
int r_opendir(r_dir_t *rdir, const char *dirname)
{
if (rdir == NULL || dirname == NULL || *dirname == '\0')
return -1;
@ -226,7 +235,8 @@ int r_opendir(r_dir_t *rdir, const char *dirname) {
return 0;
}
int r_closedir(r_dir_t *rdir) {
int r_closedir(r_dir_t *rdir)
{
int ret = 0;
if (rdir == NULL)
@ -252,7 +262,8 @@ int r_closedir(r_dir_t *rdir) {
return ret;
}
char* r_readdir(r_dir_t *rdir) {
char* r_readdir(r_dir_t *rdir)
{
size_t len;
char *filename;
struct dirent *dentry;
@ -304,7 +315,8 @@ char* r_readdir(r_dir_t *rdir) {
return NULL;
}
int r_mkdir(const char *path) {
int r_mkdir(const char *path)
{
char *dir, *d;
struct stat stats;
int err = 0;

View File

@ -52,7 +52,8 @@ static struct {
static int fontheight;
static int barheight;
void win_init_font(Display *dpy, const char *fontstr) {
void win_init_font(Display *dpy, const char *fontstr)
{
int n;
char *def, **missing;
@ -84,7 +85,8 @@ void win_init_font(Display *dpy, const char *fontstr) {
barheight = fontheight + 2 * V_TEXT_PAD;
}
unsigned long win_alloc_color(win_t *win, const char *name) {
unsigned long win_alloc_color(win_t *win, const char *name)
{
XColor col;
if (win == NULL)
@ -98,7 +100,8 @@ unsigned long win_alloc_color(win_t *win, const char *name) {
return col.pixel;
}
void win_init(win_t *win) {
void win_init(win_t *win)
{
win_env_t *e;
if (win == NULL)
@ -132,7 +135,8 @@ void win_init(win_t *win) {
wm_delete_win = XInternAtom(e->dpy, "WM_DELETE_WINDOW", False);
}
void win_set_sizehints(win_t *win) {
void win_set_sizehints(win_t *win)
{
XSizeHints sizehints;
if (win == NULL || win->xwin == None)
@ -146,7 +150,8 @@ void win_set_sizehints(win_t *win) {
XSetWMNormalHints(win->env.dpy, win->xwin, &sizehints);
}
void win_open(win_t *win) {
void win_open(win_t *win)
{
win_env_t *e;
XClassHint classhint;
XColor col;
@ -229,7 +234,8 @@ void win_open(win_t *win) {
win_toggle_fullscreen(win);
}
void win_close(win_t *win) {
void win_close(win_t *win)
{
if (win == NULL || win->xwin == None)
return;
@ -244,7 +250,8 @@ void win_close(win_t *win) {
XCloseDisplay(win->env.dpy);
}
bool win_configure(win_t *win, XConfigureEvent *c) {
bool win_configure(win_t *win, XConfigureEvent *c)
{
bool changed;
if (win == NULL || c == NULL)
@ -266,7 +273,8 @@ bool win_configure(win_t *win, XConfigureEvent *c) {
return changed;
}
void win_expose(win_t *win, XExposeEvent *e) {
void win_expose(win_t *win, XExposeEvent *e)
{
if (win == NULL || win->xwin == None || win->pm == None || e == NULL)
return;
@ -274,7 +282,8 @@ void win_expose(win_t *win, XExposeEvent *e) {
e->x, e->y, e->width, e->height, e->x, e->y);
}
bool win_moveresize(win_t *win, int x, int y, unsigned int w, unsigned int h) {
bool win_moveresize(win_t *win, int x, int y, unsigned int w, unsigned int h)
{
if (win == NULL || win->xwin == None)
return false;
@ -299,7 +308,8 @@ bool win_moveresize(win_t *win, int x, int y, unsigned int w, unsigned int h) {
return true;
}
void win_toggle_fullscreen(win_t *win) {
void win_toggle_fullscreen(win_t *win)
{
XEvent ev;
XClientMessageEvent *cm;
@ -323,7 +333,8 @@ void win_toggle_fullscreen(win_t *win) {
SubstructureNotifyMask | SubstructureRedirectMask, &ev);
}
void win_toggle_bar(win_t *win) {
void win_toggle_bar(win_t *win)
{
if (win == NULL || win->xwin == None)
return;
@ -336,7 +347,8 @@ void win_toggle_bar(win_t *win) {
}
}
void win_clear(win_t *win) {
void win_clear(win_t *win)
{
int h;
win_env_t *e;
@ -353,7 +365,8 @@ void win_clear(win_t *win) {
XFillRectangle(e->dpy, win->pm, gc, 0, 0, win->w, h);
}
void win_draw_bar(win_t *win) {
void win_draw_bar(win_t *win)
{
int len, olen, x, y, w, tw;
char rest[3];
const char *dots = "...";
@ -408,7 +421,8 @@ void win_draw_bar(win_t *win) {
}
}
void win_draw(win_t *win) {
void win_draw(win_t *win)
{
if (win == NULL || win->xwin == None || win->pm == None)
return;
@ -437,7 +451,8 @@ void win_draw_rect(win_t *win, Pixmap pm, int x, int y, int w, int h,
XDrawRectangle(win->env.dpy, pm, gc, x, y, w, h);
}
int win_textwidth(const char *text, unsigned int len, bool with_padding) {
int win_textwidth(const char *text, unsigned int len, bool with_padding)
{
XRectangle r;
int padding = with_padding ? 2 * H_TEXT_PAD : 0;
@ -449,7 +464,8 @@ int win_textwidth(const char *text, unsigned int len, bool with_padding) {
}
}
void win_set_title(win_t *win, const char *title) {
void win_set_title(win_t *win, const char *title)
{
if (win == NULL || win->xwin == None)
return;
@ -469,14 +485,16 @@ void win_set_title(win_t *win, const char *title) {
PropModeReplace, (unsigned char *) title, strlen(title));
}
void win_set_bar_info(win_t *win, char *linfo, char *rinfo) {
void win_set_bar_info(win_t *win, char *linfo, char *rinfo)
{
if (win != NULL) {
win->bar.l = linfo;
win->bar.r = rinfo;
}
}
void win_set_cursor(win_t *win, cursor_t cursor) {
void win_set_cursor(win_t *win, cursor_t cursor)
{
if (win == NULL || win->xwin == None)
return;