3 * Copyright (C) 2002-2004 A.J. van Os; Released under GNU GPL
6 * Deal with the MAC internals of a MS Word file
13 * bGetDocumentText - make a list of the text blocks of a Word document
15 * Return TRUE when succesful, otherwise FALSE
18 bGetDocumentText(FILE *pFile
, const UCHAR
*aucHeader
)
20 text_block_type tTextBlock
;
21 ULONG ulBeginOfText
, ulEndOfText
;
27 fail(aucHeader
== NULL
);
29 DBG_MSG("bGetDocumentText");
31 NO_DBG_PRINT_BLOCK(aucHeader
, 0x20);
33 /* Get the status flags from the header */
34 ucDocStatus
= ucGetByte(0x0a, aucHeader
);
36 bFastSaved
= (ucDocStatus
& BIT(5)) != 0;
37 DBG_MSG_C(bFastSaved
, "This document is Fast Saved");
39 werr(0, "MacWord: fast saved documents are not supported yet");
43 /* Get length information */
44 ulBeginOfText
= ulGetLongBE(0x14, aucHeader
);
45 DBG_HEX(ulBeginOfText
);
46 ulEndOfText
= ulGetLongBE(0x18, aucHeader
);
48 ulTextLen
= ulEndOfText
- ulBeginOfText
;
50 tTextBlock
.ulFileOffset
= ulBeginOfText
;
51 tTextBlock
.ulCharPos
= ulBeginOfText
;
52 tTextBlock
.ulLength
= ulTextLen
;
53 tTextBlock
.bUsesUnicode
= FALSE
;
54 tTextBlock
.usPropMod
= IGNORE_PROPMOD
;
55 if (!bAdd2TextBlockList(&tTextBlock
)) {
56 DBG_HEX(tTextBlock
.ulFileOffset
);
57 DBG_HEX(tTextBlock
.ulCharPos
);
58 DBG_DEC(tTextBlock
.ulLength
);
59 DBG_DEC(tTextBlock
.bUsesUnicode
);
60 DBG_DEC(tTextBlock
.usPropMod
);
64 } /* end of bGetDocumentText */
67 * iInitDocumentMAC - initialize an MAC document
69 * Returns the version of Word that made the document or -1
72 iInitDocumentMAC(FILE *pFile
, long lFilesize
)
81 if (lFilesize
< 256) {
85 /* Read the headerblock */
86 if (!bReadBytes(aucHeader
, 256, 0x00, pFile
)) {
89 /* Get the "magic number" from the header */
90 usIdent
= usGetWord(0x00, aucHeader
);
92 fail(usIdent
!= 0x37fe); /* MacWord 4 and 5 */
93 iWordVersion
= iGetVersionNumber(aucHeader
);
94 if (iWordVersion
!= 4 && iWordVersion
!= 5) {
95 werr(0, "This file is not from ''Mac Word 4 or 5'.");
98 bSuccess
= bGetDocumentText(pFile
, aucHeader
);
100 vGetPropertyInfo(pFile
, NULL
,
102 aucHeader
, iWordVersion
);
103 vSetDefaultTabWidth(pFile
, NULL
,
105 aucHeader
, iWordVersion
);
107 return bSuccess
? iWordVersion
: -1;
108 } /* end of iInitDocumentMAC */