1 /*****************************************************************
4 ** A recompile of the CBM fixfonts program **
6 ** Version 40.2 vom 16.01.1999 © THOR-Software, Thomas Richter **
7 ** Changes to compile with AROS - Henning Kiel, hkiel@aros.org **
8 *****************************************************************/
10 #include <exec/types.h>
11 #include <exec/memory.h>
14 #include <dos/dosextens.h>
15 #include <dos/dosasl.h>
16 #include <dos/exall.h>
18 #include <diskfont/diskfont.h>
20 #include <aros/macros.h>
21 #include <proto/exec.h>
22 #include <proto/dos.h>
23 #include <proto/diskfont.h>
27 #define MAXFONTLEN 25L
30 char version
[] = "$VER: FixFonts 40.2 (16.9.1999) (c) THOR";
34 struct ExAllControl
*exall
;
35 struct ExAllData
*ead
;
36 struct DevProc
*devproc
=NULL
;
40 struct FontContentsHeader
*fhead
;
48 ULONG bufsize
= 4096L;
50 if ((buffer
=AllocMem(bufsize
,MEMF_PUBLIC
)))
52 if ((exall
=AllocDosObject(DOS_EXALLCONTROL
,TAG_DONE
)))
54 /* Set return code to fine */
59 if ((devproc
=GetDeviceProc("FONTS:",devproc
)))
62 if (CheckSignal(SIGBREAKF_CTRL_C
)) {
67 exall
->eac_LastKey
=0L;
68 if ((lock
=DupLock(devproc
->dvp_Lock
)))
70 oldlock
=CurrentDir(lock
);
73 ead
=(struct ExAllData
*)buffer
;
74 more
=ExAll(lock
,ead
,bufsize
,ED_TYPE
,exall
);
78 if (size
!=ERROR_NO_MORE_ENTRIES
) rc
=size
; /* break on an error */
82 /* if there are more entries and an error, abort */
83 if (rc
) ExAllEnd(lock
,ead
,bufsize
,ED_TYPE
,exall
);
86 /* quit loop on error */
89 if (exall
->eac_Entries
==0) continue; /* Ignore empty entries */
95 len
=strlen(ead
->ed_Name
);
99 && strncmp(ead
->ed_Name
, "TrueType", len
) != 0
102 /* check for user abort */
103 if (CheckSignal(SIGBREAKF_CTRL_C
))
108 /* Build name of the directory */
109 strcpy(fullname
,ead
->ed_Name
);
110 strcpy(fullname
+len
,".font"); /* Add .font */
112 /* Build a contents header */
113 fhead
=NewFontContents(lock
,fullname
);
116 if (fhead
->fch_NumEntries
>0)
122 for(i
= 0; i
< fhead
->fch_NumEntries
; i
++)
124 if(fhead
->fch_FileID
== FCH_ID
)
126 struct FontContents
*fc
;
128 fc
= (struct FontContents
*)(fhead
+ 1);
131 fc
->fc_YSize
= AROS_WORD2BE(fc
->fc_YSize
);
135 (fhead
->fch_FileID
== TFCH_ID
)
136 || (fhead
->fch_FileID
== OFCH_ID
)
139 struct TFontContents
*tfc
;
141 tfc
= (struct TFontContents
*)(fhead
+ 1);
144 if (tfc
->tfc_TagCount
)
149 tags
= (ULONG
*)(&tfc
->tfc_FileName
[MAXFONTPATH
-(tfc
->tfc_TagCount
*8)]);
150 for (t
= 0; t
< tfc
->tfc_TagCount
* 2 - 1; t
++)
152 tags
[t
] = AROS_LONG2BE(tags
[t
]);
155 tfc
->tfc_TagCount
= AROS_WORD2BE(tfc
->tfc_TagCount
);
156 tfc
->tfc_YSize
= AROS_WORD2BE(tfc
->tfc_YSize
);
159 } /* for(i = 0; i < fhead->fch_NumEntries; i++) */
161 fhead
->fch_FileID
= AROS_WORD2BE(fhead
->fch_FileID
);
162 fhead
->fch_NumEntries
= AROS_WORD2BE(fhead
->fch_NumEntries
);
166 file
=Open(fullname
,MODE_NEWFILE
);
169 /* Find the size of the header. This is definitely a hack... */
170 size
=*((LONG
*)((UBYTE
*)fhead
-AROS_ALIGN(sizeof(ULONG
))))-sizeof(LONG
); /* Ehem. This is AllocVec'd */
172 if (Write(file
,fhead
,size
)<0) rc
=IoErr();
174 /* Delete the file on failure, clear executeable otherwise */
175 if (rc
) DeleteFile(fullname
);
176 else SetProtection(fullname
,FIBF_EXECUTE
);
185 DeleteFile(fullname
); /* Remove empty fonts */
187 DisposeFontContents(fhead
); /* remove the fcheader */
191 /* FontContents allocation */
193 if (size
==0) rc
=ERROR_NO_FREE_STORE
;
196 } /* if name small enough */
197 } /* if type is directory */
200 /* Abort on failure */
203 } while(ead
); /* ExAll buffer loop */
204 } while(more
); /* while more entries in exall-loop */
206 /* restore the old directory */
215 /* No more entries? */
216 if ((devproc
->dvp_Flags
& DVPF_ASSIGN
)==0) break;
220 { /* GetDeviceProc worked */
222 if (rc
==ERROR_NO_MORE_ENTRIES
) rc
=0; /* Default fault is fine */
223 break; /* loop abort */
225 } while(rc
==0); /* GetDeviceProc loop */
227 FreeDeviceProc(devproc
);
228 FreeDosObject(DOS_EXALLCONTROL
,exall
);
232 rc
=ERROR_NO_FREE_STORE
;
235 /* Still no error? Rewrite font cache! */
243 size
=AvailFonts((STRPTR
)buffer
,bufsize
,fontflags
);
246 FreeMem(buffer
,bufsize
);
248 buffer
=AllocMem(bufsize
,MEMF_PUBLIC
);
251 rc
=ERROR_NO_FREE_STORE
;
264 } /* buffer enlarge loop */
266 if (fontflags
& AFF_TAGGED
) break;
268 fontflags
|= AFF_TAGGED
; /* and now for the tagged stuff */
270 } /* FontCache rewrite */
272 FreeMem(buffer
,bufsize
);
276 rc
=ERROR_NO_FREE_STORE
; /* buffer allocation */
283 PrintFault(rc
,"FixFonts failed");
285 if (rc
==ERROR_BREAK
) rc
=0;