source: trunk/pin/src/afm2pak.c@ 49

Last change on this file since 49 was 1, checked in by bart, 18 years ago

Initial checkin of PIN.EXE source code
this contains memory fixes for larger PPD files

File size: 5.8 KB
Line 
1/*DDK*************************************************************************/
2/* */
3/* COPYRIGHT Copyright (C) 1991, 2003 IBM Corporation */
4/* */
5/* The following IBM OS/2 source code is provided to you solely for */
6/* the purpose of assisting you in your development of OS/2 device */
7/* drivers. You may use this code in accordance with the IBM License */
8/* Agreement provided in the IBM Developer Connection Device Driver */
9/* Source Kit for OS/2. This Copyright statement may not be removed. */
10/* */
11/*****************************************************************************/
12/**************************************************************************
13 *
14 * SOURCE FILE NAME = AFM2PAK.C
15 *
16 * DESCRIPTIVE NAME = Convert AFM files to PAK
17 *
18 *
19 * VERSION = V1.0
20 *
21 * DATE
22 *
23 * DESCRIPTION Convert AFM files to PAK. Also bind it to target driver.
24 *
25 *
26 * FUNCTIONS
27 *
28 *
29 *
30 * NOTES
31 *
32 *
33 * STRUCTURES
34 *
35 * EXTERNAL REFERENCES
36 *
37 * EXTERNAL FUNCTIONS
38 *
39*/
40
41// ppds to package
42#include <os2.h>
43#include <stdio.h>
44#include <stdlib.h>
45#include <string.h>
46
47#include "afm2pak.h"
48
49#include "config.h"
50#include "driverea.h"
51#include "conv_afm.h"
52#include "lists.h"
53#include "listfls.h"
54
55
56#include "package.h"
57
58
59static PBYTE pbDirectoryMem = NULL;
60static ULONG ulDirectorySize = 0;
61static PPAKSIGNATURE pSignature = NULL;
62static PPAK_FONT_DIRENTRY pEntry = NULL;
63
64
65static
66int Directory_Init(ULONG ulCntFiles)
67{
68 // allocate memory for directory segment
69 ulDirectorySize = ulCntFiles*sizeof(PAK_FONT_DIRENTRY)+sizeof(PAKSIGNATURE);
70
71 if ((pbDirectoryMem = malloc(ulDirectorySize)) ==
72 NULL)
73 {
74 //RepError( err_cantopen, "dir mem alloc" );
75 printf("memory alloc fails");
76 goto EXIT_FAIL;
77 }
78
79 // fill with zeros
80 memset( pbDirectoryMem, 0, ulDirectorySize);
81 pSignature = (PPAKSIGNATURE)pbDirectoryMem;
82
83 strcpy(pSignature->szName, PAKSIGNATURE_FONTPACK_V1);
84 pSignature->iTblSize = ulCntFiles;
85 pSignature->iEntries = 0;
86
87 pEntry = (PPAK_FONT_DIRENTRY)(pbDirectoryMem + sizeof(PAKSIGNATURE));
88
89 return TRUE;
90
91EXIT_FAIL:
92 if(pbDirectoryMem)
93 {
94 free(pbDirectoryMem);
95 pbDirectoryMem = NULL;
96 }
97 return FALSE;
98}
99
100static
101int Directory_Write(FILE *fhOut)
102{
103 if (fwrite( pbDirectoryMem,1,ulDirectorySize,fhOut) != ulDirectorySize)
104 {
105// RepError( err_output2, "directory" );
106 printf("directory write error");
107 goto EXIT_FAIL;
108 }
109
110 return TRUE;
111EXIT_FAIL:
112 return FALSE;
113}
114
115static
116int Directory_Done(void)
117{
118 if(pbDirectoryMem)
119 {
120 free(pbDirectoryMem);
121 pbDirectoryMem = NULL;
122 }
123
124 return TRUE;
125}
126
127static int AFM2PAK_ALL_GO = 0;
128
129//
130//
131int AFM2PAK_Init()
132{
133
134 if(!DriverEA_Init(OUTPUT_DRV))
135 goto EXIT_FAIL_DRIVER_INIT;
136 printf(" driverea init ok\n");
137 if(!DriverEA_IsVersionSupported())
138 goto EXIT_FAIL_DRIVER_VERSION;
139 printf(" driverea version ok\n");
140 if(!DriverEA_GetRequiredFiles())
141 goto EXIT_FAIL_DRIVER_EA;
142 printf(" driverea requiredfiles ok\n");
143
144 if(AFM_FILE_LIST)
145 {
146 // read files from .LST
147 if(!FilenameList_ReadFromListFile(AFM_FILE_LIST))
148 goto EXIT_FAIL_FILENAME_LIST;
149 }
150 else
151 {
152 if(!FilenameList_ReadFromDirectory(AFM_SOURCE_PATH, "*.afm"))
153 goto EXIT_FAIL_FILENAME_LIST;
154 }
155 printf(" afmfilelist read ok\n");
156
157 if(!Directory_Init(FilenameList_GetCount()))
158 goto EXIT_FAIL_DIRECTORY;
159 printf(" directory init ok\n");
160
161 if(!Conv_AFM_Init())
162 goto EXIT_FAIL_CONVERTER;
163 printf(" converter init ok\n");
164
165 AFM2PAK_ALL_GO = TRUE;
166 return TRUE; // suprisingly, all went fine
167
168EXIT_FAIL:
169EXIT_FAIL_CONVERTER:
170 Conv_AFM_Done();
171EXIT_FAIL_DIRECTORY:
172 Directory_Done();
173EXIT_FAIL_FILENAME_LIST:
174 FilenameList_Destroy();
175EXIT_FAIL_DRIVER_EA:
176 ;
177EXIT_FAIL_DRIVER_VERSION:
178 ;
179
180EXIT_FAIL_DRIVER_INIT:
181 DriverEA_Done();
182
183 return FALSE;
184}
185
186int AFM2PAK_Work()
187{
188 FILE *fhOut = NULL;
189 PSZ pszInFile = NULL;
190 char szInFilePath[250] = "";
191 ULONG ulConvCnt = 0;
192 ULONG ulFailCnt = 0;
193
194 if(!AFM2PAK_ALL_GO) return FALSE;
195
196 fhOut = fopen(OUTPUT_PAK,"wb");
197
198 fseek(fhOut,ulDirectorySize,SEEK_SET);
199
200 pszInFile = FilenameList_GetName(1);
201 while(pszInFile)
202 {
203 pEntry->ulOffset = ftell(fhOut);
204
205 strcpy(szInFilePath,AFM_SOURCE_PATH);
206 strcat(szInFilePath,pszInFile);
207 printf("converting %s : ",pszInFile);
208 if(!Conv_AFM_WritePFM(szInFilePath,fhOut,pEntry->szFontName,pEntry->szFontFullName))
209 {
210 printf(" fail\n");
211 ulFailCnt++;
212 pszInFile = FilenameList_GetName(0);
213 continue; // do not fail me again, general!
214// goto EXIT_FAIL;
215 }
216 printf(" OK (%s)\n",pEntry->szFontName);
217 ulConvCnt++;
218
219 pEntry->ulSize = ftell(fhOut) - pEntry->ulOffset;
220
221 pEntry++;
222 pSignature->iEntries++;
223
224 pszInFile = FilenameList_GetName(0);
225 }
226
227 // write out directory
228
229 fseek(fhOut,0,SEEK_SET);
230 Directory_Write(fhOut);
231
232 fclose(fhOut);
233
234 ReqfileList_AddName(OUTPUT_PAK_FILENAME);
235
236 DriverEA_SetRequiredFiles();
237
238 // and the deed is done
239 printf("done: %ld font files converted, %ld failed\n",ulConvCnt,ulFailCnt);
240
241 return TRUE;
242
243EXIT_FAIL:
244 if(fhOut) fclose(fhOut);
245
246 return FALSE;
247}
248
249int AFM2PAK_Done()
250{
251 if(!AFM2PAK_ALL_GO) return FALSE;
252 AFM2PAK_ALL_GO = FALSE;
253
254 Conv_AFM_Done();
255
256 DriverEA_Done();
257
258 return 1;
259}
Note: See TracBrowser for help on using the repository browser.