2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
5 Desc: Free a structure returned by ReadStruct()
9 #include <exec/memory.h>
10 #include <proto/dos.h>
11 #include <proto/exec.h>
12 #include <aros/debug.h>
13 #include <utility/hooks.h>
24 /******************************************************************************
28 #include <aros/bigendianio.h>
29 #include <proto/alib.h>
38 Free a structure which was created by ReadStruct().
41 data - This was returned by ReadStruct() in the dataptr parameter.
43 sd - Description of the structure to be read. The first element
44 is the size of the structure.
57 dos.library/Open(), dos.library/Close(), ReadByte(), ReadWord(),
58 ReadLong(), ReadFloat(),
59 ReadString(), ReadStruct(), WriteByte(), WriteWord(), WriteLong(),
60 WriteFloat(), WriteDouble(), WriteString(), WriteStruct()
62 ******************************************************************************/
65 struct FreeLevel
* curr
;
67 # define list ((struct List *)&_list)
71 if (!(curr
= AllocMem (sizeof (struct FreeLevel
), MEMF_ANY
)) )
74 AddTail (list
, (struct Node
*)curr
);
80 # define DESC curr->sd[curr->pos]
81 # define IDESC curr->sd[curr->pos ++]
95 case SDT_UBYTE
: /* Read one 8bit byte */
96 case SDT_UWORD
: /* Read one 16bit word */
97 case SDT_ULONG
: /* Read one 32bit long */
98 case SDT_FLOAT
: /* Read one 32bit IEEE */
99 case SDT_DOUBLE
: /* Read one 64bit IEEE */
100 case SDT_IGNORE
: /* Ignore x bytes */
105 case SDT_STRING
: { /* Read a string */
108 sptr
= *(STRPTR
*)(curr
->s
+ IDESC
);
114 case SDT_STRUCT
: { /* Read a structure */
115 /* Ignore two parameters */
120 case SDT_PTR
: { /* Follow a pointer */
121 struct FreeLevel
* next
;
126 aptr
= ((APTR
*)(curr
->s
+ IDESC
));
127 desc
= (IPTR
*)IDESC
;
131 if (!(next
= AllocMem (sizeof (struct FreeLevel
), MEMF_ANY
)) )
134 AddTail (list
, (struct Node
*)next
);
144 case SDT_FILL_BYTE
: /* Fill x bytes */
145 case SDT_FILL_LONG
: /* Fill x longs */
146 case SDT_IFILL_BYTE
: /* Fill x bytes */
147 case SDT_IFILL_LONG
: /* Fill x longs */
148 curr
->pos
+= 3; /* Ignore three parameters */
151 case SDT_SPECIAL
: { /* Call user hook */
155 data
.sdd_Dest
= ((APTR
)(curr
->s
+ IDESC
));
156 data
.sdd_Mode
= SDV_SPECIALMODE_FREE
;
158 hook
= (struct Hook
*)IDESC
;
160 CallHookA (hook
, NULL
, &data
);
166 /* End of the description list ? */
169 struct FreeLevel
* last
;
171 /* Remove the current level */
173 Remove ((struct Node
*)last
);
175 /* Get the last level */
176 if ((curr
= (struct FreeLevel
*)GetTail (list
)))
178 FreeMem (last
->s
, last
->size
);
179 FreeMem (last
, sizeof (struct FreeLevel
));
188 FreeMem (curr
->s
, curr
->size
);
189 FreeMem (curr
, sizeof (struct FreeLevel
));
194 while ((curr
= (struct FreeLevel
*)RemTail (list
)))
195 FreeMem (curr
, sizeof (struct FreeLevel
));