1 #ifndef TOOLLIB_TOOLLIB_H
2 #define TOOLLIB_TOOLLIB_H
5 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
11 /* Do we have <stdarg.h> ? */
13 # define HAVE_STDARG_H
26 #endif /* PROTOTYPES */
28 #if defined(HAVE_STDARG_H) && defined(__STDC__) && __STDC__
30 # define VA_START(args, lastarg) va_start(args, lastarg)
33 # define VA_START(args, lastarg) va_start(args)
39 typedef struct _Node Node
;
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 \
81 # define GetTail(l) (void *)(((List *)l)->prelast->prev \
82 ? ((List *)l)->prelast \
84 # define GetNext(n) (void *)(((Node *)n)->next->next \
87 # define GetPrev(n) (void *)(((Node *)n)->prev->prev \
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); \
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__)
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 */