Imported from antiword-0.37.tar.gz.
[antiword.git] / wordmac.c
blobc6a8f26207ab72aea18bb6c06d8ebd18da9a5e23
1 /*
2 * wordmac.c
3 * Copyright (C) 2002-2004 A.J. van Os; Released under GNU GPL
5 * Description:
6 * Deal with the MAC internals of a MS Word file
7 */
9 #include "antiword.h"
13 * bGetDocumentText - make a list of the text blocks of a Word document
15 * Return TRUE when succesful, otherwise FALSE
17 static BOOL
18 bGetDocumentText(FILE *pFile, const UCHAR *aucHeader)
20 text_block_type tTextBlock;
21 ULONG ulBeginOfText, ulEndOfText;
22 ULONG ulTextLen;
23 UCHAR ucDocStatus;
24 BOOL bFastSaved;
26 fail(pFile == NULL);
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);
35 DBG_HEX(ucDocStatus);
36 bFastSaved = (ucDocStatus & BIT(5)) != 0;
37 DBG_MSG_C(bFastSaved, "This document is Fast Saved");
38 if (bFastSaved) {
39 werr(0, "MacWord: fast saved documents are not supported yet");
40 return FALSE;
43 /* Get length information */
44 ulBeginOfText = ulGetLongBE(0x14, aucHeader);
45 DBG_HEX(ulBeginOfText);
46 ulEndOfText = ulGetLongBE(0x18, aucHeader);
47 DBG_HEX(ulEndOfText);
48 ulTextLen = ulEndOfText - ulBeginOfText;
49 DBG_DEC(ulTextLen);
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);
61 return FALSE;
63 return TRUE;
64 } /* end of bGetDocumentText */
67 * iInitDocumentMAC - initialize an MAC document
69 * Returns the version of Word that made the document or -1
71 int
72 iInitDocumentMAC(FILE *pFile, long lFilesize)
74 int iWordVersion;
75 BOOL bSuccess;
76 USHORT usIdent;
77 UCHAR aucHeader[256];
79 fail(pFile == NULL);
81 if (lFilesize < 256) {
82 return -1;
85 /* Read the headerblock */
86 if (!bReadBytes(aucHeader, 256, 0x00, pFile)) {
87 return -1;
89 /* Get the "magic number" from the header */
90 usIdent = usGetWord(0x00, aucHeader);
91 DBG_HEX(usIdent);
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'.");
96 return -1;
98 bSuccess = bGetDocumentText(pFile, aucHeader);
99 if (bSuccess) {
100 vGetPropertyInfo(pFile, NULL,
101 NULL, 0, NULL, 0,
102 aucHeader, iWordVersion);
103 vSetDefaultTabWidth(pFile, NULL,
104 NULL, 0, NULL, 0,
105 aucHeader, iWordVersion);
107 return bSuccess ? iWordVersion : -1;
108 } /* end of iInitDocumentMAC */