From eb8d737eea2866bfb45e50423a1fd6c51454c2f6 Mon Sep 17 00:00:00 2001 From: simon987 Date: Wed, 16 Dec 2020 19:56:38 -0500 Subject: [PATCH] more bounds checking, error handling --- CMakeLists.txt | 5 +- src/antiword.h | 8 +- src/asc85enc.c | 4 +- src/depot.c | 4 +- src/draw.c | 1047 ------------------------------------ src/draw.h | 46 -- src/findtext.c | 7 +- src/icons.c | 96 ---- src/main_ros.c | 520 ------------------ src/main_u.c | 321 ----------- src/misc.c | 11 +- src/prop6.c | 2 +- src/prop8.c | 3 +- src/properties.c | 6 +- src/propmod.c | 3 + src/sist2_hotfix.c | 11 + src/startup.c | 145 ----- src/stylesheet.c | 23 +- src/summary.c | 13 +- src/unix.c | 4 +- src/wordole.c | 1286 ++++++++++++++++++++++---------------------- src/xml.c | 7 +- 22 files changed, 719 insertions(+), 2853 deletions(-) delete mode 100644 src/draw.c delete mode 100644 src/draw.h delete mode 100644 src/icons.c delete mode 100644 src/main_ros.c delete mode 100644 src/main_u.c create mode 100644 src/sist2_hotfix.c delete mode 100644 src/startup.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 6d9e002..e0c666d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ add_library(antiword src/prop2.c src/prop6.c src/prop8.c src/properties.c src/propmod.c src/rowlist.c src/sectlist.c src/stylelist.c src/stylesheet.c src/summary.c src/tabstop.c src/text.c src/unix.c src/utf8.c src/word2text.c src/worddos.c src/wordlib.c - src/wordmac.c src/wordole.c src/wordwin.c src/xmalloc.c src/xml.c + src/wordmac.c src/wordole.c src/wordwin.c src/xmalloc.c src/xml.c src/sist2_hotfix.c ) target_compile_options( @@ -22,6 +22,7 @@ target_compile_options( PRIVATE -Wall -pedantic - -O2 + -Ofast + -g -DNDEBUG ) diff --git a/src/antiword.h b/src/antiword.h index 5167d02..fcb21ed 100644 --- a/src/antiword.h +++ b/src/antiword.h @@ -249,6 +249,12 @@ #define MAPPING_FILE_UTF_8 "UTF-8.txt" #endif /* __riscos */ +/* sist2 hotfixes */ + +#define BUF_AUC 1 +extern void setBufferSize(ULONG size); +extern BOOL isOutOfBounds(ULONG offset); + /* Prototypes */ /* asc85enc.c */ @@ -637,7 +643,7 @@ extern USHORT usStc2istd(UCHAR); extern void vGet2Stylesheet(FILE *, int, const UCHAR *); extern void vGet6Stylesheet(FILE *, ULONG, const ULONG *, size_t, const UCHAR *); -extern void vGet8Stylesheet(FILE *, const pps_info_type *, +extern BOOL vGet8Stylesheet(FILE *, const pps_info_type *, const ULONG *, size_t, const ULONG *, size_t, const UCHAR *); extern void vFillStyleFromStylesheet(USHORT, style_block_type *); diff --git a/src/asc85enc.c b/src/asc85enc.c index 3f23e4a..bc53323 100644 --- a/src/asc85enc.c +++ b/src/asc85enc.c @@ -61,8 +61,8 @@ vOutputByte(ULONG ulChar, FILE *pOutFile) void vASCII85EncodeByte(FILE *pOutFile, int iByte) { - static ULONG ulBuffer[4] = { 0, 0, 0, 0 }; - static int iInBuffer = 0; + static __thread ULONG ulBuffer[4] = { 0, 0, 0, 0 }; + static __thread int iInBuffer = 0; ULONG ulValue, ulTmp; int iIndex; diff --git a/src/depot.c b/src/depot.c index 39b5af6..762b69b 100644 --- a/src/depot.c +++ b/src/depot.c @@ -51,7 +51,7 @@ bCreateSmallBlockList(ULONG ulStartblock, const ULONG *aulBBD, size_t tBBDLen) if (ulTmp >= (ULONG)tBBDLen) { DBG_DEC(ulTmp); DBG_DEC(tBBDLen); - werr(1, "The Big Block Depot is damaged"); + return FALSE; } } DBG_DEC(tSmallBlockListLen); @@ -72,7 +72,7 @@ bCreateSmallBlockList(ULONG ulStartblock, const ULONG *aulBBD, size_t tBBDLen) if (ulTmp >= (ULONG)tBBDLen) { DBG_DEC(ulTmp); DBG_DEC(tBBDLen); - werr(1, "The Big Block Depot is damaged"); + return FALSE; } aulSmallBlockList[iIndex] = ulTmp; NO_DBG_DEC(aulSmallBlockList[iIndex]); diff --git a/src/draw.c b/src/draw.c deleted file mode 100644 index f833d75..0000000 --- a/src/draw.c +++ /dev/null @@ -1,1047 +0,0 @@ -/* - * draw.c - * Copyright (C) 1998-2005 A.J. van Os; Released under GPL - * - * Description: - * Functions to deal with the Draw format - */ - -#include -#include -#include -#include "DeskLib:KeyCodes.h" -#include "DeskLib:Error.h" -#include "DeskLib:Menu.h" -#include "DeskLib:Template.h" -#include "DeskLib:Window.h" -#include "DeskLib:EventMsg.h" -#include "flexlib:flex.h" -#include "drawfile.h" -#include "antiword.h" - -/* The work area must be a little bit larger than the diagram */ -#define WORKAREA_EXTENSION 5 -/* Diagram memory */ -#define INITIAL_SIZE 32768 /* 32k */ -#define EXTENSION_SIZE 4096 /* 4k */ -/* Main window title */ -#define WINDOW_TITLE_LEN 28 -#define FILENAME_TITLE_LEN (WINDOW_TITLE_LEN - 10) - - -#if !defined(__GNUC__) -int -flex_alloc(flex_ptr anchor, int n) -{ - void *pvTmp; - - TRACE_MSG("flex_alloc"); - - if (anchor == NULL || n < 0) { - return 0; - } - if (n == 0) { - n = 1; - } - pvTmp = malloc(n); - if (pvTmp == NULL) { - return 0; - } - *anchor = pvTmp; - return 1; -} /* end of flex_alloc */ - -void -flex_free(flex_ptr anchor) -{ - TRACE_MSG("flex_free"); - - if (anchor == NULL || *anchor == NULL) { - return; - } - free(*anchor); - *anchor = NULL; -} /* end of flex_free */ - -int -flex_extend(flex_ptr anchor, int newsize) -{ - void *pvTmp; - - TRACE_MSG("flex_extend"); - - if (anchor == NULL || newsize < 0) { - return 0; - } - if (newsize == 0) { - newsize = 1; - } - pvTmp = realloc(*anchor, newsize); - if (pvTmp == NULL) { - return 0; - } - *anchor = pvTmp; - return 1; -} /* end of flex_extend */ -#endif /* !__GNUC__ */ - -/* - * vCreateMainWindow - create the Main window - * - * remark: does not return if the Main window can't be created - */ -static window_handle -tCreateMainWindow(void) -{ - window_handle tMainWindow; - - TRACE_MSG("tCreateMainWindow"); - - tMainWindow = Window_Create("MainWindow", template_TITLEMIN); - if (tMainWindow == 0) { - werr(1, "I can't find the 'MainWindow' template"); - } - return tMainWindow; -} /* end of tCreateMainWindow */ - -/* - * vCreateScaleWindow - create the Scale view window - * - * remark: does not return if the Scale view window can't be created - */ -static window_handle -tCreateScaleWindow(void) -{ - window_handle tScaleWindow; - - TRACE_MSG("tCreateScaleWindow"); - - tScaleWindow = Window_Create("ScaleView", template_TITLEMIN); - if (tScaleWindow == 0) { - werr(1, "I can't find the 'ScaleView' template"); - } - return tScaleWindow; -} /* end of tCreateScaleWindow */ - -/* - * pCreateDiagram - create and initialize a diagram - * - * remark: does not return if the diagram can't be created - */ -diagram_type * -pCreateDiagram(const char *szTask, const char *szFilename) -{ - diagram_type *pDiag; - options_type tOptions; - window_handle tMainWindow, tScaleWindow; - wimp_box tBox; - - TRACE_MSG("pCreateDiagram"); - - fail(szTask == NULL || szTask[0] == '\0'); - - /* Create the main window */ - tMainWindow = tCreateMainWindow(); - - /* Create the scale view window */ - tScaleWindow = tCreateScaleWindow(); - - /* Get the necessary memory */ - pDiag = xmalloc(sizeof(diagram_type)); - if (flex_alloc((flex_ptr)&pDiag->tInfo.data, INITIAL_SIZE) != 1) { - werr(1, "Memory allocation failed, unable to continue"); - } - - /* Initialize the diagram */ - vGetOptions(&tOptions); - pDiag->tMainWindow = tMainWindow; - pDiag->tScaleWindow = tScaleWindow; - pDiag->iScaleFactorCurr = tOptions.iScaleFactor; - pDiag->iScaleFactorTemp = tOptions.iScaleFactor; - pDiag->tMemorySize = INITIAL_SIZE; - tBox.min.x = 0; - tBox.min.y = -(Drawfile_ScreenToDraw(32 + 3) * 8 + 1); - tBox.max.x = Drawfile_ScreenToDraw(16) * MIN_SCREEN_WIDTH + 1; - tBox.max.y = 0; - Error_CheckFatal(Drawfile_CreateDiagram(&pDiag->tInfo, - pDiag->tMemorySize, szTask, tBox)); - DBG_DEC(pDiag->tInfo.length); - pDiag->lXleft = 0; - pDiag->lYtop = 0; - strncpy(pDiag->szFilename, - szBasename(szFilename), sizeof(pDiag->szFilename) - 1); - pDiag->szFilename[sizeof(pDiag->szFilename) - 1] = '\0'; - /* Return success */ - return pDiag; -} /* end of pCreateDiagram */ - -/* - * bDestroyDiagram - remove a diagram by freeing the memory it uses - */ -BOOL -bDestroyDiagram(event_pollblock *pEvent, void *pvReference) -{ - diagram_type *pDiag; - window_handle tWindow; - - TRACE_MSG("bDestroyDiagram"); - - fail(pEvent == NULL); - fail(pvReference == NULL); - - if (pEvent == NULL || pvReference == NULL) { - return FALSE; - } - - pDiag = (diagram_type *)pvReference; - - switch (pEvent->type) { - case event_CLOSE: - tWindow = pEvent->data.openblock.window; - break; - case event_KEY: - tWindow = pEvent->data.key.caret.window; - break; - default: - DBG_DEC(pEvent->type); - return FALSE; - } - if (tWindow != pDiag->tMainWindow) { - return FALSE; - } - - /* Delete the main window */ - Window_Delete(pDiag->tMainWindow); - pDiag->tMainWindow = 0; - - /* Delete the scale window */ - Window_Delete(pDiag->tScaleWindow); - pDiag->tScaleWindow = 0; - -#if defined(__GNUC__) - /* - * Remove all references to the diagram that will be free-ed - * by undoing the EventMsg_Claim's from within the Menu_Warn's - */ - while (EventMsg_ReleaseSpecific(message_MENUWARNING, window_ANY, - bSaveTextfile, pDiag)) - ; /* EMPTY */ - while (EventMsg_ReleaseSpecific(message_MENUWARNING, window_ANY, - bSaveDrawfile, pDiag)) - ; /* EMPTY */ - while (EventMsg_ReleaseSpecific(message_MENUWARNING, window_ANY, - bScaleOpenAction, pDiag)) - ; /* EMPTY */ -#endif /* __GNUC__ */ - - /* Free the memory */ - if (pDiag->tInfo.data != NULL && pDiag->tMemorySize != 0) { - flex_free((flex_ptr)&pDiag->tInfo.data); - } - /* Just to be on the save side */ - pDiag->tInfo.data = NULL; - pDiag->tInfo.length = 0; - pDiag->tMemorySize = 0; - - /* Destroy the diagram itself */ - pDiag = xfree(pDiag); - return TRUE; -} /* end of bDestroyDiagram */ - -/* - * vExtendDiagramSize - make sure the diagram is big enough - */ -static void -vExtendDiagramSize(diagram_type *pDiag, size_t tSize) -{ - TRACE_MSG("vExtendDiagramSize"); - - fail(pDiag == NULL || tSize % 4 != 0); - - while (pDiag->tInfo.length + tSize > pDiag->tMemorySize) { - if (flex_extend((flex_ptr)&pDiag->tInfo.data, - pDiag->tMemorySize + EXTENSION_SIZE) != 1) { - werr(1, "Memory extend failed, unable to continue"); - } - pDiag->tMemorySize += EXTENSION_SIZE; - NO_DBG_DEC(pDiag->tMemorySize); - } - TRACE_MSG("end of vExtendDiagramSize"); -} /* end of vExtendDiagramSize */ - -/* - * vPrologue2 - prologue part 2; add a font list to a diagram - */ -void -vPrologue2(diagram_type *pDiag, int iWordVersion) -{ - drawfile_object *pNew; - const font_table_type *pTmp; - char *pcTmp; - size_t tRealSize, tSize; - int iCount; - - TRACE_MSG("vPrologue2"); - - fail(pDiag == NULL); - - if (tGetFontTableLength() == 0) { - return; - } - tRealSize = offsetof(drawfile_object, data); - pTmp = NULL; - while ((pTmp = pGetNextFontTableRecord(pTmp)) != NULL) { - tRealSize += 2 + strlen(pTmp->szOurFontname); - } - DBG_DEC(tRealSize); - tSize = ROUND4(tRealSize); - vExtendDiagramSize(pDiag, tSize); - pNew = xmalloc(tSize); - memset(pNew, 0, tSize); - pNew->type = drawfile_TYPE_FONT_TABLE; - pNew->size = tSize; - pcTmp = (char *)&pNew->data.font_table.font_def[0].font_ref; - iCount = 0; - pTmp = NULL; - while ((pTmp = pGetNextFontTableRecord(pTmp)) != NULL) { - *pcTmp = ++iCount; - pcTmp++; - strcpy(pcTmp, pTmp->szOurFontname); - pcTmp += 1 + strlen(pTmp->szOurFontname); - } - Error_CheckFatal(Drawfile_AppendObject(&pDiag->tInfo, - pDiag->tMemorySize, pNew, TRUE)); - pNew = xfree(pNew); -} /* end of vPrologue2 */ - -/* - * vSubstring2Diagram - put a sub string into a diagram - */ -void -vSubstring2Diagram(diagram_type *pDiag, - char *szString, size_t tStringLength, long lStringWidth, - UCHAR ucFontColor, USHORT usFontstyle, drawfile_fontref tFontRef, - USHORT usFontSize, USHORT usMaxFontSize) -{ - drawfile_object *pNew; - long lSizeX, lSizeY, lOffset, l20, lYMove; - size_t tRealSize, tSize; - - TRACE_MSG("vSubstring2Diagram"); - - fail(pDiag == NULL || szString == NULL); - fail(pDiag->lXleft < 0); - fail(tStringLength != strlen(szString)); - fail(usFontSize < MIN_FONT_SIZE || usFontSize > MAX_FONT_SIZE); - fail(usMaxFontSize < MIN_FONT_SIZE || usMaxFontSize > MAX_FONT_SIZE); - fail(usFontSize > usMaxFontSize); - - if (szString[0] == '\0' || tStringLength == 0) { - return; - } - - if (tFontRef == 0) { - lOffset = Drawfile_ScreenToDraw(2); - l20 = Drawfile_ScreenToDraw(32 + 3); - lSizeX = Drawfile_ScreenToDraw(16); - lSizeY = Drawfile_ScreenToDraw(32); - } else { - lOffset = lToBaseLine(usMaxFontSize); - l20 = lWord2DrawUnits20(usMaxFontSize); - lSizeX = lWord2DrawUnits00(usFontSize); - lSizeY = lWord2DrawUnits00(usFontSize); - } - - lYMove = 0; - - /* Up for superscript */ - if (bIsSuperscript(usFontstyle)) { - lYMove = lMilliPoints2DrawUnits((((long)usFontSize + 1) / 2) * 375); - } - /* Down for subscript */ - if (bIsSubscript(usFontstyle)) { - lYMove = -lMilliPoints2DrawUnits((long)usFontSize * 125); - } - - tRealSize = offsetof(drawfile_object, data); - tRealSize += sizeof(drawfile_text) + tStringLength; - tSize = ROUND4(tRealSize); - vExtendDiagramSize(pDiag, tSize); - pNew = xmalloc(tSize); - memset(pNew, 0, tSize); - pNew->type = drawfile_TYPE_TEXT; - pNew->size = tSize; - pNew->data.text.bbox.min.x = (int)pDiag->lXleft; - pNew->data.text.bbox.min.y = (int)(pDiag->lYtop + lYMove); - pNew->data.text.bbox.max.x = (int)(pDiag->lXleft + lStringWidth); - pNew->data.text.bbox.max.y = (int)(pDiag->lYtop + l20 + lYMove); - pNew->data.text.fill.value = (int)ulColor2Color(ucFontColor); - pNew->data.text.bg_hint.value = 0xffffff00; /* White */ - pNew->data.text.style.font_ref = tFontRef; - pNew->data.text.style.reserved[0] = 0; - pNew->data.text.style.reserved[1] = 0; - pNew->data.text.style.reserved[2] = 0; - pNew->data.text.xsize = (int)lSizeX; - pNew->data.text.ysize = (int)lSizeY; - pNew->data.text.base.x = (int)pDiag->lXleft; - pNew->data.text.base.y = (int)(pDiag->lYtop + lOffset + lYMove); - strncpy(pNew->data.text.text, szString, tStringLength); - pNew->data.text.text[tStringLength] = '\0'; - Error_CheckFatal(Drawfile_AppendObject(&pDiag->tInfo, - pDiag->tMemorySize, pNew, TRUE)); - pNew = xfree(pNew); - /*draw_translateText(&pDiag->tInfo);*/ - pDiag->lXleft += lStringWidth; - TRACE_MSG("leaving vSubstring2Diagram"); -} /* end of vSubstring2Diagram */ - -/* - * vImage2Diagram - put an image into a diagram - */ -void -vImage2Diagram(diagram_type *pDiag, const imagedata_type *pImg, - UCHAR *pucImage, size_t tImageSize) -{ - drawfile_object *pNew; - long lWidth, lHeight; - size_t tRealSize, tSize; - - TRACE_MSG("vImage2Diagram"); - - fail(pDiag == NULL); - fail(pImg == NULL); - fail(pDiag->lXleft < 0); - fail(pImg->eImageType != imagetype_is_dib && - pImg->eImageType != imagetype_is_jpeg); - - DBG_DEC_C(pDiag->lXleft != 0, pDiag->lXleft); - - lWidth = lPoints2DrawUnits(pImg->iHorSizeScaled); - lHeight = lPoints2DrawUnits(pImg->iVerSizeScaled); - DBG_DEC(lWidth); - DBG_DEC(lHeight); - - pDiag->lYtop -= lHeight; - - tRealSize = offsetof(drawfile_object, data); - switch (pImg->eImageType) { - case imagetype_is_dib: - tRealSize += sizeof(drawfile_sprite) + tImageSize; - tSize = ROUND4(tRealSize); - vExtendDiagramSize(pDiag, tSize); - pNew = xmalloc(tSize); - memset(pNew, 0, tSize); - pNew->type = drawfile_TYPE_SPRITE; - pNew->size = tSize; - pNew->data.sprite.bbox.min.x = (int)pDiag->lXleft; - pNew->data.sprite.bbox.min.y = (int)pDiag->lYtop; - pNew->data.sprite.bbox.max.x = (int)(pDiag->lXleft + lWidth); - pNew->data.sprite.bbox.max.y = (int)(pDiag->lYtop + lHeight); - memcpy(&pNew->data.sprite.header, pucImage, tImageSize); - break; - case imagetype_is_jpeg: -#if defined(DEBUG) - (void)bGetJpegInfo(pucImage, tImageSize); -#endif /* DEBUG */ - tRealSize += sizeof(drawfile_jpeg) + tImageSize; - tSize = ROUND4(tRealSize); - vExtendDiagramSize(pDiag, tSize); - pNew = xmalloc(tSize); - memset(pNew, 0, tSize); - pNew->type = drawfile_TYPE_JPEG; - pNew->size = tSize; - pNew->data.jpeg.bbox.min.x = (int)pDiag->lXleft; - pNew->data.jpeg.bbox.min.y = (int)pDiag->lYtop; - pNew->data.jpeg.bbox.max.x = (int)(pDiag->lXleft + lWidth); - pNew->data.jpeg.bbox.max.y = (int)(pDiag->lYtop + lHeight); - pNew->data.jpeg.width = (int)lWidth; - pNew->data.jpeg.height = (int)lHeight; - pNew->data.jpeg.xdpi = 90; - pNew->data.jpeg.ydpi = 90; - pNew->data.jpeg.trfm.entries[0][0] = 0x10000; - pNew->data.jpeg.trfm.entries[0][1] = 0; - pNew->data.jpeg.trfm.entries[1][0] = 0; - pNew->data.jpeg.trfm.entries[1][1] = 0x10000; - pNew->data.jpeg.trfm.entries[2][0] = (int)pDiag->lXleft; - pNew->data.jpeg.trfm.entries[2][1] = (int)pDiag->lYtop; - pNew->data.jpeg.len = tImageSize; - memcpy(pNew->data.jpeg.data, pucImage, tImageSize); - break; - default: - DBG_DEC(pImg->eImageType); - pNew = NULL; - break; - } - - Error_CheckFatal(Drawfile_AppendObject(&pDiag->tInfo, - pDiag->tMemorySize, pNew, TRUE)); - pNew = xfree(pNew); - pDiag->lXleft = 0; -} /* end of vImage2Diagram */ - -/* - * bAddDummyImage - add a dummy image - * - * return TRUE when successful, otherwise FALSE - */ -BOOL -bAddDummyImage(diagram_type *pDiag, const imagedata_type *pImg) -{ - drawfile_object *pNew; - int *piTmp; - long lWidth, lHeight; - size_t tRealSize, tSize; - - TRACE_MSG("bAddDummyImage"); - - fail(pDiag == NULL); - fail(pImg == NULL); - fail(pDiag->lXleft < 0); - - if (pImg->iVerSizeScaled <= 0 || pImg->iHorSizeScaled <= 0) { - return FALSE; - } - - DBG_DEC_C(pDiag->lXleft != 0, pDiag->lXleft); - - lWidth = lPoints2DrawUnits(pImg->iHorSizeScaled); - lHeight = lPoints2DrawUnits(pImg->iVerSizeScaled); - - pDiag->lYtop -= lHeight; - - tRealSize = offsetof(drawfile_object, data); - tRealSize += sizeof(drawfile_path) + (14 - 1) * sizeof(int); - tSize = ROUND4(tRealSize); - vExtendDiagramSize(pDiag, tSize); - pNew = xmalloc(tSize); - memset(pNew, 0, tSize); - pNew->type = drawfile_TYPE_PATH; - pNew->size = tSize; - pNew->data.path.bbox.min.x = (int)pDiag->lXleft; - pNew->data.path.bbox.min.y = (int)pDiag->lYtop; - pNew->data.path.bbox.max.x = (int)(pDiag->lXleft + lWidth); - pNew->data.path.bbox.max.y = (int)(pDiag->lYtop + lHeight); - pNew->data.path.fill.value = -1; - pNew->data.path.outline.value = 0x4d4d4d00; /* Gray 70 percent */ - pNew->data.path.width = (int)lMilliPoints2DrawUnits(500); - pNew->data.path.style.flags = 0; - pNew->data.path.style.reserved = 0; - pNew->data.path.style.cap_width = 0; - pNew->data.path.style.cap_length = 0; - piTmp = pNew->data.path.path; - *piTmp++ = drawfile_PATH_MOVE_TO; - *piTmp++ = pNew->data.path.bbox.min.x; - *piTmp++ = pNew->data.path.bbox.min.y; - *piTmp++ = drawfile_PATH_LINE_TO; - *piTmp++ = pNew->data.path.bbox.min.x; - *piTmp++ = pNew->data.path.bbox.max.y; - *piTmp++ = drawfile_PATH_LINE_TO; - *piTmp++ = pNew->data.path.bbox.max.x; - *piTmp++ = pNew->data.path.bbox.max.y; - *piTmp++ = drawfile_PATH_LINE_TO; - *piTmp++ = pNew->data.path.bbox.max.x; - *piTmp++ = pNew->data.path.bbox.min.y; - *piTmp++ = drawfile_PATH_CLOSE_LINE; - *piTmp++ = drawfile_PATH_END_PATH; - - Error_CheckFatal(Drawfile_AppendObject(&pDiag->tInfo, - pDiag->tMemorySize, pNew, TRUE)); - pNew = xfree(pNew); - pDiag->lXleft = 0; - return TRUE; -} /* end of bAddDummyImage */ - -/* - * vMove2NextLine - move to the next line - */ -void -vMove2NextLine(diagram_type *pDiag, drawfile_fontref tFontRef, - USHORT usFontSize) -{ - long l20; - - TRACE_MSG("vMove2NextLine"); - - fail(pDiag == NULL); - fail(usFontSize < MIN_FONT_SIZE || usFontSize > MAX_FONT_SIZE); - - if (tFontRef == 0) { - l20 = Drawfile_ScreenToDraw(32 + 3); - } else { - l20 = lWord2DrawUnits20(usFontSize); - } - pDiag->lYtop -= l20; -} /* end of vMove2NextLine */ - -/* - * Create an start of paragraph (Phase 1) - */ -void -vStartOfParagraph1(diagram_type *pDiag, long lBeforeIndentation) -{ - TRACE_MSG("vStartOfParagraph1"); - - fail(pDiag == NULL); - fail(lBeforeIndentation < 0); - - pDiag->lXleft = 0; - pDiag->lYtop -= lMilliPoints2DrawUnits(lBeforeIndentation); -} /* end of vStartOfParagraph1 */ - -/* - * Create an start of paragraph (Phase 2) - * DUMMY function - */ -void -vStartOfParagraph2(diagram_type *pDiag) -{ - TRACE_MSG("vStartOfParagraph2"); -} /* end of vStartOfParagraph2 */ - -/* - * Create an end of paragraph - */ -void -vEndOfParagraph(diagram_type *pDiag, - drawfile_fontref tFontRef, USHORT usFontSize, long lAfterIndentation) -{ - TRACE_MSG("vEndOfParagraph"); - - fail(pDiag == NULL); - fail(usFontSize < MIN_FONT_SIZE || usFontSize > MAX_FONT_SIZE); - fail(lAfterIndentation < 0); - - pDiag->lXleft = 0; - pDiag->lYtop -= lMilliPoints2DrawUnits(lAfterIndentation); -} /* end of vEndOfParagraph */ - -/* - * Create an end of page - */ -void -vEndOfPage(diagram_type *pDiag, long lAfterIndentation, BOOL bNewSection) -{ - TRACE_MSG("vEndOfPage"); - - fail(pDiag == NULL); - fail(lAfterIndentation < 0); - - pDiag->lXleft = 0; - pDiag->lYtop -= lMilliPoints2DrawUnits(lAfterIndentation); -} /* end of vEndOfPage */ - -/* - * vSetHeaders - set the headers - * DUMMY function - */ -void -vSetHeaders(diagram_type *pDiag, USHORT usIstd) -{ - TRACE_MSG("vSetHeaders"); -} /* end of vSetHeaders */ - -/* - * Create a start of list - * DUMMY function - */ -void -vStartOfList(diagram_type *pDiag, UCHAR ucNFC, BOOL bIsEndOfTable) -{ - TRACE_MSG("vStartOfList"); -} /* end of vStartOfList */ - -/* - * Create an end of list - * DUMMY function - */ -void -vEndOfList(diagram_type *pDiag) -{ - TRACE_MSG("vEndOfList"); -} /* end of vEndOfList */ - -/* - * Create a start of a list item - * DUMMY function - */ -void -vStartOfListItem(diagram_type *pDiag, BOOL bNoMarks) -{ - TRACE_MSG("vStartOfListItem"); -} /* end of vStartOfListItem */ - -/* - * Create an end of a table - * DUMMY function - */ -void -vEndOfTable(diagram_type *pDiag) -{ - TRACE_MSG("vEndOfTable"); -} /* end of vEndTable */ - -/* - * Add a table row - * DUMMY function - * - * Returns TRUE when conversion type is XML - */ -BOOL -bAddTableRow(diagram_type *pDiag, char **aszColTxt, - int iNbrOfColumns, const short *asColumnWidth, UCHAR ucBorderInfo) -{ - TRACE_MSG("bAddTableRow"); - - return FALSE; -} /* end of bAddTableRow */ - -/* - * vForceRedraw - force a redraw of the main window - */ -static void -vForceRedraw(diagram_type *pDiag) -{ - window_state tWindowState; - window_redrawblock tRedraw; - int x0, y0, x1, y1; - - TRACE_MSG("vForceRedraw"); - - fail(pDiag == NULL); - - DBG_DEC(pDiag->iScaleFactorCurr); - - /* Read the size of the current diagram */ - Drawfile_QueryBox(&pDiag->tInfo, &tRedraw.rect, TRUE); - /* Adjust the size of the work area */ - x0 = tRedraw.rect.min.x * pDiag->iScaleFactorCurr / 100 - 1; - y0 = tRedraw.rect.min.y * pDiag->iScaleFactorCurr / 100 - 1; - x1 = tRedraw.rect.max.x * pDiag->iScaleFactorCurr / 100 + 1; - y1 = tRedraw.rect.max.y * pDiag->iScaleFactorCurr / 100 + 1; - /* Work area extension */ - x0 -= WORKAREA_EXTENSION; - y0 -= WORKAREA_EXTENSION; - x1 += WORKAREA_EXTENSION; - y1 += WORKAREA_EXTENSION; - Window_SetExtent(pDiag->tMainWindow, x0, y0, x1, y1); - /* Widen the box slightly to be sure all the edges are drawn */ - x0 -= 5; - y0 -= 5; - x1 += 5; - y1 += 5; - /* Force the redraw */ - Window_ForceRedraw(pDiag->tMainWindow, x0, y0, x1, y1); - /* Reopen the window to show the correct size */ - Error_CheckFatal(Wimp_GetWindowState(pDiag->tMainWindow, &tWindowState)); - tWindowState.openblock.behind = -1; - Error_CheckFatal(Wimp_OpenWindow(&tWindowState.openblock)); -} /* end of vForceRedraw */ - -/* - * vShowDiagram - put the diagram on the screen - */ -void -vShowDiagram(diagram_type *pDiag) -{ - wimp_box tRect; - int x0, y0, x1, y1; - - TRACE_MSG("vShowDiagram"); - - fail(pDiag == NULL); - - Window_Show(pDiag->tMainWindow, open_NEARLAST); - Drawfile_QueryBox(&pDiag->tInfo, &tRect, TRUE); - /* Work area extension */ - x0 = tRect.min.x - WORKAREA_EXTENSION; - y0 = tRect.min.y - WORKAREA_EXTENSION; - x1 = tRect.max.x + WORKAREA_EXTENSION; - y1 = tRect.max.y + WORKAREA_EXTENSION; - Window_SetExtent(pDiag->tMainWindow, x0, y0, x1, y1); - vForceRedraw(pDiag); -} /* end of vShowDiagram */ - -/* - * vMainButtonClick - handle mouse buttons clicks for the main screen - */ -void -vMainButtonClick(mouse_block *pMouse) -{ - caret_block tCaret; - window_state ws; - - TRACE_MSG("vMainButtonClick"); - - fail(pMouse == NULL); - - DBG_DEC(pMouse->button.data.select); - DBG_DEC(pMouse->button.data.adjust); - DBG_DEC(pMouse->window); - DBG_DEC(pMouse->icon); - - if (pMouse->window >= 0 && - pMouse->icon == -1 && - (pMouse->button.data.select || pMouse->button.data.adjust)) { - /* Get the input focus */ - Error_CheckFatal(Wimp_GetWindowState(pMouse->window, &ws)); - tCaret.window = pMouse->window; - tCaret.icon = -1; - tCaret.offset.x = pMouse->pos.x - ws.openblock.screenrect.min.x; - tCaret.offset.y = pMouse->pos.y - ws.openblock.screenrect.max.y; - tCaret.height = (int)BIT(25); - tCaret.index = 0; - Error_CheckFatal(Wimp_SetCaretPosition(&tCaret)); - } -} /* end of vMainButtonClick */ - -/* - * bMainKeyPressed - handle pressed keys for the main window - */ -BOOL -bMainKeyPressed(event_pollblock *pEvent, void *pvReference) -{ - diagram_type *pDiag; - - TRACE_MSG("bMainKeyPressed"); - - fail(pEvent == NULL); - fail(pEvent->type != event_KEY); - fail(pvReference == NULL); - - pDiag = (diagram_type *)pvReference; - - fail(pEvent->data.key.caret.window != pDiag->tMainWindow); - - - switch (pEvent->data.key.code) { - case keycode_CTRL_F2: /* Ctrl F2 */ - bDestroyDiagram(pEvent, pvReference); - break; - case keycode_F3: /* F3 */ - bSaveDrawfile(pEvent, pvReference); - break; - case keycode_SHIFT_F3: /* Shift F3 */ - bSaveTextfile(pEvent, pvReference); - break; - default: - DBG_DEC(pEvent->data.key.code); - Error_CheckFatal(Wimp_ProcessKey(pEvent->data.key.code)); - } - return TRUE; -} /* end of bMainKeyPressed */ - -/* - * bRedrawMainWindow - redraw the main window - */ -BOOL -bRedrawMainWindow(event_pollblock *pEvent, void *pvReference) -{ - window_redrawblock tBlock; - diagram_type *pDiag; - drawfile_info *pInfo; - double dScaleFactor; - BOOL bMore; - - TRACE_MSG("bRedrawMainWindow"); - - fail(pEvent == NULL); - fail(pEvent->type != event_REDRAW); - fail(pvReference == NULL); - - pDiag = (diagram_type *)pvReference; - - fail(pDiag->tMainWindow != pEvent->data.openblock.window); - fail(pDiag->iScaleFactorCurr < MIN_SCALE_FACTOR); - fail(pDiag->iScaleFactorCurr > MAX_SCALE_FACTOR); - - dScaleFactor = (double)pDiag->iScaleFactorCurr / 100.0; - pInfo = &pDiag->tInfo; - - tBlock.window = pEvent->data.openblock.window; - Error_CheckFatal(Wimp_RedrawWindow(&tBlock, &bMore)); - - /* If there is no real diagram just go thru the motions */ - while (bMore) { - if (pInfo->data != NULL && pInfo->length != 0) { - Error_CheckFatal(Drawfile_RenderDiagram(pInfo, - &tBlock, dScaleFactor)); - } - Error_CheckFatal(Wimp_GetRectangle(&tBlock, &bMore)); - } - return TRUE; -} /* end of bRedrawMainWindow */ - -/* - * bScaleOpenAction - action to be taken when the Scale view window opens - */ -BOOL -bScaleOpenAction(event_pollblock *pEvent, void *pvReference) -{ - window_state tWindowState; - diagram_type *pDiag; - - TRACE_MSG("bScaleOpenAction"); - - fail(pEvent == NULL); - fail(pEvent->type != event_SEND); - fail(pEvent->data.message.header.action != message_MENUWARN); - fail(pvReference == NULL); - - pDiag = (diagram_type *)pvReference; - - if (menu_currentopen != pDiag->pSaveMenu || - pEvent->data.message.data.menuwarn.selection[0] != SAVEMENU_SCALEVIEW) { - return FALSE; - } - - Error_CheckFatal(Wimp_GetWindowState(pDiag->tScaleWindow, - &tWindowState)); - if (tWindowState.flags.data.open) { - /* The window is already open */ - return TRUE; - } - - DBG_MSG("vScaleOpenAction for real"); - - pDiag->iScaleFactorTemp = pDiag->iScaleFactorCurr; - vUpdateWriteableNumber(pDiag->tScaleWindow, - SCALE_SCALE_WRITEABLE, pDiag->iScaleFactorTemp); - Window_Show(pDiag->tScaleWindow, open_UNDERPOINTER); - return TRUE; -} /* end of bScaleOpenAction */ - -/* - * vSetTitle - set the title of a window - */ -void -vSetTitle(diagram_type *pDiag) -{ - char szTitle[WINDOW_TITLE_LEN]; - - TRACE_MSG("vSetTitle"); - - fail(pDiag == NULL); - fail(pDiag->szFilename[0] == '\0'); - - (void)sprintf(szTitle, "%.*s at %d%%", - FILENAME_TITLE_LEN, - pDiag->szFilename, - pDiag->iScaleFactorCurr % 1000); - if (strlen(pDiag->szFilename) > FILENAME_TITLE_LEN) { - szTitle[FILENAME_TITLE_LEN - 1] = OUR_ELLIPSIS; - } - - Window_SetTitle(pDiag->tMainWindow, szTitle); -} /* end of vSetTitle */ - -/* - * vScaleButtonClick - handle a mouse button click in the Scale view window - */ -void -vScaleButtonClick(mouse_block *pMouse, diagram_type *pDiag) -{ - BOOL bCloseWindow, bRedraw; - - TRACE_MSG("vScaleButtonClick"); - - fail(pMouse == NULL || pDiag == NULL); - fail(pMouse->window != pDiag->tScaleWindow); - - bCloseWindow = FALSE; - bRedraw = FALSE; - switch (pMouse->icon) { - case SCALE_CANCEL_BUTTON: - bCloseWindow = TRUE; - pDiag->iScaleFactorTemp = pDiag->iScaleFactorCurr; - break; - case SCALE_SCALE_BUTTON: - bCloseWindow = TRUE; - bRedraw = pDiag->iScaleFactorCurr != pDiag->iScaleFactorTemp; - pDiag->iScaleFactorCurr = pDiag->iScaleFactorTemp; - break; - case SCALE_50_PCT: - pDiag->iScaleFactorTemp = 50; - break; - case SCALE_75_PCT: - pDiag->iScaleFactorTemp = 75; - break; - case SCALE_100_PCT: - pDiag->iScaleFactorTemp = 100; - break; - case SCALE_150_PCT: - pDiag->iScaleFactorTemp = 150; - break; - default: - DBG_DEC(pMouse->icon); - break; - } - if (bCloseWindow) { - /* Close the scale window */ - Error_CheckFatal(Wimp_CloseWindow(pMouse->window)); - if (bRedraw) { - /* Redraw the main window */ - vSetTitle(pDiag); - vForceRedraw(pDiag); - } - } else { - vUpdateWriteableNumber(pMouse->window, - SCALE_SCALE_WRITEABLE, - pDiag->iScaleFactorTemp); - } -} /* end of vScaleButtonClick */ - -/* - * bScaleKeyPressed - handle pressed keys for the scale window - */ -BOOL -bScaleKeyPressed(event_pollblock *pEvent, void *pvReference) -{ - icon_block tIcon; - diagram_type *pDiag; - caret_block *pCaret; - char *pcChar; - int iTmp; - - TRACE_MSG("bScaleKeyPressed"); - - fail(pEvent == NULL); - fail(pEvent->type != event_KEY); - fail(pvReference == NULL); - - pCaret = &pEvent->data.key.caret; - pDiag = (diagram_type *)pvReference; - - fail(pEvent->data.key.caret.window != pDiag->tScaleWindow); - - DBG_DEC_C(pCaret->icon != SCALE_SCALE_WRITEABLE, pCaret->icon); - DBG_DEC_C(pCaret->icon == SCALE_SCALE_WRITEABLE, pEvent->data.key.code); - - if (pEvent->data.key.code != '\r' || - pCaret->icon != SCALE_SCALE_WRITEABLE) { - Error_CheckFatal(Wimp_ProcessKey(pEvent->data.key.code)); - return TRUE; - } - - Error_CheckFatal(Wimp_GetIconState(pCaret->window, pCaret->icon, &tIcon)); - if (!tIcon.flags.data.text || !tIcon.flags.data.indirected) { - werr(1, "Icon %d must be indirected text", (int)pCaret->icon); - } - iTmp = (int)strtol(tIcon.data.indirecttext.buffer, &pcChar, 10); - if (*pcChar != '\0' && *pcChar != '\r') { - DBG_DEC(*pcChar); - } else if (iTmp < MIN_SCALE_FACTOR) { - pDiag->iScaleFactorTemp = MIN_SCALE_FACTOR; - } else if (iTmp > MAX_SCALE_FACTOR) { - pDiag->iScaleFactorTemp = MAX_SCALE_FACTOR; - } else { - pDiag->iScaleFactorTemp = iTmp; - } - pDiag->iScaleFactorCurr = pDiag->iScaleFactorTemp; - /* Close the scale window */ - Error_CheckFatal(Wimp_CloseWindow(pCaret->window)); - /* Redraw the main window */ - vSetTitle(pDiag); - vForceRedraw(pDiag); - return TRUE; -} /* end of bScaleKeyPressed */ - diff --git a/src/draw.h b/src/draw.h deleted file mode 100644 index 839bbf0..0000000 --- a/src/draw.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * draw.h - * Copyright (C) 2001 A.J. van Os; Released under GPL - * - * Description: - * Constants and macros to deal with the Draw format - */ - -#if !defined(__draw_h) -#define __draw_h 1 - -#include "drawftypes.h" - -typedef struct draw_jpegstrhdr_tag { - draw_tagtyp tag; /* 1 word */ - draw_sizetyp size; /* 1 word */ - draw_bboxtyp bbox; /* 4 words */ - int width; /* 1 word */ - int height; /* 1 word */ - int xdpi; /* 1 word */ - int ydpi; /* 1 word */ - int trfm[6]; /* 6 words */ - int len; /* 1 word */ -} draw_jpegstrhdr; - -typedef struct draw_jpegstr_tag { - draw_tagtyp tag; /* 1 word */ - draw_sizetyp size; /* 1 word */ - draw_bboxtyp bbox; /* 4 words */ - int width; /* 1 word */ - int height; /* 1 word */ - int xdpi; /* 1 word */ - int ydpi; /* 1 word */ - int trfm[6]; /* 6 words */ - int len; /* 1 word */ - unsigned char *jpeg; -} draw_jpegstr; - -typedef union draw_imageType_tag { - draw_spristr *sprite; - draw_jpegstr *jpeg; - char *bytep; - int *wordp; -} draw_imageType; - -#endif /* !__draw_h */ diff --git a/src/findtext.c b/src/findtext.c index 20724a5..4a42fe4 100644 --- a/src/findtext.c +++ b/src/findtext.c @@ -50,7 +50,7 @@ bAddTextBlocks(ULONG ulCharPosFirst, ULONG ulTotalLength, if (ulIndex >= (ULONG)tBBDLen) { DBG_DEC(ulIndex); DBG_DEC(tBBDLen); - werr(1, "The Big Block Depot is damaged"); + return FALSE; } if (ulOffset >= BIG_BLOCK_SIZE) { ulOffset -= BIG_BLOCK_SIZE; @@ -108,6 +108,7 @@ bGet6DocumentText(FILE *pFile, BOOL bUsesUnicode, ULONG ulStartBlock, DBG_DEC(tTextInfoLen); aucBuffer = xmalloc(tTextInfoLen); + setBufferSize(tTextInfoLen); if (!bReadBuffer(pFile, ulStartBlock, aulBBD, tBBDLen, BIG_BLOCK_SIZE, aucBuffer, ulBeginTextInfo, tTextInfoLen)) { @@ -218,6 +219,7 @@ bGet8DocumentText(FILE *pFile, const pps_info_type *pPPS, tBlockSize = BIG_BLOCK_SIZE; } aucBuffer = xmalloc(tTextInfoLen); + setBufferSize(tTextInfoLen); if (!bReadBuffer(pFile, pPPS->tTable.ulSB, aulBlockDepot, tBlockDepotLen, tBlockSize, aucBuffer, ulBeginTextInfo, tTextInfoLen)) { @@ -256,6 +258,9 @@ bGet8DocumentText(FILE *pFile, const pps_info_type *pPPS, lPieces = (long)((ulLen - 4) / 12); DBG_DEC(lPieces); for (lIndex = 0; lIndex < lPieces; lIndex++) { + if (lOff + (lPieces + 1) * 4 + lIndex * 8 + 6 > tTextInfoLen) { + return FALSE; + } ulTextOffset = ulGetLong( lOff + (lPieces + 1) * 4 + lIndex * 8 + 2, aucBuffer); diff --git a/src/icons.c b/src/icons.c deleted file mode 100644 index dd88c00..0000000 --- a/src/icons.c +++ /dev/null @@ -1,96 +0,0 @@ -/* - * icons.c - * Copyright (C) 1998-2001 A.J. van Os; Released under GPL - * - * Description: - * Update window icons - */ - -#include -#include "DeskLib:Error.h" -#include "DeskLib:WimpSWIs.h" -#include "antiword.h" - -void -vUpdateIcon(window_handle tWindow, icon_block *pIcon) -{ - window_redrawblock tRedraw; - BOOL bMore; - - tRedraw.window = tWindow; - tRedraw.rect = pIcon->workarearect; - Error_CheckFatal(Wimp_UpdateWindow(&tRedraw, &bMore)); - while (bMore) { - Error_CheckFatal(Wimp_PlotIcon(pIcon)); - Error_CheckFatal(Wimp_GetRectangle(&tRedraw, &bMore)); - } -} /* end of vUpdateIcon */ - -void -vUpdateRadioButton(window_handle tWindow, icon_handle tIconNumber, - BOOL bSelected) -{ - icon_block tIcon; - - Error_CheckFatal(Wimp_GetIconState(tWindow, tIconNumber, &tIcon)); - DBG_DEC(tIconNumber); - DBG_HEX(tIcon.flags.data.selected); - if (bSelected == (tIcon.flags.data.selected == 1)) { - /* No update needed */ - return; - } - Error_CheckFatal(Wimp_SetIconState(tWindow, tIconNumber, - bSelected ? 0x00200000 : 0, 0x00200000)); - vUpdateIcon(tWindow, &tIcon); -} /* end of vUpdateRadioButton */ - -/* - * vUpdateWriteable - update a writeable icon with a string - */ -void -vUpdateWriteable(window_handle tWindow, icon_handle tIconNumber, - const char *szString) -{ - icon_block tIcon; - caret_block tCaret; - int iLen; - - fail(szString == NULL); - - NO_DBG_DEC(tIconNumber); - NO_DBG_MSG(szString); - - Error_CheckFatal(Wimp_GetIconState(tWindow, tIconNumber, &tIcon)); - NO_DBG_HEX(tIcon.flags); - if (!tIcon.flags.data.text || !tIcon.flags.data.indirected) { - werr(1, "Icon %d must be indirected text", (int)tIconNumber); - return; - } - strncpy(tIcon.data.indirecttext.buffer, - szString, - tIcon.data.indirecttext.bufflen - 1); - /* Ensure the caret is behind the last character of the text */ - Error_CheckFatal(Wimp_GetCaretPosition(&tCaret)); - if (tCaret.window == tWindow && tCaret.icon == tIconNumber) { - iLen = strlen(tIcon.data.indirecttext.buffer); - if (tCaret.index != iLen) { - tCaret.index = iLen; - Error_CheckFatal(Wimp_SetCaretPosition(&tCaret)); - } - } - Error_CheckFatal(Wimp_SetIconState(tWindow, tIconNumber, 0, 0)); - vUpdateIcon(tWindow, &tIcon); -} /* end of vUpdateWriteable */ - -/* - * vUpdateWriteableNumber - update a writeable icon with a number - */ -void -vUpdateWriteableNumber(window_handle tWindow, icon_handle tIconNumber, - int iNumber) -{ - char szTmp[1+3*sizeof(int)+1]; - - (void)sprintf(szTmp, "%d", iNumber); - vUpdateWriteable(tWindow, tIconNumber, szTmp); -} /* end of vUpdateWriteableNumber */ diff --git a/src/main_ros.c b/src/main_ros.c deleted file mode 100644 index 3dc6104..0000000 --- a/src/main_ros.c +++ /dev/null @@ -1,520 +0,0 @@ -/* - * main_ros.c - * - * Released under GPL - * - * Copyright (C) 1998-2005 A.J. van Os - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * Description: - * The main program of !Antiword (RISC OS version) - */ - -#include -#include -#include -#include "DeskLib:Dialog2.h" -#include "DeskLib:Error.h" -#include "DeskLib:Event.h" -#include "DeskLib:EventMsg.h" -#include "DeskLib:Handler.h" -#include "DeskLib:Menu.h" -#include "DeskLib:Resource.h" -#include "DeskLib:Screen.h" -#include "DeskLib:Template.h" -#include "DeskLib:Window.h" -#if defined(__GNUC__) -#include "flexlib:flex.h" -#endif /* __GNUC__ */ -#include "version.h" -#include "antiword.h" - - -/* The name of this program */ -static char *szTask = "!Antiword"; - -/* The window handle of the choices window */ -static __thread window_handle tChoicesWindow = 0; - -/* Dummy diagram with the iconbar menu pointer */ -static __thread diagram_type tDummyDiagram; - -/* Program information Box */ -static __thread dialog2_block *pInfoBox = NULL; - -/* Info box fields */ -#define PURPOSE_INFO_FIELD 2 -#define AUTHOR_INFO_FIELD 3 -#define VERSION_INFO_FIELD 4 -#define STATUS_INFO_FIELD 5 - -/* Iconbar menu fields */ -#define ICONBAR_INFO_FIELD 0 -#define ICONBAR_CHOICES_FIELD 1 -#define ICONBAR_QUIT_FIELD 2 - - -/* - * bBarInfo - Show iconbar information - */ -static BOOL -bBarInfo(event_pollblock *pEvent, void *pvReference) -{ - diagram_type *pDiag; - - TRACE_MSG("bBarInfo"); - - fail(pEvent == NULL); - fail(pEvent->type != event_SEND); - fail(pEvent->data.message.header.action != message_MENUWARN); - fail(pvReference == NULL); - - pDiag = (diagram_type *)pvReference; - - if (menu_currentopen != pDiag->pSaveMenu || - pEvent->data.message.data.menuwarn.selection[0] != ICONBAR_INFO_FIELD) { - return FALSE; - } - - Dialog2_OpenDialogMenuLeaf(pEvent, pInfoBox); - return TRUE; -} /* end of bBarInfo */ - -/* - * vBarInfoSetText - Set the iconbar infobox text - */ -static void -vBarInfoSetText(dialog2_block *pBox) -{ - TRACE_MSG("vBarInfoSetText"); - - fail(pBox == NULL); - fail(pBox != pInfoBox); - - Icon_SetText(pBox->window, PURPOSE_INFO_FIELD, PURPOSESTRING); - Icon_SetText(pBox->window, AUTHOR_INFO_FIELD, AUTHORSTRING); - Icon_SetText(pBox->window, VERSION_INFO_FIELD, VERSIONSTRING); - Icon_SetText(pBox->window, STATUS_INFO_FIELD, STATUSSTRING); -} /* end of vBarInfoSetText */ - -/* - * bMouseButtonClick - respond to mouse button click - */ -static BOOL -bMouseButtonClick(event_pollblock *pEvent, void *pvReference) -{ - diagram_type *pDiag; - menu_ptr pMenu; - int iPosY; - - TRACE_MSG("bMouseButtonClick"); - - fail(pEvent == NULL); - fail(pEvent->type != event_CLICK); - fail(pvReference == NULL); - - pDiag = (diagram_type *)pvReference; - - if (pEvent->data.mouse.button.data.menu) { - pMenu = pDiag->pSaveMenu; - iPosY = (pMenu == tDummyDiagram.pSaveMenu) ? - -1 : pEvent->data.mouse.pos.y; - Menu_Show(pMenu, pEvent->data.mouse.pos.x, iPosY); - return TRUE; - } - if (pEvent->data.mouse.window == pDiag->tMainWindow && - pEvent->data.mouse.icon == -1) { - vMainButtonClick(&pEvent->data.mouse); - return TRUE; - } - if (pEvent->data.mouse.window == pDiag->tScaleWindow && - pEvent->data.mouse.icon >= 0) { - vScaleButtonClick(&pEvent->data.mouse, pDiag); - return TRUE; - } - return FALSE; -} /* end of bMouseButtonClick */ - -/* - * bAutoRedrawWindow - the redraw is handled by the WIMP - */ -static BOOL -bAutoRedrawWindow(event_pollblock *pEvent, void *pvReference) -{ - return TRUE; -} /* end of bAutoRedrawWindow */ - -static BOOL -bSaveSelect(event_pollblock *pEvent, void *pvReference) -{ - TRACE_MSG("bSaveSelect"); - - fail(pEvent == NULL); - fail(pEvent->type != event_MENU); - fail(pvReference == NULL); - - DBG_DEC(pEvent->data.selection[0]); - - switch (pEvent->data.selection[0]) { - case SAVEMENU_SCALEVIEW: - return bScaleOpenAction(pEvent, pvReference); - case SAVEMENU_SAVEDRAW: - return bSaveDrawfile(pEvent, pvReference); - case SAVEMENU_SAVETEXT: - return bSaveTextfile(pEvent, pvReference); - default: - DBG_DEC(pEvent->data.selection[0]); - return FALSE; - } -} /* end of bSaveSelect */ - -/* - * Create the window for the text from the given file - */ -static diagram_type * -pCreateTextWindow(const char *szFilename) -{ - diagram_type *pDiag; - - TRACE_MSG("pCreateTextWindow"); - - fail(szFilename == NULL || szFilename[0] == '\0'); - - /* Create the diagram */ - pDiag = pCreateDiagram(szTask+1, szFilename); - if (pDiag == NULL) { - werr(0, "Sorry, no new diagram object"); - return NULL; - } - - /* Prepare a save menu for this diagram */ - pDiag->pSaveMenu = Menu_New(szTask+1, - ">Scale view," - ">Save (Drawfile) F3," - ">Save (Text only) \213F3"); - if (pDiag->pSaveMenu == NULL) { - werr(1, "Sorry, no Savemenu object"); - } - Menu_Warn(pDiag->pSaveMenu, SAVEMENU_SCALEVIEW, - TRUE, bScaleOpenAction, pDiag); - Menu_Warn(pDiag->pSaveMenu, SAVEMENU_SAVEDRAW, - TRUE, bSaveDrawfile, pDiag); - Menu_Warn(pDiag->pSaveMenu, SAVEMENU_SAVETEXT, - TRUE, bSaveTextfile, pDiag); - - /* Claim events for the main window */ - Event_Claim(event_REDRAW, pDiag->tMainWindow, icon_ANY, - bRedrawMainWindow, pDiag); - Event_Claim(event_CLOSE, pDiag->tMainWindow, icon_ANY, - bDestroyDiagram, pDiag); - Event_Claim(event_CLICK, pDiag->tMainWindow, icon_ANY, - bMouseButtonClick, pDiag); - Event_Claim(event_KEY, pDiag->tMainWindow, icon_ANY, - bMainKeyPressed, pDiag); - - /* Claim events for the scale window */ - Event_Claim(event_REDRAW, pDiag->tScaleWindow, icon_ANY, - bAutoRedrawWindow, NULL); - Event_Claim(event_CLICK, pDiag->tScaleWindow, icon_ANY, - bMouseButtonClick, pDiag); - Event_Claim(event_KEY, pDiag->tScaleWindow, icon_ANY, - bScaleKeyPressed, pDiag); - - /* Set the window title */ - vSetTitle(pDiag); - return pDiag; -} /* end of pCreateTextWindow */ - -/* - * vProcessFile - process one file - */ -static void -vProcessFile(const char *szFilename, int iFiletype) -{ - options_type tOptions; - FILE *pFile; - diagram_type *pDiag; - long lFilesize; - int iWordVersion; - - TRACE_MSG("vProcessFile"); - - fail(szFilename == NULL || szFilename[0] == '\0'); - - DBG_MSG(szFilename); - - pFile = fopen(szFilename, "rb"); - if (pFile == NULL) { - werr(0, "I can't open '%s' for reading", szFilename); - return; - } - - lFilesize = lGetFilesize(szFilename); - if (lFilesize < 0) { - (void)fclose(pFile); - werr(0, "I can't get the size of '%s'", szFilename); - return; - } - - iWordVersion = iGuessVersionNumber(pFile, lFilesize); - if (iWordVersion < 0 || iWordVersion == 3) { - if (bIsRtfFile(pFile)) { - werr(0, "%s is not a Word Document." - " It is probably a Rich Text Format file", - szFilename); - } if (bIsWordPerfectFile(pFile)) { - werr(0, "%s is not a Word Document." - " It is probably a Word Perfect file", - szFilename); - } else { - werr(0, "%s is not a Word Document.", szFilename); - } - (void)fclose(pFile); - return; - } - /* Reset any reading done during file-testing */ - rewind(pFile); - - if (iFiletype != FILETYPE_MSWORD) { - vGetOptions(&tOptions); - if (tOptions.bAutofiletypeAllowed) { - vSetFiletype(szFilename, FILETYPE_MSWORD); - } - } - - pDiag = pCreateTextWindow(szFilename); - if (pDiag == NULL) { - (void)fclose(pFile); - return; - } - - (void)bWordDecryptor(pFile, lFilesize, pDiag); - Error_CheckFatal(Drawfile_VerifyDiagram(&pDiag->tInfo)); - vShowDiagram(pDiag); - TRACE_MSG("After vShowDiagram"); - - TRACE_MSG("before debug print"); - DBG_HEX(pFile); - TRACE_MSG("before fclose"); - (void)fclose(pFile); - TRACE_MSG("after fclose"); -} /* end of vProcessFile */ - -/* - * vSendAck - send an acknowledge - */ -static void -vSendAck(event_pollblock *pEvent) -{ - message_block tMessage; - - TRACE_MSG("vSendAck"); - - fail(pEvent == NULL); - fail(pEvent->type != event_SEND && pEvent->type != event_SENDWANTACK); - fail(pEvent->data.message.header.action != message_DATALOAD && - pEvent->data.message.header.action != message_DATAOPEN); - - tMessage.header.action = message_DATALOADACK; - tMessage.header.size = sizeof(tMessage); - tMessage.header.yourref = pEvent->data.message.header.myref; - Error_CheckFatal(Wimp_SendMessage(event_SEND, &tMessage, - pEvent->data.message.header.sender, 0)); -} /* end of vSendAck */ - -static BOOL -bEventMsgHandler(event_pollblock *pEvent, void *pvReference) -{ - TRACE_MSG("bEventMsgHandler"); - - fail(pEvent == NULL); - - switch (pEvent->type) { - case event_SEND: - case event_SENDWANTACK: - switch (pEvent->data.message.header.action) { - case message_CLOSEDOWN: - exit(EXIT_SUCCESS); - break; - case message_DATALOAD: - case message_DATAOPEN: - vProcessFile( - pEvent->data.message.data.dataload.filename, - pEvent->data.message.data.dataload.filetype); - vSendAck(pEvent); - break; - default: - DBG_DEC(pEvent->data.message.header.action); - break; - } - return TRUE; - default: - DBG_DEC(pEvent->type); - return FALSE; - } -} /* end of bEventMsgHandler */ - -/* - * bMenuSelect - select from the iconbar menu - */ -static BOOL -bMenuSelect(event_pollblock *pEvent, void *pvReference) -{ - TRACE_MSG("bMenuSelect"); - - fail(pEvent == NULL); - fail(pEvent->type != event_MENU); - - DBG_DEC(pEvent->data.selection[0]); - - switch (pEvent->data.selection[0]) { - case ICONBAR_INFO_FIELD: - return bBarInfo(pEvent, pvReference); - case ICONBAR_CHOICES_FIELD: - vChoicesOpenAction(tChoicesWindow); - Window_BringToFront(tChoicesWindow); - break; - case ICONBAR_QUIT_FIELD: - TRACE_MSG("before exit"); - exit(EXIT_SUCCESS); - break; - default: - DBG_DEC(pEvent->data.selection[0]); - break; - } - return TRUE; -} /* end of bMenuSelect */ - -/* - * bMenuClick - respond to an menu click - */ -static BOOL -bMenuClick(event_pollblock *pEvent, void *pvReference) -{ - TRACE_MSG("bMenuClick"); - - fail(pEvent == NULL); - fail(pEvent->type != event_MENU); - - if (menu_currentopen == tDummyDiagram.pSaveMenu) { - return bMenuSelect(pEvent, pvReference); - } else if (pvReference == NULL) { - return FALSE; - } - return bSaveSelect(pEvent, pvReference); -} /* end of bMenuClick */ - -static void -vTemplates(void) -{ - TRACE_MSG("vTemplates"); - - Template_Initialise(); - Template_LoadFile("Templates"); - - tChoicesWindow = Window_Create("Choices", template_TITLEMIN); - if (tChoicesWindow == 0) { - werr(1, "I can't find the 'Choices' template"); - } - - /* Claim events for the choices window */ - Event_Claim(event_REDRAW, tChoicesWindow, icon_ANY, - bAutoRedrawWindow, NULL); - Event_Claim(event_CLICK, tChoicesWindow, icon_ANY, - bChoicesMouseClick, NULL); - Event_Claim(event_KEY, tChoicesWindow, icon_ANY, - bChoicesKeyPressed, NULL); -} /* end of vTemplates */ - -static void -vInitialise(void) -{ - int aiMessages[] = {0}; - icon_handle tBarIcon; - - - TRACE_MSG("vInitialise"); - - Resource_Initialise(szTask+1); - Event_Initialise3(szTask+1, 310, aiMessages); - EventMsg_Initialise(); - Screen_CacheModeInfo(); -#if defined(__GNUC__) - flex_init(szTask+1, 0, 0); - flex_set_budge(1); -#endif /* __GNUC__ */ - vTemplates(); - - /* Prepare iconbar menu */ - tDummyDiagram.tInfo.data = NULL; - tDummyDiagram.tInfo.length = 0; - tDummyDiagram.pSaveMenu = Menu_New(szTask+1, ">Info,Choices...,Quit"); - if (tDummyDiagram.pSaveMenu == NULL) { - werr(1, "Sorry, no Barmenu object"); - } - pInfoBox = Dialog2_CreateDialogBlock("ProgInfo", -1, -1, - vBarInfoSetText, NULL, NULL); - - if (pInfoBox == NULL) { - werr(1, "Sorry, no Infobox object"); - } - Menu_Warn(tDummyDiagram.pSaveMenu, ICONBAR_INFO_FIELD, - TRUE, bBarInfo, &tDummyDiagram); - - /* Create an icon on the icon bar */ - tBarIcon = Icon_BarIcon(szTask, iconbar_RIGHT); - Event_Claim(event_CLICK, window_ICONBAR, tBarIcon, - bMouseButtonClick, &tDummyDiagram); - - /* Generic claims */ - Event_Claim(event_OPEN, window_ANY, icon_ANY, - Handler_OpenWindow, NULL); - Event_Claim(event_CLOSE, window_ANY, icon_ANY, - Handler_CloseWindow, NULL); - Event_Claim(event_MENU, window_ANY, icon_ANY, - bMenuClick, NULL); - EventMsg_Claim(message_DATALOAD, window_ICONBAR, - bEventMsgHandler, NULL); - EventMsg_Claim(message_MODECHANGE, window_ANY, - Handler_ModeChange, NULL); -} /* end of vInitialise */ - -int -main(int argc, char **argv) -{ - int iFirst, iFiletype; - - TRACE_MSG("main"); - - vInitialise(); - iFirst = iReadOptions(argc, argv); - if (iFirst != 1) { - return EXIT_FAILURE; - } - - if (argc > 1) { - iFiletype = iGetFiletype(argv[1]); - if (iFiletype < 0) { - return EXIT_FAILURE; - } - vProcessFile(argv[1], iFiletype); - TRACE_MSG("main after vProcessFile"); - } - - for (;;) { - Event_Poll(); - } -} /* end of main */ diff --git a/src/main_u.c b/src/main_u.c deleted file mode 100644 index 4eaaea3..0000000 --- a/src/main_u.c +++ /dev/null @@ -1,321 +0,0 @@ -/* - * main_u.c - * - * Released under GPL - * - * Copyright (C) 1998-2004 A.J. van Os - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * Description: - * The main program of 'antiword' (Unix version) - */ - -#include -#include -#if defined(__dos) -#include -#include -#endif /* __dos */ -#if defined(__CYGWIN__) || defined(__CYGMING__) -# ifdef X_LOCALE -# include -# else -# include -# endif -#else -#include -#endif /* __CYGWIN__ || __CYGMING__ */ -#if defined(N_PLAT_NLM) -#if !defined(_VA_LIST) -#include "NW-only/nw_os.h" -#endif /* !_VA_LIST */ -#include "getopt.h" -#endif /* N_PLAT_NLM */ -#include "version.h" -#include "antiword.h" - -/* The name of this program */ -static const char *szTask = NULL; - - -static void -vUsage(void) -{ - fprintf(stderr, "\tName: %s\n", szTask); - fprintf(stderr, "\tPurpose: "PURPOSESTRING"\n"); - fprintf(stderr, "\tAuthor: "AUTHORSTRING"\n"); - fprintf(stderr, "\tVersion: "VERSIONSTRING); -#if defined(__dos) - fprintf(stderr, VERSIONSTRING2); -#endif /* __dos */ - fprintf(stderr, "\n"); - fprintf(stderr, "\tStatus: "STATUSSTRING"\n"); - fprintf(stderr, - "\tUsage: %s [switches] wordfile1 [wordfile2 ...]\n", szTask); - fprintf(stderr, - "\tSwitches: [-f|-t|-a papersize|-p papersize|-x dtd]" - "[-m mapping][-w #][-i #][-Ls]\n"); - fprintf(stderr, "\t\t-f formatted text output\n"); - fprintf(stderr, "\t\t-t text output (default)\n"); - fprintf(stderr, "\t\t-a Adobe PDF output\n"); - fprintf(stderr, "\t\t-p PostScript output\n"); - fprintf(stderr, "\t\t paper size like: a4, letter or legal\n"); - fprintf(stderr, "\t\t-x XML output\n"); - fprintf(stderr, "\t\t like: db (DocBook)\n"); - fprintf(stderr, "\t\t-m character mapping file\n"); - fprintf(stderr, "\t\t-w in characters of text output\n"); - fprintf(stderr, "\t\t-i image level (PostScript only)\n"); - fprintf(stderr, "\t\t-L use landscape mode (PostScript only)\n"); - fprintf(stderr, "\t\t-r Show removed text\n"); - fprintf(stderr, "\t\t-s Show hidden (by Word) text\n"); -} /* end of vUsage */ - -/* - * pStdin2TmpFile - save stdin in a temporary file - * - * returns: the pointer to the temporary file or NULL - */ -static FILE * -pStdin2TmpFile(long *lFilesize) -{ - FILE *pTmpFile; - size_t tSize; - BOOL bFailure; - UCHAR aucBytes[BUFSIZ]; - - DBG_MSG("pStdin2TmpFile"); - - fail(lFilesize == NULL); - - /* Open the temporary file */ - pTmpFile = tmpfile(); - if (pTmpFile == NULL) { - return NULL; - } - -#if defined(__dos) - /* Stdin must be read as a binary stream */ - setmode(fileno(stdin), O_BINARY); -#endif /* __dos */ - - /* Copy stdin to the temporary file */ - *lFilesize = 0; - bFailure = TRUE; - for (;;) { - tSize = fread(aucBytes, 1, sizeof(aucBytes), stdin); - if (tSize == 0) { - bFailure = feof(stdin) == 0; - break; - } - if (fwrite(aucBytes, 1, tSize, pTmpFile) != tSize) { - bFailure = TRUE; - break; - } - *lFilesize += (long)tSize; - } - -#if defined(__dos) - /* Switch stdin back to a text stream */ - setmode(fileno(stdin), O_TEXT); -#endif /* __dos */ - - /* Deal with the result of the copy action */ - if (bFailure) { - *lFilesize = 0; - (void)fclose(pTmpFile); - return NULL; - } - rewind(pTmpFile); - return pTmpFile; -} /* end of pStdin2TmpFile */ - -/* - * bProcessFile - process a single file - * - * returns: TRUE when the given file is a supported Word file, otherwise FALSE - */ -static BOOL -bProcessFile(const char *szFilename) -{ - FILE *pFile; - diagram_type *pDiag; - long lFilesize; - int iWordVersion; - BOOL bResult; - - fail(szFilename == NULL || szFilename[0] == '\0'); - - DBG_MSG(szFilename); - - if (szFilename[0] == '-' && szFilename[1] == '\0') { - pFile = pStdin2TmpFile(&lFilesize); - if (pFile == NULL) { - werr(0, "I can't save the standard input to a file"); - return FALSE; - } - } else { - pFile = fopen(szFilename, "rb"); - if (pFile == NULL) { - werr(0, "I can't open '%s' for reading", szFilename); - return FALSE; - } - - lFilesize = lGetFilesize(szFilename); - if (lFilesize < 0) { - (void)fclose(pFile); - werr(0, "I can't get the size of '%s'", szFilename); - return FALSE; - } - } - - iWordVersion = iGuessVersionNumber(pFile, lFilesize); - if (iWordVersion < 0 || iWordVersion == 3) { - if (bIsRtfFile(pFile)) { - werr(0, "%s is not a Word Document." - " It is probably a Rich Text Format file", - szFilename); - } if (bIsWordPerfectFile(pFile)) { - werr(0, "%s is not a Word Document." - " It is probably a Word Perfect file", - szFilename); - } else { -#if defined(__dos) - werr(0, "%s is not a Word Document or the filename" - " is not in the 8+3 format.", szFilename); -#else - werr(0, "%s is not a Word Document.", szFilename); -#endif /* __dos */ - } - (void)fclose(pFile); - return FALSE; - } - /* Reset any reading done during file testing */ - rewind(pFile); - - pDiag = pCreateDiagram(szTask, szFilename); - if (pDiag == NULL) { - (void)fclose(pFile); - return FALSE; - } - - bResult = bWordDecryptor(pFile, lFilesize, pDiag); - vDestroyDiagram(pDiag); - - (void)fclose(pFile); - return bResult; -} /* end of bProcessFile */ - -int -main(int argc, char **argv) -{ - options_type tOptions; - const char *szWordfile; - int iFirst, iIndex, iGoodCount; - BOOL bUsage, bMultiple, bUseTXT, bUseXML; - - if (argc <= 0) { - return EXIT_FAILURE; - } - - szTask = szBasename(argv[0]); - - if (argc <= 1) { - iFirst = 1; - bUsage = TRUE; - } else { - iFirst = iReadOptions(argc, argv); - bUsage = iFirst <= 0; - } - if (bUsage) { - vUsage(); - return iFirst < 0 ? EXIT_FAILURE : EXIT_SUCCESS; - } - -#if defined(N_PLAT_NLM) && !defined(_VA_LIST) - nwinit(); -#endif /* N_PLAT_NLM && !_VA_LIST */ - - vGetOptions(&tOptions); - -#if !defined(__dos) - if (is_locale_utf8()) { -#if defined(__STDC_ISO_10646__) - /* - * If the user wants UTF-8 and the envirionment variables - * support UTF-8, than set the locale accordingly - */ - if (tOptions.eEncoding == encoding_utf_8) { - if (setlocale(LC_CTYPE, "") == NULL) { - werr(1, "Can't set the UTF-8 locale! " - "Check LANG, LC_CTYPE, LC_ALL."); - } - DBG_MSG("The UTF-8 locale has been set"); - } else { - (void)setlocale(LC_CTYPE, "C"); - } -#endif /* __STDC_ISO_10646__ */ - } else { - if (setlocale(LC_CTYPE, "") == NULL) { - werr(0, "Can't set the locale! Will use defaults"); - (void)setlocale(LC_CTYPE, "C"); - } - DBG_MSG("The locale has been set"); - } -#endif /* !__dos */ - - bMultiple = argc - iFirst > 1; - bUseTXT = tOptions.eConversionType == conversion_text || - tOptions.eConversionType == conversion_fmt_text; - bUseXML = tOptions.eConversionType == conversion_xml; - iGoodCount = 0; - -#if defined(__dos) - if (tOptions.eConversionType == conversion_pdf) { - /* PDF must be written as a binary stream */ - setmode(fileno(stdout), O_BINARY); - } -#endif /* __dos */ - - if (bUseXML) { - fprintf(stdout, - "\n" - "\n", - bMultiple ? "set" : "book"); - if (bMultiple) { - fprintf(stdout, "\n"); - } - } - - for (iIndex = iFirst; iIndex < argc; iIndex++) { - if (bMultiple && bUseTXT) { - szWordfile = szBasename(argv[iIndex]); - fprintf(stdout, "::::::::::::::\n"); - fprintf(stdout, "%s\n", szWordfile); - fprintf(stdout, "::::::::::::::\n"); - } - if (bProcessFile(argv[iIndex])) { - iGoodCount++; - } - } - - if (bMultiple && bUseXML) { - fprintf(stdout, "\n"); - } - - DBG_DEC(iGoodCount); - return iGoodCount <= 0 ? EXIT_FAILURE : EXIT_SUCCESS; -} /* end of main */ diff --git a/src/misc.c b/src/misc.c index 609a2f0..fe2c4c5 100644 --- a/src/misc.c +++ b/src/misc.c @@ -224,11 +224,12 @@ bReadBuffer(FILE *pFile, ULONG ulStartBlock, if (ulIndex >= (ULONG)tBlockDepotLen) { DBG_DEC(ulIndex); DBG_DEC(tBlockDepotLen); - if (tBlockSize >= BIG_BLOCK_SIZE) { - werr(1, "The Big Block Depot is damaged"); - } else { - werr(1, "The Small Block Depot is damaged"); - } +// if (tBlockSize >= BIG_BLOCK_SIZE) { +// werr(1, "The Big Block Depot is damaged"); +// } else { +// werr(1, "The Small Block Depot is damaged"); +// } + return FALSE; } if (ulOffset >= (ULONG)tBlockSize) { ulOffset -= tBlockSize; diff --git a/src/prop6.c b/src/prop6.c index e4c468d..41ecf80 100644 --- a/src/prop6.c +++ b/src/prop6.c @@ -410,7 +410,7 @@ eGet6RowInfo(int iFodo, } if (iCol >= (int)elementsof(pRow->asColumnWidth)) { DBG_DEC(iCol); - werr(1, "The number of columns is corrupt"); + return found_nothing; } pRow->ucNumberOfColumns = (UCHAR)iCol; iPosPrev = (int)(short)usGetWord( diff --git a/src/prop8.c b/src/prop8.c index c31204e..ab0d73c 100644 --- a/src/prop8.c +++ b/src/prop8.c @@ -479,7 +479,8 @@ eGet8RowInfo(int iFodo, } if (iCol >= (int)elementsof(pRow->asColumnWidth)) { DBG_DEC(iCol); - werr(1, "The number of columns is corrupt"); + return found_nothing; +// werr(1, "The number of columns is corrupt"); } pRow->ucNumberOfColumns = (UCHAR)iCol; iPosPrev = (int)(short)usGetWord( diff --git a/src/properties.c b/src/properties.c index 28087a4..f6f676c 100644 --- a/src/properties.c +++ b/src/properties.c @@ -115,8 +115,10 @@ vGetPropertyInfo(FILE *pFile, const pps_info_type *pPPS, case 8: vGet8LstInfo(pFile, pPPS, aulBBD, tBBDLen, aulSBD, tSBDLen, aucHeader); - vGet8Stylesheet(pFile, pPPS, - aulBBD, tBBDLen, aulSBD, tSBDLen, aucHeader); + if (!vGet8Stylesheet(pFile, pPPS, + aulBBD, tBBDLen, aulSBD, tSBDLen, aucHeader)) { + return; + } vGet8DopInfo(pFile, &pPPS->tTable, aulBBD, tBBDLen, aulSBD, tSBDLen, aucHeader); vGet8SepInfo(pFile, pPPS, diff --git a/src/propmod.c b/src/propmod.c index c567ccd..02dfe02 100644 --- a/src/propmod.c +++ b/src/propmod.c @@ -63,6 +63,9 @@ vAdd2PropModList(const UCHAR *aucPropMod) NO_DBG_DEC(tNextFree); tLen = 2 + (size_t)usGetWord(0, aucPropMod); + if (isOutOfBounds(tLen)) { + return; + } NO_DBG_HEX(tLen); NO_DBG_PRINT_BLOCK(pucPropMod, tLen); ppAnchor[tNextFree] = xmalloc(tLen); diff --git a/src/sist2_hotfix.c b/src/sist2_hotfix.c new file mode 100644 index 0000000..d46908f --- /dev/null +++ b/src/sist2_hotfix.c @@ -0,0 +1,11 @@ +#include "antiword.h" + +static __thread ULONG buffer; + +BOOL isOutOfBounds(ULONG offset) { + return offset > buffer; +} + +void setBufferSize(ULONG size) { + buffer = size; +} diff --git a/src/startup.c b/src/startup.c deleted file mode 100644 index 7e1b6d7..0000000 --- a/src/startup.c +++ /dev/null @@ -1,145 +0,0 @@ -/* - * startup.c - * Copyright (C) 1998-2001 A.J. van Os; Released under GPL - * - * Description: - * Try to force a single startup of !Antiword - */ - -#include -#include -#include -#include "DeskLib:Error.h" -#include "DeskLib:Event.h" -#include "DeskLib:SWI.h" -#include "antiword.h" - - -#if !defined(TaskManager_EnumerateTasks) -#define TaskManager_EnumerateTasks 0x042681 -#endif /* TaskManager_EnumerateTasks */ - -/* - * bIsMatch - decide whether the two strings match - * - * like strcmp, but this one ignores case - */ -static BOOL -bIsMatch(const char *szStr1, const char *szStr2) -{ - const char *pcTmp1, *pcTmp2; - - for (pcTmp1 = szStr1, pcTmp2 = szStr2; - *pcTmp1 != '\0'; - pcTmp1++, pcTmp2++) { - if (toupper(*pcTmp1) != toupper(*pcTmp2)) { - return FALSE; - } - } - return *pcTmp2 == '\0'; -} /* end of bIsMatch */ - -/* - * tGetTaskHandle - get the task handle of the given task - * - * returns the task handle when found, otherwise 0 - */ -static task_handle -tGetTaskHandle(const char *szTaskname) -{ - const char *pcTmp; - int iReg0, iIndex; - int aiBuffer[4]; - char szTmp[21]; - - iReg0 = 0; - do { - /* Get info on the next task */ - Error_CheckFatal(SWI(3, 1, TaskManager_EnumerateTasks | XOS_Bit, - iReg0, aiBuffer, sizeof(aiBuffer), &iReg0)); - /* Copy the (control character terminated) task name */ - for (iIndex = 0, pcTmp = (const char *)aiBuffer[1]; - iIndex < elementsof(szTmp); - iIndex++, pcTmp++) { - if (iscntrl(*pcTmp)) { - szTmp[iIndex] = '\0'; - break; - } - szTmp[iIndex] = *pcTmp; - } - szTmp[elementsof(szTmp) - 1] = '\0'; - if (bIsMatch(szTmp, szTaskname)) { - /* Task found */ - return (task_handle)aiBuffer[0]; - } - } while (iReg0 >= 0); - - /* Task not found */ - return 0; -} /* end of tGetTaskHandle */ - -int -main(int argc, char **argv) -{ - message_block tMsg; - task_handle tTaskHandle; - size_t tArgLen; - int aiMessages[] = {0}; - char szCommand[512]; - - Event_Initialise3("StartUp", 310, aiMessages); - - if (argc > 1) { - tArgLen = strlen(argv[1]); - } else { - tArgLen = 0; - } - if (tArgLen >= sizeof(tMsg.data.dataload.filename)) { - werr(1, "Input filename too long"); - return EXIT_FAILURE; - } - - tTaskHandle = tGetTaskHandle("antiword"); - - if (tTaskHandle == 0) { - /* Antiword is not active */ - strcpy(szCommand, "chain:.!Antiword"); - if (argc > 1) { - strcat(szCommand, " "); - strcat(szCommand, argv[1]); - } -#if defined(DEBUG) - strcat(szCommand, " "); - strcat(szCommand, "2>.Debug"); -#endif /* DEBUG */ - system(szCommand); - /* If we reach here something has gone wrong */ - return EXIT_FAILURE; - } - - /* Antiword is active */ - if (argc > 1) { - /* - * Send the argument to Antiword by imitating a - * drag-and-drop to Antiword's iconbar icon - */ - memset(&tMsg, 0, sizeof(tMsg)); - tMsg.header.size = ROUND4(offsetof(message_block, data) + - offsetof(message_dataload, filename) + - 1 + tArgLen); - tMsg.header.yourref = 0; - tMsg.header.action = message_DATALOAD; - tMsg.data.dataload.window = window_ICONBAR; - tMsg.data.dataload.icon = -1; - tMsg.data.dataload.size = 0; - tMsg.data.dataload.filetype = FILETYPE_MSWORD; - strcpy(tMsg.data.dataload.filename, argv[1]); - Error_CheckFatal(Wimp_SendMessage(event_SEND, - &tMsg, tTaskHandle, 0)); - return EXIT_SUCCESS; - } else { - /* Give an error message and return */ - werr(1, "Antiword is already running"); - return EXIT_FAILURE; - } -} /* end of main */ diff --git a/src/stylesheet.c b/src/stylesheet.c index 85f4890..7d17d83 100644 --- a/src/stylesheet.c +++ b/src/stylesheet.c @@ -458,6 +458,9 @@ vGet6Stylesheet(FILE *pFile, ULONG ulStartBlock, iIndex < (int)tStdCount; iIndex++, tOffset += 2 + tStdLen) { NO_DBG_DEC(tOffset); + if (tOffset > tStshInfoLen) { + return; + } tStdLen = (size_t)usGetWord(tOffset, aucBuffer); NO_DBG_DEC(tStdLen); if (abFilled[iIndex]) { @@ -505,6 +508,9 @@ vGet6Stylesheet(FILE *pFile, ULONG ulStartBlock, NO_DBG_DEC(usUpxCount); tPos = 2 + tStdBaseInFile; NO_DBG_DEC(tPos); + if (tOffset + tPos > tStshInfoLen) { + return; + } tNameLen = (size_t)ucGetByte(tOffset + tPos, aucBuffer); NO_DBG_DEC(tNameLen); NO_DBG_STRN(aucBuffer + tOffset + tPos + 1, tNameLen); @@ -590,7 +596,7 @@ vGet6Stylesheet(FILE *pFile, ULONG ulStartBlock, /* * Build the lists with Stylesheet Information for Word 8/9/10 files */ -void +BOOL vGet8Stylesheet(FILE *pFile, const pps_info_type *pPPS, const ULONG *aulBBD, size_t tBBDLen, const ULONG *aulSBD, size_t tSBDLen, @@ -619,7 +625,7 @@ vGet8Stylesheet(FILE *pFile, const pps_info_type *pPPS, NO_DBG_HEX(pPPS->tTable.ulSize); if (pPPS->tTable.ulSize == 0) { DBG_MSG("No stylesheet information"); - return; + return TRUE; } if (pPPS->tTable.ulSize < MIN_SIZE_FOR_BBD_USE) { @@ -638,7 +644,7 @@ vGet8Stylesheet(FILE *pFile, const pps_info_type *pPPS, aulBlockDepot, tBlockDepotLen, tBlockSize, aucBuffer, ulBeginStshInfo, tStshInfoLen)) { aucBuffer = xfree(aucBuffer); - return; + return FALSE; } NO_DBG_PRINT_BLOCK(aucBuffer, tStshInfoLen); @@ -659,6 +665,10 @@ vGet8Stylesheet(FILE *pFile, const pps_info_type *pPPS, iIndex < (int)tStdCount; iIndex++, tOffset += 2 + tStdLen) { NO_DBG_DEC(tOffset); + if (tOffset + 6 > tStshInfoLen) { + aucBuffer = xfree(aucBuffer); + return FALSE; + } tStdLen = (size_t)usGetWord(tOffset, aucBuffer); NO_DBG_DEC(tStdLen); if (abFilled[iIndex]) { @@ -706,6 +716,9 @@ vGet8Stylesheet(FILE *pFile, const pps_info_type *pPPS, NO_DBG_DEC(usUpxCount); tPos = 2 + tStdBaseInFile; NO_DBG_DEC(tPos); + if (tOffset + tPos > tStshInfoLen) { + return FALSE; + } tNameLen = (size_t)usGetWord(tOffset + tPos, aucBuffer); NO_DBG_DEC(tNameLen); tNameLen *= 2; /* From Unicode characters to bytes */ @@ -720,6 +733,9 @@ vGet8Stylesheet(FILE *pFile, const pps_info_type *pPPS, if (tPos >= tStdLen) { continue; } + if (tOffset + tPos > tStshInfoLen) { + return FALSE; + } tUpxLen = (size_t)usGetWord(tOffset + tPos, aucBuffer); NO_DBG_DEC(tUpxLen); if (tPos + tUpxLen > tStdLen) { @@ -788,6 +804,7 @@ vGet8Stylesheet(FILE *pFile, const pps_info_type *pPPS, /* Clean up before you leave */ abFilled = xfree(abFilled); aucBuffer = xfree(aucBuffer); + return TRUE; } /* end of vGet8Stylesheet */ /* diff --git a/src/summary.c b/src/summary.c index 12e59cc..139ff08 100644 --- a/src/summary.c +++ b/src/summary.c @@ -207,7 +207,7 @@ tFiletime(ULONG ulOffset, const UCHAR *aucBuffer) /* * vAnalyseSummaryInfo - analyse the summary information */ -static void +static BOOL vAnalyseSummaryInfo(const UCHAR *aucBuffer) { ULONG ulOffset; @@ -220,6 +220,9 @@ vAnalyseSummaryInfo(const UCHAR *aucBuffer) ulOffset = ulGetLong(12 + tIndex * 8, aucBuffer); NO_DBG_DEC(tPropID); NO_DBG_HEX(ulOffset); + if (isOutOfBounds(ulOffset)) { + return FALSE; + } tPropType = (size_t)ulGetLong(ulOffset, aucBuffer); NO_DBG_DEC(tPropType); switch (tPropID) { @@ -277,6 +280,9 @@ vAnalyseDocumentSummaryInfo(const UCHAR *aucBuffer) ulOffset = ulGetLong(12 + tIndex * 8, aucBuffer); NO_DBG_DEC(tPropID); NO_DBG_HEX(ulOffset); + if (isOutOfBounds(ulOffset)) { + return; + } tPropType = (size_t)ulGetLong(ulOffset, aucBuffer); NO_DBG_DEC(tPropType); switch (tPropID) { @@ -406,6 +412,7 @@ pucAnalyseSummaryInfoHeader(FILE *pFile, /* Read the Summery Information */ aucBuffer = xmalloc(tLength); + setBufferSize(tLength); if (!bReadBuffer(pFile, ulStartBlock, aulBlockDepot, tBlockDepotLen, tBlockSize, aucBuffer, ulOffset, tLength)) { @@ -625,7 +632,9 @@ vSetSummaryInfoOLE(FILE *pFile, const pps_info_type *pPPS, pPPS->tSummaryInfo.ulSB, pPPS->tSummaryInfo.ulSize, aulBBD, tBBDLen, aulSBD, tSBDLen); if (pucBuffer != NULL) { - vAnalyseSummaryInfo(pucBuffer); + if (!vAnalyseSummaryInfo(pucBuffer)) { + return; + } pucBuffer = xfree(pucBuffer); } diff --git a/src/unix.c b/src/unix.c index 3da3964..c3b0965 100644 --- a/src/unix.c +++ b/src/unix.c @@ -21,9 +21,9 @@ werr(int iFatal, const char *szFormat, ...) va_list tArg; va_start(tArg, szFormat); - (void)vfprintf(stderr, szFormat, tArg); +// (void)vfprintf(stderr, szFormat, tArg); va_end(tArg); - fprintf(stderr, "\n"); +// fprintf(stderr, "\n"); switch (iFatal) { case 0: /* The message is just a warning, so no exit */ return; diff --git a/src/wordole.c b/src/wordole.c index 539669f..3ed807a 100644 --- a/src/wordole.c +++ b/src/wordole.c @@ -11,69 +11,69 @@ /* Private type for Property Set Storage entries */ typedef struct pps_entry_tag { - ULONG ulNext; - ULONG ulPrevious; - ULONG ulDir; - ULONG ulSB; - ULONG ulSize; - int iLevel; - char szName[32]; - UCHAR ucType; + ULONG ulNext; + ULONG ulPrevious; + ULONG ulDir; + ULONG ulSB; + ULONG ulSize; + int iLevel; + char szName[32]; + UCHAR ucType; } pps_entry_type; /* Show that a PPS number or index should not be used */ -#define PPS_NUMBER_INVALID 0xffffffffUL +#define PPS_NUMBER_INVALID 0xffffffffUL /* Macro to make sure all such statements will be identical */ -#define FREE_ALL() \ - do {\ - vDestroySmallBlockList();\ - aulRootList = xfree(aulRootList);\ - aulSbdList = xfree(aulSbdList);\ - aulBbdList = xfree(aulBbdList);\ - aulSBD = xfree(aulSBD);\ - aulBBD = xfree(aulBBD);\ - } while(0) +#define FREE_ALL() \ + do {\ + vDestroySmallBlockList();\ + aulRootList = xfree(aulRootList);\ + aulSbdList = xfree(aulSbdList);\ + aulBbdList = xfree(aulBbdList);\ + aulSBD = xfree(aulSBD);\ + aulBBD = xfree(aulBBD);\ + } while(0) /* * ulReadLong - read four bytes from the given file and offset */ -static ULONG -ulReadLong(FILE *pFile, ULONG ulOffset) -{ - UCHAR aucBytes[4]; +static BOOL +ulReadLong(FILE *pFile, ULONG ulOffset, ULONG *out) { + UCHAR aucBytes[4]; - fail(pFile == NULL); + fail(pFile == NULL); - if (!bReadBytes(aucBytes, 4, ulOffset, pFile)) { - werr(1, "Read long 0x%lx not possible", ulOffset); - } - return ulGetLong(0, aucBytes); + if (!bReadBytes(aucBytes, 4, ulOffset, pFile)) { + return FALSE; + } + + *out = ulGetLong(0, aucBytes); + return TRUE; } /* end of ulReadLong */ /* * vName2String - turn the name into a proper string. */ static void -vName2String(char *szName, const UCHAR *aucBytes, size_t tNameSize) -{ - char *pcChar; - size_t tIndex; +vName2String(char *szName, const UCHAR *aucBytes, size_t tNameSize) { + char *pcChar; + size_t tIndex; - fail(aucBytes == NULL || szName == NULL); + fail(aucBytes == NULL || szName == NULL); - if (tNameSize < 2) { - szName[0] = '\0'; - return; - } - for (tIndex = 0, pcChar = szName; - tIndex < 2 * tNameSize; - tIndex += 2, pcChar++) { - *pcChar = (char)aucBytes[tIndex]; - } - szName[tNameSize - 1] = '\0'; + if (tNameSize < 2) { + szName[0] = '\0'; + return; + } + for (tIndex = 0, pcChar = szName; + tIndex < 2 * tNameSize; + tIndex += 2, pcChar++) { + *pcChar = (char) aucBytes[tIndex]; + } + szName[tNameSize - 1] = '\0'; } /* end of vName2String */ /* @@ -83,28 +83,25 @@ vName2String(char *szName, const UCHAR *aucBytes, size_t tNameSize) */ static size_t tReadBlockIndices(FILE *pFile, ULONG *aulBlockDepot, - size_t tMaxRec, ULONG ulOffset) -{ - size_t tDone; - int iIndex; - UCHAR aucBytes[BIG_BLOCK_SIZE]; + size_t tMaxRec, ULONG ulOffset) { + size_t tDone; + int iIndex; + UCHAR aucBytes[BIG_BLOCK_SIZE]; - fail(pFile == NULL || aulBlockDepot == NULL); - fail(tMaxRec == 0); + fail(pFile == NULL || aulBlockDepot == NULL); + fail(tMaxRec == 0); - /* Read a big block with BBD or SBD indices */ - if (!bReadBytes(aucBytes, BIG_BLOCK_SIZE, ulOffset, pFile)) { - werr(0, "Reading big block from 0x%lx is not possible", - ulOffset); - return 0; - } - /* Split the big block into indices, an index is four bytes */ - tDone = min(tMaxRec, (size_t)BIG_BLOCK_SIZE / 4); - for (iIndex = 0; iIndex < (int)tDone; iIndex++) { - aulBlockDepot[iIndex] = ulGetLong(4 * iIndex, aucBytes); - NO_DBG_DEC(aulBlockDepot[iIndex]); - } - return tDone; + /* Read a big block with BBD or SBD indices */ + if (!bReadBytes(aucBytes, BIG_BLOCK_SIZE, ulOffset, pFile)) { + return 0; + } + /* Split the big block into indices, an index is four bytes */ + tDone = min(tMaxRec, (size_t) BIG_BLOCK_SIZE / 4); + for (iIndex = 0; iIndex < (int) tDone; iIndex++) { + aulBlockDepot[iIndex] = ulGetLong(4 * iIndex, aucBytes); + NO_DBG_DEC(aulBlockDepot[iIndex]); + } + return tDone; } /* end of tReadBlockIndices */ /* @@ -112,29 +109,27 @@ tReadBlockIndices(FILE *pFile, ULONG *aulBlockDepot, */ static BOOL bGetBBD(FILE *pFile, const ULONG *aulDepot, size_t tDepotLen, - ULONG *aulBBD, size_t tBBDLen) -{ - ULONG ulBegin; - size_t tToGo, tDone; - int iIndex; + ULONG *aulBBD, size_t tBBDLen) { + ULONG ulBegin; + size_t tToGo, tDone; + int iIndex; - fail(pFile == NULL || aulDepot == NULL || aulBBD == NULL); + fail(pFile == NULL || aulDepot == NULL || aulBBD == NULL); - DBG_MSG("bGetBBD"); + DBG_MSG("bGetBBD"); - tToGo = tBBDLen; - for (iIndex = 0; iIndex < (int)tDepotLen && tToGo != 0; iIndex++) { - ulBegin = (aulDepot[iIndex] + 1) * BIG_BLOCK_SIZE; - NO_DBG_HEX(ulBegin); - tDone = tReadBlockIndices(pFile, aulBBD, tToGo, ulBegin); - fail(tDone > tToGo); - if (tDone == 0) { - return FALSE; - } - aulBBD += tDone; - tToGo -= tDone; - } - return tToGo == 0; + tToGo = tBBDLen; + for (iIndex = 0; iIndex < (int) tDepotLen && tToGo != 0; iIndex++) { + ulBegin = (aulDepot[iIndex] + 1) * BIG_BLOCK_SIZE; + NO_DBG_HEX(ulBegin); + tDone = tReadBlockIndices(pFile, aulBBD, tToGo, ulBegin); + if (tDone == 0) { + return FALSE; + } + aulBBD += tDone; + tToGo -= tDone; + } + return tToGo == 0; } /* end of bGetBBD */ /* @@ -142,30 +137,29 @@ bGetBBD(FILE *pFile, const ULONG *aulDepot, size_t tDepotLen, */ static BOOL bGetSBD(FILE *pFile, const ULONG *aulDepot, size_t tDepotLen, - ULONG *aulSBD, size_t tSBDLen) -{ - ULONG ulBegin; - size_t tToGo, tDone; - int iIndex; + ULONG *aulSBD, size_t tSBDLen) { + ULONG ulBegin; + size_t tToGo, tDone; + int iIndex; - fail(pFile == NULL || aulDepot == NULL || aulSBD == NULL); + fail(pFile == NULL || aulDepot == NULL || aulSBD == NULL); - DBG_MSG("bGetSBD"); + DBG_MSG("bGetSBD"); - tToGo = tSBDLen; - for (iIndex = 0; iIndex < (int)tDepotLen && tToGo != 0; iIndex++) { - fail(aulDepot[iIndex] >= ULONG_MAX / BIG_BLOCK_SIZE); - ulBegin = (aulDepot[iIndex] + 1) * BIG_BLOCK_SIZE; - NO_DBG_HEX(ulBegin); - tDone = tReadBlockIndices(pFile, aulSBD, tToGo, ulBegin); - fail(tDone > tToGo); - if (tDone == 0) { - return FALSE; - } - aulSBD += tDone; - tToGo -= tDone; - } - return tToGo == 0; + tToGo = tSBDLen; + for (iIndex = 0; iIndex < (int) tDepotLen && tToGo != 0; iIndex++) { + fail(aulDepot[iIndex] >= ULONG_MAX / BIG_BLOCK_SIZE); + ulBegin = (aulDepot[iIndex] + 1) * BIG_BLOCK_SIZE; + NO_DBG_HEX(ulBegin); + tDone = tReadBlockIndices(pFile, aulSBD, tToGo, ulBegin); + fail(tDone > tToGo); + if (tDone == 0) { + return FALSE; + } + aulSBD += tDone; + tToGo -= tDone; + } + return tToGo == 0; } /* end of bGetSBD */ /* @@ -173,43 +167,42 @@ bGetSBD(FILE *pFile, const ULONG *aulDepot, size_t tDepotLen, */ static void vComputePPSlevels(pps_entry_type *atPPSlist, pps_entry_type *pNode, - int iLevel, int iRecursionLevel) -{ - fail(atPPSlist == NULL || pNode == NULL); - fail(iLevel < 0 || iRecursionLevel < 0); + int iLevel, int iRecursionLevel) { + fail(atPPSlist == NULL || pNode == NULL); + fail(iLevel < 0 || iRecursionLevel < 0); - if (iRecursionLevel > 25) { - /* This removes the possibility of an infinite recursion */ - DBG_DEC(iRecursionLevel); - return; - } - if (pNode->iLevel <= iLevel) { - /* Avoid entering a loop */ - DBG_DEC(iLevel); - DBG_DEC(pNode->iLevel); - return; - } + if (iRecursionLevel > 25) { + /* This removes the possibility of an infinite recursion */ + DBG_DEC(iRecursionLevel); + return; + } + if (pNode->iLevel <= iLevel) { + /* Avoid entering a loop */ + DBG_DEC(iLevel); + DBG_DEC(pNode->iLevel); + return; + } - pNode->iLevel = iLevel; + pNode->iLevel = iLevel; - if (pNode->ulDir != PPS_NUMBER_INVALID) { - vComputePPSlevels(atPPSlist, - &atPPSlist[pNode->ulDir], - iLevel + 1, - iRecursionLevel + 1); - } - if (pNode->ulNext != PPS_NUMBER_INVALID) { - vComputePPSlevels(atPPSlist, - &atPPSlist[pNode->ulNext], - iLevel, - iRecursionLevel + 1); - } - if (pNode->ulPrevious != PPS_NUMBER_INVALID) { - vComputePPSlevels(atPPSlist, - &atPPSlist[pNode->ulPrevious], - iLevel, - iRecursionLevel + 1); - } + if (pNode->ulDir != PPS_NUMBER_INVALID) { + vComputePPSlevels(atPPSlist, + &atPPSlist[pNode->ulDir], + iLevel + 1, + iRecursionLevel + 1); + } + if (pNode->ulNext != PPS_NUMBER_INVALID) { + vComputePPSlevels(atPPSlist, + &atPPSlist[pNode->ulNext], + iLevel, + iRecursionLevel + 1); + } + if (pNode->ulPrevious != PPS_NUMBER_INVALID) { + vComputePPSlevels(atPPSlist, + &atPPSlist[pNode->ulPrevious], + iLevel, + iRecursionLevel + 1); + } } /* end of vComputePPSlevels */ /* @@ -219,181 +212,181 @@ vComputePPSlevels(pps_entry_type *atPPSlist, pps_entry_type *pNode, */ static BOOL bGetPPS(FILE *pFile, - const ULONG *aulRootList, size_t tRootListLen, pps_info_type *pPPS) -{ - pps_entry_type *atPPSlist; - ULONG ulBegin, ulOffset, ulTmp; - size_t tNbrOfPPS, tNameSize; - int iIndex, iStartBlock, iRootIndex; - BOOL bWord, bExcel; - UCHAR aucBytes[PROPERTY_SET_STORAGE_SIZE]; + const ULONG *aulRootList, size_t tRootListLen, pps_info_type *pPPS) { + pps_entry_type *atPPSlist; + ULONG ulBegin, ulOffset, ulTmp; + size_t tNbrOfPPS, tNameSize; + int iIndex, iStartBlock, iRootIndex; + BOOL bWord, bExcel; + UCHAR aucBytes[PROPERTY_SET_STORAGE_SIZE]; - fail(pFile == NULL || aulRootList == NULL || pPPS == NULL); + fail(pFile == NULL || aulRootList == NULL || pPPS == NULL); - DBG_MSG("bGetPPS"); + DBG_MSG("bGetPPS"); - NO_DBG_DEC(tRootListLen); + NO_DBG_DEC(tRootListLen); - bWord = FALSE; - bExcel = FALSE; - (void)memset(pPPS, 0, sizeof(*pPPS)); + bWord = FALSE; + bExcel = FALSE; + (void) memset(pPPS, 0, sizeof(*pPPS)); - /* Read and store all the Property Set Storage entries */ + /* Read and store all the Property Set Storage entries */ - tNbrOfPPS = tRootListLen * BIG_BLOCK_SIZE / PROPERTY_SET_STORAGE_SIZE; - atPPSlist = xcalloc(tNbrOfPPS, sizeof(pps_entry_type)); - iRootIndex = 0; + tNbrOfPPS = tRootListLen * BIG_BLOCK_SIZE / PROPERTY_SET_STORAGE_SIZE; + atPPSlist = xcalloc(tNbrOfPPS, sizeof(pps_entry_type)); + iRootIndex = 0; - for (iIndex = 0; iIndex < (int)tNbrOfPPS; iIndex++) { - ulTmp = (ULONG)iIndex * PROPERTY_SET_STORAGE_SIZE; - iStartBlock = (int)(ulTmp / BIG_BLOCK_SIZE); - ulOffset = ulTmp % BIG_BLOCK_SIZE; - ulBegin = (aulRootList[iStartBlock] + 1) * BIG_BLOCK_SIZE + - ulOffset; - NO_DBG_HEX(ulBegin); - if (!bReadBytes(aucBytes, PROPERTY_SET_STORAGE_SIZE, - ulBegin, pFile)) { - werr(0, "Reading PPS %d is not possible", iIndex); - atPPSlist = xfree(atPPSlist); - return FALSE; - } - tNameSize = (size_t)usGetWord(0x40, aucBytes); - tNameSize = (tNameSize + 1) / 2; - if ( tNameSize > sizeof(atPPSlist[iIndex].szName)) { - werr(0, "Name Size of PPS %d is too large", iIndex); - tNameSize = sizeof(atPPSlist[iIndex].szName); - } - vName2String(atPPSlist[iIndex].szName, aucBytes, tNameSize); - atPPSlist[iIndex].ucType = ucGetByte(0x42, aucBytes); - if (atPPSlist[iIndex].ucType == 5) { - iRootIndex = iIndex; - } - atPPSlist[iIndex].ulPrevious = ulGetLong(0x44, aucBytes); - atPPSlist[iIndex].ulNext = ulGetLong(0x48, aucBytes); - atPPSlist[iIndex].ulDir = ulGetLong(0x4c, aucBytes); - atPPSlist[iIndex].ulSB = ulGetLong(0x74, aucBytes); - atPPSlist[iIndex].ulSize = ulGetLong(0x78, aucBytes); - atPPSlist[iIndex].iLevel = INT_MAX; - if ((atPPSlist[iIndex].ulPrevious >= (ULONG)tNbrOfPPS && - atPPSlist[iIndex].ulPrevious != PPS_NUMBER_INVALID) || - (atPPSlist[iIndex].ulNext >= (ULONG)tNbrOfPPS && - atPPSlist[iIndex].ulNext != PPS_NUMBER_INVALID) || - (atPPSlist[iIndex].ulDir >= (ULONG)tNbrOfPPS && - atPPSlist[iIndex].ulDir != PPS_NUMBER_INVALID)) { - DBG_DEC(iIndex); - DBG_DEC(atPPSlist[iIndex].ulPrevious); - DBG_DEC(atPPSlist[iIndex].ulNext); - DBG_DEC(atPPSlist[iIndex].ulDir); - DBG_DEC(tNbrOfPPS); - werr(0, "The Property Set Storage is damaged"); - atPPSlist = xfree(atPPSlist); - return FALSE; - } - } + for (iIndex = 0; iIndex < (int) tNbrOfPPS; iIndex++) { + ulTmp = (ULONG) iIndex * PROPERTY_SET_STORAGE_SIZE; + iStartBlock = (int) (ulTmp / BIG_BLOCK_SIZE); + ulOffset = ulTmp % BIG_BLOCK_SIZE; + ulBegin = (aulRootList[iStartBlock] + 1) * BIG_BLOCK_SIZE + + ulOffset; + NO_DBG_HEX(ulBegin); + if (!bReadBytes(aucBytes, PROPERTY_SET_STORAGE_SIZE, + ulBegin, pFile)) { + werr(0, "Reading PPS %d is not possible", iIndex); + atPPSlist = xfree(atPPSlist); + return FALSE; + } + tNameSize = (size_t) usGetWord(0x40, aucBytes); + tNameSize = (tNameSize + 1) / 2; + if (tNameSize > sizeof(atPPSlist[iIndex].szName)) { + werr(0, "Name Size of PPS %d is too large", iIndex); + tNameSize = sizeof(atPPSlist[iIndex].szName); + } + vName2String(atPPSlist[iIndex].szName, aucBytes, tNameSize); + atPPSlist[iIndex].ucType = ucGetByte(0x42, aucBytes); + if (atPPSlist[iIndex].ucType == 5) { + iRootIndex = iIndex; + } + atPPSlist[iIndex].ulPrevious = ulGetLong(0x44, aucBytes); + atPPSlist[iIndex].ulNext = ulGetLong(0x48, aucBytes); + atPPSlist[iIndex].ulDir = ulGetLong(0x4c, aucBytes); + atPPSlist[iIndex].ulSB = ulGetLong(0x74, aucBytes); + atPPSlist[iIndex].ulSize = ulGetLong(0x78, aucBytes); + atPPSlist[iIndex].iLevel = INT_MAX; + if ((atPPSlist[iIndex].ulPrevious >= (ULONG) tNbrOfPPS && + atPPSlist[iIndex].ulPrevious != PPS_NUMBER_INVALID) || + (atPPSlist[iIndex].ulNext >= (ULONG) tNbrOfPPS && + atPPSlist[iIndex].ulNext != PPS_NUMBER_INVALID) || + (atPPSlist[iIndex].ulDir >= (ULONG) tNbrOfPPS && + atPPSlist[iIndex].ulDir != PPS_NUMBER_INVALID)) { + DBG_DEC(iIndex); + DBG_DEC(atPPSlist[iIndex].ulPrevious); + DBG_DEC(atPPSlist[iIndex].ulNext); + DBG_DEC(atPPSlist[iIndex].ulDir); + DBG_DEC(tNbrOfPPS); + werr(0, "The Property Set Storage is damaged"); + atPPSlist = xfree(atPPSlist); + return FALSE; + } + } #if 0 /* defined(DEBUG) */ - DBG_MSG("Before"); - for (iIndex = 0; iIndex < (int)tNbrOfPPS; iIndex++) { - DBG_MSG(atPPSlist[iIndex].szName); - DBG_HEX(atPPSlist[iIndex].ulDir); - DBG_HEX(atPPSlist[iIndex].ulPrevious); - DBG_HEX(atPPSlist[iIndex].ulNext); - DBG_DEC(atPPSlist[iIndex].ulSB); - DBG_HEX(atPPSlist[iIndex].ulSize); - DBG_DEC(atPPSlist[iIndex].iLevel); - } + DBG_MSG("Before"); + for (iIndex = 0; iIndex < (int)tNbrOfPPS; iIndex++) { + DBG_MSG(atPPSlist[iIndex].szName); + DBG_HEX(atPPSlist[iIndex].ulDir); + DBG_HEX(atPPSlist[iIndex].ulPrevious); + DBG_HEX(atPPSlist[iIndex].ulNext); + DBG_DEC(atPPSlist[iIndex].ulSB); + DBG_HEX(atPPSlist[iIndex].ulSize); + DBG_DEC(atPPSlist[iIndex].iLevel); + } #endif /* DEBUG */ - /* Add level information to each entry */ - vComputePPSlevels(atPPSlist, &atPPSlist[iRootIndex], 0, 0); + /* Add level information to each entry */ + vComputePPSlevels(atPPSlist, &atPPSlist[iRootIndex], 0, 0); - /* Check the entries on level 1 for the required information */ - NO_DBG_MSG("After"); - for (iIndex = 0; iIndex < (int)tNbrOfPPS; iIndex++) { + /* Check the entries on level 1 for the required information */ + NO_DBG_MSG("After"); + for (iIndex = 0; iIndex < (int) tNbrOfPPS; iIndex++) { #if 0 /* defined(DEBUG) */ - DBG_MSG(atPPSlist[iIndex].szName); - DBG_HEX(atPPSlist[iIndex].ulDir); - DBG_HEX(atPPSlist[iIndex].ulPrevious); - DBG_HEX(atPPSlist[iIndex].ulNext); - DBG_DEC(atPPSlist[iIndex].ulSB); - DBG_HEX(atPPSlist[iIndex].ulSize); - DBG_DEC(atPPSlist[iIndex].iLevel); + DBG_MSG(atPPSlist[iIndex].szName); + DBG_HEX(atPPSlist[iIndex].ulDir); + DBG_HEX(atPPSlist[iIndex].ulPrevious); + DBG_HEX(atPPSlist[iIndex].ulNext); + DBG_DEC(atPPSlist[iIndex].ulSB); + DBG_HEX(atPPSlist[iIndex].ulSize); + DBG_DEC(atPPSlist[iIndex].iLevel); #endif /* DEBUG */ - if (atPPSlist[iIndex].iLevel != 1 || - atPPSlist[iIndex].ucType != 2 || - atPPSlist[iIndex].szName[0] == '\0' || - atPPSlist[iIndex].ulSize == 0) { - /* This entry can be ignored */ - continue; - } - if (pPPS->tWordDocument.ulSize == 0 && - STREQ(atPPSlist[iIndex].szName, "WordDocument")) { - pPPS->tWordDocument.ulSB = atPPSlist[iIndex].ulSB; - pPPS->tWordDocument.ulSize = atPPSlist[iIndex].ulSize; - bWord = TRUE; - } else if (pPPS->tData.ulSize == 0 && - STREQ(atPPSlist[iIndex].szName, "Data")) { - pPPS->tData.ulSB = atPPSlist[iIndex].ulSB; - pPPS->tData.ulSize = atPPSlist[iIndex].ulSize; - } else if (pPPS->t0Table.ulSize == 0 && - STREQ(atPPSlist[iIndex].szName, "0Table")) { - pPPS->t0Table.ulSB = atPPSlist[iIndex].ulSB; - pPPS->t0Table.ulSize = atPPSlist[iIndex].ulSize; - } else if (pPPS->t1Table.ulSize == 0 && - STREQ(atPPSlist[iIndex].szName, "1Table")) { - pPPS->t1Table.ulSB = atPPSlist[iIndex].ulSB; - pPPS->t1Table.ulSize = atPPSlist[iIndex].ulSize; - } else if (pPPS->tSummaryInfo.ulSize == 0 && - STREQ(atPPSlist[iIndex].szName, - "\005SummaryInformation")) { - pPPS->tSummaryInfo.ulSB = atPPSlist[iIndex].ulSB; - pPPS->tSummaryInfo.ulSize = atPPSlist[iIndex].ulSize; - } else if (pPPS->tDocSummaryInfo.ulSize == 0 && - STREQ(atPPSlist[iIndex].szName, - "\005DocumentSummaryInformation")) { - pPPS->tDocSummaryInfo.ulSB = atPPSlist[iIndex].ulSB; - pPPS->tDocSummaryInfo.ulSize = atPPSlist[iIndex].ulSize; - } else if (STREQ(atPPSlist[iIndex].szName, "Book") || - STREQ(atPPSlist[iIndex].szName, "Workbook")) { - bExcel = TRUE; - } - } + if (atPPSlist[iIndex].iLevel != 1 || + atPPSlist[iIndex].ucType != 2 || + atPPSlist[iIndex].szName[0] == '\0' || + atPPSlist[iIndex].ulSize == 0) { + /* This entry can be ignored */ + continue; + } + if (pPPS->tWordDocument.ulSize == 0 && + STREQ(atPPSlist[iIndex].szName, "WordDocument")) { + pPPS->tWordDocument.ulSB = atPPSlist[iIndex].ulSB; + pPPS->tWordDocument.ulSize = atPPSlist[iIndex].ulSize; + bWord = TRUE; + } else if (pPPS->tData.ulSize == 0 && + STREQ(atPPSlist[iIndex].szName, "Data")) { + pPPS->tData.ulSB = atPPSlist[iIndex].ulSB; + pPPS->tData.ulSize = atPPSlist[iIndex].ulSize; + } else if (pPPS->t0Table.ulSize == 0 && + STREQ(atPPSlist[iIndex].szName, "0Table")) { + pPPS->t0Table.ulSB = atPPSlist[iIndex].ulSB; + pPPS->t0Table.ulSize = atPPSlist[iIndex].ulSize; + } else if (pPPS->t1Table.ulSize == 0 && + STREQ(atPPSlist[iIndex].szName, "1Table")) { + pPPS->t1Table.ulSB = atPPSlist[iIndex].ulSB; + pPPS->t1Table.ulSize = atPPSlist[iIndex].ulSize; + } else if (pPPS->tSummaryInfo.ulSize == 0 && + STREQ(atPPSlist[iIndex].szName, + "\005SummaryInformation")) { + pPPS->tSummaryInfo.ulSB = atPPSlist[iIndex].ulSB; + pPPS->tSummaryInfo.ulSize = atPPSlist[iIndex].ulSize; + } else if (pPPS->tDocSummaryInfo.ulSize == 0 && + STREQ(atPPSlist[iIndex].szName, + "\005DocumentSummaryInformation")) { + pPPS->tDocSummaryInfo.ulSB = atPPSlist[iIndex].ulSB; + pPPS->tDocSummaryInfo.ulSize = atPPSlist[iIndex].ulSize; + } else if (STREQ(atPPSlist[iIndex].szName, "Book") || + STREQ(atPPSlist[iIndex].szName, "Workbook")) { + bExcel = TRUE; + } + } - /* Free the space for the Property Set Storage entries */ - atPPSlist = xfree(atPPSlist); + /* Free the space for the Property Set Storage entries */ + atPPSlist = xfree(atPPSlist); - /* Draw your conclusions */ - if (bWord) { - return TRUE; - } + /* Draw your conclusions */ + if (bWord) { + return TRUE; + } - if (bExcel) { - werr(0, "Sorry, but this is an Excel spreadsheet"); - } else { - werr(0, "This OLE file does not contain a Word document"); - } - return FALSE; + if (bExcel) { + werr(0, "Sorry, but this is an Excel spreadsheet"); + } else { + werr(0, "This OLE file does not contain a Word document"); + } + return FALSE; } /* end of bGetPPS */ /* * vGetBbdList - make a list of the places to find big blocks */ static void -vGetBbdList(FILE *pFile, int iNbr, ULONG *aulBbdList, ULONG ulOffset) -{ - int iIndex; +vGetBbdList(FILE *pFile, int iNbr, ULONG *aulBbdList, ULONG ulOffset) { + int iIndex; - fail(pFile == NULL); - fail(iNbr > 127); - fail(aulBbdList == NULL); + fail(pFile == NULL); + fail(iNbr > 127); + fail(aulBbdList == NULL); - NO_DBG_DEC(iNbr); - for (iIndex = 0; iIndex < iNbr; iIndex++) { - aulBbdList[iIndex] = - ulReadLong(pFile, ulOffset + 4 * (ULONG)iIndex); - NO_DBG_DEC(iIndex); - NO_DBG_HEX(aulBbdList[iIndex]); + NO_DBG_DEC(iNbr); + for (iIndex = 0; iIndex < iNbr; iIndex++) { + BOOL ok = ulReadLong(pFile, ulOffset + 4 * (ULONG) iIndex, &aulBbdList[iIndex]); + if (!ok) { + return; } + NO_DBG_DEC(iIndex); + NO_DBG_HEX(aulBbdList[iIndex]); + } } /* end of vGetBbdList */ /* @@ -403,134 +396,133 @@ vGetBbdList(FILE *pFile, int iNbr, ULONG *aulBbdList, ULONG ulOffset) */ static BOOL bGetDocumentText(FILE *pFile, const pps_info_type *pPPS, - const ULONG *aulBBD, size_t tBBDLen, - const ULONG *aulSBD, size_t tSBDLen, - const UCHAR *aucHeader, int iWordVersion) -{ - ULONG ulBeginOfText; - ULONG ulTextLen, ulFootnoteLen, ulEndnoteLen; - ULONG ulHdrFtrLen, ulMacroLen, ulAnnotationLen; - ULONG ulTextBoxLen, ulHdrTextBoxLen; - UINT uiQuickSaves; - BOOL bFarEastWord, bTemplate, bFastSaved, bEncrypted, bSuccess; - USHORT usIdent, usDocStatus; + const ULONG *aulBBD, size_t tBBDLen, + const ULONG *aulSBD, size_t tSBDLen, + const UCHAR *aucHeader, int iWordVersion) { + ULONG ulBeginOfText; + ULONG ulTextLen, ulFootnoteLen, ulEndnoteLen; + ULONG ulHdrFtrLen, ulMacroLen, ulAnnotationLen; + ULONG ulTextBoxLen, ulHdrTextBoxLen; + UINT uiQuickSaves; + BOOL bFarEastWord, bTemplate, bFastSaved, bEncrypted, bSuccess; + USHORT usIdent, usDocStatus; - fail(pFile == NULL || pPPS == NULL); - fail(aulBBD == NULL); - fail(aulSBD == NULL); + fail(pFile == NULL || pPPS == NULL); + fail(aulBBD == NULL); + fail(aulSBD == NULL); - DBG_MSG("bGetDocumentText"); + DBG_MSG("bGetDocumentText"); - /* Get the "magic number" from the header */ - usIdent = usGetWord(0x00, aucHeader); - DBG_HEX(usIdent); - bFarEastWord = usIdent == 0x8098 || usIdent == 0x8099 || - usIdent == 0xa697 || usIdent == 0xa699; - /* Get the status flags from the header */ - usDocStatus = usGetWord(0x0a, aucHeader); - DBG_HEX(usDocStatus); - bTemplate = (usDocStatus & BIT(0)) != 0; - DBG_MSG_C(bTemplate, "This document is a Template"); - bFastSaved = (usDocStatus & BIT(2)) != 0; - uiQuickSaves = (UINT)(usDocStatus & 0x00f0) >> 4; - DBG_MSG_C(bFastSaved, "This document is Fast Saved"); - DBG_DEC_C(bFastSaved, uiQuickSaves); - bEncrypted = (usDocStatus & BIT(8)) != 0; - if (bEncrypted) { - werr(0, "Encrypted documents are not supported"); - return FALSE; - } + /* Get the "magic number" from the header */ + usIdent = usGetWord(0x00, aucHeader); + DBG_HEX(usIdent); + bFarEastWord = usIdent == 0x8098 || usIdent == 0x8099 || + usIdent == 0xa697 || usIdent == 0xa699; + /* Get the status flags from the header */ + usDocStatus = usGetWord(0x0a, aucHeader); + DBG_HEX(usDocStatus); + bTemplate = (usDocStatus & BIT(0)) != 0; + DBG_MSG_C(bTemplate, "This document is a Template"); + bFastSaved = (usDocStatus & BIT(2)) != 0; + uiQuickSaves = (UINT) (usDocStatus & 0x00f0) >> 4; + DBG_MSG_C(bFastSaved, "This document is Fast Saved"); + DBG_DEC_C(bFastSaved, uiQuickSaves); + bEncrypted = (usDocStatus & BIT(8)) != 0; + if (bEncrypted) { + werr(0, "Encrypted documents are not supported"); + return FALSE; + } - /* Get length information */ - ulBeginOfText = ulGetLong(0x18, aucHeader); - DBG_HEX(ulBeginOfText); - switch (iWordVersion) { - case 6: - case 7: - ulTextLen = ulGetLong(0x34, aucHeader); - ulFootnoteLen = ulGetLong(0x38, aucHeader); - ulHdrFtrLen = ulGetLong(0x3c, aucHeader); - ulMacroLen = ulGetLong(0x40, aucHeader); - ulAnnotationLen = ulGetLong(0x44, aucHeader); - ulEndnoteLen = ulGetLong(0x48, aucHeader); - ulTextBoxLen = ulGetLong(0x4c, aucHeader); - ulHdrTextBoxLen = ulGetLong(0x50, aucHeader); - break; - case 8: - ulTextLen = ulGetLong(0x4c, aucHeader); - ulFootnoteLen = ulGetLong(0x50, aucHeader); - ulHdrFtrLen = ulGetLong(0x54, aucHeader); - ulMacroLen = ulGetLong(0x58, aucHeader); - ulAnnotationLen = ulGetLong(0x5c, aucHeader); - ulEndnoteLen = ulGetLong(0x60, aucHeader); - ulTextBoxLen = ulGetLong(0x64, aucHeader); - ulHdrTextBoxLen = ulGetLong(0x68, aucHeader); - break; - default: - werr(0, "This version of Word is not supported"); - return FALSE; - } - DBG_DEC(ulTextLen); - DBG_DEC(ulFootnoteLen); - DBG_DEC(ulHdrFtrLen); - DBG_DEC(ulMacroLen); - DBG_DEC(ulAnnotationLen); - DBG_DEC(ulEndnoteLen); - DBG_DEC(ulTextBoxLen); - DBG_DEC(ulHdrTextBoxLen); + /* Get length information */ + ulBeginOfText = ulGetLong(0x18, aucHeader); + DBG_HEX(ulBeginOfText); + switch (iWordVersion) { + case 6: + case 7: + ulTextLen = ulGetLong(0x34, aucHeader); + ulFootnoteLen = ulGetLong(0x38, aucHeader); + ulHdrFtrLen = ulGetLong(0x3c, aucHeader); + ulMacroLen = ulGetLong(0x40, aucHeader); + ulAnnotationLen = ulGetLong(0x44, aucHeader); + ulEndnoteLen = ulGetLong(0x48, aucHeader); + ulTextBoxLen = ulGetLong(0x4c, aucHeader); + ulHdrTextBoxLen = ulGetLong(0x50, aucHeader); + break; + case 8: + ulTextLen = ulGetLong(0x4c, aucHeader); + ulFootnoteLen = ulGetLong(0x50, aucHeader); + ulHdrFtrLen = ulGetLong(0x54, aucHeader); + ulMacroLen = ulGetLong(0x58, aucHeader); + ulAnnotationLen = ulGetLong(0x5c, aucHeader); + ulEndnoteLen = ulGetLong(0x60, aucHeader); + ulTextBoxLen = ulGetLong(0x64, aucHeader); + ulHdrTextBoxLen = ulGetLong(0x68, aucHeader); + break; + default: + werr(0, "This version of Word is not supported"); + return FALSE; + } + DBG_DEC(ulTextLen); + DBG_DEC(ulFootnoteLen); + DBG_DEC(ulHdrFtrLen); + DBG_DEC(ulMacroLen); + DBG_DEC(ulAnnotationLen); + DBG_DEC(ulEndnoteLen); + DBG_DEC(ulTextBoxLen); + DBG_DEC(ulHdrTextBoxLen); - /* Make a list of the text blocks */ - switch (iWordVersion) { - case 6: - case 7: - if (bFastSaved) { - bSuccess = bGet6DocumentText(pFile, - bFarEastWord, - pPPS->tWordDocument.ulSB, - aulBBD, tBBDLen, - aucHeader); - } else { - bSuccess = bAddTextBlocks(ulBeginOfText, - ulTextLen + - ulFootnoteLen + - ulHdrFtrLen + - ulMacroLen + ulAnnotationLen + - ulEndnoteLen + - ulTextBoxLen + ulHdrTextBoxLen, - bFarEastWord, - IGNORE_PROPMOD, - pPPS->tWordDocument.ulSB, - aulBBD, tBBDLen); - } - break; - case 8: - bSuccess = bGet8DocumentText(pFile, - pPPS, - aulBBD, tBBDLen, aulSBD, tSBDLen, - aucHeader); - break; - default: - werr(0, "This version of Word is not supported"); - bSuccess = FALSE; - break; - } + /* Make a list of the text blocks */ + switch (iWordVersion) { + case 6: + case 7: + if (bFastSaved) { + bSuccess = bGet6DocumentText(pFile, + bFarEastWord, + pPPS->tWordDocument.ulSB, + aulBBD, tBBDLen, + aucHeader); + } else { + bSuccess = bAddTextBlocks(ulBeginOfText, + ulTextLen + + ulFootnoteLen + + ulHdrFtrLen + + ulMacroLen + ulAnnotationLen + + ulEndnoteLen + + ulTextBoxLen + ulHdrTextBoxLen, + bFarEastWord, + IGNORE_PROPMOD, + pPPS->tWordDocument.ulSB, + aulBBD, tBBDLen); + } + break; + case 8: + bSuccess = bGet8DocumentText(pFile, + pPPS, + aulBBD, tBBDLen, aulSBD, tSBDLen, + aucHeader); + break; + default: + werr(0, "This version of Word is not supported"); + bSuccess = FALSE; + break; + } - if (bSuccess) { - vSplitBlockList(pFile, - ulTextLen, - ulFootnoteLen, - ulHdrFtrLen, - ulMacroLen, - ulAnnotationLen, - ulEndnoteLen, - ulTextBoxLen, - ulHdrTextBoxLen, - !bFastSaved && iWordVersion == 8); - } else { - vDestroyTextBlockList(); - werr(0, "I can't find the text of this document"); - } - return bSuccess; + if (bSuccess) { + vSplitBlockList(pFile, + ulTextLen, + ulFootnoteLen, + ulHdrFtrLen, + ulMacroLen, + ulAnnotationLen, + ulEndnoteLen, + ulTextBoxLen, + ulHdrTextBoxLen, + !bFastSaved && iWordVersion == 8); + } else { + vDestroyTextBlockList(); + werr(0, "I can't find the text of this document"); + } + return bSuccess; } /* end of bGetDocumentText */ /* @@ -538,82 +530,81 @@ bGetDocumentText(FILE *pFile, const pps_info_type *pPPS, */ static void vGetDocumentData(FILE *pFile, const pps_info_type *pPPS, - const ULONG *aulBBD, size_t tBBDLen, - const UCHAR *aucHeader, int iWordVersion) -{ - options_type tOptions; - ULONG ulBeginOfText; - BOOL bFastSaved, bHasImages, bSuccess; - USHORT usDocStatus; + const ULONG *aulBBD, size_t tBBDLen, + const UCHAR *aucHeader, int iWordVersion) { + options_type tOptions; + ULONG ulBeginOfText; + BOOL bFastSaved, bHasImages, bSuccess; + USHORT usDocStatus; - fail(pFile == NULL); - fail(pPPS == NULL); - fail(aulBBD == NULL); + fail(pFile == NULL); + fail(pPPS == NULL); + fail(aulBBD == NULL); - /* Get the options */ - vGetOptions(&tOptions); + /* Get the options */ + vGetOptions(&tOptions); - /* Get the status flags from the header */ - usDocStatus = usGetWord(0x0a, aucHeader); - DBG_HEX(usDocStatus); - bFastSaved = (usDocStatus & BIT(2)) != 0; - bHasImages = (usDocStatus & BIT(3)) != 0; + /* Get the status flags from the header */ + usDocStatus = usGetWord(0x0a, aucHeader); + DBG_HEX(usDocStatus); + bFastSaved = (usDocStatus & BIT(2)) != 0; + bHasImages = (usDocStatus & BIT(3)) != 0; - if (!bHasImages || - tOptions.eConversionType == conversion_text || - tOptions.eConversionType == conversion_fmt_text || - tOptions.eConversionType == conversion_xml || - tOptions.eImageLevel == level_no_images) { - /* - * No images in the document or text-only output or - * no images wanted, so no data blocks will be needed - */ - vDestroyDataBlockList(); - return; - } + if (!bHasImages || + tOptions.eConversionType == conversion_text || + tOptions.eConversionType == conversion_fmt_text || + tOptions.eConversionType == conversion_xml || + tOptions.eImageLevel == level_no_images) { + /* + * No images in the document or text-only output or + * no images wanted, so no data blocks will be needed + */ + vDestroyDataBlockList(); + return; + } - /* Get length information */ - ulBeginOfText = ulGetLong(0x18, aucHeader); - DBG_HEX(ulBeginOfText); + /* Get length information */ + ulBeginOfText = ulGetLong(0x18, aucHeader); + DBG_HEX(ulBeginOfText); - /* Make a list of the data blocks */ - switch (iWordVersion) { - case 6: - case 7: - /* - * The data blocks are in the text stream. The text stream - * is in "fast saved" format or "normal saved" format - */ - if (bFastSaved) { - bSuccess = bGet6DocumentData(pFile, - pPPS->tWordDocument.ulSB, - aulBBD, tBBDLen, - aucHeader); - } else { - bSuccess = bAddDataBlocks(ulBeginOfText, - (ULONG)LONG_MAX, - pPPS->tWordDocument.ulSB, - aulBBD, tBBDLen); - } - break; - case 8: - /* - * The data blocks are in the data stream. The data stream - * is always in "normal saved" format - */ - bSuccess = bAddDataBlocks(0, (ULONG)LONG_MAX, - pPPS->tData.ulSB, aulBBD, tBBDLen); - break; - default: - werr(0, "This version of Word is not supported"); - bSuccess = FALSE; - break; - } + /* Make a list of the data blocks */ + switch (iWordVersion) { + case 6: + case 7: + /* + * The data blocks are in the text stream. The text stream + * is in "fast saved" format or "normal saved" format + */ + if (bFastSaved) { + bSuccess = bGet6DocumentData(pFile, + pPPS->tWordDocument.ulSB, + aulBBD, tBBDLen, + aucHeader); + } else { + bSuccess = bAddDataBlocks(ulBeginOfText, + (ULONG) LONG_MAX, + pPPS->tWordDocument.ulSB, + aulBBD, tBBDLen); + } + break; + case 8: + /* + * The data blocks are in the data stream. The data stream + * is always in "normal saved" format + */ + bSuccess = bAddDataBlocks(0, (ULONG) LONG_MAX, + pPPS->tData.ulSB, aulBBD, tBBDLen); + break; + default: + werr(0, "This version of Word is not supported"); + bSuccess = FALSE; + break; + } - if (!bSuccess) { - vDestroyDataBlockList(); - werr(0, "I can't find the data of this document"); - } + if (!bSuccess) { + vDestroyDataBlockList(); + werr(0, "I can't find the data of this document"); + } } /* end of vGetDocumentData */ /* @@ -622,187 +613,180 @@ vGetDocumentData(FILE *pFile, const pps_info_type *pPPS, * Returns the version of Word that made the document or -1 */ int -iInitDocumentOLE(FILE *pFile, long lFilesize) -{ - pps_info_type PPS_info; - ULONG *aulBBD, *aulSBD; - ULONG *aulRootList, *aulBbdList, *aulSbdList; - ULONG ulBdbListStart, ulAdditionalBBDlist; - ULONG ulRootStartblock, ulSbdStartblock, ulSBLstartblock; - ULONG ulStart, ulTmp; - long lMaxBlock; - size_t tBBDLen, tSBDLen, tNumBbdBlocks, tRootListLen; - int iWordVersion, iIndex, iToGo; - BOOL bSuccess; - USHORT usIdent, usDocStatus; - UCHAR aucHeader[HEADER_SIZE]; +iInitDocumentOLE(FILE *pFile, long lFilesize) { + pps_info_type PPS_info; + ULONG *aulBBD, *aulSBD; + ULONG *aulRootList, *aulBbdList, *aulSbdList; + ULONG ulBdbListStart, ulAdditionalBBDlist; + ULONG ulRootStartblock, ulSbdStartblock, ulSBLstartblock; + ULONG ulStart, ulTmp; + long lMaxBlock; + size_t tBBDLen, tSBDLen, tNumBbdBlocks, tRootListLen; + int iWordVersion, iIndex, iToGo; + BOOL bSuccess; + USHORT usIdent, usDocStatus; + UCHAR aucHeader[HEADER_SIZE]; - fail(pFile == NULL); + fail(pFile == NULL); - lMaxBlock = lFilesize / BIG_BLOCK_SIZE - 2; - DBG_DEC(lMaxBlock); - if (lMaxBlock < 1) { - return -1; - } - tBBDLen = (size_t)(lMaxBlock + 1); - tNumBbdBlocks = (size_t)ulReadLong(pFile, 0x2c); - DBG_DEC(tNumBbdBlocks); - ulRootStartblock = ulReadLong(pFile, 0x30); - DBG_DEC(ulRootStartblock); - ulSbdStartblock = ulReadLong(pFile, 0x3c); - DBG_DEC(ulSbdStartblock); - ulAdditionalBBDlist = ulReadLong(pFile, 0x44); - DBG_HEX(ulAdditionalBBDlist); - ulSBLstartblock = ulReadLong(pFile, - (ulRootStartblock + 1) * BIG_BLOCK_SIZE + 0x74); - DBG_DEC(ulSBLstartblock); - tSBDLen = (size_t)(ulReadLong(pFile, - (ulRootStartblock + 1) * BIG_BLOCK_SIZE + 0x78) / - SMALL_BLOCK_SIZE); - /* All to be xcalloc-ed pointers to NULL */ - aulRootList = NULL; - aulSbdList = NULL; - aulBbdList = NULL; - aulSBD = NULL; - aulBBD = NULL; + lMaxBlock = lFilesize / BIG_BLOCK_SIZE - 2; + DBG_DEC(lMaxBlock); + if (lMaxBlock < 1) { + return -1; + } + tBBDLen = (size_t) (lMaxBlock + 1); + if (!ulReadLong(pFile, 0x2c, &tNumBbdBlocks)) { return -1; } + if (tNumBbdBlocks > 100000) { + return -1; + } + if (!ulReadLong(pFile, 0x30, &ulRootStartblock)) { return -1; } + if (!ulReadLong(pFile, 0x30, &ulRootStartblock)) { return -1; } + if (!ulReadLong(pFile, 0x3c, &ulSbdStartblock)) { return -1; } + if (!ulReadLong(pFile, 0x44, &ulAdditionalBBDlist)) { return -1; } + if (!ulReadLong(pFile, (ulRootStartblock + 1) * BIG_BLOCK_SIZE + 0x74, &ulSBLstartblock)) { return -1; } + if (!ulReadLong(pFile, (ulRootStartblock + 1) * BIG_BLOCK_SIZE + 0x78, &tSBDLen)) { return -1; } + tSBDLen = tSBDLen / SMALL_BLOCK_SIZE; + /* All to be xcalloc-ed pointers to NULL */ + aulRootList = NULL; + aulSbdList = NULL; + aulBbdList = NULL; + aulSBD = NULL; + aulBBD = NULL; /* Big Block Depot */ - aulBbdList = xcalloc(tNumBbdBlocks, sizeof(ULONG)); - aulBBD = xcalloc(tBBDLen, sizeof(ULONG)); - iToGo = (int)tNumBbdBlocks; - vGetBbdList(pFile, min(iToGo, 109), aulBbdList, 0x4c); - ulStart = 109; - iToGo -= 109; - while (ulAdditionalBBDlist != END_OF_CHAIN && iToGo > 0) { - ulBdbListStart = (ulAdditionalBBDlist + 1) * BIG_BLOCK_SIZE; - vGetBbdList(pFile, min(iToGo, 127), - aulBbdList + ulStart, ulBdbListStart); - ulAdditionalBBDlist = ulReadLong(pFile, - ulBdbListStart + 4 * 127); - DBG_DEC(ulAdditionalBBDlist); - DBG_HEX(ulAdditionalBBDlist); - ulStart += 127; - iToGo -= 127; - } - if (!bGetBBD(pFile, aulBbdList, tNumBbdBlocks, aulBBD, tBBDLen)) { - FREE_ALL(); - return -1; - } - aulBbdList = xfree(aulBbdList); + aulBbdList = xcalloc(tNumBbdBlocks, sizeof(ULONG)); + aulBBD = xcalloc(tBBDLen, sizeof(ULONG)); + iToGo = (int) tNumBbdBlocks; + vGetBbdList(pFile, min(iToGo, 109), aulBbdList, 0x4c); + ulStart = 109; + iToGo -= 109; + while (ulAdditionalBBDlist != END_OF_CHAIN && iToGo > 0) { + ulBdbListStart = (ulAdditionalBBDlist + 1) * BIG_BLOCK_SIZE; + vGetBbdList(pFile, min(iToGo, 127), + aulBbdList + ulStart, ulBdbListStart); + if (!ulReadLong(pFile, ulBdbListStart + 4 * 127, &ulAdditionalBBDlist)) { return -1; } + ulStart += 127; + iToGo -= 127; + } + if (!bGetBBD(pFile, aulBbdList, tNumBbdBlocks, aulBBD, tBBDLen)) { + FREE_ALL(); + return -1; + } + aulBbdList = xfree(aulBbdList); /* Small Block Depot */ - aulSbdList = xcalloc(tBBDLen, sizeof(ULONG)); - aulSBD = xcalloc(tSBDLen, sizeof(ULONG)); - for (iIndex = 0, ulTmp = ulSbdStartblock; - iIndex < (int)tBBDLen && ulTmp != END_OF_CHAIN; - iIndex++, ulTmp = aulBBD[ulTmp]) { - if (ulTmp >= (ULONG)tBBDLen) { - DBG_DEC(ulTmp); - DBG_DEC(tBBDLen); - werr(1, "The Big Block Depot is damaged"); - } - aulSbdList[iIndex] = ulTmp; - NO_DBG_HEX(aulSbdList[iIndex]); - } - if (!bGetSBD(pFile, aulSbdList, tBBDLen, aulSBD, tSBDLen)) { - FREE_ALL(); - return -1; - } - aulSbdList = xfree(aulSbdList); + aulSbdList = xcalloc(tBBDLen, sizeof(ULONG)); + aulSBD = xcalloc(tSBDLen, sizeof(ULONG)); + for (iIndex = 0, ulTmp = ulSbdStartblock; + iIndex < (int) tBBDLen && ulTmp != END_OF_CHAIN; + iIndex++, ulTmp = aulBBD[ulTmp]) { + if (ulTmp >= (ULONG) tBBDLen) { + DBG_DEC(ulTmp); + DBG_DEC(tBBDLen); + return -1; + } + aulSbdList[iIndex] = ulTmp; + NO_DBG_HEX(aulSbdList[iIndex]); + } + if (!bGetSBD(pFile, aulSbdList, tBBDLen, aulSBD, tSBDLen)) { + FREE_ALL(); + return -1; + } + aulSbdList = xfree(aulSbdList); /* Root list */ - for (tRootListLen = 0, ulTmp = ulRootStartblock; - tRootListLen < tBBDLen && ulTmp != END_OF_CHAIN; - tRootListLen++, ulTmp = aulBBD[ulTmp]) { - if (ulTmp >= (ULONG)tBBDLen) { - DBG_DEC(ulTmp); - DBG_DEC(tBBDLen); - werr(1, "The Big Block Depot is damaged"); - } - } - if (tRootListLen == 0) { - werr(0, "No Rootlist found"); - FREE_ALL(); - return -1; - } - aulRootList = xcalloc(tRootListLen, sizeof(ULONG)); - for (iIndex = 0, ulTmp = ulRootStartblock; - iIndex < (int)tBBDLen && ulTmp != END_OF_CHAIN; - iIndex++, ulTmp = aulBBD[ulTmp]) { - if (ulTmp >= (ULONG)tBBDLen) { - DBG_DEC(ulTmp); - DBG_DEC(tBBDLen); - werr(1, "The Big Block Depot is damaged"); - } - aulRootList[iIndex] = ulTmp; - NO_DBG_DEC(aulRootList[iIndex]); - } - fail(tRootListLen != (size_t)iIndex); - bSuccess = bGetPPS(pFile, aulRootList, tRootListLen, &PPS_info); - aulRootList = xfree(aulRootList); - if (!bSuccess) { - FREE_ALL(); - return -1; - } + for (tRootListLen = 0, ulTmp = ulRootStartblock; + tRootListLen < tBBDLen && ulTmp != END_OF_CHAIN; + tRootListLen++, ulTmp = aulBBD[ulTmp]) { + if (ulTmp >= (ULONG) tBBDLen) { + DBG_DEC(ulTmp); + DBG_DEC(tBBDLen); + return -1; + } + } + if (tRootListLen == 0) { + werr(0, "No Rootlist found"); + FREE_ALL(); + return -1; + } + aulRootList = xcalloc(tRootListLen, sizeof(ULONG)); + for (iIndex = 0, ulTmp = ulRootStartblock; + iIndex < (int) tBBDLen && ulTmp != END_OF_CHAIN; + iIndex++, ulTmp = aulBBD[ulTmp]) { + if (ulTmp >= (ULONG) tBBDLen) { + DBG_DEC(ulTmp); + DBG_DEC(tBBDLen); + return -1; + } + aulRootList[iIndex] = ulTmp; + NO_DBG_DEC(aulRootList[iIndex]); + } + fail(tRootListLen != (size_t) iIndex); + bSuccess = bGetPPS(pFile, aulRootList, tRootListLen, &PPS_info); + aulRootList = xfree(aulRootList); + if (!bSuccess) { + FREE_ALL(); + return -1; + } /* Small block list */ - if (!bCreateSmallBlockList(ulSBLstartblock, aulBBD, tBBDLen)) { - FREE_ALL(); - return -1; - } + if (!bCreateSmallBlockList(ulSBLstartblock, aulBBD, tBBDLen)) { + FREE_ALL(); + return -1; + } - if (PPS_info.tWordDocument.ulSize < MIN_SIZE_FOR_BBD_USE) { - DBG_DEC(PPS_info.tWordDocument.ulSize); - FREE_ALL(); - werr(0, "I'm afraid the text stream of this file " - "is too small to handle."); - return -1; - } - /* Read the headerblock */ - if (!bReadBuffer(pFile, PPS_info.tWordDocument.ulSB, - aulBBD, tBBDLen, BIG_BLOCK_SIZE, - aucHeader, 0, HEADER_SIZE)) { - FREE_ALL(); - return -1; - } - usIdent = usGetWord(0x00, aucHeader); - DBG_HEX(usIdent); - fail(usIdent != 0x8098 && /* Word 7 for oriental languages */ - usIdent != 0x8099 && /* Word 7 for oriental languages */ - usIdent != 0xa5dc && /* Word 6 & 7 */ - usIdent != 0xa5ec && /* Word 7 & 97 & 98 */ - usIdent != 0xa697 && /* Word 7 for oriental languages */ - usIdent != 0xa699); /* Word 7 for oriental languages */ - iWordVersion = iGetVersionNumber(aucHeader); - if (iWordVersion < 6) { - FREE_ALL(); - werr(0, "This file is from a version of Word before Word 6."); - return -1; - } + if (PPS_info.tWordDocument.ulSize < MIN_SIZE_FOR_BBD_USE) { + DBG_DEC(PPS_info.tWordDocument.ulSize); + FREE_ALL(); + werr(0, "I'm afraid the text stream of this file " + "is too small to handle."); + return -1; + } + /* Read the headerblock */ + if (!bReadBuffer(pFile, PPS_info.tWordDocument.ulSB, + aulBBD, tBBDLen, BIG_BLOCK_SIZE, + aucHeader, 0, HEADER_SIZE)) { + FREE_ALL(); + return -1; + } + usIdent = usGetWord(0x00, aucHeader); + DBG_HEX(usIdent); + fail(usIdent != 0x8098 && /* Word 7 for oriental languages */ + usIdent != 0x8099 && /* Word 7 for oriental languages */ + usIdent != 0xa5dc && /* Word 6 & 7 */ + usIdent != 0xa5ec && /* Word 7 & 97 & 98 */ + usIdent != 0xa697 && /* Word 7 for oriental languages */ + usIdent != 0xa699); /* Word 7 for oriental languages */ + iWordVersion = iGetVersionNumber(aucHeader); + if (iWordVersion < 6) { + FREE_ALL(); + werr(0, "This file is from a version of Word before Word 6."); + return -1; + } - /* Get the status flags from the header */ - usDocStatus = usGetWord(0x0a, aucHeader); - if (usDocStatus & BIT(9)) { - PPS_info.tTable = PPS_info.t1Table; - } else { - PPS_info.tTable = PPS_info.t0Table; - } - /* Clean the entries that should not be used */ - memset(&PPS_info.t0Table, 0, sizeof(PPS_info.t0Table)); - memset(&PPS_info.t1Table, 0, sizeof(PPS_info.t1Table)); + /* Get the status flags from the header */ + usDocStatus = usGetWord(0x0a, aucHeader); + if (usDocStatus & BIT(9)) { + PPS_info.tTable = PPS_info.t1Table; + } else { + PPS_info.tTable = PPS_info.t0Table; + } + /* Clean the entries that should not be used */ + memset(&PPS_info.t0Table, 0, sizeof(PPS_info.t0Table)); + memset(&PPS_info.t1Table, 0, sizeof(PPS_info.t1Table)); - bSuccess = bGetDocumentText(pFile, &PPS_info, - aulBBD, tBBDLen, aulSBD, tSBDLen, - aucHeader, iWordVersion); - if (bSuccess) { - vGetDocumentData(pFile, &PPS_info, - aulBBD, tBBDLen, aucHeader, iWordVersion); - vGetPropertyInfo(pFile, &PPS_info, - aulBBD, tBBDLen, aulSBD, tSBDLen, - aucHeader, iWordVersion); - vSetDefaultTabWidth(pFile, &PPS_info, - aulBBD, tBBDLen, aulSBD, tSBDLen, - aucHeader, iWordVersion); - vGetNotesInfo(pFile, &PPS_info, - aulBBD, tBBDLen, aulSBD, tSBDLen, - aucHeader, iWordVersion); - } - FREE_ALL(); - return bSuccess ? iWordVersion : -1; + bSuccess = bGetDocumentText(pFile, &PPS_info, + aulBBD, tBBDLen, aulSBD, tSBDLen, + aucHeader, iWordVersion); + if (bSuccess) { + vGetDocumentData(pFile, &PPS_info, + aulBBD, tBBDLen, aucHeader, iWordVersion); + vGetPropertyInfo(pFile, &PPS_info, + aulBBD, tBBDLen, aulSBD, tSBDLen, + aucHeader, iWordVersion); + vSetDefaultTabWidth(pFile, &PPS_info, + aulBBD, tBBDLen, aulSBD, tSBDLen, + aucHeader, iWordVersion); + vGetNotesInfo(pFile, &PPS_info, + aulBBD, tBBDLen, aulSBD, tSBDLen, + aucHeader, iWordVersion); + } + FREE_ALL(); + return bSuccess ? iWordVersion : -1; } /* end of iInitDocumentOLE */ diff --git a/src/xml.c b/src/xml.c index eaa334f..bac48b4 100644 --- a/src/xml.c +++ b/src/xml.c @@ -217,7 +217,7 @@ ucPopStack(void) fail(tStackNextFree == 0); if (tStackNextFree == 0) { - werr(1, "The stack is empty, unable to continue"); +// werr(1, "The stack is empty, unable to continue"); return TAG_NOTAG; } return aucStack[--tStackNextFree]; @@ -504,7 +504,8 @@ vAddEndTag(diagram_type *pDiag, UCHAR ucTag) DBG_DEC(ucTag); DBG_DEC(ucTopTag); DBG_FIXME(); - werr(1, "Impossible tag sequence, unable to continue"); +// werr(1, "Impossible tag sequence, unable to continue"); + return; } if (atDocBookTags[(UINT)ucTag].bAddNewlineEnd) { @@ -1010,7 +1011,7 @@ vEndOfParagraphXML(diagram_type *pDiag, UINT uiMaxLevel) break; case TAG_NOTAG: DBG_FIXME(); - werr(1, "Impossible tag sequence, unable to continue"); +// werr(1, "Impossible tag sequence, unable to continue"); break; default: DBG_DEC(ucTopTag);