nsxiv4383a65
Strictly adhere to ANSI-C standard
+26 −35
8 files changed
- M Makefile +2 −2
- M config.c +1 −1
- M image.c +2 −3
- M main.c +3 −3
- M options.c +1 −1
- M thumbs.c +1 −1
- M util.c +1 −1
- M util.h +15 −23
| @@ -1,7 +1,7 @@ | |||
| 1 | − | VERSION = git-20111012 | |
| 1 | + | VERSION = git-20111013 | |
| 2 | 2 | ||
| 3 | 3 | CC = gcc | |
| 4 | − | CFLAGS = -Wall -pedantic -O2 | |
| 4 | + | CFLAGS = -ansi -Wall -pedantic -O2 | |
| 5 | 5 | LDFLAGS = | |
| 6 | 6 | LIBS = -lX11 -lImlib2 | |
| 7 | 7 | ||
| @@ -9,7 +9,7 @@ | |||
| 9 | 9 | #define PUT_MACRO(m) \ | |
| 10 | 10 | printf(" -D%s=%s", #m, QUOTE(m)) | |
| 11 | 11 | ||
| 12 | − | inline int puts_if(const char *s, int c) { | |
| 12 | + | int puts_if(const char *s, int c) { | |
| 13 | 13 | return c ? printf(" %s", s) : 0; | |
| 14 | 14 | } | |
| 15 | 15 | ||
| @@ -43,7 +43,6 @@ enum { MIN_GIF_DELAY = 50 }; | |||
| 43 | 43 | float zoom_min; | |
| 44 | 44 | float zoom_max; | |
| 45 | 45 | ||
| 46 | − | static inline | |
| 47 | 46 | bool zoomdiff(float z1, float z2) { | |
| 48 | 47 | const float mindelta = 0.001; | |
| 49 | 48 | return (z1 - z2 > mindelta) || (z1 - z2 < mindelta); | |
| @@ -311,11 +310,11 @@ bool img_load(img_t *img, const fileinfo_t *file) { | |||
| 311 | 310 | (void) fmt; | |
| 312 | 311 | ||
| 313 | 312 | #if EXIF_SUPPORT | |
| 314 | − | if (streq(fmt, "jpeg")) | |
| 313 | + | if (STREQ(fmt, "jpeg")) | |
| 315 | 314 | exif_auto_orientate(file); | |
| 316 | 315 | #endif | |
| 317 | 316 | #if GIF_SUPPORT | |
| 318 | − | if (streq(fmt, "gif")) | |
| 317 | + | if (STREQ(fmt, "gif")) | |
| 319 | 318 | img_load_gif(img, file); | |
| 320 | 319 | #endif | |
| 321 | 320 | ||
| @@ -145,7 +145,7 @@ void set_timeout(timeout_f handler, int time, bool overwrite) { | |||
| 145 | 145 | if (timeouts[i].handler == handler) { | |
| 146 | 146 | if (!timeouts[i].active || overwrite) { | |
| 147 | 147 | gettimeofday(&timeouts[i].when, 0); | |
| 148 | − | tv_add_msec(&timeouts[i].when, time); | |
| 148 | + | TV_ADD_MSEC(&timeouts[i].when, time); | |
| 149 | 149 | timeouts[i].active = true; | |
| 150 | 150 | } | |
| 151 | 151 | return; | |
| @@ -171,7 +171,7 @@ bool check_timeouts(struct timeval *t) { | |||
| 171 | 171 | gettimeofday(&now, 0); | |
| 172 | 172 | while (i < ARRLEN(timeouts)) { | |
| 173 | 173 | if (timeouts[i].active) { | |
| 174 | − | tdiff = tv_diff(&timeouts[i].when, &now); | |
| 174 | + | tdiff = TV_DIFF(&timeouts[i].when, &now); | |
| 175 | 175 | if (tdiff <= 0) { | |
| 176 | 176 | timeouts[i].active = false; | |
| 177 | 177 | if (timeouts[i].handler != NULL) | |
| @@ -184,7 +184,7 @@ bool check_timeouts(struct timeval *t) { | |||
| 184 | 184 | i++; | |
| 185 | 185 | } | |
| 186 | 186 | if (tmin > 0 && t != NULL) | |
| 187 | − | tv_set_msec(t, tmin); | |
| 187 | + | TV_SET_MSEC(t, tmin); | |
| 188 | 188 | return tmin > 0; | |
| 189 | 189 | } | |
| 190 | 190 | ||
| @@ -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 | } | |
| @@ -258,7 +258,7 @@ bool tns_load(tns_t *tns, int n, const fileinfo_t *file, | |||
| 258 | 258 | (void) fmt; | |
| 259 | 259 | ||
| 260 | 260 | #if EXIF_SUPPORT | |
| 261 | − | if (!cache_hit && streq(fmt, "jpeg")) | |
| 261 | + | if (!cache_hit && STREQ(fmt, "jpeg")) | |
| 262 | 262 | exif_auto_orientate(file); | |
| 263 | 263 | #endif | |
| 264 | 264 | ||
| @@ -272,7 +272,7 @@ char* r_readdir(r_dir_t *rdir) { | |||
| 272 | 272 | ||
| 273 | 273 | while (true) { | |
| 274 | 274 | if (rdir->dir != NULL && (dentry = readdir(rdir->dir)) != NULL) { | |
| 275 | − | if (streq(dentry->d_name, ".") || streq(dentry->d_name, "..")) | |
| 275 | + | if (STREQ(dentry->d_name, ".") || STREQ(dentry->d_name, "..")) | |
| 276 | 276 | continue; | |
| 277 | 277 | ||
| 278 | 278 | len = strlen(rdir->name) + strlen(dentry->d_name) + 2; | |
| @@ -36,6 +36,21 @@ | |||
| 36 | 36 | ||
| 37 | 37 | #define ARRLEN(a) (sizeof(a) / sizeof((a)[0])) | |
| 38 | 38 | ||
| 39 | + | #define STREQ(s1,s2) (strcmp((s1), (s2)) == 0) | |
| 40 | + | ||
| 41 | + | #define TV_DIFF(t1,t2) (((t1)->tv_sec - (t2)->tv_sec ) * 1000 + \ | |
| 42 | + | ((t1)->tv_usec - (t2)->tv_usec) / 1000) | |
| 43 | + | ||
| 44 | + | #define TV_SET_MSEC(tv,t) { \ | |
| 45 | + | (tv)->tv_sec = (t) / 1000; \ | |
| 46 | + | (tv)->tv_usec = (t) % 1000 * 1000; \ | |
| 47 | + | } | |
| 48 | + | ||
| 49 | + | #define TV_ADD_MSEC(tv,t) { \ | |
| 50 | + | (tv)->tv_sec = (t) / 1000; \ | |
| 51 | + | (tv)->tv_usec = (t) % 1000 * 1000; \ | |
| 52 | + | } | |
| 53 | + | ||
| 39 | 54 | typedef struct { | |
| 40 | 55 | DIR *dir; | |
| 41 | 56 | char *name; | |
| @@ -46,29 +61,6 @@ typedef struct { | |||
| 46 | 61 | int stlen; | |
| 47 | 62 | } r_dir_t; | |
| 48 | 63 | ||
| 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 | − | ||
| 72 | 64 | void* s_malloc(size_t); | |
| 73 | 65 | void* s_realloc(void*, size_t); | |
| 74 | 66 | char* s_strdup(char*); | |