nsxiv22d4e99
Transformed function macros in util.h to inline functions
+35 −24
7 files changed
- M Makefile +1 −1
- M image.c +2 −2
- M main.c +3 −3
- M options.c +1 −1
- M thumbs.c +1 −1
- M util.c +1 −1
- M util.h +26 −15
| @@ -1,4 +1,4 @@ | |||
| 1 | − | VERSION = git-20110928 | |
| 1 | + | VERSION = git-20110929 | |
| 2 | 2 | ||
| 3 | 3 | CC = gcc | |
| 4 | 4 | CFLAGS = -Wall -pedantic -O2 | |
| @@ -303,11 +303,11 @@ bool img_load(img_t *img, const fileinfo_t *file) { | |||
| 303 | 303 | (void) fmt; | |
| 304 | 304 | ||
| 305 | 305 | #if EXIF_SUPPORT | |
| 306 | − | if (STREQ(fmt, "jpeg")) | |
| 306 | + | if (streq(fmt, "jpeg")) | |
| 307 | 307 | exif_auto_orientate(file); | |
| 308 | 308 | #endif | |
| 309 | 309 | #if GIF_SUPPORT | |
| 310 | − | if (STREQ(fmt, "gif")) | |
| 310 | + | if (streq(fmt, "gif")) | |
| 311 | 311 | img_load_gif(img, file); | |
| 312 | 312 | #endif | |
| 313 | 313 | ||
| @@ -144,7 +144,7 @@ void set_timeout(timeout_f handler, int time, bool overwrite) { | |||
| 144 | 144 | if (timeouts[i].handler == handler) { | |
| 145 | 145 | if (!timeouts[i].active || overwrite) { | |
| 146 | 146 | gettimeofday(&timeouts[i].when, 0); | |
| 147 | − | MSEC_ADD_TO_TIMEVAL(time, &timeouts[i].when); | |
| 147 | + | tv_add_msec(&timeouts[i].when, time); | |
| 148 | 148 | timeouts[i].active = true; | |
| 149 | 149 | } | |
| 150 | 150 | return; | |
| @@ -170,7 +170,7 @@ bool check_timeouts(struct timeval *t) { | |||
| 170 | 170 | gettimeofday(&now, 0); | |
| 171 | 171 | while (i < ARRLEN(timeouts)) { | |
| 172 | 172 | if (timeouts[i].active) { | |
| 173 | − | tdiff = TIMEDIFF(&timeouts[i].when, &now); | |
| 173 | + | tdiff = tv_diff(&timeouts[i].when, &now); | |
| 174 | 174 | if (tdiff <= 0) { | |
| 175 | 175 | timeouts[i].active = false; | |
| 176 | 176 | if (timeouts[i].handler) | |
| @@ -183,7 +183,7 @@ bool check_timeouts(struct timeval *t) { | |||
| 183 | 183 | i++; | |
| 184 | 184 | } | |
| 185 | 185 | if (tmin > 0 && t) | |
| 186 | − | MSEC_TO_TIMEVAL(tmin, t); | |
| 186 | + | tv_set_msec(t, tmin); | |
| 187 | 187 | return tmin > 0; | |
| 188 | 188 | } | |
| 189 | 189 | ||
| @@ -140,5 +140,5 @@ void parse_options(int argc, char **argv) { | |||
| 140 | 140 | _options.filenames = argv + optind; | |
| 141 | 141 | _options.filecnt = argc - optind; | |
| 142 | 142 | _options.from_stdin = _options.filecnt == 1 && | |
| 143 | − | STREQ(_options.filenames[0], "-"); | |
| 143 | + | streq(_options.filenames[0], "-"); | |
| 144 | 144 | } | |
| @@ -255,7 +255,7 @@ bool tns_load(tns_t *tns, int n, const fileinfo_t *file, | |||
| 255 | 255 | (void) fmt; | |
| 256 | 256 | ||
| 257 | 257 | #if EXIF_SUPPORT | |
| 258 | − | if (!cache_hit && STREQ(fmt, "jpeg")) | |
| 258 | + | if (!cache_hit && streq(fmt, "jpeg")) | |
| 259 | 259 | exif_auto_orientate(file); | |
| 260 | 260 | #endif | |
| 261 | 261 | ||
| @@ -270,7 +270,7 @@ char* r_readdir(r_dir_t *rdir) { | |||
| 270 | 270 | ||
| 271 | 271 | while (1) { | |
| 272 | 272 | if (rdir->dir && (dentry = readdir(rdir->dir))) { | |
| 273 | − | if (STREQ(dentry->d_name, ".") || STREQ(dentry->d_name, "..")) | |
| 273 | + | if (streq(dentry->d_name, ".") || streq(dentry->d_name, "..")) | |
| 274 | 274 | continue; | |
| 275 | 275 | ||
| 276 | 276 | len = strlen(rdir->name) + strlen(dentry->d_name) + 2; | |
| @@ -22,8 +22,11 @@ | |||
| 22 | 22 | #include <stdio.h> | |
| 23 | 23 | #include <stdarg.h> | |
| 24 | 24 | #include <dirent.h> | |
| 25 | + | #include <sys/time.h> | |
| 25 | 26 | #include <sys/types.h> | |
| 26 | 27 | ||
| 28 | + | #include "types.h" | |
| 29 | + | ||
| 27 | 30 | #ifndef MIN | |
| 28 | 31 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) | |
| 29 | 32 | #endif | |
| @@ -33,21 +36,6 @@ | |||
| 33 | 36 | ||
| 34 | 37 | #define ARRLEN(a) (sizeof(a) / sizeof((a)[0])) | |
| 35 | 38 | ||
| 36 | − | #define STREQ(a,b) (!strcmp((a), (b))) | |
| 37 | − | ||
| 38 | − | #define TIMEDIFF(t1,t2) (((t1)->tv_sec - (t2)->tv_sec) * 1000 + \ | |
| 39 | − | ((t1)->tv_usec - (t2)->tv_usec) / 1000) | |
| 40 | − | ||
| 41 | − | #define MSEC_TO_TIMEVAL(t,tv) { \ | |
| 42 | − | (tv)->tv_sec = (t) / 1000; \ | |
| 43 | − | (tv)->tv_usec = (t) % 1000 * 1000; \ | |
| 44 | − | } | |
| 45 | − | ||
| 46 | − | #define MSEC_ADD_TO_TIMEVAL(t,tv) { \ | |
| 47 | − | (tv)->tv_sec += (t) / 1000; \ | |
| 48 | − | (tv)->tv_usec += (t) % 1000 * 1000; \ | |
| 49 | − | } | |
| 50 | − | ||
| 51 | 39 | typedef struct { | |
| 52 | 40 | DIR *dir; | |
| 53 | 41 | char *name; | |
| @@ -58,6 +46,29 @@ typedef struct { | |||
| 58 | 46 | int stlen; | |
| 59 | 47 | } r_dir_t; | |
| 60 | 48 | ||
| 49 | + | static inline | |
| 50 | + | bool streq(const char *a, const char *b) { | |
| 51 | + | return strcmp(a, b) == 0; | |
| 52 | + | } | |
| 53 | + | ||
| 54 | + | static inline | |
| 55 | + | long tv_diff(const struct timeval *t1, const struct timeval *t2) { | |
| 56 | + | return (t1->tv_sec - t2->tv_sec) * 1000 + | |
| 57 | + | (t1->tv_usec - t2->tv_usec) / 1000; | |
| 58 | + | } | |
| 59 | + | ||
| 60 | + | static inline | |
| 61 | + | void tv_set_msec(struct timeval *t, int msec) { | |
| 62 | + | t->tv_sec = msec / 1000; | |
| 63 | + | t->tv_usec = msec % 1000 * 1000; | |
| 64 | + | } | |
| 65 | + | ||
| 66 | + | static inline | |
| 67 | + | void tv_add_msec(struct timeval *t, int msec) { | |
| 68 | + | t->tv_sec += msec / 1000; | |
| 69 | + | t->tv_usec += msec % 1000 * 1000; | |
| 70 | + | } | |
| 71 | + | ||
| 61 | 72 | void* s_malloc(size_t); | |
| 62 | 73 | void* s_realloc(void*, size_t); | |
| 63 | 74 | char* s_strdup(char*); | |