Beispiel #1
0
UnicodeString TRegistry::ReadString(const UnicodeString & Name)
{
  UnicodeString Result = L"";
  TRegDataType RegData = rdUnknown;
  intptr_t Len = GetDataSize(Name);
  if (Len > 0)
  {
    Result.SetLength(Len);
    GetData(Name, static_cast<void *>(const_cast<wchar_t *>(Result.c_str())), Len, RegData);
    if ((RegData == rdString) || (RegData == rdExpandString))
    {
      PackStr(Result);
    }
    else { ReadError(Name); }
  }
  else
  {
    Result = L"";
  }
  return Result;
}
UnicodeString UnMungeStr(const UnicodeString & Str)
{
  // Str should contain ASCII characters only
  RawByteString Source = Str;
  RawByteString Dest;
  char * Buffer = Dest.SetLength(Source.GetLength());
  putty_unmungestr(Source.c_str(), Buffer, static_cast<int>(Source.GetLength()));
  // Cut the string at null character
  PackStr(Dest);
  UnicodeString Result;
  const std::string Bom(CONST_BOM);
  if (Dest.Pos(Bom.c_str()) == 1)
  {
    Dest.Delete(1, Bom.size());
    Result = UTF8ToString(Dest);
  }
  else
  {
    Result = AnsiToString(Dest);
  }
  return Result;
}
UnicodeString MungeStr(const UnicodeString & Str, bool ForceAnsi)
{
  RawByteString Source;
  if (ForceAnsi)
  {
    Source = RawByteString(AnsiString(Str));
  }
  else
  {
    Source = RawByteString(UTF8String(Str));
    if (Source.Length() > Str.Length())
    {
      Source.Insert(CONST_BOM, 1);
    }
  }
  // should contain ASCII characters only
  RawByteString Dest;
  char * Buffer = Dest.SetLength(Source.Length() * 3 + 1);
  putty_mungestr(Source.c_str(), Buffer);
  PackStr(Dest);
  return UnicodeString(Dest.c_str(), Dest.Length());
}
Beispiel #4
0
BOOL
PackBinaryData(
    PPARSERDATA pParserData,
    PMPD        pmpd
    )

/*++

Routine Description:

    Package the data parsed from a printer description file into binary format

Arguments:

    pParserData - Points to parser data structure
    pmpd - Points to a buffer for storing binary printer description data

Return Value:

    TRUE if successful, FALSE otherwise

--*/

