source: trunk/pin/src/ppd2pak.c@ 3

Last change on this file since 3 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: 6.3 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 = PPD2PAK.C
15 *
16 * DESCRIPTIVE NAME = Convert PPD files to PAK
17 *
18 *
19 * VERSION = V1.0
20 *
21 * DATE
22 *
23 * DESCRIPTION Convert PPD files to PAK. Also bind it/devices 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 "ppd2pak.h"
48
49#include "config.h"
50#include "driverea.h"
51#include "conv_ppd.h"
52#include "lists.h"
53#include "listfls.h"
54
55#include "package.h"
56
57//
58// this is our directory.
59// it is different from ppd2ppb (but very similar to afm2pak)
60//
61
62static PBYTE pbDirectoryMem = NULL;
63static ULONG ulDirectorySize = 0;
64static PPAKSIGNATURE pSignature = NULL;
65static PPAK_DEV_DIRENTRY pEntry = NULL;
66
67
68static
69int Directory_Init(ULONG ulCntFiles)
70{
71 // allocate memory for directory segment
72 ulDirectorySize = ulCntFiles*sizeof(PAK_DEV_DIRENTRY)+sizeof(PAKSIGNATURE);
73
74 if ((pbDirectoryMem = malloc(ulDirectorySize)) ==
75 NULL)
76 {
77 //RepError( err_cantopen, "dir mem alloc" );
78 printf("memory allocation fails (asked for %d bytes)\n", ulDirectorySize);
79 goto EXIT_FAIL;
80 }
81
82 // fill with zeros
83 memset( pbDirectoryMem, 0, ulDirectorySize);
84 pSignature = (PPAKSIGNATURE)pbDirectoryMem;
85
86 strcpy(pSignature->szName, PAKSIGNATURE_DEVPACK_V1);
87 pSignature->iTblSize = ulCntFiles;
88 pSignature->iEntries = 0;
89
90 pEntry = (PPAK_DEV_DIRENTRY)(pbDirectoryMem + sizeof(PAKSIGNATURE));
91
92 return TRUE;
93
94EXIT_FAIL:
95 if(pbDirectoryMem)
96 {
97 free(pbDirectoryMem);
98 pbDirectoryMem = NULL;
99 }
100 return FALSE;
101}
102
103static
104int Directory_Write(FILE *fhOut)
105{
106 if (fwrite( pbDirectoryMem,1,ulDirectorySize,fhOut) != ulDirectorySize)
107 {
108// RepError( err_output2, "directory" );
109 printf("error writing PAK table of contents\n");
110 goto EXIT_FAIL;
111 }
112
113 return TRUE;
114EXIT_FAIL:
115 return FALSE;
116}
117
118static
119int Directory_Done(void)
120{
121 if(pbDirectoryMem)
122 {
123 free(pbDirectoryMem);
124 pbDirectoryMem = NULL;
125 }
126
127 return TRUE;
128}
129
130static int PPD2PAK_ALL_GO = 0;
131
132//
133//
134int PPD2PAK_Init()
135{
136
137 if(!DriverEA_Init(OUTPUT_DRV))
138 goto EXIT_FAIL_DRIVER_INIT;
139 printf(" extended attributes read\n");
140 if(!DriverEA_IsVersionSupported())
141 goto EXIT_FAIL_DRIVER_VERSION;
142 if(!DriverEA_GetRequiredFiles())
143 goto EXIT_FAIL_DRIVER_EA;
144
145 // check if requiredfiles already contains OUTPUT_PAK we are to produce
146 // if so, fail - because driver is not 'clean' (PPD importing most likely
147 // was already attempted here)
148
149 printf(" requiredfiles list: ok\n");
150 if(!DriverEA_GetDeviceNames())
151 goto EXIT_FAIL_DRIVER_EA;
152 printf(" devicenames list: ok\n");
153
154 if(PPD_FILE_LIST)
155 {
156 // read files from .LST
157 if(!FilenameList_ReadFromListFile(PPD_FILE_LIST))
158 goto EXIT_FAIL_FILENAME_LIST;
159 }
160 else
161 {
162 // just read in all files from directory
163 if(!FilenameList_ReadFromDirectory(PPD_SOURCE_PATH, "*.ppd"))
164 goto EXIT_FAIL_FILENAME_LIST;
165 }
166 printf(" ppd list initialized\n");
167
168 if(!Directory_Init(FilenameList_GetCount()))
169 goto EXIT_FAIL_DIRECTORY;
170 printf(" PAK table of contents initialized\n");
171
172 if(!Conv_PPD_Init())
173 goto EXIT_FAIL_CONVERTER;
174 printf(" PPD converter initialized\n");
175
176 PPD2PAK_ALL_GO = TRUE;
177 return TRUE; // suprisingly, all went fine
178
179EXIT_FAIL:
180EXIT_FAIL_CONVERTER:
181 Conv_PPD_Done();
182EXIT_FAIL_DIRECTORY:
183 Directory_Done();
184EXIT_FAIL_FILENAME_LIST:
185 FilenameList_Destroy();
186EXIT_FAIL_DRIVER_EA:
187 ;
188EXIT_FAIL_DRIVER_VERSION:
189 ;
190
191EXIT_FAIL_DRIVER_INIT:
192 DriverEA_Done();
193
194 return FALSE;
195}
196
197int PPD2PAK_Work()
198{
199 FILE *fhOut = NULL;
200 PSZ pszInFile = NULL;
201 char szInFilePath[250] = "";
202 ULONG ulConvCnt = 0;
203 ULONG ulFailCnt = 0;
204
205 if(!PPD2PAK_ALL_GO) return FALSE;
206
207 fhOut = fopen(OUTPUT_PAK,"wb");
208
209 fseek(fhOut,ulDirectorySize,SEEK_SET);
210
211 pszInFile = FilenameList_GetName(1);
212 while(pszInFile)
213 {
214 pEntry->ulOffset = ftell(fhOut);
215
216 strcpy(szInFilePath,PPD_SOURCE_PATH);
217 strcat(szInFilePath,pszInFile);
218 printf("converting %s : ",pszInFile);
219 if(!Conv_PPD_WritePPB(szInFilePath,fhOut,pEntry->szDeviceName))
220 {
221 ulFailCnt++;
222 printf(" fail\n");
223 pszInFile = FilenameList_GetName(0);
224 continue; // do not fail me again, general!
225// goto EXIT_FAIL;
226 }
227 printf(" OK (%s)\n",pEntry->szDeviceName);
228 ulConvCnt++;
229
230 DeviceList_AddName(pEntry->szDeviceName);
231 pEntry->ulSize = ftell(fhOut) - pEntry->ulOffset;
232
233 pEntry++;
234 pSignature->iEntries++;
235
236 pszInFile = FilenameList_GetName(0);
237 }
238
239 // write out directory
240
241 fseek(fhOut,0,SEEK_SET);
242 Directory_Write(fhOut);
243
244 fclose(fhOut);
245
246 ReqfileList_AddName(OUTPUT_PAK_FILENAME);
247
248 DriverEA_SetRequiredFiles();
249 DriverEA_SetDeviceNames();
250
251 // and the deed is done
252 printf("done: %ld devices converted, %ld failed\n",ulConvCnt,ulFailCnt);
253
254 return TRUE;
255
256EXIT_FAIL:
257 if(fhOut) fclose(fhOut);
258
259 return FALSE;
260}
261
262int PPD2PAK_Done()
263{
264 if(!PPD2PAK_ALL_GO) return FALSE;
265 PPD2PAK_ALL_GO = FALSE;
266
267 Conv_PPD_Done();
268
269 DriverEA_Done();
270
271 return 1;
272}
Note: See TracBrowser for help on using the repository browser.