2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
8 /****************************************************************************************/
11 #include <utility/tagitem.h>
12 #include <proto/exec.h>
13 #include <proto/utility.h>
15 #include <aros/debug.h>
17 #include "diskfont_intern.h"
19 /****************************************************************************************/
23 BPTR
*prevsegment
, ULONG segmentsize
, ULONG memflags
,
24 struct DiskfontBase_intern
*DiskfontBase
29 if ((mem
= AllocMem(segmentsize
+ sizeof(ULONG
) + sizeof(BPTR
), memflags
)))
33 *mem
++ = segmentsize
+ sizeof(ULONG
) + sizeof(BPTR
);
34 if (prevsegment
) prevsegment
[-1] = MKBADDR(mem
);
35 membptr
= (BPTR
*) mem
;
37 mem
= (ULONG
*)membptr
;
43 /****************************************************************************************/
49 /****************************************************************************************/
51 struct TagItem
*ReadTags(BPTR fh
, ULONG numtags
, struct DiskfontBase_intern
*DiskfontBase
)
53 struct TagItem
*taglist
,
56 D(bug("ReadTags(fh=%p, numtags=%u)\n", fh
, numtags
));
58 /* Allocate memory for the tags */
60 numtags
* sizeof(struct TagItem
),
68 /* Read the taglist into the buffer */
74 if (!ReadLong( &DiskfontBase
->dsh
, &val
, (void *)fh
))
78 if (!ReadLong( &DiskfontBase
->dsh
, &val
, (void *)fh
))
80 tagptr
->ti_Data
= val
;
85 ReturnPtr ("ReadTags", struct TagItem
*, taglist
);
91 ReturnPtr("ReadTags", struct TagItem
*, NULL
);
95 /****************************************************************************************/
101 /****************************************************************************************/
103 struct TagItem
*ReadTagsNum(BPTR fh
, ULONG
*numtagsptr
, struct DiskfontBase_intern
*DiskfontBase
)
105 struct TagItem
*taglist
;
108 D(bug("ReadTagsNum(fh=%p, numtagptr=0x%lx)\n", fh
, numtagsptr
));
110 /* Allocate memory for the tags */
112 if (!ReadLong(&DiskfontBase
->dsh
, &numtags
, (void *)fh
))
115 taglist
= ReadTags(fh
, numtags
, DiskfontBase
);
119 if (numtagsptr
!= NULL
)
120 *numtagsptr
= numtags
;
122 ReturnPtr ("ReadTagsNum", struct TagItem
*, taglist
);
125 if (numtagsptr
!= NULL
)
128 ReturnPtr("ReadTagsNum", struct TagItem
*, FALSE
);
132 /****************************************************************************************/
138 /****************************************************************************************/
140 BOOL
WriteTagsNum(BPTR fh
, const struct TagItem
*taglist
, struct DiskfontBase_intern
*DiskfontBase
)
145 D(bug("WriteTags(fh=%p, taglists=%p)\n", fh
, taglist
));
147 num
= NumTags(taglist
, DiskfontBase
);
149 if (!WriteLong(&DiskfontBase
->dsh
, num
, (void *)fh
))
152 for (; (tag
= NextTagItem(&taglist
)); )
154 if (!WriteLong( &DiskfontBase
->dsh
, tag
->ti_Tag
, (void *)fh
))
157 if (!WriteLong( &DiskfontBase
->dsh
, tag
->ti_Data
, (void *)fh
))
160 WriteLong(&DiskfontBase
->dsh
, TAG_DONE
, (void *)fh
);
161 WriteLong(&DiskfontBase
->dsh
, 0, (void *)fh
);
163 ReturnBool ("WriteTags", TRUE
);
166 ReturnBool ("WriteTags", FALSE
);
169 /****************************************************************************************/
175 /****************************************************************************************/
177 ULONG
NumTags(const struct TagItem
*taglist
, struct DiskfontBase_intern
*DiskfontBase
)
178 /* Counts the number of tags in at taglist including TAG_DONE */
183 D(bug("NumTags(taglist=%p)\n", taglist
));
185 for (; NextTagItem(&taglist
); )
188 numtags
++; /* Count TAG_DONE */
190 ReturnInt ("NumTags", ULONG
, numtags
);
193 /****************************************************************************************/
199 /****************************************************************************************/
203 struct TagItem
*desttaglist
,
204 const struct TagItem
*sourcetaglist
,
205 struct DiskfontBase_intern
*DiskfontBase
207 /* Copies tags from a taglist to another memory location, returning
208 the number of tags copied */
215 D(bug("CopyTagItems(desttaglist=%p, sourcetaglist=%p)\n", desttaglist
, sourcetaglist
));
217 for (; (tag
= NextTagItem(&sourcetaglist
)); )
219 desttaglist
->ti_Tag
= tag
->ti_Tag
;
220 desttaglist
->ti_Data
= tag
->ti_Data
;
226 /* Insert TAG_DONE */
227 desttaglist
->ti_Tag
= TAG_DONE
;
228 desttaglist
->ti_Data
= 0L;
233 ReturnInt ("CopyTagItems", ULONG
, numtags
);
236 /****************************************************************************************/