{
    PBYTE   pbuf = (PBYTE) pmpd;
    DWORD   offset = 0;

    //
    // Pack MPD structure itself
    //

    pmpd->mpdSignature = MPD_SIGNATURE;
    pmpd->parserVersion = XLD_PARSER_VERSION;
    pmpd->checksum = pParserData->checksum ? pParserData->checksum : 0xffff;
    pmpd->specVersion = pParserData->specVersion;
    pmpd->fileVersion = pParserData->fileVersion;
    pmpd->xlProtocol = pParserData->xlProtocol;

    pmpd->numPlanes = pParserData->numPlanes;
    pmpd->bitsPerPlane = pParserData->bitsPerPlane;
    pmpd->maxCustomSize = pParserData->maxCustomSize;

    offset += RoundUpDWord(sizeof(MPD));

    //
    // Pack vendor and model names
    //

    offset += PackStr(pbuf, offset, &pmpd->pVendorName, pParserData->pVendorName);
    offset += PackStr(pbuf, offset, &pmpd->pModelName, pParserData->pModelName);

    //
    // Pack JCL invocation strings
    //

    offset += PackInvocation(pbuf, offset, &pmpd->jclBegin, &pParserData->jclBegin);
    offset += PackInvocation(pbuf, offset, &pmpd->jclEnterLanguage, &pParserData->jclEnterLanguage);
    offset += PackInvocation(pbuf, offset, &pmpd->jclEnd, &pParserData->jclEnd);

    //
    // Pack symbols, font encoding, and font metrics
    //

    offset += PackSymbols(pbuf, offset, pParserData->pSymbols);
    offset += PackSymbols(pbuf, offset, pParserData->pFontMtx);
    offset += PackSymbols(pbuf, offset, pParserData->pFontEnc);

    //
    // Pack fetaure constraints information
    //
    
    if ((pmpd->cConstraints = pParserData->cConstraints) != 0) {

        DWORD   constraintSize;

        pmpd->pConstraints = (PCONSTRAINT) offset;
        constraintSize = sizeof(CONSTRAINT) * pmpd->cConstraints;
        memcpy(pbuf + offset, pParserData->pConstraints, constraintSize);
        offset += RoundUpDWord(constraintSize);
    }
    
    //
    // Pack device font information
    //

    if ((pmpd->cFonts = pParserData->cFonts) != 0) {

        PDEVFONT    pPackedFont;
        PFONTREC    pFont;

        pmpd->pFonts = (PDEVFONT) offset;
        pPackedFont = (PDEVFONT) (pbuf + offset);
        offset += RoundUpDWord(sizeof(DEVFONT) * pmpd->cFonts);

        for (pFont = pParserData->pFonts; pFont; pFont = pFont->pNext, pPackedFont++) {

            offset += PackStr(pbuf, offset, &pPackedFont->pName, pFont->pName);
            offset += PackStr(pbuf, offset, &pPackedFont->pXlation, pFont->pXlation);

            pPackedFont->mpdSignature = MPD_SIGNATURE;

            pPackedFont->pMetrics =
                (PFONTMTX) ((PSYMBOLOBJ) pFont->pFontMtx)->invocation.pData;

            pPackedFont->pEncoding =
                (PFD_GLYPHSET) ((PSYMBOLOBJ) pFont->pFontEnc)->invocation.pData;
        }
    }

    //
    // Pack printer feature information
    //

    if ((pmpd->cFeatures = pParserData->cFeatures) != 0) {

        PFEATUREOBJ pFeature = pParserData->pFeatures;
        DWORD       count = pParserData->cFeatures;
        PFEATURE    pPackedFeature;

        pmpd->featureSize = sizeof(FEATURE);
        pmpd->pPrinterFeatures = (PFEATURE) offset;
        pPackedFeature = (PFEATURE) (pbuf + offset);
        offset += RoundUpDWord(sizeof(FEATURE) * count);

        while (count--) {

            POPTIONOBJ  pOption;
            POPTION     pPackedOption;

            //
            // Printer feature information
            //

            offset += PackStr(pbuf, offset, &pPackedFeature->pName, pFeature->pName);
            offset += PackStr(pbuf, offset, &pPackedFeature->pXlation, pFeature->pXlation);

            pPackedFeature->mpdSignature = MPD_SIGNATURE;
            if (pFeature->installable)
                pPackedFeature->flags |= FF_INSTALLABLE;
            pPackedFeature->defaultSelection = pFeature->defaultIndex;
            pPackedFeature->section = pFeature->section;
            pPackedFeature->groupId = pFeature->groupId;
            pPackedFeature->size = GetFeatureSelectionSize(pFeature->groupId);
            pPackedFeature->count = (WORD) CountListItem(pFeature->pOptions);

            if (pPackedFeature->groupId < MAX_KNOWN_FEATURES) {

                pmpd->pBuiltinFeatures[pPackedFeature->groupId] =
                    (PFEATURE) ((PBYTE) pPackedFeature - pbuf);
            }

            pOption = pFeature->pOptions;
            pPackedOption = (POPTION) (pbuf + offset);
            pPackedFeature->pFeatureOptions = (POPTION) offset;
            offset += RoundUpDWord(pPackedFeature->size * pPackedFeature->count);

            while (pOption != NULL) {

                //
                // Feature selection information
                //

                offset += PackStr(pbuf, offset, &pPackedOption->pName, pOption->pName);
                offset += PackStr(pbuf, offset, &pPackedOption->pXlation, pOption->pXlation);
                offset += PackInvocation(
                                pbuf, offset, &pPackedOption->invocation, &pOption->invocation);

                pPackedOption->mpdSignature = MPD_SIGNATURE;

                switch (pPackedFeature->groupId) {

                case GID_PAPERSIZE:

                    ((PPAPERSIZE) pPackedOption)->size = ((PPAPEROBJ) pOption)->size;
                    ((PPAPERSIZE) pPackedOption)->imageableArea =
                        ((PPAPEROBJ) pOption)->imageableArea;
                    break;

                case GID_RESOLUTION:

                    ((PRESOPTION) pPackedOption)->xdpi = ((PRESOBJ) pOption)->xdpi;
                    ((PRESOPTION) pPackedOption)->ydpi = ((PRESOBJ) pOption)->ydpi;
                    break;

                case GID_MEMOPTION:

                    ((PMEMOPTION) pPackedOption)->freeMem = ((PMEMOBJ) pOption)->freeMem;
                    break;
                }

                pPackedOption = (POPTION) ((PBYTE) pPackedOption + pPackedFeature->size);
                pOption = pOption->pNext;
            }

            pFeature = pFeature->pNext;
            pPackedFeature++;
        }
    }

    if (!MpdPaperSizes(pmpd) || !MpdInputSlots(pmpd) ||
        !MpdResOptions(pmpd) || !MpdMemOptions(pmpd))
    {
        Error(("Missing required features\n"));
        return FALSE;
    }

    if (offset != pmpd->fileSize) {

        Error(("Incorrect binary printer description data size\n"));
        Assert(FALSE);
    }

    return TRUE;
}