Reformatted files to use spaces instead of hard tabs. No substantitve changes.

This commit is contained in:
Andy McFadden 2002-09-21 00:49:42 +00:00
parent ebc52e08c3
commit 768a224513
24 changed files with 10029 additions and 10029 deletions

File diff suppressed because it is too large Load Diff

View File

@ -14,7 +14,7 @@
/*
* ===========================================================================
* Read and write
* Read and write
* ===========================================================================
*/
@ -24,23 +24,23 @@
uchar
Nu_ReadOneC(NuArchive* pArchive, FILE* fp, ushort* pCrc)
{
int ic;
int ic;
Assert(pArchive != nil);
Assert(fp != nil);
Assert(pCrc != nil);
Assert(pArchive != nil);
Assert(fp != nil);
Assert(pCrc != nil);
ic = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
ic = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
return ic;
return ic;
}
uchar
Nu_ReadOne(NuArchive* pArchive, FILE* fp)
{
ushort dummyCrc /*= 0*/;
return Nu_ReadOneC(pArchive, fp, &dummyCrc);
ushort dummyCrc /*= 0*/;
return Nu_ReadOneC(pArchive, fp, &dummyCrc);
}
/*
@ -49,18 +49,18 @@ Nu_ReadOne(NuArchive* pArchive, FILE* fp)
void
Nu_WriteOneC(NuArchive* pArchive, FILE* fp, uchar val, ushort* pCrc)
{
Assert(pArchive != nil);
Assert(fp != nil);
Assert(pCrc != nil);
Assert(pArchive != nil);
Assert(fp != nil);
Assert(pCrc != nil);
putc(val, fp);
putc(val, fp);
}
void
Nu_WriteOne(NuArchive* pArchive, FILE* fp, uchar val)
{
ushort dummyCrc /*= 0*/;
Nu_WriteOneC(pArchive, fp, val, &dummyCrc);
ushort dummyCrc /*= 0*/;
Nu_WriteOneC(pArchive, fp, val, &dummyCrc);
}
@ -70,25 +70,25 @@ Nu_WriteOne(NuArchive* pArchive, FILE* fp, uchar val)
ushort
Nu_ReadTwoC(NuArchive* pArchive, FILE* fp, ushort* pCrc)
{
int ic1, ic2;
int ic1, ic2;
Assert(pArchive != nil);
Assert(fp != nil);
Assert(pCrc != nil);
Assert(pArchive != nil);
Assert(fp != nil);
Assert(pCrc != nil);
ic1 = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic1, *pCrc);
ic2 = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic2, *pCrc);
ic1 = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic1, *pCrc);
ic2 = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic2, *pCrc);
return ic1 | ic2 << 8;
return ic1 | ic2 << 8;
}
ushort
Nu_ReadTwo(NuArchive* pArchive, FILE* fp)
{
ushort dummyCrc /*= 0*/;
return Nu_ReadTwoC(pArchive, fp, &dummyCrc);
ushort dummyCrc /*= 0*/;
return Nu_ReadTwoC(pArchive, fp, &dummyCrc);
}
@ -98,26 +98,26 @@ Nu_ReadTwo(NuArchive* pArchive, FILE* fp)
void
Nu_WriteTwoC(NuArchive* pArchive, FILE* fp, ushort val, ushort* pCrc)
{
int ic1, ic2;
int ic1, ic2;
Assert(pArchive != nil);
Assert(fp != nil);
Assert(pCrc != nil);
Assert(pArchive != nil);
Assert(fp != nil);
Assert(pCrc != nil);
ic1 = val & 0xff;
*pCrc = Nu_UpdateCRC16((uchar)ic1, *pCrc);
ic2 = val >> 8;
*pCrc = Nu_UpdateCRC16((uchar)ic2, *pCrc);
ic1 = val & 0xff;
*pCrc = Nu_UpdateCRC16((uchar)ic1, *pCrc);
ic2 = val >> 8;
*pCrc = Nu_UpdateCRC16((uchar)ic2, *pCrc);
putc(ic1, fp);
putc(ic2, fp);
putc(ic1, fp);
putc(ic2, fp);
}
void
Nu_WriteTwo(NuArchive* pArchive, FILE* fp, ushort val)
{
ushort dummyCrc /*= 0*/;
Nu_WriteTwoC(pArchive, fp, val, &dummyCrc);
ushort dummyCrc /*= 0*/;
Nu_WriteTwoC(pArchive, fp, val, &dummyCrc);
}
@ -127,29 +127,29 @@ Nu_WriteTwo(NuArchive* pArchive, FILE* fp, ushort val)
ulong
Nu_ReadFourC(NuArchive* pArchive, FILE* fp, ushort* pCrc)
{
int ic1, ic2, ic3, ic4;
int ic1, ic2, ic3, ic4;
Assert(pArchive != nil);
Assert(fp != nil);
Assert(pCrc != nil);
Assert(pArchive != nil);
Assert(fp != nil);
Assert(pCrc != nil);
ic1 = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic1, *pCrc);
ic2 = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic2, *pCrc);
ic3 = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic3, *pCrc);
ic4 = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic4, *pCrc);
ic1 = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic1, *pCrc);
ic2 = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic2, *pCrc);
ic3 = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic3, *pCrc);
ic4 = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic4, *pCrc);
return ic1 | ic2 << 8 | (ulong)ic3 << 16 | (ulong)ic4 << 24;
return ic1 | ic2 << 8 | (ulong)ic3 << 16 | (ulong)ic4 << 24;
}
ulong
Nu_ReadFour(NuArchive* pArchive, FILE* fp)
{
ushort dummyCrc /*= 0*/;
return Nu_ReadFourC(pArchive, fp, &dummyCrc);
ushort dummyCrc /*= 0*/;
return Nu_ReadFourC(pArchive, fp, &dummyCrc);
}
@ -159,32 +159,32 @@ Nu_ReadFour(NuArchive* pArchive, FILE* fp)
void
Nu_WriteFourC(NuArchive* pArchive, FILE* fp, ulong val, ushort* pCrc)
{
int ic1, ic2, ic3, ic4;
int ic1, ic2, ic3, ic4;
Assert(pArchive != nil);
Assert(fp != nil);
Assert(pCrc != nil);
Assert(pArchive != nil);
Assert(fp != nil);
Assert(pCrc != nil);
ic1 = val & 0xff;
*pCrc = Nu_UpdateCRC16((uchar)ic1, *pCrc);
ic2 = (val >> 8) & 0xff;
*pCrc = Nu_UpdateCRC16((uchar)ic2, *pCrc);
ic3 = (val >> 16) & 0xff;
*pCrc = Nu_UpdateCRC16((uchar)ic3, *pCrc);
ic4 = val >> 24;
*pCrc = Nu_UpdateCRC16((uchar)ic4, *pCrc);
ic1 = val & 0xff;
*pCrc = Nu_UpdateCRC16((uchar)ic1, *pCrc);
ic2 = (val >> 8) & 0xff;
*pCrc = Nu_UpdateCRC16((uchar)ic2, *pCrc);
ic3 = (val >> 16) & 0xff;
*pCrc = Nu_UpdateCRC16((uchar)ic3, *pCrc);
ic4 = val >> 24;
*pCrc = Nu_UpdateCRC16((uchar)ic4, *pCrc);
putc(ic1, fp);
putc(ic2, fp);
putc(ic3, fp);
putc(ic4, fp);
putc(ic1, fp);
putc(ic2, fp);
putc(ic3, fp);
putc(ic4, fp);
}
void
Nu_WriteFour(NuArchive* pArchive, FILE* fp, ulong val)
{
ushort dummyCrc /*=0*/;
Nu_WriteFourC(pArchive, fp, val, &dummyCrc);
ushort dummyCrc /*=0*/;
Nu_WriteFourC(pArchive, fp, val, &dummyCrc);
}
@ -198,46 +198,46 @@ Nu_WriteFour(NuArchive* pArchive, FILE* fp, ulong val)
NuDateTime
Nu_ReadDateTimeC(NuArchive* pArchive, FILE* fp, ushort* pCrc)
{
NuDateTime temp;
int ic;
NuDateTime temp;
int ic;
Assert(pArchive != nil);
Assert(fp != nil);
Assert(pCrc != nil);
Assert(pArchive != nil);
Assert(fp != nil);
Assert(pCrc != nil);
ic = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
temp.second = ic;
ic = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
temp.minute = ic;
ic = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
temp.hour = ic;
ic = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
temp.year = ic;
ic = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
temp.day = ic;
ic = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
temp.month = ic;
ic = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
temp.extra = ic;
ic = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
temp.weekDay = ic;
ic = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
temp.second = ic;
ic = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
temp.minute = ic;
ic = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
temp.hour = ic;
ic = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
temp.year = ic;
ic = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
temp.day = ic;
ic = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
temp.month = ic;
ic = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
temp.extra = ic;
ic = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
temp.weekDay = ic;
return temp;
return temp;
}
NuDateTime
Nu_ReadDateTime(NuArchive* pArchive, FILE* fp, ushort* pCrc)
{
ushort dummyCrc /*= 0*/;
return Nu_ReadDateTimeC(pArchive, fp, &dummyCrc);
ushort dummyCrc /*= 0*/;
return Nu_ReadDateTimeC(pArchive, fp, &dummyCrc);
}
@ -246,45 +246,45 @@ Nu_ReadDateTime(NuArchive* pArchive, FILE* fp, ushort* pCrc)
*/
void
Nu_WriteDateTimeC(NuArchive* pArchive, FILE* fp, NuDateTime dateTime,
ushort* pCrc)
ushort* pCrc)
{
int ic;
int ic;
Assert(pArchive != nil);
Assert(fp != nil);
Assert(pCrc != nil);
Assert(pArchive != nil);
Assert(fp != nil);
Assert(pCrc != nil);
ic = dateTime.second;
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
putc(ic, fp);
ic = dateTime.minute;
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
putc(ic, fp);
ic = dateTime.hour;
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
putc(ic, fp);
ic = dateTime.year;
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
putc(ic, fp);
ic = dateTime.day;
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
putc(ic, fp);
ic = dateTime.month;
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
putc(ic, fp);
ic = dateTime.extra;
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
putc(ic, fp);
ic = dateTime.weekDay;
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
putc(ic, fp);
ic = dateTime.second;
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
putc(ic, fp);
ic = dateTime.minute;
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
putc(ic, fp);
ic = dateTime.hour;
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
putc(ic, fp);
ic = dateTime.year;
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
putc(ic, fp);
ic = dateTime.day;
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
putc(ic, fp);
ic = dateTime.month;
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
putc(ic, fp);
ic = dateTime.extra;
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
putc(ic, fp);
ic = dateTime.weekDay;
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
putc(ic, fp);
}
void
Nu_WriteDateTime(NuArchive* pArchive, FILE* fp, NuDateTime dateTime)
{
ushort dummyCrc /*= 0*/;
Nu_WriteDateTimeC(pArchive, fp, dateTime, &dummyCrc);
ushort dummyCrc /*= 0*/;
Nu_WriteDateTimeC(pArchive, fp, dateTime, &dummyCrc);
}
@ -293,29 +293,29 @@ Nu_WriteDateTime(NuArchive* pArchive, FILE* fp, NuDateTime dateTime)
*/
void
Nu_ReadBytesC(NuArchive* pArchive, FILE* fp, void* vbuffer, long count,
ushort* pCrc)
ushort* pCrc)
{
uchar* buffer = vbuffer;
int ic;
uchar* buffer = vbuffer;
int ic;
Assert(pArchive != nil);
Assert(fp != nil);
Assert(pCrc != nil);
Assert(buffer != nil);
Assert(count > 0);
Assert(pArchive != nil);
Assert(fp != nil);
Assert(pCrc != nil);
Assert(buffer != nil);
Assert(count > 0);
while (count--) {
ic = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
*buffer++ = ic;
}
while (count--) {
ic = getc(fp);
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
*buffer++ = ic;
}
}
void
Nu_ReadBytes(NuArchive* pArchive, FILE* fp, void* vbuffer, long count)
{
ushort dummyCrc /*= 0*/;
Nu_ReadBytesC(pArchive, fp, vbuffer, count, &dummyCrc);
ushort dummyCrc /*= 0*/;
Nu_ReadBytesC(pArchive, fp, vbuffer, count, &dummyCrc);
}
@ -324,35 +324,35 @@ Nu_ReadBytes(NuArchive* pArchive, FILE* fp, void* vbuffer, long count)
*/
void
Nu_WriteBytesC(NuArchive* pArchive, FILE* fp, const void* vbuffer, long count,
ushort* pCrc)
ushort* pCrc)
{
const uchar* buffer = vbuffer;
int ic;
const uchar* buffer = vbuffer;
int ic;
Assert(pArchive != nil);
Assert(fp != nil);
Assert(pCrc != nil);
Assert(buffer != nil);
Assert(count > 0);
Assert(pArchive != nil);
Assert(fp != nil);
Assert(pCrc != nil);
Assert(buffer != nil);
Assert(count > 0);
while (count--) {
ic = *buffer++;
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
putc(ic, fp);
}
while (count--) {
ic = *buffer++;
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
putc(ic, fp);
}
}
void
Nu_WriteBytes(NuArchive* pArchive, FILE* fp, const void* vbuffer, long count)
{
ushort dummyCrc /*= 0*/;
Nu_WriteBytesC(pArchive, fp, vbuffer, count, &dummyCrc);
ushort dummyCrc /*= 0*/;
Nu_WriteBytesC(pArchive, fp, vbuffer, count, &dummyCrc);
}
/*
* ===========================================================================
* General
* General
* ===========================================================================
*/
@ -363,10 +363,10 @@ Nu_WriteBytes(NuArchive* pArchive, FILE* fp, const void* vbuffer, long count)
NuError
Nu_HeaderIOFailed(NuArchive* pArchive, FILE* fp)
{
if (feof(fp) || ferror(fp))
return kNuErrFile;
else
return kNuErrNone;
if (feof(fp) || ferror(fp))
return kNuErrFile;
else
return kNuErrNone;
}
@ -379,22 +379,22 @@ Nu_HeaderIOFailed(NuArchive* pArchive, FILE* fp)
NuError
Nu_SeekArchive(NuArchive* pArchive, FILE* fp, long offset, int ptrname)
{
if (Nu_IsStreaming(pArchive)) {
Assert(ptrname == SEEK_CUR);
Assert(offset > 0);
if (Nu_IsStreaming(pArchive)) {
Assert(ptrname == SEEK_CUR);
Assert(offset > 0);
/* might be faster to fread a chunk at a time */
while (offset--)
(void) getc(fp);
/* might be faster to fread a chunk at a time */
while (offset--)
(void) getc(fp);
if (ferror(fp) || feof(fp))
return kNuErrFileSeek;
} else {
if (fseek(fp, offset, ptrname) < 0)
return kNuErrFileSeek;
}
if (ferror(fp) || feof(fp))
return kNuErrFileSeek;
} else {
if (fseek(fp, offset, ptrname) < 0)
return kNuErrFileSeek;
}
return kNuErrNone;
return kNuErrNone;
}
@ -406,15 +406,15 @@ Nu_SeekArchive(NuArchive* pArchive, FILE* fp, long offset, int ptrname)
NuError
Nu_RewindArchive(NuArchive* pArchive)
{
Assert(pArchive != nil);
Assert(!Nu_IsStreaming(pArchive));
Assert(pArchive != nil);
Assert(!Nu_IsStreaming(pArchive));
if (Nu_SeekArchive(pArchive, pArchive->archiveFp,
pArchive->headerOffset + kNuMasterHeaderSize, SEEK_SET) != 0)
return kNuErrFileSeek;
if (Nu_SeekArchive(pArchive, pArchive->archiveFp,
pArchive->headerOffset + kNuMasterHeaderSize, SEEK_SET) != 0)
return kNuErrFileSeek;
pArchive->currentOffset = pArchive->headerOffset + kNuMasterHeaderSize;
return kNuErrNone;
pArchive->currentOffset = pArchive->headerOffset + kNuMasterHeaderSize;
return kNuErrNone;
}

