|
|
1.1 ! root 1: //-------------------------------------------------------------------------- ! 2: // ! 3: // Module Name: PPD.C ! 4: // ! 5: // Brief Description: This module contains the PSCRIPT driver's PPD ! 6: // Compiler. ! 7: // ! 8: // Author: Kent Settle (kentse) ! 9: // Created: 20-Mar-1991 ! 10: // ! 11: // Copyright (c) 1991 Microsoft Corporation ! 12: // ! 13: // This module contains routines which will take an Adobe PPD (printer ! 14: //-------------------------------------------------------------------------- ! 15: ! 16: #include "string.h" ! 17: #include "pscript.h" ! 18: ! 19: // declarations of routines residing within this module. ! 20: ! 21: PNTPD GetNTPD(PDEVDATA, PWSTR); ! 22: ! 23: // external declarations. ! 24: ! 25: extern VOID InitNTPD(PNTPD); ! 26: extern VOID ParsePPD(PNTPD, PTMP_NTPD, PPARSEDATA); ! 27: extern VOID BuildNTPD(PNTPD, PTMP_NTPD); ! 28: extern DWORD SizeNTPD(PNTPD, PTMP_NTPD); ! 29: ! 30: extern TABLE_ENTRY KeywordTable[]; ! 31: extern TABLE_ENTRY SecondKeyTable[]; ! 32: extern TABLE_ENTRY FontTable[]; ! 33: ! 34: //-------------------------------------------------------------------------- ! 35: // PNTPD GetNTPD(pdev, pwstrPPDFile) ! 36: // PDEVDATA pdev; ! 37: // PWSTR pwstrPPDFile; ! 38: // ! 39: // This is the routine which does all the work. It Parses the PPD file ! 40: // a line at a time, looking for keywords, then acting appropriately. ! 41: // ! 42: // Returns: ! 43: // This routine returns TRUE for success, FALSE otherwise. ! 44: // ! 45: // History: ! 46: // 04-Aug-1992 -by- Kent Settle (kentse) ! 47: // Integrated into driver, rather than stand alone exe. ! 48: // 22-Mar-1991 -by- Kent Settle (kentse) ! 49: // Wrote it. ! 50: //-------------------------------------------------------------------------- ! 51: ! 52: PNTPD GetNTPD(pdev, pwstrPPDFile) ! 53: PDEVDATA pdev; ! 54: PWSTR pwstrPPDFile; ! 55: { ! 56: PNTPD pntpd, pstub; ! 57: PTMP_NTPD ptmp; ! 58: PPARSEDATA pdata; ! 59: NTPD ntpdStub; ! 60: DWORD dwSize; ! 61: ! 62: // allocate some memory for parsing data structure. ! 63: ! 64: if (!(pdata = (PPARSEDATA)HeapAlloc(pdev->hheap, 0, sizeof(PARSEDATA)))) ! 65: { ! 66: RIP("PSCRIPT!GetNTPD: HeapAlloc for pdata failed.\n"); ! 67: return((PNTPD)NULL); ! 68: } ! 69: ! 70: memset(pdata, 0, sizeof(PARSEDATA)); ! 71: ! 72: // open PPD file for input. ! 73: ! 74: pdata->fEOF = FALSE; ! 75: pdata->hFile = CreateFile(pwstrPPDFile, GENERIC_READ, ! 76: FILE_SHARE_READ, NULL, OPEN_EXISTING, ! 77: FILE_ATTRIBUTE_NORMAL, NULL); ! 78: ! 79: if (pdata->hFile == INVALID_HANDLE_VALUE) ! 80: { ! 81: RIP("PSCRIPT!GetNTPD: failed to open PPD file.\n"); ! 82: return((PNTPD)NULL); ! 83: } ! 84: ! 85: // allocate some memory to build the TMP_NTPD structure. ! 86: ! 87: if (!(ptmp = (PTMP_NTPD)HeapAlloc(pdev->hheap, 0, sizeof(TMP_NTPD)))) ! 88: { ! 89: CloseHandle(pdata->hFile); ! 90: RIP("PSCRIPT!GetNTPD: GlobalAlloc for ptmp failed.\n"); ! 91: return((PNTPD)NULL); ! 92: } ! 93: ! 94: memset(ptmp, 0, sizeof(TMP_NTPD)); ! 95: ! 96: // now parse the PPD file, building the TMP_NTPD structure. ! 97: ! 98: pstub = &ntpdStub; ! 99: memset(pstub, 0, sizeof(ntpdStub)); ! 100: ! 101: InitNTPD(pstub); ! 102: ! 103: ParsePPD(pstub, ptmp, pdata); ! 104: ! 105: // we are done with the PPD file, so close it. ! 106: ! 107: CloseHandle(pdata->hFile); ! 108: HeapFree(pdev->hheap, 0, (PVOID)pdata); ! 109: ! 110: // find out how big the NTPD structure will be for this printer. ! 111: ! 112: if (!(dwSize = SizeNTPD(pstub, ptmp))) ! 113: { ! 114: HeapFree(pdev->hheap, 0, (PVOID)ptmp); ! 115: RIP("PSCRIPT!GetNTPD: SizeNTPD failed.\n"); ! 116: return((PNTPD)NULL); ! 117: } ! 118: ! 119: // allocate some memory to build the NTPD structure in. ! 120: ! 121: if (!(pntpd = (PNTPD)HeapAlloc(pdev->hheap, 0, dwSize))) ! 122: { ! 123: HeapFree(pdev->hheap, 0, (PVOID)ptmp); ! 124: RIP("PSCRIPT!GetNTPD: HeapAlloc for pntpd failed.\n"); ! 125: return((PNTPD)NULL); ! 126: } ! 127: ! 128: // ParsePPD will have filled in the NTPD stub structure, so copy ! 129: // it to the real NTPD structure, then call BuildNTPD to add to ! 130: // it. ! 131: ! 132: memcpy(pntpd, pstub, sizeof(ntpdStub)); ! 133: ! 134: // now move data from the TMP_NTPD structure, into the more compact ! 135: // NTPD structure. ! 136: ! 137: BuildNTPD(pntpd, ptmp); ! 138: ! 139: // free up temporary memory. ! 140: ! 141: HeapFree(pdev->hheap, 0, (PVOID)ptmp); ! 142: ! 143: return(pntpd); // success ! 144: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.