2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
5 Desc: Free a structure returned by ReadStruct()
10 #include <exec/memory.h>
11 #include <proto/dos.h>
12 #include <proto/exec.h>
13 #include <aros/debug.h>
14 #include <utility/hooks.h>
25 /******************************************************************************
29 #include <aros/bigendianio.h>
30 #include <proto/alib.h>
39 Free a structure which was created by ReadStruct().
42 data - This was returned by ReadStruct() in the dataptr parameter.
44 sd - Description of the structure to be read. The first element
45 is the size of the structure.
58 Open(), Close(), ReadByte(), ReadWord(), ReadLong(), ReadFloat(),
59 ReadString(), ReadStruct(), WriteByte(), WriteWord(), WriteLong(),
60 WriteFloat(), WriteDouble(), WriteString(), WriteStruct()
65 ******************************************************************************/
68 struct FreeLevel
* curr
;
70 # define list ((struct List *)&_list)
74 if (!(curr
= AllocMem (sizeof (struct FreeLevel
), MEMF_ANY
)) )
77 AddTail (list
, (struct Node
*)curr
);
83 # define DESC curr->sd[curr->pos]
84 # define IDESC curr->sd[curr->pos ++]
98 case SDT_UBYTE
: /* Read one 8bit byte */
99 case SDT_UWORD
: /* Read one 16bit word */
100 case SDT_ULONG
: /* Read one 32bit long */
101 case SDT_FLOAT
: /* Read one 32bit IEEE */
102 case SDT_DOUBLE
: /* Read one 64bit IEEE */
103 case SDT_IGNORE
: /* Ignore x bytes */
108 case SDT_STRING
: { /* Read a string */
111 sptr
= *(STRPTR
*)(curr
->s
+ IDESC
);
118 case SDT_STRUCT
: { /* Read a structure */
119 /* Ignore two parameters */
124 case SDT_PTR
: { /* Follow a pointer */
125 struct FreeLevel
* next
;
130 aptr
= ((APTR
*)(curr
->s
+ IDESC
));
131 desc
= (IPTR
*)IDESC
;
135 if (!(next
= AllocMem (sizeof (struct FreeLevel
), MEMF_ANY
)) )
138 AddTail (list
, (struct Node
*)next
);
148 case SDT_FILL_BYTE
: /* Fill x bytes */
149 case SDT_FILL_LONG
: /* Fill x longs */
150 case SDT_IFILL_BYTE
: /* Fill x bytes */
151 case SDT_IFILL_LONG
: /* Fill x longs */
152 curr
->pos
+= 3; /* Ignore three parameters */
155 case SDT_SPECIAL
: { /* Call user hook */
159 data
.sdd_Dest
= ((APTR
)(curr
->s
+ IDESC
));
160 data
.sdd_Mode
= SDV_SPECIALMODE_FREE
;
162 hook
= (struct Hook
*)IDESC
;
164 CallHookA (hook
, NULL
, &data
);
170 /* End of the description list ? */
173 struct FreeLevel
* last
;
175 /* Remove the current level */
177 Remove ((struct Node
*)last
);
179 /* Get the last level */
180 if ((curr
= (struct FreeLevel
*)GetTail (list
)))
182 FreeMem (last
->s
, last
->size
);
183 FreeMem (last
, sizeof (struct FreeLevel
));
192 FreeMem (curr
->s
, curr
->size
);
193 FreeMem (curr
, sizeof (struct FreeLevel
));
198 while ((curr
= (struct FreeLevel
*)RemTail (list
)))
199 FreeMem (curr
, sizeof (struct FreeLevel
));