View File

@ -9,7 +9,7 @@
#include "NufxLibPriv.h"
/* for ShrinkIt-mimic mode, don't compress files under 512 bytes */
#define kNuSHKLZWThreshold 512
#define kNuSHKLZWThreshold 512
/*
@ -17,45 +17,45 @@
*/
static NuError
Nu_CompressUncompressed(NuArchive* pArchive, NuStraw* pStraw,
FILE* fp, ulong srcLen, ulong* pDstLen, ushort *pCrc)
FILE* fp, ulong srcLen, ulong* pDstLen, ushort *pCrc)
{
NuError err = kNuErrNone;
/*uchar* buffer = nil;*/
ulong count, getsize;
NuError err = kNuErrNone;
/*uchar* buffer = nil;*/
ulong count, getsize;
Assert(pArchive != nil);
Assert(pStraw != nil);
Assert(fp != nil);
Assert(srcLen > 0);
Assert(pArchive != nil);
Assert(pStraw != nil);
Assert(fp != nil);
Assert(srcLen > 0);
*pDstLen = srcLen; /* get this over with */
*pDstLen = srcLen; /* get this over with */
/* doesn't have to be same size as funnel, but it's not a bad idea */
/*buffer = Nu_Malloc(pArchive, kNuFunnelBufSize);*/
/*BailAlloc(buffer);*/
err = Nu_AllocCompressionBufferIFN(pArchive);
BailError(err);
/* doesn't have to be same size as funnel, but it's not a bad idea */
/*buffer = Nu_Malloc(pArchive, kNuFunnelBufSize);*/
/*BailAlloc(buffer);*/
err = Nu_AllocCompressionBufferIFN(pArchive);
BailError(err);
if (pCrc != nil)
*pCrc = kNuInitialThreadCRC;
count = srcLen;
if (pCrc != nil)
*pCrc = kNuInitialThreadCRC;
count = srcLen;
while (count) {
getsize = (count > kNuGenCompBufSize) ? kNuGenCompBufSize : count;
while (count) {
getsize = (count > kNuGenCompBufSize) ? kNuGenCompBufSize : count;
err = Nu_StrawRead(pArchive, pStraw, pArchive->compBuf, getsize);
BailError(err);
if (pCrc != nil)
*pCrc = Nu_CalcCRC16(*pCrc, pArchive->compBuf, getsize);
err = Nu_FWrite(fp, pArchive->compBuf, getsize);
BailError(err);
err = Nu_StrawRead(pArchive, pStraw, pArchive->compBuf, getsize);
BailError(err);
if (pCrc != nil)
*pCrc = Nu_CalcCRC16(*pCrc, pArchive->compBuf, getsize);
err = Nu_FWrite(fp, pArchive->compBuf, getsize);
BailError(err);
count -= getsize;
}
count -= getsize;
}
bail:
/*Nu_Free(pArchive, buffer);*/
return err;
/*Nu_Free(pArchive, buffer);*/
return err;
}
@ -67,14 +67,14 @@ bail:
* not be modified.
*
* If "sourceFormat" is uncompressed:
* "targetFormat" will be used to compress the data
* the data source length will be placed into pThread->thThreadEOF
* the compressed size will be placed into pThread->thCompThreadEOF
* "targetFormat" will be used to compress the data
* the data source length will be placed into pThread->thThreadEOF
* the compressed size will be placed into pThread->thCompThreadEOF
*
* If "sourceFormat" is compressed:
* the data will be copied without compression (targetFormat is ignored)
* the data source "otherLen" value will be placed into pThread->thThreadEOF
* the data source length will be placed into pThread->thCompThreadEOF
* the data will be copied without compression (targetFormat is ignored)
* the data source "otherLen" value will be placed into pThread->thThreadEOF
* the data source length will be placed into pThread->thCompThreadEOF
*
* The actual format used will be placed in pThread->thThreadFormat, and
* the CRC of the uncompressed data will be placed in pThread->thThreadCRC.
@ -86,184 +86,184 @@ bail:
*/
NuError
Nu_CompressToArchive(NuArchive* pArchive, NuDataSource* pDataSource,
NuThreadID threadID, NuThreadFormat sourceFormat,
NuThreadFormat targetFormat, NuProgressData* pProgressData, FILE* dstFp,
NuThread* pThread)
NuThreadID threadID, NuThreadFormat sourceFormat,
NuThreadFormat targetFormat, NuProgressData* pProgressData, FILE* dstFp,
NuThread* pThread)
{
NuError err;
long origOffset;
NuStraw* pStraw = nil;
NuDataSink* pDataSink = nil;
ulong srcLen, dstLen;
ushort threadCrc;
NuError err;
long origOffset;
NuStraw* pStraw = nil;
NuDataSink* pDataSink = nil;
ulong srcLen, dstLen;
ushort threadCrc;
Assert(pArchive != nil);
Assert(pDataSource != nil);
/* okay if pProgressData is nil */
Assert(dstFp != nil);
Assert(pThread != nil);
Assert(pArchive != nil);
Assert(pDataSource != nil);
/* okay if pProgressData is nil */
Assert(dstFp != nil);
Assert(pThread != nil);
/* remember file offset, so we can back up if compression fails */
err = Nu_FTell(dstFp, &origOffset);
BailError(err);
Assert(origOffset == pThread->fileOffset); /* can get rid of ftell? */
/* remember file offset, so we can back up if compression fails */
err = Nu_FTell(dstFp, &origOffset);
BailError(err);
Assert(origOffset == pThread->fileOffset); /* can get rid of ftell? */
/* fill in some thread fields */
threadCrc = kNuInitialThreadCRC;
/* fill in some thread fields */
threadCrc = kNuInitialThreadCRC;
pThread->thThreadClass = NuThreadIDGetClass(threadID);
pThread->thThreadKind = NuThreadIDGetKind(threadID);
pThread->actualThreadEOF = (ulong)-1;
/* nuThreadIdx and fileOffset should already be set */
pThread->thThreadClass = NuThreadIDGetClass(threadID);
pThread->thThreadKind = NuThreadIDGetKind(threadID);
pThread->actualThreadEOF = (ulong)-1;
/* nuThreadIdx and fileOffset should already be set */
/*
* Get the input length. For "buffer" and "fp" sources, this is just
* a value passed in. For "file" sources, this is the length of the
* file on disk. The file should already have been opened successfully
* by the caller.
*
* If the input file is zero bytes long, "store" it uncompressed and
* bail immediately.
*
* (Our desire to store uncompressible data without compression clashes
* with a passing interest in doing CRLF conversions on input data. We
* want to know the length ahead of time, which potentially makes the
* compression code simpler, but prevents us from doing the conversion
* unless we pre-flight the conversion with a separate pass through the
* input file. Of course, it's still possible for the application to
* convert the file into a temp file and add from there, so all is
* not lost.)
*/
srcLen = Nu_DataSourceGetDataLen(pDataSource);
/*DBUG(("+++ input file length is %lu\n", srcLen));*/
/*
* Get the input length. For "buffer" and "fp" sources, this is just
* a value passed in. For "file" sources, this is the length of the
* file on disk. The file should already have been opened successfully
* by the caller.
*
* If the input file is zero bytes long, "store" it uncompressed and
* bail immediately.
*
* (Our desire to store uncompressible data without compression clashes
* with a passing interest in doing CRLF conversions on input data. We
* want to know the length ahead of time, which potentially makes the
* compression code simpler, but prevents us from doing the conversion
* unless we pre-flight the conversion with a separate pass through the
* input file. Of course, it's still possible for the application to
* convert the file into a temp file and add from there, so all is
* not lost.)
*/
srcLen = Nu_DataSourceGetDataLen(pDataSource);
/*DBUG(("+++ input file length is %lu\n", srcLen));*/
/*
* Create a "Straw" to slurp the input through and track progress.
*/
err = Nu_StrawNew(pArchive, pDataSource, pProgressData, &pStraw);
BailError(err);
/*
* Create a "Straw" to slurp the input through and track progress.
*/
err = Nu_StrawNew(pArchive, pDataSource, pProgressData, &pStraw);
BailError(err);
if (!srcLen) {
/* empty file! */
pThread->thThreadFormat = kNuThreadFormatUncompressed;
pThread->thThreadCRC = threadCrc;
pThread->thThreadEOF = 0;
pThread->thCompThreadEOF = 0;
pThread->actualThreadEOF = 0;
goto done; /* send final progress message */
}
if (!srcLen) {
/* empty file! */
pThread->thThreadFormat = kNuThreadFormatUncompressed;
pThread->thThreadCRC = threadCrc;
pThread->thThreadEOF = 0;
pThread->thCompThreadEOF = 0;
pThread->actualThreadEOF = 0;
goto done; /* send final progress message */
}
if (sourceFormat == kNuThreadFormatUncompressed) {
/*
* Compress the input.
*/
if (sourceFormat == kNuThreadFormatUncompressed) {
/*
* Compress the input.
*/
/* GSHK doesn't compress anything under 512 bytes */
if (pArchive->valMimicSHK && srcLen < kNuSHKLZWThreshold)
targetFormat = kNuThreadFormatUncompressed;
/* GSHK doesn't compress anything under 512 bytes */
if (pArchive->valMimicSHK && srcLen < kNuSHKLZWThreshold)
targetFormat = kNuThreadFormatUncompressed;
if (pProgressData != nil) {
if (targetFormat != kNuThreadFormatUncompressed)
Nu_StrawSetProgressState(pStraw, kNuProgressCompressing);
else
Nu_StrawSetProgressState(pStraw, kNuProgressStoring);
}
err = Nu_ProgressDataCompressPrep(pArchive, pStraw, targetFormat,
srcLen);
BailError(err);
if (pProgressData != nil) {
if (targetFormat != kNuThreadFormatUncompressed)
Nu_StrawSetProgressState(pStraw, kNuProgressCompressing);
else
Nu_StrawSetProgressState(pStraw, kNuProgressStoring);
}
err = Nu_ProgressDataCompressPrep(pArchive, pStraw, targetFormat,
srcLen);
BailError(err);
switch (targetFormat) {
case kNuThreadFormatUncompressed:
err = Nu_CompressUncompressed(pArchive, pStraw, dstFp, srcLen,
&dstLen, &threadCrc);
break;
case kNuThreadFormatLZW1:
err = Nu_CompressLZW1(pArchive, pStraw, dstFp, srcLen, &dstLen,
&threadCrc);
break;
case kNuThreadFormatLZW2:
err = Nu_CompressLZW2(pArchive, pStraw, dstFp, srcLen, &dstLen,
&threadCrc);
break;
default:
Assert(0);
err = kNuErrInternal;
goto bail;
}
switch (targetFormat) {
case kNuThreadFormatUncompressed:
err = Nu_CompressUncompressed(pArchive, pStraw, dstFp, srcLen,
&dstLen, &threadCrc);
break;
case kNuThreadFormatLZW1:
err = Nu_CompressLZW1(pArchive, pStraw, dstFp, srcLen, &dstLen,
&threadCrc);
break;
case kNuThreadFormatLZW2:
err = Nu_CompressLZW2(pArchive, pStraw, dstFp, srcLen, &dstLen,
&threadCrc);
break;
default:
Assert(0);
err = kNuErrInternal;
goto bail;
}
BailError(err);
BailError(err);
pThread->thThreadCRC = threadCrc; /* CRC of uncompressed data */
pThread->thThreadCRC = threadCrc; /* CRC of uncompressed data */
if (dstLen < srcLen ||
(dstLen == srcLen && targetFormat == kNuThreadFormatUncompressed))
{
/* got smaller, or we didn't try to compress it; keep it */
pThread->thThreadEOF = srcLen;
pThread->thCompThreadEOF = dstLen;
pThread->thThreadFormat = targetFormat;
} else {
/* got bigger, store it uncompressed */
err = Nu_FSeek(dstFp, origOffset, SEEK_SET);
BailError(err);
err = Nu_StrawRewind(pArchive, pStraw);
BailError(err);
if (pProgressData != nil)
Nu_StrawSetProgressState(pStraw, kNuProgressStoring);
err = Nu_ProgressDataCompressPrep(pArchive, pStraw,
kNuThreadFormatUncompressed, srcLen);
BailError(err);
if (dstLen < srcLen ||
(dstLen == srcLen && targetFormat == kNuThreadFormatUncompressed))
{
/* got smaller, or we didn't try to compress it; keep it */
pThread->thThreadEOF = srcLen;
pThread->thCompThreadEOF = dstLen;
pThread->thThreadFormat = targetFormat;
} else {
/* got bigger, store it uncompressed */
err = Nu_FSeek(dstFp, origOffset, SEEK_SET);
BailError(err);
err = Nu_StrawRewind(pArchive, pStraw);
BailError(err);
if (pProgressData != nil)
Nu_StrawSetProgressState(pStraw, kNuProgressStoring);
err = Nu_ProgressDataCompressPrep(pArchive, pStraw,
kNuThreadFormatUncompressed, srcLen);
BailError(err);
DBUG(("--- compression (%d) failed (%ld vs %ld), storing\n",
targetFormat, dstLen, srcLen));
err = Nu_CompressUncompressed(pArchive, pStraw, dstFp, srcLen,
&dstLen, &threadCrc);
BailError(err);
DBUG(("--- compression (%d) failed (%ld vs %ld), storing\n",
targetFormat, dstLen, srcLen));
err = Nu_CompressUncompressed(pArchive, pStraw, dstFp, srcLen,
&dstLen, &threadCrc);
BailError(err);
/* [didn't need to recompute CRC, but I was being paranoid] */
Assert(threadCrc == pThread->thThreadCRC);
/* [didn't need to recompute CRC, but I was being paranoid] */
Assert(threadCrc == pThread->thThreadCRC);
pThread->thThreadEOF = srcLen;
pThread->thCompThreadEOF = dstLen;
pThread->thThreadFormat = kNuThreadFormatUncompressed;
}
pThread->thThreadEOF = srcLen;
pThread->thCompThreadEOF = dstLen;
pThread->thThreadFormat = kNuThreadFormatUncompressed;
}
} else {
/*
* Copy the already-compressed input.
*/
if (pProgressData != nil)
Nu_StrawSetProgressState(pStraw, kNuProgressCopying);
err = Nu_ProgressDataCompressPrep(pArchive, pStraw,
kNuThreadFormatUncompressed, srcLen);
BailError(err);
} else {
/*
* Copy the already-compressed input.
*/
if (pProgressData != nil)
Nu_StrawSetProgressState(pStraw, kNuProgressCopying);
err = Nu_ProgressDataCompressPrep(pArchive, pStraw,
kNuThreadFormatUncompressed, srcLen);
BailError(err);
err = Nu_CompressUncompressed(pArchive, pStraw, dstFp, srcLen,
&dstLen, nil);
BailError(err);
err = Nu_CompressUncompressed(pArchive, pStraw, dstFp, srcLen,
&dstLen, nil);
BailError(err);
pThread->thThreadEOF = Nu_DataSourceGetOtherLen(pDataSource);
pThread->thCompThreadEOF = srcLen;
pThread->thThreadFormat = sourceFormat;
pThread->thThreadCRC = Nu_DataSourceGetRawCrc(pDataSource);
}
pThread->actualThreadEOF = pThread->thThreadEOF;
pThread->thThreadEOF = Nu_DataSourceGetOtherLen(pDataSource);
pThread->thCompThreadEOF = srcLen;
pThread->thThreadFormat = sourceFormat;
pThread->thThreadCRC = Nu_DataSourceGetRawCrc(pDataSource);
}
pThread->actualThreadEOF = pThread->thThreadEOF;
done:
DBUG(("+++ srcLen=%ld, dstLen=%ld, actual=%ld\n",
srcLen, dstLen, pThread->actualThreadEOF));
DBUG(("+++ srcLen=%ld, dstLen=%ld, actual=%ld\n",
srcLen, dstLen, pThread->actualThreadEOF));
/* make sure we send a final "success" progress message at 100% */
if (pProgressData != nil) {
(void) Nu_StrawSetProgressState(pStraw, kNuProgressDone);
err = Nu_StrawSendProgressUpdate(pArchive, pStraw);
BailError(err);
}
/* make sure we send a final "success" progress message at 100% */
if (pProgressData != nil) {
(void) Nu_StrawSetProgressState(pStraw, kNuProgressDone);
err = Nu_StrawSendProgressUpdate(pArchive, pStraw);
BailError(err);
}
bail:
(void) Nu_StrawFree(pArchive, pStraw);
(void) Nu_DataSinkFree(pDataSink);
return err;
(void) Nu_StrawFree(pArchive, pStraw);
(void) Nu_DataSinkFree(pDataSink);
return err;
}
@ -280,84 +280,84 @@ bail:
*/
NuError
Nu_CopyPresizedToArchive(NuArchive* pArchive, NuDataSource* pDataSource,
NuThreadID threadID, FILE* dstFp, NuThread* pThread, char** ppSavedCopy)
NuThreadID threadID, FILE* dstFp, NuThread* pThread, char** ppSavedCopy)
{
NuError err = kNuErrNone;
NuStraw* pStraw = nil;
/*uchar* buffer = nil;*/
ulong srcLen, bufferLen;
ulong count, getsize;
NuError err = kNuErrNone;
NuStraw* pStraw = nil;
/*uchar* buffer = nil;*/
ulong srcLen, bufferLen;
ulong count, getsize;
srcLen = Nu_DataSourceGetDataLen(pDataSource);
bufferLen = Nu_DataSourceGetOtherLen(pDataSource);
if (bufferLen < srcLen) {
/* hey, this won't fit! */
DBUG(("--- can't fit %lu into buffer of %lu!\n", srcLen, bufferLen));
err = kNuErrPreSizeOverflow;
goto bail;
}
DBUG(("+++ copying %lu into buffer of %lu\n", srcLen, bufferLen));
srcLen = Nu_DataSourceGetDataLen(pDataSource);
bufferLen = Nu_DataSourceGetOtherLen(pDataSource);
if (bufferLen < srcLen) {
/* hey, this won't fit! */
DBUG(("--- can't fit %lu into buffer of %lu!\n", srcLen, bufferLen));
err = kNuErrPreSizeOverflow;
goto bail;
}
DBUG(("+++ copying %lu into buffer of %lu\n", srcLen, bufferLen));
pThread->thThreadClass = NuThreadIDGetClass(threadID);
pThread->thThreadFormat = kNuThreadFormatUncompressed;
pThread->thThreadKind = NuThreadIDGetKind(threadID);
pThread->thThreadCRC = 0; /* no CRC on pre-sized stuff */
pThread->thThreadEOF = srcLen;
pThread->thCompThreadEOF = bufferLen;
pThread->actualThreadEOF = bufferLen;
/* nuThreadIdx and fileOffset should already be set */
pThread->thThreadClass = NuThreadIDGetClass(threadID);
pThread->thThreadFormat = kNuThreadFormatUncompressed;
pThread->thThreadKind = NuThreadIDGetKind(threadID);
pThread->thThreadCRC = 0; /* no CRC on pre-sized stuff */
pThread->thThreadEOF = srcLen;
pThread->thCompThreadEOF = bufferLen;
pThread->actualThreadEOF = bufferLen;
/* nuThreadIdx and fileOffset should already be set */
/*
* Prepare to copy the data through a buffer. The "straw" thing
* is a convenient way to deal with the dataSource, even though we
* don't have a progress updater.
*/
err = Nu_StrawNew(pArchive, pDataSource, nil, &pStraw);
BailError(err);
/*
* Prepare to copy the data through a buffer. The "straw" thing
* is a convenient way to deal with the dataSource, even though we
* don't have a progress updater.
*/
err = Nu_StrawNew(pArchive, pDataSource, nil, &pStraw);
BailError(err);
count = srcLen;
/*buffer = Nu_Malloc(pArchive, kNuFunnelBufSize);*/
/*BailAlloc(buffer);*/
err = Nu_AllocCompressionBufferIFN(pArchive);
BailError(err);
count = srcLen;
/*buffer = Nu_Malloc(pArchive, kNuFunnelBufSize);*/
/*BailAlloc(buffer);*/
err = Nu_AllocCompressionBufferIFN(pArchive);
BailError(err);
while (count) {
getsize = (count > kNuGenCompBufSize) ? kNuGenCompBufSize : count;
while (count) {
getsize = (count > kNuGenCompBufSize) ? kNuGenCompBufSize : count;
err = Nu_StrawRead(pArchive, pStraw, pArchive->compBuf, getsize);
BailError(err);
err = Nu_FWrite(dstFp, pArchive->compBuf, getsize);
BailError(err);
err = Nu_StrawRead(pArchive, pStraw, pArchive->compBuf, getsize);
BailError(err);
err = Nu_FWrite(dstFp, pArchive->compBuf, getsize);
BailError(err);
if (ppSavedCopy != nil && *ppSavedCopy == nil) {
/*
* Grab a copy of the filename for our own use. This assumes
* that the filename fits in kNuGenCompBufSize, which is a
* pretty safe thing to assume.
*/
Assert(threadID == kNuThreadIDFilename);
Assert(count == getsize);
*ppSavedCopy = Nu_Malloc(pArchive, getsize+1);
BailAlloc(*ppSavedCopy);
memcpy(*ppSavedCopy, pArchive->compBuf, getsize);
(*ppSavedCopy)[getsize] = '\0'; /* make sure it's terminated */
}
if (ppSavedCopy != nil && *ppSavedCopy == nil) {
/*
* Grab a copy of the filename for our own use. This assumes
* that the filename fits in kNuGenCompBufSize, which is a
* pretty safe thing to assume.
*/
Assert(threadID == kNuThreadIDFilename);
Assert(count == getsize);
*ppSavedCopy = Nu_Malloc(pArchive, getsize+1);
BailAlloc(*ppSavedCopy);
memcpy(*ppSavedCopy, pArchive->compBuf, getsize);
(*ppSavedCopy)[getsize] = '\0'; /* make sure it's terminated */
}
count -= getsize;
}
count -= getsize;
}
/*
* Pad out the rest of the buffer. Could probably do this more
* efficiently through the buffer we've allocated, but these regions
* tend to be either 32 or 200 bytes.
*/
count = bufferLen - srcLen;
while (count--)
Nu_WriteOne(pArchive, dstFp, 0);
/*
* Pad out the rest of the buffer. Could probably do this more
* efficiently through the buffer we've allocated, but these regions
* tend to be either 32 or 200 bytes.
*/
count = bufferLen - srcLen;
while (count--)
Nu_WriteOne(pArchive, dstFp, 0);
bail:
(void) Nu_StrawFree(pArchive, pStraw);
/*Nu_Free(pArchive, buffer);*/
return err;
(void) Nu_StrawFree(pArchive, pStraw);
/*Nu_Free(pArchive, buffer);*/
return err;
}

