File: util.h

package info (click to toggle)
tcng 10b-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,632 kB
  • ctags: 2,515
  • sloc: ansic: 19,038; pascal: 4,640; yacc: 2,619; sh: 1,908; perl: 1,546; lex: 772; makefile: 755
file content (73 lines) | stat: -rw-r--r-- 2,076 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * util.h - Utility functions
 *
 * Written 2001,2002,2004 by Werner Almesberger
 * Copyright 2001 EPFL-ICA
 * Copyright 2001,2002 Bivio Networks, Network Robots
 * Copyright 2004 Werner Almesberger
 */


#ifndef UTIL_H
#define UTIL_H

#include <memutil.h>


#define UNDEF_U32 (~0U)


/* ----- Helper functions for performance tuning --------------------------- */


void start_timer(void);
void print_timer(const char *label);


/* ----- Macros to simplify handling of default parameters ----------------- */

/*
 * Define list of default parameters as follows:
 *
 * #define __DEFAULT_PRM(f) f(param1) f(param2) ...
 */

#define __DP_LIST(p) &prm_##p,
#define __DP_DECL(p) prm_##p##_default,
#define __DP_ARGS(p) PARAM_DSC prm_##p##_default,
#define __DP_PASS(p) prm_##p,
#define __DP_SET(p) prm_##p##_default = prm_##p;
#define __DP_GET(p) if (!prm_##p.present) prm_##p = prm_##p##_default;
#define __DP_CHECK(p) \
  if (!prm_##p.present) lerrorf(loc,"required parameter \"%s\" is missing",#p);
#define DEFAULT_LIST __DEFAULT_PRM(__DP_LIST)
#define DEFAULT_ARGS __DEFAULT_PRM(__DP_ARGS) void *__unused
#define DEFAULT_PASS __DEFAULT_PRM(__DP_PASS) NULL
#define DEFAULT_DECL \
  PARAM_DSC __DEFAULT_PRM(__DP_DECL) __attribute__((unused)) __unused
#define DEFAULT_SET \
  do { __DEFAULT_PRM(__DP_SET) } while (0)
#define DEFAULT_GET \
  do { __DEFAULT_PRM(__DP_GET) } while (0)
#define DEFAULT_CHECK(l) \
  do { LOCATION loc = l; __DEFAULT_PRM_REQ(__DP_CHECK) } while (0)

/*
 * When recursing, we need another set of variables to save defaults to.
 */

#define __DP_DECL_SAVED(p) prm_##p##_saved,
#define __DP_PASS_SAVED(p) prm_##p##_saved,
#define __DP_SAVE(p) prm_##p##_saved = prm_##p;
#define DEFAULT_PASS_SAVED __DEFAULT_PRM(__DP_PASS_SAVED) NULL
#define DEFAULT_DECL_SAVED \
  PARAM_DSC __DEFAULT_PRM(__DP_DECL_SAVED) __attribute__((unused)) __unused
#define DEFAULT_SAVE \
  do { __DEFAULT_PRM(__DP_SAVE) } while (0)


/* ----- Helper function for qsort ----------------------------------------- */

int comp_int(const void *a,const void *b);

#endif /* UTIL_H */