revert between 56095 -> 55830 in arch
[AROS.git] / workbench / libs / diskfont / basicfuncs.c
blob3979d277cb060fd85223d1489fdf9c8486c36bc6
1 /*
2 Copyright © 1995-2004, The AROS Development Team. All rights reserved.
3 $Id$
5 Some support functions
6 */
8 /****************************************************************************************/
10 #include <dos/dos.h>
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 /****************************************************************************************/
21 APTR AllocSegment
23 BPTR *prevsegment, ULONG segmentsize, ULONG memflags,
24 struct DiskfontBase *DiskfontBase
27 ULONG *mem;
29 if ((mem = AllocMem(segmentsize + sizeof(ULONG) + sizeof(BPTR), memflags)))
31 BPTR *membptr;
33 *mem++ = segmentsize + sizeof(ULONG) + sizeof(BPTR);
34 if (prevsegment) prevsegment[-1] = MKBADDR(mem);
35 membptr = (BPTR *) mem;
36 *membptr++ = BNULL;
37 mem = (ULONG *)membptr;
40 return mem;
43 /****************************************************************************************/
45 /************/
46 /* ReadTags */
47 /************/
49 /****************************************************************************************/
51 struct TagItem *ReadTags(BPTR fh, ULONG numtags, struct DiskfontBase *DiskfontBase)
53 struct TagItem *taglist,
54 *tagptr;
56 D(bug("ReadTags(fh=%p, numtags=%u)\n", fh, numtags));
58 /* Allocate memory for the tags */
59 taglist = AllocVec(
60 numtags * sizeof(struct TagItem),
61 MEMF_ANY);
63 if (!taglist)
64 goto rt_failure;
66 tagptr = taglist;
68 /* Read the taglist into the buffer */
70 for (; numtags --; )
72 ULONG val;
74 if (!ReadLong( &DiskfontBase->dsh, &val, (void *)fh))
75 goto readfail;
76 tagptr->ti_Tag = val;
78 if (!ReadLong( &DiskfontBase->dsh, &val, (void *)fh ))
79 goto readfail;
80 tagptr->ti_Data = val;
82 tagptr ++;
85 ReturnPtr ("ReadTags", struct TagItem*, taglist);
87 readfail:
88 FreeVec(taglist);
89 rt_failure:
91 ReturnPtr("ReadTags", struct TagItem*, NULL);
95 /****************************************************************************************/
97 /***************/
98 /* ReadTagsNum */
99 /***************/
101 /****************************************************************************************/
103 struct TagItem *ReadTagsNum(BPTR fh, ULONG *numtagsptr, struct DiskfontBase *DiskfontBase)
105 struct TagItem *taglist;
106 ULONG numtags;
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))
113 goto rt_failure;
115 taglist = ReadTags(fh, numtags, DiskfontBase);
116 if (taglist == NULL)
117 goto rt_failure;
119 if (numtagsptr != NULL)
120 *numtagsptr = numtags;
122 ReturnPtr ("ReadTagsNum", struct TagItem*, taglist);
124 rt_failure:
125 if (numtagsptr != NULL)
126 *numtagsptr = 0;
128 ReturnPtr("ReadTagsNum", struct TagItem*, FALSE);
132 /****************************************************************************************/
134 /****************/
135 /* WriteTagsNum */
136 /****************/
138 /****************************************************************************************/
140 BOOL WriteTagsNum(BPTR fh, const struct TagItem *taglist, struct DiskfontBase *DiskfontBase)
142 struct TagItem *tag;
143 ULONG num;
145 D(bug("WriteTags(fh=%p, taglists=%p)\n", fh, taglist));
147 num = NumTags(taglist, DiskfontBase);
149 if (!WriteLong(&DiskfontBase->dsh, num, (void *)fh))
150 goto wt_failure;
152 for (; (tag = NextTagItem((struct TagItem **)&taglist)); )
154 if (!WriteLong( &DiskfontBase->dsh, tag->ti_Tag, (void *)fh ))
155 goto wt_failure;
157 if (!WriteLong( &DiskfontBase->dsh, tag->ti_Data, (void *)fh))
158 goto wt_failure;
160 WriteLong(&DiskfontBase->dsh, TAG_DONE, (void *)fh);
161 WriteLong(&DiskfontBase->dsh, 0, (void *)fh);
163 ReturnBool ("WriteTags", TRUE);
165 wt_failure:
166 ReturnBool ("WriteTags", FALSE);
169 /****************************************************************************************/
171 /**************/
172 /* NumTags */
173 /**************/
175 /****************************************************************************************/
177 ULONG NumTags(const struct TagItem *taglist, struct DiskfontBase *DiskfontBase)
178 /* Counts the number of tags in at taglist including TAG_DONE */
181 ULONG numtags = 0;
183 D(bug("NumTags(taglist=%p)\n", taglist));
185 for (; NextTagItem((struct TagItem **)&taglist); )
186 numtags ++;
188 numtags ++; /* Count TAG_DONE */
190 ReturnInt ("NumTags", ULONG, numtags);
193 /****************************************************************************************/
195 /****************/
196 /* CopyTagItems */
197 /****************/
199 /****************************************************************************************/
201 ULONG CopyTagItems
203 struct TagItem *desttaglist,
204 const struct TagItem *sourcetaglist,
205 struct DiskfontBase *DiskfontBase
207 /* Copies tags from a taglist to another memory location, returning
208 the number of tags copied */
211 ULONG numtags=0;
213 struct TagItem *tag;
215 D(bug("CopyTagItems(desttaglist=%p, sourcetaglist=%p)\n", desttaglist, sourcetaglist));
217 for (; (tag = NextTagItem((struct TagItem **)&sourcetaglist)); )
219 desttaglist->ti_Tag = tag->ti_Tag;
220 desttaglist->ti_Data = tag->ti_Data;
222 desttaglist++;
223 numtags++;
226 /* Insert TAG_DONE */
227 desttaglist->ti_Tag = TAG_DONE;
228 desttaglist->ti_Data = 0L;
230 /* Count TAG_DONE */
231 numtags++;
233 ReturnInt ("CopyTagItems", ULONG, numtags);
236 /****************************************************************************************/