View File

@ -6,7 +6,7 @@
*
* Compute 16-bit CRCs.
*/
#define __Crc16_c__ 1
#define __Crc16_c__ 1
#include "NufxLibPriv.h"
#define CRC_TAB
@ -85,25 +85,25 @@ const ushort gNuCrc16Table[256] = {
ushort
Nu_CalcCRC16(ushort seed, const uchar* ptr, int count)
{
ushort CRC = seed;
ushort CRC = seed;
#ifndef CRC_TAB
int x;
Assert(sizeof(ushort) == 2); /* I think this is assumed */
int x;
Assert(sizeof(ushort) == 2); /* I think this is assumed */
#endif
do {
do {
#ifndef CRC_TAB
CRC ^= *ptr++ << 8; /* XOR hi-byte of CRC w/dat */
for (x = 8; x; --x) /* Then, for 8 bit shifts... */
if (CRC & 0x8000) /* Test hi order bit of CRC */
CRC = CRC << 1 ^ 0x1021; /* if set, shift & XOR w/$1021 */
else
CRC <<= 1; /* Else, just shift left once. */
CRC ^= *ptr++ << 8; /* XOR hi-byte of CRC w/dat */
for (x = 8; x; --x) /* Then, for 8 bit shifts... */
if (CRC & 0x8000) /* Test hi order bit of CRC */
CRC = CRC << 1 ^ 0x1021; /* if set, shift & XOR w/$1021 */
else
CRC <<= 1; /* Else, just shift left once. */
#else
CRC = Nu_UpdateCRC16(*ptr++, CRC); /* look up new value in table */
CRC = Nu_UpdateCRC16(*ptr++, CRC); /* look up new value in table */
#endif
} while (--count);
} while (--count);
return (CRC);
return (CRC);
}

View File

@ -12,47 +12,47 @@
/* pull a string out of one of the static arrays */
#define GetStaticString(index, staticArray) ( \
(index) >= NELEM(staticArray) ? "<unknown>" : staticArray[index] \
)
#define GetStaticString(index, staticArray) ( \
(index) >= NELEM(staticArray) ? "<unknown>" : staticArray[index] \
)
/* thread's thread_class */
static const char* gThreadClassNames[] = {
"message_thread",
"control_thread",
"data_thread",
"filename_thread",
"message_thread",
"control_thread",
"data_thread",
"filename_thread",
};
/* thread's thread_format */
static const char* gThreadFormatNames[] = {
"uncompressed",
"Huffman Squeeze",
"dynamic LZW/1",
"dynamic LZW/2",
"12-bit LZC",
"16-bit LZC",
"uncompressed",
"Huffman Squeeze",
"dynamic LZW/1",
"dynamic LZW/2",
"12-bit LZC",
"16-bit LZC",
};
/* days of the week */
static const char* gDayNames[] = {
"[ null ]",
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
"[ null ]",
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
/* months of the year */
static const char* gMonths[] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
#define kNuDateOutputLen 64
#define kNuDateOutputLen 64
/* file_sys_id values */
static const char* gFileSysIDs[] = {
"Reserved/unknown ($00)", "ProDOS/SOS", "DOS 3.3", "DOS 3.2",
"Apple II Pascal", "Macintosh (MFS)", "Macintosh (HFS)",
"LISA file system", "Apple CP/M", "Reserved 0x09", "MS-DOS",
"High-Sierra", "ISO 9660", "AppleShare"
"Reserved/unknown ($00)", "ProDOS/SOS", "DOS 3.3", "DOS 3.2",
"Apple II Pascal", "Macintosh (MFS)", "Macintosh (HFS)",
"LISA file system", "Apple CP/M", "Reserved 0x09", "MS-DOS",
"High-Sierra", "ISO 9660", "AppleShare"
};
@ -66,48 +66,48 @@ static const char* gFileSysIDs[] = {
static char*
Nu_DebugDumpDate(const NuDateTime* pDateTime, char* buffer)
{
char* cp;
char* cp;
/* is it valid? */
if (pDateTime->day > 30 || pDateTime->month > 11 || pDateTime->hour > 24 ||
pDateTime->minute > 59)
{
strcpy(buffer, " <invalid> ");
goto bail;
}
/* is it valid? */
if (pDateTime->day > 30 || pDateTime->month > 11 || pDateTime->hour > 24 ||
pDateTime->minute > 59)
{
strcpy(buffer, " <invalid> ");
goto bail;
}
/* is it empty? */
if ((pDateTime->second | pDateTime->minute | pDateTime->hour |
pDateTime->year | pDateTime->day | pDateTime->month |
pDateTime->extra | pDateTime->weekDay) == 0)
{
strcpy(buffer, " [No Date] ");
goto bail;
}
/* is it empty? */
if ((pDateTime->second | pDateTime->minute | pDateTime->hour |
pDateTime->year | pDateTime->day | pDateTime->month |
pDateTime->extra | pDateTime->weekDay) == 0)
{
strcpy(buffer, " [No Date] ");
goto bail;
}
cp = buffer;
cp = buffer;
/* only print weekDay if one was stored */
if (pDateTime->weekDay) {
if (pDateTime->weekDay < NELEM(gDayNames))
sprintf(cp, "%s, ", gDayNames[pDateTime->weekDay]);
else
sprintf(cp, "??%d, ", pDateTime->weekDay);
cp += strlen(cp);
}
/* only print weekDay if one was stored */
if (pDateTime->weekDay) {
if (pDateTime->weekDay < NELEM(gDayNames))
sprintf(cp, "%s, ", gDayNames[pDateTime->weekDay]);
else
sprintf(cp, "??%d, ", pDateTime->weekDay);
cp += strlen(cp);
}
sprintf(cp, "%02d-%s-%04d %02d:%02d:%02d",
pDateTime->day+1, gMonths[pDateTime->month],
pDateTime->year < 40 ? pDateTime->year + 2000 : pDateTime->year + 1900,
pDateTime->hour, pDateTime->minute, pDateTime->second);
sprintf(cp, "%02d-%s-%04d %02d:%02d:%02d",
pDateTime->day+1, gMonths[pDateTime->month],
pDateTime->year < 40 ? pDateTime->year + 2000 : pDateTime->year + 1900,
pDateTime->hour, pDateTime->minute, pDateTime->second);
bail:
sprintf(buffer + strlen(buffer), " [s%d m%d h%d Y%d D%d M%d x%d w%d]",
pDateTime->second, pDateTime->minute, pDateTime->hour,
pDateTime->year, pDateTime->day, pDateTime->month, pDateTime->extra,
pDateTime->weekDay);
sprintf(buffer + strlen(buffer), " [s%d m%d h%d Y%d D%d M%d x%d w%d]",
pDateTime->second, pDateTime->minute, pDateTime->hour,
pDateTime->year, pDateTime->day, pDateTime->month, pDateTime->extra,
pDateTime->weekDay);
return buffer;
return buffer;
}
@ -119,12 +119,12 @@ bail:
static void
ConvertToHexStr(const uchar* inBuf, int inLen, char* outBuf)
{
while (inLen--) {
*outBuf++ = HexConv((*inBuf >> 4) & 0x0f);
*outBuf++ = HexConv(*inBuf & 0x0f);
inBuf++;
}
*outBuf = '\0';
while (inLen--) {
*outBuf++ = HexConv((*inBuf >> 4) & 0x0f);
*outBuf++ = HexConv(*inBuf & 0x0f);
inBuf++;
}
*outBuf = '\0';
}
@ -134,38 +134,38 @@ ConvertToHexStr(const uchar* inBuf, int inLen, char* outBuf)
void
Nu_DebugDumpThread(const NuThread* pThread)
{
static const char* kInd = " ";
NuThreadID threadID;
const char* descr;
static const char* kInd = " ";
NuThreadID threadID;
const char* descr;
Assert(pThread != nil);
Assert(pThread != nil);
printf("%sThreadClass: 0x%04x (%s)\n", kInd,
pThread->thThreadClass,
GetStaticString(pThread->thThreadClass, gThreadClassNames));
printf("%sThreadFormat: 0x%04x (%s)\n", kInd,
pThread->thThreadFormat,
GetStaticString(pThread->thThreadFormat, gThreadFormatNames));
printf("%sThreadClass: 0x%04x (%s)\n", kInd,
pThread->thThreadClass,
GetStaticString(pThread->thThreadClass, gThreadClassNames));
printf("%sThreadFormat: 0x%04x (%s)\n", kInd,
pThread->thThreadFormat,
GetStaticString(pThread->thThreadFormat, gThreadFormatNames));
threadID = NuMakeThreadID(pThread->thThreadClass, pThread->thThreadKind);
switch (threadID) {
case kNuThreadIDOldComment: descr = "old comment"; break;
case kNuThreadIDComment: descr = "comment"; break;
case kNuThreadIDIcon: descr = "icon"; break;
case kNuThreadIDMkdir: descr = "mkdir"; break;
case kNuThreadIDDataFork: descr = "data fork"; break;
case kNuThreadIDDiskImage: descr = "disk image"; break;
case kNuThreadIDRsrcFork: descr = "rsrc fork"; break;
case kNuThreadIDFilename: descr = "filename"; break;
default: descr = "<unknown>"; break;
}
printf("%sThreadKind: 0x%04x (%s)\n", kInd,
pThread->thThreadKind, descr);
threadID = NuMakeThreadID(pThread->thThreadClass, pThread->thThreadKind);
switch (threadID) {
case kNuThreadIDOldComment: descr = "old comment"; break;
case kNuThreadIDComment: descr = "comment"; break;
case kNuThreadIDIcon: descr = "icon"; break;
case kNuThreadIDMkdir: descr = "mkdir"; break;
case kNuThreadIDDataFork: descr = "data fork"; break;
case kNuThreadIDDiskImage: descr = "disk image"; break;
case kNuThreadIDRsrcFork: descr = "rsrc fork"; break;
case kNuThreadIDFilename: descr = "filename"; break;
default: descr = "<unknown>"; break;
}
printf("%sThreadKind: 0x%04x (%s)\n", kInd,
pThread->thThreadKind, descr);
printf("%sThreadCRC: 0x%04x ThreadEOF: %lu CompThreadEOF: %lu\n", kInd,
pThread->thThreadCRC, pThread->thThreadEOF, pThread->thCompThreadEOF);
printf("%s*File data offset: %ld actualThreadEOF: %ld\n", kInd,
pThread->fileOffset, pThread->actualThreadEOF);
printf("%sThreadCRC: 0x%04x ThreadEOF: %lu CompThreadEOF: %lu\n", kInd,
pThread->thThreadCRC, pThread->thThreadEOF, pThread->thCompThreadEOF);
printf("%s*File data offset: %ld actualThreadEOF: %ld\n", kInd,
pThread->fileOffset, pThread->actualThreadEOF);
}
/*
@ -177,105 +177,105 @@ Nu_DebugDumpThread(const NuThread* pThread)
*/
static void
Nu_DebugDumpRecord(NuArchive* pArchive, const NuRecord* pRecord,
const NuRecord* pXrefRecord, Boolean isDeleted)
const NuRecord* pXrefRecord, Boolean isDeleted)
{
NuError err; /* dummy */
static const char* kInd = " ";
char dateBuf[kNuDateOutputLen];
const NuThreadMod* pThreadMod;
const NuThread* pThread;
ulong idx;
NuError err; /* dummy */
static const char* kInd = " ";
char dateBuf[kNuDateOutputLen];
const NuThreadMod* pThreadMod;
const NuThread* pThread;
ulong idx;
Assert(pRecord != nil);
Assert(pRecord != nil);
printf("%s%s%sFilename: '%s' (idx=%lu)\n", kInd,
isDeleted ? "[DEL] " : "",
pXrefRecord != nil && pXrefRecord->pThreadMods != nil ? "[MOD] " : "",
pRecord->filename == nil ? "<not specified>" : pRecord->filename,
pRecord->recordIdx);
printf("%sHeaderID: '%.4s' VersionNumber: 0x%04x HeaderCRC: 0x%04x\n",
kInd,
pRecord->recNufxID, pRecord->recVersionNumber, pRecord->recHeaderCRC);
printf("%sAttribCount: %u TotalThreads: %lu\n", kInd,
pRecord->recAttribCount, pRecord->recTotalThreads);
printf("%sFileSysID: %u (%s) FileSysInfo: 0x%04x ('%c')\n", kInd,
pRecord->recFileSysID,
GetStaticString(pRecord->recFileSysID, gFileSysIDs),
pRecord->recFileSysInfo,
NuGetSepFromSysInfo(pRecord->recFileSysInfo));
/* do something fancy for ProDOS? */
printf("%sFileType: 0x%08lx ExtraType: 0x%08lx Access: 0x%08lx\n", kInd,
pRecord->recFileType, pRecord->recExtraType, pRecord->recAccess);
printf("%sCreateWhen: %s\n", kInd,
Nu_DebugDumpDate(&pRecord->recCreateWhen, dateBuf));
printf("%sModWhen: %s\n", kInd,
Nu_DebugDumpDate(&pRecord->recModWhen, dateBuf));
printf("%sArchiveWhen: %s\n", kInd,
Nu_DebugDumpDate(&pRecord->recArchiveWhen, dateBuf));
printf("%sStorageType: %u OptionSize: %u FilenameLength: %u\n", kInd,
pRecord->recStorageType, pRecord->recOptionSize,
pRecord->recFilenameLength);
if (pRecord->recOptionSize) {
char* outBuf = Nu_Malloc(pArchive, pRecord->recOptionSize * 2 +1);
BailAlloc(outBuf);
Assert(pRecord->recOptionList != nil);
ConvertToHexStr(pRecord->recOptionList, pRecord->recOptionSize, outBuf);
printf("%sOptionList: [%s]\n", kInd, outBuf);
Nu_Free(pArchive, outBuf);
}
printf("%s%s%sFilename: '%s' (idx=%lu)\n", kInd,
isDeleted ? "[DEL] " : "",
pXrefRecord != nil && pXrefRecord->pThreadMods != nil ? "[MOD] " : "",
pRecord->filename == nil ? "<not specified>" : pRecord->filename,
pRecord->recordIdx);
printf("%sHeaderID: '%.4s' VersionNumber: 0x%04x HeaderCRC: 0x%04x\n",
kInd,
pRecord->recNufxID, pRecord->recVersionNumber, pRecord->recHeaderCRC);
printf("%sAttribCount: %u TotalThreads: %lu\n", kInd,
pRecord->recAttribCount, pRecord->recTotalThreads);
printf("%sFileSysID: %u (%s) FileSysInfo: 0x%04x ('%c')\n", kInd,
pRecord->recFileSysID,
GetStaticString(pRecord->recFileSysID, gFileSysIDs),
pRecord->recFileSysInfo,
NuGetSepFromSysInfo(pRecord->recFileSysInfo));
/* do something fancy for ProDOS? */
printf("%sFileType: 0x%08lx ExtraType: 0x%08lx Access: 0x%08lx\n", kInd,
pRecord->recFileType, pRecord->recExtraType, pRecord->recAccess);
printf("%sCreateWhen: %s\n", kInd,
Nu_DebugDumpDate(&pRecord->recCreateWhen, dateBuf));
printf("%sModWhen: %s\n", kInd,
Nu_DebugDumpDate(&pRecord->recModWhen, dateBuf));
printf("%sArchiveWhen: %s\n", kInd,
Nu_DebugDumpDate(&pRecord->recArchiveWhen, dateBuf));
printf("%sStorageType: %u OptionSize: %u FilenameLength: %u\n", kInd,
pRecord->recStorageType, pRecord->recOptionSize,
pRecord->recFilenameLength);
if (pRecord->recOptionSize) {
char* outBuf = Nu_Malloc(pArchive, pRecord->recOptionSize * 2 +1);
BailAlloc(outBuf);
Assert(pRecord->recOptionList != nil);
ConvertToHexStr(pRecord->recOptionList, pRecord->recOptionSize, outBuf);
printf("%sOptionList: [%s]\n", kInd, outBuf);
Nu_Free(pArchive, outBuf);
}
printf("%s*ExtraCount: %ld RecFileOffset: %ld RecHeaderLength: %ld\n",
kInd,
pRecord->extraCount, pRecord->fileOffset, pRecord->recHeaderLength);
printf("%s*ExtraCount: %ld RecFileOffset: %ld RecHeaderLength: %ld\n",
kInd,
pRecord->extraCount, pRecord->fileOffset, pRecord->recHeaderLength);
for (idx = 0; idx < pRecord->recTotalThreads; idx++) {
pThread = Nu_GetThread(pRecord, idx);
Assert(pThread != nil);
for (idx = 0; idx < pRecord->recTotalThreads; idx++) {
pThread = Nu_GetThread(pRecord, idx);
Assert(pThread != nil);
printf("%s--Thread #%lu (idx=%lu)\n", kInd, idx, pThread->threadIdx);
Nu_DebugDumpThread(pThread);
}
printf("%s--Thread #%lu (idx=%lu)\n", kInd, idx, pThread->threadIdx);
Nu_DebugDumpThread(pThread);
}
if (pXrefRecord != nil)
pThreadMod = pXrefRecord->pThreadMods;
else
pThreadMod = pRecord->pThreadMods; /* probably empty */
if (pXrefRecord != nil)
pThreadMod = pXrefRecord->pThreadMods;
else
pThreadMod = pRecord->pThreadMods; /* probably empty */
if (pThreadMod != nil)
printf("%s*ThreadMods -----\n", kInd);
while (pThreadMod != nil) {
switch (pThreadMod->entry.kind) {
case kNuThreadModAdd:
printf("%s *-ThreadMod ADD 0x%08lx 0x%04x (sourceType=%d)\n", kInd,
pThreadMod->entry.add.threadID,
pThreadMod->entry.add.threadFormat,
Nu_DataSourceGetType(pThreadMod->entry.add.pDataSource));
break;
case kNuThreadModUpdate:
printf("%s *-ThreadMod UPDATE %06ld\n", kInd,
pThreadMod->entry.update.threadIdx);
break;
case kNuThreadModDelete:
printf("%s *-ThreadMod DELETE %06ld\n", kInd,
pThreadMod->entry.delete.threadIdx);
break;
case kNuThreadModUnknown:
default:
Assert(0);
printf("%s++ThreadMod UNKNOWN\n", kInd);
break;
}
if (pThreadMod != nil)
printf("%s*ThreadMods -----\n", kInd);
while (pThreadMod != nil) {
switch (pThreadMod->entry.kind) {
case kNuThreadModAdd:
printf("%s *-ThreadMod ADD 0x%08lx 0x%04x (sourceType=%d)\n", kInd,
pThreadMod->entry.add.threadID,
pThreadMod->entry.add.threadFormat,
Nu_DataSourceGetType(pThreadMod->entry.add.pDataSource));
break;
case kNuThreadModUpdate:
printf("%s *-ThreadMod UPDATE %06ld\n", kInd,
pThreadMod->entry.update.threadIdx);
break;
case kNuThreadModDelete:
printf("%s *-ThreadMod DELETE %06ld\n", kInd,
pThreadMod->entry.delete.threadIdx);
break;
case kNuThreadModUnknown:
default:
Assert(0);
printf("%s++ThreadMod UNKNOWN\n", kInd);
break;
}
pThreadMod = pThreadMod->pNext;
}
pThreadMod = pThreadMod->pNext;
}
/*printf("%s*TotalLength: %ld TotalCompLength: %ld\n",
kInd, pRecord->totalLength, pRecord->totalCompLength);*/
printf("%s*TotalCompLength: %ld\n", kInd, pRecord->totalCompLength);
printf("\n");
/*printf("%s*TotalLength: %ld TotalCompLength: %ld\n",
kInd, pRecord->totalLength, pRecord->totalCompLength);*/
printf("%s*TotalCompLength: %ld\n", kInd, pRecord->totalCompLength);
printf("\n");
bail:
return;
return;
}
/*
@ -283,41 +283,41 @@ bail:
*/
static void
Nu_DebugDumpRecordSet(NuArchive* pArchive, const NuRecordSet* pRecordSet,
const NuRecordSet* pXrefSet)
const NuRecordSet* pXrefSet)
{
const NuRecord* pRecord;
const NuRecord* pXrefRecord;
Boolean doXref;
long count;
const NuRecord* pRecord;
const NuRecord* pXrefRecord;
Boolean doXref;
long count;
doXref = false;
pXrefRecord = nil;
if (pXrefSet != nil && Nu_RecordSet_GetLoaded(pXrefSet)) {
pXrefRecord = Nu_RecordSet_GetListHead(pXrefSet);
doXref = true;
}
doXref = false;
pXrefRecord = nil;
if (pXrefSet != nil && Nu_RecordSet_GetLoaded(pXrefSet)) {
pXrefRecord = Nu_RecordSet_GetListHead(pXrefSet);
doXref = true;
}
/* dump every record, if we've loaded them */
count = Nu_RecordSet_GetNumRecords(pRecordSet);
pRecord = Nu_RecordSet_GetListHead(pRecordSet);
if (pRecord != nil) {
Assert(count != 0);
while (count--) {
Assert(pRecord != nil);
/* dump every record, if we've loaded them */
count = Nu_RecordSet_GetNumRecords(pRecordSet);
pRecord = Nu_RecordSet_GetListHead(pRecordSet);
if (pRecord != nil) {
Assert(count != 0);
while (count--) {
Assert(pRecord != nil);
if (pXrefRecord != nil &&
pRecord->recordIdx == pXrefRecord->recordIdx)
{
Nu_DebugDumpRecord(pArchive, pRecord, pXrefRecord, false);
pXrefRecord = pXrefRecord->pNext;
} else {
Nu_DebugDumpRecord(pArchive, pRecord, nil, doXref);
}
pRecord = pRecord->pNext;
}
} else {
Assert(count == 0);
}
if (pXrefRecord != nil &&
pRecord->recordIdx == pXrefRecord->recordIdx)
{
Nu_DebugDumpRecord(pArchive, pRecord, pXrefRecord, false);
pXrefRecord = pXrefRecord->pNext;
} else {
Nu_DebugDumpRecord(pArchive, pRecord, nil, doXref);
}
pRecord = pRecord->pNext;
}
} else {
Assert(count == 0);
}
}
/*
@ -326,20 +326,20 @@ Nu_DebugDumpRecordSet(NuArchive* pArchive, const NuRecordSet* pRecordSet,
static void
Nu_DebugDumpMH(const NuMasterHeader* pMasterHeader)
{
static const char* kInd = " ";
char dateBuf1[kNuDateOutputLen];
static const char* kInd = " ";
char dateBuf1[kNuDateOutputLen];
Assert(pMasterHeader != nil);
Assert(pMasterHeader != nil);
printf("%sNufileID: '%.6s' MasterCRC: 0x%04x TotalRecords: %lu\n", kInd,
pMasterHeader->mhNufileID, pMasterHeader->mhMasterCRC,
pMasterHeader->mhTotalRecords);
printf("%sArchiveCreateWhen: %s\n", kInd,
Nu_DebugDumpDate(&pMasterHeader->mhArchiveCreateWhen, dateBuf1));
printf("%sArchiveModWhen: %s\n", kInd,
Nu_DebugDumpDate(&pMasterHeader->mhArchiveModWhen, dateBuf1));
printf("%sMasterVersion: %u MasterEOF: %lu\n", kInd,
pMasterHeader->mhMasterVersion, pMasterHeader->mhMasterEOF);
printf("%sNufileID: '%.6s' MasterCRC: 0x%04x TotalRecords: %lu\n", kInd,
pMasterHeader->mhNufileID, pMasterHeader->mhMasterCRC,
pMasterHeader->mhTotalRecords);
printf("%sArchiveCreateWhen: %s\n", kInd,
Nu_DebugDumpDate(&pMasterHeader->mhArchiveCreateWhen, dateBuf1));
printf("%sArchiveModWhen: %s\n", kInd,
Nu_DebugDumpDate(&pMasterHeader->mhArchiveModWhen, dateBuf1));
printf("%sMasterVersion: %u MasterEOF: %lu\n", kInd,
pMasterHeader->mhMasterVersion, pMasterHeader->mhMasterEOF);
}
/*
@ -353,32 +353,32 @@ Nu_DebugDumpMH(const NuMasterHeader* pMasterHeader)
void
Nu_DebugDumpAll(NuArchive* pArchive)
{
Assert(pArchive != nil);
Assert(pArchive != nil);
printf("*Archive pathname: '%s'\n", pArchive->archivePathname);
printf("*Archive type: %d\n", pArchive->archiveType);
printf("*Header offset: %ld\n", pArchive->headerOffset);
printf("*Num records: %ld orig, %ld copy, %ld new\n",
Nu_RecordSet_GetNumRecords(&pArchive->origRecordSet),
Nu_RecordSet_GetNumRecords(&pArchive->copyRecordSet),
Nu_RecordSet_GetNumRecords(&pArchive->newRecordSet));
printf("*NuRecordIdx seed: %lu NuRecordIdx next: %lu\n",
pArchive->recordIdxSeed, pArchive->nextRecordIdx);
printf("*Archive pathname: '%s'\n", pArchive->archivePathname);
printf("*Archive type: %d\n", pArchive->archiveType);
printf("*Header offset: %ld\n", pArchive->headerOffset);
printf("*Num records: %ld orig, %ld copy, %ld new\n",
Nu_RecordSet_GetNumRecords(&pArchive->origRecordSet),
Nu_RecordSet_GetNumRecords(&pArchive->copyRecordSet),
Nu_RecordSet_GetNumRecords(&pArchive->newRecordSet));
printf("*NuRecordIdx seed: %lu NuRecordIdx next: %lu\n",
pArchive->recordIdxSeed, pArchive->nextRecordIdx);
/* master header */
Nu_DebugDumpMH(&pArchive->masterHeader);
/* master header */
Nu_DebugDumpMH(&pArchive->masterHeader);
printf(" *ORIG record set (x-ref with COPY):\n");
Nu_DebugDumpRecordSet(pArchive, &pArchive->origRecordSet,
&pArchive->copyRecordSet);
printf(" *NEW record set:\n");
Nu_DebugDumpRecordSet(pArchive, &pArchive->newRecordSet, nil);
printf(" *ORIG record set (x-ref with COPY):\n");
Nu_DebugDumpRecordSet(pArchive, &pArchive->origRecordSet,
&pArchive->copyRecordSet);
printf(" *NEW record set:\n");
Nu_DebugDumpRecordSet(pArchive, &pArchive->newRecordSet, nil);
if (!Nu_RecordSet_GetLoaded(&pArchive->origRecordSet) &&
!Nu_RecordSet_GetLoaded(&pArchive->newRecordSet))
{
printf("*** DEBUG: original records not loaded yet? ***\n");
}
if (!Nu_RecordSet_GetLoaded(&pArchive->origRecordSet) &&
!Nu_RecordSet_GetLoaded(&pArchive->newRecordSet))
{
printf("*** DEBUG: original records not loaded yet? ***\n");
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -14,49 +14,49 @@
*/
static NuError
Nu_ExpandUncompressed(NuArchive* pArchive, const NuRecord* pRecord,
const NuThread* pThread, FILE* infp, NuFunnel* pFunnel, ushort* pCrc)
const NuThread* pThread, FILE* infp, NuFunnel* pFunnel, ushort* pCrc)
{
NuError err;
/*uchar* buffer = nil;*/
ulong count, getsize;
NuError err;
/*uchar* buffer = nil;*/
ulong count, getsize;
Assert(pArchive != nil);
Assert(pThread != nil);
Assert(infp != nil);
Assert(pFunnel != nil);
Assert(pArchive != nil);
Assert(pThread != nil);
Assert(infp != nil);
Assert(pFunnel != nil);
/* doesn't have to be same size as funnel, but it's not a bad idea */
/*buffer = Nu_Malloc(pArchive, kNuFunnelBufSize);*/
/*BailAlloc(buffer);*/
err = Nu_AllocCompressionBufferIFN(pArchive);
BailError(err);
/* doesn't have to be same size as funnel, but it's not a bad idea */
/*buffer = Nu_Malloc(pArchive, kNuFunnelBufSize);*/
/*BailAlloc(buffer);*/
err = Nu_AllocCompressionBufferIFN(pArchive);
BailError(err);
/* quick assert for bad archive that should have been caught earlier */
/* (filename threads are uncompressed, but compThreadEOF is buf len) */
if (pThread->thThreadClass == kNuThreadClassData)
Assert(pThread->actualThreadEOF == pThread->thCompThreadEOF);
/* quick assert for bad archive that should have been caught earlier */
/* (filename threads are uncompressed, but compThreadEOF is buf len) */
if (pThread->thThreadClass == kNuThreadClassData)
Assert(pThread->actualThreadEOF == pThread->thCompThreadEOF);
count = pThread->actualThreadEOF;
count = pThread->actualThreadEOF;
while (count) {
getsize = (count > kNuGenCompBufSize) ? kNuGenCompBufSize : count;
while (count) {
getsize = (count > kNuGenCompBufSize) ? kNuGenCompBufSize : count;
err = Nu_FRead(infp, pArchive->compBuf, getsize);
BailError(err);
if (pCrc != nil)
*pCrc = Nu_CalcCRC16(*pCrc, pArchive->compBuf, getsize);
err = Nu_FunnelWrite(pArchive, pFunnel, pArchive->compBuf, getsize);
BailError(err);
err = Nu_FRead(infp, pArchive->compBuf, getsize);
BailError(err);
if (pCrc != nil)
*pCrc = Nu_CalcCRC16(*pCrc, pArchive->compBuf, getsize);
err = Nu_FunnelWrite(pArchive, pFunnel, pArchive->compBuf, getsize);
BailError(err);
count -= getsize;
}
count -= getsize;
}
err = Nu_FunnelFlush(pArchive, pFunnel);
BailError(err);
err = Nu_FunnelFlush(pArchive, pFunnel);
BailError(err);
bail:
/*Nu_Free(pArchive, buffer);*/
return err;
/*Nu_Free(pArchive, buffer);*/
return err;
}
/*
@ -65,42 +65,42 @@ bail:
*/
static NuError
Nu_ExpandRaw(NuArchive* pArchive, const NuThread* pThread, FILE* infp,
NuFunnel* pFunnel)
NuFunnel* pFunnel)
{
NuError err;
/*uchar* buffer = nil;*/
ulong count, getsize;
NuError err;
/*uchar* buffer = nil;*/
ulong count, getsize;
Assert(pArchive != nil);
Assert(pThread != nil);
Assert(infp != nil);
Assert(pFunnel != nil);
Assert(pArchive != nil);
Assert(pThread != nil);
Assert(infp != nil);
Assert(pFunnel != nil);
/* doesn't have to be same size as funnel, but it's not a bad idea */
/*buffer = Nu_Malloc(pArchive, kNuFunnelBufSize);*/
/*BailAlloc(buffer);*/
err = Nu_AllocCompressionBufferIFN(pArchive);
BailError(err);
/* doesn't have to be same size as funnel, but it's not a bad idea */
/*buffer = Nu_Malloc(pArchive, kNuFunnelBufSize);*/
/*BailAlloc(buffer);*/
err = Nu_AllocCompressionBufferIFN(pArchive);
BailError(err);
count = pThread->thCompThreadEOF;
count = pThread->thCompThreadEOF;
while (count) {
getsize = (count > kNuGenCompBufSize) ? kNuGenCompBufSize : count;
while (count) {
getsize = (count > kNuGenCompBufSize) ? kNuGenCompBufSize : count;
err = Nu_FRead(infp, pArchive->compBuf, getsize);
BailError(err);
err = Nu_FunnelWrite(pArchive, pFunnel, pArchive->compBuf, getsize);
BailError(err);
err = Nu_FRead(infp, pArchive->compBuf, getsize);
BailError(err);
err = Nu_FunnelWrite(pArchive, pFunnel, pArchive->compBuf, getsize);
BailError(err);
count -= getsize;
}
count -= getsize;
}
err = Nu_FunnelFlush(pArchive, pFunnel);
BailError(err);
err = Nu_FunnelFlush(pArchive, pFunnel);
BailError(err);
bail:
/*Nu_Free(pArchive, buffer);*/
return err;
/*Nu_Free(pArchive, buffer);*/
return err;
}
@ -110,104 +110,104 @@ bail:
*/
NuError
Nu_ExpandStream(NuArchive* pArchive, const NuRecord* pRecord,
const NuThread* pThread, FILE* infp, NuFunnel* pFunnel)
const NuThread* pThread, FILE* infp, NuFunnel* pFunnel)
{
NuError err = kNuErrNone;
ushort calcCrc;
ushort* pCalcCrc;
NuError err = kNuErrNone;
ushort calcCrc;
ushort* pCalcCrc;
if (!pThread->thThreadEOF && !pThread->thCompThreadEOF) {
/* somebody stored an empty file! */
goto done;
}
if (!pThread->thThreadEOF && !pThread->thCompThreadEOF) {
/* somebody stored an empty file! */
goto done;
}
/*
* A brief history of the "threadCRC" field in the thread header:
* record versions 0 and 1 didn't use the threadCRC field
* record version 2 put the CRC of the compressed data in threadCRC
* record version 3 put the CRC of the uncompressed data in threadCRC
*
* P8 ShrinkIt uses v1, GSHK uses v3. If something ever shipped with
* v2, it didn't last long enough to leave an impression, so I'm not
* going to support it. BTW, P8 ShrinkIt always uses LZW/1, which
* puts a CRC in the compressed stream. Your uncompressed data is,
* unfortunately, unprotected before v3.
*/
calcCrc = kNuInitialThreadCRC;
pCalcCrc = nil;
if (Nu_ThreadHasCRC(pRecord->recVersionNumber, NuGetThreadID(pThread)) &&
!pArchive->valIgnoreCRC)
{
pCalcCrc = &calcCrc;
}
/*
* A brief history of the "threadCRC" field in the thread header:
* record versions 0 and 1 didn't use the threadCRC field
* record version 2 put the CRC of the compressed data in threadCRC
* record version 3 put the CRC of the uncompressed data in threadCRC
*
* P8 ShrinkIt uses v1, GSHK uses v3. If something ever shipped with
* v2, it didn't last long enough to leave an impression, so I'm not
* going to support it. BTW, P8 ShrinkIt always uses LZW/1, which
* puts a CRC in the compressed stream. Your uncompressed data is,
* unfortunately, unprotected before v3.
*/
calcCrc = kNuInitialThreadCRC;
pCalcCrc = nil;
if (Nu_ThreadHasCRC(pRecord->recVersionNumber, NuGetThreadID(pThread)) &&
!pArchive->valIgnoreCRC)
{
pCalcCrc = &calcCrc;
}
err = Nu_ProgressDataExpandPrep(pArchive, pFunnel, pThread);
BailError(err);
err = Nu_ProgressDataExpandPrep(pArchive, pFunnel, pThread);
BailError(err);
/*
* If we're not expanding the data, use a simple copier.
*/
if (!Nu_FunnelGetDoExpand(pFunnel)) {
Nu_FunnelSetProgressState(pFunnel, kNuProgressCopying);
err = Nu_ExpandRaw(pArchive, pThread, infp, pFunnel);
BailError(err);
goto done;
}
/*
* If we're not expanding the data, use a simple copier.
*/
if (!Nu_FunnelGetDoExpand(pFunnel)) {
Nu_FunnelSetProgressState(pFunnel, kNuProgressCopying);
err = Nu_ExpandRaw(pArchive, pThread, infp, pFunnel);
BailError(err);
goto done;
}
Nu_FunnelSetProgressState(pFunnel, kNuProgressExpanding);
switch (pThread->thThreadFormat) {
case kNuThreadFormatUncompressed:
Nu_FunnelSetProgressState(pFunnel, kNuProgressCopying);
err = Nu_ExpandUncompressed(pArchive, pRecord, pThread, infp, pFunnel,
pCalcCrc);
break;
case kNuThreadFormatHuffmanSQ:
err = kNuErrBadFormat;
Nu_ReportError(NU_BLOB, kNuErrNone,
"Huffman-compressed threads not supported");
break;
case kNuThreadFormatLZW1:
case kNuThreadFormatLZW2:
err = Nu_ExpandLZW(pArchive, pRecord, pThread, infp, pFunnel, pCalcCrc);
break;
case kNuThreadFormatLZC12:
case kNuThreadFormatLZC16:
err = kNuErrBadFormat;
Nu_ReportError(NU_BLOB, kNuErrNone,
"LZC-compressed threads not supported");
break;
default:
err = kNuErrBadFormat;
Nu_ReportError(NU_BLOB, err,
"format %u unknown", pThread->thThreadFormat);
break;
}
Nu_FunnelSetProgressState(pFunnel, kNuProgressExpanding);
switch (pThread->thThreadFormat) {
case kNuThreadFormatUncompressed:
Nu_FunnelSetProgressState(pFunnel, kNuProgressCopying);
err = Nu_ExpandUncompressed(pArchive, pRecord, pThread, infp, pFunnel,
pCalcCrc);
break;
case kNuThreadFormatHuffmanSQ:
err = kNuErrBadFormat;
Nu_ReportError(NU_BLOB, kNuErrNone,
"Huffman-compressed threads not supported");
break;
case kNuThreadFormatLZW1:
case kNuThreadFormatLZW2:
err = Nu_ExpandLZW(pArchive, pRecord, pThread, infp, pFunnel, pCalcCrc);
break;
case kNuThreadFormatLZC12:
case kNuThreadFormatLZC16:
err = kNuErrBadFormat;
Nu_ReportError(NU_BLOB, kNuErrNone,
"LZC-compressed threads not supported");
break;
default:
err = kNuErrBadFormat;
Nu_ReportError(NU_BLOB, err,
"format %u unknown", pThread->thThreadFormat);
break;
}
BailError(err);
BailError(err);
/*
* If we have a CRC to check, check it.
*/
if (pCalcCrc != nil) {
if (calcCrc != pThread->thThreadCRC) {
if (!Nu_ShouldIgnoreBadCRC(pArchive, pRecord, kNuErrBadThreadCRC)) {
err = kNuErrBadThreadCRC;
Nu_ReportError(NU_BLOB, err, "expected 0x%04x, got 0x%04x",
pThread->thThreadCRC, calcCrc);
goto bail;
}
} else {
DBUG(("--- thread CRCs match\n"));
}
}
/*
* If we have a CRC to check, check it.
*/
if (pCalcCrc != nil) {
if (calcCrc != pThread->thThreadCRC) {
if (!Nu_ShouldIgnoreBadCRC(pArchive, pRecord, kNuErrBadThreadCRC)) {
err = kNuErrBadThreadCRC;
Nu_ReportError(NU_BLOB, err, "expected 0x%04x, got 0x%04x",
pThread->thThreadCRC, calcCrc);
goto bail;
}
} else {
DBUG(("--- thread CRCs match\n"));
}
}
done:
/* make sure we send a final "success" progress message at 100% */
(void) Nu_FunnelSetProgressState(pFunnel, kNuProgressDone);
err = Nu_FunnelSendProgressUpdate(pArchive, pFunnel);
BailError(err);
/* make sure we send a final "success" progress message at 100% */
(void) Nu_FunnelSetProgressState(pFunnel, kNuProgressDone);
err = Nu_FunnelSendProgressUpdate(pArchive, pFunnel);
BailError(err);
bail:
return err;
return err;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -19,13 +19,13 @@
const char*
Nu_strerror(int errnum)
{
extern int sys_nerr;
extern char *sys_errlist[];
extern int sys_nerr;
extern char *sys_errlist[];
if (errnum < 0 || errnum > sys_nerr)
return NULL;
if (errnum < 0 || errnum > sys_nerr)
return NULL;
return sys_errlist[errnum];
return sys_errlist[errnum];
}
#endif
@ -41,13 +41,13 @@ Nu_strerror(int errnum)
void*
Nu_memmove(void* dst, const void* src, size_t n)
{
void* retval = dst;
char* srcp = (char*)src;
char* dstp = (char*)dst;
void* retval = dst;
char* srcp = (char*)src;
char* dstp = (char*)dst;
/* you can normally get away with this if n==0 */
assert(dst != NULL);
assert(src != NULL);
/* you can normally get away with this if n==0 */
assert(dst != NULL);
assert(src != NULL);
if (dstp == srcp || !n) {
/* nothing to do */
@ -63,7 +63,7 @@ Nu_memmove(void* dst, const void* src, size_t n)
*dstp++ = *srcp++;
}
return retval;
return retval;
}
#endif
@ -83,7 +83,7 @@ Nu_memmove(void* dst, const void* src, size_t n)
unsigned long
Nu_strtoul(const char *nptr, char **endptr, int base)
{
return strtol(nptr, endptr, base);
return strtol(nptr, endptr, base);
}
#endif
@ -94,9 +94,9 @@ Nu_strtoul(const char *nptr, char **endptr, int base)
int
Nu_strcasecmp(const char *str1, const char *str2)
{
while (*str1 && *str2 && toupper(*str1) == toupper(*str2))
str1++, str2++;
return (toupper(*str1) - toupper(*str2));
while (*str1 && *str2 && toupper(*str1) == toupper(*str2))
str1++, str2++;
return (toupper(*str1) - toupper(*str2));
}
#endif
@ -108,13 +108,13 @@ Nu_strcasecmp(const char *str1, const char *str2)
int
Nu_strncasecmp(const char *str1, const char *str2, size_t n)
{
while (n && *str1 && *str2 && toupper(*str1) == toupper(*str2))
str1++, str2++, n--;
while (n && *str1 && *str2 && toupper(*str1) == toupper(*str2))
str1++, str2++, n--;
if (n)
return (toupper(*str1) - toupper(*str2));
else
return 0; /* no mismatch in first n chars */
if (n)
return (toupper(*str1) - toupper(*str2));
else
return 0; /* no mismatch in first n chars */
}
#endif

View File

@ -42,11 +42,11 @@ int Nu_strncasecmp(const char *s1, const char *s2, size_t n);
#include <sys/types.h>
#define nil NULL /* I can't seem to stop typing 'nil' now */
#define nil NULL /* I can't seem to stop typing 'nil' now */
typedef uchar Boolean;
#define false (0)
#define true (!false)
typedef uchar Boolean;
#define false (0)
#define true (!false)
/*
@ -54,15 +54,15 @@ typedef uchar Boolean;
*/
/* compute #of elements in a static array */
#define NELEM(x) (sizeof(x) / sizeof((x)[0]))
#define NELEM(x) (sizeof(x) / sizeof((x)[0]))
/* convert single hex digit char to number */
#define HexDigit(x) ( !isxdigit((int)(x)) ? -1 : \
(x) <= '9' ? (x) - '0' : toupper(x) +10 - 'A' )
(x) <= '9' ? (x) - '0' : toupper(x) +10 - 'A' )
/* convert number from 0-15 to hex digit */
#define HexConv(x) ( ((uint)(x)) <= 15 ? \
( (x) <= 9 ? (x) + '0' : (x) -10 + 'A') : -1 )
#define HexConv(x) ( ((uint)(x)) <= 15 ? \
( (x) <= 9 ? (x) + '0' : (x) -10 + 'A') : -1 )
/*
@ -80,29 +80,29 @@ typedef uchar Boolean;
#if defined(DEBUG_VERBOSE)
/* quick debug printf macro */
#define DBUG(args) printf args
#define DBUG(args) printf args
#else
#define DBUG(args) ((void)0)
#define DBUG(args) ((void)0)
#endif
#if defined(NDEBUG)
#define DebugFill(addr, len) ((void)0)
#define DebugFill(addr, len) ((void)0)
#define DebugAbort() ((void)0)
#define DebugAbort() ((void)0)
#else
/* when debugging, fill Malloc blocks with junk, unless we're using Purify */
#if !defined(PURIFY)
#define DebugFill(addr, len) memset(addr, 0xa3, len)
#define DebugFill(addr, len) memset(addr, 0xa3, len)
#else
#define DebugFill(addr, len) ((void)0)
#define DebugFill(addr, len) ((void)0)
#endif
#define DebugAbort() abort()
#define DebugAbort() abort()
#endif
#define kInvalidFill (0xa3)
#define kInvalidPtr ((void*)0xa3a3a3a3)
#define kInvalidFill (0xa3)
#define kInvalidPtr ((void*)0xa3a3a3a3)
#endif /*__MiscStuff__*/

