wmbiff: use temporary variables and remove casts.
[dockapps.git] / wmhdplop / util.h
blobdf3954084f9ad2322ea2adfd6fb13996433123ee
1 #ifndef UTIL_H
2 #define UTIL_H
3 #include <assert.h>
4 #include <stdlib.h>
5 #include <stdio.h>
7 #ifndef MAX
8 # define MAX(x,y) ((x)>(y)?(x):(y))
9 #endif
10 #ifndef MIN
11 # define MIN(x,y) ((x)<(y)?(x):(y))
12 #endif
13 #ifndef SQR
14 # define SQR(a) ((a)*(a))
15 #endif
16 #ifndef ABS
17 # define ABS(a) ((a)>0?(a):-(a))
18 #endif
19 #define ALLOC_OBJ(p) { p = calloc(1, sizeof(*p)); assert(p);}
20 #define FREE_OBJ(p) free(p);
21 #define ALLOC_VEC(p, n) { p = calloc(n, sizeof(*(p))); assert(p); }
22 #define SET_VEC(p, v, i0, i1) { int _i; \
23 for (_i = (i0); _i < (i1); _i++) p[_i] = v; }
24 #define FREE_VEC(p) free(p);
26 #define ALLOC_ARR(v,nl,nc) \
27 { int __i; v = calloc(nl,sizeof(*(v))); assert(v); \
28 v[0]=calloc((nc)*(nl), sizeof(**(v))); assert((v)[0]); \
29 for (__i=1; __i < nl; ++__i) (v)[__i] = (v)[__i-1] + nc; }
30 #define FREE_ARR(p) { free(p[0]); free(p); }
31 #define BASE_ARR(p) (p[0])
33 #ifndef NO_BLAHBLAH
34 # define BLAHBLAH(n,x) if (Prefs.verbosity >= n) { x; fflush(stdout); }
35 #else
36 # define BLAHBLAH(n,x)
37 #endif
39 #define ONLY_ONCE(x) { static int __cnt = 0; if (__cnt++==0) { x;} }
40 #define ONLY_NTIMES(n,x) { static int __cnt = 0; if (__cnt++<n) { x;} }
44 /* macro for str_hache */
45 #define CVINT(a,b,c,d) (a + (b<<8) + (c<<16) + (d<<24))
47 #define IS_INSIDE(x, y, xmin, ymin, xmax, ymax) ((x) >= (xmin) && (x) <= (xmax) && (y) >= (ymin) && (y) <= (ymax))
49 char *str_dup(const char *s);
50 int str_is_empty(const char *s);
51 char *str_multi_str(const char *src, const char **keys, int nb_keys, int *key_idx);
52 char *str_multi_substitute(const char *src, const char **keys, const char **substitutions, int nkeys);
53 char *str_substitute(const char *src, const char *key, const char *substitution);
54 char *shell_quote(const char *src);
55 unsigned str_hash(const unsigned char *s, int max_len);
56 unsigned char chr_noaccent_tolower(unsigned char c);
57 void str_noaccent_tolower(unsigned char *s);
58 unsigned char *str_noaccent_casestr(const unsigned char *meule, const unsigned char *aiguille);
59 char *str_printf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
60 char *str_fget_line(FILE *f);
61 void str_trim(unsigned char *s);
63 typedef struct strlist {
64 char *s;
65 struct strlist *next;
66 } strlist;
67 strlist *strlist_ins(strlist *head, const char *s);
68 #endif