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

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

Gcc patches + makefile

File size: 92.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/* */
15/* */
16/* */
17/* */
18/****************************************************************************/
19
20// need full audit!
21// must eliminate RepWarning and RepError
22// declare all internal functions and variables static
23// remove outdated comments and code
24
25/**************************************************************************
26 *
27 * SOURCE FILE NAME = PPD2BIN.C
28 *
29 * DESCRIPTIVE NAME = PPD Formatter
30 *
31 * VERSION = V2.0
32 *
33 * DATE
34 *
35 * DESCRIPTION Parses a PPD files and puts the information in an
36 * output file
37 *
38 *
39 * FUNCTIONS
40 * AmbFilename
41 * atoRound
42 * RepWarning
43 * RepError
44 * SkipNumber
45 * SkipBlank
46 * MovePast
47 * CopyString
48 * CopyInQuote
49 * Openppd
50 * ScanParam
51 * ScanProcedure
52 * AddExtension
53 * FreeAll
54 * RemoveExtension
55 * GetArgs
56 * SaveCommand
57 * SaveProcedure
58 * SaveString
59 * FormPpd
60 * bld_compare
61 * CntInpFiles
62 * WriteRCFile
63 * main
64 *
65 *
66 * NOTES Uses the following format for output file:
67 * The output file consists of following segments:
68 *
69 * 1. Signature
70 * 2. Printer directory segment
71 * 3. One or more printer information segments
72 *
73 * Signature has got the following structure:
74 * Identifying name 40 bytes,
75 * Total no of entries in dir 2 bytes,
76 * Present no of entries in dir 2 bytes,
77 * free 4 bytes.
78 *
79 * Each entry in Printer directory segment has got the
80 * following structure:
81 * Printer name 40 bytes,
82 * Offset of printer segment 4 bytes,
83 * free 4 bytes.
84 *
85 * Each printer information segment has got the structure
86 * stored in format DESPPD. Towards the end of printer info
87 * segment lies the list buffer of length specified by the
88 * first two bytes of DESPPD structure. The buffer contains
89 * various command string lists and dimension lists.
90 *
91 * STRUCTURES
92 *
93 * EXTERNAL REFERENCES
94 *
95 * EXTERNAL FUNCTIONS
96 *
97*/
98//#define INCL_GENPLIB_LAYOUT
99#include <os2.h>
100#include <stdio.h>
101#include <stdlib.h>
102#include <string.h>
103#include <ctype.h>
104#ifndef __KLIBC__
105 #include <builtin.h>
106#else
107 typedef INT *PINT;
108 #define strcmpi strcmp
109#endif
110
111//#include <genplib.h>
112#include "ppd2bin.h"
113//#include "ppdialog.h"
114#include "struct.h"
115#include "fontres.h"
116// #define IBUFFSIZE 2048
117#define IBUFFSIZE (1024 * 35) // upped from 11 [wgs]
118#define MAX_ESC_STR_LEN 256L
119#define COMPRESS TRUE
120#define NOCOMPRESS FALSE
121
122#define CSTR_NORMAL 0
123#define CSTR_INCLUDE_SLASH 1
124#define CSTR_HEX2CHAR 2
125#define CSTR_EXCLUDE_DQUOTE 4
126
127/**************************************************************************
128* The headers #def INT as int. Just following this, there is a #define int SHORT
129* This will cause trouble with using PINTs since it expects a 32 bit value
130* to be pointed to. And that definintion will not be affected by the #define int SHORT
131* To avoid the problem, I undef INT and the use typedef to reassign it.
132* [wgs] 1/17/98
133***********************************************************************/
134#ifdef INT
135#undef INT
136typedef int INT;
137#endif
138
139#define int SHORT
140#define unsigned USHORT
141
142int SkipBlank(char *);
143
144//FILE *ppdOut;
145//BOOL fWriteWords = FALSE;
146long test_prefix = 0x12345678;
147//FILE *fhOut = NULL;
148
149typedef struct
150{
151 FILE *fhFile;
152 long lFileLen;
153 long lCurPos;
154 char *pbBuffer;
155} FILEBUFFER, *PFILEBUFFER;
156
157FILEBUFFER fbIn;
158
159
160long test_post = 0x12345678;
161char abBuffin[IBUFFSIZE]; /* buffer required for reading input */
162/* the following appears only to be used in processing the current file and not stored */
163/* [wgs] and since the input file is might be over 64k(esp. the hp8000_6.ppd) */
164struct
165{
166 long usFileStart;
167 long usFileEnd;
168} UIFileGroup;
169
170char acDefFont[] = "Courier";
171int cbBuffout = 0; /* number of bytes filled in output
172 buffer */
173DESPPD desPpd; /* printer descriptor segments */
174
175
176//char *pbDirBuffer; /* pointer to directory buffer tobe
177// allocated */
178PBYTE pbItemsBuffer; /* pointer to items */
179// static char pbPrBuffer[1024 * 4];
180static char pbPrBuffer[ IBUFFSIZE ];
181USHORT USBlockHeader[ 150 ]; // www.fcuk.lv
182
183BOOL BUI = FALSE;
184
185#define MAX_FORM_SIZE 127
186SHORT sFormCount;
187PCH pFormTable[64]; /* allow 64 forms */
188
189UINT nErrorLogLevel=2;
190//
191// log levels:
192// 5 : very quiet
193// 4 : errors
194// 3 : serious warning
195// 2 : warnings
196// 1 : predictable and handled quirks
197// 0 : log entrance and exit from function
198// log how many times function is called
199//
200
201/*
202** D74609
203*/
204#define TRUNCATE_FLOAT (float) 0.0
205#define ROUND_FLOAT (float) 0.9999
206
207int MovePast( char *, char );
208VOID roundImgAreaVals(int *, float, CHAR );
209
210BOOL VerifyPPDLineSize( PCHAR );
211BOOL BErrorWasDisplayed = FALSE;
212
213VOID ProcessUIList( VOID );
214UINT ProcessUIBlock( PUI_LIST, PUI_BLOCK, UINT, PUSHORT );
215int CopyString( char *, char *, int, UINT );
216
217/*** This is a new section for compression
218*/
219#include "ppdtable.h"
220#define HASHSLOTS 251
221
222typedef struct _WORDELEMENT
223{
224 PSZ pszWord; //Pointer to keyword
225 SHORT sIndex; //0 based index plus adjustment
226 SHORT sList; //0 based list
227 struct _WORDELEMENT *pNext;
228} WORDELEMENT, *PWORDELEMENT;
229
230PWORDELEMENT pPSKeyWords;
231PWORDELEMENT aHashTable[ HASHSLOTS ];
232INT iShrinkage; //When the ppb is expanded this is the diff between
233 //compressed and uncompressed size
234
235INT MatchKeywords( PBYTE, PUI_LIST, PBYTE, BOOL );
236PUI_BLOCK QueryBlockFromKeyword( PUI_LIST, PBYTE, PBYTE, PINT );
237PUI_ENTRY QueryEntryFromOption( PBYTE, PUI_BLOCK, PBYTE, PINT );
238VOID ProcessCmdsAsUIs( VOID );
239INT ProcessUIConstraints( VOID );
240INT CopyWord( PCHAR, PCHAR );
241VOID VerifyUICList( VOID );
242PCHAR SearchKeySubst( PCHAR );
243
244BOOL ParsePPDLang( PSZ, PSZ );
245FILE *MRILangFile;
246CHAR MRIPathString[ CCHMAXPATH ];
247
248
249#include "buffers.ch"
250
251#include "p2phash.ch"
252
253#include "p2putil.ch"
254
255
256/***************************************************************************
257 *
258 * FUNCTION NAME = Openppd
259 *
260 * DESCRIPTION = Opens the file specified in read only text mode and
261 * returns True if open successful ,else FALSE. The
262 * file handle is stored in fhIn
263 *
264 * INPUT = szFileName - filename
265 *
266 * OUTPUT = NONE.
267 *
268 * RETURN-NORMAL = NONE.
269 * RETURN-ERROR = NONE.
270 *
271 ************************************************************************* */
272
273BOOL Openppd( char *szFilename )
274{
275//long i; NOTUSED
276
277
278 fbIn.fhFile = fopen( szFilename, "rb" );
279
280
281 if (!fbIn.fhFile)
282 {
283 /*
284 ** Previously, if a file couldn't be found, then the compiler would stop.
285 ** However, confidential OEM PPD files will not be out on the DDK.
286 ** Therefore, change to simply ignore files that aren't found. However,
287 ** do display it for build purposes.
288 */
289// RepWarning( err_cantopen, szFilename );
290 printf( "[INFO: %s - File not found. Ignore and continue.]\n",
291 szFilename );
292 *szFilename = 0;
293 return( FALSE );
294 }
295
296
297 fseek( fbIn.fhFile, 0L, SEEK_END);
298 fbIn.lFileLen = ftell( fbIn.fhFile );
299 fseek( fbIn.fhFile, 0L, SEEK_SET);
300
301 fbIn.pbBuffer = (char *)malloc( fbIn.lFileLen * sizeof( char ) );
302 fread( fbIn.pbBuffer, sizeof( char ), fbIn.lFileLen, fbIn.fhFile );
303
304
305 fbseek(&fbIn, 0L, SEEK_SET);
306// printf( "Converting %s\n", szFilename );
307 return( TRUE );
308}
309
310/***************************************************************************
311 *
312 * FUNCTION NAME = ScanParam
313 *
314 * DESCRIPTION = This routine scans the szSrchstring in the input
315 * file and provides the remaining parameter in the
316 * return buffer provided. If szSrchstring is found
317 * this routine returns TRUE else FALSE.
318 *
319 * INPUT = szSrchstring - search string address
320 *
321 * OUTPUT = pbBufaddress - return buffer address
322 *
323 * RETURN-NORMAL = NONE.
324 * RETURN-ERROR = NONE.
325 *
326 ************************************************************************* */
327
328BOOL ScanParam( char *szSrchstring, char *pbBufreturn )
329{
330 BOOL fIseof, fIsFound;
331
332 INT j = 0, k;
333 INT i;
334 long li, lc;
335 UINT uiStrLen = strlen( szSrchstring );
336
337 long uiCurrFileLoc;
338 INT x;
339
340 fIseof = FALSE;
341
342 /*
343 ** search for parameter till token found or file eof encountered
344 */
345 while (!fIseof)
346 {
347 if ((lc = fbtell(&fbIn)) == -1L)
348 {
349 return( FALSE );
350 }
351
352 /*
353 **
354 */
355 uiCurrFileLoc = fbtell( &fbIn );
356
357 if ((i = fbread(abBuffin,1,IBUFFSIZE,&fbIn)) != IBUFFSIZE)
358 {
359 fIseof = TRUE;
360 }
361
362 /*
363 ** Verify that the line size does not exceed IBUFFSIZE bytes.
364 ** Report an error and skip the command if this exists.
365 */
366 if (VerifyPPDLineSize( abBuffin ) == TRUE)
367 {
368 if (i <= 1)
369 {
370 break;
371 }
372
373 /*
374 ** Ignore the last partially read line
375 */
376 if (!fIseof) /* didn't hit end of file, then don't need do adjust */
377 { /* ignore the partially read line */
378 if (i > 3)
379 i--;
380 for (li = 1;i;li++, i--)
381 {
382 if ((abBuffin[i] == '*') && (abBuffin[i - 1] == '\n'))
383 {
384 break;
385 }
386 } /* for */
387
388 /*
389 ** shift back the current access pointer of the file
390 ** make it point to the beginning of the partially read line
391 */
392 if (li > 1 && li < IBUFFSIZE)
393 {
394 if (fbseek( &fbIn, -(li-1), SEEK_CUR) == -1L) /* oops, something */
395 {
396 return( FALSE );
397 }
398 } /* check for reasonable backup values */
399 } /* if (!fIseof) */
400
401 j = 0;
402 fIsFound = FALSE;
403 while (j < i)
404 {
405 if (!strncmp( abBuffin+j, szSrchstring, uiStrLen ))
406 {
407 /* @COOK */
408 if (isspace( *(abBuffin + j + uiStrLen) ) ||
409 *(abBuffin + j + uiStrLen) == ':')
410 {
411 fIsFound = TRUE;
412 }
413 }
414 k = j;
415
416 for (;;j++)
417 {
418 /*
419 ** Check to see if a comment is on the next line. This will
420 ** prevent a trap if the compiler finds a comment immediately
421 ** following a command line. The compiler won't read the
422 ** comment and possibly exceed buffer space.
423 */
424 if ((abBuffin[j] == 0xA) && (abBuffin[j+1] == 0x2A ||
425 abBuffin[j+1] == '%'))
426 {
427 j++;
428 break;
429 }
430
431 if (j == i)
432 {
433 break;
434 }
435 }
436
437 if (fIsFound)
438 {
439 /*
440 */
441 if (BUI == TRUE)
442 {
443 fbseek( &fbIn, uiCurrFileLoc + k, SEEK_SET );
444 lc = fbtell( &fbIn );
445
446 /*
447 ** Change '1024 * 4' to IBUFFSIZE.
448 */
449// fread( abBuffin, 1, 1024 * 4, fhIn );
450 fbread( abBuffin, 1, IBUFFSIZE, &fbIn );
451 j = MovePast( abBuffin, ' ' );
452 memset( pbBufreturn, 0, IBUFFSIZE );
453 memcpy( pbBufreturn, abBuffin + j, IBUFFSIZE - j );
454 fbseek( &fbIn, lc + 10, SEEK_SET );
455 }
456 else
457 {
458 k += uiStrLen;
459 k += SkipBlank( abBuffin + k );
460
461 if (j >= k)
462 {
463 x = j - k;
464 }
465 else
466 {
467 x = 0;
468 while (abBuffin[ k + x ] != 0x0A)
469 {
470 x++;
471 }
472 }
473