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 exec.library/Open(), exec.library/Close(), ReadByte(), ReadWord(),
59 ReadLong(), ReadFloat(),
60 ReadString(), ReadStruct(), WriteByte(), WriteWord(), WriteLong(),
61 WriteFloat(), WriteDouble(), WriteString(), WriteStruct()
66 ******************************************************************************/
69 struct FreeLevel
* curr
;
71 # define list ((struct List *)&_list)
75 if (!(curr
= AllocMem (sizeof (struct FreeLevel
), MEMF_ANY
)) )
78 AddTail (list
, (struct Node
*)curr
);
84 # define DESC curr->sd[curr->pos]
85 # define IDESC curr->sd[curr->pos ++]
99 case SDT_UBYTE
: /* Read one 8bit byte */
100 case SDT_UWORD
: /* Read one 16bit word */
101 case SDT_ULONG
: /* Read one 32bit long */
102 case SDT_FLOAT
: /* Read one 32bit IEEE */
103 case SDT_DOUBLE
: /* Read one 64bit IEEE */
104 case SDT_IGNORE
: /* Ignore x bytes */
109 case SDT_STRING
: { /* Read a string */
112 sptr
= *(STRPTR
*)(curr
->s
+ IDESC
);
119 case SDT_STRUCT
: { /* Read a structure */
120 /* Ignore two parameters */
125 case SDT_PTR
: { /* Follow a pointer */
126 struct FreeLevel
* next
;
131 aptr
= ((APTR
*)(curr
->s
+ IDESC
));
132 desc
= (IPTR
*)IDESC
;
136 if (!(next
= AllocMem (sizeof (struct FreeLevel
), MEMF_ANY
)) )
139 AddTail (list
, (struct Node
*)next
);
149 case SDT_FILL_BYTE
: /* Fill x bytes */
150 case SDT_FILL_LONG
: /* Fill x longs */
151 case SDT_IFILL_BYTE
: /* Fill x bytes */
152 case SDT_IFILL_LONG
: /* Fill x longs */
153 curr
->pos
+= 3; /* Ignore three parameters */
156 case SDT_SPECIAL
: { /* Call user hook */
160 data
.sdd_Dest
= ((APTR
)(curr
->s
+ IDESC
));
161 data
.sdd_Mode
= SDV_SPECIALMODE_FREE
;
163 hook
= (struct Hook
*)IDESC
;
165 CallHookA (hook
, NULL
, &data
);
171 /* End of the description list ? */
174 struct FreeLevel
* last
;
176 /* Remove the current level */
178 Remove ((struct Node
*)last
);
180 /* Get the last level */
181 if ((curr
= (struct FreeLevel
*)GetTail (list
)))
183 FreeMem (last
->s
, last
->size
);
184 FreeMem (last
, sizeof (struct FreeLevel
));
193 FreeMem (curr
->s
, curr
->size
);
194 FreeMem (curr
, sizeof (struct FreeLevel
));
199 while ((curr
= (struct FreeLevel
*)RemTail (list
)))
200 FreeMem (curr
, sizeof (struct FreeLevel
));