Annotation of ntddk/src/print/pscrptui/ppd.c, revision 1.1

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: #include "pscrptui.h"
        !            19: 
        !            20: #define TESTING 0
        !            21: 
        !            22: // declarations of routines residing within this module.
        !            23: 
        !            24: PNTPD UIGetNTPD(PWSTR);
        !            25: 
        !            26: // external declarations.
        !            27: 
        !            28: extern VOID InitNTPD(PNTPD);
        !            29: extern VOID ParsePPD(PNTPD, PTMP_NTPD, PPARSEDATA);
        !            30: extern VOID BuildNTPD(PNTPD, PTMP_NTPD);
        !            31: extern DWORD SizeNTPD(PNTPD, PTMP_NTPD);
        !            32: 
        !            33: extern TABLE_ENTRY KeywordTable[];
        !            34: extern TABLE_ENTRY SecondKeyTable[];
        !            35: extern TABLE_ENTRY FontTable[];
        !            36: 
        !            37: //--------------------------------------------------------------------------
        !            38: // PNTPD UIGetNTPD(pwstrPPDFile)
        !            39: // PWSTR    pwstrPPDFile;
        !            40: //
        !            41: // This is the routine which does all the work.  It Parses the PPD file
        !            42: // a line at a time, looking for keywords, then acting appropriately.
        !            43: //
        !            44: // Returns:
        !            45: //   This routine returns TRUE for success, FALSE otherwise.
        !            46: //
        !            47: // History:
        !            48: //   04-Aug-1992    -by-    Kent Settle     (kentse)
        !            49: //  Integrated into driver, rather than stand alone exe.
        !            50: //   22-Mar-1991    -by-    Kent Settle    (kentse)
        !            51: //  Wrote it.
        !            52: //--------------------------------------------------------------------------
        !            53: 
        !            54: PNTPD UIGetNTPD(pwstrPPDFile)
        !            55: PWSTR    pwstrPPDFile;
        !            56: {
        !            57:     PNTPD       pntpd, pstub;
        !            58:     PTMP_NTPD   ptmp;
        !            59:     PPARSEDATA  pdata;
        !            60:     NTPD        ntpdStub;
        !            61:     DWORD       dwSize;
        !            62: #if DBG
        !            63:     UNALIGNED DWORD      *pID;
        !            64: #endif
        !            65: 
        !            66:     // allocate some memory to build the TMP_NTPD structure.
        !            67: 
        !            68:     if (!(ptmp = (PTMP_NTPD)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT,
        !            69:                                         sizeof(TMP_NTPD))))
        !            70:     {
        !            71:         RIP("PSCRPTUI!UIGetNTPD: GlobalAlloc for ptmp failed.\n");
        !            72:         return((PNTPD)NULL);
        !            73:     }
        !            74: 
        !            75:     // allocate some memory for parsing data structure.
        !            76: 
        !            77:     if (!(pdata = (PPARSEDATA)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT,
        !            78:                                           sizeof(PARSEDATA))))
        !            79:     {
        !            80:         RIP("PSCRPTUI!UIGetNTPD: GlobalAlloc for ptmp failed.\n");
        !            81:         return((PNTPD)NULL);
        !            82:     }
        !            83: 
        !            84:     // open PPD file for input.
        !            85: 
        !            86:     pdata->fEOF = FALSE;
        !            87:     pdata->hFile = CreateFile(pwstrPPDFile, GENERIC_READ,
        !            88:                           FILE_SHARE_READ, NULL, OPEN_EXISTING,
        !            89:                           FILE_ATTRIBUTE_NORMAL, NULL);
        !            90: 
        !            91:     if (pdata->hFile == INVALID_HANDLE_VALUE)
        !            92:     {
        !            93:         RIP("PSCRPTUI!UIGetNTPD:  failed to open PPD file.\n");
        !            94:         return((PNTPD)NULL);
        !            95:     }
        !            96: 
        !            97:     // now parse the PPD file, building the TMP_NTPD structure.
        !            98: 
        !            99:     pstub = &ntpdStub;
        !           100:     memset(pstub, 0, sizeof(ntpdStub));
        !           101: 
        !           102:     InitNTPD(pstub);
        !           103: 
        !           104:     ParsePPD(pstub, ptmp, pdata);
        !           105: 
        !           106:     // we are done with the PPD file, so close it.
        !           107: 
        !           108:     CloseHandle(pdata->hFile);
        !           109:     GlobalFree((HGLOBAL)pdata);
        !           110: 
        !           111:     // find out how big the NTPD structure will be for this printer.
        !           112: 
        !           113:     if (!(dwSize = SizeNTPD(pstub, ptmp)))
        !           114:     {
        !           115:         GlobalFree((HGLOBAL)ptmp);
        !           116:         RIP("PSCRPTUI!UIGetNTPD: SizeNTPD failed.\n");
        !           117:         return((PNTPD)NULL);
        !           118:     }
        !           119: 
        !           120: #if DBG
        !           121:     // attach our driver signature to the end of the NTPD structure, and
        !           122:     // make sure it does not get overwritten.
        !           123: 
        !           124:     dwSize += sizeof(DWORD);
        !           125: #endif
        !           126: 
        !           127:     // allocate some memory to build the NTPD structure in.
        !           128: 
        !           129:     if (!(pntpd = (PNTPD)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, dwSize)))
        !           130:     {
        !           131:         GlobalFree((HGLOBAL)ptmp);
        !           132:         RIP("PSCRPTUI!UIGetNTPD: GlobalAlloc for pntpd failed.\n");
        !           133:         return((PNTPD)NULL);
        !           134:     }
        !           135: 
        !           136:     // ParsePPD will have filled in the NTPD stub structure, so copy
        !           137:     // it to the real NTPD structure, then call BuildNTPD to add to
        !           138:     // it.
        !           139: 
        !           140:     memcpy(pntpd, pstub, sizeof(ntpdStub));
        !           141: 
        !           142: #if DBG
        !           143:     pID = (UNALIGNED DWORD *)((CHAR *)pntpd + pntpd->cjThis);
        !           144: 
        !           145:     *pID = DRIVER_ID;
        !           146: #endif
        !           147: 
        !           148:     // now move data from the TMP_NTPD structure, into the more compact
        !           149:     // NTPD structure.
        !           150: 
        !           151:     BuildNTPD(pntpd, ptmp);
        !           152: 
        !           153: #if DBG
        !           154:     // do a little sanity checking.
        !           155: 
        !           156:     pID = (UNALIGNED DWORD *)((CHAR *)pntpd + pntpd->cjThis);
        !           157: 
        !           158:     ASSERTPS((*pID != DRIVER_ID),
        !           159:              "PSCRPTUI!UIGetNTPD: NTPD structure overran buffer!!!\n");
        !           160: #endif
        !           161: 
        !           162:     // free up temporary memory.
        !           163: 
        !           164:     GlobalFree((HGLOBAL)ptmp);
        !           165: 
        !           166:     return(pntpd);  // success
        !           167: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.