From 768a224513d70941e8c821f461fbb437871c2a7b Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Sat, 21 Sep 2002 00:49:42 +0000 Subject: [PATCH] Reformatted files to use spaces instead of hard tabs. No substantitve changes. --- nufxlib-0/Archive.c | 1362 ++++++++-------- nufxlib-0/ArchiveIO.c | 382 ++--- nufxlib-0/Compress.c | 510 +++--- nufxlib-0/Crc16.c | 28 +- nufxlib-0/Debug.c | 484 +++--- nufxlib-0/Deferred.c | 3382 +++++++++++++++++++------------------- nufxlib-0/Entry.c | 674 ++++---- nufxlib-0/Expand.c | 290 ++-- nufxlib-0/FileIO.c | 1464 ++++++++--------- nufxlib-0/Funnel.c | 840 +++++----- nufxlib-0/Lzw.c | 2160 ++++++++++++------------ nufxlib-0/MiscStuff.c | 44 +- nufxlib-0/MiscStuff.h | 34 +- nufxlib-0/MiscUtils.c | 508 +++--- nufxlib-0/NufxLib.h | 776 ++++----- nufxlib-0/NufxLibPriv.h | 664 ++++---- nufxlib-0/Record.c | 3438 +++++++++++++++++++-------------------- nufxlib-0/SourceSink.c | 872 +++++----- nufxlib-0/SunOS4.h | 56 +- nufxlib-0/SysDefs.h | 6 +- nufxlib-0/Thread.c | 1616 +++++++++--------- nufxlib-0/Value.c | 336 ++-- nufxlib-0/Version.c.in | 26 +- nufxlib-0/configure.in | 106 +- 24 files changed, 10029 insertions(+), 10029 deletions(-) diff --git a/nufxlib-0/Archive.c b/nufxlib-0/Archive.c index 8772e39..ccc23db 100644 --- a/nufxlib-0/Archive.c +++ b/nufxlib-0/Archive.c @@ -12,37 +12,37 @@ # include #endif #ifndef O_BINARY -# define O_BINARY 0 +# define O_BINARY 0 #endif /* master header identification */ static const uchar kNuMasterID[kNufileIDLen] = - { 0x4e, 0xf5, 0x46, 0xe9, 0x6c, 0xe5 }; + { 0x4e, 0xf5, 0x46, 0xe9, 0x6c, 0xe5 }; /* other identification; can be no longer than kNufileIDLen */ static const uchar kNuBinary2ID[] = - { 0x0a, 0x47, 0x4c }; + { 0x0a, 0x47, 0x4c }; static const uchar kNuSHKSEAID[] = - { 0xa2, 0x2e, 0x00 }; + { 0xa2, 0x2e, 0x00 }; /* * Offsets to some interesting places in the wrappers. */ -#define kNuBNYFileSizeLo 8 /* file size in 512-byte blocks (2B) */ -#define kNuBNYFileSizeHi 114 /* ... (2B) */ -#define kNuBNYEOFLo 20 /* file size in bytes (3B) */ -#define kNuBNYEOFHi 116 /* ... (1B) */ -#define kNuBNYDiskSpace 117 /* total space req'd; equiv FileSize (4B) */ -#define kNuBNYFilesToFollow 127 /* (1B) #of files in rest of BNY file */ -#define kNuSEAFunkySize 11938 /* length of archive + 68 (4B?) */ -#define kNuSEAFunkyAdjust 68 /* ... adjustment to "FunkySize" */ -#define kNuSEALength1 11946 /* length of archive (4B?) */ -#define kNuSEALength2 12001 /* length of archive (4B?) */ +#define kNuBNYFileSizeLo 8 /* file size in 512-byte blocks (2B) */ +#define kNuBNYFileSizeHi 114 /* ... (2B) */ +#define kNuBNYEOFLo 20 /* file size in bytes (3B) */ +#define kNuBNYEOFHi 116 /* ... (1B) */ +#define kNuBNYDiskSpace 117 /* total space req'd; equiv FileSize (4B) */ +#define kNuBNYFilesToFollow 127 /* (1B) #of files in rest of BNY file */ +#define kNuSEAFunkySize 11938 /* length of archive + 68 (4B?) */ +#define kNuSEAFunkyAdjust 68 /* ... adjustment to "FunkySize" */ +#define kNuSEALength1 11946 /* length of archive (4B?) */ +#define kNuSEALength2 12001 /* length of archive (4B?) */ /* * =========================================================================== - * Archive and MasterHeader utility functions + * Archive and MasterHeader utility functions * =========================================================================== */ @@ -52,40 +52,40 @@ static const uchar kNuSHKSEAID[] = static NuError Nu_NuArchiveNew(NuArchive** ppArchive) { - Assert(ppArchive != nil); + Assert(ppArchive != nil); - /* validate some assumptions we make throughout the code */ - Assert(sizeof(int) >= 2); - Assert(sizeof(ushort) >= 2); - Assert(sizeof(ulong) >= 4); - Assert(sizeof(void*) >= sizeof(NuArchive*)); + /* validate some assumptions we make throughout the code */ + Assert(sizeof(int) >= 2); + Assert(sizeof(ushort) >= 2); + Assert(sizeof(ulong) >= 4); + Assert(sizeof(void*) >= sizeof(NuArchive*)); - *ppArchive = Nu_Calloc(nil, sizeof(**ppArchive)); - if (*ppArchive == nil) - return kNuErrMalloc; + *ppArchive = Nu_Calloc(nil, sizeof(**ppArchive)); + if (*ppArchive == nil) + return kNuErrMalloc; - (*ppArchive)->structMagic = kNuArchiveStructMagic; + (*ppArchive)->structMagic = kNuArchiveStructMagic; - (*ppArchive)->recordIdxSeed = 1000; /* could be a random number */ - (*ppArchive)->nextRecordIdx = (*ppArchive)->recordIdxSeed; + (*ppArchive)->recordIdxSeed = 1000; /* could be a random number */ + (*ppArchive)->nextRecordIdx = (*ppArchive)->recordIdxSeed; - /* - * Initialize assorted values to defaults. We don't try to do any - * system-specific values here; it's up to the application to decide - * what is most appropriate for the current system. - */ - (*ppArchive)->valAllowDuplicates = false; - (*ppArchive)->valConvertExtractedEOL = kNuConvertOff; - (*ppArchive)->valDataCompression = kNuCompressLZW2; - (*ppArchive)->valDiscardWrapper = false; - (*ppArchive)->valEOL = kNuEOLLF; /* non-UNIX apps must override */ - (*ppArchive)->valHandleExisting = kNuMaybeOverwrite; - (*ppArchive)->valIgnoreCRC = false; - (*ppArchive)->valMimicSHK = false; - (*ppArchive)->valModifyOrig = false; - (*ppArchive)->valOnlyUpdateOlder = false; + /* + * Initialize assorted values to defaults. We don't try to do any + * system-specific values here; it's up to the application to decide + * what is most appropriate for the current system. + */ + (*ppArchive)->valAllowDuplicates = false; + (*ppArchive)->valConvertExtractedEOL = kNuConvertOff; + (*ppArchive)->valDataCompression = kNuCompressLZW2; + (*ppArchive)->valDiscardWrapper = false; + (*ppArchive)->valEOL = kNuEOLLF; /* non-UNIX apps must override */ + (*ppArchive)->valHandleExisting = kNuMaybeOverwrite; + (*ppArchive)->valIgnoreCRC = false; + (*ppArchive)->valMimicSHK = false; + (*ppArchive)->valModifyOrig = false; + (*ppArchive)->valOnlyUpdateOlder = false; - return kNuErrNone; + return kNuErrNone; } /* @@ -94,25 +94,25 @@ Nu_NuArchiveNew(NuArchive** ppArchive) static NuError Nu_NuArchiveFree(NuArchive* pArchive) { - Assert(pArchive != nil); - Assert(pArchive->structMagic == kNuArchiveStructMagic); + Assert(pArchive != nil); + Assert(pArchive->structMagic == kNuArchiveStructMagic); - (void) Nu_RecordSet_FreeAllRecords(pArchive, &pArchive->origRecordSet); - pArchive->haveToc = false; - (void) Nu_RecordSet_FreeAllRecords(pArchive, &pArchive->copyRecordSet); - (void) Nu_RecordSet_FreeAllRecords(pArchive, &pArchive->newRecordSet); + (void) Nu_RecordSet_FreeAllRecords(pArchive, &pArchive->origRecordSet); + pArchive->haveToc = false; + (void) Nu_RecordSet_FreeAllRecords(pArchive, &pArchive->copyRecordSet); + (void) Nu_RecordSet_FreeAllRecords(pArchive, &pArchive->newRecordSet); - Nu_Free(nil, pArchive->archivePathname); - Nu_Free(nil, pArchive->tmpPathname); - Nu_Free(nil, pArchive->compBuf); - Nu_Free(nil, pArchive->lzwCompressState); - Nu_Free(nil, pArchive->lzwExpandState); + Nu_Free(nil, pArchive->archivePathname); + Nu_Free(nil, pArchive->tmpPathname); + Nu_Free(nil, pArchive->compBuf); + Nu_Free(nil, pArchive->lzwCompressState); + Nu_Free(nil, pArchive->lzwExpandState); - /* mark it as deceased to prevent further use, then free it */ - pArchive->structMagic = kNuArchiveStructMagic ^ 0xffffffff; - Nu_Free(nil, pArchive); + /* mark it as deceased to prevent further use, then free it */ + pArchive->structMagic = kNuArchiveStructMagic ^ 0xffffffff; + Nu_Free(nil, pArchive); - return kNuErrNone; + return kNuErrNone; } @@ -121,13 +121,13 @@ Nu_NuArchiveFree(NuArchive* pArchive) */ void Nu_MasterHeaderCopy(NuArchive* pArchive, NuMasterHeader* pDstHeader, - const NuMasterHeader* pSrcHeader) + const NuMasterHeader* pSrcHeader) { - Assert(pArchive != nil); - Assert(pDstHeader != nil); - Assert(pSrcHeader != nil); + Assert(pArchive != nil); + Assert(pDstHeader != nil); + Assert(pSrcHeader != nil); - *pDstHeader = *pSrcHeader; + *pDstHeader = *pSrcHeader; } /* @@ -136,12 +136,12 @@ Nu_MasterHeaderCopy(NuArchive* pArchive, NuMasterHeader* pDstHeader, NuError Nu_GetMasterHeader(NuArchive* pArchive, const NuMasterHeader** ppMasterHeader) { - if (ppMasterHeader == nil) - return kNuErrInvalidArg; + if (ppMasterHeader == nil) + return kNuErrInvalidArg; - *ppMasterHeader = &pArchive->masterHeader; + *ppMasterHeader = &pArchive->masterHeader; - return kNuErrNone; + return kNuErrNone; } @@ -151,16 +151,16 @@ Nu_GetMasterHeader(NuArchive* pArchive, const NuMasterHeader** ppMasterHeader) NuError Nu_AllocCompressionBufferIFN(NuArchive* pArchive) { - Assert(pArchive != nil); + Assert(pArchive != nil); - if (pArchive->compBuf != nil) - return kNuErrNone; + if (pArchive->compBuf != nil) + return kNuErrNone; - pArchive->compBuf = Nu_Malloc(pArchive, kNuGenCompBufSize); - if (pArchive->compBuf == nil) - return kNuErrMalloc; + pArchive->compBuf = Nu_Malloc(pArchive, kNuGenCompBufSize); + if (pArchive->compBuf == nil) + return kNuErrMalloc; - return kNuErrNone; + return kNuErrNone; } @@ -170,7 +170,7 @@ Nu_AllocCompressionBufferIFN(NuArchive* pArchive) NuRecordIdx Nu_GetNextRecordIdx(NuArchive* pArchive) { - return pArchive->nextRecordIdx++; + return pArchive->nextRecordIdx++; } /* @@ -179,13 +179,13 @@ Nu_GetNextRecordIdx(NuArchive* pArchive) NuThreadIdx Nu_GetNextThreadIdx(NuArchive* pArchive) { - return pArchive->nextRecordIdx++; /* just use the record counter */ + return pArchive->nextRecordIdx++; /* just use the record counter */ } /* * =========================================================================== - * Wrapper (SEA, BXY, BSE) functions + * Wrapper (SEA, BXY, BSE) functions * =========================================================================== */ @@ -195,20 +195,20 @@ Nu_GetNextThreadIdx(NuArchive* pArchive) NuError Nu_CopyWrapperToTemp(NuArchive* pArchive) { - NuError err; + NuError err; - Assert(pArchive->headerOffset); /* no wrapper to copy?? */ + Assert(pArchive->headerOffset); /* no wrapper to copy?? */ - err = Nu_FSeek(pArchive->archiveFp, 0, SEEK_SET); - BailError(err); - err = Nu_FSeek(pArchive->tmpFp, 0, SEEK_SET); - BailError(err); - err = Nu_CopyFileSection(pArchive, pArchive->tmpFp, - pArchive->archiveFp, pArchive->headerOffset); - BailError(err); + err = Nu_FSeek(pArchive->archiveFp, 0, SEEK_SET); + BailError(err); + err = Nu_FSeek(pArchive->tmpFp, 0, SEEK_SET); + BailError(err); + err = Nu_CopyFileSection(pArchive, pArchive->tmpFp, + pArchive->archiveFp, pArchive->headerOffset); + BailError(err); bail: - return err; + return err; } @@ -220,8 +220,8 @@ bail: * assumed to start at offset 0. * * Wrappers must appear in this order: - * Binary II - * ShrinkIt SEA (Self-Extracting Archive) + * Binary II + * ShrinkIt SEA (Self-Extracting Archive) * * If they didn't, we wouldn't be this far. * @@ -233,127 +233,127 @@ bail: NuError Nu_UpdateWrapper(NuArchive* pArchive, FILE* fp) { - NuError err = kNuErrNone; - Boolean hasBinary2, hasSea; - uchar identBuf[kNufileIDLen]; - ulong archiveLen, archiveLen512; + NuError err = kNuErrNone; + Boolean hasBinary2, hasSea; + uchar identBuf[kNufileIDLen]; + ulong archiveLen, archiveLen512; - Assert(pArchive->newMasterHeader.isValid); /* need new crc and len */ + Assert(pArchive->newMasterHeader.isValid); /* need new crc and len */ - hasBinary2 = hasSea = false; + hasBinary2 = hasSea = false; - switch (pArchive->archiveType) { - case kNuArchiveNuFX: - goto bail; - case kNuArchiveNuFXInBNY: - hasBinary2 = true; - break; - case kNuArchiveNuFXSelfEx: - hasSea = true; - break; - case kNuArchiveNuFXSelfExInBNY: - hasBinary2 = hasSea = true; - break; - default: - if (pArchive->headerOffset) { - Nu_ReportError(NU_BLOB, kNuErrNone, "Can't fix the wrapper??"); - err = kNuErrInternal; - goto bail; - } else - goto bail; - } + switch (pArchive->archiveType) { + case kNuArchiveNuFX: + goto bail; + case kNuArchiveNuFXInBNY: + hasBinary2 = true; + break; + case kNuArchiveNuFXSelfEx: + hasSea = true; + break; + case kNuArchiveNuFXSelfExInBNY: + hasBinary2 = hasSea = true; + break; + default: + if (pArchive->headerOffset) { + Nu_ReportError(NU_BLOB, kNuErrNone, "Can't fix the wrapper??"); + err = kNuErrInternal; + goto bail; + } else + goto bail; + } - err = Nu_FSeek(fp, 0, SEEK_SET); - BailError(err); + err = Nu_FSeek(fp, 0, SEEK_SET); + BailError(err); - if (hasBinary2) { - /* sanity check - make sure it's Binary II */ - Nu_ReadBytes(pArchive, fp, identBuf, kNufileIDLen); - if ((err = Nu_HeaderIOFailed(pArchive, fp)) != kNuErrNone) { - Nu_ReportError(NU_BLOB, err, "Failed reading BNY wrapper"); - goto bail; - } - if (memcmp(identBuf, kNuBinary2ID, sizeof(kNuBinary2ID)) != 0) { - err = kNuErrInternal; - Nu_ReportError(NU_BLOB, kNuErrNone,"Didn't find Binary II wrapper"); - goto bail; - } + if (hasBinary2) { + /* sanity check - make sure it's Binary II */ + Nu_ReadBytes(pArchive, fp, identBuf, kNufileIDLen); + if ((err = Nu_HeaderIOFailed(pArchive, fp)) != kNuErrNone) { + Nu_ReportError(NU_BLOB, err, "Failed reading BNY wrapper"); + goto bail; + } + if (memcmp(identBuf, kNuBinary2ID, sizeof(kNuBinary2ID)) != 0) { + err = kNuErrInternal; + Nu_ReportError(NU_BLOB, kNuErrNone,"Didn't find Binary II wrapper"); + goto bail; + } - /* archiveLen includes the SEA wrapper, if any */ - archiveLen = pArchive->newMasterHeader.mhMasterEOF + - (pArchive->headerOffset - kNuBinary2BlockSize); - archiveLen512 = (archiveLen + 511) / 512; + /* archiveLen includes the SEA wrapper, if any */ + archiveLen = pArchive->newMasterHeader.mhMasterEOF + + (pArchive->headerOffset - kNuBinary2BlockSize); + archiveLen512 = (archiveLen + 511) / 512; - err = Nu_FSeek(fp, kNuBNYFileSizeLo - kNufileIDLen, SEEK_CUR); - BailError(err); - Nu_WriteTwo(pArchive, fp, (ushort)(archiveLen512 & 0xffff)); + err = Nu_FSeek(fp, kNuBNYFileSizeLo - kNufileIDLen, SEEK_CUR); + BailError(err); + Nu_WriteTwo(pArchive, fp, (ushort)(archiveLen512 & 0xffff)); - err = Nu_FSeek(fp, kNuBNYFileSizeHi - (kNuBNYFileSizeLo+2), SEEK_CUR); - BailError(err); - Nu_WriteTwo(pArchive, fp, (ushort)(archiveLen512 >> 16)); + err = Nu_FSeek(fp, kNuBNYFileSizeHi - (kNuBNYFileSizeLo+2), SEEK_CUR); + BailError(err); + Nu_WriteTwo(pArchive, fp, (ushort)(archiveLen512 >> 16)); - err = Nu_FSeek(fp, kNuBNYEOFLo - (kNuBNYFileSizeHi+2), SEEK_CUR); - BailError(err); - Nu_WriteTwo(pArchive, fp, (ushort)(archiveLen & 0xffff)); - Nu_WriteOne(pArchive, fp, (uchar)((archiveLen >> 16) & 0xff)); + err = Nu_FSeek(fp, kNuBNYEOFLo - (kNuBNYFileSizeHi+2), SEEK_CUR); + BailError(err); + Nu_WriteTwo(pArchive, fp, (ushort)(archiveLen & 0xffff)); + Nu_WriteOne(pArchive, fp, (uchar)((archiveLen >> 16) & 0xff)); - err = Nu_FSeek(fp, kNuBNYEOFHi - (kNuBNYEOFLo+3), SEEK_CUR); - BailError(err); - Nu_WriteOne(pArchive, fp, (uchar)(archiveLen >> 24)); + err = Nu_FSeek(fp, kNuBNYEOFHi - (kNuBNYEOFLo+3), SEEK_CUR); + BailError(err); + Nu_WriteOne(pArchive, fp, (uchar)(archiveLen >> 24)); - err = Nu_FSeek(fp, kNuBNYDiskSpace - (kNuBNYEOFHi+1), SEEK_CUR); - BailError(err); - Nu_WriteFour(pArchive, fp, archiveLen512); + err = Nu_FSeek(fp, kNuBNYDiskSpace - (kNuBNYEOFHi+1), SEEK_CUR); + BailError(err); + Nu_WriteFour(pArchive, fp, archiveLen512); - /* seek just past end of BNY wrapper */ - err = Nu_FSeek(fp, kNuBinary2BlockSize - (kNuBNYDiskSpace+4), SEEK_CUR); - BailError(err); + /* seek just past end of BNY wrapper */ + err = Nu_FSeek(fp, kNuBinary2BlockSize - (kNuBNYDiskSpace+4), SEEK_CUR); + BailError(err); - if ((err = Nu_HeaderIOFailed(pArchive, fp)) != kNuErrNone) { - Nu_ReportError(NU_BLOB, err, "Failed updating Binary II wrapper"); - goto bail; - } - } + if ((err = Nu_HeaderIOFailed(pArchive, fp)) != kNuErrNone) { + Nu_ReportError(NU_BLOB, err, "Failed updating Binary II wrapper"); + goto bail; + } + } - if (hasSea) { - /* sanity check - make sure it's SEA */ - Nu_ReadBytes(pArchive, fp, identBuf, kNufileIDLen); - if ((err = Nu_HeaderIOFailed(pArchive, fp)) != kNuErrNone) { - Nu_ReportError(NU_BLOB, err, "Failed reading SEA wrapper"); - goto bail; - } - if (memcmp(identBuf, kNuSHKSEAID, sizeof(kNuSHKSEAID)) != 0) { - err = kNuErrInternal; - Nu_ReportError(NU_BLOB, kNuErrNone, "Didn't find SEA wrapper"); - goto bail; - } + if (hasSea) { + /* sanity check - make sure it's SEA */ + Nu_ReadBytes(pArchive, fp, identBuf, kNufileIDLen); + if ((err = Nu_HeaderIOFailed(pArchive, fp)) != kNuErrNone) { + Nu_ReportError(NU_BLOB, err, "Failed reading SEA wrapper"); + goto bail; + } + if (memcmp(identBuf, kNuSHKSEAID, sizeof(kNuSHKSEAID)) != 0) { + err = kNuErrInternal; + Nu_ReportError(NU_BLOB, kNuErrNone, "Didn't find SEA wrapper"); + goto bail; + } - archiveLen = pArchive->newMasterHeader.mhMasterEOF; + archiveLen = pArchive->newMasterHeader.mhMasterEOF; - err = Nu_FSeek(fp, kNuSEAFunkySize - kNufileIDLen, SEEK_CUR); - BailError(err); - Nu_WriteFour(pArchive, fp, archiveLen + kNuSEAFunkyAdjust); + err = Nu_FSeek(fp, kNuSEAFunkySize - kNufileIDLen, SEEK_CUR); + BailError(err); + Nu_WriteFour(pArchive, fp, archiveLen + kNuSEAFunkyAdjust); - err = Nu_FSeek(fp, kNuSEALength1 - (kNuSEAFunkySize+4), SEEK_CUR); - BailError(err); - Nu_WriteTwo(pArchive, fp, (ushort)archiveLen); + err = Nu_FSeek(fp, kNuSEALength1 - (kNuSEAFunkySize+4), SEEK_CUR); + BailError(err); + Nu_WriteTwo(pArchive, fp, (ushort)archiveLen); - err = Nu_FSeek(fp, kNuSEALength2 - (kNuSEALength1+2), SEEK_CUR); - BailError(err); - Nu_WriteTwo(pArchive, fp, (ushort)archiveLen); + err = Nu_FSeek(fp, kNuSEALength2 - (kNuSEALength1+2), SEEK_CUR); + BailError(err); + Nu_WriteTwo(pArchive, fp, (ushort)archiveLen); - /* seek past end of SEA wrapper */ - err = Nu_FSeek(fp, kNuSEAOffset - (kNuSEALength2+2), SEEK_CUR); - BailError(err); + /* seek past end of SEA wrapper */ + err = Nu_FSeek(fp, kNuSEAOffset - (kNuSEALength2+2), SEEK_CUR); + BailError(err); - if ((err = Nu_HeaderIOFailed(pArchive, fp)) != kNuErrNone) { - Nu_ReportError(NU_BLOB, err, "Failed updating SEA wrapper"); - goto bail; - } - } + if ((err = Nu_HeaderIOFailed(pArchive, fp)) != kNuErrNone) { + Nu_ReportError(NU_BLOB, err, "Failed updating SEA wrapper"); + goto bail; + } + } bail: - return kNuErrNone; + return kNuErrNone; } @@ -380,68 +380,68 @@ bail: NuError Nu_AdjustWrapperPadding(NuArchive* pArchive, FILE* fp) { - NuError err = kNuErrNone; - Boolean hasBinary2, hasSea; + NuError err = kNuErrNone; + Boolean hasBinary2, hasSea; - hasBinary2 = hasSea = false; + hasBinary2 = hasSea = false; - switch (pArchive->archiveType) { - case kNuArchiveNuFX: - goto bail; - case kNuArchiveNuFXInBNY: - hasBinary2 = true; - break; - case kNuArchiveNuFXSelfEx: - hasSea = true; - break; - case kNuArchiveNuFXSelfExInBNY: - hasBinary2 = hasSea = true; - break; - default: - if (pArchive->headerOffset) { - Nu_ReportError(NU_BLOB, kNuErrNone, "Can't check the padding??"); - err = kNuErrInternal; - goto bail; - } else - goto bail; - } + switch (pArchive->archiveType) { + case kNuArchiveNuFX: + goto bail; + case kNuArchiveNuFXInBNY: + hasBinary2 = true; + break; + case kNuArchiveNuFXSelfEx: + hasSea = true; + break; + case kNuArchiveNuFXSelfExInBNY: + hasBinary2 = hasSea = true; + break; + default: + if (pArchive->headerOffset) { + Nu_ReportError(NU_BLOB, kNuErrNone, "Can't check the padding??"); + err = kNuErrInternal; + goto bail; + } else + goto bail; + } - err = Nu_FSeek(fp, 0, SEEK_END); - BailError(err); + err = Nu_FSeek(fp, 0, SEEK_END); + BailError(err); - if (hasSea && pArchive->valMimicSHK) { - /* throw on a single pad byte, for no apparent reason whatsoever */ - Nu_WriteOne(pArchive, fp, 0); - } + if (hasSea && pArchive->valMimicSHK) { + /* throw on a single pad byte, for no apparent reason whatsoever */ + Nu_WriteOne(pArchive, fp, 0); + } - if (hasBinary2) { - /* pad out to the next 128-byte boundary */ - long curOffset; + if (hasBinary2) { + /* pad out to the next 128-byte boundary */ + long curOffset; - err = Nu_FTell(fp, &curOffset); - BailError(err); + err = Nu_FTell(fp, &curOffset); + BailError(err); - if (curOffset & 0x7f) { - int i; + if (curOffset & 0x7f) { + int i; - for (i = kNuBinary2BlockSize - (curOffset & 0x7f); i > 0; i--) - Nu_WriteOne(pArchive, fp, 0); - } - } + for (i = kNuBinary2BlockSize - (curOffset & 0x7f); i > 0; i--) + Nu_WriteOne(pArchive, fp, 0); + } + } - if ((err = Nu_HeaderIOFailed(pArchive, fp)) != kNuErrNone) { - Nu_ReportError(NU_BLOB, err, "Failed updating wrapper padding"); - goto bail; - } + if ((err = Nu_HeaderIOFailed(pArchive, fp)) != kNuErrNone) { + Nu_ReportError(NU_BLOB, err, "Failed updating wrapper padding"); + goto bail; + } bail: - return err; + return err; } /* * =========================================================================== - * Open an archive + * Open an archive * =========================================================================== */ @@ -456,158 +456,158 @@ bail: static NuError Nu_ReadMasterHeader(NuArchive* pArchive) { - NuError err; - ushort crc; - FILE* fp; - NuMasterHeader* pHeader; - Boolean isBinary2 = false; - Boolean isSea = false; + NuError err; + ushort crc; + FILE* fp; + NuMasterHeader* pHeader; + Boolean isBinary2 = false; + Boolean isSea = false; - Assert(pArchive != nil); + Assert(pArchive != nil); - fp = pArchive->archiveFp; /* saves typing */ - pHeader = &pArchive->masterHeader; + fp = pArchive->archiveFp; /* saves typing */ + pHeader = &pArchive->masterHeader; - pArchive->headerOffset = 0; - Nu_ReadBytes(pArchive, fp, pHeader->mhNufileID, kNufileIDLen); + pArchive->headerOffset = 0; + Nu_ReadBytes(pArchive, fp, pHeader->mhNufileID, kNufileIDLen); - if (memcmp(pHeader->mhNufileID, kNuBinary2ID, sizeof(kNuBinary2ID)) == 0) - { - int count; + if (memcmp(pHeader->mhNufileID, kNuBinary2ID, sizeof(kNuBinary2ID)) == 0) + { + int count; - /* looks like a Binary II archive, might be BXY or BSE; seek forward */ - err = Nu_SeekArchive(pArchive, fp, kNuBNYFilesToFollow - kNufileIDLen, - SEEK_CUR); - if (err != kNuErrNone) { - err = kNuErrNotNuFX; - Nu_ReportError(NU_BLOB, kNuErrNone, - "Might be Binary II, but it's not NuFX"); - goto bail; - } + /* looks like a Binary II archive, might be BXY or BSE; seek forward */ + err = Nu_SeekArchive(pArchive, fp, kNuBNYFilesToFollow - kNufileIDLen, + SEEK_CUR); + if (err != kNuErrNone) { + err = kNuErrNotNuFX; + Nu_ReportError(NU_BLOB, kNuErrNone, + "Might be Binary II, but it's not NuFX"); + goto bail; + } - /* - * Check "files to follow", so we can be sure this isn't a BNY that - * just happened to have a .SHK as the first file. If it is, then - * any updates to the archive will trash the rest of the BNY files. - */ - count = Nu_ReadOne(pArchive, fp); - if (count != 0) { - err = kNuErrNotNuFX; - Nu_ReportError(NU_BLOB, kNuErrNone, - "This is a Binary II archive with %d files in it", count+1); - goto bail; - } + /* + * Check "files to follow", so we can be sure this isn't a BNY that + * just happened to have a .SHK as the first file. If it is, then + * any updates to the archive will trash the rest of the BNY files. + */ + count = Nu_ReadOne(pArchive, fp); + if (count != 0) { + err = kNuErrNotNuFX; + Nu_ReportError(NU_BLOB, kNuErrNone, + "This is a Binary II archive with %d files in it", count+1); + goto bail; + } - /* that was last item in BNY header, no need to seek */ - Assert(kNuBNYFilesToFollow == kNuBinary2BlockSize -1); + /* that was last item in BNY header, no need to seek */ + Assert(kNuBNYFilesToFollow == kNuBinary2BlockSize -1); - isBinary2 = true; - pArchive->headerOffset += kNuBinary2BlockSize; - Nu_ReadBytes(pArchive, fp, pHeader->mhNufileID, kNufileIDLen); - } - if (memcmp(pHeader->mhNufileID, kNuSHKSEAID, sizeof(kNuSHKSEAID)) == 0) - { - /* might be GSHK self-extracting; seek forward */ - err = Nu_SeekArchive(pArchive, fp, kNuSEAOffset - kNufileIDLen, - SEEK_CUR); - if (err != kNuErrNone) { - err = kNuErrNotNuFX; - Nu_ReportError(NU_BLOB, kNuErrNone, - "Looks like GS executable, not NuFX"); - goto bail; - } + isBinary2 = true; + pArchive->headerOffset += kNuBinary2BlockSize; + Nu_ReadBytes(pArchive, fp, pHeader->mhNufileID, kNufileIDLen); + } + if (memcmp(pHeader->mhNufileID, kNuSHKSEAID, sizeof(kNuSHKSEAID)) == 0) + { + /* might be GSHK self-extracting; seek forward */ + err = Nu_SeekArchive(pArchive, fp, kNuSEAOffset - kNufileIDLen, + SEEK_CUR); + if (err != kNuErrNone) { + err = kNuErrNotNuFX; + Nu_ReportError(NU_BLOB, kNuErrNone, + "Looks like GS executable, not NuFX"); + goto bail; + } - isSea = true; - pArchive->headerOffset += kNuSEAOffset; - Nu_ReadBytes(pArchive, fp, pHeader->mhNufileID, kNufileIDLen); - } + isSea = true; + pArchive->headerOffset += kNuSEAOffset; + Nu_ReadBytes(pArchive, fp, pHeader->mhNufileID, kNufileIDLen); + } - if (memcmp(kNuMasterID, pHeader->mhNufileID, kNufileIDLen) != 0) { - err = kNuErrNotNuFX; + if (memcmp(kNuMasterID, pHeader->mhNufileID, kNufileIDLen) != 0) { + err = kNuErrNotNuFX; - if (isBinary2) - Nu_ReportError(NU_BLOB, kNuErrNone, - "Looks like Binary II, not NuFX"); - else if (isSea) - Nu_ReportError(NU_BLOB, kNuErrNone, - "Looks like GS executable, not NuFX"); - else if (Nu_HeaderIOFailed(pArchive, fp) != kNuErrNone) - Nu_ReportError(NU_BLOB, kNuErrNone, - "Couldn't read enough data, not NuFX?"); - else - Nu_ReportError(NU_BLOB, kNuErrNone, - "Not a NuFX archive? Got 0x%02x%02x%02x%02x%02x%02x...", - pHeader->mhNufileID[0], pHeader->mhNufileID[1], - pHeader->mhNufileID[2], pHeader->mhNufileID[3], - pHeader->mhNufileID[4], pHeader->mhNufileID[5]); - goto bail; - } + if (isBinary2) + Nu_ReportError(NU_BLOB, kNuErrNone, + "Looks like Binary II, not NuFX"); + else if (isSea) + Nu_ReportError(NU_BLOB, kNuErrNone, + "Looks like GS executable, not NuFX"); + else if (Nu_HeaderIOFailed(pArchive, fp) != kNuErrNone) + Nu_ReportError(NU_BLOB, kNuErrNone, + "Couldn't read enough data, not NuFX?"); + else + Nu_ReportError(NU_BLOB, kNuErrNone, + "Not a NuFX archive? Got 0x%02x%02x%02x%02x%02x%02x...", + pHeader->mhNufileID[0], pHeader->mhNufileID[1], + pHeader->mhNufileID[2], pHeader->mhNufileID[3], + pHeader->mhNufileID[4], pHeader->mhNufileID[5]); + goto bail; + } - crc = 0; - pHeader->mhMasterCRC = Nu_ReadTwo(pArchive, fp); - pHeader->mhTotalRecords = Nu_ReadFourC(pArchive, fp, &crc); - pHeader->mhArchiveCreateWhen = Nu_ReadDateTimeC(pArchive, fp, &crc); - pHeader->mhArchiveModWhen = Nu_ReadDateTimeC(pArchive, fp, &crc); - pHeader->mhMasterVersion = Nu_ReadTwoC(pArchive, fp, &crc); - Nu_ReadBytesC(pArchive, fp, pHeader->mhReserved1, - kNufileMasterReserved1Len, &crc); - pHeader->mhMasterEOF = Nu_ReadFourC(pArchive, fp, &crc); - Nu_ReadBytesC(pArchive, fp, pHeader->mhReserved2, - kNufileMasterReserved2Len, &crc); + crc = 0; + pHeader->mhMasterCRC = Nu_ReadTwo(pArchive, fp); + pHeader->mhTotalRecords = Nu_ReadFourC(pArchive, fp, &crc); + pHeader->mhArchiveCreateWhen = Nu_ReadDateTimeC(pArchive, fp, &crc); + pHeader->mhArchiveModWhen = Nu_ReadDateTimeC(pArchive, fp, &crc); + pHeader->mhMasterVersion = Nu_ReadTwoC(pArchive, fp, &crc); + Nu_ReadBytesC(pArchive, fp, pHeader->mhReserved1, + kNufileMasterReserved1Len, &crc); + pHeader->mhMasterEOF = Nu_ReadFourC(pArchive, fp, &crc); + Nu_ReadBytesC(pArchive, fp, pHeader->mhReserved2, + kNufileMasterReserved2Len, &crc); - /* check for errors in any of the above reads */ - if ((err = Nu_HeaderIOFailed(pArchive, fp)) != kNuErrNone) { - Nu_ReportError(NU_BLOB, err, "Failed reading master header"); - goto bail; - } - if (pHeader->mhMasterVersion > kNuMaxMHVersion) { - err = kNuErrBadMHVersion; - Nu_ReportError(NU_BLOB, err, "Bad MH version %u", - pHeader->mhMasterVersion); - goto bail; - } + /* check for errors in any of the above reads */ + if ((err = Nu_HeaderIOFailed(pArchive, fp)) != kNuErrNone) { + Nu_ReportError(NU_BLOB, err, "Failed reading master header"); + goto bail; + } + if (pHeader->mhMasterVersion > kNuMaxMHVersion) { + err = kNuErrBadMHVersion; + Nu_ReportError(NU_BLOB, err, "Bad MH version %u", + pHeader->mhMasterVersion); + goto bail; + } - /* compare the CRC */ - if (!pArchive->valIgnoreCRC && crc != pHeader->mhMasterCRC) { - if (!Nu_ShouldIgnoreBadCRC(pArchive, nil, kNuErrBadMHCRC)) { - err = kNuErrBadMHCRC; - Nu_ReportError(NU_BLOB, err, "Stored MH CRC=0x%04x, calc=0x%04x", - pHeader->mhMasterCRC, crc); - goto bail; - } - } + /* compare the CRC */ + if (!pArchive->valIgnoreCRC && crc != pHeader->mhMasterCRC) { + if (!Nu_ShouldIgnoreBadCRC(pArchive, nil, kNuErrBadMHCRC)) { + err = kNuErrBadMHCRC; + Nu_ReportError(NU_BLOB, err, "Stored MH CRC=0x%04x, calc=0x%04x", + pHeader->mhMasterCRC, crc); + goto bail; + } + } - /* - * Set up a few things in the archive structure on our way out. - */ - if (isBinary2) { - if (isSea) - pArchive->archiveType = kNuArchiveNuFXSelfExInBNY; - else - pArchive->archiveType = kNuArchiveNuFXInBNY; - } else { - if (isSea) - pArchive->archiveType = kNuArchiveNuFXSelfEx; - else - pArchive->archiveType = kNuArchiveNuFX; - } + /* + * Set up a few things in the archive structure on our way out. + */ + if (isBinary2) { + if (isSea) + pArchive->archiveType = kNuArchiveNuFXSelfExInBNY; + else + pArchive->archiveType = kNuArchiveNuFXInBNY; + } else { + if (isSea) + pArchive->archiveType = kNuArchiveNuFXSelfEx; + else + pArchive->archiveType = kNuArchiveNuFX; + } - if (isSea || isBinary2) { - DBUG(("--- Archive isSea=%d isBinary2=%d type=%d\n", - isSea, isBinary2, pArchive->archiveType)); - } + if (isSea || isBinary2) { + DBUG(("--- Archive isSea=%d isBinary2=%d type=%d\n", + isSea, isBinary2, pArchive->archiveType)); + } - /*pArchive->origNumRecords = pHeader->mhTotalRecords;*/ - pArchive->currentOffset = pArchive->headerOffset + kNuMasterHeaderSize; + /*pArchive->origNumRecords = pHeader->mhTotalRecords;*/ + pArchive->currentOffset = pArchive->headerOffset + kNuMasterHeaderSize; - /*DBUG(("--- GOT: records=%ld, vers=%d, EOF=%ld, type=%d, hdrOffset=%ld\n", - pHeader->mhTotalRecords, pHeader->mhMasterVersion, - pHeader->mhMasterEOF, pArchive->archiveType, pArchive->headerOffset));*/ + /*DBUG(("--- GOT: records=%ld, vers=%d, EOF=%ld, type=%d, hdrOffset=%ld\n", + pHeader->mhTotalRecords, pHeader->mhMasterVersion, + pHeader->mhMasterEOF, pArchive->archiveType, pArchive->headerOffset));*/ - pHeader->isValid = true; + pHeader->isValid = true; bail: - return err; + return err; } @@ -618,26 +618,26 @@ bail: static void Nu_InitNewArchive(NuArchive* pArchive) { - NuMasterHeader* pHeader; - - Assert(pArchive != nil); + NuMasterHeader* pHeader; + + Assert(pArchive != nil); - pHeader = &pArchive->masterHeader; + pHeader = &pArchive->masterHeader; - memcpy(pHeader->mhNufileID, kNuMasterID, kNufileIDLen); - /*pHeader->mhMasterCRC*/ - pHeader->mhTotalRecords = 0; - Nu_SetCurrentDateTime(&pHeader->mhArchiveCreateWhen); - /*pHeader->mhArchiveModWhen*/ - pHeader->mhMasterVersion = kNuOurMHVersion; - /*pHeader->mhReserved1*/ - pHeader->mhMasterEOF = kNuMasterHeaderSize; - /*pHeader->mhReserved2*/ + memcpy(pHeader->mhNufileID, kNuMasterID, kNufileIDLen); + /*pHeader->mhMasterCRC*/ + pHeader->mhTotalRecords = 0; + Nu_SetCurrentDateTime(&pHeader->mhArchiveCreateWhen); + /*pHeader->mhArchiveModWhen*/ + pHeader->mhMasterVersion = kNuOurMHVersion; + /*pHeader->mhReserved1*/ + pHeader->mhMasterEOF = kNuMasterHeaderSize; + /*pHeader->mhReserved2*/ - pHeader->isValid = true; + pHeader->isValid = true; - /* no need to use a temp file for a newly-created archive */ - pArchive->valModifyOrig = true; + /* no need to use a temp file for a newly-created archive */ + pArchive->valModifyOrig = true; } @@ -647,30 +647,30 @@ Nu_InitNewArchive(NuArchive* pArchive) NuError Nu_StreamOpenRO(FILE* infp, NuArchive** ppArchive) { - NuError err; - NuArchive* pArchive = nil; + NuError err; + NuArchive* pArchive = nil; - Assert(infp != nil); - Assert(ppArchive != nil); + Assert(infp != nil); + Assert(ppArchive != nil); - err = Nu_NuArchiveNew(ppArchive); - if (err != kNuErrNone) - goto bail; - pArchive = *ppArchive; + err = Nu_NuArchiveNew(ppArchive); + if (err != kNuErrNone) + goto bail; + pArchive = *ppArchive; - pArchive->openMode = kNuOpenStreamingRO; - pArchive->archiveFp = infp; - pArchive->archivePathname = strdup("(stream)"); + pArchive->openMode = kNuOpenStreamingRO; + pArchive->archiveFp = infp; + pArchive->archivePathname = strdup("(stream)"); - err = Nu_ReadMasterHeader(pArchive); - BailError(err); + err = Nu_ReadMasterHeader(pArchive); + BailError(err); bail: - if (err != kNuErrNone) { - if (pArchive != nil) - (void) Nu_NuArchiveFree(pArchive); - } - return err; + if (err != kNuErrNone) { + if (pArchive != nil) + (void) Nu_NuArchiveFree(pArchive); + } + return err; } @@ -680,42 +680,42 @@ bail: NuError Nu_OpenRO(const char* archivePathname, NuArchive** ppArchive) { - NuError err; - NuArchive* pArchive = nil; - FILE* fp = nil; + NuError err; + NuArchive* pArchive = nil; + FILE* fp = nil; - if (archivePathname == nil || !strlen(archivePathname) || ppArchive == nil) - return kNuErrInvalidArg; + if (archivePathname == nil || !strlen(archivePathname) || ppArchive == nil) + return kNuErrInvalidArg; - *ppArchive = nil; + *ppArchive = nil; - fp = fopen(archivePathname, kNuFileOpenReadOnly); - if (fp == nil) { - Nu_ReportError(NU_BLOB, errno, "Unable to open '%s'", archivePathname); - err = kNuErrFileOpen; - goto bail; - } + fp = fopen(archivePathname, kNuFileOpenReadOnly); + if (fp == nil) { + Nu_ReportError(NU_BLOB, errno, "Unable to open '%s'", archivePathname); + err = kNuErrFileOpen; + goto bail; + } - err = Nu_NuArchiveNew(ppArchive); - if (err != kNuErrNone) - goto bail; - pArchive = *ppArchive; + err = Nu_NuArchiveNew(ppArchive); + if (err != kNuErrNone) + goto bail; + pArchive = *ppArchive; - pArchive->openMode = kNuOpenRO; - pArchive->archiveFp = fp; - pArchive->archivePathname = strdup(archivePathname); + pArchive->openMode = kNuOpenRO; + pArchive->archiveFp = fp; + pArchive->archivePathname = strdup(archivePathname); - err = Nu_ReadMasterHeader(pArchive); - BailError(err); + err = Nu_ReadMasterHeader(pArchive); + BailError(err); bail: - if (err != kNuErrNone) { - if (pArchive != nil) - (void) Nu_NuArchiveFree(pArchive); - if (fp != nil) - fclose(fp); - } - return err; + if (err != kNuErrNone) { + if (pArchive != nil) + (void) Nu_NuArchiveFree(pArchive); + if (fp != nil) + fclose(fp); + } + return err; } @@ -726,94 +726,94 @@ bail: static NuError Nu_OpenTempFile(char* fileName, FILE** pFp) { - NuArchive* pArchive = nil; /* dummy for NU_BLOB */ - NuError err = kNuErrNone; - int len; + NuArchive* pArchive = nil; /* dummy for NU_BLOB */ + NuError err = kNuErrNone; + int len; - /* - * If this is a mktemp-style template, use mktemp or mkstemp to fill in - * the blanks. - * - * BUG: not all implementations of mktemp actually generate a unique - * name. We probably need to do probing here. Some BSD variants like - * to complain about mktemp, since it's generally a bad way to do - * things. - */ - len = strlen(fileName); - if (len > 6 && strcmp(fileName + len - 6, "XXXXXX") == 0) { + /* + * If this is a mktemp-style template, use mktemp or mkstemp to fill in + * the blanks. + * + * BUG: not all implementations of mktemp actually generate a unique + * name. We probably need to do probing here. Some BSD variants like + * to complain about mktemp, since it's generally a bad way to do + * things. + */ + len = strlen(fileName); + if (len > 6 && strcmp(fileName + len - 6, "XXXXXX") == 0) { #if defined(HAVE_MKSTEMP) && defined(HAVE_FDOPEN) - int fd; + int fd; - DBUG(("+++ Using mkstemp\n")); + DBUG(("+++ Using mkstemp\n")); - /* this modifies the template *and* opens the file */ - fd = mkstemp(fileName); - if (fd < 0) { - err = errno ? errno : kNuErrFileOpen; - Nu_ReportError(NU_BLOB, kNuErrNone, "mkstemp failed on '%s'", - fileName); - goto bail; - } + /* this modifies the template *and* opens the file */ + fd = mkstemp(fileName); + if (fd < 0) { + err = errno ? errno : kNuErrFileOpen; + Nu_ReportError(NU_BLOB, kNuErrNone, "mkstemp failed on '%s'", + fileName); + goto bail; + } - DBUG(("--- Fd-opening temp file '%s'\n", fileName)); - *pFp = fdopen(fd, kNuFileOpenReadWriteCreat); - if (*pFp == nil) { - close(fd); - err = errno ? errno : kNuErrFileOpen; - goto bail; - } + DBUG(("--- Fd-opening temp file '%s'\n", fileName)); + *pFp = fdopen(fd, kNuFileOpenReadWriteCreat); + if (*pFp == nil) { + close(fd); + err = errno ? errno : kNuErrFileOpen; + goto bail; + } - /* file is open, we're done */ - goto bail; + /* file is open, we're done */ + goto bail; #else - char* result; + char* result; - DBUG(("+++ Using mktemp\n")); - result = mktemp(fileName); - if (result == nil) { - Nu_ReportError(NU_BLOB, kNuErrNone, "mktemp failed on '%s'", - fileName); - err = kNuErrInternal; - goto bail; - } + DBUG(("+++ Using mktemp\n")); + result = mktemp(fileName); + if (result == nil) { + Nu_ReportError(NU_BLOB, kNuErrNone, "mktemp failed on '%s'", + fileName); + err = kNuErrInternal; + goto bail; + } - /* now open the filename as usual */ + /* now open the filename as usual */ #endif - } + } - DBUG(("--- Opening temp file '%s'\n", fileName)); + DBUG(("--- Opening temp file '%s'\n", fileName)); #if defined(HAVE_FDOPEN) - { - int fd; + { + int fd; - fd = open(fileName, O_RDWR|O_CREAT|O_EXCL|O_BINARY, 0600); + fd = open(fileName, O_RDWR|O_CREAT|O_EXCL|O_BINARY, 0600); - *pFp = fdopen(fd, kNuFileOpenReadWriteCreat); - if (*pFp == nil) { - close(fd); - err = errno ? errno : kNuErrFileOpen; - goto bail; - } - } + *pFp = fdopen(fd, kNuFileOpenReadWriteCreat); + if (*pFp == nil) { + close(fd); + err = errno ? errno : kNuErrFileOpen; + goto bail; + } + } #else - /* (not sure how portable "access" is... I think it's POSIX) */ - if (access(fileName, F_OK) == 0) { - err = kNuErrFileExists; - goto bail; - } + /* (not sure how portable "access" is... I think it's POSIX) */ + if (access(fileName, F_OK) == 0) { + err = kNuErrFileExists; + goto bail; + } - *pFp = fopen(fileName, kNuFileOpenReadWriteCreat); - if (*pFp == nil) { - err = errno ? errno : kNuErrFileOpen; - goto bail; - } + *pFp = fopen(fileName, kNuFileOpenReadWriteCreat); + if (*pFp == nil) { + err = errno ? errno : kNuErrFileOpen; + goto bail; + } #endif bail: - return err; + return err; } /* @@ -822,127 +822,127 @@ bail: */ NuError Nu_OpenRW(const char* archivePathname, const char* tmpPathname, ulong flags, - NuArchive** ppArchive) + NuArchive** ppArchive) { - NuError err; - FILE* fp = nil; - FILE* tmpFp = nil; - NuArchive* pArchive = nil; - char* tmpPathDup = nil; - Boolean archiveExists; - Boolean newlyCreated; + NuError err; + FILE* fp = nil; + FILE* tmpFp = nil; + NuArchive* pArchive = nil; + char* tmpPathDup = nil; + Boolean archiveExists; + Boolean newlyCreated; - if (archivePathname == nil || !strlen(archivePathname) || - tmpPathname == nil || !strlen(tmpPathname) || ppArchive == nil || - (flags & ~(kNuOpenCreat|kNuOpenExcl)) != 0) - { - return kNuErrInvalidArg; - } + if (archivePathname == nil || !strlen(archivePathname) || + tmpPathname == nil || !strlen(tmpPathname) || ppArchive == nil || + (flags & ~(kNuOpenCreat|kNuOpenExcl)) != 0) + { + return kNuErrInvalidArg; + } - archiveExists = (access(archivePathname, F_OK) == 0); + archiveExists = (access(archivePathname, F_OK) == 0); - /* - * Open or create archive file. - */ - if (archiveExists) { - if ((flags & kNuOpenCreat) && (flags & kNuOpenExcl)) { - err = kNuErrFileExists; - Nu_ReportError(NU_BLOB, err, "File '%s' exists", archivePathname); - goto bail; - } - fp = fopen(archivePathname, kNuFileOpenReadWrite); - newlyCreated = false; - } else { - if (!(flags & kNuOpenCreat)) { - err = kNuErrFileNotFound; - Nu_ReportError(NU_BLOB, err, "File '%s' not found",archivePathname); - goto bail; - } - fp = fopen(archivePathname, kNuFileOpenReadWriteCreat); - newlyCreated = true; - } + /* + * Open or create archive file. + */ + if (archiveExists) { + if ((flags & kNuOpenCreat) && (flags & kNuOpenExcl)) { + err = kNuErrFileExists; + Nu_ReportError(NU_BLOB, err, "File '%s' exists", archivePathname); + goto bail; + } + fp = fopen(archivePathname, kNuFileOpenReadWrite); + newlyCreated = false; + } else { + if (!(flags & kNuOpenCreat)) { + err = kNuErrFileNotFound; + Nu_ReportError(NU_BLOB, err, "File '%s' not found",archivePathname); + goto bail; + } + fp = fopen(archivePathname, kNuFileOpenReadWriteCreat); + newlyCreated = true; + } - if (fp == nil) { - Nu_ReportError(NU_BLOB, errno, "Unable to open '%s'", archivePathname); - err = kNuErrFileOpen; - goto bail; - } + if (fp == nil) { + Nu_ReportError(NU_BLOB, errno, "Unable to open '%s'", archivePathname); + err = kNuErrFileOpen; + goto bail; + } - /* - * Treat zero-length files as newly-created archives. - */ - if (archiveExists && !newlyCreated) { - long length; + /* + * Treat zero-length files as newly-created archives. + */ + if (archiveExists && !newlyCreated) { + long length; - err = Nu_GetFileLength(nil, fp, &length); - BailError(err); + err = Nu_GetFileLength(nil, fp, &length); + BailError(err); - if (!length) { - DBUG(("--- treating zero-length file as newly created archive\n")); - newlyCreated = true; - } - } + if (!length) { + DBUG(("--- treating zero-length file as newly created archive\n")); + newlyCreated = true; + } + } - /* - * Create a temp file. We don't need one for a newly-created archive, - * at least not right away. It's possible the caller could add some - * files, flush the changes, and then want to delete them without - * closing and reopening the archive. - * - * So, create a temp file whether we think we need one or not. Won't - * do any harm, and might save us some troubles later. - */ - tmpPathDup = strdup(tmpPathname); - BailNil(tmpPathDup); - err = Nu_OpenTempFile(tmpPathDup, &tmpFp); - if (err != kNuErrNone) { - Nu_ReportError(NU_BLOB, err, "Failed opening temp file '%s'", - tmpPathname); - goto bail; - } + /* + * Create a temp file. We don't need one for a newly-created archive, + * at least not right away. It's possible the caller could add some + * files, flush the changes, and then want to delete them without + * closing and reopening the archive. + * + * So, create a temp file whether we think we need one or not. Won't + * do any harm, and might save us some troubles later. + */ + tmpPathDup = strdup(tmpPathname); + BailNil(tmpPathDup); + err = Nu_OpenTempFile(tmpPathDup, &tmpFp); + if (err != kNuErrNone) { + Nu_ReportError(NU_BLOB, err, "Failed opening temp file '%s'", + tmpPathname); + goto bail; + } - err = Nu_NuArchiveNew(ppArchive); - if (err != kNuErrNone) - goto bail; - pArchive = *ppArchive; + err = Nu_NuArchiveNew(ppArchive); + if (err != kNuErrNone) + goto bail; + pArchive = *ppArchive; - pArchive->openMode = kNuOpenRW; - pArchive->newlyCreated = newlyCreated; - pArchive->archiveFp = fp; - pArchive->archivePathname = strdup(archivePathname); - fp = nil; - pArchive->tmpFp = tmpFp; - tmpFp = nil; - pArchive->tmpPathname = tmpPathDup; - tmpPathDup = nil; + pArchive->openMode = kNuOpenRW; + pArchive->newlyCreated = newlyCreated; + pArchive->archiveFp = fp; + pArchive->archivePathname = strdup(archivePathname); + fp = nil; + pArchive->tmpFp = tmpFp; + tmpFp = nil; + pArchive->tmpPathname = tmpPathDup; + tmpPathDup = nil; - if (archiveExists && !newlyCreated) { - err = Nu_ReadMasterHeader(pArchive); - BailError(err); - } else { - Nu_InitNewArchive(pArchive); - } + if (archiveExists && !newlyCreated) { + err = Nu_ReadMasterHeader(pArchive); + BailError(err); + } else { + Nu_InitNewArchive(pArchive); + } bail: - if (err != kNuErrNone) { - if (pArchive != nil) { - (void) Nu_NuArchiveFree(pArchive); - *ppArchive = nil; - } - if (fp != nil) - fclose(fp); - if (tmpFp != nil) - fclose(tmpFp); - if (tmpPathDup != nil) - Nu_Free(pArchive, tmpPathDup); - } - return err; + if (err != kNuErrNone) { + if (pArchive != nil) { + (void) Nu_NuArchiveFree(pArchive); + *ppArchive = nil; + } + if (fp != nil) + fclose(fp); + if (tmpFp != nil) + fclose(tmpFp); + if (tmpPathDup != nil) + Nu_Free(pArchive, tmpPathDup); + } + return err; } /* * =========================================================================== - * Update an archive + * Update an archive * =========================================================================== */ @@ -951,57 +951,57 @@ bail: */ NuError Nu_WriteMasterHeader(NuArchive* pArchive, FILE* fp, - NuMasterHeader* pHeader) + NuMasterHeader* pHeader) { - NuError err; - long crcOffset; - ushort crc; + NuError err; + long crcOffset; + ushort crc; - Assert(pArchive != nil); - Assert(fp != nil); - Assert(pHeader != nil); - Assert(pHeader->isValid); - Assert(pHeader->mhMasterVersion == kNuOurMHVersion); + Assert(pArchive != nil); + Assert(fp != nil); + Assert(pHeader != nil); + Assert(pHeader->isValid); + Assert(pHeader->mhMasterVersion == kNuOurMHVersion); - crc = 0; + crc = 0; - Nu_WriteBytes(pArchive, fp, pHeader->mhNufileID, kNufileIDLen); - err = Nu_FTell(fp, &crcOffset); - BailError(err); - Nu_WriteTwo(pArchive, fp, 0); - Nu_WriteFourC(pArchive, fp, pHeader->mhTotalRecords, &crc); - Nu_WriteDateTimeC(pArchive, fp, pHeader->mhArchiveCreateWhen, &crc); - Nu_WriteDateTimeC(pArchive, fp, pHeader->mhArchiveModWhen, &crc); - Nu_WriteTwoC(pArchive, fp, pHeader->mhMasterVersion, &crc); - Nu_WriteBytesC(pArchive, fp, pHeader->mhReserved1, - kNufileMasterReserved1Len, &crc); - Nu_WriteFourC(pArchive, fp, pHeader->mhMasterEOF, &crc); - Nu_WriteBytesC(pArchive, fp, pHeader->mhReserved2, - kNufileMasterReserved2Len, &crc); - - /* go back and write the CRC (sadly, the seek will flush the stdio buf) */ - pHeader->mhMasterCRC = crc; - err = Nu_FSeek(fp, crcOffset, SEEK_SET); - BailError(err); - Nu_WriteTwo(pArchive, fp, pHeader->mhMasterCRC); + Nu_WriteBytes(pArchive, fp, pHeader->mhNufileID, kNufileIDLen); + err = Nu_FTell(fp, &crcOffset); + BailError(err); + Nu_WriteTwo(pArchive, fp, 0); + Nu_WriteFourC(pArchive, fp, pHeader->mhTotalRecords, &crc); + Nu_WriteDateTimeC(pArchive, fp, pHeader->mhArchiveCreateWhen, &crc); + Nu_WriteDateTimeC(pArchive, fp, pHeader->mhArchiveModWhen, &crc); + Nu_WriteTwoC(pArchive, fp, pHeader->mhMasterVersion, &crc); + Nu_WriteBytesC(pArchive, fp, pHeader->mhReserved1, + kNufileMasterReserved1Len, &crc); + Nu_WriteFourC(pArchive, fp, pHeader->mhMasterEOF, &crc); + Nu_WriteBytesC(pArchive, fp, pHeader->mhReserved2, + kNufileMasterReserved2Len, &crc); + + /* go back and write the CRC (sadly, the seek will flush the stdio buf) */ + pHeader->mhMasterCRC = crc; + err = Nu_FSeek(fp, crcOffset, SEEK_SET); + BailError(err); + Nu_WriteTwo(pArchive, fp, pHeader->mhMasterCRC); - /* check for errors in any of the above writes */ - if ((err = Nu_HeaderIOFailed(pArchive, fp)) != kNuErrNone) { - Nu_ReportError(NU_BLOB, err, "Failed writing master header"); - goto bail; - } + /* check for errors in any of the above writes */ + if ((err = Nu_HeaderIOFailed(pArchive, fp)) != kNuErrNone) { + Nu_ReportError(NU_BLOB, err, "Failed writing master header"); + goto bail; + } - DBUG(("--- Master header written successfully at %ld (crc=0x%04x)\n", - crcOffset - kNufileIDLen, crc)); + DBUG(("--- Master header written successfully at %ld (crc=0x%04x)\n", + crcOffset - kNufileIDLen, crc)); bail: - return err; + return err; } /* * =========================================================================== - * Close an archive + * Close an archive * =========================================================================== */ @@ -1014,34 +1014,34 @@ bail: static void Nu_CloseAndFree(NuArchive* pArchive) { - if (pArchive->archiveFp != nil) { - DBUG(("--- Closing archive\n")); - fclose(pArchive->archiveFp); - pArchive->archiveFp = nil; - } + if (pArchive->archiveFp != nil) { + DBUG(("--- Closing archive\n")); + fclose(pArchive->archiveFp); + pArchive->archiveFp = nil; + } - if (pArchive->tmpFp != nil) { - DBUG(("--- Closing and removing temp file\n")); - fclose(pArchive->tmpFp); - pArchive->tmpFp = nil; - Assert(pArchive->tmpPathname != nil); - if (remove(pArchive->tmpPathname) != 0) { - Nu_ReportError(NU_BLOB, errno, "Unable to remove temp file '%s'", - pArchive->tmpPathname); - /* keep going */ - } - } + if (pArchive->tmpFp != nil) { + DBUG(("--- Closing and removing temp file\n")); + fclose(pArchive->tmpFp); + pArchive->tmpFp = nil; + Assert(pArchive->tmpPathname != nil); + if (remove(pArchive->tmpPathname) != 0) { + Nu_ReportError(NU_BLOB, errno, "Unable to remove temp file '%s'", + pArchive->tmpPathname); + /* keep going */ + } + } - if (pArchive->newlyCreated && Nu_RecordSet_IsEmpty(&pArchive->origRecordSet)) - { - DBUG(("--- Newly-created archive unmodified; removing it\n")); - if (remove(pArchive->archivePathname) != 0) { - Nu_ReportError(NU_BLOB, errno, "Unable to remove archive file '%s'", - pArchive->archivePathname); - } - } - - Nu_NuArchiveFree(pArchive); + if (pArchive->newlyCreated && Nu_RecordSet_IsEmpty(&pArchive->origRecordSet)) + { + DBUG(("--- Newly-created archive unmodified; removing it\n")); + if (remove(pArchive->archivePathname) != 0) { + Nu_ReportError(NU_BLOB, errno, "Unable to remove archive file '%s'", + pArchive->archivePathname); + } + } + + Nu_NuArchiveFree(pArchive); } /* @@ -1050,26 +1050,26 @@ Nu_CloseAndFree(NuArchive* pArchive) NuError Nu_Close(NuArchive* pArchive) { - NuError err = kNuErrNone; - long flushStatus; + NuError err = kNuErrNone; + long flushStatus; - Assert(pArchive != nil); + Assert(pArchive != nil); - if (!Nu_IsReadOnly(pArchive)) - err = Nu_Flush(pArchive, &flushStatus); - if (err == kNuErrNone) - Nu_CloseAndFree(pArchive); - else { - DBUG(("--- Close NuFlush status was 0x%4lx\n", flushStatus)); - } + if (!Nu_IsReadOnly(pArchive)) + err = Nu_Flush(pArchive, &flushStatus); + if (err == kNuErrNone) + Nu_CloseAndFree(pArchive); + else { + DBUG(("--- Close NuFlush status was 0x%4lx\n", flushStatus)); + } - return err; + return err; } /* * =========================================================================== - * Delete and replace an archive + * Delete and replace an archive * =========================================================================== */ @@ -1079,11 +1079,11 @@ Nu_Close(NuArchive* pArchive) NuError Nu_DeleteArchiveFile(NuArchive* pArchive) { - Assert(pArchive != nil); - Assert(pArchive->archiveFp == nil); - Assert(pArchive->archivePathname != nil); + Assert(pArchive != nil); + Assert(pArchive->archiveFp == nil); + Assert(pArchive->archivePathname != nil); - return Nu_DeleteFile(pArchive->archivePathname); + return Nu_DeleteFile(pArchive->archivePathname); } /* @@ -1093,12 +1093,12 @@ Nu_DeleteArchiveFile(NuArchive* pArchive) NuError Nu_RenameTempToArchive(NuArchive* pArchive) { - Assert(pArchive != nil); - Assert(pArchive->archiveFp == nil); - Assert(pArchive->tmpFp == nil); - Assert(pArchive->archivePathname != nil); - Assert(pArchive->tmpPathname != nil); + Assert(pArchive != nil); + Assert(pArchive->archiveFp == nil); + Assert(pArchive->tmpFp == nil); + Assert(pArchive->archivePathname != nil); + Assert(pArchive->tmpPathname != nil); - return Nu_RenameFile(pArchive->tmpPathname, pArchive->archivePathname); + return Nu_RenameFile(pArchive->tmpPathname, pArchive->archivePathname); } diff --git a/nufxlib-0/ArchiveIO.c b/nufxlib-0/ArchiveIO.c index 71f763d..2484a29 100644 --- a/nufxlib-0/ArchiveIO.c +++ b/nufxlib-0/ArchiveIO.c @@ -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; } diff --git a/nufxlib-0/Compress.c b/nufxlib-0/Compress.c index d68a3de..bd4d9d2 100644 --- a/nufxlib-0/Compress.c +++ b/nufxlib-0/Compress.c @@ -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; } diff --git a/nufxlib-0/Crc16.c b/nufxlib-0/Crc16.c index 112853f..8188ac0 100644 --- a/nufxlib-0/Crc16.c +++ b/nufxlib-0/Crc16.c @@ -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); } diff --git a/nufxlib-0/Debug.c b/nufxlib-0/Debug.c index 4077075..df4d57f 100644 --- a/nufxlib-0/Debug.c +++ b/nufxlib-0/Debug.c @@ -12,47 +12,47 @@ /* pull a string out of one of the static arrays */ -#define GetStaticString(index, staticArray) ( \ - (index) >= NELEM(staticArray) ? "" : staticArray[index] \ - ) +#define GetStaticString(index, staticArray) ( \ + (index) >= NELEM(staticArray) ? "" : 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, " "); - goto bail; - } + /* is it valid? */ + if (pDateTime->day > 30 || pDateTime->month > 11 || pDateTime->hour > 24 || + pDateTime->minute > 59) + { + strcpy(buffer, " "); + 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 = ""; 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 = ""; 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 ? "" : 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 ? "" : 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"); + } } diff --git a/nufxlib-0/Deferred.c b/nufxlib-0/Deferred.c index 2c84aaf..1b0cb9e 100644 --- a/nufxlib-0/Deferred.c +++ b/nufxlib-0/Deferred.c @@ -11,7 +11,7 @@ /* * =========================================================================== - * NuThreadMod functions + * NuThreadMod functions * =========================================================================== */ @@ -25,26 +25,26 @@ */ NuError Nu_ThreadModAdd_New(NuArchive* pArchive, NuThreadID threadID, - NuThreadFormat threadFormat, NuDataSource* pDataSource, - NuThreadMod** ppThreadMod) + NuThreadFormat threadFormat, NuDataSource* pDataSource, + NuThreadMod** ppThreadMod) { - Assert(ppThreadMod != nil); - Assert(pDataSource != nil); + Assert(ppThreadMod != nil); + Assert(pDataSource != nil); - *ppThreadMod = Nu_Calloc(pArchive, sizeof(**ppThreadMod)); - if (*ppThreadMod == nil) - return kNuErrMalloc; + *ppThreadMod = Nu_Calloc(pArchive, sizeof(**ppThreadMod)); + if (*ppThreadMod == nil) + return kNuErrMalloc; - (*ppThreadMod)->entry.kind = kNuThreadModAdd; - (*ppThreadMod)->entry.add.threadIdx = Nu_GetNextThreadIdx(pArchive); - (*ppThreadMod)->entry.add.threadID = threadID; - (*ppThreadMod)->entry.add.threadFormat = threadFormat; - (*ppThreadMod)->entry.add.pDataSource = pDataSource; + (*ppThreadMod)->entry.kind = kNuThreadModAdd; + (*ppThreadMod)->entry.add.threadIdx = Nu_GetNextThreadIdx(pArchive); + (*ppThreadMod)->entry.add.threadID = threadID; + (*ppThreadMod)->entry.add.threadFormat = threadFormat; + (*ppThreadMod)->entry.add.pDataSource = pDataSource; - /* decide if this is a pre-sized thread [do we want to do this here??] */ - (*ppThreadMod)->entry.add.isPresized = Nu_IsPresizedThreadID(threadID); + /* decide if this is a pre-sized thread [do we want to do this here??] */ + (*ppThreadMod)->entry.add.isPresized = Nu_IsPresizedThreadID(threadID); - return kNuErrNone; + return kNuErrNone; } /* @@ -54,20 +54,20 @@ Nu_ThreadModAdd_New(NuArchive* pArchive, NuThreadID threadID, */ NuError Nu_ThreadModUpdate_New(NuArchive* pArchive, NuThreadIdx threadIdx, - NuDataSource* pDataSource, NuThreadMod** ppThreadMod) + NuDataSource* pDataSource, NuThreadMod** ppThreadMod) { - Assert(ppThreadMod != nil); - Assert(pDataSource != nil); + Assert(ppThreadMod != nil); + Assert(pDataSource != nil); - *ppThreadMod = Nu_Calloc(pArchive, sizeof(**ppThreadMod)); - if (*ppThreadMod == nil) - return kNuErrMalloc; + *ppThreadMod = Nu_Calloc(pArchive, sizeof(**ppThreadMod)); + if (*ppThreadMod == nil) + return kNuErrMalloc; - (*ppThreadMod)->entry.kind = kNuThreadModUpdate; - (*ppThreadMod)->entry.update.threadIdx = threadIdx; - (*ppThreadMod)->entry.update.pDataSource = Nu_DataSourceCopy(pDataSource); + (*ppThreadMod)->entry.kind = kNuThreadModUpdate; + (*ppThreadMod)->entry.update.threadIdx = threadIdx; + (*ppThreadMod)->entry.update.pDataSource = Nu_DataSourceCopy(pDataSource); - return kNuErrNone; + return kNuErrNone; } /* @@ -78,19 +78,19 @@ Nu_ThreadModUpdate_New(NuArchive* pArchive, NuThreadIdx threadIdx, */ NuError Nu_ThreadModDelete_New(NuArchive* pArchive, NuThreadIdx threadIdx, - NuThreadID threadID, NuThreadMod** ppThreadMod) + NuThreadID threadID, NuThreadMod** ppThreadMod) { - Assert(ppThreadMod != nil); + Assert(ppThreadMod != nil); - *ppThreadMod = Nu_Calloc(pArchive, sizeof(**ppThreadMod)); - if (*ppThreadMod == nil) - return kNuErrMalloc; + *ppThreadMod = Nu_Calloc(pArchive, sizeof(**ppThreadMod)); + if (*ppThreadMod == nil) + return kNuErrMalloc; - (*ppThreadMod)->entry.kind = kNuThreadModDelete; - (*ppThreadMod)->entry.delete.threadIdx = threadIdx; - (*ppThreadMod)->entry.delete.threadID = threadID; + (*ppThreadMod)->entry.kind = kNuThreadModDelete; + (*ppThreadMod)->entry.delete.threadIdx = threadIdx; + (*ppThreadMod)->entry.delete.threadID = threadID; - return kNuErrNone; + return kNuErrNone; } /* @@ -99,21 +99,21 @@ Nu_ThreadModDelete_New(NuArchive* pArchive, NuThreadIdx threadIdx, void Nu_ThreadModFree(NuArchive* pArchive, NuThreadMod* pThreadMod) { - if (pThreadMod == nil) - return; + if (pThreadMod == nil) + return; - switch (pThreadMod->entry.kind) { - case kNuThreadModAdd: - Nu_DataSourceFree(pThreadMod->entry.add.pDataSource); - break; - case kNuThreadModUpdate: - Nu_DataSourceFree(pThreadMod->entry.update.pDataSource); - break; - default: - break; - } + switch (pThreadMod->entry.kind) { + case kNuThreadModAdd: + Nu_DataSourceFree(pThreadMod->entry.add.pDataSource); + break; + case kNuThreadModUpdate: + Nu_DataSourceFree(pThreadMod->entry.update.pDataSource); + break; + default: + break; + } - Nu_Free(pArchive, pThreadMod); + Nu_Free(pArchive, pThreadMod); } @@ -133,42 +133,42 @@ Nu_ThreadModFree(NuArchive* pArchive, NuThreadMod* pThreadMod) NuThreadMod* Nu_ThreadMod_FindByThreadIdx(const NuRecord* pRecord, NuThreadIdx threadIdx) { - NuThreadMod* pThreadMod; - NuThreadMod* pMatch = nil; + NuThreadMod* pThreadMod; + NuThreadMod* pMatch = nil; - pThreadMod = pRecord->pThreadMods; - while (pThreadMod) { - switch (pThreadMod->entry.kind) { - case kNuThreadModAdd: - /* can't happen */ - Assert(pThreadMod->entry.add.threadIdx != threadIdx); - break; - case kNuThreadModUpdate: - if (pThreadMod->entry.update.threadIdx == threadIdx) { - Assert(pMatch == nil); - pMatch = pThreadMod; - } - break; - case kNuThreadModDelete: - if (pThreadMod->entry.delete.threadIdx == threadIdx) { - Assert(pMatch == nil); - pMatch = pThreadMod; - } - break; - default: - Assert(0); - /* keep going, I guess */ - } - pThreadMod = pThreadMod->pNext; - } + pThreadMod = pRecord->pThreadMods; + while (pThreadMod) { + switch (pThreadMod->entry.kind) { + case kNuThreadModAdd: + /* can't happen */ + Assert(pThreadMod->entry.add.threadIdx != threadIdx); + break; + case kNuThreadModUpdate: + if (pThreadMod->entry.update.threadIdx == threadIdx) { + Assert(pMatch == nil); + pMatch = pThreadMod; + } + break; + case kNuThreadModDelete: + if (pThreadMod->entry.delete.threadIdx == threadIdx) { + Assert(pMatch == nil); + pMatch = pThreadMod; + } + break; + default: + Assert(0); + /* keep going, I guess */ + } + pThreadMod = pThreadMod->pNext; + } - return pMatch; + return pMatch; } /* * =========================================================================== - * ThreadMod list operations + * ThreadMod list operations * =========================================================================== */ @@ -177,27 +177,27 @@ Nu_ThreadMod_FindByThreadIdx(const NuRecord* pRecord, NuThreadIdx threadIdx) */ NuError Nu_ThreadModAdd_FindByThreadID(const NuRecord* pRecord, NuThreadID threadID, - NuThreadMod** ppThreadMod) + NuThreadMod** ppThreadMod) { - NuThreadMod* pThreadMod; + NuThreadMod* pThreadMod; - Assert(pRecord != nil); - Assert(ppThreadMod != nil); + Assert(pRecord != nil); + Assert(ppThreadMod != nil); - pThreadMod = pRecord->pThreadMods; - while (pThreadMod != nil) { - if (pThreadMod->entry.kind != kNuThreadModAdd) - continue; + pThreadMod = pRecord->pThreadMods; + while (pThreadMod != nil) { + if (pThreadMod->entry.kind != kNuThreadModAdd) + continue; - if (pThreadMod->entry.add.threadID == threadID) { - *ppThreadMod = pThreadMod; - return kNuErrNone; - } + if (pThreadMod->entry.add.threadID == threadID) { + *ppThreadMod = pThreadMod; + return kNuErrNone; + } - pThreadMod = pThreadMod->pNext; - } + pThreadMod = pThreadMod->pNext; + } - return kNuErrNotFound; + return kNuErrNotFound; } @@ -207,37 +207,37 @@ Nu_ThreadModAdd_FindByThreadID(const NuRecord* pRecord, NuThreadID threadID, void Nu_FreeThreadMods(NuArchive* pArchive, NuRecord* pRecord) { - NuThreadMod* pThreadMod; - NuThreadMod* pNext; + NuThreadMod* pThreadMod; + NuThreadMod* pNext; - Assert(pRecord != nil); - pThreadMod = pRecord->pThreadMods; + Assert(pRecord != nil); + pThreadMod = pRecord->pThreadMods; - if (pThreadMod == nil) - return; + if (pThreadMod == nil) + return; - while (pThreadMod != nil) { - pNext = pThreadMod->pNext; + while (pThreadMod != nil) { + pNext = pThreadMod->pNext; - Nu_ThreadModFree(pArchive, pThreadMod); - pThreadMod = pNext; - } + Nu_ThreadModFree(pArchive, pThreadMod); + pThreadMod = pNext; + } - pRecord->pThreadMods = nil; + pRecord->pThreadMods = nil; } /* * =========================================================================== - * Temporary structure for holding updated thread info + * Temporary structure for holding updated thread info * =========================================================================== */ /* used when constructing a new set of threads */ typedef struct { - int numThreads; /* max #of threads */ - int nextSlot; /* where the next one goes */ - NuThread* pThreads; /* static-sized array */ + int numThreads; /* max #of threads */ + int nextSlot; /* where the next one goes */ + NuThread* pThreads; /* static-sized array */ } NuNewThreads; /* @@ -245,19 +245,19 @@ typedef struct { */ static NuError Nu_NewThreads_New(NuArchive* pArchive, NuNewThreads** ppNewThreads, - long numThreads) + long numThreads) { - NuError err = kNuErrNone; + NuError err = kNuErrNone; - *ppNewThreads = Nu_Malloc(pArchive, sizeof(**ppNewThreads)); - BailAlloc(*ppNewThreads); - (*ppNewThreads)->numThreads = numThreads; - (*ppNewThreads)->nextSlot = 0; - (*ppNewThreads)->pThreads = Nu_Malloc(pArchive, numThreads * sizeof(NuThread)); - BailAlloc((*ppNewThreads)->pThreads); + *ppNewThreads = Nu_Malloc(pArchive, sizeof(**ppNewThreads)); + BailAlloc(*ppNewThreads); + (*ppNewThreads)->numThreads = numThreads; + (*ppNewThreads)->nextSlot = 0; + (*ppNewThreads)->pThreads = Nu_Malloc(pArchive, numThreads * sizeof(NuThread)); + BailAlloc((*ppNewThreads)->pThreads); bail: - return err; + return err; } /* @@ -266,10 +266,10 @@ bail: static void Nu_NewThreads_Free(NuArchive* pArchive, NuNewThreads* pNewThreads) { - if (pNewThreads != nil) { - Nu_Free(pArchive, pNewThreads->pThreads); - Nu_Free(pArchive, pNewThreads); - } + if (pNewThreads != nil) { + Nu_Free(pArchive, pNewThreads->pThreads); + Nu_Free(pArchive, pNewThreads); + } } /* @@ -278,10 +278,10 @@ Nu_NewThreads_Free(NuArchive* pArchive, NuNewThreads* pNewThreads) static Boolean Nu_NewThreads_HasRoom(const NuNewThreads* pNewThreads) { - if (pNewThreads->nextSlot < pNewThreads->numThreads) - return true; - else - return false; + if (pNewThreads->nextSlot < pNewThreads->numThreads) + return true; + else + return false; } /* @@ -293,18 +293,18 @@ Nu_NewThreads_HasRoom(const NuNewThreads* pNewThreads) static NuThread* Nu_NewThreads_GetNext(NuNewThreads* pNewThreads, NuArchive* pArchive) { - NuThread* pThread; + NuThread* pThread; - pThread = &pNewThreads->pThreads[pNewThreads->nextSlot]; - memset(pThread, 0, sizeof(*pThread)); + pThread = &pNewThreads->pThreads[pNewThreads->nextSlot]; + memset(pThread, 0, sizeof(*pThread)); - pThread->fileOffset = -1; /* mark as invalid */ + pThread->fileOffset = -1; /* mark as invalid */ - /* advance slot */ - pNewThreads->nextSlot++; - Assert(pNewThreads->nextSlot <= pNewThreads->numThreads); + /* advance slot */ + pNewThreads->nextSlot++; + Assert(pNewThreads->nextSlot <= pNewThreads->numThreads); - return pThread; + return pThread; } /* @@ -313,9 +313,9 @@ Nu_NewThreads_GetNext(NuNewThreads* pNewThreads, NuArchive* pArchive) static int Nu_NewThreads_GetNumThreads(const NuNewThreads* pNewThreads) { - Assert(pNewThreads != nil); + Assert(pNewThreads != nil); - return pNewThreads->numThreads; + return pNewThreads->numThreads; } /* @@ -324,18 +324,18 @@ Nu_NewThreads_GetNumThreads(const NuNewThreads* pNewThreads) static ulong Nu_NewThreads_TotalCompThreadEOF(NuNewThreads* pNewThreads) { - ulong compThreadEOF; - int i; + ulong compThreadEOF; + int i; - /* we should be all full up at this point; if not, we have a bug */ - Assert(pNewThreads != nil); - Assert(pNewThreads->numThreads == pNewThreads->nextSlot); + /* we should be all full up at this point; if not, we have a bug */ + Assert(pNewThreads != nil); + Assert(pNewThreads->numThreads == pNewThreads->nextSlot); - compThreadEOF = 0; - for (i = 0; i < pNewThreads->numThreads; i++) - compThreadEOF += pNewThreads->pThreads[i].thCompThreadEOF; + compThreadEOF = 0; + for (i = 0; i < pNewThreads->numThreads; i++) + compThreadEOF += pNewThreads->pThreads[i].thCompThreadEOF; - return compThreadEOF; + return compThreadEOF; } @@ -347,16 +347,16 @@ Nu_NewThreads_TotalCompThreadEOF(NuNewThreads* pNewThreads) static NuThread* Nu_NewThreads_DonateThreads(NuNewThreads* pNewThreads) { - NuThread* pThreads = pNewThreads->pThreads; + NuThread* pThreads = pNewThreads->pThreads; - pNewThreads->pThreads = nil; - return pThreads; + pNewThreads->pThreads = nil; + return pThreads; } /* * =========================================================================== - * Archive construction - Record-level functions + * Archive construction - Record-level functions * =========================================================================== */ @@ -369,39 +369,39 @@ Nu_NewThreads_DonateThreads(NuNewThreads* pNewThreads) static NuError Nu_CopyArchiveRecord(NuArchive* pArchive, NuRecord* pRecord) { - NuError err = kNuErrNone; - long offsetAdjust; - long outputOffset; - int i; + NuError err = kNuErrNone; + long offsetAdjust; + long outputOffset; + int i; - err = Nu_FTell(pArchive->tmpFp, &outputOffset); - BailError(err); - offsetAdjust = outputOffset - pRecord->fileOffset; + err = Nu_FTell(pArchive->tmpFp, &outputOffset); + BailError(err); + offsetAdjust = outputOffset - pRecord->fileOffset; - DBUG(("--- Copying record '%s' (adj=%ld)\n", pRecord->filename, - offsetAdjust)); + DBUG(("--- Copying record '%s' (adj=%ld)\n", pRecord->filename, + offsetAdjust)); - /* seek to the start point in the source file, and copy the whole thing */ - err = Nu_FSeek(pArchive->archiveFp, pRecord->fileOffset, SEEK_SET); - BailError(err); - err = Nu_CopyFileSection(pArchive, pArchive->tmpFp, pArchive->archiveFp, - pRecord->recHeaderLength + pRecord->totalCompLength); - BailError(err); + /* seek to the start point in the source file, and copy the whole thing */ + err = Nu_FSeek(pArchive->archiveFp, pRecord->fileOffset, SEEK_SET); + BailError(err); + err = Nu_CopyFileSection(pArchive, pArchive->tmpFp, pArchive->archiveFp, + pRecord->recHeaderLength + pRecord->totalCompLength); + BailError(err); - /* adjust the file offsets in the record header and in the threads */ - pRecord->fileOffset += offsetAdjust; + /* adjust the file offsets in the record header and in the threads */ + pRecord->fileOffset += offsetAdjust; - for (i = 0; i < (int)pRecord->recTotalThreads; i++) { - NuThread* pThread = Nu_GetThread(pRecord, i); + for (i = 0; i < (int)pRecord->recTotalThreads; i++) { + NuThread* pThread = Nu_GetThread(pRecord, i); - pThread->fileOffset += offsetAdjust; - } + pThread->fileOffset += offsetAdjust; + } - Assert(outputOffset + pRecord->recHeaderLength + pRecord->totalCompLength == - (ulong)ftell(pArchive->tmpFp)); + Assert(outputOffset + pRecord->recHeaderLength + pRecord->totalCompLength == + (ulong)ftell(pArchive->tmpFp)); bail: - return err; + return err; } @@ -412,74 +412,74 @@ bail: */ static NuError Nu_CountEventualThreads(const NuRecord* pRecord, long* pTotalThreads, - long* pFilenameThreads) + long* pFilenameThreads) { - const NuThreadMod* pThreadMod; - const NuThread* pThread; - long idx, numThreads, numFilenameThreads; + const NuThreadMod* pThreadMod; + const NuThread* pThread; + long idx, numThreads, numFilenameThreads; - /* - * Number of threads is equal to: - * the number of existing threads - * MINUS the number of "delete" threadMods (you can't delete the same - * thread more than once) - * PLUS the number of "add" threadMods - */ - numThreads = pRecord->recTotalThreads; - numFilenameThreads = 0; + /* + * Number of threads is equal to: + * the number of existing threads + * MINUS the number of "delete" threadMods (you can't delete the same + * thread more than once) + * PLUS the number of "add" threadMods + */ + numThreads = pRecord->recTotalThreads; + numFilenameThreads = 0; - pThreadMod = pRecord->pThreadMods; - while (pThreadMod != nil) { - switch (pThreadMod->entry.kind) { - case kNuThreadModAdd: - numThreads++; - if (pThreadMod->entry.add.threadID == kNuThreadIDFilename) - numFilenameThreads++; - break; - case kNuThreadModDelete: - numThreads--; - if (pThreadMod->entry.delete.threadID == kNuThreadIDFilename) - numFilenameThreads--; - break; - case kNuThreadModUpdate: - break; - default: - Assert(0); - break; - } + pThreadMod = pRecord->pThreadMods; + while (pThreadMod != nil) { + switch (pThreadMod->entry.kind) { + case kNuThreadModAdd: + numThreads++; + if (pThreadMod->entry.add.threadID == kNuThreadIDFilename) + numFilenameThreads++; + break; + case kNuThreadModDelete: + numThreads--; + if (pThreadMod->entry.delete.threadID == kNuThreadIDFilename) + numFilenameThreads--; + break; + case kNuThreadModUpdate: + break; + default: + Assert(0); + break; + } - pThreadMod = pThreadMod->pNext; - } + pThreadMod = pThreadMod->pNext; + } - /* - * If the record has more than one filename thread, we only keep - * the first one, so remove it from our accounting here. It should - * not have been possible to add a new filename thread when an - * existing one was present, so we don't check the threadMods. - */ - for (idx = 0; idx < (long)pRecord->recTotalThreads; idx++) { - pThread = Nu_GetThread(pRecord, idx); - Assert(pThread != nil); + /* + * If the record has more than one filename thread, we only keep + * the first one, so remove it from our accounting here. It should + * not have been possible to add a new filename thread when an + * existing one was present, so we don't check the threadMods. + */ + for (idx = 0; idx < (long)pRecord->recTotalThreads; idx++) { + pThread = Nu_GetThread(pRecord, idx); + Assert(pThread != nil); - if (NuGetThreadID(pThread) == kNuThreadIDFilename) - numFilenameThreads++; - } - Assert(numFilenameThreads >= 0); - if (numFilenameThreads > 1) { - DBUG(("--- ODD: found multiple filename threads (%ld)\n", - numFilenameThreads)); - numThreads -= (numFilenameThreads -1); - } + if (NuGetThreadID(pThread) == kNuThreadIDFilename) + numFilenameThreads++; + } + Assert(numFilenameThreads >= 0); + if (numFilenameThreads > 1) { + DBUG(("--- ODD: found multiple filename threads (%ld)\n", + numFilenameThreads)); + numThreads -= (numFilenameThreads -1); + } - /* - * Records with no threads should've been screened out already. - */ - if (numThreads <= 0) - return kNuErrInternal; + /* + * Records with no threads should've been screened out already. + */ + if (numThreads <= 0) + return kNuErrInternal; - *pTotalThreads = numThreads; - *pFilenameThreads = numFilenameThreads; /* [should cap this at 1?] */ - return kNuErrNone; + *pTotalThreads = numThreads; + *pFilenameThreads = numFilenameThreads; /* [should cap this at 1?] */ + return kNuErrNone; } @@ -496,29 +496,29 @@ Nu_CountEventualThreads(const NuRecord* pRecord, long* pTotalThreads, static Boolean Nu_VerifyAllTouched(NuArchive* pArchive, const NuRecord* pRecord) { - const NuThreadMod* pThreadMod; - const NuThread* pThread; - long idx; + const NuThreadMod* pThreadMod; + const NuThread* pThread; + long idx; - Assert(pArchive != nil); - Assert(pRecord != nil); + Assert(pArchive != nil); + Assert(pRecord != nil); - pThreadMod = pRecord->pThreadMods; - while (pThreadMod != nil) { - if (!pThreadMod->entry.generic.used) - return false; - pThreadMod = pThreadMod->pNext; - } + pThreadMod = pRecord->pThreadMods; + while (pThreadMod != nil) { + if (!pThreadMod->entry.generic.used) + return false; + pThreadMod = pThreadMod->pNext; + } - for (idx = 0; idx < (long)pRecord->recTotalThreads; idx++) { - pThread = Nu_GetThread(pRecord, idx); - Assert(pThread != nil); + for (idx = 0; idx < (long)pRecord->recTotalThreads; idx++) { + pThread = Nu_GetThread(pRecord, idx); + Assert(pThread != nil); - if (!pThread->used) - return false; - } + if (!pThread->used) + return false; + } - return true; + return true; } @@ -534,12 +534,12 @@ Nu_VerifyAllTouched(NuArchive* pArchive, const NuRecord* pRecord) static void Nu_SetNewThreadFilename(NuArchive* pArchive, NuRecord* pRecord, char* newName) { - Assert(pRecord != nil); - Assert(newName != nil); + Assert(pRecord != nil); + Assert(newName != nil); - Nu_Free(pArchive, pRecord->threadFilename); - pRecord->threadFilename = newName; - pRecord->filename = pRecord->threadFilename; + Nu_Free(pArchive, pRecord->threadFilename); + pRecord->threadFilename = newName; + pRecord->filename = pRecord->threadFilename; } /* @@ -552,29 +552,29 @@ Nu_SetNewThreadFilename(NuArchive* pArchive, NuRecord* pRecord, char* newName) static NuError Nu_UpdateDiskImageFields(NuArchive* pArchive, NuRecord* pRecord, long sourceLen) { - NuError err = kNuErrNone; - long actualLen; + NuError err = kNuErrNone; + long actualLen; - if (pRecord->recStorageType <= 13) - pRecord->recStorageType = 512; - actualLen = pRecord->recExtraType * pRecord->recStorageType; + if (pRecord->recStorageType <= 13) + pRecord->recStorageType = 512; + actualLen = pRecord->recExtraType * pRecord->recStorageType; - if (actualLen != sourceLen) { - /* didn't match, see if we can fix it */ - DBUG(("--- fixing up disk image size\n")); - if ((sourceLen & 0x1ff) == 0) { - pRecord->recStorageType = 512; - pRecord->recExtraType = sourceLen / 512; - } else { - /* oh dear */ - err = kNuErrBadData; - Nu_ReportError(NU_BLOB, kNuErrNone,"disk image size of %ld invalid", - sourceLen); - /* fall through and out */ - } - } + if (actualLen != sourceLen) { + /* didn't match, see if we can fix it */ + DBUG(("--- fixing up disk image size\n")); + if ((sourceLen & 0x1ff) == 0) { + pRecord->recStorageType = 512; + pRecord->recExtraType = sourceLen / 512; + } else { + /* oh dear */ + err = kNuErrBadData; + Nu_ReportError(NU_BLOB, kNuErrNone,"disk image size of %ld invalid", + sourceLen); + /* fall through and out */ + } + } - return err; + return err; } /* @@ -594,91 +594,91 @@ Nu_UpdateDiskImageFields(NuArchive* pArchive, NuRecord* pRecord, long sourceLen) */ static NuError Nu_ConstructArchiveUpdate(NuArchive* pArchive, FILE* fp, NuRecord* pRecord, - NuThread* pThread, const NuThreadMod* pThreadMod) + NuThread* pThread, const NuThreadMod* pThreadMod) { - NuError err; - NuDataSource* pDataSource = nil; - ulong sourceLen; - ulong threadBufSize; + NuError err; + NuDataSource* pDataSource = nil; + ulong sourceLen; + ulong threadBufSize; - /* - * We're going to copy the data out of the data source. Because - * "update" actions only operate on pre-sized chunks, and the data - * is never compressed, this should be straightforward. However, - * we do need to make sure that the data will fit. - * - * I expect these to be small, and it's just a raw data copy, so no - * progress updater is used. - */ - Assert(Nu_IsPresizedThreadID(NuGetThreadID(pThread))); - Assert(pThread->thCompThreadEOF >= pThread->thThreadEOF); - threadBufSize = pThread->thCompThreadEOF; - pDataSource = pThreadMod->entry.update.pDataSource; - Assert(pDataSource != nil); + /* + * We're going to copy the data out of the data source. Because + * "update" actions only operate on pre-sized chunks, and the data + * is never compressed, this should be straightforward. However, + * we do need to make sure that the data will fit. + * + * I expect these to be small, and it's just a raw data copy, so no + * progress updater is used. + */ + Assert(Nu_IsPresizedThreadID(NuGetThreadID(pThread))); + Assert(pThread->thCompThreadEOF >= pThread->thThreadEOF); + threadBufSize = pThread->thCompThreadEOF; + pDataSource = pThreadMod->entry.update.pDataSource; + Assert(pDataSource != nil); - err = Nu_DataSourcePrepareInput(pArchive, pDataSource); - if (err == kNuErrSkipped) { - /* something failed (during file open?), just skip this one */ - DBUG(("--- skipping pre-sized thread update to %ld\n", - pThread->threadIdx)); - err = kNuErrNone; - goto skip_update; - } else if (err != kNuErrNone) - goto bail; + err = Nu_DataSourcePrepareInput(pArchive, pDataSource); + if (err == kNuErrSkipped) { + /* something failed (during file open?), just skip this one */ + DBUG(("--- skipping pre-sized thread update to %ld\n", + pThread->threadIdx)); + err = kNuErrNone; + goto skip_update; + } else if (err != kNuErrNone) + goto bail; - /* - * Check to see if the data will fit. In some cases we can verify - * the size during the UpdatePresizedThread call, but if it's being - * added from a file we can't tell until now. - * - * We could be nice and give the user a chance to do something about - * this, but frankly the application should have checked the file - * size before handing it to us. - */ - sourceLen = Nu_DataSourceGetDataLen(pDataSource); - if (sourceLen > pThread->thCompThreadEOF) { - err = kNuErrPreSizeOverflow; - Nu_ReportError(NU_BLOB, err, "can't fit %ld bytes into %ld-byte buffer", - sourceLen, pThread->thCompThreadEOF); - goto bail; - } + /* + * Check to see if the data will fit. In some cases we can verify + * the size during the UpdatePresizedThread call, but if it's being + * added from a file we can't tell until now. + * + * We could be nice and give the user a chance to do something about + * this, but frankly the application should have checked the file + * size before handing it to us. + */ + sourceLen = Nu_DataSourceGetDataLen(pDataSource); + if (sourceLen > pThread->thCompThreadEOF) { + err = kNuErrPreSizeOverflow; + Nu_ReportError(NU_BLOB, err, "can't fit %ld bytes into %ld-byte buffer", + sourceLen, pThread->thCompThreadEOF); + goto bail; + } - /* - * During an update operation, the user's specification of "otherLen" - * doesn't really matter, because we're not going to change the size - * of the region in the archive. However, this size *is* used by - * the code to figure out how big the buffer should be, and will - * determine where the file pointer ends up when the call returns. - * So, we jam in the "real" value. - */ - Nu_DataSourceSetOtherLen(pDataSource, pThread->thCompThreadEOF); + /* + * During an update operation, the user's specification of "otherLen" + * doesn't really matter, because we're not going to change the size + * of the region in the archive. However, this size *is* used by + * the code to figure out how big the buffer should be, and will + * determine where the file pointer ends up when the call returns. + * So, we jam in the "real" value. + */ + Nu_DataSourceSetOtherLen(pDataSource, pThread->thCompThreadEOF); - if (NuGetThreadID(pThread) == kNuThreadIDFilename) { - /* special handling for filename updates */ - char* savedCopy = nil; - err = Nu_CopyPresizedToArchive(pArchive, pDataSource, - NuGetThreadID(pThread), fp, pThread, &savedCopy); - if (err != kNuErrNone) { - Nu_ReportError(NU_BLOB, err, "thread update failed"); - goto bail; - } - Nu_SetNewThreadFilename(pArchive, pRecord, savedCopy); + if (NuGetThreadID(pThread) == kNuThreadIDFilename) { + /* special handling for filename updates */ + char* savedCopy = nil; + err = Nu_CopyPresizedToArchive(pArchive, pDataSource, + NuGetThreadID(pThread), fp, pThread, &savedCopy); + if (err != kNuErrNone) { + Nu_ReportError(NU_BLOB, err, "thread update failed"); + goto bail; + } + Nu_SetNewThreadFilename(pArchive, pRecord, savedCopy); - } else { - err = Nu_CopyPresizedToArchive(pArchive, pDataSource, - NuGetThreadID(pThread), fp, pThread, nil); - if (err != kNuErrNone) { - Nu_ReportError(NU_BLOB, err, "thread update failed"); - goto bail; - } - } - Assert((ulong)ftell(fp) == pThread->fileOffset + threadBufSize); + } else { + err = Nu_CopyPresizedToArchive(pArchive, pDataSource, + NuGetThreadID(pThread), fp, pThread, nil); + if (err != kNuErrNone) { + Nu_ReportError(NU_BLOB, err, "thread update failed"); + goto bail; + } + } + Assert((ulong)ftell(fp) == pThread->fileOffset + threadBufSize); skip_update: - Nu_DataSourceUnPrepareInput(pArchive, pDataSource); + Nu_DataSourceUnPrepareInput(pArchive, pDataSource); bail: - return err; + return err; } @@ -700,175 +700,175 @@ bail: */ static NuError Nu_HandleAddThreadMods(NuArchive* pArchive, NuRecord* pRecord, - NuThreadID threadID, Boolean doKeepFirstOnly, NuNewThreads* pNewThreads, - FILE* dstFp) + NuThreadID threadID, Boolean doKeepFirstOnly, NuNewThreads* pNewThreads, + FILE* dstFp) { - NuError err = kNuErrNone; + NuError err = kNuErrNone; - NuProgressData progressData; - NuProgressData* pProgressData; - NuThreadMod* pThreadMod; - NuThread* pNewThread; - Boolean foundOne = false; + NuProgressData progressData; + NuProgressData* pProgressData; + NuThreadMod* pThreadMod; + NuThread* pNewThread; + Boolean foundOne = false; - /* - * Now find all "add" threadMods with matching threadIDs. Allow - * matching by wildcards, but don't re-use "used" entries. - */ - pThreadMod = pRecord->pThreadMods; - while (pThreadMod != nil) { - if (pThreadMod->entry.kind == kNuThreadModAdd && - !pThreadMod->entry.generic.used && - (pThreadMod->entry.add.threadID == threadID || - threadID == kNuThreadIDWildcard)) - { - DBUG(("+++ found ADD for 0x%08lx\n", pThreadMod->entry.add.threadID)); - pThreadMod->entry.generic.used = true; + /* + * Now find all "add" threadMods with matching threadIDs. Allow + * matching by wildcards, but don't re-use "used" entries. + */ + pThreadMod = pRecord->pThreadMods; + while (pThreadMod != nil) { + if (pThreadMod->entry.kind == kNuThreadModAdd && + !pThreadMod->entry.generic.used && + (pThreadMod->entry.add.threadID == threadID || + threadID == kNuThreadIDWildcard)) + { + DBUG(("+++ found ADD for 0x%08lx\n", pThreadMod->entry.add.threadID)); + pThreadMod->entry.generic.used = true; - /* if we're adding filename threads, stop after first one */ - /* [shouldn't be able to happen... we only allow one filename!] */ - if (doKeepFirstOnly && foundOne) { - assert(0); /* can this happen?? */ - continue; - } - foundOne = true; + /* if we're adding filename threads, stop after first one */ + /* [shouldn't be able to happen... we only allow one filename!] */ + if (doKeepFirstOnly && foundOne) { + assert(0); /* can this happen?? */ + continue; + } + foundOne = true; - if (!Nu_NewThreads_HasRoom(pNewThreads)) { - Assert(0); - err = kNuErrInternal; - goto bail; - } + if (!Nu_NewThreads_HasRoom(pNewThreads)) { + Assert(0); + err = kNuErrInternal; + goto bail; + } - /* if this is a data thread, prepare the progress message */ - pProgressData = nil; - if (NuThreadIDGetClass(pThreadMod->entry.add.threadID) == - kNuThreadClassData) - { - /* - * We're going to show the name as it appears in the - * archive, rather than the name of the file we're - * reading the data out of. We could do this differently - * for a "file" data source, but we might as well be - * consistent. - */ - err = Nu_ProgressDataInit_Compress(pArchive, &progressData, - pRecord, pRecord->filename); - BailError(err); + /* if this is a data thread, prepare the progress message */ + pProgressData = nil; + if (NuThreadIDGetClass(pThreadMod->entry.add.threadID) == + kNuThreadClassData) + { + /* + * We're going to show the name as it appears in the + * archive, rather than the name of the file we're + * reading the data out of. We could do this differently + * for a "file" data source, but we might as well be + * consistent. + */ + err = Nu_ProgressDataInit_Compress(pArchive, &progressData, + pRecord, pRecord->filename); + BailError(err); - /* send initial progress so they see name if "open" fails */ - progressData.state = kNuProgressOpening; - err = Nu_SendInitialProgress(pArchive, &progressData); - BailError(err); + /* send initial progress so they see name if "open" fails */ + progressData.state = kNuProgressOpening; + err = Nu_SendInitialProgress(pArchive, &progressData); + BailError(err); - pProgressData = &progressData; - } + pProgressData = &progressData; + } - /* get new thread storage, and init the thread's data offset */ - /* (the threadIdx is set by GetNext) */ - pNewThread = Nu_NewThreads_GetNext(pNewThreads, pArchive); - pNewThread->threadIdx = pThreadMod->entry.add.threadIdx; - err = Nu_FTell(dstFp, &pNewThread->fileOffset); - BailError(err); + /* get new thread storage, and init the thread's data offset */ + /* (the threadIdx is set by GetNext) */ + pNewThread = Nu_NewThreads_GetNext(pNewThreads, pArchive); + pNewThread->threadIdx = pThreadMod->entry.add.threadIdx; + err = Nu_FTell(dstFp, &pNewThread->fileOffset); + BailError(err); - /* this returns kNuErrSkipped if user elects to skip */ - err = Nu_DataSourcePrepareInput(pArchive, - pThreadMod->entry.add.pDataSource); - BailError(err); + /* this returns kNuErrSkipped if user elects to skip */ + err = Nu_DataSourcePrepareInput(pArchive, + pThreadMod->entry.add.pDataSource); + BailError(err); - /* - * If they're adding a disk image thread, make sure the disk- - * related fields in the record header are correct. - */ - if (pThreadMod->entry.add.threadID == kNuThreadIDDiskImage) { - const NuDataSource* pDataSource = - pThreadMod->entry.add.pDataSource; - ulong uncompLen; + /* + * If they're adding a disk image thread, make sure the disk- + * related fields in the record header are correct. + */ + if (pThreadMod->entry.add.threadID == kNuThreadIDDiskImage) { + const NuDataSource* pDataSource = + pThreadMod->entry.add.pDataSource; + ulong uncompLen; - if (Nu_DataSourceGetThreadFormat(pDataSource) == - kNuThreadFormatUncompressed) - { - uncompLen = Nu_DataSourceGetDataLen(pDataSource); - } else { - uncompLen = Nu_DataSourceGetOtherLen(pDataSource); - } + if (Nu_DataSourceGetThreadFormat(pDataSource) == + kNuThreadFormatUncompressed) + { + uncompLen = Nu_DataSourceGetDataLen(pDataSource); + } else { + uncompLen = Nu_DataSourceGetOtherLen(pDataSource); + } - err = Nu_UpdateDiskImageFields(pArchive, pRecord, uncompLen); - BailError(err); - } + err = Nu_UpdateDiskImageFields(pArchive, pRecord, uncompLen); + BailError(err); + } - if (Nu_DataSourceGetType(pThreadMod->entry.add.pDataSource) == - kNuDataSourceFromFile) - { - DBUG(("+++ ADDING from '%s' for '%s' (idx=%ld id=0x%08lx)\n", - Nu_DataSourceFile_GetPathname(pThreadMod->entry.add.pDataSource), - pRecord->filename, - pThreadMod->entry.add.threadIdx, - pThreadMod->entry.add.threadID)); - } else { - DBUG(("+++ ADDING from (type=%d) for '%s' (idx=%ld id=0x%08lx)\n", - Nu_DataSourceGetType(pThreadMod->entry.add.pDataSource), - pRecord->filename, - pThreadMod->entry.add.threadIdx, - pThreadMod->entry.add.threadID)); - } + if (Nu_DataSourceGetType(pThreadMod->entry.add.pDataSource) == + kNuDataSourceFromFile) + { + DBUG(("+++ ADDING from '%s' for '%s' (idx=%ld id=0x%08lx)\n", + Nu_DataSourceFile_GetPathname(pThreadMod->entry.add.pDataSource), + pRecord->filename, + pThreadMod->entry.add.threadIdx, + pThreadMod->entry.add.threadID)); + } else { + DBUG(("+++ ADDING from (type=%d) for '%s' (idx=%ld id=0x%08lx)\n", + Nu_DataSourceGetType(pThreadMod->entry.add.pDataSource), + pRecord->filename, + pThreadMod->entry.add.threadIdx, + pThreadMod->entry.add.threadID)); + } - if (pThreadMod->entry.add.threadID == kNuThreadIDFilename) { - /* filenames are special */ - char* savedCopy = nil; + if (pThreadMod->entry.add.threadID == kNuThreadIDFilename) { + /* filenames are special */ + char* savedCopy = nil; - Assert(pThreadMod->entry.add.threadFormat == - kNuThreadFormatUncompressed); - err = Nu_CopyPresizedToArchive(pArchive, - pThreadMod->entry.add.pDataSource, - pThreadMod->entry.add.threadID, - dstFp, pNewThread, &savedCopy); - if (err != kNuErrNone) { - Nu_ReportError(NU_BLOB, err, "fn thread add failed"); - goto bail; - } - /* NOTE: on failure, "dropRecFilename" is still set. This - doesn't matter though, since we'll either copy the original - record, or abort the entire thing. At any rate, we can't - just clear it, because we've already made space for the - record header, and didn't include the filename in it. */ + Assert(pThreadMod->entry.add.threadFormat == + kNuThreadFormatUncompressed); + err = Nu_CopyPresizedToArchive(pArchive, + pThreadMod->entry.add.pDataSource, + pThreadMod->entry.add.threadID, + dstFp, pNewThread, &savedCopy); + if (err != kNuErrNone) { + Nu_ReportError(NU_BLOB, err, "fn thread add failed"); + goto bail; + } + /* NOTE: on failure, "dropRecFilename" is still set. This + doesn't matter though, since we'll either copy the original + record, or abort the entire thing. At any rate, we can't + just clear it, because we've already made space for the + record header, and didn't include the filename in it. */ - Nu_SetNewThreadFilename(pArchive, pRecord, savedCopy); + Nu_SetNewThreadFilename(pArchive, pRecord, savedCopy); - } else if (pThreadMod->entry.add.isPresized) { - /* don't compress, just copy */ - Assert(pThreadMod->entry.add.threadFormat == - kNuThreadFormatUncompressed); - err = Nu_CopyPresizedToArchive(pArchive, - pThreadMod->entry.add.pDataSource, - pThreadMod->entry.add.threadID, - dstFp, pNewThread, nil); - /* fall through with err */ + } else if (pThreadMod->entry.add.isPresized) { + /* don't compress, just copy */ + Assert(pThreadMod->entry.add.threadFormat == + kNuThreadFormatUncompressed); + err = Nu_CopyPresizedToArchive(pArchive, + pThreadMod->entry.add.pDataSource, + pThreadMod->entry.add.threadID, + dstFp, pNewThread, nil); + /* fall through with err */ - } else { - /* compress (possibly by just copying) the source to dstFp */ - err = Nu_CompressToArchive(pArchive, - pThreadMod->entry.add.pDataSource, - pThreadMod->entry.add.threadID, - Nu_DataSourceGetThreadFormat( - pThreadMod->entry.add.pDataSource), - pThreadMod->entry.add.threadFormat, - pProgressData, dstFp, pNewThread); - /* fall through with err */ - } + } else { + /* compress (possibly by just copying) the source to dstFp */ + err = Nu_CompressToArchive(pArchive, + pThreadMod->entry.add.pDataSource, + pThreadMod->entry.add.threadID, + Nu_DataSourceGetThreadFormat( + pThreadMod->entry.add.pDataSource), + pThreadMod->entry.add.threadFormat, + pProgressData, dstFp, pNewThread); + /* fall through with err */ + } - if (err != kNuErrNone) { - Nu_ReportError(NU_BLOB, err, "thread add failed"); - goto bail; - } - Nu_DataSourceUnPrepareInput(pArchive, - pThreadMod->entry.add.pDataSource); - } + if (err != kNuErrNone) { + Nu_ReportError(NU_BLOB, err, "thread add failed"); + goto bail; + } + Nu_DataSourceUnPrepareInput(pArchive, + pThreadMod->entry.add.pDataSource); + } - pThreadMod = pThreadMod->pNext; - } + pThreadMod = pThreadMod->pNext; + } bail: - return err; + return err; } /* @@ -891,133 +891,133 @@ bail: */ static NuError Nu_ConstructArchiveThreads(NuArchive* pArchive, NuRecord* pRecord, - NuThreadID threadID, Boolean doKeepFirstOnly, NuNewThreads* pNewThreads) + NuThreadID threadID, Boolean doKeepFirstOnly, NuNewThreads* pNewThreads) { - NuError err = kNuErrNone; - NuThread* pThread; - NuThreadMod* pThreadMod; - Boolean foundOne = false; - NuThread* pNewThread; - int idx; + NuError err = kNuErrNone; + NuThread* pThread; + NuThreadMod* pThreadMod; + Boolean foundOne = false; + NuThread* pNewThread; + int idx; - /* - * First, find any existing threads that match. If they have a - * "delete" threadMod, ignore them; if they have an "update" threadMod, - * use that instead. - */ - for (idx = 0; idx < (int)pRecord->recTotalThreads; idx++) { - pThread = Nu_GetThread(pRecord, idx); - Assert(pThread != nil); + /* + * First, find any existing threads that match. If they have a + * "delete" threadMod, ignore them; if they have an "update" threadMod, + * use that instead. + */ + for (idx = 0; idx < (int)pRecord->recTotalThreads; idx++) { + pThread = Nu_GetThread(pRecord, idx); + Assert(pThread != nil); - DBUG(("+++ THREAD #%d (used=%d)\n", idx, pThread->used)); - if (threadID == kNuThreadIDWildcard || - threadID == NuGetThreadID(pThread)) - { - /* match! */ - DBUG(("+++ MATCH THREAD #%d\n", idx)); - if (pThread->used) - continue; - pThread->used = true; /* no matter what, we're done with this */ + DBUG(("+++ THREAD #%d (used=%d)\n", idx, pThread->used)); + if (threadID == kNuThreadIDWildcard || + threadID == NuGetThreadID(pThread)) + { + /* match! */ + DBUG(("+++ MATCH THREAD #%d\n", idx)); + if (pThread->used) + continue; + pThread->used = true; /* no matter what, we're done with this */ - pThreadMod = Nu_ThreadMod_FindByThreadIdx(pRecord, - pThread->threadIdx); + pThreadMod = Nu_ThreadMod_FindByThreadIdx(pRecord, + pThread->threadIdx); - if (pThreadMod != nil) { - /* - * The thread has a related ThreadMod. Deal with it. - */ + if (pThreadMod != nil) { + /* + * The thread has a related ThreadMod. Deal with it. + */ - pThreadMod->entry.generic.used = true; /* for assert, later */ + pThreadMod->entry.generic.used = true; /* for assert, later */ - if (pThreadMod->entry.kind == kNuThreadModDelete) { - /* this is a delete, ignore this thread */ - DBUG(("+++ deleted %ld!\n", pThread->threadIdx)); - continue; - } else if (pThreadMod->entry.kind == kNuThreadModUpdate) { - /* update pre-sized data in place */ + if (pThreadMod->entry.kind == kNuThreadModDelete) { + /* this is a delete, ignore this thread */ + DBUG(("+++ deleted %ld!\n", pThread->threadIdx)); + continue; + } else if (pThreadMod->entry.kind == kNuThreadModUpdate) { + /* update pre-sized data in place */ - DBUG(("+++ updating threadIdx=%ld\n", - pThread->threadIdx)); + DBUG(("+++ updating threadIdx=%ld\n", + pThread->threadIdx)); - /* only one filename per customer */ - /* [does this make sense here??] */ - if (doKeepFirstOnly && foundOne) - continue; - foundOne = true; + /* only one filename per customer */ + /* [does this make sense here??] */ + if (doKeepFirstOnly && foundOne) + continue; + foundOne = true; - /* add an entry in the new list of threads */ - pNewThread = Nu_NewThreads_GetNext(pNewThreads, pArchive); - Nu_CopyThreadContents(pNewThread, pThread); + /* add an entry in the new list of threads */ + pNewThread = Nu_NewThreads_GetNext(pNewThreads, pArchive); + Nu_CopyThreadContents(pNewThread, pThread); - /* set the thread's file offset */ - err = Nu_FTell(pArchive->tmpFp, &pNewThread->fileOffset); - BailError(err); + /* set the thread's file offset */ + err = Nu_FTell(pArchive->tmpFp, &pNewThread->fileOffset); + BailError(err); - err = Nu_ConstructArchiveUpdate(pArchive, pArchive->tmpFp, - pRecord, pNewThread, pThreadMod); - BailError(err); - } else { - /* unknown ThreadMod type - this shouldn't happen! */ - Assert(0); - err = kNuErrInternal; - goto bail; - } - } else { - /* - * Thread is unmodified. - */ + err = Nu_ConstructArchiveUpdate(pArchive, pArchive->tmpFp, + pRecord, pNewThread, pThreadMod); + BailError(err); + } else { + /* unknown ThreadMod type - this shouldn't happen! */ + Assert(0); + err = kNuErrInternal; + goto bail; + } + } else { + /* + * Thread is unmodified. + */ - /* only one filename per customer */ - if (doKeepFirstOnly && foundOne) - continue; - foundOne = true; + /* only one filename per customer */ + if (doKeepFirstOnly && foundOne) + continue; + foundOne = true; - /* - * Copy the original data to the new location. Right now, - * pThread->fileOffset has the correct offset for the - * original file, and tmpFp is positioned at the correct - * output offset. We want to seek the source file, replace - * pThread->fileOffset with the *new* offset, and then - * copy the data. - * - * This feels skankier than it really is because we're - * using the thread in the "copy" set for two purposes. - * It'd be cleaner to pass in the thread from the "orig" - * set, but there's really not much value in doing so. - * - * [should this have a progress meter associated?] - */ - DBUG(("+++ just copying threadIdx=%ld\n", - pThread->threadIdx)); - err = Nu_FSeek(pArchive->archiveFp, pThread->fileOffset, - SEEK_SET); - BailError(err); - err = Nu_FTell(pArchive->tmpFp, &pThread->fileOffset); - BailError(err); - err = Nu_CopyFileSection(pArchive, pArchive->tmpFp, - pArchive->archiveFp, pThread->thCompThreadEOF); - BailError(err); + /* + * Copy the original data to the new location. Right now, + * pThread->fileOffset has the correct offset for the + * original file, and tmpFp is positioned at the correct + * output offset. We want to seek the source file, replace + * pThread->fileOffset with the *new* offset, and then + * copy the data. + * + * This feels skankier than it really is because we're + * using the thread in the "copy" set for two purposes. + * It'd be cleaner to pass in the thread from the "orig" + * set, but there's really not much value in doing so. + * + * [should this have a progress meter associated?] + */ + DBUG(("+++ just copying threadIdx=%ld\n", + pThread->threadIdx)); + err = Nu_FSeek(pArchive->archiveFp, pThread->fileOffset, + SEEK_SET); + BailError(err); + err = Nu_FTell(pArchive->tmpFp, &pThread->fileOffset); + BailError(err); + err = Nu_CopyFileSection(pArchive, pArchive->tmpFp, + pArchive->archiveFp, pThread->thCompThreadEOF); + BailError(err); - /* copy an entry over into the replacement thread list */ - pNewThread = Nu_NewThreads_GetNext(pNewThreads, pArchive); - Nu_CopyThreadContents(pNewThread, pThread); - } - } - } + /* copy an entry over into the replacement thread list */ + pNewThread = Nu_NewThreads_GetNext(pNewThreads, pArchive); + Nu_CopyThreadContents(pNewThread, pThread); + } + } + } - /* no need to check for "add" mods; there can't be one for us */ - if (doKeepFirstOnly && foundOne) - goto bail; + /* no need to check for "add" mods; there can't be one for us */ + if (doKeepFirstOnly && foundOne) + goto bail; - /* - * Now handle any "add" threadMods. - */ - err = Nu_HandleAddThreadMods(pArchive, pRecord, threadID, doKeepFirstOnly, - pNewThreads, pArchive->tmpFp); - BailError(err); + /* + * Now handle any "add" threadMods. + */ + err = Nu_HandleAddThreadMods(pArchive, pRecord, threadID, doKeepFirstOnly, + pNewThreads, pArchive->tmpFp); + BailError(err); bail: - return err; + return err; } /* @@ -1037,179 +1037,179 @@ bail: static NuError Nu_ConstructArchiveRecord(NuArchive* pArchive, NuRecord* pRecord) { - NuError err; - NuNewThreads* pNewThreads = nil; - long threadDisp; - long initialOffset, finalOffset; - long numThreads, numFilenameThreads; - int newHeaderSize; + NuError err; + NuNewThreads* pNewThreads = nil; + long threadDisp; + long initialOffset, finalOffset; + long numThreads, numFilenameThreads; + int newHeaderSize; - Assert(pArchive != nil); - Assert(pRecord != nil); + Assert(pArchive != nil); + Assert(pRecord != nil); - DBUG(("--- Reconstructing '%s'\n", pRecord->filename)); + DBUG(("--- Reconstructing '%s'\n", pRecord->filename)); - err = Nu_FTell(pArchive->tmpFp, &initialOffset); - BailError(err); - Assert(initialOffset != 0); + err = Nu_FTell(pArchive->tmpFp, &initialOffset); + BailError(err); + Assert(initialOffset != 0); - /* - * Figure out how large the record header is. This requires - * measuring the static elements, the not-so-static elements like - * the GS/OS option list and perhaps the filename, and getting an - * accurate count of the number of threads. - * - * Since we're going to keep any option lists and extra junk stored in - * the header originally, the size of the new base record header is - * equal to the original recAttribCount. The attribute count conveniently - * does *not* include the filename, so if we've moved it out of the - * record header and into a thread, it won't affect us here. - */ - err = Nu_CountEventualThreads(pRecord, &numThreads, &numFilenameThreads); - BailError(err); - Assert(numThreads > 0); /* threadless records should already be gone */ - if (numThreads <= 0) { - err = kNuErrInternal; - goto bail; - } + /* + * Figure out how large the record header is. This requires + * measuring the static elements, the not-so-static elements like + * the GS/OS option list and perhaps the filename, and getting an + * accurate count of the number of threads. + * + * Since we're going to keep any option lists and extra junk stored in + * the header originally, the size of the new base record header is + * equal to the original recAttribCount. The attribute count conveniently + * does *not* include the filename, so if we've moved it out of the + * record header and into a thread, it won't affect us here. + */ + err = Nu_CountEventualThreads(pRecord, &numThreads, &numFilenameThreads); + BailError(err); + Assert(numThreads > 0); /* threadless records should already be gone */ + if (numThreads <= 0) { + err = kNuErrInternal; + goto bail; + } - /* - * Handle filename deletion. - */ - if (!numFilenameThreads && pRecord->threadFilename) { - /* looks like a previously existing filename thread got removed */ - DBUG(("--- Dropping thread filename '%s'\n", pRecord->threadFilename)); - if (pRecord->filename == pRecord->threadFilename) - pRecord->filename = nil; /* don't point at freed memory! */ - Nu_Free(pArchive, pRecord->threadFilename); - pRecord->threadFilename = nil; + /* + * Handle filename deletion. + */ + if (!numFilenameThreads && pRecord->threadFilename) { + /* looks like a previously existing filename thread got removed */ + DBUG(("--- Dropping thread filename '%s'\n", pRecord->threadFilename)); + if (pRecord->filename == pRecord->threadFilename) + pRecord->filename = nil; /* don't point at freed memory! */ + Nu_Free(pArchive, pRecord->threadFilename); + pRecord->threadFilename = nil; - /* I don't think this is possible, but check it anyway */ - if (pRecord->filename == nil && pRecord->recFilename != nil && - !pRecord->dropRecFilename) - { - DBUG(("--- HEY, how did this happen?\n")); - pRecord->filename = pRecord->recFilename; - } - } - if (pRecord->filename == nil) - pRecord->filename = kNuDefaultRecordName; + /* I don't think this is possible, but check it anyway */ + if (pRecord->filename == nil && pRecord->recFilename != nil && + !pRecord->dropRecFilename) + { + DBUG(("--- HEY, how did this happen?\n")); + pRecord->filename = pRecord->recFilename; + } + } + if (pRecord->filename == nil) + pRecord->filename = kNuDefaultRecordName; - /* make a hole, including the header filename if we're not dropping it */ - newHeaderSize = pRecord->recAttribCount + numThreads * kNuThreadHeaderSize; - if (!pRecord->dropRecFilename) - newHeaderSize += pRecord->recFilenameLength; + /* make a hole, including the header filename if we're not dropping it */ + newHeaderSize = pRecord->recAttribCount + numThreads * kNuThreadHeaderSize; + if (!pRecord->dropRecFilename) + newHeaderSize += pRecord->recFilenameLength; - DBUG(("+++ new header size = %d\n", newHeaderSize)); - err = Nu_FSeek(pArchive->tmpFp, newHeaderSize, SEEK_CUR); - BailError(err); + DBUG(("+++ new header size = %d\n", newHeaderSize)); + err = Nu_FSeek(pArchive->tmpFp, newHeaderSize, SEEK_CUR); + BailError(err); - /* - * It is important to arrange the threads in a specific order. For - * example, we can have trouble doing a streaming archive read if the - * filename isn't the first thread the collection. It's prudent to - * mimic GSHK's behavior, so we act to ensure that things appear in - * the following order: - * - * (1) filename thread - * (2) comment thread(s) - * (3) data thread with data fork - * (4) data thread with disk image - * (5) data thread with rsrc fork - * (6) everything else - * - * If we ended up with two filename threads (perhaps some other aberrant - * application created the archive; we certainly wouldn't do that), we - * keep the first one. We're more lenient on propagating strange - * multiple comment and data thread situations, even though the - * thread updating mechanism in this library won't necessarily allow - * such situations. - */ + /* + * It is important to arrange the threads in a specific order. For + * example, we can have trouble doing a streaming archive read if the + * filename isn't the first thread the collection. It's prudent to + * mimic GSHK's behavior, so we act to ensure that things appear in + * the following order: + * + * (1) filename thread + * (2) comment thread(s) + * (3) data thread with data fork + * (4) data thread with disk image + * (5) data thread with rsrc fork + * (6) everything else + * + * If we ended up with two filename threads (perhaps some other aberrant + * application created the archive; we certainly wouldn't do that), we + * keep the first one. We're more lenient on propagating strange + * multiple comment and data thread situations, even though the + * thread updating mechanism in this library won't necessarily allow + * such situations. + */ - err = Nu_NewThreads_New(pArchive, &pNewThreads, numThreads); - BailError(err); + err = Nu_NewThreads_New(pArchive, &pNewThreads, numThreads); + BailError(err); - err = Nu_ConstructArchiveThreads(pArchive, pRecord, kNuThreadIDFilename, - true, pNewThreads); - BailError(err); - err = Nu_ConstructArchiveThreads(pArchive, pRecord, kNuThreadIDComment, - false, pNewThreads); - BailError(err); - err = Nu_ConstructArchiveThreads(pArchive, pRecord, kNuThreadIDDataFork, - false, pNewThreads); - BailError(err); - err = Nu_ConstructArchiveThreads(pArchive, pRecord, kNuThreadIDDiskImage, - false, pNewThreads); - BailError(err); - err = Nu_ConstructArchiveThreads(pArchive, pRecord, kNuThreadIDRsrcFork, - false, pNewThreads); - BailError(err); - err = Nu_ConstructArchiveThreads(pArchive, pRecord, kNuThreadIDWildcard, - false, pNewThreads); - BailError(err); + err = Nu_ConstructArchiveThreads(pArchive, pRecord, kNuThreadIDFilename, + true, pNewThreads); + BailError(err); + err = Nu_ConstructArchiveThreads(pArchive, pRecord, kNuThreadIDComment, + false, pNewThreads); + BailError(err); + err = Nu_ConstructArchiveThreads(pArchive, pRecord, kNuThreadIDDataFork, + false, pNewThreads); + BailError(err); + err = Nu_ConstructArchiveThreads(pArchive, pRecord, kNuThreadIDDiskImage, + false, pNewThreads); + BailError(err); + err = Nu_ConstructArchiveThreads(pArchive, pRecord, kNuThreadIDRsrcFork, + false, pNewThreads); + BailError(err); + err = Nu_ConstructArchiveThreads(pArchive, pRecord, kNuThreadIDWildcard, + false, pNewThreads); + BailError(err); - /* - * Perform some sanity checks. - */ - Assert(!Nu_NewThreads_HasRoom(pNewThreads)); + /* + * Perform some sanity checks. + */ + Assert(!Nu_NewThreads_HasRoom(pNewThreads)); - /* verify that all threads and threadMods have been touched */ - if (!Nu_VerifyAllTouched(pArchive, pRecord)) { - err = kNuErrInternal; - goto bail; - } + /* verify that all threads and threadMods have been touched */ + if (!Nu_VerifyAllTouched(pArchive, pRecord)) { + err = kNuErrInternal; + goto bail; + } - /* verify that file displacement is where it should be */ - threadDisp = (long)Nu_NewThreads_TotalCompThreadEOF(pNewThreads); - err = Nu_FTell(pArchive->tmpFp, &finalOffset); - BailError(err); - Assert(finalOffset > initialOffset); - if (finalOffset - (initialOffset + newHeaderSize) != threadDisp) { - Nu_ReportError(NU_BLOB, kNuErrNone, - "ERROR: didn't end up where expected (%ld %ld %ld)", - initialOffset, finalOffset, threadDisp); - err = kNuErrInternal; - Assert(0); - } + /* verify that file displacement is where it should be */ + threadDisp = (long)Nu_NewThreads_TotalCompThreadEOF(pNewThreads); + err = Nu_FTell(pArchive->tmpFp, &finalOffset); + BailError(err); + Assert(finalOffset > initialOffset); + if (finalOffset - (initialOffset + newHeaderSize) != threadDisp) { + Nu_ReportError(NU_BLOB, kNuErrNone, + "ERROR: didn't end up where expected (%ld %ld %ld)", + initialOffset, finalOffset, threadDisp); + err = kNuErrInternal; + Assert(0); + } - /* - * Free existing Threads and ThreadMods, and move the list from - * pNewThreads over. - */ - Nu_Free(pArchive, pRecord->pThreads); - Nu_FreeThreadMods(pArchive, pRecord); - pRecord->pThreads = Nu_NewThreads_DonateThreads(pNewThreads); - pRecord->recTotalThreads = Nu_NewThreads_GetNumThreads(pNewThreads); + /* + * Free existing Threads and ThreadMods, and move the list from + * pNewThreads over. + */ + Nu_Free(pArchive, pRecord->pThreads); + Nu_FreeThreadMods(pArchive, pRecord); + pRecord->pThreads = Nu_NewThreads_DonateThreads(pNewThreads); + pRecord->recTotalThreads = Nu_NewThreads_GetNumThreads(pNewThreads); - /* - * Now, seek back and write the record header. - */ - err = Nu_FSeek(pArchive->tmpFp, initialOffset, SEEK_SET); - BailError(err); - err = Nu_WriteRecordHeader(pArchive, pRecord, pArchive->tmpFp); - BailError(err); + /* + * Now, seek back and write the record header. + */ + err = Nu_FSeek(pArchive->tmpFp, initialOffset, SEEK_SET); + BailError(err); + err = Nu_WriteRecordHeader(pArchive, pRecord, pArchive->tmpFp); + BailError(err); - /* - * Seek forward once again, so we are positioned at the correct - * place to write the next record. - */ - err = Nu_FSeek(pArchive->tmpFp, finalOffset, SEEK_SET); - BailError(err); + /* + * Seek forward once again, so we are positioned at the correct + * place to write the next record. + */ + err = Nu_FSeek(pArchive->tmpFp, finalOffset, SEEK_SET); + BailError(err); bail: - if (err == kNuErrSkipped) { - /* - * Something went wrong and they want to skip this record but - * keep going otherwise. We need to back up in the file so the - * original copy of the record can go here. - */ - err = Nu_FSeek(pArchive->tmpFp, initialOffset, SEEK_SET); - if (err == kNuErrNone) - err = kNuErrSkipped; /* tell the caller we skipped it */ - } + if (err == kNuErrSkipped) { + /* + * Something went wrong and they want to skip this record but + * keep going otherwise. We need to back up in the file so the + * original copy of the record can go here. + */ + err = Nu_FSeek(pArchive->tmpFp, initialOffset, SEEK_SET); + if (err == kNuErrNone) + err = kNuErrSkipped; /* tell the caller we skipped it */ + } - Nu_NewThreads_Free(pArchive, pNewThreads); - return err; + Nu_NewThreads_Free(pArchive, pNewThreads); + return err; } @@ -1228,216 +1228,216 @@ bail: static NuError Nu_ConstructNewRecord(NuArchive* pArchive, NuRecord* pRecord, FILE* fp) { - NuError err; - NuNewThreads* pNewThreads = nil; - NuThreadMod* pThreadMod; - long threadDisp; - long initialOffset, finalOffset; - long numThreadMods, numFilenameThreads; - int newHeaderSize; + NuError err; + NuNewThreads* pNewThreads = nil; + NuThreadMod* pThreadMod; + long threadDisp; + long initialOffset, finalOffset; + long numThreadMods, numFilenameThreads; + int newHeaderSize; - Assert(pArchive != nil); - Assert(pRecord != nil); + Assert(pArchive != nil); + Assert(pRecord != nil); - DBUG(("--- Constructing '%s'\n", pRecord->filename)); + DBUG(("--- Constructing '%s'\n", pRecord->filename)); - err = Nu_FTell(fp, &initialOffset); - BailError(err); - Assert(initialOffset != 0); + err = Nu_FTell(fp, &initialOffset); + BailError(err); + Assert(initialOffset != 0); - /* - * Quick sanity check: verify that the record has no threads of its - * own, and all threadMods are "add" threadMods. While we're at it, - * make ourselves useful by counting up the number of eventual - * threads, and verify that there is exactly one filename thread. - */ - Assert(pRecord->pThreads == nil); + /* + * Quick sanity check: verify that the record has no threads of its + * own, and all threadMods are "add" threadMods. While we're at it, + * make ourselves useful by counting up the number of eventual + * threads, and verify that there is exactly one filename thread. + */ + Assert(pRecord->pThreads == nil); - numThreadMods = 0; - numFilenameThreads = 0; - pThreadMod = pRecord->pThreadMods; - while (pThreadMod) { - if (pThreadMod->entry.kind != kNuThreadModAdd) { - Nu_ReportError(NU_BLOB, kNuErrNone, "unexpected non-add threadMod"); - err = kNuErrInternal; - Assert(0); - goto bail; - } - numThreadMods++; - if (pThreadMod->entry.add.threadID == kNuThreadIDFilename) - numFilenameThreads++; + numThreadMods = 0; + numFilenameThreads = 0; + pThreadMod = pRecord->pThreadMods; + while (pThreadMod) { + if (pThreadMod->entry.kind != kNuThreadModAdd) { + Nu_ReportError(NU_BLOB, kNuErrNone, "unexpected non-add threadMod"); + err = kNuErrInternal; + Assert(0); + goto bail; + } + numThreadMods++; + if (pThreadMod->entry.add.threadID == kNuThreadIDFilename) + numFilenameThreads++; - pThreadMod = pThreadMod->pNext; - } - Assert(numFilenameThreads <= 1); + pThreadMod = pThreadMod->pNext; + } + Assert(numFilenameThreads <= 1); - /* - * If there's no filename thread, make one. We do this for brand-new - * records when the application doesn't explicitly add a thread. - */ - if (!numFilenameThreads) { - NuDataSource* pTmpDataSource = nil; - NuThreadMod* pNewThreadMod = nil; - int len, maxLen; + /* + * If there's no filename thread, make one. We do this for brand-new + * records when the application doesn't explicitly add a thread. + */ + if (!numFilenameThreads) { + NuDataSource* pTmpDataSource = nil; + NuThreadMod* pNewThreadMod = nil; + int len, maxLen; - /* - * Generally speaking, the "add file" call should set the - * filename. If somehow it didn't, assign a default. - */ - if (pRecord->filename == nil) { - pRecord->newFilename = strdup(kNuDefaultRecordName); - pRecord->filename = pRecord->newFilename; - } + /* + * Generally speaking, the "add file" call should set the + * filename. If somehow it didn't, assign a default. + */ + if (pRecord->filename == nil) { + pRecord->newFilename = strdup(kNuDefaultRecordName); + pRecord->filename = pRecord->newFilename; + } - DBUG(("--- No filename thread found, adding one ('%s')\n", - pRecord->filename)); + DBUG(("--- No filename thread found, adding one ('%s')\n", + pRecord->filename)); - /* - * Create a trivial data source for the filename. The size of - * the filename buffer is the larger of the filename length and - * the default filename buffer size. This mimics GSHK's behavior. - * (If we're really serious about renaming it, maybe we should - * leave some extra space on the end...?) - */ - len = strlen(pRecord->filename); - maxLen = len > kNuDefaultFilenameThreadSize ? - len : kNuDefaultFilenameThreadSize; - err = Nu_DataSourceBuffer_New(kNuThreadFormatUncompressed, false, - maxLen, (const uchar*)pRecord->filename, 0, - strlen(pRecord->filename), &pTmpDataSource); - BailError(err); + /* + * Create a trivial data source for the filename. The size of + * the filename buffer is the larger of the filename length and + * the default filename buffer size. This mimics GSHK's behavior. + * (If we're really serious about renaming it, maybe we should + * leave some extra space on the end...?) + */ + len = strlen(pRecord->filename); + maxLen = len > kNuDefaultFilenameThreadSize ? + len : kNuDefaultFilenameThreadSize; + err = Nu_DataSourceBuffer_New(kNuThreadFormatUncompressed, false, + maxLen, (const uchar*)pRecord->filename, 0, + strlen(pRecord->filename), &pTmpDataSource); + BailError(err); - /* put in a new "add" threadMod */ - err = Nu_ThreadModAdd_New(pArchive, kNuThreadIDFilename, - kNuThreadFormatUncompressed, pTmpDataSource, &pNewThreadMod); - BailError(err); + /* put in a new "add" threadMod */ + err = Nu_ThreadModAdd_New(pArchive, kNuThreadIDFilename, + kNuThreadFormatUncompressed, pTmpDataSource, &pNewThreadMod); + BailError(err); - /* add it to the list */ - Nu_RecordAddThreadMod(pRecord, pNewThreadMod); - pNewThreadMod = nil; + /* add it to the list */ + Nu_RecordAddThreadMod(pRecord, pNewThreadMod); + pNewThreadMod = nil; - numFilenameThreads++; - numThreadMods++; - } + numFilenameThreads++; + numThreadMods++; + } - /* - * Figure out how large the record header is. We don't generate - * GS/OS option lists or "extra" data here, and we always put the - * filename in a thread, so the size is constant. (If somebody - * does a GS/OS or Mac port and wants to add option lists, it should - * not be hard to adjust the size accordingly.) - * - * This initializes the record's attribCount. We use the "base size" - * and add two for the (unused) filename length. - */ - pRecord->recAttribCount = kNuRecordHeaderBaseSize +2; - newHeaderSize = pRecord->recAttribCount + numThreadMods * kNuThreadHeaderSize; + /* + * Figure out how large the record header is. We don't generate + * GS/OS option lists or "extra" data here, and we always put the + * filename in a thread, so the size is constant. (If somebody + * does a GS/OS or Mac port and wants to add option lists, it should + * not be hard to adjust the size accordingly.) + * + * This initializes the record's attribCount. We use the "base size" + * and add two for the (unused) filename length. + */ + pRecord->recAttribCount = kNuRecordHeaderBaseSize +2; + newHeaderSize = pRecord->recAttribCount + numThreadMods * kNuThreadHeaderSize; - DBUG(("+++ new header size = %d\n", newHeaderSize)); + DBUG(("+++ new header size = %d\n", newHeaderSize)); - /* leave a hole */ - err = Nu_FSeek(fp, newHeaderSize, SEEK_CUR); - BailError(err); + /* leave a hole */ + err = Nu_FSeek(fp, newHeaderSize, SEEK_CUR); + BailError(err); - /* - * It is important to arrange the threads in a specific order. See - * the comments in Nu_ConstructArchiveRecord for the rationale. - */ - err = Nu_NewThreads_New(pArchive, &pNewThreads, numThreadMods); - BailError(err); + /* + * It is important to arrange the threads in a specific order. See + * the comments in Nu_ConstructArchiveRecord for the rationale. + */ + err = Nu_NewThreads_New(pArchive, &pNewThreads, numThreadMods); + BailError(err); - err = Nu_HandleAddThreadMods(pArchive, pRecord, kNuThreadIDFilename, - true, pNewThreads, fp); - BailError(err); - err = Nu_HandleAddThreadMods(pArchive, pRecord, kNuThreadIDComment, - false, pNewThreads, fp); - BailError(err); - err = Nu_HandleAddThreadMods(pArchive, pRecord, kNuThreadIDDataFork, - false, pNewThreads, fp); - BailError(err); - err = Nu_HandleAddThreadMods(pArchive, pRecord, kNuThreadIDDiskImage, - false, pNewThreads, fp); - BailError(err); - err = Nu_HandleAddThreadMods(pArchive, pRecord, kNuThreadIDRsrcFork, - false, pNewThreads, fp); - BailError(err); - err = Nu_HandleAddThreadMods(pArchive, pRecord, kNuThreadIDWildcard, - false, pNewThreads, fp); - BailError(err); + err = Nu_HandleAddThreadMods(pArchive, pRecord, kNuThreadIDFilename, + true, pNewThreads, fp); + BailError(err); + err = Nu_HandleAddThreadMods(pArchive, pRecord, kNuThreadIDComment, + false, pNewThreads, fp); + BailError(err); + err = Nu_HandleAddThreadMods(pArchive, pRecord, kNuThreadIDDataFork, + false, pNewThreads, fp); + BailError(err); + err = Nu_HandleAddThreadMods(pArchive, pRecord, kNuThreadIDDiskImage, + false, pNewThreads, fp); + BailError(err); + err = Nu_HandleAddThreadMods(pArchive, pRecord, kNuThreadIDRsrcFork, + false, pNewThreads, fp); + BailError(err); + err = Nu_HandleAddThreadMods(pArchive, pRecord, kNuThreadIDWildcard, + false, pNewThreads, fp); + BailError(err); - /* - * Perform some sanity checks. - */ - Assert(!Nu_NewThreads_HasRoom(pNewThreads)); + /* + * Perform some sanity checks. + */ + Assert(!Nu_NewThreads_HasRoom(pNewThreads)); - /* verify that all threads and threadMods have been touched */ - if (!Nu_VerifyAllTouched(pArchive, pRecord)) { - err = kNuErrInternal; - goto bail; - } + /* verify that all threads and threadMods have been touched */ + if (!Nu_VerifyAllTouched(pArchive, pRecord)) { + err = kNuErrInternal; + goto bail; + } - /* verify that file displacement is where it should be */ - threadDisp = Nu_NewThreads_TotalCompThreadEOF(pNewThreads); - err = Nu_FTell(fp, &finalOffset); - BailError(err); - Assert(finalOffset > initialOffset); - if (finalOffset - (initialOffset + newHeaderSize) != threadDisp) { - Nu_ReportError(NU_BLOB, kNuErrNone, - "ERROR: didn't end up where expected (%ld %ld %ld)", - initialOffset, finalOffset, threadDisp); - err = kNuErrInternal; - Assert(0); - } + /* verify that file displacement is where it should be */ + threadDisp = Nu_NewThreads_TotalCompThreadEOF(pNewThreads); + err = Nu_FTell(fp, &finalOffset); + BailError(err); + Assert(finalOffset > initialOffset); + if (finalOffset - (initialOffset + newHeaderSize) != threadDisp) { + Nu_ReportError(NU_BLOB, kNuErrNone, + "ERROR: didn't end up where expected (%ld %ld %ld)", + initialOffset, finalOffset, threadDisp); + err = kNuErrInternal; + Assert(0); + } - /* - * Install pNewThreads as the thread list. - */ - Assert(pRecord->pThreads == nil && pRecord->recTotalThreads == 0); - pRecord->pThreads = Nu_NewThreads_DonateThreads(pNewThreads); - pRecord->recTotalThreads = Nu_NewThreads_GetNumThreads(pNewThreads); + /* + * Install pNewThreads as the thread list. + */ + Assert(pRecord->pThreads == nil && pRecord->recTotalThreads == 0); + pRecord->pThreads = Nu_NewThreads_DonateThreads(pNewThreads); + pRecord->recTotalThreads = Nu_NewThreads_GetNumThreads(pNewThreads); - /* - * Fill in misc record header fields. - * - * We could set recArchiveWhen here, if we wanted to override what - * the application set, but I don't think there's any value in that. - */ - pRecord->fileOffset = initialOffset; + /* + * Fill in misc record header fields. + * + * We could set recArchiveWhen here, if we wanted to override what + * the application set, but I don't think there's any value in that. + */ + pRecord->fileOffset = initialOffset; - /* - * Now, seek back and write the record header. - */ - err = Nu_FSeek(fp, initialOffset, SEEK_SET); - BailError(err); - err = Nu_WriteRecordHeader(pArchive, pRecord, fp); - BailError(err); + /* + * Now, seek back and write the record header. + */ + err = Nu_FSeek(fp, initialOffset, SEEK_SET); + BailError(err); + err = Nu_WriteRecordHeader(pArchive, pRecord, fp); + BailError(err); - /* - * Seek forward once again, so we are positioned at the correct - * place to write the next record. - */ - err = Nu_FSeek(fp, finalOffset, SEEK_SET); - BailError(err); + /* + * Seek forward once again, so we are positioned at the correct + * place to write the next record. + */ + err = Nu_FSeek(fp, finalOffset, SEEK_SET); + BailError(err); - /* - * Trash the threadMods. - */ - Nu_FreeThreadMods(pArchive, pRecord); + /* + * Trash the threadMods. + */ + Nu_FreeThreadMods(pArchive, pRecord); bail: - if (err == kNuErrSkipped) { - /* - * Something went wrong and they want to skip this record but - * keep going otherwise. We need to back up in the file so the - * next record can go here. - */ - err = Nu_FSeek(fp, initialOffset, SEEK_SET); - if (err == kNuErrNone) - err = kNuErrSkipped; /* tell the caller we skipped it */ - } + if (err == kNuErrSkipped) { + /* + * Something went wrong and they want to skip this record but + * keep going otherwise. We need to back up in the file so the + * next record can go here. + */ + err = Nu_FSeek(fp, initialOffset, SEEK_SET); + if (err == kNuErrNone) + err = kNuErrSkipped; /* tell the caller we skipped it */ + } - Nu_NewThreads_Free(pArchive, pNewThreads); - return err; + Nu_NewThreads_Free(pArchive, pNewThreads); + return err; } @@ -1454,85 +1454,85 @@ bail: static NuError Nu_UpdateRecordInOriginal(NuArchive* pArchive, NuRecord* pRecord) { - NuError err = kNuErrNone; - NuThread* pThread; - const NuThreadMod* pThreadMod; + NuError err = kNuErrNone; + NuThread* pThread; + const NuThreadMod* pThreadMod; - /* - * Loop through all threadMods. - */ - pThreadMod = pRecord->pThreadMods; - while (pThreadMod != nil) { - Assert(pThreadMod->entry.kind == kNuThreadModUpdate); + /* + * Loop through all threadMods. + */ + pThreadMod = pRecord->pThreadMods; + while (pThreadMod != nil) { + Assert(pThreadMod->entry.kind == kNuThreadModUpdate); - /* find the thread associated with this threadMod */ - err = Nu_FindThreadByIdx(pRecord, pThreadMod->entry.update.threadIdx, - &pThread); - BailError(err); /* should never happen */ + /* find the thread associated with this threadMod */ + err = Nu_FindThreadByIdx(pRecord, pThreadMod->entry.update.threadIdx, + &pThread); + BailError(err); /* should never happen */ - /* seek to the appropriate spot */ - err = Nu_FSeek(pArchive->archiveFp, pThread->fileOffset, SEEK_SET); - BailError(err); + /* seek to the appropriate spot */ + err = Nu_FSeek(pArchive->archiveFp, pThread->fileOffset, SEEK_SET); + BailError(err); - /* do the update; this updates "pThread" with the new info */ - err = Nu_ConstructArchiveUpdate(pArchive, pArchive->archiveFp, - pRecord, pThread, pThreadMod); - BailError(err); + /* do the update; this updates "pThread" with the new info */ + err = Nu_ConstructArchiveUpdate(pArchive, pArchive->archiveFp, + pRecord, pThread, pThreadMod); + BailError(err); - pThreadMod = pThreadMod->pNext; - } + pThreadMod = pThreadMod->pNext; + } - /* - * We have to write a new record header without disturbing - * anything around it. Nothing we've done should've changed - * the size of the record header, so just go ahead and write it. - * - * We have to do this regardless of "dirtyHeader", because we just - * tweaked some of our threads around, and we need to rewrite the - * thread headers (which updates the record header CRC, and so on). - */ - err = Nu_FSeek(pArchive->archiveFp, pRecord->fileOffset, SEEK_SET); - BailError(err); - err = Nu_WriteRecordHeader(pArchive, pRecord, pArchive->archiveFp); - BailError(err); + /* + * We have to write a new record header without disturbing + * anything around it. Nothing we've done should've changed + * the size of the record header, so just go ahead and write it. + * + * We have to do this regardless of "dirtyHeader", because we just + * tweaked some of our threads around, and we need to rewrite the + * thread headers (which updates the record header CRC, and so on). + */ + err = Nu_FSeek(pArchive->archiveFp, pRecord->fileOffset, SEEK_SET); + BailError(err); + err = Nu_WriteRecordHeader(pArchive, pRecord, pArchive->archiveFp); + BailError(err); - /* - * Let's be paranoid and verify that the write didn't overflow - * into the thread header. We compare our current offset against - * the offset of the first thread. (If we're in a weird record - * with no threads, we could compare against the offset of the - * next record, but I don't want to deal with a case that should - * never happen anyway.) - */ - DBUG(("--- record header wrote %ld bytes\n", - pArchive->currentOffset - pRecord->fileOffset)); - pThread = pRecord->pThreads; - if (pThread != nil && pArchive->currentOffset != pThread->fileOffset) { - /* guess what, we just trashed the archive */ - err = kNuErrDamaged; - Nu_ReportError(NU_BLOB, err, - "Bad record header write (off by %ld), archive damaged", - pArchive->currentOffset - pThread->fileOffset); - goto bail; - } - DBUG(("--- record header written safely\n")); + /* + * Let's be paranoid and verify that the write didn't overflow + * into the thread header. We compare our current offset against + * the offset of the first thread. (If we're in a weird record + * with no threads, we could compare against the offset of the + * next record, but I don't want to deal with a case that should + * never happen anyway.) + */ + DBUG(("--- record header wrote %ld bytes\n", + pArchive->currentOffset - pRecord->fileOffset)); + pThread = pRecord->pThreads; + if (pThread != nil && pArchive->currentOffset != pThread->fileOffset) { + /* guess what, we just trashed the archive */ + err = kNuErrDamaged; + Nu_ReportError(NU_BLOB, err, + "Bad record header write (off by %ld), archive damaged", + pArchive->currentOffset - pThread->fileOffset); + goto bail; + } + DBUG(("--- record header written safely\n")); - /* - * It's customary to throw out the thread mods when you're done. (I'm - * not really sure why I'm doing this now, but here we are.) - */ - Nu_FreeThreadMods(pArchive, pRecord); + /* + * It's customary to throw out the thread mods when you're done. (I'm + * not really sure why I'm doing this now, but here we are.) + */ + Nu_FreeThreadMods(pArchive, pRecord); bail: - return err; + return err; } /* * =========================================================================== - * Archive construction - main functions + * Archive construction - main functions * =========================================================================== */ @@ -1547,82 +1547,82 @@ bail: static NuError Nu_CreateTempFromOriginal(NuArchive* pArchive) { - NuError err = kNuErrNone; - NuRecord* pRecord; + NuError err = kNuErrNone; + NuRecord* pRecord; - Assert(pArchive->tmpFp != 0); - Assert(ftell(pArchive->tmpFp) == 0); /* should be empty as well */ + Assert(pArchive->tmpFp != 0); + Assert(ftell(pArchive->tmpFp) == 0); /* should be empty as well */ - /* - * Leave space for the master header and (if we're preserving it) any - * header gunk. - */ - Assert(!pArchive->valDiscardWrapper || pArchive->headerOffset == 0); - err = Nu_FSeek(pArchive->tmpFp, - pArchive->headerOffset + kNuMasterHeaderSize, SEEK_SET); - BailError(err); + /* + * Leave space for the master header and (if we're preserving it) any + * header gunk. + */ + Assert(!pArchive->valDiscardWrapper || pArchive->headerOffset == 0); + err = Nu_FSeek(pArchive->tmpFp, + pArchive->headerOffset + kNuMasterHeaderSize, SEEK_SET); + BailError(err); - if (Nu_RecordSet_GetLoaded(&pArchive->copyRecordSet)) { - /* - * Run through the "copy" records. If the original record header is - * umodified, just copy it; otherwise write a new one with a new CRC. - */ - if (Nu_RecordSet_IsEmpty(&pArchive->copyRecordSet)) { - /* new archive or all records deleted */ - DBUG(("--- No records in 'copy' set\n")); - goto bail; - } - pRecord = Nu_RecordSet_GetListHead(&pArchive->copyRecordSet); - } else { - /* - * There's no "copy" set defined. If we have an "orig" set, we - * must be doing nothing but add files to an existing archive - * without the "modify orig" flag set. - */ - if (Nu_RecordSet_IsEmpty(&pArchive->origRecordSet)) { - DBUG(("--- No records in 'copy' or 'orig' set\n")); - goto bail; - } - pRecord = Nu_RecordSet_GetListHead(&pArchive->origRecordSet); - } + if (Nu_RecordSet_GetLoaded(&pArchive->copyRecordSet)) { + /* + * Run through the "copy" records. If the original record header is + * umodified, just copy it; otherwise write a new one with a new CRC. + */ + if (Nu_RecordSet_IsEmpty(&pArchive->copyRecordSet)) { + /* new archive or all records deleted */ + DBUG(("--- No records in 'copy' set\n")); + goto bail; + } + pRecord = Nu_RecordSet_GetListHead(&pArchive->copyRecordSet); + } else { + /* + * There's no "copy" set defined. If we have an "orig" set, we + * must be doing nothing but add files to an existing archive + * without the "modify orig" flag set. + */ + if (Nu_RecordSet_IsEmpty(&pArchive->origRecordSet)) { + DBUG(("--- No records in 'copy' or 'orig' set\n")); + goto bail; + } + pRecord = Nu_RecordSet_GetListHead(&pArchive->origRecordSet); + } - /* - * Reconstruct or copy the records. It's probably not necessary - * to reconstruct the entire record if we're just updating the - * record header, but since all we do is copy the data anyway, - * it's not much slower. - */ - while (pRecord != nil) { - if (!pRecord->dirtyHeader && pRecord->pThreadMods == nil) { - err = Nu_CopyArchiveRecord(pArchive, pRecord); - BailError(err); - } else { - err = Nu_ConstructArchiveRecord(pArchive, pRecord); - if (err == kNuErrSkipped) { - /* - * We're going to retain the original. This requires us - * to copy the original record from the "orig" record set - * and replace what we had in the "copy" set, so that at - * the end of the day the "copy" set accurately reflects - * what's in the archive. - */ - DBUG(("--- Skipping, copying %ld instead\n", - pRecord->recordIdx)); - err = Nu_RecordSet_ReplaceRecord(pArchive, - &pArchive->copyRecordSet, pRecord, - &pArchive->origRecordSet, &pRecord); - BailError(err); - err = Nu_CopyArchiveRecord(pArchive, pRecord); - BailError(err); - } - BailError(err); - } + /* + * Reconstruct or copy the records. It's probably not necessary + * to reconstruct the entire record if we're just updating the + * record header, but since all we do is copy the data anyway, + * it's not much slower. + */ + while (pRecord != nil) { + if (!pRecord->dirtyHeader && pRecord->pThreadMods == nil) { + err = Nu_CopyArchiveRecord(pArchive, pRecord); + BailError(err); + } else { + err = Nu_ConstructArchiveRecord(pArchive, pRecord); + if (err == kNuErrSkipped) { + /* + * We're going to retain the original. This requires us + * to copy the original record from the "orig" record set + * and replace what we had in the "copy" set, so that at + * the end of the day the "copy" set accurately reflects + * what's in the archive. + */ + DBUG(("--- Skipping, copying %ld instead\n", + pRecord->recordIdx)); + err = Nu_RecordSet_ReplaceRecord(pArchive, + &pArchive->copyRecordSet, pRecord, + &pArchive->origRecordSet, &pRecord); + BailError(err); + err = Nu_CopyArchiveRecord(pArchive, pRecord); + BailError(err); + } + BailError(err); + } - pRecord = pRecord->pNext; - } + pRecord = pRecord->pNext; + } bail: - return err; + return err; } @@ -1635,40 +1635,40 @@ bail: static NuError Nu_UpdateInOriginal(NuArchive* pArchive) { - NuError err = kNuErrNone; - NuRecord* pRecord; + NuError err = kNuErrNone; + NuRecord* pRecord; - if (!Nu_RecordSet_GetLoaded(&pArchive->copyRecordSet)) { - /* - * There's nothing for us to do; we probably just have a - * bunch of new stuff being added. - */ - DBUG(("--- UpdateInOriginal: nothing to do\n")); - goto done; - } + if (!Nu_RecordSet_GetLoaded(&pArchive->copyRecordSet)) { + /* + * There's nothing for us to do; we probably just have a + * bunch of new stuff being added. + */ + DBUG(("--- UpdateInOriginal: nothing to do\n")); + goto done; + } - /* - * Run through and process all the updates. - */ - pRecord = Nu_RecordSet_GetListHead(&pArchive->copyRecordSet); - while (pRecord != nil) { - if (pRecord->dirtyHeader || pRecord->pThreadMods != nil) { - err = Nu_UpdateRecordInOriginal(pArchive, pRecord); - BailError(err); - } + /* + * Run through and process all the updates. + */ + pRecord = Nu_RecordSet_GetListHead(&pArchive->copyRecordSet); + while (pRecord != nil) { + if (pRecord->dirtyHeader || pRecord->pThreadMods != nil) { + err = Nu_UpdateRecordInOriginal(pArchive, pRecord); + BailError(err); + } - pRecord = pRecord->pNext; - } + pRecord = pRecord->pNext; + } done: - /* seek to the end of the archive */ - err = Nu_FSeek(pArchive->archiveFp, - pArchive->headerOffset + pArchive->masterHeader.mhMasterEOF, - SEEK_SET); - BailError(err); + /* seek to the end of the archive */ + err = Nu_FSeek(pArchive->archiveFp, + pArchive->headerOffset + pArchive->masterHeader.mhMasterEOF, + SEEK_SET); + BailError(err); bail: - return err; + return err; } @@ -1681,41 +1681,41 @@ bail: static NuError Nu_CreateNewRecords(NuArchive* pArchive, FILE* fp) { - NuError err = kNuErrNone; - NuRecord* pRecord; + NuError err = kNuErrNone; + NuRecord* pRecord; - pRecord = Nu_RecordSet_GetListHead(&pArchive->newRecordSet); - while (pRecord != nil) { - err = Nu_ConstructNewRecord(pArchive, pRecord, fp); - if (err == kNuErrSkipped) { - /* - * We decided to skip this record, so delete it from "new". - * - * (I think this is the only time we delete something from the - * "new" set...) - */ - NuRecord* pNextRecord = pRecord->pNext; + pRecord = Nu_RecordSet_GetListHead(&pArchive->newRecordSet); + while (pRecord != nil) { + err = Nu_ConstructNewRecord(pArchive, pRecord, fp); + if (err == kNuErrSkipped) { + /* + * We decided to skip this record, so delete it from "new". + * + * (I think this is the only time we delete something from the + * "new" set...) + */ + NuRecord* pNextRecord = pRecord->pNext; - DBUG(("--- Skipping, deleting new %ld\n", pRecord->recordIdx)); - err = Nu_RecordSet_DeleteRecord(pArchive, &pArchive->newRecordSet, - pRecord); - Assert(err == kNuErrNone); - BailError(err); - pRecord = pNextRecord; - } else { - BailError(err); - pRecord = pRecord->pNext; - } - } + DBUG(("--- Skipping, deleting new %ld\n", pRecord->recordIdx)); + err = Nu_RecordSet_DeleteRecord(pArchive, &pArchive->newRecordSet, + pRecord); + Assert(err == kNuErrNone); + BailError(err); + pRecord = pNextRecord; + } else { + BailError(err); + pRecord = pRecord->pNext; + } + } bail: - return err; + return err; } /* * =========================================================================== - * Archive update helpers + * Archive update helpers * =========================================================================== */ @@ -1734,49 +1734,49 @@ bail: static Boolean Nu_NoHeavyUpdates(NuArchive* pArchive) { - const NuRecord* pRecord; - long count; + const NuRecord* pRecord; + long count; - /* if not loaded, then *no* changes were made to original records */ - if (!Nu_RecordSet_GetLoaded(&pArchive->copyRecordSet)) - return true; + /* if not loaded, then *no* changes were made to original records */ + if (!Nu_RecordSet_GetLoaded(&pArchive->copyRecordSet)) + return true; - /* - * You can't add to "copy" set, so any deletions are visible by the - * reduced record count. The function that deletes records from - * which all threads have been removed should be called before we - * get here. - */ - if (Nu_RecordSet_GetNumRecords(&pArchive->copyRecordSet) != - Nu_RecordSet_GetNumRecords(&pArchive->origRecordSet)) - { - return false; - } + /* + * You can't add to "copy" set, so any deletions are visible by the + * reduced record count. The function that deletes records from + * which all threads have been removed should be called before we + * get here. + */ + if (Nu_RecordSet_GetNumRecords(&pArchive->copyRecordSet) != + Nu_RecordSet_GetNumRecords(&pArchive->origRecordSet)) + { + return false; + } - /* - * Run through the set of records, looking for a threadMod with a - * change type we can't handle in place. - */ - count = Nu_RecordSet_GetNumRecords(&pArchive->copyRecordSet); - pRecord = Nu_RecordSet_GetListHead(&pArchive->copyRecordSet); - while (count--) { - const NuThreadMod* pThreadMod; + /* + * Run through the set of records, looking for a threadMod with a + * change type we can't handle in place. + */ + count = Nu_RecordSet_GetNumRecords(&pArchive->copyRecordSet); + pRecord = Nu_RecordSet_GetListHead(&pArchive->copyRecordSet); + while (count--) { + const NuThreadMod* pThreadMod; - Assert(pRecord != nil); + Assert(pRecord != nil); - pThreadMod = pRecord->pThreadMods; - while (pThreadMod != nil) { - /* the only acceptable kind is "update" */ - if (pThreadMod->entry.kind != kNuThreadModUpdate) - return false; + pThreadMod = pRecord->pThreadMods; + while (pThreadMod != nil) { + /* the only acceptable kind is "update" */ + if (pThreadMod->entry.kind != kNuThreadModUpdate) + return false; - pThreadMod = pThreadMod->pNext; - } + pThreadMod = pThreadMod->pNext; + } - pRecord = pRecord->pNext; - } + pRecord = pRecord->pNext; + } - return true; + return true; } @@ -1792,38 +1792,38 @@ Nu_NoHeavyUpdates(NuArchive* pArchive) static NuError Nu_PurgeEmptyRecords(NuArchive* pArchive, NuRecordSet* pRecordSet) { - NuError err = kNuErrNone; - NuRecord* pRecord; - NuRecord** ppRecord; + NuError err = kNuErrNone; + NuRecord* pRecord; + NuRecord** ppRecord; - Assert(pArchive != nil); - Assert(pRecordSet != nil); + Assert(pArchive != nil); + Assert(pRecordSet != nil); - if (Nu_RecordSet_IsEmpty(pRecordSet)) - return kNuErrNone; + if (Nu_RecordSet_IsEmpty(pRecordSet)) + return kNuErrNone; - ppRecord = Nu_RecordSet_GetListHeadPtr(pRecordSet); - Assert(ppRecord != nil); - Assert(*ppRecord != nil); + ppRecord = Nu_RecordSet_GetListHeadPtr(pRecordSet); + Assert(ppRecord != nil); + Assert(*ppRecord != nil); - /* maintain a pointer to the pointer, so we can delete easily */ - while (*ppRecord != nil) { - pRecord = *ppRecord; + /* maintain a pointer to the pointer, so we can delete easily */ + while (*ppRecord != nil) { + pRecord = *ppRecord; - if (Nu_RecordIsEmpty(pArchive, pRecord)) { - DBUG(("--- Purging empty record %06ld '%s' (0x%08lx-->0x%08lx)\n", - pRecord->recordIdx, pRecord->filename, - (ulong)ppRecord, (ulong)pRecord)); - err = Nu_RecordSet_DeleteRecordPtr(pArchive, pRecordSet, ppRecord); - BailError(err); - /* pRecord is now invalid, and *ppRecord has been updated */ - } else { - ppRecord = &pRecord->pNext; - } - } + if (Nu_RecordIsEmpty(pArchive, pRecord)) { + DBUG(("--- Purging empty record %06ld '%s' (0x%08lx-->0x%08lx)\n", + pRecord->recordIdx, pRecord->filename, + (ulong)ppRecord, (ulong)pRecord)); + err = Nu_RecordSet_DeleteRecordPtr(pArchive, pRecordSet, ppRecord); + BailError(err); + /* pRecord is now invalid, and *ppRecord has been updated */ + } else { + ppRecord = &pRecord->pNext; + } + } bail: - return err; + return err; } @@ -1837,36 +1837,36 @@ bail: static NuError Nu_UpdateMasterHeader(NuArchive* pArchive, FILE* fp, long archiveEOF) { - NuError err; - long numRecords; + NuError err; + long numRecords; - Nu_MasterHeaderCopy(pArchive, &pArchive->newMasterHeader, - &pArchive->masterHeader); + Nu_MasterHeaderCopy(pArchive, &pArchive->newMasterHeader, + &pArchive->masterHeader); - numRecords = 0; - if (Nu_RecordSet_GetLoaded(&pArchive->copyRecordSet)) - numRecords += Nu_RecordSet_GetNumRecords(&pArchive->copyRecordSet); - else - numRecords += Nu_RecordSet_GetNumRecords(&pArchive->origRecordSet); - if (Nu_RecordSet_GetLoaded(&pArchive->newRecordSet)) - numRecords += Nu_RecordSet_GetNumRecords(&pArchive->newRecordSet); - if (numRecords == 0) { - /* don't allow empty archives */ - DBUG(("--- Didn't find any records\n")); - err = kNuErrNoRecords; - goto bail; - } + numRecords = 0; + if (Nu_RecordSet_GetLoaded(&pArchive->copyRecordSet)) + numRecords += Nu_RecordSet_GetNumRecords(&pArchive->copyRecordSet); + else + numRecords += Nu_RecordSet_GetNumRecords(&pArchive->origRecordSet); + if (Nu_RecordSet_GetLoaded(&pArchive->newRecordSet)) + numRecords += Nu_RecordSet_GetNumRecords(&pArchive->newRecordSet); + if (numRecords == 0) { + /* don't allow empty archives */ + DBUG(("--- Didn't find any records\n")); + err = kNuErrNoRecords; + goto bail; + } - pArchive->newMasterHeader.mhTotalRecords = numRecords; - pArchive->newMasterHeader.mhMasterEOF = archiveEOF; - pArchive->newMasterHeader.mhMasterVersion = kNuOurMHVersion; - Nu_SetCurrentDateTime(&pArchive->newMasterHeader.mhArchiveModWhen); + pArchive->newMasterHeader.mhTotalRecords = numRecords; + pArchive->newMasterHeader.mhMasterEOF = archiveEOF; + pArchive->newMasterHeader.mhMasterVersion = kNuOurMHVersion; + Nu_SetCurrentDateTime(&pArchive->newMasterHeader.mhArchiveModWhen); - err = Nu_WriteMasterHeader(pArchive, fp, &pArchive->newMasterHeader); - BailError(err); + err = Nu_WriteMasterHeader(pArchive, fp, &pArchive->newMasterHeader); + BailError(err); bail: - return err; + return err; } @@ -1876,65 +1876,65 @@ bail: static NuError Nu_ResetTempFile(NuArchive* pArchive) { - NuError err = kNuErrNone; + NuError err = kNuErrNone; - /* read-only archives don't have a temp file */ - if (Nu_IsReadOnly(pArchive)) - return kNuErrNone; /* or kNuErrArchiveRO? */ + /* read-only archives don't have a temp file */ + if (Nu_IsReadOnly(pArchive)) + return kNuErrNone; /* or kNuErrArchiveRO? */ - Assert(pArchive != nil); - Assert(pArchive->tmpPathname != nil); + Assert(pArchive != nil); + Assert(pArchive->tmpPathname != nil); -#if 0 /* keep the temp file around for examination */ +#if 0 /* keep the temp file around for examination */ if (pArchive->tmpFp != nil) { - DBUG(("--- NOT Resetting temp file\n")); - fflush(pArchive->tmpFp); - goto bail; + DBUG(("--- NOT Resetting temp file\n")); + fflush(pArchive->tmpFp); + goto bail; } #endif - DBUG(("--- Resetting temp file\n")); + DBUG(("--- Resetting temp file\n")); - /* if we renamed the temp over the original, we need to open a new temp */ - if (pArchive->tmpFp == nil) { - pArchive->tmpFp = fopen(pArchive->tmpPathname, kNuFileOpenReadWriteCreat); - if (pArchive->tmpFp == nil) { - err = errno ? errno : kNuErrFileOpen; - Nu_ReportError(NU_BLOB, errno, "Unable to open temp file '%s'", - pArchive->tmpPathname); - goto bail; - } - } else { - /* - * Truncate the temp file. - */ - err = Nu_FSeek(pArchive->tmpFp, 0, SEEK_SET); - BailError(err); - err = Nu_TruncateOpenFile(pArchive->tmpFp, 0); - if (err == kNuErrInternal) { - /* do it the hard way if we don't have ftruncate or equivalent */ - err = kNuErrNone; - fclose(pArchive->tmpFp); - pArchive->tmpFp = fopen(pArchive->tmpPathname, kNuFileOpenWriteTrunc); - if (pArchive->tmpFp == nil) { - err = errno ? errno : kNuErrFileOpen; - Nu_ReportError(NU_BLOB, err, "failed truncating tmp file"); - goto bail; - } - fclose(pArchive->tmpFp); - pArchive->tmpFp = - fopen(pArchive->tmpPathname, kNuFileOpenReadWriteCreat); - if (pArchive->tmpFp == nil) { - err = errno ? errno : kNuErrFileOpen; - Nu_ReportError(NU_BLOB, err, "Unable to open temp file '%s'", - pArchive->tmpPathname); - goto bail; - } - } - } + /* if we renamed the temp over the original, we need to open a new temp */ + if (pArchive->tmpFp == nil) { + pArchive->tmpFp = fopen(pArchive->tmpPathname, kNuFileOpenReadWriteCreat); + if (pArchive->tmpFp == nil) { + err = errno ? errno : kNuErrFileOpen; + Nu_ReportError(NU_BLOB, errno, "Unable to open temp file '%s'", + pArchive->tmpPathname); + goto bail; + } + } else { + /* + * Truncate the temp file. + */ + err = Nu_FSeek(pArchive->tmpFp, 0, SEEK_SET); + BailError(err); + err = Nu_TruncateOpenFile(pArchive->tmpFp, 0); + if (err == kNuErrInternal) { + /* do it the hard way if we don't have ftruncate or equivalent */ + err = kNuErrNone; + fclose(pArchive->tmpFp); + pArchive->tmpFp = fopen(pArchive->tmpPathname, kNuFileOpenWriteTrunc); + if (pArchive->tmpFp == nil) { + err = errno ? errno : kNuErrFileOpen; + Nu_ReportError(NU_BLOB, err, "failed truncating tmp file"); + goto bail; + } + fclose(pArchive->tmpFp); + pArchive->tmpFp = + fopen(pArchive->tmpPathname, kNuFileOpenReadWriteCreat); + if (pArchive->tmpFp == nil) { + err = errno ? errno : kNuErrFileOpen; + Nu_ReportError(NU_BLOB, err, "Unable to open temp file '%s'", + pArchive->tmpPathname); + goto bail; + } + } + } bail: - return err; + return err; } /* @@ -1946,30 +1946,30 @@ bail: static NuError Nu_RecordResetUsedFlags(NuArchive* pArchive, NuRecord* pRecord) { - NuThread* pThread; - long idx; + NuThread* pThread; + long idx; - Assert(pArchive != nil); - Assert(pRecord != nil); + Assert(pArchive != nil); + Assert(pRecord != nil); - /* these should already be clear */ - if (pRecord->pThreadMods) { - Assert(0); - return kNuErrInternal; - } + /* these should already be clear */ + if (pRecord->pThreadMods) { + Assert(0); + return kNuErrInternal; + } - /* these might still be set */ - for (idx = 0; idx < (long)pRecord->recTotalThreads; idx++) { - pThread = Nu_GetThread(pRecord, idx); - Assert(pThread != nil); + /* these might still be set */ + for (idx = 0; idx < (long)pRecord->recTotalThreads; idx++) { + pThread = Nu_GetThread(pRecord, idx); + Assert(pThread != nil); - pThread->used = false; - } + pThread->used = false; + } - /* and this */ - pRecord->dirtyHeader = false; + /* and this */ + pRecord->dirtyHeader = false; - return kNuErrNone; + return kNuErrNone; } /* @@ -1978,21 +1978,21 @@ Nu_RecordResetUsedFlags(NuArchive* pArchive, NuRecord* pRecord) static NuError Nu_ResetUsedFlags(NuArchive* pArchive, NuRecordSet* pRecordSet) { - NuError err = kNuErrNone; - NuRecord* pRecord; + NuError err = kNuErrNone; + NuRecord* pRecord; - pRecord = Nu_RecordSet_GetListHead(pRecordSet); - while (pRecord != nil) { - err = Nu_RecordResetUsedFlags(pArchive, pRecord); - if (err != kNuErrNone) { - Assert(0); - break; - } + pRecord = Nu_RecordSet_GetListHead(pRecordSet); + while (pRecord != nil) { + err = Nu_RecordResetUsedFlags(pArchive, pRecord); + if (err != kNuErrNone) { + Assert(0); + break; + } - pRecord = pRecord->pNext; - } + pRecord = pRecord->pNext; + } - return err; + return err; } @@ -2002,27 +2002,27 @@ Nu_ResetUsedFlags(NuArchive* pArchive, NuRecordSet* pRecordSet) static void Nu_ResetCopySetIfUntouched(NuArchive* pArchive) { - const NuRecord* pRecord; + const NuRecord* pRecord; - /* have any records been deleted? */ - if (Nu_RecordSet_GetNumRecords(&pArchive->copyRecordSet) != - pArchive->masterHeader.mhTotalRecords) - { - return; - } + /* have any records been deleted? */ + if (Nu_RecordSet_GetNumRecords(&pArchive->copyRecordSet) != + pArchive->masterHeader.mhTotalRecords) + { + return; + } - /* do we have any thread mods or dirty record headers? */ - pRecord = Nu_RecordSet_GetListHead(&pArchive->copyRecordSet); - while (pRecord != nil) { - if (pRecord->pThreadMods != nil || pRecord->dirtyHeader) - return; + /* do we have any thread mods or dirty record headers? */ + pRecord = Nu_RecordSet_GetListHead(&pArchive->copyRecordSet); + while (pRecord != nil) { + if (pRecord->pThreadMods != nil || pRecord->dirtyHeader) + return; - pRecord = pRecord->pNext; - } + pRecord = pRecord->pNext; + } - /* looks like nothing has been touched */ - DBUG(("--- copy set untouched, trashing it\n")); - (void) Nu_RecordSet_FreeAllRecords(pArchive, &pArchive->copyRecordSet); + /* looks like nothing has been touched */ + DBUG(("--- copy set untouched, trashing it\n")); + (void) Nu_RecordSet_FreeAllRecords(pArchive, &pArchive->copyRecordSet); } @@ -2033,57 +2033,57 @@ Nu_ResetCopySetIfUntouched(NuArchive* pArchive) static NuError Nu_AddCommentToFirstNewRecord(NuArchive* pArchive) { - NuError err = kNuErrNone; - NuRecord* pRecord; - NuThreadMod* pThreadMod = nil; - NuThreadMod* pExistingThreadMod = nil; - NuDataSource* pDataSource = nil; + NuError err = kNuErrNone; + NuRecord* pRecord; + NuThreadMod* pThreadMod = nil; + NuThreadMod* pExistingThreadMod = nil; + NuDataSource* pDataSource = nil; - /* if there aren't any records there, skip this */ - if (Nu_RecordSet_IsEmpty(&pArchive->newRecordSet)) - goto bail; + /* if there aren't any records there, skip this */ + if (Nu_RecordSet_IsEmpty(&pArchive->newRecordSet)) + goto bail; - pRecord = Nu_RecordSet_GetListHead(&pArchive->newRecordSet); + pRecord = Nu_RecordSet_GetListHead(&pArchive->newRecordSet); - /* - * See if this record already has a comment. If so, don't add - * another one. - */ - err = Nu_ThreadModAdd_FindByThreadID(pRecord, kNuThreadIDComment, - &pExistingThreadMod); - if (err == kNuErrNone) { - DBUG(("+++ record already has a comment, not adding another\n")); - goto bail; /* already exists */ - } - err = kNuErrNone; + /* + * See if this record already has a comment. If so, don't add + * another one. + */ + err = Nu_ThreadModAdd_FindByThreadID(pRecord, kNuThreadIDComment, + &pExistingThreadMod); + if (err == kNuErrNone) { + DBUG(("+++ record already has a comment, not adding another\n")); + goto bail; /* already exists */ + } + err = kNuErrNone; - /* create a new data source with nothing in it */ - err = Nu_DataSourceBuffer_New(kNuThreadFormatUncompressed, false, - kNuDefaultCommentSize, nil, 0, 0, &pDataSource); - BailError(err); - Assert(pDataSource != nil); + /* create a new data source with nothing in it */ + err = Nu_DataSourceBuffer_New(kNuThreadFormatUncompressed, false, + kNuDefaultCommentSize, nil, 0, 0, &pDataSource); + BailError(err); + Assert(pDataSource != nil); - /* create a new ThreadMod */ - err = Nu_ThreadModAdd_New(pArchive, kNuThreadIDComment, - kNuThreadFormatUncompressed, pDataSource, &pThreadMod); - BailError(err); - Assert(pThreadMod != nil); - pDataSource = nil; /* don't free on exit */ + /* create a new ThreadMod */ + err = Nu_ThreadModAdd_New(pArchive, kNuThreadIDComment, + kNuThreadFormatUncompressed, pDataSource, &pThreadMod); + BailError(err); + Assert(pThreadMod != nil); + pDataSource = nil; /* don't free on exit */ - /* add the thread mod to the record */ - Nu_RecordAddThreadMod(pRecord, pThreadMod); - pThreadMod = nil; /* don't free on exit */ + /* add the thread mod to the record */ + Nu_RecordAddThreadMod(pRecord, pThreadMod); + pThreadMod = nil; /* don't free on exit */ bail: - Nu_ThreadModFree(pArchive, pThreadMod); - Nu_DataSourceFree(pDataSource); - return err; + Nu_ThreadModFree(pArchive, pThreadMod); + Nu_DataSourceFree(pDataSource); + return err; } /* * =========================================================================== - * Main entry points + * Main entry points * =========================================================================== */ @@ -2096,376 +2096,376 @@ bail: NuError Nu_Flush(NuArchive* pArchive, long* pStatusFlags) { - NuError err = kNuErrNone; - Boolean canAbort = true; - Boolean writeToTemp = true; - long initialEOF, finalOffset; + NuError err = kNuErrNone; + Boolean canAbort = true; + Boolean writeToTemp = true; + long initialEOF, finalOffset; - DBUG(("--- FLUSH\n")); + DBUG(("--- FLUSH\n")); - if (pStatusFlags == nil) - return kNuErrInvalidArg; - /* these do get set on error, so clear them no matter what */ - *pStatusFlags = 0; + if (pStatusFlags == nil) + return kNuErrInvalidArg; + /* these do get set on error, so clear them no matter what */ + *pStatusFlags = 0; - if (Nu_IsReadOnly(pArchive)) - return kNuErrArchiveRO; + if (Nu_IsReadOnly(pArchive)) + return kNuErrArchiveRO; - err = Nu_GetFileLength(pArchive, pArchive->archiveFp, &initialEOF); - BailError(err); + err = Nu_GetFileLength(pArchive, pArchive->archiveFp, &initialEOF); + BailError(err); - /* - * Step 1: figure out if we have anything to do. If the "copy" and "new" - * lists are empty, then there's nothing for us to do. - * - * As a special case, we test for an archive that had all of its - * records deleted. This looks a lot like an archive that has had - * nothing done, because we would have made a "copy" list and then - * deleted all the records, leaving us with an empty list. - * - * In some cases, such as doing a bulk delete that doesn't end up - * matching anything or an attempted UpdatePresizedThread on a thread - * that isn't actually pre-sized, we create the "copy" list but don't - * actually change anything. We deal with that by frying the "copy" - * list if it doesn't have anything interesting in it. - */ - Nu_ResetCopySetIfUntouched(pArchive); - if (Nu_RecordSet_IsEmpty(&pArchive->copyRecordSet) && - Nu_RecordSet_IsEmpty(&pArchive->newRecordSet)) - { - if (Nu_RecordSet_GetLoaded(&pArchive->copyRecordSet)) { - DBUG(("--- All records deleted!\n")); - /* - * Options: - * (1) allow it, leaving an archive with nothing but a header - * that will probably be rejected by other NuFX applications - * (2) reject it, returning an error - * (3) allow it, and just delete the original archive - * - * I dislike #1, and #3 can be implemented by the application - * when it gets a #2. - */ - err = kNuErrAllDeleted; - goto bail; - } else { - DBUG(("--- Nothing pending\n")); - goto flushed; - } - } + /* + * Step 1: figure out if we have anything to do. If the "copy" and "new" + * lists are empty, then there's nothing for us to do. + * + * As a special case, we test for an archive that had all of its + * records deleted. This looks a lot like an archive that has had + * nothing done, because we would have made a "copy" list and then + * deleted all the records, leaving us with an empty list. + * + * In some cases, such as doing a bulk delete that doesn't end up + * matching anything or an attempted UpdatePresizedThread on a thread + * that isn't actually pre-sized, we create the "copy" list but don't + * actually change anything. We deal with that by frying the "copy" + * list if it doesn't have anything interesting in it. + */ + Nu_ResetCopySetIfUntouched(pArchive); + if (Nu_RecordSet_IsEmpty(&pArchive->copyRecordSet) && + Nu_RecordSet_IsEmpty(&pArchive->newRecordSet)) + { + if (Nu_RecordSet_GetLoaded(&pArchive->copyRecordSet)) { + DBUG(("--- All records deleted!\n")); + /* + * Options: + * (1) allow it, leaving an archive with nothing but a header + * that will probably be rejected by other NuFX applications + * (2) reject it, returning an error + * (3) allow it, and just delete the original archive + * + * I dislike #1, and #3 can be implemented by the application + * when it gets a #2. + */ + err = kNuErrAllDeleted; + goto bail; + } else { + DBUG(("--- Nothing pending\n")); + goto flushed; + } + } - /* if we have any changes, we certainly should have the TOC by now */ - Assert(pArchive->haveToc); - Assert(Nu_RecordSet_GetLoaded(&pArchive->origRecordSet)); + /* if we have any changes, we certainly should have the TOC by now */ + Assert(pArchive->haveToc); + Assert(Nu_RecordSet_GetLoaded(&pArchive->origRecordSet)); - /* - * Step 2: purge any records from the "copy" and "new" lists that don't - * have any threads. You can't delete from the "new" list, but it's - * possible somebody called NuAddRecord and never put anything in it. - */ - err = Nu_PurgeEmptyRecords(pArchive, &pArchive->copyRecordSet); - BailError(err); - err = Nu_PurgeEmptyRecords(pArchive, &pArchive->newRecordSet); - BailError(err); + /* + * Step 2: purge any records from the "copy" and "new" lists that don't + * have any threads. You can't delete from the "new" list, but it's + * possible somebody called NuAddRecord and never put anything in it. + */ + err = Nu_PurgeEmptyRecords(pArchive, &pArchive->copyRecordSet); + BailError(err); + err = Nu_PurgeEmptyRecords(pArchive, &pArchive->newRecordSet); + BailError(err); - /* we rejected delete-all actions above, so just check for empty */ - if (Nu_RecordSet_IsEmpty(&pArchive->copyRecordSet) && - Nu_RecordSet_IsEmpty(&pArchive->newRecordSet)) - { - DBUG(("--- Nothing pending after purge\n")); - goto flushed; - } + /* we rejected delete-all actions above, so just check for empty */ + if (Nu_RecordSet_IsEmpty(&pArchive->copyRecordSet) && + Nu_RecordSet_IsEmpty(&pArchive->newRecordSet)) + { + DBUG(("--- Nothing pending after purge\n")); + goto flushed; + } - /* - * Step 3: if we're in ShrinkIt-compatibility mode, add a comment - * thread to the first record in the new list. GSHK does this every - * time it adds files, regardless of the prior contents of the archive. - */ - if (pArchive->valMimicSHK) { - err = Nu_AddCommentToFirstNewRecord(pArchive); - BailError(err); - } + /* + * Step 3: if we're in ShrinkIt-compatibility mode, add a comment + * thread to the first record in the new list. GSHK does this every + * time it adds files, regardless of the prior contents of the archive. + */ + if (pArchive->valMimicSHK) { + err = Nu_AddCommentToFirstNewRecord(pArchive); + BailError(err); + } - /* - * Step 4: decide if we want to make changes in place, or write to - * a temp file. Any deletions or additions to existing records will - * require writing to a temp file. Additions of new records and - * updates to pre-sized threads can be done in place. - */ - writeToTemp = true; - if (pArchive->valModifyOrig && Nu_NoHeavyUpdates(pArchive)) - writeToTemp = false; - /* discard the wrapper, if desired */ - if (writeToTemp && pArchive->valDiscardWrapper) - pArchive->headerOffset = 0; + /* + * Step 4: decide if we want to make changes in place, or write to + * a temp file. Any deletions or additions to existing records will + * require writing to a temp file. Additions of new records and + * updates to pre-sized threads can be done in place. + */ + writeToTemp = true; + if (pArchive->valModifyOrig && Nu_NoHeavyUpdates(pArchive)) + writeToTemp = false; + /* discard the wrapper, if desired */ + if (writeToTemp && pArchive->valDiscardWrapper) + pArchive->headerOffset = 0; - /* - * Step 5: handle updates to existing records. - */ - if (!writeToTemp) { - /* - * Step 5a: modifying in place, process all UPDATE ThreadMods now. - */ - DBUG(("--- No heavy updates found, updating in place\n")); - if (Nu_RecordSet_GetLoaded(&pArchive->copyRecordSet)) - canAbort = false; /* modifying original, can't cleanly abort */ + /* + * Step 5: handle updates to existing records. + */ + if (!writeToTemp) { + /* + * Step 5a: modifying in place, process all UPDATE ThreadMods now. + */ + DBUG(("--- No heavy updates found, updating in place\n")); + if (Nu_RecordSet_GetLoaded(&pArchive->copyRecordSet)) + canAbort = false; /* modifying original, can't cleanly abort */ - err = Nu_UpdateInOriginal(pArchive); - if (err == kNuErrDamaged) - *pStatusFlags |= kNuFlushCorrupted; - if (err != kNuErrNone) { - Nu_ReportError(NU_BLOB, err, "update to original failed"); - goto bail; - } - } else { - /* - * Step 5b: not modifying in place, reconstruct the appropriate - * parts of the original archive in the temp file, possibly copying - * the front bits over first. Updates and thread-adds will be - * done here. - */ - DBUG(("--- Updating to temp file (valModifyOrig=%ld)\n", - pArchive->valModifyOrig)); - err = Nu_CreateTempFromOriginal(pArchive); - if (err != kNuErrNone) { - DBUG(("--- Create temp from original failed\n")); - goto bail; - } - } - /* on completion, tmpFp (or archiveFp) points to current archive EOF */ + err = Nu_UpdateInOriginal(pArchive); + if (err == kNuErrDamaged) + *pStatusFlags |= kNuFlushCorrupted; + if (err != kNuErrNone) { + Nu_ReportError(NU_BLOB, err, "update to original failed"); + goto bail; + } + } else { + /* + * Step 5b: not modifying in place, reconstruct the appropriate + * parts of the original archive in the temp file, possibly copying + * the front bits over first. Updates and thread-adds will be + * done here. + */ + DBUG(("--- Updating to temp file (valModifyOrig=%ld)\n", + pArchive->valModifyOrig)); + err = Nu_CreateTempFromOriginal(pArchive); + if (err != kNuErrNone) { + DBUG(("--- Create temp from original failed\n")); + goto bail; + } + } + /* on completion, tmpFp (or archiveFp) points to current archive EOF */ - /* - * Step 6: add the new records from the "new" list, if any. Add a - * filename thread to records where one wasn't provided. These records - * are either added to the original archive or the temp file as - * appropriate. - */ - if (writeToTemp) - err = Nu_CreateNewRecords(pArchive, pArchive->tmpFp); - else - err = Nu_CreateNewRecords(pArchive, pArchive->archiveFp); - BailError(err); + /* + * Step 6: add the new records from the "new" list, if any. Add a + * filename thread to records where one wasn't provided. These records + * are either added to the original archive or the temp file as + * appropriate. + */ + if (writeToTemp) + err = Nu_CreateNewRecords(pArchive, pArchive->tmpFp); + else + err = Nu_CreateNewRecords(pArchive, pArchive->archiveFp); + BailError(err); - /* on completion, tmpFp (or archiveFp) points to current archive EOF */ + /* on completion, tmpFp (or archiveFp) points to current archive EOF */ - /* - * Step 7: truncate the archive. This isn't strictly necessary. It - * comes in handy if we were compressing the very last file and it - * actually expanded. We went back and wrote the uncompressed data, - * but there's a bunch of junk after it from the first try. - * - * On systems like Win32 that don't support ftruncate, this will fail, - * so we just ignore the result. - */ - if (writeToTemp) { - err = Nu_FTell(pArchive->tmpFp, &finalOffset); - BailError(err); - (void) Nu_TruncateOpenFile(pArchive->tmpFp, finalOffset); - } else { - err = Nu_FTell(pArchive->archiveFp, &finalOffset); - BailError(err); - (void) Nu_TruncateOpenFile(pArchive->archiveFp, finalOffset); - } + /* + * Step 7: truncate the archive. This isn't strictly necessary. It + * comes in handy if we were compressing the very last file and it + * actually expanded. We went back and wrote the uncompressed data, + * but there's a bunch of junk after it from the first try. + * + * On systems like Win32 that don't support ftruncate, this will fail, + * so we just ignore the result. + */ + if (writeToTemp) { + err = Nu_FTell(pArchive->tmpFp, &finalOffset); + BailError(err); + (void) Nu_TruncateOpenFile(pArchive->tmpFp, finalOffset); + } else { + err = Nu_FTell(pArchive->archiveFp, &finalOffset); + BailError(err); + (void) Nu_TruncateOpenFile(pArchive->archiveFp, finalOffset); + } - /* - * Step 8: create an updated master header, and write it to the - * appropriate file. The "newMasterHeader" field in pArchive will - * hold the new header. - */ - Assert(!pArchive->newMasterHeader.isValid); - if (writeToTemp) { - err = Nu_FSeek(pArchive->tmpFp, pArchive->headerOffset, SEEK_SET); - BailError(err); - err = Nu_UpdateMasterHeader(pArchive, pArchive->tmpFp, - finalOffset - pArchive->headerOffset); - /* fall through with err */ - } else { - err = Nu_FSeek(pArchive->archiveFp, pArchive->headerOffset, SEEK_SET); - BailError(err); - err = Nu_UpdateMasterHeader(pArchive, pArchive->archiveFp, - finalOffset - pArchive->headerOffset); - /* fall through with err */ - } - if (err == kNuErrNoRecords) { - /* - * Somehow we ended up without any records at all. If we managed - * to get this far, it could only be because the user told us to - * skip adding everything. - */ - Nu_ReportError(NU_BLOB, kNuErrNone, "no records in this archive"); - goto bail; - } else if (err != kNuErrNone) { - Nu_ReportError(NU_BLOB, err, "failed writing master header"); - goto bail; - } - Assert(pArchive->newMasterHeader.isValid); + /* + * Step 8: create an updated master header, and write it to the + * appropriate file. The "newMasterHeader" field in pArchive will + * hold the new header. + */ + Assert(!pArchive->newMasterHeader.isValid); + if (writeToTemp) { + err = Nu_FSeek(pArchive->tmpFp, pArchive->headerOffset, SEEK_SET); + BailError(err); + err = Nu_UpdateMasterHeader(pArchive, pArchive->tmpFp, + finalOffset - pArchive->headerOffset); + /* fall through with err */ + } else { + err = Nu_FSeek(pArchive->archiveFp, pArchive->headerOffset, SEEK_SET); + BailError(err); + err = Nu_UpdateMasterHeader(pArchive, pArchive->archiveFp, + finalOffset - pArchive->headerOffset); + /* fall through with err */ + } + if (err == kNuErrNoRecords) { + /* + * Somehow we ended up without any records at all. If we managed + * to get this far, it could only be because the user told us to + * skip adding everything. + */ + Nu_ReportError(NU_BLOB, kNuErrNone, "no records in this archive"); + goto bail; + } else if (err != kNuErrNone) { + Nu_ReportError(NU_BLOB, err, "failed writing master header"); + goto bail; + } + Assert(pArchive->newMasterHeader.isValid); - /* - * Step 9: carry forward the BXY, SEA, or BSE header, if necessary. This - * implicitly assumes that the header doesn't change size. If this - * assumption is invalid, we'd need to adjust "headerOffset" earlier, - * or do lots of data copying. Looks like Binary II and SEA headers - * are both fixed size, so we should be okay. - */ - if (pArchive->headerOffset) { - if (writeToTemp) { - if (!pArchive->valDiscardWrapper) { - DBUG(("--- Preserving wrapper\n")); - /* copy header to temp */ - err = Nu_CopyWrapperToTemp(pArchive); - BailError(err); - /* update fields that require it */ - err = Nu_UpdateWrapper(pArchive, pArchive->tmpFp); - BailError(err); - /* check the padding */ - err = Nu_AdjustWrapperPadding(pArchive, pArchive->tmpFp); - BailError(err); - } - } else { - /* may need to tweak what's in place? */ - DBUG(("--- Updating wrapper\n")); - err = Nu_UpdateWrapper(pArchive, pArchive->archiveFp); - BailError(err); - /* should only be necessary if we've added new records */ - err = Nu_AdjustWrapperPadding(pArchive, pArchive->archiveFp); - BailError(err); - } - } + /* + * Step 9: carry forward the BXY, SEA, or BSE header, if necessary. This + * implicitly assumes that the header doesn't change size. If this + * assumption is invalid, we'd need to adjust "headerOffset" earlier, + * or do lots of data copying. Looks like Binary II and SEA headers + * are both fixed size, so we should be okay. + */ + if (pArchive->headerOffset) { + if (writeToTemp) { + if (!pArchive->valDiscardWrapper) { + DBUG(("--- Preserving wrapper\n")); + /* copy header to temp */ + err = Nu_CopyWrapperToTemp(pArchive); + BailError(err); + /* update fields that require it */ + err = Nu_UpdateWrapper(pArchive, pArchive->tmpFp); + BailError(err); + /* check the padding */ + err = Nu_AdjustWrapperPadding(pArchive, pArchive->tmpFp); + BailError(err); + } + } else { + /* may need to tweak what's in place? */ + DBUG(("--- Updating wrapper\n")); + err = Nu_UpdateWrapper(pArchive, pArchive->archiveFp); + BailError(err); + /* should only be necessary if we've added new records */ + err = Nu_AdjustWrapperPadding(pArchive, pArchive->archiveFp); + BailError(err); + } + } - /* - * Step 10: if necessary, remove the original file and rename the - * temp file over it. - * - * I'm not messing with access permissions on the archive file here, - * because if they opened it read-write then the archive itself - * must also be read-write (unless somebody snuck in and chmodded it - * while we were busy). The temp file is certainly writable, so we - * should be able to just leave it all alone. - * - * I'm closing both temp and archive before renaming, because on some - * operating systems you can't do certain things with open files. - */ - if (writeToTemp) { - canAbort = false; /* no going back */ - fclose(pArchive->tmpFp); - pArchive->tmpFp = nil; - fclose(pArchive->archiveFp); - pArchive->archiveFp = nil; - *pStatusFlags |= kNuFlushSucceeded; + /* + * Step 10: if necessary, remove the original file and rename the + * temp file over it. + * + * I'm not messing with access permissions on the archive file here, + * because if they opened it read-write then the archive itself + * must also be read-write (unless somebody snuck in and chmodded it + * while we were busy). The temp file is certainly writable, so we + * should be able to just leave it all alone. + * + * I'm closing both temp and archive before renaming, because on some + * operating systems you can't do certain things with open files. + */ + if (writeToTemp) { + canAbort = false; /* no going back */ + fclose(pArchive->tmpFp); + pArchive->tmpFp = nil; + fclose(pArchive->archiveFp); + pArchive->archiveFp = nil; + *pStatusFlags |= kNuFlushSucceeded; - err = Nu_DeleteArchiveFile(pArchive); - if (err != kNuErrNone) { - Nu_ReportError(NU_BLOB, err, "unable to remove original archive"); - Nu_ReportError(NU_BLOB, kNuErrNone, "New data is in '%s'", - pArchive->tmpPathname); - *pStatusFlags |= kNuFlushInaccessible; - goto bail; - } + err = Nu_DeleteArchiveFile(pArchive); + if (err != kNuErrNone) { + Nu_ReportError(NU_BLOB, err, "unable to remove original archive"); + Nu_ReportError(NU_BLOB, kNuErrNone, "New data is in '%s'", + pArchive->tmpPathname); + *pStatusFlags |= kNuFlushInaccessible; + goto bail; + } - err = Nu_RenameTempToArchive(pArchive); - if (err != kNuErrNone) { - Nu_ReportError(NU_BLOB, err, "unable to rename temp file"); - Nu_ReportError(NU_BLOB, kNuErrNone, - "NOTE: only copy of archive is in '%s'", pArchive->tmpPathname); - /* maintain Entry.c semantics (and keep them from removing temp) */ - Nu_Free(pArchive, pArchive->archivePathname); - pArchive->archivePathname = nil; - Nu_Free(pArchive, pArchive->tmpPathname); - pArchive->tmpPathname = nil; - /* bail will put us into read-only mode, which is what we want */ - goto bail; - } + err = Nu_RenameTempToArchive(pArchive); + if (err != kNuErrNone) { + Nu_ReportError(NU_BLOB, err, "unable to rename temp file"); + Nu_ReportError(NU_BLOB, kNuErrNone, + "NOTE: only copy of archive is in '%s'", pArchive->tmpPathname); + /* maintain Entry.c semantics (and keep them from removing temp) */ + Nu_Free(pArchive, pArchive->archivePathname); + pArchive->archivePathname = nil; + Nu_Free(pArchive, pArchive->tmpPathname); + pArchive->tmpPathname = nil; + /* bail will put us into read-only mode, which is what we want */ + goto bail; + } - pArchive->archiveFp = fopen(pArchive->archivePathname, - kNuFileOpenReadWrite); - if (pArchive->archiveFp == nil) { - err = errno ? errno : -1; - Nu_ReportError(NU_BLOB, err, - "unable to reopen archive file '%s' after rename", - pArchive->archivePathname); - *pStatusFlags |= kNuFlushInaccessible; - goto bail; /* the Entry.c funcs will obstruct further use */ - } - } else { - fflush(pArchive->archiveFp); - if (ferror(pArchive->archiveFp)) { - err = kNuErrFileWrite; - Nu_ReportError(NU_BLOB, kNuErrNone, "final archive flush failed"); - *pStatusFlags |= kNuFlushCorrupted; - goto bail; - } - canAbort = false; - *pStatusFlags |= kNuFlushSucceeded; - } + pArchive->archiveFp = fopen(pArchive->archivePathname, + kNuFileOpenReadWrite); + if (pArchive->archiveFp == nil) { + err = errno ? errno : -1; + Nu_ReportError(NU_BLOB, err, + "unable to reopen archive file '%s' after rename", + pArchive->archivePathname); + *pStatusFlags |= kNuFlushInaccessible; + goto bail; /* the Entry.c funcs will obstruct further use */ + } + } else { + fflush(pArchive->archiveFp); + if (ferror(pArchive->archiveFp)) { + err = kNuErrFileWrite; + Nu_ReportError(NU_BLOB, kNuErrNone, "final archive flush failed"); + *pStatusFlags |= kNuFlushCorrupted; + goto bail; + } + canAbort = false; + *pStatusFlags |= kNuFlushSucceeded; + } - Assert(canAbort == false); + Assert(canAbort == false); - /* - * Step 11: clean up data structures. If we have a "copy" list, then - * throw out the "orig" list and move the "copy" list over it. Append - * anything in the "new" list to it. Move the "new" master header - * over the original. - */ - Assert(pArchive->newMasterHeader.isValid); - Nu_MasterHeaderCopy(pArchive, &pArchive->masterHeader, - &pArchive->newMasterHeader); - if (Nu_RecordSet_GetLoaded(&pArchive->copyRecordSet)) { - err = Nu_RecordSet_FreeAllRecords(pArchive, &pArchive->origRecordSet); - BailError(err); - err = Nu_RecordSet_MoveAllRecords(pArchive, &pArchive->origRecordSet, - &pArchive->copyRecordSet); - BailError(err); - } - err = Nu_RecordSet_MoveAllRecords(pArchive, &pArchive->origRecordSet, - &pArchive->newRecordSet); - BailError(err); - err = Nu_ResetUsedFlags(pArchive, &pArchive->origRecordSet); - BailError(err); + /* + * Step 11: clean up data structures. If we have a "copy" list, then + * throw out the "orig" list and move the "copy" list over it. Append + * anything in the "new" list to it. Move the "new" master header + * over the original. + */ + Assert(pArchive->newMasterHeader.isValid); + Nu_MasterHeaderCopy(pArchive, &pArchive->masterHeader, + &pArchive->newMasterHeader); + if (Nu_RecordSet_GetLoaded(&pArchive->copyRecordSet)) { + err = Nu_RecordSet_FreeAllRecords(pArchive, &pArchive->origRecordSet); + BailError(err); + err = Nu_RecordSet_MoveAllRecords(pArchive, &pArchive->origRecordSet, + &pArchive->copyRecordSet); + BailError(err); + } + err = Nu_RecordSet_MoveAllRecords(pArchive, &pArchive->origRecordSet, + &pArchive->newRecordSet); + BailError(err); + err = Nu_ResetUsedFlags(pArchive, &pArchive->origRecordSet); + BailError(err); flushed: - /* - * Step 12: reset the "copy" and "new" lists, and reset the temp file. - * Clear out the "new" master header copy. - */ - err = Nu_RecordSet_FreeAllRecords(pArchive, &pArchive->copyRecordSet); - BailError(err); - err = Nu_RecordSet_FreeAllRecords(pArchive, &pArchive->newRecordSet); - BailError(err); - pArchive->newMasterHeader.isValid = false; + /* + * Step 12: reset the "copy" and "new" lists, and reset the temp file. + * Clear out the "new" master header copy. + */ + err = Nu_RecordSet_FreeAllRecords(pArchive, &pArchive->copyRecordSet); + BailError(err); + err = Nu_RecordSet_FreeAllRecords(pArchive, &pArchive->newRecordSet); + BailError(err); + pArchive->newMasterHeader.isValid = false; - err = Nu_ResetTempFile(pArchive); - if (err != kNuErrNone) { - /* can't NuAbort() our way out of a bad temp file */ - canAbort = false; - goto bail; - } + err = Nu_ResetTempFile(pArchive); + if (err != kNuErrNone) { + /* can't NuAbort() our way out of a bad temp file */ + canAbort = false; + goto bail; + } bail: - if (err != kNuErrNone) { - if (canAbort) { - (void) Nu_Abort(pArchive); - Assert(!(*pStatusFlags & kNuFlushSucceeded)); - *pStatusFlags |= kNuFlushAborted; + if (err != kNuErrNone) { + if (canAbort) { + (void) Nu_Abort(pArchive); + Assert(!(*pStatusFlags & kNuFlushSucceeded)); + *pStatusFlags |= kNuFlushAborted; - /* - * If we were adding to original archive, truncate it back if - * we are able to do so. This retains any BXY/BSE wrapper padding. - */ - if (!writeToTemp) { - err = Nu_TruncateOpenFile(pArchive->archiveFp, initialEOF); - if (err == kNuErrNone) { - DBUG(("+++ truncating orig archive back to %ld\n", - initialEOF)); - } - } - } else { - Nu_ReportError(NU_BLOB, kNuErrNone, - "disabling write access after failed update"); - pArchive->openMode = kNuOpenRO; - *pStatusFlags |= kNuFlushReadOnly; - } - } - return err; + /* + * If we were adding to original archive, truncate it back if + * we are able to do so. This retains any BXY/BSE wrapper padding. + */ + if (!writeToTemp) { + err = Nu_TruncateOpenFile(pArchive->archiveFp, initialEOF); + if (err == kNuErrNone) { + DBUG(("+++ truncating orig archive back to %ld\n", + initialEOF)); + } + } + } else { + Nu_ReportError(NU_BLOB, kNuErrNone, + "disabling write access after failed update"); + pArchive->openMode = kNuOpenRO; + *pStatusFlags |= kNuFlushReadOnly; + } + } + return err; } @@ -2475,21 +2475,21 @@ bail: NuError Nu_Abort(NuArchive* pArchive) { - Assert(pArchive != nil); + Assert(pArchive != nil); - if (Nu_IsReadOnly(pArchive)) - return kNuErrArchiveRO; + if (Nu_IsReadOnly(pArchive)) + return kNuErrArchiveRO; - DBUG(("--- Aborting changes\n")); + DBUG(("--- Aborting changes\n")); - /* - * Throw out the "copy" and "new" record sets, and reset the - * temp file. - */ - (void) Nu_RecordSet_FreeAllRecords(pArchive, &pArchive->copyRecordSet); - (void) Nu_RecordSet_FreeAllRecords(pArchive, &pArchive->newRecordSet); - pArchive->newMasterHeader.isValid = false; + /* + * Throw out the "copy" and "new" record sets, and reset the + * temp file. + */ + (void) Nu_RecordSet_FreeAllRecords(pArchive, &pArchive->copyRecordSet); + (void) Nu_RecordSet_FreeAllRecords(pArchive, &pArchive->newRecordSet); + pArchive->newMasterHeader.isValid = false; - return Nu_ResetTempFile(pArchive); + return Nu_ResetTempFile(pArchive); } diff --git a/nufxlib-0/Entry.c b/nufxlib-0/Entry.c index fe388e4..3d65f81 100644 --- a/nufxlib-0/Entry.c +++ b/nufxlib-0/Entry.c @@ -11,7 +11,7 @@ /* * =========================================================================== - * Misc utils + * Misc utils * =========================================================================== */ @@ -27,7 +27,7 @@ static inline void Nu_SetBusy(NuArchive* pArchive) { - pArchive->busy = true; + pArchive->busy = true; } /* @@ -36,7 +36,7 @@ Nu_SetBusy(NuArchive* pArchive) static inline void Nu_ClearBusy(NuArchive* pArchive) { - pArchive->busy = false; + pArchive->busy = false; } @@ -48,14 +48,14 @@ Nu_ClearBusy(NuArchive* pArchive) static NuError Nu_PartiallyValidateNuArchive(const NuArchive* pArchive) { - if (pArchive == nil) - return kNuErrInvalidArg; + if (pArchive == nil) + return kNuErrInvalidArg; - pArchive = pArchive; - if (pArchive->structMagic != kNuArchiveStructMagic) - return kNuErrBadStruct; + pArchive = pArchive; + if (pArchive->structMagic != kNuArchiveStructMagic) + return kNuErrBadStruct; - return kNuErrNone; + return kNuErrNone; } /* @@ -64,731 +64,731 @@ Nu_PartiallyValidateNuArchive(const NuArchive* pArchive) static NuError Nu_ValidateNuArchive(const NuArchive* pArchive) { - NuError err; + NuError err; - err = Nu_PartiallyValidateNuArchive(pArchive); - if (err != kNuErrNone) - return err; + err = Nu_PartiallyValidateNuArchive(pArchive); + if (err != kNuErrNone) + return err; - /* explicitly block reentrant calls */ - if (pArchive->busy) - return kNuErrBusy; + /* explicitly block reentrant calls */ + if (pArchive->busy) + return kNuErrBusy; - /* make sure the TOC state is consistent */ - if (pArchive->haveToc) { - if (pArchive->masterHeader.mhTotalRecords != 0) - Assert(Nu_RecordSet_GetListHead(&pArchive->origRecordSet) != nil); - Assert(Nu_RecordSet_GetNumRecords(&pArchive->origRecordSet) == - pArchive->masterHeader.mhTotalRecords); - } else { - Assert(Nu_RecordSet_GetListHead(&pArchive->origRecordSet) == nil); - } + /* make sure the TOC state is consistent */ + if (pArchive->haveToc) { + if (pArchive->masterHeader.mhTotalRecords != 0) + Assert(Nu_RecordSet_GetListHead(&pArchive->origRecordSet) != nil); + Assert(Nu_RecordSet_GetNumRecords(&pArchive->origRecordSet) == + pArchive->masterHeader.mhTotalRecords); + } else { + Assert(Nu_RecordSet_GetListHead(&pArchive->origRecordSet) == nil); + } - /* make sure we have open files to work with */ - Assert(pArchive->archivePathname == nil || pArchive->archiveFp != nil); - if (pArchive->archivePathname != nil && pArchive->archiveFp == nil) - return kNuErrInternal; - Assert(pArchive->tmpPathname == nil || pArchive->tmpFp != nil); - if (pArchive->tmpPathname != nil && pArchive->tmpFp == nil) - return kNuErrInternal; + /* make sure we have open files to work with */ + Assert(pArchive->archivePathname == nil || pArchive->archiveFp != nil); + if (pArchive->archivePathname != nil && pArchive->archiveFp == nil) + return kNuErrInternal; + Assert(pArchive->tmpPathname == nil || pArchive->tmpFp != nil); + if (pArchive->tmpPathname != nil && pArchive->tmpFp == nil) + return kNuErrInternal; - /* further validations */ + /* further validations */ - return kNuErrNone; + return kNuErrNone; } /* * =========================================================================== - * Streaming and non-streaming read-only + * Streaming and non-streaming read-only * =========================================================================== */ NuError NuStreamOpenRO(FILE* infp, NuArchive** ppArchive) { - NuError err; + NuError err; - if (infp == nil || ppArchive == nil) - return kNuErrInvalidArg; + if (infp == nil || ppArchive == nil) + return kNuErrInvalidArg; - err = Nu_StreamOpenRO(infp, (NuArchive**) ppArchive); + err = Nu_StreamOpenRO(infp, (NuArchive**) ppArchive); - return err; + return err; } NuError NuContents(NuArchive* pArchive, NuCallback contentFunc) { - NuError err; + NuError err; - if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { - Nu_SetBusy(pArchive); - if (Nu_IsStreaming(pArchive)) - err = Nu_StreamContents(pArchive, contentFunc); - else - err = Nu_Contents(pArchive, contentFunc); - Nu_ClearBusy(pArchive); - } + if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { + Nu_SetBusy(pArchive); + if (Nu_IsStreaming(pArchive)) + err = Nu_StreamContents(pArchive, contentFunc); + else + err = Nu_Contents(pArchive, contentFunc); + Nu_ClearBusy(pArchive); + } - return err; + return err; } NuError NuExtract(NuArchive* pArchive) { - NuError err; + NuError err; - if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { - Nu_SetBusy(pArchive); - if (Nu_IsStreaming(pArchive)) - err = Nu_StreamExtract(pArchive); - else - err = Nu_Extract(pArchive); - Nu_ClearBusy(pArchive); - } + if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { + Nu_SetBusy(pArchive); + if (Nu_IsStreaming(pArchive)) + err = Nu_StreamExtract(pArchive); + else + err = Nu_Extract(pArchive); + Nu_ClearBusy(pArchive); + } - return err; + return err; } NuError NuTest(NuArchive* pArchive) { - NuError err; + NuError err; - if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { - Nu_SetBusy(pArchive); - if (Nu_IsStreaming(pArchive)) - err = Nu_StreamTest(pArchive); - else - err = Nu_Test(pArchive); - Nu_ClearBusy(pArchive); - } + if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { + Nu_SetBusy(pArchive); + if (Nu_IsStreaming(pArchive)) + err = Nu_StreamTest(pArchive); + else + err = Nu_Test(pArchive); + Nu_ClearBusy(pArchive); + } - return err; + return err; } /* * =========================================================================== - * Strictly non-streaming read-only + * Strictly non-streaming read-only * =========================================================================== */ NuError NuOpenRO(const char* filename, NuArchive** ppArchive) { - NuError err; + NuError err; - err = Nu_OpenRO(filename, (NuArchive**) ppArchive); + err = Nu_OpenRO(filename, (NuArchive**) ppArchive); - return err; + return err; } NuError NuExtractRecord(NuArchive* pArchive, NuRecordIdx recordIdx) { - NuError err; + NuError err; - if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { - Nu_SetBusy(pArchive); - err = Nu_ExtractRecord(pArchive, recordIdx); - Nu_ClearBusy(pArchive); - } + if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { + Nu_SetBusy(pArchive); + err = Nu_ExtractRecord(pArchive, recordIdx); + Nu_ClearBusy(pArchive); + } - return err; + return err; } NuError NuExtractThread(NuArchive* pArchive, NuThreadIdx threadIdx, - NuDataSink* pDataSink) + NuDataSink* pDataSink) { - NuError err; + NuError err; - if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { - Nu_SetBusy(pArchive); - err = Nu_ExtractThread(pArchive, threadIdx, pDataSink); - Nu_ClearBusy(pArchive); - } + if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { + Nu_SetBusy(pArchive); + err = Nu_ExtractThread(pArchive, threadIdx, pDataSink); + Nu_ClearBusy(pArchive); + } - return err; + return err; } NuError NuGetRecord(NuArchive* pArchive, NuRecordIdx recordIdx, - const NuRecord** ppRecord) + const NuRecord** ppRecord) { - NuError err; + NuError err; - if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { - Nu_SetBusy(pArchive); - err = Nu_GetRecord(pArchive, recordIdx, ppRecord); - Nu_ClearBusy(pArchive); - } + if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { + Nu_SetBusy(pArchive); + err = Nu_GetRecord(pArchive, recordIdx, ppRecord); + Nu_ClearBusy(pArchive); + } - return err; + return err; } NuError NuGetRecordIdxByName(NuArchive* pArchive, const char* name, - NuRecordIdx* pRecordIdx) + NuRecordIdx* pRecordIdx) { - NuError err; + NuError err; - if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { - Nu_SetBusy(pArchive); - err = Nu_GetRecordIdxByName(pArchive, name, pRecordIdx); - Nu_ClearBusy(pArchive); - } + if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { + Nu_SetBusy(pArchive); + err = Nu_GetRecordIdxByName(pArchive, name, pRecordIdx); + Nu_ClearBusy(pArchive); + } - return err; + return err; } NuError NuGetRecordIdxByPosition(NuArchive* pArchive, unsigned long position, - NuRecordIdx* pRecordIdx) + NuRecordIdx* pRecordIdx) { - NuError err; + NuError err; - if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { - Nu_SetBusy(pArchive); - err = Nu_GetRecordIdxByPosition(pArchive, position, pRecordIdx); - Nu_ClearBusy(pArchive); - } + if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { + Nu_SetBusy(pArchive); + err = Nu_GetRecordIdxByPosition(pArchive, position, pRecordIdx); + Nu_ClearBusy(pArchive); + } - return err; + return err; } /* * =========================================================================== - * Read/Write + * Read/Write * =========================================================================== */ NuError NuOpenRW(const char* archivePathname, const char* tmpPathname, - unsigned long flags, NuArchive** ppArchive) + unsigned long flags, NuArchive** ppArchive) { - NuError err; + NuError err; - err = Nu_OpenRW(archivePathname, tmpPathname, flags, - (NuArchive**) ppArchive); + err = Nu_OpenRW(archivePathname, tmpPathname, flags, + (NuArchive**) ppArchive); - return err; + return err; } NuError NuFlush(NuArchive* pArchive, long* pStatusFlags) { - NuError err; + NuError err; - if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { - Nu_SetBusy(pArchive); - err = Nu_Flush(pArchive, pStatusFlags); - Nu_ClearBusy(pArchive); - } + if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { + Nu_SetBusy(pArchive); + err = Nu_Flush(pArchive, pStatusFlags); + Nu_ClearBusy(pArchive); + } - return err; + return err; } NuError NuAbort(NuArchive* pArchive) { - NuError err; + NuError err; - if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { - Nu_SetBusy(pArchive); - err = Nu_Abort(pArchive); - Nu_ClearBusy(pArchive); - } + if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { + Nu_SetBusy(pArchive); + err = Nu_Abort(pArchive); + Nu_ClearBusy(pArchive); + } - return err; + return err; } NuError NuAddRecord(NuArchive* pArchive, const NuFileDetails* pFileDetails, - NuRecordIdx* pRecordIdx) + NuRecordIdx* pRecordIdx) { - NuError err; + NuError err; - if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { - Nu_SetBusy(pArchive); - err = Nu_AddRecord(pArchive, pFileDetails, pRecordIdx, nil); - Nu_ClearBusy(pArchive); - } + if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { + Nu_SetBusy(pArchive); + err = Nu_AddRecord(pArchive, pFileDetails, pRecordIdx, nil); + Nu_ClearBusy(pArchive); + } - return err; + return err; } NuError NuAddThread(NuArchive* pArchive, NuRecordIdx recordIdx, NuThreadID threadID, - NuDataSource* pDataSource, NuThreadIdx* pThreadIdx) + NuDataSource* pDataSource, NuThreadIdx* pThreadIdx) { - NuError err; + NuError err; - if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { - Nu_SetBusy(pArchive); - err = Nu_AddThread(pArchive, recordIdx, threadID, - pDataSource, pThreadIdx); - Nu_ClearBusy(pArchive); - } + if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { + Nu_SetBusy(pArchive); + err = Nu_AddThread(pArchive, recordIdx, threadID, + pDataSource, pThreadIdx); + Nu_ClearBusy(pArchive); + } - return err; + return err; } NuError NuAddFile(NuArchive* pArchive, const char* pathname, - const NuFileDetails* pFileDetails, short isFromRsrcFork, - NuRecordIdx* pRecordIdx) + const NuFileDetails* pFileDetails, short isFromRsrcFork, + NuRecordIdx* pRecordIdx) { - NuError err; + NuError err; - if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { - Nu_SetBusy(pArchive); - err = Nu_AddFile(pArchive, pathname, pFileDetails, - (Boolean)(isFromRsrcFork != 0), pRecordIdx); - Nu_ClearBusy(pArchive); - } + if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { + Nu_SetBusy(pArchive); + err = Nu_AddFile(pArchive, pathname, pFileDetails, + (Boolean)(isFromRsrcFork != 0), pRecordIdx); + Nu_ClearBusy(pArchive); + } - return err; + return err; } NuError NuRename(NuArchive* pArchive, NuRecordIdx recordIdx, const char* pathname, - char fssep) + char fssep) { - NuError err; + NuError err; - if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { - Nu_SetBusy(pArchive); - err = Nu_Rename(pArchive, recordIdx, pathname, fssep); - Nu_ClearBusy(pArchive); - } + if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { + Nu_SetBusy(pArchive); + err = Nu_Rename(pArchive, recordIdx, pathname, fssep); + Nu_ClearBusy(pArchive); + } - return err; + return err; } NuError NuSetRecordAttr(NuArchive* pArchive, NuRecordIdx recordIdx, - const NuRecordAttr* pRecordAttr) + const NuRecordAttr* pRecordAttr) { - NuError err; + NuError err; - if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { - Nu_SetBusy(pArchive); - err = Nu_SetRecordAttr(pArchive, recordIdx, pRecordAttr); - Nu_ClearBusy(pArchive); - } + if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { + Nu_SetBusy(pArchive); + err = Nu_SetRecordAttr(pArchive, recordIdx, pRecordAttr); + Nu_ClearBusy(pArchive); + } - return err; + return err; } NuError NuUpdatePresizedThread(NuArchive* pArchive, NuThreadIdx threadIdx, - NuDataSource* pDataSource, long* pMaxLen) + NuDataSource* pDataSource, long* pMaxLen) { - NuError err; + NuError err; - if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { - Nu_SetBusy(pArchive); - err = Nu_UpdatePresizedThread(pArchive, threadIdx, - pDataSource, pMaxLen); - Nu_ClearBusy(pArchive); - } + if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { + Nu_SetBusy(pArchive); + err = Nu_UpdatePresizedThread(pArchive, threadIdx, + pDataSource, pMaxLen); + Nu_ClearBusy(pArchive); + } - return err; + return err; } NuError NuDelete(NuArchive* pArchive) { - NuError err; + NuError err; - if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { - Nu_SetBusy(pArchive); - err = Nu_Delete(pArchive); - Nu_ClearBusy(pArchive); - } + if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { + Nu_SetBusy(pArchive); + err = Nu_Delete(pArchive); + Nu_ClearBusy(pArchive); + } - return err; + return err; } NuError NuDeleteRecord(NuArchive* pArchive, NuRecordIdx recordIdx) { - NuError err; + NuError err; - if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { - Nu_SetBusy(pArchive); - err = Nu_DeleteRecord(pArchive, recordIdx); - Nu_ClearBusy(pArchive); - } + if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { + Nu_SetBusy(pArchive); + err = Nu_DeleteRecord(pArchive, recordIdx); + Nu_ClearBusy(pArchive); + } - return err; + return err; } NuError NuDeleteThread(NuArchive* pArchive, NuThreadIdx threadIdx) { - NuError err; + NuError err; - if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { - Nu_SetBusy(pArchive); - err = Nu_DeleteThread(pArchive, threadIdx); - Nu_ClearBusy(pArchive); - } + if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { + Nu_SetBusy(pArchive); + err = Nu_DeleteThread(pArchive, threadIdx); + Nu_ClearBusy(pArchive); + } - return err; + return err; } /* * =========================================================================== - * General interfaces + * General interfaces * =========================================================================== */ NuError NuClose(NuArchive* pArchive) { - NuError err; + NuError err; - if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { - Nu_SetBusy(pArchive); - err = Nu_Close(pArchive); - /* on success, pArchive has been freed */ - if (err != kNuErrNone) - Nu_ClearBusy(pArchive); - } + if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) { + Nu_SetBusy(pArchive); + err = Nu_Close(pArchive); + /* on success, pArchive has been freed */ + if (err != kNuErrNone) + Nu_ClearBusy(pArchive); + } - return err; + return err; } NuError NuGetMasterHeader(NuArchive* pArchive, const NuMasterHeader** ppMasterHeader) { - NuError err; + NuError err; - if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) - err = Nu_GetMasterHeader(pArchive, ppMasterHeader); + if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) + err = Nu_GetMasterHeader(pArchive, ppMasterHeader); - return err; + return err; } NuError NuGetExtraData(NuArchive* pArchive, void** ppData) { - NuError err; + NuError err; - if (ppData == nil) - return kNuErrInvalidArg; - if ((err = Nu_PartiallyValidateNuArchive(pArchive)) == kNuErrNone) - *ppData = pArchive->extraData; + if (ppData == nil) + return kNuErrInvalidArg; + if ((err = Nu_PartiallyValidateNuArchive(pArchive)) == kNuErrNone) + *ppData = pArchive->extraData; - return err; + return err; } NuError NuSetExtraData(NuArchive* pArchive, void* pData) { - NuError err; + NuError err; - if ((err = Nu_PartiallyValidateNuArchive(pArchive)) == kNuErrNone) - pArchive->extraData = pData; + if ((err = Nu_PartiallyValidateNuArchive(pArchive)) == kNuErrNone) + pArchive->extraData = pData; - return err; + return err; } NuError NuGetValue(NuArchive* pArchive, NuValueID ident, NuValue* pValue) { - NuError err; + NuError err; - if ((err = Nu_PartiallyValidateNuArchive(pArchive)) == kNuErrNone) - return Nu_GetValue(pArchive, ident, pValue); + if ((err = Nu_PartiallyValidateNuArchive(pArchive)) == kNuErrNone) + return Nu_GetValue(pArchive, ident, pValue); - return err; + return err; } NuError NuSetValue(NuArchive* pArchive, NuValueID ident, NuValue value) { - NuError err; + NuError err; - if ((err = Nu_PartiallyValidateNuArchive(pArchive)) == kNuErrNone) - return Nu_SetValue(pArchive, ident, value); + if ((err = Nu_PartiallyValidateNuArchive(pArchive)) == kNuErrNone) + return Nu_SetValue(pArchive, ident, value); - return err; + return err; } NuError NuGetAttr(NuArchive* pArchive, NuAttrID ident, NuAttr* pAttr) { - NuError err; + NuError err; - if ((err = Nu_PartiallyValidateNuArchive(pArchive)) == kNuErrNone) - return Nu_GetAttr(pArchive, ident, pAttr); + if ((err = Nu_PartiallyValidateNuArchive(pArchive)) == kNuErrNone) + return Nu_GetAttr(pArchive, ident, pAttr); - return err; + return err; } const char* NuStrError(NuError err) { - return Nu_StrError(err); + return Nu_StrError(err); } NuError NuDebugDumpArchive(NuArchive* pArchive) { #if defined(DEBUG_MSGS) - /* skip validation checks for this one */ - Nu_DebugDumpAll(pArchive); - return kNuErrNone; + /* skip validation checks for this one */ + Nu_DebugDumpAll(pArchive); + return kNuErrNone; #else - /* function doesn't exist */ - return kNuErrGeneric; + /* function doesn't exist */ + return kNuErrGeneric; #endif } NuError NuGetVersion(long* pMajorVersion, long* pMinorVersion, long* pBugVersion, - const char** ppBuildDate, const char** ppBuildFlags) + const char** ppBuildDate, const char** ppBuildFlags) { - return Nu_GetVersion(pMajorVersion, pMinorVersion, pBugVersion, - ppBuildDate, ppBuildFlags); + return Nu_GetVersion(pMajorVersion, pMinorVersion, pBugVersion, + ppBuildDate, ppBuildFlags); } /* * =========================================================================== - * Sources and Sinks + * Sources and Sinks * =========================================================================== */ NuError NuCreateDataSourceForFile(NuThreadFormat threadFormat, short doClose, - unsigned long otherLen, const char* pathname, short isFromRsrcFork, - NuDataSource** ppDataSource) + unsigned long otherLen, const char* pathname, short isFromRsrcFork, + NuDataSource** ppDataSource) { - return Nu_DataSourceFile_New(threadFormat, (Boolean)(doClose != 0), - otherLen, pathname, (Boolean)(isFromRsrcFork != 0), ppDataSource); + return Nu_DataSourceFile_New(threadFormat, (Boolean)(doClose != 0), + otherLen, pathname, (Boolean)(isFromRsrcFork != 0), ppDataSource); } NuError NuCreateDataSourceForFP(NuThreadFormat threadFormat, short doClose, - unsigned long otherLen, FILE* fp, long offset, long length, - NuDataSource** ppDataSource) + unsigned long otherLen, FILE* fp, long offset, long length, + NuDataSource** ppDataSource) { - return Nu_DataSourceFP_New(threadFormat, (Boolean)(doClose != 0), - otherLen, fp, offset, length, ppDataSource); + return Nu_DataSourceFP_New(threadFormat, (Boolean)(doClose != 0), + otherLen, fp, offset, length, ppDataSource); } NuError NuCreateDataSourceForBuffer(NuThreadFormat threadFormat, short doClose, - unsigned long otherLen, const unsigned char* buffer, long offset, - long length, NuDataSource** ppDataSource) + unsigned long otherLen, const unsigned char* buffer, long offset, + long length, NuDataSource** ppDataSource) { - return Nu_DataSourceBuffer_New(threadFormat, (Boolean)(doClose != 0), - otherLen, buffer, offset, length, ppDataSource); + return Nu_DataSourceBuffer_New(threadFormat, (Boolean)(doClose != 0), + otherLen, buffer, offset, length, ppDataSource); } NuError NuFreeDataSource(NuDataSource* pDataSource) { - return Nu_DataSourceFree(pDataSource); + return Nu_DataSourceFree(pDataSource); } NuError NuDataSourceSetRawCrc(NuDataSource* pDataSource, unsigned short crc) { - if (pDataSource == nil) - return kNuErrInvalidArg; - Nu_DataSourceSetRawCrc(pDataSource, crc); - return kNuErrNone; + if (pDataSource == nil) + return kNuErrInvalidArg; + Nu_DataSourceSetRawCrc(pDataSource, crc); + return kNuErrNone; } NuError NuCreateDataSinkForFile(short doExpand, NuValue convertEOL, - const char* pathname, char fssep, NuDataSink** ppDataSink) + const char* pathname, char fssep, NuDataSink** ppDataSink) { - return Nu_DataSinkFile_New((Boolean)(doExpand != 0), convertEOL, pathname, - fssep, ppDataSink); + return Nu_DataSinkFile_New((Boolean)(doExpand != 0), convertEOL, pathname, + fssep, ppDataSink); } NuError NuCreateDataSinkForFP(short doExpand, NuValue convertEOL, FILE* fp, - NuDataSink** ppDataSink) + NuDataSink** ppDataSink) { - return Nu_DataSinkFP_New((Boolean)(doExpand != 0), convertEOL, fp, - ppDataSink); + return Nu_DataSinkFP_New((Boolean)(doExpand != 0), convertEOL, fp, + ppDataSink); } NuError NuCreateDataSinkForBuffer(short doExpand, NuValue convertEOL, - unsigned char* buffer, unsigned long bufLen, NuDataSink** ppDataSink) + unsigned char* buffer, unsigned long bufLen, NuDataSink** ppDataSink) { - return Nu_DataSinkBuffer_New((Boolean)(doExpand != 0), convertEOL, buffer, - bufLen, ppDataSink); + return Nu_DataSinkBuffer_New((Boolean)(doExpand != 0), convertEOL, buffer, + bufLen, ppDataSink); } NuError NuFreeDataSink(NuDataSink* pDataSink) { - return Nu_DataSinkFree(pDataSink); + return Nu_DataSinkFree(pDataSink); } NuError NuDataSinkGetOutCount(NuDataSink* pDataSink, ulong* pOutCount) { - if (pDataSink == nil || pOutCount == nil) - return kNuErrInvalidArg; + if (pDataSink == nil || pOutCount == nil) + return kNuErrInvalidArg; - *pOutCount = Nu_DataSinkGetOutCount(pDataSink); - return kNuErrNone; + *pOutCount = Nu_DataSinkGetOutCount(pDataSink); + return kNuErrNone; } /* * =========================================================================== - * Non-archive operations + * Non-archive operations * =========================================================================== */ void NuRecordCopyAttr(NuRecordAttr* pRecordAttr, const NuRecord* pRecord) { - pRecordAttr->fileSysID = pRecord->recFileSysID; - /*pRecordAttr->fileSysInfo = pRecord->recFileSysInfo;*/ - pRecordAttr->access = pRecord->recAccess; - pRecordAttr->fileType = pRecord->recFileType; - pRecordAttr->extraType = pRecord->recExtraType; - pRecordAttr->createWhen = pRecord->recCreateWhen; - pRecordAttr->modWhen = pRecord->recModWhen; - pRecordAttr->archiveWhen = pRecord->recArchiveWhen; + pRecordAttr->fileSysID = pRecord->recFileSysID; + /*pRecordAttr->fileSysInfo = pRecord->recFileSysInfo;*/ + pRecordAttr->access = pRecord->recAccess; + pRecordAttr->fileType = pRecord->recFileType; + pRecordAttr->extraType = pRecord->recExtraType; + pRecordAttr->createWhen = pRecord->recCreateWhen; + pRecordAttr->modWhen = pRecord->recModWhen; + pRecordAttr->archiveWhen = pRecord->recArchiveWhen; } NuError NuRecordCopyThreads(const NuRecord* pNuRecord, NuThread** ppThreads) { - if (pNuRecord == nil || ppThreads == nil) - return kNuErrInvalidArg; + if (pNuRecord == nil || ppThreads == nil) + return kNuErrInvalidArg; - Assert(pNuRecord->pThreads != nil); + Assert(pNuRecord->pThreads != nil); - *ppThreads = Nu_Malloc(nil, pNuRecord->recTotalThreads * sizeof(NuThread)); - if (*ppThreads == nil) - return kNuErrMalloc; + *ppThreads = Nu_Malloc(nil, pNuRecord->recTotalThreads * sizeof(NuThread)); + if (*ppThreads == nil) + return kNuErrMalloc; - memcpy(*ppThreads, pNuRecord->pThreads, - pNuRecord->recTotalThreads * sizeof(NuThread)); + memcpy(*ppThreads, pNuRecord->pThreads, + pNuRecord->recTotalThreads * sizeof(NuThread)); - return kNuErrNone; + return kNuErrNone; } unsigned long NuRecordGetNumThreads(const NuRecord* pNuRecord) { - if (pNuRecord == nil) - return -1; + if (pNuRecord == nil) + return -1; - return pNuRecord->recTotalThreads; + return pNuRecord->recTotalThreads; } const NuThread* NuThreadGetByIdx(const NuThread* pNuThread, long idx) { - if (pNuThread == nil) - return nil; - return &pNuThread[idx]; /* can't range-check here */ + if (pNuThread == nil) + return nil; + return &pNuThread[idx]; /* can't range-check here */ } short NuIsPresizedThreadID(NuThreadID threadID) { - return Nu_IsPresizedThreadID(threadID); + return Nu_IsPresizedThreadID(threadID); } /* * =========================================================================== - * Callback setters + * Callback setters * =========================================================================== */ NuError NuSetSelectionFilter(NuArchive* pArchive, NuCallback filterFunc) { - NuError err; + NuError err; - /*Assert(!((ulong)filterFunc % 4));*/ + /*Assert(!((ulong)filterFunc % 4));*/ - if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) - pArchive->selectionFilterFunc = filterFunc; + if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) + pArchive->selectionFilterFunc = filterFunc; - return err; + return err; } NuError NuSetOutputPathnameFilter(NuArchive* pArchive, NuCallback filterFunc) { - NuError err; + NuError err; - /*Assert(!((ulong)filterFunc % 4));*/ + /*Assert(!((ulong)filterFunc % 4));*/ - if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) - pArchive->outputPathnameFunc = filterFunc; + if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) + pArchive->outputPathnameFunc = filterFunc; - return err; + return err; } NuError NuSetProgressUpdater(NuArchive* pArchive, NuCallback updateFunc) { - NuError err; + NuError err; - /*Assert(!((ulong)updateFunc % 4));*/ + /*Assert(!((ulong)updateFunc % 4));*/ - if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) - pArchive->progressUpdaterFunc = updateFunc; + if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) + pArchive->progressUpdaterFunc = updateFunc; - return err; + return err; } NuError NuSetErrorHandler(NuArchive* pArchive, NuCallback errorFunc) { - NuError err; + NuError err; - /*Assert(!((ulong)errorFunc % 4));*/ + /*Assert(!((ulong)errorFunc % 4));*/ - if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) - pArchive->errorHandlerFunc = errorFunc; + if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) + pArchive->errorHandlerFunc = errorFunc; - return err; + return err; } NuError NuSetErrorMessageHandler(NuArchive* pArchive, NuCallback messageHandlerFunc) { - NuError err; + NuError err; - /*Assert(!((ulong)messageHandlerFunc % 4));*/ + /*Assert(!((ulong)messageHandlerFunc % 4));*/ - if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) - pArchive->messageHandlerFunc = messageHandlerFunc; + if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) + pArchive->messageHandlerFunc = messageHandlerFunc; - return err; + return err; } NuError NuSetGlobalErrorMessageHandler(NuCallback messageHandlerFunc) { - /*Assert(!((ulong)messageHandlerFunc % 4));*/ + /*Assert(!((ulong)messageHandlerFunc % 4));*/ - gNuGlobalErrorMessageHandler = messageHandlerFunc; - return kNuErrNone; + gNuGlobalErrorMessageHandler = messageHandlerFunc; + return kNuErrNone; } diff --git a/nufxlib-0/Expand.c b/nufxlib-0/Expand.c index d033b03..fdf570f 100644 --- a/nufxlib-0/Expand.c +++ b/nufxlib-0/Expand.c @@ -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; } diff --git a/nufxlib-0/FileIO.c b/nufxlib-0/FileIO.c index 86b9a2c..d7085ea 100644 --- a/nufxlib-0/FileIO.c +++ b/nufxlib-0/FileIO.c @@ -22,28 +22,28 @@ * For systems (e.g. Visual C++ 6.0) that don't have these standard values. */ #ifndef S_IRUSR -# define S_IRUSR 0400 -# define S_IWUSR 0200 -# define S_IXUSR 0100 -# define S_IRWXU (S_IRUSR|S_IWUSR|S_IXUSR) -# define S_IRGRP (S_IRUSR >> 3) -# define S_IWGRP (S_IWUSR >> 3) -# define S_IXGRP (S_IXUSR >> 3) -# define S_IRWXG (S_IRWXU >> 3) -# define S_IROTH (S_IRGRP >> 3) -# define S_IWOTH (S_IWGRP >> 3) -# define S_IXOTH (S_IXGRP >> 3) -# define S_IRWXO (S_IRWXG >> 3) +# define S_IRUSR 0400 +# define S_IWUSR 0200 +# define S_IXUSR 0100 +# define S_IRWXU (S_IRUSR|S_IWUSR|S_IXUSR) +# define S_IRGRP (S_IRUSR >> 3) +# define S_IWGRP (S_IWUSR >> 3) +# define S_IXGRP (S_IXUSR >> 3) +# define S_IRWXG (S_IRWXU >> 3) +# define S_IROTH (S_IRGRP >> 3) +# define S_IWOTH (S_IWGRP >> 3) +# define S_IXOTH (S_IXGRP >> 3) +# define S_IRWXO (S_IRWXG >> 3) #endif #ifndef S_ISREG -# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) -# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) #endif /* * =========================================================================== - * DateTime conversions + * DateTime conversions * =========================================================================== */ @@ -81,36 +81,36 @@ static void Nu_DateTimeToGMTSeconds(const NuDateTime* pDateTime, time_t* pWhen) { - struct tm tmbuf; - time_t when; + struct tm tmbuf; + time_t when; - Assert(pDateTime != nil); - Assert(pWhen != nil); + Assert(pDateTime != nil); + Assert(pWhen != nil); - tmbuf.tm_sec = pDateTime->second; - tmbuf.tm_min = pDateTime->minute; - tmbuf.tm_hour = pDateTime->hour; - tmbuf.tm_mday = pDateTime->day +1; - tmbuf.tm_mon = pDateTime->month; - tmbuf.tm_year = pDateTime->year; - if (pDateTime->year < 40) - tmbuf.tm_year += 100; /* P8 uses 0-39 for 2000-2039 */ - tmbuf.tm_wday = 0; - tmbuf.tm_yday = 0; - tmbuf.tm_isdst = -1; /* let it figure DST and time zone */ + tmbuf.tm_sec = pDateTime->second; + tmbuf.tm_min = pDateTime->minute; + tmbuf.tm_hour = pDateTime->hour; + tmbuf.tm_mday = pDateTime->day +1; + tmbuf.tm_mon = pDateTime->month; + tmbuf.tm_year = pDateTime->year; + if (pDateTime->year < 40) + tmbuf.tm_year += 100; /* P8 uses 0-39 for 2000-2039 */ + tmbuf.tm_wday = 0; + tmbuf.tm_yday = 0; + tmbuf.tm_isdst = -1; /* let it figure DST and time zone */ - #if defined(HAVE_MKTIME) - when = mktime(&tmbuf); - #elif defined(HAVE_TIMELOCAL) - when = timelocal(&tmbuf); - #else - # error "need time converter" - #endif + #if defined(HAVE_MKTIME) + when = mktime(&tmbuf); + #elif defined(HAVE_TIMELOCAL) + when = timelocal(&tmbuf); + #else + # error "need time converter" + #endif - if (when == (time_t) -1) - *pWhen = 0; - else - *pWhen = when; + if (when == (time_t) -1) + *pWhen = 0; + else + *pWhen = when; } /* @@ -119,26 +119,26 @@ Nu_DateTimeToGMTSeconds(const NuDateTime* pDateTime, time_t* pWhen) static void Nu_GMTSecondsToDateTime(const time_t* pWhen, NuDateTime *pDateTime) { - struct tm* ptm; + struct tm* ptm; - Assert(pWhen != nil); - Assert(pDateTime != nil); + Assert(pWhen != nil); + Assert(pDateTime != nil); - #if defined(HAVE_LOCALTIME_R) && defined(USE_REENTRANT_CALLS) - struct tm res; - ptm = localtime_r(pWhen, &res); - #else - /* NOTE: not thread-safe */ - ptm = localtime(pWhen); - #endif - pDateTime->second = ptm->tm_sec; - pDateTime->minute = ptm->tm_min; - pDateTime->hour = ptm->tm_hour; - pDateTime->day = ptm->tm_mday -1; - pDateTime->month = ptm->tm_mon; - pDateTime->year = ptm->tm_year; - pDateTime->extra = 0; - pDateTime->weekDay = ptm->tm_wday +1; + #if defined(HAVE_LOCALTIME_R) && defined(USE_REENTRANT_CALLS) + struct tm res; + ptm = localtime_r(pWhen, &res); + #else + /* NOTE: not thread-safe */ + ptm = localtime(pWhen); + #endif + pDateTime->second = ptm->tm_sec; + pDateTime->minute = ptm->tm_min; + pDateTime->hour = ptm->tm_hour; + pDateTime->day = ptm->tm_mday -1; + pDateTime->month = ptm->tm_mon; + pDateTime->year = ptm->tm_year; + pDateTime->extra = 0; + pDateTime->weekDay = ptm->tm_wday +1; } #endif @@ -149,15 +149,15 @@ Nu_GMTSecondsToDateTime(const time_t* pWhen, NuDateTime *pDateTime) void Nu_SetCurrentDateTime(NuDateTime* pDateTime) { - Assert(pDateTime != nil); + Assert(pDateTime != nil); #if defined(UNIX_LIKE) || defined(WINDOWS_LIKE) - { - time_t now = time(nil); - Nu_GMTSecondsToDateTime(&now, pDateTime); - } + { + time_t now = time(nil); + Nu_GMTSecondsToDateTime(&now, pDateTime); + } #else - #error "Port this" + #error "Port this" #endif } @@ -173,37 +173,37 @@ Nu_SetCurrentDateTime(NuDateTime* pDateTime) Boolean Nu_IsOlder(const NuDateTime* pWhen1, const NuDateTime* pWhen2) { - long result, year1, year2; + long result, year1, year2; - /* adjust for P8 ShrinkIt Y2K problem */ - year1 = pWhen1->year; - if (year1 < 40) - year1 += 100; - year2 = pWhen2->year; - if (year2 < 40) - year2 += 100; + /* adjust for P8 ShrinkIt Y2K problem */ + year1 = pWhen1->year; + if (year1 < 40) + year1 += 100; + year2 = pWhen2->year; + if (year2 < 40) + year2 += 100; - result = year1 - year2; - if (!result) - result = pWhen1->month - pWhen2->month; - if (!result) - result = pWhen1->day - pWhen2->day; - if (!result) - result = pWhen1->hour - pWhen2->hour; - if (!result) - result = pWhen1->minute - pWhen2->minute; - if (!result) - result = pWhen1->second - pWhen2->second; + result = year1 - year2; + if (!result) + result = pWhen1->month - pWhen2->month; + if (!result) + result = pWhen1->day - pWhen2->day; + if (!result) + result = pWhen1->hour - pWhen2->hour; + if (!result) + result = pWhen1->minute - pWhen2->minute; + if (!result) + result = pWhen1->second - pWhen2->second; - if (result < 0) - return true; - return false; + if (result < 0) + return true; + return false; } /* * =========================================================================== - * Get/set file info + * Get/set file info * =========================================================================== */ @@ -211,22 +211,22 @@ Nu_IsOlder(const NuDateTime* pWhen1, const NuDateTime* pWhen2) * System-independent (mostly) file info struct. */ typedef struct NuFileInfo { - Boolean isValid; /* init to "false", set "true" after we get data */ + Boolean isValid; /* init to "false", set "true" after we get data */ - Boolean isRegularFile; /* is this a regular file? */ - Boolean isDirectory; /* is this a directory? */ + Boolean isRegularFile; /* is this a regular file? */ + Boolean isDirectory; /* is this a directory? */ - ulong dataEof; - ulong rsrcEof; + ulong dataEof; + ulong rsrcEof; - ulong fileType; - ulong auxType; - NuDateTime modWhen; - mode_t unixMode; /* UNIX-style permissions */ + ulong fileType; + ulong auxType; + NuDateTime modWhen; + mode_t unixMode; /* UNIX-style permissions */ } NuFileInfo; -#define kDefaultFileType 0 /* "NON" */ -#define kDefaultAuxType 0 /* $0000 */ +#define kDefaultFileType 0 /* "NON" */ +#define kDefaultAuxType 0 /* $0000 */ /* @@ -235,28 +235,28 @@ typedef struct NuFileInfo { static Boolean Nu_IsForkedFile(NuArchive* pArchive, const NuRecord* pRecord) { - const NuThread* pThread; - NuThreadID threadID; - Boolean gotData, gotRsrc; - int i; + const NuThread* pThread; + NuThreadID threadID; + Boolean gotData, gotRsrc; + int i; - gotData = gotRsrc = false; + gotData = gotRsrc = false; - for (i = 0; i < (int)pRecord->recTotalThreads; i++) { - pThread = Nu_GetThread(pRecord, i); - Assert(pThread != nil); + for (i = 0; i < (int)pRecord->recTotalThreads; i++) { + pThread = Nu_GetThread(pRecord, i); + Assert(pThread != nil); - threadID = NuMakeThreadID(pThread->thThreadClass,pThread->thThreadKind); - if (threadID == kNuThreadIDDataFork) - gotData = true; - else if (threadID == kNuThreadIDRsrcFork) - gotRsrc = true; - } + threadID = NuMakeThreadID(pThread->thThreadClass,pThread->thThreadKind); + if (threadID == kNuThreadIDDataFork) + gotData = true; + else if (threadID == kNuThreadIDRsrcFork) + gotRsrc = true; + } - if (gotData && gotRsrc) - return true; - else - return false; + if (gotData && gotRsrc) + return true; + else + return false; } @@ -266,51 +266,51 @@ Nu_IsForkedFile(NuArchive* pArchive, const NuRecord* pRecord) */ static NuError Nu_GetFileInfo(NuArchive* pArchive, const char* pathname, - NuFileInfo* pFileInfo) + NuFileInfo* pFileInfo) { - NuError err = kNuErrNone; - Assert(pArchive != nil); - Assert(pathname != nil); - Assert(pFileInfo != nil); + NuError err = kNuErrNone; + Assert(pArchive != nil); + Assert(pathname != nil); + Assert(pFileInfo != nil); - pFileInfo->isValid = false; + pFileInfo->isValid = false; #if defined(UNIX_LIKE) || defined(WINDOWS_LIKE) - { - struct stat sbuf; - int cc; + { + struct stat sbuf; + int cc; - cc = stat(pathname, &sbuf); - if (cc) { - if (errno == ENOENT) - err = kNuErrFileNotFound; - else - err = kNuErrFileStat; - goto bail; - } + cc = stat(pathname, &sbuf); + if (cc) { + if (errno == ENOENT) + err = kNuErrFileNotFound; + else + err = kNuErrFileStat; + goto bail; + } - pFileInfo->isRegularFile = false; - if (S_ISREG(sbuf.st_mode)) - pFileInfo->isRegularFile = true; - pFileInfo->isDirectory = false; - if (S_ISDIR(sbuf.st_mode)) - pFileInfo->isDirectory = true; + pFileInfo->isRegularFile = false; + if (S_ISREG(sbuf.st_mode)) + pFileInfo->isRegularFile = true; + pFileInfo->isDirectory = false; + if (S_ISDIR(sbuf.st_mode)) + pFileInfo->isDirectory = true; - /* BUG: should check for 32-bit overflow from 64-bit off_t */ - pFileInfo->dataEof = sbuf.st_size; - pFileInfo->rsrcEof = 0; - pFileInfo->fileType = kDefaultFileType; - pFileInfo->auxType = kDefaultAuxType; - Nu_GMTSecondsToDateTime(&sbuf.st_mtime, &pFileInfo->modWhen); - pFileInfo->unixMode = sbuf.st_mode; - pFileInfo->isValid = true; - } + /* BUG: should check for 32-bit overflow from 64-bit off_t */ + pFileInfo->dataEof = sbuf.st_size; + pFileInfo->rsrcEof = 0; + pFileInfo->fileType = kDefaultFileType; + pFileInfo->auxType = kDefaultAuxType; + Nu_GMTSecondsToDateTime(&sbuf.st_mtime, &pFileInfo->modWhen); + pFileInfo->unixMode = sbuf.st_mode; + pFileInfo->isValid = true; + } #else - #error "Port this" + #error "Port this" #endif bail: - return err; + return err; } @@ -324,55 +324,55 @@ bail: */ static NuError Nu_FileForkExists(NuArchive* pArchive, const char* pathname, - Boolean isForkedFile, Boolean checkRsrcFork, Boolean* pExists, - NuFileInfo* pFileInfo) + Boolean isForkedFile, Boolean checkRsrcFork, Boolean* pExists, + NuFileInfo* pFileInfo) { - NuError err = kNuErrNone; + NuError err = kNuErrNone; - Assert(pArchive != nil); - Assert(pathname != nil); - Assert(checkRsrcFork == true || checkRsrcFork == false); - Assert(pExists != nil); - Assert(pFileInfo != nil); + Assert(pArchive != nil); + Assert(pathname != nil); + Assert(checkRsrcFork == true || checkRsrcFork == false); + Assert(pExists != nil); + Assert(pFileInfo != nil); #if defined(UNIX_LIKE) || defined(WINDOWS_LIKE) - /* - * We ignore "isForkedFile" and "checkRsrcFork". The file must not - * exist at all. - */ - Assert(pArchive->lastFileCreated == nil); + /* + * We ignore "isForkedFile" and "checkRsrcFork". The file must not + * exist at all. + */ + Assert(pArchive->lastFileCreated == nil); - *pExists = true; - err = Nu_GetFileInfo(pArchive, pathname, pFileInfo); - if (err == kNuErrFileNotFound) { - err = kNuErrNone; - *pExists = false; - } + *pExists = true; + err = Nu_GetFileInfo(pArchive, pathname, pFileInfo); + if (err == kNuErrFileNotFound) { + err = kNuErrNone; + *pExists = false; + } #elif defined(__ORCAC__) - /* - * If the file doesn't exist, great. If it does, and "lastFileCreated" - * matches up with this one, then we know that it exists because we - * created it. - * - * This is great unless the record has two data forks or something - * equally dopey, so we check to be sure that the fork we want to - * put the data into is currently empty. - * - * It is possible, though asinine, for a Mac OS or GS/OS extraction - * program to put the data and resource forks of a record into - * separate files, so we can't just assume that because we wrote - * the data fork to file A it is okay for file B to exist. That's - * why we compare the pathname instead of just remembering that - * we already created a file for this record. - */ - #error "Finish me" + /* + * If the file doesn't exist, great. If it does, and "lastFileCreated" + * matches up with this one, then we know that it exists because we + * created it. + * + * This is great unless the record has two data forks or something + * equally dopey, so we check to be sure that the fork we want to + * put the data into is currently empty. + * + * It is possible, though asinine, for a Mac OS or GS/OS extraction + * program to put the data and resource forks of a record into + * separate files, so we can't just assume that because we wrote + * the data fork to file A it is okay for file B to exist. That's + * why we compare the pathname instead of just remembering that + * we already created a file for this record. + */ + #error "Finish me" #else - #error "Port this" + #error "Port this" #endif - return err; + return err; } @@ -381,53 +381,53 @@ Nu_FileForkExists(NuArchive* pArchive, const char* pathname, */ static NuError Nu_SetFileDates(NuArchive* pArchive, const NuRecord* pRecord, - const char* pathname) + const char* pathname) { - NuError err = kNuErrNone; + NuError err = kNuErrNone; - Assert(pArchive != nil); - Assert(pRecord != nil); - Assert(pathname != nil); + Assert(pArchive != nil); + Assert(pRecord != nil); + Assert(pathname != nil); #if defined(UNIX_LIKE) || defined(WINDOWS_LIKE) - { - struct utimbuf utbuf; + { + struct utimbuf utbuf; - /* ignore create time, and set access time equal to mod time */ - Nu_DateTimeToGMTSeconds(&pRecord->recModWhen, &utbuf.modtime); - utbuf.actime = utbuf.modtime; + /* ignore create time, and set access time equal to mod time */ + Nu_DateTimeToGMTSeconds(&pRecord->recModWhen, &utbuf.modtime); + utbuf.actime = utbuf.modtime; - /* only do it if the NuDateTime was valid */ - if (utbuf.modtime) { - if (utime(pathname, &utbuf) < 0) { - Nu_ReportError(NU_BLOB, errno, - "Unable to set time stamp on '%s'", pathname); - err = kNuErrFileSetDate; - goto bail; - } - } - } + /* only do it if the NuDateTime was valid */ + if (utbuf.modtime) { + if (utime(pathname, &utbuf) < 0) { + Nu_ReportError(NU_BLOB, errno, + "Unable to set time stamp on '%s'", pathname); + err = kNuErrFileSetDate; + goto bail; + } + } + } #else - #error "Port this" + #error "Port this" #endif bail: - return err; + return err; } /* * Returns "true" if the record is locked (in the ProDOS sense). * - * Bits 31-8 reserved, must be zero - * Bit 7 (D) 1 = destroy enabled - * Bit 6 (R) 1 = rename enabled - * Bit 5 (B) 1 = file needs to be backed up - * Bits 4-3 reserved, must be zero - * Bit 2 (I) 1 = file is invisible - * Bit 1 (W) 1 = write enabled - * Bit 0 (R) 1 = read enabled + * Bits 31-8 reserved, must be zero + * Bit 7 (D) 1 = destroy enabled + * Bit 6 (R) 1 = rename enabled + * Bit 5 (B) 1 = file needs to be backed up + * Bits 4-3 reserved, must be zero + * Bit 2 (I) 1 = file is invisible + * Bit 1 (W) 1 = write enabled + * Bit 0 (R) 1 = read enabled * * A "locked" file would be 00?00001, "unlocked" 11?00011, with many * possible variations. For our purposes, we treat all files as unlocked @@ -436,10 +436,10 @@ bail: static Boolean Nu_IsRecordLocked(const NuRecord* pRecord) { - if (pRecord->recAccess == 0x21L || pRecord->recAccess == 0x01L) - return true; - else - return false; + if (pRecord->recAccess == 0x21L || pRecord->recAccess == 0x01L) + return true; + else + return false; } /* @@ -450,38 +450,38 @@ Nu_IsRecordLocked(const NuRecord* pRecord) */ static NuError Nu_SetFileAccess(NuArchive* pArchive, const NuRecord* pRecord, - const char* pathname) + const char* pathname) { - NuError err = kNuErrNone; + NuError err = kNuErrNone; - Assert(pArchive != nil); - Assert(pRecord != nil); - Assert(pathname != nil); + Assert(pArchive != nil); + Assert(pRecord != nil); + Assert(pathname != nil); #if defined(UNIX_LIKE) || defined(WINDOWS_LIKE) - /* only need to do something if the file was "locked" */ - if (Nu_IsRecordLocked(pRecord)) { - /* set it to 444 */ - if (chmod(pathname, S_IRUSR | S_IRGRP | S_IROTH) < 0) { - Nu_ReportError(NU_BLOB, errno, - "unable to set access for '%s'", pathname); - err = kNuErrFileSetAccess; - goto bail; - } - } + /* only need to do something if the file was "locked" */ + if (Nu_IsRecordLocked(pRecord)) { + /* set it to 444 */ + if (chmod(pathname, S_IRUSR | S_IRGRP | S_IROTH) < 0) { + Nu_ReportError(NU_BLOB, errno, + "unable to set access for '%s'", pathname); + err = kNuErrFileSetAccess; + goto bail; + } + } #else - #error "Port this" + #error "Port this" #endif bail: - return err; + return err; } /* * =========================================================================== - * Create/open an output file + * Create/open an output file * =========================================================================== */ @@ -493,40 +493,40 @@ bail: */ static NuError Nu_PrepareForWriting(NuArchive* pArchive, const char* pathname, - Boolean prepRsrc, NuFileInfo* pFileInfo) + Boolean prepRsrc, NuFileInfo* pFileInfo) { - NuError err = kNuErrNone; + NuError err = kNuErrNone; - Assert(pArchive != nil); - Assert(pathname != nil); - Assert(prepRsrc == true || prepRsrc == false); - Assert(pFileInfo != nil); + Assert(pArchive != nil); + Assert(pathname != nil); + Assert(prepRsrc == true || prepRsrc == false); + Assert(pFileInfo != nil); - Assert(pFileInfo->isValid == true); + Assert(pFileInfo->isValid == true); - /* don't go playing with directories, pipes, etc */ - if (pFileInfo->isRegularFile != true) - return kNuErrNotRegularFile; + /* don't go playing with directories, pipes, etc */ + if (pFileInfo->isRegularFile != true) + return kNuErrNotRegularFile; #if defined(UNIX_LIKE) || defined(WINDOWS_LIKE) - if (!(pFileInfo->unixMode & S_IWUSR)) { - /* make it writable by owner, plus whatever it was before */ - if (chmod(pathname, S_IWUSR | pFileInfo->unixMode) < 0) { - Nu_ReportError(NU_BLOB, errno, - "unable to set access for '%s'", pathname); - err = kNuErrFileSetAccess; - goto bail; - } - } + if (!(pFileInfo->unixMode & S_IWUSR)) { + /* make it writable by owner, plus whatever it was before */ + if (chmod(pathname, S_IWUSR | pFileInfo->unixMode) < 0) { + Nu_ReportError(NU_BLOB, errno, + "unable to set access for '%s'", pathname); + err = kNuErrFileSetAccess; + goto bail; + } + } - return kNuErrNone; + return kNuErrNone; #else - #error "Port this" + #error "Port this" #endif bail: - return err; + return err; } @@ -536,31 +536,31 @@ bail: static NuError Nu_Mkdir(NuArchive* pArchive, const char* dir) { - NuError err = kNuErrNone; + NuError err = kNuErrNone; - Assert(pArchive != nil); - Assert(dir != nil); + Assert(pArchive != nil); + Assert(dir != nil); #if defined(UNIX_LIKE) - if (mkdir(dir, S_IRWXU | S_IRGRP|S_IXGRP | S_IROTH|S_IXOTH) < 0) { - err = errno ? errno : kNuErrDirCreate; - Nu_ReportError(NU_BLOB, err, "Unable to create dir '%s'", dir); - goto bail; - } + if (mkdir(dir, S_IRWXU | S_IRGRP|S_IXGRP | S_IROTH|S_IXOTH) < 0) { + err = errno ? errno : kNuErrDirCreate; + Nu_ReportError(NU_BLOB, err, "Unable to create dir '%s'", dir); + goto bail; + } #elif defined(WINDOWS_LIKE) - if (mkdir(dir) < 0) { - err = errno ? errno : kNuErrDirCreate; - Nu_ReportError(NU_BLOB, err, "Unable to create dir '%s'", dir); - goto bail; - } + if (mkdir(dir) < 0) { + err = errno ? errno : kNuErrDirCreate; + Nu_ReportError(NU_BLOB, err, "Unable to create dir '%s'", dir); + goto bail; + } #else - #error "Port this" + #error "Port this" #endif bail: - return err; + return err; } @@ -571,50 +571,50 @@ bail: */ static NuError Nu_CreateSubdirIFN(NuArchive* pArchive, const char* pathStart, - const char* pathEnd, char fssep) + const char* pathEnd, char fssep) { - NuError err = kNuErrNone; - NuFileInfo fileInfo; - char* tmpBuf = nil; + NuError err = kNuErrNone; + NuFileInfo fileInfo; + char* tmpBuf = nil; - Assert(pArchive != nil); - Assert(pathStart != nil); - Assert(pathEnd != nil); - Assert(fssep != '\0'); + Assert(pArchive != nil); + Assert(pathStart != nil); + Assert(pathEnd != nil); + Assert(fssep != '\0'); - /* pathStart might have whole path, but we only want up to "pathEnd" */ - tmpBuf = strdup(pathStart); - tmpBuf[pathEnd - pathStart +1] = '\0'; + /* pathStart might have whole path, but we only want up to "pathEnd" */ + tmpBuf = strdup(pathStart); + tmpBuf[pathEnd - pathStart +1] = '\0'; - err = Nu_GetFileInfo(pArchive, tmpBuf, &fileInfo); - if (err == kNuErrFileNotFound) { - /* dir doesn't exist; move up a level and check parent */ - pathEnd = strrchr(tmpBuf, fssep); - if (pathEnd != nil) { - pathEnd--; - Assert(pathEnd >= tmpBuf); - err = Nu_CreateSubdirIFN(pArchive, tmpBuf, pathEnd, fssep); - BailError(err); - } + err = Nu_GetFileInfo(pArchive, tmpBuf, &fileInfo); + if (err == kNuErrFileNotFound) { + /* dir doesn't exist; move up a level and check parent */ + pathEnd = strrchr(tmpBuf, fssep); + if (pathEnd != nil) { + pathEnd--; + Assert(pathEnd >= tmpBuf); + err = Nu_CreateSubdirIFN(pArchive, tmpBuf, pathEnd, fssep); + BailError(err); + } - /* parent is taken care of; create this one */ - err = Nu_Mkdir(pArchive, tmpBuf); - BailError(err); - } else if (err != kNuErrNone) { - goto bail; - } else { - /* file does exist, make sure it's a directory */ - Assert(fileInfo.isValid == true); - if (!fileInfo.isDirectory) { - err = kNuErrNotDir; - Nu_ReportError(NU_BLOB, err, "Unable to create path '%s'", tmpBuf); - goto bail; - } - } + /* parent is taken care of; create this one */ + err = Nu_Mkdir(pArchive, tmpBuf); + BailError(err); + } else if (err != kNuErrNone) { + goto bail; + } else { + /* file does exist, make sure it's a directory */ + Assert(fileInfo.isValid == true); + if (!fileInfo.isDirectory) { + err = kNuErrNotDir; + Nu_ReportError(NU_BLOB, err, "Unable to create path '%s'", tmpBuf); + goto bail; + } + } bail: - Nu_Free(pArchive, tmpBuf); - return err; + Nu_Free(pArchive, tmpBuf); + return err; } /* @@ -627,48 +627,48 @@ bail: static NuError Nu_CreatePathIFN(NuArchive* pArchive, const char* pathname, char fssep) { - NuError err = kNuErrNone; - const char* pathStart; - const char* pathEnd; + NuError err = kNuErrNone; + const char* pathStart; + const char* pathEnd; - Assert(pArchive != nil); - Assert(pathname != nil); - Assert(fssep != '\0'); + Assert(pArchive != nil); + Assert(pathname != nil); + Assert(fssep != '\0'); - pathStart = pathname; - if (pathname[0] == fssep) - pathStart++; + pathStart = pathname; + if (pathname[0] == fssep) + pathStart++; - /* NOTE: not expecting names like "foo/bar/ack/", with terminating fssep */ - pathEnd = strrchr(pathStart, fssep); - if (pathEnd == nil) { - /* no subdirectory components found */ - goto bail; - } - pathEnd--; + /* NOTE: not expecting names like "foo/bar/ack/", with terminating fssep */ + pathEnd = strrchr(pathStart, fssep); + if (pathEnd == nil) { + /* no subdirectory components found */ + goto bail; + } + pathEnd--; - Assert(pathEnd >= pathStart); - if (pathEnd - pathStart < 0) - goto bail; + Assert(pathEnd >= pathStart); + if (pathEnd - pathStart < 0) + goto bail; - /* (on some filesystems, strncasecmp would be appropriate here) */ - if (pArchive->lastDirCreated && - strncmp(pathStart, pArchive->lastDirCreated, pathEnd - pathStart +1) == 0) - { - /* we created this one recently, don't do it again */ - goto bail; - } + /* (on some filesystems, strncasecmp would be appropriate here) */ + if (pArchive->lastDirCreated && + strncmp(pathStart, pArchive->lastDirCreated, pathEnd - pathStart +1) == 0) + { + /* we created this one recently, don't do it again */ + goto bail; + } - /* - * Test to determine which directories exist. The most likely case - * is that some or all of the components have already been created, - * so we start with the last one and work backward. - */ - err = Nu_CreateSubdirIFN(pArchive, pathStart, pathEnd, fssep); - BailError(err); + /* + * Test to determine which directories exist. The most likely case + * is that some or all of the components have already been created, + * so we start with the last one and work backward. + */ + err = Nu_CreateSubdirIFN(pArchive, pathStart, pathEnd, fssep); + BailError(err); bail: - return err; + return err; } @@ -677,12 +677,12 @@ bail: */ static NuError Nu_OpenFileForWrite(NuArchive* pArchive, const char* pathname, - Boolean openRsrc, FILE** pFp) + Boolean openRsrc, FILE** pFp) { - *pFp = fopen(pathname, kNuFileOpenWriteTrunc); - if (*pFp == nil) - return errno ? errno : -1; - return kNuErrNone; + *pFp = fopen(pathname, kNuFileOpenWriteTrunc); + if (*pFp == nil) + return errno ? errno : -1; + return kNuErrNone; } @@ -697,231 +697,231 @@ Nu_OpenFileForWrite(NuArchive* pArchive, const char* pathname, */ NuError Nu_OpenOutputFile(NuArchive* pArchive, const NuRecord* pRecord, - const NuThread* pThread, const char* newPathname, char newFssep, - FILE** pFp) + const NuThread* pThread, const char* newPathname, char newFssep, + FILE** pFp) { - NuError err = kNuErrNone; - Boolean exists, isForkedFile, extractingRsrc = false; - NuFileInfo fileInfo; - NuErrorStatus errorStatus; - NuResult result; + NuError err = kNuErrNone; + Boolean exists, isForkedFile, extractingRsrc = false; + NuFileInfo fileInfo; + NuErrorStatus errorStatus; + NuResult result; - Assert(pArchive != nil); - Assert(pRecord != nil); - Assert(pThread != nil); - Assert(newPathname != nil); - Assert(pFp != nil); + Assert(pArchive != nil); + Assert(pRecord != nil); + Assert(pThread != nil); + Assert(newPathname != nil); + Assert(pFp != nil); - /* set up some defaults, in case something goes wrong */ - errorStatus.operation = kNuOpExtract; - errorStatus.err = kNuErrInternal; - errorStatus.sysErr = 0; - errorStatus.message = nil; - errorStatus.pRecord = pRecord; - errorStatus.pathname = newPathname; - errorStatus.filenameSeparator = newFssep; - /*errorStatus.origArchiveTouched = false;*/ - errorStatus.canAbort = true; - errorStatus.canRetry = true; - errorStatus.canIgnore = false; - errorStatus.canSkip = true; - errorStatus.canRename = true; - errorStatus.canOverwrite = true; + /* set up some defaults, in case something goes wrong */ + errorStatus.operation = kNuOpExtract; + errorStatus.err = kNuErrInternal; + errorStatus.sysErr = 0; + errorStatus.message = nil; + errorStatus.pRecord = pRecord; + errorStatus.pathname = newPathname; + errorStatus.filenameSeparator = newFssep; + /*errorStatus.origArchiveTouched = false;*/ + errorStatus.canAbort = true; + errorStatus.canRetry = true; + errorStatus.canIgnore = false; + errorStatus.canSkip = true; + errorStatus.canRename = true; + errorStatus.canOverwrite = true; - /* decide if this is a forked file (i.e. has *both* forks) */ - isForkedFile = Nu_IsForkedFile(pArchive, pRecord); + /* decide if this is a forked file (i.e. has *both* forks) */ + isForkedFile = Nu_IsForkedFile(pArchive, pRecord); - /* decide if we're extracting a resource fork */ - if (NuMakeThreadID(pThread->thThreadClass, pThread->thThreadKind) == - kNuThreadIDRsrcFork) - { - extractingRsrc = true; - } + /* decide if we're extracting a resource fork */ + if (NuMakeThreadID(pThread->thThreadClass, pThread->thThreadKind) == + kNuThreadIDRsrcFork) + { + extractingRsrc = true; + } - /* - * Determine whether the file and fork already exists. If the file - * is one we just created, and the fork we want to write to is - * empty, this will *not* set "exists". - */ - fileInfo.isValid = false; - err = Nu_FileForkExists(pArchive, newPathname, isForkedFile, - extractingRsrc, &exists, &fileInfo); - BailError(err); + /* + * Determine whether the file and fork already exists. If the file + * is one we just created, and the fork we want to write to is + * empty, this will *not* set "exists". + */ + fileInfo.isValid = false; + err = Nu_FileForkExists(pArchive, newPathname, isForkedFile, + extractingRsrc, &exists, &fileInfo); + BailError(err); - if (exists) { - Assert(fileInfo.isValid == true); + if (exists) { + Assert(fileInfo.isValid == true); - /* - * The file exists when it shouldn't. Decide what to do, based - * on the options configured by the application. - */ - - /* - * Start by checking to see if we're willing to overwrite older files. - * If not, see if the application wants to rename the file, or force - * the overwrite. Most likely they'll just want to skip it. - */ - if ((pArchive->valOnlyUpdateOlder) && - !Nu_IsOlder(&fileInfo.modWhen, &pRecord->recModWhen)) - { - if (pArchive->errorHandlerFunc != nil) { - errorStatus.err = kNuErrNotNewer; - result = (*pArchive->errorHandlerFunc)(pArchive, &errorStatus); + /* + * The file exists when it shouldn't. Decide what to do, based + * on the options configured by the application. + */ + + /* + * Start by checking to see if we're willing to overwrite older files. + * If not, see if the application wants to rename the file, or force + * the overwrite. Most likely they'll just want to skip it. + */ + if ((pArchive->valOnlyUpdateOlder) && + !Nu_IsOlder(&fileInfo.modWhen, &pRecord->recModWhen)) + { + if (pArchive->errorHandlerFunc != nil) { + errorStatus.err = kNuErrNotNewer; + result = (*pArchive->errorHandlerFunc)(pArchive, &errorStatus); - switch (result) { - case kNuAbort: - err = kNuErrAborted; - goto bail; - case kNuRetry: - case kNuRename: - err = kNuErrRename; - goto bail; - case kNuSkip: - err = kNuErrSkipped; - goto bail; - case kNuOverwrite: - break; /* fall back into main code */ - case kNuIgnore: - default: - err = kNuErrSyntax; - Nu_ReportError(NU_BLOB, err, - "Wasn't expecting result %d here", result); - goto bail; - } - } else { - err = kNuErrNotNewer; - goto bail; - } - } + switch (result) { + case kNuAbort: + err = kNuErrAborted; + goto bail; + case kNuRetry: + case kNuRename: + err = kNuErrRename; + goto bail; + case kNuSkip: + err = kNuErrSkipped; + goto bail; + case kNuOverwrite: + break; /* fall back into main code */ + case kNuIgnore: + default: + err = kNuErrSyntax; + Nu_ReportError(NU_BLOB, err, + "Wasn't expecting result %d here", result); + goto bail; + } + } else { + err = kNuErrNotNewer; + goto bail; + } + } - /* If they "might" allow overwrites, and they have an error-handling - * callback defined, call that to find out what they want to do - * here. Options include skipping the file, overwriting the file, - * and extracting to a different file. - */ - if (pArchive->valHandleExisting == kNuMaybeOverwrite) { - if (pArchive->errorHandlerFunc != nil) { - errorStatus.err = kNuErrFileExists; - result = (*pArchive->errorHandlerFunc)(pArchive, &errorStatus); + /* If they "might" allow overwrites, and they have an error-handling + * callback defined, call that to find out what they want to do + * here. Options include skipping the file, overwriting the file, + * and extracting to a different file. + */ + if (pArchive->valHandleExisting == kNuMaybeOverwrite) { + if (pArchive->errorHandlerFunc != nil) { + errorStatus.err = kNuErrFileExists; + result = (*pArchive->errorHandlerFunc)(pArchive, &errorStatus); - switch (result) { - case kNuAbort: - err = kNuErrAborted; - goto bail; - case kNuRetry: - case kNuRename: - err = kNuErrRename; - goto bail; - case kNuSkip: - err = kNuErrSkipped; - goto bail; - case kNuOverwrite: - break; /* fall back into main code */ - case kNuIgnore: - default: - err = kNuErrSyntax; - Nu_ReportError(NU_BLOB, err, - "Wasn't expecting result %d here", result); - goto bail; - } - } else { - /* no error handler, return an error to the caller */ - err = kNuErrFileExists; - goto bail; - } - } else if (pArchive->valHandleExisting == kNuNeverOverwrite) { - err = kNuErrSkipped; - goto bail; - } - } else { - /* - * The file doesn't exist. If we're doing a "freshen" from the - * archive, we don't want to create a new file, so we return an - * error to the user instead. However, we give the application - * a chance to straighten things out. Most likely they'll just - * return kNuSkip. - */ - if (pArchive->valHandleExisting == kNuMustOverwrite) { - DBUG(("+++ can't freshen nonexistent file '%s'\n", newPathname)); - if (pArchive->errorHandlerFunc != nil) { - errorStatus.err = kNuErrDuplicateNotFound; + switch (result) { + case kNuAbort: + err = kNuErrAborted; + goto bail; + case kNuRetry: + case kNuRename: + err = kNuErrRename; + goto bail; + case kNuSkip: + err = kNuErrSkipped; + goto bail; + case kNuOverwrite: + break; /* fall back into main code */ + case kNuIgnore: + default: + err = kNuErrSyntax; + Nu_ReportError(NU_BLOB, err, + "Wasn't expecting result %d here", result); + goto bail; + } + } else { + /* no error handler, return an error to the caller */ + err = kNuErrFileExists; + goto bail; + } + } else if (pArchive->valHandleExisting == kNuNeverOverwrite) { + err = kNuErrSkipped; + goto bail; + } + } else { + /* + * The file doesn't exist. If we're doing a "freshen" from the + * archive, we don't want to create a new file, so we return an + * error to the user instead. However, we give the application + * a chance to straighten things out. Most likely they'll just + * return kNuSkip. + */ + if (pArchive->valHandleExisting == kNuMustOverwrite) { + DBUG(("+++ can't freshen nonexistent file '%s'\n", newPathname)); + if (pArchive->errorHandlerFunc != nil) { + errorStatus.err = kNuErrDuplicateNotFound; - /* give them a chance to rename */ - result = (*pArchive->errorHandlerFunc)(pArchive, &errorStatus); - switch (result) { - case kNuAbort: - err = kNuErrAborted; - goto bail; - case kNuRetry: - case kNuRename: - err = kNuErrRename; - goto bail; - case kNuSkip: - err = kNuErrSkipped; - goto bail; - case kNuOverwrite: - break; /* fall back into main code */ - case kNuIgnore: - default: - err = kNuErrSyntax; - Nu_ReportError(NU_BLOB, err, - "Wasn't expecting result %d here", result); - goto bail; - } - } else { - /* no error handler, return an error to the caller */ - err = kNuErrDuplicateNotFound; - goto bail; - } - } - } + /* give them a chance to rename */ + result = (*pArchive->errorHandlerFunc)(pArchive, &errorStatus); + switch (result) { + case kNuAbort: + err = kNuErrAborted; + goto bail; + case kNuRetry: + case kNuRename: + err = kNuErrRename; + goto bail; + case kNuSkip: + err = kNuErrSkipped; + goto bail; + case kNuOverwrite: + break; /* fall back into main code */ + case kNuIgnore: + default: + err = kNuErrSyntax; + Nu_ReportError(NU_BLOB, err, + "Wasn't expecting result %d here", result); + goto bail; + } + } else { + /* no error handler, return an error to the caller */ + err = kNuErrDuplicateNotFound; + goto bail; + } + } + } - Assert(err == kNuErrNone); + Assert(err == kNuErrNone); - /* - * After the above, if the file exists then we need to prepare it for - * writing. On some systems -- notably those with forked files -- it - * may be easiest to delete the entire file and start over. On - * simpler systems, an (optional) chmod followed by an open that - * truncates the file should be sufficient. - * - * If the file didn't exist, we need to be sure that the path leading - * up to its eventual location exists. This might require creating - * several directories. We distinguish the case of "file isn't there" - * from "file is there but fork isn't" by seeing if we were able to - * get valid file info. - */ - if (exists) { - Assert(fileInfo.isValid == true); - err = Nu_PrepareForWriting(pArchive, newPathname, extractingRsrc, - &fileInfo); - BailError(err); - } else if (!fileInfo.isValid) { - err = Nu_CreatePathIFN(pArchive, newPathname, newFssep); - BailError(err); - } + /* + * After the above, if the file exists then we need to prepare it for + * writing. On some systems -- notably those with forked files -- it + * may be easiest to delete the entire file and start over. On + * simpler systems, an (optional) chmod followed by an open that + * truncates the file should be sufficient. + * + * If the file didn't exist, we need to be sure that the path leading + * up to its eventual location exists. This might require creating + * several directories. We distinguish the case of "file isn't there" + * from "file is there but fork isn't" by seeing if we were able to + * get valid file info. + */ + if (exists) { + Assert(fileInfo.isValid == true); + err = Nu_PrepareForWriting(pArchive, newPathname, extractingRsrc, + &fileInfo); + BailError(err); + } else if (!fileInfo.isValid) { + err = Nu_CreatePathIFN(pArchive, newPathname, newFssep); + BailError(err); + } - /* - * Open sesame. - */ - err = Nu_OpenFileForWrite(pArchive, newPathname, extractingRsrc, pFp); - BailError(err); + /* + * Open sesame. + */ + err = Nu_OpenFileForWrite(pArchive, newPathname, extractingRsrc, pFp); + BailError(err); #if defined(HAS_RESOURCE_FORKS) - pArchive->lastFileCreated = newPathname; + pArchive->lastFileCreated = newPathname; #endif bail: - if (err != kNuErrNone) { - if (err != kNuErrSkipped && err != kNuErrRename && - err != kNuErrFileExists) - { - Nu_ReportError(NU_BLOB, err, "Unable to open '%s'%s", - newPathname, extractingRsrc ? " (rsrc fork)" : ""); - } - } - return err; + if (err != kNuErrNone) { + if (err != kNuErrSkipped && err != kNuErrRename && + err != kNuErrFileExists) + { + Nu_ReportError(NU_BLOB, err, "Unable to open '%s'%s", + newPathname, extractingRsrc ? " (rsrc fork)" : ""); + } + } + return err; } @@ -944,29 +944,29 @@ bail: */ NuError Nu_CloseOutputFile(NuArchive* pArchive, const NuRecord* pRecord, FILE* fp, - const char* pathname) + const char* pathname) { - NuError err; + NuError err; - Assert(pArchive != nil); - Assert(pRecord != nil); - Assert(fp != nil); + Assert(pArchive != nil); + Assert(pRecord != nil); + Assert(fp != nil); - fclose(fp); + fclose(fp); - err = Nu_SetFileDates(pArchive, pRecord, pathname); - BailError(err); + err = Nu_SetFileDates(pArchive, pRecord, pathname); + BailError(err); - err = Nu_SetFileAccess(pArchive, pRecord, pathname); - BailError(err); + err = Nu_SetFileAccess(pArchive, pRecord, pathname); + BailError(err); bail: - return kNuErrNone; + return kNuErrNone; } /* * =========================================================================== - * Open an input file + * Open an input file * =========================================================================== */ @@ -975,12 +975,12 @@ bail: */ static NuError Nu_OpenFileForRead(NuArchive* pArchive, const char* pathname, - Boolean openRsrc, FILE** pFp) + Boolean openRsrc, FILE** pFp) { - *pFp = fopen(pathname, kNuFileOpenReadOnly); - if (*pFp == nil) - return errno ? errno : -1; - return kNuErrNone; + *pFp = fopen(pathname, kNuFileOpenReadOnly); + if (*pFp == nil) + return errno ? errno : -1; + return kNuErrNone; } @@ -992,87 +992,87 @@ Nu_OpenFileForRead(NuArchive* pArchive, const char* pathname, */ NuError Nu_OpenInputFile(NuArchive* pArchive, const char* pathname, - Boolean openRsrc, FILE** pFp) + Boolean openRsrc, FILE** pFp) { - NuError err = kNuErrNone; - NuError openErr = kNuErrNone; - NuErrorStatus errorStatus; - NuResult result; + NuError err = kNuErrNone; + NuError openErr = kNuErrNone; + NuErrorStatus errorStatus; + NuResult result; - Assert(pArchive != nil); - Assert(pathname != nil); - Assert(pFp != nil); + Assert(pArchive != nil); + Assert(pathname != nil); + Assert(pFp != nil); retry: - /* - * Open sesame. - */ - err = Nu_OpenFileForRead(pArchive, pathname, openRsrc, pFp); - if (err == kNuErrNone) /* success! */ - goto bail; + /* + * Open sesame. + */ + err = Nu_OpenFileForRead(pArchive, pathname, openRsrc, pFp); + if (err == kNuErrNone) /* success! */ + goto bail; - if (err == ENOENT) - openErr = kNuErrFileNotFound; + if (err == ENOENT) + openErr = kNuErrFileNotFound; - if (pArchive->errorHandlerFunc != nil) { - errorStatus.operation = kNuOpAdd; - errorStatus.err = openErr; - errorStatus.sysErr = 0; - errorStatus.message = nil; - errorStatus.pRecord = nil; - errorStatus.pathname = pathname; - errorStatus.filenameSeparator = '\0'; - /*errorStatus.origArchiveTouched = false;*/ - errorStatus.canAbort = true; - errorStatus.canRetry = true; - errorStatus.canIgnore = false; - errorStatus.canSkip = true; - errorStatus.canRename = false; - errorStatus.canOverwrite = false; + if (pArchive->errorHandlerFunc != nil) { + errorStatus.operation = kNuOpAdd; + errorStatus.err = openErr; + errorStatus.sysErr = 0; + errorStatus.message = nil; + errorStatus.pRecord = nil; + errorStatus.pathname = pathname; + errorStatus.filenameSeparator = '\0'; + /*errorStatus.origArchiveTouched = false;*/ + errorStatus.canAbort = true; + errorStatus.canRetry = true; + errorStatus.canIgnore = false; + errorStatus.canSkip = true; + errorStatus.canRename = false; + errorStatus.canOverwrite = false; - DBUG(("--- invoking error handler function\n")); - result = (*pArchive->errorHandlerFunc)(pArchive, &errorStatus); + DBUG(("--- invoking error handler function\n")); + result = (*pArchive->errorHandlerFunc)(pArchive, &errorStatus); - switch (result) { - case kNuAbort: - err = kNuErrAborted; - goto bail; - case kNuRetry: - goto retry; - case kNuSkip: - err = kNuErrSkipped; - goto bail; - case kNuRename: - case kNuOverwrite: - case kNuIgnore: - default: - err = kNuErrSyntax; - Nu_ReportError(NU_BLOB, err, - "Wasn't expecting result %d here", result); - goto bail; - } - } else { - DBUG(("+++ no error callback in OpenInputFile\n")); - } + switch (result) { + case kNuAbort: + err = kNuErrAborted; + goto bail; + case kNuRetry: + goto retry; + case kNuSkip: + err = kNuErrSkipped; + goto bail; + case kNuRename: + case kNuOverwrite: + case kNuIgnore: + default: + err = kNuErrSyntax; + Nu_ReportError(NU_BLOB, err, + "Wasn't expecting result %d here", result); + goto bail; + } + } else { + DBUG(("+++ no error callback in OpenInputFile\n")); + } bail: - if (err == kNuErrNone) { - Assert(*pFp != nil); - } else { - if (err != kNuErrSkipped && err != kNuErrRename && - err != kNuErrFileExists) - { - Nu_ReportError(NU_BLOB, err, "Unable to open '%s'%s", - pathname, openRsrc ? " (rsrc fork)" : ""); - } - } - return err; + if (err == kNuErrNone) { + Assert(*pFp != nil); + } else { + if (err != kNuErrSkipped && err != kNuErrRename && + err != kNuErrFileExists) + { + Nu_ReportError(NU_BLOB, err, "Unable to open '%s'%s", + pathname, openRsrc ? " (rsrc fork)" : ""); + } + } + return err; } /* * =========================================================================== - * Delete and rename files + * Delete and rename files * =========================================================================== */ @@ -1083,17 +1083,17 @@ NuError Nu_DeleteFile(const char* pathname) { #if defined(UNIX_LIKE) || defined(WINDOWS_LIKE) - int cc; + int cc; - DBUG(("--- Deleting '%s'\n", pathname)); + DBUG(("--- Deleting '%s'\n", pathname)); - cc = unlink(pathname); - if (cc < 0) - return errno ? errno : -1; - else - return kNuErrNone; + cc = unlink(pathname); + if (cc < 0) + return errno ? errno : -1; + else + return kNuErrNone; #else - #error "Port this" + #error "Port this" #endif } @@ -1104,24 +1104,24 @@ NuError Nu_RenameFile(const char* fromPath, const char* toPath) { #if defined(UNIX_LIKE) || defined(WINDOWS_LIKE) - int cc; + int cc; - DBUG(("--- Renaming '%s' to '%s'\n", fromPath, toPath)); + DBUG(("--- Renaming '%s' to '%s'\n", fromPath, toPath)); - cc = rename(fromPath, toPath); - if (cc < 0) - return errno ? errno : -1; - else - return kNuErrNone; + cc = rename(fromPath, toPath); + if (cc < 0) + return errno ? errno : -1; + else + return kNuErrNone; #else - #error "Port this" + #error "Port this" #endif } /* * =========================================================================== - * NuError wrappers for std functions + * NuError wrappers for std functions * =========================================================================== */ @@ -1131,16 +1131,16 @@ Nu_RenameFile(const char* fromPath, const char* toPath) NuError Nu_FTell(FILE* fp, long* pOffset) { - Assert(fp != nil); - Assert(pOffset != nil); + Assert(fp != nil); + Assert(pOffset != nil); - errno = 0; - *pOffset = ftell(fp); - if (*pOffset < 0) { - Nu_ReportError(NU_NILBLOB, errno, "file ftell failed"); - return errno ? errno : kNuErrFileSeek; - } - return kNuErrNone; + errno = 0; + *pOffset = ftell(fp); + if (*pOffset < 0) { + Nu_ReportError(NU_NILBLOB, errno, "file ftell failed"); + return errno ? errno : kNuErrFileSeek; + } + return kNuErrNone; } /* @@ -1149,16 +1149,16 @@ Nu_FTell(FILE* fp, long* pOffset) NuError Nu_FSeek(FILE* fp, long offset, int ptrname) { - Assert(fp != nil); - Assert(ptrname == SEEK_SET || ptrname == SEEK_CUR || ptrname == SEEK_END); + Assert(fp != nil); + Assert(ptrname == SEEK_SET || ptrname == SEEK_CUR || ptrname == SEEK_END); - errno = 0; - if (fseek(fp, offset, ptrname) < 0) { - Nu_ReportError(NU_NILBLOB, errno, - "file fseek(%ld, %d) failed", offset, ptrname); - return errno ? errno : kNuErrFileSeek; - } - return kNuErrNone; + errno = 0; + if (fseek(fp, offset, ptrname) < 0) { + Nu_ReportError(NU_NILBLOB, errno, + "file fseek(%ld, %d) failed", offset, ptrname); + return errno ? errno : kNuErrFileSeek; + } + return kNuErrNone; } /* @@ -1168,13 +1168,13 @@ Nu_FSeek(FILE* fp, long offset, int ptrname) NuError Nu_FRead(FILE* fp, void* buf, size_t nbyte) { - size_t result; + size_t result; - errno = 0; - result = fread(buf, nbyte, 1, fp); - if (result != 1) - return errno ? errno : kNuErrFileRead; - return kNuErrNone; + errno = 0; + result = fread(buf, nbyte, 1, fp); + if (result != 1) + return errno ? errno : kNuErrFileRead; + return kNuErrNone; } /* @@ -1184,18 +1184,18 @@ Nu_FRead(FILE* fp, void* buf, size_t nbyte) NuError Nu_FWrite(FILE* fp, const void* buf, size_t nbyte) { - size_t result; + size_t result; - errno = 0; - result = fwrite(buf, nbyte, 1, fp); - if (result != 1) - return errno ? errno : kNuErrFileWrite; - return kNuErrNone; + errno = 0; + result = fwrite(buf, nbyte, 1, fp); + if (result != 1) + return errno ? errno : kNuErrFileWrite; + return kNuErrNone; } /* * =========================================================================== - * Misc functions + * Misc functions * =========================================================================== */ @@ -1205,33 +1205,33 @@ Nu_FWrite(FILE* fp, const void* buf, size_t nbyte) NuError Nu_CopyFileSection(NuArchive* pArchive, FILE* dstFp, FILE* srcFp, long length) { - NuError err; - long readLen; + NuError err; + long readLen; - Assert(pArchive != nil); - Assert(dstFp != nil); - Assert(srcFp != nil); - Assert(length); + Assert(pArchive != nil); + Assert(dstFp != nil); + Assert(srcFp != nil); + Assert(length); - /* nice big buffer, for speed... could use getc/putc for simplicity */ - err = Nu_AllocCompressionBufferIFN(pArchive); - BailError(err); + /* nice big buffer, for speed... could use getc/putc for simplicity */ + err = Nu_AllocCompressionBufferIFN(pArchive); + BailError(err); - DBUG(("+++ Copying %ld bytes\n", length)); + DBUG(("+++ Copying %ld bytes\n", length)); - while (length) { - readLen = length > kNuGenCompBufSize ? kNuGenCompBufSize : length; + while (length) { + readLen = length > kNuGenCompBufSize ? kNuGenCompBufSize : length; - err = Nu_FRead(srcFp, pArchive->compBuf, readLen); - BailError(err); - err = Nu_FWrite(dstFp, pArchive->compBuf, readLen); - BailError(err); + err = Nu_FRead(srcFp, pArchive->compBuf, readLen); + BailError(err); + err = Nu_FWrite(dstFp, pArchive->compBuf, readLen); + BailError(err); - length -= readLen; - } + length -= readLen; + } bail: - return err; + return err; } @@ -1248,26 +1248,26 @@ bail: NuError Nu_GetFileLength(NuArchive* pArchive, FILE* fp, long* pLength) { - NuError err; - long oldpos; + NuError err; + long oldpos; - Assert(fp != nil); - Assert(pLength != nil); + Assert(fp != nil); + Assert(pLength != nil); - err = Nu_FTell(fp, &oldpos); - BailError(err); + err = Nu_FTell(fp, &oldpos); + BailError(err); - err = Nu_FSeek(fp, 0, SEEK_END); - BailError(err); + err = Nu_FSeek(fp, 0, SEEK_END); + BailError(err); - err = Nu_FTell(fp, pLength); - BailError(err); + err = Nu_FTell(fp, pLength); + BailError(err); - err = Nu_FSeek(fp, oldpos, SEEK_SET); - BailError(err); + err = Nu_FSeek(fp, oldpos, SEEK_SET); + BailError(err); bail: - return err; + return err; } @@ -1278,16 +1278,16 @@ bail: NuError Nu_TruncateOpenFile(FILE* fp, long length) { - #if defined(HAVE_FTRUNCATE) - if (ftruncate(fileno(fp), length) < 0) - return errno ? errno : -1; - return kNuErrNone; - #elif defined(HAVE_CHSIZE) - if (chsize(fileno(fp), length) < 0) - return errno ? errno : -1; - return kNuErrNone; - #else - return kNuErrInternal; - #endif + #if defined(HAVE_FTRUNCATE) + if (ftruncate(fileno(fp), length) < 0) + return errno ? errno : -1; + return kNuErrNone; + #elif defined(HAVE_CHSIZE) + if (chsize(fileno(fp), length) < 0) + return errno ? errno : -1; + return kNuErrNone; + #else + return kNuErrInternal; + #endif } diff --git a/nufxlib-0/Funnel.c b/nufxlib-0/Funnel.c index 0b498b2..35b4c6b 100644 --- a/nufxlib-0/Funnel.c +++ b/nufxlib-0/Funnel.c @@ -11,7 +11,7 @@ /* * =========================================================================== - * Progress updater + * Progress updater * =========================================================================== */ @@ -24,39 +24,39 @@ */ NuError Nu_ProgressDataInit_Compress(NuArchive* pArchive, NuProgressData* pProgressData, - const NuRecord* pRecord, const char* origPathname) + const NuRecord* pRecord, const char* origPathname) { - const char* cp; + const char* cp; - Assert(pProgressData != nil); - Assert(pArchive != nil); - Assert(pRecord != nil); - Assert(origPathname != nil); + Assert(pProgressData != nil); + Assert(pArchive != nil); + Assert(pRecord != nil); + Assert(origPathname != nil); - pProgressData->pRecord = pRecord; + pProgressData->pRecord = pRecord; - pProgressData->origPathname = origPathname; - pProgressData->pathname = pRecord->filename; - cp = strrchr(pRecord->filename, - NuGetSepFromSysInfo(pRecord->recFileSysInfo)); - if (cp == nil || *(cp+1) == '\0') - pProgressData->filename = pProgressData->pathname; - else - pProgressData->filename = cp+1; + pProgressData->origPathname = origPathname; + pProgressData->pathname = pRecord->filename; + cp = strrchr(pRecord->filename, + NuGetSepFromSysInfo(pRecord->recFileSysInfo)); + if (cp == nil || *(cp+1) == '\0') + pProgressData->filename = pProgressData->pathname; + else + pProgressData->filename = cp+1; - pProgressData->operation = kNuOpAdd; - pProgressData->state = kNuProgressPreparing; - /*pProgressData->compressedLength = 0;*/ - /*pProgressData->compressedProgress = 0;*/ - pProgressData->uncompressedLength = 0; - pProgressData->uncompressedProgress = 0; + pProgressData->operation = kNuOpAdd; + pProgressData->state = kNuProgressPreparing; + /*pProgressData->compressedLength = 0;*/ + /*pProgressData->compressedProgress = 0;*/ + pProgressData->uncompressedLength = 0; + pProgressData->uncompressedProgress = 0; - pProgressData->compress.threadFormat = (NuThreadFormat)-1; + pProgressData->compress.threadFormat = (NuThreadFormat)-1; - /* ya know... if this is nil, none of the above matters much */ - pProgressData->progressFunc = pArchive->progressUpdaterFunc; + /* ya know... if this is nil, none of the above matters much */ + pProgressData->progressFunc = pArchive->progressUpdaterFunc; - return kNuErrNone; + return kNuErrNone; } @@ -69,57 +69,57 @@ Nu_ProgressDataInit_Compress(NuArchive* pArchive, NuProgressData* pProgressData, */ NuError Nu_ProgressDataInit_Expand(NuArchive* pArchive, NuProgressData* pProgressData, - const NuRecord* pRecord, const char* newPathname, char newFssep, - NuValue convertEOL) + const NuRecord* pRecord, const char* newPathname, char newFssep, + NuValue convertEOL) { - const NuThread* pThreadIter; - const char* cp; - int i; + const NuThread* pThreadIter; + const char* cp; + int i; - Assert(pProgressData != nil); - Assert(pArchive != nil); - Assert(pRecord != nil); - Assert(newPathname != nil); - Assert(newFssep != 0); + Assert(pProgressData != nil); + Assert(pArchive != nil); + Assert(pRecord != nil); + Assert(newPathname != nil); + Assert(newFssep != 0); - pProgressData->pRecord = pRecord; - pProgressData->expand.pThread = nil; + pProgressData->pRecord = pRecord; + pProgressData->expand.pThread = nil; - pProgressData->origPathname = pRecord->filename; - pProgressData->pathname = newPathname; - cp = strrchr(newPathname, newFssep); - if (cp == nil || *(cp+1) == '\0') - pProgressData->filename = newPathname; - else - pProgressData->filename = cp+1; + pProgressData->origPathname = pRecord->filename; + pProgressData->pathname = newPathname; + cp = strrchr(newPathname, newFssep); + if (cp == nil || *(cp+1) == '\0') + pProgressData->filename = newPathname; + else + pProgressData->filename = cp+1; - pProgressData->expand.convertEOL = convertEOL; + pProgressData->expand.convertEOL = convertEOL; - /* total up the data threads */ - pProgressData->expand.totalCompressedLength = 0; - pProgressData->expand.totalUncompressedLength = 0; + /* total up the data threads */ + pProgressData->expand.totalCompressedLength = 0; + pProgressData->expand.totalUncompressedLength = 0; - for (i = 0; i < (int)pRecord->recTotalThreads; i++) { - pThreadIter = Nu_GetThread(pRecord, i); - if (pThreadIter->thThreadClass != kNuThreadClassData) - continue; - pProgressData->expand.totalCompressedLength += pThreadIter->thCompThreadEOF; - pProgressData->expand.totalUncompressedLength += pThreadIter->actualThreadEOF; - } + for (i = 0; i < (int)pRecord->recTotalThreads; i++) { + pThreadIter = Nu_GetThread(pRecord, i); + if (pThreadIter->thThreadClass != kNuThreadClassData) + continue; + pProgressData->expand.totalCompressedLength += pThreadIter->thCompThreadEOF; + pProgressData->expand.totalUncompressedLength += pThreadIter->actualThreadEOF; + } - pProgressData->operation = kNuOpExtract; - if (pArchive->testMode) - pProgressData->operation = kNuOpTest; - pProgressData->state = kNuProgressPreparing; - /*pProgressData->expand.compressedLength = 0;*/ - /*pProgressData->expand.compressedProgress = 0;*/ - pProgressData->uncompressedLength = 0; - pProgressData->uncompressedProgress = 0; + pProgressData->operation = kNuOpExtract; + if (pArchive->testMode) + pProgressData->operation = kNuOpTest; + pProgressData->state = kNuProgressPreparing; + /*pProgressData->expand.compressedLength = 0;*/ + /*pProgressData->expand.compressedProgress = 0;*/ + pProgressData->uncompressedLength = 0; + pProgressData->uncompressedProgress = 0; - /* ya know... if this is nil, none of the above matters much */ - pProgressData->progressFunc = pArchive->progressUpdaterFunc; + /* ya know... if this is nil, none of the above matters much */ + pProgressData->progressFunc = pArchive->progressUpdaterFunc; - return kNuErrNone; + return kNuErrNone; } @@ -128,22 +128,22 @@ Nu_ProgressDataInit_Expand(NuArchive* pArchive, NuProgressData* pProgressData, */ NuError Nu_ProgressDataCompressPrep(NuArchive* pArchive, NuStraw* pStraw, - NuThreadFormat threadFormat, ulong sourceLen) + NuThreadFormat threadFormat, ulong sourceLen) { - NuProgressData* pProgressData; + NuProgressData* pProgressData; - Assert(pArchive != nil); - Assert(pStraw != nil); - Assert(sourceLen < 32767*65536); + Assert(pArchive != nil); + Assert(pStraw != nil); + Assert(sourceLen < 32767*65536); - pProgressData = pStraw->pProgress; - if (pProgressData == nil) - return kNuErrNone; + pProgressData = pStraw->pProgress; + if (pProgressData == nil) + return kNuErrNone; - pProgressData->uncompressedLength = sourceLen; - pProgressData->compress.threadFormat = threadFormat; + pProgressData->uncompressedLength = sourceLen; + pProgressData->compress.threadFormat = threadFormat; - return kNuErrNone; + return kNuErrNone; } /* @@ -153,23 +153,23 @@ Nu_ProgressDataCompressPrep(NuArchive* pArchive, NuStraw* pStraw, */ NuError Nu_ProgressDataExpandPrep(NuArchive* pArchive, NuFunnel* pFunnel, - const NuThread* pThread) + const NuThread* pThread) { - NuProgressData* pProgressData; + NuProgressData* pProgressData; - Assert(pArchive != nil); - Assert(pFunnel != nil); - Assert(pThread != nil); + Assert(pArchive != nil); + Assert(pFunnel != nil); + Assert(pThread != nil); - pProgressData = pFunnel->pProgress; - if (pProgressData == nil) - return kNuErrNone; + pProgressData = pFunnel->pProgress; + if (pProgressData == nil) + return kNuErrNone; - /*pProgressData->compressedLength = pThread->thCompThreadEOF;*/ - pProgressData->uncompressedLength = pThread->actualThreadEOF; - pProgressData->expand.pThread = pThread; + /*pProgressData->compressedLength = pThread->thCompThreadEOF;*/ + pProgressData->uncompressedLength = pThread->actualThreadEOF; + pProgressData->expand.pThread = pThread; - return kNuErrNone; + return kNuErrNone; } /* @@ -179,28 +179,28 @@ Nu_ProgressDataExpandPrep(NuArchive* pArchive, NuFunnel* pFunnel, NuError Nu_SendInitialProgress(NuArchive* pArchive, const NuProgressData* pProgress) { - NuResult result; + NuResult result; - Assert(pArchive != nil); - Assert(pProgress != nil); + Assert(pArchive != nil); + Assert(pProgress != nil); - if (pProgress->progressFunc == nil) - return kNuErrNone; + if (pProgress->progressFunc == nil) + return kNuErrNone; - result = (*pProgress->progressFunc)(pArchive, (NuProgressData*) pProgress); + result = (*pProgress->progressFunc)(pArchive, (NuProgressData*) pProgress); - if (result == kNuSkip) - return kNuErrSkipped; /* [dunno how well this works] */ - if (result == kNuAbort) - return kNuErrAborted; + if (result == kNuSkip) + return kNuErrSkipped; /* [dunno how well this works] */ + if (result == kNuAbort) + return kNuErrAborted; - return kNuErrNone; + return kNuErrNone; } /* * =========================================================================== - * NuFunnel object + * NuFunnel object * =========================================================================== */ @@ -209,33 +209,33 @@ Nu_SendInitialProgress(NuArchive* pArchive, const NuProgressData* pProgress) */ NuError Nu_FunnelNew(NuArchive* pArchive, NuDataSink* pDataSink, NuValue convertEOL, - NuValue convertEOLTo, NuProgressData* pProgress, NuFunnel** ppFunnel) + NuValue convertEOLTo, NuProgressData* pProgress, NuFunnel** ppFunnel) { - NuError err = kNuErrNone; - NuFunnel* pFunnel = nil; + NuError err = kNuErrNone; + NuFunnel* pFunnel = nil; - Assert(ppFunnel != nil); - Assert(pDataSink != nil); - Assert(convertEOL == kNuConvertOff || - convertEOL == kNuConvertOn || - convertEOL == kNuConvertAuto); + Assert(ppFunnel != nil); + Assert(pDataSink != nil); + Assert(convertEOL == kNuConvertOff || + convertEOL == kNuConvertOn || + convertEOL == kNuConvertAuto); - pFunnel = Nu_Calloc(pArchive, sizeof(*pFunnel)); - BailAlloc(pFunnel); - pFunnel->buffer = Nu_Malloc(pArchive, kNuFunnelBufSize); - BailAlloc(pFunnel->buffer); + pFunnel = Nu_Calloc(pArchive, sizeof(*pFunnel)); + BailAlloc(pFunnel); + pFunnel->buffer = Nu_Malloc(pArchive, kNuFunnelBufSize); + BailAlloc(pFunnel->buffer); - pFunnel->pDataSink = pDataSink; - pFunnel->convertEOL = convertEOL; - pFunnel->convertEOLTo = convertEOLTo; - pFunnel->pProgress = pProgress; + pFunnel->pDataSink = pDataSink; + pFunnel->convertEOL = convertEOL; + pFunnel->convertEOLTo = convertEOLTo; + pFunnel->pProgress = pProgress; bail: - if (err != kNuErrNone) - Nu_FunnelFree(pArchive, pFunnel); - else - *ppFunnel = pFunnel; - return err; + if (err != kNuErrNone) + Nu_FunnelFree(pArchive, pFunnel); + else + *ppFunnel = pFunnel; + return err; } @@ -248,19 +248,19 @@ bail: NuError Nu_FunnelFree(NuArchive* pArchive, NuFunnel* pFunnel) { - if (pFunnel == nil) - return kNuErrNone; + if (pFunnel == nil) + return kNuErrNone; #ifdef DEBUG_MSGS - if (pFunnel->bufCount) - Nu_ReportError(NU_BLOB_DEBUG, kNuErrNone, - "freeing non-empty funnel"); + if (pFunnel->bufCount) + Nu_ReportError(NU_BLOB_DEBUG, kNuErrNone, + "freeing non-empty funnel"); #endif - Nu_Free(pArchive, pFunnel->buffer); - Nu_Free(pArchive, pFunnel); + Nu_Free(pArchive, pFunnel->buffer); + Nu_Free(pArchive, pFunnel); - return kNuErrNone; + return kNuErrNone; } @@ -274,14 +274,14 @@ Nu_FunnelFree(NuArchive* pArchive, NuFunnel* pFunnel) void Nu_FunnelSetMaxOutput(NuFunnel* pFunnel, ulong maxBytes) { - Assert(pFunnel != nil); - Assert(maxBytes > 0); + Assert(pFunnel != nil); + Assert(maxBytes > 0); - pFunnel->outMax = maxBytes; - if (pFunnel->outCount >= pFunnel->outMax) - pFunnel->outMaxExceeded = true; - else - pFunnel->outMaxExceeded = false; + pFunnel->outMax = maxBytes; + if (pFunnel->outCount >= pFunnel->outMax) + pFunnel->outMaxExceeded = true; + else + pFunnel->outMaxExceeded = false; } #endif @@ -302,26 +302,26 @@ Nu_FunnelSetMaxOutput(NuFunnel* pFunnel, ulong maxBytes) * much point in tweaking it to death. */ static const char gNuIsBinary[256] = { - 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, /* ^@-^O */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^P-^_ */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* - / */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0 - ? */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ - O */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* P - _ */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ` - o */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /* p - DEL */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x80 */ - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x90 */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xa0 */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xb0 */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xc0 */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xd0 */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xe0 */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xf0 */ + 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, /* ^@-^O */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* ^P-^_ */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* - / */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0 - ? */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ - O */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* P - _ */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ` - o */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /* p - DEL */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x80 */ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x90 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xa0 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xb0 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xc0 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xd0 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xe0 */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xf0 */ }; -#define kNuMaxHighASCII 1 /* max #of binary chars per 100 bytes */ -#define kNuMinConvThreshold 40 /* min of 40 chars for auto-detect */ +#define kNuMaxHighASCII 1 /* max #of binary chars per 100 bytes */ +#define kNuMinConvThreshold 40 /* min of 40 chars for auto-detect */ /* * Decide, based on the contents of the buffer, whether we should do an * EOL conversion on the data. @@ -337,52 +337,52 @@ static const char gNuIsBinary[256] = { static NuValue Nu_DetermineConversion(NuFunnel* pFunnel, const uchar* buffer, ulong count) { - ulong bufCount, numBinary, numLF, numCR; - uchar val; + ulong bufCount, numBinary, numLF, numCR; + uchar val; - if (count < kNuMinConvThreshold) - return kNuConvertOff; + if (count < kNuMinConvThreshold) + return kNuConvertOff; - bufCount = count; - numBinary = numLF = numCR = 0; - while (bufCount--) { - val = *buffer++; - if (gNuIsBinary[val]) - numBinary++; - if (val == kNuCharLF) - numLF++; - if (val == kNuCharCR) - numCR++; - } + bufCount = count; + numBinary = numLF = numCR = 0; + while (bufCount--) { + val = *buffer++; + if (gNuIsBinary[val]) + numBinary++; + if (val == kNuCharLF) + numLF++; + if (val == kNuCharCR) + numCR++; + } - /* if #found is > #allowed, it's a binary file */ - if (count < 100) { - /* use simplified check on files between kNuMinConvThreshold and 100 */ - if (numBinary > kNuMaxHighASCII) - return kNuConvertOff; - } else if (numBinary > (count / 100) * kNuMaxHighASCII) - return kNuConvertOff; + /* if #found is > #allowed, it's a binary file */ + if (count < 100) { + /* use simplified check on files between kNuMinConvThreshold and 100 */ + if (numBinary > kNuMaxHighASCII) + return kNuConvertOff; + } else if (numBinary > (count / 100) * kNuMaxHighASCII) + return kNuConvertOff; - /* - * If our "convert to" setting is the same as what we're converting - * from, we can turn off the converter and speed things up. - * - * These are simplistic, but this is intended as an optimization. We - * will blow it if the input has lots of CRs and LFs scattered about, - * and they just happen to be in equal amounts, but it's not clear - * to me that an automatic EOL conversion makes sense on that sort - * of file anyway. - */ - if (numLF && !numCR) - pFunnel->convertEOLFrom = kNuEOLLF; - else if (!numLF && numCR) - pFunnel->convertEOLFrom = kNuEOLCR; - else if (numLF && numLF == numCR) - pFunnel->convertEOLFrom = kNuEOLCRLF; - else - pFunnel->convertEOLFrom = kNuEOLUnknown; + /* + * If our "convert to" setting is the same as what we're converting + * from, we can turn off the converter and speed things up. + * + * These are simplistic, but this is intended as an optimization. We + * will blow it if the input has lots of CRs and LFs scattered about, + * and they just happen to be in equal amounts, but it's not clear + * to me that an automatic EOL conversion makes sense on that sort + * of file anyway. + */ + if (numLF && !numCR) + pFunnel->convertEOLFrom = kNuEOLLF; + else if (!numLF && numCR) + pFunnel->convertEOLFrom = kNuEOLCR; + else if (numLF && numLF == numCR) + pFunnel->convertEOLFrom = kNuEOLCRLF; + else + pFunnel->convertEOLFrom = kNuEOLUnknown; - return kNuConvertOn; + return kNuConvertOn; } @@ -396,24 +396,24 @@ Nu_DetermineConversion(NuFunnel* pFunnel, const uchar* buffer, ulong count) static inline void Nu_FunnelPutBlock(NuFunnel* pFunnel, const uchar* buf, ulong len) { - Assert(pFunnel != nil); - Assert(pFunnel->pDataSink != nil); - Assert(buf != nil); - Assert(len > 0); + Assert(pFunnel != nil); + Assert(pFunnel->pDataSink != nil); + Assert(buf != nil); + Assert(len > 0); #if 0 - if (pFunnel->outMax) { - if (pFunnel->outMaxExceeded) - return; - if (pFunnel->outCount + len > pFunnel->outMax) { - pFunnel->outMaxExceeded = true; - return; - } - } - pFunnel->outCount += len; + if (pFunnel->outMax) { + if (pFunnel->outMaxExceeded) + return; + if (pFunnel->outCount + len > pFunnel->outMax) { + pFunnel->outMaxExceeded = true; + return; + } + } + pFunnel->outCount += len; #endif - Nu_DataSinkPutBlock(pFunnel->pDataSink, buf, len); + Nu_DataSinkPutBlock(pFunnel->pDataSink, buf, len); } @@ -423,22 +423,22 @@ Nu_FunnelPutBlock(NuFunnel* pFunnel, const uchar* buf, ulong len) static inline void Nu_PutEOL(NuFunnel* pFunnel) { - uchar ch; + uchar ch; - if (pFunnel->convertEOLTo == kNuEOLCR) { - ch = kNuCharCR; - Nu_FunnelPutBlock(pFunnel, &ch, 1); - } else if (pFunnel->convertEOLTo == kNuEOLLF) { - ch = kNuCharLF; - Nu_FunnelPutBlock(pFunnel, &ch, 1); - } else if (pFunnel->convertEOLTo == kNuEOLCRLF) { - ch = kNuCharCR; - Nu_FunnelPutBlock(pFunnel, &ch, 1); - ch = kNuCharLF; - Nu_FunnelPutBlock(pFunnel, &ch, 1); - } else { - Assert(0); - } + if (pFunnel->convertEOLTo == kNuEOLCR) { + ch = kNuCharCR; + Nu_FunnelPutBlock(pFunnel, &ch, 1); + } else if (pFunnel->convertEOLTo == kNuEOLLF) { + ch = kNuCharLF; + Nu_FunnelPutBlock(pFunnel, &ch, 1); + } else if (pFunnel->convertEOLTo == kNuEOLCRLF) { + ch = kNuCharCR; + Nu_FunnelPutBlock(pFunnel, &ch, 1); + ch = kNuCharLF; + Nu_FunnelPutBlock(pFunnel, &ch, 1); + } else { + Assert(0); + } } /* @@ -452,72 +452,72 @@ Nu_PutEOL(NuFunnel* pFunnel) static NuError Nu_FunnelWriteConvert(NuFunnel* pFunnel, const uchar* buffer, ulong count) { - NuError err = kNuErrNone; - ulong progressCount = count; + NuError err = kNuErrNone; + ulong progressCount = count; - /*if (pFunnel->outMaxExceeded) - return kNuErrOutMax;*/ + /*if (pFunnel->outMaxExceeded) + return kNuErrOutMax;*/ - if (pFunnel->convertEOL == kNuConvertAuto) { - /* - * This is the first write/flush we've done on this Funnel. - * Check the data we have buffered to decide whether or not - * we want to convert this. - */ - pFunnel->convertEOL = Nu_DetermineConversion(pFunnel, buffer, count); - DBUG(("+++ DetermineConversion --> %ld / %ld\n", pFunnel->convertEOL, - pFunnel->convertEOLFrom)); + if (pFunnel->convertEOL == kNuConvertAuto) { + /* + * This is the first write/flush we've done on this Funnel. + * Check the data we have buffered to decide whether or not + * we want to convert this. + */ + pFunnel->convertEOL = Nu_DetermineConversion(pFunnel, buffer, count); + DBUG(("+++ DetermineConversion --> %ld / %ld\n", pFunnel->convertEOL, + pFunnel->convertEOLFrom)); - if (pFunnel->convertEOLFrom == pFunnel->convertEOLTo) { - DBUG(("+++ Switching redundant converter off\n")); - pFunnel->convertEOL = kNuConvertOff; - } - /* put it where the progress meter can see it */ - if (pFunnel->pProgress != nil) - pFunnel->pProgress->expand.convertEOL = pFunnel->convertEOL; - } + if (pFunnel->convertEOLFrom == pFunnel->convertEOLTo) { + DBUG(("+++ Switching redundant converter off\n")); + pFunnel->convertEOL = kNuConvertOff; + } + /* put it where the progress meter can see it */ + if (pFunnel->pProgress != nil) + pFunnel->pProgress->expand.convertEOL = pFunnel->convertEOL; + } - if (pFunnel->convertEOL == kNuConvertOff) { - /* write it straight */ - Nu_FunnelPutBlock(pFunnel, buffer, count); - } else { - /* do the LF conversion */ - Boolean lastCR = pFunnel->lastCR; /* local copy */ - uchar uch; + if (pFunnel->convertEOL == kNuConvertOff) { + /* write it straight */ + Nu_FunnelPutBlock(pFunnel, buffer, count); + } else { + /* do the LF conversion */ + Boolean lastCR = pFunnel->lastCR; /* local copy */ + uchar uch; - /* - * We could get a significant speed improvement here by writing - * non-EOL chars as a larger block instead of single bytes. - */ - while (count--) { - if (*buffer == kNuCharCR) { - Nu_PutEOL(pFunnel); - lastCR = true; - } else if (*buffer == kNuCharLF) { - if (!lastCR) - Nu_PutEOL(pFunnel); - lastCR = false; - } else { - uch = *buffer; - Nu_FunnelPutBlock(pFunnel, &uch, 1); - lastCR = false; - } - buffer++; - } - pFunnel->lastCR = lastCR; + /* + * We could get a significant speed improvement here by writing + * non-EOL chars as a larger block instead of single bytes. + */ + while (count--) { + if (*buffer == kNuCharCR) { + Nu_PutEOL(pFunnel); + lastCR = true; + } else if (*buffer == kNuCharLF) { + if (!lastCR) + Nu_PutEOL(pFunnel); + lastCR = false; + } else { + uch = *buffer; + Nu_FunnelPutBlock(pFunnel, &uch, 1); + lastCR = false; + } + buffer++; + } + pFunnel->lastCR = lastCR; - } + } - /*if (pFunnel->outMaxExceeded) - err = kNuErrOutMax;*/ + /*if (pFunnel->outMaxExceeded) + err = kNuErrOutMax;*/ - err = Nu_DataSinkGetError(pFunnel->pDataSink); + err = Nu_DataSinkGetError(pFunnel->pDataSink); - /* update progress counter with pre-LFCR count */ - if (err == kNuErrNone && pFunnel->pProgress != nil) - pFunnel->pProgress->uncompressedProgress += progressCount; + /* update progress counter with pre-LFCR count */ + if (err == kNuErrNone && pFunnel->pProgress != nil) + pFunnel->pProgress->uncompressedProgress += progressCount; - return err; + return err; } @@ -527,20 +527,20 @@ Nu_FunnelWriteConvert(NuFunnel* pFunnel, const uchar* buffer, ulong count) NuError Nu_FunnelFlush(NuArchive* pArchive, NuFunnel* pFunnel) { - NuError err = kNuErrNone; + NuError err = kNuErrNone; - if (!pFunnel->bufCount) - goto bail; + if (!pFunnel->bufCount) + goto bail; - err = Nu_FunnelWriteConvert(pFunnel, pFunnel->buffer, pFunnel->bufCount); - BailError(err); + err = Nu_FunnelWriteConvert(pFunnel, pFunnel->buffer, pFunnel->bufCount); + BailError(err); - pFunnel->bufCount = 0; - err = Nu_FunnelSendProgressUpdate(pArchive, pFunnel); - /* fall through with error */ + pFunnel->bufCount = 0; + err = Nu_FunnelSendProgressUpdate(pArchive, pFunnel); + /* fall through with error */ bail: - return err; + return err; } @@ -550,43 +550,43 @@ bail: */ NuError Nu_FunnelWrite(NuArchive* pArchive, NuFunnel* pFunnel, const uchar* buffer, - ulong count) + ulong count) { - NuError err = kNuErrNone; + NuError err = kNuErrNone; - /*pFunnel->inCount += count;*/ + /*pFunnel->inCount += count;*/ - /* - * If it will fit into the buffer, just copy it in. - */ - if (pFunnel->bufCount + count < kNuFunnelBufSize) { - memcpy(pFunnel->buffer + pFunnel->bufCount, buffer, count); - pFunnel->bufCount += count; - goto bail; - } else { - /* - * Won't fit. We have to flush what we have, and we can either - * blow out what we were just given or put it at the start of - * the buffer. - */ - err = Nu_FunnelFlush(pArchive, pFunnel); - BailError(err); + /* + * If it will fit into the buffer, just copy it in. + */ + if (pFunnel->bufCount + count < kNuFunnelBufSize) { + memcpy(pFunnel->buffer + pFunnel->bufCount, buffer, count); + pFunnel->bufCount += count; + goto bail; + } else { + /* + * Won't fit. We have to flush what we have, and we can either + * blow out what we were just given or put it at the start of + * the buffer. + */ + err = Nu_FunnelFlush(pArchive, pFunnel); + BailError(err); - if (count >= kNuFunnelBufSize / 4) { - /* it's more than 25% of the buffer, just write it now */ - err = Nu_FunnelWriteConvert(pFunnel, buffer, count); - BailError(err); - } else { - memcpy(pFunnel->buffer, buffer, count); - pFunnel->bufCount = count; - } - goto bail; - } + if (count >= kNuFunnelBufSize / 4) { + /* it's more than 25% of the buffer, just write it now */ + err = Nu_FunnelWriteConvert(pFunnel, buffer, count); + BailError(err); + } else { + memcpy(pFunnel->buffer, buffer, count); + pFunnel->bufCount = count; + } + goto bail; + } bail: - /*if (err == kNuErrNone) - err = Nu_FunnelSendProgressUpdate(pArchive, pFunnel);*/ - return err; + /*if (err == kNuErrNone) + err = Nu_FunnelSendProgressUpdate(pArchive, pFunnel);*/ + return err; } @@ -596,14 +596,14 @@ bail: NuError Nu_FunnelSetProgressState(NuFunnel* pFunnel, NuProgressState state) { - Assert(pFunnel != nil); + Assert(pFunnel != nil); - if (pFunnel->pProgress == nil) - return kNuErrNone; + if (pFunnel->pProgress == nil) + return kNuErrNone; - pFunnel->pProgress->state = state; + pFunnel->pProgress->state = state; - return kNuErrNone; + return kNuErrNone; } @@ -613,21 +613,21 @@ Nu_FunnelSetProgressState(NuFunnel* pFunnel, NuProgressState state) NuError Nu_FunnelSendProgressUpdate(NuArchive* pArchive, NuFunnel* pFunnel) { - NuProgressData* pProgress; + NuProgressData* pProgress; - Assert(pArchive != nil); - Assert(pFunnel != nil); + Assert(pArchive != nil); + Assert(pFunnel != nil); - pProgress = pFunnel->pProgress; - if (pProgress == nil) - return kNuErrNone; /* no progress meter attached */ + pProgress = pFunnel->pProgress; + if (pProgress == nil) + return kNuErrNone; /* no progress meter attached */ - /* don't continue if they're not accepting progress messages */ - if (pProgress->progressFunc == nil) - return kNuErrNone; + /* don't continue if they're not accepting progress messages */ + if (pProgress->progressFunc == nil) + return kNuErrNone; - /* other than the choice of arguments, it's pretty much the same story */ - return Nu_SendInitialProgress(pArchive, pProgress); + /* other than the choice of arguments, it's pretty much the same story */ + return Nu_SendInitialProgress(pArchive, pProgress); } @@ -637,16 +637,16 @@ Nu_FunnelSendProgressUpdate(NuArchive* pArchive, NuFunnel* pFunnel) Boolean Nu_FunnelGetDoExpand(NuFunnel* pFunnel) { - Assert(pFunnel != nil); - Assert(pFunnel->pDataSink != nil); + Assert(pFunnel != nil); + Assert(pFunnel->pDataSink != nil); - return Nu_DataSinkGetDoExpand(pFunnel->pDataSink); + return Nu_DataSinkGetDoExpand(pFunnel->pDataSink); } /* * =========================================================================== - * NuStraw object + * NuStraw object * =========================================================================== */ @@ -655,27 +655,27 @@ Nu_FunnelGetDoExpand(NuFunnel* pFunnel) */ NuError Nu_StrawNew(NuArchive* pArchive, NuDataSource* pDataSource, - NuProgressData* pProgress, NuStraw** ppStraw) + NuProgressData* pProgress, NuStraw** ppStraw) { - NuError err = kNuErrNone; - NuStraw* pStraw = nil; + NuError err = kNuErrNone; + NuStraw* pStraw = nil; - Assert(ppStraw != nil); - Assert(pDataSource != nil); + Assert(ppStraw != nil); + Assert(pDataSource != nil); - pStraw = Nu_Calloc(pArchive, sizeof(*pStraw)); - BailAlloc(pStraw); - pStraw->pDataSource = pDataSource; - pStraw->pProgress = pProgress; - pStraw->lastProgress = 0; - pStraw->lastDisplayed = 0; + pStraw = Nu_Calloc(pArchive, sizeof(*pStraw)); + BailAlloc(pStraw); + pStraw->pDataSource = pDataSource; + pStraw->pProgress = pProgress; + pStraw->lastProgress = 0; + pStraw->lastDisplayed = 0; bail: - if (err != kNuErrNone) - Nu_StrawFree(pArchive, pStraw); - else - *ppStraw = pStraw; - return err; + if (err != kNuErrNone) + Nu_StrawFree(pArchive, pStraw); + else + *ppStraw = pStraw; + return err; } /* @@ -684,13 +684,13 @@ bail: NuError Nu_StrawFree(NuArchive* pArchive, NuStraw* pStraw) { - if (pStraw == nil) - return kNuErrNone; + if (pStraw == nil) + return kNuErrNone; - /* we don't own the data source or progress meter */ - Nu_Free(pArchive, pStraw); + /* we don't own the data source or progress meter */ + Nu_Free(pArchive, pStraw); - return kNuErrNone; + return kNuErrNone; } @@ -700,12 +700,12 @@ Nu_StrawFree(NuArchive* pArchive, NuStraw* pStraw) NuError Nu_StrawSetProgressState(NuStraw* pStraw, NuProgressState state) { - Assert(pStraw != nil); - Assert(pStraw->pProgress != nil); + Assert(pStraw != nil); + Assert(pStraw->pProgress != nil); - pStraw->pProgress->state = state; + pStraw->pProgress->state = state; - return kNuErrNone; + return kNuErrNone; } /* @@ -714,21 +714,21 @@ Nu_StrawSetProgressState(NuStraw* pStraw, NuProgressState state) NuError Nu_StrawSendProgressUpdate(NuArchive* pArchive, NuStraw* pStraw) { - NuProgressData* pProgress; + NuProgressData* pProgress; - Assert(pArchive != nil); - Assert(pStraw != nil); + Assert(pArchive != nil); + Assert(pStraw != nil); - pProgress = pStraw->pProgress; - if (pProgress == nil) - return kNuErrNone; /* no progress meter attached */ + pProgress = pStraw->pProgress; + if (pProgress == nil) + return kNuErrNone; /* no progress meter attached */ - /* don't continue if they're not accepting progress messages */ - if (pProgress->progressFunc == nil) - return kNuErrNone; + /* don't continue if they're not accepting progress messages */ + if (pProgress->progressFunc == nil) + return kNuErrNone; - /* other than the choice of arguments, it's pretty much the same story */ - return Nu_SendInitialProgress(pArchive, pProgress); + /* other than the choice of arguments, it's pretty much the same story */ + return Nu_SendInitialProgress(pArchive, pProgress); } @@ -738,51 +738,51 @@ Nu_StrawSendProgressUpdate(NuArchive* pArchive, NuStraw* pStraw) NuError Nu_StrawRead(NuArchive* pArchive, NuStraw* pStraw, uchar* buffer, long len) { - NuError err; + NuError err; - Assert(pArchive != nil); - Assert(pStraw != nil); - Assert(buffer != nil); - Assert(len > 0); + Assert(pArchive != nil); + Assert(pStraw != nil); + Assert(buffer != nil); + Assert(len > 0); - /* - * No buffering going on, so this is straightforward. - */ + /* + * No buffering going on, so this is straightforward. + */ - err = Nu_DataSourceGetBlock(pStraw->pDataSource, buffer, len); - BailError(err); + err = Nu_DataSourceGetBlock(pStraw->pDataSource, buffer, len); + BailError(err); - /* - * Progress updating for adding is a little more complicated than - * for extracting. When extracting, the funnel controls the size - * of the output buffer, and only pushes an update when the output - * buffer fills. Here, we don't know how much will be asked for at - * a time, so we have to pace the updates or we risk flooding the - * application. - * - * We also have another problem: we want to indicate how much data - * has been processed, not how much data is *about* to be processed. - * So we have to set the percentage based on how much was requested - * on the previous call. (This assumes that whatever they asked for - * last time has already been fully processed.) - */ - if (pStraw->pProgress != nil) { - pStraw->pProgress->uncompressedProgress = pStraw->lastProgress; - pStraw->lastProgress += len; + /* + * Progress updating for adding is a little more complicated than + * for extracting. When extracting, the funnel controls the size + * of the output buffer, and only pushes an update when the output + * buffer fills. Here, we don't know how much will be asked for at + * a time, so we have to pace the updates or we risk flooding the + * application. + * + * We also have another problem: we want to indicate how much data + * has been processed, not how much data is *about* to be processed. + * So we have to set the percentage based on how much was requested + * on the previous call. (This assumes that whatever they asked for + * last time has already been fully processed.) + */ + if (pStraw->pProgress != nil) { + pStraw->pProgress->uncompressedProgress = pStraw->lastProgress; + pStraw->lastProgress += len; - if (!pStraw->pProgress->uncompressedProgress || - (pStraw->pProgress->uncompressedProgress - pStraw->lastDisplayed - > (kNuFunnelBufSize * 3 / 4))) - { - err = Nu_StrawSendProgressUpdate(pArchive, pStraw); - pStraw->lastDisplayed = pStraw->pProgress->uncompressedProgress; - BailError(err); - } + if (!pStraw->pProgress->uncompressedProgress || + (pStraw->pProgress->uncompressedProgress - pStraw->lastDisplayed + > (kNuFunnelBufSize * 3 / 4))) + { + err = Nu_StrawSendProgressUpdate(pArchive, pStraw); + pStraw->lastDisplayed = pStraw->pProgress->uncompressedProgress; + BailError(err); + } - } + } bail: - return err; + return err; } @@ -793,12 +793,12 @@ bail: NuError Nu_StrawRewind(NuArchive* pArchive, NuStraw* pStraw) { - assert(pStraw != nil); - assert(pStraw->pDataSource != nil); + assert(pStraw != nil); + assert(pStraw->pDataSource != nil); - pStraw->lastProgress = 0; - pStraw->lastDisplayed = 0; + pStraw->lastProgress = 0; + pStraw->lastDisplayed = 0; - return Nu_DataSourceRewind(pStraw->pDataSource); + return Nu_DataSourceRewind(pStraw->pDataSource); } diff --git a/nufxlib-0/Lzw.c b/nufxlib-0/Lzw.c index fe56a0a..437774c 100644 --- a/nufxlib-0/Lzw.c +++ b/nufxlib-0/Lzw.c @@ -30,19 +30,19 @@ #include "NufxLibPriv.h" /* the LZW algorithms operate on 4K chunks */ -#define kNuLZWBlockSize 4096 +#define kNuLZWBlockSize 4096 /* a little padding to avoid mysterious crashes on bad data */ -#define kNuSafetyPadding 64 +#define kNuSafetyPadding 64 -#define kNuLZWClearCode 0x0100 -#define kNuLZWFirstCode 0x0101 +#define kNuLZWClearCode 0x0100 +#define kNuLZWFirstCode 0x0101 /* sometimes we want to get *really* verbose rather late in a large archive */ #ifdef DEBUG_LZW static Boolean gNuDebugVerbose = true; - #define DBUG_LZW(x) { if (gNuDebugVerbose) { DBUG(x); } } + #define DBUG_LZW(x) { if (gNuDebugVerbose) { DBUG(x); } } #else #define DBUG_LZW ((void)0) #endif @@ -50,7 +50,7 @@ /* * =========================================================================== - * Compression + * Compression * =========================================================================== */ @@ -58,11 +58,11 @@ * We use a hash function borrowed from UNIX compress, which is described * in the v4.3 sources as: * - * Algorithm: use open addressing double hashing (no chaining) on the - * prefix code / next character combination. We do a variant of Knuth's - * algorithm D (vol. 3, sec. 6.4) along with G. Knott's relatively-prime - * secondary probe. Here, the modular division first probe is gives way - * to a faster exclusive-or manipulation. + * Algorithm: use open addressing double hashing (no chaining) on the + * prefix code / next character combination. We do a variant of Knuth's + * algorithm D (vol. 3, sec. 6.4) along with G. Knott's relatively-prime + * secondary probe. Here, the modular division first probe is gives way + * to a faster exclusive-or manipulation. * * The function used to generate it is: * @@ -81,23 +81,23 @@ * occupancy. */ -#define kNuLZWHashSize 5119 /* must be prime */ -#define kNuLZWEntryUnused 0 /* indicates an unused hash entry */ -#define kNuLZWHashFuncTblSize 256 /* one entry per char value */ -#define kNuLZWDefaultVol 0xfe /* use this as volume number */ -#define kNuLZWHashDelta 0x120 /* used in secondary hashing */ -#define kNuLZWMinCode kNuLZWClearCode /* smallest 12-bit LZW code */ -#define kNuLZWMaxCode 0x0fff /* largest 12-bit LZW code */ -#define kNuLZW2StopCode 0x0ffd /* LZW/2 stops here */ +#define kNuLZWHashSize 5119 /* must be prime */ +#define kNuLZWEntryUnused 0 /* indicates an unused hash entry */ +#define kNuLZWHashFuncTblSize 256 /* one entry per char value */ +#define kNuLZWDefaultVol 0xfe /* use this as volume number */ +#define kNuLZWHashDelta 0x120 /* used in secondary hashing */ +#define kNuLZWMinCode kNuLZWClearCode /* smallest 12-bit LZW code */ +#define kNuLZWMaxCode 0x0fff /* largest 12-bit LZW code */ +#define kNuLZW2StopCode 0x0ffd /* LZW/2 stops here */ /* * Mask of bits, from 0 to 8. */ static const int gBitMask[] = { - 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff + 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff }; -#define kNuRLEDefaultEscape 0xdb /* ShrinkIt standard */ +#define kNuRLEDefaultEscape 0xdb /* ShrinkIt standard */ /* * This holds all of the "big" dynamic state, plus a few things that I @@ -111,25 +111,25 @@ static const int gBitMask[] = { * guessing "ushort" is better overall. */ typedef struct LZWCompressState { - NuArchive* pArchive; + NuArchive* pArchive; - ushort entry[kNuLZWHashSize]; /* uint or ushort */ - ushort prefix[kNuLZWMaxCode+1]; /* uint or ushort */ - uchar suffix[kNuLZWMaxCode+1]; + ushort entry[kNuLZWHashSize]; /* uint or ushort */ + ushort prefix[kNuLZWMaxCode+1]; /* uint or ushort */ + uchar suffix[kNuLZWMaxCode+1]; - ushort hashFunc[kNuLZWHashFuncTblSize]; /* uint or ushort */ + ushort hashFunc[kNuLZWHashFuncTblSize]; /* uint or ushort */ - uchar inputBuf[kNuLZWBlockSize]; /* 4K of raw input */ - uchar rleBuf[kNuLZWBlockSize*2 + kNuSafetyPadding]; - uchar lzwBuf[(kNuLZWBlockSize * 3) / 2 + kNuSafetyPadding]; + uchar inputBuf[kNuLZWBlockSize]; /* 4K of raw input */ + uchar rleBuf[kNuLZWBlockSize*2 + kNuSafetyPadding]; + uchar lzwBuf[(kNuLZWBlockSize * 3) / 2 + kNuSafetyPadding]; - ushort chunkCrc; /* CRC for LZW/1 */ + ushort chunkCrc; /* CRC for LZW/1 */ - /* LZW/2 state variables */ - int nextFree; - int codeBits; - int highCode; - Boolean initialClear; + /* LZW/2 state variables */ + int nextFree; + int codeBits; + int highCode; + Boolean initialClear; } LZWCompressState; @@ -139,30 +139,30 @@ typedef struct LZWCompressState { static NuError Nu_AllocLZWCompressState(NuArchive* pArchive) { - NuError err; - LZWCompressState* lzwState; - int ic; + NuError err; + LZWCompressState* lzwState; + int ic; - Assert(pArchive != nil); - Assert(pArchive->lzwCompressState == nil); + Assert(pArchive != nil); + Assert(pArchive->lzwCompressState == nil); - /* allocate the general-purpose compression buffer, if needed */ - err = Nu_AllocCompressionBufferIFN(pArchive); - if (err != kNuErrNone) - return err; + /* allocate the general-purpose compression buffer, if needed */ + err = Nu_AllocCompressionBufferIFN(pArchive); + if (err != kNuErrNone) + return err; - pArchive->lzwCompressState = Nu_Malloc(pArchive, sizeof(LZWCompressState)); - if (pArchive->lzwCompressState == nil) - return kNuErrMalloc; + pArchive->lzwCompressState = Nu_Malloc(pArchive, sizeof(LZWCompressState)); + if (pArchive->lzwCompressState == nil) + return kNuErrMalloc; - /* - * The "hashFunc" table only needs to be set up once. - */ - lzwState = pArchive->lzwCompressState; - for (ic = 256; --ic >= 0; ) - lzwState->hashFunc[ic] = (((ic & 0x7) << 7) ^ ic) << 2; + /* + * The "hashFunc" table only needs to be set up once. + */ + lzwState = pArchive->lzwCompressState; + for (ic = 256; --ic >= 0; ) + lzwState->hashFunc[ic] = (((ic & 0x7) << 7) ^ ic) << 2; - return kNuErrNone; + return kNuErrNone; } @@ -184,64 +184,64 @@ Nu_AllocLZWCompressState(NuArchive* pArchive) static NuError Nu_CompressBlockRLE(LZWCompressState* lzwState, int* pRLESize) { - const uchar* inPtr = lzwState->inputBuf; - const uchar* endPtr = inPtr + kNuLZWBlockSize; - uchar* outPtr = lzwState->rleBuf; - uchar matchChar; - int matchCount; + const uchar* inPtr = lzwState->inputBuf; + const uchar* endPtr = inPtr + kNuLZWBlockSize; + uchar* outPtr = lzwState->rleBuf; + uchar matchChar; + int matchCount; - while (inPtr < endPtr) { - matchChar = *inPtr; - matchCount = 1; + while (inPtr < endPtr) { + matchChar = *inPtr; + matchCount = 1; - /* count up the matching chars */ - while (*++inPtr == matchChar && inPtr < endPtr) - matchCount++; + /* count up the matching chars */ + while (*++inPtr == matchChar && inPtr < endPtr) + matchCount++; - if (matchCount > 3) { - if (matchCount > 256) { - /* rare case - really long match */ - while (matchCount > 256) { - *outPtr++ = kNuRLEDefaultEscape; - *outPtr++ = matchChar; - *outPtr++ = 255; - matchCount -= 256; - } + if (matchCount > 3) { + if (matchCount > 256) { + /* rare case - really long match */ + while (matchCount > 256) { + *outPtr++ = kNuRLEDefaultEscape; + *outPtr++ = matchChar; + *outPtr++ = 255; + matchCount -= 256; + } - /* take care of the odd bits -- which might not form a run! */ - if (matchCount > 3) { - *outPtr++ = kNuRLEDefaultEscape; - *outPtr++ = matchChar; - *outPtr++ = matchCount -1; - } else { - while (matchCount--) - *outPtr++ = matchChar; - } + /* take care of the odd bits -- which might not form a run! */ + if (matchCount > 3) { + *outPtr++ = kNuRLEDefaultEscape; + *outPtr++ = matchChar; + *outPtr++ = matchCount -1; + } else { + while (matchCount--) + *outPtr++ = matchChar; + } - } else { - /* common case */ - *outPtr++ = kNuRLEDefaultEscape; - *outPtr++ = matchChar; - *outPtr++ = matchCount -1; - } + } else { + /* common case */ + *outPtr++ = kNuRLEDefaultEscape; + *outPtr++ = matchChar; + *outPtr++ = matchCount -1; + } - } else { - if (matchChar == kNuRLEDefaultEscape) { - /* encode 1-3 0xDBs */ - *outPtr++ = kNuRLEDefaultEscape; - *outPtr++ = kNuRLEDefaultEscape; - *outPtr++ = matchCount -1; - } else { - while (matchCount--) - *outPtr++ = matchChar; - } - } - } + } else { + if (matchChar == kNuRLEDefaultEscape) { + /* encode 1-3 0xDBs */ + *outPtr++ = kNuRLEDefaultEscape; + *outPtr++ = kNuRLEDefaultEscape; + *outPtr++ = matchCount -1; + } else { + while (matchCount--) + *outPtr++ = matchChar; + } + } + } - *pRLESize = outPtr - lzwState->rleBuf; - Assert(*pRLESize > 0 && *pRLESize < sizeof(lzwState->rleBuf)); + *pRLESize = outPtr - lzwState->rleBuf; + Assert(*pRLESize > 0 && *pRLESize < sizeof(lzwState->rleBuf)); - return kNuErrNone; + return kNuErrNone; } @@ -251,19 +251,19 @@ Nu_CompressBlockRLE(LZWCompressState* lzwState, int* pRLESize) static void Nu_ClearLZWTable(LZWCompressState* lzwState) { - Assert(lzwState != nil); + Assert(lzwState != nil); - /*DBUG_LZW(("### clear table\n"));*/ + /*DBUG_LZW(("### clear table\n"));*/ - /* reset table entries */ - Assert(kNuLZWEntryUnused == 0); /* make sure this is okay */ - memset(lzwState->entry, 0, sizeof(lzwState->entry)); + /* reset table entries */ + Assert(kNuLZWEntryUnused == 0); /* make sure this is okay */ + memset(lzwState->entry, 0, sizeof(lzwState->entry)); - /* reset state variables */ - lzwState->nextFree = kNuLZWFirstCode; - lzwState->codeBits = 9; - lzwState->highCode = ~(~0 << lzwState->codeBits); /* a/k/a 0x01ff */ - lzwState->initialClear = false; + /* reset state variables */ + lzwState->nextFree = kNuLZWFirstCode; + lzwState->codeBits = 9; + lzwState->highCode = ~(~0 << lzwState->codeBits); /* a/k/a 0x01ff */ + lzwState->initialClear = false; } @@ -289,37 +289,37 @@ Nu_ClearLZWTable(LZWCompressState* lzwState) static inline void Nu_LZWPutCode(uchar** pOutBuf, ulong prefixCode, int codeBits, int* pAtBit) { - int atBit = *pAtBit; - uchar* outBuf = *pOutBuf; + int atBit = *pAtBit; + uchar* outBuf = *pOutBuf; - /*DBUG_LZW(("### PUT: prefixCode=0x%04lx, codeBits=%d, atBit=%d\n", - prefixCode, codeBits, atBit));*/ + /*DBUG_LZW(("### PUT: prefixCode=0x%04lx, codeBits=%d, atBit=%d\n", + prefixCode, codeBits, atBit));*/ - Assert(atBit >= 0 && atBit < sizeof(gBitMask)); + Assert(atBit >= 0 && atBit < sizeof(gBitMask)); - if (atBit) { - /* align the prefix code with the existing byte */ - prefixCode <<= atBit; + if (atBit) { + /* align the prefix code with the existing byte */ + prefixCode <<= atBit; - /* merge it with the buffer contents (if necessary) and write lo bits */ - outBuf--; - *outBuf = (uchar)((*outBuf & gBitMask[atBit]) | prefixCode); - outBuf++; - } else { - /* nothing to merge with; write lo byte at next posn and advance */ - *outBuf++ = (uchar)prefixCode; - } + /* merge it with the buffer contents (if necessary) and write lo bits */ + outBuf--; + *outBuf = (uchar)((*outBuf & gBitMask[atBit]) | prefixCode); + outBuf++; + } else { + /* nothing to merge with; write lo byte at next posn and advance */ + *outBuf++ = (uchar)prefixCode; + } - /* codes are at least 9 bits, so we know we have to write one more */ - *outBuf++ = (uchar)(prefixCode >> 8); + /* codes are at least 9 bits, so we know we have to write one more */ + *outBuf++ = (uchar)(prefixCode >> 8); - /* in some cases, we may have to write yet another */ - atBit += codeBits; - if (atBit > 16) - *outBuf++ = (uchar)(prefixCode >> 16); - - *pAtBit = atBit & 0x07; - *pOutBuf = outBuf; + /* in some cases, we may have to write yet another */ + atBit += codeBits; + if (atBit > 16) + *outBuf++ = (uchar)(prefixCode >> 16); + + *pAtBit = atBit & 0x07; + *pOutBuf = outBuf; } @@ -345,196 +345,196 @@ Nu_LZWPutCode(uchar** pOutBuf, ulong prefixCode, int codeBits, int* pAtBit) */ static NuError Nu_CompressLZWBlock(LZWCompressState* lzwState, const uchar* inputBuf, - int inputCount, int* pOutputCount) + int inputCount, int* pOutputCount) { - int nextFree, ic, atBit, codeBits; - int hash, hashDelta; - int prefixCode, code, highCode; - const uchar* inputEnd = inputBuf + inputCount; - /* local copies of lzwState members, for speed */ - const ushort* pHashFunc = lzwState->hashFunc; - ushort* pEntry = lzwState->entry; - ushort* pPrefix = lzwState->prefix; - uchar* pSuffix = lzwState->suffix; - uchar* outBuf = lzwState->lzwBuf; + int nextFree, ic, atBit, codeBits; + int hash, hashDelta; + int prefixCode, code, highCode; + const uchar* inputEnd = inputBuf + inputCount; + /* local copies of lzwState members, for speed */ + const ushort* pHashFunc = lzwState->hashFunc; + ushort* pEntry = lzwState->entry; + ushort* pPrefix = lzwState->prefix; + uchar* pSuffix = lzwState->suffix; + uchar* outBuf = lzwState->lzwBuf; - Assert(lzwState != nil); - Assert(inputBuf != nil); - Assert(inputCount > 0 && inputCount <= kNuLZWBlockSize); - /* make sure nobody has been messing with the types */ - Assert(sizeof(pHashFunc[0]) == sizeof(lzwState->hashFunc[0])); - Assert(sizeof(pEntry[0]) == sizeof(lzwState->entry[0])); - Assert(sizeof(pPrefix[0]) == sizeof(lzwState->prefix[0])); - Assert(sizeof(pSuffix[0]) == sizeof(lzwState->suffix[0])); + Assert(lzwState != nil); + Assert(inputBuf != nil); + Assert(inputCount > 0 && inputCount <= kNuLZWBlockSize); + /* make sure nobody has been messing with the types */ + Assert(sizeof(pHashFunc[0]) == sizeof(lzwState->hashFunc[0])); + Assert(sizeof(pEntry[0]) == sizeof(lzwState->entry[0])); + Assert(sizeof(pPrefix[0]) == sizeof(lzwState->prefix[0])); + Assert(sizeof(pSuffix[0]) == sizeof(lzwState->suffix[0])); - /*DBUG_LZW(("### START LZW (nextFree=0x%04x)\n", lzwState->nextFree));*/ + /*DBUG_LZW(("### START LZW (nextFree=0x%04x)\n", lzwState->nextFree));*/ - atBit = 0; + atBit = 0; - if (lzwState->initialClear) { - /*DBUG_LZW(("### initialClear set\n"));*/ - codeBits = lzwState->codeBits; - Nu_LZWPutCode(&outBuf, kNuLZWClearCode, codeBits, &atBit); - Nu_ClearLZWTable(lzwState); - } + if (lzwState->initialClear) { + /*DBUG_LZW(("### initialClear set\n"));*/ + codeBits = lzwState->codeBits; + Nu_LZWPutCode(&outBuf, kNuLZWClearCode, codeBits, &atBit); + Nu_ClearLZWTable(lzwState); + } table_cleared: - /* recover our state (or get newly-cleared state) */ - nextFree = lzwState->nextFree; - codeBits = lzwState->codeBits; - highCode = lzwState->highCode; + /* recover our state (or get newly-cleared state) */ + nextFree = lzwState->nextFree; + codeBits = lzwState->codeBits; + highCode = lzwState->highCode; - prefixCode = *inputBuf++; + prefixCode = *inputBuf++; - /*DBUG_LZW(("### fchar=0x%02x\n", prefixCode));*/ + /*DBUG_LZW(("### fchar=0x%02x\n", prefixCode));*/ - while (inputBuf < inputEnd) { - ic = *inputBuf++; - /*DBUG_LZW(("### char=0x%02x\n", ic));*/ + while (inputBuf < inputEnd) { + ic = *inputBuf++; + /*DBUG_LZW(("### char=0x%02x\n", ic));*/ - hash = prefixCode ^ pHashFunc[ic]; - code = pEntry[hash]; + hash = prefixCode ^ pHashFunc[ic]; + code = pEntry[hash]; - if (code != kNuLZWEntryUnused) { - /* something is here, either our prefix or a hash collision */ - if (pSuffix[code] != ic || pPrefix[code] != prefixCode) { - /* we've collided; do the secondary probe */ - hashDelta = (kNuLZWHashDelta - ic) << 2; - do { - /* rehash and keep looking */ - Assert(code >= kNuLZWMinCode && code <= kNuLZWMaxCode); - if (hash >= hashDelta) - hash -= hashDelta; - else - hash += kNuLZWHashSize - hashDelta; - Assert(hash >= 0 && hash < kNuLZWHashSize); + if (code != kNuLZWEntryUnused) { + /* something is here, either our prefix or a hash collision */ + if (pSuffix[code] != ic || pPrefix[code] != prefixCode) { + /* we've collided; do the secondary probe */ + hashDelta = (kNuLZWHashDelta - ic) << 2; + do { + /* rehash and keep looking */ + Assert(code >= kNuLZWMinCode && code <= kNuLZWMaxCode); + if (hash >= hashDelta) + hash -= hashDelta; + else + hash += kNuLZWHashSize - hashDelta; + Assert(hash >= 0 && hash < kNuLZWHashSize); - if ((code = pEntry[hash]) == kNuLZWEntryUnused) - goto new_code; - } while (pSuffix[code] != ic || pPrefix[code] != prefixCode); - } + if ((code = pEntry[hash]) == kNuLZWEntryUnused) + goto new_code; + } while (pSuffix[code] != ic || pPrefix[code] != prefixCode); + } - /* else we found a matching string, and can keep searching */ - prefixCode = code; + /* else we found a matching string, and can keep searching */ + prefixCode = code; - } else { - /* found an empty entry, add the prefix+suffix to the table */ + } else { + /* found an empty entry, add the prefix+suffix to the table */ new_code: - Nu_LZWPutCode(&outBuf, prefixCode, codeBits, &atBit); - Assert(outBuf < lzwState->lzwBuf + sizeof(lzwState->lzwBuf)); - /*DBUG_LZW(("### outBuf now at +%d\n",outBuf - lzwState->lzwBuf));*/ + Nu_LZWPutCode(&outBuf, prefixCode, codeBits, &atBit); + Assert(outBuf < lzwState->lzwBuf + sizeof(lzwState->lzwBuf)); + /*DBUG_LZW(("### outBuf now at +%d\n",outBuf - lzwState->lzwBuf));*/ - code = nextFree; - Assert(hash < kNuLZWHashSize); - Assert(code >= kNuLZWMinCode); - Assert(code <= kNuLZWMaxCode); + code = nextFree; + Assert(hash < kNuLZWHashSize); + Assert(code >= kNuLZWMinCode); + Assert(code <= kNuLZWMaxCode); - /* - * GSHK accepts 0x0ffd, and then sends the table clear - * immediately. We could improve on GSHK's compression slightly - * by using the entire table, but I want to generate the exact - * same output as GSHK. (The decoder believes the table clear - * is entry 0xffe, so we've got one more coming, and possibly - * two if we tweak getcode slightly.) - * - * Experiments show that switching to 0xffe increases the size - * of files that don't compress well, and decreases the size - * of files that do. In both cases, the difference in size - * is very small. - */ - Assert(code <= kNuLZW2StopCode); - /*if (code <= kNuLZW2StopCode) {*/ - /*DBUG_LZW(("### added new code 0x%04x prefix=0x%04x ch=0x%02x\n", - code, prefixCode, ic));*/ + /* + * GSHK accepts 0x0ffd, and then sends the table clear + * immediately. We could improve on GSHK's compression slightly + * by using the entire table, but I want to generate the exact + * same output as GSHK. (The decoder believes the table clear + * is entry 0xffe, so we've got one more coming, and possibly + * two if we tweak getcode slightly.) + * + * Experiments show that switching to 0xffe increases the size + * of files that don't compress well, and decreases the size + * of files that do. In both cases, the difference in size + * is very small. + */ + Assert(code <= kNuLZW2StopCode); + /*if (code <= kNuLZW2StopCode) {*/ + /*DBUG_LZW(("### added new code 0x%04x prefix=0x%04x ch=0x%02x\n", + code, prefixCode, ic));*/ - pEntry[hash] = code; - pPrefix[code] = prefixCode; - pSuffix[code] = ic; + pEntry[hash] = code; + pPrefix[code] = prefixCode; + pSuffix[code] = ic; - /* - * Check and see if it's time to increase the code size (note - * we flip earlier than LZC by one here). - */ - if (code >= highCode) { - highCode += code +1; - codeBits++; - } + /* + * Check and see if it's time to increase the code size (note + * we flip earlier than LZC by one here). + */ + if (code >= highCode) { + highCode += code +1; + codeBits++; + } - nextFree++; + nextFree++; - /*}*/ + /*}*/ - prefixCode = ic; + prefixCode = ic; - /* if the table is full, clear it (only for LZW/2) */ - if (code == kNuLZW2StopCode) { - /* output last code */ - Nu_LZWPutCode(&outBuf, prefixCode, codeBits, &atBit); + /* if the table is full, clear it (only for LZW/2) */ + if (code == kNuLZW2StopCode) { + /* output last code */ + Nu_LZWPutCode(&outBuf, prefixCode, codeBits, &atBit); - if (inputBuf < inputEnd) { - /* still have data, keep going */ - Nu_LZWPutCode(&outBuf, kNuLZWClearCode, codeBits, &atBit); - Nu_ClearLZWTable(lzwState); - goto table_cleared; - } else { - /* no more input, hold table clear for next block */ - DBUG(("--- RARE: block-end clear\n")); - lzwState->initialClear = true; - goto table_clear_finish; - } - } + if (inputBuf < inputEnd) { + /* still have data, keep going */ + Nu_LZWPutCode(&outBuf, kNuLZWClearCode, codeBits, &atBit); + Nu_ClearLZWTable(lzwState); + goto table_cleared; + } else { + /* no more input, hold table clear for next block */ + DBUG(("--- RARE: block-end clear\n")); + lzwState->initialClear = true; + goto table_clear_finish; + } + } - Assert(nextFree <= kNuLZW2StopCode); - } - } + Assert(nextFree <= kNuLZW2StopCode); + } + } - /* - * Output the last code. Since there's no following character, we don't - * need to add an entry to the table... whatever we've found is already - * in there. - */ - Nu_LZWPutCode(&outBuf, prefixCode, codeBits, &atBit); + /* + * Output the last code. Since there's no following character, we don't + * need to add an entry to the table... whatever we've found is already + * in there. + */ + Nu_LZWPutCode(&outBuf, prefixCode, codeBits, &atBit); - /* - * Update the counters so LZW/2 has continuity. - */ - Assert(nextFree <= kNuLZW2StopCode); - if (nextFree >= highCode) { - highCode += nextFree +1; - codeBits++; - } - nextFree++; /* make room for the code we just wrote */ + /* + * Update the counters so LZW/2 has continuity. + */ + Assert(nextFree <= kNuLZW2StopCode); + if (nextFree >= highCode) { + highCode += nextFree +1; + codeBits++; + } + nextFree++; /* make room for the code we just wrote */ - if (nextFree > kNuLZW2StopCode) { - /* - * The code we just wrote, which was part of a longer string already - * in the tree, took the last entry in the table. We need to clear - * the table, but we can't do it in this block. We will have to - * emit a table clear as the very first thing in the next block. - */ - DBUG(("--- RARE: block-end inter clear\n")); - lzwState->initialClear = true; - } + if (nextFree > kNuLZW2StopCode) { + /* + * The code we just wrote, which was part of a longer string already + * in the tree, took the last entry in the table. We need to clear + * the table, but we can't do it in this block. We will have to + * emit a table clear as the very first thing in the next block. + */ + DBUG(("--- RARE: block-end inter clear\n")); + lzwState->initialClear = true; + } table_clear_finish: - /* save state for next pass through */ - lzwState->nextFree = nextFree; - lzwState->codeBits = codeBits; - lzwState->highCode = highCode; + /* save state for next pass through */ + lzwState->nextFree = nextFree; + lzwState->codeBits = codeBits; + lzwState->highCode = highCode; - Assert(inputBuf == inputEnd); + Assert(inputBuf == inputEnd); - *pOutputCount = outBuf - lzwState->lzwBuf; + *pOutputCount = outBuf - lzwState->lzwBuf; - /* - if (*pOutputCount < inputCount) { - DBUG_LZW(("### compressed from %d to %d\n", inputCount, *pOutputCount)); - } else { - DBUG_LZW(("### NO compression (%d to %d)\n", inputCount,*pOutputCount)); - } - */ + /* + if (*pOutputCount < inputCount) { + DBUG_LZW(("### compressed from %d to %d\n", inputCount, *pOutputCount)); + } else { + DBUG_LZW(("### NO compression (%d to %d)\n", inputCount,*pOutputCount)); + } + */ - return kNuErrNone; + return kNuErrNone; } /* @@ -547,230 +547,230 @@ Nu_CompressLZWBlock(LZWCompressState* lzwState, const uchar* inputBuf, */ static NuError Nu_CompressLZW(NuArchive* pArchive, NuStraw* pStraw, FILE* fp, - ulong srcLen, ulong* pDstLen, ushort* pThreadCrc, Boolean isType2) + ulong srcLen, ulong* pDstLen, ushort* pThreadCrc, Boolean isType2) { - NuError err = kNuErrNone; - LZWCompressState* lzwState; - long initialOffset; - const uchar* lzwInputBuf; - uint blockSize, rleSize, lzwSize; - long compressedLen; - Boolean keepLzw; + NuError err = kNuErrNone; + LZWCompressState* lzwState; + long initialOffset; + const uchar* lzwInputBuf; + uint blockSize, rleSize, lzwSize; + long compressedLen; + Boolean keepLzw; - Assert(pArchive != nil); - Assert(pStraw != nil); - Assert(fp != nil); - Assert(srcLen > 0); - Assert(pDstLen != nil); - Assert(pThreadCrc != nil); - Assert(isType2 == true || isType2 == false); + Assert(pArchive != nil); + Assert(pStraw != nil); + Assert(fp != nil); + Assert(srcLen > 0); + Assert(pDstLen != nil); + Assert(pThreadCrc != nil); + Assert(isType2 == true || isType2 == false); - /* - * Do some initialization and set-up. - */ - if (pArchive->lzwCompressState == nil) { - err = Nu_AllocLZWCompressState(pArchive); - BailError(err); - } - Assert(pArchive->lzwCompressState != nil); - Assert(pArchive->compBuf != nil); + /* + * Do some initialization and set-up. + */ + if (pArchive->lzwCompressState == nil) { + err = Nu_AllocLZWCompressState(pArchive); + BailError(err); + } + Assert(pArchive->lzwCompressState != nil); + Assert(pArchive->compBuf != nil); - lzwState = pArchive->lzwCompressState; - lzwState->pArchive = pArchive; - compressedLen = 0; + lzwState = pArchive->lzwCompressState; + lzwState->pArchive = pArchive; + compressedLen = 0; - /* - * And now for something ugly: for LZW/1 we have to compute the CRC - * twice. Old versions of ShrinkIt used LZW/1 and put the CRC in - * the compressed block while newer versions used LZW/2 and put the - * CRC in the thread header. We're using LZW/1 with the newer record - * format, so we need two CRCs. For some odd reason Andy N. decided - * to use 0xffff as the initial value for the thread one, so we can't - * just store the same thing in two places. - * - * Of course, this also means that an LZW/2 chunk stored in an old - * pre-v3 record wouldn't have a CRC at all... - * - * LZW/1 is included here for completeness. I can't think of a reason - * why you'd want to use it, really. - */ - lzwState->chunkCrc = kNuInitialChunkCRC; /* 0x0000 */ + /* + * And now for something ugly: for LZW/1 we have to compute the CRC + * twice. Old versions of ShrinkIt used LZW/1 and put the CRC in + * the compressed block while newer versions used LZW/2 and put the + * CRC in the thread header. We're using LZW/1 with the newer record + * format, so we need two CRCs. For some odd reason Andy N. decided + * to use 0xffff as the initial value for the thread one, so we can't + * just store the same thing in two places. + * + * Of course, this also means that an LZW/2 chunk stored in an old + * pre-v3 record wouldn't have a CRC at all... + * + * LZW/1 is included here for completeness. I can't think of a reason + * why you'd want to use it, really. + */ + lzwState->chunkCrc = kNuInitialChunkCRC; /* 0x0000 */ - /* - * An LZW/1 file starts off with a CRC of the data, which means we - * have to compress the whole thing, then seek back afterward and - * write the value. This annoyance went away in LZW/2. - */ - err = Nu_FTell(fp, &initialOffset); - BailError(err); + /* + * An LZW/1 file starts off with a CRC of the data, which means we + * have to compress the whole thing, then seek back afterward and + * write the value. This annoyance went away in LZW/2. + */ + err = Nu_FTell(fp, &initialOffset); + BailError(err); - if (!isType2) { - putc(0, fp); /* leave space for CRC */ - putc(0, fp); - compressedLen += 2; - } - putc(kNuLZWDefaultVol, fp); - putc(kNuRLEDefaultEscape, fp); - compressedLen += 2; + if (!isType2) { + putc(0, fp); /* leave space for CRC */ + putc(0, fp); + compressedLen += 2; + } + putc(kNuLZWDefaultVol, fp); + putc(kNuRLEDefaultEscape, fp); + compressedLen += 2; - if (isType2) - Nu_ClearLZWTable(lzwState); + if (isType2) + Nu_ClearLZWTable(lzwState); - while (srcLen) { - /* - * Fill up the input buffer. - */ - blockSize = (srcLen > kNuLZWBlockSize) ? kNuLZWBlockSize : srcLen; + while (srcLen) { + /* + * Fill up the input buffer. + */ + blockSize = (srcLen > kNuLZWBlockSize) ? kNuLZWBlockSize : srcLen; - err = Nu_StrawRead(pArchive, pStraw, lzwState->inputBuf, blockSize); - if (err != kNuErrNone) { - Nu_ReportError(NU_BLOB, err, "compression read failed"); - goto bail; - } + err = Nu_StrawRead(pArchive, pStraw, lzwState->inputBuf, blockSize); + if (err != kNuErrNone) { + Nu_ReportError(NU_BLOB, err, "compression read failed"); + goto bail; + } - /* - * ShrinkIt was originally just going to be a 5.25" disk compressor, - * so the compression functions were organized around 4K blocks (the - * size of one track on a 5.25" disk). The block passed into the - * RLE function is always 4K, so we zero out any extra space. - */ - if (blockSize < kNuLZWBlockSize) { - memset(lzwState->inputBuf + blockSize, 0, - kNuLZWBlockSize - blockSize); - } + /* + * ShrinkIt was originally just going to be a 5.25" disk compressor, + * so the compression functions were organized around 4K blocks (the + * size of one track on a 5.25" disk). The block passed into the + * RLE function is always 4K, so we zero out any extra space. + */ + if (blockSize < kNuLZWBlockSize) { + memset(lzwState->inputBuf + blockSize, 0, + kNuLZWBlockSize - blockSize); + } - /* - * Compute the CRC. For LZW/1 this is on the entire 4K block, for - * LZW/2 this is on just the "real" data. - */ - if (isType2) { - *pThreadCrc = Nu_CalcCRC16(*pThreadCrc, - lzwState->inputBuf, blockSize); - } else { - *pThreadCrc = Nu_CalcCRC16(*pThreadCrc, - lzwState->inputBuf, kNuLZWBlockSize); - lzwState->chunkCrc = Nu_CalcCRC16(lzwState->chunkCrc, - lzwState->inputBuf, kNuLZWBlockSize); - } + /* + * Compute the CRC. For LZW/1 this is on the entire 4K block, for + * LZW/2 this is on just the "real" data. + */ + if (isType2) { + *pThreadCrc = Nu_CalcCRC16(*pThreadCrc, + lzwState->inputBuf, blockSize); + } else { + *pThreadCrc = Nu_CalcCRC16(*pThreadCrc, + lzwState->inputBuf, kNuLZWBlockSize); + lzwState->chunkCrc = Nu_CalcCRC16(lzwState->chunkCrc, + lzwState->inputBuf, kNuLZWBlockSize); + } - /* - * Try to compress with RLE, from inputBuf to rleBuf. - */ - err = Nu_CompressBlockRLE(lzwState, (int*) &rleSize); - BailError(err); + /* + * Try to compress with RLE, from inputBuf to rleBuf. + */ + err = Nu_CompressBlockRLE(lzwState, (int*) &rleSize); + BailError(err); - if (rleSize < kNuLZWBlockSize) { - lzwInputBuf = lzwState->rleBuf; - } else { - lzwInputBuf = lzwState->inputBuf; - rleSize = kNuLZWBlockSize; - } + if (rleSize < kNuLZWBlockSize) { + lzwInputBuf = lzwState->rleBuf; + } else { + lzwInputBuf = lzwState->inputBuf; + rleSize = kNuLZWBlockSize; + } - /* - * Compress with LZW, into lzwBuf. - */ - if (!isType2) - Nu_ClearLZWTable(lzwState); - err = Nu_CompressLZWBlock(lzwState, lzwInputBuf, rleSize, - (int*) &lzwSize); - BailError(err); + /* + * Compress with LZW, into lzwBuf. + */ + if (!isType2) + Nu_ClearLZWTable(lzwState); + err = Nu_CompressLZWBlock(lzwState, lzwInputBuf, rleSize, + (int*) &lzwSize); + BailError(err); - /* decide if we want to keep it, bearing in mind the LZW/2 header */ - if (pArchive->valMimicSHK) { - /* GSHK doesn't factor in header -- and *sometimes* uses "<=" !! */ - keepLzw = (lzwSize < rleSize); - } else { - if (isType2) - keepLzw = (lzwSize +2 < rleSize); - else - keepLzw = (lzwSize < rleSize); - } + /* decide if we want to keep it, bearing in mind the LZW/2 header */ + if (pArchive->valMimicSHK) { + /* GSHK doesn't factor in header -- and *sometimes* uses "<=" !! */ + keepLzw = (lzwSize < rleSize); + } else { + if (isType2) + keepLzw = (lzwSize +2 < rleSize); + else + keepLzw = (lzwSize < rleSize); + } - /* - * Write the compressed (or not) chunk. - */ - if (keepLzw) { - /* - * LZW succeeded. - */ - if (isType2) - rleSize |= 0x8000; /* for LZW/2, set "LZW used" flag */ + /* + * Write the compressed (or not) chunk. + */ + if (keepLzw) { + /* + * LZW succeeded. + */ + if (isType2) + rleSize |= 0x8000; /* for LZW/2, set "LZW used" flag */ - putc(rleSize & 0xff, fp); /* size after RLE */ - putc(rleSize >> 8, fp); - compressedLen += 2; + putc(rleSize & 0xff, fp); /* size after RLE */ + putc(rleSize >> 8, fp); + compressedLen += 2; - if (isType2) { - /* write compressed LZW len (+4 for header bytes) */ - putc((lzwSize+4) & 0xff, fp); - putc((lzwSize+4) >> 8, fp); - compressedLen += 2; - } else { - /* set LZW/1 "LZW used" flag */ - putc(1, fp); - compressedLen++; - } - - /* write data from LZW buffer */ - err = Nu_FWrite(fp, lzwState->lzwBuf, lzwSize); - BailError(err); - compressedLen += lzwSize; - } else { - /* - * LZW failed. - */ - putc(rleSize & 0xff, fp); /* size after RLE */ - putc(rleSize >> 8, fp); - compressedLen += 2; + if (isType2) { + /* write compressed LZW len (+4 for header bytes) */ + putc((lzwSize+4) & 0xff, fp); + putc((lzwSize+4) >> 8, fp); + compressedLen += 2; + } else { + /* set LZW/1 "LZW used" flag */ + putc(1, fp); + compressedLen++; + } + + /* write data from LZW buffer */ + err = Nu_FWrite(fp, lzwState->lzwBuf, lzwSize); + BailError(err); + compressedLen += lzwSize; + } else { + /* + * LZW failed. + */ + putc(rleSize & 0xff, fp); /* size after RLE */ + putc(rleSize >> 8, fp); + compressedLen += 2; - if (isType2) { - /* clear LZW/2 table; we can't use it next time */ - Nu_ClearLZWTable(lzwState); - } else { - /* set LZW/1 "LZW not used" flag */ - putc(0, fp); - compressedLen++; - } + if (isType2) { + /* clear LZW/2 table; we can't use it next time */ + Nu_ClearLZWTable(lzwState); + } else { + /* set LZW/1 "LZW not used" flag */ + putc(0, fp); + compressedLen++; + } - /* write data from RLE or plain-input buffer */ - err = Nu_FWrite(fp, lzwInputBuf, rleSize); - BailError(err); - compressedLen += rleSize; - } + /* write data from RLE or plain-input buffer */ + err = Nu_FWrite(fp, lzwInputBuf, rleSize); + BailError(err); + compressedLen += rleSize; + } - /* - * Update the counter and continue. - */ - srcLen -= blockSize; - } + /* + * Update the counter and continue. + */ + srcLen -= blockSize; + } - /* - * For LZW/1, go back and write the CRC. - */ - if (!isType2) { - long curOffset; + /* + * For LZW/1, go back and write the CRC. + */ + if (!isType2) { + long curOffset; - err = Nu_FTell(fp, &curOffset); - BailError(err); - err = Nu_FSeek(fp, initialOffset, SEEK_SET); - BailError(err); - putc(lzwState->chunkCrc & 0xff, fp); - putc(lzwState->chunkCrc >> 8, fp); - err = Nu_FSeek(fp, curOffset, SEEK_SET); - BailError(err); - } + err = Nu_FTell(fp, &curOffset); + BailError(err); + err = Nu_FSeek(fp, initialOffset, SEEK_SET); + BailError(err); + putc(lzwState->chunkCrc & 0xff, fp); + putc(lzwState->chunkCrc >> 8, fp); + err = Nu_FSeek(fp, curOffset, SEEK_SET); + BailError(err); + } - /* P8SHK and GSHK add an extra byte to LZW-compressed threads */ - if (pArchive->valMimicSHK) { - putc(0, fp); - compressedLen++; - } + /* P8SHK and GSHK add an extra byte to LZW-compressed threads */ + if (pArchive->valMimicSHK) { + putc(0, fp); + compressedLen++; + } - *pDstLen = compressedLen; + *pDstLen = compressedLen; bail: - return err; + return err; } /* @@ -778,9 +778,9 @@ bail: */ NuError Nu_CompressLZW1(NuArchive* pArchive, NuStraw* pStraw, FILE* fp, - ulong srcLen, ulong* pDstLen, ushort* pCrc) + ulong srcLen, ulong* pDstLen, ushort* pCrc) { - return Nu_CompressLZW(pArchive, pStraw, fp, srcLen, pDstLen, pCrc, false); + return Nu_CompressLZW(pArchive, pStraw, fp, srcLen, pDstLen, pCrc, false); } /* @@ -788,40 +788,40 @@ Nu_CompressLZW1(NuArchive* pArchive, NuStraw* pStraw, FILE* fp, */ NuError Nu_CompressLZW2(NuArchive* pArchive, NuStraw* pStraw, FILE* fp, - ulong srcLen, ulong* pDstLen, ushort* pCrc) + ulong srcLen, ulong* pDstLen, ushort* pCrc) { - return Nu_CompressLZW(pArchive, pStraw, fp, srcLen, pDstLen, pCrc, true); + return Nu_CompressLZW(pArchive, pStraw, fp, srcLen, pDstLen, pCrc, true); } /* * =========================================================================== - * Expansion + * Expansion * =========================================================================== */ /* if we don't have at least this much data, we try to read more */ /* (the "+3" is for the chunk header bytes) */ -#define kNuLZWDesiredChunk (kNuLZWBlockSize + 3) +#define kNuLZWDesiredChunk (kNuLZWBlockSize + 3) /* * Static tables useful for bit manipulation. */ static const uint gMaskTable[17] = { - 0x0000, 0x01ff, 0x03ff, 0x03ff, 0x07ff, 0x07ff, 0x07ff, 0x07ff, - 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, - 0x0fff + 0x0000, 0x01ff, 0x03ff, 0x03ff, 0x07ff, 0x07ff, 0x07ff, 0x07ff, + 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, 0x0fff, + 0x0fff }; /* convert high byte of "entry" into a bit width */ static const uint gBitWidth[17] = { - 8,9,10,10,11,11,11,11,12,12,12,12,12,12,12,12,12 + 8,9,10,10,11,11,11,11,12,12,12,12,12,12,12,12,12 }; /* entry in the trie */ typedef struct TableEntry { - uchar ch; - uint prefix; + uchar ch; + uint prefix; } TableEntry; /* @@ -830,28 +830,28 @@ typedef struct TableEntry { * an open archive, and re-used. */ typedef struct LZWExpandState { - NuArchive* pArchive; + NuArchive* pArchive; - TableEntry trie[4096-256]; /* holds from 9 bits to 12 bits */ - uchar stack[kNuLZWBlockSize]; + TableEntry trie[4096-256]; /* holds from 9 bits to 12 bits */ + uchar stack[kNuLZWBlockSize]; - uint entry; /* 16-bit index into table */ - uint oldcode; /* carryover state for LZW/2 */ - uint incode; /* carryover state for LZW/2 */ - uint finalc; /* carryover state for LZW/2 */ - Boolean resetFix; /* work around an LZW/2 bug */ + uint entry; /* 16-bit index into table */ + uint oldcode; /* carryover state for LZW/2 */ + uint incode; /* carryover state for LZW/2 */ + uint finalc; /* carryover state for LZW/2 */ + Boolean resetFix; /* work around an LZW/2 bug */ - ushort chunkCrc; /* CRC we calculate for LZW/1 */ - ushort fileCrc; /* CRC stored with file */ + ushort chunkCrc; /* CRC we calculate for LZW/1 */ + ushort fileCrc; /* CRC stored with file */ - uchar diskVol; /* disk volume # */ - uchar rleEscape; /* RLE escape char, usually 0xdb */ + uchar diskVol; /* disk volume # */ + uchar rleEscape; /* RLE escape char, usually 0xdb */ - ulong dataInBuffer; /* #of bytes in compBuf */ - uchar* dataPtr; /* current data offset */ + ulong dataInBuffer; /* #of bytes in compBuf */ + uchar* dataPtr; /* current data offset */ - uchar lzwOutBuf[kNuLZWBlockSize + kNuSafetyPadding]; - uchar rleOutBuf[kNuLZWBlockSize + kNuSafetyPadding]; + uchar lzwOutBuf[kNuLZWBlockSize + kNuSafetyPadding]; + uchar rleOutBuf[kNuLZWBlockSize + kNuSafetyPadding]; } LZWExpandState; @@ -861,51 +861,51 @@ typedef struct LZWExpandState { static NuError Nu_AllocLZWExpandState(NuArchive* pArchive) { - NuError err; + NuError err; - Assert(pArchive != nil); - Assert(pArchive->lzwExpandState == nil); + Assert(pArchive != nil); + Assert(pArchive->lzwExpandState == nil); - /* allocate the general-purpose compression buffer, if needed */ - err = Nu_AllocCompressionBufferIFN(pArchive); - if (err != kNuErrNone) - return err; + /* allocate the general-purpose compression buffer, if needed */ + err = Nu_AllocCompressionBufferIFN(pArchive); + if (err != kNuErrNone) + return err; - pArchive->lzwExpandState = Nu_Malloc(pArchive, sizeof(LZWExpandState)); - if (pArchive->lzwExpandState == nil) - return kNuErrMalloc; - return kNuErrNone; + pArchive->lzwExpandState = Nu_Malloc(pArchive, sizeof(LZWExpandState)); + if (pArchive->lzwExpandState == nil) + return kNuErrMalloc; + return kNuErrNone; } #ifdef NDEBUG -# define Nu_LZWPush(uch) ( *stackPtr++ = (uch) ) -# define Nu_LZWPop() ( *(--stackPtr) ) +# define Nu_LZWPush(uch) ( *stackPtr++ = (uch) ) +# define Nu_LZWPop() ( *(--stackPtr) ) # define Nu_LZWStackEmpty() ( stackPtr == lzwState->stack ) #else -# define Nu_LZWPush(uch) \ - ( Nu_LZWPushCheck(uch, lzwState, stackPtr), *stackPtr++ = (uch) ) -# define Nu_LZWPop() \ - ( Nu_LZWPopCheck(lzwState, stackPtr), *(--stackPtr) ) -# define Nu_LZWStackEmpty() ( stackPtr == lzwState->stack ) +# define Nu_LZWPush(uch) \ + ( Nu_LZWPushCheck(uch, lzwState, stackPtr), *stackPtr++ = (uch) ) +# define Nu_LZWPop() \ + ( Nu_LZWPopCheck(lzwState, stackPtr), *(--stackPtr) ) +# define Nu_LZWStackEmpty() ( stackPtr == lzwState->stack ) static inline void Nu_LZWPushCheck(uchar uch, const LZWExpandState* lzwState,const uchar* stackPtr) { - if (stackPtr >= lzwState->stack + sizeof(lzwState->stack)) { - Nu_ReportError(lzwState->NU_BLOB, kNuErrBadData, "stack overflow"); - abort(); - } + if (stackPtr >= lzwState->stack + sizeof(lzwState->stack)) { + Nu_ReportError(lzwState->NU_BLOB, kNuErrBadData, "stack overflow"); + abort(); + } } static inline void Nu_LZWPopCheck(const LZWExpandState* lzwState, const uchar* stackPtr) { - if (stackPtr == lzwState->stack) { - Nu_ReportError(lzwState->NU_BLOB, kNuErrBadData, "stack underflow"); - abort(); - } + if (stackPtr == lzwState->stack) { + Nu_ReportError(lzwState->NU_BLOB, kNuErrBadData, "stack underflow"); + abort(); + } } #endif @@ -924,45 +924,45 @@ Nu_LZWPopCheck(const LZWExpandState* lzwState, const uchar* stackPtr) static inline uint Nu_LZWGetCode(const uchar** pInBuf, uint entry, int* pAtBit, uint* pLastByte) { - uint numBits, startBit, lastBit; - ulong value; + uint numBits, startBit, lastBit; + ulong value; - Assert(sizeof(uint) >= 2); + Assert(sizeof(uint) >= 2); - numBits = (entry +1) >> 8; /* bit-width of next code */ - startBit = *pAtBit; - lastBit = startBit + gBitWidth[numBits]; + numBits = (entry +1) >> 8; /* bit-width of next code */ + startBit = *pAtBit; + lastBit = startBit + gBitWidth[numBits]; - /* - * We need one or two bytes from the input. These have to be shifted - * around and merged with the bits we already have (if any). - */ - if (!startBit) - value = *(*pInBuf)++; - else - value = *pLastByte; + /* + * We need one or two bytes from the input. These have to be shifted + * around and merged with the bits we already have (if any). + */ + if (!startBit) + value = *(*pInBuf)++; + else + value = *pLastByte; - if (lastBit > 16) { - /* need two more bytes */ - value |= *(*pInBuf)++ << 8; - *pLastByte = *(*pInBuf)++; - value |= (ulong) *pLastByte << 16; - } else { - /* only need one more byte */ - *pLastByte = *(*pInBuf)++; - value |= *pLastByte << 8; - } + if (lastBit > 16) { + /* need two more bytes */ + value |= *(*pInBuf)++ << 8; + *pLastByte = *(*pInBuf)++; + value |= (ulong) *pLastByte << 16; + } else { + /* only need one more byte */ + *pLastByte = *(*pInBuf)++; + value |= *pLastByte << 8; + } - *pAtBit = lastBit & 0x07; + *pAtBit = lastBit & 0x07; - /*printf("| EX: value=$%06lx mask=$%04x return=$%03lx\n", - value,gMaskTable[numBits], (value >> startBit) & gMaskTable[numBits]);*/ + /*printf("| EX: value=$%06lx mask=$%04x return=$%03lx\n", + value,gMaskTable[numBits], (value >> startBit) & gMaskTable[numBits]);*/ - /*DBUG_LZW(("### getcode 0x%04lx\n", - (value >> startBit) & gMaskTable[numBits]));*/ + /*DBUG_LZW(("### getcode 0x%04lx\n", + (value >> startBit) & gMaskTable[numBits]));*/ - /* I believe ANSI allows shifting by zero bits, so don't test "!startBit" */ - return (value >> startBit) & gMaskTable[numBits]; + /* I believe ANSI allows shifting by zero bits, so don't test "!startBit" */ + return (value >> startBit) & gMaskTable[numBits]; } @@ -974,84 +974,84 @@ Nu_LZWGetCode(const uchar** pInBuf, uint entry, int* pAtBit, uint* pLastByte) static NuError Nu_ExpandLZW1(LZWExpandState* lzwState, uint expectedLen) { - NuError err = kNuErrNone; - TableEntry* tablePtr; - int atBit; - uint entry, oldcode, incode, ptr; - uint lastByte, finalc; - const uchar* inbuf; - uchar* outbuf; - uchar* outbufend; - uchar* stackPtr; + NuError err = kNuErrNone; + TableEntry* tablePtr; + int atBit; + uint entry, oldcode, incode, ptr; + uint lastByte, finalc; + const uchar* inbuf; + uchar* outbuf; + uchar* outbufend; + uchar* stackPtr; - Assert(lzwState != nil); - Assert(expectedLen > 0 && expectedLen <= kNuLZWBlockSize); + Assert(lzwState != nil); + Assert(expectedLen > 0 && expectedLen <= kNuLZWBlockSize); - inbuf = lzwState->dataPtr; - outbuf = lzwState->lzwOutBuf; - outbufend = outbuf + expectedLen; - tablePtr = lzwState->trie - 256; /* don't store 256 empties */ - stackPtr = lzwState->stack; + inbuf = lzwState->dataPtr; + outbuf = lzwState->lzwOutBuf; + outbufend = outbuf + expectedLen; + tablePtr = lzwState->trie - 256; /* don't store 256 empties */ + stackPtr = lzwState->stack; - atBit = 0; - lastByte = 0; + atBit = 0; + lastByte = 0; - entry = kNuLZWFirstCode; /* 0x101 */ - finalc = oldcode = incode = Nu_LZWGetCode(&inbuf, entry, &atBit, &lastByte); - *outbuf++ = incode; - Assert(incode <= 0xff); - if (incode > 0xff) { - err = kNuErrBadData; - Nu_ReportError(lzwState->NU_BLOB, err, "invalid initial LZW symbol"); - goto bail; - } + entry = kNuLZWFirstCode; /* 0x101 */ + finalc = oldcode = incode = Nu_LZWGetCode(&inbuf, entry, &atBit, &lastByte); + *outbuf++ = incode; + Assert(incode <= 0xff); + if (incode > 0xff) { + err = kNuErrBadData; + Nu_ReportError(lzwState->NU_BLOB, err, "invalid initial LZW symbol"); + goto bail; + } - while (outbuf < outbufend) { - incode = ptr = Nu_LZWGetCode(&inbuf, entry, &atBit, &lastByte); + while (outbuf < outbufend) { + incode = ptr = Nu_LZWGetCode(&inbuf, entry, &atBit, &lastByte); - /* handle KwKwK case */ - if (ptr >= entry) { - Nu_LZWPush((uchar)finalc); - ptr = oldcode; - } + /* handle KwKwK case */ + if (ptr >= entry) { + Nu_LZWPush((uchar)finalc); + ptr = oldcode; + } - /* fill the stack by chasing up the trie */ - while (ptr > 0xff) { - Nu_LZWPush(tablePtr[ptr].ch); - ptr = tablePtr[ptr].prefix; - Assert(ptr < 4096); - } + /* fill the stack by chasing up the trie */ + while (ptr > 0xff) { + Nu_LZWPush(tablePtr[ptr].ch); + ptr = tablePtr[ptr].prefix; + Assert(ptr < 4096); + } - /* done chasing up, now dump the stack, starting with ptr */ - finalc = ptr; - *outbuf++ = ptr; - /*printf("PUT 0x%02x\n", *(outbuf-1));*/ - while (!Nu_LZWStackEmpty()) { - *outbuf++ = Nu_LZWPop(); - /*printf("POP/PUT 0x%02x\n", *(outbuf-1));*/ - } + /* done chasing up, now dump the stack, starting with ptr */ + finalc = ptr; + *outbuf++ = ptr; + /*printf("PUT 0x%02x\n", *(outbuf-1));*/ + while (!Nu_LZWStackEmpty()) { + *outbuf++ = Nu_LZWPop(); + /*printf("POP/PUT 0x%02x\n", *(outbuf-1));*/ + } - /* add the new prefix to the trie -- last string plus new char */ - Assert(finalc <= 0xff); - tablePtr[entry].ch = finalc; - tablePtr[entry].prefix = oldcode; - entry++; - oldcode = incode; - } + /* add the new prefix to the trie -- last string plus new char */ + Assert(finalc <= 0xff); + tablePtr[entry].ch = finalc; + tablePtr[entry].prefix = oldcode; + entry++; + oldcode = incode; + } bail: - if (outbuf != outbufend) { - err = kNuErrBadData; - Nu_ReportError(lzwState->NU_BLOB, err, "LZW expansion failed"); - return err; - } + if (outbuf != outbufend) { + err = kNuErrBadData; + Nu_ReportError(lzwState->NU_BLOB, err, "LZW expansion failed"); + return err; + } - /* adjust input buffer */ - lzwState->dataInBuffer -= (inbuf - lzwState->dataPtr); - Assert(lzwState->dataInBuffer < 32767*65536); - lzwState->dataPtr = (uchar*)inbuf; + /* adjust input buffer */ + lzwState->dataInBuffer -= (inbuf - lzwState->dataPtr); + Assert(lzwState->dataInBuffer < 32767*65536); + lzwState->dataPtr = (uchar*)inbuf; - return err; + return err; } /* @@ -1063,138 +1063,138 @@ bail: */ static NuError Nu_ExpandLZW2(LZWExpandState* lzwState, uint expectedLen, - uint expectedInputUsed) + uint expectedInputUsed) { - NuError err = kNuErrNone; - TableEntry* tablePtr; - int atBit; - uint entry, oldcode, incode, ptr; - uint lastByte, finalc; - const uchar* inbuf; - const uchar* inbufend; - uchar* outbuf; - uchar* outbufend; - uchar* stackPtr; + NuError err = kNuErrNone; + TableEntry* tablePtr; + int atBit; + uint entry, oldcode, incode, ptr; + uint lastByte, finalc; + const uchar* inbuf; + const uchar* inbufend; + uchar* outbuf; + uchar* outbufend; + uchar* stackPtr; - /*DBUG_LZW(("### LZW/2 block start (compIn=%d, rleOut=%d, entry=0x%04x)\n", - expectedInputUsed, expectedLen, lzwState->entry));*/ - Assert(lzwState != nil); - Assert(expectedLen > 0 && expectedLen <= kNuLZWBlockSize); + /*DBUG_LZW(("### LZW/2 block start (compIn=%d, rleOut=%d, entry=0x%04x)\n", + expectedInputUsed, expectedLen, lzwState->entry));*/ + Assert(lzwState != nil); + Assert(expectedLen > 0 && expectedLen <= kNuLZWBlockSize); - inbuf = lzwState->dataPtr; - inbufend = lzwState->dataPtr + expectedInputUsed; - outbuf = lzwState->lzwOutBuf; - outbufend = outbuf + expectedLen; - entry = lzwState->entry; - tablePtr = lzwState->trie - 256; /* don't store 256 empties */ - stackPtr = lzwState->stack; + inbuf = lzwState->dataPtr; + inbufend = lzwState->dataPtr + expectedInputUsed; + outbuf = lzwState->lzwOutBuf; + outbufend = outbuf + expectedLen; + entry = lzwState->entry; + tablePtr = lzwState->trie - 256; /* don't store 256 empties */ + stackPtr = lzwState->stack; - atBit = 0; - lastByte = 0; + atBit = 0; + lastByte = 0; - /* - * If the table isn't empty, initialize from the saved state and - * jump straight into the main loop. - * - * There's a funny situation that arises when a table clear is the - * second-to-last code in the previous chunk. After we see the - * table clear, we get the next code and use it to initialize "oldcode" - * and "incode" -- but we don't advance "entry" yet. The way that - * ShrinkIt originally worked, the next time we came through we'd - * see what we thought was an empty table and we'd reinitialize. So - * we use "resetFix" to keep track of this situation. - */ - if (entry != kNuLZWFirstCode || lzwState->resetFix) { - /* table not empty */ - oldcode = lzwState->oldcode; - incode = lzwState->incode; - finalc = lzwState->finalc; - lzwState->resetFix = false; - goto main_loop; - } + /* + * If the table isn't empty, initialize from the saved state and + * jump straight into the main loop. + * + * There's a funny situation that arises when a table clear is the + * second-to-last code in the previous chunk. After we see the + * table clear, we get the next code and use it to initialize "oldcode" + * and "incode" -- but we don't advance "entry" yet. The way that + * ShrinkIt originally worked, the next time we came through we'd + * see what we thought was an empty table and we'd reinitialize. So + * we use "resetFix" to keep track of this situation. + */ + if (entry != kNuLZWFirstCode || lzwState->resetFix) { + /* table not empty */ + oldcode = lzwState->oldcode; + incode = lzwState->incode; + finalc = lzwState->finalc; + lzwState->resetFix = false; + goto main_loop; + } clear_table: - /* table is either empty or was just explicitly cleared; reset */ - entry = kNuLZWFirstCode; /* 0x0101 */ - if (outbuf == outbufend) { - /* block must've ended on a table clear */ - DBUG(("--- RARE: ending clear\n")); - /* reset values, mostly to quiet gcc's "used before init" warnings */ - oldcode = incode = finalc = 0; - goto main_loop; /* the while condition will fall through */ - } - finalc = oldcode = incode = Nu_LZWGetCode(&inbuf, entry, &atBit, &lastByte); - *outbuf++ = incode; - /*printf("PUT 0x%02x\n", *(outbuf-1));*/ - if (incode > 0xff) { - err = kNuErrBadData; - Nu_ReportError(lzwState->NU_BLOB, err, "invalid initial LZW symbol"); - goto bail; - } + /* table is either empty or was just explicitly cleared; reset */ + entry = kNuLZWFirstCode; /* 0x0101 */ + if (outbuf == outbufend) { + /* block must've ended on a table clear */ + DBUG(("--- RARE: ending clear\n")); + /* reset values, mostly to quiet gcc's "used before init" warnings */ + oldcode = incode = finalc = 0; + goto main_loop; /* the while condition will fall through */ + } + finalc = oldcode = incode = Nu_LZWGetCode(&inbuf, entry, &atBit, &lastByte); + *outbuf++ = incode; + /*printf("PUT 0x%02x\n", *(outbuf-1));*/ + if (incode > 0xff) { + err = kNuErrBadData; + Nu_ReportError(lzwState->NU_BLOB, err, "invalid initial LZW symbol"); + goto bail; + } - if (outbuf == outbufend) { - /* if we're out of data, raise the "reset fix" flag */ - DBUG(("--- RARE: resetFix!\n")); - lzwState->resetFix = true; - /* fall through; the while condition will let us slip past */ - } + if (outbuf == outbufend) { + /* if we're out of data, raise the "reset fix" flag */ + DBUG(("--- RARE: resetFix!\n")); + lzwState->resetFix = true; + /* fall through; the while condition will let us slip past */ + } main_loop: - while (outbuf < outbufend) { - incode = ptr = Nu_LZWGetCode(&inbuf, entry, &atBit, &lastByte); - /*DBUG_LZW(("### read incode=0x%04x\n", incode));*/ - if (incode == kNuLZWClearCode) /* table clear - 0x0100 */ - goto clear_table; + while (outbuf < outbufend) { + incode = ptr = Nu_LZWGetCode(&inbuf, entry, &atBit, &lastByte); + /*DBUG_LZW(("### read incode=0x%04x\n", incode));*/ + if (incode == kNuLZWClearCode) /* table clear - 0x0100 */ + goto clear_table; - /* handle KwKwK case */ - if (ptr >= entry) { - Nu_LZWPush((uchar)finalc); - ptr = oldcode; - } + /* handle KwKwK case */ + if (ptr >= entry) { + Nu_LZWPush((uchar)finalc); + ptr = oldcode; + } - /* fill the stack by chasing up the trie */ - while (ptr > 0xff) { - Nu_LZWPush(tablePtr[ptr].ch); - ptr = tablePtr[ptr].prefix; - Assert(ptr < 4096); - } + /* fill the stack by chasing up the trie */ + while (ptr > 0xff) { + Nu_LZWPush(tablePtr[ptr].ch); + ptr = tablePtr[ptr].prefix; + Assert(ptr < 4096); + } - /* done chasing up, now dump the stack, starting with ptr */ - finalc = ptr; - *outbuf++ = ptr; - /*printf("PUT 0x%02x\n", *(outbuf-1));*/ - while (!Nu_LZWStackEmpty()) { - *outbuf++ = Nu_LZWPop(); - /*printf("POP/PUT 0x%02x\n", *(outbuf-1));*/ - } + /* done chasing up, now dump the stack, starting with ptr */ + finalc = ptr; + *outbuf++ = ptr; + /*printf("PUT 0x%02x\n", *(outbuf-1));*/ + while (!Nu_LZWStackEmpty()) { + *outbuf++ = Nu_LZWPop(); + /*printf("POP/PUT 0x%02x\n", *(outbuf-1));*/ + } - /* add the new prefix to the trie -- last string plus new char */ - /*DBUG_LZW(("### entry 0x%04x gets prefix=0x%04x and ch=0x%02x\n", - entry, oldcode, finalc));*/ - Assert(finalc <= 0xff); - tablePtr[entry].ch = finalc; - tablePtr[entry].prefix = oldcode; - entry++; - oldcode = incode; - } + /* add the new prefix to the trie -- last string plus new char */ + /*DBUG_LZW(("### entry 0x%04x gets prefix=0x%04x and ch=0x%02x\n", + entry, oldcode, finalc));*/ + Assert(finalc <= 0xff); + tablePtr[entry].ch = finalc; + tablePtr[entry].prefix = oldcode; + entry++; + oldcode = incode; + } bail: - /*DBUG_LZW(("### end of block\n"));*/ - Assert(inbuf == inbufend); - Assert(outbuf == outbufend); + /*DBUG_LZW(("### end of block\n"));*/ + Assert(inbuf == inbufend); + Assert(outbuf == outbufend); - /* adjust input buffer */ - lzwState->dataInBuffer -= (inbuf - lzwState->dataPtr); - Assert(lzwState->dataInBuffer < 32767*65536); - lzwState->dataPtr = (uchar*)inbuf; + /* adjust input buffer */ + lzwState->dataInBuffer -= (inbuf - lzwState->dataPtr); + Assert(lzwState->dataInBuffer < 32767*65536); + lzwState->dataPtr = (uchar*)inbuf; - /* save off local copies of stuff */ - lzwState->entry = entry; - lzwState->oldcode = oldcode; - lzwState->incode = incode; - lzwState->finalc = finalc; + /* save off local copies of stuff */ + lzwState->entry = entry; + lzwState->oldcode = oldcode; + lzwState->incode = incode; + lzwState->finalc = finalc; - return err; + return err; } @@ -1203,47 +1203,47 @@ bail: */ static NuError Nu_ExpandRLE(LZWExpandState* lzwState, const uchar* inbuf, - uint expectedInputUsed) + uint expectedInputUsed) { - NuError err = kNuErrNone; - uchar *outbuf; - uchar *outbufend; - const uchar *inbufend; - uchar uch, rleEscape; - int count; + NuError err = kNuErrNone; + uchar *outbuf; + uchar *outbufend; + const uchar *inbufend; + uchar uch, rleEscape; + int count; - outbuf = lzwState->rleOutBuf; - outbufend = outbuf + kNuLZWBlockSize; - inbufend = inbuf + expectedInputUsed; - rleEscape = lzwState->rleEscape; + outbuf = lzwState->rleOutBuf; + outbufend = outbuf + kNuLZWBlockSize; + inbufend = inbuf + expectedInputUsed; + rleEscape = lzwState->rleEscape; - while (outbuf < outbufend) { - uch = *inbuf++; - if (uch == rleEscape) { - uch = *inbuf++; - count = *inbuf++; - while (count-- >= 0) - *outbuf++ = uch; - } else { - *outbuf++ = uch; - } - } + while (outbuf < outbufend) { + uch = *inbuf++; + if (uch == rleEscape) { + uch = *inbuf++; + count = *inbuf++; + while (count-- >= 0) + *outbuf++ = uch; + } else { + *outbuf++ = uch; + } + } - if (outbuf != outbufend) { - err = kNuErrBadData; - Nu_ReportError(lzwState->NU_BLOB, err, - "RLE output glitch (off by %d)", (int)(outbufend-outbuf)); - goto bail; - } - if (inbuf != inbufend) { - err = kNuErrBadData; - Nu_ReportError(lzwState->NU_BLOB, err, - "RLE input glitch (off by %d)", (int)(inbufend-inbuf)); - goto bail; - } + if (outbuf != outbufend) { + err = kNuErrBadData; + Nu_ReportError(lzwState->NU_BLOB, err, + "RLE output glitch (off by %d)", (int)(outbufend-outbuf)); + goto bail; + } + if (inbuf != inbufend) { + err = kNuErrBadData; + Nu_ReportError(lzwState->NU_BLOB, err, + "RLE input glitch (off by %d)", (int)(inbufend-inbuf)); + goto bail; + } bail: - return err; + return err; } @@ -1253,9 +1253,9 @@ bail: static inline uchar Nu_GetHeaderByte(LZWExpandState* lzwState) { - lzwState->dataInBuffer--; - Assert(lzwState->dataInBuffer > 0); - return *lzwState->dataPtr++; + lzwState->dataInBuffer--; + Assert(lzwState->dataInBuffer > 0); + return *lzwState->dataPtr++; } /* @@ -1270,330 +1270,330 @@ Nu_GetHeaderByte(LZWExpandState* lzwState) */ NuError Nu_ExpandLZW(NuArchive* pArchive, const NuRecord* pRecord, - const NuThread* pThread, FILE* infp, NuFunnel* pFunnel, ushort* pThreadCrc) + const NuThread* pThread, FILE* infp, NuFunnel* pFunnel, ushort* pThreadCrc) { - NuError err = kNuErrNone; - Boolean isType2; - LZWExpandState* lzwState; - ulong compRemaining, uncompRemaining, minSize; + NuError err = kNuErrNone; + Boolean isType2; + LZWExpandState* lzwState; + ulong compRemaining, uncompRemaining, minSize; - Assert(pArchive != nil); - Assert(pThread != nil); - Assert(infp != nil); - Assert(pFunnel != nil); + Assert(pArchive != nil); + Assert(pThread != nil); + Assert(infp != nil); + Assert(pFunnel != nil); - /* - * Do some initialization and set-up. - */ - if (pArchive->lzwExpandState == nil) { - err = Nu_AllocLZWExpandState(pArchive); - BailError(err); - } - Assert(pArchive->lzwExpandState != nil); - Assert(pArchive->compBuf != nil); + /* + * Do some initialization and set-up. + */ + if (pArchive->lzwExpandState == nil) { + err = Nu_AllocLZWExpandState(pArchive); + BailError(err); + } + Assert(pArchive->lzwExpandState != nil); + Assert(pArchive->compBuf != nil); - lzwState = pArchive->lzwExpandState; - lzwState->pArchive = pArchive; + lzwState = pArchive->lzwExpandState; + lzwState->pArchive = pArchive; - if (pThread->thThreadFormat == kNuThreadFormatLZW1) { - isType2 = false; - minSize = 7; /* crc-lo,crc-hi,vol,rle-delim,len-lo,len-hi,lzw-used */ - lzwState->chunkCrc = kNuInitialChunkCRC; /* 0x0000 */ - } else if (pThread->thThreadFormat == kNuThreadFormatLZW2) { - isType2 = true; - minSize = 4; /* vol,rle-delim,len-lo,len-hi */ - } else { - err = kNuErrBadFormat; - goto bail; - } + if (pThread->thThreadFormat == kNuThreadFormatLZW1) { + isType2 = false; + minSize = 7; /* crc-lo,crc-hi,vol,rle-delim,len-lo,len-hi,lzw-used */ + lzwState->chunkCrc = kNuInitialChunkCRC; /* 0x0000 */ + } else if (pThread->thThreadFormat == kNuThreadFormatLZW2) { + isType2 = true; + minSize = 4; /* vol,rle-delim,len-lo,len-hi */ + } else { + err = kNuErrBadFormat; + goto bail; + } - uncompRemaining = pThread->actualThreadEOF; - compRemaining = pThread->thCompThreadEOF; - if (compRemaining < minSize) { - err = kNuErrBadData; - Nu_ReportError(NU_BLOB, err, "thread too short to be valid LZW"); - goto bail; - } - if (compRemaining && !uncompRemaining) { - err = kNuErrBadData; - Nu_ReportError(NU_BLOB, err, - "compressed data but no uncompressed data??"); - goto bail; - } + uncompRemaining = pThread->actualThreadEOF; + compRemaining = pThread->thCompThreadEOF; + if (compRemaining < minSize) { + err = kNuErrBadData; + Nu_ReportError(NU_BLOB, err, "thread too short to be valid LZW"); + goto bail; + } + if (compRemaining && !uncompRemaining) { + err = kNuErrBadData; + Nu_ReportError(NU_BLOB, err, + "compressed data but no uncompressed data??"); + goto bail; + } - /* - * Read the LZW header out of the data stream. - */ - if (!isType2) { - lzwState->fileCrc = getc(infp); - lzwState->fileCrc |= getc(infp) << 8; - compRemaining -= 2; - } - lzwState->diskVol = getc(infp); /* disk volume #; not really used */ - lzwState->rleEscape = getc(infp); /* RLE escape char for this thread */ - compRemaining -= 2; + /* + * Read the LZW header out of the data stream. + */ + if (!isType2) { + lzwState->fileCrc = getc(infp); + lzwState->fileCrc |= getc(infp) << 8; + compRemaining -= 2; + } + lzwState->diskVol = getc(infp); /* disk volume #; not really used */ + lzwState->rleEscape = getc(infp); /* RLE escape char for this thread */ + compRemaining -= 2; - lzwState->dataInBuffer = 0; - lzwState->dataPtr = nil; + lzwState->dataInBuffer = 0; + lzwState->dataPtr = nil; - /* reset pointers */ - lzwState->entry = kNuLZWFirstCode; /* 0x0101 */ - lzwState->resetFix = false; + /* reset pointers */ + lzwState->entry = kNuLZWFirstCode; /* 0x0101 */ + lzwState->resetFix = false; - /*DBUG_LZW(("### LZW%d block, vol=0x%02x, rleEsc=0x%02x\n", - isType2 +1, lzwState->diskVol, lzwState->rleEscape));*/ + /*DBUG_LZW(("### LZW%d block, vol=0x%02x, rleEsc=0x%02x\n", + isType2 +1, lzwState->diskVol, lzwState->rleEscape));*/ - /* - * Read large blocks of the source file into compBuf, taking care not - * to read past the end of the thread data. - * - * The motivation for doing it this way rather than just reading the - * next compressed chunk are (1) compBuf is considerably larger than - * stdio BUFSIZ on most systems, and (2) for LZW/1 we don't know the - * size of the compressed data anyway. - * - * We need to ensure that we have at least one full compressed chunk - * in the buffer. Since the compressor will refuse to store the - * compressed data if it grows, we know that we need 4K plus the - * chunk header. - * - * Once we have what looks like a full chunk, invoke the LZW decoder. - */ - while (uncompRemaining) { - Boolean rleUsed; - Boolean lzwUsed; - ulong getSize; - uint rleLen; /* length after RLE; 4096 if no RLE */ - uint lzwLen = 0; /* type 2 only */ - uint writeLen, inCount; - const uchar* writeBuf; + /* + * Read large blocks of the source file into compBuf, taking care not + * to read past the end of the thread data. + * + * The motivation for doing it this way rather than just reading the + * next compressed chunk are (1) compBuf is considerably larger than + * stdio BUFSIZ on most systems, and (2) for LZW/1 we don't know the + * size of the compressed data anyway. + * + * We need to ensure that we have at least one full compressed chunk + * in the buffer. Since the compressor will refuse to store the + * compressed data if it grows, we know that we need 4K plus the + * chunk header. + * + * Once we have what looks like a full chunk, invoke the LZW decoder. + */ + while (uncompRemaining) { + Boolean rleUsed; + Boolean lzwUsed; + ulong getSize; + uint rleLen; /* length after RLE; 4096 if no RLE */ + uint lzwLen = 0; /* type 2 only */ + uint writeLen, inCount; + const uchar* writeBuf; - /* if we're low, and there's more data available, read more */ - if (lzwState->dataInBuffer < kNuLZWDesiredChunk && compRemaining) { - /* - * First thing we do is slide the old data to the start of - * the buffer. - */ - if (lzwState->dataInBuffer) { - Assert(lzwState->dataPtr != nil); - Assert(pArchive->compBuf != lzwState->dataPtr); - memmove(pArchive->compBuf, lzwState->dataPtr, - lzwState->dataInBuffer); - } - lzwState->dataPtr = pArchive->compBuf; + /* if we're low, and there's more data available, read more */ + if (lzwState->dataInBuffer < kNuLZWDesiredChunk && compRemaining) { + /* + * First thing we do is slide the old data to the start of + * the buffer. + */ + if (lzwState->dataInBuffer) { + Assert(lzwState->dataPtr != nil); + Assert(pArchive->compBuf != lzwState->dataPtr); + memmove(pArchive->compBuf, lzwState->dataPtr, + lzwState->dataInBuffer); + } + lzwState->dataPtr = pArchive->compBuf; - /* - * Next we read as much as we can. - */ - if (kNuGenCompBufSize - lzwState->dataInBuffer < compRemaining) - getSize = kNuGenCompBufSize - lzwState->dataInBuffer; - else - getSize = compRemaining; + /* + * Next we read as much as we can. + */ + if (kNuGenCompBufSize - lzwState->dataInBuffer < compRemaining) + getSize = kNuGenCompBufSize - lzwState->dataInBuffer; + else + getSize = compRemaining; - /*printf("+++ READING %ld\n", getSize);*/ - err = Nu_FRead(infp, lzwState->dataPtr + lzwState->dataInBuffer, - getSize); - if (err != kNuErrNone) - { - Nu_ReportError(NU_BLOB, err, - "failed reading compressed data (%ld bytes)", getSize); - goto bail; - } - lzwState->dataInBuffer += getSize; - compRemaining -= getSize; + /*printf("+++ READING %ld\n", getSize);*/ + err = Nu_FRead(infp, lzwState->dataPtr + lzwState->dataInBuffer, + getSize); + if (err != kNuErrNone) + { + Nu_ReportError(NU_BLOB, err, + "failed reading compressed data (%ld bytes)", getSize); + goto bail; + } + lzwState->dataInBuffer += getSize; + compRemaining -= getSize; - Assert(compRemaining < 32767*65536); - Assert(lzwState->dataInBuffer <= kNuGenCompBufSize); - } - Assert(lzwState->dataInBuffer); + Assert(compRemaining < 32767*65536); + Assert(lzwState->dataInBuffer <= kNuGenCompBufSize); + } + Assert(lzwState->dataInBuffer); - /* - * Read the LZW block header. - */ - if (isType2) { - rleLen = Nu_GetHeaderByte(lzwState); - rleLen |= Nu_GetHeaderByte(lzwState) << 8; - lzwUsed = rleLen & 0x8000 ? true : false; - rleLen &= 0x1fff; - rleUsed = (rleLen != kNuLZWBlockSize); + /* + * Read the LZW block header. + */ + if (isType2) { + rleLen = Nu_GetHeaderByte(lzwState); + rleLen |= Nu_GetHeaderByte(lzwState) << 8; + lzwUsed = rleLen & 0x8000 ? true : false; + rleLen &= 0x1fff; + rleUsed = (rleLen != kNuLZWBlockSize); - if (lzwUsed) { - lzwLen = Nu_GetHeaderByte(lzwState); - lzwLen |= Nu_GetHeaderByte(lzwState) << 8; - lzwLen -= 4; /* don't include header bytes */ - } - } else { - rleLen = Nu_GetHeaderByte(lzwState); - rleLen |= Nu_GetHeaderByte(lzwState) << 8; - lzwUsed = Nu_GetHeaderByte(lzwState); - if (lzwUsed != 0 && lzwUsed != 1) { - err = kNuErrBadData; - Nu_ReportError(NU_BLOB, err, "garbled LZW header"); - goto bail; - } - rleUsed = (rleLen != kNuLZWBlockSize); - } + if (lzwUsed) { + lzwLen = Nu_GetHeaderByte(lzwState); + lzwLen |= Nu_GetHeaderByte(lzwState) << 8; + lzwLen -= 4; /* don't include header bytes */ + } + } else { + rleLen = Nu_GetHeaderByte(lzwState); + rleLen |= Nu_GetHeaderByte(lzwState) << 8; + lzwUsed = Nu_GetHeaderByte(lzwState); + if (lzwUsed != 0 && lzwUsed != 1) { + err = kNuErrBadData; + Nu_ReportError(NU_BLOB, err, "garbled LZW header"); + goto bail; + } + rleUsed = (rleLen != kNuLZWBlockSize); + } - /*DBUG_LZW(("### CHUNK rleLen=%d(%d) lzwLen=%d(%d) uncompRem=%ld\n", - rleLen, rleUsed, lzwLen, lzwUsed, uncompRemaining));*/ + /*DBUG_LZW(("### CHUNK rleLen=%d(%d) lzwLen=%d(%d) uncompRem=%ld\n", + rleLen, rleUsed, lzwLen, lzwUsed, uncompRemaining));*/ - if (uncompRemaining <= kNuLZWBlockSize) - writeLen = uncompRemaining; /* last block */ - else - writeLen = kNuLZWBlockSize; + if (uncompRemaining <= kNuLZWBlockSize) + writeLen = uncompRemaining; /* last block */ + else + writeLen = kNuLZWBlockSize; - #ifndef NDEBUG - writeBuf = nil; - #endif + #ifndef NDEBUG + writeBuf = nil; + #endif - /* - * Decode the chunk, and point "writeBuf" at the uncompressed data. - * - * LZW always expands from the read buffer into lzwState->lzwOutBuf. - * RLE expands from a specific buffer to lzwState->rleOutBuf. - */ - if (lzwUsed) { - if (!isType2) { - err = Nu_ExpandLZW1(lzwState, rleLen); - } else { - Assert(lzwState->dataInBuffer >= lzwLen); - err = Nu_ExpandLZW2(lzwState, rleLen, lzwLen); - } + /* + * Decode the chunk, and point "writeBuf" at the uncompressed data. + * + * LZW always expands from the read buffer into lzwState->lzwOutBuf. + * RLE expands from a specific buffer to lzwState->rleOutBuf. + */ + if (lzwUsed) { + if (!isType2) { + err = Nu_ExpandLZW1(lzwState, rleLen); + } else { + Assert(lzwState->dataInBuffer >= lzwLen); + err = Nu_ExpandLZW2(lzwState, rleLen, lzwLen); + } - BailError(err); + BailError(err); - if (rleUsed) { - err = Nu_ExpandRLE(lzwState, lzwState->lzwOutBuf, rleLen); - BailError(err); - writeBuf = lzwState->rleOutBuf; - } else { - writeBuf = lzwState->lzwOutBuf; - } + if (rleUsed) { + err = Nu_ExpandRLE(lzwState, lzwState->lzwOutBuf, rleLen); + BailError(err); + writeBuf = lzwState->rleOutBuf; + } else { + writeBuf = lzwState->lzwOutBuf; + } - } else { - if (rleUsed) { - err = Nu_ExpandRLE(lzwState, lzwState->dataPtr, rleLen); - BailError(err); - writeBuf = lzwState->rleOutBuf; - inCount = rleLen; - } else { - writeBuf = lzwState->dataPtr; - inCount = writeLen; - } - - /* - * Advance the input buffer data pointers to consume the input. - * The LZW expansion functions do this for us, but we're not - * using LZW. - */ - lzwState->dataPtr += inCount; - lzwState->dataInBuffer -= inCount; - Assert(lzwState->dataInBuffer < 32767*65536); + } else { + if (rleUsed) { + err = Nu_ExpandRLE(lzwState, lzwState->dataPtr, rleLen); + BailError(err); + writeBuf = lzwState->rleOutBuf; + inCount = rleLen; + } else { + writeBuf = lzwState->dataPtr; + inCount = writeLen; + } + + /* + * Advance the input buffer data pointers to consume the input. + * The LZW expansion functions do this for us, but we're not + * using LZW. + */ + lzwState->dataPtr += inCount; + lzwState->dataInBuffer -= inCount; + Assert(lzwState->dataInBuffer < 32767*65536); - /* no LZW used, reset pointers */ - lzwState->entry = kNuLZWFirstCode; /* 0x0101 */ - lzwState->resetFix = false; - } + /* no LZW used, reset pointers */ + lzwState->entry = kNuLZWFirstCode; /* 0x0101 */ + lzwState->resetFix = false; + } - Assert(writeBuf != nil); + Assert(writeBuf != nil); - /* - * Compute the CRC of the uncompressed data, and write it. For - * LZW/1, the CRC of the last block includes the zeros that pad - * it out to 4096 bytes. - * - * See commentary in the compression code for why we have to - * compute two CRCs for LZW/1. - */ - if (isType2) { - if (pThreadCrc != nil) { - *pThreadCrc = Nu_CalcCRC16(*pThreadCrc, writeBuf, writeLen); - } - } else { - if (pThreadCrc != nil) { - *pThreadCrc = Nu_CalcCRC16(*pThreadCrc, writeBuf, - kNuLZWBlockSize); - } - lzwState->chunkCrc = Nu_CalcCRC16(lzwState->chunkCrc, - writeBuf, kNuLZWBlockSize); - } + /* + * Compute the CRC of the uncompressed data, and write it. For + * LZW/1, the CRC of the last block includes the zeros that pad + * it out to 4096 bytes. + * + * See commentary in the compression code for why we have to + * compute two CRCs for LZW/1. + */ + if (isType2) { + if (pThreadCrc != nil) { + *pThreadCrc = Nu_CalcCRC16(*pThreadCrc, writeBuf, writeLen); + } + } else { + if (pThreadCrc != nil) { + *pThreadCrc = Nu_CalcCRC16(*pThreadCrc, writeBuf, + kNuLZWBlockSize); + } + lzwState->chunkCrc = Nu_CalcCRC16(lzwState->chunkCrc, + writeBuf, kNuLZWBlockSize); + } - /* write the data, possibly doing an EOL conversion */ - err = Nu_FunnelWrite(pArchive, pFunnel, writeBuf, writeLen); - if (err != kNuErrNone) { - Nu_ReportError(NU_BLOB, err, "unable to write output"); - goto bail; - } + /* write the data, possibly doing an EOL conversion */ + err = Nu_FunnelWrite(pArchive, pFunnel, writeBuf, writeLen); + if (err != kNuErrNone) { + Nu_ReportError(NU_BLOB, err, "unable to write output"); + goto bail; + } - uncompRemaining -= writeLen; - Assert(uncompRemaining < 32767*65536); - } + uncompRemaining -= writeLen; + Assert(uncompRemaining < 32767*65536); + } - /* - * It appears that ShrinkIt appends an extra byte after the last - * LZW block. The byte is included in the compThreadEOF, but isn't - * consumed by the LZW expansion routine, so it's usually harmless. - * - * It is *possible* for extra bytes to be here legitimately, but very - * unlikely. The very last block is always padded out to 4K with - * zeros. If you found a situation where that last block failed - * to compress with RLE and LZW (perhaps the last block filled up - * all but the last 2 or 3 bytes with uncompressible data), but - * earlier data made the overall file compressible, you would have - * a few stray bytes in the archive. - * - * This is a little easier to do if the last block has lots of single - * 0xdb characters in it, since that requires RLE to escape them. - * - * Whatever the case, issue a warning if it looks like there's too - * many of them. - */ - if (lzwState->dataInBuffer > 1) { - DBUG(("--- Found %ld bytes following compressed data (compRem=%ld)\n", - lzwState->dataInBuffer, compRemaining)); - if (lzwState->dataInBuffer > 32) { - Nu_ReportError(NU_BLOB, kNuErrNone, "(Warning) lots of fluff (%ld)", - lzwState->dataInBuffer); - } - } + /* + * It appears that ShrinkIt appends an extra byte after the last + * LZW block. The byte is included in the compThreadEOF, but isn't + * consumed by the LZW expansion routine, so it's usually harmless. + * + * It is *possible* for extra bytes to be here legitimately, but very + * unlikely. The very last block is always padded out to 4K with + * zeros. If you found a situation where that last block failed + * to compress with RLE and LZW (perhaps the last block filled up + * all but the last 2 or 3 bytes with uncompressible data), but + * earlier data made the overall file compressible, you would have + * a few stray bytes in the archive. + * + * This is a little easier to do if the last block has lots of single + * 0xdb characters in it, since that requires RLE to escape them. + * + * Whatever the case, issue a warning if it looks like there's too + * many of them. + */ + if (lzwState->dataInBuffer > 1) { + DBUG(("--- Found %ld bytes following compressed data (compRem=%ld)\n", + lzwState->dataInBuffer, compRemaining)); + if (lzwState->dataInBuffer > 32) { + Nu_ReportError(NU_BLOB, kNuErrNone, "(Warning) lots of fluff (%ld)", + lzwState->dataInBuffer); + } + } - /* - * We might be okay with stray bytes in the thread, but we're definitely - * not okay with anything identified as compressed data being unused. - */ - if (compRemaining) { - err = kNuErrBadData; - Nu_ReportError(NU_BLOB, err, - "not all compressed data was used (%ld/%ld)", - compRemaining, lzwState->dataInBuffer); - goto bail; - } + /* + * We might be okay with stray bytes in the thread, but we're definitely + * not okay with anything identified as compressed data being unused. + */ + if (compRemaining) { + err = kNuErrBadData; + Nu_ReportError(NU_BLOB, err, + "not all compressed data was used (%ld/%ld)", + compRemaining, lzwState->dataInBuffer); + goto bail; + } - /* - * ShrinkIt used to put the CRC in the stream and not in the thread - * header. For LZW/1, we check the CRC here; for LZW/2, we hope it's - * in the thread header. (As noted in the compression code, it's - * possible to end up with two CRCs or no CRCs.) - */ - if (!isType2 && !pArchive->valIgnoreCRC) { - if (lzwState->chunkCrc != lzwState->fileCrc) { - if (!Nu_ShouldIgnoreBadCRC(pArchive, pRecord, kNuErrBadDataCRC)) { - err = kNuErrBadDataCRC; - Nu_ReportError(NU_BLOB, err, - "expected 0x%04x, got 0x%04x (LZW/1)", - lzwState->fileCrc, lzwState->chunkCrc); - (void) Nu_FunnelFlush(pArchive, pFunnel); - goto bail; - } - } else { - DBUG(("--- LZW/1 CRCs match (0x%04x)\n", lzwState->chunkCrc)); - } - } + /* + * ShrinkIt used to put the CRC in the stream and not in the thread + * header. For LZW/1, we check the CRC here; for LZW/2, we hope it's + * in the thread header. (As noted in the compression code, it's + * possible to end up with two CRCs or no CRCs.) + */ + if (!isType2 && !pArchive->valIgnoreCRC) { + if (lzwState->chunkCrc != lzwState->fileCrc) { + if (!Nu_ShouldIgnoreBadCRC(pArchive, pRecord, kNuErrBadDataCRC)) { + err = kNuErrBadDataCRC; + Nu_ReportError(NU_BLOB, err, + "expected 0x%04x, got 0x%04x (LZW/1)", + lzwState->fileCrc, lzwState->chunkCrc); + (void) Nu_FunnelFlush(pArchive, pFunnel); + goto bail; + } + } else { + DBUG(("--- LZW/1 CRCs match (0x%04x)\n", lzwState->chunkCrc)); + } + } bail: - if (err == kNuErrNone) - err = Nu_FunnelFlush(pArchive, pFunnel); + if (err == kNuErrNone) + err = Nu_FunnelFlush(pArchive, pFunnel); - return err; + return err; } diff --git a/nufxlib-0/MiscStuff.c b/nufxlib-0/MiscStuff.c index a14af3f..ce94151 100644 --- a/nufxlib-0/MiscStuff.c +++ b/nufxlib-0/MiscStuff.c @@ -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 diff --git a/nufxlib-0/MiscStuff.h b/nufxlib-0/MiscStuff.h index 1f35ea0..5455fad 100644 --- a/nufxlib-0/MiscStuff.h +++ b/nufxlib-0/MiscStuff.h @@ -42,11 +42,11 @@ int Nu_strncasecmp(const char *s1, const char *s2, size_t n); #include -#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__*/ diff --git a/nufxlib-0/MiscUtils.c b/nufxlib-0/MiscUtils.c index 00c8d3f..f2ffbda 100644 --- a/nufxlib-0/MiscUtils.c +++ b/nufxlib-0/MiscUtils.c @@ -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 diff --git a/nufxlib-0/NufxLib.h b/nufxlib-0/NufxLib.h index 502957a..b92bf27 100644 --- a/nufxlib-0/NufxLib.h +++ b/nufxlib-0/NufxLib.h @@ -18,7 +18,7 @@ extern "C" { /* * =========================================================================== - * Types + * Types * =========================================================================== */ @@ -29,93 +29,93 @@ extern "C" { * errors (like ENOENT). A NuError can hold either. */ typedef enum NuError { - kNuErrNone = 0, + kNuErrNone = 0, - kNuErrGeneric = -1, - kNuErrInternal = -2, - kNuErrUsage = -3, - kNuErrSyntax = -4, - kNuErrMalloc = -5, - kNuErrInvalidArg = -6, - kNuErrBadStruct = -7, - kNuErrUnexpectedNil = -8, - kNuErrBusy = -9, + kNuErrGeneric = -1, + kNuErrInternal = -2, + kNuErrUsage = -3, + kNuErrSyntax = -4, + kNuErrMalloc = -5, + kNuErrInvalidArg = -6, + kNuErrBadStruct = -7, + kNuErrUnexpectedNil = -8, + kNuErrBusy = -9, - kNuErrSkipped = -10, /* processing skipped by request */ - kNuErrAborted = -11, /* processing aborted by request */ - kNuErrRename = -12, /* user wants to rename before extracting */ + kNuErrSkipped = -10, /* processing skipped by request */ + kNuErrAborted = -11, /* processing aborted by request */ + kNuErrRename = -12, /* user wants to rename before extracting */ - kNuErrFile = -20, - kNuErrFileOpen = -21, - kNuErrFileClose = -22, - kNuErrFileRead = -23, - kNuErrFileWrite = -24, - kNuErrFileSeek = -25, - kNuErrFileExists = -26, /* existed when it shouldn't */ - kNuErrFileNotFound = -27, /* didn't exist when it should have */ - kNuErrFileStat = -28, /* some sort of GetFileInfo failure */ - kNuErrFileNotReadable = -29, /* bad access permissions */ + kNuErrFile = -20, + kNuErrFileOpen = -21, + kNuErrFileClose = -22, + kNuErrFileRead = -23, + kNuErrFileWrite = -24, + kNuErrFileSeek = -25, + kNuErrFileExists = -26, /* existed when it shouldn't */ + kNuErrFileNotFound = -27, /* didn't exist when it should have */ + kNuErrFileStat = -28, /* some sort of GetFileInfo failure */ + kNuErrFileNotReadable = -29, /* bad access permissions */ - kNuErrDirExists = -30, /* dir exists, don't need to create it */ - kNuErrNotDir = -31, /* expected a dir, got a regular file */ - kNuErrNotRegularFile = -32, /* expected regular file, got weirdness */ - kNuErrDirCreate = -33, /* unable to create a directory */ - kNuErrOpenDir = -34, /* error opening directory */ - kNuErrReadDir = -35, /* error reading directory */ - kNuErrFileSetDate = -36, /* unable to set file date */ - kNuErrFileSetAccess = -37, /* unable to set file access permissions */ + kNuErrDirExists = -30, /* dir exists, don't need to create it */ + kNuErrNotDir = -31, /* expected a dir, got a regular file */ + kNuErrNotRegularFile = -32, /* expected regular file, got weirdness */ + kNuErrDirCreate = -33, /* unable to create a directory */ + kNuErrOpenDir = -34, /* error opening directory */ + kNuErrReadDir = -35, /* error reading directory */ + kNuErrFileSetDate = -36, /* unable to set file date */ + kNuErrFileSetAccess = -37, /* unable to set file access permissions */ - kNuErrNotNuFX = -40, /* 'NuFile' missing; not a NuFX archive? */ - kNuErrBadMHVersion = -41, /* bad master header version */ - kNuErrRecHdrNotFound = -42, /* 'NuFX' missing; corrupted archive? */ - kNuErrNoRecords = -43, /* archive doesn't have any records */ - kNuErrBadRecord = -44, /* something about the record looked bad */ - kNuErrBadMHCRC = -45, /* bad master header CRC */ - kNuErrBadRHCRC = -46, /* bad record header CRC */ - kNuErrBadThreadCRC = -47, /* bad thread header CRC */ - kNuErrBadDataCRC = -48, /* bad CRC detected in the data */ + kNuErrNotNuFX = -40, /* 'NuFile' missing; not a NuFX archive? */ + kNuErrBadMHVersion = -41, /* bad master header version */ + kNuErrRecHdrNotFound = -42, /* 'NuFX' missing; corrupted archive? */ + kNuErrNoRecords = -43, /* archive doesn't have any records */ + kNuErrBadRecord = -44, /* something about the record looked bad */ + kNuErrBadMHCRC = -45, /* bad master header CRC */ + kNuErrBadRHCRC = -46, /* bad record header CRC */ + kNuErrBadThreadCRC = -47, /* bad thread header CRC */ + kNuErrBadDataCRC = -48, /* bad CRC detected in the data */ - kNuErrBadFormat = -50, /* compression type not supported */ - kNuErrBadData = -51, /* expansion func didn't like input */ - kNuErrBufferOverrun = -52, /* overflowed a user buffer */ - kNuErrBufferUnderrun = -53, /* underflowed a user buffer */ - kNuErrOutMax = -54, /* output limit exceeded */ + kNuErrBadFormat = -50, /* compression type not supported */ + kNuErrBadData = -51, /* expansion func didn't like input */ + kNuErrBufferOverrun = -52, /* overflowed a user buffer */ + kNuErrBufferUnderrun = -53, /* underflowed a user buffer */ + kNuErrOutMax = -54, /* output limit exceeded */ - kNuErrNotFound = -60, /* (generic) search unsuccessful */ - kNuErrRecordNotFound = -61, /* search for specific record failed */ - kNuErrRecIdxNotFound = -62, /* search by NuRecordIdx failed */ - kNuErrThreadIdxNotFound = -63, /* search by NuThreadIdx failed */ - kNuErrThreadIDNotFound = -64, /* search by NuThreadID failed */ - kNuErrRecNameNotFound = -65, /* search by storageName failed */ - kNuErrRecordExists = -66, /* found existing record with same name */ + kNuErrNotFound = -60, /* (generic) search unsuccessful */ + kNuErrRecordNotFound = -61, /* search for specific record failed */ + kNuErrRecIdxNotFound = -62, /* search by NuRecordIdx failed */ + kNuErrThreadIdxNotFound = -63, /* search by NuThreadIdx failed */ + kNuErrThreadIDNotFound = -64, /* search by NuThreadID failed */ + kNuErrRecNameNotFound = -65, /* search by storageName failed */ + kNuErrRecordExists = -66, /* found existing record with same name */ - kNuErrAllDeleted = -70, /* attempt to delete everything */ - kNuErrArchiveRO = -71, /* archive is open in read-only mode */ - kNuErrModRecChange = -72, /* tried to change modified record */ - kNuErrModThreadChange = -73, /* tried to change modified thread */ - kNuErrThreadAdd = -74, /* adding that thread creates a conflict */ - kNuErrNotPreSized = -75, /* tried to update a non-pre-sized thread */ - kNuErrPreSizeOverflow = -76, /* too much data */ - kNuErrInvalidFilename = -77, /* invalid filename */ + kNuErrAllDeleted = -70, /* attempt to delete everything */ + kNuErrArchiveRO = -71, /* archive is open in read-only mode */ + kNuErrModRecChange = -72, /* tried to change modified record */ + kNuErrModThreadChange = -73, /* tried to change modified thread */ + kNuErrThreadAdd = -74, /* adding that thread creates a conflict */ + kNuErrNotPreSized = -75, /* tried to update a non-pre-sized thread */ + kNuErrPreSizeOverflow = -76, /* too much data */ + kNuErrInvalidFilename = -77, /* invalid filename */ - kNuErrLeadingFssep = -80, /* names in archives must not start w/sep */ - kNuErrNotNewer = -81, /* item same age or older than existing */ - kNuErrDuplicateNotFound = -82, /* "must overwrite" was set, but item DNE */ - kNuErrDamaged = -83 /* original archive may have been damaged */ + kNuErrLeadingFssep = -80, /* names in archives must not start w/sep */ + kNuErrNotNewer = -81, /* item same age or older than existing */ + kNuErrDuplicateNotFound = -82, /* "must overwrite" was set, but item DNE */ + kNuErrDamaged = -83 /* original archive may have been damaged */ } NuError; /* * Return values from callback functions. */ typedef enum NuResult { - kNuOK = 0, - kNuSkip = 1, - kNuAbort = 2, - /*kNuAbortAll = 3,*/ - kNuRetry = 4, - kNuIgnore = 5, - kNuRename = 6, - kNuOverwrite = 7 + kNuOK = 0, + kNuSkip = 1, + kNuAbort = 2, + /*kNuAbortAll = 3,*/ + kNuRetry = 4, + kNuIgnore = 5, + kNuRename = 6, + kNuOverwrite = 7 } NuResult; /* @@ -135,78 +135,78 @@ typedef unsigned long NuThreadIdx; * values have explicit identifiers. */ typedef unsigned long NuThreadID; -#define NuMakeThreadID(class, kind) /* construct a NuThreadID */ \ - ((unsigned long)class << 16 | (unsigned long)kind) -#define NuGetThreadID(pThread) /* pull NuThreadID out of NuThread */ \ - (NuMakeThreadID(pThread->thThreadClass, pThread->thThreadKind)) +#define NuMakeThreadID(class, kind) /* construct a NuThreadID */ \ + ((unsigned long)class << 16 | (unsigned long)kind) +#define NuGetThreadID(pThread) /* pull NuThreadID out of NuThread */ \ + (NuMakeThreadID(pThread->thThreadClass, pThread->thThreadKind)) #define NuThreadIDGetClass(threadID) /* get threadClass from NuThreadID */ \ - ((unsigned short) ((unsigned long)(threadID) >> 16)) + ((unsigned short) ((unsigned long)(threadID) >> 16)) #define NuThreadIDGetKind(threadID) /* get threadKind from NuThreadID */ \ - ((unsigned short) ((threadID) & 0xffff)) -#define kNuThreadClassMessage 0x0000 -#define kNuThreadClassControl 0x0001 -#define kNuThreadClassData 0x0002 -#define kNuThreadClassFilename 0x0003 -#define kNuThreadIDOldComment NuMakeThreadID(kNuThreadClassMessage, 0x0000) -#define kNuThreadIDComment NuMakeThreadID(kNuThreadClassMessage, 0x0001) -#define kNuThreadIDIcon NuMakeThreadID(kNuThreadClassMessage, 0x0002) -#define kNuThreadIDMkdir NuMakeThreadID(kNuThreadClassControl, 0x0000) -#define kNuThreadIDDataFork NuMakeThreadID(kNuThreadClassData, 0x0000) -#define kNuThreadIDDiskImage NuMakeThreadID(kNuThreadClassData, 0x0001) -#define kNuThreadIDRsrcFork NuMakeThreadID(kNuThreadClassData, 0x0002) -#define kNuThreadIDFilename NuMakeThreadID(kNuThreadClassFilename, 0x0000) -#define kNuThreadIDWildcard NuMakeThreadID(0xffff, 0xffff) + ((unsigned short) ((threadID) & 0xffff)) +#define kNuThreadClassMessage 0x0000 +#define kNuThreadClassControl 0x0001 +#define kNuThreadClassData 0x0002 +#define kNuThreadClassFilename 0x0003 +#define kNuThreadIDOldComment NuMakeThreadID(kNuThreadClassMessage, 0x0000) +#define kNuThreadIDComment NuMakeThreadID(kNuThreadClassMessage, 0x0001) +#define kNuThreadIDIcon NuMakeThreadID(kNuThreadClassMessage, 0x0002) +#define kNuThreadIDMkdir NuMakeThreadID(kNuThreadClassControl, 0x0000) +#define kNuThreadIDDataFork NuMakeThreadID(kNuThreadClassData, 0x0000) +#define kNuThreadIDDiskImage NuMakeThreadID(kNuThreadClassData, 0x0001) +#define kNuThreadIDRsrcFork NuMakeThreadID(kNuThreadClassData, 0x0002) +#define kNuThreadIDFilename NuMakeThreadID(kNuThreadClassFilename, 0x0000) +#define kNuThreadIDWildcard NuMakeThreadID(0xffff, 0xffff) /* enumerate the possible values for thThreadFormat */ typedef enum NuThreadFormat { - kNuThreadFormatUncompressed = 0x0000, - kNuThreadFormatHuffmanSQ = 0x0001, - kNuThreadFormatLZW1 = 0x0002, - kNuThreadFormatLZW2 = 0x0003, - kNuThreadFormatLZC12 = 0x0004, - kNuThreadFormatLZC16 = 0x0005 + kNuThreadFormatUncompressed = 0x0000, + kNuThreadFormatHuffmanSQ = 0x0001, + kNuThreadFormatLZW1 = 0x0002, + kNuThreadFormatLZW2 = 0x0003, + kNuThreadFormatLZC12 = 0x0004, + kNuThreadFormatLZC16 = 0x0005 } NuThreadFormat; /* extract the filesystem separator char from the "file_sys_info" field */ #define NuGetSepFromSysInfo(sysInfo) \ - ((char) ((sysInfo) & 0xff)) + ((char) ((sysInfo) & 0xff)) /* return a file_sys_info with a replaced filesystem separator */ #define NuSetSepInSysInfo(sysInfo, newSep) \ - ((ushort) (((sysInfo) & 0xff00) | ((newSep) & 0xff)) ) + ((ushort) (((sysInfo) & 0xff00) | ((newSep) & 0xff)) ) /* GS/OS-defined file system identifiers; sadly, UNIX is not among them */ typedef enum NuFileSysID { - kNuFileSysUnknown = 0, /* NuFX spec says use this */ - kNuFileSysProDOS = 1, - kNuFileSysDOS33 = 2, - kNuFileSysDOS32 = 3, - kNuFileSysPascal = 4, - kNuFileSysMacHFS = 5, - kNuFileSysMacMFS = 6, - kNuFileSysLisa = 7, - kNuFileSysCPM = 8, - kNuFileSysCharFST = 9, - kNuFileSysMSDOS = 10, - kNuFileSysHighSierra = 11, - kNuFileSysISO9660 = 12, - kNuFileSysAppleShare = 13 + kNuFileSysUnknown = 0, /* NuFX spec says use this */ + kNuFileSysProDOS = 1, + kNuFileSysDOS33 = 2, + kNuFileSysDOS32 = 3, + kNuFileSysPascal = 4, + kNuFileSysMacHFS = 5, + kNuFileSysMacMFS = 6, + kNuFileSysLisa = 7, + kNuFileSysCPM = 8, + kNuFileSysCharFST = 9, + kNuFileSysMSDOS = 10, + kNuFileSysHighSierra = 11, + kNuFileSysISO9660 = 12, + kNuFileSysAppleShare = 13 } NuFileSysID; /* simplified definition of storage types */ typedef enum NuStorageType { - kNuStorageUnknown = 0, - kNuStorageSeedling = 1, /* <= 512 bytes */ - kNuStorageSapling = 2, /* < 128KB */ - kNuStorageTree = 3, /* < 16MB */ - kNuStorageExtended = 5, /* forked (any size) */ - kNuStorageDirectory = 0x0d + kNuStorageUnknown = 0, + kNuStorageSeedling = 1, /* <= 512 bytes */ + kNuStorageSapling = 2, /* < 128KB */ + kNuStorageTree = 3, /* < 16MB */ + kNuStorageExtended = 5, /* forked (any size) */ + kNuStorageDirectory = 0x0d } NuStorageType; /* flags for NuOpenRW */ enum { - kNuOpenCreat = 0x0001, - kNuOpenExcl = 0x0002 + kNuOpenCreat = 0x0001, + kNuOpenExcl = 0x0002 }; @@ -225,17 +225,17 @@ typedef NuResult (*NuCallback)(NuArchive* pArchive, void* args); * Parameters that affect archive operations. */ typedef enum NuValueID { - kNuValueInvalid = 0, - kNuValueIgnoreCRC = 1, - kNuValueDataCompression = 2, - kNuValueDiscardWrapper = 3, - kNuValueEOL = 4, - kNuValueConvertExtractedEOL = 5, - kNuValueOnlyUpdateOlder = 6, - kNuValueAllowDuplicates = 7, - kNuValueHandleExisting = 8, - kNuValueModifyOrig = 9, - kNuValueMimicSHK = 10 + kNuValueInvalid = 0, + kNuValueIgnoreCRC = 1, + kNuValueDataCompression = 2, + kNuValueDiscardWrapper = 3, + kNuValueEOL = 4, + kNuValueConvertExtractedEOL = 5, + kNuValueOnlyUpdateOlder = 6, + kNuValueAllowDuplicates = 7, + kNuValueHandleExisting = 8, + kNuValueModifyOrig = 9, + kNuValueMimicSHK = 10 } NuValueID; typedef unsigned long NuValue; @@ -243,34 +243,34 @@ typedef unsigned long NuValue; * Enumerated values for things you pass in a NuValue. */ enum NuValueValue { - /* for the truly retentive */ - kNuValueFalse = 0, - kNuValueTrue = 1, + /* for the truly retentive */ + kNuValueFalse = 0, + kNuValueTrue = 1, - /* for kNuValueDataCompression */ - kNuCompressNone = 10, - kNuCompressSQ = 11, - kNuCompressLZW1 = 12, - kNuCompressLZW2 = 13, - kNuCompressLZC12 = 14, - kNuCompressLZC16 = 15, + /* for kNuValueDataCompression */ + kNuCompressNone = 10, + kNuCompressSQ = 11, + kNuCompressLZW1 = 12, + kNuCompressLZW2 = 13, + kNuCompressLZC12 = 14, + kNuCompressLZC16 = 15, - /* for kNuValueEOL */ - kNuEOLUnknown = 50, - kNuEOLCR = 51, - kNuEOLLF = 52, - kNuEOLCRLF = 53, + /* for kNuValueEOL */ + kNuEOLUnknown = 50, + kNuEOLCR = 51, + kNuEOLLF = 52, + kNuEOLCRLF = 53, - /* for kNuValueConvertExtractedEOL */ - kNuConvertOff = 60, - kNuConvertOn = 61, - kNuConvertAuto = 62, + /* for kNuValueConvertExtractedEOL */ + kNuConvertOff = 60, + kNuConvertOn = 61, + kNuConvertAuto = 62, - /* for kNuValueHandleExisting */ - kNuMaybeOverwrite = 90, - kNuNeverOverwrite = 91, - kNuAlwaysOverwrite = 93, - kNuMustOverwrite = 94 + /* for kNuValueHandleExisting */ + kNuMaybeOverwrite = 90, + kNuNeverOverwrite = 91, + kNuAlwaysOverwrite = 93, + kNuMustOverwrite = 94 }; @@ -278,9 +278,9 @@ enum NuValueValue { * Pull out archive attributes. */ typedef enum NuAttrID { - kNuAttrInvalid = 0, - kNuAttrArchiveType = 1, - kNuAttrNumRecords = 2 + kNuAttrInvalid = 0, + kNuAttrArchiveType = 1, + kNuAttrNumRecords = 2 } NuAttrID; typedef unsigned long NuAttr; @@ -288,13 +288,13 @@ typedef unsigned long NuAttr; * Archive types. */ typedef enum NuArchiveType { - kNuArchiveUnknown, /* .??? */ - kNuArchiveNuFX, /* .SHK (sometimes .SDK) */ - kNuArchiveNuFXInBNY, /* .BXY */ - kNuArchiveNuFXSelfEx, /* .SEA */ - kNuArchiveNuFXSelfExInBNY, /* .BSE */ + kNuArchiveUnknown, /* .??? */ + kNuArchiveNuFX, /* .SHK (sometimes .SDK) */ + kNuArchiveNuFXInBNY, /* .BXY */ + kNuArchiveNuFXSelfEx, /* .SEA */ + kNuArchiveNuFXSelfExInBNY, /* .BSE */ - kNuArchiveBNY /* .BNY, .BQY - not supported */ + kNuArchiveBNY /* .BNY, .BQY - not supported */ } NuArchiveType; @@ -303,120 +303,120 @@ typedef enum NuArchiveType { * can be set independently, so don't use these defines to *interpret* * what you see. They're reasonable things to *set* the access field to. */ -#define kNuAccessLocked 0x21 -#define kNuAccessUnlocked 0xe3 +#define kNuAccessLocked 0x21 +#define kNuAccessUnlocked 0xe3 /* * NuFlush result flags. */ -#define kNuFlushSucceeded (1L) -#define kNuFlushAborted (1L << 1) -#define kNuFlushCorrupted (1L << 2) -#define kNuFlushReadOnly (1L << 3) -#define kNuFlushInaccessible (1L << 4) +#define kNuFlushSucceeded (1L) +#define kNuFlushAborted (1L << 1) +#define kNuFlushCorrupted (1L << 2) +#define kNuFlushReadOnly (1L << 3) +#define kNuFlushInaccessible (1L << 4) /* * =========================================================================== - * NuFX archive defintions + * NuFX archive defintions * =========================================================================== */ -typedef struct NuThreadMod NuThreadMod; /* dummy def for internal struct */ -typedef union NuDataSource NuDataSource; /* dummy def for internal struct */ -typedef union NuDataSink NuDataSink; /* dummy def for internal struct */ +typedef struct NuThreadMod NuThreadMod; /* dummy def for internal struct */ +typedef union NuDataSource NuDataSource; /* dummy def for internal struct */ +typedef union NuDataSink NuDataSink; /* dummy def for internal struct */ /* * NuFX Date/Time structure; same as TimeRec from IIgs "misctool.h". */ typedef struct NuDateTime { - unsigned char second; - unsigned char minute; - unsigned char hour; - unsigned char year; - unsigned char day; - unsigned char month; - unsigned char extra; - unsigned char weekDay; + unsigned char second; + unsigned char minute; + unsigned char hour; + unsigned char year; + unsigned char day; + unsigned char month; + unsigned char extra; + unsigned char weekDay; } NuDateTime; /* * NuFX "thread" definition. */ typedef struct NuThread { - /* from the archive */ - unsigned short thThreadClass; - NuThreadFormat thThreadFormat; - unsigned short thThreadKind; - unsigned short thThreadCRC; /* comp or uncomp data; see rec vers */ - unsigned long thThreadEOF; - unsigned long thCompThreadEOF; + /* from the archive */ + unsigned short thThreadClass; + NuThreadFormat thThreadFormat; + unsigned short thThreadKind; + unsigned short thThreadCRC; /* comp or uncomp data; see rec vers */ + unsigned long thThreadEOF; + unsigned long thCompThreadEOF; - /* extra goodies */ - NuThreadIdx threadIdx; - unsigned long actualThreadEOF; /* disk images might be off */ - long fileOffset; /* fseek offset to data in file */ + /* extra goodies */ + NuThreadIdx threadIdx; + unsigned long actualThreadEOF; /* disk images might be off */ + long fileOffset; /* fseek offset to data in file */ - /* internal use only */ - unsigned short used; /* mark as uninteresting */ + /* internal use only */ + unsigned short used; /* mark as uninteresting */ } NuThread; /* * NuFX "record" definition. */ -#define kNufxIDLen 4 /* len of 'NuFX' with funky MSBs */ -#define kNuReasonableAttribCount 256 -#define kNuReasonableFilenameLen 1024 -#define kNuReasonableTotalThreads 16 -#define kNuMaxRecordVersion 3 /* max we can handle */ -#define kNuOurRecordVersion 3 /* what we write */ +#define kNufxIDLen 4 /* len of 'NuFX' with funky MSBs */ +#define kNuReasonableAttribCount 256 +#define kNuReasonableFilenameLen 1024 +#define kNuReasonableTotalThreads 16 +#define kNuMaxRecordVersion 3 /* max we can handle */ +#define kNuOurRecordVersion 3 /* what we write */ typedef struct NuRecord { - /* version 0+ */ - unsigned char recNufxID[kNufxIDLen]; - unsigned short recHeaderCRC; - unsigned short recAttribCount; - unsigned short recVersionNumber; - unsigned long recTotalThreads; - NuFileSysID recFileSysID; - unsigned short recFileSysInfo; - unsigned long recAccess; - unsigned long recFileType; - unsigned long recExtraType; - unsigned short recStorageType; /* NuStorage*,file_sys_block_size */ - NuDateTime recCreateWhen; - NuDateTime recModWhen; - NuDateTime recArchiveWhen; + /* version 0+ */ + unsigned char recNufxID[kNufxIDLen]; + unsigned short recHeaderCRC; + unsigned short recAttribCount; + unsigned short recVersionNumber; + unsigned long recTotalThreads; + NuFileSysID recFileSysID; + unsigned short recFileSysInfo; + unsigned long recAccess; + unsigned long recFileType; + unsigned long recExtraType; + unsigned short recStorageType; /* NuStorage*,file_sys_block_size */ + NuDateTime recCreateWhen; + NuDateTime recModWhen; + NuDateTime recArchiveWhen; - /* option lists only in version 1+ */ - unsigned short recOptionSize; - unsigned char* recOptionList; /* NULL if v0 or recOptionSize==0 */ + /* option lists only in version 1+ */ + unsigned short recOptionSize; + unsigned char* recOptionList; /* NULL if v0 or recOptionSize==0 */ - /* data specified by recAttribCount, not accounted for by option list */ - long extraCount; - unsigned char* extraBytes; + /* data specified by recAttribCount, not accounted for by option list */ + long extraCount; + unsigned char* extraBytes; - unsigned short recFilenameLength; /* usually zero */ - char* recFilename; /* doubles as disk volume_name */ + unsigned short recFilenameLength; /* usually zero */ + char* recFilename; /* doubles as disk volume_name */ - /* extra goodies; "dirtyHeader" does not apply to anything below */ - NuRecordIdx recordIdx; /* session-unique record index */ - char* threadFilename; /* extracted from filename thread */ - char* newFilename; /* memorized during "add file" call */ - const char* filename; /* points at recFilen or threadFilen */ - unsigned long recHeaderLength; /* size of rec hdr, incl thread hdrs */ - unsigned long totalCompLength; /* total len of data in archive file */ + /* extra goodies; "dirtyHeader" does not apply to anything below */ + NuRecordIdx recordIdx; /* session-unique record index */ + char* threadFilename; /* extracted from filename thread */ + char* newFilename; /* memorized during "add file" call */ + const char* filename; /* points at recFilen or threadFilen */ + unsigned long recHeaderLength; /* size of rec hdr, incl thread hdrs */ + unsigned long totalCompLength; /* total len of data in archive file */ - long fileOffset; /* file offset of record header */ + long fileOffset; /* file offset of record header */ - /* use provided interface to access this */ - struct NuThread* pThreads; /* ptr to thread array */ + /* use provided interface to access this */ + struct NuThread* pThreads; /* ptr to thread array */ - /* private -- things the application shouldn't look at */ - struct NuRecord* pNext; /* used internally */ - NuThreadMod* pThreadMods; /* used internally */ - short dirtyHeader; /* set in "copy" when hdr fields uptd */ - short dropRecFilename; /* if set, we're dropping this name */ + /* private -- things the application shouldn't look at */ + struct NuRecord* pNext; /* used internally */ + NuThreadMod* pThreadMods; /* used internally */ + short dirtyHeader; /* set in "copy" when hdr fields uptd */ + short dropRecFilename; /* if set, we're dropping this name */ } NuRecord; /* @@ -425,30 +425,30 @@ typedef struct NuRecord { * The "mhReserved2" entry doesn't appear in my copy of the $e0/8002 File * Type Note, but as best as I can recall the MH block must be 48 bytes. */ -#define kNufileIDLen 6 /* length of 'NuFile' with funky MSBs */ -#define kNufileMasterReserved1Len 8 -#define kNufileMasterReserved2Len 6 -#define kNuMaxMHVersion 2 /* max we can handle */ -#define kNuOurMHVersion 2 /* what we write */ +#define kNufileIDLen 6 /* length of 'NuFile' with funky MSBs */ +#define kNufileMasterReserved1Len 8 +#define kNufileMasterReserved2Len 6 +#define kNuMaxMHVersion 2 /* max we can handle */ +#define kNuOurMHVersion 2 /* what we write */ typedef struct NuMasterHeader { - unsigned char mhNufileID[kNufileIDLen]; - unsigned short mhMasterCRC; - unsigned long mhTotalRecords; - NuDateTime mhArchiveCreateWhen; - NuDateTime mhArchiveModWhen; - unsigned short mhMasterVersion; - unsigned char mhReserved1[kNufileMasterReserved1Len]; - unsigned long mhMasterEOF; - unsigned char mhReserved2[kNufileMasterReserved2Len]; + unsigned char mhNufileID[kNufileIDLen]; + unsigned short mhMasterCRC; + unsigned long mhTotalRecords; + NuDateTime mhArchiveCreateWhen; + NuDateTime mhArchiveModWhen; + unsigned short mhMasterVersion; + unsigned char mhReserved1[kNufileMasterReserved1Len]; + unsigned long mhMasterEOF; + unsigned char mhReserved2[kNufileMasterReserved2Len]; - /* private -- internal use only */ - short isValid; + /* private -- internal use only */ + short isValid; } NuMasterHeader; /* * =========================================================================== - * Misc declarations + * Misc declarations * =========================================================================== */ @@ -457,34 +457,34 @@ typedef struct NuMasterHeader { * a small subset of the full record. */ typedef struct NuRecordAttr { - NuFileSysID fileSysID; - /*unsigned short fileSysInfo;*/ - unsigned long access; - unsigned long fileType; - unsigned long extraType; - NuDateTime createWhen; - NuDateTime modWhen; - NuDateTime archiveWhen; + NuFileSysID fileSysID; + /*unsigned short fileSysInfo;*/ + unsigned long access; + unsigned long fileType; + unsigned long extraType; + NuDateTime createWhen; + NuDateTime modWhen; + NuDateTime archiveWhen; } NuRecordAttr; /* * Some additional details about a file. */ typedef struct NuFileDetails { - /* used during AddFile call */ - NuThreadID threadID; /* data, rsrc, disk img? */ + /* used during AddFile call */ + NuThreadID threadID; /* data, rsrc, disk img? */ - /* these go straight into the NuRecord */ - const char* storageName; - NuFileSysID fileSysID; - unsigned short fileSysInfo; - unsigned long access; - unsigned long fileType; - unsigned long extraType; - unsigned short storageType; /* use Unknown, or disk block size */ - NuDateTime createWhen; - NuDateTime modWhen; - NuDateTime archiveWhen; + /* these go straight into the NuRecord */ + const char* storageName; + NuFileSysID fileSysID; + unsigned short fileSysInfo; + unsigned long access; + unsigned long fileType; + unsigned long extraType; + unsigned short storageType; /* use Unknown, or disk block size */ + NuDateTime createWhen; + NuDateTime modWhen; + NuDateTime archiveWhen; } NuFileDetails; @@ -492,49 +492,49 @@ typedef struct NuFileDetails { * Passed into the SelectionFilter callback. */ typedef struct NuSelectionProposal { - const NuRecord* pRecord; - const NuThread* pThread; + const NuRecord* pRecord; + const NuThread* pThread; } NuSelectionProposal; /* * Passed into the OuputPathnameFilter callback. */ typedef struct NuPathnameProposal { - const char* pathname; - char filenameSeparator; - const NuRecord* pRecord; - const NuThread* pThread; + const char* pathname; + char filenameSeparator; + const NuRecord* pRecord; + const NuThread* pThread; - const char* newPathname; - unsigned char newFilenameSeparator; - /*NuThreadID newStorage;*/ - NuDataSink* newDataSink; + const char* newPathname; + unsigned char newFilenameSeparator; + /*NuThreadID newStorage;*/ + NuDataSink* newDataSink; } NuPathnameProposal; /* used by error handler and progress updater to indicate what we're doing */ typedef enum NuOperation { - kNuOpUnknown = 0, - kNuOpAdd, - kNuOpExtract, - kNuOpTest, - kNuOpDelete, /* not used for progress updates */ - kNuOpContents /* not used for progress updates */ + kNuOpUnknown = 0, + kNuOpAdd, + kNuOpExtract, + kNuOpTest, + kNuOpDelete, /* not used for progress updates */ + kNuOpContents /* not used for progress updates */ } NuOperation; /* state of progress when adding or extracting */ typedef enum NuProgressState { - kNuProgressPreparing, /* not started yet */ - kNuProgressOpening, /* opening files */ + kNuProgressPreparing, /* not started yet */ + kNuProgressOpening, /* opening files */ - kNuProgressCompressing, /* compressing data */ - kNuProgressStoring, /* storing (no compression) data */ - kNuProgressExpanding, /* expanding data */ - kNuProgressCopying, /* copying data (in or out) */ + kNuProgressCompressing, /* compressing data */ + kNuProgressStoring, /* storing (no compression) data */ + kNuProgressExpanding, /* expanding data */ + kNuProgressCopying, /* copying data (in or out) */ - kNuProgressDone, /* all done, success */ - kNuProgressSkipped, /* all done, we skipped this one */ - kNuProgressFailed /* all done, failure */ + kNuProgressDone, /* all done, success */ + kNuProgressSkipped, /* all done, we skipped this one */ + kNuProgressFailed /* all done, failure */ } NuProgressState; /* @@ -545,83 +545,83 @@ typedef enum NuProgressState { * than a specified amount. ] */ typedef struct NuProgressData { - /* what are we doing */ - NuOperation operation; - /* what specifically are we doing */ - NuProgressState state; - /* how far along are we */ - short percentComplete; /* 0-100 */ + /* what are we doing */ + NuOperation operation; + /* what specifically are we doing */ + NuProgressState state; + /* how far along are we */ + short percentComplete; /* 0-100 */ - /* original pathname (in archive for expand, on disk for compress) */ - const char* origPathname; - /* processed pathname (PathnameFilter for expand, in-record for compress) */ - const char* pathname; - /* basename of "pathname" */ - const char* filename; - /* pointer to the record we're expanding from */ - const NuRecord* pRecord; + /* original pathname (in archive for expand, on disk for compress) */ + const char* origPathname; + /* processed pathname (PathnameFilter for expand, in-record for compress) */ + const char* pathname; + /* basename of "pathname" */ + const char* filename; + /* pointer to the record we're expanding from */ + const NuRecord* pRecord; - unsigned long uncompressedLength; /* size of uncompressed data */ - unsigned long uncompressedProgress; /* #of bytes in/out */ + unsigned long uncompressedLength; /* size of uncompressed data */ + unsigned long uncompressedProgress; /* #of bytes in/out */ - struct { - NuThreadFormat threadFormat; /* compression being applied */ - } compress; + struct { + NuThreadFormat threadFormat; /* compression being applied */ + } compress; - struct { - unsigned long totalCompressedLength; /* all "data" threads */ - unsigned long totalUncompressedLength; + struct { + unsigned long totalCompressedLength; /* all "data" threads */ + unsigned long totalUncompressedLength; - /*unsigned long compressedLength; * size of compressed data */ - /*unsigned long compressedProgress; * #of compressed bytes in/out*/ - const NuThread* pThread; /* thread we're working on */ - NuValue convertEOL; /* set if LF/CR conv is on */ - } expand; + /*unsigned long compressedLength; * size of compressed data */ + /*unsigned long compressedProgress; * #of compressed bytes in/out*/ + const NuThread* pThread; /* thread we're working on */ + NuValue convertEOL; /* set if LF/CR conv is on */ + } expand; - /* pay no attention */ - NuCallback progressFunc; + /* pay no attention */ + NuCallback progressFunc; } NuProgressData; /* * Passed into the ErrorHandler callback. */ typedef struct NuErrorStatus { - NuOperation operation; /* were we adding, extracting, ?? */ - NuError err; /* library error code */ - int sysErr; /* system error code, if applicable */ - const char* message; /* (optional) message to user */ - const NuRecord* pRecord; /* relevant record, if any */ - const char* pathname; /* relevant pathname, if any */ - char filenameSeparator; /* fssep for this path, if any */ - /*char origArchiveTouched;*/ + NuOperation operation; /* were we adding, extracting, ?? */ + NuError err; /* library error code */ + int sysErr; /* system error code, if applicable */ + const char* message; /* (optional) message to user */ + const NuRecord* pRecord; /* relevant record, if any */ + const char* pathname; /* relevant pathname, if any */ + char filenameSeparator; /* fssep for this path, if any */ + /*char origArchiveTouched;*/ - char canAbort; /* give option to abort */ - /*char canAbortAll;*/ /* abort + discard all recent changes */ - char canRetry; /* give option to retry same op */ - char canIgnore; /* give option to ignore error */ - char canSkip; /* give option to skip this file/rec */ - char canRename; /* give option to rename file */ - char canOverwrite; /* give option to overwrite file */ + char canAbort; /* give option to abort */ + /*char canAbortAll;*/ /* abort + discard all recent changes */ + char canRetry; /* give option to retry same op */ + char canIgnore; /* give option to ignore error */ + char canSkip; /* give option to skip this file/rec */ + char canRename; /* give option to rename file */ + char canOverwrite; /* give option to overwrite file */ } NuErrorStatus; /* * Error message callback gets one of these. */ typedef struct NuErrorMessage { - const char* message; /* the message itself */ - NuError err; /* relevant error code (may be none) */ - short isDebug; /* set for debug-only messages */ + const char* message; /* the message itself */ + NuError err; /* relevant error code (may be none) */ + short isDebug; /* set for debug-only messages */ - /* these identify where the message originated if lib built w/debug set */ - const char* file; /* source file */ - int line; /* line number */ - const char* function; /* function name (might be nil) */ + /* these identify where the message originated if lib built w/debug set */ + const char* file; /* source file */ + int line; /* line number */ + const char* function; /* function name (might be nil) */ } NuErrorMessage; /* * =========================================================================== - * Function prototypes + * Function prototypes * =========================================================================== */ @@ -635,32 +635,32 @@ NuError NuTest(NuArchive* pArchive); NuError NuOpenRO(const char* archivePathname, NuArchive** ppArchive); NuError NuExtractRecord(NuArchive* pArchive, NuRecordIdx recordIdx); NuError NuExtractThread(NuArchive* pArchive, NuThreadIdx threadIdx, - NuDataSink* pDataSink); + NuDataSink* pDataSink); NuError NuGetRecord(NuArchive* pArchive, NuRecordIdx recordIdx, - const NuRecord** ppRecord); + const NuRecord** ppRecord); NuError NuGetRecordIdxByName(NuArchive* pArchive, const char* name, - NuRecordIdx* pRecordIdx); + NuRecordIdx* pRecordIdx); NuError NuGetRecordIdxByPosition(NuArchive* pArchive, unsigned long position, - NuRecordIdx* pRecordIdx); + NuRecordIdx* pRecordIdx); /* read/write interfaces */ NuError NuOpenRW(const char* archivePathname, const char* tempPathname, - unsigned long flags, NuArchive** ppArchive); + unsigned long flags, NuArchive** ppArchive); NuError NuFlush(NuArchive* pArchive, long* pStatusFlags); NuError NuAddRecord(NuArchive* pArchive, const NuFileDetails* pFileDetails, - NuRecordIdx* pRecordIdx); + NuRecordIdx* pRecordIdx); NuError NuAddThread(NuArchive* pArchive, NuRecordIdx recordIdx, - NuThreadIdx threadID, NuDataSource* pDataSource, - NuThreadIdx* pThreadIdx); + NuThreadIdx threadID, NuDataSource* pDataSource, + NuThreadIdx* pThreadIdx); NuError NuAddFile(NuArchive* pArchive, const char* pathname, - const NuFileDetails* pFileDetails, short fromRsrcFork, - NuRecordIdx* pRecordIdx); + const NuFileDetails* pFileDetails, short fromRsrcFork, + NuRecordIdx* pRecordIdx); NuError NuRename(NuArchive* pArchive, NuRecordIdx recordIdx, - const char* pathname, char fssep); + const char* pathname, char fssep); NuError NuSetRecordAttr(NuArchive* pArchive, NuRecordIdx recordIdx, - const NuRecordAttr* pRecordAttr); + const NuRecordAttr* pRecordAttr); NuError NuUpdatePresizedThread(NuArchive* pArchive, NuThreadIdx threadIdx, - NuDataSource* pDataSource, long* pMaxLen); + NuDataSource* pDataSource, long* pMaxLen); NuError NuDelete(NuArchive* pArchive); NuError NuDeleteRecord(NuArchive* pArchive, NuRecordIdx recordIdx); NuError NuDeleteThread(NuArchive* pArchive, NuRecordIdx threadIdx); @@ -669,37 +669,37 @@ NuError NuDeleteThread(NuArchive* pArchive, NuRecordIdx threadIdx); NuError NuClose(NuArchive* pArchive); NuError NuAbort(NuArchive* pArchive); NuError NuGetMasterHeader(NuArchive* pArchive, - const NuMasterHeader** ppMasterHeader); + const NuMasterHeader** ppMasterHeader); NuError NuGetExtraData(NuArchive* pArchive, void** ppData); NuError NuSetExtraData(NuArchive* pArchive, void* pData); NuError NuGetValue(NuArchive* pArchive, NuValueID ident, NuValue* pValue); NuError NuSetValue(NuArchive* pArchive, NuValueID ident, NuValue value); NuError NuGetAttr(NuArchive* pArchive, NuAttrID ident, NuAttr* pAttr); NuError NuGetVersion(long* pMajorVersion, long* pMinorVersion, - long* pBugVersion, const char** ppBuildDate, - const char** ppBuildFlags); + long* pBugVersion, const char** ppBuildDate, + const char** ppBuildFlags); const char* NuStrError(NuError err); NuError NuDebugDumpArchive(NuArchive* pArchive); /* sources and sinks */ NuError NuCreateDataSourceForFile(NuThreadFormat threadFormat, short doClose, - unsigned long otherLen, const char* pathname, short isFromRsrcFork, - NuDataSource** ppDataSource); + unsigned long otherLen, const char* pathname, short isFromRsrcFork, + NuDataSource** ppDataSource); NuError NuCreateDataSourceForFP(NuThreadFormat threadFormat, short doClose, - unsigned long otherLen, FILE* fp, long offset, long length, - NuDataSource** ppDataSource); + unsigned long otherLen, FILE* fp, long offset, long length, + NuDataSource** ppDataSource); NuError NuCreateDataSourceForBuffer(NuThreadFormat threadFormat, short doClose, - unsigned long otherLen, const unsigned char* buffer, long offset, - long length, NuDataSource** ppDataSource); + unsigned long otherLen, const unsigned char* buffer, long offset, + long length, NuDataSource** ppDataSource); NuError NuFreeDataSource(NuDataSource* pDataSource); NuError NuDataSourceSetRawCrc(NuDataSource* pDataSource, unsigned short crc); NuError NuCreateDataSinkForFile(short doExpand, NuValue convertEOL, - const char* pathname, char fssep, NuDataSink** ppDataSink); + const char* pathname, char fssep, NuDataSink** ppDataSink); NuError NuCreateDataSinkForFP(short doExpand, NuValue convertEOL, - FILE* fp, NuDataSink** ppDataSink); + FILE* fp, NuDataSink** ppDataSink); NuError NuCreateDataSinkForBuffer(short doExpand, NuValue convertEOL, - unsigned char* buffer, unsigned long bufLen, - NuDataSink** ppDataSink); + unsigned char* buffer, unsigned long bufLen, + NuDataSink** ppDataSink); NuError NuFreeDataSink(NuDataSink* pDataSink); NuError NuDataSinkGetOutCount(NuDataSink* pDataSink, unsigned long* pOutCount); @@ -710,10 +710,10 @@ unsigned long NuRecordGetNumThreads(const NuRecord* pRecord); const NuThread* NuThreadGetByIdx(const NuThread* pThread, long idx); short NuIsPresizedThreadID(NuThreadID threadID); -#define NuGetThread(pRecord, idx) ( (const NuThread*) \ - ((unsigned long) (idx) < (unsigned long) (pRecord)->recTotalThreads ? \ - &(pRecord)->pThreads[(idx)] : NULL) \ - ) +#define NuGetThread(pRecord, idx) ( (const NuThread*) \ + ((unsigned long) (idx) < (unsigned long) (pRecord)->recTotalThreads ? \ + &(pRecord)->pThreads[(idx)] : NULL) \ + ) /* callback setters */ @@ -722,7 +722,7 @@ NuError NuSetOutputPathnameFilter(NuArchive* pArchive, NuCallback filterFunc); NuError NuSetProgressUpdater(NuArchive* pArchive, NuCallback updateFunc); NuError NuSetErrorHandler(NuArchive* pArchive, NuCallback errorFunc); NuError NuSetErrorMessageHandler(NuArchive* pArchive, - NuCallback messageHandlerFunc); + NuCallback messageHandlerFunc); NuError NuSetGlobalErrorMessageHandler(NuCallback messageHandlerFunc); diff --git a/nufxlib-0/NufxLibPriv.h b/nufxlib-0/NufxLibPriv.h index 72edeb5..cbf044d 100644 --- a/nufxlib-0/NufxLibPriv.h +++ b/nufxlib-0/NufxLibPriv.h @@ -22,7 +22,7 @@ /* * =========================================================================== - * NuArchive definition + * NuArchive definition * =========================================================================== */ @@ -31,47 +31,47 @@ * and non-streaming read-write mode. */ typedef enum NuOpenMode { - kNuOpenUnknown, - kNuOpenStreamingRO, - kNuOpenRO, - kNuOpenRW + kNuOpenUnknown, + kNuOpenStreamingRO, + kNuOpenRO, + kNuOpenRW } NuOpenMode; #define Nu_IsStreaming(pArchive) ((pArchive)->openMode == kNuOpenStreamingRO) -#define Nu_IsReadOnly(pArchive) ((pArchive)->openMode == kNuOpenStreamingRO ||\ - (pArchive)->openMode == kNuOpenRO) +#define Nu_IsReadOnly(pArchive) ((pArchive)->openMode == kNuOpenStreamingRO ||\ + (pArchive)->openMode == kNuOpenRO) #ifdef FOPEN_WANTS_B -# define kNuFileOpenReadOnly "rb" -# define kNuFileOpenReadWrite "r+b" -# define kNuFileOpenWriteTrunc "wb" -# define kNuFileOpenReadWriteCreat "w+b" +# define kNuFileOpenReadOnly "rb" +# define kNuFileOpenReadWrite "r+b" +# define kNuFileOpenWriteTrunc "wb" +# define kNuFileOpenReadWriteCreat "w+b" #else -# define kNuFileOpenReadOnly "r" -# define kNuFileOpenReadWrite "r+" -# define kNuFileOpenWriteTrunc "w" -# define kNuFileOpenReadWriteCreat "w+" +# define kNuFileOpenReadOnly "r" +# define kNuFileOpenReadWrite "r+" +# define kNuFileOpenWriteTrunc "w" +# define kNuFileOpenReadWriteCreat "w+" #endif /* * Some NuFX and Binary II definitions. */ -#define kNuMasterHeaderSize 48 /* size of fixed-length master header */ -#define kNuRecordHeaderBaseSize 58 /* size of rec hdr up to variable stuff */ -#define kNuThreadHeaderSize 16 /* size of fixed-length thread header */ -#define kNuDefaultFilenameThreadSize 32 /* default size of filename thred */ -#define kNuDefaultCommentSize 200 /* size of GSHK-mimic comments */ -#define kNuBinary2BlockSize 128 /* size of bxy header and padding */ -#define kNuSEAOffset 0x2ee5 /* fixed(??) offset to data in SEA */ +#define kNuMasterHeaderSize 48 /* size of fixed-length master header */ +#define kNuRecordHeaderBaseSize 58 /* size of rec hdr up to variable stuff */ +#define kNuThreadHeaderSize 16 /* size of fixed-length thread header */ +#define kNuDefaultFilenameThreadSize 32 /* default size of filename thred */ +#define kNuDefaultCommentSize 200 /* size of GSHK-mimic comments */ +#define kNuBinary2BlockSize 128 /* size of bxy header and padding */ +#define kNuSEAOffset 0x2ee5 /* fixed(??) offset to data in SEA */ -#define kNuInitialChunkCRC 0x0000 /* start for CRC in LZW/1 chunk */ -#define kNuInitialThreadCRC 0xffff /* start for CRC in v3 thread header */ +#define kNuInitialChunkCRC 0x0000 /* start for CRC in LZW/1 chunk */ +#define kNuInitialThreadCRC 0xffff /* start for CRC in v3 thread header */ /* size of general-purpose compression buffer */ -#define kNuGenCompBufSize 32768 +#define kNuGenCompBufSize 32768 -#define kNuCharLF 0x0a -#define kNuCharCR 0x0d +#define kNuCharLF 0x0a +#define kNuCharCR 0x0d /* @@ -85,99 +85,99 @@ typedef enum NuOpenMode { * appropriate to use "orig" or not. */ typedef struct NuRecordSet { - Boolean loaded; - ulong numRecords; - NuRecord* nuRecordHead; - NuRecord* nuRecordTail; + Boolean loaded; + ulong numRecords; + NuRecord* nuRecordHead; + NuRecord* nuRecordTail; } NuRecordSet; /* * Archive state. */ struct NuArchive { - ulong structMagic; - Boolean busy; + ulong structMagic; + Boolean busy; - NuOpenMode openMode; - Boolean newlyCreated; - char* archivePathname; /* pathname or "(stream)" */ - FILE* archiveFp; - NuArchiveType archiveType; - long headerOffset; /* adjustment for BXY/SEA/BSE */ + NuOpenMode openMode; + Boolean newlyCreated; + char* archivePathname; /* pathname or "(stream)" */ + FILE* archiveFp; + NuArchiveType archiveType; + long headerOffset; /* adjustment for BXY/SEA/BSE */ - char* tmpPathname; /* temp file, for writes */ - FILE* tmpFp; + char* tmpPathname; /* temp file, for writes */ + FILE* tmpFp; - /* used during initial processing; helps avoid ftell() calls */ - long currentOffset; + /* used during initial processing; helps avoid ftell() calls */ + long currentOffset; - /* setting this changes Extract into Test */ - Boolean testMode; + /* setting this changes Extract into Test */ + Boolean testMode; - /* clumsy way of remembering name used for other fork in forked file */ - const char* lastFileCreated; - /* clumsy way to avoid trying to create the same subdir several times */ - const char* lastDirCreated; + /* clumsy way of remembering name used for other fork in forked file */ + const char* lastFileCreated; + /* clumsy way to avoid trying to create the same subdir several times */ + const char* lastDirCreated; - /* master header from the archive */ - NuMasterHeader masterHeader; /* original */ - NuMasterHeader newMasterHeader; /* working copy during update */ + /* master header from the archive */ + NuMasterHeader masterHeader; /* original */ + NuMasterHeader newMasterHeader; /* working copy during update */ - /* list of records from archive, plus some extra state */ - NuRecordIdx recordIdxSeed; /* where the NuRecordIdxs start */ - NuRecordIdx nextRecordIdx; /* next record gets this value */ - Boolean haveToc; /* set if we have full TOC */ - NuRecordSet origRecordSet; /* records from archive */ - NuRecordSet copyRecordSet; /* copy of orig, for write ops */ - NuRecordSet newRecordSet; /* newly-added records */ + /* list of records from archive, plus some extra state */ + NuRecordIdx recordIdxSeed; /* where the NuRecordIdxs start */ + NuRecordIdx nextRecordIdx; /* next record gets this value */ + Boolean haveToc; /* set if we have full TOC */ + NuRecordSet origRecordSet; /* records from archive */ + NuRecordSet copyRecordSet; /* copy of orig, for write ops */ + NuRecordSet newRecordSet; /* newly-added records */ - /* state for compression functions */ - uchar* compBuf; /* large general-purpose buffer */ - void* lzwCompressState; /* state for LZW/1 and LZW/2 */ - void* lzwExpandState; /* state for LZW/1 and LZW/2 */ + /* state for compression functions */ + uchar* compBuf; /* large general-purpose buffer */ + void* lzwCompressState; /* state for LZW/1 and LZW/2 */ + void* lzwExpandState; /* state for LZW/1 and LZW/2 */ - /* options and attributes that the user can set */ - /* (these can be changed by a callback, so don't cache them internally) */ - void* extraData; /* application-defined pointer */ + /* options and attributes that the user can set */ + /* (these can be changed by a callback, so don't cache them internally) */ + void* extraData; /* application-defined pointer */ - NuValue valAllowDuplicates; /* allow dups when adding? */ - NuValue valConvertExtractedEOL; /* convert EOL during extract? */ - NuValue valDataCompression; /* how to compress when adding? */ - NuValue valDiscardWrapper; /* remove BNY or SEA header? */ - NuValue valEOL; /* EOL value to convert to */ - NuValue valHandleExisting; /* how to deal with existing files*/ - NuValue valIgnoreCRC; /* don't compute or test CRCs */ - NuValue valMimicSHK; /* mimic some ShrinkIt quirks */ - NuValue valModifyOrig; /* modify original arc in place? */ - NuValue valOnlyUpdateOlder; /* modify original arc in place? */ + NuValue valAllowDuplicates; /* allow dups when adding? */ + NuValue valConvertExtractedEOL; /* convert EOL during extract? */ + NuValue valDataCompression; /* how to compress when adding? */ + NuValue valDiscardWrapper; /* remove BNY or SEA header? */ + NuValue valEOL; /* EOL value to convert to */ + NuValue valHandleExisting; /* how to deal with existing files*/ + NuValue valIgnoreCRC; /* don't compute or test CRCs */ + NuValue valMimicSHK; /* mimic some ShrinkIt quirks */ + NuValue valModifyOrig; /* modify original arc in place? */ + NuValue valOnlyUpdateOlder; /* modify original arc in place? */ - /* callback functions */ - NuCallback selectionFilterFunc; - NuCallback outputPathnameFunc; - NuCallback progressUpdaterFunc; - NuCallback errorHandlerFunc; - NuCallback messageHandlerFunc; + /* callback functions */ + NuCallback selectionFilterFunc; + NuCallback outputPathnameFunc; + NuCallback progressUpdaterFunc; + NuCallback errorHandlerFunc; + NuCallback messageHandlerFunc; }; -#define kNuArchiveStructMagic 0xc0edbabe +#define kNuArchiveStructMagic 0xc0edbabe -#define kNuDefaultRecordName "UNKNOWN" +#define kNuDefaultRecordName "UNKNOWN" /* * =========================================================================== - * ThreadMod definition + * ThreadMod definition * =========================================================================== */ /* operations we can perform on threads in a record */ typedef enum ThreadModKind { - kNuThreadModUnknown = 0, + kNuThreadModUnknown = 0, - kNuThreadModAdd, - kNuThreadModUpdate, - kNuThreadModDelete + kNuThreadModAdd, + kNuThreadModUpdate, + kNuThreadModDelete } ThreadModKind; /* @@ -186,50 +186,50 @@ typedef enum ThreadModKind { * right after you delete it, nor delete one you have modified. */ struct NuThreadMod { - union { - ThreadModKind kind; + union { + ThreadModKind kind; - struct { - ThreadModKind kind; - Boolean used; - } generic; + struct { + ThreadModKind kind; + Boolean used; + } generic; - struct { - ThreadModKind kind; - Boolean used; - Boolean isPresized; - NuThreadIdx threadIdx; - NuThreadID threadID; - NuThreadFormat threadFormat; - NuDataSource* pDataSource; - } add; + struct { + ThreadModKind kind; + Boolean used; + Boolean isPresized; + NuThreadIdx threadIdx; + NuThreadID threadID; + NuThreadFormat threadFormat; + NuDataSource* pDataSource; + } add; - struct { - ThreadModKind kind; - Boolean used; - NuThreadIdx threadIdx; - NuDataSource* pDataSource; - } update; + struct { + ThreadModKind kind; + Boolean used; + NuThreadIdx threadIdx; + NuDataSource* pDataSource; + } update; - struct { - ThreadModKind kind; - Boolean used; - NuThreadIdx threadIdx; - NuThreadID threadID; /* used for watching filename threads */ - } delete; - } entry; + struct { + ThreadModKind kind; + Boolean used; + NuThreadIdx threadIdx; + NuThreadID threadID; /* used for watching filename threads */ + } delete; + } entry; - struct NuThreadMod* pNext; + struct NuThreadMod* pNext; }; /* * =========================================================================== - * NuFunnel/NuStraw definition + * NuFunnel/NuStraw definition * =========================================================================== */ -#define kNuFunnelBufSize 16384 +#define kNuFunnelBufSize 16384 /* * File funnel definition. This is used for writing output to files @@ -248,29 +248,29 @@ struct NuThreadMod { * block-oriented). */ typedef struct NuFunnel { - /* data storage */ - uchar* buffer; /* kNuFunnelBufSize worth of storage */ - long bufCount; /* #of bytes in buffer */ + /* data storage */ + uchar* buffer; /* kNuFunnelBufSize worth of storage */ + long bufCount; /* #of bytes in buffer */ - /* EOL conversion; if "auto", on first flush we convert to "on" or "off" */ - NuValue convertEOL; /* on/off/auto */ - NuValue convertEOLTo; /* EOL to switch to */ - NuValue convertEOLFrom; /* EOL terminator we think we found */ - Boolean lastCR; /* was last char a CR? */ + /* EOL conversion; if "auto", on first flush we convert to "on" or "off" */ + NuValue convertEOL; /* on/off/auto */ + NuValue convertEOLTo; /* EOL to switch to */ + NuValue convertEOLFrom; /* EOL terminator we think we found */ + Boolean lastCR; /* was last char a CR? */ #if 0 - ulong inCount; /* total #of bytes in the top */ - ulong outCount; /* total #of bytes out the bottom */ + ulong inCount; /* total #of bytes in the top */ + ulong outCount; /* total #of bytes out the bottom */ - ulong outMax; /* flag an err when outCount exceeds this */ - Boolean outMaxExceeded; /* in fact, it's this flag */ + ulong outMax; /* flag an err when outCount exceeds this */ + Boolean outMaxExceeded; /* in fact, it's this flag */ #endif - /* update this when stuff happens */ - NuProgressData* pProgress; + /* update this when stuff happens */ + NuProgressData* pProgress; - /* data goeth out here */ - NuDataSink* pDataSink; + /* data goeth out here */ + NuDataSink* pDataSink; } NuFunnel; @@ -284,15 +284,15 @@ typedef struct NuFunnel { * will be, so we want to do it for the input. */ typedef struct NuStraw { - /* update this when stuff happens */ - NuProgressData* pProgress; + /* update this when stuff happens */ + NuProgressData* pProgress; - /* data cometh in here */ - NuDataSource* pDataSource; + /* data cometh in here */ + NuDataSource* pDataSource; - /* progress update fields */ - ulong lastProgress; - ulong lastDisplayed; + /* progress update fields */ + ulong lastProgress; + ulong lastDisplayed; } NuStraw; /*NuError Nu_CopyStreamToStream(FILE* outfp, FILE* infp, ulong count);*/ @@ -300,7 +300,7 @@ typedef struct NuStraw { /* * =========================================================================== - * Data source and sink abstractions + * Data source and sink abstractions * =========================================================================== */ @@ -309,49 +309,49 @@ typedef struct NuStraw { */ typedef enum NuDataSourceType { - kNuDataSourceUnknown = 0, - kNuDataSourceFromFile, - kNuDataSourceFromFP, - kNuDataSourceFromBuffer + kNuDataSourceUnknown = 0, + kNuDataSourceFromFile, + kNuDataSourceFromFP, + kNuDataSourceFromBuffer } NuDataSourceType; typedef struct NuDataSourceCommon { - NuDataSourceType sourceType; - NuThreadFormat threadFormat; /* is it already compressed? */ - ushort rawCrc; /* crc for already-compressed data*/ - Boolean doClose; /* close on completion? */ - ulong dataLen; /* length of data (var for buf) */ - ulong otherLen; /* uncomp len or preset buf size */ + NuDataSourceType sourceType; + NuThreadFormat threadFormat; /* is it already compressed? */ + ushort rawCrc; /* crc for already-compressed data*/ + Boolean doClose; /* close on completion? */ + ulong dataLen; /* length of data (var for buf) */ + ulong otherLen; /* uncomp len or preset buf size */ } NuDataSourceCommon; union NuDataSource { - NuDataSourceType sourceType; + NuDataSourceType sourceType; - NuDataSourceCommon common; + NuDataSourceCommon common; - struct { - NuDataSourceCommon common; - char* pathname; - Boolean fromRsrcFork; + struct { + NuDataSourceCommon common; + char* pathname; + Boolean fromRsrcFork; - /* temp storage; only valid when processing in library */ - FILE* fp; - } fromFile; + /* temp storage; only valid when processing in library */ + FILE* fp; + } fromFile; - struct { - NuDataSourceCommon common; - FILE* fp; - long offset; /* starting offset */ - } fromFP; + struct { + NuDataSourceCommon common; + FILE* fp; + long offset; /* starting offset */ + } fromFP; - struct { - NuDataSourceCommon common; - const uchar* buffer; /* non-const if doClose=true */ - long offset; /* starting offset */ + struct { + NuDataSourceCommon common; + const uchar* buffer; /* non-const if doClose=true */ + long offset; /* starting offset */ - long curOffset; /* current offset */ - long curDataLen; /* remaining data */ - } fromBuffer; + long curOffset; /* current offset */ + long curDataLen; /* remaining data */ + } fromBuffer; }; @@ -360,51 +360,51 @@ union NuDataSource { */ typedef enum NuDataSinkType { - kNuDataSinkUnknown = 0, - kNuDataSinkToFile, - kNuDataSinkToFP, - kNuDataSinkToBuffer, - kNuDataSinkToVoid + kNuDataSinkUnknown = 0, + kNuDataSinkToFile, + kNuDataSinkToFP, + kNuDataSinkToBuffer, + kNuDataSinkToVoid } NuDataSinkType; typedef struct NuDataSinkCommon { - NuDataSinkType sinkType; - Boolean doExpand; /* expand file? */ - NuValue convertEOL; /* convert EOL? (req "expand") */ - ulong outCount; + NuDataSinkType sinkType; + Boolean doExpand; /* expand file? */ + NuValue convertEOL; /* convert EOL? (req "expand") */ + ulong outCount; } NuDataSinkCommon; union NuDataSink { - NuDataSinkType sinkType; + NuDataSinkType sinkType; - NuDataSinkCommon common; + NuDataSinkCommon common; - struct { - NuDataSinkCommon common; - char* pathname; /* file to open */ - char fssep; + struct { + NuDataSinkCommon common; + char* pathname; /* file to open */ + char fssep; - /* temp storage; must be nil except when processing in library */ - FILE* fp; - } toFile; + /* temp storage; must be nil except when processing in library */ + FILE* fp; + } toFile; - struct { - NuDataSinkCommon common; - FILE* fp; - } toFP; + struct { + NuDataSinkCommon common; + FILE* fp; + } toFP; - struct { - NuDataSinkCommon common; - uchar* buffer; - ulong bufLen; /* max amount of data "buffer" holds */ - NuError stickyErr; - } toBuffer; + struct { + NuDataSinkCommon common; + uchar* buffer; + ulong bufLen; /* max amount of data "buffer" holds */ + NuError stickyErr; + } toBuffer; }; /* * =========================================================================== - * Function prototypes + * Function prototypes * =========================================================================== */ @@ -416,22 +416,22 @@ union NuDataSink { */ #ifdef DEBUG_MSGS #ifdef HAS__FUNCTION__ - #define _FUNCTION_ __FUNCTION__ + #define _FUNCTION_ __FUNCTION__ #else - #define _FUNCTION_ "" + #define _FUNCTION_ "" #endif - #define NU_BLOB pArchive, __FILE__, __LINE__, _FUNCTION_, false - #define NU_BLOB_DEBUG pArchive, __FILE__, __LINE__, _FUNCTION_, true - #define NU_NILBLOB NULL, __FILE__, __LINE__, _FUNCTION_, false - #define DebugShowError(err) \ - Nu_ReportError(pArchive, __FILE__, __LINE__, _FUNCTION_, \ - true, err, "(DEBUG)"); + #define NU_BLOB pArchive, __FILE__, __LINE__, _FUNCTION_, false + #define NU_BLOB_DEBUG pArchive, __FILE__, __LINE__, _FUNCTION_, true + #define NU_NILBLOB NULL, __FILE__, __LINE__, _FUNCTION_, false + #define DebugShowError(err) \ + Nu_ReportError(pArchive, __FILE__, __LINE__, _FUNCTION_, \ + true, err, "(DEBUG)"); #else - #define NU_BLOB pArchive, "", 0, "", false - #define NU_BLOB_DEBUG pArchive, "", 0, "", true - #define NU_NILBLOB NULL, "", 0, "", false - #define DebugShowError(err) ((void)0) + #define NU_BLOB pArchive, "", 0, "", false + #define NU_BLOB_DEBUG pArchive, "", 0, "", true + #define NU_NILBLOB NULL, "", 0, "", false + #define DebugShowError(err) ((void)0) #endif /* @@ -441,29 +441,29 @@ union NuDataSink { * us a stack trace of exiting functions. This makes it easier to debug * problems sent in as screen dumps via e-mail. */ -#define BailError(err) { \ - if ((err) != kNuErrNone) { \ - /* [should this be debug-only, or all the time?] */ \ - DebugShowError(err); \ - goto bail; \ - } \ - } -#define BailErrorQuiet(err) { \ - if ((err) != kNuErrNone) \ - goto bail; \ - } -#define BailNil(val) { \ - if ((val) == nil) { \ - err = kNuErrUnexpectedNil; \ - BailError(err); \ - } \ - } -#define BailAlloc(val) { \ - if ((val) == nil) { \ - err = kNuErrMalloc; \ - BailError(err); \ - } \ - } +#define BailError(err) { \ + if ((err) != kNuErrNone) { \ + /* [should this be debug-only, or all the time?] */ \ + DebugShowError(err); \ + goto bail; \ + } \ + } +#define BailErrorQuiet(err) { \ + if ((err) != kNuErrNone) \ + goto bail; \ + } +#define BailNil(val) { \ + if ((val) == nil) { \ + err = kNuErrUnexpectedNil; \ + BailError(err); \ + } \ + } +#define BailAlloc(val) { \ + if ((val) == nil) { \ + err = kNuErrMalloc; \ + BailError(err); \ + } \ + } /* @@ -472,9 +472,9 @@ union NuDataSink { /* Archive.c */ void Nu_MasterHeaderCopy(NuArchive* pArchive, NuMasterHeader* pDstHeader, - const NuMasterHeader* pSrcHeader); + const NuMasterHeader* pSrcHeader); NuError Nu_GetMasterHeader(NuArchive* pArchive, - const NuMasterHeader** ppMasterHeader); + const NuMasterHeader** ppMasterHeader); NuRecordIdx Nu_GetNextRecordIdx(NuArchive* pArchive); NuThreadIdx Nu_GetNextThreadIdx(NuArchive* pArchive); NuError Nu_CopyWrapperToTemp(NuArchive* pArchive); @@ -484,9 +484,9 @@ NuError Nu_AllocCompressionBufferIFN(NuArchive* pArchive); NuError Nu_StreamOpenRO(FILE* infp, NuArchive** ppArchive); NuError Nu_OpenRO(const char* filename, NuArchive** ppArchive); NuError Nu_OpenRW(const char* archivePathname, const char* tempPathname, - ulong flags, NuArchive** ppArchive); + ulong flags, NuArchive** ppArchive); NuError Nu_WriteMasterHeader(NuArchive* pArchive, FILE* fp, - NuMasterHeader* pMasterHeader); + NuMasterHeader* pMasterHeader); NuError Nu_Close(NuArchive* pArchive); NuError Nu_Abort(NuArchive* pArchive); NuError Nu_RenameTempToArchive(NuArchive* pArchive); @@ -508,44 +508,44 @@ void Nu_WriteFour(NuArchive* pArchive, FILE* fp, ulong val); NuDateTime Nu_ReadDateTimeC(NuArchive* pArchive, FILE* fp, ushort* pCrc); NuDateTime Nu_ReadDateTime(NuArchive* pArchive, FILE* fp, ushort* pCrc); void Nu_WriteDateTimeC(NuArchive* pArchive, FILE* fp, NuDateTime dateTime, - ushort* pCrc); + ushort* pCrc); void Nu_WriteDateTime(NuArchive* pArchive, FILE* fp, NuDateTime dateTime); void Nu_ReadBytesC(NuArchive* pArchive, FILE* fp, void* vbuffer, long count, - ushort* pCrc); + ushort* pCrc); void Nu_ReadBytes(NuArchive* pArchive, FILE* fp, void* vbuffer, long count); void Nu_WriteBytesC(NuArchive* pArchive, FILE* fp, const void* vbuffer, - long count, ushort* pCrc); + long count, ushort* pCrc); void Nu_WriteBytes(NuArchive* pArchive, FILE* fp, const void* vbuffer, - long count); + long count); NuError Nu_HeaderIOFailed(NuArchive* pArchive, FILE* fp); NuError Nu_SeekArchive(NuArchive* pArchive, FILE* fp, long offset, - int ptrname); + int ptrname); NuError Nu_RewindArchive(NuArchive* pArchive); /* Compress.c */ NuError Nu_CompressToArchive(NuArchive* pArchive, NuDataSource* pDataSource, - NuThreadID threadID, NuThreadFormat sourceFormat, - NuThreadFormat targetFormat, NuProgressData* progressData, FILE* dstFp, - NuThread* pThread); + NuThreadID threadID, NuThreadFormat sourceFormat, + NuThreadFormat targetFormat, NuProgressData* progressData, FILE* dstFp, + NuThread* pThread); NuError Nu_CopyPresizedToArchive(NuArchive* pArchive, - NuDataSource* pDataSource, NuThreadID threadID, FILE* dstFp, - NuThread* pThread, char** ppSavedCopy); + NuDataSource* pDataSource, NuThreadID threadID, FILE* dstFp, + NuThread* pThread, char** ppSavedCopy); /* Crc16.c */ extern const ushort gNuCrc16Table[256]; ushort Nu_CalcCRC16(ushort seed, const uchar* ptr, int count); -#ifdef __Crc16_c__ /* just doing "static inline" warns def-but-not-used */ - #define CRC_INLINE /**/ +#ifdef __Crc16_c__ /* just doing "static inline" warns def-but-not-used */ + #define CRC_INLINE /**/ #else #define CRC_INLINE extern inline #endif -#if defined(inline) && !defined(__Crc16_c__) /* somebody ovrd inline def? */ +#if defined(inline) && !defined(__Crc16_c__) /* somebody ovrd inline def? */ ushort Nu_UpdateCRC16(uchar val, ushort crc); #else CRC_INLINE ushort Nu_UpdateCRC16(uchar val, ushort crc) { - return (gNuCrc16Table[((crc >> 8) & 0xFF) ^ val] ^ (crc << 8)) & 0xFFFF; + return (gNuCrc16Table[((crc >> 8) & 0xFF) ^ val] ^ (crc << 8)) & 0xFFFF; } #endif @@ -557,34 +557,34 @@ void Nu_DebugDumpThread(const NuThread* pThread); /* Deferred.c */ NuError Nu_ThreadModAdd_New(NuArchive* pArchive, NuThreadID threadID, - NuThreadFormat threadFormat, NuDataSource* pDataSource, - NuThreadMod** ppThreadMod); + NuThreadFormat threadFormat, NuDataSource* pDataSource, + NuThreadMod** ppThreadMod); NuError Nu_ThreadModUpdate_New(NuArchive* pArchive, NuThreadIdx threadIdx, - NuDataSource* pDataSource, NuThreadMod** ppThreadMod); + NuDataSource* pDataSource, NuThreadMod** ppThreadMod); NuError Nu_ThreadModDelete_New(NuArchive* pArchive, NuThreadIdx threadIdx, - NuThreadID threadID, NuThreadMod** ppThreadMod); + NuThreadID threadID, NuThreadMod** ppThreadMod); void Nu_ThreadModFree(NuArchive* pArchive, NuThreadMod* pThreadMod); NuError Nu_ThreadModAdd_FindByThreadID(const NuRecord* pRecord, - NuThreadID threadID, NuThreadMod** ppThreadMod); + NuThreadID threadID, NuThreadMod** ppThreadMod); void Nu_FreeThreadMods(NuArchive* pArchive, NuRecord* pRecord); NuThreadMod* Nu_ThreadMod_FindByThreadIdx(const NuRecord* pRecord, - NuThreadIdx threadIdx); + NuThreadIdx threadIdx); NuError Nu_Flush(NuArchive* pArchive, long* pStatusFlags); /* Expand.c */ NuError Nu_ExpandStream(NuArchive* pArchive, const NuRecord* pRecord, - const NuThread* pThread, FILE* infp, NuFunnel* pFunnel); + const NuThread* pThread, FILE* infp, NuFunnel* pFunnel); /* FileIO.c */ void Nu_SetCurrentDateTime(NuDateTime* pDateTime); Boolean Nu_IsOlder(const NuDateTime* pWhen1, const NuDateTime* pWhen2); NuError Nu_OpenOutputFile(NuArchive* pArchive, const NuRecord* pRecord, const NuThread* pThread, const char* newPathname, char newFssep, - FILE** pFp); + FILE** pFp); NuError Nu_CloseOutputFile(NuArchive* pArchive, const NuRecord* pRecord, - FILE* fp, const char* pathname); + FILE* fp, const char* pathname); NuError Nu_OpenInputFile(NuArchive* pArchive, const char* pathname, - Boolean openRsrc, FILE** pFp); + Boolean openRsrc, FILE** pFp); NuError Nu_DeleteFile(const char* pathname); NuError Nu_RenameFile(const char* fromPath, const char* toPath); NuError Nu_FTell(FILE* fp, long* pOffset); @@ -592,64 +592,64 @@ NuError Nu_FSeek(FILE* fp, long offset, int ptrname); NuError Nu_FRead(FILE* fp, void* buf, size_t nbyte); NuError Nu_FWrite(FILE* fp, const void* buf, size_t nbyte); NuError Nu_CopyFileSection(NuArchive* pArchive, FILE* dstFp, FILE* srcFp, - long length); + long length); NuError Nu_GetFileLength(NuArchive* pArchive, FILE* fp, long* pLength); NuError Nu_TruncateOpenFile(FILE* fp, long length); /* Funnel.c */ NuError Nu_ProgressDataInit_Compress(NuArchive* pArchive, - NuProgressData* pProgressData, const NuRecord* pRecord, - const char* origPathname); + NuProgressData* pProgressData, const NuRecord* pRecord, + const char* origPathname); NuError Nu_ProgressDataInit_Expand(NuArchive* pArchive, - NuProgressData* pProgressData, const NuRecord* pRecord, - const char* newPathname, char newFssep, NuValue convertEOL); + NuProgressData* pProgressData, const NuRecord* pRecord, + const char* newPathname, char newFssep, NuValue convertEOL); NuError Nu_SendInitialProgress(NuArchive* pArchive, - const NuProgressData* pProgress); + const NuProgressData* pProgress); NuError Nu_FunnelNew(NuArchive* pArchive, NuDataSink* pDataSink, - NuValue convertEOL, NuValue convertEOLTo, NuProgressData* pProgress, - NuFunnel** ppFunnel); + NuValue convertEOL, NuValue convertEOLTo, NuProgressData* pProgress, + NuFunnel** ppFunnel); NuError Nu_FunnelFree(NuArchive* pArchive, NuFunnel* pFunnel); /*void Nu_FunnelSetMaxOutput(NuFunnel* pFunnel, ulong maxBytes);*/ NuError Nu_FunnelWrite(NuArchive* pArchive, NuFunnel* pFunnel, - const uchar* buffer, ulong count); + const uchar* buffer, ulong count); NuError Nu_FunnelFlush(NuArchive* pArchive, NuFunnel* pFunnel); NuError Nu_ProgressDataCompressPrep(NuArchive* pArchive, NuStraw* pStraw, - NuThreadFormat threadFormat, ulong sourceLen); + NuThreadFormat threadFormat, ulong sourceLen); NuError Nu_ProgressDataExpandPrep(NuArchive* pArchive, NuFunnel* pFunnel, - const NuThread* pThread); + const NuThread* pThread); NuError Nu_FunnelSetProgressState(NuFunnel* pFunnel, NuProgressState state); NuError Nu_FunnelSendProgressUpdate(NuArchive* pArchive, NuFunnel* pFunnel); Boolean Nu_FunnelGetDoExpand(NuFunnel* pFunnel); NuError Nu_StrawNew(NuArchive* pArchive, NuDataSource* pDataSource, - NuProgressData* pProgress, NuStraw** ppStraw); + NuProgressData* pProgress, NuStraw** ppStraw); NuError Nu_StrawFree(NuArchive* pArchive, NuStraw* pStraw); NuError Nu_StrawSetProgressState(NuStraw* pStraw, NuProgressState state); NuError Nu_StrawSendProgressUpdate(NuArchive* pArchive, NuStraw* pStraw); NuError Nu_StrawRead(NuArchive* pArchive, NuStraw* pStraw, uchar* buffer, - long len); + long len); NuError Nu_StrawRewind(NuArchive* pArchive, NuStraw* pStraw); /* Lzw.c */ NuError Nu_CompressLZW1(NuArchive* pArchive, NuStraw* pStraw, FILE* fp, - ulong srcLen, ulong* pDstLen, ushort* pCrc); + ulong srcLen, ulong* pDstLen, ushort* pCrc); NuError Nu_CompressLZW2(NuArchive* pArchive, NuStraw* pStraw, FILE* fp, - ulong srcLen, ulong* pDstLen, ushort* pCrc); + ulong srcLen, ulong* pDstLen, ushort* pCrc); NuError Nu_ExpandLZW(NuArchive* pArchive, const NuRecord* pRecord, - const NuThread* pThread, FILE* infp, NuFunnel* pFunnel, ushort* pCrc); + const NuThread* pThread, FILE* infp, NuFunnel* pFunnel, ushort* pCrc); /* MiscUtils.c */ extern const char* kNufxLibName; extern NuCallback gNuGlobalErrorMessageHandler; const char* 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, ...) #if defined(__GNUC__) __attribute__ ((format(printf, 7, 8))) #endif ; -#ifdef USE_DMALLOC /* want file and line numbers for calls */ +#ifdef USE_DMALLOC /* want file and line numbers for calls */ # define Nu_Malloc(archive, size) malloc(size) # define Nu_Calloc(archive, size) calloc(1, size) # define Nu_Realloc(archive, ptr, size) realloc(ptr, size) @@ -673,23 +673,23 @@ NuRecord** Nu_RecordSet_GetListHeadPtr(NuRecordSet* pRecordSet); NuRecord* Nu_RecordSet_GetListTail(const NuRecordSet* pRecordSet); Boolean Nu_RecordSet_IsEmpty(const NuRecordSet* pRecordSet); NuError Nu_RecordSet_FreeAllRecords(NuArchive* pArchive, - NuRecordSet* pRecordSet); + NuRecordSet* pRecordSet); NuError Nu_RecordSet_DeleteRecordPtr(NuArchive* pArchive, - NuRecordSet* pRecordSet, NuRecord** ppRecord); + NuRecordSet* pRecordSet, NuRecord** ppRecord); NuError Nu_RecordSet_DeleteRecord(NuArchive* pArchive, NuRecordSet* pRecordSet, - NuRecord* pRecord); + NuRecord* pRecord); NuError Nu_RecordSet_Clone(NuArchive* pArchive, NuRecordSet* pDstSet, - const NuRecordSet* pSrcSet); + const NuRecordSet* pSrcSet); NuError Nu_RecordSet_MoveAllRecords(NuArchive* pArchive, NuRecordSet* pDstSet, - NuRecordSet* pSrcSet); + NuRecordSet* pSrcSet); NuError Nu_RecordSet_FindByIdx(const NuRecordSet* pRecordSet, NuRecordIdx rec, - NuRecord** ppRecord); + NuRecord** ppRecord); NuError Nu_RecordSet_FindByThreadIdx(NuRecordSet* pRecordSet, - NuThreadIdx threadIdx, NuRecord** ppRecord, NuThread** ppThread); + NuThreadIdx threadIdx, NuRecord** ppRecord, NuThread** ppThread); NuError Nu_RecordSet_ReplaceRecord(NuArchive* pArchive, NuRecordSet* pBadSet, - NuRecord* pBadRecord, NuRecordSet* pGoodSet, NuRecord** ppGoodRecord); + NuRecord* pBadRecord, NuRecordSet* pGoodSet, NuRecord** ppGoodRecord); Boolean Nu_ShouldIgnoreBadCRC(NuArchive* pArchive, const NuRecord* pRecord, - NuError err); + NuError err); NuError Nu_WriteRecordHeader(NuArchive* pArchive, NuRecord* pRecord, FILE* fp); NuError Nu_GetTOCIfNeeded(NuArchive* pArchive); NuError Nu_StreamContents(NuArchive* pArchive, NuCallback contentFunc); @@ -700,35 +700,35 @@ NuError Nu_Extract(NuArchive* pArchive); NuError Nu_ExtractRecord(NuArchive* pArchive, NuRecordIdx recIdx); NuError Nu_Test(NuArchive* pArchive); NuError Nu_GetRecord(NuArchive* pArchive, NuRecordIdx recordIdx, - const NuRecord** ppRecord); + const NuRecord** ppRecord); NuError Nu_GetRecordIdxByName(NuArchive* pArchive, const char* name, - NuRecordIdx* pRecordIdx); + NuRecordIdx* pRecordIdx); NuError Nu_GetRecordIdxByPosition(NuArchive* pArchive, ulong position, - NuRecordIdx* pRecordIdx); + NuRecordIdx* pRecordIdx); NuError Nu_FindRecordForWriteByIdx(NuArchive* pArchive, NuRecordIdx recIdx, - NuRecord** ppFoundRecord); + NuRecord** ppFoundRecord); NuError Nu_AddFile(NuArchive* pArchive, const char* pathname, const NuFileDetails* pFileDetails, Boolean fromRsrcFork, - NuRecordIdx* pRecordIdx); + NuRecordIdx* pRecordIdx); NuError Nu_AddRecord(NuArchive* pArchive, const NuFileDetails* pFileDetails, - NuRecordIdx* pRecordIdx, NuRecord** ppRecord); + NuRecordIdx* pRecordIdx, NuRecord** ppRecord); NuError Nu_Rename(NuArchive* pArchive, NuRecordIdx recIdx, - const char* pathname, char fssep); + const char* pathname, char fssep); NuError Nu_SetRecordAttr(NuArchive* pArchive, NuRecordIdx recordIdx, - const NuRecordAttr* pRecordAttr); + const NuRecordAttr* pRecordAttr); NuError Nu_Delete(NuArchive* pArchive); NuError Nu_DeleteRecord(NuArchive* pArchive, NuRecordIdx rec); /* SourceSink.c */ NuError Nu_DataSourceFile_New(NuThreadFormat threadFormat, Boolean doClose, - ulong otherLen, const char* pathname, Boolean isFromRsrcFork, - NuDataSource** ppDataSource); + ulong otherLen, const char* pathname, Boolean isFromRsrcFork, + NuDataSource** ppDataSource); NuError Nu_DataSourceFP_New(NuThreadFormat threadFormat, Boolean doClose, - ulong otherLen, FILE* fp, long offset, long length, - NuDataSource** ppDataSource); + ulong otherLen, FILE* fp, long offset, long length, + NuDataSource** ppDataSource); NuError Nu_DataSourceBuffer_New(NuThreadFormat threadFormat, - Boolean doClose, ulong otherLen, const uchar* buffer, long offset, - long length, NuDataSource** ppDataSource); + Boolean doClose, ulong otherLen, const uchar* buffer, long offset, + long length, NuDataSource** ppDataSource); NuDataSource* Nu_DataSourceCopy(NuDataSource* pDataSource); NuError Nu_DataSourceFree(NuDataSource* pDataSource); NuDataSourceType Nu_DataSourceGetType(const NuDataSource* pDataSource); @@ -739,20 +739,20 @@ void Nu_DataSourceSetOtherLen(NuDataSource* pDataSource, long otherLen); ushort Nu_DataSourceGetRawCrc(const NuDataSource* pDataSource); void Nu_DataSourceSetRawCrc(NuDataSource* pDataSource, ushort crc); NuError Nu_DataSourcePrepareInput(NuArchive* pArchive, - NuDataSource* pDataSource); + NuDataSource* pDataSource); void Nu_DataSourceUnPrepareInput(NuArchive* pArchive, - NuDataSource* pDataSource); + NuDataSource* pDataSource); const char* Nu_DataSourceFile_GetPathname(NuDataSource* pDataSource); NuError Nu_DataSourceGetBlock(NuDataSource* pDataSource, uchar* buf, ulong len); NuError Nu_DataSourceRewind(NuDataSource* pDataSource); NuError Nu_DataSinkFile_New(Boolean doExpand, NuValue convertEOL, - const char* pathname, char fssep, NuDataSink** ppDataSink); + const char* pathname, char fssep, NuDataSink** ppDataSink); NuError Nu_DataSinkFP_New(Boolean doExpand, NuValue convertEOL, FILE* fp, - NuDataSink** ppDataSink); + NuDataSink** ppDataSink); NuError Nu_DataSinkBuffer_New(Boolean doExpand, NuValue convertEOL, - uchar* buffer, ulong bufLen, NuDataSink** ppDataSink); + uchar* buffer, ulong bufLen, NuDataSink** ppDataSink); NuError Nu_DataSinkVoid_New(Boolean doExpand, NuValue convertEOL, - NuDataSink** ppDataSink); + NuDataSink** ppDataSink); NuError Nu_DataSinkFree(NuDataSink* pDataSink); NuDataSinkType Nu_DataSinkGetType(const NuDataSink* pDataSink); Boolean Nu_DataSinkGetDoExpand(const NuDataSink* pDataSink); @@ -768,20 +768,20 @@ NuError Nu_DataSinkGetError(NuDataSink* pDataSink); /* Thread.c */ #ifdef __Thread_c__ - #define THREAD_INLINE /**/ + #define THREAD_INLINE /**/ #else #define THREAD_INLINE extern inline #endif -#if defined(inline) && !defined(__Thread_c__) /* somebody ovrd inline def? */ +#if defined(inline) && !defined(__Thread_c__) /* somebody ovrd inline def? */ NuThread* Nu_GetThread(const NuRecord* pRecord, int idx); #else THREAD_INLINE NuThread* Nu_GetThread(const NuRecord* pRecord, int idx) { - if (idx >= (int)pRecord->recTotalThreads) - return nil; - else - return &pRecord->pThreads[idx]; + if (idx >= (int)pRecord->recTotalThreads) + return nil; + else + return &pRecord->pThreads[idx]; } #endif void Nu_StripHiIfAllSet(char* str); @@ -789,28 +789,28 @@ Boolean Nu_IsPresizedThreadID(NuThreadID threadID); Boolean Nu_IsCompressibleThreadID(NuThreadID threadID); Boolean Nu_ThreadHasCRC(long recordVersion, NuThreadID threadID); NuError Nu_FindThreadByIdx(const NuRecord* pRecord, NuThreadIdx thread, - NuThread** ppThread); + NuThread** ppThread); NuError Nu_FindThreadByID(const NuRecord* pRecord, NuThreadID threadID, - NuThread** ppThread); + NuThread** ppThread); void Nu_CopyThreadContents(NuThread* pDstThread, const NuThread* pSrcThread); NuError Nu_ReadThreadHeaders(NuArchive* pArchive, NuRecord* pRecord, - ushort* pCrc); + ushort* pCrc); NuError Nu_WriteThreadHeaders(NuArchive* pArchive, NuRecord* pRecord, FILE* fp, - ushort* pCrc); + ushort* pCrc); NuError Nu_ComputeThreadData(NuArchive* pArchive, NuRecord* pRecord); NuError Nu_ScanThreads(NuArchive* pArchive, NuRecord* pRecord,long numThreads); NuError Nu_ExtractThreadBulk(NuArchive* pArchive, const NuRecord* pRecord, - const NuThread* pThread); + const NuThread* pThread); NuError Nu_SkipThread(NuArchive* pArchive, const NuRecord* pRecord, - const NuThread* pThread); + const NuThread* pThread); NuError Nu_ExtractThread(NuArchive* pArchive, NuThreadIdx threadIdx, - NuDataSink* pDataSink); + NuDataSink* pDataSink); NuError Nu_OkayToAddThread(NuArchive* pArchive, const NuRecord* pRecord, - NuThreadID threadID); + NuThreadID threadID); NuError Nu_AddThread(NuArchive* pArchive, NuRecordIdx rec, NuThreadID threadID, - NuDataSource* pDataSource, NuThreadIdx* pThreadIdx); + NuDataSource* pDataSource, NuThreadIdx* pThreadIdx); NuError Nu_UpdatePresizedThread(NuArchive* pArchive, NuThreadIdx threadIdx, - NuDataSource* pDataSource, long* pMaxLen); + NuDataSource* pDataSource, long* pMaxLen); NuError Nu_DeleteThread(NuArchive* pArchive, NuThreadIdx threadIdx); /* Value.c */ @@ -818,10 +818,10 @@ NuError Nu_GetValue(NuArchive* pArchive, NuValueID ident, NuValue* pValue); NuError Nu_SetValue(NuArchive* pArchive, NuValueID ident, NuValue value); NuError Nu_GetAttr(NuArchive* pArchive, NuAttrID ident, NuAttr* pAttr); NuThreadFormat Nu_ConvertCompressValToFormat(NuArchive* pArchive, - NuValue compValue); + NuValue compValue); /* Version.c */ NuError Nu_GetVersion(long* pMajorVersion, long* pMinorVersion, - long* pBugVersion, const char** ppBuildDate, const char** ppBuildFlags); + long* pBugVersion, const char** ppBuildDate, const char** ppBuildFlags); #endif /*__NufxLibPriv__*/ diff --git a/nufxlib-0/Record.c b/nufxlib-0/Record.c index dbb6292..2cb8017 100644 --- a/nufxlib-0/Record.c +++ b/nufxlib-0/Record.c @@ -17,7 +17,7 @@ static const uchar kNufxID[kNufxIDLen] = { 0x4e, 0xf5, 0x46, 0xd8 }; /* * =========================================================================== - * Simple NuRecord stuff + * Simple NuRecord stuff * =========================================================================== */ @@ -29,22 +29,22 @@ static const uchar kNufxID[kNufxIDLen] = { 0x4e, 0xf5, 0x46, 0xd8 }; static NuError Nu_InitRecordContents(NuArchive* pArchive, NuRecord* pRecord) { - Assert(pRecord != nil); + Assert(pRecord != nil); - DebugFill(pRecord, sizeof(*pRecord)); + DebugFill(pRecord, sizeof(*pRecord)); - pRecord->recOptionList = nil; - pRecord->extraBytes = nil; - pRecord->recFilename = nil; - pRecord->threadFilename = nil; - pRecord->newFilename = nil; - pRecord->pThreads = nil; - pRecord->pNext = nil; - pRecord->pThreadMods = nil; - pRecord->dirtyHeader = false; - pRecord->dropRecFilename = false; + pRecord->recOptionList = nil; + pRecord->extraBytes = nil; + pRecord->recFilename = nil; + pRecord->threadFilename = nil; + pRecord->newFilename = nil; + pRecord->pThreads = nil; + pRecord->pNext = nil; + pRecord->pThreadMods = nil; + pRecord->dirtyHeader = false; + pRecord->dropRecFilename = false; - return kNuErrNone; + return kNuErrNone; } /* @@ -53,13 +53,13 @@ Nu_InitRecordContents(NuArchive* pArchive, NuRecord* pRecord) static NuError Nu_RecordNew(NuArchive* pArchive, NuRecord** ppRecord) { - Assert(ppRecord != nil); + Assert(ppRecord != nil); - *ppRecord = Nu_Malloc(pArchive, sizeof(**ppRecord)); - if (*ppRecord == nil) - return kNuErrMalloc; + *ppRecord = Nu_Malloc(pArchive, sizeof(**ppRecord)); + if (*ppRecord == nil) + return kNuErrMalloc; - return Nu_InitRecordContents(pArchive, *ppRecord); + return Nu_InitRecordContents(pArchive, *ppRecord); } /* @@ -69,20 +69,20 @@ Nu_RecordNew(NuArchive* pArchive, NuRecord** ppRecord) static NuError Nu_FreeRecordContents(NuArchive* pArchive, NuRecord* pRecord) { - Assert(pRecord != nil); + Assert(pRecord != nil); - Nu_Free(pArchive, pRecord->recOptionList); - Nu_Free(pArchive, pRecord->extraBytes); - Nu_Free(pArchive, pRecord->recFilename); - Nu_Free(pArchive, pRecord->threadFilename); - Nu_Free(pArchive, pRecord->newFilename); - Nu_Free(pArchive, pRecord->pThreads); - /* don't Free(pRecord->pNext)! */ - Nu_FreeThreadMods(pArchive, pRecord); + Nu_Free(pArchive, pRecord->recOptionList); + Nu_Free(pArchive, pRecord->extraBytes); + Nu_Free(pArchive, pRecord->recFilename); + Nu_Free(pArchive, pRecord->threadFilename); + Nu_Free(pArchive, pRecord->newFilename); + Nu_Free(pArchive, pRecord->pThreads); + /* don't Free(pRecord->pNext)! */ + Nu_FreeThreadMods(pArchive, pRecord); - (void) Nu_InitRecordContents(pArchive, pRecord); /* mark as freed */ + (void) Nu_InitRecordContents(pArchive, pRecord); /* mark as freed */ - return kNuErrNone; + return kNuErrNone; } /* @@ -91,13 +91,13 @@ Nu_FreeRecordContents(NuArchive* pArchive, NuRecord* pRecord) static NuError Nu_RecordFree(NuArchive* pArchive, NuRecord* pRecord) { - if (pRecord == nil) - return kNuErrNone; + if (pRecord == nil) + return kNuErrNone; - (void) Nu_FreeRecordContents(pArchive, pRecord); - Nu_Free(pArchive, pRecord); + (void) Nu_FreeRecordContents(pArchive, pRecord); + Nu_Free(pArchive, pRecord); - return kNuErrNone; + return kNuErrNone; } /* @@ -107,24 +107,24 @@ Nu_RecordFree(NuArchive* pArchive, NuRecord* pRecord) static NuError CopySizedField(NuArchive* pArchive, void* vppDst, const void* vpSrc, uint len) { - NuError err = kNuErrNone; - uchar** ppDst = vppDst; - const uchar* pSrc = vpSrc; + NuError err = kNuErrNone; + uchar** ppDst = vppDst; + const uchar* pSrc = vpSrc; - Assert(ppDst != nil); + Assert(ppDst != nil); - if (len) { - Assert(pSrc != nil); - *ppDst = Nu_Malloc(pArchive, len); - BailAlloc(*ppDst); - memcpy(*ppDst, pSrc, len); - } else { - Assert(pSrc == nil); - *ppDst = nil; - } + if (len) { + Assert(pSrc != nil); + *ppDst = Nu_Malloc(pArchive, len); + BailAlloc(*ppDst); + memcpy(*ppDst, pSrc, len); + } else { + Assert(pSrc == nil); + *ppDst = nil; + } bail: - return err; + return err; } /* @@ -133,46 +133,46 @@ bail: static NuError Nu_RecordCopy(NuArchive* pArchive, NuRecord** ppDst, const NuRecord* pSrc) { - NuError err; - NuRecord* pDst; + NuError err; + NuRecord* pDst; - err = Nu_RecordNew(pArchive, ppDst); - BailError(err); + err = Nu_RecordNew(pArchive, ppDst); + BailError(err); - /* copy all the static fields, then copy or blank the "hairy" parts */ - pDst = *ppDst; - memcpy(pDst, pSrc, sizeof(*pSrc)); - CopySizedField(pArchive, &pDst->recOptionList, pSrc->recOptionList, - pSrc->recOptionSize); - CopySizedField(pArchive, &pDst->extraBytes, pSrc->extraBytes, - pSrc->extraCount); - CopySizedField(pArchive, &pDst->recFilename, pSrc->recFilename, - pSrc->recFilenameLength == 0 ? 0 : pSrc->recFilenameLength+1); - CopySizedField(pArchive, &pDst->threadFilename, pSrc->threadFilename, - pSrc->threadFilename == nil ? 0 : strlen(pSrc->threadFilename) +1); - CopySizedField(pArchive, &pDst->newFilename, pSrc->newFilename, - pSrc->newFilename == nil ? 0 : strlen(pSrc->newFilename) +1); - CopySizedField(pArchive, &pDst->pThreads, pSrc->pThreads, - pSrc->recTotalThreads * sizeof(*pDst->pThreads)); + /* copy all the static fields, then copy or blank the "hairy" parts */ + pDst = *ppDst; + memcpy(pDst, pSrc, sizeof(*pSrc)); + CopySizedField(pArchive, &pDst->recOptionList, pSrc->recOptionList, + pSrc->recOptionSize); + CopySizedField(pArchive, &pDst->extraBytes, pSrc->extraBytes, + pSrc->extraCount); + CopySizedField(pArchive, &pDst->recFilename, pSrc->recFilename, + pSrc->recFilenameLength == 0 ? 0 : pSrc->recFilenameLength+1); + CopySizedField(pArchive, &pDst->threadFilename, pSrc->threadFilename, + pSrc->threadFilename == nil ? 0 : strlen(pSrc->threadFilename) +1); + CopySizedField(pArchive, &pDst->newFilename, pSrc->newFilename, + pSrc->newFilename == nil ? 0 : strlen(pSrc->newFilename) +1); + CopySizedField(pArchive, &pDst->pThreads, pSrc->pThreads, + pSrc->recTotalThreads * sizeof(*pDst->pThreads)); - /* now figure out what the filename is supposed to point at */ - if (pSrc->filename == pSrc->threadFilename) - pDst->filename = pDst->threadFilename; - else if (pSrc->filename == pSrc->recFilename) - pDst->filename = pDst->recFilename; - else if (pSrc->filename == pSrc->newFilename) - pDst->filename = pDst->newFilename; - else - pDst->filename = pSrc->filename; /* probably static kDefault value */ + /* now figure out what the filename is supposed to point at */ + if (pSrc->filename == pSrc->threadFilename) + pDst->filename = pDst->threadFilename; + else if (pSrc->filename == pSrc->recFilename) + pDst->filename = pDst->recFilename; + else if (pSrc->filename == pSrc->newFilename) + pDst->filename = pDst->newFilename; + else + pDst->filename = pSrc->filename; /* probably static kDefault value */ - pDst->pNext = nil; + pDst->pNext = nil; - /* these only hold for copy from orig... may need to remove */ - Assert(pSrc->pThreadMods == nil); - Assert(!pSrc->dirtyHeader); + /* these only hold for copy from orig... may need to remove */ + Assert(pSrc->pThreadMods == nil); + Assert(!pSrc->dirtyHeader); bail: - return err; + return err; } @@ -191,22 +191,22 @@ bail: void Nu_RecordAddThreadMod(NuRecord* pRecord, NuThreadMod* pThreadMod) { - NuThreadMod* pScanThreadMod; + NuThreadMod* pScanThreadMod; - Assert(pRecord != nil); - Assert(pThreadMod != nil); + Assert(pRecord != nil); + Assert(pThreadMod != nil); - if (pRecord->pThreadMods == nil) { - pRecord->pThreadMods = pThreadMod; - } else { - pScanThreadMod = pRecord->pThreadMods; - while (pScanThreadMod->pNext != nil) - pScanThreadMod = pScanThreadMod->pNext; + if (pRecord->pThreadMods == nil) { + pRecord->pThreadMods = pThreadMod; + } else { + pScanThreadMod = pRecord->pThreadMods; + while (pScanThreadMod->pNext != nil) + pScanThreadMod = pScanThreadMod->pNext; - pScanThreadMod->pNext = pThreadMod; - } + pScanThreadMod->pNext = pThreadMod; + } - pThreadMod->pNext = nil; + pThreadMod->pNext = nil; } @@ -226,47 +226,47 @@ Nu_RecordAddThreadMod(NuRecord* pRecord, NuThreadMod* pThreadMod) Boolean Nu_RecordIsEmpty(NuArchive* pArchive, const NuRecord* pRecord) { - const NuThreadMod* pThreadMod; - int numThreads; + const NuThreadMod* pThreadMod; + int numThreads; - Assert(pRecord != nil); + Assert(pRecord != nil); - numThreads = pRecord->recTotalThreads; + numThreads = pRecord->recTotalThreads; - pThreadMod = pRecord->pThreadMods; - while (pThreadMod != nil) { - switch (pThreadMod->entry.kind) { - case kNuThreadModAdd: - case kNuThreadModUpdate: - return false; - case kNuThreadModDelete: - numThreads--; - break; - case kNuThreadModUnknown: - default: - Assert(0); - return false; - } + pThreadMod = pRecord->pThreadMods; + while (pThreadMod != nil) { + switch (pThreadMod->entry.kind) { + case kNuThreadModAdd: + case kNuThreadModUpdate: + return false; + case kNuThreadModDelete: + numThreads--; + break; + case kNuThreadModUnknown: + default: + Assert(0); + return false; + } - pThreadMod = pThreadMod->pNext; - } + pThreadMod = pThreadMod->pNext; + } - if (numThreads > 0) - return false; - else if (numThreads == 0) - return true; - else { - Assert(0); - Nu_ReportError(NU_BLOB, kNuErrInternal, - "Thread counting failed (%d)", numThreads); - return false; - } + if (numThreads > 0) + return false; + else if (numThreads == 0) + return true; + else { + Assert(0); + Nu_ReportError(NU_BLOB, kNuErrInternal, + "Thread counting failed (%d)", numThreads); + return false; + } } /* * =========================================================================== - * NuRecordSet functions + * NuRecordSet functions * =========================================================================== */ @@ -277,50 +277,50 @@ Nu_RecordIsEmpty(NuArchive* pArchive, const NuRecord* pRecord) Boolean Nu_RecordSet_GetLoaded(const NuRecordSet* pRecordSet) { - Assert(pRecordSet != nil); - return pRecordSet->loaded; + Assert(pRecordSet != nil); + return pRecordSet->loaded; } void Nu_RecordSet_SetLoaded(NuRecordSet* pRecordSet, Boolean val) { - pRecordSet->loaded = val; + pRecordSet->loaded = val; } ulong Nu_RecordSet_GetNumRecords(const NuRecordSet* pRecordSet) { - return pRecordSet->numRecords; + return pRecordSet->numRecords; } void Nu_RecordSet_SetNumRecords(NuRecordSet* pRecordSet, ulong val) { - pRecordSet->numRecords = val; + pRecordSet->numRecords = val; } void Nu_RecordSet_IncNumRecords(NuRecordSet* pRecordSet) { - pRecordSet->numRecords++; + pRecordSet->numRecords++; } NuRecord* Nu_RecordSet_GetListHead(const NuRecordSet* pRecordSet) { - return pRecordSet->nuRecordHead; + return pRecordSet->nuRecordHead; } NuRecord** Nu_RecordSet_GetListHeadPtr(NuRecordSet* pRecordSet) { - return &pRecordSet->nuRecordHead; + return &pRecordSet->nuRecordHead; } NuRecord* Nu_RecordSet_GetListTail(const NuRecordSet* pRecordSet) { - return pRecordSet->nuRecordTail; + return pRecordSet->nuRecordTail; } @@ -331,10 +331,10 @@ Nu_RecordSet_GetListTail(const NuRecordSet* pRecordSet) Boolean Nu_RecordSet_IsEmpty(const NuRecordSet* pRecordSet) { - if (!pRecordSet->loaded || pRecordSet->numRecords == 0) - return true; + if (!pRecordSet->loaded || pRecordSet->numRecords == 0) + return true; - return false; + return false; } /* @@ -343,33 +343,33 @@ Nu_RecordSet_IsEmpty(const NuRecordSet* pRecordSet) NuError Nu_RecordSet_FreeAllRecords(NuArchive* pArchive, NuRecordSet* pRecordSet) { - NuError err = kNuErrNone; - NuRecord* pRecord; - NuRecord* pNextRecord; + NuError err = kNuErrNone; + NuRecord* pRecord; + NuRecord* pNextRecord; - if (!pRecordSet->loaded) { - Assert(pRecordSet->nuRecordHead == nil); - Assert(pRecordSet->numRecords == 0); - return kNuErrNone; - } + if (!pRecordSet->loaded) { + Assert(pRecordSet->nuRecordHead == nil); + Assert(pRecordSet->numRecords == 0); + return kNuErrNone; + } - DBUG(("+++ FreeAllRecords\n")); - pRecord = pRecordSet->nuRecordHead; - while (pRecord != nil) { - pNextRecord = pRecord->pNext; + DBUG(("+++ FreeAllRecords\n")); + pRecord = pRecordSet->nuRecordHead; + while (pRecord != nil) { + pNextRecord = pRecord->pNext; - err = Nu_RecordFree(pArchive, pRecord); - BailError(err); /* don't really expect this to fail */ + err = Nu_RecordFree(pArchive, pRecord); + BailError(err); /* don't really expect this to fail */ - pRecord = pNextRecord; - } + pRecord = pNextRecord; + } - pRecordSet->nuRecordHead = pRecordSet->nuRecordTail = nil; - pRecordSet->numRecords = 0; - pRecordSet->loaded = false; + pRecordSet->nuRecordHead = pRecordSet->nuRecordTail = nil; + pRecordSet->numRecords = 0; + pRecordSet->loaded = false; bail: - return err; + return err; } @@ -379,27 +379,27 @@ bail: static NuError Nu_RecordSet_AddRecord(NuRecordSet* pRecordSet, NuRecord* pRecord) { - Assert(pRecordSet != nil); - Assert(pRecord != nil); + Assert(pRecordSet != nil); + Assert(pRecord != nil); - /* if one is nil, both must be nil */ - Assert(pRecordSet->nuRecordHead == nil || pRecordSet->nuRecordTail != nil); - Assert(pRecordSet->nuRecordTail == nil || pRecordSet->nuRecordHead != nil); + /* if one is nil, both must be nil */ + Assert(pRecordSet->nuRecordHead == nil || pRecordSet->nuRecordTail != nil); + Assert(pRecordSet->nuRecordTail == nil || pRecordSet->nuRecordHead != nil); - if (pRecordSet->nuRecordHead == nil) { - /* empty list */ - pRecordSet->nuRecordHead = pRecordSet->nuRecordTail = pRecord; - pRecordSet->loaded = true; - Assert(!pRecordSet->numRecords); - } else { - pRecord->pNext = nil; - pRecordSet->nuRecordTail->pNext = pRecord; - pRecordSet->nuRecordTail = pRecord; - } + if (pRecordSet->nuRecordHead == nil) { + /* empty list */ + pRecordSet->nuRecordHead = pRecordSet->nuRecordTail = pRecord; + pRecordSet->loaded = true; + Assert(!pRecordSet->numRecords); + } else { + pRecord->pNext = nil; + pRecordSet->nuRecordTail->pNext = pRecord; + pRecordSet->nuRecordTail = pRecord; + } - pRecordSet->numRecords++; + pRecordSet->numRecords++; - return kNuErrNone; + return kNuErrNone; } @@ -413,42 +413,42 @@ Nu_RecordSet_AddRecord(NuRecordSet* pRecordSet, NuRecord* pRecord) */ NuError Nu_RecordSet_DeleteRecordPtr(NuArchive* pArchive, NuRecordSet* pRecordSet, - NuRecord** ppRecord) + NuRecord** ppRecord) { - NuError err; - NuRecord* pRecord; + NuError err; + NuRecord* pRecord; - Assert(pRecordSet != nil); - Assert(ppRecord != nil); - Assert(*ppRecord != nil); + Assert(pRecordSet != nil); + Assert(ppRecord != nil); + Assert(*ppRecord != nil); - /* save a copy of the record we're freeing */ - pRecord = *ppRecord; + /* save a copy of the record we're freeing */ + pRecord = *ppRecord; - /* update the pHead or pNext pointer */ - *ppRecord = (*ppRecord)->pNext; - pRecordSet->numRecords--; + /* update the pHead or pNext pointer */ + *ppRecord = (*ppRecord)->pNext; + pRecordSet->numRecords--; - /* if we're deleting the tail, we have to find the "new" last entry */ - if (pRecord == pRecordSet->nuRecordTail) { - if (pRecordSet->nuRecordHead == nil) { - /* this was the last entry; we're done */ - pRecordSet->nuRecordTail = nil; - } else { - /* walk through the list... delete bottom-up will be slow! */ - pRecordSet->nuRecordTail = pRecordSet->nuRecordHead; - while (pRecordSet->nuRecordTail->pNext != nil) - pRecordSet->nuRecordTail = pRecordSet->nuRecordTail->pNext; - } - } + /* if we're deleting the tail, we have to find the "new" last entry */ + if (pRecord == pRecordSet->nuRecordTail) { + if (pRecordSet->nuRecordHead == nil) { + /* this was the last entry; we're done */ + pRecordSet->nuRecordTail = nil; + } else { + /* walk through the list... delete bottom-up will be slow! */ + pRecordSet->nuRecordTail = pRecordSet->nuRecordHead; + while (pRecordSet->nuRecordTail->pNext != nil) + pRecordSet->nuRecordTail = pRecordSet->nuRecordTail->pNext; + } + } - if (pRecordSet->numRecords) - Assert(pRecordSet->nuRecordHead!=nil && pRecordSet->nuRecordTail!=nil); - else - Assert(pRecordSet->nuRecordHead==nil && pRecordSet->nuRecordTail==nil); + if (pRecordSet->numRecords) + Assert(pRecordSet->nuRecordHead!=nil && pRecordSet->nuRecordTail!=nil); + else + Assert(pRecordSet->nuRecordHead==nil && pRecordSet->nuRecordTail==nil); - err = Nu_RecordFree(pArchive, pRecord); - return err; + err = Nu_RecordFree(pArchive, pRecord); + return err; } /* @@ -456,32 +456,32 @@ Nu_RecordSet_DeleteRecordPtr(NuArchive* pArchive, NuRecordSet* pRecordSet, */ NuError Nu_RecordSet_DeleteRecord(NuArchive* pArchive, NuRecordSet* pRecordSet, - NuRecord* pRecord) + NuRecord* pRecord) { - NuError err; - NuRecord** ppRecord; + NuError err; + NuRecord** ppRecord; - ppRecord = Nu_RecordSet_GetListHeadPtr(pRecordSet); - Assert(ppRecord != nil); - Assert(*ppRecord != nil); + ppRecord = Nu_RecordSet_GetListHeadPtr(pRecordSet); + Assert(ppRecord != nil); + Assert(*ppRecord != nil); - /* look for the record, so we can update his neighbors */ - /* (this also ensures that the record really is in the set we think it is)*/ - while (*ppRecord) { - if (*ppRecord == pRecord) { - err = Nu_RecordSet_DeleteRecordPtr(pArchive, pRecordSet, ppRecord); - BailError(err); - goto bail; - } + /* look for the record, so we can update his neighbors */ + /* (this also ensures that the record really is in the set we think it is)*/ + while (*ppRecord) { + if (*ppRecord == pRecord) { + err = Nu_RecordSet_DeleteRecordPtr(pArchive, pRecordSet, ppRecord); + BailError(err); + goto bail; + } - ppRecord = &((*ppRecord)->pNext); - } + ppRecord = &((*ppRecord)->pNext); + } - DBUG(("--- Nu_RecordSet_DeleteRecord failed\n")); - err = kNuErrNotFound; + DBUG(("--- Nu_RecordSet_DeleteRecord failed\n")); + err = kNuErrNotFound; bail: - return err; + return err; } /* @@ -490,39 +490,39 @@ bail: */ NuError Nu_RecordSet_Clone(NuArchive* pArchive, NuRecordSet* pDstSet, - const NuRecordSet* pSrcSet) + const NuRecordSet* pSrcSet) { - NuError err = kNuErrNone; - const NuRecord* pSrcRecord; - NuRecord* pDstRecord; + NuError err = kNuErrNone; + const NuRecord* pSrcRecord; + NuRecord* pDstRecord; - Assert(pDstSet != nil); - Assert(pSrcSet != nil); - Assert(Nu_RecordSet_GetLoaded(pDstSet) == false); - Assert(Nu_RecordSet_GetLoaded(pSrcSet) == true); + Assert(pDstSet != nil); + Assert(pSrcSet != nil); + Assert(Nu_RecordSet_GetLoaded(pDstSet) == false); + Assert(Nu_RecordSet_GetLoaded(pSrcSet) == true); - DBUG(("--- Cloning record set\n")); + DBUG(("--- Cloning record set\n")); - Nu_RecordSet_SetLoaded(pDstSet, true); + Nu_RecordSet_SetLoaded(pDstSet, true); - /* copy each record over */ - pSrcRecord = pSrcSet->nuRecordHead; - while (pSrcRecord != nil) { - err = Nu_RecordCopy(pArchive, &pDstRecord, pSrcRecord); - BailError(err); - err = Nu_RecordSet_AddRecord(pDstSet, pDstRecord); - BailError(err); + /* copy each record over */ + pSrcRecord = pSrcSet->nuRecordHead; + while (pSrcRecord != nil) { + err = Nu_RecordCopy(pArchive, &pDstRecord, pSrcRecord); + BailError(err); + err = Nu_RecordSet_AddRecord(pDstSet, pDstRecord); + BailError(err); - pSrcRecord = pSrcRecord->pNext; - } + pSrcRecord = pSrcRecord->pNext; + } - Assert(pDstSet->numRecords == pSrcSet->numRecords); + Assert(pDstSet->numRecords == pSrcSet->numRecords); bail: - if (err != kNuErrNone) { - Nu_RecordSet_FreeAllRecords(pArchive, pDstSet); - } - return err; + if (err != kNuErrNone) { + Nu_RecordSet_FreeAllRecords(pArchive, pDstSet); + } + return err; } /* @@ -532,36 +532,36 @@ bail: */ NuError Nu_RecordSet_MoveAllRecords(NuArchive* pArchive, NuRecordSet* pDstSet, - NuRecordSet* pSrcSet) + NuRecordSet* pSrcSet) { - NuError err = kNuErrNone; + NuError err = kNuErrNone; - Assert(pDstSet != nil); - Assert(pSrcSet != nil); + Assert(pDstSet != nil); + Assert(pSrcSet != nil); - if (!Nu_RecordSet_GetNumRecords(pSrcSet)) /* nothing to do? */ - return kNuErrNone; + if (!Nu_RecordSet_GetNumRecords(pSrcSet)) /* nothing to do? */ + return kNuErrNone; - if (pDstSet->nuRecordHead == nil) { - /* empty dst list */ - pDstSet->nuRecordHead = pSrcSet->nuRecordHead; - pDstSet->nuRecordTail = pSrcSet->nuRecordTail; - pDstSet->numRecords = pSrcSet->numRecords; - pDstSet->loaded = true; - } else { - /* append to dst list */ - Assert(pDstSet->loaded); - pDstSet->nuRecordTail->pNext = pSrcSet->nuRecordHead; - pDstSet->nuRecordTail = pSrcSet->nuRecordTail; - pDstSet->numRecords += pSrcSet->numRecords; - } + if (pDstSet->nuRecordHead == nil) { + /* empty dst list */ + pDstSet->nuRecordHead = pSrcSet->nuRecordHead; + pDstSet->nuRecordTail = pSrcSet->nuRecordTail; + pDstSet->numRecords = pSrcSet->numRecords; + pDstSet->loaded = true; + } else { + /* append to dst list */ + Assert(pDstSet->loaded); + pDstSet->nuRecordTail->pNext = pSrcSet->nuRecordHead; + pDstSet->nuRecordTail = pSrcSet->nuRecordTail; + pDstSet->numRecords += pSrcSet->numRecords; + } - /* nuke all pointers in original list */ - pSrcSet->nuRecordHead = pSrcSet->nuRecordTail = nil; - pSrcSet->numRecords = 0; - pSrcSet->loaded = false; + /* nuke all pointers in original list */ + pSrcSet->nuRecordHead = pSrcSet->nuRecordTail = nil; + pSrcSet->numRecords = 0; + pSrcSet->loaded = false; - return err; + return err; } @@ -570,21 +570,21 @@ Nu_RecordSet_MoveAllRecords(NuArchive* pArchive, NuRecordSet* pDstSet, */ NuError Nu_RecordSet_FindByIdx(const NuRecordSet* pRecordSet, NuRecordIdx recIdx, - NuRecord** ppRecord) + NuRecord** ppRecord) { - NuRecord* pRecord; + NuRecord* pRecord; - pRecord = pRecordSet->nuRecordHead; - while (pRecord != nil) { - if (pRecord->recordIdx == recIdx) { - *ppRecord = pRecord; - return kNuErrNone; - } + pRecord = pRecordSet->nuRecordHead; + while (pRecord != nil) { + if (pRecord->recordIdx == recIdx) { + *ppRecord = pRecord; + return kNuErrNone; + } - pRecord = pRecord->pNext; - } + pRecord = pRecord->pNext; + } - return kNuErrRecIdxNotFound; + return kNuErrRecIdxNotFound; } @@ -593,23 +593,23 @@ Nu_RecordSet_FindByIdx(const NuRecordSet* pRecordSet, NuRecordIdx recIdx, */ NuError Nu_RecordSet_FindByThreadIdx(NuRecordSet* pRecordSet, NuThreadIdx threadIdx, - NuRecord** ppRecord, NuThread** ppThread) + NuRecord** ppRecord, NuThread** ppThread) { - NuError err = kNuErrThreadIdxNotFound; - NuRecord* pRecord; + NuError err = kNuErrThreadIdxNotFound; + NuRecord* pRecord; - pRecord = Nu_RecordSet_GetListHead(pRecordSet); - while (pRecord != nil) { - err = Nu_FindThreadByIdx(pRecord, threadIdx, ppThread); - if (err == kNuErrNone) { - *ppRecord = pRecord; - break; - } - pRecord = pRecord->pNext; - } + pRecord = Nu_RecordSet_GetListHead(pRecordSet); + while (pRecord != nil) { + err = Nu_FindThreadByIdx(pRecord, threadIdx, ppThread); + if (err == kNuErrNone) { + *ppRecord = pRecord; + break; + } + pRecord = pRecord->pNext; + } - Assert(err != kNuErrNone || (*ppRecord != nil && *ppThread != nil)); - return err; + Assert(err != kNuErrNone || (*ppRecord != nil && *ppThread != nil)); + return err; } @@ -617,10 +617,10 @@ Nu_RecordSet_FindByThreadIdx(NuRecordSet* pRecordSet, NuThreadIdx threadIdx, * Compare two filenames pulled out of a record. * * Interesting issues: - * - some filesystems are case-sensitive, some aren't - * - the fssep may be different ('/', ':') for otherwise equivalent names - * - system-dependent conversions could resolve two different names to - * the same thing + * - some filesystems are case-sensitive, some aren't + * - the fssep may be different ('/', ':') for otherwise equivalent names + * - system-dependent conversions could resolve two different names to + * the same thing * * Some of these are out of our control. For now, I'm just doing a * case-sensitive comparison, since the most interesting case for us is @@ -637,7 +637,7 @@ Nu_RecordSet_FindByThreadIdx(NuRecordSet* pRecordSet, NuThreadIdx threadIdx, static int Nu_CompareRecordNames(const char* name1, const char* name2) { - return strcmp(name1, name2); + return strcmp(name1, name2); } @@ -646,26 +646,26 @@ Nu_CompareRecordNames(const char* name1, const char* name2) */ static NuError Nu_RecordSet_FindByName(const NuRecordSet* pRecordSet, const char* name, - NuRecord** ppRecord) + NuRecord** ppRecord) { - NuRecord* pRecord; + NuRecord* pRecord; - Assert(pRecordSet != nil); - Assert(pRecordSet->loaded); - Assert(name != nil); - Assert(ppRecord != nil); + Assert(pRecordSet != nil); + Assert(pRecordSet->loaded); + Assert(name != nil); + Assert(ppRecord != nil); - pRecord = pRecordSet->nuRecordHead; - while (pRecord != nil) { - if (Nu_CompareRecordNames(pRecord->filename, name) == 0) { - *ppRecord = pRecord; - return kNuErrNone; - } + pRecord = pRecordSet->nuRecordHead; + while (pRecord != nil) { + if (Nu_CompareRecordNames(pRecord->filename, name) == 0) { + *ppRecord = pRecord; + return kNuErrNone; + } - pRecord = pRecord->pNext; - } + pRecord = pRecord->pNext; + } - return kNuErrRecNameNotFound; + return kNuErrRecNameNotFound; } /* @@ -678,29 +678,29 @@ Nu_RecordSet_FindByName(const NuRecordSet* pRecordSet, const char* name, */ static NuError Nu_RecordSet_ReverseFindByName(const NuRecordSet* pRecordSet, const char* name, - NuRecord** ppRecord) + NuRecord** ppRecord) { - NuRecord* pRecord; - NuRecord* pFoundRecord = nil; + NuRecord* pRecord; + NuRecord* pFoundRecord = nil; - Assert(pRecordSet != nil); - Assert(pRecordSet->loaded); - Assert(name != nil); - Assert(ppRecord != nil); + Assert(pRecordSet != nil); + Assert(pRecordSet->loaded); + Assert(name != nil); + Assert(ppRecord != nil); - pRecord = pRecordSet->nuRecordHead; - while (pRecord != nil) { - if (Nu_CompareRecordNames(pRecord->filename, name) == 0) - pFoundRecord = pRecord; + pRecord = pRecordSet->nuRecordHead; + while (pRecord != nil) { + if (Nu_CompareRecordNames(pRecord->filename, name) == 0) + pFoundRecord = pRecord; - pRecord = pRecord->pNext; - } + pRecord = pRecord->pNext; + } - if (pFoundRecord != nil) { - *ppRecord = pFoundRecord; - return kNuErrNone; - } - return kNuErrRecNameNotFound; + if (pFoundRecord != nil) { + *ppRecord = pFoundRecord; + return kNuErrNone; + } + return kNuErrRecNameNotFound; } @@ -716,74 +716,74 @@ Nu_RecordSet_ReverseFindByName(const NuRecordSet* pRecordSet, const char* name, */ NuError Nu_RecordSet_ReplaceRecord(NuArchive* pArchive, NuRecordSet* pBadSet, - NuRecord* pBadRecord, NuRecordSet* pGoodSet, NuRecord** ppNewRecord) + NuRecord* pBadRecord, NuRecordSet* pGoodSet, NuRecord** ppNewRecord) { - NuError err; - NuRecord* pGoodRecord; - NuRecord* pSiblingRecord; - NuRecord* pNewRecord = nil; + NuError err; + NuRecord* pGoodRecord; + NuRecord* pSiblingRecord; + NuRecord* pNewRecord = nil; - Assert(pArchive != nil); - Assert(pBadSet != nil); - Assert(pBadRecord != nil); - Assert(pGoodSet != nil); - Assert(ppNewRecord != nil); + Assert(pArchive != nil); + Assert(pBadSet != nil); + Assert(pBadRecord != nil); + Assert(pGoodSet != nil); + Assert(ppNewRecord != nil); - /* - * Find a record in "pGoodSet" that has the same record index as - * the "bad" record. - */ - err = Nu_RecordSet_FindByIdx(pGoodSet, pBadRecord->recordIdx, - &pGoodRecord); - BailError(err); + /* + * Find a record in "pGoodSet" that has the same record index as + * the "bad" record. + */ + err = Nu_RecordSet_FindByIdx(pGoodSet, pBadRecord->recordIdx, + &pGoodRecord); + BailError(err); - /* - * Clone the original. - */ - err = Nu_RecordCopy(pArchive, &pNewRecord, pGoodRecord); - BailError(err); + /* + * Clone the original. + */ + err = Nu_RecordCopy(pArchive, &pNewRecord, pGoodRecord); + BailError(err); - /* - * Insert the new one into the "bad" record set, in the exact same - * position. - */ - pNewRecord->pNext = pBadRecord->pNext; - if (pBadSet->nuRecordTail == pBadRecord) - pBadSet->nuRecordTail = pNewRecord; - if (pBadSet->nuRecordHead == pBadRecord) - pBadSet->nuRecordHead = pNewRecord; - else { - /* find the record that points to pBadRecord */ - pSiblingRecord = pBadSet->nuRecordHead; - while (pSiblingRecord->pNext != pBadRecord && pSiblingRecord != nil) - pSiblingRecord = pSiblingRecord->pNext; + /* + * Insert the new one into the "bad" record set, in the exact same + * position. + */ + pNewRecord->pNext = pBadRecord->pNext; + if (pBadSet->nuRecordTail == pBadRecord) + pBadSet->nuRecordTail = pNewRecord; + if (pBadSet->nuRecordHead == pBadRecord) + pBadSet->nuRecordHead = pNewRecord; + else { + /* find the record that points to pBadRecord */ + pSiblingRecord = pBadSet->nuRecordHead; + while (pSiblingRecord->pNext != pBadRecord && pSiblingRecord != nil) + pSiblingRecord = pSiblingRecord->pNext; - if (pSiblingRecord == nil) { - /* looks like "pBadRecord" wasn't part of "pBadSet" after all */ - assert(0); - err = kNuErrInternal; - goto bail; - } + if (pSiblingRecord == nil) { + /* looks like "pBadRecord" wasn't part of "pBadSet" after all */ + assert(0); + err = kNuErrInternal; + goto bail; + } - pSiblingRecord->pNext = pNewRecord; - } + pSiblingRecord->pNext = pNewRecord; + } - err = Nu_RecordFree(pArchive, pBadRecord); - BailError(err); + err = Nu_RecordFree(pArchive, pBadRecord); + BailError(err); - *ppNewRecord = pNewRecord; - pNewRecord = nil; /* don't free */ + *ppNewRecord = pNewRecord; + pNewRecord = nil; /* don't free */ bail: - if (pNewRecord != nil) - Nu_RecordFree(pArchive, pNewRecord); - return err; + if (pNewRecord != nil) + Nu_RecordFree(pArchive, pNewRecord); + return err; } /* * =========================================================================== - * Assorted utility functions + * Assorted utility functions * =========================================================================== */ @@ -794,54 +794,54 @@ bail: Boolean Nu_ShouldIgnoreBadCRC(NuArchive* pArchive, const NuRecord* pRecord, NuError err) { - NuErrorStatus errorStatus; - NuResult result; - Boolean retval = false; + NuErrorStatus errorStatus; + NuResult result; + Boolean retval = false; - Assert(pArchive->valIgnoreCRC == false); + Assert(pArchive->valIgnoreCRC == false); - if (pArchive->errorHandlerFunc != nil) { - errorStatus.operation = kNuOpTest; /* mostly accurate */ - errorStatus.err = err; - errorStatus.sysErr = 0; - errorStatus.message = nil; - errorStatus.pRecord = pRecord; - errorStatus.pathname = nil; - errorStatus.filenameSeparator = 0; - if (pRecord != nil) { - errorStatus.pathname = pRecord->filename; - errorStatus.filenameSeparator = - NuGetSepFromSysInfo(pRecord->recFileSysInfo); - } - /*errorStatus.origArchiveTouched = false;*/ - errorStatus.canAbort = true; - errorStatus.canRetry = false; - errorStatus.canIgnore = true; - errorStatus.canSkip = false; - errorStatus.canRename = false; - errorStatus.canOverwrite = false; + if (pArchive->errorHandlerFunc != nil) { + errorStatus.operation = kNuOpTest; /* mostly accurate */ + errorStatus.err = err; + errorStatus.sysErr = 0; + errorStatus.message = nil; + errorStatus.pRecord = pRecord; + errorStatus.pathname = nil; + errorStatus.filenameSeparator = 0; + if (pRecord != nil) { + errorStatus.pathname = pRecord->filename; + errorStatus.filenameSeparator = + NuGetSepFromSysInfo(pRecord->recFileSysInfo); + } + /*errorStatus.origArchiveTouched = false;*/ + errorStatus.canAbort = true; + errorStatus.canRetry = false; + errorStatus.canIgnore = true; + errorStatus.canSkip = false; + errorStatus.canRename = false; + errorStatus.canOverwrite = false; - result = (*pArchive->errorHandlerFunc)(pArchive, &errorStatus); + result = (*pArchive->errorHandlerFunc)(pArchive, &errorStatus); - switch (result) { - case kNuAbort: - goto bail; - case kNuIgnore: - retval = true; - goto bail; - case kNuSkip: - case kNuOverwrite: - case kNuRetry: - case kNuRename: - default: - Nu_ReportError(NU_BLOB, kNuErrSyntax, - "Wasn't expecting result %d here", result); - break; - } - } + switch (result) { + case kNuAbort: + goto bail; + case kNuIgnore: + retval = true; + goto bail; + case kNuSkip: + case kNuOverwrite: + case kNuRetry: + case kNuRename: + default: + Nu_ReportError(NU_BLOB, kNuErrSyntax, + "Wasn't expecting result %d here", result); + break; + } + } bail: - return retval; + return retval; } @@ -854,188 +854,188 @@ bail: static NuError Nu_ReadRecordHeader(NuArchive* pArchive, NuRecord* pRecord) { - NuError err = kNuErrNone; - ushort crc; - FILE* fp; - int bytesRead; + NuError err = kNuErrNone; + ushort crc; + FILE* fp; + int bytesRead; - Assert(pArchive != nil); - Assert(pRecord != nil); - Assert(pRecord->pThreads == nil); - Assert(pRecord->pNext == nil); + Assert(pArchive != nil); + Assert(pRecord != nil); + Assert(pRecord->pThreads == nil); + Assert(pRecord->pNext == nil); - fp = pArchive->archiveFp; + fp = pArchive->archiveFp; - pRecord->recordIdx = Nu_GetNextRecordIdx(pArchive); + pRecord->recordIdx = Nu_GetNextRecordIdx(pArchive); - /* points to whichever filename storage we like best */ - pRecord->filename = nil; - pRecord->fileOffset = pArchive->currentOffset; + /* points to whichever filename storage we like best */ + pRecord->filename = nil; + pRecord->fileOffset = pArchive->currentOffset; - (void) Nu_ReadBytes(pArchive, fp, pRecord->recNufxID, kNufxIDLen); - if (memcmp(kNufxID, pRecord->recNufxID, kNufxIDLen) != 0) { - err = kNuErrRecHdrNotFound; - Nu_ReportError(NU_BLOB, kNuErrNone, - "Couldn't find start of next record"); - goto bail; - } + (void) Nu_ReadBytes(pArchive, fp, pRecord->recNufxID, kNufxIDLen); + if (memcmp(kNufxID, pRecord->recNufxID, kNufxIDLen) != 0) { + err = kNuErrRecHdrNotFound; + Nu_ReportError(NU_BLOB, kNuErrNone, + "Couldn't find start of next record"); + goto bail; + } - /* - * Read the static fields. - */ - crc = 0; - pRecord->recHeaderCRC = Nu_ReadTwo(pArchive, fp); - pRecord->recAttribCount = Nu_ReadTwoC(pArchive, fp, &crc); - pRecord->recVersionNumber = Nu_ReadTwoC(pArchive, fp, &crc); - pRecord->recTotalThreads = Nu_ReadFourC(pArchive, fp, &crc); - pRecord->recFileSysID = Nu_ReadTwoC(pArchive, fp, &crc); - pRecord->recFileSysInfo = Nu_ReadTwoC(pArchive, fp, &crc); - pRecord->recAccess = Nu_ReadFourC(pArchive, fp, &crc); - pRecord->recFileType = Nu_ReadFourC(pArchive, fp, &crc); - pRecord->recExtraType = Nu_ReadFourC(pArchive, fp, &crc); - pRecord->recStorageType = Nu_ReadTwoC(pArchive, fp, &crc); - pRecord->recCreateWhen = Nu_ReadDateTimeC(pArchive, fp, &crc); - pRecord->recModWhen = Nu_ReadDateTimeC(pArchive, fp, &crc); - pRecord->recArchiveWhen = Nu_ReadDateTimeC(pArchive, fp, &crc); - bytesRead = 56; /* 4-byte 'NuFX' plus the above */ + /* + * Read the static fields. + */ + crc = 0; + pRecord->recHeaderCRC = Nu_ReadTwo(pArchive, fp); + pRecord->recAttribCount = Nu_ReadTwoC(pArchive, fp, &crc); + pRecord->recVersionNumber = Nu_ReadTwoC(pArchive, fp, &crc); + pRecord->recTotalThreads = Nu_ReadFourC(pArchive, fp, &crc); + pRecord->recFileSysID = Nu_ReadTwoC(pArchive, fp, &crc); + pRecord->recFileSysInfo = Nu_ReadTwoC(pArchive, fp, &crc); + pRecord->recAccess = Nu_ReadFourC(pArchive, fp, &crc); + pRecord->recFileType = Nu_ReadFourC(pArchive, fp, &crc); + pRecord->recExtraType = Nu_ReadFourC(pArchive, fp, &crc); + pRecord->recStorageType = Nu_ReadTwoC(pArchive, fp, &crc); + pRecord->recCreateWhen = Nu_ReadDateTimeC(pArchive, fp, &crc); + pRecord->recModWhen = Nu_ReadDateTimeC(pArchive, fp, &crc); + pRecord->recArchiveWhen = Nu_ReadDateTimeC(pArchive, fp, &crc); + bytesRead = 56; /* 4-byte 'NuFX' plus the above */ - /* - * Do some sanity checks before we continue. - */ + /* + * Do some sanity checks before we continue. + */ if ((err = Nu_HeaderIOFailed(pArchive, fp)) != kNuErrNone) { Nu_ReportError(NU_BLOB, err, "Failed reading record header"); goto bail; } - if (pRecord->recAttribCount > kNuReasonableAttribCount) { - err = kNuErrBadRecord; - Nu_ReportError(NU_BLOB, err, "Attrib count is huge (%u)", - pRecord->recAttribCount); - goto bail; - } - if (pRecord->recVersionNumber > kNuMaxRecordVersion) { - err = kNuErrBadRecord; - Nu_ReportError(NU_BLOB, err, "Unrecognized record version number (%u)", - pRecord->recVersionNumber); - goto bail; - } - if (pRecord->recTotalThreads > kNuReasonableTotalThreads) { - err = kNuErrBadRecord; - Nu_ReportError(NU_BLOB, err, "Unreasonable number of threads (%lu)", - pRecord->recTotalThreads); - goto bail; - } + if (pRecord->recAttribCount > kNuReasonableAttribCount) { + err = kNuErrBadRecord; + Nu_ReportError(NU_BLOB, err, "Attrib count is huge (%u)", + pRecord->recAttribCount); + goto bail; + } + if (pRecord->recVersionNumber > kNuMaxRecordVersion) { + err = kNuErrBadRecord; + Nu_ReportError(NU_BLOB, err, "Unrecognized record version number (%u)", + pRecord->recVersionNumber); + goto bail; + } + if (pRecord->recTotalThreads > kNuReasonableTotalThreads) { + err = kNuErrBadRecord; + Nu_ReportError(NU_BLOB, err, "Unreasonable number of threads (%lu)", + pRecord->recTotalThreads); + goto bail; + } - /* - * Read the option list, if present. - */ - if (pRecord->recVersionNumber > 0) { - pRecord->recOptionSize = Nu_ReadTwoC(pArchive, fp, &crc); - bytesRead += 2; + /* + * Read the option list, if present. + */ + if (pRecord->recVersionNumber > 0) { + pRecord->recOptionSize = Nu_ReadTwoC(pArchive, fp, &crc); + bytesRead += 2; - if (pRecord->recOptionSize + bytesRead > pRecord->recAttribCount -2) { - /* option size exceeds the total attribute area */ - err = kNuErrBadRecord; - Nu_ReportError(NU_BLOB, kNuErrBadRecord, - "Option size exceeds attribs (%u)", pRecord->recOptionSize); - goto bail; - } + if (pRecord->recOptionSize + bytesRead > pRecord->recAttribCount -2) { + /* option size exceeds the total attribute area */ + err = kNuErrBadRecord; + Nu_ReportError(NU_BLOB, kNuErrBadRecord, + "Option size exceeds attribs (%u)", pRecord->recOptionSize); + goto bail; + } - if (pRecord->recOptionSize) { - pRecord->recOptionList = Nu_Malloc(pArchive,pRecord->recOptionSize); - BailAlloc(pRecord->recOptionList); - (void) Nu_ReadBytesC(pArchive, fp, pRecord->recOptionList, - pRecord->recOptionSize, &crc); - bytesRead += pRecord->recOptionSize; - } - } else { - pRecord->recOptionSize = 0; - pRecord->recOptionList = nil; - } + if (pRecord->recOptionSize) { + pRecord->recOptionList = Nu_Malloc(pArchive,pRecord->recOptionSize); + BailAlloc(pRecord->recOptionList); + (void) Nu_ReadBytesC(pArchive, fp, pRecord->recOptionList, + pRecord->recOptionSize, &crc); + bytesRead += pRecord->recOptionSize; + } + } else { + pRecord->recOptionSize = 0; + pRecord->recOptionList = nil; + } - /* last two bytes are the filename len; all else is "extra" */ - pRecord->extraCount = (pRecord->recAttribCount -2) - bytesRead; - Assert(pRecord->extraCount >= 0); + /* last two bytes are the filename len; all else is "extra" */ + pRecord->extraCount = (pRecord->recAttribCount -2) - bytesRead; + Assert(pRecord->extraCount >= 0); - /* - * Some programs (for example, NuLib) may leave extra junk in here. This - * is allowed by the archive spec. We may want to preserve it, so we - * allocate space for it and read it if it exists. - */ - if (pRecord->extraCount) { - pRecord->extraBytes = Nu_Malloc(pArchive, pRecord->extraCount); - BailAlloc(pRecord->extraBytes); - (void) Nu_ReadBytesC(pArchive, fp, pRecord->extraBytes, - pRecord->extraCount, &crc); - bytesRead += pRecord->extraCount; - } + /* + * Some programs (for example, NuLib) may leave extra junk in here. This + * is allowed by the archive spec. We may want to preserve it, so we + * allocate space for it and read it if it exists. + */ + if (pRecord->extraCount) { + pRecord->extraBytes = Nu_Malloc(pArchive, pRecord->extraCount); + BailAlloc(pRecord->extraBytes); + (void) Nu_ReadBytesC(pArchive, fp, pRecord->extraBytes, + pRecord->extraCount, &crc); + bytesRead += pRecord->extraCount; + } - /* - * Read the in-record filename if one exists (likely in v0 records only). - */ - pRecord->recFilenameLength = Nu_ReadTwoC(pArchive, fp, &crc); - bytesRead += 2; - if (pRecord->recFilenameLength > kNuReasonableFilenameLen) { - err = kNuErrBadRecord; - Nu_ReportError(NU_BLOB, kNuErrBadRecord, "Filename length is huge (%u)", - pRecord->recFilenameLength); - goto bail; - } - if (pRecord->recFilenameLength) { - pRecord->recFilename = Nu_Malloc(pArchive, pRecord->recFilenameLength +1); - BailAlloc(pRecord->recFilename); - (void) Nu_ReadBytesC(pArchive, fp, pRecord->recFilename, - pRecord->recFilenameLength, &crc); - pRecord->recFilename[pRecord->recFilenameLength] = '\0'; + /* + * Read the in-record filename if one exists (likely in v0 records only). + */ + pRecord->recFilenameLength = Nu_ReadTwoC(pArchive, fp, &crc); + bytesRead += 2; + if (pRecord->recFilenameLength > kNuReasonableFilenameLen) { + err = kNuErrBadRecord; + Nu_ReportError(NU_BLOB, kNuErrBadRecord, "Filename length is huge (%u)", + pRecord->recFilenameLength); + goto bail; + } + if (pRecord->recFilenameLength) { + pRecord->recFilename = Nu_Malloc(pArchive, pRecord->recFilenameLength +1); + BailAlloc(pRecord->recFilename); + (void) Nu_ReadBytesC(pArchive, fp, pRecord->recFilename, + pRecord->recFilenameLength, &crc); + pRecord->recFilename[pRecord->recFilenameLength] = '\0'; - bytesRead += pRecord->recFilenameLength; + bytesRead += pRecord->recFilenameLength; - Nu_StripHiIfAllSet(pRecord->recFilename); - - /* use the in-header one */ - pRecord->filename = pRecord->recFilename; - } + Nu_StripHiIfAllSet(pRecord->recFilename); + + /* use the in-header one */ + pRecord->filename = pRecord->recFilename; + } - /* - * Read the threads records. The data is included in the record header - * CRC, so we have to pass that in too. - */ - err = Nu_ReadThreadHeaders(pArchive, pRecord, &crc); - BailError(err); + /* + * Read the threads records. The data is included in the record header + * CRC, so we have to pass that in too. + */ + err = Nu_ReadThreadHeaders(pArchive, pRecord, &crc); + BailError(err); - /* - * After all is said and done, did we read the file without errors, - * and does the CRC match? - */ + /* + * After all is said and done, did we read the file without errors, + * and does the CRC match? + */ if ((err = Nu_HeaderIOFailed(pArchive, fp)) != kNuErrNone) { Nu_ReportError(NU_BLOB, err, "Failed reading late record header"); goto bail; } - if (!pArchive->valIgnoreCRC && crc != pRecord->recHeaderCRC) { - if (!Nu_ShouldIgnoreBadCRC(pArchive, pRecord, kNuErrBadRHCRC)) { - err = kNuErrBadRHCRC; - Nu_ReportError(NU_BLOB, err, "Stored RH CRC=0x%04x, calc=0x%04x", - pRecord->recHeaderCRC, crc); - goto bail; - } - } + if (!pArchive->valIgnoreCRC && crc != pRecord->recHeaderCRC) { + if (!Nu_ShouldIgnoreBadCRC(pArchive, pRecord, kNuErrBadRHCRC)) { + err = kNuErrBadRHCRC; + Nu_ReportError(NU_BLOB, err, "Stored RH CRC=0x%04x, calc=0x%04x", + pRecord->recHeaderCRC, crc); + goto bail; + } + } - /* - * Init or compute misc record fields. - */ - /* adjust "currentOffset" for the entire record header */ - pArchive->currentOffset += bytesRead; - pArchive->currentOffset += pRecord->recTotalThreads * kNuThreadHeaderSize; + /* + * Init or compute misc record fields. + */ + /* adjust "currentOffset" for the entire record header */ + pArchive->currentOffset += bytesRead; + pArchive->currentOffset += pRecord->recTotalThreads * kNuThreadHeaderSize; - pRecord->recHeaderLength = - bytesRead + pRecord->recTotalThreads * kNuThreadHeaderSize; + pRecord->recHeaderLength = + bytesRead + pRecord->recTotalThreads * kNuThreadHeaderSize; - err = Nu_ComputeThreadData(pArchive, pRecord); - BailError(err); + err = Nu_ComputeThreadData(pArchive, pRecord); + BailError(err); bail: - if (err != kNuErrNone) - (void)Nu_FreeRecordContents(pArchive, pRecord); - return err; + if (err != kNuErrNone) + (void)Nu_FreeRecordContents(pArchive, pRecord); + return err; } @@ -1044,12 +1044,12 @@ bail: * the current set of threads. * * The rules we follow (stopping at the first match) are: - * - If there's a disk thread, leave it alone. Disk block size issues - * should already have been resolved. If we end up copying the same - * bogus block size we were given initially, that's fine. - * - If there's a resource fork, set the storageType to 5. - * - If there's a data fork, set the storageType to 1-3. - * - If there are no data-class threads at all, set the storageType to zero. + * - If there's a disk thread, leave it alone. Disk block size issues + * should already have been resolved. If we end up copying the same + * bogus block size we were given initially, that's fine. + * - If there's a resource fork, set the storageType to 5. + * - If there's a data fork, set the storageType to 1-3. + * - If there are no data-class threads at all, set the storageType to zero. * * This assumes that all updates have already been processed, i.e. there's * no lingering add or delete threadMods. This only examines the thread @@ -1061,42 +1061,42 @@ bail: static void Nu_UpdateStorageType(NuArchive* pArchive, NuRecord* pRecord) { - NuError err; - NuThread* pThread; + NuError err; + NuThread* pThread; - err = Nu_FindThreadByID(pRecord, kNuThreadIDDiskImage, &pThread); - if (err == kNuErrNone) - goto bail; + err = Nu_FindThreadByID(pRecord, kNuThreadIDDiskImage, &pThread); + if (err == kNuErrNone) + goto bail; - err = Nu_FindThreadByID(pRecord, kNuThreadIDRsrcFork, &pThread); - if (err == kNuErrNone) { - DBUG(("--- setting storageType to %d (was %d)\n", kNuStorageExtended, - pRecord->recStorageType)); - pRecord->recStorageType = kNuStorageExtended; - goto bail; - } + err = Nu_FindThreadByID(pRecord, kNuThreadIDRsrcFork, &pThread); + if (err == kNuErrNone) { + DBUG(("--- setting storageType to %d (was %d)\n", kNuStorageExtended, + pRecord->recStorageType)); + pRecord->recStorageType = kNuStorageExtended; + goto bail; + } - err = Nu_FindThreadByID(pRecord, kNuThreadIDDataFork, &pThread); - if (err == kNuErrNone) { - int newType; - if (pThread->actualThreadEOF <= 512) - newType = kNuStorageSeedling; - else if (pThread->actualThreadEOF < 131072) - newType = kNuStorageSapling; - else - newType = kNuStorageTree; - DBUG(("--- setting storageType to %d (was %d)\n", newType, - pRecord->recStorageType)); - pRecord->recStorageType = newType; - goto bail; - } + err = Nu_FindThreadByID(pRecord, kNuThreadIDDataFork, &pThread); + if (err == kNuErrNone) { + int newType; + if (pThread->actualThreadEOF <= 512) + newType = kNuStorageSeedling; + else if (pThread->actualThreadEOF < 131072) + newType = kNuStorageSapling; + else + newType = kNuStorageTree; + DBUG(("--- setting storageType to %d (was %d)\n", newType, + pRecord->recStorageType)); + pRecord->recStorageType = newType; + goto bail; + } - DBUG(("--- no stuff here, setting storageType to %d (was %d)\n", - kNuStorageUnknown, pRecord->recStorageType)); - pRecord->recStorageType = kNuStorageUnknown; + DBUG(("--- no stuff here, setting storageType to %d (was %d)\n", + kNuStorageUnknown, pRecord->recStorageType)); + pRecord->recStorageType = kNuStorageUnknown; bail: - return; + return; } /* @@ -1115,139 +1115,139 @@ bail: NuError Nu_WriteRecordHeader(NuArchive* pArchive, NuRecord* pRecord, FILE* fp) { - NuError err = kNuErrNone; - ushort crc; - long crcOffset; - int bytesWritten; + NuError err = kNuErrNone; + ushort crc; + long crcOffset; + int bytesWritten; - Assert(pArchive != nil); - Assert(pRecord != nil); - Assert(fp != nil); + Assert(pArchive != nil); + Assert(pRecord != nil); + Assert(fp != nil); - /* - * Before we get started, let's make sure the storageType makes sense - * for this record. - */ - Nu_UpdateStorageType(pArchive, pRecord); + /* + * Before we get started, let's make sure the storageType makes sense + * for this record. + */ + Nu_UpdateStorageType(pArchive, pRecord); - DBUG(("--- Writing record header (v=%d)\n", pRecord->recVersionNumber)); - - (void) Nu_WriteBytes(pArchive, fp, pRecord->recNufxID, kNufxIDLen); - err = Nu_FTell(fp, &crcOffset); - BailError(err); + DBUG(("--- Writing record header (v=%d)\n", pRecord->recVersionNumber)); + + (void) Nu_WriteBytes(pArchive, fp, pRecord->recNufxID, kNufxIDLen); + err = Nu_FTell(fp, &crcOffset); + BailError(err); - /* - * Write the static fields. - */ - crc = 0; - Nu_WriteTwo(pArchive, fp, 0); /* crc -- come back later */ - Nu_WriteTwoC(pArchive, fp, pRecord->recAttribCount, &crc); - Nu_WriteTwoC(pArchive, fp, pRecord->recVersionNumber, &crc); - Nu_WriteFourC(pArchive, fp, pRecord->recTotalThreads, &crc); - Nu_WriteTwoC(pArchive, fp, (ushort)pRecord->recFileSysID, &crc); - Nu_WriteTwoC(pArchive, fp, pRecord->recFileSysInfo, &crc); - Nu_WriteFourC(pArchive, fp, pRecord->recAccess, &crc); - Nu_WriteFourC(pArchive, fp, pRecord->recFileType, &crc); - Nu_WriteFourC(pArchive, fp, pRecord->recExtraType, &crc); - Nu_WriteTwoC(pArchive, fp, pRecord->recStorageType, &crc); - Nu_WriteDateTimeC(pArchive, fp, pRecord->recCreateWhen, &crc); - Nu_WriteDateTimeC(pArchive, fp, pRecord->recModWhen, &crc); - Nu_WriteDateTimeC(pArchive, fp, pRecord->recArchiveWhen, &crc); - bytesWritten = 56; /* 4-byte 'NuFX' plus the above */ + /* + * Write the static fields. + */ + crc = 0; + Nu_WriteTwo(pArchive, fp, 0); /* crc -- come back later */ + Nu_WriteTwoC(pArchive, fp, pRecord->recAttribCount, &crc); + Nu_WriteTwoC(pArchive, fp, pRecord->recVersionNumber, &crc); + Nu_WriteFourC(pArchive, fp, pRecord->recTotalThreads, &crc); + Nu_WriteTwoC(pArchive, fp, (ushort)pRecord->recFileSysID, &crc); + Nu_WriteTwoC(pArchive, fp, pRecord->recFileSysInfo, &crc); + Nu_WriteFourC(pArchive, fp, pRecord->recAccess, &crc); + Nu_WriteFourC(pArchive, fp, pRecord->recFileType, &crc); + Nu_WriteFourC(pArchive, fp, pRecord->recExtraType, &crc); + Nu_WriteTwoC(pArchive, fp, pRecord->recStorageType, &crc); + Nu_WriteDateTimeC(pArchive, fp, pRecord->recCreateWhen, &crc); + Nu_WriteDateTimeC(pArchive, fp, pRecord->recModWhen, &crc); + Nu_WriteDateTimeC(pArchive, fp, pRecord->recArchiveWhen, &crc); + bytesWritten = 56; /* 4-byte 'NuFX' plus the above */ - if ((err = Nu_HeaderIOFailed(pArchive, fp)) != kNuErrNone) { - Nu_ReportError(NU_BLOB, err, "Failed writing record header"); - goto bail; - } + if ((err = Nu_HeaderIOFailed(pArchive, fp)) != kNuErrNone) { + Nu_ReportError(NU_BLOB, err, "Failed writing record header"); + goto bail; + } - /* - * Write the option list, if present. - */ - if (pRecord->recVersionNumber > 0) { - Nu_WriteTwoC(pArchive, fp, pRecord->recOptionSize, &crc); - bytesWritten += 2; + /* + * Write the option list, if present. + */ + if (pRecord->recVersionNumber > 0) { + Nu_WriteTwoC(pArchive, fp, pRecord->recOptionSize, &crc); + bytesWritten += 2; - if (pRecord->recOptionSize) { - Nu_WriteBytesC(pArchive, fp, pRecord->recOptionList, - pRecord->recOptionSize, &crc); - bytesWritten += pRecord->recOptionSize; - } - } + if (pRecord->recOptionSize) { + Nu_WriteBytesC(pArchive, fp, pRecord->recOptionList, + pRecord->recOptionSize, &crc); + bytesWritten += pRecord->recOptionSize; + } + } - /* - * Preserve whatever miscellaneous junk was left in here by the last guy. - * We don't know what this is or why it's here, but who knows, maybe - * it's important. - * - * Besides, if we don't, we'll have to go back and fix the attrib count. - */ - if (pRecord->extraCount) { - Nu_WriteBytesC(pArchive, fp, pRecord->extraBytes, pRecord->extraCount, - &crc); - bytesWritten += pRecord->extraCount; - } + /* + * Preserve whatever miscellaneous junk was left in here by the last guy. + * We don't know what this is or why it's here, but who knows, maybe + * it's important. + * + * Besides, if we don't, we'll have to go back and fix the attrib count. + */ + if (pRecord->extraCount) { + Nu_WriteBytesC(pArchive, fp, pRecord->extraBytes, pRecord->extraCount, + &crc); + bytesWritten += pRecord->extraCount; + } - /* - * If the record has a filename in the header, write it, unless - * recent changes have inspired us to drop the name from the header. - * - * Records that begin with no filename will have a default one - * stuffed in, so it's possible for pRecord->filename to be set - * already even if there wasn't one in the record. (In such cases, - * we don't write a name.) - */ - if (pRecord->recFilenameLength && !pRecord->dropRecFilename) { - Nu_WriteTwoC(pArchive, fp, pRecord->recFilenameLength, &crc); - bytesWritten += 2; - Nu_WriteBytesC(pArchive, fp, pRecord->recFilename, - pRecord->recFilenameLength, &crc); - } else { - Nu_WriteTwoC(pArchive, fp, 0, &crc); - bytesWritten += 2; - } + /* + * If the record has a filename in the header, write it, unless + * recent changes have inspired us to drop the name from the header. + * + * Records that begin with no filename will have a default one + * stuffed in, so it's possible for pRecord->filename to be set + * already even if there wasn't one in the record. (In such cases, + * we don't write a name.) + */ + if (pRecord->recFilenameLength && !pRecord->dropRecFilename) { + Nu_WriteTwoC(pArchive, fp, pRecord->recFilenameLength, &crc); + bytesWritten += 2; + Nu_WriteBytesC(pArchive, fp, pRecord->recFilename, + pRecord->recFilenameLength, &crc); + } else { + Nu_WriteTwoC(pArchive, fp, 0, &crc); + bytesWritten += 2; + } - /* make sure we are where we thought we would be */ - if (bytesWritten != pRecord->recAttribCount) { - err = kNuErrInternal; - Nu_ReportError(NU_BLOB, kNuErrNone, - "Didn't write what was expected (%d vs %d)", - bytesWritten, pRecord->recAttribCount); - goto bail; - } + /* make sure we are where we thought we would be */ + if (bytesWritten != pRecord->recAttribCount) { + err = kNuErrInternal; + Nu_ReportError(NU_BLOB, kNuErrNone, + "Didn't write what was expected (%d vs %d)", + bytesWritten, pRecord->recAttribCount); + goto bail; + } - /* write the thread headers */ - err = Nu_WriteThreadHeaders(pArchive, pRecord, fp, &crc); - BailError(err); + /* write the thread headers */ + err = Nu_WriteThreadHeaders(pArchive, pRecord, fp, &crc); + BailError(err); - /* get the current file offset, for some computations later */ - err = Nu_FTell(fp, &pArchive->currentOffset); - BailError(err); + /* get the current file offset, for some computations later */ + err = Nu_FTell(fp, &pArchive->currentOffset); + BailError(err); - /* go back and fill in the CRC */ - pRecord->recHeaderCRC = crc; - err = Nu_FSeek(fp, crcOffset, SEEK_SET); - BailError(err); - Nu_WriteTwo(pArchive, fp, pRecord->recHeaderCRC); + /* go back and fill in the CRC */ + pRecord->recHeaderCRC = crc; + err = Nu_FSeek(fp, crcOffset, SEEK_SET); + BailError(err); + Nu_WriteTwo(pArchive, fp, pRecord->recHeaderCRC); - /* - * All okay? - */ - if ((err = Nu_HeaderIOFailed(pArchive, fp)) != kNuErrNone) { - Nu_ReportError(NU_BLOB, err, "Failed writing late record header"); - goto bail; - } + /* + * All okay? + */ + if ((err = Nu_HeaderIOFailed(pArchive, fp)) != kNuErrNone) { + Nu_ReportError(NU_BLOB, err, "Failed writing late record header"); + goto bail; + } - /* - * Update values for misc record fields. - */ - pRecord->recHeaderLength = - bytesWritten + pRecord->recTotalThreads * kNuThreadHeaderSize; + /* + * Update values for misc record fields. + */ + pRecord->recHeaderLength = + bytesWritten + pRecord->recTotalThreads * kNuThreadHeaderSize; - err = Nu_ComputeThreadData(pArchive, pRecord); - BailError(err); + err = Nu_ComputeThreadData(pArchive, pRecord); + BailError(err); bail: - return err; + return err; } @@ -1258,23 +1258,23 @@ bail: static NuError Nu_RecordWalkPrepare(NuArchive* pArchive, NuRecord** ppRecord) { - NuError err = kNuErrNone; + NuError err = kNuErrNone; - Assert(pArchive != nil); - Assert(ppRecord != nil); + Assert(pArchive != nil); + Assert(ppRecord != nil); - DBUG(("--- walk prep\n")); - - *ppRecord = nil; + DBUG(("--- walk prep\n")); + + *ppRecord = nil; - if (!pArchive->haveToc) { - /* might have tried and aborted earlier, rewind to start of records */ - err = Nu_RewindArchive(pArchive); - BailError(err); - } + if (!pArchive->haveToc) { + /* might have tried and aborted earlier, rewind to start of records */ + err = Nu_RewindArchive(pArchive); + BailError(err); + } bail: - return err; + return err; } /* @@ -1291,45 +1291,45 @@ bail: static NuError Nu_RecordWalkGetNext(NuArchive* pArchive, NuRecord** ppRecord) { - NuError err = kNuErrNone; + NuError err = kNuErrNone; - Assert(pArchive != nil); - Assert(ppRecord != nil); + Assert(pArchive != nil); + Assert(ppRecord != nil); - /*DBUG(("--- walk toc=%d\n", pArchive->haveToc));*/ + /*DBUG(("--- walk toc=%d\n", pArchive->haveToc));*/ - if (pArchive->haveToc) { - if (*ppRecord == nil) - *ppRecord = Nu_RecordSet_GetListHead(&pArchive->origRecordSet); - else - *ppRecord = (*ppRecord)->pNext; - } else { - *ppRecord = nil; /* so we don't try to free it on exit */ + if (pArchive->haveToc) { + if (*ppRecord == nil) + *ppRecord = Nu_RecordSet_GetListHead(&pArchive->origRecordSet); + else + *ppRecord = (*ppRecord)->pNext; + } else { + *ppRecord = nil; /* so we don't try to free it on exit */ - /* allocate and fill in a new record */ - err = Nu_RecordNew(pArchive, ppRecord); - BailError(err); + /* allocate and fill in a new record */ + err = Nu_RecordNew(pArchive, ppRecord); + BailError(err); - /* read data from archive file */ - err = Nu_ReadRecordHeader(pArchive, *ppRecord); - BailError(err); - err = Nu_ScanThreads(pArchive, *ppRecord, (*ppRecord)->recTotalThreads); - BailError(err); + /* read data from archive file */ + err = Nu_ReadRecordHeader(pArchive, *ppRecord); + BailError(err); + err = Nu_ScanThreads(pArchive, *ppRecord, (*ppRecord)->recTotalThreads); + BailError(err); - DBUG(("--- Found record '%s'\n", (*ppRecord)->filename)); + DBUG(("--- Found record '%s'\n", (*ppRecord)->filename)); - /* add to list */ - err = Nu_RecordSet_AddRecord(&pArchive->origRecordSet, *ppRecord); - BailError(err); - } + /* add to list */ + err = Nu_RecordSet_AddRecord(&pArchive->origRecordSet, *ppRecord); + BailError(err); + } bail: - if (err != kNuErrNone && !pArchive->haveToc) { - /* on failure, free whatever we allocated */ - Nu_RecordFree(pArchive, *ppRecord); - *ppRecord = nil; - } - return err; + if (err != kNuErrNone && !pArchive->haveToc) { + /* on failure, free whatever we allocated */ + Nu_RecordFree(pArchive, *ppRecord); + *ppRecord = nil; + } + return err; } /* @@ -1340,18 +1340,18 @@ bail: static NuError Nu_RecordWalkFinish(NuArchive* pArchive, NuError walkErr) { - if (pArchive->haveToc) - return kNuErrNone; + if (pArchive->haveToc) + return kNuErrNone; - if (walkErr == kNuErrNone) { - pArchive->haveToc = true; - /* mark as loaded, even if there weren't any entries (e.g. new arc) */ - Nu_RecordSet_SetLoaded(&pArchive->origRecordSet, true); - return kNuErrNone; - } else { - pArchive->haveToc = false; /* redundant */ - return Nu_RecordSet_FreeAllRecords(pArchive, &pArchive->origRecordSet); - } + if (walkErr == kNuErrNone) { + pArchive->haveToc = true; + /* mark as loaded, even if there weren't any entries (e.g. new arc) */ + Nu_RecordSet_SetLoaded(&pArchive->origRecordSet, true); + return kNuErrNone; + } else { + pArchive->haveToc = false; /* redundant */ + return Nu_RecordSet_FreeAllRecords(pArchive, &pArchive->origRecordSet); + } } @@ -1364,36 +1364,36 @@ Nu_RecordWalkFinish(NuArchive* pArchive, NuError walkErr) NuError Nu_GetTOCIfNeeded(NuArchive* pArchive) { - NuError err = kNuErrNone; - NuRecord* pRecord; - ulong count; + NuError err = kNuErrNone; + NuRecord* pRecord; + ulong count; - Assert(pArchive != nil); + Assert(pArchive != nil); - if (pArchive->haveToc) - goto bail; + if (pArchive->haveToc) + goto bail; - DBUG(("--- GetTOCIfNeeded\n")); + DBUG(("--- GetTOCIfNeeded\n")); - err = Nu_RecordWalkPrepare(pArchive, &pRecord); - BailError(err); + err = Nu_RecordWalkPrepare(pArchive, &pRecord); + BailError(err); - count = pArchive->masterHeader.mhTotalRecords; - while (count--) { - err = Nu_RecordWalkGetNext(pArchive, &pRecord); - BailError(err); - } + count = pArchive->masterHeader.mhTotalRecords; + while (count--) { + err = Nu_RecordWalkGetNext(pArchive, &pRecord); + BailError(err); + } bail: - (void) Nu_RecordWalkFinish(pArchive, err); - return err; + (void) Nu_RecordWalkFinish(pArchive, err); + return err; } /* * =========================================================================== - * Streaming read-only operations + * Streaming read-only operations * =========================================================================== */ @@ -1404,43 +1404,43 @@ bail: NuError Nu_StreamContents(NuArchive* pArchive, NuCallback contentFunc) { - NuError err = kNuErrNone; - NuRecord tmpRecord; - NuResult result; - ulong count; + NuError err = kNuErrNone; + NuRecord tmpRecord; + NuResult result; + ulong count; - if (contentFunc == nil) { - err = kNuErrInvalidArg; - goto bail; - } + if (contentFunc == nil) { + err = kNuErrInvalidArg; + goto bail; + } - Nu_InitRecordContents(pArchive, &tmpRecord); - count = pArchive->masterHeader.mhTotalRecords; + Nu_InitRecordContents(pArchive, &tmpRecord); + count = pArchive->masterHeader.mhTotalRecords; - while (count--) { - err = Nu_ReadRecordHeader(pArchive, &tmpRecord); - BailError(err); - err = Nu_ScanThreads(pArchive, &tmpRecord, tmpRecord.recTotalThreads); - BailError(err); + while (count--) { + err = Nu_ReadRecordHeader(pArchive, &tmpRecord); + BailError(err); + err = Nu_ScanThreads(pArchive, &tmpRecord, tmpRecord.recTotalThreads); + BailError(err); - /*Nu_DebugDumpRecord(&tmpRecord); - printf("\n");*/ + /*Nu_DebugDumpRecord(&tmpRecord); + printf("\n");*/ - /* let them display the contents */ - result = (*contentFunc)(pArchive, &tmpRecord); - if (result == kNuAbort) { - err = kNuErrAborted; - goto bail; - } + /* let them display the contents */ + result = (*contentFunc)(pArchive, &tmpRecord); + if (result == kNuAbort) { + err = kNuErrAborted; + goto bail; + } - /* dispose of the entry */ - (void) Nu_FreeRecordContents(pArchive, &tmpRecord); - (void) Nu_InitRecordContents(pArchive, &tmpRecord); - } + /* dispose of the entry */ + (void) Nu_FreeRecordContents(pArchive, &tmpRecord); + (void) Nu_InitRecordContents(pArchive, &tmpRecord); + } bail: - (void) Nu_FreeRecordContents(pArchive, &tmpRecord); - return err; + (void) Nu_FreeRecordContents(pArchive, &tmpRecord); + return err; } @@ -1461,27 +1461,27 @@ bail: static NuError Nu_FakeZeroExtract(NuArchive* pArchive, NuRecord* pRecord) { - NuError err; - NuThread fakeThread; + NuError err; + NuThread fakeThread; - Assert(pRecord != nil); + Assert(pRecord != nil); - DBUG(("--- found empty record, creating zero-byte data file\n")); - fakeThread.thThreadClass = kNuThreadClassData; - fakeThread.thThreadFormat = kNuThreadFormatUncompressed; - fakeThread.thThreadKind = 0x0000; /* assume data thread */ - fakeThread.thThreadCRC = kNuInitialThreadCRC; - fakeThread.thThreadEOF = 0; - fakeThread.thCompThreadEOF = 0; - fakeThread.actualThreadEOF = 0; - fakeThread.threadIdx = (NuThreadIdx)-1; /* shouldn't matter */ - fakeThread.fileOffset = 0; /* shouldn't matter */ + DBUG(("--- found empty record, creating zero-byte data file\n")); + fakeThread.thThreadClass = kNuThreadClassData; + fakeThread.thThreadFormat = kNuThreadFormatUncompressed; + fakeThread.thThreadKind = 0x0000; /* assume data thread */ + fakeThread.thThreadCRC = kNuInitialThreadCRC; + fakeThread.thThreadEOF = 0; + fakeThread.thCompThreadEOF = 0; + fakeThread.actualThreadEOF = 0; + fakeThread.threadIdx = (NuThreadIdx)-1; /* shouldn't matter */ + fakeThread.fileOffset = 0; /* shouldn't matter */ - err = Nu_ExtractThreadBulk(pArchive, pRecord, &fakeThread); - if (err == kNuErrSkipped) - err = Nu_SkipThread(pArchive, pRecord, &fakeThread); + err = Nu_ExtractThreadBulk(pArchive, pRecord, &fakeThread); + if (err == kNuErrSkipped) + err = Nu_SkipThread(pArchive, pRecord, &fakeThread); - return err; + return err; } @@ -1491,104 +1491,104 @@ Nu_FakeZeroExtract(NuArchive* pArchive, NuRecord* pRecord) NuError Nu_StreamExtract(NuArchive* pArchive) { - NuError err = kNuErrNone; - NuRecord tmpRecord; - Boolean hasInterestingThread; - ulong count; - long idx; + NuError err = kNuErrNone; + NuRecord tmpRecord; + Boolean hasInterestingThread; + ulong count; + long idx; - /* reset this just to be safe */ - pArchive->lastDirCreated = nil; + /* reset this just to be safe */ + pArchive->lastDirCreated = nil; - Nu_InitRecordContents(pArchive, &tmpRecord); - count = pArchive->masterHeader.mhTotalRecords; + Nu_InitRecordContents(pArchive, &tmpRecord); + count = pArchive->masterHeader.mhTotalRecords; - while (count--) { - /* - * Read the record header (which includes the thread header blocks). - */ - err = Nu_ReadRecordHeader(pArchive, &tmpRecord); - BailError(err); + while (count--) { + /* + * Read the record header (which includes the thread header blocks). + */ + err = Nu_ReadRecordHeader(pArchive, &tmpRecord); + BailError(err); - /* - * We may need to pull the filename out of a thread, but we don't - * want to blow past any data while we do it. There's no really - * good way to deal with this, so we just assume that all NuFX - * applications are nice and put the filename thread first. - */ - for (idx = 0; idx < (long)tmpRecord.recTotalThreads; idx++) { - const NuThread* pThread = Nu_GetThread(&tmpRecord, idx); + /* + * We may need to pull the filename out of a thread, but we don't + * want to blow past any data while we do it. There's no really + * good way to deal with this, so we just assume that all NuFX + * applications are nice and put the filename thread first. + */ + for (idx = 0; idx < (long)tmpRecord.recTotalThreads; idx++) { + const NuThread* pThread = Nu_GetThread(&tmpRecord, idx); - if (NuMakeThreadID(pThread->thThreadClass, pThread->thThreadKind) - == kNuThreadIDFilename) - { - break; - } - } - /* if we have fn, read it; either way, leave idx pointing at next */ - if (idx < (long)tmpRecord.recTotalThreads) { - idx++; /* want count, not index */ - err = Nu_ScanThreads(pArchive, &tmpRecord, idx); - BailError(err); - } else - idx = 0; - if (tmpRecord.filename == nil) { - Nu_ReportError(NU_BLOB, kNuErrNone, - "Couldn't find filename in record"); - err = kNuErrBadRecord; - goto bail; - } + if (NuMakeThreadID(pThread->thThreadClass, pThread->thThreadKind) + == kNuThreadIDFilename) + { + break; + } + } + /* if we have fn, read it; either way, leave idx pointing at next */ + if (idx < (long)tmpRecord.recTotalThreads) { + idx++; /* want count, not index */ + err = Nu_ScanThreads(pArchive, &tmpRecord, idx); + BailError(err); + } else + idx = 0; + if (tmpRecord.filename == nil) { + Nu_ReportError(NU_BLOB, kNuErrNone, + "Couldn't find filename in record"); + err = kNuErrBadRecord; + goto bail; + } - /*Nu_DebugDumpRecord(&tmpRecord); - printf("\n");*/ + /*Nu_DebugDumpRecord(&tmpRecord); + printf("\n");*/ - hasInterestingThread = false; + hasInterestingThread = false; - /* extract all relevant (remaining) threads */ - pArchive->lastFileCreated = nil; - for ( ; idx < (long)tmpRecord.recTotalThreads; idx++) { - const NuThread* pThread = Nu_GetThread(&tmpRecord, idx); + /* extract all relevant (remaining) threads */ + pArchive->lastFileCreated = nil; + for ( ; idx < (long)tmpRecord.recTotalThreads; idx++) { + const NuThread* pThread = Nu_GetThread(&tmpRecord, idx); - if (pThread->thThreadClass == kNuThreadClassData) { - hasInterestingThread = true; - err = Nu_ExtractThreadBulk(pArchive, &tmpRecord, pThread); - if (err == kNuErrSkipped) { - err = Nu_SkipThread(pArchive, &tmpRecord, pThread); - BailError(err); - } else if (err != kNuErrNone) - goto bail; - } else { - printf("IGNORING 0x%08lx from '%s'\n", - NuMakeThreadID(pThread->thThreadClass, pThread->thThreadKind), - tmpRecord.filename); - if (NuGetThreadID(pThread) != kNuThreadIDComment && - NuGetThreadID(pThread) != kNuThreadIDFilename) - { - hasInterestingThread = true; - } - err = Nu_SkipThread(pArchive, &tmpRecord, pThread); - BailError(err); - } - } + if (pThread->thThreadClass == kNuThreadClassData) { + hasInterestingThread = true; + err = Nu_ExtractThreadBulk(pArchive, &tmpRecord, pThread); + if (err == kNuErrSkipped) { + err = Nu_SkipThread(pArchive, &tmpRecord, pThread); + BailError(err); + } else if (err != kNuErrNone) + goto bail; + } else { + printf("IGNORING 0x%08lx from '%s'\n", + NuMakeThreadID(pThread->thThreadClass, pThread->thThreadKind), + tmpRecord.filename); + if (NuGetThreadID(pThread) != kNuThreadIDComment && + NuGetThreadID(pThread) != kNuThreadIDFilename) + { + hasInterestingThread = true; + } + err = Nu_SkipThread(pArchive, &tmpRecord, pThread); + BailError(err); + } + } - /* - * If we're trying to be compatible with ShrinkIt, and the record - * had nothing in it but comments and filenames, then we need to - * create a zero-byte data file. - */ - if (pArchive->valMimicSHK && !hasInterestingThread) { - err = Nu_FakeZeroExtract(pArchive, &tmpRecord); - BailError(err); - } + /* + * If we're trying to be compatible with ShrinkIt, and the record + * had nothing in it but comments and filenames, then we need to + * create a zero-byte data file. + */ + if (pArchive->valMimicSHK && !hasInterestingThread) { + err = Nu_FakeZeroExtract(pArchive, &tmpRecord); + BailError(err); + } - /* dispose of the entry */ - (void) Nu_FreeRecordContents(pArchive, &tmpRecord); - (void) Nu_InitRecordContents(pArchive, &tmpRecord); - } + /* dispose of the entry */ + (void) Nu_FreeRecordContents(pArchive, &tmpRecord); + (void) Nu_InitRecordContents(pArchive, &tmpRecord); + } bail: - (void) Nu_FreeRecordContents(pArchive, &tmpRecord); - return err; + (void) Nu_FreeRecordContents(pArchive, &tmpRecord); + return err; } /* @@ -1598,18 +1598,18 @@ bail: NuError Nu_StreamTest(NuArchive* pArchive) { - NuError err; + NuError err; - pArchive->testMode = true; - err = Nu_StreamExtract(pArchive); - pArchive->testMode = false; - return err; + pArchive->testMode = true; + err = Nu_StreamExtract(pArchive); + pArchive->testMode = false; + return err; } /* * =========================================================================== - * Non-streaming read-only operations + * Non-streaming read-only operations * =========================================================================== */ @@ -1622,35 +1622,35 @@ Nu_StreamTest(NuArchive* pArchive) NuError Nu_Contents(NuArchive* pArchive, NuCallback contentFunc) { - NuError err = kNuErrNone; - NuRecord* pRecord; - NuResult result; - ulong count; + NuError err = kNuErrNone; + NuRecord* pRecord; + NuResult result; + ulong count; - if (contentFunc == nil) { - err = kNuErrInvalidArg; - goto bail; - } + if (contentFunc == nil) { + err = kNuErrInvalidArg; + goto bail; + } - err = Nu_RecordWalkPrepare(pArchive, &pRecord); - BailError(err); + err = Nu_RecordWalkPrepare(pArchive, &pRecord); + BailError(err); - count = pArchive->masterHeader.mhTotalRecords; - while (count--) { - err = Nu_RecordWalkGetNext(pArchive, &pRecord); - BailError(err); + count = pArchive->masterHeader.mhTotalRecords; + while (count--) { + err = Nu_RecordWalkGetNext(pArchive, &pRecord); + BailError(err); - Assert(pRecord->filename != nil); - result = (*contentFunc)(pArchive, pRecord); - if (result == kNuAbort) { - err = kNuErrAborted; - goto bail; - } - } + Assert(pRecord->filename != nil); + result = (*contentFunc)(pArchive, pRecord); + if (result == kNuAbort) { + err = kNuErrAborted; + goto bail; + } + } bail: - (void) Nu_RecordWalkFinish(pArchive, err); - return err; + (void) Nu_RecordWalkFinish(pArchive, err); + return err; } @@ -1663,51 +1663,51 @@ bail: static NuError Nu_ExtractRecordByPtr(NuArchive* pArchive, NuRecord* pRecord) { - NuError err = kNuErrNone; - Boolean hasInterestingThread; - ulong idx; + NuError err = kNuErrNone; + Boolean hasInterestingThread; + ulong idx; - Assert(!Nu_IsStreaming(pArchive)); /* we don't skip things we don't read */ - Assert(pRecord != nil); + Assert(!Nu_IsStreaming(pArchive)); /* we don't skip things we don't read */ + Assert(pRecord != nil); - /* extract all relevant threads */ - hasInterestingThread = false; - pArchive->lastFileCreated = nil; - for (idx = 0; idx < pRecord->recTotalThreads; idx++) { - const NuThread* pThread = Nu_GetThread(pRecord, idx); + /* extract all relevant threads */ + hasInterestingThread = false; + pArchive->lastFileCreated = nil; + for (idx = 0; idx < pRecord->recTotalThreads; idx++) { + const NuThread* pThread = Nu_GetThread(pRecord, idx); - if (pThread->thThreadClass == kNuThreadClassData) { - hasInterestingThread = true; - err = Nu_ExtractThreadBulk(pArchive, pRecord, pThread); - if (err == kNuErrSkipped) { - err = Nu_SkipThread(pArchive, pRecord, pThread); - BailError(err); - } else if (err != kNuErrNone) - goto bail; - } else { - if (NuGetThreadID(pThread) != kNuThreadIDComment && - NuGetThreadID(pThread) != kNuThreadIDFilename) - { - hasInterestingThread = true; - } - DBUG(("IGNORING 0x%08lx from '%s'\n", - NuMakeThreadID(pThread->thThreadClass, pThread->thThreadKind), - pRecord->filename)); - } - } + if (pThread->thThreadClass == kNuThreadClassData) { + hasInterestingThread = true; + err = Nu_ExtractThreadBulk(pArchive, pRecord, pThread); + if (err == kNuErrSkipped) { + err = Nu_SkipThread(pArchive, pRecord, pThread); + BailError(err); + } else if (err != kNuErrNone) + goto bail; + } else { + if (NuGetThreadID(pThread) != kNuThreadIDComment && + NuGetThreadID(pThread) != kNuThreadIDFilename) + { + hasInterestingThread = true; + } + DBUG(("IGNORING 0x%08lx from '%s'\n", + NuMakeThreadID(pThread->thThreadClass, pThread->thThreadKind), + pRecord->filename)); + } + } - /* - * If we're trying to be compatible with ShrinkIt, and the record - * had nothing in it but comments and filenames, then we need to - * create a zero-byte data file. - */ - if (pArchive->valMimicSHK && !hasInterestingThread) { - err = Nu_FakeZeroExtract(pArchive, pRecord); - BailError(err); - } + /* + * If we're trying to be compatible with ShrinkIt, and the record + * had nothing in it but comments and filenames, then we need to + * create a zero-byte data file. + */ + if (pArchive->valMimicSHK && !hasInterestingThread) { + err = Nu_FakeZeroExtract(pArchive, pRecord); + BailError(err); + } bail: - return err; + return err; } @@ -1717,43 +1717,43 @@ bail: NuError Nu_Extract(NuArchive* pArchive) { - NuError err; - NuRecord* pRecord = nil; - ulong count; - long offset; + NuError err; + NuRecord* pRecord = nil; + ulong count; + long offset; - /* reset this just to be safe */ - pArchive->lastDirCreated = nil; + /* reset this just to be safe */ + pArchive->lastDirCreated = nil; - err = Nu_RecordWalkPrepare(pArchive, &pRecord); - BailError(err); + err = Nu_RecordWalkPrepare(pArchive, &pRecord); + BailError(err); - count = pArchive->masterHeader.mhTotalRecords; - while (count--) { - /* read the record and threads if we don't have them yet */ - err = Nu_RecordWalkGetNext(pArchive, &pRecord); - BailError(err); + count = pArchive->masterHeader.mhTotalRecords; + while (count--) { + /* read the record and threads if we don't have them yet */ + err = Nu_RecordWalkGetNext(pArchive, &pRecord); + BailError(err); - if (!pArchive->haveToc) { - /* remember where the end of the record is */ - err = Nu_FTell(pArchive->archiveFp, &offset); - BailError(err); - } + if (!pArchive->haveToc) { + /* remember where the end of the record is */ + err = Nu_FTell(pArchive->archiveFp, &offset); + BailError(err); + } - /* extract one or more threads */ - err = Nu_ExtractRecordByPtr(pArchive, pRecord); - BailError(err); + /* extract one or more threads */ + err = Nu_ExtractRecordByPtr(pArchive, pRecord); + BailError(err); - if (!pArchive->haveToc) { - /* line us back up so RecordWalkGetNext can read the record hdr */ - err = Nu_FSeek(pArchive->archiveFp, offset, SEEK_SET); - BailError(err); - } - } + if (!pArchive->haveToc) { + /* line us back up so RecordWalkGetNext can read the record hdr */ + err = Nu_FSeek(pArchive->archiveFp, offset, SEEK_SET); + BailError(err); + } + } bail: - (void) Nu_RecordWalkFinish(pArchive, err); - return err; + (void) Nu_RecordWalkFinish(pArchive, err); + return err; } @@ -1763,25 +1763,25 @@ bail: NuError Nu_ExtractRecord(NuArchive* pArchive, NuRecordIdx recIdx) { - NuError err; - NuRecord* pRecord; + NuError err; + NuRecord* pRecord; - if (Nu_IsStreaming(pArchive)) - return kNuErrUsage; - err = Nu_GetTOCIfNeeded(pArchive); - BailError(err); + if (Nu_IsStreaming(pArchive)) + return kNuErrUsage; + err = Nu_GetTOCIfNeeded(pArchive); + BailError(err); - /* find the correct record by index */ - err = Nu_RecordSet_FindByIdx(&pArchive->origRecordSet, recIdx, &pRecord); - BailError(err); - Assert(pRecord != nil); + /* find the correct record by index */ + err = Nu_RecordSet_FindByIdx(&pArchive->origRecordSet, recIdx, &pRecord); + BailError(err); + Assert(pRecord != nil); - /* extract whatever looks promising */ - err = Nu_ExtractRecordByPtr(pArchive, pRecord); - BailError(err); + /* extract whatever looks promising */ + err = Nu_ExtractRecordByPtr(pArchive, pRecord); + BailError(err); bail: - return err; + return err; } @@ -1792,12 +1792,12 @@ bail: NuError Nu_Test(NuArchive* pArchive) { - NuError err; + NuError err; - pArchive->testMode = true; - err = Nu_Extract(pArchive); - pArchive->testMode = false; - return err; + pArchive->testMode = true; + err = Nu_Extract(pArchive); + pArchive->testMode = false; + return err; } @@ -1810,27 +1810,27 @@ Nu_Test(NuArchive* pArchive) */ NuError Nu_GetRecord(NuArchive* pArchive, NuRecordIdx recordIdx, - const NuRecord** ppRecord) + const NuRecord** ppRecord) { - NuError err; + NuError err; - if (recordIdx == 0 || ppRecord == nil) - return kNuErrInvalidArg; + if (recordIdx == 0 || ppRecord == nil) + return kNuErrInvalidArg; - if (Nu_IsStreaming(pArchive)) - return kNuErrUsage; - err = Nu_GetTOCIfNeeded(pArchive); - BailError(err); + if (Nu_IsStreaming(pArchive)) + return kNuErrUsage; + err = Nu_GetTOCIfNeeded(pArchive); + BailError(err); - err = Nu_RecordSet_FindByIdx(&pArchive->origRecordSet, recordIdx, - (NuRecord**)ppRecord); - if (err == kNuErrNone) { - Assert(*ppRecord != nil); - } - /* fall through with error */ + err = Nu_RecordSet_FindByIdx(&pArchive->origRecordSet, recordIdx, + (NuRecord**)ppRecord); + if (err == kNuErrNone) { + Assert(*ppRecord != nil); + } + /* fall through with error */ bail: - return err; + return err; } /* @@ -1838,28 +1838,28 @@ bail: */ NuError Nu_GetRecordIdxByName(NuArchive* pArchive, const char* name, - NuRecordIdx* pRecordIdx) + NuRecordIdx* pRecordIdx) { - NuError err; - NuRecord* pRecord = nil; + NuError err; + NuRecord* pRecord = nil; - if (pRecordIdx == nil) - return kNuErrInvalidArg; + if (pRecordIdx == nil) + return kNuErrInvalidArg; - if (Nu_IsStreaming(pArchive)) - return kNuErrUsage; - err = Nu_GetTOCIfNeeded(pArchive); - BailError(err); + if (Nu_IsStreaming(pArchive)) + return kNuErrUsage; + err = Nu_GetTOCIfNeeded(pArchive); + BailError(err); - err = Nu_RecordSet_FindByName(&pArchive->origRecordSet, name, &pRecord); - if (err == kNuErrNone) { - Assert(pRecord != nil); - *pRecordIdx = pRecord->recordIdx; - } - /* fall through with error */ + err = Nu_RecordSet_FindByName(&pArchive->origRecordSet, name, &pRecord); + if (err == kNuErrNone) { + Assert(pRecord != nil); + *pRecordIdx = pRecord->recordIdx; + } + /* fall through with error */ bail: - return err; + return err; } /* @@ -1867,40 +1867,40 @@ bail: */ NuError Nu_GetRecordIdxByPosition(NuArchive* pArchive, ulong position, - NuRecordIdx* pRecordIdx) + NuRecordIdx* pRecordIdx) { - NuError err; - const NuRecord* pRecord; + NuError err; + const NuRecord* pRecord; - if (pRecordIdx == nil) - return kNuErrInvalidArg; + if (pRecordIdx == nil) + return kNuErrInvalidArg; - if (Nu_IsStreaming(pArchive)) - return kNuErrUsage; - err = Nu_GetTOCIfNeeded(pArchive); - BailError(err); + if (Nu_IsStreaming(pArchive)) + return kNuErrUsage; + err = Nu_GetTOCIfNeeded(pArchive); + BailError(err); - if (position >= Nu_RecordSet_GetNumRecords(&pArchive->origRecordSet)) { - err = kNuErrRecordNotFound; - goto bail; - } + if (position >= Nu_RecordSet_GetNumRecords(&pArchive->origRecordSet)) { + err = kNuErrRecordNotFound; + goto bail; + } - pRecord = Nu_RecordSet_GetListHead(&pArchive->origRecordSet); - while (position--) { - Assert(pRecord->pNext != nil); - pRecord = pRecord->pNext; - } + pRecord = Nu_RecordSet_GetListHead(&pArchive->origRecordSet); + while (position--) { + Assert(pRecord->pNext != nil); + pRecord = pRecord->pNext; + } - *pRecordIdx = pRecord->recordIdx; + *pRecordIdx = pRecord->recordIdx; bail: - return err; + return err; } /* * =========================================================================== - * Read/write record operations (add, delete) + * Read/write record operations (add, delete) * =========================================================================== */ @@ -1919,40 +1919,40 @@ bail: */ NuError Nu_FindRecordForWriteByIdx(NuArchive* pArchive, NuRecordIdx recIdx, - NuRecord** ppFoundRecord) + NuRecord** ppFoundRecord) { - NuError err; + NuError err; - Assert(pArchive != nil); - Assert(ppFoundRecord != nil); + Assert(pArchive != nil); + Assert(ppFoundRecord != nil); - if (Nu_RecordSet_GetLoaded(&pArchive->copyRecordSet)) { - err = Nu_RecordSet_FindByIdx(&pArchive->copyRecordSet, recIdx, - ppFoundRecord); - } else { - Assert(Nu_RecordSet_GetLoaded(&pArchive->origRecordSet)); - err = Nu_RecordSet_FindByIdx(&pArchive->origRecordSet, recIdx, - ppFoundRecord); - *ppFoundRecord = nil; /* can't delete from here */ - } - BailErrorQuiet(err); + if (Nu_RecordSet_GetLoaded(&pArchive->copyRecordSet)) { + err = Nu_RecordSet_FindByIdx(&pArchive->copyRecordSet, recIdx, + ppFoundRecord); + } else { + Assert(Nu_RecordSet_GetLoaded(&pArchive->origRecordSet)); + err = Nu_RecordSet_FindByIdx(&pArchive->origRecordSet, recIdx, + ppFoundRecord); + *ppFoundRecord = nil; /* can't delete from here */ + } + BailErrorQuiet(err); - /* - * The record exists. If we were looking in the "orig" set, we have - * to create a "copy" set and return it from there. - */ - if (*ppFoundRecord == nil) { - err = Nu_RecordSet_Clone(pArchive, &pArchive->copyRecordSet, - &pArchive->origRecordSet); - BailError(err); - err = Nu_RecordSet_FindByIdx(&pArchive->copyRecordSet, recIdx, - ppFoundRecord); - Assert(err == kNuErrNone && *ppFoundRecord != nil); /* must succeed */ - BailError(err); - } + /* + * The record exists. If we were looking in the "orig" set, we have + * to create a "copy" set and return it from there. + */ + if (*ppFoundRecord == nil) { + err = Nu_RecordSet_Clone(pArchive, &pArchive->copyRecordSet, + &pArchive->origRecordSet); + BailError(err); + err = Nu_RecordSet_FindByIdx(&pArchive->copyRecordSet, recIdx, + ppFoundRecord); + Assert(err == kNuErrNone && *ppFoundRecord != nil); /* must succeed */ + BailError(err); + } bail: - return err; + return err; } @@ -1970,125 +1970,125 @@ bail: */ static NuError Nu_HandleAddDuplicateRecord(NuArchive* pArchive, NuRecordSet* pRecordSet, - NuRecord* pRecord, const NuFileDetails* pFileDetails) + NuRecord* pRecord, const NuFileDetails* pFileDetails) { - NuError err = kNuErrNone; - NuErrorStatus errorStatus; - NuResult result; + NuError err = kNuErrNone; + NuErrorStatus errorStatus; + NuResult result; - Assert(pRecordSet == &pArchive->origRecordSet || - pRecordSet == &pArchive->copyRecordSet); - Assert(pRecord != nil); - Assert(pFileDetails != nil); - Assert(pArchive->valAllowDuplicates == false); + Assert(pRecordSet == &pArchive->origRecordSet || + pRecordSet == &pArchive->copyRecordSet); + Assert(pRecord != nil); + Assert(pFileDetails != nil); + Assert(pArchive->valAllowDuplicates == false); - /* - * If "only update older" is set, check the dates. Reject the - * request if the archived file isn't older than the new file. This - * tells the application that the request was rejected, but it's - * okay for them to move on to the next file. - */ - if (pArchive->valOnlyUpdateOlder) { - if (!Nu_IsOlder(&pRecord->recModWhen, &pFileDetails->modWhen)) - return kNuErrNotNewer; - } + /* + * If "only update older" is set, check the dates. Reject the + * request if the archived file isn't older than the new file. This + * tells the application that the request was rejected, but it's + * okay for them to move on to the next file. + */ + if (pArchive->valOnlyUpdateOlder) { + if (!Nu_IsOlder(&pRecord->recModWhen, &pFileDetails->modWhen)) + return kNuErrNotNewer; + } - /* - * The file exists when it shouldn't. Decide what to do, based - * on the options configured by the application. - * - * If they "might" allow overwrites, and they have an error-handling - * callback defined, call that to find out what they want to do - * here. Options include skipping or overwriting the record. - * - * We don't currently allow renaming of records, though I suppose we - * could. - */ - switch (pArchive->valHandleExisting) { - case kNuMaybeOverwrite: - if (pArchive->errorHandlerFunc != nil) { - errorStatus.operation = kNuOpAdd; - errorStatus.err = kNuErrRecordExists; - errorStatus.sysErr = 0; - errorStatus.message = nil; - errorStatus.pRecord = pRecord; - errorStatus.pathname = pFileDetails->storageName; - errorStatus.filenameSeparator = - NuGetSepFromSysInfo(pFileDetails->fileSysInfo); - /*errorStatus.origArchiveTouched = false;*/ - errorStatus.canAbort = true; - errorStatus.canRetry = false; - errorStatus.canIgnore = false; - errorStatus.canSkip = true; - errorStatus.canRename = false; - errorStatus.canOverwrite = true; + /* + * The file exists when it shouldn't. Decide what to do, based + * on the options configured by the application. + * + * If they "might" allow overwrites, and they have an error-handling + * callback defined, call that to find out what they want to do + * here. Options include skipping or overwriting the record. + * + * We don't currently allow renaming of records, though I suppose we + * could. + */ + switch (pArchive->valHandleExisting) { + case kNuMaybeOverwrite: + if (pArchive->errorHandlerFunc != nil) { + errorStatus.operation = kNuOpAdd; + errorStatus.err = kNuErrRecordExists; + errorStatus.sysErr = 0; + errorStatus.message = nil; + errorStatus.pRecord = pRecord; + errorStatus.pathname = pFileDetails->storageName; + errorStatus.filenameSeparator = + NuGetSepFromSysInfo(pFileDetails->fileSysInfo); + /*errorStatus.origArchiveTouched = false;*/ + errorStatus.canAbort = true; + errorStatus.canRetry = false; + errorStatus.canIgnore = false; + errorStatus.canSkip = true; + errorStatus.canRename = false; + errorStatus.canOverwrite = true; - result = (*pArchive->errorHandlerFunc)(pArchive, &errorStatus); + result = (*pArchive->errorHandlerFunc)(pArchive, &errorStatus); - switch (result) { - case kNuAbort: - err = kNuErrAborted; - goto bail; - case kNuSkip: - err = kNuErrSkipped; - goto bail; - case kNuOverwrite: - break; /* fall back into main code */ - case kNuRetry: - case kNuRename: - case kNuIgnore: - default: - err = kNuErrSyntax; - Nu_ReportError(NU_BLOB, err, - "Wasn't expecting result %d here", result); - goto bail; - } - } else { - /* no error handler, treat like NeverOverwrite */ - err = kNuErrSkipped; - goto bail; - } - break; - case kNuNeverOverwrite: - err = kNuErrSkipped; - goto bail; - case kNuMustOverwrite: - case kNuAlwaysOverwrite: - /* fall through to record deletion */ - break; - default: - assert(0); - err = kNuErrInternal; - goto bail; - } + switch (result) { + case kNuAbort: + err = kNuErrAborted; + goto bail; + case kNuSkip: + err = kNuErrSkipped; + goto bail; + case kNuOverwrite: + break; /* fall back into main code */ + case kNuRetry: + case kNuRename: + case kNuIgnore: + default: + err = kNuErrSyntax; + Nu_ReportError(NU_BLOB, err, + "Wasn't expecting result %d here", result); + goto bail; + } + } else { + /* no error handler, treat like NeverOverwrite */ + err = kNuErrSkipped; + goto bail; + } + break; + case kNuNeverOverwrite: + err = kNuErrSkipped; + goto bail; + case kNuMustOverwrite: + case kNuAlwaysOverwrite: + /* fall through to record deletion */ + break; + default: + assert(0); + err = kNuErrInternal; + goto bail; + } - err = kNuErrNone; + err = kNuErrNone; - /* - * We're going to overwrite the existing record. To do this, we have - * to start by deleting it from the "copy" list. - * - * If the copy set doesn't yet exist, we have to create it and find - * the record in the new set. - */ - if (pRecordSet == &pArchive->origRecordSet) { - Assert(!Nu_RecordSet_GetLoaded(&pArchive->copyRecordSet)); - err = Nu_RecordSet_Clone(pArchive, &pArchive->copyRecordSet, - &pArchive->origRecordSet); - BailError(err); + /* + * We're going to overwrite the existing record. To do this, we have + * to start by deleting it from the "copy" list. + * + * If the copy set doesn't yet exist, we have to create it and find + * the record in the new set. + */ + if (pRecordSet == &pArchive->origRecordSet) { + Assert(!Nu_RecordSet_GetLoaded(&pArchive->copyRecordSet)); + err = Nu_RecordSet_Clone(pArchive, &pArchive->copyRecordSet, + &pArchive->origRecordSet); + BailError(err); - err = Nu_RecordSet_FindByIdx(&pArchive->copyRecordSet, - pRecord->recordIdx, &pRecord); - Assert(err == kNuErrNone && pRecord != nil); /* must succeed */ - BailError(err); - } + err = Nu_RecordSet_FindByIdx(&pArchive->copyRecordSet, + pRecord->recordIdx, &pRecord); + Assert(err == kNuErrNone && pRecord != nil); /* must succeed */ + BailError(err); + } - DBUG(("+++ deleting record %ld\n", pRecord->recordIdx)); - err = Nu_RecordSet_DeleteRecord(pArchive,&pArchive->copyRecordSet, pRecord); - BailError(err); + DBUG(("+++ deleting record %ld\n", pRecord->recordIdx)); + err = Nu_RecordSet_DeleteRecord(pArchive,&pArchive->copyRecordSet, pRecord); + BailError(err); bail: - return err; + return err; } /* @@ -2108,132 +2108,132 @@ bail: */ NuError Nu_AddRecord(NuArchive* pArchive, const NuFileDetails* pFileDetails, - NuRecordIdx* pRecordIdx, NuRecord** ppNewRecord) + NuRecordIdx* pRecordIdx, NuRecord** ppNewRecord) { - NuError err; - NuRecord* pNewRecord = nil; + NuError err; + NuRecord* pNewRecord = nil; - if (pFileDetails == nil || pFileDetails->storageName == nil || - pFileDetails->storageName[0] == '\0' || - NuGetSepFromSysInfo(pFileDetails->fileSysInfo) == 0) - /* pRecordIdx may be nil */ - /* ppNewRecord may be nil */ - { - err = kNuErrInvalidArg; - goto bail; - } + if (pFileDetails == nil || pFileDetails->storageName == nil || + pFileDetails->storageName[0] == '\0' || + NuGetSepFromSysInfo(pFileDetails->fileSysInfo) == 0) + /* pRecordIdx may be nil */ + /* ppNewRecord may be nil */ + { + err = kNuErrInvalidArg; + goto bail; + } - if (Nu_IsReadOnly(pArchive)) - return kNuErrArchiveRO; - err = Nu_GetTOCIfNeeded(pArchive); - BailError(err); + if (Nu_IsReadOnly(pArchive)) + return kNuErrArchiveRO; + err = Nu_GetTOCIfNeeded(pArchive); + BailError(err); - /* NuFX spec forbids leading fssep chars */ - if (pFileDetails->storageName[0] == - NuGetSepFromSysInfo(pFileDetails->fileSysInfo)) - { - err = kNuErrLeadingFssep; - goto bail; - } + /* NuFX spec forbids leading fssep chars */ + if (pFileDetails->storageName[0] == + NuGetSepFromSysInfo(pFileDetails->fileSysInfo)) + { + err = kNuErrLeadingFssep; + goto bail; + } - /* - * If requested, look for an existing record. Look in the "copy" - * list if we have it (so we don't complain if they've already deleted - * the record), or in the "orig" list if we don't. Look in the "new" - * list to see if it clashes with something we've just added. - * - * If this is a brand-new archive, there won't be an "orig" list - * either. - */ - if (!pArchive->valAllowDuplicates) { - NuRecordSet* pRecordSet; - NuRecord* pFoundRecord; + /* + * If requested, look for an existing record. Look in the "copy" + * list if we have it (so we don't complain if they've already deleted + * the record), or in the "orig" list if we don't. Look in the "new" + * list to see if it clashes with something we've just added. + * + * If this is a brand-new archive, there won't be an "orig" list + * either. + */ + if (!pArchive->valAllowDuplicates) { + NuRecordSet* pRecordSet; + NuRecord* pFoundRecord; - pRecordSet = &pArchive->copyRecordSet; - if (!Nu_RecordSet_GetLoaded(pRecordSet)) - pRecordSet = &pArchive->origRecordSet; - Assert(Nu_RecordSet_GetLoaded(pRecordSet)); - err = Nu_RecordSet_FindByName(pRecordSet, pFileDetails->storageName, - &pFoundRecord); - if (err == kNuErrNone) { - /* handle the existing record */ - DBUG(("--- Duplicate record found (%06ld) '%s'\n", - pFoundRecord->recordIdx, pFoundRecord->filename)); - err = Nu_HandleAddDuplicateRecord(pArchive, pRecordSet, - pFoundRecord, pFileDetails); - if (err != kNuErrNone) { - /* for whatever reason, we're not replacing it */ - DBUG(("--- Returning err=%d\n", err)); - goto bail; - } - } else { - /* if we *must* replace an existing file, we fail now */ - if (pArchive->valHandleExisting == kNuMustOverwrite) { - DBUG(("+++ can't freshen nonexistent '%s'\n", - pFileDetails->storageName)); - err = kNuErrDuplicateNotFound; - goto bail; - } - } + pRecordSet = &pArchive->copyRecordSet; + if (!Nu_RecordSet_GetLoaded(pRecordSet)) + pRecordSet = &pArchive->origRecordSet; + Assert(Nu_RecordSet_GetLoaded(pRecordSet)); + err = Nu_RecordSet_FindByName(pRecordSet, pFileDetails->storageName, + &pFoundRecord); + if (err == kNuErrNone) { + /* handle the existing record */ + DBUG(("--- Duplicate record found (%06ld) '%s'\n", + pFoundRecord->recordIdx, pFoundRecord->filename)); + err = Nu_HandleAddDuplicateRecord(pArchive, pRecordSet, + pFoundRecord, pFileDetails); + if (err != kNuErrNone) { + /* for whatever reason, we're not replacing it */ + DBUG(("--- Returning err=%d\n", err)); + goto bail; + } + } else { + /* if we *must* replace an existing file, we fail now */ + if (pArchive->valHandleExisting == kNuMustOverwrite) { + DBUG(("+++ can't freshen nonexistent '%s'\n", + pFileDetails->storageName)); + err = kNuErrDuplicateNotFound; + goto bail; + } + } - if (Nu_RecordSet_GetLoaded(&pArchive->newRecordSet)) { - err = Nu_RecordSet_FindByName(&pArchive->newRecordSet, - pFileDetails->storageName, &pFoundRecord); - if (err == kNuErrNone) { - /* we can't delete from the "new" list, so return an error */ - err = kNuErrRecordExists; - goto bail; - } - } + if (Nu_RecordSet_GetLoaded(&pArchive->newRecordSet)) { + err = Nu_RecordSet_FindByName(&pArchive->newRecordSet, + pFileDetails->storageName, &pFoundRecord); + if (err == kNuErrNone) { + /* we can't delete from the "new" list, so return an error */ + err = kNuErrRecordExists; + goto bail; + } + } - /* clear "err" so we can continue */ - err = kNuErrNone; - } + /* clear "err" so we can continue */ + err = kNuErrNone; + } - /* - * Prepare the new record structure. - */ - err = Nu_RecordNew(pArchive, &pNewRecord); - BailError(err); - (void) Nu_InitRecordContents(pArchive, pNewRecord); - memcpy(pNewRecord->recNufxID, kNufxID, kNufxIDLen); - /*pNewRecord->recHeaderCRC*/ - /*pNewRecord->recAttribCount*/ - pNewRecord->recVersionNumber = kNuOurRecordVersion; - pNewRecord->recTotalThreads = 0; - pNewRecord->recFileSysID = pFileDetails->fileSysID; - pNewRecord->recFileSysInfo = pFileDetails->fileSysInfo; - pNewRecord->recAccess = pFileDetails->access; - pNewRecord->recFileType = pFileDetails->fileType; - pNewRecord->recExtraType = pFileDetails->extraType; - pNewRecord->recStorageType = pFileDetails->storageType; - pNewRecord->recCreateWhen = pFileDetails->createWhen; - pNewRecord->recModWhen = pFileDetails->modWhen; - pNewRecord->recArchiveWhen = pFileDetails->archiveWhen; - pNewRecord->recOptionSize = 0; - pNewRecord->extraCount = 0; - pNewRecord->recFilenameLength = 0; + /* + * Prepare the new record structure. + */ + err = Nu_RecordNew(pArchive, &pNewRecord); + BailError(err); + (void) Nu_InitRecordContents(pArchive, pNewRecord); + memcpy(pNewRecord->recNufxID, kNufxID, kNufxIDLen); + /*pNewRecord->recHeaderCRC*/ + /*pNewRecord->recAttribCount*/ + pNewRecord->recVersionNumber = kNuOurRecordVersion; + pNewRecord->recTotalThreads = 0; + pNewRecord->recFileSysID = pFileDetails->fileSysID; + pNewRecord->recFileSysInfo = pFileDetails->fileSysInfo; + pNewRecord->recAccess = pFileDetails->access; + pNewRecord->recFileType = pFileDetails->fileType; + pNewRecord->recExtraType = pFileDetails->extraType; + pNewRecord->recStorageType = pFileDetails->storageType; + pNewRecord->recCreateWhen = pFileDetails->createWhen; + pNewRecord->recModWhen = pFileDetails->modWhen; + pNewRecord->recArchiveWhen = pFileDetails->archiveWhen; + pNewRecord->recOptionSize = 0; + pNewRecord->extraCount = 0; + pNewRecord->recFilenameLength = 0; - pNewRecord->recordIdx = Nu_GetNextRecordIdx(pArchive); - pNewRecord->newFilename = strdup(pFileDetails->storageName); - pNewRecord->filename = pNewRecord->newFilename; - pNewRecord->totalCompLength = 0; - pNewRecord->fileOffset = -1; + pNewRecord->recordIdx = Nu_GetNextRecordIdx(pArchive); + pNewRecord->newFilename = strdup(pFileDetails->storageName); + pNewRecord->filename = pNewRecord->newFilename; + pNewRecord->totalCompLength = 0; + pNewRecord->fileOffset = -1; - /* - * Add it to the "new" record set. - */ - err = Nu_RecordSet_AddRecord(&pArchive->newRecordSet, pNewRecord); - BailError(err); + /* + * Add it to the "new" record set. + */ + err = Nu_RecordSet_AddRecord(&pArchive->newRecordSet, pNewRecord); + BailError(err); - /* return values */ - if (pRecordIdx != nil) - *pRecordIdx = pNewRecord->recordIdx; - if (ppNewRecord != nil) - *ppNewRecord = pNewRecord; + /* return values */ + if (pRecordIdx != nil) + *pRecordIdx = pNewRecord->recordIdx; + if (ppNewRecord != nil) + *ppNewRecord = pNewRecord; bail: - return err; + return err; } @@ -2245,52 +2245,52 @@ bail: */ static NuError Nu_AddFileThreadMod(NuArchive* pArchive, NuRecord* pRecord, - const char* pathname, const NuFileDetails* pFileDetails, - Boolean fromRsrcFork) + const char* pathname, const NuFileDetails* pFileDetails, + Boolean fromRsrcFork) { - NuError err; - NuThreadFormat threadFormat; - NuDataSource* pDataSource = nil; - NuThreadMod* pThreadMod = nil; + NuError err; + NuThreadFormat threadFormat; + NuDataSource* pDataSource = nil; + NuThreadMod* pThreadMod = nil; - Assert(pArchive != nil); - Assert(pRecord != nil); - Assert(pathname != nil); - Assert(pFileDetails != nil); - Assert(fromRsrcFork == true || fromRsrcFork == false); + Assert(pArchive != nil); + Assert(pRecord != nil); + Assert(pathname != nil); + Assert(pFileDetails != nil); + Assert(fromRsrcFork == true || fromRsrcFork == false); - if (Nu_IsReadOnly(pArchive)) - return kNuErrArchiveRO; + if (Nu_IsReadOnly(pArchive)) + return kNuErrArchiveRO; - /* decide if this should be compressed; we know source isn't */ - if (Nu_IsCompressibleThreadID(pFileDetails->threadID)) - threadFormat = Nu_ConvertCompressValToFormat(pArchive, - pArchive->valDataCompression); - else - threadFormat = kNuThreadFormatUncompressed; + /* decide if this should be compressed; we know source isn't */ + if (Nu_IsCompressibleThreadID(pFileDetails->threadID)) + threadFormat = Nu_ConvertCompressValToFormat(pArchive, + pArchive->valDataCompression); + else + threadFormat = kNuThreadFormatUncompressed; - /* create a data source for this file, which is assumed uncompressed */ - err = Nu_DataSourceFile_New(kNuThreadFormatUncompressed, false, 0, - pathname, fromRsrcFork, &pDataSource); - BailError(err); + /* create a data source for this file, which is assumed uncompressed */ + err = Nu_DataSourceFile_New(kNuThreadFormatUncompressed, false, 0, + pathname, fromRsrcFork, &pDataSource); + BailError(err); - /* create a new ThreadMod */ - err = Nu_ThreadModAdd_New(pArchive, pFileDetails->threadID, threadFormat, - pDataSource, &pThreadMod); - BailError(err); - Assert(pThreadMod != nil); - pDataSource = nil; /* don't free on exit */ + /* create a new ThreadMod */ + err = Nu_ThreadModAdd_New(pArchive, pFileDetails->threadID, threadFormat, + pDataSource, &pThreadMod); + BailError(err); + Assert(pThreadMod != nil); + pDataSource = nil; /* don't free on exit */ - /* add the thread mod to the record */ - Nu_RecordAddThreadMod(pRecord, pThreadMod); - pThreadMod = nil; /* don't free on exit */ + /* add the thread mod to the record */ + Nu_RecordAddThreadMod(pRecord, pThreadMod); + pThreadMod = nil; /* don't free on exit */ bail: - if (pDataSource != nil) - Nu_DataSourceFree(pDataSource); - if (pThreadMod != nil) - Nu_ThreadModFree(pArchive, pThreadMod); - return err; + if (pDataSource != nil) + Nu_DataSourceFree(pDataSource); + if (pThreadMod != nil) + Nu_ThreadModFree(pArchive, pThreadMod); + return err; } /* @@ -2307,132 +2307,132 @@ bail: NuError Nu_AddFile(NuArchive* pArchive, const char* pathname, const NuFileDetails* pFileDetails, Boolean fromRsrcFork, - NuRecordIdx* pRecordIdx) + NuRecordIdx* pRecordIdx) { - NuError err = kNuErrNone; - NuRecordIdx recordIdx = 0; - NuRecord* pRecord; + NuError err = kNuErrNone; + NuRecordIdx recordIdx = 0; + NuRecord* pRecord; - if (pathname == nil || pFileDetails == nil || - !(fromRsrcFork == true || fromRsrcFork == false)) - { - return kNuErrInvalidArg; - } + if (pathname == nil || pFileDetails == nil || + !(fromRsrcFork == true || fromRsrcFork == false)) + { + return kNuErrInvalidArg; + } - if (Nu_IsReadOnly(pArchive)) - return kNuErrArchiveRO; - err = Nu_GetTOCIfNeeded(pArchive); - BailError(err); + if (Nu_IsReadOnly(pArchive)) + return kNuErrArchiveRO; + err = Nu_GetTOCIfNeeded(pArchive); + BailError(err); - if (pFileDetails->storageName == nil) { - err = kNuErrInvalidArg; - Nu_ReportError(NU_BLOB, err, "Must specify storageName"); - goto bail; - } - if (pFileDetails->storageName[0] == - NuGetSepFromSysInfo(pFileDetails->fileSysInfo)) - { - err = kNuErrLeadingFssep; - goto bail; - } + if (pFileDetails->storageName == nil) { + err = kNuErrInvalidArg; + Nu_ReportError(NU_BLOB, err, "Must specify storageName"); + goto bail; + } + if (pFileDetails->storageName[0] == + NuGetSepFromSysInfo(pFileDetails->fileSysInfo)) + { + err = kNuErrLeadingFssep; + goto bail; + } - DBUG(("+++ ADDING '%s' (%s) 0x%02lx 0x%04lx threadID=0x%08lx\n", pathname, - pFileDetails->storageName, pFileDetails->fileType, - pFileDetails->extraType, pFileDetails->threadID)); + DBUG(("+++ ADDING '%s' (%s) 0x%02lx 0x%04lx threadID=0x%08lx\n", pathname, + pFileDetails->storageName, pFileDetails->fileType, + pFileDetails->extraType, pFileDetails->threadID)); - /* - * See if there's another record among the "new additions" with the - * same storageName and compatible threads. - * - * If found, add a new thread in that record. If an incompatibility - * exists (same fork already present, disk image is there, etc), either - * create a new record or return with an error. - * - * We want to search from the *end* of the "new" list, so that if - * duplicates are allowed we find the entry most likely to be paired - * up with the fork currently being added. - */ - if (Nu_RecordSet_GetLoaded(&pArchive->newRecordSet)) { - NuRecord* pNewRecord; + /* + * See if there's another record among the "new additions" with the + * same storageName and compatible threads. + * + * If found, add a new thread in that record. If an incompatibility + * exists (same fork already present, disk image is there, etc), either + * create a new record or return with an error. + * + * We want to search from the *end* of the "new" list, so that if + * duplicates are allowed we find the entry most likely to be paired + * up with the fork currently being added. + */ + if (Nu_RecordSet_GetLoaded(&pArchive->newRecordSet)) { + NuRecord* pNewRecord; - err = Nu_RecordSet_ReverseFindByName(&pArchive->newRecordSet, - pFileDetails->storageName, &pNewRecord); - if (err == kNuErrNone) { - /* is it okay to add it here? */ - err = Nu_OkayToAddThread(pArchive, pNewRecord, - pFileDetails->threadID); + err = Nu_RecordSet_ReverseFindByName(&pArchive->newRecordSet, + pFileDetails->storageName, &pNewRecord); + if (err == kNuErrNone) { + /* is it okay to add it here? */ + err = Nu_OkayToAddThread(pArchive, pNewRecord, + pFileDetails->threadID); - if (err == kNuErrNone) { - /* okay to add it to this record */ - DBUG((" attaching to existing record %06ld\n", - pNewRecord->recordIdx)); - err = Nu_AddFileThreadMod(pArchive, pNewRecord, pathname, - pFileDetails, fromRsrcFork); - BailError(err); - recordIdx = pNewRecord->recordIdx; - goto bail; /* we're done! */ - } + if (err == kNuErrNone) { + /* okay to add it to this record */ + DBUG((" attaching to existing record %06ld\n", + pNewRecord->recordIdx)); + err = Nu_AddFileThreadMod(pArchive, pNewRecord, pathname, + pFileDetails, fromRsrcFork); + BailError(err); + recordIdx = pNewRecord->recordIdx; + goto bail; /* we're done! */ + } - err = kNuErrNone; /* go a little farther */ + err = kNuErrNone; /* go a little farther */ - /* - * We found a brand-new record with the same name, but we - * can't add this fork to that record. We can't delete the - * item from the "new" list, so we can ignore HandleExisting. - * If we don't allow duplicates, return an error; if we do, - * then just continue with the normal processing path. - */ - if (!pArchive->valAllowDuplicates) { - DBUG(("+++ found matching record in new list, no dups\n")); - err = kNuErrRecordExists; - goto bail; - } + /* + * We found a brand-new record with the same name, but we + * can't add this fork to that record. We can't delete the + * item from the "new" list, so we can ignore HandleExisting. + * If we don't allow duplicates, return an error; if we do, + * then just continue with the normal processing path. + */ + if (!pArchive->valAllowDuplicates) { + DBUG(("+++ found matching record in new list, no dups\n")); + err = kNuErrRecordExists; + goto bail; + } - } else if (err == kNuErrRecNameNotFound) { - /* no match in "new" list, fall through to normal processing */ - err = kNuErrNone; - } else { - /* general failure */ - goto bail; - } - } + } else if (err == kNuErrRecNameNotFound) { + /* no match in "new" list, fall through to normal processing */ + err = kNuErrNone; + } else { + /* general failure */ + goto bail; + } + } - /* - * Wasn't found, invoke Nu_AddRecord. This will search through the - * existing records, using the "allow duplicates" flag to cope with - * any matches it finds. On success, we should have a brand-new record - * to play with. - */ - err = Nu_AddRecord(pArchive, pFileDetails, &recordIdx, &pRecord); - BailError(err); - DBUG(("--- Added new record %06ld\n", recordIdx)); + /* + * Wasn't found, invoke Nu_AddRecord. This will search through the + * existing records, using the "allow duplicates" flag to cope with + * any matches it finds. On success, we should have a brand-new record + * to play with. + */ + err = Nu_AddRecord(pArchive, pFileDetails, &recordIdx, &pRecord); + BailError(err); + DBUG(("--- Added new record %06ld\n", recordIdx)); - /* - * Got the record, now add a data file thread. - */ - err = Nu_AddFileThreadMod(pArchive, pRecord, pathname, pFileDetails, - fromRsrcFork); - BailError(err); + /* + * Got the record, now add a data file thread. + */ + err = Nu_AddFileThreadMod(pArchive, pRecord, pathname, pFileDetails, + fromRsrcFork); + BailError(err); bail: - if (err == kNuErrNone && pRecordIdx != nil) - *pRecordIdx = recordIdx; + if (err == kNuErrNone && pRecordIdx != nil) + *pRecordIdx = recordIdx; - return err; + return err; } /* * Rename a record. There are three situations: * - * (1) Record has the filename in a thread, and the field has enough - * room to hold the new name. For this case we add an "update" threadMod - * with the new data. - * (2) Record has the filename in a thread, and there is not enough room - * to hold the new name. Here, we add a "delete" threadMod for the - * existing filename, and add an "add" threadMod for the new. - * (3) Record stores the filename in the header. We zero out the filename - * and add a filename thread. + * (1) Record has the filename in a thread, and the field has enough + * room to hold the new name. For this case we add an "update" threadMod + * with the new data. + * (2) Record has the filename in a thread, and there is not enough room + * to hold the new name. Here, we add a "delete" threadMod for the + * existing filename, and add an "add" threadMod for the new. + * (3) Record stores the filename in the header. We zero out the filename + * and add a filename thread. * * We don't actually check to see if the filename is changing. If you * want to rename something to the same thing, go right ahead. (This @@ -2441,143 +2441,143 @@ bail: */ NuError Nu_Rename(NuArchive* pArchive, NuRecordIdx recIdx, const char* pathname, - char fssep) + char fssep) { - NuError err; - NuRecord* pRecord; - NuThread* pFilenameThread; - const NuThreadMod* pThreadMod; - NuThreadMod* pNewThreadMod = nil; - NuDataSource* pDataSource = nil; - long requiredCapacity, existingCapacity, newCapacity; - Boolean doDelete, doAdd, doUpdate; + NuError err; + NuRecord* pRecord; + NuThread* pFilenameThread; + const NuThreadMod* pThreadMod; + NuThreadMod* pNewThreadMod = nil; + NuDataSource* pDataSource = nil; + long requiredCapacity, existingCapacity, newCapacity; + Boolean doDelete, doAdd, doUpdate; - if (recIdx == 0 || pathname == nil || pathname[0] == '\0' || fssep == '\0') - return kNuErrInvalidArg; + if (recIdx == 0 || pathname == nil || pathname[0] == '\0' || fssep == '\0') + return kNuErrInvalidArg; - if (pathname[0] == fssep) { - err = kNuErrLeadingFssep; - Nu_ReportError(NU_BLOB, err, "rename path"); - goto bail; - } + if (pathname[0] == fssep) { + err = kNuErrLeadingFssep; + Nu_ReportError(NU_BLOB, err, "rename path"); + goto bail; + } - if (Nu_IsReadOnly(pArchive)) - return kNuErrArchiveRO; - err = Nu_GetTOCIfNeeded(pArchive); - BailError(err); + if (Nu_IsReadOnly(pArchive)) + return kNuErrArchiveRO; + err = Nu_GetTOCIfNeeded(pArchive); + BailError(err); - /* find the record in the "copy" set */ - err = Nu_FindRecordForWriteByIdx(pArchive, recIdx, &pRecord); - BailError(err); - Assert(pRecord != nil); + /* find the record in the "copy" set */ + err = Nu_FindRecordForWriteByIdx(pArchive, recIdx, &pRecord); + BailError(err); + Assert(pRecord != nil); - /* look for a filename thread */ - err = Nu_FindThreadByID(pRecord, kNuThreadIDFilename, &pFilenameThread); + /* look for a filename thread */ + err = Nu_FindThreadByID(pRecord, kNuThreadIDFilename, &pFilenameThread); - if (err != kNuErrNone) - pFilenameThread = nil; - else if (err == kNuErrNone && pRecord->pThreadMods) { - /* found a thread, check to see if it has been deleted (or modifed) */ - Assert(pFilenameThread != nil); - pThreadMod = Nu_ThreadMod_FindByThreadIdx(pRecord, - pFilenameThread->threadIdx); - if (pThreadMod != nil) { - DBUG(("--- tried to modify threadIdx %ld, which has already been\n", - pFilenameThread->threadIdx)); - err = kNuErrModThreadChange; - goto bail; - } - } + if (err != kNuErrNone) + pFilenameThread = nil; + else if (err == kNuErrNone && pRecord->pThreadMods) { + /* found a thread, check to see if it has been deleted (or modifed) */ + Assert(pFilenameThread != nil); + pThreadMod = Nu_ThreadMod_FindByThreadIdx(pRecord, + pFilenameThread->threadIdx); + if (pThreadMod != nil) { + DBUG(("--- tried to modify threadIdx %ld, which has already been\n", + pFilenameThread->threadIdx)); + err = kNuErrModThreadChange; + goto bail; + } + } - /* - * Looks like we're okay so far. Figure out what to do. - */ - doDelete = doAdd = doUpdate = false; - newCapacity = existingCapacity = 0; - requiredCapacity = strlen(pathname); + /* + * Looks like we're okay so far. Figure out what to do. + */ + doDelete = doAdd = doUpdate = false; + newCapacity = existingCapacity = 0; + requiredCapacity = strlen(pathname); - if (pFilenameThread != nil) { - existingCapacity = pFilenameThread->thCompThreadEOF; - if (existingCapacity >= requiredCapacity) { - doUpdate = true; - newCapacity = existingCapacity; - } else { - doDelete = doAdd = true; - /* make sure they have a few bytes of leeway */ - /*newCapacity = (requiredCapacity + kNuDefaultFilenameThreadSize) & - (~(kNuDefaultFilenameThreadSize-1));*/ - newCapacity = requiredCapacity + 8; - } - } else { - doAdd = true; - /*newCapacity = (requiredCapacity + kNuDefaultFilenameThreadSize) & - (~(kNuDefaultFilenameThreadSize-1));*/ - newCapacity = requiredCapacity + 8; - } + if (pFilenameThread != nil) { + existingCapacity = pFilenameThread->thCompThreadEOF; + if (existingCapacity >= requiredCapacity) { + doUpdate = true; + newCapacity = existingCapacity; + } else { + doDelete = doAdd = true; + /* make sure they have a few bytes of leeway */ + /*newCapacity = (requiredCapacity + kNuDefaultFilenameThreadSize) & + (~(kNuDefaultFilenameThreadSize-1));*/ + newCapacity = requiredCapacity + 8; + } + } else { + doAdd = true; + /*newCapacity = (requiredCapacity + kNuDefaultFilenameThreadSize) & + (~(kNuDefaultFilenameThreadSize-1));*/ + newCapacity = requiredCapacity + 8; + } - Assert(doAdd || doDelete || doUpdate); - Assert(doDelete == false || doAdd == true); + Assert(doAdd || doDelete || doUpdate); + Assert(doDelete == false || doAdd == true); - /* create a data source for the filename, if needed */ - if (doAdd || doUpdate) { - Assert(newCapacity); - err = Nu_DataSourceBuffer_New(kNuThreadFormatUncompressed, true, - newCapacity, (const uchar*)strdup(pathname), 0, - requiredCapacity /*(strlen)*/, &pDataSource); - BailError(err); - } + /* create a data source for the filename, if needed */ + if (doAdd || doUpdate) { + Assert(newCapacity); + err = Nu_DataSourceBuffer_New(kNuThreadFormatUncompressed, true, + newCapacity, (const uchar*)strdup(pathname), 0, + requiredCapacity /*(strlen)*/, &pDataSource); + BailError(err); + } - if (doDelete) { - err = Nu_ThreadModDelete_New(pArchive, pFilenameThread->threadIdx, - kNuThreadIDFilename, &pNewThreadMod); - BailError(err); - Nu_RecordAddThreadMod(pRecord, pNewThreadMod); - pNewThreadMod = nil; /* successful, don't free */ - } + if (doDelete) { + err = Nu_ThreadModDelete_New(pArchive, pFilenameThread->threadIdx, + kNuThreadIDFilename, &pNewThreadMod); + BailError(err); + Nu_RecordAddThreadMod(pRecord, pNewThreadMod); + pNewThreadMod = nil; /* successful, don't free */ + } - if (doAdd) { - err = Nu_ThreadModAdd_New(pArchive, kNuThreadIDFilename, - kNuThreadFormatUncompressed, pDataSource, &pNewThreadMod); - BailError(err); - pDataSource = nil; /* successful, don't free */ - Nu_RecordAddThreadMod(pRecord, pNewThreadMod); - pNewThreadMod = nil; /* successful, don't free */ - } + if (doAdd) { + err = Nu_ThreadModAdd_New(pArchive, kNuThreadIDFilename, + kNuThreadFormatUncompressed, pDataSource, &pNewThreadMod); + BailError(err); + pDataSource = nil; /* successful, don't free */ + Nu_RecordAddThreadMod(pRecord, pNewThreadMod); + pNewThreadMod = nil; /* successful, don't free */ + } - if (doUpdate) { - err = Nu_ThreadModUpdate_New(pArchive, pFilenameThread->threadIdx, - pDataSource, &pNewThreadMod); - BailError(err); - pDataSource = nil; /* successful, don't free */ - Nu_RecordAddThreadMod(pRecord, pNewThreadMod); - pNewThreadMod = nil; /* successful, don't free */ - } + if (doUpdate) { + err = Nu_ThreadModUpdate_New(pArchive, pFilenameThread->threadIdx, + pDataSource, &pNewThreadMod); + BailError(err); + pDataSource = nil; /* successful, don't free */ + Nu_RecordAddThreadMod(pRecord, pNewThreadMod); + pNewThreadMod = nil; /* successful, don't free */ + } - DBUG(("--- renaming '%s' to '%s' with delete=%d add=%d update=%d\n", - pRecord->filename, pathname, doDelete, doAdd, doUpdate)); + DBUG(("--- renaming '%s' to '%s' with delete=%d add=%d update=%d\n", + pRecord->filename, pathname, doDelete, doAdd, doUpdate)); - /* - * Update the fssep, if necessary. (This is slightly silly -- we - * have to rewrite the record header anyway since we're changing - * threads around.) - */ - if (NuGetSepFromSysInfo(pRecord->recFileSysInfo) != fssep) { - DBUG(("--- and updating the fssep\n")); - pRecord->recFileSysInfo = NuSetSepInSysInfo(pRecord->recFileSysInfo, - fssep); - pRecord->dirtyHeader = true; - } + /* + * Update the fssep, if necessary. (This is slightly silly -- we + * have to rewrite the record header anyway since we're changing + * threads around.) + */ + if (NuGetSepFromSysInfo(pRecord->recFileSysInfo) != fssep) { + DBUG(("--- and updating the fssep\n")); + pRecord->recFileSysInfo = NuSetSepInSysInfo(pRecord->recFileSysInfo, + fssep); + pRecord->dirtyHeader = true; + } - /* if we had a header filename, mark it for oblivion */ - if (pFilenameThread == nil) { - DBUG(("+++ rename gonna drop the filename\n")); - pRecord->dropRecFilename = true; - } + /* if we had a header filename, mark it for oblivion */ + if (pFilenameThread == nil) { + DBUG(("+++ rename gonna drop the filename\n")); + pRecord->dropRecFilename = true; + } bail: - Nu_ThreadModFree(pArchive, pNewThreadMod); - Nu_DataSourceFree(pDataSource); - return err; + Nu_ThreadModFree(pArchive, pNewThreadMod); + Nu_DataSourceFree(pDataSource); + return err; } @@ -2586,36 +2586,36 @@ bail: */ NuError Nu_SetRecordAttr(NuArchive* pArchive, NuRecordIdx recordIdx, - const NuRecordAttr* pRecordAttr) + const NuRecordAttr* pRecordAttr) { - NuError err; - NuRecord* pRecord; + NuError err; + NuRecord* pRecord; - if (pRecordAttr == nil) - return kNuErrInvalidArg; + if (pRecordAttr == nil) + return kNuErrInvalidArg; - if (Nu_IsReadOnly(pArchive)) - return kNuErrArchiveRO; - err = Nu_GetTOCIfNeeded(pArchive); - BailError(err); + if (Nu_IsReadOnly(pArchive)) + return kNuErrArchiveRO; + err = Nu_GetTOCIfNeeded(pArchive); + BailError(err); - /* pull the record out of the "copy" set */ - err = Nu_FindRecordForWriteByIdx(pArchive, recordIdx, &pRecord); - BailError(err); + /* pull the record out of the "copy" set */ + err = Nu_FindRecordForWriteByIdx(pArchive, recordIdx, &pRecord); + BailError(err); - Assert(pRecord != nil); - pRecord->recFileSysID = pRecordAttr->fileSysID; - /*pRecord->recFileSysInfo = pRecordAttr->fileSysInfo;*/ - pRecord->recAccess = pRecordAttr->access; - pRecord->recFileType = pRecordAttr->fileType; - pRecord->recExtraType = pRecordAttr->extraType; - pRecord->recCreateWhen = pRecordAttr->createWhen; - pRecord->recModWhen = pRecordAttr->modWhen; - pRecord->recArchiveWhen = pRecordAttr->archiveWhen; - pRecord->dirtyHeader = true; + Assert(pRecord != nil); + pRecord->recFileSysID = pRecordAttr->fileSysID; + /*pRecord->recFileSysInfo = pRecordAttr->fileSysInfo;*/ + pRecord->recAccess = pRecordAttr->access; + pRecord->recFileType = pRecordAttr->fileType; + pRecord->recExtraType = pRecordAttr->extraType; + pRecord->recCreateWhen = pRecordAttr->createWhen; + pRecord->recModWhen = pRecordAttr->modWhen; + pRecord->recArchiveWhen = pRecordAttr->archiveWhen; + pRecord->dirtyHeader = true; bail: - return err; + return err; } @@ -2625,81 +2625,81 @@ bail: NuError Nu_Delete(NuArchive* pArchive) { - NuError err; - NuSelectionProposal selProposal; - NuRecord* pNextRecord; - NuRecord* pRecord; - NuResult result; + NuError err; + NuSelectionProposal selProposal; + NuRecord* pNextRecord; + NuRecord* pRecord; + NuResult result; - if (Nu_IsReadOnly(pArchive)) - return kNuErrArchiveRO; - err = Nu_GetTOCIfNeeded(pArchive); - BailError(err); + if (Nu_IsReadOnly(pArchive)) + return kNuErrArchiveRO; + err = Nu_GetTOCIfNeeded(pArchive); + BailError(err); - /* - * If we don't yet have a copy set, make one. - */ - if (!Nu_RecordSet_GetLoaded(&pArchive->copyRecordSet)) { - err = Nu_RecordSet_Clone(pArchive, &pArchive->copyRecordSet, - &pArchive->origRecordSet); - BailError(err); - } + /* + * If we don't yet have a copy set, make one. + */ + if (!Nu_RecordSet_GetLoaded(&pArchive->copyRecordSet)) { + err = Nu_RecordSet_Clone(pArchive, &pArchive->copyRecordSet, + &pArchive->origRecordSet); + BailError(err); + } - /* - * Run through the copy set. This is different from most other - * operations, which run through the "orig" set. However, since - * we're not interested in allowing the user to delete things that - * have already been deleted, we might as well use this set. - */ - pNextRecord = Nu_RecordSet_GetListHead(&pArchive->copyRecordSet); - while (pNextRecord != nil) { - pRecord = pNextRecord; - pNextRecord = pRecord->pNext; + /* + * Run through the copy set. This is different from most other + * operations, which run through the "orig" set. However, since + * we're not interested in allowing the user to delete things that + * have already been deleted, we might as well use this set. + */ + pNextRecord = Nu_RecordSet_GetListHead(&pArchive->copyRecordSet); + while (pNextRecord != nil) { + pRecord = pNextRecord; + pNextRecord = pRecord->pNext; - /* - * Deletion of modified records (thread adds, deletes, or updates) - * isn't allowed. There's no point in showing the record to the - * user. - */ - if (pRecord->pThreadMods != nil) { - DBUG(("+++ Skipping delete on a modified record\n")); - continue; - } + /* + * Deletion of modified records (thread adds, deletes, or updates) + * isn't allowed. There's no point in showing the record to the + * user. + */ + if (pRecord->pThreadMods != nil) { + DBUG(("+++ Skipping delete on a modified record\n")); + continue; + } - /* - * If a selection filter is defined, allow the user the opportunity - * to select which files will be deleted, or abort the entire - * operation. - */ - if (pArchive->selectionFilterFunc != nil) { - selProposal.pRecord = pRecord; - selProposal.pThread = pRecord->pThreads; /* doesn't matter */ - result = (*pArchive->selectionFilterFunc)(pArchive, &selProposal); + /* + * If a selection filter is defined, allow the user the opportunity + * to select which files will be deleted, or abort the entire + * operation. + */ + if (pArchive->selectionFilterFunc != nil) { + selProposal.pRecord = pRecord; + selProposal.pThread = pRecord->pThreads; /* doesn't matter */ + result = (*pArchive->selectionFilterFunc)(pArchive, &selProposal); - if (result == kNuSkip) - continue; - if (result == kNuAbort) { - err = kNuErrAborted; - goto bail; - } - } + if (result == kNuSkip) + continue; + if (result == kNuAbort) { + err = kNuErrAborted; + goto bail; + } + } - /* - * Do we want to allow this? (Same test as for DeleteRecord.) - */ - if (pRecord->pThreadMods != nil || pRecord->dirtyHeader) { - DBUG(("--- Tried to delete a modified record\n")); - err = kNuErrModRecChange; - goto bail; - } + /* + * Do we want to allow this? (Same test as for DeleteRecord.) + */ + if (pRecord->pThreadMods != nil || pRecord->dirtyHeader) { + DBUG(("--- Tried to delete a modified record\n")); + err = kNuErrModRecChange; + goto bail; + } - err = Nu_RecordSet_DeleteRecord(pArchive, &pArchive->copyRecordSet, - pRecord); - BailError(err); - } + err = Nu_RecordSet_DeleteRecord(pArchive, &pArchive->copyRecordSet, + pRecord); + BailError(err); + } bail: - return err; + return err; } /* @@ -2708,37 +2708,37 @@ bail: NuError Nu_DeleteRecord(NuArchive* pArchive, NuRecordIdx recIdx) { - NuError err; - NuRecord* pRecord; + NuError err; + NuRecord* pRecord; - if (Nu_IsReadOnly(pArchive)) - return kNuErrArchiveRO; - err = Nu_GetTOCIfNeeded(pArchive); - BailError(err); + if (Nu_IsReadOnly(pArchive)) + return kNuErrArchiveRO; + err = Nu_GetTOCIfNeeded(pArchive); + BailError(err); - err = Nu_FindRecordForWriteByIdx(pArchive, recIdx, &pRecord); - BailError(err); + err = Nu_FindRecordForWriteByIdx(pArchive, recIdx, &pRecord); + BailError(err); - /* - * Deletion of modified records (thread adds, deletes, or updates) isn't - * allowed. It probably wouldn't be hard to handle, but it's pointless. - * Preventing the action maintains our general semantics of disallowing - * conflicting actions on the same object. - * - * We also block it if the header is dirty (e.g. they changed the - * record's filetype). This isn't necessary for correct operation, - * but again it maintains the semantics. - */ - if (pRecord->pThreadMods != nil || pRecord->dirtyHeader) { - DBUG(("--- Tried to delete a modified record\n")); - err = kNuErrModRecChange; - goto bail; - } + /* + * Deletion of modified records (thread adds, deletes, or updates) isn't + * allowed. It probably wouldn't be hard to handle, but it's pointless. + * Preventing the action maintains our general semantics of disallowing + * conflicting actions on the same object. + * + * We also block it if the header is dirty (e.g. they changed the + * record's filetype). This isn't necessary for correct operation, + * but again it maintains the semantics. + */ + if (pRecord->pThreadMods != nil || pRecord->dirtyHeader) { + DBUG(("--- Tried to delete a modified record\n")); + err = kNuErrModRecChange; + goto bail; + } - err = Nu_RecordSet_DeleteRecord(pArchive,&pArchive->copyRecordSet, pRecord); - BailError(err); + err = Nu_RecordSet_DeleteRecord(pArchive,&pArchive->copyRecordSet, pRecord); + BailError(err); bail: - return err; + return err; } diff --git a/nufxlib-0/SourceSink.c b/nufxlib-0/SourceSink.c index 172fcee..a099fdf 100644 --- a/nufxlib-0/SourceSink.c +++ b/nufxlib-0/SourceSink.c @@ -12,7 +12,7 @@ /* * =========================================================================== - * NuDataSource + * NuDataSource * =========================================================================== */ @@ -22,15 +22,15 @@ static NuError Nu_DataSourceNew(NuDataSource** ppDataSource) { - Assert(ppDataSource != nil); + Assert(ppDataSource != nil); - *ppDataSource = Nu_Malloc(nil, sizeof(**ppDataSource)); - if (*ppDataSource == nil) - return kNuErrMalloc; + *ppDataSource = Nu_Malloc(nil, sizeof(**ppDataSource)); + if (*ppDataSource == nil) + return kNuErrMalloc; - (*ppDataSource)->sourceType = kNuDataSourceUnknown; + (*ppDataSource)->sourceType = kNuDataSourceUnknown; - return kNuErrNone; + return kNuErrNone; } @@ -47,31 +47,31 @@ Nu_DataSourceNew(NuDataSource** ppDataSource) NuDataSource* Nu_DataSourceCopy(NuDataSource* pDataSource) { - NuDataSource* pNewDataSource; + NuDataSource* pNewDataSource; - Assert(pDataSource != nil); + Assert(pDataSource != nil); - if (Nu_DataSourceNew(&pNewDataSource) != kNuErrNone) - return nil; - Assert(pNewDataSource != nil); + if (Nu_DataSourceNew(&pNewDataSource) != kNuErrNone) + return nil; + Assert(pNewDataSource != nil); - /* this gets most of it */ - memcpy(pNewDataSource, pDataSource, sizeof(*pNewDataSource)); + /* this gets most of it */ + memcpy(pNewDataSource, pDataSource, sizeof(*pNewDataSource)); - /* copy anything we're sure to free up */ - if (pDataSource->sourceType == kNuDataSourceFromFile) { - Assert(pDataSource->fromFile.fp == nil); /* does this matter? */ - pNewDataSource->fromFile.pathname = - strdup(pDataSource->fromFile.pathname); - } + /* copy anything we're sure to free up */ + if (pDataSource->sourceType == kNuDataSourceFromFile) { + Assert(pDataSource->fromFile.fp == nil); /* does this matter? */ + pNewDataSource->fromFile.pathname = + strdup(pDataSource->fromFile.pathname); + } - /* don't let the original free up the resources */ - if (pDataSource->common.doClose) { - DBUG(("--- clearing doClose on source-copy of data source\n")); - pDataSource->common.doClose = false; - } + /* don't let the original free up the resources */ + if (pDataSource->common.doClose) { + DBUG(("--- clearing doClose on source-copy of data source\n")); + pDataSource->common.doClose = false; + } - return pNewDataSource; + return pNewDataSource; } @@ -81,38 +81,38 @@ Nu_DataSourceCopy(NuDataSource* pDataSource) NuError Nu_DataSourceFree(NuDataSource* pDataSource) { - if (pDataSource == nil) - return kNuErrNone; + if (pDataSource == nil) + return kNuErrNone; - switch (pDataSource->sourceType) { - case kNuDataSourceFromFile: - Nu_Free(nil, pDataSource->fromFile.pathname); - if (pDataSource->fromFile.fp != nil) { - fclose(pDataSource->fromFile.fp); - pDataSource->fromFile.fp = nil; - } - break; - case kNuDataSourceFromFP: - if (pDataSource->common.doClose) { - fclose(pDataSource->fromFile.fp); - pDataSource->fromFile.fp = nil; - } - break; - case kNuDataSourceFromBuffer: - if (pDataSource->common.doClose) { - Nu_Free(nil, (char*)pDataSource->fromBuffer.buffer); - pDataSource->fromBuffer.buffer = nil; - } - break; - case kNuDataSourceUnknown: - break; - default: - Assert(0); - return kNuErrInternal; - } + switch (pDataSource->sourceType) { + case kNuDataSourceFromFile: + Nu_Free(nil, pDataSource->fromFile.pathname); + if (pDataSource->fromFile.fp != nil) { + fclose(pDataSource->fromFile.fp); + pDataSource->fromFile.fp = nil; + } + break; + case kNuDataSourceFromFP: + if (pDataSource->common.doClose) { + fclose(pDataSource->fromFile.fp); + pDataSource->fromFile.fp = nil; + } + break; + case kNuDataSourceFromBuffer: + if (pDataSource->common.doClose) { + Nu_Free(nil, (char*)pDataSource->fromBuffer.buffer); + pDataSource->fromBuffer.buffer = nil; + } + break; + case kNuDataSourceUnknown: + break; + default: + Assert(0); + return kNuErrInternal; + } - Nu_Free(nil, pDataSource); - return kNuErrNone; + Nu_Free(nil, pDataSource); + return kNuErrNone; } @@ -121,34 +121,34 @@ Nu_DataSourceFree(NuDataSource* pDataSource) */ NuError Nu_DataSourceFile_New(NuThreadFormat threadFormat, Boolean doClose, - ulong otherLen, const char* pathname, Boolean isFromRsrcFork, - NuDataSource** ppDataSource) + ulong otherLen, const char* pathname, Boolean isFromRsrcFork, + NuDataSource** ppDataSource) { - NuError err; + NuError err; - if (!(doClose == true || doClose == false) || - pathname == nil || - !(isFromRsrcFork == true || isFromRsrcFork == false) || - ppDataSource == nil) - { - return kNuErrInvalidArg; - } + if (!(doClose == true || doClose == false) || + pathname == nil || + !(isFromRsrcFork == true || isFromRsrcFork == false) || + ppDataSource == nil) + { + return kNuErrInvalidArg; + } - err = Nu_DataSourceNew(ppDataSource); - BailErrorQuiet(err); + err = Nu_DataSourceNew(ppDataSource); + BailErrorQuiet(err); - (*ppDataSource)->common.sourceType = kNuDataSourceFromFile; - (*ppDataSource)->common.threadFormat = threadFormat; - (*ppDataSource)->common.doClose = doClose; - (*ppDataSource)->common.otherLen = otherLen; - (*ppDataSource)->fromFile.pathname = strdup(pathname); - (*ppDataSource)->fromFile.fromRsrcFork = isFromRsrcFork; + (*ppDataSource)->common.sourceType = kNuDataSourceFromFile; + (*ppDataSource)->common.threadFormat = threadFormat; + (*ppDataSource)->common.doClose = doClose; + (*ppDataSource)->common.otherLen = otherLen; + (*ppDataSource)->fromFile.pathname = strdup(pathname); + (*ppDataSource)->fromFile.fromRsrcFork = isFromRsrcFork; - (*ppDataSource)->common.dataLen = 0; /* to be filled in later */ - (*ppDataSource)->fromFile.fp = nil; /* to be filled in later */ + (*ppDataSource)->common.dataLen = 0; /* to be filled in later */ + (*ppDataSource)->fromFile.fp = nil; /* to be filled in later */ bail: - return err; + return err; } @@ -158,37 +158,37 @@ bail: */ NuError Nu_DataSourceFP_New(NuThreadFormat threadFormat, Boolean doClose, - ulong otherLen, FILE* fp, long offset, long length, - NuDataSource** ppDataSource) + ulong otherLen, FILE* fp, long offset, long length, + NuDataSource** ppDataSource) { - NuError err; + NuError err; - if (!(doClose == true || doClose == false) || - fp == nil || offset < 0 || length < 0 || - ppDataSource == nil) - { - return kNuErrInvalidArg; - } + if (!(doClose == true || doClose == false) || + fp == nil || offset < 0 || length < 0 || + ppDataSource == nil) + { + return kNuErrInvalidArg; + } - if (otherLen && otherLen < (ulong)length) { - DBUG(("--- rejecting FP len=%ld other=%ld\n", length, otherLen)); - err = kNuErrPreSizeOverflow; - goto bail; - } + if (otherLen && otherLen < (ulong)length) { + DBUG(("--- rejecting FP len=%ld other=%ld\n", length, otherLen)); + err = kNuErrPreSizeOverflow; + goto bail; + } - err = Nu_DataSourceNew(ppDataSource); - BailErrorQuiet(err); + err = Nu_DataSourceNew(ppDataSource); + BailErrorQuiet(err); - (*ppDataSource)->common.sourceType = kNuDataSourceFromFP; - (*ppDataSource)->common.threadFormat = threadFormat; - (*ppDataSource)->common.doClose = doClose; - (*ppDataSource)->common.dataLen = length; - (*ppDataSource)->common.otherLen = otherLen; - (*ppDataSource)->fromFP.fp = fp; - (*ppDataSource)->fromFP.offset = offset; + (*ppDataSource)->common.sourceType = kNuDataSourceFromFP; + (*ppDataSource)->common.threadFormat = threadFormat; + (*ppDataSource)->common.doClose = doClose; + (*ppDataSource)->common.dataLen = length; + (*ppDataSource)->common.otherLen = otherLen; + (*ppDataSource)->fromFP.fp = fp; + (*ppDataSource)->fromFP.offset = offset; bail: - return err; + return err; } @@ -201,45 +201,45 @@ bail: */ NuError Nu_DataSourceBuffer_New(NuThreadFormat threadFormat, Boolean doClose, - ulong otherLen, const uchar* buffer, long offset, long length, - NuDataSource** ppDataSource) + ulong otherLen, const uchar* buffer, long offset, long length, + NuDataSource** ppDataSource) { - NuError err; + NuError err; - if (!(doClose == true || doClose == false) || - offset < 0 || length < 0 || ppDataSource == nil) - { - return kNuErrInvalidArg; - } - if (buffer == nil && (offset != 0 || length != 0)) - { - return kNuErrInvalidArg; - } - if (buffer == nil) - doClose = false; + if (!(doClose == true || doClose == false) || + offset < 0 || length < 0 || ppDataSource == nil) + { + return kNuErrInvalidArg; + } + if (buffer == nil && (offset != 0 || length != 0)) + { + return kNuErrInvalidArg; + } + if (buffer == nil) + doClose = false; - if (otherLen && otherLen < (ulong)length) { - DBUG(("--- rejecting buffer len=%ld other=%ld\n", length, otherLen)); - err = kNuErrPreSizeOverflow; - goto bail; - } + if (otherLen && otherLen < (ulong)length) { + DBUG(("--- rejecting buffer len=%ld other=%ld\n", length, otherLen)); + err = kNuErrPreSizeOverflow; + goto bail; + } - err = Nu_DataSourceNew(ppDataSource); - BailErrorQuiet(err); + err = Nu_DataSourceNew(ppDataSource); + BailErrorQuiet(err); - (*ppDataSource)->common.sourceType = kNuDataSourceFromBuffer; - (*ppDataSource)->common.threadFormat = threadFormat; - (*ppDataSource)->common.doClose = doClose; - (*ppDataSource)->common.dataLen = length; - (*ppDataSource)->common.otherLen = otherLen; - (*ppDataSource)->fromBuffer.buffer = buffer; - (*ppDataSource)->fromBuffer.offset = offset; + (*ppDataSource)->common.sourceType = kNuDataSourceFromBuffer; + (*ppDataSource)->common.threadFormat = threadFormat; + (*ppDataSource)->common.doClose = doClose; + (*ppDataSource)->common.dataLen = length; + (*ppDataSource)->common.otherLen = otherLen; + (*ppDataSource)->fromBuffer.buffer = buffer; + (*ppDataSource)->fromBuffer.offset = offset; - (*ppDataSource)->fromBuffer.curOffset = offset; - (*ppDataSource)->fromBuffer.curDataLen = length; + (*ppDataSource)->fromBuffer.curOffset = offset; + (*ppDataSource)->fromBuffer.curDataLen = length; bail: - return err; + return err; } @@ -249,8 +249,8 @@ bail: NuDataSourceType Nu_DataSourceGetType(const NuDataSource* pDataSource) { - Assert(pDataSource != nil); - return pDataSource->sourceType; + Assert(pDataSource != nil); + return pDataSource->sourceType; } /* @@ -259,8 +259,8 @@ Nu_DataSourceGetType(const NuDataSource* pDataSource) NuThreadFormat Nu_DataSourceGetThreadFormat(const NuDataSource* pDataSource) { - Assert(pDataSource != nil); - return pDataSource->common.threadFormat; + Assert(pDataSource != nil); + return pDataSource->common.threadFormat; } /* @@ -269,14 +269,14 @@ Nu_DataSourceGetThreadFormat(const NuDataSource* pDataSource) ulong Nu_DataSourceGetDataLen(const NuDataSource* pDataSource) { - Assert(pDataSource != nil); + Assert(pDataSource != nil); - if (pDataSource->sourceType == kNuDataSourceFromFile) { - /* dataLen can only be valid if file has been opened */ - Assert(pDataSource->fromFile.fp != nil); - } + if (pDataSource->sourceType == kNuDataSourceFromFile) { + /* dataLen can only be valid if file has been opened */ + Assert(pDataSource->fromFile.fp != nil); + } - return pDataSource->common.dataLen; + return pDataSource->common.dataLen; } /* @@ -285,8 +285,8 @@ Nu_DataSourceGetDataLen(const NuDataSource* pDataSource) ulong Nu_DataSourceGetOtherLen(const NuDataSource* pDataSource) { - Assert(pDataSource != nil); - return pDataSource->common.otherLen; + Assert(pDataSource != nil); + return pDataSource->common.otherLen; } /* @@ -295,8 +295,8 @@ Nu_DataSourceGetOtherLen(const NuDataSource* pDataSource) void Nu_DataSourceSetOtherLen(NuDataSource* pDataSource, long otherLen) { - Assert(pDataSource != nil && otherLen > 0); - pDataSource->common.otherLen = otherLen; + Assert(pDataSource != nil && otherLen > 0); + pDataSource->common.otherLen = otherLen; } @@ -306,8 +306,8 @@ Nu_DataSourceSetOtherLen(NuDataSource* pDataSource, long otherLen) ushort Nu_DataSourceGetRawCrc(const NuDataSource* pDataSource) { - Assert(pDataSource != nil); - return pDataSource->common.rawCrc; + Assert(pDataSource != nil); + return pDataSource->common.rawCrc; } /* @@ -317,8 +317,8 @@ Nu_DataSourceGetRawCrc(const NuDataSource* pDataSource) void Nu_DataSourceSetRawCrc(NuDataSource* pDataSource, ushort crc) { - Assert(pDataSource != nil); - pDataSource->common.rawCrc = crc; + Assert(pDataSource != nil); + pDataSource->common.rawCrc = crc; } @@ -328,47 +328,47 @@ Nu_DataSourceSetRawCrc(NuDataSource* pDataSource, ushort crc) NuError Nu_DataSourcePrepareInput(NuArchive* pArchive, NuDataSource* pDataSource) { - NuError err = kNuErrNone; - FILE* fileFp = nil; + NuError err = kNuErrNone; + FILE* fileFp = nil; - /* - * Doesn't apply to buffer sources. - */ - if (Nu_DataSourceGetType(pDataSource) == kNuDataSourceFromBuffer) - goto bail; + /* + * Doesn't apply to buffer sources. + */ + if (Nu_DataSourceGetType(pDataSource) == kNuDataSourceFromBuffer) + goto bail; - /* - * FP sources can be used several times, so we need to seek them - * to the correct offset before we begin. - */ - if (Nu_DataSourceGetType(pDataSource) == kNuDataSourceFromFP) { - err = Nu_FSeek(pDataSource->fromFP.fp, pDataSource->fromFP.offset, - SEEK_SET); - goto bail; /* return this err */ - } + /* + * FP sources can be used several times, so we need to seek them + * to the correct offset before we begin. + */ + if (Nu_DataSourceGetType(pDataSource) == kNuDataSourceFromFP) { + err = Nu_FSeek(pDataSource->fromFP.fp, pDataSource->fromFP.offset, + SEEK_SET); + goto bail; /* return this err */ + } - /* - * We're adding from a file on disk. Open it. - */ - err = Nu_OpenInputFile(pArchive, - pDataSource->fromFile.pathname, pDataSource->fromFile.fromRsrcFork, - &fileFp); - BailError(err); + /* + * We're adding from a file on disk. Open it. + */ + err = Nu_OpenInputFile(pArchive, + pDataSource->fromFile.pathname, pDataSource->fromFile.fromRsrcFork, + &fileFp); + BailError(err); - Assert(fileFp != nil); - pDataSource->fromFile.fp = fileFp; - err = Nu_GetFileLength(pArchive, fileFp, - (long*)&pDataSource->common.dataLen); - BailError(err); + Assert(fileFp != nil); + pDataSource->fromFile.fp = fileFp; + err = Nu_GetFileLength(pArchive, fileFp, + (long*)&pDataSource->common.dataLen); + BailError(err); - if (pDataSource->common.otherLen && - pDataSource->common.otherLen < pDataSource->common.dataLen) - { - DBUG(("--- Uh oh, looks like file len is too small for presized\n")); - } + if (pDataSource->common.otherLen && + pDataSource->common.otherLen < pDataSource->common.dataLen) + { + DBUG(("--- Uh oh, looks like file len is too small for presized\n")); + } bail: - return err; + return err; } @@ -385,14 +385,14 @@ bail: void Nu_DataSourceUnPrepareInput(NuArchive* pArchive, NuDataSource* pDataSource) { - if (Nu_DataSourceGetType(pDataSource) != kNuDataSourceFromFile) - return; + if (Nu_DataSourceGetType(pDataSource) != kNuDataSourceFromFile) + return; - if (pDataSource->fromFile.fp != nil) { - fclose(pDataSource->fromFile.fp); - pDataSource->fromFile.fp = nil; - pDataSource->common.dataLen = 0; - } + if (pDataSource->fromFile.fp != nil) { + fclose(pDataSource->fromFile.fp); + pDataSource->fromFile.fp = nil; + pDataSource->common.dataLen = 0; + } } @@ -402,11 +402,11 @@ Nu_DataSourceUnPrepareInput(NuArchive* pArchive, NuDataSource* pDataSource) const char* Nu_DataSourceFile_GetPathname(NuDataSource* pDataSource) { - Assert(pDataSource != nil); - Assert(pDataSource->sourceType == kNuDataSourceFromFile); - Assert(pDataSource->fromFile.pathname != nil); + Assert(pDataSource != nil); + Assert(pDataSource->sourceType == kNuDataSourceFromFile); + Assert(pDataSource->fromFile.pathname != nil); - return pDataSource->fromFile.pathname; + return pDataSource->fromFile.pathname; } @@ -416,42 +416,42 @@ Nu_DataSourceFile_GetPathname(NuDataSource* pDataSource) NuError Nu_DataSourceGetBlock(NuDataSource* pDataSource, uchar* buf, ulong len) { - NuError err; + NuError err; - Assert(pDataSource != nil); - Assert(buf != nil); - Assert(len > 0); + Assert(pDataSource != nil); + Assert(buf != nil); + Assert(len > 0); - switch (pDataSource->sourceType) { - case kNuDataSourceFromFile: - Assert(pDataSource->fromFile.fp != nil); - err = Nu_FRead(pDataSource->fromFile.fp, buf, len); - if (feof(pDataSource->fromFile.fp)) - Nu_ReportError(NU_NILBLOB, err, "EOF hit unexpectedly"); - return err; + switch (pDataSource->sourceType) { + case kNuDataSourceFromFile: + Assert(pDataSource->fromFile.fp != nil); + err = Nu_FRead(pDataSource->fromFile.fp, buf, len); + if (feof(pDataSource->fromFile.fp)) + Nu_ReportError(NU_NILBLOB, err, "EOF hit unexpectedly"); + return err; - case kNuDataSourceFromFP: - err = Nu_FRead(pDataSource->fromFP.fp, buf, len); - if (feof(pDataSource->fromFP.fp)) - Nu_ReportError(NU_NILBLOB, err, "EOF hit unexpectedly"); - return err; + case kNuDataSourceFromFP: + err = Nu_FRead(pDataSource->fromFP.fp, buf, len); + if (feof(pDataSource->fromFP.fp)) + Nu_ReportError(NU_NILBLOB, err, "EOF hit unexpectedly"); + return err; - case kNuDataSourceFromBuffer: - if ((long)len > pDataSource->fromBuffer.curDataLen) { - /* buffer underrun */ - return kNuErrBufferUnderrun; - } - memcpy(buf, - pDataSource->fromBuffer.buffer + pDataSource->fromBuffer.curOffset, - len); - pDataSource->fromBuffer.curOffset += len; - pDataSource->fromBuffer.curDataLen -= len; - return kNuErrNone; + case kNuDataSourceFromBuffer: + if ((long)len > pDataSource->fromBuffer.curDataLen) { + /* buffer underrun */ + return kNuErrBufferUnderrun; + } + memcpy(buf, + pDataSource->fromBuffer.buffer + pDataSource->fromBuffer.curOffset, + len); + pDataSource->fromBuffer.curOffset += len; + pDataSource->fromBuffer.curDataLen -= len; + return kNuErrNone; - default: - Assert(false); - return kNuErrInternal; - } + default: + Assert(false); + return kNuErrInternal; + } } @@ -461,36 +461,36 @@ Nu_DataSourceGetBlock(NuDataSource* pDataSource, uchar* buf, ulong len) NuError Nu_DataSourceRewind(NuDataSource* pDataSource) { - NuError err; + NuError err; - Assert(pDataSource != nil); + Assert(pDataSource != nil); - switch (pDataSource->sourceType) { - case kNuDataSourceFromFile: - Assert(pDataSource->fromFile.fp != nil); - err = Nu_FSeek(pDataSource->fromFile.fp, 0, SEEK_SET); - break; /* fall through with error */ - case kNuDataSourceFromFP: - err = Nu_FSeek(pDataSource->fromFP.fp, pDataSource->fromFP.offset, - SEEK_SET); - break; /* fall through with error */ - case kNuDataSourceFromBuffer: - pDataSource->fromBuffer.curOffset = pDataSource->fromBuffer.offset; - pDataSource->fromBuffer.curDataLen = pDataSource->common.dataLen; - err = kNuErrNone; - break; - default: - Assert(false); - err = kNuErrInternal; - } + switch (pDataSource->sourceType) { + case kNuDataSourceFromFile: + Assert(pDataSource->fromFile.fp != nil); + err = Nu_FSeek(pDataSource->fromFile.fp, 0, SEEK_SET); + break; /* fall through with error */ + case kNuDataSourceFromFP: + err = Nu_FSeek(pDataSource->fromFP.fp, pDataSource->fromFP.offset, + SEEK_SET); + break; /* fall through with error */ + case kNuDataSourceFromBuffer: + pDataSource->fromBuffer.curOffset = pDataSource->fromBuffer.offset; + pDataSource->fromBuffer.curDataLen = pDataSource->common.dataLen; + err = kNuErrNone; + break; + default: + Assert(false); + err = kNuErrInternal; + } - return err; + return err; } /* * =========================================================================== - * NuDataSink + * NuDataSink * =========================================================================== */ @@ -500,15 +500,15 @@ Nu_DataSourceRewind(NuDataSource* pDataSource) static NuError Nu_DataSinkNew(NuDataSink** ppDataSink) { - Assert(ppDataSink != nil); + Assert(ppDataSink != nil); - *ppDataSink = Nu_Malloc(nil, sizeof(**ppDataSink)); - if (*ppDataSink == nil) - return kNuErrMalloc; + *ppDataSink = Nu_Malloc(nil, sizeof(**ppDataSink)); + if (*ppDataSink == nil) + return kNuErrMalloc; - (*ppDataSink)->sinkType = kNuDataSinkUnknown; + (*ppDataSink)->sinkType = kNuDataSinkUnknown; - return kNuErrNone; + return kNuErrNone; } @@ -518,29 +518,29 @@ Nu_DataSinkNew(NuDataSink** ppDataSink) NuError Nu_DataSinkFree(NuDataSink* pDataSink) { - if (pDataSink == nil) - return kNuErrNone; + if (pDataSink == nil) + return kNuErrNone; - switch (pDataSink->sinkType) { - case kNuDataSinkToFile: - Nu_DataSinkFile_Close(pDataSink); - Nu_Free(nil, pDataSink->toFile.pathname); - break; - case kNuDataSinkToFP: - break; - case kNuDataSinkToBuffer: - break; - case kNuDataSinkToVoid: - break; - case kNuDataSinkUnknown: - break; - default: - Assert(0); - return kNuErrInternal; - } + switch (pDataSink->sinkType) { + case kNuDataSinkToFile: + Nu_DataSinkFile_Close(pDataSink); + Nu_Free(nil, pDataSink->toFile.pathname); + break; + case kNuDataSinkToFP: + break; + case kNuDataSinkToBuffer: + break; + case kNuDataSinkToVoid: + break; + case kNuDataSinkUnknown: + break; + default: + Assert(0); + return kNuErrInternal; + } - Nu_Free(nil, pDataSink); - return kNuErrNone; + Nu_Free(nil, pDataSink); + return kNuErrNone; } @@ -549,37 +549,37 @@ Nu_DataSinkFree(NuDataSink* pDataSink) */ NuError Nu_DataSinkFile_New(Boolean doExpand, NuValue convertEOL, const char* pathname, - char fssep, NuDataSink** ppDataSink) + char fssep, NuDataSink** ppDataSink) { - NuError err; + NuError err; - if ((doExpand != true && doExpand != false) || - (convertEOL != kNuConvertOff && convertEOL != kNuConvertOn && - convertEOL != kNuConvertAuto) || - pathname == nil || - fssep == 0 || - ppDataSink == nil) - { - return kNuErrInvalidArg; - } + if ((doExpand != true && doExpand != false) || + (convertEOL != kNuConvertOff && convertEOL != kNuConvertOn && + convertEOL != kNuConvertAuto) || + pathname == nil || + fssep == 0 || + ppDataSink == nil) + { + return kNuErrInvalidArg; + } - err = Nu_DataSinkNew(ppDataSink); - BailErrorQuiet(err); + err = Nu_DataSinkNew(ppDataSink); + BailErrorQuiet(err); - (*ppDataSink)->common.sinkType = kNuDataSinkToFile; - (*ppDataSink)->common.doExpand = doExpand; - if (doExpand) - (*ppDataSink)->common.convertEOL = convertEOL; - else - (*ppDataSink)->common.convertEOL = kNuConvertOff; - (*ppDataSink)->common.outCount = 0; - (*ppDataSink)->toFile.pathname = strdup(pathname); - (*ppDataSink)->toFile.fssep = fssep; + (*ppDataSink)->common.sinkType = kNuDataSinkToFile; + (*ppDataSink)->common.doExpand = doExpand; + if (doExpand) + (*ppDataSink)->common.convertEOL = convertEOL; + else + (*ppDataSink)->common.convertEOL = kNuConvertOff; + (*ppDataSink)->common.outCount = 0; + (*ppDataSink)->toFile.pathname = strdup(pathname); + (*ppDataSink)->toFile.fssep = fssep; - (*ppDataSink)->toFile.fp = nil; + (*ppDataSink)->toFile.fp = nil; bail: - return err; + return err; } @@ -588,33 +588,33 @@ bail: */ NuError Nu_DataSinkFP_New(Boolean doExpand, NuValue convertEOL, FILE* fp, - NuDataSink** ppDataSink) + NuDataSink** ppDataSink) { - NuError err; + NuError err; - if ((doExpand != true && doExpand != false) || - (convertEOL != kNuConvertOff && convertEOL != kNuConvertOn && - convertEOL != kNuConvertAuto) || - fp == nil || - ppDataSink == nil) - { - return kNuErrInvalidArg; - } + if ((doExpand != true && doExpand != false) || + (convertEOL != kNuConvertOff && convertEOL != kNuConvertOn && + convertEOL != kNuConvertAuto) || + fp == nil || + ppDataSink == nil) + { + return kNuErrInvalidArg; + } - err = Nu_DataSinkNew(ppDataSink); - BailErrorQuiet(err); + err = Nu_DataSinkNew(ppDataSink); + BailErrorQuiet(err); - (*ppDataSink)->common.sinkType = kNuDataSinkToFP; - (*ppDataSink)->common.doExpand = doExpand; - if (doExpand) - (*ppDataSink)->common.convertEOL = convertEOL; - else - (*ppDataSink)->common.convertEOL = kNuConvertOff; - (*ppDataSink)->common.outCount = 0; - (*ppDataSink)->toFP.fp = fp; + (*ppDataSink)->common.sinkType = kNuDataSinkToFP; + (*ppDataSink)->common.doExpand = doExpand; + if (doExpand) + (*ppDataSink)->common.convertEOL = convertEOL; + else + (*ppDataSink)->common.convertEOL = kNuConvertOff; + (*ppDataSink)->common.outCount = 0; + (*ppDataSink)->toFP.fp = fp; bail: - return err; + return err; } @@ -623,37 +623,37 @@ bail: */ NuError Nu_DataSinkBuffer_New(Boolean doExpand, NuValue convertEOL, uchar* buffer, - ulong bufLen, NuDataSink** ppDataSink) + ulong bufLen, NuDataSink** ppDataSink) { - NuError err; + NuError err; - if ((doExpand != true && doExpand != false) || - (convertEOL != kNuConvertOff && convertEOL != kNuConvertOn && - convertEOL != kNuConvertAuto) || - buffer == nil || - bufLen == 0 || - ppDataSink == nil) - { - return kNuErrInvalidArg; - } + if ((doExpand != true && doExpand != false) || + (convertEOL != kNuConvertOff && convertEOL != kNuConvertOn && + convertEOL != kNuConvertAuto) || + buffer == nil || + bufLen == 0 || + ppDataSink == nil) + { + return kNuErrInvalidArg; + } - err = Nu_DataSinkNew(ppDataSink); - BailErrorQuiet(err); + err = Nu_DataSinkNew(ppDataSink); + BailErrorQuiet(err); - (*ppDataSink)->common.sinkType = kNuDataSinkToBuffer; - (*ppDataSink)->common.doExpand = doExpand; - if (doExpand) - (*ppDataSink)->common.convertEOL = convertEOL; - else - (*ppDataSink)->common.convertEOL = kNuConvertOff; - (*ppDataSink)->common.convertEOL = convertEOL; - (*ppDataSink)->common.outCount = 0; - (*ppDataSink)->toBuffer.buffer = buffer; - (*ppDataSink)->toBuffer.bufLen = bufLen; - (*ppDataSink)->toBuffer.stickyErr = kNuErrNone; + (*ppDataSink)->common.sinkType = kNuDataSinkToBuffer; + (*ppDataSink)->common.doExpand = doExpand; + if (doExpand) + (*ppDataSink)->common.convertEOL = convertEOL; + else + (*ppDataSink)->common.convertEOL = kNuConvertOff; + (*ppDataSink)->common.convertEOL = convertEOL; + (*ppDataSink)->common.outCount = 0; + (*ppDataSink)->toBuffer.buffer = buffer; + (*ppDataSink)->toBuffer.bufLen = bufLen; + (*ppDataSink)->toBuffer.stickyErr = kNuErrNone; bail: - return err; + return err; } @@ -662,23 +662,23 @@ bail: */ NuError Nu_DataSinkVoid_New(Boolean doExpand, NuValue convertEOL, - NuDataSink** ppDataSink) + NuDataSink** ppDataSink) { - NuError err; + NuError err; - Assert(doExpand == true || doExpand == false); - Assert(ppDataSink != nil); + Assert(doExpand == true || doExpand == false); + Assert(ppDataSink != nil); - err = Nu_DataSinkNew(ppDataSink); - BailErrorQuiet(err); + err = Nu_DataSinkNew(ppDataSink); + BailErrorQuiet(err); - (*ppDataSink)->common.sinkType = kNuDataSinkToVoid; - (*ppDataSink)->common.doExpand = doExpand; - (*ppDataSink)->common.convertEOL = convertEOL; - (*ppDataSink)->common.outCount = 0; + (*ppDataSink)->common.sinkType = kNuDataSinkToVoid; + (*ppDataSink)->common.doExpand = doExpand; + (*ppDataSink)->common.convertEOL = convertEOL; + (*ppDataSink)->common.outCount = 0; bail: - return err; + return err; } @@ -688,8 +688,8 @@ bail: NuDataSinkType Nu_DataSinkGetType(const NuDataSink* pDataSink) { - Assert(pDataSink != nil); - return pDataSink->sinkType; + Assert(pDataSink != nil); + return pDataSink->sinkType; } @@ -699,7 +699,7 @@ Nu_DataSinkGetType(const NuDataSink* pDataSink) Boolean Nu_DataSinkGetDoExpand(const NuDataSink* pDataSink) { - return pDataSink->common.doExpand; + return pDataSink->common.doExpand; } /* @@ -708,7 +708,7 @@ Nu_DataSinkGetDoExpand(const NuDataSink* pDataSink) NuValue Nu_DataSinkGetConvertEOL(const NuDataSink* pDataSink) { - return pDataSink->common.convertEOL; + return pDataSink->common.convertEOL; } /* @@ -717,7 +717,7 @@ Nu_DataSinkGetConvertEOL(const NuDataSink* pDataSink) ulong Nu_DataSinkGetOutCount(const NuDataSink* pDataSink) { - return pDataSink->common.outCount; + return pDataSink->common.outCount; } @@ -727,10 +727,10 @@ Nu_DataSinkGetOutCount(const NuDataSink* pDataSink) const char* Nu_DataSinkFile_GetPathname(const NuDataSink* pDataSink) { - Assert(pDataSink != nil); - Assert(pDataSink->sinkType == kNuDataSinkToFile); + Assert(pDataSink != nil); + Assert(pDataSink->sinkType == kNuDataSinkToFile); - return pDataSink->toFile.pathname; + return pDataSink->toFile.pathname; } /* @@ -739,10 +739,10 @@ Nu_DataSinkFile_GetPathname(const NuDataSink* pDataSink) char Nu_DataSinkFile_GetFssep(const NuDataSink* pDataSink) { - Assert(pDataSink != nil); - Assert(pDataSink->sinkType == kNuDataSinkToFile); + Assert(pDataSink != nil); + Assert(pDataSink->sinkType == kNuDataSinkToFile); - return pDataSink->toFile.fssep; + return pDataSink->toFile.fssep; } /* @@ -751,10 +751,10 @@ Nu_DataSinkFile_GetFssep(const NuDataSink* pDataSink) FILE* Nu_DataSinkFile_GetFP(const NuDataSink* pDataSink) { - Assert(pDataSink != nil); - Assert(pDataSink->sinkType == kNuDataSinkToFile); + Assert(pDataSink != nil); + Assert(pDataSink->sinkType == kNuDataSinkToFile); - return pDataSink->toFile.fp; + return pDataSink->toFile.fp; } /* @@ -763,10 +763,10 @@ Nu_DataSinkFile_GetFP(const NuDataSink* pDataSink) void Nu_DataSinkFile_SetFP(NuDataSink* pDataSink, FILE* fp) { - Assert(pDataSink != nil); - Assert(pDataSink->sinkType == kNuDataSinkToFile); + Assert(pDataSink != nil); + Assert(pDataSink->sinkType == kNuDataSinkToFile); - pDataSink->toFile.fp = fp; + pDataSink->toFile.fp = fp; } /* @@ -775,12 +775,12 @@ Nu_DataSinkFile_SetFP(NuDataSink* pDataSink, FILE* fp) void Nu_DataSinkFile_Close(NuDataSink* pDataSink) { - Assert(pDataSink != nil); + Assert(pDataSink != nil); - if (pDataSink->toFile.fp != nil) { - fclose(pDataSink->toFile.fp); - pDataSink->toFile.fp = nil; - } + if (pDataSink->toFile.fp != nil) { + fclose(pDataSink->toFile.fp); + pDataSink->toFile.fp = nil; + } } @@ -790,43 +790,43 @@ Nu_DataSinkFile_Close(NuDataSink* pDataSink) NuError Nu_DataSinkPutBlock(NuDataSink* pDataSink, const uchar* buf, ulong len) { - NuError err; + NuError err; - Assert(pDataSink != nil); - Assert(buf != nil); - Assert(len > 0); + Assert(pDataSink != nil); + Assert(buf != nil); + Assert(len > 0); - switch (pDataSink->sinkType) { - case kNuDataSinkToFile: - err = Nu_FWrite(pDataSink->toFile.fp, buf, len); - if (err != kNuErrNone) - return err; - break; - case kNuDataSinkToFP: - err = Nu_FWrite(pDataSink->toFP.fp, buf, len); - if (err != kNuErrNone) - return err; - break; - case kNuDataSinkToBuffer: - if (len > pDataSink->toBuffer.bufLen) { - /* buffer overrun; set a "sticky" error, like FILE* does */ - err = kNuErrBufferOverrun; - pDataSink->toBuffer.stickyErr = err; - return err; - } - memcpy(pDataSink->toBuffer.buffer, buf, len); - pDataSink->toBuffer.buffer += len; - pDataSink->toBuffer.bufLen -= len; - break; - case kNuDataSinkToVoid: - /* do nothing */ - break; - default: - Assert(false); - return kNuErrInternal; - } - pDataSink->common.outCount += len; - return kNuErrNone; + switch (pDataSink->sinkType) { + case kNuDataSinkToFile: + err = Nu_FWrite(pDataSink->toFile.fp, buf, len); + if (err != kNuErrNone) + return err; + break; + case kNuDataSinkToFP: + err = Nu_FWrite(pDataSink->toFP.fp, buf, len); + if (err != kNuErrNone) + return err; + break; + case kNuDataSinkToBuffer: + if (len > pDataSink->toBuffer.bufLen) { + /* buffer overrun; set a "sticky" error, like FILE* does */ + err = kNuErrBufferOverrun; + pDataSink->toBuffer.stickyErr = err; + return err; + } + memcpy(pDataSink->toBuffer.buffer, buf, len); + pDataSink->toBuffer.buffer += len; + pDataSink->toBuffer.bufLen -= len; + break; + case kNuDataSinkToVoid: + /* do nothing */ + break; + default: + Assert(false); + return kNuErrInternal; + } + pDataSink->common.outCount += len; + return kNuErrNone; } @@ -836,31 +836,31 @@ Nu_DataSinkPutBlock(NuDataSink* pDataSink, const uchar* buf, ulong len) NuError Nu_DataSinkGetError(NuDataSink* pDataSink) { - NuError err = kNuErrNone; + NuError err = kNuErrNone; - Assert(pDataSink != nil); + Assert(pDataSink != nil); - switch (pDataSink->sinkType) { - case kNuDataSinkToFile: - if (ferror(pDataSink->toFile.fp)) - err = kNuErrFileWrite; - break; - case kNuDataSinkToFP: - if (ferror(pDataSink->toFP.fp)) - err = kNuErrFileWrite; - break; - case kNuDataSinkToBuffer: - err = pDataSink->toBuffer.stickyErr; - break; - case kNuDataSinkToVoid: - /* do nothing */ - break; - default: - Assert(false); - err = kNuErrInternal; - break; - } + switch (pDataSink->sinkType) { + case kNuDataSinkToFile: + if (ferror(pDataSink->toFile.fp)) + err = kNuErrFileWrite; + break; + case kNuDataSinkToFP: + if (ferror(pDataSink->toFP.fp)) + err = kNuErrFileWrite; + break; + case kNuDataSinkToBuffer: + err = pDataSink->toBuffer.stickyErr; + break; + case kNuDataSinkToVoid: + /* do nothing */ + break; + default: + Assert(false); + err = kNuErrInternal; + break; + } - return err; + return err; } diff --git a/nufxlib-0/SunOS4.h b/nufxlib-0/SunOS4.h index 76161ea..22467d1 100644 --- a/nufxlib-0/SunOS4.h +++ b/nufxlib-0/SunOS4.h @@ -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__*/ diff --git a/nufxlib-0/SysDefs.h b/nufxlib-0/SysDefs.h index 35e22a2..91c6ab2 100644 --- a/nufxlib-0/SysDefs.h +++ b/nufxlib-0/SysDefs.h @@ -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 diff --git a/nufxlib-0/Thread.c b/nufxlib-0/Thread.c index 1ed526c..8dc3f9c 100644 --- a/nufxlib-0/Thread.c +++ b/nufxlib-0/Thread.c @@ -12,7 +12,7 @@ /* * =========================================================================== - * Utils + * Utils * =========================================================================== */ @@ -29,14 +29,14 @@ void Nu_StripHiIfAllSet(char* str) { - uchar* cp; + uchar* cp; - for (cp = (uchar*)str; *cp != '\0'; cp++) - if (!(*cp & 0x80)) - return; + for (cp = (uchar*)str; *cp != '\0'; cp++) + if (!(*cp & 0x80)) + return; - for (cp = (uchar*)str; *cp != '\0'; cp++) - *cp &= 0x7f; + for (cp = (uchar*)str; *cp != '\0'; cp++) + *cp &= 0x7f; } @@ -47,10 +47,10 @@ Nu_StripHiIfAllSet(char* str) Boolean Nu_IsPresizedThreadID(NuThreadID threadID) { - if (threadID == kNuThreadIDFilename || threadID == kNuThreadIDComment) - return true; - else - return false; + if (threadID == kNuThreadIDFilename || threadID == kNuThreadIDComment) + return true; + else + return false; } @@ -61,10 +61,10 @@ Nu_IsPresizedThreadID(NuThreadID threadID) Boolean Nu_IsCompressibleThreadID(NuThreadID threadID) { - if (NuThreadIDGetClass(threadID) == kNuThreadClassData) - return true; - else - return false; + if (NuThreadIDGetClass(threadID) == kNuThreadClassData) + return true; + else + return false; } @@ -75,8 +75,8 @@ Nu_IsCompressibleThreadID(NuThreadID threadID) Boolean Nu_ThreadHasCRC(long recordVersion, NuThreadID threadID) { - return recordVersion >= 3 && - NuThreadIDGetClass(threadID) == kNuThreadClassData; + return recordVersion >= 3 && + NuThreadIDGetClass(threadID) == kNuThreadClassData; } @@ -85,22 +85,22 @@ Nu_ThreadHasCRC(long recordVersion, NuThreadID threadID) */ NuError Nu_FindThreadByIdx(const NuRecord* pRecord, NuThreadIdx thread, - NuThread** ppThread) + NuThread** ppThread) { - NuThread* pThread; - int idx; + NuThread* pThread; + int idx; - for (idx = 0; idx < (int)pRecord->recTotalThreads; idx++) { - pThread = Nu_GetThread(pRecord, idx); - Assert(pThread != nil); + for (idx = 0; idx < (int)pRecord->recTotalThreads; idx++) { + pThread = Nu_GetThread(pRecord, idx); + Assert(pThread != nil); - if (pThread->threadIdx == thread) { - *ppThread = pThread; - return kNuErrNone; - } - } + if (pThread->threadIdx == thread) { + *ppThread = pThread; + return kNuErrNone; + } + } - return kNuErrThreadIdxNotFound; + return kNuErrThreadIdxNotFound; } @@ -110,22 +110,22 @@ Nu_FindThreadByIdx(const NuRecord* pRecord, NuThreadIdx thread, */ NuError Nu_FindThreadByID(const NuRecord* pRecord, NuThreadID threadID, - NuThread** ppThread) + NuThread** ppThread) { - NuThread* pThread; - int idx; + NuThread* pThread; + int idx; - for (idx = 0; idx < (int)pRecord->recTotalThreads; idx++) { - pThread = Nu_GetThread(pRecord, idx); - Assert(pThread != nil); + for (idx = 0; idx < (int)pRecord->recTotalThreads; idx++) { + pThread = Nu_GetThread(pRecord, idx); + Assert(pThread != nil); - if (NuGetThreadID(pThread) == threadID) { - *ppThread = pThread; - return kNuErrNone; - } - } + if (NuGetThreadID(pThread) == threadID) { + *ppThread = pThread; + return kNuErrNone; + } + } - return kNuErrThreadIDNotFound; + return kNuErrThreadIDNotFound; } @@ -135,16 +135,16 @@ Nu_FindThreadByID(const NuRecord* pRecord, NuThreadID threadID, void Nu_CopyThreadContents(NuThread* pDstThread, const NuThread* pSrcThread) { - Assert(pDstThread != nil); - Assert(pSrcThread != nil); + Assert(pDstThread != nil); + Assert(pSrcThread != nil); - memcpy(pDstThread, pSrcThread, sizeof(*pDstThread)); + memcpy(pDstThread, pSrcThread, sizeof(*pDstThread)); } /* * =========================================================================== - * Reading threads from the archive + * Reading threads from the archive * =========================================================================== */ @@ -154,26 +154,26 @@ Nu_CopyThreadContents(NuThread* pDstThread, const NuThread* pSrcThread) static NuError Nu_ReadThreadHeader(NuArchive* pArchive, NuThread* pThread, ushort* pCrc) { - FILE* fp; + FILE* fp; - Assert(pArchive != nil); - Assert(pThread != nil); - Assert(pCrc != nil); + Assert(pArchive != nil); + Assert(pThread != nil); + Assert(pCrc != nil); - fp = pArchive->archiveFp; + fp = pArchive->archiveFp; - pThread->thThreadClass = Nu_ReadTwoC(pArchive, fp, pCrc); - pThread->thThreadFormat = Nu_ReadTwoC(pArchive, fp, pCrc); - pThread->thThreadKind = Nu_ReadTwoC(pArchive, fp, pCrc); - pThread->thThreadCRC = Nu_ReadTwoC(pArchive, fp, pCrc); - pThread->thThreadEOF = Nu_ReadFourC(pArchive, fp, pCrc); - pThread->thCompThreadEOF = Nu_ReadFourC(pArchive, fp, pCrc); + pThread->thThreadClass = Nu_ReadTwoC(pArchive, fp, pCrc); + pThread->thThreadFormat = Nu_ReadTwoC(pArchive, fp, pCrc); + pThread->thThreadKind = Nu_ReadTwoC(pArchive, fp, pCrc); + pThread->thThreadCRC = Nu_ReadTwoC(pArchive, fp, pCrc); + pThread->thThreadEOF = Nu_ReadFourC(pArchive, fp, pCrc); + pThread->thCompThreadEOF = Nu_ReadFourC(pArchive, fp, pCrc); - pThread->threadIdx = Nu_GetNextThreadIdx(pArchive); - pThread->actualThreadEOF = 0; /* fix me later */ - pThread->fileOffset = -1; /* mark as invalid */ + pThread->threadIdx = Nu_GetNextThreadIdx(pArchive); + pThread->actualThreadEOF = 0; /* fix me later */ + pThread->fileOffset = -1; /* mark as invalid */ - return Nu_HeaderIOFailed(pArchive, fp); + return Nu_HeaderIOFailed(pArchive, fp); } /* @@ -186,68 +186,68 @@ Nu_ReadThreadHeader(NuArchive* pArchive, NuThread* pThread, ushort* pCrc) NuError Nu_ReadThreadHeaders(NuArchive* pArchive, NuRecord* pRecord, ushort* pCrc) { - NuError err = kNuErrNone; - NuThread* pThread; - long count; + NuError err = kNuErrNone; + NuThread* pThread; + long count; - Assert(pArchive != nil); - Assert(pRecord != nil); - Assert(pCrc != nil); + Assert(pArchive != nil); + Assert(pRecord != nil); + Assert(pCrc != nil); - if (!pRecord->recTotalThreads) { - /* not sure if this is reasonable, but we can handle it */ - DBUG(("--- WEIRD: no threads in the record?\n")); - goto bail; - } + if (!pRecord->recTotalThreads) { + /* not sure if this is reasonable, but we can handle it */ + DBUG(("--- WEIRD: no threads in the record?\n")); + goto bail; + } - pRecord->pThreads = Nu_Malloc(pArchive, - pRecord->recTotalThreads * sizeof(NuThread)); - BailAlloc(pRecord->pThreads); + pRecord->pThreads = Nu_Malloc(pArchive, + pRecord->recTotalThreads * sizeof(NuThread)); + BailAlloc(pRecord->pThreads); - count = pRecord->recTotalThreads; - pThread = pRecord->pThreads; - while (count--) { - err = Nu_ReadThreadHeader(pArchive, pThread, pCrc); - BailError(err); + count = pRecord->recTotalThreads; + pThread = pRecord->pThreads; + while (count--) { + err = Nu_ReadThreadHeader(pArchive, pThread, pCrc); + BailError(err); - /* - * Some versions of ShrinkIt write an invalid thThreadEOF for disks, - * so we have to figure out what it's supposed to be. - */ - if (NuMakeThreadID(pThread->thThreadClass, pThread->thThreadKind) == - kNuThreadIDDiskImage) - { - if (pRecord->recStorageType <= 13) { - /* supposed to be block size, but SHK v3.0.1 stored it wrong */ - pThread->actualThreadEOF = pRecord->recExtraType * 512; + /* + * Some versions of ShrinkIt write an invalid thThreadEOF for disks, + * so we have to figure out what it's supposed to be. + */ + if (NuMakeThreadID(pThread->thThreadClass, pThread->thThreadKind) == + kNuThreadIDDiskImage) + { + if (pRecord->recStorageType <= 13) { + /* supposed to be block size, but SHK v3.0.1 stored it wrong */ + pThread->actualThreadEOF = pRecord->recExtraType * 512; - } else if (pRecord->recStorageType == 256 && - pRecord->recExtraType == 280 && - pRecord->recFileSysID == kNuFileSysDOS33) - { - /* - * Fix for less-common ShrinkIt problem: looks like an old - * version of GS/ShrinkIt used 256 as the block size when - * compressing DOS 3.3 images from 5.25" disks. If that - * appears to be the case here, crank up the block size. - */ - DBUG(("--- no such thing as a 70K disk image!\n")); - pThread->actualThreadEOF = pRecord->recExtraType * 512; + } else if (pRecord->recStorageType == 256 && + pRecord->recExtraType == 280 && + pRecord->recFileSysID == kNuFileSysDOS33) + { + /* + * Fix for less-common ShrinkIt problem: looks like an old + * version of GS/ShrinkIt used 256 as the block size when + * compressing DOS 3.3 images from 5.25" disks. If that + * appears to be the case here, crank up the block size. + */ + DBUG(("--- no such thing as a 70K disk image!\n")); + pThread->actualThreadEOF = pRecord->recExtraType * 512; - } else { - pThread->actualThreadEOF = - pRecord->recExtraType * pRecord->recStorageType; - } - } else { - pThread->actualThreadEOF = pThread->thThreadEOF; - } + } else { + pThread->actualThreadEOF = + pRecord->recExtraType * pRecord->recStorageType; + } + } else { + pThread->actualThreadEOF = pThread->thThreadEOF; + } - pThread->used = false; - pThread++; - } + pThread->used = false; + pThread++; + } bail: - return err; + return err; } @@ -256,21 +256,21 @@ bail: */ static NuError Nu_WriteThreadHeader(NuArchive* pArchive, const NuThread* pThread, FILE* fp, - ushort* pCrc) + ushort* pCrc) { - Assert(pArchive != nil); - Assert(pThread != nil); - Assert(fp != nil); - Assert(pCrc != nil); + Assert(pArchive != nil); + Assert(pThread != nil); + Assert(fp != nil); + Assert(pCrc != nil); - Nu_WriteTwoC(pArchive, fp, pThread->thThreadClass, pCrc); - Nu_WriteTwoC(pArchive, fp, (ushort)pThread->thThreadFormat, pCrc); - Nu_WriteTwoC(pArchive, fp, pThread->thThreadKind, pCrc); - Nu_WriteTwoC(pArchive, fp, pThread->thThreadCRC, pCrc); - Nu_WriteFourC(pArchive, fp, pThread->thThreadEOF, pCrc); - Nu_WriteFourC(pArchive, fp, pThread->thCompThreadEOF, pCrc); + Nu_WriteTwoC(pArchive, fp, pThread->thThreadClass, pCrc); + Nu_WriteTwoC(pArchive, fp, (ushort)pThread->thThreadFormat, pCrc); + Nu_WriteTwoC(pArchive, fp, pThread->thThreadKind, pCrc); + Nu_WriteTwoC(pArchive, fp, pThread->thThreadCRC, pCrc); + Nu_WriteFourC(pArchive, fp, pThread->thThreadEOF, pCrc); + Nu_WriteFourC(pArchive, fp, pThread->thCompThreadEOF, pCrc); - return Nu_HeaderIOFailed(pArchive, fp); + return Nu_HeaderIOFailed(pArchive, fp); } /* @@ -278,22 +278,22 @@ Nu_WriteThreadHeader(NuArchive* pArchive, const NuThread* pThread, FILE* fp, */ NuError Nu_WriteThreadHeaders(NuArchive* pArchive, NuRecord* pRecord, FILE* fp, - ushort* pCrc) + ushort* pCrc) { - NuError err = kNuErrNone; - NuThread* pThread; - int idx; + NuError err = kNuErrNone; + NuThread* pThread; + int idx; - for (idx = 0; idx < (int)pRecord->recTotalThreads; idx++) { - pThread = Nu_GetThread(pRecord, idx); - Assert(pThread != nil); + for (idx = 0; idx < (int)pRecord->recTotalThreads; idx++) { + pThread = Nu_GetThread(pRecord, idx); + Assert(pThread != nil); - err = Nu_WriteThreadHeader(pArchive, pThread, fp, pCrc); - BailError(err); - } + err = Nu_WriteThreadHeader(pArchive, pThread, fp, pCrc); + BailError(err); + } bail: - return err; + return err; } @@ -308,30 +308,30 @@ bail: NuError Nu_ComputeThreadData(NuArchive* pArchive, NuRecord* pRecord) { - NuThread* pThread; - long fileOffset, count; + NuThread* pThread; + long fileOffset, count; - Assert(pArchive != nil); - Assert(pRecord != nil); + Assert(pArchive != nil); + Assert(pRecord != nil); - /*pRecord->totalLength = 0;*/ - pRecord->totalCompLength = 0; + /*pRecord->totalLength = 0;*/ + pRecord->totalCompLength = 0; - fileOffset = pArchive->currentOffset; + fileOffset = pArchive->currentOffset; - count = pRecord->recTotalThreads; - pThread = pRecord->pThreads; - while (count--) { - pThread->fileOffset = fileOffset; + count = pRecord->recTotalThreads; + pThread = pRecord->pThreads; + while (count--) { + pThread->fileOffset = fileOffset; - /*pRecord->totalLength += pThread->thThreadEOF;*/ - pRecord->totalCompLength += pThread->thCompThreadEOF; - fileOffset += pThread->thCompThreadEOF; + /*pRecord->totalLength += pThread->thThreadEOF;*/ + pRecord->totalCompLength += pThread->thCompThreadEOF; + fileOffset += pThread->thCompThreadEOF; - pThread++; - } + pThread++; + } - return kNuErrNone; + return kNuErrNone; } @@ -349,80 +349,80 @@ Nu_ComputeThreadData(NuArchive* pArchive, NuRecord* pRecord) NuError Nu_ScanThreads(NuArchive* pArchive, NuRecord* pRecord, long numThreads) { - NuError err = kNuErrNone; - NuThread* pThread; - FILE* fp; + NuError err = kNuErrNone; + NuThread* pThread; + FILE* fp; - Assert(pArchive != nil); - Assert(pRecord != nil); + Assert(pArchive != nil); + Assert(pRecord != nil); - fp = pArchive->archiveFp; + fp = pArchive->archiveFp; - Assert(numThreads <= (long)pRecord->recTotalThreads); + Assert(numThreads <= (long)pRecord->recTotalThreads); - pThread = pRecord->pThreads; - while (numThreads--) { - if (pRecord->threadFilename == nil && - NuMakeThreadID(pThread->thThreadClass, pThread->thThreadKind) == - kNuThreadIDFilename) - { - /* it's the first filename thread, read the whole thing */ - if (pThread->thCompThreadEOF > kNuReasonableFilenameLen) { - err = kNuErrBadRecord; - Nu_ReportError(NU_BLOB, err, "Bad thread filename len (%lu)", - pThread->thCompThreadEOF); - goto bail; - } - pRecord->threadFilename = Nu_Malloc(pArchive, - pThread->thCompThreadEOF +1); - BailAlloc(pRecord->threadFilename); + pThread = pRecord->pThreads; + while (numThreads--) { + if (pRecord->threadFilename == nil && + NuMakeThreadID(pThread->thThreadClass, pThread->thThreadKind) == + kNuThreadIDFilename) + { + /* it's the first filename thread, read the whole thing */ + if (pThread->thCompThreadEOF > kNuReasonableFilenameLen) { + err = kNuErrBadRecord; + Nu_ReportError(NU_BLOB, err, "Bad thread filename len (%lu)", + pThread->thCompThreadEOF); + goto bail; + } + pRecord->threadFilename = Nu_Malloc(pArchive, + pThread->thCompThreadEOF +1); + BailAlloc(pRecord->threadFilename); - /* note there is no CRC on a filename thread */ - (void) Nu_ReadBytes(pArchive, fp, pRecord->threadFilename, - pThread->thCompThreadEOF); - if ((err = Nu_HeaderIOFailed(pArchive, fp)) != kNuErrNone) { - Nu_ReportError(NU_BLOB, err, "Failed reading filename thread"); - goto bail; - } + /* note there is no CRC on a filename thread */ + (void) Nu_ReadBytes(pArchive, fp, pRecord->threadFilename, + pThread->thCompThreadEOF); + if ((err = Nu_HeaderIOFailed(pArchive, fp)) != kNuErrNone) { + Nu_ReportError(NU_BLOB, err, "Failed reading filename thread"); + goto bail; + } - /* null-terminate on the actual len, not the buffer len */ - pRecord->threadFilename[pThread->thThreadEOF] = '\0'; + /* null-terminate on the actual len, not the buffer len */ + pRecord->threadFilename[pThread->thThreadEOF] = '\0'; - Nu_StripHiIfAllSet(pRecord->threadFilename); + Nu_StripHiIfAllSet(pRecord->threadFilename); - /* prefer this one over the record one, but only one should exist */ - if (pRecord->filename != nil) { - DBUG(("--- HEY: got record filename and thread filename\n")); - } - pRecord->filename = pRecord->threadFilename; + /* prefer this one over the record one, but only one should exist */ + if (pRecord->filename != nil) { + DBUG(("--- HEY: got record filename and thread filename\n")); + } + pRecord->filename = pRecord->threadFilename; - } else { - /* not a filename (or not first filename), skip past it */ - err = Nu_SeekArchive(pArchive, pArchive->archiveFp, - pThread->thCompThreadEOF, SEEK_CUR); - BailError(err); - } + } else { + /* not a filename (or not first filename), skip past it */ + err = Nu_SeekArchive(pArchive, pArchive->archiveFp, + pThread->thCompThreadEOF, SEEK_CUR); + BailError(err); + } - pThread++; - } + pThread++; + } - /* - * Should've had one by now. Supposedly, older versions of ShrinkIt - * wouldn't prompt for a disk image name on DOS 3.3 volumes, so you'd - * end up with a disk image that had no name attached. This will tend - * to confuse things, so we go ahead and give it a name. - */ - if (pRecord->filename == nil) - pRecord->filename = kNuDefaultRecordName; + /* + * Should've had one by now. Supposedly, older versions of ShrinkIt + * wouldn't prompt for a disk image name on DOS 3.3 volumes, so you'd + * end up with a disk image that had no name attached. This will tend + * to confuse things, so we go ahead and give it a name. + */ + if (pRecord->filename == nil) + pRecord->filename = kNuDefaultRecordName; - pArchive->currentOffset += pRecord->totalCompLength; + pArchive->currentOffset += pRecord->totalCompLength; - if (!Nu_IsStreaming(pArchive)) { - Assert(pArchive->currentOffset == ftell(pArchive->archiveFp)); - } + if (!Nu_IsStreaming(pArchive)) { + Assert(pArchive->currentOffset == ftell(pArchive->archiveFp)); + } bail: - return err; + return err; } @@ -433,23 +433,23 @@ bail: */ NuError Nu_SkipThread(NuArchive* pArchive, const NuRecord* pRecord, - const NuThread* pThread) + const NuThread* pThread) { - NuError err; + NuError err; - if (!Nu_IsStreaming(pArchive)) /* for debugging */ - return kNuErrNone; /* for debugging */ - Assert(Nu_IsStreaming(pArchive)); + if (!Nu_IsStreaming(pArchive)) /* for debugging */ + return kNuErrNone; /* for debugging */ + Assert(Nu_IsStreaming(pArchive)); - err = Nu_SeekArchive(pArchive, pArchive->archiveFp, - pThread->thCompThreadEOF, SEEK_CUR); - return err; + err = Nu_SeekArchive(pArchive, pArchive->archiveFp, + pThread->thCompThreadEOF, SEEK_CUR); + return err; } /* * =========================================================================== - * Extract + * Extract * =========================================================================== */ @@ -461,43 +461,43 @@ Nu_SkipThread(NuArchive* pArchive, const NuRecord* pRecord, */ static NuError Nu_ExtractThreadToDataSink(NuArchive* pArchive, const NuRecord* pRecord, - const NuThread* pThread, NuProgressData* pProgress, NuDataSink* pDataSink) + const NuThread* pThread, NuProgressData* pProgress, NuDataSink* pDataSink) { - NuError err; - NuFunnel* pFunnel = nil; + NuError err; + NuFunnel* pFunnel = nil; - /* if it's not a stream, seek to the appropriate spot in the file */ - if (!Nu_IsStreaming(pArchive)) { - err = Nu_SeekArchive(pArchive, pArchive->archiveFp, - pThread->fileOffset, SEEK_SET); - if (err != kNuErrNone) { - Nu_ReportError(NU_BLOB, err, "Unable to seek input to %ld", - pThread->fileOffset); - goto bail; - } - } + /* if it's not a stream, seek to the appropriate spot in the file */ + if (!Nu_IsStreaming(pArchive)) { + err = Nu_SeekArchive(pArchive, pArchive->archiveFp, + pThread->fileOffset, SEEK_SET); + if (err != kNuErrNone) { + Nu_ReportError(NU_BLOB, err, "Unable to seek input to %ld", + pThread->fileOffset); + goto bail; + } + } - /* - * Set up an output funnel to write to. - */ - err = Nu_FunnelNew(pArchive, pDataSink, Nu_DataSinkGetConvertEOL(pDataSink), - pArchive->valEOL, pProgress, &pFunnel); - BailError(err); + /* + * Set up an output funnel to write to. + */ + err = Nu_FunnelNew(pArchive, pDataSink, Nu_DataSinkGetConvertEOL(pDataSink), + pArchive->valEOL, pProgress, &pFunnel); + BailError(err); - /* - * Write it. - */ - err = Nu_ExpandStream(pArchive, pRecord, pThread, pArchive->archiveFp, - pFunnel); - if (err != kNuErrNone) { - if (err != kNuErrSkipped && err != kNuErrAborted) - Nu_ReportError(NU_BLOB, err, "ExpandStream failed"); - goto bail; - } + /* + * Write it. + */ + err = Nu_ExpandStream(pArchive, pRecord, pThread, pArchive->archiveFp, + pFunnel); + if (err != kNuErrNone) { + if (err != kNuErrSkipped && err != kNuErrAborted) + Nu_ReportError(NU_BLOB, err, "ExpandStream failed"); + goto bail; + } bail: - (void) Nu_FunnelFree(pArchive, pFunnel); - return err; + (void) Nu_FunnelFree(pArchive, pFunnel); + return err; } @@ -515,204 +515,204 @@ bail: */ static NuError Nu_ExtractThreadCommon(NuArchive* pArchive, const NuRecord* pRecord, - const NuThread* pThread, NuDataSink* pDataSink) + const NuThread* pThread, NuDataSink* pDataSink) { - NuError err = kNuErrNone; - NuSelectionProposal selProposal; - NuPathnameProposal pathProposal; - NuProgressData progressData; - NuProgressData* pProgressData; - NuDataSink* pOrigDataSink; - char* newPathStorage = nil; - const char* newPathname; - NuResult result; - uchar newFssep; - Boolean doFreeSink = false; + NuError err = kNuErrNone; + NuSelectionProposal selProposal; + NuPathnameProposal pathProposal; + NuProgressData progressData; + NuProgressData* pProgressData; + NuDataSink* pOrigDataSink; + char* newPathStorage = nil; + const char* newPathname; + NuResult result; + uchar newFssep; + Boolean doFreeSink = false; - Assert(pRecord != nil); - Assert(pThread != nil); - Assert(pDataSink != nil); + Assert(pRecord != nil); + Assert(pThread != nil); + Assert(pDataSink != nil); - memset(&progressData, 0, sizeof(progressData)); - pProgressData = nil; + memset(&progressData, 0, sizeof(progressData)); + pProgressData = nil; - /* - * If we're just trying to verify the archive contents, create a - * data sink that goes nowhere at all. - */ - if (pArchive->testMode) { - err = Nu_DataSinkVoid_New( - Nu_DataSinkGetDoExpand(pDataSink), - Nu_DataSinkGetConvertEOL(pDataSink), - &pDataSink); - BailError(err); - doFreeSink = true; - } + /* + * If we're just trying to verify the archive contents, create a + * data sink that goes nowhere at all. + */ + if (pArchive->testMode) { + err = Nu_DataSinkVoid_New( + Nu_DataSinkGetDoExpand(pDataSink), + Nu_DataSinkGetConvertEOL(pDataSink), + &pDataSink); + BailError(err); + doFreeSink = true; + } - pOrigDataSink = pDataSink; /* save a copy for the "retry" loop */ + pOrigDataSink = pDataSink; /* save a copy for the "retry" loop */ - /* - * Decide if we want to extract this thread. This is mostly for - * use by the "bulk" extract, not the per-thread extract, but it - * still applies if they so desire. - */ - if (pArchive->selectionFilterFunc != nil) { - selProposal.pRecord = pRecord; - selProposal.pThread = pThread; - result = (*pArchive->selectionFilterFunc)(pArchive, &selProposal); + /* + * Decide if we want to extract this thread. This is mostly for + * use by the "bulk" extract, not the per-thread extract, but it + * still applies if they so desire. + */ + if (pArchive->selectionFilterFunc != nil) { + selProposal.pRecord = pRecord; + selProposal.pThread = pThread; + result = (*pArchive->selectionFilterFunc)(pArchive, &selProposal); - if (result == kNuSkip) - return Nu_SkipThread(pArchive, pRecord, pThread); - if (result == kNuAbort) { - err = kNuErrAborted; - goto bail; - } - } + if (result == kNuSkip) + return Nu_SkipThread(pArchive, pRecord, pThread); + if (result == kNuAbort) { + err = kNuErrAborted; + goto bail; + } + } - newPathname = nil; - newFssep = 0; + newPathname = nil; + newFssep = 0; retry_name: - if (Nu_DataSinkGetType(pDataSink) == kNuDataSinkToFile) { - /* - * We're extracting. Figure out the name of the file to write it to. - * If they want to use the sleazy FILE* back door, create a new - * data sink and use that instead. - * - * Start by resetting everything to defaults, in case this isn't - * our first time through the "rename" loop. - */ - newPathname = Nu_DataSinkFile_GetPathname(pDataSink); - newFssep = Nu_DataSinkFile_GetFssep(pDataSink); - pDataSink = pOrigDataSink; + if (Nu_DataSinkGetType(pDataSink) == kNuDataSinkToFile) { + /* + * We're extracting. Figure out the name of the file to write it to. + * If they want to use the sleazy FILE* back door, create a new + * data sink and use that instead. + * + * Start by resetting everything to defaults, in case this isn't + * our first time through the "rename" loop. + */ + newPathname = Nu_DataSinkFile_GetPathname(pDataSink); + newFssep = Nu_DataSinkFile_GetFssep(pDataSink); + pDataSink = pOrigDataSink; - /* if they don't have a pathname func defined, we just use default */ - if (pArchive->outputPathnameFunc != nil) { - pathProposal.pathname = pRecord->filename; - pathProposal.filenameSeparator = - NuGetSepFromSysInfo(pRecord->recFileSysInfo); - pathProposal.pRecord = pRecord; - pathProposal.pThread = pThread; - pathProposal.newPathname = nil; - pathProposal.newFilenameSeparator = '\0'; - /*pathProposal.newStorage = (NuThreadID)-1;*/ - pathProposal.newDataSink = nil; + /* if they don't have a pathname func defined, we just use default */ + if (pArchive->outputPathnameFunc != nil) { + pathProposal.pathname = pRecord->filename; + pathProposal.filenameSeparator = + NuGetSepFromSysInfo(pRecord->recFileSysInfo); + pathProposal.pRecord = pRecord; + pathProposal.pThread = pThread; + pathProposal.newPathname = nil; + pathProposal.newFilenameSeparator = '\0'; + /*pathProposal.newStorage = (NuThreadID)-1;*/ + pathProposal.newDataSink = nil; - result = (*pArchive->outputPathnameFunc)(pArchive, &pathProposal); + result = (*pArchive->outputPathnameFunc)(pArchive, &pathProposal); - if (result == kNuSkip) - return Nu_SkipThread(pArchive, pRecord, pThread); - if (result == kNuAbort) { - err = kNuErrAborted; - goto bail; - } + if (result == kNuSkip) + return Nu_SkipThread(pArchive, pRecord, pThread); + if (result == kNuAbort) { + err = kNuErrAborted; + goto bail; + } - /* we don't own this string, so make a copy */ - if (pathProposal.newPathname != nil) { - newPathStorage = strdup(pathProposal.newPathname); - newPathname = newPathStorage; - } else - newPathname = nil; - if (pathProposal.newFilenameSeparator != '\0') - newFssep = pathProposal.newFilenameSeparator; + /* we don't own this string, so make a copy */ + if (pathProposal.newPathname != nil) { + newPathStorage = strdup(pathProposal.newPathname); + newPathname = newPathStorage; + } else + newPathname = nil; + if (pathProposal.newFilenameSeparator != '\0') + newFssep = pathProposal.newFilenameSeparator; - /* if they want to send this somewhere else, let them */ - if (pathProposal.newDataSink != nil) - pDataSink = pathProposal.newDataSink; - } + /* if they want to send this somewhere else, let them */ + if (pathProposal.newDataSink != nil) + pDataSink = pathProposal.newDataSink; + } - /* at least one of these must be set */ - Assert(!(newPathname == nil && pathProposal.newDataSink == nil)); - } + /* at least one of these must be set */ + Assert(!(newPathname == nil && pathProposal.newDataSink == nil)); + } - /* - * Prepare the progress data if this is a data thread. - */ - if (newPathname == nil) { - /* using a data sink; get the pathname out of the record */ - newPathname = pRecord->filename; - newFssep = NuGetSepFromSysInfo(pRecord->recFileSysInfo); - } - if (pThread->thThreadClass == kNuThreadClassData) { - pProgressData = &progressData; - err = Nu_ProgressDataInit_Expand(pArchive, pProgressData, pRecord, - newPathname, newFssep, Nu_DataSinkGetConvertEOL(pOrigDataSink)); - BailError(err); + /* + * Prepare the progress data if this is a data thread. + */ + if (newPathname == nil) { + /* using a data sink; get the pathname out of the record */ + newPathname = pRecord->filename; + newFssep = NuGetSepFromSysInfo(pRecord->recFileSysInfo); + } + if (pThread->thThreadClass == kNuThreadClassData) { + pProgressData = &progressData; + err = Nu_ProgressDataInit_Expand(pArchive, pProgressData, pRecord, + newPathname, newFssep, Nu_DataSinkGetConvertEOL(pOrigDataSink)); + BailError(err); - /* send initial progress so they see the right name if "open" fails */ - pProgressData->state = kNuProgressOpening; - err = Nu_SendInitialProgress(pArchive, pProgressData); - BailError(err); - } + /* send initial progress so they see the right name if "open" fails */ + pProgressData->state = kNuProgressOpening; + err = Nu_SendInitialProgress(pArchive, pProgressData); + BailError(err); + } - if (Nu_DataSinkGetType(pDataSink) == kNuDataSinkToFile) { - /* - * We're extracting to a file. Open it, creating it if necessary and - * allowed. - */ - FILE* fileFp = nil; + if (Nu_DataSinkGetType(pDataSink) == kNuDataSinkToFile) { + /* + * We're extracting to a file. Open it, creating it if necessary and + * allowed. + */ + FILE* fileFp = nil; - err = Nu_OpenOutputFile(pArchive, pRecord, pThread, newPathname, - newFssep, &fileFp); - if (err == kNuErrRename) { - /* they want to rename; the OutputPathname callback handles this */ - Nu_Free(pArchive, newPathStorage); - newPathStorage = nil; - /* reset these just to be careful */ - newPathname = nil; - fileFp = nil; - goto retry_name; - } else if (err != kNuErrNone) { - goto bail; - } + err = Nu_OpenOutputFile(pArchive, pRecord, pThread, newPathname, + newFssep, &fileFp); + if (err == kNuErrRename) { + /* they want to rename; the OutputPathname callback handles this */ + Nu_Free(pArchive, newPathStorage); + newPathStorage = nil; + /* reset these just to be careful */ + newPathname = nil; + fileFp = nil; + goto retry_name; + } else if (err != kNuErrNone) { + goto bail; + } - Assert(fileFp != nil); - (void) Nu_DataSinkFile_SetFP(pDataSink, fileFp); + Assert(fileFp != nil); + (void) Nu_DataSinkFile_SetFP(pDataSink, fileFp); - DBUG(("+++ EXTRACTING 0x%08lx from '%s' at offset %0ld to '%s'\n", - NuMakeThreadID(pThread->thThreadClass, pThread->thThreadKind), - pRecord->filename, pThread->fileOffset, newPathname)); - } else { - DBUG(("+++ EXTRACTING 0x%08lx from '%s' at offset %0ld to sink\n", - NuMakeThreadID(pThread->thThreadClass, pThread->thThreadKind), - pRecord->filename, pThread->fileOffset)); - } + DBUG(("+++ EXTRACTING 0x%08lx from '%s' at offset %0ld to '%s'\n", + NuMakeThreadID(pThread->thThreadClass, pThread->thThreadKind), + pRecord->filename, pThread->fileOffset, newPathname)); + } else { + DBUG(("+++ EXTRACTING 0x%08lx from '%s' at offset %0ld to sink\n", + NuMakeThreadID(pThread->thThreadClass, pThread->thThreadKind), + pRecord->filename, pThread->fileOffset)); + } - /* extract to the file */ - err = Nu_ExtractThreadToDataSink(pArchive, pRecord, pThread, - pProgressData, pDataSink); - BailError(err); + /* extract to the file */ + err = Nu_ExtractThreadToDataSink(pArchive, pRecord, pThread, + pProgressData, pDataSink); + BailError(err); - if (Nu_DataSinkGetType(pDataSink) == kNuDataSinkToFile) { - /* - * Close the file, adjusting the modification date and access - * permissions as appropriate. - */ - err = Nu_CloseOutputFile(pArchive, pRecord, - Nu_DataSinkFile_GetFP(pDataSink), newPathname); - Nu_DataSinkFile_SetFP(pDataSink, nil); - BailError(err); - } + if (Nu_DataSinkGetType(pDataSink) == kNuDataSinkToFile) { + /* + * Close the file, adjusting the modification date and access + * permissions as appropriate. + */ + err = Nu_CloseOutputFile(pArchive, pRecord, + Nu_DataSinkFile_GetFP(pDataSink), newPathname); + Nu_DataSinkFile_SetFP(pDataSink, nil); + BailError(err); + } bail: - if (err != kNuErrNone) { - /* send a final progress message, indicating failure */ - if (err == kNuErrSkipped) - pProgressData->state = kNuProgressSkipped; - else - pProgressData->state = kNuProgressFailed; - (void) Nu_SendInitialProgress(pArchive, pProgressData); - } + if (err != kNuErrNone) { + /* send a final progress message, indicating failure */ + if (err == kNuErrSkipped) + pProgressData->state = kNuProgressSkipped; + else + pProgressData->state = kNuProgressFailed; + (void) Nu_SendInitialProgress(pArchive, pProgressData); + } - /* if this was an ordinary file, and it's still open, close it */ - if (Nu_DataSinkGetType(pDataSink) == kNuDataSinkToFile) - Nu_DataSinkFile_Close(pDataSink); + /* if this was an ordinary file, and it's still open, close it */ + if (Nu_DataSinkGetType(pDataSink) == kNuDataSinkToFile) + Nu_DataSinkFile_Close(pDataSink); - Nu_Free(pArchive, newPathStorage); + Nu_Free(pArchive, newPathStorage); - if (doFreeSink) - Nu_DataSinkFree(pDataSink); - return err; + if (doFreeSink) + Nu_DataSinkFree(pDataSink); + return err; } /* @@ -722,33 +722,33 @@ bail: */ NuError Nu_ExtractThreadBulk(NuArchive* pArchive, const NuRecord* pRecord, - const NuThread* pThread) + const NuThread* pThread) { - NuError err; - NuDataSink* pDataSink = nil; + NuError err; + NuDataSink* pDataSink = nil; - /* - * Create a file data sink for the file. We use whatever EOL conversion - * is set as the default for the entire archive. (If you want to - * specify your own EOL conversion for each individual file, you will - * need to extract them individually, creating a data sink for each.) - */ - err = Nu_DataSinkFile_New(true, pArchive->valConvertExtractedEOL, - pRecord->filename, NuGetSepFromSysInfo(pRecord->recFileSysInfo), - &pDataSink); - BailError(err); + /* + * Create a file data sink for the file. We use whatever EOL conversion + * is set as the default for the entire archive. (If you want to + * specify your own EOL conversion for each individual file, you will + * need to extract them individually, creating a data sink for each.) + */ + err = Nu_DataSinkFile_New(true, pArchive->valConvertExtractedEOL, + pRecord->filename, NuGetSepFromSysInfo(pRecord->recFileSysInfo), + &pDataSink); + BailError(err); - err = Nu_ExtractThreadCommon(pArchive, pRecord, pThread, pDataSink); - BailError(err); + err = Nu_ExtractThreadCommon(pArchive, pRecord, pThread, pDataSink); + BailError(err); bail: - if (pDataSink != nil) { - NuError err2 = Nu_DataSinkFree(pDataSink); - if (err == kNuErrNone) - err = err2; - } + if (pDataSink != nil) { + NuError err2 = Nu_DataSinkFree(pDataSink); + if (err == kNuErrNone) + err = err2; + } - return err; + return err; } @@ -757,35 +757,35 @@ bail: */ NuError Nu_ExtractThread(NuArchive* pArchive, NuThreadIdx threadIdx, - NuDataSink* pDataSink) + NuDataSink* pDataSink) { - NuError err; - NuRecord* pRecord; - NuThread* pThread; + NuError err; + NuRecord* pRecord; + NuThread* pThread; - if (Nu_IsStreaming(pArchive)) - return kNuErrUsage; - if (threadIdx == 0 || pDataSink == nil) - return kNuErrInvalidArg; + if (Nu_IsStreaming(pArchive)) + return kNuErrUsage; + if (threadIdx == 0 || pDataSink == nil) + return kNuErrInvalidArg; - /* find the correct record and thread by index */ - err = Nu_RecordSet_FindByThreadIdx(&pArchive->origRecordSet, threadIdx, - &pRecord, &pThread); - BailError(err); - Assert(pRecord != nil); + /* find the correct record and thread by index */ + err = Nu_RecordSet_FindByThreadIdx(&pArchive->origRecordSet, threadIdx, + &pRecord, &pThread); + BailError(err); + Assert(pRecord != nil); - /* extract away */ - err = Nu_ExtractThreadCommon(pArchive, pRecord, pThread, pDataSink); - BailError(err); + /* extract away */ + err = Nu_ExtractThreadCommon(pArchive, pRecord, pThread, pDataSink); + BailError(err); bail: - return err; + return err; } /* * =========================================================================== - * Add/update/delete + * Add/update/delete * =========================================================================== */ @@ -800,54 +800,54 @@ bail: */ static NuError Nu_FindNoFutureThread(NuArchive* pArchive, const NuRecord* pRecord, - NuThreadID threadID) + NuThreadID threadID) { - NuError err = kNuErrNone; - const NuThread* pThread; - const NuThreadMod* pThreadMod; - int idx; + NuError err = kNuErrNone; + const NuThread* pThread; + const NuThreadMod* pThreadMod; + int idx; - /* - * Start by scanning the existing threads (if any). - */ - for (idx = 0; idx < (int)pRecord->recTotalThreads; idx++) { - pThread = Nu_GetThread(pRecord, idx); - Assert(pThread != nil); + /* + * Start by scanning the existing threads (if any). + */ + for (idx = 0; idx < (int)pRecord->recTotalThreads; idx++) { + pThread = Nu_GetThread(pRecord, idx); + Assert(pThread != nil); - if (NuGetThreadID(pThread) == threadID) { - /* found a match, see if it has been deleted */ - pThreadMod = Nu_ThreadMod_FindByThreadIdx(pRecord, - pThread->threadIdx); - if (pThreadMod != nil && - pThreadMod->entry.kind == kNuThreadModDelete) - { - /* it's deleted, ignore it */ - continue; - } - DBUG(("--- found existing thread matching 0x%08lx\n", threadID)); - err = kNuErrThreadAdd; - goto bail; - } - } + if (NuGetThreadID(pThread) == threadID) { + /* found a match, see if it has been deleted */ + pThreadMod = Nu_ThreadMod_FindByThreadIdx(pRecord, + pThread->threadIdx); + if (pThreadMod != nil && + pThreadMod->entry.kind == kNuThreadModDelete) + { + /* it's deleted, ignore it */ + continue; + } + DBUG(("--- found existing thread matching 0x%08lx\n", threadID)); + err = kNuErrThreadAdd; + goto bail; + } + } - /* - * Now look for "add" threadMods with a matching threadID. - */ - pThreadMod = pRecord->pThreadMods; - while (pThreadMod != nil) { - if (pThreadMod->entry.kind == kNuThreadModAdd && - pThreadMod->entry.add.threadID == threadID) - { - DBUG(("--- found 'add' threadMod matching 0x%08lx\n", threadID)); - err = kNuErrThreadAdd; - goto bail; - } + /* + * Now look for "add" threadMods with a matching threadID. + */ + pThreadMod = pRecord->pThreadMods; + while (pThreadMod != nil) { + if (pThreadMod->entry.kind == kNuThreadModAdd && + pThreadMod->entry.add.threadID == threadID) + { + DBUG(("--- found 'add' threadMod matching 0x%08lx\n", threadID)); + err = kNuErrThreadAdd; + goto bail; + } - pThreadMod = pThreadMod->pNext; - } + pThreadMod = pThreadMod->pNext; + } bail: - return err; + return err; } /* @@ -855,54 +855,54 @@ bail: */ static NuError Nu_FindNoFutureThreadClass(NuArchive* pArchive, const NuRecord* pRecord, - long threadClass) + long threadClass) { - NuError err = kNuErrNone; - const NuThread* pThread; - const NuThreadMod* pThreadMod; - int idx; + NuError err = kNuErrNone; + const NuThread* pThread; + const NuThreadMod* pThreadMod; + int idx; - /* - * Start by scanning the existing threads (if any). - */ - for (idx = 0; idx < (int)pRecord->recTotalThreads; idx++) { - pThread = Nu_GetThread(pRecord, idx); - Assert(pThread != nil); + /* + * Start by scanning the existing threads (if any). + */ + for (idx = 0; idx < (int)pRecord->recTotalThreads; idx++) { + pThread = Nu_GetThread(pRecord, idx); + Assert(pThread != nil); - if (pThread->thThreadClass == threadClass) { - /* found a match, see if it has been deleted */ - pThreadMod = Nu_ThreadMod_FindByThreadIdx(pRecord, - pThread->threadIdx); - if (pThreadMod != nil && - pThreadMod->entry.kind == kNuThreadModDelete) - { - /* it's deleted, ignore it */ - continue; - } - DBUG(("--- Found existing thread matching 0x%04lx\n", threadClass)); - err = kNuErrThreadAdd; - goto bail; - } - } + if (pThread->thThreadClass == threadClass) { + /* found a match, see if it has been deleted */ + pThreadMod = Nu_ThreadMod_FindByThreadIdx(pRecord, + pThread->threadIdx); + if (pThreadMod != nil && + pThreadMod->entry.kind == kNuThreadModDelete) + { + /* it's deleted, ignore it */ + continue; + } + DBUG(("--- Found existing thread matching 0x%04lx\n", threadClass)); + err = kNuErrThreadAdd; + goto bail; + } + } - /* - * Now look for "add" threadMods with a matching threadClass. - */ - pThreadMod = pRecord->pThreadMods; - while (pThreadMod != nil) { - if (pThreadMod->entry.kind == kNuThreadModAdd && - NuThreadIDGetClass(pThreadMod->entry.add.threadID) == threadClass) - { - DBUG(("--- Found 'add' threadMod matching 0x%04lx\n", threadClass)); - err = kNuErrThreadAdd; - goto bail; - } + /* + * Now look for "add" threadMods with a matching threadClass. + */ + pThreadMod = pRecord->pThreadMods; + while (pThreadMod != nil) { + if (pThreadMod->entry.kind == kNuThreadModAdd && + NuThreadIDGetClass(pThreadMod->entry.add.threadID) == threadClass) + { + DBUG(("--- Found 'add' threadMod matching 0x%04lx\n", threadClass)); + err = kNuErrThreadAdd; + goto bail; + } - pThreadMod = pThreadMod->pNext; - } + pThreadMod = pThreadMod->pNext; + } bail: - return err; + return err; } @@ -916,37 +916,37 @@ bail: */ static NuError Nu_FindThreadForWriteByIdx(NuArchive* pArchive, NuThreadIdx threadIdx, - NuRecord** ppFoundRecord, NuThread** ppFoundThread) + NuRecord** ppFoundRecord, NuThread** ppFoundThread) { - NuError err; + NuError err; - if (Nu_RecordSet_GetLoaded(&pArchive->copyRecordSet)) { - err = Nu_RecordSet_FindByThreadIdx(&pArchive->copyRecordSet, threadIdx, - ppFoundRecord, ppFoundThread); - } else { - Assert(Nu_RecordSet_GetLoaded(&pArchive->origRecordSet)); - err = Nu_RecordSet_FindByThreadIdx(&pArchive->origRecordSet, threadIdx, - ppFoundRecord, ppFoundThread); - *ppFoundThread = nil; /* can't delete from here, wipe ptr */ - } - BailError(err); + if (Nu_RecordSet_GetLoaded(&pArchive->copyRecordSet)) { + err = Nu_RecordSet_FindByThreadIdx(&pArchive->copyRecordSet, threadIdx, + ppFoundRecord, ppFoundThread); + } else { + Assert(Nu_RecordSet_GetLoaded(&pArchive->origRecordSet)); + err = Nu_RecordSet_FindByThreadIdx(&pArchive->origRecordSet, threadIdx, + ppFoundRecord, ppFoundThread); + *ppFoundThread = nil; /* can't delete from here, wipe ptr */ + } + BailError(err); - /* - * The thread exists. If we were looking in the "orig" set, we have - * to create a "copy" set, and delete it from that. - */ - if (*ppFoundThread == nil) { - err = Nu_RecordSet_Clone(pArchive, &pArchive->copyRecordSet, - &pArchive->origRecordSet); - BailError(err); - err = Nu_RecordSet_FindByThreadIdx(&pArchive->copyRecordSet, threadIdx, - ppFoundRecord, ppFoundThread); - Assert(err == kNuErrNone && *ppFoundThread != nil); /* must succeed */ - BailError(err); - } + /* + * The thread exists. If we were looking in the "orig" set, we have + * to create a "copy" set, and delete it from that. + */ + if (*ppFoundThread == nil) { + err = Nu_RecordSet_Clone(pArchive, &pArchive->copyRecordSet, + &pArchive->origRecordSet); + BailError(err); + err = Nu_RecordSet_FindByThreadIdx(&pArchive->copyRecordSet, threadIdx, + ppFoundRecord, ppFoundThread); + Assert(err == kNuErrNone && *ppFoundThread != nil); /* must succeed */ + BailError(err); + } bail: - return err; + return err; } /* @@ -957,50 +957,50 @@ bail: */ NuError Nu_OkayToAddThread(NuArchive* pArchive, const NuRecord* pRecord, - NuThreadID threadID) + NuThreadID threadID) { - NuError err = kNuErrNone; + NuError err = kNuErrNone; - /* - * Check for class conflicts (can't mix data and control threads). - */ - if (NuThreadIDGetClass(threadID) == kNuThreadClassData) { - err = Nu_FindNoFutureThreadClass(pArchive, pRecord, - kNuThreadClassControl); - BailError(err); - } else if (NuThreadIDGetClass(threadID) == kNuThreadClassControl) { - err = Nu_FindNoFutureThreadClass(pArchive, pRecord, - kNuThreadClassData); - BailError(err); - } + /* + * Check for class conflicts (can't mix data and control threads). + */ + if (NuThreadIDGetClass(threadID) == kNuThreadClassData) { + err = Nu_FindNoFutureThreadClass(pArchive, pRecord, + kNuThreadClassControl); + BailError(err); + } else if (NuThreadIDGetClass(threadID) == kNuThreadClassControl) { + err = Nu_FindNoFutureThreadClass(pArchive, pRecord, + kNuThreadClassData); + BailError(err); + } - /* - * Check for specific type conflicts. - */ - if (threadID == kNuThreadIDDataFork) { - err = Nu_FindNoFutureThread(pArchive, pRecord, kNuThreadIDDataFork); - BailError(err); - err = Nu_FindNoFutureThread(pArchive, pRecord, kNuThreadIDDiskImage); - BailError(err); - } else if (threadID == kNuThreadIDRsrcFork) { - err = Nu_FindNoFutureThread(pArchive, pRecord, kNuThreadIDRsrcFork); - BailError(err); - err = Nu_FindNoFutureThread(pArchive, pRecord, kNuThreadIDDiskImage); - BailError(err); - } else if (threadID == kNuThreadIDDiskImage) { - err = Nu_FindNoFutureThread(pArchive, pRecord, kNuThreadIDDataFork); - BailError(err); - err = Nu_FindNoFutureThread(pArchive, pRecord, kNuThreadIDRsrcFork); - BailError(err); - err = Nu_FindNoFutureThread(pArchive, pRecord, kNuThreadIDDiskImage); - BailError(err); - } else if (threadID == kNuThreadIDFilename) { - err = Nu_FindNoFutureThread(pArchive, pRecord, kNuThreadIDFilename); - BailError(err); - } + /* + * Check for specific type conflicts. + */ + if (threadID == kNuThreadIDDataFork) { + err = Nu_FindNoFutureThread(pArchive, pRecord, kNuThreadIDDataFork); + BailError(err); + err = Nu_FindNoFutureThread(pArchive, pRecord, kNuThreadIDDiskImage); + BailError(err); + } else if (threadID == kNuThreadIDRsrcFork) { + err = Nu_FindNoFutureThread(pArchive, pRecord, kNuThreadIDRsrcFork); + BailError(err); + err = Nu_FindNoFutureThread(pArchive, pRecord, kNuThreadIDDiskImage); + BailError(err); + } else if (threadID == kNuThreadIDDiskImage) { + err = Nu_FindNoFutureThread(pArchive, pRecord, kNuThreadIDDataFork); + BailError(err); + err = Nu_FindNoFutureThread(pArchive, pRecord, kNuThreadIDRsrcFork); + BailError(err); + err = Nu_FindNoFutureThread(pArchive, pRecord, kNuThreadIDDiskImage); + BailError(err); + } else if (threadID == kNuThreadIDFilename) { + err = Nu_FindNoFutureThread(pArchive, pRecord, kNuThreadIDFilename); + BailError(err); + } bail: - return err; + return err; } @@ -1022,85 +1022,85 @@ bail: */ NuError Nu_AddThread(NuArchive* pArchive, NuRecordIdx recIdx, NuThreadID threadID, - NuDataSource* pDataSource, NuThreadIdx* pThreadIdx) + NuDataSource* pDataSource, NuThreadIdx* pThreadIdx) { - NuError err; - NuRecord* pRecord; - NuThreadMod* pThreadMod = nil; - NuThreadFormat threadFormat; + NuError err; + NuRecord* pRecord; + NuThreadMod* pThreadMod = nil; + NuThreadFormat threadFormat; - /* okay for pThreadIdx to be nil */ - if (recIdx == 0 || pDataSource == nil) - return kNuErrInvalidArg; + /* okay for pThreadIdx to be nil */ + if (recIdx == 0 || pDataSource == nil) + return kNuErrInvalidArg; - if (Nu_IsReadOnly(pArchive)) - return kNuErrArchiveRO; - err = Nu_GetTOCIfNeeded(pArchive); - BailError(err); + if (Nu_IsReadOnly(pArchive)) + return kNuErrArchiveRO; + err = Nu_GetTOCIfNeeded(pArchive); + BailError(err); - /* - * Find the record. If it doesn't exist in the copy set, check to - * see if it's in the "new" set. - */ - err = Nu_FindRecordForWriteByIdx(pArchive, recIdx, &pRecord); - if (err == kNuErrRecIdxNotFound && - Nu_RecordSet_GetLoaded(&pArchive->newRecordSet)) - { - err = Nu_RecordSet_FindByIdx(&pArchive->newRecordSet, recIdx, &pRecord); - } - BailError(err); - Assert(pRecord != nil); + /* + * Find the record. If it doesn't exist in the copy set, check to + * see if it's in the "new" set. + */ + err = Nu_FindRecordForWriteByIdx(pArchive, recIdx, &pRecord); + if (err == kNuErrRecIdxNotFound && + Nu_RecordSet_GetLoaded(&pArchive->newRecordSet)) + { + err = Nu_RecordSet_FindByIdx(&pArchive->newRecordSet, recIdx, &pRecord); + } + BailError(err); + Assert(pRecord != nil); - /* - * Do some tests, looking for specific types of threads that conflict - * with what we're trying to add. - */ - err = Nu_OkayToAddThread(pArchive, pRecord, threadID); - BailError(err); + /* + * Do some tests, looking for specific types of threads that conflict + * with what we're trying to add. + */ + err = Nu_OkayToAddThread(pArchive, pRecord, threadID); + BailError(err); - /* - * Decide if we want to compress the data from this source. If the - * data is already compressed (as indicated by the data source) or - * this type of thread isn't compressible (e.g. it's a filename), then - * we don't compress it. Otherwise, we use whatever compression mode - * is currently configured. - */ - if (Nu_DataSourceGetThreadFormat(pDataSource) == kNuThreadFormatUncompressed && - Nu_IsCompressibleThreadID(threadID)) - { - threadFormat = Nu_ConvertCompressValToFormat(pArchive, - pArchive->valDataCompression); - } else { - threadFormat = kNuThreadFormatUncompressed; - } - DBUG(("--- using threadFormat = %d\n", threadFormat)); + /* + * Decide if we want to compress the data from this source. If the + * data is already compressed (as indicated by the data source) or + * this type of thread isn't compressible (e.g. it's a filename), then + * we don't compress it. Otherwise, we use whatever compression mode + * is currently configured. + */ + if (Nu_DataSourceGetThreadFormat(pDataSource) == kNuThreadFormatUncompressed && + Nu_IsCompressibleThreadID(threadID)) + { + threadFormat = Nu_ConvertCompressValToFormat(pArchive, + pArchive->valDataCompression); + } else { + threadFormat = kNuThreadFormatUncompressed; + } + DBUG(("--- using threadFormat = %d\n", threadFormat)); - /* create a new ThreadMod */ - err = Nu_ThreadModAdd_New(pArchive, threadID, threadFormat, pDataSource, - &pThreadMod); - BailError(err); - Assert(pThreadMod != nil); + /* create a new ThreadMod */ + err = Nu_ThreadModAdd_New(pArchive, threadID, threadFormat, pDataSource, + &pThreadMod); + BailError(err); + Assert(pThreadMod != nil); - /* add the thread mod to the record */ - Nu_RecordAddThreadMod(pRecord, pThreadMod); - if (pThreadIdx != nil) - *pThreadIdx = pThreadMod->entry.add.threadIdx; - pThreadMod = nil; /* successful, don't free */ + /* add the thread mod to the record */ + Nu_RecordAddThreadMod(pRecord, pThreadMod); + if (pThreadIdx != nil) + *pThreadIdx = pThreadMod->entry.add.threadIdx; + pThreadMod = nil; /* successful, don't free */ - /* - * If we've got a header filename and we're adding a filename thread, - * we don't want to write the record header name when we reconstruct - * the record. - */ - if (threadID == kNuThreadIDFilename && pRecord->recFilenameLength) { - DBUG(("+++ gonna drop the filename\n")); - pRecord->dropRecFilename = true; - } + /* + * If we've got a header filename and we're adding a filename thread, + * we don't want to write the record header name when we reconstruct + * the record. + */ + if (threadID == kNuThreadIDFilename && pRecord->recFilenameLength) { + DBUG(("+++ gonna drop the filename\n")); + pRecord->dropRecFilename = true; + } bail: - if (pThreadMod != nil) - Nu_ThreadModFree(pArchive, pThreadMod); - return err; + if (pThreadMod != nil) + Nu_ThreadModFree(pArchive, pThreadMod); + return err; } @@ -1117,120 +1117,120 @@ bail: */ NuError Nu_UpdatePresizedThread(NuArchive* pArchive, NuThreadIdx threadIdx, - NuDataSource* pDataSource, long* pMaxLen) + NuDataSource* pDataSource, long* pMaxLen) { - NuError err; - NuThreadMod* pThreadMod = nil; - NuRecord* pFoundRecord; - NuThread* pFoundThread; + NuError err; + NuThreadMod* pThreadMod = nil; + NuRecord* pFoundRecord; + NuThread* pFoundThread; - if (pDataSource == nil) { - err = kNuErrInvalidArg; - goto bail; - } + if (pDataSource == nil) { + err = kNuErrInvalidArg; + goto bail; + } - /* presized threads always contain uncompressed data */ - if (Nu_DataSourceGetThreadFormat(pDataSource) != - kNuThreadFormatUncompressed) - { - err = kNuErrBadFormat; - Nu_ReportError(NU_BLOB, err, - "presized threads can't hold compressed data"); - goto bail; - } + /* presized threads always contain uncompressed data */ + if (Nu_DataSourceGetThreadFormat(pDataSource) != + kNuThreadFormatUncompressed) + { + err = kNuErrBadFormat; + Nu_ReportError(NU_BLOB, err, + "presized threads can't hold compressed data"); + goto bail; + } - if (Nu_IsReadOnly(pArchive)) - return kNuErrArchiveRO; - err = Nu_GetTOCIfNeeded(pArchive); - BailError(err); + if (Nu_IsReadOnly(pArchive)) + return kNuErrArchiveRO; + err = Nu_GetTOCIfNeeded(pArchive); + BailError(err); - /* - * Find the thread in the "copy" set. (If there isn't a copy set, - * make one.) - */ - err = Nu_FindThreadForWriteByIdx(pArchive, threadIdx, &pFoundRecord, - &pFoundThread); - BailError(err); + /* + * Find the thread in the "copy" set. (If there isn't a copy set, + * make one.) + */ + err = Nu_FindThreadForWriteByIdx(pArchive, threadIdx, &pFoundRecord, + &pFoundThread); + BailError(err); - if (!Nu_IsPresizedThreadID(NuGetThreadID(pFoundThread)) || - !(pFoundThread->thCompThreadEOF >= pFoundThread->thThreadEOF)) - { - err = kNuErrNotPreSized; - Nu_ReportError(NU_BLOB, err, "invalid thread for update"); - goto bail; - } + if (!Nu_IsPresizedThreadID(NuGetThreadID(pFoundThread)) || + !(pFoundThread->thCompThreadEOF >= pFoundThread->thThreadEOF)) + { + err = kNuErrNotPreSized; + Nu_ReportError(NU_BLOB, err, "invalid thread for update"); + goto bail; + } - if (pMaxLen != nil) - *pMaxLen = pFoundThread->thCompThreadEOF; + if (pMaxLen != nil) + *pMaxLen = pFoundThread->thCompThreadEOF; - /* - * Check to see if somebody is trying to delete this, or has already - * updated it. - */ - if (Nu_ThreadMod_FindByThreadIdx(pFoundRecord, threadIdx) != nil) { - DBUG(("--- Tried to modify a deleted or modified thread\n")); - err = kNuErrModThreadChange; - goto bail; - } + /* + * Check to see if somebody is trying to delete this, or has already + * updated it. + */ + if (Nu_ThreadMod_FindByThreadIdx(pFoundRecord, threadIdx) != nil) { + DBUG(("--- Tried to modify a deleted or modified thread\n")); + err = kNuErrModThreadChange; + goto bail; + } - /* - * Verify that "otherLen" in the data source is less than or equal - * to our len, if we can. If the data source is a file on disk, - * we're not really supposed to look at it until we flush. We - * could sneak a peek right now, which would prevent us from aborting - * the entire operation when it turns out the file won't fit, but - * that violates our semantics (and besides, the application really - * should've done that already). - * - * If the data source is from a file, we just assume it'll fit and - * let the chips fall where they may later on. - */ - if (Nu_DataSourceGetType(pDataSource) != kNuDataSourceFromFile) { - if (pFoundThread->thCompThreadEOF < - Nu_DataSourceGetOtherLen(pDataSource)) - { - err = kNuErrPreSizeOverflow; - Nu_ReportError(NU_BLOB, err, "can't put %ld bytes into %ld", - Nu_DataSourceGetOtherLen(pDataSource), - pFoundThread->thCompThreadEOF); - goto bail; - } + /* + * Verify that "otherLen" in the data source is less than or equal + * to our len, if we can. If the data source is a file on disk, + * we're not really supposed to look at it until we flush. We + * could sneak a peek right now, which would prevent us from aborting + * the entire operation when it turns out the file won't fit, but + * that violates our semantics (and besides, the application really + * should've done that already). + * + * If the data source is from a file, we just assume it'll fit and + * let the chips fall where they may later on. + */ + if (Nu_DataSourceGetType(pDataSource) != kNuDataSourceFromFile) { + if (pFoundThread->thCompThreadEOF < + Nu_DataSourceGetOtherLen(pDataSource)) + { + err = kNuErrPreSizeOverflow; + Nu_ReportError(NU_BLOB, err, "can't put %ld bytes into %ld", + Nu_DataSourceGetOtherLen(pDataSource), + pFoundThread->thCompThreadEOF); + goto bail; + } - /* check for zero-length and excessively long filenames */ - if (NuGetThreadID(pFoundThread) == kNuThreadIDFilename && - (Nu_DataSourceGetOtherLen(pDataSource) == 0 || - Nu_DataSourceGetOtherLen(pDataSource) > kNuReasonableFilenameLen)) - { - err = kNuErrInvalidFilename; - Nu_ReportError(NU_BLOB, err, "invalid filename (%ld bytes)", - Nu_DataSourceGetOtherLen(pDataSource)); - goto bail; - } - } + /* check for zero-length and excessively long filenames */ + if (NuGetThreadID(pFoundThread) == kNuThreadIDFilename && + (Nu_DataSourceGetOtherLen(pDataSource) == 0 || + Nu_DataSourceGetOtherLen(pDataSource) > kNuReasonableFilenameLen)) + { + err = kNuErrInvalidFilename; + Nu_ReportError(NU_BLOB, err, "invalid filename (%ld bytes)", + Nu_DataSourceGetOtherLen(pDataSource)); + goto bail; + } + } - /* - * Looks like it'll fit, and it's the right kind of data. Create - * an "update" threadMod. Note this copies the data source. - */ - Assert(pFoundThread->thThreadFormat == kNuThreadFormatUncompressed); - err = Nu_ThreadModUpdate_New(pArchive, threadIdx, pDataSource, &pThreadMod); - BailError(err); - Assert(pThreadMod != nil); + /* + * Looks like it'll fit, and it's the right kind of data. Create + * an "update" threadMod. Note this copies the data source. + */ + Assert(pFoundThread->thThreadFormat == kNuThreadFormatUncompressed); + err = Nu_ThreadModUpdate_New(pArchive, threadIdx, pDataSource, &pThreadMod); + BailError(err); + Assert(pThreadMod != nil); - /* add the thread mod to the record */ - Nu_RecordAddThreadMod(pFoundRecord, pThreadMod); + /* add the thread mod to the record */ + Nu_RecordAddThreadMod(pFoundRecord, pThreadMod); - /* - * NOTE: changes to filename threads will be picked up later and - * incorporated into the record's threadFilename. We don't worry - * about the record header filename, because we might be doing an - * update-in-place and that prevents us from removing the filename - * (doing so would change the size of the archive). No need to - * do any filename-specific changes here. - */ + /* + * NOTE: changes to filename threads will be picked up later and + * incorporated into the record's threadFilename. We don't worry + * about the record header filename, because we might be doing an + * update-in-place and that prevents us from removing the filename + * (doing so would change the size of the archive). No need to + * do any filename-specific changes here. + */ bail: - return err; + return err; } /* @@ -1246,46 +1246,46 @@ bail: NuError Nu_DeleteThread(NuArchive* pArchive, NuThreadIdx threadIdx) { - NuError err; - NuThreadMod* pThreadMod = nil; - NuRecord* pFoundRecord; - NuThread* pFoundThread; + NuError err; + NuThreadMod* pThreadMod = nil; + NuRecord* pFoundRecord; + NuThread* pFoundThread; - if (Nu_IsReadOnly(pArchive)) - return kNuErrArchiveRO; - err = Nu_GetTOCIfNeeded(pArchive); - BailError(err); + if (Nu_IsReadOnly(pArchive)) + return kNuErrArchiveRO; + err = Nu_GetTOCIfNeeded(pArchive); + BailError(err); - /* - * Find the thread in the "copy" set. (If there isn't a copy set, - * make one.) - */ - err = Nu_FindThreadForWriteByIdx(pArchive, threadIdx, &pFoundRecord, - &pFoundThread); - BailError(err); + /* + * Find the thread in the "copy" set. (If there isn't a copy set, + * make one.) + */ + err = Nu_FindThreadForWriteByIdx(pArchive, threadIdx, &pFoundRecord, + &pFoundThread); + BailError(err); - /* - * Deletion of modified threads (updates or previous deletes) isn't - * allowed. Deletion of threads from deleted records can't happen, - * because deleted records are completely removed from the "copy" set. - */ - if (Nu_ThreadMod_FindByThreadIdx(pFoundRecord, threadIdx) != nil) { - DBUG(("--- Tried to delete a deleted or modified thread\n")); - err = kNuErrModThreadChange; - goto bail; - } + /* + * Deletion of modified threads (updates or previous deletes) isn't + * allowed. Deletion of threads from deleted records can't happen, + * because deleted records are completely removed from the "copy" set. + */ + if (Nu_ThreadMod_FindByThreadIdx(pFoundRecord, threadIdx) != nil) { + DBUG(("--- Tried to delete a deleted or modified thread\n")); + err = kNuErrModThreadChange; + goto bail; + } - /* - * Looks good. Add a new "delete" ThreadMod to the list. - */ - err = Nu_ThreadModDelete_New(pArchive, threadIdx, - NuGetThreadID(pFoundThread), &pThreadMod); - BailError(err); - Nu_RecordAddThreadMod(pFoundRecord, pThreadMod); - pThreadMod = nil; /* successful, don't free */ + /* + * Looks good. Add a new "delete" ThreadMod to the list. + */ + err = Nu_ThreadModDelete_New(pArchive, threadIdx, + NuGetThreadID(pFoundThread), &pThreadMod); + BailError(err); + Nu_RecordAddThreadMod(pFoundRecord, pThreadMod); + pThreadMod = nil; /* successful, don't free */ bail: - Nu_ThreadModFree(pArchive, pThreadMod); - return err; + Nu_ThreadModFree(pArchive, pThreadMod); + return err; } diff --git a/nufxlib-0/Value.c b/nufxlib-0/Value.c index c6999d9..7d4b9ad 100644 --- a/nufxlib-0/Value.c +++ b/nufxlib-0/Value.c @@ -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; } diff --git a/nufxlib-0/Version.c.in b/nufxlib-0/Version.c.in index d8266cb..9f40a7d 100644 --- a/nufxlib-0/Version.c.in +++ b/nufxlib-0/Version.c.in @@ -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; } diff --git a/nufxlib-0/configure.in b/nufxlib-0/configure.in index 18da94b..308b2ea 100644 --- a/nufxlib-0/configure.in +++ b/nufxlib-0/configure.in @@ -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 - 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 + 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)