2 Copyright © 1995-2013, 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 dos.library/Open(), dos.library/Close(), ReadByte(), ReadWord(),
59 ReadLong(), ReadFloat(),
60 ReadString(), ReadStruct(), WriteByte(), WriteWord(), WriteLong(),
61 WriteFloat(), WriteDouble(), WriteString(), WriteStruct()
63 ******************************************************************************/
66 struct FreeLevel
* curr
;
68 # define list ((struct List *)&_list)
72 if (!(curr
= AllocMem (sizeof (struct FreeLevel
), MEMF_ANY
)) )
75 AddTail (list
, (struct Node
*)curr
);
81 # define DESC curr->sd[curr->pos]
82 # define IDESC curr->sd[curr->pos ++]
96 case SDT_UBYTE
: /* Read one 8bit byte */
97 case SDT_UWORD
: /* Read one 16bit word */
98 case SDT_ULONG
: /* Read one 32bit long */
99 case SDT_FLOAT
: /* Read one 32bit IEEE */
100 case SDT_DOUBLE
: /* Read one 64bit IEEE */
101 case SDT_IGNORE
: /* Ignore x bytes */
106 case SDT_STRING
: { /* Read a string */
109 sptr
= *(STRPTR
*)(curr
->s
+ IDESC
);
115 case SDT_STRUCT
: { /* Read a structure */
116 /* Ignore two parameters */
121 case SDT_PTR
: { /* Follow a pointer */
122 struct FreeLevel
* next
;
127 aptr
= ((APTR
*)(curr
->s
+ IDESC
));
128 desc
= (IPTR
*)IDESC
;
132 if (!(next
= AllocMem (sizeof (struct FreeLevel
), MEMF_ANY
)) )
135 AddTail (list
, (struct Node
*)next
);
145 case SDT_FILL_BYTE
: /* Fill x bytes */
146 case SDT_FILL_LONG
: /* Fill x longs */
147 case SDT_IFILL_BYTE
: /* Fill x bytes */
148 case SDT_IFILL_LONG
: /* Fill x longs */
149 curr
->pos
+= 3; /* Ignore three parameters */
152 case SDT_SPECIAL
: { /* Call user hook */
156 data
.sdd_Dest
= ((APTR
)(curr
->s
+ IDESC
));
157 data
.sdd_Mode
= SDV_SPECIALMODE_FREE
;
159 hook
= (struct Hook
*)IDESC
;
161 CallHookA (hook
, NULL
, &data
);
167 /* End of the description list ? */
170 struct FreeLevel
* last
;
172 /* Remove the current level */
174 Remove ((struct Node
*)last
);
176 /* Get the last level */
177 if ((curr
= (struct FreeLevel
*)GetTail (list
)))
179 FreeMem (last
->s
, last
->size
);
180 FreeMem (last
, sizeof (struct FreeLevel
));
189 FreeMem (curr
->s
, curr
->size
);
190 FreeMem (curr
, sizeof (struct FreeLevel
));
195 while ((curr
= (struct FreeLevel
*)RemTail (list
)))
196 FreeMem (curr
, sizeof (struct FreeLevel
));