Use types with explicit sizes

Much of what the "reformat" code does involves processing data that is
8, 16, or 32 bits.  We want to use size-specific types from stdint.h
(e.g. uint16_t) rather than "unsigned short".

This was a quick pass to replace the various "unsigned" declarations.
More can be done here and elsewhere.
This commit is contained in:
Andy McFadden 2014-11-20 18:10:18 -08:00
parent 0deecec87c
commit 8f61f84585
52 changed files with 679 additions and 689 deletions

View File

@ -1791,7 +1791,7 @@ bail:
* really large files.
*/
CString
DiskArchive::LoadFile(const WCHAR* pathName, BYTE** pBuf, long* pLen,
DiskArchive::LoadFile(const WCHAR* pathName, uint8_t** pBuf, long* pLen,
GenericEntry::ConvertEOL conv, GenericEntry::ConvertHighASCII convHA) const
{
CString errMsg;
@ -1836,7 +1836,7 @@ DiskArchive::LoadFile(const WCHAR* pathName, BYTE** pBuf, long* pLen,
goto bail;
}
*pBuf = new BYTE[fileLen];
*pBuf = new uint8_t[fileLen];
if (*pBuf == NULL) {
errMsg.Format(L"Unable to allocate %ld bytes for '%ls'.",
fileLen, pathName);
@ -3056,8 +3056,8 @@ DiskArchive::XferPrepare(const XferFileOptions* pXferOpts)
* version just tucks the pointers into NufxLib structures.)
*/
CString
DiskArchive::XferFile(FileDetails* pDetails, BYTE** pDataBuf,
long dataLen, BYTE** pRsrcBuf, long rsrcLen)
DiskArchive::XferFile(FileDetails* pDetails, uint8_t** pDataBuf,
long dataLen, uint8_t** pRsrcBuf, long rsrcLen)
{
//const int kFileTypeTXT = 0x04;
DiskFS::CreateParms createParms;

View File

@ -153,8 +153,8 @@ public:
private:
virtual CString Close(void);
virtual void XferPrepare(const XferFileOptions* pXferOpts);
virtual CString XferFile(FileDetails* pDetails, BYTE** pDataBuf,
long dataLen, BYTE** pRsrcBuf, long rsrcLen);
virtual CString XferFile(FileDetails* pDetails, uint8_t** pDataBuf,
long dataLen, uint8_t** pRsrcBuf, long rsrcLen);
virtual void XferAbort(CWnd* pMsgWnd);
virtual void XferFinish(CWnd* pMsgWnd);
@ -222,11 +222,11 @@ private:
NuResult HandleReplaceExisting(const A2File* pExisting,
FileDetails* pDetails);
CString ProcessFileAddData(DiskFS* pDiskFS, int addOptsConvEOL);
CString LoadFile(const WCHAR* pathName, BYTE** pBuf, long* pLen,
CString LoadFile(const WCHAR* pathName, uint8_t** pBuf, long* pLen,
GenericEntry::ConvertEOL conv, GenericEntry::ConvertHighASCII convHA) const;
DIError AddForksToDisk(DiskFS* pDiskFS, const DiskFS::CreateParms* pParms,
const BYTE* dataBuf, long dataLen,
const BYTE* rsrcBuf, long rsrcLen) const;
const uint8_t* dataBuf, long dataLen,
const uint8_t* rsrcBuf, long rsrcLen) const;
void AddToAddDataList(FileAddData* pData);
void FreeAddDataList(void);
void ConvertFDToCP(const FileDetails* pDetails,

View File

@ -440,7 +440,7 @@ DiskEditDialog::SetSpinner(int id, long val)
* Convert a chunk of data into a hex dump, and stuff it into the edit control.
*/
void
DiskEditDialog::DisplayData(const BYTE* srcBuf, int size)
DiskEditDialog::DisplayData(const uint8_t* srcBuf, int size)
{
WCHAR textBuf[80 * 16 * 2];
WCHAR* cp;

View File

@ -49,8 +49,8 @@ public:
virtual int LoadData(void) = 0;
virtual void DisplayData(void) = 0;
virtual void DisplayData(const BYTE* buf, int size);
virtual void DisplayNibbleData(const BYTE* srcBuf, int size);
virtual void DisplayData(const uint8_t* buf, int size);
virtual void DisplayNibbleData(const uint8_t* srcBuf, int size);
bool GetReadOnly(void) const { return fReadOnly; }
void SetReadOnly(bool val) { fReadOnly = val; }
@ -149,7 +149,7 @@ protected:
long fTrack;
long fSector;
BYTE fSectorData[kSectorSize];
uint8_t fSectorData[kSectorSize];
};
/*
@ -229,7 +229,7 @@ protected:
afx_msg virtual void OnOpenFile(void);
long fBlock;
BYTE fBlockData[kBlockSize];
uint8_t fBlockData[kBlockSize];
};
@ -308,7 +308,7 @@ protected:
afx_msg virtual void OnNibbleParms(void) { ASSERT(false); }
long fTrack;
BYTE fNibbleData[DiskImgLib::kTrackAllocSize];
uint8_t fNibbleData[DiskImgLib::kTrackAllocSize];
long fNibbleDataLen;
};

View File

@ -228,10 +228,10 @@ public:
// Utility functions.
const WCHAR* GetFileTypeString(void) const;
static bool CheckHighASCII(const BYTE* buffer,
static bool CheckHighASCII(const uint8_t* buffer,
unsigned long count);
static ConvertEOL DetermineConversion(const BYTE* buffer,
static ConvertEOL DetermineConversion(const uint8_t* buffer,
long count, EOLType* pSourceType, ConvertHighASCII* pConvHA);
static int GenericEntry::WriteConvert(FILE* fp, const char* buf,
size_t len, ConvertEOL* pConv, ConvertHighASCII* pConvHA,
@ -520,8 +520,8 @@ public:
// Transfer files, one at a time, into this archive from another.
virtual void XferPrepare(const XferFileOptions* pXferOpts) = 0;
virtual CString XferFile(FileDetails* pDetails, BYTE** pDataBuf,
long dataLen, BYTE** pRsrcBuf, long rsrcLen) = 0;
virtual CString XferFile(FileDetails* pDetails, uint8_t** pDataBuf,
long dataLen, uint8_t** pRsrcBuf, long rsrcLen) = 0;
virtual void XferAbort(CWnd* pMsgWnd) = 0;
virtual void XferFinish(CWnd* pMsgWnd) = 0;
static void UNIXTimeToDateTime(const time_t* pWhen, NuDateTime *pDateTime);

View File

@ -139,8 +139,8 @@ public:
// save a buffer of data as a file in a disk image or file archive
static bool SaveToArchive(GenericArchive::FileDetails* pDetails,
const BYTE* dataBuf, long dataLen,
const BYTE* rsrcBuf, long rsrcLen,
const uint8_t* dataBuf, long dataLen,
const uint8_t* rsrcBuf, long rsrcLen,
CString& errMsg, CWnd* pDialog);
static const WCHAR kOpenNuFX[];
@ -317,11 +317,11 @@ private:
void BulkConvertImage(const WCHAR* pathName, const WCHAR* targetDir,
const DiskConvertDialog& convDlg, CString* pErrMsg);
int SSTOpenImage(int seqNum, DiskImg* pDiskImg);
int SSTLoadData(int seqNum, DiskImg* pDiskImg, BYTE* trackBuf,
int SSTLoadData(int seqNum, DiskImg* pDiskImg, uint8_t* trackBuf,
long* pBadCount);
long SSTGetBufOffset(int track);
long SSTCountBadBytes(const BYTE* sctBuf, int count);
void SSTProcessTrackData(BYTE* trackBuf);
long SSTCountBadBytes(const uint8_t* sctBuf, int count);
void SSTProcessTrackData(uint8_t* trackBuf);
void VolumeCopier(bool openFile);
bool EditTwoImgProps(const WCHAR* fileName);

View File

@ -1134,7 +1134,7 @@ NufxArchive::AddDisk(ActionProgressDialog* pActionProgress,
ASSERT(pDiskImg != NULL);
/* allocate storage for the entire disk */
diskData = new BYTE[pDiskImg->GetNumBlocks() * kBlockSize];
diskData = new uint8_t[pDiskImg->GetNumBlocks() * kBlockSize];
if (diskData == NULL) {
errMsg.Format(L"Unable to allocate %d bytes.",
pDiskImg->GetNumBlocks() * kBlockSize);
@ -1988,7 +1988,7 @@ NufxArchive::RecompressThread(NufxEntry* pEntry, int threadKind,
/* create a data source for it */
nerr = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed,
0, (const BYTE*)buf, 0, len, ArrayDeleteHandler,
0, (const uint8_t*) buf, 0, len, ArrayDeleteHandler,
&pSource);
if (nerr != kNuErrNone) {
pErrMsg->Format(L"Unable to create NufxLib data source (len=%d).",
@ -2538,7 +2538,7 @@ NufxArchive::SetComment(CWnd* pMsgWnd, GenericEntry* pGenericEntry,
/* create a data source to write from */
nerr = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed,
maxLen, (const BYTE*)(LPCSTR)newStr, 0,
maxLen, (const uint8_t*)(LPCSTR) newStr, 0,
newStr.GetLength(), NULL, &pSource);
if (nerr != kNuErrNone) {
errMsg.Format(L"Unable to create NufxLib data source (len=%d, maxLen=%d).",

View File

@ -29,6 +29,7 @@
#include <shlobj.h>
#include <mmsystem.h>
#include <stdint.h>
#include <stdio.h>
#include <time.h>
#include <string.h>

View File

@ -1552,7 +1552,7 @@ MainWindow::OnToolsSSTMerge(void)
const int kBadCountThreshold = 3072;
DiskImg srcImg0, srcImg1;
CString appName, saveName, saveFolder, errMsg;
BYTE* trackBuf = NULL;
uint8_t* trackBuf = NULL;
long badCount;
// no need to flush -- can't really open raw SST images
@ -1563,7 +1563,7 @@ MainWindow::OnToolsSSTMerge(void)
appName.LoadString(IDS_MB_APP_NAME);
trackBuf = new BYTE[kSSTNumTracks * kSSTTrackLen];
trackBuf = new uint8_t[kSSTNumTracks * kSSTTrackLen];
if (trackBuf == NULL)
goto bail;
@ -1774,11 +1774,11 @@ bail:
* Returns 0 on success, -1 on failure.
*/
int
MainWindow::SSTLoadData(int seqNum, DiskImg* pDiskImg, BYTE* trackBuf,
MainWindow::SSTLoadData(int seqNum, DiskImg* pDiskImg, uint8_t* trackBuf,
long* pBadCount)
{
DIError dierr;
BYTE sctBuf[256];
uint8_t sctBuf[256];
int track, sector;
long bufOffset;

View File

@ -8,15 +8,17 @@
// are changed infrequently
//
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#ifndef _WIN32
/* UNIX includes */
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include <fcntl.h>
#include <ctype.h>
@ -47,9 +49,6 @@
#include <windows.h>
#include <atlstr.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <io.h>
#include <fcntl.h>
@ -65,7 +64,6 @@ typedef unsigned int ssize_t;
#define HAVE__VSNPRINTF
#define strcasecmp stricmp
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

View File

@ -23,15 +23,16 @@
//#include <windows.h>
// C RunTime Header Files
#include <stdint.h>
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>
#include <sys/stat.h>
#include <errno.h>
#include <stdio.h>
#include <assert.h>
//#include <tchar.h>
#include <afxwin.h>
#include <afxcmn.h>
#include <afxdlgs.h>

View File

@ -32,11 +32,11 @@ ReformatAWGS_WP::Process(const ReformatHolder* pHolder,
ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
ReformatOutput* pOutput)
{
const unsigned char* srcBuf = pHolder->GetSourceBuf(part);
const uint8_t* srcBuf = pHolder->GetSourceBuf(part);
long srcLen = pHolder->GetSourceLen(part);
fUseRTF = true;
Chunk doc, header, footer;
unsigned short val;
uint16_t val;
CheckGSCharConv();
@ -149,7 +149,7 @@ ReformatAWGS_WP::Process(const ReformatHolder* pHolder,
* Read one of the chunks of the file.
*/
bool
ReformatAWGS_WP::ReadChunk(const unsigned char** pSrcBuf, long* pSrcLen,
ReformatAWGS_WP::ReadChunk(const uint8_t** pSrcBuf, long* pSrcLen,
Chunk* pChunk)
{
/* starts with the saveArray count */
@ -210,12 +210,12 @@ ReformatAWGS_WP::PrintChunk(const Chunk* pChunk)
{
const int kDefaultStatusBits = kAWGSJustifyLeft | kAWGSSingleSpace;
SaveArrayEntry sae;
const unsigned char* saveArray;
const uint8_t* saveArray;
int saCount;
const unsigned char* blockPtr;
const uint8_t* blockPtr;
long blockLen;
const unsigned char* pRuler;
unsigned short rulerStatusBits;
const uint8_t* pRuler;
uint16_t rulerStatusBits;
saveArray = pChunk->saveArray;
saCount = pChunk->saveArrayCount;
@ -291,12 +291,11 @@ ReformatAWGS_WP::PrintChunk(const Chunk* pChunk)
* skip through them earlier. We don't really need to worry about running
* off the end due to a bad file.
*/
const unsigned char*
const uint8_t*
ReformatAWGS_WP::FindTextBlock(const Chunk* pChunk, int blockNum)
{
const unsigned char* blockPtr = pChunk->textBlocks;
long count = pChunk->numTextBlocks;
unsigned long blockSize;
const uint8_t* blockPtr = pChunk->textBlocks;
uint32_t blockSize;
while (blockNum--) {
blockSize = Get32LE(blockPtr);
@ -315,12 +314,12 @@ ReformatAWGS_WP::FindTextBlock(const Chunk* pChunk, int blockNum)
* Returns the #of bytes consumed.
*/
int
ReformatAWGS_WP::PrintParagraph(const unsigned char* ptr, long maxLen)
ReformatAWGS_WP::PrintParagraph(const uint8_t* ptr, long maxLen)
{
const unsigned char* startPtr = ptr;
unsigned short firstFont;
unsigned char firstStyle, firstSize, firstColor;
unsigned char uch;
const uint8_t* startPtr = ptr;
uint16_t firstFont;
uint8_t firstStyle, firstSize, firstColor;
uint8_t uch;
if (maxLen < 7) {
LOGI("AWGS_WP GLITCH: not enough storage for para header (%d)",
@ -408,9 +407,9 @@ ReformatAWGS_WP::PrintParagraph(const unsigned char* ptr, long maxLen)
/*
* Run through the SaveArray and find the highest-numbered ruler index.
*/
unsigned short
ReformatAWGS_WP::GetNumRulers(const unsigned char* pSaveArray,
unsigned short saveArrayCount)
uint16_t
ReformatAWGS_WP::GetNumRulers(const uint8_t* pSaveArray,
uint16_t saveArrayCount)
{
SaveArrayEntry sa;
int maxRuler = -1;
@ -430,7 +429,7 @@ ReformatAWGS_WP::GetNumRulers(const unsigned char* pSaveArray,
/* there must be at least one paragraph, so this must hold */
assert(maxRuler >= 0);
return (unsigned short) (maxRuler+1);
return (uint16_t) (maxRuler+1);
}
/*
@ -439,12 +438,12 @@ ReformatAWGS_WP::GetNumRulers(const unsigned char* pSaveArray,
*
* These are stored linearly, so we just need to look at the last entry.
*/
unsigned short
ReformatAWGS_WP::GetNumTextBlocks(const unsigned char* pSaveArray,
unsigned short saveArrayCount)
uint16_t
ReformatAWGS_WP::GetNumTextBlocks(const uint8_t* pSaveArray,
uint16_t saveArrayCount)
{
SaveArrayEntry sa;
unsigned short maxTextBlock;
uint16_t maxTextBlock;
assert(saveArrayCount > 0);
UnpackSaveArrayEntry(pSaveArray + (saveArrayCount-1) * kSaveArrayEntryLen,
@ -475,14 +474,14 @@ ReformatAWGS_WP::GetNumTextBlocks(const unsigned char* pSaveArray,
}
#endif
return (unsigned short) (maxTextBlock+1);
return (uint16_t) (maxTextBlock+1);
}
/*
* Unpack a SaveArray entry.
*/
void
ReformatAWGS_WP::UnpackSaveArrayEntry(const unsigned char* pSaveArray,
ReformatAWGS_WP::UnpackSaveArrayEntry(const uint8_t* pSaveArray,
SaveArrayEntry* pSAE)
{
pSAE->textBlock = Get16LE(pSaveArray + 0);
@ -503,11 +502,11 @@ ReformatAWGS_WP::UnpackSaveArrayEntry(const unsigned char* pSaveArray,
* Returns "true" on success, "false" on failure.
*/
bool
ReformatAWGS_WP::SkipTextBlocks(const unsigned char** pSrcBuf,
ReformatAWGS_WP::SkipTextBlocks(const uint8_t** pSrcBuf,
long* pSrcLen, int textBlockCount)
{
unsigned long blockSize;
const unsigned char* srcBuf = *pSrcBuf;
uint32_t blockSize;
const uint8_t* srcBuf = *pSrcBuf;
long srcLen = *pSrcLen;
LOGI("Scanning %d text blocks", textBlockCount);

View File

@ -29,12 +29,12 @@ private:
* Definition of a "SaveArray" entry.
*/
typedef struct SaveArrayEntry {
unsigned short textBlock; // Text Block number
unsigned short offset; // add to offset of text block
unsigned short attributes; // 0=normal text, 1=page break para
unsigned short rulerNum; // number of ruler for this para
unsigned short pixelHeight; // height of para in pixels
unsigned short numLines; // number of lines in this para
uint16_t textBlock; // Text Block number
uint16_t offset; // add to offset of text block
uint16_t attributes; // 0=normal text, 1=page break para
uint16_t rulerNum; // number of ruler for this para
uint16_t pixelHeight; // height of para in pixels
uint16_t numLines; // number of lines in this para
} SaveArrayEntry;
/*
@ -42,12 +42,12 @@ private:
* has the same general structure.
*/
typedef struct Chunk {
const unsigned char* saveArray;
const unsigned char* rulers;
const unsigned char* textBlocks;
unsigned short saveArrayCount;
unsigned short numRulers;
unsigned short numTextBlocks;
const uint8_t* saveArray;
const uint8_t* rulers;
const uint8_t* textBlocks;
uint16_t saveArrayCount;
uint16_t numRulers;
uint16_t numTextBlocks;
} Chunk;
enum {
@ -74,18 +74,18 @@ private:
kAWGSSingleSpace = 0x01
};
bool ReadChunk(const unsigned char** pSrcBuf, long* pSrcLen,
bool ReadChunk(const uint8_t** pSrcBuf, long* pSrcLen,
Chunk* pChunk);
void PrintChunk(const Chunk* pChunk);
const unsigned char* FindTextBlock(const Chunk* pChunk, int blockNum);
int PrintParagraph(const unsigned char* ptr, long maxLen);
unsigned short GetNumRulers(const unsigned char* pSaveArray,
unsigned short saveArrayCount);
unsigned short GetNumTextBlocks(const unsigned char* pSaveArray,
unsigned short saveArrayCount);
void UnpackSaveArrayEntry(const unsigned char* pSaveArray,
const uint8_t* FindTextBlock(const Chunk* pChunk, int blockNum);
int PrintParagraph(const uint8_t* ptr, long maxLen);
uint16_t GetNumRulers(const uint8_t* pSaveArray,
uint16_t saveArrayCount);
uint16_t GetNumTextBlocks(const uint8_t* pSaveArray,
uint16_t saveArrayCount);
void UnpackSaveArrayEntry(const uint8_t* pSaveArray,
SaveArrayEntry* pSAE);
bool SkipTextBlocks(const unsigned char** pSrcBuf,
bool SkipTextBlocks(const uint8_t** pSrcBuf,
long* pSrcLen, int blockCount);
};

View File

@ -49,13 +49,13 @@ ReformatAWP::Process(const ReformatHolder* pHolder,
ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
ReformatOutput* pOutput)
{
const unsigned char* srcPtr = pHolder->GetSourceBuf(part);
const uint8_t* srcPtr = pHolder->GetSourceBuf(part);
long srcLen = pHolder->GetSourceLen(part);
long length = srcLen;
int retval = -1;
bool skipRecord;
uchar lineRecCode, lineRecData;
uint8_t lineRecCode, lineRecData;
if (srcLen > 65536)
fUseRTF = false;
@ -168,8 +168,8 @@ ReformatAWP::InitDocState(void)
* Process a line record.
*/
int
ReformatAWP::ProcessLineRecord(uchar lineRecData, uchar lineRecCode,
const unsigned char** pSrcPtr, long* pLength)
ReformatAWP::ProcessLineRecord(uint8_t lineRecData, uint8_t lineRecCode,
const uint8_t** pSrcPtr, long* pLength)
{
int err = 0;
@ -305,12 +305,12 @@ ReformatAWP::ProcessLineRecord(uchar lineRecData, uchar lineRecCode,
* "lineRecData" has the number of bytes of input that we have yet to read.
*/
int
ReformatAWP::HandleTextRecord(uchar lineRecData,
const unsigned char** pSrcPtr, long* pLength)
ReformatAWP::HandleTextRecord(uint8_t lineRecData,
const uint8_t** pSrcPtr, long* pLength)
{
int err = 0;
uchar tabFlags;
uchar byteCountPlusCR;
uint8_t tabFlags;
uint8_t byteCountPlusCR;
int byteCount = lineRecData;
bool noOutput = false;
int ic;
@ -493,7 +493,7 @@ ReformatADB::Process(const ReformatHolder* pHolder,
ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
ReformatOutput* pOutput)
{
const unsigned char* srcPtr = pHolder->GetSourceBuf(part);
const uint8_t* srcPtr = pHolder->GetSourceBuf(part);
long srcLen = pHolder->GetSourceLen(part);
long length = srcLen;
int retval = -1;
@ -533,7 +533,7 @@ ReformatADB::Process(const ReformatHolder* pHolder,
LOGI(" ADB should be %d reports", numReports);
/* dump category names as first record */
const unsigned char* catPtr;
const uint8_t* catPtr;
int catCount;
catPtr = srcPtr + 357;
catCount = numCats;
@ -544,7 +544,7 @@ ReformatADB::Process(const ReformatHolder* pHolder,
BufPrintf(",\"");
int nameLen = *catPtr;
const unsigned char* namePtr = catPtr + 1;
const uint8_t* namePtr = catPtr + 1;
while (nameLen--) {
if (*namePtr == '"')
BufPrintf("\"\"");
@ -650,7 +650,7 @@ ReformatADB::Process(const ReformatHolder* pHolder,
}
} else {
while (ctrl--) {
unsigned char ch = Read8(&srcPtr, &length);
uint8_t ch = Read8(&srcPtr, &length);
BufPrintf("%c", ch);
if (ch == '"')
BufPrintf("%c", ch);
@ -751,7 +751,7 @@ ReformatASP::Process(const ReformatHolder* pHolder,
ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
ReformatOutput* pOutput)
{
const unsigned char* srcPtr = pHolder->GetSourceBuf(part);
const uint8_t* srcPtr = pHolder->GetSourceBuf(part);
long srcLen = pHolder->GetSourceLen(part);
long length = srcLen;
int retval = -1;
@ -798,7 +798,7 @@ ReformatASP::Process(const ReformatHolder* pHolder,
*/
fCurrentRow = 1;
while (length > 0) {
unsigned short rowLen;
uint16_t rowLen;
int rowNum;
/* row length or EOF marker */
@ -843,10 +843,9 @@ bail:
* Process one row of spreadsheet data.
*/
int
ReformatASP::ProcessRow(int rowNum, const unsigned char** pSrcPtr,
long* pLength)
ReformatASP::ProcessRow(int rowNum, const uint8_t** pSrcPtr, long* pLength)
{
uchar ctrl;
uint8_t ctrl;
bool first = true;
fCurrentCol = 0;
@ -900,9 +899,9 @@ ReformatASP::ProcessRow(int rowNum, const unsigned char** pSrcPtr,
* Process the contents of a single cell.
*/
void
ReformatASP::ProcessCell(const unsigned char* srcPtr, long cellLength)
ReformatASP::ProcessCell(const uint8_t* srcPtr, long cellLength)
{
uchar flag1, flag2;
uint8_t flag1, flag2;
double dval;
int i;
@ -971,7 +970,7 @@ ReformatASP::ProcessCell(const unsigned char* srcPtr, long cellLength)
* several bytes to express.
*/
void
ReformatASP::PrintToken(const unsigned char** pSrcPtr, long* pLength)
ReformatASP::PrintToken(const uint8_t** pSrcPtr, long* pLength)
{
/* string constants; note these must NOT contain '"' chars */
const int kTokenStart = 0xc0;
@ -993,7 +992,7 @@ ReformatASP::PrintToken(const unsigned char** pSrcPtr, long* pLength)
/*0xf8*/ "*", "(", "-" /*unary*/, "+" /*unary*/,
/*0xfc*/ "...", "", "", ""
};
uchar token;
uint8_t token;
token = Read8(pSrcPtr, pLength);
if (token < kTokenStart) {
@ -1039,7 +1038,7 @@ ReformatASP::PrintToken(const unsigned char** pSrcPtr, long* pLength)
return;
}
while (i--) {
unsigned char ch = Read8(pSrcPtr, pLength);
uint8_t ch = Read8(pSrcPtr, pLength);
BufPrintQChar(ch);
}
}
@ -1102,15 +1101,15 @@ ReformatASP::PrintCol(int col)
* -----
*/
double
ReformatASP::ConvertSANEDouble(const unsigned char* srcPtr)
ReformatASP::ConvertSANEDouble(const uint8_t* srcPtr)
{
double newVal;
unsigned char* dptr;
uint8_t* dptr;
int i;
ASSERT(sizeof(newVal) == kSANELen);
dptr = (unsigned char*) &newVal;
dptr = (uint8_t*) &newVal;
for (i = 0; i < kSANELen; i++)
*dptr++ = *srcPtr++;

View File

@ -25,7 +25,6 @@ public:
ReformatOutput* pOutput);
private:
typedef unsigned char uchar;
/*
* Constants.
@ -110,20 +109,20 @@ private:
* be exactly 300 bytes.
*/
typedef struct FileHeader {
uchar unused1[4]; /* 000 - 003: not used */
uchar seventyNine; /* 004 : $4f (79) */
uchar tabStops[80]; /* 005 - 084: tab stops, one of "=<^>.|" */
uchar zoomFlag; /* 085 : boolean Zoom flag */
uchar unused2[4]; /* 086 - 089: not used */
uchar paginatedFlag; /* 090 : boolean Paginated flag */
uchar minLeftMargin; /* 091 : minimum "unseen" left margin */
uchar mailMergeFlag; /* 092 : boolean - file has merge cmds */
uchar unused3[83]; /* 093 - 175: not used, reserved */
uchar multiRulerFlag; /* 176 : (3.0) boolean Multiple Rulers */
uchar tabRulers[6]; /* 177 - 182: (3.0) used internally */
uchar sfMinVers; /* 183 : (3.0) min version of AW req */
uchar unused4[66]; /* 184 - 249: reserved */
uchar unused5[50]; /* 250 - 299: available */
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;
/*
@ -139,10 +138,10 @@ private:
void InitDocState(void);
int ProcessLineRecord(uchar lineRecData, uchar lineRecCode,
const unsigned char** pSrcPtr, long* pLength);
int HandleTextRecord(uchar lineRecData,
const unsigned char** pSrcPtr, long* pLength);
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;
@ -192,54 +191,52 @@ private:
kSANELen = 8,
};
typedef unsigned char uchar;
/*
* File header, mapped directly on top of the input. This structure must
* be exactly 300 bytes.
*/
typedef struct FileHeader {
uchar unused1[4]; /* 000-003: not used */
uchar colWidth[127]; /* 004-130: column width for each column */
uchar recalcOrder; /* 131 : recalc order ('R' or 'C') */
uchar recalcFreq; /* 132 : recalc frequency ('A' or 'M') */
uchar lastRowRef[2]; /* 133-134: last row referenced */
uchar lastColRef; /* 135 : last column referenced */
uchar numWindows; /* 136 : '1'/'S'/'T' */
uchar windowSync; /* 137 : if two windows, are sync'ed? */
uchar winInfo1[24]; /* 138-161: struct with info for 1st window */
uchar winInfo2[24]; /* 162-185: struct with info for 2nd window */
uchar unused2[27]; /* 186-212: not used */
uchar cellProt; /* 213 : cell protection on/off */
uchar unused3; /* 214 : not used */
uchar platenWidth; /* 215 : platen width */
uchar leftMargin; /* 216 : left margin, in 1/10th inches */
uchar rightMargin; /* 217 : right margin */
uchar cpi; /* 218 : characters per inch */
uchar paperLength; /* 219 : paper length, 1/10th inches */
uchar topMargin; /* 220 : top margin */
uchar bottomMargin; /* 221 : bottom margin */
uchar lpi; /* 222 : lines per inch (6 or 8) */
uchar spacing; /* 223 : 'S'ingle, 'D'ouble, or 'T'riple */
uchar printerCodes[14];/*224-237: "special codes" for printer */
uchar printDash; /* 238 : print dash when entry is blank */
uchar reportHeader; /* 239 : print report header */
uchar zoomed; /* 240 : zoomed to show formulas */
uchar reserved1; /* 241 : used internally (v2.1) */
uchar ssMinVers; /* 242 : holds 0 for AW2.x, 0x1e for AW3.x */
uchar reserved2[7]; /* 243-249: reserved */
uchar available[50]; /* 250-299: available for non-AW app use */
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 unsigned char** pSrcPtr,
int ProcessRow(int rowNum, const uint8_t** pSrcPtr,
long* pLength);
void ProcessCell(const unsigned char* srcPtr, long cellLength);
void PrintToken(const unsigned char** 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 unsigned char* srcPtr);
double ConvertSANEDouble(const uint8_t* srcPtr);
};
#endif /*REFORMAT_APPLEWORKS_H*/

View File

@ -79,7 +79,7 @@ ReformatSCAssem::Examine(ReformatHolder* pHolder)
/*static*/ bool
ReformatSCAssem::IsSCAssem(const ReformatHolder* pHolder)
{
const unsigned char* ptr = pHolder->GetSourceBuf(ReformatHolder::kPartData);
const uint8_t* ptr = pHolder->GetSourceBuf(ReformatHolder::kPartData);
long srcLen = pHolder->GetSourceLen(ReformatHolder::kPartData);
int len;
@ -108,7 +108,7 @@ ReformatSCAssem::Process(const ReformatHolder* pHolder,
ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
ReformatOutput* pOutput)
{
const unsigned char* srcPtr = pHolder->GetSourceBuf(part);
const uint8_t* srcPtr = pHolder->GetSourceBuf(part);
long srcLen = pHolder->GetSourceLen(part);
long length = srcLen;
// (this was written before tab stuff in ReformatAsm class existed)
@ -132,8 +132,8 @@ ReformatSCAssem::Process(const ReformatHolder* pHolder,
}
while (length > 0) {
unsigned char lineLen;
unsigned short lineNum;
uint8_t lineLen;
uint16_t lineNum;
/* pull the length byte, which we sanity-check */
lineLen = *srcPtr++;
@ -155,7 +155,7 @@ ReformatSCAssem::Process(const ReformatHolder* pHolder,
} else if (*srcPtr == 0xc0) {
if (length > 2) {
int count = *(srcPtr+1);
unsigned char ch = *(srcPtr+2);
uint8_t ch = *(srcPtr + 2);
srcPtr += 2;
length -= 2;
@ -274,7 +274,7 @@ ReformatMerlin::Examine(ReformatHolder* pHolder)
/*static*/ bool
ReformatMerlin::IsMerlin(const ReformatHolder* pHolder)
{
const unsigned char* ptr = pHolder->GetSourceBuf(ReformatHolder::kPartData);
const uint8_t* ptr = pHolder->GetSourceBuf(ReformatHolder::kPartData);
long srcLen = pHolder->GetSourceLen(ReformatHolder::kPartData);
bool isLineStart = true;
@ -334,14 +334,14 @@ ReformatMerlin::Process(const ReformatHolder* pHolder,
ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
ReformatOutput* pOutput)
{
const unsigned char* srcPtr = pHolder->GetSourceBuf(part);
const uint8_t* srcPtr = pHolder->GetSourceBuf(part);
long srcLen = pHolder->GetSourceLen(part);
long length = srcLen;
int retval = -1;
enum { kStateLabel, kStateMnemonic, kStateOperand, kStateComment };
int tabStop[] = { 0, 9, 15, 26 }; // 1:1 map with state enum
int state;
unsigned char quoteChar = '\0';
uint8_t quoteChar = '\0';
fUseRTF = false;
@ -461,9 +461,9 @@ ReformatLISA2::Examine(ReformatHolder* pHolder)
bool
ReformatLISA2::IsLISA(const ReformatHolder* pHolder)
{
const unsigned char* srcPtr = pHolder->GetSourceBuf(ReformatHolder::kPartData);
const uint8_t* srcPtr = pHolder->GetSourceBuf(ReformatHolder::kPartData);
long srcLen = pHolder->GetSourceLen(ReformatHolder::kPartData);
unsigned short version, len;
uint16_t version, len;
if (srcLen < 8)
return false;
@ -523,7 +523,7 @@ ReformatLISA2::Process(const ReformatHolder* pHolder,
ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
ReformatOutput* pOutput)
{
const unsigned char* srcPtr = pHolder->GetSourceBuf(part);
const uint8_t* srcPtr = pHolder->GetSourceBuf(part);
long srcLen = pHolder->GetSourceLen(part);
long actualLen;
int retval = -1;
@ -535,7 +535,7 @@ ReformatLISA2::Process(const ReformatHolder* pHolder,
goto bail;
}
unsigned short version;
uint16_t version;
version = Read16(&srcPtr, &srcLen); // usually 0x1800; maybe "2.4"?
actualLen = Read16(&srcPtr, &srcLen);
@ -580,10 +580,10 @@ bail:
}
void
ReformatLISA2::ProcessLine(const unsigned char* buf)
ReformatLISA2::ProcessLine(const uint8_t* buf)
{
int len = *buf;
unsigned char uch;
uint8_t uch;
// consume length byte
buf++;
@ -784,7 +784,7 @@ ReformatLISA3::Examine(ReformatHolder* pHolder)
ReformatLISA3::IsLISA(const ReformatHolder* pHolder)
{
bool dosStructure = (pHolder->GetSourceFormat() == ReformatHolder::kSourceFormatDOS);
const unsigned char* srcPtr = pHolder->GetSourceBuf(ReformatHolder::kPartData);
const uint8_t* srcPtr = pHolder->GetSourceBuf(ReformatHolder::kPartData);
long srcLen = pHolder->GetSourceLen(ReformatHolder::kPartData);
if (pHolder->GetSourceFormat() == ReformatHolder::kSourceFormatDOS)
@ -793,7 +793,7 @@ ReformatLISA3::IsLISA(const ReformatHolder* pHolder)
if (srcLen < kHeaderLen+2)
return false; // too short
unsigned short codeLen, symLen;
uint16_t codeLen, symLen;
codeLen = srcPtr[0x00] | srcPtr[0x01] << 8;
symLen = srcPtr[0x02] | srcPtr[0x03] << 8;
@ -822,7 +822,7 @@ ReformatLISA3::Process(const ReformatHolder* pHolder,
ReformatHolder::ReformatID id, ReformatHolder::ReformatPart part,
ReformatOutput* pOutput)
{
const unsigned char* srcPtr = pHolder->GetSourceBuf(part);
const uint8_t* srcPtr = pHolder->GetSourceBuf(part);
long srcLen = pHolder->GetSourceLen(part);
int retval = -1;
@ -833,7 +833,7 @@ ReformatLISA3::Process(const ReformatHolder* pHolder,
fUseRTF = false;
unsigned short codeLen, symLen;
uint16_t codeLen, symLen;
codeLen = srcPtr[0x00] | srcPtr[0x01] << 8;
symLen = srcPtr[0x02] | srcPtr[0x03] << 8;
@ -868,8 +868,8 @@ ReformatLISA3::Process(const ReformatHolder* pHolder,
/*
* Do stuff with source lines.
*/
const unsigned char* codePtr;
const unsigned char* endPtr;
const uint8_t* codePtr;
const uint8_t* endPtr;
int lineNum;
codePtr = srcPtr + kHeaderLen + symLen;
@ -878,7 +878,7 @@ ReformatLISA3::Process(const ReformatHolder* pHolder,
lineNum = 0;
while (codePtr < endPtr) {
unsigned char flagByte;
uint8_t flagByte;
int lineLen;
OutputStart();
@ -967,9 +967,9 @@ bail:
* BIGONE
*/
void
ReformatLISA3::ProcessLine(const unsigned char* codePtr, int len)
ReformatLISA3::ProcessLine(const uint8_t* codePtr, int len)
{
unsigned char mnemonic = 0;
uint8_t mnemonic = 0;
//printf("{code=0x%02x len=%d}", *codePtr, len);
if (*codePtr == kCMNTTKN+1 || *codePtr == kCMNTTKN) {
@ -987,7 +987,7 @@ ReformatLISA3::ProcessLine(const unsigned char* codePtr, int len)
goto bail;
} else if (*codePtr == kMACTKN || *codePtr == kMACTKN+1) {
/* CHKMACRO - handle macro */
unsigned short idx;
uint16_t idx;
mnemonic = *codePtr;
idx = (*codePtr & 0x01) << 8;
idx |= *++codePtr;
@ -999,7 +999,7 @@ ReformatLISA3::ProcessLine(const unsigned char* codePtr, int len)
goto ConvtOperand;
} else if (*codePtr == kLBLTKN || *codePtr == kLBLTKN+1) {
/* CHKCLBL - handle label at start of line */
unsigned short idx;
uint16_t idx;
idx = (*codePtr & 0x01) << 8;
idx |= *++codePtr;
PrintSymEntry(idx);
@ -1055,17 +1055,17 @@ bail:
* CNVOPRND
*/
void
ReformatLISA3::ConvertOperand(unsigned char mnemonic,
const unsigned char** pCodePtr, int* pLen)
ReformatLISA3::ConvertOperand(uint8_t mnemonic,
const uint8_t** pCodePtr, int* pLen)
{
static const char kOPRTRST1[] = "+-*/&|^=<>%<><";
static const char kOPRTRST2[] = "\0\0\0\0\0\0\0\0\0\0\0==>";
const unsigned char* codePtr = *pCodePtr;
const uint8_t* codePtr = *pCodePtr;
int len = *pLen;
OperandResult result;
unsigned char adrsMode = 0;
unsigned char val;
uint8_t adrsMode = 0;
uint8_t val;
//printf("{opr len=%d}", len);
@ -1116,7 +1116,7 @@ ReformatLISA3::ConvertOperand(unsigned char mnemonic,
}
OutOprtr:
unsigned char opr;
uint8_t opr;
if (!len)
break;
@ -1164,7 +1164,7 @@ bail:
* Output a single byte as a binary string.
*/
void
ReformatLISA3::PrintBin(unsigned char val)
ReformatLISA3::PrintBin(uint8_t val)
{
char buf[9];
buf[8] = '\0';
@ -1178,10 +1178,10 @@ ReformatLISA3::PrintBin(unsigned char val)
* OUTNUM
*/
ReformatLISA3::OperandResult
ReformatLISA3::PrintNum(int adrsMode, unsigned char val,
const unsigned char** pCodePtr, int* pLen)
ReformatLISA3::PrintNum(int adrsMode, uint8_t val,
const uint8_t** pCodePtr, int* pLen)
{
const unsigned char* codePtr = *pCodePtr;
const uint8_t* codePtr = *pCodePtr;
int len = *pLen;
OperandResult result = kResultUnknown;
char numBuf[12];
@ -1196,7 +1196,7 @@ ReformatLISA3::PrintNum(int adrsMode, unsigned char val,
len--;
} else if (val == 0x1b) {
// 2-byte decimal
unsigned short num;
uint16_t num;
num = *codePtr++;
num |= *codePtr++ << 8;
len -= 2;
@ -1211,7 +1211,7 @@ ReformatLISA3::PrintNum(int adrsMode, unsigned char val,
} else if (val == 0x1d) {
// 2-byte hex
Output('$');
unsigned short num;
uint16_t num;
num = *codePtr++;
num |= *codePtr++ << 8;
sprintf(numBuf, "%04X", num);
@ -1252,7 +1252,7 @@ ReformatLISA3::PrintNum(int adrsMode, unsigned char val,
Output(val - 0x20);
} else if (val < 0x60) {
// ?6..?9 tokens (+0x5c)
unsigned char newVal = val - 0x24;
uint8_t newVal = val - 0x24;
Output('?');
if (newVal == ';')
Output('#');
@ -1325,8 +1325,8 @@ ReformatLISA3::PrintSymEntry(int ent)
return;
}
const unsigned char* packed = &fSymTab[ent * 8];
unsigned char tmp[8];
const uint8_t* packed = &fSymTab[ent * 8];
uint8_t tmp[8];
int i;
tmp[0] = packed[0] >> 2;
@ -1350,7 +1350,7 @@ ReformatLISA3::PrintSymEntry(int ent)
}
void
ReformatLISA3::PrintMnemonic(unsigned char val)
ReformatLISA3::PrintMnemonic(uint8_t val)
{
const char* ptr = &gMnemonics3[val * 3];
Output(ptr[0]);
@ -1364,7 +1364,7 @@ ReformatLISA3::PrintMnemonic(unsigned char val)
* Prints the comment. Finishes off the operand if necessary.
*/
void
ReformatLISA3::PrintComment(int adrsMode, const unsigned char* codePtr, int len)
ReformatLISA3::PrintComment(int adrsMode, const uint8_t* codePtr, int len)
{
assert(len >= 0);
@ -1448,7 +1448,7 @@ ReformatLISA4::Examine(ReformatHolder* pHolder)
ReformatLISA4::IsLISA(const ReformatHolder* pHolder)
{
bool dosStructure = (pHolder->GetSourceFormat() == ReformatHolder::kSourceFormatDOS);
const unsigned char* srcPtr = pHolder->GetSourceBuf(ReformatHolder::kPartData);
const uint8_t* srcPtr = pHolder->GetSourceBuf(ReformatHolder::kPartData);
long srcLen = pHolder->GetSourceLen(ReformatHolder::kPartData);
if (pHolder->GetSourceFormat() == ReformatHolder::kSourceFormatDOS)
@ -1457,9 +1457,9 @@ ReformatLISA4::IsLISA(const ReformatHolder* pHolder)
if (srcLen < kHeaderLen+2)
return false; // too short
unsigned short version;
unsigned short symEnd;
unsigned short symCount;
uint16_t version;
uint16_t symEnd;
uint16_t symCount;
version = srcPtr[0x00] | srcPtr[0x01] << 8;
symEnd = srcPtr[0x02] | srcPtr[0x03] << 8;
@ -1475,7 +1475,7 @@ ReformatLISA4::IsLISA(const ReformatHolder* pHolder)
return false;;
}
unsigned char opTab, adTab, comTab;
uint8_t opTab, adTab, comTab;
opTab = srcPtr[0x06];
adTab = srcPtr[0x07];
comTab = srcPtr[0x08];
@ -1492,7 +1492,7 @@ ReformatLISA4::IsLISA(const ReformatHolder* pHolder)
return true;
}