New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / compiler / alib / alib_util.c
blob32ce1d026b61ac849584745300c0dd5f30d6fa3c
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
5 Internal utility functions.
6 */
8 #include <aros/system.h>
9 #include "alib_intern.h"
11 #ifdef AROS_SLOWSTACKMETHODS
12 /******************************************************************************
14 NAME */
15 Msg GetMsgFromStack (
17 /* SYNOPSIS */
18 ULONG MethodID,
19 va_list args)
21 /* FUNCTION
22 Builds a message structure with the parameters which are passed on
23 the stack. This function is used on machines which have compilers
24 which don't pass the arguments to a varargs function unlike the
25 Amiga ones.
27 INPUTS
28 MethodID - This is the ID of the message
29 args - This has to be initialized by va_start()
30 firstlocal - The address of the first local function of the
31 function which wants to call GetMsgFromStack()
33 RESULT
34 A message which can be passed to any function which expects the
35 structure which is defined for this MethodID or NULL if something
36 failed. This call may fail for different reasons on different
37 systems. On some systems, NULL indicates that there was not enough
38 memory, on others that the MethodID is unknown.
40 NOTES
41 This function fails for structures with more than 20 fields.
43 EXAMPLE
45 BUGS
47 SEE ALSO
48 NewObject(), SetAttrs(), GetAttr(), DisposeObject(), DoMethod(),
49 DoSuperMethod(), "Basic Object-Oriented Programming System for
50 Intuition" and the "boopsi Class Reference" Dokument.
52 INTERNALS
53 HPPA: Allocate a structure which can contain all ULONGs between
54 the first argument of, for example, DoMethod() and its first local
55 variable. This will copy a bit too much memory but in the end, it
56 saves a lot of work, since it's not neccessary to register every
57 structure.
59 HISTORY
60 22.11.96 digulla created
62 ******************************************************************************/
64 #if !AROS_STACK_GROWS_DOWNWARDS
65 ULONG size;
66 Msg msg;
68 size = 21;
70 if ((msg = AllocVec (size * sizeof (ULONG), MEMF_CLEAR)))
72 ULONG * ulptr = (ULONG * msg);
74 *ulptr ++ = MethodID;
76 while (-- size)
78 *ulptr ++ = va_arg (args, ULONG);
82 return msg;
83 #else
84 return NULL;
85 #endif
86 } /* GetMsgFromStack */
88 /******************************************************************************
90 NAME */
91 void FreeMsgFromStack (
93 /* SYNOPSIS */
94 Msg msg)
96 /* FUNCTION
97 Frees the memory occupied by the message which was created by
98 GetMsgFromStack().
100 INPUTS
101 msg - The return value of GetMsgFromStack(). May be NULL.
103 RESULT
104 None.
106 NOTES
108 EXAMPLE
110 BUGS
112 SEE ALSO
113 GetMsgFromStack()
115 HISTORY
116 22.11.96 digulla created
118 ******************************************************************************/
120 if (msg)
121 FreeVec (msg);
122 } /* FreeMsgFromStack */
124 #endif /* AROS_SLOWSTACKMETHODS */
126 #ifdef AROS_SLOWSTACKTAGS
127 /******************************************************************************
129 NAME */
130 struct TagItem * GetTagsFromStack (
132 /* SYNOPSIS */
133 ULONG firstTag,
134 va_list args)
136 /* FUNCTION
137 Builds a tagitem array with the tags on the stack. This function is
138 used on machines which have compilers which don't pass the
139 arguments to a varargs function unlike the Amiga ones.
141 INPUTS
142 firstTag - This is the first tag passed to the function
143 args - This has to be initialized by va_start()
145 RESULT
146 A TagItem array which can be passed to any function which expects
147 such an array or NULL if something failed. This call may fail for
148 different reasons on different systems. On some systems, NULL
149 indicates that there was not enough memory, on others that the
150 MethodID is unknown.
152 NOTES
154 EXAMPLE
156 BUGS
158 SEE ALSO
159 NewObject(), SetAttrs(), GetAttr(), DisposeObject(), DoMethod(),
160 DoSuperMethod(), "Basic Object-Oriented Programming System for
161 Intuition" and the "boopsi Class Reference" Dokument.
163 INTERNALS
164 Allocate a structure which can contain all tags until the first
165 TAG_END. This takes into account TAG_MORE and the like. The code
166 will break if someone makes assumptions about the way taglists
167 are built in memory, ie. if he looks for the next TAG_MORE and
168 then simply skips it instead of following it.
170 HISTORY
171 22.11.96 digulla created
173 ******************************************************************************/
175 struct TagItem * ti;
176 ULONG tag;
177 ULONG size;
178 va_list ap;
180 va_copy(ap, args);
181 tag = firstTag;
183 for (size=0;;size++)
185 if (tag == TAG_END || tag == TAG_MORE)
187 size ++; /* Copy this tag, too */
188 break;
191 switch (tag)
193 case TAG_IGNORE:
194 size --; /* Don't copy this tag */
195 break;
197 case TAG_SKIP: {
198 ULONG skip;
200 skip = va_arg(args, IPTR);
202 while (skip --)
204 (void) va_arg(args, ULONG);
205 (void) va_arg(args, IPTR);
208 break; }
210 default:
211 (void) va_arg(args, IPTR);
214 tag = va_arg (args, ULONG);
217 tag = firstTag;
219 if ((msg = AllocVec (size*sizeof(TagItem), MEMF_ANY)))
221 for (size=0;;size++)
223 ti[size].ti_Tag = tag;
225 if (tag == TAG_END)
226 break;
227 else if (tag == TAG_MORE)
229 ti[size].ti_Data = (IPTR) va_arg (ap, struct TagItem *);
230 break;
233 switch (tag)
235 case TAG_IGNORE:
236 size --; /* Don't copy this tag */
237 break;
239 case TAG_SKIP: {
240 ULONG skip;
242 skip = va_arg(ap, IPTR);
244 while (skip --)
246 (void) va_arg(ap, ULONG);
247 (void) va_arg(ap, IPTR);
250 break; }
252 default:
253 ti[size].ti_Data = va_arg(ap, IPTR);
256 tag = va_arg (ap, ULONG);
259 va_end(ap);
260 return msg;
261 } /* GetTagsFromStack */
263 /******************************************************************************
265 NAME */
266 void FreeTagsFromStack (
268 /* SYNOPSIS */
269 struct TagItem * tags)
271 /* FUNCTION
272 Frees the memory occupied by the tagitems which were created by
273 GetTagsFromStack().
275 INPUTS
276 tags - The return value of GetTagsFromStack(). May be NULL.
278 RESULT
279 None.
281 NOTES
283 EXAMPLE
285 BUGS
287 SEE ALSO
288 GetTagsFromStack()
290 HISTORY
291 22.11.96 digulla created
293 ******************************************************************************/
295 if (tags)
296 FreeVec (tags);
297 } /* FreeTagsFromStack */
299 #endif /* AROS_SLOWSTACKTAGS */