3 * Copyright (C) 2002-2005 A.J. van Os; Released under GNU GPL
6 * Deal with the DOS 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
, long lFilesize
, const UCHAR
*aucHeader
)
20 text_block_type tTextBlock
;
23 UCHAR ucDocStatus
, ucVersion
;
26 fail(lFilesize
< 128);
27 fail(aucHeader
== NULL
);
29 /* Get the status flags from the header */
30 ucDocStatus
= ucGetByte(0x75, aucHeader
);
32 bFastSaved
= (ucDocStatus
& BIT(1)) != 0;
33 DBG_MSG_C(bFastSaved
, "This document is Fast Saved");
34 ucVersion
= ucGetByte(0x74, aucHeader
);
36 DBG_MSG_C(ucVersion
== 0, "Written by Word 4.0 or earlier");
37 DBG_MSG_C(ucVersion
== 3, "Word 5.0 format, but not written by Word");
38 DBG_MSG_C(ucVersion
== 4, "Written by Word 5.x");
40 werr(0, "Word for DOS: autosave documents are not supported");
44 /* Get length information */
45 ulTextLen
= ulGetLong(0x0e, aucHeader
);
49 tTextBlock
.ulFileOffset
= 128;
50 tTextBlock
.ulCharPos
= 128;
51 tTextBlock
.ulLength
= ulTextLen
;
52 tTextBlock
.bUsesUnicode
= FALSE
;
53 tTextBlock
.usPropMod
= IGNORE_PROPMOD
;
54 if (!bAdd2TextBlockList(&tTextBlock
)) {
55 DBG_HEX(tTextBlock
.ulFileOffset
);
56 DBG_HEX(tTextBlock
.ulCharPos
);
57 DBG_DEC(tTextBlock
.ulLength
);
58 DBG_DEC(tTextBlock
.bUsesUnicode
);
59 DBG_DEC(tTextBlock
.usPropMod
);
63 } /* end of bGetDocumentText */
66 * iInitDocumentDOS - initialize an DOS document
68 * Returns the version of Word that made the document or -1
71 iInitDocumentDOS(FILE *pFile
, long lFilesize
)
80 if (lFilesize
< 128) {
84 /* Read the headerblock */
85 if (!bReadBytes(aucHeader
, 128, 0x00, pFile
)) {
88 /* Get the "magic number" from the header */
89 usIdent
= usGetWord(0x00, aucHeader
);
91 fail(usIdent
!= 0xbe31); /* Word for DOS */
92 iWordVersion
= iGetVersionNumber(aucHeader
);
93 if (iWordVersion
!= 0) {
94 werr(0, "This file is not from 'Word for DOS'.");
97 bSuccess
= bGetDocumentText(pFile
, lFilesize
, aucHeader
);
99 vGetPropertyInfo(pFile
, NULL
,
101 aucHeader
, iWordVersion
);
102 vSetDefaultTabWidth(pFile
, NULL
,
104 aucHeader
, iWordVersion
);
105 vGetNotesInfo(pFile
, NULL
,
107 aucHeader
, iWordVersion
);
109 return bSuccess
? iWordVersion
: -1;
110 } /* end of iInitDocumentDOS */