2025-04-27 07:49:33 -04:00

1311 lines
34 KiB
Plaintext

/*++
Copyright (c) 1996-1997 Microsoft Corporation
Module Name:
pclxl.c
Abstract:
PCL XL dump tool
Environment:
Windows NT PostScript driver
Revision History:
01/17/97 -eigos-
Created it.
--*/
#include "precomp.h"
//
// Macros
//
#define FILENAME_SIZE 256
#define OUTPUT_VERBOSE 0x01
//
// Error messages
//
#define ERROR_INVALID_ARGUMENT -1
#define ERROR_OPENFILE -2
#define ERROR_HEAP_CREATE -3
#define ERROR_PARSE_XL_DATA -4
#define ERROR_HEAP_ALLOC -5
#define ARGUMENT_ERR_MSG_LINE 1
static BYTE *gcstrArgumentError[ARGUMENT_ERR_MSG_LINE] = {
"Usage: pclxl [output data]\n"
};
static BYTE gcstrOpenFileFailure[] = "Cannot open file \"%ws\".\n";
static BYTE gcstrHeapCreateFailure[] = "Failed to Create Heap.\a";
static BYTE gcstrHeapAlloc[] = "Failed to allocate memory.\n";
static BYTE gcstrParseError[] = "Failed to parse data.\n";
//
// Globals
//
DWORD gdwOutputFlags;
DWORD gdwStatusFlags;
#define STATUS_ARRAY 0x01
#define STATUS_EMBEDED_DATA 0x02
#define STATUS_EMBEDED_DATA_BYTE 0x03
//
// Binary Stream Tag Values
//
//
static BYTE gcstrNULL[] = "NULL"; // 0x00 White Space NULL
//
// 0x01 - 0x08 Not Used
//
static BYTE gcstrHT[] = "HT"; // 0x09
static BYTE gcstrLF[] = "LF"; // 0x0a
static BYTE gcstrVT[] = "VT"; // 0x0b
static BYTE gcstrFF[] = "FF"; // 0x0c
static BYTE gcstrCR[] = "CR"; // 0x0d
// 0x09 - 0x0d White Space HT, LF, VT, FF, CR
//
// 0x0e - 0x1f Not Used
//
static BYTE gcstrSP[] = "SP"; // 0x20
// 0x20 White Space Space
//
// 0x21 - 0x26 Not Used
//
// 0x27 Reserved for Beginning of ASCII binding.
// 0x28 Reserved for Beginning of binary binding - high byte first.
// 0x29 Reserved for Beginning of binary binding - low byte first.
//
// 0x41 - 0xb9 Operators
//
static BYTE gcstrBeginSession[] = "BeginSession";
static BYTE gcstrEndSession[] = "EndSession";
static BYTE gcstrBeginPage[] = "BeginPage";
static BYTE gcstrEndPage[] = "EndPage";
// 0x45
// 0x46
static BYTE gcstrComment[] = "Comment";
static BYTE gcstrOpenDataSource[] = "OpenDataSource";
static BYTE gcstrCloseDataSource[] = "ClosedataSource";
// 0x4a
// 0x4b
// 0x4c
// 0x4d
// 0x4e
static BYTE gcstrBeginFontHeader[] = "BeginFontHeader";
static BYTE gcstrReadFontHeader[] = "ReadFontHeader";
static BYTE gcstrEndFontHeader[] = "EndFontHeader";
static BYTE gcstrBeginChar[] = "BeginChar";
static BYTE gcstrReadChar[] = "ReadChar";
static BYTE gcstrEndChar[] = "EndChar";
static BYTE gcstrRemoveFont[] = "RemoveFont";
// 0x56
// 0x57
// 0x58
// 0x59
// 0x5a
static BYTE gcstrBeginStream[] = "BeginStream";
static BYTE gcstrReadStream[] = "ReadStream";
static BYTE gcstrEndStream[] = "EndStream";
static BYTE gcstrExecStream[] = "ExecStresm";
// 0x5f
static BYTE gcstrPopGS[] = "PopGS";
static BYTE gcstrPushGS[] = "PushGS";
static BYTE gcstrSetClipReplace[] = "SetClipReplace";
static BYTE gcstrSetBrushSource[] = "SetBrushSource";
static BYTE gcstrSetCharAngle[] = "SetCharAngle";
static BYTE gcstrSetCharScale[] = "SetCharScale";
static BYTE gcstrSetCharShear[] = "SetCharShear";
static BYTE gcstrSetClipIntersect[] = "SetClipIntersect";
static BYTE gcstrSetClipRectangle[] = "SetClipRectangle";
static BYTE gcstrSetClipToPage[] = "SetClipToPage";
static BYTE gcstrSetColorSpace[] = "SetColorSpace";
static BYTE gcstrSetCursor[] = "SetCursor";
static BYTE gcstrSetCursorRel[] = "SetCursorRel";
static BYTE gcstrSetHalftoneMethod[] = "SetHalftoneMethod";
static BYTE gcstrSetFillMode[] = "SetFillMode";
static BYTE gcstrSetFont[] = "SetFont";
static BYTE gcstrSetLineDash[] = "SetLineDash";
static BYTE gcstrSetLineCap[] = "SetLineCap";
static BYTE gcstrSetLineJoin[] = "SetLineJoin";
static BYTE gcstrSetMiterLimit[] = "SetMitterLimit";
static BYTE gcstrSetPageDefaultCTM[] = "SetPageDefaultCTM";
static BYTE gcstrSetPageOrigin[] = "SetPageOrigin";
static BYTE gcstrSetPageRotation[] = "SetPageRotation";
static BYTE gcstrSetPageScale[] = "SetPageScale";
static BYTE gcstrSetPatternTxMode[] = "SetPatternTxMode";
static BYTE gcstrSetPenSource[] = "SetPenSource";
static BYTE gcstrSetPenWidth[] = "SetPenWidth";
static BYTE gcstrSetROP[] = "SetROP";
static BYTE gcstrSetSourceTxMode[] = "SetSourceTxMode";
static BYTE gcstrSetCharBoldValue[] = "SetCharBoldValue";
// 0x7e
static BYTE gcstrSetClipMode[] = "SetClipMode";
static BYTE gcstrSetPathToClip[] = "SetPathToClip";
static BYTE gcstrSetCharSubMode[] = "SetCharSubMode";
// 0x82
// 0x83
static BYTE gcstrCloseSubPath[] = "CloseSubPath";
static BYTE gcstrNewPath[] = "NewPath";
static BYTE gcstrPaintPath[] = "PaintPath";
// 0x87
// 0x88
// 0x89
// 0x8a
// 0x8b
// 0x8c
// 0x8d
// 0x8e
// 0x8f
// 0x90
static BYTE gcstrArcPath[] = "ArcPath";
// 0x92
static BYTE gcstrBezierPath[] = "BezierPath";
// 0x94
static BYTE gcstrBezierRelPath[] = "BezierRelPath";
static BYTE gcstrChord[] = "Chord";
static BYTE gcstrChordPath[] = "ChordPath";
static BYTE gcstrEllipse[] = "Ellipse";
static BYTE gcstrEllipsePath[] = "EliipsePath";
// 0x9a
static BYTE gcstrLinePath[] = "LinePath";
// 0x9c
static BYTE gcstrLineRelPath[] = "LineRelPath";
static BYTE gcstrPie[] = "Pie";
static BYTE gcstrPiePath[] = "PiePath";
static BYTE gcstrRectangle[] = "Rectangle";
static BYTE gcstrRectanglePath[] = "RectanglePath";
static BYTE gcstrRoundRectangle[] = "RoundRectangle";
static BYTE gcstrRoundRectanglePath[] = "RoudnRectanglePath";
// 0xa4
// 0xa5
// 0xa6
// 0xa7
static BYTE gcstrText[] = "Text";
static BYTE gcstrTextPath[] = "TextPath";
// 0xa8
// 0xa9
// 0xaa
// 0xab
// 0xac
// 0xad
// 0xae
// 0xaf
static BYTE gcstrBeginImage[] = "BeginImage";
static BYTE gcstrReadImage[] = "ReadImage";
static BYTE gcstrEndImage[] = "EndImage";
static BYTE gcstrBeginRestPattern[] = "BeginRestPattern";
static BYTE gcstrReadRastPattern[] = "ReadRastPattern";
static BYTE gcstrEndRastPattern[] = "EndRastPattern";
static BYTE gcstrBeginScan[] = "BeginScan";
// 0xb7
static BYTE gcstrEndScan[] = "EndScan";
static BYTE gcstrScanLineRel[] = "ScanLineRel";
// 0xba - 0xbf Reserved for future use.
// 0xc0 ubyte
// 0xc1 uint16
// 0xc2 uint32
// 0xc3 sint16
// 0xc4 sint32
// 0xc5 real32
// 0xc6
// 0xc7
// 0xc8 ubyte_array
// 0xc9 uint16_array
// 0xca uint32_array
// 0xcb sint16_array
// 0xcc sint32_array
// 0xcd real32_array
// 0xce
// 0xcf
// 0xd0 ubyte_xy
// 0xd1 uint16_xy
// 0xd2 uint32_xy
// 0xd3 sint16_xy
// 0xd4 sint32_xy
// 0xd5 real32_xy
// 0xd6
// 0xd7
// 0xd8
// 0xd9
// 0xda
// 0xdb
// 0xdc
// 0xdd
// 0xde
// 0xdf
// 0xe0 ubyte_box
// 0xe1 uint16_box
// 0xe2 uint32_box
// 0xe3 sint16_box
// 0xe4 sint32_box
// 0xe5 real32_box
//
// 0xe6 - 0xef Reserved form future use.
//
// 0xf0 - 0xf7 Reserved form future use.
//
// 0xf8 attr_ubyte
// 0xf9 attr_uint16
//
// 0xfa dataLength Embedded Data Follows
//
// 0xfb dataLengthByte Emmedded Data Follows (0-255 bytes)
//
// 0xfc - 0xff Reserved for future use.
//
typedef enum _TAG_TYPE { NotUsed, WhiteSpace, Operator, DataType, Attribute, EmbedData, Binding, Reserved} TAG_TYPE;
typedef struct _BINARY_TAG {
TAG_TYPE TagType;
PBYTE pubTagName;
} BINARY_TAG, *PBINARY_TAG;
static BINARY_TAG
BinaryTagArray[256] = {
{WhiteSpace, gcstrNULL },// 0x00
{NotUsed, NULL },// 0x01
{NotUsed, NULL },// 0x02
{NotUsed, NULL },// 0x03
{NotUsed, NULL },// 0x04
{NotUsed, NULL },// 0x05
{NotUsed, NULL },// 0x06
{NotUsed, NULL },// 0x07
{NotUsed, NULL },// 0x08
{WhiteSpace, gcstrHT },// 0x09
{WhiteSpace, gcstrLF },// 0x0a
{WhiteSpace, gcstrVT },// 0x0b
{WhiteSpace, gcstrFF },// 0x0c
{WhiteSpace, gcstrCR },// 0x0d
{NotUsed, NULL },// 0x0e
{NotUsed, NULL },// 0x0f
{NotUsed, NULL },// 0x10
{NotUsed, NULL },// 0x11
{NotUsed, NULL },// 0x12
{NotUsed, NULL },// 0x13
{NotUsed, NULL },// 0x14
{NotUsed, NULL },// 0x15
{NotUsed, NULL },// 0x16
{NotUsed, NULL },// 0x17
{NotUsed, NULL },// 0x18
{NotUsed, NULL },// 0x19
{NotUsed, NULL },// 0x1a
{NotUsed, NULL },// 0x1b
{NotUsed, NULL },// 0x1c
{NotUsed, NULL },// 0x1d
{NotUsed, NULL },// 0x1e
{NotUsed, NULL },// 0x1f
{WhiteSpace, gcstrSP },// 0x20
{NotUsed, NULL },// 0x21
{NotUsed, NULL },// 0x22
{NotUsed, NULL },// 0x23
{NotUsed, NULL },// 0x24
{NotUsed, NULL },// 0x25
{NotUsed, NULL },// 0x26
{Binding, NULL },// 0x27
{Binding, NULL },// 0x28
{Binding, NULL },// 0x29
{NotUsed, NULL },// 0x2a
{NotUsed, NULL },// 0x2b
{NotUsed, NULL },// 0x2c
{NotUsed, NULL },// 0x2d
{NotUsed, NULL },// 0x2e
{NotUsed, NULL },// 0x2f
{NotUsed, NULL },// 0x30
{NotUsed, NULL },// 0x31
{NotUsed, NULL },// 0x32
{NotUsed, NULL },// 0x33
{NotUsed, NULL },// 0x34
{NotUsed, NULL },// 0x35
{NotUsed, NULL },// 0x36
{NotUsed, NULL },// 0x37
{NotUsed, NULL },// 0x38
{NotUsed, NULL },// 0x39
{NotUsed, NULL },// 0x3a
{NotUsed, NULL },// 0x3b
{NotUsed, NULL },// 0x3c
{NotUsed, NULL },// 0x3d
{NotUsed, NULL },// 0x3e
{NotUsed, NULL },// 0x3f
{NotUsed, NULL },// 0x40
{Operator, gcstrBeginSession },// 0x41
{Operator, gcstrEndSession },// 0x42
{Operator, gcstrBeginPage },// 0x43
{Operator, gcstrEndPage },// 0x44
{Operator, NULL },// 0x45
{Operator, NULL },// 0x46
{Operator, gcstrComment },// 0x47
{Operator, gcstrOpenDataSource },// 0x48
{Operator, gcstrCloseDataSource },// 0x49
{Operator, NULL },// 0x4a
{Operator, NULL },// 0x4b
{Operator, NULL },// 0x4c
{Operator, NULL },// 0x4d
{Operator, NULL },// 0x4e
{Operator, gcstrBeginFontHeader },// 0x4f
{Operator, gcstrReadFontHeader },// 0x50
{Operator, gcstrEndFontHeader },// 0x51
{Operator, gcstrBeginChar },// 0x52
{Operator, gcstrReadChar },// 0x53
{Operator, gcstrEndChar },// 0x54
{Operator, gcstrRemoveFont },// 0x55
{Operator, NULL },// 0x56
{Operator, NULL },// 0x57
{Operator, NULL },// 0x58
{Operator, NULL },// 0x59
{Operator, NULL },// 0x5a
{Operator, gcstrBeginStream },// 0x5b
{Operator, gcstrReadStream },// 0x5c
{Operator, gcstrEndStream },// 0x5d
{Operator, gcstrExecStream },// 0x5e
{Operator, NULL },// 0x5f
{Operator, gcstrPopGS },// 0x60
{Operator, gcstrPushGS },// 0x61
{Operator, gcstrSetClipReplace },// 0x62
{Operator, gcstrSetBrushSource },// 0x63
{Operator, gcstrSetCharAngle },// 0x64
{Operator, gcstrSetCharScale },// 0x65
{Operator, gcstrSetCharShear },// 0x66
{Operator, gcstrSetClipIntersect },// 0x67
{Operator, gcstrSetClipRectangle },// 0x68
{Operator, gcstrSetClipToPage },// 0x69
{Operator, gcstrSetColorSpace },// 0x6a
{Operator, gcstrSetCursor },// 0x6b
{Operator, gcstrSetCursorRel },// 0x6c
{Operator, gcstrSetHalftoneMethod },// 0x6d
{Operator, gcstrSetFillMode },// 0x6e
{Operator, gcstrSetFont },// 0x6f
{Operator, gcstrSetLineDash },// 0x70
{Operator, gcstrSetLineCap },// 0x71
{Operator, gcstrSetLineJoin },// 0x72
{Operator, gcstrSetMiterLimit },// 0x73
{Operator, gcstrSetPageDefaultCTM },// 0x74
{Operator, gcstrSetPageOrigin },// 0x75
{Operator, gcstrSetPageRotation },// 0x76
{Operator, gcstrSetPageScale },// 0x77
{Operator, gcstrSetPatternTxMode },// 0x78
{Operator, gcstrSetPenSource },// 0x79
{Operator, gcstrSetPenWidth },// 0x7a
{Operator, gcstrSetROP },// 0x7b
{Operator, gcstrSetSourceTxMode },// 0x7c
{Operator, gcstrSetCharBoldValue },// 0x7d
{Operator, NULL },// 0x7e
{Operator, gcstrSetClipMode },// 0x7f
{Operator, gcstrSetPathToClip },// 0x80
{Operator, gcstrSetCharSubMode },// 0x81
{Operator, NULL },// 0x82
{Operator, NULL },// 0x83
{Operator, gcstrCloseSubPath },// 0x84
{Operator, gcstrNewPath },// 0x85
{Operator, gcstrPaintPath },// 0x86
{Operator, NULL },// 0x87
{Operator, NULL },// 0x88
{Operator, NULL },// 0x89
{Operator, NULL },// 0x8a
{Operator, NULL },// 0x8b
{Operator, NULL },// 0x8c
{Operator, NULL },// 0x8d
{Operator, NULL },// 0x8e
{Operator, NULL },// 0x8f
{Operator, NULL },// 0x90
{Operator, gcstrArcPath },// 0x91
{Operator, NULL },// 0x92
{Operator, gcstrBezierPath },// 0x93
{Operator, NULL },// 0x94
{Operator, gcstrBezierRelPath },// 0x95
{Operator, gcstrChord },// 0x96
{Operator, gcstrChordPath },// 0x97
{Operator, gcstrEllipse },// 0x98
{Operator, gcstrEllipsePath },// 0x99
{Operator, NULL },// 0x9a
{Operator, gcstrLinePath },// 0x9b
{Operator, gcstrPie },// 0x9c
{Operator, gcstrPiePath },// 0x9d
{Operator, gcstrRectangle },// 0x9e
{Operator, gcstrRectanglePath },// 0x9f
{Operator, gcstrRoundRectangle },// 0xa0
{Operator, gcstrRoundRectanglePath },// 0xa1
{Operator, NULL },// 0xa2
{Operator, NULL },// 0xa3
{Operator, NULL },// 0xa4
{Operator, NULL },// 0xa5
{Operator, NULL },// 0xa6
{Operator, NULL },// 0xa7
{Operator, gcstrText },// 0xa8
{Operator, gcstrTextPath },// 0xa9
{Operator, NULL },// 0xaa
{Operator, NULL },// 0xab
{Operator, NULL },// 0xac
{Operator, NULL },// 0xad
{Operator, NULL },// 0xae
{Operator, NULL },// 0xaf
{Operator, gcstrBeginImage },// 0xb0
{Operator, gcstrReadImage },// 0xb1
{Operator, gcstrEndImage },// 0xb2
{Operator, gcstrBeginRestPattern },// 0xb3
{Operator, gcstrReadRastPattern },// 0xb4
{Operator, gcstrEndRastPattern },// 0xb5
{Operator, gcstrBeginScan },// 0xb6
{Operator, NULL },// 0xb7
{Operator, gcstrEndScan },// 0xb8
{Operator, gcstrScanLineRel },// 0xb9
{Operator, NULL },// 0xba
{Reserved, NULL },// 0xbb
{Reserved, NULL },// 0xbc
{Reserved, NULL },// 0xbd
{Reserved, NULL },// 0xbe
{Reserved, NULL },// 0xbf
{DataType,"ubyte" },// 0xc0
{DataType,"uint16" },// 0xc1
{DataType,"uint32" },// 0xc2
{DataType,"sint16" },// 0xc3
{DataType,"sint32" },// 0xc4
{DataType,"real32" },// 0xc5
{DataType,NULL },// 0xc6
{DataType,NULL },// 0xc7
{DataType, "ubyte_array" },// 0xc8
{DataType, "uint16_array" },// 0xc9
{DataType, "uint32_array" },// 0xca
{DataType, "sint16_array" },// 0xcb
{DataType, "sint32_array" },// 0xcc
{DataType, "real32_array" },// 0xcd
{DataType,NULL },// 0xce
{DataType,NULL },// 0xcf
{DataType,"ubyte_xy" },// 0xd0
{DataType,"uint16_xy" },// 0xd1
{DataType, "uint32_xy" },// 0xd2
{DataType, "sint16_xy" },// 0xd3
{DataType, "sint32_xy" },// 0xd4
{DataType, "real32_xy" },// 0xd5
{DataType,NULL },// 0xd6
{DataType,NULL },// 0xd7
{DataType,NULL },// 0xd8
{DataType,NULL },// 0xd9
{DataType,NULL },// 0xda
{DataType,NULL },// 0xdb
{DataType,NULL },// 0xdc
{DataType,NULL },// 0xdd
{DataType,NULL },// 0xde
{DataType,NULL },// 0xdf
{DataType,"ubyte_box" },// 0xe0
{DataType,"uint16_box" },// 0xe1
{DataType,"uint32_box" },// 0xe2
{DataType,"sint16_box" },// 0xe3
{DataType,"sint32_box" },// 0xe4
{DataType,"real32_box" },// 0xe5
{DataType,NULL },// 0xe6
{DataType,NULL },// 0xe7
{DataType,NULL },// 0xe8
{DataType,NULL },// 0xe9
{DataType,NULL },// 0xea
{DataType,NULL },// 0xeb
{DataType,NULL },// 0xec
{DataType,NULL },// 0xed
{DataType,NULL },// 0xee
{DataType,NULL },// 0xef
{Reserved,NULL },// 0xf0
{Reserved,NULL },// 0xf1
{Reserved,NULL },// 0xf2
{Reserved,NULL },// 0xf3
{Reserved,NULL },// 0xf4
{Reserved,NULL },// 0xf5
{Reserved,NULL },// 0xf6
{Reserved,NULL },// 0xf7
{Attribute,"attr_ubyte" },// 0xf8
{Attribute,"attr_uint16" },// 0xf9
{EmbedData,"dataLength" },// 0xfa
{EmbedData,"dataLengthByte" },// 0xfb
{Reserved, NULL }, //0xfc
{Reserved, NULL }, //0xfd
{Reserved, NULL }, //0xfe
{Reserved, NULL } //0xff
};
//
// Attribute IDs
//
static PBYTE pubAttributeID[180] = {
NULL, // 0
NULL,
"PaletteDepth",
"ColorSpace",
"NullBrush",
"NullPen",
"PaleteData",
NULL,
"PatternSelectID",
"GrayLevel",
NULL,
"RGBColor",
"PatternOrigin",
"NewDestinationSize",
NULL,
NULL,
NULL,
NULL, // 17
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
"DeviceMatrix", // 33
"DitherMatrixDataType",
"DitherOrigin",
"MediaDestination",
"MediaSize",
"MediaSource",
"MediaType",
"Orientation",
"PageAngle",
"PageOrigin",
"PageScale",
"ROP3",
"TxMode",
NULL,
"CustomMediaSize",
"CustomMediaSizeUnits", // 48
"PageCopies", // 49
"DitherMatrixSize",
"DithermatrixDepth",
"SimplexPageMode",
"DuplexPageMode",
"DuplexPageSize",
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL, // 64
"ArgDirection",
"BoundingBox",
"DashOffset",
"EllipseDimension",
"EndPoint",
"FillMode",
"LineCapStyle",
"LineJointStyle",
"MiterLength",
"PenDashStyle",
"PenWidth",
"Point",
"NumberOfPoints",
"SolidLine",
"StartPoint",
"PointType", // 80
"ControlPoint1", // 81
"ControlPoint2",
"ClipRegion",
"ClipMode",
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL, // 96
NULL, // 97
"ColorDepth",
"BlockHeight",
"ColorMapping",
"CompressMode",
"DestinationBox",
"DestinationSize",
"PatternPersistence",
"PatternDefineID",
NULL,
"SourceHeight",
"SourceWidth",
"StartLine",
"XPairType",
"NumberOfXPairs",
NULL, // 112
"XStart", // 113
"XEnd",
"NumberOfScanLines",
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL, // 128
"CommentData", // 129
"DataOrg",
NULL,
NULL,
NULL,
"Measure",
NULL,
"SourceType",
"UnitsPerMeasure",
NULL,
"StreamName",
"StreamDataLength",
NULL,
NULL,
"ErrorReport",
NULL, // 144
NULL, // 145
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL, // 160
"CharAngle", // 161
"CharCode",
"CharDataSize",
"CharScale",
"CharShear",
"CharSize",
"FontHeaderLength",
"FontName",
"FontFormat",
"SymbolSet",
"TextData",
"CharSubModeArray",
NULL,
NULL,
"XSpacingData",
"YSpacingData",
"CharBoldValue",
NULL,
NULL
};
//
// PJL strings
//
static BYTE gcstrPJL[] = "PJL";
static BYTE gcstrJOB[] = "JOB";
static BYTE gcstrSET[] = "SET";
static BYTE gcstrCOMMENT[] = "COMMENT";
static BYTE gcstrENTER[] = "ENTER";
static BYTE gcstrLANGUAGE[] = "LANGUAGE";
static BYTE gcstrPCLXL[] = "PCLXL";
#define NU 0x0
#define ESC 0x1b
#define SP 0x20
#define HT 0x09
#define LF 0x0a
#define VT 0x0b
#define FF 0x0c
#define CR 0x0d
//
// Internal function prototype
//
BOOL
BArgCheck(
IN INT,
IN CHAR **,
OUT PWSTR);
VOID
VArgumentError();
BOOL
BParseXLData(PVOID pXLFile, DWORD dwXLFileSize);
PBYTE
PRemovePJL(PBYTE pXLFile);
PBYTE PDecodeXL(PBYTE pData);
PBYTE
PSkipSpace(PBYTE pData);
PBYTE
PSkipLine(PBYTE pData);
PBYTE
PSkipWord(PBYTE pData);
//
//
// Functions
//
//
int _CRTAPI1
main(
IN int argc,
IN char **argv)
/*++
Routine Description:
main
Arguments:
argc - Number of parameters in the following
argv - The parameters, starting with our name
Return Value:
Return error code
Note:
--*/
{
WCHAR awchXLFileName[FILENAME_SIZE];
DWORD dwXLFileSize;
PVOID pXLFile;
HANDLE hXLFile;
//
// Argument check
// pclxl [Output data]
//
gdwStatusFlags = 0;
if (!BArgCheck(argc,
argv,
awchXLFileName))
{
VArgumentError();
return ERROR_INVALID_ARGUMENT;
}
//
// Open *.RC file.
//
if (gdwOutputFlags & OUTPUT_VERBOSE)
{
printf("***********************************************************\n");
printf("FILE: %ws\n", awchXLFileName);
printf("***********************************************************\n");
}
if (!(hXLFile = MapFileIntoMemory( (PTSTR)awchXLFileName,
(PVOID)&pXLFile,
(PDWORD)&dwXLFileSize )))
{
fprintf( stderr, gcstrOpenFileFailure, awchXLFileName);
return ERROR_OPENFILE;
}
if (!BParseXLData(pXLFile, dwXLFileSize))
{
fprintf( stderr, gcstrParseError);
return ERROR_PARSE_XL_DATA;
}
#if 0
//
// Heap Creation
//
if (!(hHeap = HeapCreate( HEAP_NO_SERIALIZE, 0x10000, 0x10000)))
{
fprintf( stderr, gcstrHeapCreateFailure);
ERR(("CreateHeap failed: %d\n", GetLastError()));
return ERROR_HEAP_CREATE;
}
#endif
UnmapFileFromMemory(hXLFile);
return 0;
}
BOOL
BArgCheck(
INT argc,
CHAR **argv,
PWSTR pwstrFileName)
{
if (argc != 2)
return FALSE;
argv++;
MultiByteToWideChar(CP_ACP,
0,
*argv,
strlen(*argv)+1,
pwstrFileName,
FILENAME_SIZE);
return TRUE;
}
VOID
VArgumentError()
{
SHORT sI;
for (sI = 0; sI < ARGUMENT_ERR_MSG_LINE; sI++)
{
fprintf( stderr, gcstrArgumentError[sI]);
}
}
BOOL
BParseXLData(
PBYTE pXLFile,
DWORD dwXLFileSize)
{
PBYTE pubFile;
//
// Remove PJL command
//
pubFile = PRemovePJL(pXLFile);
if ((DWORD)(pubFile - pXLFile) > dwXLFileSize)
return FALSE;
//
//
//
while ( (DWORD)(pubFile - pXLFile) < dwXLFileSize &&
pubFile != NULL &&
*pubFile != ESC)
pubFile = PDecodeXL(pubFile);
if (pubFile && (DWORD)(pubFile - pXLFile) <= dwXLFileSize)
return TRUE;
else
return FALSE;
}
PBYTE
PRemovePJL(
PBYTE pXLFile)
{
BOOL bBreak = FALSE;
if ((*pXLFile++ != ESC) ||
(*pXLFile++ != '%') ||
(*pXLFile++ != '-') ||
(*pXLFile++ != '1') ||
(*pXLFile++ != '2') ||
(*pXLFile++ != '3') ||
(*pXLFile++ != '4') ||
(*pXLFile++ != '5') ||
(*pXLFile++ != 'X') )
return NULL;
while (*pXLFile == '@' && !bBreak)
{
//
// Broken PJL command. Return FALSE.
//
if (*pXLFile == '@')
pXLFile ++;
if (strncmp(pXLFile, gcstrPJL, 3))
return NULL;
pXLFile = PSkipWord(pXLFile);
switch (*pXLFile)
{
case 'C':
if (!strncmp(pXLFile, gcstrCOMMENT, 7))
{
pXLFile = PSkipLine(pXLFile);
}
break;
case 'E':
if (!strncmp(pXLFile, gcstrENTER, 5))
{
pXLFile = PSkipWord(pXLFile);
if (!strncmp(pXLFile, gcstrLANGUAGE, 8))
{
pXLFile += 9;
if (!strncmp(pXLFile, gcstrPCLXL, 5))
{
bBreak = TRUE;
pXLFile = PSkipLine(pXLFile);
}
}
}
break;
case 'J':
if (!strncmp(pXLFile, gcstrJOB, 3))
{
pXLFile = PSkipLine(pXLFile);
}
break;
case 'S':
if (!strncmp(pXLFile, gcstrSET, 3))
{
pXLFile = PSkipLine(pXLFile);
}
break;
default:
return NULL;
}
}
return pXLFile;
}
PBYTE
PSkipWord(
PBYTE pData)
{
while (*pData != SP)
pData++;
while (*pData == SP)
pData++;
return pData;
}
PBYTE
PSkipLine(
PBYTE pData)
{
while (*pData != LF)
pData ++;
pData ++;
return pData;
}
PBYTE
PSkipSpace(
PBYTE pData)
{
while (*pData == SP)
pData ++;
return pData;
}
PBYTE
PSkipWhiteSpace(
PBYTE pData)
{
while (*pData == NU ||
*pData == SP ||
*pData == HT ||
*pData == LF ||
*pData == VT ||
*pData == HT ||
*pData == CR)
{
pData++;
}
return pData;
}
PBYTE
PDecodeXL(
PBYTE pData)
{
SHORT sNumOfData, sI;
DWORD dwI, dwNumOfData;
BYTE ubType;
switch(BinaryTagArray[*pData].TagType)
{
case NotUsed:
printf("NotUsed(0x%x)\n",*pData);
pData++;
break;
case WhiteSpace:
pData = PSkipWhiteSpace(pData);
break;
case Operator:
printf("Operator:%s(0x%x)\n\n",BinaryTagArray[*pData].pubTagName,*pData);
pData++;
break;
case DataType:
ubType = *pData;
printf(" Data:%s(0x%x):",BinaryTagArray[ubType].pubTagName,ubType);
pData++;
sNumOfData = 0;
if (0xc0 <= ubType && ubType <= 0xc5)
{
//
// One value
//
sNumOfData = 1;
}
else if (0xc8 <= ubType && ubType <= 0xcd)
{
//
// Array
//
sNumOfData = 0;
}
else if (0xd0 <= ubType && ubType <= 0xd5)
{
//
// Two values
//
sNumOfData = 2;
}
else if (0xe0 <= ubType && ubType <= 0xe5)
{
//
// Four values
//
sNumOfData = 4;
}
printf("(");
if (sNumOfData)
{
while (sNumOfData-- > 0)
{
switch(ubType%8)
{
case 0:
printf("%d", (BYTE)*pData);
pData++;
break;
case 1:
printf("%d", *(PUSHORT)pData);
pData+=2;
break;
case 2:
printf("%d", *(PULONG)pData);
pData+=4;
break;
case 3:
printf("%d", *(PSHORT)pData);
pData+=2;
break;
case 4:
printf("%d", *(PLONG)pData);
pData+=4;
break;
case 5:
printf("0x%x", *(PDWORD)pData);
pData+=4;
break;
}
if (sNumOfData >= 1)
printf(", ");
}
}
else
{
if (*pData == 0xc0)
{
pData++;
sNumOfData = *pData;
pData ++;
}
else if (*pData == 0xc1)
{
pData++;
sNumOfData = *(PUSHORT)pData;
pData += 2;
}
switch(ubType%8)
{
case 0:
for (sI = 0; sI < sNumOfData; sI ++, pData++)
printf("%c", *pData);
break;
case 1:
for (sI = 0; sI < sNumOfData; sI ++, pData+=2)
printf("%d", *(PUSHORT)pData);
break;
case 2:
for (sI = 0; sI < sNumOfData; sI ++, pData+=4)
printf("%d", *(PULONG)pData);
break;
case 3:
for (sI = 0; sI < sNumOfData; sI ++, pData+=2)
printf("%d", *(PSHORT)pData);
break;
case 4:
for (sI = 0; sI < sNumOfData; sI ++, pData+=4)
printf("%d", *(PLONG)pData);
break;
case 5:
for (sI = 0; sI < sNumOfData; sI ++, pData+=4)
printf("0x%x", *(PDWORD)pData);
break;
}
}
printf(")\n");
break;
case Attribute:
if (*pData == 0xf8)
{
printf(" Attribute(0x%x):%s(%d)\n",*pData, pubAttributeID[*(PBYTE)(pData+1)], *(PBYTE)(pData+1));
pData += 2;
}
else if (*pData == 0xf9)
{
printf(" Attribute(0x%x):%s(%d)\n",*pData, pubAttributeID[*(PDWORD)(pData+1)], *(PWORD)(pData+1));
pData+=2;
}
break;
case EmbedData:
printf(" Embed Data(0x%x)", *pData);
if (*pData == 0xfa)
{
pData++;
dwNumOfData = *(PDWORD)pData;
printf(":Size(0x%x):Hex(",dwNumOfData);
pData +=4;
for (dwI = 0; dwI < dwNumOfData; dwI ++, pData++)
{
printf("%x",*pData);
}
}
else if (*pData == 0xfb)
{
pData++;
sNumOfData = *(PBYTE)pData;
pData++;
printf(":Size(0x%x):Hex(",sNumOfData);
for (sI = 0; sI < sNumOfData; sI ++, pData++)
{
printf("%x",*pData);
}
}
printf(")\n\n");
break;
case Binding:
printf("Binding: ");
if (*pData == 0x27)
printf("ASCII\n");
else if (*pData == 0x28)
printf("binary - high byte first\n");
else if (*pData == 0x29)
printf("binary - low byte first\n");
pData ++;
printf("Comment:");
while (*pData != LF)
{
printf("%c", *pData);
pData++;
}
printf("\n");
break;
case Reserved:
printf("Reserved\n");
pData ++;
break;
}
return pData;
}