View File

@ -24,165 +24,165 @@ const char* kNufxLibName = "nufxlib";
const char*
Nu_StrError(NuError err)
{
/*
* BUG: this should be set up as per-thread storage in an MT environment.
* I would be more inclined to worry about this if I was expecting
* it to be used. So long as valid values are passed in, and the
* switch statement is kept up to date, we should never have cause
* to return this.
*
* An easier solution, should this present a problem for someone, would
* be to have the function return nil or "unknown error" when the
* error value isn't recognized.
*/
static char defaultMsg[32];
/*
* BUG: this should be set up as per-thread storage in an MT environment.
* I would be more inclined to worry about this if I was expecting
* it to be used. So long as valid values are passed in, and the
* switch statement is kept up to date, we should never have cause
* to return this.
*
* An easier solution, should this present a problem for someone, would
* be to have the function return nil or "unknown error" when the
* error value isn't recognized.
*/
static char defaultMsg[32];
switch (err) {
case kNuErrNone:
return "(no error)";
switch (err) {
case kNuErrNone:
return "(no error)";
case kNuErrGeneric:
return "NufxLib generic error";
case kNuErrInternal:
return "NufxLib internal error";
case kNuErrUsage:
return "NufxLib usage error";
case kNuErrSyntax:
return "NufxLib syntax error";
case kNuErrMalloc:
return "NufxLib malloc error";
case kNuErrInvalidArg:
return "Invalid arguments to NufxLib";
case kNuErrBadStruct:
return "Bad NuArchive structure passed to NufxLib";
case kNuErrBusy:
return "Attempted invalid reentrant call";
case kNuErrGeneric:
return "NufxLib generic error";
case kNuErrInternal:
return "NufxLib internal error";
case kNuErrUsage:
return "NufxLib usage error";
case kNuErrSyntax:
return "NufxLib syntax error";
case kNuErrMalloc:
return "NufxLib malloc error";
case kNuErrInvalidArg:
return "Invalid arguments to NufxLib";
case kNuErrBadStruct:
return "Bad NuArchive structure passed to NufxLib";
case kNuErrBusy:
return "Attempted invalid reentrant call";
case kNuErrSkipped:
return "Skipped by user";
case kNuErrAborted:
return "Processing aborted";
case kNuErrRename:
return "User wants to rename file";
case kNuErrSkipped:
return "Skipped by user";
case kNuErrAborted:
return "Processing aborted";
case kNuErrRename:
return "User wants to rename file";
case kNuErrFile:
return "NufxLib trouble with a file";
case kNuErrFileOpen:
return "NufxLib unable to open file";
case kNuErrFileClose:
return "NufxLib unable to close file";
case kNuErrFileRead:
return "NufxLib unable to read file";
case kNuErrFileWrite:
return "NufxLib unable to write file";
case kNuErrFileSeek:
return "NufxLib unable to seek file";
case kNuErrFileExists:
return "File already exists";
case kNuErrFileNotFound:
return "No such file or directory";
case kNuErrFileStat:
return "Couldn't get file info";
case kNuErrFileNotReadable:
return "Read access denied";
case kNuErrFile:
return "NufxLib trouble with a file";
case kNuErrFileOpen:
return "NufxLib unable to open file";
case kNuErrFileClose:
return "NufxLib unable to close file";
case kNuErrFileRead:
return "NufxLib unable to read file";
case kNuErrFileWrite:
return "NufxLib unable to write file";
case kNuErrFileSeek:
return "NufxLib unable to seek file";
case kNuErrFileExists:
return "File already exists";
case kNuErrFileNotFound:
return "No such file or directory";
case kNuErrFileStat:
return "Couldn't get file info";
case kNuErrFileNotReadable:
return "Read access denied";
case kNuErrDirExists:
return "Directory already exists";
case kNuErrNotDir:
return "Not a directory";
case kNuErrNotRegularFile:
return "Not a regular file";
case kNuErrDirCreate:
return "Unable to create directory";
case kNuErrOpenDir:
return "Unable to open directory";
case kNuErrReadDir:
return "Unable to read directory";
case kNuErrFileSetDate:
return "Unable to set file date";
case kNuErrFileSetAccess:
return "Unable to set file access";
case kNuErrDirExists:
return "Directory already exists";
case kNuErrNotDir:
return "Not a directory";
case kNuErrNotRegularFile:
return "Not a regular file";
case kNuErrDirCreate:
return "Unable to create directory";
case kNuErrOpenDir:
return "Unable to open directory";
case kNuErrReadDir:
return "Unable to read directory";
case kNuErrFileSetDate:
return "Unable to set file date";
case kNuErrFileSetAccess:
return "Unable to set file access";
case kNuErrNotNuFX:
return "Input is not a NuFX archive";
case kNuErrBadMHVersion:
return "Unrecognized Master Header version";
case kNuErrRecHdrNotFound:
return "Next record not found";
case kNuErrNoRecords:
return "No records in archive";
case kNuErrBadRecord:
return "Bad data in record";
case kNuErrBadMHCRC:
return "Bad Master Header CRC";
case kNuErrBadRHCRC:
return "Bad Record header CRC";
case kNuErrBadThreadCRC:
return "Bad Thread header CRC";
case kNuErrBadDataCRC:
return "Data CRC mismatch";
case kNuErrNotNuFX:
return "Input is not a NuFX archive";
case kNuErrBadMHVersion:
return "Unrecognized Master Header version";
case kNuErrRecHdrNotFound:
return "Next record not found";
case kNuErrNoRecords:
return "No records in archive";
case kNuErrBadRecord:
return "Bad data in record";
case kNuErrBadMHCRC:
return "Bad Master Header CRC";
case kNuErrBadRHCRC:
return "Bad Record header CRC";
case kNuErrBadThreadCRC:
return "Bad Thread header CRC";
case kNuErrBadDataCRC:
return "Data CRC mismatch";
case kNuErrBadFormat:
return "Thread compression format unsupported";
case kNuErrBadData:
return "Bad data found";
case kNuErrBufferOverrun:
return "Buffer overrun";
case kNuErrBufferUnderrun:
return "Buffer underrun";
case kNuErrOutMax:
return "Output limit exceeded";
case kNuErrBadFormat:
return "Thread compression format unsupported";
case kNuErrBadData:
return "Bad data found";
case kNuErrBufferOverrun:
return "Buffer overrun";
case kNuErrBufferUnderrun:
return "Buffer underrun";
case kNuErrOutMax:
return "Output limit exceeded";
case kNuErrNotFound:
return "Not found";
case kNuErrRecordNotFound:
return "Record not found";
case kNuErrRecIdxNotFound:
return "RecordIdx not found";
case kNuErrThreadIdxNotFound:
return "ThreadIdx not found";
case kNuErrThreadIDNotFound:
return "ThreadID not found";
case kNuErrRecNameNotFound:
return "Record name not found";
case kNuErrRecordExists:
return "Record already exists";
case kNuErrNotFound:
return "Not found";
case kNuErrRecordNotFound:
return "Record not found";
case kNuErrRecIdxNotFound:
return "RecordIdx not found";
case kNuErrThreadIdxNotFound:
return "ThreadIdx not found";
case kNuErrThreadIDNotFound:
return "ThreadID not found";
case kNuErrRecNameNotFound:
return "Record name not found";
case kNuErrRecordExists:
return "Record already exists";
case kNuErrAllDeleted:
return "Tried to delete all files";
case kNuErrArchiveRO:
return "Archive is in read-only mode";
case kNuErrModRecChange:
return "Attempt to alter a modified record";
case kNuErrModThreadChange:
return "Attempt to alter a modified thread";
case kNuErrThreadAdd:
return "Can't add conflicting threadID";
case kNuErrNotPreSized:
return "Operation only permitted on pre-sized threads";
case kNuErrPreSizeOverflow:
return "Data exceeds pre-sized thread size";
case kNuErrInvalidFilename:
return "Invalid filename";
case kNuErrAllDeleted:
return "Tried to delete all files";
case kNuErrArchiveRO:
return "Archive is in read-only mode";
case kNuErrModRecChange:
return "Attempt to alter a modified record";
case kNuErrModThreadChange:
return "Attempt to alter a modified thread";
case kNuErrThreadAdd:
return "Can't add conflicting threadID";
case kNuErrNotPreSized:
return "Operation only permitted on pre-sized threads";
case kNuErrPreSizeOverflow:
return "Data exceeds pre-sized thread size";
case kNuErrInvalidFilename:
return "Invalid filename";
case kNuErrLeadingFssep:
return "Storage name started with fssep char";
case kNuErrNotNewer:
return "New item wasn't newer than existing";
case kNuErrDuplicateNotFound:
return "Can only update an existing item";
case kNuErrDamaged:
return "Original archive may have been damaged";
case kNuErrLeadingFssep:
return "Storage name started with fssep char";
case kNuErrNotNewer:
return "New item wasn't newer than existing";
case kNuErrDuplicateNotFound:
return "Can only update an existing item";
case kNuErrDamaged:
return "Original archive may have been damaged";
default:
sprintf(defaultMsg, "(error=%d)", err);
return defaultMsg;
}
default:
sprintf(defaultMsg, "(error=%d)", err);
return defaultMsg;
}
}
#define kNuHeftyBufSize 256 /* all error messages should fit in this */
#define kNuExtraGoodies 8 /* leave room for "\0" and other trivial chars*/
#define kNuHeftyBufSize 256 /* all error messages should fit in this */
#define kNuExtraGoodies 8 /* leave room for "\0" and other trivial chars*/
/*
* Similar to perror(), but takes the error as an argument, and knows
@ -196,107 +196,107 @@ Nu_StrError(NuError err)
*/
void
Nu_ReportError(NuArchive* pArchive, const char* file, int line,
const char* function, Boolean isDebug, NuError err, const char* format, ...)
const char* function, Boolean isDebug, NuError err, const char* format, ...)
{
NuErrorMessage errorMessage;
const char* msg;
va_list args;
char buf[kNuHeftyBufSize];
int count;
#if defined(HAVE_SNPRINTF) || defined(SPRINTF_RETURNS_INT)
int cc;
#endif
NuErrorMessage errorMessage;
const char* msg;
va_list args;
char buf[kNuHeftyBufSize];
int count;
#if defined(HAVE_SNPRINTF) || defined(SPRINTF_RETURNS_INT)
int cc;
#endif
Assert(format != nil);
Assert(format != nil);
va_start(args, format);
va_start(args, format);
#if defined(HAVE_VSNPRINTF) && defined(VSNPRINTF_DECLARED)
count = vsnprintf(buf, sizeof(buf)-kNuExtraGoodies, format, args);
#else
#ifdef SPRINTF_RETURNS_INT
count = vsprintf(buf, format, args);
#else
vsprintf(buf, format, args);
count = strlen(buf);
#endif
#endif
#if defined(HAVE_VSNPRINTF) && defined(VSNPRINTF_DECLARED)
count = vsnprintf(buf, sizeof(buf)-kNuExtraGoodies, format, args);
#else
#ifdef SPRINTF_RETURNS_INT
count = vsprintf(buf, format, args);
#else
vsprintf(buf, format, args);
count = strlen(buf);
#endif
#endif
va_end(args);
va_end(args);
Assert(count > 0);
if (count < 0)
goto bail;
Assert(count > 0);
if (count < 0)
goto bail;
/* print the error code data, if any */
if (err != kNuErrNone) {
/* we know we have room for ": ", because of kNuExtraGoodies */
strcpy(buf+count, ": ");
count += 2;
/* print the error code data, if any */
if (err != kNuErrNone) {
/* we know we have room for ": ", because of kNuExtraGoodies */
strcpy(buf+count, ": ");
count += 2;
msg = nil;
if (err >= 0)
msg = strerror(err);
if (msg == nil)
msg = Nu_StrError(err);
msg = nil;
if (err >= 0)
msg = strerror(err);
if (msg == nil)
msg = Nu_StrError(err);
#if defined(HAVE_SNPRINTF) && defined(SNPRINTF_DECLARED)
if (msg == nil)
cc = snprintf(buf+count, sizeof(buf) - count,
"(unknown err=%d)", err);
else
cc = snprintf(buf+count, sizeof(buf) - count, "%s", msg);
#else
#ifdef SPRINTF_RETURNS_INT
if (msg == nil)
cc = sprintf(buf+count, "(unknown err=%d)", err);
else
cc = sprintf(buf+count, "%s", msg);
Assert(cc > 0);
count += cc;
#else
if (msg == nil)
sprintf(buf+count, "(unknown err=%d)", err);
else
sprintf(buf+count, "%s", msg);
count += strlen(buf + count);
#endif
#endif
#if defined(HAVE_SNPRINTF) && defined(SNPRINTF_DECLARED)
if (msg == nil)
cc = snprintf(buf+count, sizeof(buf) - count,
"(unknown err=%d)", err);
else
cc = snprintf(buf+count, sizeof(buf) - count, "%s", msg);
#else
#ifdef SPRINTF_RETURNS_INT
if (msg == nil)
cc = sprintf(buf+count, "(unknown err=%d)", err);
else
cc = sprintf(buf+count, "%s", msg);
Assert(cc > 0);
count += cc;
#else
if (msg == nil)
sprintf(buf+count, "(unknown err=%d)", err);
else
sprintf(buf+count, "%s", msg);
count += strlen(buf + count);
#endif
#endif
}
}
#if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) || \
!defined(SNPRINTF_DELCARED) || !defined(VSNPRINTF_DECLARED)
/* couldn't do it right, so check for overflow */
Assert(count <= kNuHeftyBufSize);
#endif
#if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) || \
!defined(SNPRINTF_DELCARED) || !defined(VSNPRINTF_DECLARED)
/* couldn't do it right, so check for overflow */
Assert(count <= kNuHeftyBufSize);
#endif
if ((pArchive != nil && pArchive->messageHandlerFunc == nil) ||
(pArchive == nil && gNuGlobalErrorMessageHandler == nil))
{
if (isDebug) {
fprintf(stderr, "%s: [%s:%d %s] %s\n", kNufxLibName,
file, line, function, buf);
} else {
fprintf(stderr, "%s: ERROR: %s\n", kNufxLibName, buf);
}
} else {
errorMessage.message = buf;
errorMessage.err = err;
errorMessage.isDebug = isDebug;
errorMessage.file = file;
errorMessage.line = line;
errorMessage.function = function;
if (pArchive == nil)
(void) (*gNuGlobalErrorMessageHandler)(pArchive, &errorMessage);
else
(void) (*pArchive->messageHandlerFunc)(pArchive, &errorMessage);
}
if ((pArchive != nil && pArchive->messageHandlerFunc == nil) ||
(pArchive == nil && gNuGlobalErrorMessageHandler == nil))
{
if (isDebug) {
fprintf(stderr, "%s: [%s:%d %s] %s\n", kNufxLibName,
file, line, function, buf);
} else {
fprintf(stderr, "%s: ERROR: %s\n", kNufxLibName, buf);
}
} else {
errorMessage.message = buf;
errorMessage.err = err;
errorMessage.isDebug = isDebug;
errorMessage.file = file;
errorMessage.line = line;
errorMessage.function = function;
if (pArchive == nil)
(void) (*gNuGlobalErrorMessageHandler)(pArchive, &errorMessage);
else
(void) (*pArchive->messageHandlerFunc)(pArchive, &errorMessage);
}
bail:
return;
return;
}
@ -313,46 +313,46 @@ bail:
void*
Nu_Malloc(NuArchive* pArchive, size_t size)
{
void* _result;
void* _result;
Assert(size > 0);
_result = malloc(size);
if (_result == nil) {
Nu_ReportError(NU_BLOB, kNuErrMalloc, "malloc(%u) failed", (uint) size);
DebugAbort(); /* leave a core dump if we're built for it */
}
DebugFill(_result, size);
return _result;
Assert(size > 0);
_result = malloc(size);
if (_result == nil) {
Nu_ReportError(NU_BLOB, kNuErrMalloc, "malloc(%u) failed", (uint) size);
DebugAbort(); /* leave a core dump if we're built for it */
}
DebugFill(_result, size);
return _result;
}
void*
Nu_Calloc(NuArchive* pArchive, size_t size)
{
void* _cresult = Nu_Malloc(pArchive, size);
memset(_cresult, 0, size);
return _cresult;
void* _cresult = Nu_Malloc(pArchive, size);
memset(_cresult, 0, size);
return _cresult;
}
void*
Nu_Realloc(NuArchive* pArchive, void* ptr, size_t size)
{
void* _result;
void* _result;
Assert(ptr != nil); /* disallow this usage */
Assert(size > 0); /* disallow this usage */
_result = realloc(ptr, size);
if (_result == nil) {
Nu_ReportError(NU_BLOB, kNuErrMalloc, "realloc(%u) failed",(uint) size);
DebugAbort(); /* leave a core dump if we're built for it */
}
return _result;
Assert(ptr != nil); /* disallow this usage */
Assert(size > 0); /* disallow this usage */
_result = realloc(ptr, size);
if (_result == nil) {
Nu_ReportError(NU_BLOB, kNuErrMalloc, "realloc(%u) failed",(uint) size);
DebugAbort(); /* leave a core dump if we're built for it */
}
return _result;
}
void
Nu_Free(NuArchive* pArchive, void* ptr)
{
if (ptr != nil)
free(ptr);
if (ptr != nil)
free(ptr);
}
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -13,35 +13,35 @@
#define __SunOS4__
#ifdef __GNUC__
extern int _flsbuf(int, FILE*);
extern int _filbuf(FILE*);
extern int _flsbuf(int, FILE*);
extern int _filbuf(FILE*);
#endif
extern void bcopy(char*, char*, int);
extern int fclose(FILE*);
extern int fflush(FILE*);
extern int fprintf(FILE*, const char*, ...);
extern int fread(char*, int, int, FILE *);
extern int fseek(FILE*, long, int);
extern int ftruncate(int, off_t);
extern int fwrite(const char*, int, int, FILE*);
extern char* mktemp(char *template);
extern time_t mktime(struct tm*);
extern int perror(const char*);
extern int printf(const char*, ...);
extern int remove(const char*);
extern int rename(const char*, const char*);
extern int tolower(int);
extern int setvbuf(FILE*, char*, int, int);
extern int sscanf(char*, const char*, ...);
extern int strcasecmp(const char*, const char*);
extern int strncasecmp(const char*, const char*, size_t);
extern long strtol(const char *, char **, int);
extern int system(const char*);
extern time_t timelocal(struct tm*);
extern time_t time(time_t*);
extern int toupper(int);
extern int vfprintf(FILE*, const char *, va_list);
extern char* vsprintf(char *str, const char *format, va_list ap);
extern void bcopy(char*, char*, int);
extern int fclose(FILE*);
extern int fflush(FILE*);
extern int fprintf(FILE*, const char*, ...);
extern int fread(char*, int, int, FILE *);
extern int fseek(FILE*, long, int);
extern int ftruncate(int, off_t);
extern int fwrite(const char*, int, int, FILE*);
extern char* mktemp(char *template);
extern time_t mktime(struct tm*);
extern int perror(const char*);
extern int printf(const char*, ...);
extern int remove(const char*);
extern int rename(const char*, const char*);
extern int tolower(int);
extern int setvbuf(FILE*, char*, int, int);
extern int sscanf(char*, const char*, ...);
extern int strcasecmp(const char*, const char*);
extern int strncasecmp(const char*, const char*, size_t);
extern long strtol(const char *, char **, int);
extern int system(const char*);
extern time_t timelocal(struct tm*);
extern time_t time(time_t*);
extern int toupper(int);
extern int vfprintf(FILE*, const char *, va_list);
extern char* vsprintf(char *str, const char *format, va_list ap);
#endif /*__SunOS4__*/

