Implemented _ultow() and export [Nt/Zw]QueryVolumeInformationFile().
[wine] / dlls / wineps / ppd.c
1 /*      PostScript Printer Description (PPD) file parser
2  *
3  *      See  http://www.adobe.com/supportservice/devrelations/PDFS/TN/5003.PPD_Spec_v4.3.pdf
4  *
5  *      Copyright 1998  Huw D M Davies
6  */
7
8 #include <string.h>
9 #include <stdio.h>
10 #include <ctype.h>
11 #include "winnt.h" /* HEAP_ZERO_MEMORY */
12 #include "heap.h"
13 #include "debugtools.h"
14 #include "psdrv.h"
15 #include "winspool.h"
16
17 DEFAULT_DEBUG_CHANNEL(psdrv);
18
19 typedef struct {
20 char    *key;
21 char    *option;
22 char    *opttrans;
23 char    *value;
24 char    *valtrans;
25 } PPDTuple;
26
27
28 /* map of page names in ppd file to Windows paper constants */
29
30 static struct {
31   char *PSName;
32   WORD WinPage;
33 } PageTrans[] = {
34   {"10x11",                   DMPAPER_10X11},
35   {"10x14",                   DMPAPER_10X14},
36   {"12x11",                   DMPAPER_12X11},
37   {"15x11",                   DMPAPER_15X11},
38   {"9x11",                    DMPAPER_9X11},
39   {"A2",                      DMPAPER_A2},
40   {"A3",                      DMPAPER_A3},
41   {"A3.Transverse",           DMPAPER_A3_TRANSVERSE},
42   {"A3Extra",                 DMPAPER_A3_EXTRA},
43   {"A3Extra.Transverse",      DMPAPER_A3_EXTRA_TRANSVERSE},
44   {"A3Rotated",               DMPAPER_A3_ROTATED},
45   {"A4",                      DMPAPER_A4},
46   {"A4.Transverse",           DMPAPER_A4_TRANSVERSE},
47   {"A4Extra",                 DMPAPER_A4_EXTRA},
48   {"A4Plus",                  DMPAPER_A4_PLUS},
49   {"A4Rotated",               DMPAPER_A4_ROTATED},
50   {"A4Small",                 DMPAPER_A4SMALL},
51   {"A5",                      DMPAPER_A5},
52   {"A5.Transverse",           DMPAPER_A5_TRANSVERSE},
53   {"A5Extra",                 DMPAPER_A5_EXTRA},
54   {"A5Rotated",               DMPAPER_A5_ROTATED},
55   {"A6",                      DMPAPER_A6},
56   {"A6Rotated",               DMPAPER_A6_ROTATED},
57   {"ARCHC",                   DMPAPER_CSHEET},
58   {"ARCHD",                   DMPAPER_DSHEET},
59   {"ARCHE",                   DMPAPER_ESHEET},
60   {"B4",                      DMPAPER_B4},
61   {"B4Rotated",               DMPAPER_B4_JIS_ROTATED},
62   {"B5",                      DMPAPER_B5},
63   {"B5.Transverse",           DMPAPER_B5_TRANSVERSE},
64   {"B5Rotated",               DMPAPER_B5_JIS_ROTATED},
65   {"B6",                      DMPAPER_B6_JIS},
66   {"B6Rotated",               DMPAPER_B6_JIS_ROTATED},
67   {"C4",                      DMPAPER_ENV_C4},
68   {"C5",                      DMPAPER_ENV_C5},
69   {"C6",                      DMPAPER_ENV_C6},
70   {"Comm10",                  DMPAPER_ENV_10},
71   {"DL",                      DMPAPER_ENV_DL},
72   {"DoublePostcard",          DMPAPER_DBL_JAPANESE_POSTCARD},
73   {"DoublePostcardRotated",   DMPAPER_DBL_JAPANESE_POSTCARD_ROTATED},
74   {"Env9",                    DMPAPER_ENV_9},
75   {"Env10",                   DMPAPER_ENV_10},
76   {"Env11",                   DMPAPER_ENV_11},
77   {"Env12",                   DMPAPER_ENV_12},
78   {"Env14",                   DMPAPER_ENV_14},
79   {"EnvC3",                   DMPAPER_ENV_C3},
80   {"EnvC4",                   DMPAPER_ENV_C4},
81   {"EnvC5",                   DMPAPER_ENV_C5},
82   {"EnvC6",                   DMPAPER_ENV_C6},
83   {"EnvC65",                  DMPAPER_ENV_C65},
84   {"EnvChou3",                DMPAPER_JENV_CHOU3},
85   {"EnvChou3Rotated",         DMPAPER_JENV_CHOU3_ROTATED},
86   {"EnvChou4",                DMPAPER_JENV_CHOU4},
87   {"EnvChou4Rotated",         DMPAPER_JENV_CHOU4_ROTATED},
88   {"EnvDL",                   DMPAPER_ENV_DL},
89   {"EnvInvite",               DMPAPER_ENV_INVITE},
90   {"EnvISOB4",                DMPAPER_ENV_B4},
91   {"EnvISOB5",                DMPAPER_ENV_B5},
92   {"EnvISOB6",                DMPAPER_ENV_B6},
93   {"EnvItalian",              DMPAPER_ENV_ITALY},
94   {"EnvKaku2",                DMPAPER_JENV_KAKU2},
95   {"EnvKaku2Rotated",         DMPAPER_JENV_KAKU2_ROTATED},
96   {"EnvKaku3",                DMPAPER_JENV_KAKU3},
97   {"EnvKaku3Rotated",         DMPAPER_JENV_KAKU3_ROTATED},
98   {"EnvMonarch",              DMPAPER_ENV_MONARCH},
99   {"EnvPersonal",             DMPAPER_ENV_PERSONAL},
100   {"EnvPRC1",                 DMPAPER_PENV_1},
101   {"EnvPRC1Rotated",          DMPAPER_PENV_1_ROTATED},
102   {"EnvPRC2",                 DMPAPER_PENV_2},
103   {"EnvPRC2Rotated",          DMPAPER_PENV_2_ROTATED},
104   {"EnvPRC3",                 DMPAPER_PENV_3},
105   {"EnvPRC3Rotated",          DMPAPER_PENV_3_ROTATED},
106   {"EnvPRC4",                 DMPAPER_PENV_4},
107   {"EnvPRC4Rotated",          DMPAPER_PENV_4_ROTATED},
108   {"EnvPRC5",                 DMPAPER_PENV_5},
109   {"EnvPRC5Rotated",          DMPAPER_PENV_5_ROTATED},
110   {"EnvPRC6",                 DMPAPER_PENV_6},
111   {"EnvPRC6Rotated",          DMPAPER_PENV_6_ROTATED},
112   {"EnvPRC7",                 DMPAPER_PENV_7},
113   {"EnvPRC7Rotated",          DMPAPER_PENV_7_ROTATED},
114   {"EnvPRC8",                 DMPAPER_PENV_8},
115   {"EnvPRC8Rotated",          DMPAPER_PENV_8_ROTATED},
116   {"EnvPRC9",                 DMPAPER_PENV_9},
117   {"EnvPRC9Rotated",          DMPAPER_PENV_9_ROTATED},
118   {"EnvPRC10",                DMPAPER_PENV_10},
119   {"EnvPRC10Rotated",         DMPAPER_PENV_10_ROTATED},
120   {"EnvYou4",                 DMPAPER_JENV_YOU4},
121   {"EnvYou4Rotated",          DMPAPER_JENV_YOU4_ROTATED},
122   {"Executive",               DMPAPER_EXECUTIVE},
123   {"FanFoldUS",               DMPAPER_FANFOLD_US},
124   {"FanFoldGerman",           DMPAPER_FANFOLD_STD_GERMAN},
125   {"FanFoldGermanLegal",      DMPAPER_FANFOLD_LGL_GERMAN},
126   {"Folio",                   DMPAPER_FOLIO},
127   {"ISOB4",                   DMPAPER_ISO_B4},
128   {"ISOB5Extra",              DMPAPER_B5_EXTRA},
129   {"Ledger",                  DMPAPER_LEDGER},
130   {"Legal",                   DMPAPER_LEGAL},
131   {"LegalExtra",              DMPAPER_LEGAL_EXTRA},
132   {"Letter",                  DMPAPER_LETTER},
133   {"Letter.Transverse",       DMPAPER_LETTER_TRANSVERSE},
134   {"LetterExtra",             DMPAPER_LETTER_EXTRA},
135   {"LetterExtra.Transverse",  DMPAPER_LETTER_EXTRA_TRANSVERSE},
136   {"LetterPlus",              DMPAPER_LETTER_PLUS},
137   {"LetterRotated",           DMPAPER_LETTER_ROTATED},
138   {"LetterSmall",             DMPAPER_LETTERSMALL},
139   {"Monarch",                 DMPAPER_ENV_MONARCH},
140   {"Note",                    DMPAPER_NOTE},
141   {"Postcard",                DMPAPER_JAPANESE_POSTCARD},
142   {"PostcardRotated",         DMPAPER_JAPANESE_POSTCARD_ROTATED},
143   {"PRC16K",                  DMPAPER_P16K},
144   {"PRC16KRotated",           DMPAPER_P16K_ROTATED},
145   {"PRC32K",                  DMPAPER_P32K},
146   {"PRC32KBig",               DMPAPER_P32KBIG},
147   {"PRC32KBigRotated",        DMPAPER_P32KBIG_ROTATED},
148   {"PRC32KRotated",           DMPAPER_P32K_ROTATED},
149   {"Quarto",                  DMPAPER_QUARTO},
150   {"Statement",               DMPAPER_STATEMENT},
151   {"SuperA",                  DMPAPER_A_PLUS},
152   {"SuperB",                  DMPAPER_B_PLUS},
153   {"Tabloid",                 DMPAPER_TABLOID},
154   {"TabloidExtra",            DMPAPER_TABLOID_EXTRA},
155   {NULL,                      0}
156 };
157
158 /* the same for bin names */
159
160 static struct {
161   char *PSName;
162   WORD WinBin;
163 } BinTrans[] = {
164   {"Cassette",          DMBIN_CASSETTE},
165   {"Envelope",          DMBIN_ENVELOPE},
166   {"LargeCapacity",     DMBIN_LARGECAPACITY},
167   {"Lower",             DMBIN_LOWER},
168   {"ManualFeed",        DMBIN_MANUAL},
169   {"Middle",            DMBIN_MIDDLE},
170   {"Upper",             DMBIN_UPPER},
171   {NULL,                0}
172 };
173
174 /***********************************************************************
175  *
176  *              PSDRV_PPDDecodeHex
177  *
178  * Copies str into a newly allocated string from the process heap subsituting
179  * hex strings enclosed in '<' and '>' for their byte codes.
180  *
181  */
182 static char *PSDRV_PPDDecodeHex(char *str)
183 {
184     char *buf, *in, *out;
185     BOOL inhex = FALSE;
186
187     buf = HeapAlloc(PSDRV_Heap, 0, strlen(str) + 1);
188     if(!buf)
189         return NULL;
190
191     for(in = str, out = buf; *in; in++) {
192         if(!inhex) {
193             if(*in != '<')
194                 *out++ = *in;
195             else
196                 inhex = TRUE;
197         } else {
198             if(*in == '>') {
199                 inhex = FALSE;
200                 continue;
201             }
202             else if(isspace(*in))
203                 continue;
204             else {
205                 int i;
206                 if(!isxdigit(*in) || !isxdigit(*(in + 1))) {
207                     ERR("Invalid hex char in hex string\n");
208                     HeapFree(PSDRV_Heap, 0, buf);
209                     return NULL;
210                 }
211                 *out = 0;
212                 for(i = 0; i < 2; i++) {
213                     if(isdigit(*(in + i)))
214                         *out |= (*(in + i) - '0') << ((1-i) * 4);
215                     else
216                         *out |= (toupper(*(in + i)) - 'A' + 10) << ((1-i) * 4);
217                 }
218                 out++;
219                 in++;
220             }
221         }
222     }
223     *out = '\0';
224     return buf;
225 }
226
227
228 /***********************************************************************
229  *
230  *              PSDRV_PPDGetTransValue
231  *
232  */
233 static BOOL PSDRV_PPDGetTransValue(char *start, PPDTuple *tuple)
234 {
235     char *buf, *end;
236
237     end = strpbrk(start, "\r\n");
238     if(end == start) return FALSE;
239     if(!end) end = start + strlen(start);
240     buf = HeapAlloc( PSDRV_Heap, 0, end - start + 1 );
241     memcpy(buf, start, end - start);
242     *(buf + (end - start)) = '\0';
243     tuple->valtrans = PSDRV_PPDDecodeHex(buf);
244     HeapFree( PSDRV_Heap, 0, buf );
245     return TRUE;
246 }
247
248
249 /***********************************************************************
250  *
251  *              PSDRV_PPDGetInvocationValue
252  *
253  * Passed string that should be surrounded by `"'s, return string alloced
254  * from process heap.
255  */
256 static BOOL PSDRV_PPDGetInvocationValue(FILE *fp, char *pos, PPDTuple *tuple)
257 {
258     char *start, *end, *buf;
259     char line[257];
260     int len;
261
262     start = pos + 1;
263     buf = HeapAlloc( PSDRV_Heap, 0, strlen(start) + 1 );
264     len = 0;
265     do {
266         end = strchr(start, '"');
267         if(end) {
268             buf = HeapReAlloc( PSDRV_Heap, 0, buf, 
269                                len + (end - start) + 1 );
270             memcpy(buf + len, start, end - start);
271             *(buf + len + (end - start)) = '\0';
272             tuple->value = buf;
273             start = strchr(end, '/');
274             if(start)
275                 return PSDRV_PPDGetTransValue(start + 1, tuple);
276             return TRUE;
277         } else {
278             int sl = strlen(start);
279             buf = HeapReAlloc( PSDRV_Heap, 0, buf, len + sl + 1 );
280             strcpy(buf + len, start);
281             len += sl;
282         }
283     } while( fgets((start = line), sizeof(line), fp) );
284
285     tuple->value = NULL;
286     HeapFree( PSDRV_Heap, 0, buf );
287     return FALSE;
288 }
289
290
291 /***********************************************************************
292  *
293  *              PSDRV_PPDGetQuotedValue
294  *
295  * Passed string that should be surrounded by `"'s. Expand <xx> as hex
296  * return string alloced from process heap.
297  */
298 static BOOL PSDRV_PPDGetQuotedValue(FILE *fp, char *pos, PPDTuple *tuple)
299 {
300     char *buf;
301
302     if(!PSDRV_PPDGetInvocationValue(fp, pos, tuple))
303         return FALSE;
304     buf = PSDRV_PPDDecodeHex(tuple->value);
305     HeapFree(PSDRV_Heap, 0, tuple->value);
306     tuple->value = buf;
307     return TRUE;
308 }
309
310
311 /***********************************************************************
312  *
313  *              PSDRV_PPDGetStringValue
314  *
315  * Just strip leading white space.
316  */
317 static BOOL PSDRV_PPDGetStringValue(char *str, PPDTuple *tuple)
318 {
319     char *start = str, *end;
320
321     while(*start != '\0' && isspace(*start))
322         start++;
323
324     end = strpbrk(start, "/\r\n");
325     if(!end) end = start + strlen(start);
326     tuple->value = HeapAlloc( PSDRV_Heap, 0, (end - start) + 1 );
327     memcpy(tuple->value, start, end - start);
328     *(tuple->value + (end - start)) = '\0';
329     if(*end == '/')
330         PSDRV_PPDGetTransValue(end + 1, tuple);
331     return TRUE;
332 }
333
334
335 /***********************************************************************
336  *
337  *              PSDRV_PPDSymbolValue
338  *
339  * Not implemented yet.
340  */
341 static BOOL PSDRV_PPDGetSymbolValue(char *pos, PPDTuple *tuple)
342 {
343     FIXME("Stub\n");
344     return FALSE;
345 }
346
347
348 /*********************************************************************
349  *
350  *              PSDRV_PPDGetNextTuple
351  *
352  * Gets the next Keyword Option Value tuple from the file. Allocs space off
353  * the process heap which should be free()ed by the caller if not needed.
354  */
355 static BOOL PSDRV_PPDGetNextTuple(FILE *fp, PPDTuple *tuple)
356 {
357     char line[257], *opt = NULL, *cp, *trans;
358     BOOL gotoption = TRUE;
359
360     memset(tuple, 0, sizeof(*tuple));
361
362     do {
363         if(!fgets(line, sizeof(line), fp))
364             return FALSE;
365         if(line[0] == '*' && line[1] != '%' && strncmp(line, "*End", 4))
366             break;
367     } while(1);
368
369     if(line[strlen(line)-1] != '\n') {
370         ERR("Line too long.\n");
371         return FALSE;
372     }
373
374     for(cp = line; !isspace(*cp); cp++)
375         ;
376
377     if(*(cp-1) == ':') {
378         cp--;
379         gotoption = FALSE;
380     } else {
381         opt = cp;
382     }
383
384     tuple->key = HeapAlloc( PSDRV_Heap, 0, cp - line + 1 );
385     if(!tuple->key) return FALSE;
386
387     memcpy(tuple->key, line, cp - line);
388     tuple->key[cp - line] = '\0';
389
390     if(gotoption) {
391         while(isspace(*opt))
392             opt++;
393         cp = strpbrk(opt, ":/");
394         if(!cp) {
395             ERR("Error in line '%s'?\n", line);
396             return FALSE;
397         }
398         tuple->option = HeapAlloc( PSDRV_Heap, 0, cp - opt + 1 );
399         if(!tuple->option) return FALSE;
400         memcpy(tuple->option, opt, cp - opt);
401         tuple->option[cp - opt] = '\0';
402         if(*cp == '/') {
403             char *buf;
404             trans = cp + 1;
405             cp = strchr(trans, ':');
406             if(!cp) {
407                 ERR("Error in line '%s'?\n", line);
408                 return FALSE;
409             }
410             buf = HeapAlloc( PSDRV_Heap, 0, cp - trans + 1 );
411             if(!buf) return FALSE;
412             memcpy(buf, trans, cp - trans);
413             buf[cp - trans] = '\0';
414             tuple->opttrans = PSDRV_PPDDecodeHex(buf);
415             HeapFree( PSDRV_Heap, 0, buf );
416         }
417     }
418     while(!isspace(*cp))
419         cp++;
420
421     while(isspace(*cp))
422         cp++;
423
424     switch(*cp) {
425     case '"':
426         if( (!gotoption && strncmp(tuple->key, "*?", 2) ) ||
427              !strncmp(tuple->key, "*JCL", 4))
428             PSDRV_PPDGetQuotedValue(fp, cp, tuple);
429         else
430             PSDRV_PPDGetInvocationValue(fp, cp, tuple);
431         break;
432
433     case '^':
434         PSDRV_PPDGetSymbolValue(cp, tuple);
435         break;
436
437     default:
438         PSDRV_PPDGetStringValue(cp, tuple);
439     }
440     return TRUE;
441 }
442
443 /*********************************************************************
444  *
445  *              PSDRV_PPDGetPageSizeInfo
446  *
447  * Searches ppd PageSize list to return entry matching name or creates new
448  * entry which is appended to the list if name is not found.
449  *
450  */
451 PAGESIZE *PSDRV_PPDGetPageSizeInfo(PPD *ppd, char *name)
452 {
453     PAGESIZE *page = ppd->PageSizes, *lastpage;
454     
455     if(!page) {
456        page = ppd->PageSizes = HeapAlloc( PSDRV_Heap,
457                                             HEAP_ZERO_MEMORY, sizeof(*page) );
458        return page;
459     } else {
460         for( ; page; page = page->next) {
461             if(!strcmp(page->Name, name))
462                  return page;
463             lastpage = page;
464         }
465
466         lastpage->next = HeapAlloc( PSDRV_Heap,
467                                            HEAP_ZERO_MEMORY, sizeof(*page) );
468         return lastpage->next;
469     }
470 }
471
472 /**********************************************************************
473  *
474  *              PSDRV_PPDGetWord
475  *
476  * Returns ptr alloced from heap to first word in str. Strips leading spaces.
477  * Puts ptr to next word in next
478  */
479 static char *PSDRV_PPDGetWord(char *str, char **next)
480 {
481     char *start, *end, *ret;
482
483     start = str;
484     while(start && *start && isspace(*start))
485         start++;
486     if(!start || !*start) return FALSE;
487
488     end = start;
489     while(*end && !isspace(*end))
490         end++;
491
492     ret = HeapAlloc( PSDRV_Heap, 0, end - start + 1 );
493     memcpy(ret, start, end - start );
494     *(ret + (end - start)) = '\0';
495
496     while(*end && isspace(*end))
497         end++;
498     if(*end)
499         *next = end;
500     else
501         *next = NULL;
502
503     return ret;
504 }
505
506 /***********************************************************************
507  *
508  *              PSDRV_ParsePPD
509  *
510  *
511  */
512 PPD *PSDRV_ParsePPD(char *fname)
513 {
514     FILE *fp;
515     PPD *ppd;
516     PPDTuple tuple;
517
518     TRACE("%s\n", fname);
519
520     if((fp = fopen(fname, "r")) == NULL) {
521         WARN("Couldn't open ppd file '%s'\n", fname);
522         return NULL;
523     }
524
525     ppd = HeapAlloc( PSDRV_Heap, HEAP_ZERO_MEMORY, sizeof(*ppd));
526     if(!ppd) {
527         ERR("Unable to allocate memory for ppd\n");
528         fclose(fp);
529         return NULL;
530     }
531
532     
533     while( PSDRV_PPDGetNextTuple(fp, &tuple)) {
534
535         if(!strcmp("*NickName", tuple.key)) {
536             ppd->NickName = tuple.value;
537             tuple.value = NULL;
538             TRACE("NickName = '%s'\n", ppd->NickName);
539         }
540
541         else if(!strcmp("*LanguageLevel", tuple.key)) {
542             sscanf(tuple.value, "%d", &(ppd->LanguageLevel));
543             TRACE("LanguageLevel = %d\n", ppd->LanguageLevel);
544         }
545
546         else if(!strcmp("*ColorDevice", tuple.key)) {
547             if(!strcasecmp(tuple.value, "true"))
548                 ppd->ColorDevice = TRUE;
549             TRACE("ColorDevice = %d\n", (int)ppd->ColorDevice);
550         }
551
552         else if((!strcmp("*DefaultResolution", tuple.key)) ||
553                 (!strcmp("*DefaultJCLResolution", tuple.key))) {
554             sscanf(tuple.value, "%d", &(ppd->DefaultResolution));
555             TRACE("DefaultResolution = %d\n", ppd->DefaultResolution);
556         }
557
558         else if(!strcmp("*Font", tuple.key)) {
559             FONTNAME *fn;
560
561             for(fn = ppd->InstalledFonts; fn && fn->next; fn = fn->next)
562                 ;
563             if(!fn) {
564                 ppd->InstalledFonts = HeapAlloc(PSDRV_Heap,
565                                                HEAP_ZERO_MEMORY, sizeof(*fn));
566                 fn = ppd->InstalledFonts;
567             } else {
568                fn->next = HeapAlloc(PSDRV_Heap,
569                                                HEAP_ZERO_MEMORY, sizeof(*fn));
570                fn = fn->next;
571             }
572             fn->Name = tuple.option;
573             tuple.option = NULL;
574         }
575
576         else if(!strcmp("*DefaultFont", tuple.key)) {
577             ppd->DefaultFont = tuple.value;
578             tuple.value = NULL;
579         }
580
581         else if(!strcmp("*JCLBegin", tuple.key)) {
582             ppd->JCLBegin = tuple.value;
583             tuple.value = NULL;
584         }
585
586         else if(!strcmp("*JCLToPSInterpreter", tuple.key)) {
587             ppd->JCLToPSInterpreter = tuple.value;
588             tuple.value = NULL;
589         }
590
591         else if(!strcmp("*JCLEnd", tuple.key)) {
592             ppd->JCLEnd = tuple.value;
593             tuple.value = NULL;
594         }
595
596         else if(!strcmp("*PageSize", tuple.key)) {
597             PAGESIZE *page;
598             page = PSDRV_PPDGetPageSizeInfo(ppd, tuple.option);
599
600             if(!page->Name) {
601                 int i;
602
603                 page->Name = tuple.option;
604                 tuple.option = NULL;
605                 
606                 for(i = 0; PageTrans[i].PSName; i++) {
607                     if(!strcmp(PageTrans[i].PSName, page->Name)) { /* case ? */
608                         page->WinPage = PageTrans[i].WinPage;
609                         break;
610                     }
611                 }
612                 if(!page->WinPage)
613                     FIXME("Can't find Windows page type for '%s'\n",
614                           page->Name);
615             }
616             if(!page->FullName) {
617                 if(tuple.opttrans) {
618                     page->FullName = tuple.opttrans;
619                     tuple.opttrans = NULL;
620                 } else {
621                     page->FullName = HEAP_strdupA( PSDRV_Heap, 0, page->Name );
622                 }
623             }
624             if(!page->InvocationString) {
625                 page->InvocationString = tuple.value;
626                 tuple.value = NULL;
627             }
628         }
629
630         else if(!strcmp("*ImageableArea", tuple.key)) {
631             PAGESIZE *page;
632             page = PSDRV_PPDGetPageSizeInfo(ppd, tuple.option);
633             
634             if(!page->Name) {
635                 page->Name = tuple.option;
636                 tuple.option = NULL;
637             }
638             if(!page->FullName) {
639                 page->FullName = tuple.opttrans;
640                 tuple.opttrans = NULL;
641             }
642
643 #define PIA page->ImageableArea
644             if(!PIA) {
645                 PIA = HeapAlloc( PSDRV_Heap, 0, sizeof(*PIA) );
646                 sscanf(tuple.value, "%f%f%f%f", &PIA->llx, &PIA->lly,
647                                                 &PIA->urx, &PIA->ury);
648             }
649 #undef PIA
650         }
651
652
653         else if(!strcmp("*PaperDimension", tuple.key)) {
654             PAGESIZE *page;
655             page = PSDRV_PPDGetPageSizeInfo(ppd, tuple.option);
656             
657             if(!page->Name) {
658                 page->Name = tuple.option;
659                 tuple.option = NULL;
660             }
661             if(!page->FullName) {
662                 page->FullName = tuple.opttrans;
663                 tuple.opttrans = NULL;
664             }
665
666 #define PD page->PaperDimension
667             if(!PD) {
668                 PD = HeapAlloc( PSDRV_Heap, 0, sizeof(*PD) );
669                 sscanf(tuple.value, "%f%f", &PD->x, &PD->y);
670             }
671 #undef PD
672         }
673
674         else if(!strcmp("*LandscapeOrientation", tuple.key)) {
675             if(!strcmp(tuple.value, "Plus90"))
676                 ppd->LandscapeOrientation = 90;
677             else if(!strcmp(tuple.value, "Minus90"))
678                 ppd->LandscapeOrientation = -90;
679
680             /* anything else, namely 'any', leaves value at 0 */
681
682             TRACE("LandscapeOrientation = %d\n", 
683                   ppd->LandscapeOrientation);
684         }
685         
686         else if(!strcmp("*UIConstraints", tuple.key)) {
687             char *start;
688             CONSTRAINT *con, **insert = &ppd->Constraints;
689
690             while(*insert)
691                 insert = &((*insert)->next);
692             
693             con = *insert = HeapAlloc( PSDRV_Heap, HEAP_ZERO_MEMORY,
694                                        sizeof(*con) );
695
696             start = tuple.value;
697             
698             con->Feature1 = PSDRV_PPDGetWord(start, &start);
699             con->Value1 = PSDRV_PPDGetWord(start, &start);
700             con->Feature2 = PSDRV_PPDGetWord(start, &start);
701             con->Value2 = PSDRV_PPDGetWord(start, &start);
702         }
703             
704         else if(!strcmp("*InputSlot", tuple.key)) {
705             INPUTSLOT *slot, **insert = &ppd->InputSlots;
706             int i;
707
708             while(*insert)
709                 insert = &((*insert)->next);
710
711             slot = *insert = HeapAlloc( PSDRV_Heap, HEAP_ZERO_MEMORY,
712                                     sizeof(*slot) );
713
714             slot->Name = tuple.option;
715             tuple.option = NULL;
716             if(tuple.opttrans) {
717                 slot->FullName = tuple.opttrans;
718                 tuple.opttrans = NULL;
719             } else {
720                 slot->FullName = HEAP_strdupA( PSDRV_Heap, 0, slot->Name );
721             }
722
723             if(tuple.value) {
724                 slot->InvocationString = tuple.value;
725                 tuple.value = NULL;
726             }
727
728             
729             for(i = 0; BinTrans[i].PSName; i++) {
730                 if(!strcmp(BinTrans[i].PSName, slot->Name)) { /* case ? */
731                     slot->WinBin = BinTrans[i].WinBin;
732                     break;
733                 }
734             }
735             if(!slot->WinBin)
736                 FIXME("Can't find Windows bin type for '%s'\n",
737                           slot->Name);
738
739         }   
740
741         if(tuple.key) HeapFree(PSDRV_Heap, 0, tuple.key);
742         if(tuple.option) HeapFree(PSDRV_Heap, 0, tuple.option);
743         if(tuple.value) HeapFree(PSDRV_Heap, 0, tuple.value);
744         if(tuple.opttrans) HeapFree(PSDRV_Heap, 0, tuple.opttrans);
745         if(tuple.valtrans) HeapFree(PSDRV_Heap, 0, tuple.valtrans);    
746         
747     }
748
749
750     {
751         FONTNAME *fn;
752         PAGESIZE *page;
753         CONSTRAINT *con;
754         INPUTSLOT *slot;
755         OPTION *option;
756         OPTIONENTRY *optionEntry;
757
758         for(fn = ppd->InstalledFonts; fn; fn = fn->next)
759             TRACE("'%s'\n", fn->Name);
760         
761         for(page = ppd->PageSizes; page; page = page->next) {
762             TRACE("'%s' aka '%s' (%d) invoked by '%s'\n", page->Name,
763               page->FullName, page->WinPage, page->InvocationString);
764             if(page->ImageableArea)
765                 TRACE("Area = %.2f,%.2f - %.2f, %.2f\n", 
766                       page->ImageableArea->llx, page->ImageableArea->lly,
767                       page->ImageableArea->urx, page->ImageableArea->ury);
768             if(page->PaperDimension)
769                 TRACE("Dimension = %.2f x %.2f\n", 
770                       page->PaperDimension->x, page->PaperDimension->y);
771         }
772
773         for(con = ppd->Constraints; con; con = con->next)
774             TRACE("CONSTRAINTS@ %s %s %s %s\n", con->Feature1,
775                   con->Value1, con->Feature2, con->Value2);
776
777         for(option = ppd->InstalledOptions; option; option = option->next) {
778             TRACE("OPTION: %s %s %s\n", option->OptionName,
779                   option->FullName, option->DefaultOption);
780             for(optionEntry = option->Options; optionEntry;
781                 optionEntry = optionEntry->next)
782                 TRACE("\tOPTIONENTRY: %s %s %s\n", optionEntry->Name,
783                       optionEntry->FullName, optionEntry->InvocationString);
784         }
785
786         for(slot = ppd->InputSlots; slot; slot = slot->next)
787             TRACE("INPUTSLOTS '%s' Name '%s' (%d) Invocation '%s'\n",
788                   slot->Name, slot->FullName, slot->WinBin, 
789                   slot->InvocationString);
790     }
791
792     return ppd;
793 }
794