2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
5 Hook funtions needed for PropChunk().
8 #include "iffparse_intern.h"
12 /****************************/
13 /* PropLCI Purge func */
14 /****************************/
16 #define IFFParseBase IPB(hook->h_Data)
21 struct LocalContextItem
* lci
,
25 struct StoredProperty
*sp
;
27 DEBUG_PROPHOOKS(dprintf("PropPurgeFunc: hook %p lci %p p 0x%lx", hook
, lci
, p
));
29 /* Get the stored property structure */
30 sp
= (struct StoredProperty
*)LocalItemData(lci
);
32 /* Free the chunk buffer */
33 if (sp
->sp_Data
) FreeMem(sp
->sp_Data
, sp
->sp_Size
);
35 /* Free the local item itself */
38 DEBUG_PROPHOOKS(dprintf("PropPurgeFunc: return NULL\n"));
43 /****************************/
44 /* PropChunk entry-handler */
45 /****************************/
47 struct PF_ResourceInfo
49 struct LocalContextItem
*LCI
;
56 VOID
PF_FreeResources(struct PF_ResourceInfo
*ri
,
57 struct IFFParseBase_intern
* IFFParseBase
)
59 if (ri
->LCI
) FreeLocalItem(ri
->LCI
);
60 if (ri
->Buffer
) FreeMem(ri
->Buffer
, ri
->BufferSize
);
66 #define IFFParseBase IPB(hook->h_Data)
71 struct IFFHandle
* iff
,
75 struct LocalContextItem
*lci
;
78 struct StoredProperty
*sp
;
79 struct ContextNode
*cn
;
81 struct PF_ResourceInfo resinfo
= {0}; /* = {0} is important */
93 DEBUG_PROPHOOKS(dprintf("PropFunc: hook %p iff %p p %p\n", hook
, iff
, p
));
95 /* The Chunk that caused us to be invoked is always the top chunk */
101 /* Allocate new LCI for containig the property */
108 sizeof (struct StoredProperty
)
112 DEBUG_PROPHOOKS(dprintf("PropFunc: return IFFERR_NOMEM #1\n"));
120 /* Get userdata (storedproperty) */
121 sp
= (struct StoredProperty
*)LocalItemData(lci
);
124 /* Allocate buffer to read chunk into */
125 if ((size
= cn
->cn_Size
))
127 buf
= AllocMem(size
, MEMF_ANY
);
130 DEBUG_PROPHOOKS(dprintf("PropFunc: return IFFERR_NOMEM #2\n"));
132 PF_FreeResources(&resinfo
, IFFParseBase
);
134 return (IFFERR_NOMEM
);
138 resinfo
.Buffer
= buf
;
139 resinfo
.BufferSize
= size
;
144 DEBUG_PROPHOOKS(dprintf("PropFunc: ReadChunkBytes(iff %p, buf %p, size %ld)\n", iff
, buf
, size
));
148 /* Read chunk into the buffer */
149 bytesread
= ReadChunkBytes(iff
, buf
, size
);
151 DEBUG_PROPHOOKS(dprintf("PropFunc: ReadChunkBytes returned %lu\n", bytesread
));
154 if (bytesread
!= size
)
156 DEBUG_PROPHOOKS(dprintf("PropFunc: incomplete read! (%ld != %ld)\n", bytesread
, size
));
157 PF_FreeResources(&resinfo
, IFFParseBase
);
162 DEBUG_PROPHOOKS(dprintf("PropFunc: err = IFFERR_MANGLED\n"));
163 err
= IFFERR_MANGLED
;
164 /* FIXME: should return err here? */
170 /* Store the new item IN PROP, so it may be found with FindProp() */
171 err
= StoreLocalItem(iff
,lci
,IFFSLI_PROP
/*IFFSLI_ROOT*/);
175 DEBUG_PROPHOOKS(dprintf("PropFunc: return %ld\n", err
));
177 PF_FreeResources(&resinfo
, IFFParseBase
);
183 SetLocalItemPurge(lci
, &IFFParseBase
->proppurgehook
);
185 DEBUG_PROPHOOKS(dprintf("PropFunc: return 0\n"));