View File

@ -104,13 +104,13 @@
#if defined(__unix__) || defined(__unix) || defined(__BEOS__) || \
defined(__hpux) || defined(_AIX) || defined(__APPLE__)
# define UNIX_LIKE /* standardize */
defined(__hpux) || defined(_AIX) || defined(__APPLE__)
# define UNIX_LIKE /* standardize */
#endif
#if defined(UNIX_LIKE)
# ifdef USE_REENTRANT_CALLS
# define _REENTRANT /* Solaris 2.x convention */
# define _REENTRANT /* Solaris 2.x convention */
# endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -15,50 +15,50 @@
NuError
Nu_GetValue(NuArchive* pArchive, NuValueID ident, NuValue* pValue)
{
NuError err = kNuErrNone;
NuError err = kNuErrNone;
if (pValue == nil)
return kNuErrInvalidArg;
if (pValue == nil)
return kNuErrInvalidArg;
switch (ident) {
case kNuValueAllowDuplicates:
*pValue = pArchive->valAllowDuplicates;
break;
case kNuValueConvertExtractedEOL:
*pValue = pArchive->valConvertExtractedEOL;
break;
case kNuValueDataCompression:
*pValue = pArchive->valDataCompression;
break;
case kNuValueDiscardWrapper:
*pValue = pArchive->valDiscardWrapper;
break;
case kNuValueEOL:
*pValue = pArchive->valEOL;
break;
case kNuValueHandleExisting:
*pValue = pArchive->valHandleExisting;
break;
case kNuValueIgnoreCRC:
*pValue = pArchive->valIgnoreCRC;
break;
case kNuValueMimicSHK:
*pValue = pArchive->valMimicSHK;
break;
case kNuValueModifyOrig:
*pValue = pArchive->valModifyOrig;
break;
case kNuValueOnlyUpdateOlder:
*pValue = pArchive->valOnlyUpdateOlder;
break;
default:
err = kNuErrInvalidArg;
Nu_ReportError(NU_BLOB, err, "Unknown ValueID %d requested", ident);
goto bail;
}
switch (ident) {
case kNuValueAllowDuplicates:
*pValue = pArchive->valAllowDuplicates;
break;
case kNuValueConvertExtractedEOL:
*pValue = pArchive->valConvertExtractedEOL;
break;
case kNuValueDataCompression:
*pValue = pArchive->valDataCompression;
break;
case kNuValueDiscardWrapper:
*pValue = pArchive->valDiscardWrapper;
break;
case kNuValueEOL:
*pValue = pArchive->valEOL;
break;
case kNuValueHandleExisting:
*pValue = pArchive->valHandleExisting;
break;
case kNuValueIgnoreCRC:
*pValue = pArchive->valIgnoreCRC;
break;
case kNuValueMimicSHK:
*pValue = pArchive->valMimicSHK;
break;
case kNuValueModifyOrig:
*pValue = pArchive->valModifyOrig;
break;
case kNuValueOnlyUpdateOlder:
*pValue = pArchive->valOnlyUpdateOlder;
break;
default:
err = kNuErrInvalidArg;
Nu_ReportError(NU_BLOB, err, "Unknown ValueID %d requested", ident);
goto bail;
}
bail:
return err;
return err;
}
@ -68,98 +68,98 @@ bail:
NuError
Nu_SetValue(NuArchive* pArchive, NuValueID ident, NuValue value)
{
NuError err = kNuErrInvalidArg;
NuError err = kNuErrInvalidArg;
switch (ident) {
case kNuValueAllowDuplicates:
if (value != true && value != false) {
Nu_ReportError(NU_BLOB, err,
"Invalid kNuValueAllowDuplicates value %ld\n", value);
goto bail;
}
pArchive->valAllowDuplicates = value;
break;
case kNuValueConvertExtractedEOL:
if (value < kNuConvertOff || value > kNuConvertAuto) {
Nu_ReportError(NU_BLOB, err,
"Invalid kNuValueConvertExtractedEOL value %ld\n", value);
goto bail;
}
pArchive->valConvertExtractedEOL = value;
break;
case kNuValueDataCompression:
if (value < kNuCompressNone || value > kNuCompressLZC16) {
Nu_ReportError(NU_BLOB, err,
"Invalid kNuValueDataCompression value %ld\n", value);
goto bail;
}
pArchive->valDataCompression = value;
break;
case kNuValueDiscardWrapper:
if (value != true && value != false) {
Nu_ReportError(NU_BLOB, err,
"Invalid kNuValueDiscardWrapper value %ld\n", value);
goto bail;
}
pArchive->valDiscardWrapper = value;
break;
case kNuValueEOL:
if (value < kNuEOLUnknown || value > kNuEOLCRLF) {
Nu_ReportError(NU_BLOB, err,
"Invalid kNuValueEOL value %ld\n", value);
goto bail;
}
pArchive->valEOL = value;
break;
case kNuValueHandleExisting:
if (value < kNuMaybeOverwrite || value > kNuMustOverwrite) {
Nu_ReportError(NU_BLOB, err,
"Invalid kNuValueHandleExisting value %ld\n", value);
goto bail;
}
pArchive->valHandleExisting = value;
break;
case kNuValueIgnoreCRC:
if (value != true && value != false) {
Nu_ReportError(NU_BLOB, err,
"Invalid kNuValueIgnoreCRC value %ld\n", value);
goto bail;
}
pArchive->valIgnoreCRC = value;
break;
case kNuValueMimicSHK:
if (value != true && value != false) {
Nu_ReportError(NU_BLOB, err,
"Invalid kNuValueMimicSHK value %ld\n", value);
goto bail;
}
pArchive->valMimicSHK = value;
break;
case kNuValueModifyOrig:
if (value != true && value != false) {
Nu_ReportError(NU_BLOB, err,
"Invalid kNuValueModifyOrig value %ld\n", value);
goto bail;
}
pArchive->valModifyOrig = value;
break;
case kNuValueOnlyUpdateOlder:
if (value != true && value != false) {
Nu_ReportError(NU_BLOB, err,
"Invalid kNuValueOnlyUpdateOlder value %ld\n", value);
goto bail;
}
pArchive->valOnlyUpdateOlder = value;
break;
default:
Nu_ReportError(NU_BLOB, err, "Unknown ValueID %d requested", ident);
goto bail;
}
switch (ident) {
case kNuValueAllowDuplicates:
if (value != true && value != false) {
Nu_ReportError(NU_BLOB, err,
"Invalid kNuValueAllowDuplicates value %ld\n", value);
goto bail;
}
pArchive->valAllowDuplicates = value;
break;
case kNuValueConvertExtractedEOL:
if (value < kNuConvertOff || value > kNuConvertAuto) {
Nu_ReportError(NU_BLOB, err,
"Invalid kNuValueConvertExtractedEOL value %ld\n", value);
goto bail;
}
pArchive->valConvertExtractedEOL = value;
break;
case kNuValueDataCompression:
if (value < kNuCompressNone || value > kNuCompressLZC16) {
Nu_ReportError(NU_BLOB, err,
"Invalid kNuValueDataCompression value %ld\n", value);
goto bail;
}
pArchive->valDataCompression = value;
break;
case kNuValueDiscardWrapper:
if (value != true && value != false) {
Nu_ReportError(NU_BLOB, err,
"Invalid kNuValueDiscardWrapper value %ld\n", value);
goto bail;
}
pArchive->valDiscardWrapper = value;
break;
case kNuValueEOL:
if (value < kNuEOLUnknown || value > kNuEOLCRLF) {
Nu_ReportError(NU_BLOB, err,
"Invalid kNuValueEOL value %ld\n", value);
goto bail;
}
pArchive->valEOL = value;
break;
case kNuValueHandleExisting:
if (value < kNuMaybeOverwrite || value > kNuMustOverwrite) {
Nu_ReportError(NU_BLOB, err,
"Invalid kNuValueHandleExisting value %ld\n", value);
goto bail;
}
pArchive->valHandleExisting = value;
break;
case kNuValueIgnoreCRC:
if (value != true && value != false) {
Nu_ReportError(NU_BLOB, err,
"Invalid kNuValueIgnoreCRC value %ld\n", value);
goto bail;
}
pArchive->valIgnoreCRC = value;
break;
case kNuValueMimicSHK:
if (value != true && value != false) {
Nu_ReportError(NU_BLOB, err,
"Invalid kNuValueMimicSHK value %ld\n", value);
goto bail;
}
pArchive->valMimicSHK = value;
break;
case kNuValueModifyOrig:
if (value != true && value != false) {
Nu_ReportError(NU_BLOB, err,
"Invalid kNuValueModifyOrig value %ld\n", value);
goto bail;
}
pArchive->valModifyOrig = value;
break;
case kNuValueOnlyUpdateOlder:
if (value != true && value != false) {
Nu_ReportError(NU_BLOB, err,
"Invalid kNuValueOnlyUpdateOlder value %ld\n", value);
goto bail;
}
pArchive->valOnlyUpdateOlder = value;
break;
default:
Nu_ReportError(NU_BLOB, err, "Unknown ValueID %d requested", ident);
goto bail;
}
err = kNuErrNone;
err = kNuErrNone;
bail:
return err;
return err;
}
@ -171,25 +171,25 @@ bail:
NuError
Nu_GetAttr(NuArchive* pArchive, NuAttrID ident, NuAttr* pAttr)
{
NuError err = kNuErrNone;
if (pAttr == nil)
return kNuErrInvalidArg;
NuError err = kNuErrNone;
if (pAttr == nil)
return kNuErrInvalidArg;
switch (ident) {
case kNuAttrArchiveType:
*pAttr = pArchive->archiveType;
break;
case kNuAttrNumRecords:
*pAttr = pArchive->masterHeader.mhTotalRecords;
break;
default:
err = kNuErrInvalidArg;
Nu_ReportError(NU_BLOB, err, "Unknown AttrID %d requested", ident);
goto bail;
}
switch (ident) {
case kNuAttrArchiveType:
*pAttr = pArchive->archiveType;
break;
case kNuAttrNumRecords:
*pAttr = pArchive->masterHeader.mhTotalRecords;
break;
default:
err = kNuErrInvalidArg;
Nu_ReportError(NU_BLOB, err, "Unknown AttrID %d requested", ident);
goto bail;
}
bail:
return err;
return err;
}
/*
@ -200,32 +200,32 @@ bail:
NuThreadFormat
Nu_ConvertCompressValToFormat(NuArchive* pArchive, NuValue compValue)
{
NuThreadFormat threadFormat;
Boolean unsup = false;
NuThreadFormat threadFormat;
Boolean unsup = false;
switch (compValue) {
case kNuCompressNone: threadFormat = kNuThreadFormatUncompressed; break;
case kNuCompressLZW1: threadFormat = kNuThreadFormatLZW1; break;
case kNuCompressLZW2: threadFormat = kNuThreadFormatLZW2; break;
case kNuCompressSQ: threadFormat = kNuThreadFormatHuffmanSQ; break;
case kNuCompressLZC12: threadFormat = kNuThreadFormatLZC12;
unsup = true; break;
case kNuCompressLZC16: threadFormat = kNuThreadFormatLZC16;
unsup = true; break;
default:
Assert(false);
Nu_ReportError(NU_BLOB, kNuErrInvalidArg,
"Unknown compress value %ld", compValue);
return kNuThreadFormatUncompressed;
}
switch (compValue) {
case kNuCompressNone: threadFormat = kNuThreadFormatUncompressed; break;
case kNuCompressLZW1: threadFormat = kNuThreadFormatLZW1; break;
case kNuCompressLZW2: threadFormat = kNuThreadFormatLZW2; break;
case kNuCompressSQ: threadFormat = kNuThreadFormatHuffmanSQ; break;
case kNuCompressLZC12: threadFormat = kNuThreadFormatLZC12;
unsup = true; break;
case kNuCompressLZC16: threadFormat = kNuThreadFormatLZC16;
unsup = true; break;
default:
Assert(false);
Nu_ReportError(NU_BLOB, kNuErrInvalidArg,
"Unknown compress value %ld", compValue);
return kNuThreadFormatUncompressed;
}
if (unsup) {
Nu_ReportError(NU_BLOB, kNuErrNone,
"Unsupported compression type 0x%04x requested (%ld)",
threadFormat, compValue);
return kNuThreadFormatUncompressed;
}
if (unsup) {
Nu_ReportError(NU_BLOB, kNuErrNone,
"Unsupported compression type 0x%04x requested (%ld)",
threadFormat, compValue);
return kNuThreadFormatUncompressed;
}
return threadFormat;
return threadFormat;
}

View File

@ -16,7 +16,7 @@ static const long gNuMinorVersion = 0;
static const long gNuBugVersion = 1;
/* executable was build on or after this date (inserted automatically) */
static const char gNuBuildDate[] = "BUILT"; /* approximate */
static const char gNuBuildDate[] = "BUILT"; /* approximate */
static const char gNuBuildFlags[] = "OPTFLAGS";
@ -25,18 +25,18 @@ static const char gNuBuildFlags[] = "OPTFLAGS";
*/
NuError
Nu_GetVersion(long* pMajorVersion, long* pMinorVersion, long* pBugVersion,
const char** ppBuildDate, const char** ppBuildFlags)
const char** ppBuildDate, const char** ppBuildFlags)
{
if (pMajorVersion != nil)
*pMajorVersion = gNuMajorVersion;
if (pMinorVersion != nil)
*pMinorVersion = gNuMinorVersion;
if (pBugVersion != nil)
*pBugVersion = gNuBugVersion;
if (ppBuildDate != nil)
*ppBuildDate = gNuBuildDate;
if (ppBuildFlags != nil)
*ppBuildFlags = gNuBuildFlags;
return kNuErrNone;
if (pMajorVersion != nil)
*pMajorVersion = gNuMajorVersion;
if (pMinorVersion != nil)
*pMinorVersion = gNuMinorVersion;
if (pBugVersion != nil)
*pBugVersion = gNuBugVersion;
if (ppBuildDate != nil)
*ppBuildDate = gNuBuildDate;
if (ppBuildFlags != nil)
*ppBuildFlags = gNuBuildFlags;
return kNuErrNone;
}

