00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "antiword.h"
00010
00011
00012
00013
00014
00015
00016
00017 static BOOL
00018 bGetDocumentText(FILE *pFile, const UCHAR *aucHeader)
00019 {
00020 text_block_type tTextBlock;
00021 ULONG ulBeginOfText, ulEndOfText;
00022 ULONG ulTextLen;
00023 UCHAR ucDocStatus;
00024 BOOL bFastSaved;
00025
00026 fail(pFile == NULL);
00027 fail(aucHeader == NULL);
00028
00029 DBG_MSG("bGetDocumentText");
00030
00031 NO_DBG_PRINT_BLOCK(aucHeader, 0x20);
00032
00033
00034 ucDocStatus = ucGetByte(0x0a, aucHeader);
00035 DBG_HEX(ucDocStatus);
00036 bFastSaved = (ucDocStatus & BIT(5)) != 0;
00037 DBG_MSG_C(bFastSaved, "This document is Fast Saved");
00038 if (bFastSaved) {
00039 werr(0, "MacWord: fast saved documents are not supported yet");
00040 return FALSE;
00041 }
00042
00043
00044 ulBeginOfText = ulGetLongBE(0x14, aucHeader);
00045 DBG_HEX(ulBeginOfText);
00046 ulEndOfText = ulGetLongBE(0x18, aucHeader);
00047 DBG_HEX(ulEndOfText);
00048 ulTextLen = ulEndOfText - ulBeginOfText;
00049 DBG_DEC(ulTextLen);
00050 tTextBlock.ulFileOffset = ulBeginOfText;
00051 tTextBlock.ulCharPos = ulBeginOfText;
00052 tTextBlock.ulLength = ulTextLen;
00053 tTextBlock.bUsesUnicode = FALSE;
00054 tTextBlock.usPropMod = IGNORE_PROPMOD;
00055 if (!bAdd2TextBlockList(&tTextBlock)) {
00056 DBG_HEX(tTextBlock.ulFileOffset);
00057 DBG_HEX(tTextBlock.ulCharPos);
00058 DBG_DEC(tTextBlock.ulLength);
00059 DBG_DEC(tTextBlock.bUsesUnicode);
00060 DBG_DEC(tTextBlock.usPropMod);
00061 return FALSE;
00062 }
00063 return TRUE;
00064 }
00065
00066
00067
00068
00069
00070
00071 int
00072 iInitDocumentMAC(FILE *pFile, long lFilesize)
00073 {
00074 int iWordVersion;
00075 BOOL bSuccess;
00076 USHORT usIdent;
00077 UCHAR aucHeader[256];
00078
00079 fail(pFile == NULL);
00080
00081 if (lFilesize < 256) {
00082 return -1;
00083 }
00084
00085
00086 if (!bReadBytes(aucHeader, 256, 0x00, pFile)) {
00087 return -1;
00088 }
00089
00090 usIdent = usGetWord(0x00, aucHeader);
00091 DBG_HEX(usIdent);
00092 fail(usIdent != 0x37fe);
00093 iWordVersion = iGetVersionNumber(aucHeader);
00094 if (iWordVersion != 4 && iWordVersion != 5) {
00095 werr(0, "This file is not from ''Mac Word 4 or 5'.");
00096 return -1;
00097 }
00098 bSuccess = bGetDocumentText(pFile, aucHeader);
00099 if (bSuccess) {
00100 vGetPropertyInfo(pFile, NULL,
00101 NULL, 0, NULL, 0,
00102 aucHeader, iWordVersion);
00103 vSetDefaultTabWidth(pFile, NULL,
00104 NULL, 0, NULL, 0,
00105 aucHeader, iWordVersion);
00106 }
00107 return bSuccess ? iWordVersion : -1;
00108 }