Krolyxon
Commit 4383a65

Branches

Refs →

nsxiv4383a65

Strictly adhere to ANSI-C standard

Author
Bert Münnich
Date
2011-10-13 16:50 +0200
Parent
a09b20c
Commit
4383a651c733ac59cd00f193c5115567f6a72f5d

+26 −35

8 files changed

  1. M Makefile +2 −2
  2. M config.c +1 −1
  3. M image.c +2 −3
  4. M main.c +3 −3
  5. M options.c +1 −1
  6. M thumbs.c +1 −1
  7. M util.c +1 −1
  8. M util.h +15 −23
M Makefile View
@@ -1,7 +1,7 @@
1−VERSION = git-20111012
1+VERSION = git-20111013
22
33 CC = gcc
4−CFLAGS = -Wall -pedantic -O2
4+CFLAGS = -ansi -Wall -pedantic -O2
55 LDFLAGS =
66 LIBS = -lX11 -lImlib2
77
M config.c View
@@ -9,7 +9,7 @@
99 #define PUT_MACRO(m) \
1010 printf(" -D%s=%s", #m, QUOTE(m))
1111
12−inline int puts_if(const char *s, int c) {
12+int puts_if(const char *s, int c) {
1313 return c ? printf(" %s", s) : 0;
1414 }
1515
M image.c View
@@ -43,7 +43,6 @@ enum { MIN_GIF_DELAY = 50 };
4343 float zoom_min;
4444 float zoom_max;
4545
46−static inline
4746 bool zoomdiff(float z1, float z2) {
4847 const float mindelta = 0.001;
4948 return (z1 - z2 > mindelta) || (z1 - z2 < mindelta);
@@ -311,11 +310,11 @@ bool img_load(img_t *img, const fileinfo_t *file) {
311310 (void) fmt;
312311
313312 #if EXIF_SUPPORT
314− if (streq(fmt, "jpeg"))
313+ if (STREQ(fmt, "jpeg"))
315314 exif_auto_orientate(file);
316315 #endif
317316 #if GIF_SUPPORT
318− if (streq(fmt, "gif"))
317+ if (STREQ(fmt, "gif"))
319318 img_load_gif(img, file);
320319 #endif
321320
M main.c View
@@ -145,7 +145,7 @@ void set_timeout(timeout_f handler, int time, bool overwrite) {
145145 if (timeouts[i].handler == handler) {
146146 if (!timeouts[i].active || overwrite) {
147147 gettimeofday(&timeouts[i].when, 0);
148− tv_add_msec(&timeouts[i].when, time);
148+ TV_ADD_MSEC(&timeouts[i].when, time);
149149 timeouts[i].active = true;
150150 }
151151 return;
@@ -171,7 +171,7 @@ bool check_timeouts(struct timeval *t) {
171171 gettimeofday(&now, 0);
172172 while (i < ARRLEN(timeouts)) {
173173 if (timeouts[i].active) {
174− tdiff = tv_diff(&timeouts[i].when, &now);
174+ tdiff = TV_DIFF(&timeouts[i].when, &now);
175175 if (tdiff <= 0) {
176176 timeouts[i].active = false;
177177 if (timeouts[i].handler != NULL)
@@ -184,7 +184,7 @@ bool check_timeouts(struct timeval *t) {
184184 i++;
185185 }
186186 if (tmin > 0 && t != NULL)
187− tv_set_msec(t, tmin);
187+ TV_SET_MSEC(t, tmin);
188188 return tmin > 0;
189189 }
190190
M options.c View
@@ -140,5 +140,5 @@ void parse_options(int argc, char **argv) {
140140 _options.filenames = argv + optind;
141141 _options.filecnt = argc - optind;
142142 _options.from_stdin = _options.filecnt == 1 &&
143− streq(_options.filenames[0], "-");
143+ STREQ(_options.filenames[0], "-");
144144 }
M thumbs.c View
@@ -258,7 +258,7 @@ bool tns_load(tns_t *tns, int n, const fileinfo_t *file,
258258 (void) fmt;
259259
260260 #if EXIF_SUPPORT
261− if (!cache_hit && streq(fmt, "jpeg"))
261+ if (!cache_hit && STREQ(fmt, "jpeg"))
262262 exif_auto_orientate(file);
263263 #endif
264264
M util.c View
@@ -272,7 +272,7 @@ char* r_readdir(r_dir_t *rdir) {
272272
273273 while (true) {
274274 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, ".."))
276276 continue;
277277
278278 len = strlen(rdir->name) + strlen(dentry->d_name) + 2;
M util.h View
@@ -36,6 +36,21 @@
3636
3737 #define ARRLEN(a) (sizeof(a) / sizeof((a)[0]))
3838
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+
3954 typedef struct {
4055 DIR *dir;
4156 char *name;
@@ -46,29 +61,6 @@ typedef struct {
4661 int stlen;
4762 } r_dir_t;
4863
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−
7264 void* s_malloc(size_t);
7365 void* s_realloc(void*, size_t);
7466 char* s_strdup(char*);