ciderpress/reformat/AppleWorks.h

243 lines
9.6 KiB
C
Raw Normal View History

2007-03-27 17:47:10 +00:00
/*
* CiderPress
* Copyright (C) 2007 by faddenSoft, LLC. All Rights Reserved.
* See the file LICENSE for distribution terms.
*/
/*
* Reformat AppleWorks documents.
*/
Large set of changes to restore CiderPress build. CiderPress and MDC now compile, and execute far enough to open their respective "about" boxes, but I doubt they'll do much more than that. * Switch from MBCS to UNICODE APIs Microsoft switched to UTF-16 (by way of UCS-2) a long time ago, and the support for MBCS seems to be getting phased out. So it's time to switch to wide strings. This is a bit awkward for CiderPress because it works with disk and file archives with 8-bit filenames, and I want NufxLib and DiskImgLib to continue to work on Linux (which has largely taken the UTF-8 approach to Unicode). The libraries will continue to work with 8-bit filenames, with CiderPress/MDC doing the conversion at the appropriate point. There were a couple of places where strings from a structure handed back by one of the libraries were used directly in the UI, or vice-versa, which is a problem because we have nowhere to store the result of the conversion. These currently have fixed place-holder "xyzzy" strings. All UI strings are now wide. Various format strings now use "%ls" and "%hs" to explicitly specify wide and narrow. This doesn't play well with gcc, so only the Windows-specific parts use those. * Various updates to vcxproj files The project-file conversion had some cruft that is now largely gone. The build now has a common output directory for the EXEs and libraries, avoiding the old post-build copy steps. * Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots The old "prebuilts" directory is now gone. The libraries are now built as part of building the apps. I added a minimal set of files for zlib, and a full set for nufxlib. The Linux-specific nufxlib goodies are included for the benefit of the Linux utilities, which are currently broken (don't build). * Replace symbols used for include guards Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
#ifndef REFORMAT_APPLEWORKS_H
#define REFORMAT_APPLEWORKS_H
2007-03-27 17:47:10 +00:00
#include "ReformatBase.h"
/*
* Reformat an AppleWorks WP document into formatted text.
*/
class ReformatAWP : public ReformatText {
public:
ReformatAWP(void) { fShowEmbeds = true; }
virtual ~ReformatAWP(void) {}
2007-03-27 17:47:10 +00:00
virtual void Examine(ReformatHolder* pHolder) override;
virtual int Process(const ReformatHolder* pHolder,
ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
ReformatOutput* pOutput) override;
2007-03-27 17:47:10 +00:00
private:
/*
* Constants.
*/
enum {
kFileHeaderSize = 300, /* expected size of FileHeader */
kSeventyNine = 79, /* value of FileHeader.seventyNine */
kSFMinVers30 = 30, /* indicates AW 3.0 */
kTabFlagsIsRuler = 0xff, /* compare against byte 2 of text record */
kCRatEOL = 0x80, /* flag on byte 3 of the text record */
kMinTextChar = 0x20, /* values from 0x01 - 0x1f are special */
kEOFMarker = 0xff, /* two of these found at end of file */
kLineRecordText = 0x00,
kLineRecordCarriageReturn = 0xd0,
kLineRecordCommandMin = 0xd4,
kLineRecordCommandMax = 0xff,
kLineRecordCommandPageHeaderEnd = 0xd5,
kLineRecordCommandPageFooterEnd = 0xd6,
kLineRecordCommandRightJustify = 0xd7,
kLineRecordCommandPlatenWidth = 0xd8, // 10ths of an inch
kLineRecordCommandLeftMargin = 0xd9, // 10ths of an inch
kLineRecordCommandRightMargin = 0xda, // 10ths of an inch
kLineRecordCommandCharsPerInch = 0xdb,
kLineRecordCommandProportional1 = 0xdc,
kLineRecordCommandProportional2 = 0xdd,
kLineRecordCommandIndent = 0xde,
kLineRecordCommandJustify = 0xdf,
kLineRecordCommandUnjustify = 0xe0,
kLineRecordCommandCenter = 0xe1,
kLineRecordCommandPaperLength = 0xe2,
kLineRecordCommandTopMargin = 0xe3,
kLineRecordCommandBottomMargin = 0xe4,
kLineRecordCommandLinesPerInch = 0xe5,
kLineRecordCommandSingleSpace = 0xe6,
kLineRecordCommandDoubleSpace = 0xe7,
kLineRecordCommandTripleSpace = 0xe8,
kLineRecordCommandNewPage = 0xe9,
kLineRecordCommandGroupBegin = 0xea,
kLineRecordCommandGroupEnd = 0xeb,
kLineRecordCommandPageHeader = 0xec,
kLineRecordCommandPageFooter = 0xed,
kLineRecordCommandSkipLines = 0xee,
kLineRecordCommandPageNumber = 0xef,
kLineRecordCommandPauseEachPage = 0xf0,
kLineRecordCommandPauseHere = 0xf1,
kLineRecordCommandSetMarker = 0xf2,
kLineRecordCommandSetPageNumber = 0xf3,
kLineRecordCommandPageBreak = 0xf4,
kLineRecordCommandPageBreak256 = 0xf5,
kLineRecordCommandPageBreakPara = 0xf6,
kLineRecordCommandPageBreakPara256 = 0xf7,
// end of file is 0xff
kSpecialCharBoldBegin = 0x01,
kSpecialCharBoldEnd = 0x02,
kSpecialCharSuperscriptBegin = 0x03,
kSpecialCharSuperscriptEnd = 0x04,
kSpecialCharSubscriptBegin = 0x05,
kSpecialCharSubscriptEnd = 0x06,
kSpecialCharUnderlineBegin = 0x07,
kSpecialCharUnderlineEnd = 0x08,
kSpecialCharPrintPageNumber = 0x09,
kSpecialCharEnterKeyboard = 0x0a,
kSpecialCharStickySpace = 0x0b,
kSpecialCharMailMerge = 0x0c,
// reserved = 0x0d,
kSpecialCharPrintDate = 0x0e,
kSpecialCharPrintTime = 0x0f,
// Special Code N = 0x10-15
kSpecialCharTab = 0x16,
kSpecialCharTabFill = 0x17, /* tab fill char, not vis in doc */
// reserved = 0x18
kMaxSoftFailures = 8, /* give up if it looks like junk */
};
/*
* File header, mapped directly on top of the input. This structure must
* be exactly 300 bytes.
*/
typedef struct FileHeader {
uint8_t unused1[4]; /* 000 - 003: not used */
uint8_t seventyNine; /* 004 : $4f (79) */
uint8_t tabStops[80]; /* 005 - 084: tab stops, one of "=<^>.|" */
uint8_t zoomFlag; /* 085 : boolean Zoom flag */
uint8_t unused2[4]; /* 086 - 089: not used */
uint8_t paginatedFlag; /* 090 : boolean Paginated flag */
uint8_t minLeftMargin; /* 091 : minimum "unseen" left margin */
uint8_t mailMergeFlag; /* 092 : boolean - file has merge cmds */
uint8_t unused3[83]; /* 093 - 175: not used, reserved */
uint8_t multiRulerFlag; /* 176 : (3.0) boolean Multiple Rulers */
uint8_t tabRulers[6]; /* 177 - 182: (3.0) used internally */
uint8_t sfMinVers; /* 183 : (3.0) min version of AW req */
uint8_t unused4[66]; /* 184 - 249: reserved */
uint8_t unused5[50]; /* 250 - 299: available */
} FileHeader;
/*
* Current state of the document.
*/
typedef struct DocState {
long softFailures;
long line;
/* not using these yet */
int leftMargin;
} DocState;
void InitDocState(void);
int ProcessLineRecord(uint8_t lineRecData, uint8_t lineRecCode,
const uint8_t** pSrcPtr, long* pLength);
int HandleTextRecord(uint8_t lineRecData,
const uint8_t** pSrcPtr, long* pLength);
FileHeader fFileHeader;
DocState fDocState;
bool fShowEmbeds;
2007-03-27 17:47:10 +00:00
};
/*
* Reformat an AppleWorks DB document into CSV.
*/
class ReformatADB : public ReformatText {
public:
ReformatADB(void) {}
virtual ~ReformatADB(void) {}
2007-03-27 17:47:10 +00:00
virtual void Examine(ReformatHolder* pHolder) override;
virtual int Process(const ReformatHolder* pHolder,
ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
ReformatOutput* pOutput) override;
2007-03-27 17:47:10 +00:00
private:
enum {
kOffsetToFirstCatHeader = 357,
kMinHeaderLen = 379,
kReportRecordLen = 600,
kCatNameLen = 20,
kCatHeaderLen = 22,
};
2007-03-27 17:47:10 +00:00
};
/*
* Reformat an AppleWorks SS document into CSV.
*/
class ReformatASP : public ReformatText {
public:
ReformatASP(void) { fCurrentRow = fCurrentCol = 1; }
virtual ~ReformatASP(void) {}
2007-03-27 17:47:10 +00:00
virtual void Examine(ReformatHolder* pHolder) override;
virtual int Process(const ReformatHolder* pHolder,
ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
ReformatOutput* pOutput) override;
2007-03-27 17:47:10 +00:00
private:
enum {
kFileHeaderSize = 300,
kPropCount = 8,
kSANELen = 8,
};
/*
* File header, mapped directly on top of the input. This structure must
* be exactly 300 bytes.
*/
typedef struct FileHeader {
uint8_t unused1[4]; /* 000-003: not used */
uint8_t colWidth[127]; /* 004-130: column width for each column */
uint8_t recalcOrder; /* 131 : recalc order ('R' or 'C') */
uint8_t recalcFreq; /* 132 : recalc frequency ('A' or 'M') */
uint8_t lastRowRef[2]; /* 133-134: last row referenced */
uint8_t lastColRef; /* 135 : last column referenced */
uint8_t numWindows; /* 136 : '1'/'S'/'T' */
uint8_t windowSync; /* 137 : if two windows, are sync'ed? */
uint8_t winInfo1[24]; /* 138-161: struct with info for 1st window */
uint8_t winInfo2[24]; /* 162-185: struct with info for 2nd window */
uint8_t unused2[27]; /* 186-212: not used */
uint8_t cellProt; /* 213 : cell protection on/off */
uint8_t unused3; /* 214 : not used */
uint8_t platenWidth; /* 215 : platen width */
uint8_t leftMargin; /* 216 : left margin, in 1/10th inches */
uint8_t rightMargin; /* 217 : right margin */
uint8_t cpi; /* 218 : characters per inch */
uint8_t paperLength; /* 219 : paper length, 1/10th inches */
uint8_t topMargin; /* 220 : top margin */
uint8_t bottomMargin; /* 221 : bottom margin */
uint8_t lpi; /* 222 : lines per inch (6 or 8) */
uint8_t spacing; /* 223 : 'S'ingle, 'D'ouble, or 'T'riple */
uint8_t printerCodes[14];/*224-237: "special codes" for printer */
uint8_t printDash; /* 238 : print dash when entry is blank */
uint8_t reportHeader; /* 239 : print report header */
uint8_t zoomed; /* 240 : zoomed to show formulas */
uint8_t reserved1; /* 241 : used internally (v2.1) */
uint8_t ssMinVers; /* 242 : holds 0 for AW2.x, 0x1e for AW3.x */
uint8_t reserved2[7]; /* 243-249: reserved */
uint8_t available[50]; /* 250-299: available for non-AW app use */
} FileHeader;
int fCurrentRow, fCurrentCol;
char fPrintColBuf[3];
int ProcessRow(int rowNum, const uint8_t** pSrcPtr,
long* pLength);
void ProcessCell(const uint8_t* srcPtr, long cellLength);
void PrintToken(const uint8_t** pSrcPtr, long* pLength);
const char* PrintCol(int col);
double ConvertSANEDouble(const uint8_t* srcPtr);
2007-03-27 17:47:10 +00:00
};
Large set of changes to restore CiderPress build. CiderPress and MDC now compile, and execute far enough to open their respective "about" boxes, but I doubt they'll do much more than that. * Switch from MBCS to UNICODE APIs Microsoft switched to UTF-16 (by way of UCS-2) a long time ago, and the support for MBCS seems to be getting phased out. So it's time to switch to wide strings. This is a bit awkward for CiderPress because it works with disk and file archives with 8-bit filenames, and I want NufxLib and DiskImgLib to continue to work on Linux (which has largely taken the UTF-8 approach to Unicode). The libraries will continue to work with 8-bit filenames, with CiderPress/MDC doing the conversion at the appropriate point. There were a couple of places where strings from a structure handed back by one of the libraries were used directly in the UI, or vice-versa, which is a problem because we have nowhere to store the result of the conversion. These currently have fixed place-holder "xyzzy" strings. All UI strings are now wide. Various format strings now use "%ls" and "%hs" to explicitly specify wide and narrow. This doesn't play well with gcc, so only the Windows-specific parts use those. * Various updates to vcxproj files The project-file conversion had some cruft that is now largely gone. The build now has a common output directory for the EXEs and libraries, avoiding the old post-build copy steps. * Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots The old "prebuilts" directory is now gone. The libraries are now built as part of building the apps. I added a minimal set of files for zlib, and a full set for nufxlib. The Linux-specific nufxlib goodies are included for the benefit of the Linux utilities, which are currently broken (don't build). * Replace symbols used for include guards Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
#endif /*REFORMAT_APPLEWORKS_H*/