r6308@lvps87-230-33-50: verhaegs | 2007-12-03 22:24:30 +0100
[AROS.git] / test / availfonts.c
blobc47afeddf902951a0988fa60d94bf2f5bcf98f8e
1 #include <diskfont/diskfont.h>
2 #include <proto/exec.h>
3 #include <proto/dos.h>
4 #include <proto/diskfont.h>
5 #include <proto/utility.h>
7 #include <string.h>
8 #include <stdlib.h>
9 #include <stdio.h>
11 struct Library *DiskfontBase;
12 struct UtilityBase *UtilityBase;
14 UBYTE *buf;
16 void cleanup(char *msg)
18 if (msg) printf("aftest: %s\n", msg);
20 if (buf) FreeVec(buf);
22 if (UtilityBase) CloseLibrary((struct Library *)UtilityBase);
23 if (DiskfontBase) CloseLibrary(DiskfontBase);
25 exit(0);
28 void openlibs(void)
30 DiskfontBase = OpenLibrary("diskfont.library", 0);
31 if (!DiskfontBase) cleanup("Cant open diskfont.library!");
32 UtilityBase = (struct UtilityBase *) OpenLibrary("utility.library", 0);
33 if (!UtilityBase) cleanup("Cant open utility.library!");
36 void action(void)
38 struct AvailFontsHeader *afh;
39 struct TAvailFonts *af;
41 ULONG bufsize = 10000, shortage;
42 ULONG numentries;
43 ULONG i;
45 buf = AllocVec(bufsize, MEMF_ANY);
46 if (!buf) cleanup("out of memory!");
50 shortage = AvailFonts(buf, bufsize, AFF_MEMORY | AFF_DISK | AFF_BITMAP | AFF_TAGGED);
51 if (shortage)
53 bufsize += shortage;
55 FreeVec(buf);
56 buf = AllocVec(bufsize, MEMF_ANY);
57 if (!buf) cleanup("out of memory!");
59 } while (shortage);
61 afh = (struct AvailFontsHeader *)buf;
62 numentries = afh->afh_NumEntries;
64 printf("numentries = %ld\n", numentries);
66 af = (struct TAvailFonts *)(buf + 2);
68 for(i = 0; i < numentries;i++)
70 #if 1
71 printf("%s/%d [%d] flags = %x style = %x\n",
72 af->taf_Attr.tta_Name,
73 af->taf_Attr.tta_YSize,
74 af->taf_Type,
75 af->taf_Attr.tta_Flags,
76 af->taf_Attr.tta_Style);
78 printf(" tags = %p istagged = %d\n", af->taf_Attr.tta_Tags, (af->taf_Attr.tta_Style & FSF_TAGGED));
81 if ((af->taf_Attr.tta_Style & FSF_TAGGED) && (af->taf_Attr.tta_Tags))
83 struct TagItem *tag, *tstate = af->taf_Attr.tta_Tags;
85 printf("tags = %p\n", af->taf_Attr.tta_Tags);
86 //Delay(1*50);
88 while((tag = NextTagItem(&tstate)))
90 printf(" {%lx,%lx}\n", tag->ti_Tag, tag->ti_Data);
94 #else
95 printf("#%ld: %s/%d [%d] flags = %x style = %x\n",
97 af->taf_Attr.tta_Name,
98 af->taf_Attr.tta_YSize,
99 af->taf_Type,
100 af->taf_Attr.tta_Flags,
101 af->taf_Attr.tta_Style);
102 #endif
104 // Delay(10);
105 af++;
109 int main(void)
111 openlibs();
112 action();
113 cleanup(0);
115 return 0; /* keep compiler happy */