Workaround for includes conflict that stopped compilation with GCC 3.
[cake.git] / tools / toollib / toollib.h
blobaf0dfe67cd486442db12f8f64a7b0b51d8738727
1 #ifndef TOOLLIB_TOOLLIB_H
2 #define TOOLLIB_TOOLLIB_H
4 /*
5 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
6 $Id$
7 */
9 #include <sys/types.h>
11 /* Do we have <stdarg.h> ? */
12 #ifndef HAVE_STDARG_H
13 # define HAVE_STDARG_H
14 #endif
16 #ifndef PROTOTYPES
17 # ifdef __STDC__
18 # define PROTOTYPES
19 # endif
20 #endif
22 #ifdef PROTOTYPES
23 # define PARAMS(x) x
24 #else
25 # define PARAMS(x) ()
26 #endif /* PROTOTYPES */
28 #if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
29 # include <stdarg.h>
30 # define VA_START(args, lastarg) va_start(args, lastarg)
31 #else
32 # include <varargs.h>
33 # define VA_START(args, lastarg) va_start(args)
34 #endif
36 #include <stdlib.h>
38 /* Types */
39 typedef struct _Node Node;
41 struct _Node
43 Node * next,
44 * prev;
45 char * name;
48 typedef struct
50 Node * first,
51 * last,
52 * prelast;
54 List;
56 /* Macros */
57 # define IsListEmpty(l) (((List *)l)->prelast == (Node *)(l))
58 # define NewList(l) (((List *)l)->prelast = (Node *)(l), \
59 ((List *)l)->last = 0, \
60 ((List *)l)->first = (Node *)&(((List *)l)->last))
62 # define AddHead(l,n) ((void)(\
63 ((Node *)n)->next = ((List *)l)->first, \
64 ((Node *)n)->prev = (Node *)&((List *)l)->first, \
65 ((List *)l)->first->prev = ((Node *)n), \
66 ((List *)l)->first = ((Node *)n)))
68 # define AddTail(l,n) ((void)(\
69 ((Node *)n)->next = (Node *)&((List *)l)->last, \
70 ((Node *)n)->prev = ((List *)l)->prelast, \
71 ((List *)l)->prelast->next = ((Node *)n), \
72 ((List *)l)->prelast = ((Node *)n) ))
74 # define Remove(n) ((void)(\
75 ((Node *)n)->prev->next = ((Node *)n)->next,\
76 ((Node *)n)->next->prev = ((Node *)n)->prev ))
78 # define GetHead(l) (void *)(((List *)l)->first->next \
79 ? ((List *)l)->first \
80 : (Node *)0)
81 # define GetTail(l) (void *)(((List *)l)->prelast->prev \
82 ? ((List *)l)->prelast \
83 : (Node *)0)
84 # define GetNext(n) (void *)(((Node *)n)->next->next \
85 ? ((Node *)n)->next \
86 : (Node *)0)
87 # define GetPrev(n) (void *)(((Node *)n)->prev->prev \
88 ? ((Node *)n)->prev \
89 : (Node *)0)
90 # define ForeachNode(l,n) \
91 for (n=(void *)(((List *)(l))->first); \
92 ((Node *)(n))->next; \
93 n=(void *)(((Node *)(n))->next))
94 # define ForeachNodeSafe(l,node,nextnode) \
95 for (node=(void *)(((List *)(l))->first); \
96 ((nextnode)=(void*)((Node *)(node))->next); \
97 (node)=(void *)(nextnode))
99 #define cfree(x) if (x) free (x)
100 #define cstrdup(x) ((x) ? xstrdup (x) : NULL)
101 #define setstr(str,val) cfree (str); \
102 str = cstrdup (val)
103 #define xstrdup(str) _xstrdup(str,__FILE__,__LINE__)
104 #define xmalloc(size) _xmalloc(size,__FILE__,__LINE__)
105 #define xrealloc(ptr,size) _xrealloc(ptr,size,__FILE__,__LINE__)
106 #define xfree(ptr) _xfree(ptr,__FILE__,__LINE__)
107 #define new(type) (type *)xmalloc(sizeof(type))
108 #define ALIGN(x,y) ((x + (y-1)) & (-(y)))
109 #define hexval(c) (((c) > '9') ? (c) - 'a' + 10 : (c) - '0')
110 #define xcalloc(cnt,size) _xcalloc(cnt,size,__FILE__,__LINE__)
112 /* Prototypes */
113 extern int execute PARAMS ((const char * cmd, const char * args,
114 const char * in, const char * out));
115 extern char * _xstrdup PARAMS ((const char * str, const char * file, int line));
116 extern void * _xmalloc PARAMS ((size_t size, const char * file, int line));
117 extern void * _xrealloc PARAMS ((void * ptr, size_t size, const char * file, int line));
118 extern void _xfree PARAMS ((void * ptr, const char * file, int line));
119 extern void * _xcalloc PARAMS ((size_t cnt, size_t size, const char * file, int line));
120 extern Node * FindNode PARAMS ((const List * l, const char * name));
121 extern Node * FindNodeNC PARAMS ((const List * l, const char * name));
122 extern void printlist PARAMS ((const List * l));
123 extern Node * RemHead PARAMS ((List * l));
125 #endif /* TOOLLIB_TOOLLIB_H */