Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
/*
2
 * wordmac.c
3
 * Copyright (C) 2002-2004 A.J. van Os; Released under GNU GPL
4
 *
5
 * Description:
6
 * Deal with the MAC internals of a MS Word file
7
 */
8
 
9
#include "antiword.h"
10
 
11
 
12
/*
13
 * bGetDocumentText - make a list of the text blocks of a Word document
14
 *
15
 * Return TRUE when succesful, otherwise FALSE
16
 */
17
static BOOL
18
bGetDocumentText(FILE *pFile, const UCHAR *aucHeader)
19
{
20
	text_block_type	tTextBlock;
21
	ULONG	ulBeginOfText, ulEndOfText;
22
	ULONG	ulTextLen;
23
	UCHAR	ucDocStatus;
24
	BOOL    bFastSaved;
25
 
26
	fail(pFile == NULL);
27
	fail(aucHeader == NULL);
28
 
29
	DBG_MSG("bGetDocumentText");
30
 
31
	NO_DBG_PRINT_BLOCK(aucHeader, 0x20);
32
 
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;
41
	}
42
 
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;
62
	}
63
	return TRUE;
64
} /* end of bGetDocumentText */
65
 
66
/*
67
 * iInitDocumentMAC - initialize an MAC document
68
 *
69
 * Returns the version of Word that made the document or -1
70
 */
71
int
72
iInitDocumentMAC(FILE *pFile, long lFilesize)
73
{
74
	int	iWordVersion;
75
	BOOL	bSuccess;
76
	USHORT	usIdent;
77
	UCHAR	aucHeader[256];
78
 
79
	fail(pFile == NULL);
80
 
81
	if (lFilesize < 256) {
82
		return -1;
83
	}
84
 
85
	/* Read the headerblock */
86
	if (!bReadBytes(aucHeader, 256, 0x00, pFile)) {
87
		return -1;
88
	}
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;
97
	}
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);
106
	}
107
	return bSuccess ? iWordVersion : -1;
108
} /* end of iInitDocumentMAC */