1/* struct::tree - critcl - layer 0 declarations
2 * API general utilities
3 */
4
5#ifndef _UTIL_H
6#define _UTIL_H 1
7
8#include <tcl.h>
9
10/* Allocation macros for common situations.
11 */
12
13#define ALLOC(type)    (type *) ckalloc (sizeof (type))
14#define NALLOC(n,type) (type *) ckalloc ((n) * sizeof (type))
15
16/* Assertions in general, and asserting the proper range of an array index.
17 */
18
19#undef  TREE_DEBUG
20#define TREE_DEBUG 1
21
22#ifdef TREE_DEBUG
23#define XSTR(x) #x
24#define STR(x) XSTR(x)
25#define RANGEOK(i,n) ((0 <= (i)) && (i < (n)))
26#define ASSERT(x,msg) if (!(x)) { Tcl_Panic (msg " (" #x "), in file " __FILE__ " @line " STR(__LINE__)) ;}
27#define ASSERT_BOUNDS(i,n) ASSERT (RANGEOK(i,n),"array index out of bounds: " STR(i) " > " STR(n))
28#else
29#define ASSERT(x,msg)
30#define ASSERT_BOUNDS(i,n)
31#endif
32
33/* .................................................. */
34
35/* NL  = Node List. Actually a list of generic pointers.
36 * NLQ = NL Queue. Also useable as stack.
37 */
38
39typedef struct NL *NLptr;
40
41typedef struct NL {
42    NLptr next;
43    void* n;
44} NL;
45
46typedef struct NLQ {
47    NLptr start;
48    NLptr end;
49} NLQ;
50
51void  nlq_init   (NLQ* q);
52void  nlq_append (NLQ* q, void* n);
53void  nlq_push   (NLQ* q, void* n);
54void* nlq_pop    (NLQ* q);
55void* nlq_clear  (NLQ* q);
56
57#endif /* _UTIL_H */
58
59/*
60 * Local Variables:
61 * mode: c
62 * c-basic-offset: 4
63 * fill-column: 78
64 * End:
65 */
66