View File

@ -14,7 +14,7 @@ dnl Checks for libraries.
dnl Checks for header files.
AC_CHECK_HEADERS(fcntl.h malloc.h stdlib.h sys/stat.h sys/time.h sys/types.h \
sys/utime.h unistd.h utime.h)
sys/utime.h unistd.h utime.h)
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
@ -30,51 +30,51 @@ AC_CHECK_TYPE(ulong, unsigned long)
dnl Checks for library functions.
AC_CHECK_FUNCS(fdopen ftruncate memmove mkdir mkstemp mktime timelocal \
localtime_r snprintf strcasecmp strncasecmp strtoul strerror vsnprintf)
localtime_r snprintf strcasecmp strncasecmp strtoul strerror vsnprintf)
dnl Kent says: snprintf doesn't always have a declaration
AC_MSG_CHECKING(if snprintf is declared)
AC_CACHE_VAL(nufxlib_cv_snprintf_in_header, [
AC_EGREP_HEADER(snprintf, stdio.h,
[nufxlib_cv_snprintf_in_header=yes],
[nufxlib_cv_snprintf_in_header=no])
AC_EGREP_HEADER(snprintf, stdio.h,
[nufxlib_cv_snprintf_in_header=yes],
[nufxlib_cv_snprintf_in_header=no])
])
if test $nufxlib_cv_snprintf_in_header = "yes"; then
AC_DEFINE(SNPRINTF_DECLARED)
AC_DEFINE(SNPRINTF_DECLARED)
fi
AC_MSG_RESULT($nufxlib_cv_snprintf_in_header)
dnl Kent says: vsnprintf doesn't always have a declaration
AC_MSG_CHECKING(if vsnprintf is declared)
AC_CACHE_VAL(nufxlib_cv_vsnprintf_in_header, [
AC_EGREP_HEADER(vsnprintf, stdio.h,
[nufxlib_cv_vsnprintf_in_header=yes],
[nufxlib_cv_vsnprintf_in_header=no])
AC_EGREP_HEADER(vsnprintf, stdio.h,
[nufxlib_cv_vsnprintf_in_header=yes],
[nufxlib_cv_vsnprintf_in_header=no])
])
if test $nufxlib_cv_vsnprintf_in_header = "yes"; then
AC_DEFINE(VSNPRINTF_DECLARED)
AC_DEFINE(VSNPRINTF_DECLARED)
fi
AC_MSG_RESULT($nufxlib_cv_vsnprintf_in_header)
dnl Figure out what the build and link flags should be
SHARE_FLAGS='-shared'
if test "$host_cpu" = "powerpc" -a "$host_os" = "beos"; then
dnl BeOS/PPC, with Metrowerks compiler
CC=cc
GCC=
CFLAGS='-proc 603 -opt full'
SHARE_FLAGS='-shared -nostdlib'
echo "forcing CC to \"$CC\" and CFLAGS to \"$CFLAGS\""
dnl BeOS/PPC, with Metrowerks compiler
CC=cc
GCC=
CFLAGS='-proc 603 -opt full'
SHARE_FLAGS='-shared -nostdlib'
echo "forcing CC to \"$CC\" and CFLAGS to \"$CFLAGS\""
elif test "$host_os" = "beos"; then
dnl BeOS/x86
SHARE_FLAGS='-nostartfiles -Xlinker -soname="$@"'
dnl BeOS/x86
SHARE_FLAGS='-nostartfiles -Xlinker -soname="$@"'
fi
dnl if we're using gcc, include gcc-specific warning flags
if test -z "$GCC"; then
BUILD_FLAGS='$(OPT)'
BUILD_FLAGS='$(OPT)'
else
BUILD_FLAGS='$(OPT) $(GCC_FLAGS)'
BUILD_FLAGS='$(OPT) $(GCC_FLAGS)'
fi
AC_SUBST(BUILD_FLAGS)
@ -85,52 +85,52 @@ dnl BeOS doesn't like /usr/local/include, and gets feisty about it. If libdir
dnl and includedir are set to defaults, replace them with BeOS values. This
dnl might be going a little too far...
if test "$host_os" = "beos"; then
if test "$prefix" = "NONE" -a \
"$includedir" = '${prefix}/include' -a \
"$libdir" = '${exec_prefix}/lib' -a \
"$bindir" = '${exec_prefix}/bin' -a \
"$mandir" = '${prefix}/man'
then
echo replacing install locations with BeOS values
prefix=/boot
includedir='${prefix}/develop/headers'
libdir='${exec_prefix}/home/config/lib'
bindir='${exec_prefix}/home/config/bin'
mandir='/tmp'
AC_SUBST(prefix)
AC_SUBST(includedir)
AC_SUBST(libdir)
AC_SUBST(bindir)
AC_SUBST(mandir)
fi
if test "$prefix" = "NONE" -a \
"$includedir" = '${prefix}/include' -a \
"$libdir" = '${exec_prefix}/lib' -a \
"$bindir" = '${exec_prefix}/bin' -a \
"$mandir" = '${prefix}/man'
then
echo replacing install locations with BeOS values
prefix=/boot
includedir='${prefix}/develop/headers'
libdir='${exec_prefix}/home/config/lib'
bindir='${exec_prefix}/home/config/bin'
mandir='/tmp'
AC_SUBST(prefix)
AC_SUBST(includedir)
AC_SUBST(libdir)
AC_SUBST(bindir)
AC_SUBST(mandir)
fi
fi
dnl Test to see if sprintf does something reasonable. I'm going to assume
dnl that vsprintf and (if available) vsnprintf return the same thing.
AC_MSG_CHECKING(if sprintf returns int)
AC_CACHE_VAL(nufxlib_cv_sprintf_returns_int, [
AC_TRY_RUN([
#include <stdio.h>
int main(void)
{
int count;
char buf[8];
count = sprintf(buf, "123"); /* should return three */
exit(count != 3);
}
],
[nufxlib_cv_sprintf_returns_int=yes], [nufxlib_cv_sprintf_returns_int=no],
[nufxlib_cv_sprintf_returns_int=no])
AC_TRY_RUN([
#include <stdio.h>
int main(void)
{
int count;
char buf[8];
count = sprintf(buf, "123"); /* should return three */
exit(count != 3);
}
],
[nufxlib_cv_sprintf_returns_int=yes], [nufxlib_cv_sprintf_returns_int=no],
[nufxlib_cv_sprintf_returns_int=no])
])
if test $nufxlib_cv_sprintf_returns_int = "yes"; then
AC_DEFINE(SPRINTF_RETURNS_INT)
AC_DEFINE(SPRINTF_RETURNS_INT)
fi
AC_MSG_RESULT($nufxlib_cv_sprintf_returns_int)
DMALLOC=
AC_ARG_ENABLE(dmalloc, [ --enable-dmalloc: do dmalloc stuff], \
[ echo "--- enabling dmalloc"; \
DMALLOC="-L/usr/local/lib -ldmalloc"; AC_DEFINE(USE_DMALLOC) ])
[ echo "--- enabling dmalloc"; \
DMALLOC="-L/usr/local/lib -ldmalloc"; AC_DEFINE(USE_DMALLOC) ])
AC_SUBST(DMALLOC)
AC_OUTPUT(Makefile samples/Makefile)