mirror of
https://github.com/fadden/nulib2.git
synced 2025-01-14 01:29:43 +00:00
Change "nil" to "NULL"
This commit is contained in:
parent
cf433eeae0
commit
ce1b57e2ad
@ -56,7 +56,7 @@ static void Nu_CloseAndFree(NuArchive* pArchive);
|
|||||||
static NuError
|
static NuError
|
||||||
Nu_NuArchiveNew(NuArchive** ppArchive)
|
Nu_NuArchiveNew(NuArchive** ppArchive)
|
||||||
{
|
{
|
||||||
Assert(ppArchive != nil);
|
Assert(ppArchive != NULL);
|
||||||
|
|
||||||
/* validate some assumptions we make throughout the code */
|
/* validate some assumptions we make throughout the code */
|
||||||
Assert(sizeof(int) >= 2);
|
Assert(sizeof(int) >= 2);
|
||||||
@ -64,8 +64,8 @@ Nu_NuArchiveNew(NuArchive** ppArchive)
|
|||||||
Assert(sizeof(ulong) >= 4);
|
Assert(sizeof(ulong) >= 4);
|
||||||
Assert(sizeof(void*) >= sizeof(NuArchive*));
|
Assert(sizeof(void*) >= sizeof(NuArchive*));
|
||||||
|
|
||||||
*ppArchive = Nu_Calloc(nil, sizeof(**ppArchive));
|
*ppArchive = Nu_Calloc(NULL, sizeof(**ppArchive));
|
||||||
if (*ppArchive == nil)
|
if (*ppArchive == NULL)
|
||||||
return kNuErrMalloc;
|
return kNuErrMalloc;
|
||||||
|
|
||||||
(*ppArchive)->structMagic = kNuArchiveStructMagic;
|
(*ppArchive)->structMagic = kNuArchiveStructMagic;
|
||||||
@ -110,7 +110,7 @@ Nu_NuArchiveNew(NuArchive** ppArchive)
|
|||||||
static NuError
|
static NuError
|
||||||
Nu_NuArchiveFree(NuArchive* pArchive)
|
Nu_NuArchiveFree(NuArchive* pArchive)
|
||||||
{
|
{
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pArchive->structMagic == kNuArchiveStructMagic);
|
Assert(pArchive->structMagic == kNuArchiveStructMagic);
|
||||||
|
|
||||||
(void) Nu_RecordSet_FreeAllRecords(pArchive, &pArchive->origRecordSet);
|
(void) Nu_RecordSet_FreeAllRecords(pArchive, &pArchive->origRecordSet);
|
||||||
@ -118,15 +118,15 @@ Nu_NuArchiveFree(NuArchive* pArchive)
|
|||||||
(void) Nu_RecordSet_FreeAllRecords(pArchive, &pArchive->copyRecordSet);
|
(void) Nu_RecordSet_FreeAllRecords(pArchive, &pArchive->copyRecordSet);
|
||||||
(void) Nu_RecordSet_FreeAllRecords(pArchive, &pArchive->newRecordSet);
|
(void) Nu_RecordSet_FreeAllRecords(pArchive, &pArchive->newRecordSet);
|
||||||
|
|
||||||
Nu_Free(nil, pArchive->archivePathname);
|
Nu_Free(NULL, pArchive->archivePathname);
|
||||||
Nu_Free(nil, pArchive->tmpPathname);
|
Nu_Free(NULL, pArchive->tmpPathname);
|
||||||
Nu_Free(nil, pArchive->compBuf);
|
Nu_Free(NULL, pArchive->compBuf);
|
||||||
Nu_Free(nil, pArchive->lzwCompressState);
|
Nu_Free(NULL, pArchive->lzwCompressState);
|
||||||
Nu_Free(nil, pArchive->lzwExpandState);
|
Nu_Free(NULL, pArchive->lzwExpandState);
|
||||||
|
|
||||||
/* mark it as deceased to prevent further use, then free it */
|
/* mark it as deceased to prevent further use, then free it */
|
||||||
pArchive->structMagic = kNuArchiveStructMagic ^ 0xffffffff;
|
pArchive->structMagic = kNuArchiveStructMagic ^ 0xffffffff;
|
||||||
Nu_Free(nil, pArchive);
|
Nu_Free(NULL, pArchive);
|
||||||
|
|
||||||
return kNuErrNone;
|
return kNuErrNone;
|
||||||
}
|
}
|
||||||
@ -139,9 +139,9 @@ void
|
|||||||
Nu_MasterHeaderCopy(NuArchive* pArchive, NuMasterHeader* pDstHeader,
|
Nu_MasterHeaderCopy(NuArchive* pArchive, NuMasterHeader* pDstHeader,
|
||||||
const NuMasterHeader* pSrcHeader)
|
const NuMasterHeader* pSrcHeader)
|
||||||
{
|
{
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pDstHeader != nil);
|
Assert(pDstHeader != NULL);
|
||||||
Assert(pSrcHeader != nil);
|
Assert(pSrcHeader != NULL);
|
||||||
|
|
||||||
*pDstHeader = *pSrcHeader;
|
*pDstHeader = *pSrcHeader;
|
||||||
}
|
}
|
||||||
@ -152,7 +152,7 @@ Nu_MasterHeaderCopy(NuArchive* pArchive, NuMasterHeader* pDstHeader,
|
|||||||
NuError
|
NuError
|
||||||
Nu_GetMasterHeader(NuArchive* pArchive, const NuMasterHeader** ppMasterHeader)
|
Nu_GetMasterHeader(NuArchive* pArchive, const NuMasterHeader** ppMasterHeader)
|
||||||
{
|
{
|
||||||
if (ppMasterHeader == nil)
|
if (ppMasterHeader == NULL)
|
||||||
return kNuErrInvalidArg;
|
return kNuErrInvalidArg;
|
||||||
|
|
||||||
*ppMasterHeader = &pArchive->masterHeader;
|
*ppMasterHeader = &pArchive->masterHeader;
|
||||||
@ -167,13 +167,13 @@ Nu_GetMasterHeader(NuArchive* pArchive, const NuMasterHeader** ppMasterHeader)
|
|||||||
NuError
|
NuError
|
||||||
Nu_AllocCompressionBufferIFN(NuArchive* pArchive)
|
Nu_AllocCompressionBufferIFN(NuArchive* pArchive)
|
||||||
{
|
{
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
|
|
||||||
if (pArchive->compBuf != nil)
|
if (pArchive->compBuf != NULL)
|
||||||
return kNuErrNone;
|
return kNuErrNone;
|
||||||
|
|
||||||
pArchive->compBuf = Nu_Malloc(pArchive, kNuGenCompBufSize);
|
pArchive->compBuf = Nu_Malloc(pArchive, kNuGenCompBufSize);
|
||||||
if (pArchive->compBuf == nil)
|
if (pArchive->compBuf == NULL)
|
||||||
return kNuErrMalloc;
|
return kNuErrMalloc;
|
||||||
|
|
||||||
return kNuErrNone;
|
return kNuErrNone;
|
||||||
@ -505,7 +505,7 @@ Nu_ReadMasterHeader(NuArchive* pArchive)
|
|||||||
Boolean isBinary2 = false;
|
Boolean isBinary2 = false;
|
||||||
Boolean isSea = false;
|
Boolean isSea = false;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
|
|
||||||
fp = pArchive->archiveFp; /* saves typing */
|
fp = pArchive->archiveFp; /* saves typing */
|
||||||
pHeader = &pArchive->masterHeader;
|
pHeader = &pArchive->masterHeader;
|
||||||
@ -640,7 +640,7 @@ retry:
|
|||||||
|
|
||||||
/* compare the CRC */
|
/* compare the CRC */
|
||||||
if (!pArchive->valIgnoreCRC && crc != pHeader->mhMasterCRC) {
|
if (!pArchive->valIgnoreCRC && crc != pHeader->mhMasterCRC) {
|
||||||
if (!Nu_ShouldIgnoreBadCRC(pArchive, nil, kNuErrBadMHCRC)) {
|
if (!Nu_ShouldIgnoreBadCRC(pArchive, NULL, kNuErrBadMHCRC)) {
|
||||||
err = kNuErrBadMHCRC;
|
err = kNuErrBadMHCRC;
|
||||||
Nu_ReportError(NU_BLOB, err, "Stored MH CRC=0x%04x, calc=0x%04x",
|
Nu_ReportError(NU_BLOB, err, "Stored MH CRC=0x%04x, calc=0x%04x",
|
||||||
pHeader->mhMasterCRC, crc);
|
pHeader->mhMasterCRC, crc);
|
||||||
@ -717,7 +717,7 @@ Nu_InitNewArchive(NuArchive* pArchive)
|
|||||||
{
|
{
|
||||||
NuMasterHeader* pHeader;
|
NuMasterHeader* pHeader;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
|
|
||||||
pHeader = &pArchive->masterHeader;
|
pHeader = &pArchive->masterHeader;
|
||||||
|
|
||||||
@ -745,10 +745,10 @@ NuError
|
|||||||
Nu_StreamOpenRO(FILE* infp, NuArchive** ppArchive)
|
Nu_StreamOpenRO(FILE* infp, NuArchive** ppArchive)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
NuArchive* pArchive = nil;
|
NuArchive* pArchive = NULL;
|
||||||
|
|
||||||
Assert(infp != nil);
|
Assert(infp != NULL);
|
||||||
Assert(ppArchive != nil);
|
Assert(ppArchive != NULL);
|
||||||
|
|
||||||
err = Nu_NuArchiveNew(ppArchive);
|
err = Nu_NuArchiveNew(ppArchive);
|
||||||
if (err != kNuErrNone)
|
if (err != kNuErrNone)
|
||||||
@ -764,9 +764,9 @@ Nu_StreamOpenRO(FILE* infp, NuArchive** ppArchive)
|
|||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
if (pArchive != nil)
|
if (pArchive != NULL)
|
||||||
(void) Nu_NuArchiveFree(pArchive);
|
(void) Nu_NuArchiveFree(pArchive);
|
||||||
*ppArchive = nil;
|
*ppArchive = NULL;
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -779,16 +779,16 @@ NuError
|
|||||||
Nu_OpenRO(const char* archivePathname, NuArchive** ppArchive)
|
Nu_OpenRO(const char* archivePathname, NuArchive** ppArchive)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
NuArchive* pArchive = nil;
|
NuArchive* pArchive = NULL;
|
||||||
FILE* fp = nil;
|
FILE* fp = NULL;
|
||||||
|
|
||||||
if (archivePathname == nil || !strlen(archivePathname) || ppArchive == nil)
|
if (archivePathname == NULL || !strlen(archivePathname) || ppArchive == NULL)
|
||||||
return kNuErrInvalidArg;
|
return kNuErrInvalidArg;
|
||||||
|
|
||||||
*ppArchive = nil;
|
*ppArchive = NULL;
|
||||||
|
|
||||||
fp = fopen(archivePathname, kNuFileOpenReadOnly);
|
fp = fopen(archivePathname, kNuFileOpenReadOnly);
|
||||||
if (fp == nil) {
|
if (fp == NULL) {
|
||||||
Nu_ReportError(NU_BLOB, errno, "Unable to open '%s'", archivePathname);
|
Nu_ReportError(NU_BLOB, errno, "Unable to open '%s'", archivePathname);
|
||||||
err = kNuErrFileOpen;
|
err = kNuErrFileOpen;
|
||||||
goto bail;
|
goto bail;
|
||||||
@ -801,7 +801,7 @@ Nu_OpenRO(const char* archivePathname, NuArchive** ppArchive)
|
|||||||
|
|
||||||
pArchive->openMode = kNuOpenRO;
|
pArchive->openMode = kNuOpenRO;
|
||||||
pArchive->archiveFp = fp;
|
pArchive->archiveFp = fp;
|
||||||
fp = nil;
|
fp = NULL;
|
||||||
pArchive->archivePathname = strdup(archivePathname);
|
pArchive->archivePathname = strdup(archivePathname);
|
||||||
|
|
||||||
err = Nu_ReadMasterHeader(pArchive);
|
err = Nu_ReadMasterHeader(pArchive);
|
||||||
@ -809,11 +809,11 @@ Nu_OpenRO(const char* archivePathname, NuArchive** ppArchive)
|
|||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
if (pArchive != nil) {
|
if (pArchive != NULL) {
|
||||||
(void) Nu_CloseAndFree(pArchive);
|
(void) Nu_CloseAndFree(pArchive);
|
||||||
*ppArchive = nil;
|
*ppArchive = NULL;
|
||||||
}
|
}
|
||||||
if (fp != nil)
|
if (fp != NULL)
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
@ -830,7 +830,7 @@ bail:
|
|||||||
static NuError
|
static NuError
|
||||||
Nu_OpenTempFile(char* fileName, FILE** pFp)
|
Nu_OpenTempFile(char* fileName, FILE** pFp)
|
||||||
{
|
{
|
||||||
NuArchive* pArchive = nil; /* dummy for NU_BLOB */
|
NuArchive* pArchive = NULL; /* dummy for NU_BLOB */
|
||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
@ -861,7 +861,7 @@ Nu_OpenTempFile(char* fileName, FILE** pFp)
|
|||||||
|
|
||||||
DBUG(("--- Fd-opening temp file '%s'\n", fileName));
|
DBUG(("--- Fd-opening temp file '%s'\n", fileName));
|
||||||
*pFp = fdopen(fd, kNuFileOpenReadWriteCreat);
|
*pFp = fdopen(fd, kNuFileOpenReadWriteCreat);
|
||||||
if (*pFp == nil) {
|
if (*pFp == NULL) {
|
||||||
close(fd);
|
close(fd);
|
||||||
err = errno ? errno : kNuErrFileOpen;
|
err = errno ? errno : kNuErrFileOpen;
|
||||||
goto bail;
|
goto bail;
|
||||||
@ -875,7 +875,7 @@ Nu_OpenTempFile(char* fileName, FILE** pFp)
|
|||||||
|
|
||||||
DBUG(("+++ Using mktemp\n"));
|
DBUG(("+++ Using mktemp\n"));
|
||||||
result = mktemp(fileName);
|
result = mktemp(fileName);
|
||||||
if (result == nil) {
|
if (result == NULL) {
|
||||||
Nu_ReportError(NU_BLOB, kNuErrNone, "mktemp failed on '%s'",
|
Nu_ReportError(NU_BLOB, kNuErrNone, "mktemp failed on '%s'",
|
||||||
fileName);
|
fileName);
|
||||||
err = kNuErrInternal;
|
err = kNuErrInternal;
|
||||||
@ -899,7 +899,7 @@ Nu_OpenTempFile(char* fileName, FILE** pFp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
*pFp = fdopen(fd, kNuFileOpenReadWriteCreat);
|
*pFp = fdopen(fd, kNuFileOpenReadWriteCreat);
|
||||||
if (*pFp == nil) {
|
if (*pFp == NULL) {
|
||||||
close(fd);
|
close(fd);
|
||||||
err = errno ? errno : kNuErrFileOpen;
|
err = errno ? errno : kNuErrFileOpen;
|
||||||
goto bail;
|
goto bail;
|
||||||
@ -913,7 +913,7 @@ Nu_OpenTempFile(char* fileName, FILE** pFp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
*pFp = fopen(fileName, kNuFileOpenReadWriteCreat);
|
*pFp = fopen(fileName, kNuFileOpenReadWriteCreat);
|
||||||
if (*pFp == nil) {
|
if (*pFp == NULL) {
|
||||||
err = errno ? errno : kNuErrFileOpen;
|
err = errno ? errno : kNuErrFileOpen;
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
@ -933,15 +933,15 @@ Nu_OpenRW(const char* archivePathname, const char* tmpPathname, ulong flags,
|
|||||||
NuArchive** ppArchive)
|
NuArchive** ppArchive)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
FILE* fp = nil;
|
FILE* fp = NULL;
|
||||||
FILE* tmpFp = nil;
|
FILE* tmpFp = NULL;
|
||||||
NuArchive* pArchive = nil;
|
NuArchive* pArchive = NULL;
|
||||||
char* tmpPathDup = nil;
|
char* tmpPathDup = NULL;
|
||||||
Boolean archiveExists;
|
Boolean archiveExists;
|
||||||
Boolean newlyCreated;
|
Boolean newlyCreated;
|
||||||
|
|
||||||
if (archivePathname == nil || !strlen(archivePathname) ||
|
if (archivePathname == NULL || !strlen(archivePathname) ||
|
||||||
tmpPathname == nil || !strlen(tmpPathname) || ppArchive == nil ||
|
tmpPathname == NULL || !strlen(tmpPathname) || ppArchive == NULL ||
|
||||||
(flags & ~(kNuOpenCreat|kNuOpenExcl)) != 0)
|
(flags & ~(kNuOpenCreat|kNuOpenExcl)) != 0)
|
||||||
{
|
{
|
||||||
return kNuErrInvalidArg;
|
return kNuErrInvalidArg;
|
||||||
@ -970,7 +970,7 @@ Nu_OpenRW(const char* archivePathname, const char* tmpPathname, ulong flags,
|
|||||||
newlyCreated = true;
|
newlyCreated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fp == nil) {
|
if (fp == NULL) {
|
||||||
if (errno == EACCES)
|
if (errno == EACCES)
|
||||||
err = kNuErrFileAccessDenied;
|
err = kNuErrFileAccessDenied;
|
||||||
else
|
else
|
||||||
@ -985,7 +985,7 @@ Nu_OpenRW(const char* archivePathname, const char* tmpPathname, ulong flags,
|
|||||||
if (archiveExists && !newlyCreated) {
|
if (archiveExists && !newlyCreated) {
|
||||||
long length;
|
long length;
|
||||||
|
|
||||||
err = Nu_GetFileLength(nil, fp, &length);
|
err = Nu_GetFileLength(NULL, fp, &length);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
|
|
||||||
if (!length) {
|
if (!length) {
|
||||||
@ -1021,11 +1021,11 @@ Nu_OpenRW(const char* archivePathname, const char* tmpPathname, ulong flags,
|
|||||||
pArchive->newlyCreated = newlyCreated;
|
pArchive->newlyCreated = newlyCreated;
|
||||||
pArchive->archivePathname = strdup(archivePathname);
|
pArchive->archivePathname = strdup(archivePathname);
|
||||||
pArchive->archiveFp = fp;
|
pArchive->archiveFp = fp;
|
||||||
fp = nil;
|
fp = NULL;
|
||||||
pArchive->tmpFp = tmpFp;
|
pArchive->tmpFp = tmpFp;
|
||||||
tmpFp = nil;
|
tmpFp = NULL;
|
||||||
pArchive->tmpPathname = tmpPathDup;
|
pArchive->tmpPathname = tmpPathDup;
|
||||||
tmpPathDup = nil;
|
tmpPathDup = NULL;
|
||||||
|
|
||||||
if (archiveExists && !newlyCreated) {
|
if (archiveExists && !newlyCreated) {
|
||||||
err = Nu_ReadMasterHeader(pArchive);
|
err = Nu_ReadMasterHeader(pArchive);
|
||||||
@ -1036,15 +1036,15 @@ Nu_OpenRW(const char* archivePathname, const char* tmpPathname, ulong flags,
|
|||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
if (pArchive != nil) {
|
if (pArchive != NULL) {
|
||||||
(void) Nu_CloseAndFree(pArchive);
|
(void) Nu_CloseAndFree(pArchive);
|
||||||
*ppArchive = nil;
|
*ppArchive = NULL;
|
||||||
}
|
}
|
||||||
if (fp != nil)
|
if (fp != NULL)
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
if (tmpFp != nil)
|
if (tmpFp != NULL)
|
||||||
fclose(tmpFp);
|
fclose(tmpFp);
|
||||||
if (tmpPathDup != nil)
|
if (tmpPathDup != NULL)
|
||||||
Nu_Free(pArchive, tmpPathDup);
|
Nu_Free(pArchive, tmpPathDup);
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
@ -1068,9 +1068,9 @@ Nu_WriteMasterHeader(NuArchive* pArchive, FILE* fp,
|
|||||||
long crcOffset;
|
long crcOffset;
|
||||||
ushort crc;
|
ushort crc;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(fp != nil);
|
Assert(fp != NULL);
|
||||||
Assert(pHeader != nil);
|
Assert(pHeader != NULL);
|
||||||
Assert(pHeader->isValid);
|
Assert(pHeader->isValid);
|
||||||
Assert(pHeader->mhMasterVersion == kNuOurMHVersion);
|
Assert(pHeader->mhMasterVersion == kNuOurMHVersion);
|
||||||
|
|
||||||
@ -1125,17 +1125,17 @@ bail:
|
|||||||
static void
|
static void
|
||||||
Nu_CloseAndFree(NuArchive* pArchive)
|
Nu_CloseAndFree(NuArchive* pArchive)
|
||||||
{
|
{
|
||||||
if (pArchive->archiveFp != nil) {
|
if (pArchive->archiveFp != NULL) {
|
||||||
DBUG(("--- Closing archive\n"));
|
DBUG(("--- Closing archive\n"));
|
||||||
fclose(pArchive->archiveFp);
|
fclose(pArchive->archiveFp);
|
||||||
pArchive->archiveFp = nil;
|
pArchive->archiveFp = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pArchive->tmpFp != nil) {
|
if (pArchive->tmpFp != NULL) {
|
||||||
DBUG(("--- Closing and removing temp file\n"));
|
DBUG(("--- Closing and removing temp file\n"));
|
||||||
fclose(pArchive->tmpFp);
|
fclose(pArchive->tmpFp);
|
||||||
pArchive->tmpFp = nil;
|
pArchive->tmpFp = NULL;
|
||||||
Assert(pArchive->tmpPathname != nil);
|
Assert(pArchive->tmpPathname != NULL);
|
||||||
if (remove(pArchive->tmpPathname) != 0) {
|
if (remove(pArchive->tmpPathname) != 0) {
|
||||||
Nu_ReportError(NU_BLOB, errno, "Unable to remove temp file '%s'",
|
Nu_ReportError(NU_BLOB, errno, "Unable to remove temp file '%s'",
|
||||||
pArchive->tmpPathname);
|
pArchive->tmpPathname);
|
||||||
@ -1164,7 +1164,7 @@ Nu_Close(NuArchive* pArchive)
|
|||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
long flushStatus;
|
long flushStatus;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
|
|
||||||
if (!Nu_IsReadOnly(pArchive))
|
if (!Nu_IsReadOnly(pArchive))
|
||||||
err = Nu_Flush(pArchive, &flushStatus);
|
err = Nu_Flush(pArchive, &flushStatus);
|
||||||
@ -1193,9 +1193,9 @@ Nu_Close(NuArchive* pArchive)
|
|||||||
NuError
|
NuError
|
||||||
Nu_DeleteArchiveFile(NuArchive* pArchive)
|
Nu_DeleteArchiveFile(NuArchive* pArchive)
|
||||||
{
|
{
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pArchive->archiveFp == nil);
|
Assert(pArchive->archiveFp == NULL);
|
||||||
Assert(pArchive->archivePathname != nil);
|
Assert(pArchive->archivePathname != NULL);
|
||||||
|
|
||||||
return Nu_DeleteFile(pArchive->archivePathname);
|
return Nu_DeleteFile(pArchive->archivePathname);
|
||||||
}
|
}
|
||||||
@ -1207,11 +1207,11 @@ Nu_DeleteArchiveFile(NuArchive* pArchive)
|
|||||||
NuError
|
NuError
|
||||||
Nu_RenameTempToArchive(NuArchive* pArchive)
|
Nu_RenameTempToArchive(NuArchive* pArchive)
|
||||||
{
|
{
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pArchive->archiveFp == nil);
|
Assert(pArchive->archiveFp == NULL);
|
||||||
Assert(pArchive->tmpFp == nil);
|
Assert(pArchive->tmpFp == NULL);
|
||||||
Assert(pArchive->archivePathname != nil);
|
Assert(pArchive->archivePathname != NULL);
|
||||||
Assert(pArchive->tmpPathname != nil);
|
Assert(pArchive->tmpPathname != NULL);
|
||||||
|
|
||||||
return Nu_RenameFile(pArchive->tmpPathname, pArchive->archivePathname);
|
return Nu_RenameFile(pArchive->tmpPathname, pArchive->archivePathname);
|
||||||
}
|
}
|
||||||
|
@ -31,9 +31,9 @@ Nu_ReadOneC(NuArchive* pArchive, FILE* fp, ushort* pCrc)
|
|||||||
{
|
{
|
||||||
int ic;
|
int ic;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(fp != nil);
|
Assert(fp != NULL);
|
||||||
Assert(pCrc != nil);
|
Assert(pCrc != NULL);
|
||||||
|
|
||||||
ic = getc(fp);
|
ic = getc(fp);
|
||||||
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
|
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
|
||||||
@ -54,9 +54,9 @@ Nu_ReadOne(NuArchive* pArchive, FILE* fp)
|
|||||||
void
|
void
|
||||||
Nu_WriteOneC(NuArchive* pArchive, FILE* fp, uchar val, ushort* pCrc)
|
Nu_WriteOneC(NuArchive* pArchive, FILE* fp, uchar val, ushort* pCrc)
|
||||||
{
|
{
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(fp != nil);
|
Assert(fp != NULL);
|
||||||
Assert(pCrc != nil);
|
Assert(pCrc != NULL);
|
||||||
|
|
||||||
putc(val, fp);
|
putc(val, fp);
|
||||||
}
|
}
|
||||||
@ -77,9 +77,9 @@ Nu_ReadTwoC(NuArchive* pArchive, FILE* fp, ushort* pCrc)
|
|||||||
{
|
{
|
||||||
int ic1, ic2;
|
int ic1, ic2;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(fp != nil);
|
Assert(fp != NULL);
|
||||||
Assert(pCrc != nil);
|
Assert(pCrc != NULL);
|
||||||
|
|
||||||
ic1 = getc(fp);
|
ic1 = getc(fp);
|
||||||
*pCrc = Nu_UpdateCRC16((uchar)ic1, *pCrc);
|
*pCrc = Nu_UpdateCRC16((uchar)ic1, *pCrc);
|
||||||
@ -105,9 +105,9 @@ Nu_WriteTwoC(NuArchive* pArchive, FILE* fp, ushort val, ushort* pCrc)
|
|||||||
{
|
{
|
||||||
int ic1, ic2;
|
int ic1, ic2;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(fp != nil);
|
Assert(fp != NULL);
|
||||||
Assert(pCrc != nil);
|
Assert(pCrc != NULL);
|
||||||
|
|
||||||
ic1 = val & 0xff;
|
ic1 = val & 0xff;
|
||||||
*pCrc = Nu_UpdateCRC16((uchar)ic1, *pCrc);
|
*pCrc = Nu_UpdateCRC16((uchar)ic1, *pCrc);
|
||||||
@ -134,9 +134,9 @@ Nu_ReadFourC(NuArchive* pArchive, FILE* fp, ushort* pCrc)
|
|||||||
{
|
{
|
||||||
int ic1, ic2, ic3, ic4;
|
int ic1, ic2, ic3, ic4;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(fp != nil);
|
Assert(fp != NULL);
|
||||||
Assert(pCrc != nil);
|
Assert(pCrc != NULL);
|
||||||
|
|
||||||
ic1 = getc(fp);
|
ic1 = getc(fp);
|
||||||
*pCrc = Nu_UpdateCRC16((uchar)ic1, *pCrc);
|
*pCrc = Nu_UpdateCRC16((uchar)ic1, *pCrc);
|
||||||
@ -166,9 +166,9 @@ Nu_WriteFourC(NuArchive* pArchive, FILE* fp, ulong val, ushort* pCrc)
|
|||||||
{
|
{
|
||||||
int ic1, ic2, ic3, ic4;
|
int ic1, ic2, ic3, ic4;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(fp != nil);
|
Assert(fp != NULL);
|
||||||
Assert(pCrc != nil);
|
Assert(pCrc != NULL);
|
||||||
|
|
||||||
ic1 = val & 0xff;
|
ic1 = val & 0xff;
|
||||||
*pCrc = Nu_UpdateCRC16((uchar)ic1, *pCrc);
|
*pCrc = Nu_UpdateCRC16((uchar)ic1, *pCrc);
|
||||||
@ -206,9 +206,9 @@ Nu_ReadDateTimeC(NuArchive* pArchive, FILE* fp, ushort* pCrc)
|
|||||||
NuDateTime temp;
|
NuDateTime temp;
|
||||||
int ic;
|
int ic;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(fp != nil);
|
Assert(fp != NULL);
|
||||||
Assert(pCrc != nil);
|
Assert(pCrc != NULL);
|
||||||
|
|
||||||
ic = getc(fp);
|
ic = getc(fp);
|
||||||
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
|
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
|
||||||
@ -255,9 +255,9 @@ Nu_WriteDateTimeC(NuArchive* pArchive, FILE* fp, NuDateTime dateTime,
|
|||||||
{
|
{
|
||||||
int ic;
|
int ic;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(fp != nil);
|
Assert(fp != NULL);
|
||||||
Assert(pCrc != nil);
|
Assert(pCrc != NULL);
|
||||||
|
|
||||||
ic = dateTime.second;
|
ic = dateTime.second;
|
||||||
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
|
*pCrc = Nu_UpdateCRC16((uchar)ic, *pCrc);
|
||||||
@ -303,10 +303,10 @@ Nu_ReadBytesC(NuArchive* pArchive, FILE* fp, void* vbuffer, long count,
|
|||||||
uchar* buffer = vbuffer;
|
uchar* buffer = vbuffer;
|
||||||
int ic;
|
int ic;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(fp != nil);
|
Assert(fp != NULL);
|
||||||
Assert(pCrc != nil);
|
Assert(pCrc != NULL);
|
||||||
Assert(buffer != nil);
|
Assert(buffer != NULL);
|
||||||
Assert(count > 0);
|
Assert(count > 0);
|
||||||
|
|
||||||
while (count--) {
|
while (count--) {
|
||||||
@ -334,10 +334,10 @@ Nu_WriteBytesC(NuArchive* pArchive, FILE* fp, const void* vbuffer, long count,
|
|||||||
const uchar* buffer = vbuffer;
|
const uchar* buffer = vbuffer;
|
||||||
int ic;
|
int ic;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(fp != nil);
|
Assert(fp != NULL);
|
||||||
Assert(pCrc != nil);
|
Assert(pCrc != NULL);
|
||||||
Assert(buffer != nil);
|
Assert(buffer != NULL);
|
||||||
Assert(count > 0);
|
Assert(count > 0);
|
||||||
|
|
||||||
while (count--) {
|
while (count--) {
|
||||||
@ -411,7 +411,7 @@ Nu_SeekArchive(NuArchive* pArchive, FILE* fp, long offset, int ptrname)
|
|||||||
NuError
|
NuError
|
||||||
Nu_RewindArchive(NuArchive* pArchive)
|
Nu_RewindArchive(NuArchive* pArchive)
|
||||||
{
|
{
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(!Nu_IsStreaming(pArchive));
|
Assert(!Nu_IsStreaming(pArchive));
|
||||||
|
|
||||||
if (Nu_SeekArchive(pArchive, pArchive->archiveFp,
|
if (Nu_SeekArchive(pArchive, pArchive->archiveFp,
|
||||||
|
@ -53,14 +53,14 @@ Nu_CompressBzip2(NuArchive* pArchive, NuStraw* pStraw, FILE* fp,
|
|||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
bz_stream bzstream;
|
bz_stream bzstream;
|
||||||
int bzerr;
|
int bzerr;
|
||||||
uchar* outbuf = nil;
|
uchar* outbuf = NULL;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pStraw != nil);
|
Assert(pStraw != NULL);
|
||||||
Assert(fp != nil);
|
Assert(fp != NULL);
|
||||||
Assert(srcLen > 0);
|
Assert(srcLen > 0);
|
||||||
Assert(pDstLen != nil);
|
Assert(pDstLen != NULL);
|
||||||
Assert(pCrc != nil);
|
Assert(pCrc != NULL);
|
||||||
|
|
||||||
err = Nu_AllocCompressionBufferIFN(pArchive);
|
err = Nu_AllocCompressionBufferIFN(pArchive);
|
||||||
if (err != kNuErrNone)
|
if (err != kNuErrNone)
|
||||||
@ -76,7 +76,7 @@ Nu_CompressBzip2(NuArchive* pArchive, NuStraw* pStraw, FILE* fp,
|
|||||||
bzstream.bzalloc = Nu_bzalloc;
|
bzstream.bzalloc = Nu_bzalloc;
|
||||||
bzstream.bzfree = Nu_bzfree;
|
bzstream.bzfree = Nu_bzfree;
|
||||||
bzstream.opaque = pArchive;
|
bzstream.opaque = pArchive;
|
||||||
bzstream.next_in = nil;
|
bzstream.next_in = NULL;
|
||||||
bzstream.avail_in = 0;
|
bzstream.avail_in = 0;
|
||||||
bzstream.next_out = outbuf;
|
bzstream.next_out = outbuf;
|
||||||
bzstream.avail_out = kNuGenCompBufSize;
|
bzstream.avail_out = kNuGenCompBufSize;
|
||||||
@ -158,7 +158,7 @@ bz_bail:
|
|||||||
BZ2_bzCompressEnd(&bzstream); /* free up any allocated structures */
|
BZ2_bzCompressEnd(&bzstream); /* free up any allocated structures */
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (outbuf != nil)
|
if (outbuf != NULL)
|
||||||
free(outbuf);
|
free(outbuf);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -183,10 +183,10 @@ Nu_ExpandBzip2(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
ulong compRemaining;
|
ulong compRemaining;
|
||||||
uchar* outbuf;
|
uchar* outbuf;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pThread != nil);
|
Assert(pThread != NULL);
|
||||||
Assert(infp != nil);
|
Assert(infp != NULL);
|
||||||
Assert(pFunnel != nil);
|
Assert(pFunnel != NULL);
|
||||||
|
|
||||||
err = Nu_AllocCompressionBufferIFN(pArchive);
|
err = Nu_AllocCompressionBufferIFN(pArchive);
|
||||||
if (err != kNuErrNone)
|
if (err != kNuErrNone)
|
||||||
@ -204,7 +204,7 @@ Nu_ExpandBzip2(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
bzstream.bzalloc = Nu_bzalloc;
|
bzstream.bzalloc = Nu_bzalloc;
|
||||||
bzstream.bzfree = Nu_bzfree;
|
bzstream.bzfree = Nu_bzfree;
|
||||||
bzstream.opaque = pArchive;
|
bzstream.opaque = pArchive;
|
||||||
bzstream.next_in = nil;
|
bzstream.next_in = NULL;
|
||||||
bzstream.avail_in = 0;
|
bzstream.avail_in = 0;
|
||||||
bzstream.next_out = outbuf;
|
bzstream.next_out = outbuf;
|
||||||
bzstream.avail_out = kNuGenCompBufSize;
|
bzstream.avail_out = kNuGenCompBufSize;
|
||||||
@ -266,7 +266,7 @@ Nu_ExpandBzip2(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
goto bz_bail;
|
goto bz_bail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pCrc != nil)
|
if (pCrc != NULL)
|
||||||
*pCrc = Nu_CalcCRC16(*pCrc, outbuf,
|
*pCrc = Nu_CalcCRC16(*pCrc, outbuf,
|
||||||
(uchar*) bzstream.next_out - outbuf);
|
(uchar*) bzstream.next_out - outbuf);
|
||||||
|
|
||||||
@ -291,7 +291,7 @@ bz_bail:
|
|||||||
BZ2_bzDecompressEnd(&bzstream); /* free up any allocated structures */
|
BZ2_bzDecompressEnd(&bzstream); /* free up any allocated structures */
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (outbuf != nil)
|
if (outbuf != NULL)
|
||||||
free(outbuf);
|
free(outbuf);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -20,12 +20,12 @@ 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;
|
NuError err = kNuErrNone;
|
||||||
/*uchar* buffer = nil;*/
|
/*uchar* buffer = NULL;*/
|
||||||
ulong count, getsize;
|
ulong count, getsize;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pStraw != nil);
|
Assert(pStraw != NULL);
|
||||||
Assert(fp != nil);
|
Assert(fp != NULL);
|
||||||
Assert(srcLen > 0);
|
Assert(srcLen > 0);
|
||||||
|
|
||||||
*pDstLen = srcLen; /* get this over with */
|
*pDstLen = srcLen; /* get this over with */
|
||||||
@ -33,7 +33,7 @@ Nu_CompressUncompressed(NuArchive* pArchive, NuStraw* pStraw,
|
|||||||
err = Nu_AllocCompressionBufferIFN(pArchive);
|
err = Nu_AllocCompressionBufferIFN(pArchive);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
|
|
||||||
if (pCrc != nil)
|
if (pCrc != NULL)
|
||||||
*pCrc = kNuInitialThreadCRC;
|
*pCrc = kNuInitialThreadCRC;
|
||||||
count = srcLen;
|
count = srcLen;
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ Nu_CompressUncompressed(NuArchive* pArchive, NuStraw* pStraw,
|
|||||||
|
|
||||||
err = Nu_StrawRead(pArchive, pStraw, pArchive->compBuf, getsize);
|
err = Nu_StrawRead(pArchive, pStraw, pArchive->compBuf, getsize);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
if (pCrc != nil)
|
if (pCrc != NULL)
|
||||||
*pCrc = Nu_CalcCRC16(*pCrc, pArchive->compBuf, getsize);
|
*pCrc = Nu_CalcCRC16(*pCrc, pArchive->compBuf, getsize);
|
||||||
err = Nu_FWrite(fp, pArchive->compBuf, getsize);
|
err = Nu_FWrite(fp, pArchive->compBuf, getsize);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
@ -95,16 +95,16 @@ Nu_CompressToArchive(NuArchive* pArchive, NuDataSource* pDataSource,
|
|||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
long origOffset;
|
long origOffset;
|
||||||
NuStraw* pStraw = nil;
|
NuStraw* pStraw = NULL;
|
||||||
NuDataSink* pDataSink = nil;
|
NuDataSink* pDataSink = NULL;
|
||||||
ulong srcLen = 0, dstLen = 0;
|
ulong srcLen = 0, dstLen = 0;
|
||||||
ushort threadCrc;
|
ushort threadCrc;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pDataSource != nil);
|
Assert(pDataSource != NULL);
|
||||||
/* okay if pProgressData is nil */
|
/* okay if pProgressData is NULL */
|
||||||
Assert(dstFp != nil);
|
Assert(dstFp != NULL);
|
||||||
Assert(pThread != nil);
|
Assert(pThread != NULL);
|
||||||
|
|
||||||
/* remember file offset, so we can back up if compression fails */
|
/* remember file offset, so we can back up if compression fails */
|
||||||
err = Nu_FTell(dstFp, &origOffset);
|
err = Nu_FTell(dstFp, &origOffset);
|
||||||
@ -168,7 +168,7 @@ Nu_CompressToArchive(NuArchive* pArchive, NuDataSource* pDataSource,
|
|||||||
if (pArchive->valMimicSHK && srcLen < kNuSHKLZWThreshold)
|
if (pArchive->valMimicSHK && srcLen < kNuSHKLZWThreshold)
|
||||||
targetFormat = kNuThreadFormatUncompressed;
|
targetFormat = kNuThreadFormatUncompressed;
|
||||||
|
|
||||||
if (pProgressData != nil) {
|
if (pProgressData != NULL) {
|
||||||
if (targetFormat != kNuThreadFormatUncompressed)
|
if (targetFormat != kNuThreadFormatUncompressed)
|
||||||
Nu_StrawSetProgressState(pStraw, kNuProgressCompressing);
|
Nu_StrawSetProgressState(pStraw, kNuProgressCompressing);
|
||||||
else
|
else
|
||||||
@ -245,7 +245,7 @@ Nu_CompressToArchive(NuArchive* pArchive, NuDataSource* pDataSource,
|
|||||||
BailError(err);
|
BailError(err);
|
||||||
err = Nu_StrawRewind(pArchive, pStraw);
|
err = Nu_StrawRewind(pArchive, pStraw);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
if (pProgressData != nil)
|
if (pProgressData != NULL)
|
||||||
Nu_StrawSetProgressState(pStraw, kNuProgressStoring);
|
Nu_StrawSetProgressState(pStraw, kNuProgressStoring);
|
||||||
err = Nu_ProgressDataCompressPrep(pArchive, pStraw,
|
err = Nu_ProgressDataCompressPrep(pArchive, pStraw,
|
||||||
kNuThreadFormatUncompressed, srcLen);
|
kNuThreadFormatUncompressed, srcLen);
|
||||||
@ -262,7 +262,7 @@ Nu_CompressToArchive(NuArchive* pArchive, NuDataSource* pDataSource,
|
|||||||
* computed a CRC on the entire file (i.e. didn't stop early
|
* computed a CRC on the entire file (i.e. didn't stop early
|
||||||
* when it noticed the output was larger than the input). If
|
* when it noticed the output was larger than the input). If
|
||||||
* this is always the case, then we can change "&threadCrc"
|
* this is always the case, then we can change "&threadCrc"
|
||||||
* a few lines back to "nil" and avoid re-computing the CRC.
|
* a few lines back to "NULL" and avoid re-computing the CRC.
|
||||||
* If this is not always the case, remove this assert.
|
* If this is not always the case, remove this assert.
|
||||||
*/
|
*/
|
||||||
Assert(threadCrc == pThread->thThreadCRC);
|
Assert(threadCrc == pThread->thThreadCRC);
|
||||||
@ -276,14 +276,14 @@ Nu_CompressToArchive(NuArchive* pArchive, NuDataSource* pDataSource,
|
|||||||
/*
|
/*
|
||||||
* Copy the already-compressed input.
|
* Copy the already-compressed input.
|
||||||
*/
|
*/
|
||||||
if (pProgressData != nil)
|
if (pProgressData != NULL)
|
||||||
Nu_StrawSetProgressState(pStraw, kNuProgressCopying);
|
Nu_StrawSetProgressState(pStraw, kNuProgressCopying);
|
||||||
err = Nu_ProgressDataCompressPrep(pArchive, pStraw,
|
err = Nu_ProgressDataCompressPrep(pArchive, pStraw,
|
||||||
kNuThreadFormatUncompressed, srcLen);
|
kNuThreadFormatUncompressed, srcLen);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
|
|
||||||
err = Nu_CompressUncompressed(pArchive, pStraw, dstFp, srcLen,
|
err = Nu_CompressUncompressed(pArchive, pStraw, dstFp, srcLen,
|
||||||
&dstLen, nil);
|
&dstLen, NULL);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
|
|
||||||
pThread->thThreadEOF = Nu_DataSourceGetOtherLen(pDataSource);
|
pThread->thThreadEOF = Nu_DataSourceGetOtherLen(pDataSource);
|
||||||
@ -298,7 +298,7 @@ done:
|
|||||||
srcLen, dstLen, pThread->actualThreadEOF));
|
srcLen, dstLen, pThread->actualThreadEOF));
|
||||||
|
|
||||||
/* make sure we send a final "success" progress message at 100% */
|
/* make sure we send a final "success" progress message at 100% */
|
||||||
if (pProgressData != nil) {
|
if (pProgressData != NULL) {
|
||||||
(void) Nu_StrawSetProgressState(pStraw, kNuProgressDone);
|
(void) Nu_StrawSetProgressState(pStraw, kNuProgressDone);
|
||||||
err = Nu_StrawSendProgressUpdate(pArchive, pStraw);
|
err = Nu_StrawSendProgressUpdate(pArchive, pStraw);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
@ -327,7 +327,7 @@ 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;
|
NuError err = kNuErrNone;
|
||||||
NuStraw* pStraw = nil;
|
NuStraw* pStraw = NULL;
|
||||||
ulong srcLen, bufferLen;
|
ulong srcLen, bufferLen;
|
||||||
ulong count, getsize;
|
ulong count, getsize;
|
||||||
|
|
||||||
@ -355,7 +355,7 @@ Nu_CopyPresizedToArchive(NuArchive* pArchive, NuDataSource* pDataSource,
|
|||||||
* is a convenient way to deal with the dataSource, even though we
|
* is a convenient way to deal with the dataSource, even though we
|
||||||
* don't have a progress updater.
|
* don't have a progress updater.
|
||||||
*/
|
*/
|
||||||
err = Nu_StrawNew(pArchive, pDataSource, nil, &pStraw);
|
err = Nu_StrawNew(pArchive, pDataSource, NULL, &pStraw);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
|
|
||||||
count = srcLen;
|
count = srcLen;
|
||||||
@ -370,7 +370,7 @@ Nu_CopyPresizedToArchive(NuArchive* pArchive, NuDataSource* pDataSource,
|
|||||||
err = Nu_FWrite(dstFp, pArchive->compBuf, getsize);
|
err = Nu_FWrite(dstFp, pArchive->compBuf, getsize);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
|
|
||||||
if (ppSavedCopy != nil && *ppSavedCopy == nil) {
|
if (ppSavedCopy != NULL && *ppSavedCopy == NULL) {
|
||||||
/*
|
/*
|
||||||
* Grab a copy of the filename for our own use. This assumes
|
* Grab a copy of the filename for our own use. This assumes
|
||||||
* that the filename fits in kNuGenCompBufSize, which is a
|
* that the filename fits in kNuGenCompBufSize, which is a
|
||||||
|
@ -140,7 +140,7 @@ Nu_DebugDumpThread(const NuThread* pThread)
|
|||||||
NuThreadID threadID;
|
NuThreadID threadID;
|
||||||
const char* descr;
|
const char* descr;
|
||||||
|
|
||||||
Assert(pThread != nil);
|
Assert(pThread != NULL);
|
||||||
|
|
||||||
printf("%sThreadClass: 0x%04x (%s)\n", kInd,
|
printf("%sThreadClass: 0x%04x (%s)\n", kInd,
|
||||||
pThread->thThreadClass,
|
pThread->thThreadClass,
|
||||||
@ -188,15 +188,15 @@ Nu_DebugDumpRecord(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
const NuThread* pThread;
|
const NuThread* pThread;
|
||||||
ulong idx;
|
ulong idx;
|
||||||
|
|
||||||
Assert(pRecord != nil);
|
Assert(pRecord != NULL);
|
||||||
|
|
||||||
/*printf("PTR: pRecord=0x%08lx pXrefRecord=0x%08lx\n", (long) pRecord,
|
/*printf("PTR: pRecord=0x%08lx pXrefRecord=0x%08lx\n", (long) pRecord,
|
||||||
(long) pXrefRecord);*/
|
(long) pXrefRecord);*/
|
||||||
|
|
||||||
printf("%s%s%sFilename: '%s' (idx=%lu)\n", kInd,
|
printf("%s%s%sFilename: '%s' (idx=%lu)\n", kInd,
|
||||||
isDeleted ? "[DEL] " : "",
|
isDeleted ? "[DEL] " : "",
|
||||||
pXrefRecord != nil && pXrefRecord->pThreadMods != nil ? "[MOD] " : "",
|
pXrefRecord != NULL && pXrefRecord->pThreadMods != NULL ? "[MOD] " : "",
|
||||||
pRecord->filename == nil ? "<not specified>" : pRecord->filename,
|
pRecord->filename == NULL ? "<not specified>" : pRecord->filename,
|
||||||
pRecord->recordIdx);
|
pRecord->recordIdx);
|
||||||
printf("%sHeaderID: '%.4s' VersionNumber: 0x%04x HeaderCRC: 0x%04x\n",
|
printf("%sHeaderID: '%.4s' VersionNumber: 0x%04x HeaderCRC: 0x%04x\n",
|
||||||
kInd,
|
kInd,
|
||||||
@ -223,7 +223,7 @@ Nu_DebugDumpRecord(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
if (pRecord->recOptionSize) {
|
if (pRecord->recOptionSize) {
|
||||||
char* outBuf = Nu_Malloc(pArchive, pRecord->recOptionSize * 2 +1);
|
char* outBuf = Nu_Malloc(pArchive, pRecord->recOptionSize * 2 +1);
|
||||||
BailAlloc(outBuf);
|
BailAlloc(outBuf);
|
||||||
Assert(pRecord->recOptionList != nil);
|
Assert(pRecord->recOptionList != NULL);
|
||||||
ConvertToHexStr(pRecord->recOptionList, pRecord->recOptionSize, outBuf);
|
ConvertToHexStr(pRecord->recOptionList, pRecord->recOptionSize, outBuf);
|
||||||
printf("%sOptionList: [%s]\n", kInd, outBuf);
|
printf("%sOptionList: [%s]\n", kInd, outBuf);
|
||||||
Nu_Free(pArchive, outBuf);
|
Nu_Free(pArchive, outBuf);
|
||||||
@ -238,21 +238,21 @@ Nu_DebugDumpRecord(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
|
|
||||||
isFake = (idx >= pRecord->recTotalThreads - pRecord->fakeThreads);
|
isFake = (idx >= pRecord->recTotalThreads - pRecord->fakeThreads);
|
||||||
pThread = Nu_GetThread(pRecord, idx);
|
pThread = Nu_GetThread(pRecord, idx);
|
||||||
Assert(pThread != nil);
|
Assert(pThread != NULL);
|
||||||
|
|
||||||
printf("%s--Thread #%lu (idx=%lu)%s\n", kInd, idx, pThread->threadIdx,
|
printf("%s--Thread #%lu (idx=%lu)%s\n", kInd, idx, pThread->threadIdx,
|
||||||
isFake ? " [FAKE]" : "");
|
isFake ? " [FAKE]" : "");
|
||||||
Nu_DebugDumpThread(pThread);
|
Nu_DebugDumpThread(pThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pXrefRecord != nil)
|
if (pXrefRecord != NULL)
|
||||||
pThreadMod = pXrefRecord->pThreadMods;
|
pThreadMod = pXrefRecord->pThreadMods;
|
||||||
else
|
else
|
||||||
pThreadMod = pRecord->pThreadMods; /* probably empty */
|
pThreadMod = pRecord->pThreadMods; /* probably empty */
|
||||||
|
|
||||||
if (pThreadMod != nil)
|
if (pThreadMod != NULL)
|
||||||
printf("%s*ThreadMods -----\n", kInd);
|
printf("%s*ThreadMods -----\n", kInd);
|
||||||
while (pThreadMod != nil) {
|
while (pThreadMod != NULL) {
|
||||||
switch (pThreadMod->entry.kind) {
|
switch (pThreadMod->entry.kind) {
|
||||||
case kNuThreadModAdd:
|
case kNuThreadModAdd:
|
||||||
printf("%s *-ThreadMod ADD 0x%08lx 0x%04x (sourceType=%d)\n", kInd,
|
printf("%s *-ThreadMod ADD 0x%08lx 0x%04x (sourceType=%d)\n", kInd,
|
||||||
@ -300,8 +300,8 @@ Nu_DebugDumpRecordSet(NuArchive* pArchive, const NuRecordSet* pRecordSet,
|
|||||||
long count;
|
long count;
|
||||||
|
|
||||||
doXref = false;
|
doXref = false;
|
||||||
pXrefRecord = nil;
|
pXrefRecord = NULL;
|
||||||
if (pXrefSet != nil && Nu_RecordSet_GetLoaded(pXrefSet)) {
|
if (pXrefSet != NULL && Nu_RecordSet_GetLoaded(pXrefSet)) {
|
||||||
pXrefRecord = Nu_RecordSet_GetListHead(pXrefSet);
|
pXrefRecord = Nu_RecordSet_GetListHead(pXrefSet);
|
||||||
doXref = true;
|
doXref = true;
|
||||||
}
|
}
|
||||||
@ -309,18 +309,18 @@ Nu_DebugDumpRecordSet(NuArchive* pArchive, const NuRecordSet* pRecordSet,
|
|||||||
/* dump every record, if we've loaded them */
|
/* dump every record, if we've loaded them */
|
||||||
count = Nu_RecordSet_GetNumRecords(pRecordSet);
|
count = Nu_RecordSet_GetNumRecords(pRecordSet);
|
||||||
pRecord = Nu_RecordSet_GetListHead(pRecordSet);
|
pRecord = Nu_RecordSet_GetListHead(pRecordSet);
|
||||||
if (pRecord != nil) {
|
if (pRecord != NULL) {
|
||||||
Assert(count != 0);
|
Assert(count != 0);
|
||||||
while (count--) {
|
while (count--) {
|
||||||
Assert(pRecord != nil);
|
Assert(pRecord != NULL);
|
||||||
|
|
||||||
if (pXrefRecord != nil &&
|
if (pXrefRecord != NULL &&
|
||||||
pRecord->recordIdx == pXrefRecord->recordIdx)
|
pRecord->recordIdx == pXrefRecord->recordIdx)
|
||||||
{
|
{
|
||||||
Nu_DebugDumpRecord(pArchive, pRecord, pXrefRecord, false);
|
Nu_DebugDumpRecord(pArchive, pRecord, pXrefRecord, false);
|
||||||
pXrefRecord = pXrefRecord->pNext;
|
pXrefRecord = pXrefRecord->pNext;
|
||||||
} else {
|
} else {
|
||||||
Nu_DebugDumpRecord(pArchive, pRecord, nil, doXref);
|
Nu_DebugDumpRecord(pArchive, pRecord, NULL, doXref);
|
||||||
}
|
}
|
||||||
pRecord = pRecord->pNext;
|
pRecord = pRecord->pNext;
|
||||||
}
|
}
|
||||||
@ -338,7 +338,7 @@ Nu_DebugDumpMH(const NuMasterHeader* pMasterHeader)
|
|||||||
static const char* kInd = " ";
|
static const char* kInd = " ";
|
||||||
char dateBuf1[kNuDateOutputLen];
|
char dateBuf1[kNuDateOutputLen];
|
||||||
|
|
||||||
Assert(pMasterHeader != nil);
|
Assert(pMasterHeader != NULL);
|
||||||
|
|
||||||
printf("%sNufileID: '%.6s' MasterCRC: 0x%04x TotalRecords: %lu\n", kInd,
|
printf("%sNufileID: '%.6s' MasterCRC: 0x%04x TotalRecords: %lu\n", kInd,
|
||||||
pMasterHeader->mhNufileID, pMasterHeader->mhMasterCRC,
|
pMasterHeader->mhNufileID, pMasterHeader->mhMasterCRC,
|
||||||
@ -362,7 +362,7 @@ Nu_DebugDumpMH(const NuMasterHeader* pMasterHeader)
|
|||||||
void
|
void
|
||||||
Nu_DebugDumpAll(NuArchive* pArchive)
|
Nu_DebugDumpAll(NuArchive* pArchive)
|
||||||
{
|
{
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
|
|
||||||
printf("*Archive pathname: '%s'\n", pArchive->archivePathname);
|
printf("*Archive pathname: '%s'\n", pArchive->archivePathname);
|
||||||
printf("*Archive type: %d\n", pArchive->archiveType);
|
printf("*Archive type: %d\n", pArchive->archiveType);
|
||||||
@ -382,7 +382,7 @@ Nu_DebugDumpAll(NuArchive* pArchive)
|
|||||||
Nu_DebugDumpRecordSet(pArchive, &pArchive->origRecordSet,
|
Nu_DebugDumpRecordSet(pArchive, &pArchive->origRecordSet,
|
||||||
&pArchive->copyRecordSet);
|
&pArchive->copyRecordSet);
|
||||||
printf(" *NEW record set:\n");
|
printf(" *NEW record set:\n");
|
||||||
Nu_DebugDumpRecordSet(pArchive, &pArchive->newRecordSet, nil);
|
Nu_DebugDumpRecordSet(pArchive, &pArchive->newRecordSet, NULL);
|
||||||
|
|
||||||
if (!Nu_RecordSet_GetLoaded(&pArchive->origRecordSet) &&
|
if (!Nu_RecordSet_GetLoaded(&pArchive->origRecordSet) &&
|
||||||
!Nu_RecordSet_GetLoaded(&pArchive->newRecordSet))
|
!Nu_RecordSet_GetLoaded(&pArchive->newRecordSet))
|
||||||
|
@ -28,11 +28,11 @@ Nu_ThreadModAdd_New(NuArchive* pArchive, NuThreadID threadID,
|
|||||||
NuThreadFormat threadFormat, NuDataSource* pDataSource,
|
NuThreadFormat threadFormat, NuDataSource* pDataSource,
|
||||||
NuThreadMod** ppThreadMod)
|
NuThreadMod** ppThreadMod)
|
||||||
{
|
{
|
||||||
Assert(ppThreadMod != nil);
|
Assert(ppThreadMod != NULL);
|
||||||
Assert(pDataSource != nil);
|
Assert(pDataSource != NULL);
|
||||||
|
|
||||||
*ppThreadMod = Nu_Calloc(pArchive, sizeof(**ppThreadMod));
|
*ppThreadMod = Nu_Calloc(pArchive, sizeof(**ppThreadMod));
|
||||||
if (*ppThreadMod == nil)
|
if (*ppThreadMod == NULL)
|
||||||
return kNuErrMalloc;
|
return kNuErrMalloc;
|
||||||
|
|
||||||
(*ppThreadMod)->entry.kind = kNuThreadModAdd;
|
(*ppThreadMod)->entry.kind = kNuThreadModAdd;
|
||||||
@ -57,11 +57,11 @@ NuError
|
|||||||
Nu_ThreadModUpdate_New(NuArchive* pArchive, NuThreadIdx threadIdx,
|
Nu_ThreadModUpdate_New(NuArchive* pArchive, NuThreadIdx threadIdx,
|
||||||
NuDataSource* pDataSource, NuThreadMod** ppThreadMod)
|
NuDataSource* pDataSource, NuThreadMod** ppThreadMod)
|
||||||
{
|
{
|
||||||
Assert(ppThreadMod != nil);
|
Assert(ppThreadMod != NULL);
|
||||||
Assert(pDataSource != nil);
|
Assert(pDataSource != NULL);
|
||||||
|
|
||||||
*ppThreadMod = Nu_Calloc(pArchive, sizeof(**ppThreadMod));
|
*ppThreadMod = Nu_Calloc(pArchive, sizeof(**ppThreadMod));
|
||||||
if (*ppThreadMod == nil)
|
if (*ppThreadMod == NULL)
|
||||||
return kNuErrMalloc;
|
return kNuErrMalloc;
|
||||||
|
|
||||||
(*ppThreadMod)->entry.kind = kNuThreadModUpdate;
|
(*ppThreadMod)->entry.kind = kNuThreadModUpdate;
|
||||||
@ -82,10 +82,10 @@ NuError
|
|||||||
Nu_ThreadModDelete_New(NuArchive* pArchive, NuThreadIdx threadIdx,
|
Nu_ThreadModDelete_New(NuArchive* pArchive, NuThreadIdx threadIdx,
|
||||||
NuThreadID threadID, NuThreadMod** ppThreadMod)
|
NuThreadID threadID, NuThreadMod** ppThreadMod)
|
||||||
{
|
{
|
||||||
Assert(ppThreadMod != nil);
|
Assert(ppThreadMod != NULL);
|
||||||
|
|
||||||
*ppThreadMod = Nu_Calloc(pArchive, sizeof(**ppThreadMod));
|
*ppThreadMod = Nu_Calloc(pArchive, sizeof(**ppThreadMod));
|
||||||
if (*ppThreadMod == nil)
|
if (*ppThreadMod == NULL)
|
||||||
return kNuErrMalloc;
|
return kNuErrMalloc;
|
||||||
|
|
||||||
(*ppThreadMod)->entry.kind = kNuThreadModDelete;
|
(*ppThreadMod)->entry.kind = kNuThreadModDelete;
|
||||||
@ -102,7 +102,7 @@ Nu_ThreadModDelete_New(NuArchive* pArchive, NuThreadIdx threadIdx,
|
|||||||
void
|
void
|
||||||
Nu_ThreadModFree(NuArchive* pArchive, NuThreadMod* pThreadMod)
|
Nu_ThreadModFree(NuArchive* pArchive, NuThreadMod* pThreadMod)
|
||||||
{
|
{
|
||||||
if (pThreadMod == nil)
|
if (pThreadMod == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
switch (pThreadMod->entry.kind) {
|
switch (pThreadMod->entry.kind) {
|
||||||
@ -131,13 +131,13 @@ Nu_ThreadModFree(NuArchive* pArchive, NuThreadMod* pThreadMod)
|
|||||||
* be more than three or four threads per record, so the extra search
|
* be more than three or four threads per record, so the extra search
|
||||||
* isn't costly.)
|
* isn't costly.)
|
||||||
*
|
*
|
||||||
* Returns "nil" if nothing found.
|
* Returns "NULL" if nothing found.
|
||||||
*/
|
*/
|
||||||
NuThreadMod*
|
NuThreadMod*
|
||||||
Nu_ThreadMod_FindByThreadIdx(const NuRecord* pRecord, NuThreadIdx threadIdx)
|
Nu_ThreadMod_FindByThreadIdx(const NuRecord* pRecord, NuThreadIdx threadIdx)
|
||||||
{
|
{
|
||||||
NuThreadMod* pThreadMod;
|
NuThreadMod* pThreadMod;
|
||||||
NuThreadMod* pMatch = nil;
|
NuThreadMod* pMatch = NULL;
|
||||||
|
|
||||||
pThreadMod = pRecord->pThreadMods;
|
pThreadMod = pRecord->pThreadMods;
|
||||||
while (pThreadMod) {
|
while (pThreadMod) {
|
||||||
@ -148,13 +148,13 @@ Nu_ThreadMod_FindByThreadIdx(const NuRecord* pRecord, NuThreadIdx threadIdx)
|
|||||||
break;
|
break;
|
||||||
case kNuThreadModUpdate:
|
case kNuThreadModUpdate:
|
||||||
if (pThreadMod->entry.update.threadIdx == threadIdx) {
|
if (pThreadMod->entry.update.threadIdx == threadIdx) {
|
||||||
Assert(pMatch == nil);
|
Assert(pMatch == NULL);
|
||||||
pMatch = pThreadMod;
|
pMatch = pThreadMod;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case kNuThreadModDelete:
|
case kNuThreadModDelete:
|
||||||
if (pThreadMod->entry.delete.threadIdx == threadIdx) {
|
if (pThreadMod->entry.delete.threadIdx == threadIdx) {
|
||||||
Assert(pMatch == nil);
|
Assert(pMatch == NULL);
|
||||||
pMatch = pThreadMod;
|
pMatch = pThreadMod;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -184,11 +184,11 @@ Nu_ThreadModAdd_FindByThreadID(const NuRecord* pRecord, NuThreadID threadID,
|
|||||||
{
|
{
|
||||||
NuThreadMod* pThreadMod;
|
NuThreadMod* pThreadMod;
|
||||||
|
|
||||||
Assert(pRecord != nil);
|
Assert(pRecord != NULL);
|
||||||
Assert(ppThreadMod != nil);
|
Assert(ppThreadMod != NULL);
|
||||||
|
|
||||||
pThreadMod = pRecord->pThreadMods;
|
pThreadMod = pRecord->pThreadMods;
|
||||||
while (pThreadMod != nil) {
|
while (pThreadMod != NULL) {
|
||||||
if (pThreadMod->entry.kind != kNuThreadModAdd)
|
if (pThreadMod->entry.kind != kNuThreadModAdd)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -213,20 +213,20 @@ Nu_FreeThreadMods(NuArchive* pArchive, NuRecord* pRecord)
|
|||||||
NuThreadMod* pThreadMod;
|
NuThreadMod* pThreadMod;
|
||||||
NuThreadMod* pNext;
|
NuThreadMod* pNext;
|
||||||
|
|
||||||
Assert(pRecord != nil);
|
Assert(pRecord != NULL);
|
||||||
pThreadMod = pRecord->pThreadMods;
|
pThreadMod = pRecord->pThreadMods;
|
||||||
|
|
||||||
if (pThreadMod == nil)
|
if (pThreadMod == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
while (pThreadMod != nil) {
|
while (pThreadMod != NULL) {
|
||||||
pNext = pThreadMod->pNext;
|
pNext = pThreadMod->pNext;
|
||||||
|
|
||||||
Nu_ThreadModFree(pArchive, pThreadMod);
|
Nu_ThreadModFree(pArchive, pThreadMod);
|
||||||
pThreadMod = pNext;
|
pThreadMod = pNext;
|
||||||
}
|
}
|
||||||
|
|
||||||
pRecord->pThreadMods = nil;
|
pRecord->pThreadMods = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -269,7 +269,7 @@ bail:
|
|||||||
static void
|
static void
|
||||||
Nu_NewThreads_Free(NuArchive* pArchive, NuNewThreads* pNewThreads)
|
Nu_NewThreads_Free(NuArchive* pArchive, NuNewThreads* pNewThreads)
|
||||||
{
|
{
|
||||||
if (pNewThreads != nil) {
|
if (pNewThreads != NULL) {
|
||||||
Nu_Free(pArchive, pNewThreads->pThreads);
|
Nu_Free(pArchive, pNewThreads->pThreads);
|
||||||
Nu_Free(pArchive, pNewThreads);
|
Nu_Free(pArchive, pNewThreads);
|
||||||
}
|
}
|
||||||
@ -316,7 +316,7 @@ Nu_NewThreads_GetNext(NuNewThreads* pNewThreads, NuArchive* pArchive)
|
|||||||
static int
|
static int
|
||||||
Nu_NewThreads_GetNumThreads(const NuNewThreads* pNewThreads)
|
Nu_NewThreads_GetNumThreads(const NuNewThreads* pNewThreads)
|
||||||
{
|
{
|
||||||
Assert(pNewThreads != nil);
|
Assert(pNewThreads != NULL);
|
||||||
|
|
||||||
return pNewThreads->numThreads;
|
return pNewThreads->numThreads;
|
||||||
}
|
}
|
||||||
@ -331,7 +331,7 @@ Nu_NewThreads_TotalCompThreadEOF(NuNewThreads* pNewThreads)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* we should be all full up at this point; if not, we have a bug */
|
/* we should be all full up at this point; if not, we have a bug */
|
||||||
Assert(pNewThreads != nil);
|
Assert(pNewThreads != NULL);
|
||||||
Assert(pNewThreads->numThreads == pNewThreads->nextSlot);
|
Assert(pNewThreads->numThreads == pNewThreads->nextSlot);
|
||||||
|
|
||||||
compThreadEOF = 0;
|
compThreadEOF = 0;
|
||||||
@ -352,7 +352,7 @@ Nu_NewThreads_DonateThreads(NuNewThreads* pNewThreads)
|
|||||||
{
|
{
|
||||||
NuThread* pThreads = pNewThreads->pThreads;
|
NuThread* pThreads = pNewThreads->pThreads;
|
||||||
|
|
||||||
pNewThreads->pThreads = nil;
|
pNewThreads->pThreads = NULL;
|
||||||
return pThreads;
|
return pThreads;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -433,7 +433,7 @@ Nu_CountEventualThreads(const NuRecord* pRecord, long* pTotalThreads,
|
|||||||
numFilenameThreads = 0;
|
numFilenameThreads = 0;
|
||||||
|
|
||||||
pThreadMod = pRecord->pThreadMods;
|
pThreadMod = pRecord->pThreadMods;
|
||||||
while (pThreadMod != nil) {
|
while (pThreadMod != NULL) {
|
||||||
switch (pThreadMod->entry.kind) {
|
switch (pThreadMod->entry.kind) {
|
||||||
case kNuThreadModAdd:
|
case kNuThreadModAdd:
|
||||||
numThreads++;
|
numThreads++;
|
||||||
@ -463,7 +463,7 @@ Nu_CountEventualThreads(const NuRecord* pRecord, long* pTotalThreads,
|
|||||||
*/
|
*/
|
||||||
for (idx = 0; idx < (long)pRecord->recTotalThreads; idx++) {
|
for (idx = 0; idx < (long)pRecord->recTotalThreads; idx++) {
|
||||||
pThread = Nu_GetThread(pRecord, idx);
|
pThread = Nu_GetThread(pRecord, idx);
|
||||||
Assert(pThread != nil);
|
Assert(pThread != NULL);
|
||||||
|
|
||||||
if (NuGetThreadID(pThread) == kNuThreadIDFilename)
|
if (NuGetThreadID(pThread) == kNuThreadIDFilename)
|
||||||
numFilenameThreads++;
|
numFilenameThreads++;
|
||||||
@ -504,11 +504,11 @@ Nu_VerifyAllTouched(NuArchive* pArchive, const NuRecord* pRecord)
|
|||||||
const NuThread* pThread;
|
const NuThread* pThread;
|
||||||
long idx;
|
long idx;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pRecord != nil);
|
Assert(pRecord != NULL);
|
||||||
|
|
||||||
pThreadMod = pRecord->pThreadMods;
|
pThreadMod = pRecord->pThreadMods;
|
||||||
while (pThreadMod != nil) {
|
while (pThreadMod != NULL) {
|
||||||
Assert(pThreadMod->entry.generic.used == false ||
|
Assert(pThreadMod->entry.generic.used == false ||
|
||||||
pThreadMod->entry.generic.used == true);
|
pThreadMod->entry.generic.used == true);
|
||||||
if (!pThreadMod->entry.generic.used)
|
if (!pThreadMod->entry.generic.used)
|
||||||
@ -518,7 +518,7 @@ Nu_VerifyAllTouched(NuArchive* pArchive, const NuRecord* pRecord)
|
|||||||
|
|
||||||
for (idx = 0; idx < (long)pRecord->recTotalThreads; idx++) {
|
for (idx = 0; idx < (long)pRecord->recTotalThreads; idx++) {
|
||||||
pThread = Nu_GetThread(pRecord, idx);
|
pThread = Nu_GetThread(pRecord, idx);
|
||||||
Assert(pThread != nil);
|
Assert(pThread != NULL);
|
||||||
|
|
||||||
Assert(pThread->used == false || pThread->used == true);
|
Assert(pThread->used == false || pThread->used == true);
|
||||||
if (!pThread->used)
|
if (!pThread->used)
|
||||||
@ -541,8 +541,8 @@ Nu_VerifyAllTouched(NuArchive* pArchive, const NuRecord* pRecord)
|
|||||||
static void
|
static void
|
||||||
Nu_SetNewThreadFilename(NuArchive* pArchive, NuRecord* pRecord, char* newName)
|
Nu_SetNewThreadFilename(NuArchive* pArchive, NuRecord* pRecord, char* newName)
|
||||||
{
|
{
|
||||||
Assert(pRecord != nil);
|
Assert(pRecord != NULL);
|
||||||
Assert(newName != nil);
|
Assert(newName != NULL);
|
||||||
|
|
||||||
Nu_Free(pArchive, pRecord->threadFilename);
|
Nu_Free(pArchive, pRecord->threadFilename);
|
||||||
pRecord->threadFilename = newName;
|
pRecord->threadFilename = newName;
|
||||||
@ -604,7 +604,7 @@ Nu_ConstructArchiveUpdate(NuArchive* pArchive, FILE* fp, NuRecord* pRecord,
|
|||||||
NuThread* pThread, const NuThreadMod* pThreadMod)
|
NuThread* pThread, const NuThreadMod* pThreadMod)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
NuDataSource* pDataSource = nil;
|
NuDataSource* pDataSource = NULL;
|
||||||
ulong sourceLen;
|
ulong sourceLen;
|
||||||
ulong threadBufSize;
|
ulong threadBufSize;
|
||||||
|
|
||||||
@ -621,7 +621,7 @@ Nu_ConstructArchiveUpdate(NuArchive* pArchive, FILE* fp, NuRecord* pRecord,
|
|||||||
Assert(pThread->thCompThreadEOF >= pThread->thThreadEOF);
|
Assert(pThread->thCompThreadEOF >= pThread->thThreadEOF);
|
||||||
threadBufSize = pThread->thCompThreadEOF;
|
threadBufSize = pThread->thCompThreadEOF;
|
||||||
pDataSource = pThreadMod->entry.update.pDataSource;
|
pDataSource = pThreadMod->entry.update.pDataSource;
|
||||||
Assert(pDataSource != nil);
|
Assert(pDataSource != NULL);
|
||||||
|
|
||||||
err = Nu_DataSourcePrepareInput(pArchive, pDataSource);
|
err = Nu_DataSourcePrepareInput(pArchive, pDataSource);
|
||||||
if (err == kNuErrSkipped) {
|
if (err == kNuErrSkipped) {
|
||||||
@ -662,7 +662,7 @@ Nu_ConstructArchiveUpdate(NuArchive* pArchive, FILE* fp, NuRecord* pRecord,
|
|||||||
|
|
||||||
if (NuGetThreadID(pThread) == kNuThreadIDFilename) {
|
if (NuGetThreadID(pThread) == kNuThreadIDFilename) {
|
||||||
/* special handling for filename updates */
|
/* special handling for filename updates */
|
||||||
char* savedCopy = nil;
|
char* savedCopy = NULL;
|
||||||
err = Nu_CopyPresizedToArchive(pArchive, pDataSource,
|
err = Nu_CopyPresizedToArchive(pArchive, pDataSource,
|
||||||
NuGetThreadID(pThread), fp, pThread, &savedCopy);
|
NuGetThreadID(pThread), fp, pThread, &savedCopy);
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
@ -673,7 +673,7 @@ Nu_ConstructArchiveUpdate(NuArchive* pArchive, FILE* fp, NuRecord* pRecord,
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
err = Nu_CopyPresizedToArchive(pArchive, pDataSource,
|
err = Nu_CopyPresizedToArchive(pArchive, pDataSource,
|
||||||
NuGetThreadID(pThread), fp, pThread, nil);
|
NuGetThreadID(pThread), fp, pThread, NULL);
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
Nu_ReportError(NU_BLOB, err, "thread update failed");
|
Nu_ReportError(NU_BLOB, err, "thread update failed");
|
||||||
goto bail;
|
goto bail;
|
||||||
@ -723,7 +723,7 @@ Nu_HandleAddThreadMods(NuArchive* pArchive, NuRecord* pRecord,
|
|||||||
* matching by wildcards, but don't re-use "used" entries.
|
* matching by wildcards, but don't re-use "used" entries.
|
||||||
*/
|
*/
|
||||||
pThreadMod = pRecord->pThreadMods;
|
pThreadMod = pRecord->pThreadMods;
|
||||||
while (pThreadMod != nil) {
|
while (pThreadMod != NULL) {
|
||||||
if (pThreadMod->entry.kind == kNuThreadModAdd &&
|
if (pThreadMod->entry.kind == kNuThreadModAdd &&
|
||||||
!pThreadMod->entry.generic.used &&
|
!pThreadMod->entry.generic.used &&
|
||||||
(pThreadMod->entry.add.threadID == threadID ||
|
(pThreadMod->entry.add.threadID == threadID ||
|
||||||
@ -747,7 +747,7 @@ Nu_HandleAddThreadMods(NuArchive* pArchive, NuRecord* pRecord,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* if this is a data thread, prepare the progress message */
|
/* if this is a data thread, prepare the progress message */
|
||||||
pProgressData = nil;
|
pProgressData = NULL;
|
||||||
if (NuThreadIDGetClass(pThreadMod->entry.add.threadID) ==
|
if (NuThreadIDGetClass(pThreadMod->entry.add.threadID) ==
|
||||||
kNuThreadClassData)
|
kNuThreadClassData)
|
||||||
{
|
{
|
||||||
@ -836,7 +836,7 @@ Nu_HandleAddThreadMods(NuArchive* pArchive, NuRecord* pRecord,
|
|||||||
|
|
||||||
if (pThreadMod->entry.add.threadID == kNuThreadIDFilename) {
|
if (pThreadMod->entry.add.threadID == kNuThreadIDFilename) {
|
||||||
/* filenames are special */
|
/* filenames are special */
|
||||||
char* savedCopy = nil;
|
char* savedCopy = NULL;
|
||||||
|
|
||||||
Assert(pThreadMod->entry.add.threadFormat ==
|
Assert(pThreadMod->entry.add.threadFormat ==
|
||||||
kNuThreadFormatUncompressed);
|
kNuThreadFormatUncompressed);
|
||||||
@ -863,7 +863,7 @@ Nu_HandleAddThreadMods(NuArchive* pArchive, NuRecord* pRecord,
|
|||||||
err = Nu_CopyPresizedToArchive(pArchive,
|
err = Nu_CopyPresizedToArchive(pArchive,
|
||||||
pThreadMod->entry.add.pDataSource,
|
pThreadMod->entry.add.pDataSource,
|
||||||
pThreadMod->entry.add.threadID,
|
pThreadMod->entry.add.threadID,
|
||||||
dstFp, pNewThread, nil);
|
dstFp, pNewThread, NULL);
|
||||||
/* fall through with err */
|
/* fall through with err */
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -929,7 +929,7 @@ Nu_ConstructArchiveThreads(NuArchive* pArchive, NuRecord* pRecord,
|
|||||||
*/
|
*/
|
||||||
for (idx = 0; idx < (int)pRecord->recTotalThreads; idx++) {
|
for (idx = 0; idx < (int)pRecord->recTotalThreads; idx++) {
|
||||||
pThread = Nu_GetThread(pRecord, idx);
|
pThread = Nu_GetThread(pRecord, idx);
|
||||||
Assert(pThread != nil);
|
Assert(pThread != NULL);
|
||||||
|
|
||||||
DBUG(("+++ THREAD #%d (used=%d)\n", idx, pThread->used));
|
DBUG(("+++ THREAD #%d (used=%d)\n", idx, pThread->used));
|
||||||
if (threadID == kNuThreadIDWildcard ||
|
if (threadID == kNuThreadIDWildcard ||
|
||||||
@ -944,7 +944,7 @@ Nu_ConstructArchiveThreads(NuArchive* pArchive, NuRecord* pRecord,
|
|||||||
pThreadMod = Nu_ThreadMod_FindByThreadIdx(pRecord,
|
pThreadMod = Nu_ThreadMod_FindByThreadIdx(pRecord,
|
||||||
pThread->threadIdx);
|
pThread->threadIdx);
|
||||||
|
|
||||||
if (pThreadMod != nil) {
|
if (pThreadMod != NULL) {
|
||||||
/*
|
/*
|
||||||
* The thread has a related ThreadMod. Deal with it.
|
* The thread has a related ThreadMod. Deal with it.
|
||||||
*/
|
*/
|
||||||
@ -1060,14 +1060,14 @@ static NuError
|
|||||||
Nu_ConstructArchiveRecord(NuArchive* pArchive, NuRecord* pRecord)
|
Nu_ConstructArchiveRecord(NuArchive* pArchive, NuRecord* pRecord)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
NuNewThreads* pNewThreads = nil;
|
NuNewThreads* pNewThreads = NULL;
|
||||||
long threadDisp;
|
long threadDisp;
|
||||||
long initialOffset, finalOffset;
|
long initialOffset, finalOffset;
|
||||||
long numThreads, numFilenameThreads;
|
long numThreads, numFilenameThreads;
|
||||||
int newHeaderSize;
|
int newHeaderSize;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pRecord != nil);
|
Assert(pRecord != NULL);
|
||||||
|
|
||||||
DBUG(("--- Reconstructing '%s'\n", pRecord->filename));
|
DBUG(("--- Reconstructing '%s'\n", pRecord->filename));
|
||||||
|
|
||||||
@ -1102,19 +1102,19 @@ Nu_ConstructArchiveRecord(NuArchive* pArchive, NuRecord* pRecord)
|
|||||||
/* looks like a previously existing filename thread got removed */
|
/* looks like a previously existing filename thread got removed */
|
||||||
DBUG(("--- Dropping thread filename '%s'\n", pRecord->threadFilename));
|
DBUG(("--- Dropping thread filename '%s'\n", pRecord->threadFilename));
|
||||||
if (pRecord->filename == pRecord->threadFilename)
|
if (pRecord->filename == pRecord->threadFilename)
|
||||||
pRecord->filename = nil; /* don't point at freed memory! */
|
pRecord->filename = NULL; /* don't point at freed memory! */
|
||||||
Nu_Free(pArchive, pRecord->threadFilename);
|
Nu_Free(pArchive, pRecord->threadFilename);
|
||||||
pRecord->threadFilename = nil;
|
pRecord->threadFilename = NULL;
|
||||||
|
|
||||||
/* I don't think this is possible, but check it anyway */
|
/* I don't think this is possible, but check it anyway */
|
||||||
if (pRecord->filename == nil && pRecord->recFilename != nil &&
|
if (pRecord->filename == NULL && pRecord->recFilename != NULL &&
|
||||||
!pRecord->dropRecFilename)
|
!pRecord->dropRecFilename)
|
||||||
{
|
{
|
||||||
DBUG(("--- HEY, how did this happen?\n"));
|
DBUG(("--- HEY, how did this happen?\n"));
|
||||||
pRecord->filename = pRecord->recFilename;
|
pRecord->filename = pRecord->recFilename;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pRecord->filename == nil)
|
if (pRecord->filename == NULL)
|
||||||
pRecord->filename = kNuDefaultRecordName;
|
pRecord->filename = kNuDefaultRecordName;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1265,15 +1265,15 @@ static NuError
|
|||||||
Nu_ConstructNewRecord(NuArchive* pArchive, NuRecord* pRecord, FILE* fp)
|
Nu_ConstructNewRecord(NuArchive* pArchive, NuRecord* pRecord, FILE* fp)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
NuNewThreads* pNewThreads = nil;
|
NuNewThreads* pNewThreads = NULL;
|
||||||
NuThreadMod* pThreadMod;
|
NuThreadMod* pThreadMod;
|
||||||
long threadDisp;
|
long threadDisp;
|
||||||
long initialOffset, finalOffset;
|
long initialOffset, finalOffset;
|
||||||
long numThreadMods, numFilenameThreads;
|
long numThreadMods, numFilenameThreads;
|
||||||
int newHeaderSize;
|
int newHeaderSize;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pRecord != nil);
|
Assert(pRecord != NULL);
|
||||||
|
|
||||||
DBUG(("--- Constructing '%s'\n", pRecord->filename));
|
DBUG(("--- Constructing '%s'\n", pRecord->filename));
|
||||||
|
|
||||||
@ -1287,7 +1287,7 @@ Nu_ConstructNewRecord(NuArchive* pArchive, NuRecord* pRecord, FILE* fp)
|
|||||||
* make ourselves useful by counting up the number of eventual
|
* make ourselves useful by counting up the number of eventual
|
||||||
* threads, and verify that there is exactly one filename thread.
|
* threads, and verify that there is exactly one filename thread.
|
||||||
*/
|
*/
|
||||||
Assert(pRecord->pThreads == nil);
|
Assert(pRecord->pThreads == NULL);
|
||||||
|
|
||||||
numThreadMods = 0;
|
numThreadMods = 0;
|
||||||
numFilenameThreads = 0;
|
numFilenameThreads = 0;
|
||||||
@ -1312,15 +1312,15 @@ Nu_ConstructNewRecord(NuArchive* pArchive, NuRecord* pRecord, FILE* fp)
|
|||||||
* records when the application doesn't explicitly add a thread.
|
* records when the application doesn't explicitly add a thread.
|
||||||
*/
|
*/
|
||||||
if (!numFilenameThreads) {
|
if (!numFilenameThreads) {
|
||||||
NuDataSource* pTmpDataSource = nil;
|
NuDataSource* pTmpDataSource = NULL;
|
||||||
NuThreadMod* pNewThreadMod = nil;
|
NuThreadMod* pNewThreadMod = NULL;
|
||||||
int len, maxLen;
|
int len, maxLen;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Generally speaking, the "add file" call should set the
|
* Generally speaking, the "add file" call should set the
|
||||||
* filename. If somehow it didn't, assign a default.
|
* filename. If somehow it didn't, assign a default.
|
||||||
*/
|
*/
|
||||||
if (pRecord->filename == nil) {
|
if (pRecord->filename == NULL) {
|
||||||
pRecord->newFilename = strdup(kNuDefaultRecordName);
|
pRecord->newFilename = strdup(kNuDefaultRecordName);
|
||||||
pRecord->filename = pRecord->newFilename;
|
pRecord->filename = pRecord->newFilename;
|
||||||
}
|
}
|
||||||
@ -1340,7 +1340,7 @@ Nu_ConstructNewRecord(NuArchive* pArchive, NuRecord* pRecord, FILE* fp)
|
|||||||
len : kNuDefaultFilenameThreadSize;
|
len : kNuDefaultFilenameThreadSize;
|
||||||
err = Nu_DataSourceBuffer_New(kNuThreadFormatUncompressed,
|
err = Nu_DataSourceBuffer_New(kNuThreadFormatUncompressed,
|
||||||
maxLen, (const uchar*)pRecord->filename, 0,
|
maxLen, (const uchar*)pRecord->filename, 0,
|
||||||
strlen(pRecord->filename), nil, &pTmpDataSource);
|
strlen(pRecord->filename), NULL, &pTmpDataSource);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
|
|
||||||
/* put in a new "add" threadMod (which copies the data source) */
|
/* put in a new "add" threadMod (which copies the data source) */
|
||||||
@ -1351,7 +1351,7 @@ Nu_ConstructNewRecord(NuArchive* pArchive, NuRecord* pRecord, FILE* fp)
|
|||||||
|
|
||||||
/* add it to the list */
|
/* add it to the list */
|
||||||
Nu_RecordAddThreadMod(pRecord, pNewThreadMod);
|
Nu_RecordAddThreadMod(pRecord, pNewThreadMod);
|
||||||
pNewThreadMod = nil;
|
pNewThreadMod = NULL;
|
||||||
|
|
||||||
numFilenameThreads++;
|
numFilenameThreads++;
|
||||||
numThreadMods++;
|
numThreadMods++;
|
||||||
@ -1431,7 +1431,7 @@ Nu_ConstructNewRecord(NuArchive* pArchive, NuRecord* pRecord, FILE* fp)
|
|||||||
/*
|
/*
|
||||||
* Install pNewThreads as the thread list.
|
* Install pNewThreads as the thread list.
|
||||||
*/
|
*/
|
||||||
Assert(pRecord->pThreads == nil && pRecord->recTotalThreads == 0);
|
Assert(pRecord->pThreads == NULL && pRecord->recTotalThreads == 0);
|
||||||
pRecord->pThreads = Nu_NewThreads_DonateThreads(pNewThreads);
|
pRecord->pThreads = Nu_NewThreads_DonateThreads(pNewThreads);
|
||||||
pRecord->recTotalThreads = Nu_NewThreads_GetNumThreads(pNewThreads);
|
pRecord->recTotalThreads = Nu_NewThreads_GetNumThreads(pNewThreads);
|
||||||
|
|
||||||
@ -1501,7 +1501,7 @@ Nu_UpdateRecordInOriginal(NuArchive* pArchive, NuRecord* pRecord)
|
|||||||
* Loop through all threadMods.
|
* Loop through all threadMods.
|
||||||
*/
|
*/
|
||||||
pThreadMod = pRecord->pThreadMods;
|
pThreadMod = pRecord->pThreadMods;
|
||||||
while (pThreadMod != nil) {
|
while (pThreadMod != NULL) {
|
||||||
Assert(pThreadMod->entry.kind == kNuThreadModUpdate);
|
Assert(pThreadMod->entry.kind == kNuThreadModUpdate);
|
||||||
|
|
||||||
/* find the thread associated with this threadMod */
|
/* find the thread associated with this threadMod */
|
||||||
@ -1547,7 +1547,7 @@ Nu_UpdateRecordInOriginal(NuArchive* pArchive, NuRecord* pRecord)
|
|||||||
DBUG(("--- record header wrote %ld bytes\n",
|
DBUG(("--- record header wrote %ld bytes\n",
|
||||||
pArchive->currentOffset - pRecord->fileOffset));
|
pArchive->currentOffset - pRecord->fileOffset));
|
||||||
pThread = pRecord->pThreads;
|
pThread = pRecord->pThreads;
|
||||||
if (pThread != nil && pArchive->currentOffset != pThread->fileOffset) {
|
if (pThread != NULL && pArchive->currentOffset != pThread->fileOffset) {
|
||||||
/* guess what, we just trashed the archive */
|
/* guess what, we just trashed the archive */
|
||||||
err = kNuErrDamaged;
|
err = kNuErrDamaged;
|
||||||
Nu_ReportError(NU_BLOB, err,
|
Nu_ReportError(NU_BLOB, err,
|
||||||
@ -1631,8 +1631,8 @@ Nu_CreateTempFromOriginal(NuArchive* pArchive)
|
|||||||
* record header, but since all we do is copy the data anyway,
|
* record header, but since all we do is copy the data anyway,
|
||||||
* it's not much slower.
|
* it's not much slower.
|
||||||
*/
|
*/
|
||||||
while (pRecord != nil) {
|
while (pRecord != NULL) {
|
||||||
if (!pRecord->dirtyHeader && pRecord->pThreadMods == nil) {
|
if (!pRecord->dirtyHeader && pRecord->pThreadMods == NULL) {
|
||||||
err = Nu_CopyArchiveRecord(pArchive, pRecord);
|
err = Nu_CopyArchiveRecord(pArchive, pRecord);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
} else {
|
} else {
|
||||||
@ -1690,8 +1690,8 @@ Nu_UpdateInOriginal(NuArchive* pArchive)
|
|||||||
* Run through and process all the updates.
|
* Run through and process all the updates.
|
||||||
*/
|
*/
|
||||||
pRecord = Nu_RecordSet_GetListHead(&pArchive->copyRecordSet);
|
pRecord = Nu_RecordSet_GetListHead(&pArchive->copyRecordSet);
|
||||||
while (pRecord != nil) {
|
while (pRecord != NULL) {
|
||||||
if (pRecord->dirtyHeader || pRecord->pThreadMods != nil) {
|
if (pRecord->dirtyHeader || pRecord->pThreadMods != NULL) {
|
||||||
err = Nu_UpdateRecordInOriginal(pArchive, pRecord);
|
err = Nu_UpdateRecordInOriginal(pArchive, pRecord);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
}
|
}
|
||||||
@ -1724,7 +1724,7 @@ Nu_CreateNewRecords(NuArchive* pArchive, FILE* fp)
|
|||||||
NuRecord* pRecord;
|
NuRecord* pRecord;
|
||||||
|
|
||||||
pRecord = Nu_RecordSet_GetListHead(&pArchive->newRecordSet);
|
pRecord = Nu_RecordSet_GetListHead(&pArchive->newRecordSet);
|
||||||
while (pRecord != nil) {
|
while (pRecord != NULL) {
|
||||||
err = Nu_ConstructNewRecord(pArchive, pRecord, fp);
|
err = Nu_ConstructNewRecord(pArchive, pRecord, fp);
|
||||||
if (err == kNuErrSkipped) {
|
if (err == kNuErrSkipped) {
|
||||||
/*
|
/*
|
||||||
@ -1801,10 +1801,10 @@ Nu_NoHeavyUpdates(NuArchive* pArchive)
|
|||||||
while (count--) {
|
while (count--) {
|
||||||
const NuThreadMod* pThreadMod;
|
const NuThreadMod* pThreadMod;
|
||||||
|
|
||||||
Assert(pRecord != nil);
|
Assert(pRecord != NULL);
|
||||||
|
|
||||||
pThreadMod = pRecord->pThreadMods;
|
pThreadMod = pRecord->pThreadMods;
|
||||||
while (pThreadMod != nil) {
|
while (pThreadMod != NULL) {
|
||||||
/* the only acceptable kind is "update" */
|
/* the only acceptable kind is "update" */
|
||||||
if (pThreadMod->entry.kind != kNuThreadModUpdate)
|
if (pThreadMod->entry.kind != kNuThreadModUpdate)
|
||||||
return false;
|
return false;
|
||||||
@ -1835,18 +1835,18 @@ Nu_PurgeEmptyRecords(NuArchive* pArchive, NuRecordSet* pRecordSet)
|
|||||||
NuRecord* pRecord;
|
NuRecord* pRecord;
|
||||||
NuRecord** ppRecord;
|
NuRecord** ppRecord;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pRecordSet != nil);
|
Assert(pRecordSet != NULL);
|
||||||
|
|
||||||
if (Nu_RecordSet_IsEmpty(pRecordSet))
|
if (Nu_RecordSet_IsEmpty(pRecordSet))
|
||||||
return kNuErrNone;
|
return kNuErrNone;
|
||||||
|
|
||||||
ppRecord = Nu_RecordSet_GetListHeadPtr(pRecordSet);
|
ppRecord = Nu_RecordSet_GetListHeadPtr(pRecordSet);
|
||||||
Assert(ppRecord != nil);
|
Assert(ppRecord != NULL);
|
||||||
Assert(*ppRecord != nil);
|
Assert(*ppRecord != NULL);
|
||||||
|
|
||||||
/* maintain a pointer to the pointer, so we can delete easily */
|
/* maintain a pointer to the pointer, so we can delete easily */
|
||||||
while (*ppRecord != nil) {
|
while (*ppRecord != NULL) {
|
||||||
pRecord = *ppRecord;
|
pRecord = *ppRecord;
|
||||||
|
|
||||||
if (Nu_RecordIsEmpty(pArchive, pRecord)) {
|
if (Nu_RecordIsEmpty(pArchive, pRecord)) {
|
||||||
@ -1923,11 +1923,11 @@ Nu_ResetTempFile(NuArchive* pArchive)
|
|||||||
if (Nu_IsReadOnly(pArchive))
|
if (Nu_IsReadOnly(pArchive))
|
||||||
return kNuErrNone; /* or kNuErrArchiveRO? */
|
return kNuErrNone; /* or kNuErrArchiveRO? */
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pArchive->tmpPathname != nil);
|
Assert(pArchive->tmpPathname != NULL);
|
||||||
|
|
||||||
#if 0 /* keep the temp file around for examination */
|
#if 0 /* keep the temp file around for examination */
|
||||||
if (pArchive->tmpFp != nil) {
|
if (pArchive->tmpFp != NULL) {
|
||||||
DBUG(("--- NOT Resetting temp file\n"));
|
DBUG(("--- NOT Resetting temp file\n"));
|
||||||
fflush(pArchive->tmpFp);
|
fflush(pArchive->tmpFp);
|
||||||
goto bail;
|
goto bail;
|
||||||
@ -1937,9 +1937,9 @@ if (pArchive->tmpFp != nil) {
|
|||||||
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 we renamed the temp over the original, we need to open a new temp */
|
||||||
if (pArchive->tmpFp == nil) {
|
if (pArchive->tmpFp == NULL) {
|
||||||
pArchive->tmpFp = fopen(pArchive->tmpPathname, kNuFileOpenReadWriteCreat);
|
pArchive->tmpFp = fopen(pArchive->tmpPathname, kNuFileOpenReadWriteCreat);
|
||||||
if (pArchive->tmpFp == nil) {
|
if (pArchive->tmpFp == NULL) {
|
||||||
err = errno ? errno : kNuErrFileOpen;
|
err = errno ? errno : kNuErrFileOpen;
|
||||||
Nu_ReportError(NU_BLOB, errno, "Unable to open temp file '%s'",
|
Nu_ReportError(NU_BLOB, errno, "Unable to open temp file '%s'",
|
||||||
pArchive->tmpPathname);
|
pArchive->tmpPathname);
|
||||||
@ -1957,7 +1957,7 @@ if (pArchive->tmpFp != nil) {
|
|||||||
err = kNuErrNone;
|
err = kNuErrNone;
|
||||||
fclose(pArchive->tmpFp);
|
fclose(pArchive->tmpFp);
|
||||||
pArchive->tmpFp = fopen(pArchive->tmpPathname, kNuFileOpenWriteTrunc);
|
pArchive->tmpFp = fopen(pArchive->tmpPathname, kNuFileOpenWriteTrunc);
|
||||||
if (pArchive->tmpFp == nil) {
|
if (pArchive->tmpFp == NULL) {
|
||||||
err = errno ? errno : kNuErrFileOpen;
|
err = errno ? errno : kNuErrFileOpen;
|
||||||
Nu_ReportError(NU_BLOB, err, "failed truncating tmp file");
|
Nu_ReportError(NU_BLOB, err, "failed truncating tmp file");
|
||||||
goto bail;
|
goto bail;
|
||||||
@ -1965,7 +1965,7 @@ if (pArchive->tmpFp != nil) {
|
|||||||
fclose(pArchive->tmpFp);
|
fclose(pArchive->tmpFp);
|
||||||
pArchive->tmpFp =
|
pArchive->tmpFp =
|
||||||
fopen(pArchive->tmpPathname, kNuFileOpenReadWriteCreat);
|
fopen(pArchive->tmpPathname, kNuFileOpenReadWriteCreat);
|
||||||
if (pArchive->tmpFp == nil) {
|
if (pArchive->tmpFp == NULL) {
|
||||||
err = errno ? errno : kNuErrFileOpen;
|
err = errno ? errno : kNuErrFileOpen;
|
||||||
Nu_ReportError(NU_BLOB, err, "Unable to open temp file '%s'",
|
Nu_ReportError(NU_BLOB, err, "Unable to open temp file '%s'",
|
||||||
pArchive->tmpPathname);
|
pArchive->tmpPathname);
|
||||||
@ -1990,8 +1990,8 @@ Nu_RecordResetUsedFlags(NuArchive* pArchive, NuRecord* pRecord)
|
|||||||
NuThread* pThread;
|
NuThread* pThread;
|
||||||
long idx;
|
long idx;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pRecord != nil);
|
Assert(pRecord != NULL);
|
||||||
|
|
||||||
/* these should already be clear */
|
/* these should already be clear */
|
||||||
if (pRecord->pThreadMods) {
|
if (pRecord->pThreadMods) {
|
||||||
@ -2002,7 +2002,7 @@ Nu_RecordResetUsedFlags(NuArchive* pArchive, NuRecord* pRecord)
|
|||||||
/* these might still be set */
|
/* these might still be set */
|
||||||
for (idx = 0; idx < (long)pRecord->recTotalThreads; idx++) {
|
for (idx = 0; idx < (long)pRecord->recTotalThreads; idx++) {
|
||||||
pThread = Nu_GetThread(pRecord, idx);
|
pThread = Nu_GetThread(pRecord, idx);
|
||||||
Assert(pThread != nil);
|
Assert(pThread != NULL);
|
||||||
|
|
||||||
pThread->used = false;
|
pThread->used = false;
|
||||||
}
|
}
|
||||||
@ -2023,7 +2023,7 @@ Nu_ResetUsedFlags(NuArchive* pArchive, NuRecordSet* pRecordSet)
|
|||||||
NuRecord* pRecord;
|
NuRecord* pRecord;
|
||||||
|
|
||||||
pRecord = Nu_RecordSet_GetListHead(pRecordSet);
|
pRecord = Nu_RecordSet_GetListHead(pRecordSet);
|
||||||
while (pRecord != nil) {
|
while (pRecord != NULL) {
|
||||||
err = Nu_RecordResetUsedFlags(pArchive, pRecord);
|
err = Nu_RecordResetUsedFlags(pArchive, pRecord);
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
Assert(0);
|
Assert(0);
|
||||||
@ -2054,8 +2054,8 @@ Nu_ResetCopySetIfUntouched(NuArchive* pArchive)
|
|||||||
|
|
||||||
/* do we have any thread mods or dirty record headers? */
|
/* do we have any thread mods or dirty record headers? */
|
||||||
pRecord = Nu_RecordSet_GetListHead(&pArchive->copyRecordSet);
|
pRecord = Nu_RecordSet_GetListHead(&pArchive->copyRecordSet);
|
||||||
while (pRecord != nil) {
|
while (pRecord != NULL) {
|
||||||
if (pRecord->pThreadMods != nil || pRecord->dirtyHeader)
|
if (pRecord->pThreadMods != NULL || pRecord->dirtyHeader)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pRecord = pRecord->pNext;
|
pRecord = pRecord->pNext;
|
||||||
@ -2076,9 +2076,9 @@ Nu_AddCommentToFirstNewRecord(NuArchive* pArchive)
|
|||||||
{
|
{
|
||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
NuRecord* pRecord;
|
NuRecord* pRecord;
|
||||||
NuThreadMod* pThreadMod = nil;
|
NuThreadMod* pThreadMod = NULL;
|
||||||
NuThreadMod* pExistingThreadMod = nil;
|
NuThreadMod* pExistingThreadMod = NULL;
|
||||||
NuDataSource* pDataSource = nil;
|
NuDataSource* pDataSource = NULL;
|
||||||
|
|
||||||
/* if there aren't any records there, skip this */
|
/* if there aren't any records there, skip this */
|
||||||
if (Nu_RecordSet_IsEmpty(&pArchive->newRecordSet))
|
if (Nu_RecordSet_IsEmpty(&pArchive->newRecordSet))
|
||||||
@ -2100,20 +2100,20 @@ Nu_AddCommentToFirstNewRecord(NuArchive* pArchive)
|
|||||||
|
|
||||||
/* create a new data source with nothing in it */
|
/* create a new data source with nothing in it */
|
||||||
err = Nu_DataSourceBuffer_New(kNuThreadFormatUncompressed,
|
err = Nu_DataSourceBuffer_New(kNuThreadFormatUncompressed,
|
||||||
kNuDefaultCommentSize, nil, 0, 0, nil, &pDataSource);
|
kNuDefaultCommentSize, NULL, 0, 0, NULL, &pDataSource);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
Assert(pDataSource != nil);
|
Assert(pDataSource != NULL);
|
||||||
|
|
||||||
/* create a new ThreadMod */
|
/* create a new ThreadMod */
|
||||||
err = Nu_ThreadModAdd_New(pArchive, kNuThreadIDComment,
|
err = Nu_ThreadModAdd_New(pArchive, kNuThreadIDComment,
|
||||||
kNuThreadFormatUncompressed, pDataSource, &pThreadMod);
|
kNuThreadFormatUncompressed, pDataSource, &pThreadMod);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
Assert(pThreadMod != nil);
|
Assert(pThreadMod != NULL);
|
||||||
/*pDataSource = nil;*/ /* ThreadModAdd_New makes a copy */
|
/*pDataSource = NULL;*/ /* ThreadModAdd_New makes a copy */
|
||||||
|
|
||||||
/* add the thread mod to the record */
|
/* add the thread mod to the record */
|
||||||
Nu_RecordAddThreadMod(pRecord, pThreadMod);
|
Nu_RecordAddThreadMod(pRecord, pThreadMod);
|
||||||
pThreadMod = nil; /* don't free on exit */
|
pThreadMod = NULL; /* don't free on exit */
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
Nu_ThreadModFree(pArchive, pThreadMod);
|
Nu_ThreadModFree(pArchive, pThreadMod);
|
||||||
@ -2148,7 +2148,7 @@ Nu_Flush(NuArchive* pArchive, long* pStatusFlags)
|
|||||||
|
|
||||||
DBUG(("--- FLUSH\n"));
|
DBUG(("--- FLUSH\n"));
|
||||||
|
|
||||||
if (pStatusFlags == nil)
|
if (pStatusFlags == NULL)
|
||||||
return kNuErrInvalidArg;
|
return kNuErrInvalidArg;
|
||||||
/* these do get set on error, so clear them no matter what */
|
/* these do get set on error, so clear them no matter what */
|
||||||
*pStatusFlags = 0;
|
*pStatusFlags = 0;
|
||||||
@ -2410,7 +2410,7 @@ Nu_Flush(NuArchive* pArchive, long* pStatusFlags)
|
|||||||
*pStatusFlags |= kNuFlushSucceeded; /* temp file is fully valid */
|
*pStatusFlags |= kNuFlushSucceeded; /* temp file is fully valid */
|
||||||
|
|
||||||
fclose(pArchive->archiveFp);
|
fclose(pArchive->archiveFp);
|
||||||
pArchive->archiveFp = nil;
|
pArchive->archiveFp = NULL;
|
||||||
|
|
||||||
err = Nu_DeleteArchiveFile(pArchive);
|
err = Nu_DeleteArchiveFile(pArchive);
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
@ -2422,7 +2422,7 @@ Nu_Flush(NuArchive* pArchive, long* pStatusFlags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fclose(pArchive->tmpFp);
|
fclose(pArchive->tmpFp);
|
||||||
pArchive->tmpFp = nil;
|
pArchive->tmpFp = NULL;
|
||||||
|
|
||||||
err = Nu_RenameTempToArchive(pArchive);
|
err = Nu_RenameTempToArchive(pArchive);
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
@ -2431,9 +2431,9 @@ Nu_Flush(NuArchive* pArchive, long* pStatusFlags)
|
|||||||
"NOTE: only copy of archive is in '%s'", pArchive->tmpPathname);
|
"NOTE: only copy of archive is in '%s'", pArchive->tmpPathname);
|
||||||
/* maintain Entry.c semantics (and keep them from removing temp) */
|
/* maintain Entry.c semantics (and keep them from removing temp) */
|
||||||
Nu_Free(pArchive, pArchive->archivePathname);
|
Nu_Free(pArchive, pArchive->archivePathname);
|
||||||
pArchive->archivePathname = nil;
|
pArchive->archivePathname = NULL;
|
||||||
Nu_Free(pArchive, pArchive->tmpPathname);
|
Nu_Free(pArchive, pArchive->tmpPathname);
|
||||||
pArchive->tmpPathname = nil;
|
pArchive->tmpPathname = NULL;
|
||||||
/* bail will put us into read-only mode, which is what we want */
|
/* bail will put us into read-only mode, which is what we want */
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
@ -2441,7 +2441,7 @@ Nu_Flush(NuArchive* pArchive, long* pStatusFlags)
|
|||||||
bail_reopen:
|
bail_reopen:
|
||||||
pArchive->archiveFp = fopen(pArchive->archivePathname,
|
pArchive->archiveFp = fopen(pArchive->archivePathname,
|
||||||
kNuFileOpenReadWrite);
|
kNuFileOpenReadWrite);
|
||||||
if (pArchive->archiveFp == nil) {
|
if (pArchive->archiveFp == NULL) {
|
||||||
err = errno ? errno : -1;
|
err = errno ? errno : -1;
|
||||||
Nu_ReportError(NU_BLOB, err,
|
Nu_ReportError(NU_BLOB, err,
|
||||||
"unable to reopen archive file '%s' after rename",
|
"unable to reopen archive file '%s' after rename",
|
||||||
@ -2545,8 +2545,8 @@ bail:
|
|||||||
|
|
||||||
/* last-minute sanity check */
|
/* last-minute sanity check */
|
||||||
Assert(pArchive->origRecordSet.numRecords == 0 ||
|
Assert(pArchive->origRecordSet.numRecords == 0 ||
|
||||||
(pArchive->origRecordSet.nuRecordHead != nil &&
|
(pArchive->origRecordSet.nuRecordHead != NULL &&
|
||||||
pArchive->origRecordSet.nuRecordTail != nil));
|
pArchive->origRecordSet.nuRecordTail != NULL));
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -2558,7 +2558,7 @@ bail:
|
|||||||
NuError
|
NuError
|
||||||
Nu_Abort(NuArchive* pArchive)
|
Nu_Abort(NuArchive* pArchive)
|
||||||
{
|
{
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
|
|
||||||
if (Nu_IsReadOnly(pArchive))
|
if (Nu_IsReadOnly(pArchive))
|
||||||
return kNuErrArchiveRO;
|
return kNuErrArchiveRO;
|
||||||
|
@ -53,14 +53,14 @@ Nu_CompressDeflate(NuArchive* pArchive, NuStraw* pStraw, FILE* fp,
|
|||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
z_stream zstream;
|
z_stream zstream;
|
||||||
int zerr;
|
int zerr;
|
||||||
Bytef* outbuf = nil;
|
Bytef* outbuf = NULL;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pStraw != nil);
|
Assert(pStraw != NULL);
|
||||||
Assert(fp != nil);
|
Assert(fp != NULL);
|
||||||
Assert(srcLen > 0);
|
Assert(srcLen > 0);
|
||||||
Assert(pDstLen != nil);
|
Assert(pDstLen != NULL);
|
||||||
Assert(pCrc != nil);
|
Assert(pCrc != NULL);
|
||||||
|
|
||||||
err = Nu_AllocCompressionBufferIFN(pArchive);
|
err = Nu_AllocCompressionBufferIFN(pArchive);
|
||||||
if (err != kNuErrNone)
|
if (err != kNuErrNone)
|
||||||
@ -76,7 +76,7 @@ Nu_CompressDeflate(NuArchive* pArchive, NuStraw* pStraw, FILE* fp,
|
|||||||
zstream.zalloc = Nu_zalloc;
|
zstream.zalloc = Nu_zalloc;
|
||||||
zstream.zfree = Nu_zfree;
|
zstream.zfree = Nu_zfree;
|
||||||
zstream.opaque = pArchive;
|
zstream.opaque = pArchive;
|
||||||
zstream.next_in = nil;
|
zstream.next_in = NULL;
|
||||||
zstream.avail_in = 0;
|
zstream.avail_in = 0;
|
||||||
zstream.next_out = outbuf;
|
zstream.next_out = outbuf;
|
||||||
zstream.avail_out = kNuGenCompBufSize;
|
zstream.avail_out = kNuGenCompBufSize;
|
||||||
@ -159,7 +159,7 @@ z_bail:
|
|||||||
deflateEnd(&zstream); /* free up any allocated structures */
|
deflateEnd(&zstream); /* free up any allocated structures */
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (outbuf != nil)
|
if (outbuf != NULL)
|
||||||
free(outbuf);
|
free(outbuf);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -184,10 +184,10 @@ Nu_ExpandDeflate(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
ulong compRemaining;
|
ulong compRemaining;
|
||||||
Bytef* outbuf;
|
Bytef* outbuf;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pThread != nil);
|
Assert(pThread != NULL);
|
||||||
Assert(infp != nil);
|
Assert(infp != NULL);
|
||||||
Assert(pFunnel != nil);
|
Assert(pFunnel != NULL);
|
||||||
|
|
||||||
err = Nu_AllocCompressionBufferIFN(pArchive);
|
err = Nu_AllocCompressionBufferIFN(pArchive);
|
||||||
if (err != kNuErrNone)
|
if (err != kNuErrNone)
|
||||||
@ -205,7 +205,7 @@ Nu_ExpandDeflate(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
zstream.zalloc = Nu_zalloc;
|
zstream.zalloc = Nu_zalloc;
|
||||||
zstream.zfree = Nu_zfree;
|
zstream.zfree = Nu_zfree;
|
||||||
zstream.opaque = pArchive;
|
zstream.opaque = pArchive;
|
||||||
zstream.next_in = nil;
|
zstream.next_in = NULL;
|
||||||
zstream.avail_in = 0;
|
zstream.avail_in = 0;
|
||||||
zstream.next_out = outbuf;
|
zstream.next_out = outbuf;
|
||||||
zstream.avail_out = kNuGenCompBufSize;
|
zstream.avail_out = kNuGenCompBufSize;
|
||||||
@ -269,7 +269,7 @@ Nu_ExpandDeflate(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
goto z_bail;
|
goto z_bail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pCrc != nil)
|
if (pCrc != NULL)
|
||||||
*pCrc = Nu_CalcCRC16(*pCrc, outbuf, zstream.next_out - outbuf);
|
*pCrc = Nu_CalcCRC16(*pCrc, outbuf, zstream.next_out - outbuf);
|
||||||
|
|
||||||
zstream.next_out = outbuf;
|
zstream.next_out = outbuf;
|
||||||
@ -291,7 +291,7 @@ z_bail:
|
|||||||
inflateEnd(&zstream); /* free up any allocated structures */
|
inflateEnd(&zstream); /* free up any allocated structures */
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (outbuf != nil)
|
if (outbuf != NULL)
|
||||||
free(outbuf);
|
free(outbuf);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ Nu_ClearBusy(NuArchive* pArchive)
|
|||||||
static NuError
|
static NuError
|
||||||
Nu_PartiallyValidateNuArchive(const NuArchive* pArchive)
|
Nu_PartiallyValidateNuArchive(const NuArchive* pArchive)
|
||||||
{
|
{
|
||||||
if (pArchive == nil)
|
if (pArchive == NULL)
|
||||||
return kNuErrInvalidArg;
|
return kNuErrInvalidArg;
|
||||||
|
|
||||||
pArchive = pArchive;
|
pArchive = pArchive;
|
||||||
@ -77,19 +77,19 @@ Nu_ValidateNuArchive(const NuArchive* pArchive)
|
|||||||
/* make sure the TOC state is consistent */
|
/* make sure the TOC state is consistent */
|
||||||
if (pArchive->haveToc) {
|
if (pArchive->haveToc) {
|
||||||
if (pArchive->masterHeader.mhTotalRecords != 0)
|
if (pArchive->masterHeader.mhTotalRecords != 0)
|
||||||
Assert(Nu_RecordSet_GetListHead(&pArchive->origRecordSet) != nil);
|
Assert(Nu_RecordSet_GetListHead(&pArchive->origRecordSet) != NULL);
|
||||||
Assert(Nu_RecordSet_GetNumRecords(&pArchive->origRecordSet) ==
|
Assert(Nu_RecordSet_GetNumRecords(&pArchive->origRecordSet) ==
|
||||||
pArchive->masterHeader.mhTotalRecords);
|
pArchive->masterHeader.mhTotalRecords);
|
||||||
} else {
|
} else {
|
||||||
Assert(Nu_RecordSet_GetListHead(&pArchive->origRecordSet) == nil);
|
Assert(Nu_RecordSet_GetListHead(&pArchive->origRecordSet) == NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* make sure we have open files to work with */
|
/* make sure we have open files to work with */
|
||||||
Assert(pArchive->archivePathname == nil || pArchive->archiveFp != nil);
|
Assert(pArchive->archivePathname == NULL || pArchive->archiveFp != NULL);
|
||||||
if (pArchive->archivePathname != nil && pArchive->archiveFp == nil)
|
if (pArchive->archivePathname != NULL && pArchive->archiveFp == NULL)
|
||||||
return kNuErrInternal;
|
return kNuErrInternal;
|
||||||
Assert(pArchive->tmpPathname == nil || pArchive->tmpFp != nil);
|
Assert(pArchive->tmpPathname == NULL || pArchive->tmpFp != NULL);
|
||||||
if (pArchive->tmpPathname != nil && pArchive->tmpFp == nil)
|
if (pArchive->tmpPathname != NULL && pArchive->tmpFp == NULL)
|
||||||
return kNuErrInternal;
|
return kNuErrInternal;
|
||||||
|
|
||||||
/* further validations */
|
/* further validations */
|
||||||
@ -109,7 +109,7 @@ NuStreamOpenRO(FILE* infp, NuArchive** ppArchive)
|
|||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
|
|
||||||
if (infp == nil || ppArchive == nil)
|
if (infp == NULL || ppArchive == NULL)
|
||||||
return kNuErrInvalidArg;
|
return kNuErrInvalidArg;
|
||||||
|
|
||||||
err = Nu_StreamOpenRO(infp, (NuArchive**) ppArchive);
|
err = Nu_StreamOpenRO(infp, (NuArchive**) ppArchive);
|
||||||
@ -328,7 +328,7 @@ NuAddRecord(NuArchive* pArchive, const NuFileDetails* pFileDetails,
|
|||||||
|
|
||||||
if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) {
|
if ((err = Nu_ValidateNuArchive(pArchive)) == kNuErrNone) {
|
||||||
Nu_SetBusy(pArchive);
|
Nu_SetBusy(pArchive);
|
||||||
err = Nu_AddRecord(pArchive, pFileDetails, pRecordIdx, nil);
|
err = Nu_AddRecord(pArchive, pFileDetails, pRecordIdx, NULL);
|
||||||
Nu_ClearBusy(pArchive);
|
Nu_ClearBusy(pArchive);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -496,7 +496,7 @@ NuGetExtraData(NuArchive* pArchive, void** ppData)
|
|||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
|
|
||||||
if (ppData == nil)
|
if (ppData == NULL)
|
||||||
return kNuErrInvalidArg;
|
return kNuErrInvalidArg;
|
||||||
if ((err = Nu_PartiallyValidateNuArchive(pArchive)) == kNuErrNone)
|
if ((err = Nu_PartiallyValidateNuArchive(pArchive)) == kNuErrNone)
|
||||||
*ppData = pArchive->extraData;
|
*ppData = pArchive->extraData;
|
||||||
@ -604,7 +604,7 @@ NuFreeDataSource(NuDataSource* pDataSource)
|
|||||||
NUFXLIB_API NuError
|
NUFXLIB_API NuError
|
||||||
NuDataSourceSetRawCrc(NuDataSource* pDataSource, unsigned short crc)
|
NuDataSourceSetRawCrc(NuDataSource* pDataSource, unsigned short crc)
|
||||||
{
|
{
|
||||||
if (pDataSource == nil)
|
if (pDataSource == NULL)
|
||||||
return kNuErrInvalidArg;
|
return kNuErrInvalidArg;
|
||||||
Nu_DataSourceSetRawCrc(pDataSource, crc);
|
Nu_DataSourceSetRawCrc(pDataSource, crc);
|
||||||
return kNuErrNone;
|
return kNuErrNone;
|
||||||
@ -643,7 +643,7 @@ NuFreeDataSink(NuDataSink* pDataSink)
|
|||||||
NUFXLIB_API NuError
|
NUFXLIB_API NuError
|
||||||
NuDataSinkGetOutCount(NuDataSink* pDataSink, ulong* pOutCount)
|
NuDataSinkGetOutCount(NuDataSink* pDataSink, ulong* pOutCount)
|
||||||
{
|
{
|
||||||
if (pDataSink == nil || pOutCount == nil)
|
if (pDataSink == NULL || pOutCount == NULL)
|
||||||
return kNuErrInvalidArg;
|
return kNuErrInvalidArg;
|
||||||
|
|
||||||
*pOutCount = Nu_DataSinkGetOutCount(pDataSink);
|
*pOutCount = Nu_DataSinkGetOutCount(pDataSink);
|
||||||
@ -726,13 +726,13 @@ NuRecordCopyAttr(NuRecordAttr* pRecordAttr, const NuRecord* pRecord)
|
|||||||
NUFXLIB_API NuError
|
NUFXLIB_API NuError
|
||||||
NuRecordCopyThreads(const NuRecord* pNuRecord, NuThread** ppThreads)
|
NuRecordCopyThreads(const NuRecord* pNuRecord, NuThread** ppThreads)
|
||||||
{
|
{
|
||||||
if (pNuRecord == nil || ppThreads == nil)
|
if (pNuRecord == NULL || ppThreads == NULL)
|
||||||
return kNuErrInvalidArg;
|
return kNuErrInvalidArg;
|
||||||
|
|
||||||
Assert(pNuRecord->pThreads != nil);
|
Assert(pNuRecord->pThreads != NULL);
|
||||||
|
|
||||||
*ppThreads = Nu_Malloc(nil, pNuRecord->recTotalThreads * sizeof(NuThread));
|
*ppThreads = Nu_Malloc(NULL, pNuRecord->recTotalThreads * sizeof(NuThread));
|
||||||
if (*ppThreads == nil)
|
if (*ppThreads == NULL)
|
||||||
return kNuErrMalloc;
|
return kNuErrMalloc;
|
||||||
|
|
||||||
memcpy(*ppThreads, pNuRecord->pThreads,
|
memcpy(*ppThreads, pNuRecord->pThreads,
|
||||||
@ -744,7 +744,7 @@ NuRecordCopyThreads(const NuRecord* pNuRecord, NuThread** ppThreads)
|
|||||||
NUFXLIB_API unsigned long
|
NUFXLIB_API unsigned long
|
||||||
NuRecordGetNumThreads(const NuRecord* pNuRecord)
|
NuRecordGetNumThreads(const NuRecord* pNuRecord)
|
||||||
{
|
{
|
||||||
if (pNuRecord == nil)
|
if (pNuRecord == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return pNuRecord->recTotalThreads;
|
return pNuRecord->recTotalThreads;
|
||||||
@ -753,8 +753,8 @@ NuRecordGetNumThreads(const NuRecord* pNuRecord)
|
|||||||
NUFXLIB_API const NuThread*
|
NUFXLIB_API const NuThread*
|
||||||
NuThreadGetByIdx(const NuThread* pNuThread, long idx)
|
NuThreadGetByIdx(const NuThread* pNuThread, long idx)
|
||||||
{
|
{
|
||||||
if (pNuThread == nil)
|
if (pNuThread == NULL)
|
||||||
return nil;
|
return NULL;
|
||||||
return &pNuThread[idx]; /* can't range-check here */
|
return &pNuThread[idx]; /* can't range-check here */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,13 +17,13 @@ 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;
|
NuError err;
|
||||||
/*uchar* buffer = nil;*/
|
/*uchar* buffer = NULL;*/
|
||||||
ulong count, getsize;
|
ulong count, getsize;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pThread != nil);
|
Assert(pThread != NULL);
|
||||||
Assert(infp != nil);
|
Assert(infp != NULL);
|
||||||
Assert(pFunnel != nil);
|
Assert(pFunnel != NULL);
|
||||||
|
|
||||||
/* doesn't have to be same size as funnel, but it's not a bad idea */
|
/* doesn't have to be same size as funnel, but it's not a bad idea */
|
||||||
/*buffer = Nu_Malloc(pArchive, kNuFunnelBufSize);*/
|
/*buffer = Nu_Malloc(pArchive, kNuFunnelBufSize);*/
|
||||||
@ -43,7 +43,7 @@ Nu_ExpandUncompressed(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
|
|
||||||
err = Nu_FRead(infp, pArchive->compBuf, getsize);
|
err = Nu_FRead(infp, pArchive->compBuf, getsize);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
if (pCrc != nil)
|
if (pCrc != NULL)
|
||||||
*pCrc = Nu_CalcCRC16(*pCrc, pArchive->compBuf, getsize);
|
*pCrc = Nu_CalcCRC16(*pCrc, pArchive->compBuf, getsize);
|
||||||
err = Nu_FunnelWrite(pArchive, pFunnel, pArchive->compBuf, getsize);
|
err = Nu_FunnelWrite(pArchive, pFunnel, pArchive->compBuf, getsize);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
@ -68,13 +68,13 @@ Nu_ExpandRaw(NuArchive* pArchive, const NuThread* pThread, FILE* infp,
|
|||||||
NuFunnel* pFunnel)
|
NuFunnel* pFunnel)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
/*uchar* buffer = nil;*/
|
/*uchar* buffer = NULL;*/
|
||||||
ulong count, getsize;
|
ulong count, getsize;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pThread != nil);
|
Assert(pThread != NULL);
|
||||||
Assert(infp != nil);
|
Assert(infp != NULL);
|
||||||
Assert(pFunnel != nil);
|
Assert(pFunnel != NULL);
|
||||||
|
|
||||||
/* doesn't have to be same size as funnel, but it's not a bad idea */
|
/* doesn't have to be same size as funnel, but it's not a bad idea */
|
||||||
/*buffer = Nu_Malloc(pArchive, kNuFunnelBufSize);*/
|
/*buffer = Nu_Malloc(pArchive, kNuFunnelBufSize);*/
|
||||||
@ -134,7 +134,7 @@ Nu_ExpandStream(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
* unfortunately, unprotected before v3.
|
* unfortunately, unprotected before v3.
|
||||||
*/
|
*/
|
||||||
calcCrc = kNuInitialThreadCRC;
|
calcCrc = kNuInitialThreadCRC;
|
||||||
pCalcCrc = nil;
|
pCalcCrc = NULL;
|
||||||
if (Nu_ThreadHasCRC(pRecord->recVersionNumber, NuGetThreadID(pThread)) &&
|
if (Nu_ThreadHasCRC(pRecord->recVersionNumber, NuGetThreadID(pThread)) &&
|
||||||
!pArchive->valIgnoreCRC)
|
!pArchive->valIgnoreCRC)
|
||||||
{
|
{
|
||||||
@ -205,7 +205,7 @@ Nu_ExpandStream(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
/*
|
/*
|
||||||
* If we have a CRC to check, check it.
|
* If we have a CRC to check, check it.
|
||||||
*/
|
*/
|
||||||
if (pCalcCrc != nil) {
|
if (pCalcCrc != NULL) {
|
||||||
if (calcCrc != pThread->thThreadCRC) {
|
if (calcCrc != pThread->thThreadCRC) {
|
||||||
if (!Nu_ShouldIgnoreBadCRC(pArchive, pRecord, kNuErrBadThreadCRC)) {
|
if (!Nu_ShouldIgnoreBadCRC(pArchive, pRecord, kNuErrBadThreadCRC)) {
|
||||||
err = kNuErrBadDataCRC;
|
err = kNuErrBadDataCRC;
|
||||||
|
134
nufxlib/FileIO.c
134
nufxlib/FileIO.c
@ -87,8 +87,8 @@ Nu_DateTimeToGMTSeconds(const NuDateTime* pDateTime, time_t* pWhen)
|
|||||||
struct tm tmbuf;
|
struct tm tmbuf;
|
||||||
time_t when;
|
time_t when;
|
||||||
|
|
||||||
Assert(pDateTime != nil);
|
Assert(pDateTime != NULL);
|
||||||
Assert(pWhen != nil);
|
Assert(pWhen != NULL);
|
||||||
|
|
||||||
tmbuf.tm_sec = pDateTime->second;
|
tmbuf.tm_sec = pDateTime->second;
|
||||||
tmbuf.tm_min = pDateTime->minute;
|
tmbuf.tm_min = pDateTime->minute;
|
||||||
@ -124,8 +124,8 @@ Nu_GMTSecondsToDateTime(const time_t* pWhen, NuDateTime *pDateTime)
|
|||||||
{
|
{
|
||||||
struct tm* ptm;
|
struct tm* ptm;
|
||||||
|
|
||||||
Assert(pWhen != nil);
|
Assert(pWhen != NULL);
|
||||||
Assert(pDateTime != nil);
|
Assert(pDateTime != NULL);
|
||||||
|
|
||||||
#if defined(HAVE_LOCALTIME_R) && defined(USE_REENTRANT_CALLS)
|
#if defined(HAVE_LOCALTIME_R) && defined(USE_REENTRANT_CALLS)
|
||||||
struct tm res;
|
struct tm res;
|
||||||
@ -152,11 +152,11 @@ Nu_GMTSecondsToDateTime(const time_t* pWhen, NuDateTime *pDateTime)
|
|||||||
void
|
void
|
||||||
Nu_SetCurrentDateTime(NuDateTime* pDateTime)
|
Nu_SetCurrentDateTime(NuDateTime* pDateTime)
|
||||||
{
|
{
|
||||||
Assert(pDateTime != nil);
|
Assert(pDateTime != NULL);
|
||||||
|
|
||||||
#if defined(UNIX_LIKE) || defined(WINDOWS_LIKE)
|
#if defined(UNIX_LIKE) || defined(WINDOWS_LIKE)
|
||||||
{
|
{
|
||||||
time_t now = time(nil);
|
time_t now = time(NULL);
|
||||||
Nu_GMTSecondsToDateTime(&now, pDateTime);
|
Nu_GMTSecondsToDateTime(&now, pDateTime);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -247,7 +247,7 @@ Nu_IsForkedFile(NuArchive* pArchive, const NuRecord* pRecord)
|
|||||||
|
|
||||||
for (i = 0; i < (int)pRecord->recTotalThreads; i++) {
|
for (i = 0; i < (int)pRecord->recTotalThreads; i++) {
|
||||||
pThread = Nu_GetThread(pRecord, i);
|
pThread = Nu_GetThread(pRecord, i);
|
||||||
Assert(pThread != nil);
|
Assert(pThread != NULL);
|
||||||
|
|
||||||
threadID = NuMakeThreadID(pThread->thThreadClass,pThread->thThreadKind);
|
threadID = NuMakeThreadID(pThread->thThreadClass,pThread->thThreadKind);
|
||||||
if (threadID == kNuThreadIDDataFork)
|
if (threadID == kNuThreadIDDataFork)
|
||||||
@ -272,9 +272,9 @@ Nu_GetFileInfo(NuArchive* pArchive, const char* pathname,
|
|||||||
NuFileInfo* pFileInfo)
|
NuFileInfo* pFileInfo)
|
||||||
{
|
{
|
||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pathname != nil);
|
Assert(pathname != NULL);
|
||||||
Assert(pFileInfo != nil);
|
Assert(pFileInfo != NULL);
|
||||||
|
|
||||||
pFileInfo->isValid = false;
|
pFileInfo->isValid = false;
|
||||||
|
|
||||||
@ -424,11 +424,11 @@ Nu_FileForkExists(NuArchive* pArchive, const char* pathname,
|
|||||||
{
|
{
|
||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pathname != nil);
|
Assert(pathname != NULL);
|
||||||
Assert(checkRsrcFork == true || checkRsrcFork == false);
|
Assert(checkRsrcFork == true || checkRsrcFork == false);
|
||||||
Assert(pExists != nil);
|
Assert(pExists != NULL);
|
||||||
Assert(pFileInfo != nil);
|
Assert(pFileInfo != NULL);
|
||||||
|
|
||||||
#if defined(MAC_LIKE)
|
#if defined(MAC_LIKE)
|
||||||
/*
|
/*
|
||||||
@ -440,7 +440,7 @@ Nu_FileForkExists(NuArchive* pArchive, const char* pathname,
|
|||||||
/*
|
/*
|
||||||
* Check the data fork.
|
* Check the data fork.
|
||||||
*/
|
*/
|
||||||
Assert(pArchive->lastFileCreated == nil);
|
Assert(pArchive->lastFileCreated == NULL);
|
||||||
err = Nu_GetFileInfo(pArchive, pathname, pFileInfo);
|
err = Nu_GetFileInfo(pArchive, pathname, pFileInfo);
|
||||||
if (err == kNuErrFileNotFound) {
|
if (err == kNuErrFileNotFound) {
|
||||||
err = kNuErrNone;
|
err = kNuErrNone;
|
||||||
@ -470,7 +470,7 @@ Nu_FileForkExists(NuArchive* pArchive, const char* pathname,
|
|||||||
* On Unix and Windows we ignore "isForkedFile" and "checkRsrcFork".
|
* On Unix and Windows we ignore "isForkedFile" and "checkRsrcFork".
|
||||||
* The file must not exist at all.
|
* The file must not exist at all.
|
||||||
*/
|
*/
|
||||||
Assert(pArchive->lastFileCreated == nil);
|
Assert(pArchive->lastFileCreated == NULL);
|
||||||
|
|
||||||
*pExists = true;
|
*pExists = true;
|
||||||
err = Nu_GetFileInfo(pArchive, pathname, pFileInfo);
|
err = Nu_GetFileInfo(pArchive, pathname, pFileInfo);
|
||||||
@ -515,9 +515,9 @@ Nu_SetFileDates(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
{
|
{
|
||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pRecord != nil);
|
Assert(pRecord != NULL);
|
||||||
Assert(pathname != nil);
|
Assert(pathname != NULL);
|
||||||
|
|
||||||
#if defined(UNIX_LIKE) || defined(WINDOWS_LIKE)
|
#if defined(UNIX_LIKE) || defined(WINDOWS_LIKE)
|
||||||
{
|
{
|
||||||
@ -584,9 +584,9 @@ Nu_SetFileAccess(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
{
|
{
|
||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pRecord != nil);
|
Assert(pRecord != NULL);
|
||||||
Assert(pathname != nil);
|
Assert(pathname != NULL);
|
||||||
|
|
||||||
#if defined(UNIX_LIKE) || defined(WINDOWS_LIKE)
|
#if defined(UNIX_LIKE) || defined(WINDOWS_LIKE)
|
||||||
/* only need to do something if the file was "locked" */
|
/* only need to do something if the file was "locked" */
|
||||||
@ -636,10 +636,10 @@ Nu_PrepareForWriting(NuArchive* pArchive, const char* pathname,
|
|||||||
char path[4096];
|
char path[4096];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pathname != nil);
|
Assert(pathname != NULL);
|
||||||
Assert(prepRsrc == true || prepRsrc == false);
|
Assert(prepRsrc == true || prepRsrc == false);
|
||||||
Assert(pFileInfo != nil);
|
Assert(pFileInfo != NULL);
|
||||||
|
|
||||||
Assert(pFileInfo->isValid == true);
|
Assert(pFileInfo->isValid == true);
|
||||||
|
|
||||||
@ -684,8 +684,8 @@ Nu_Mkdir(NuArchive* pArchive, const char* dir)
|
|||||||
{
|
{
|
||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(dir != nil);
|
Assert(dir != NULL);
|
||||||
|
|
||||||
#if defined(UNIX_LIKE)
|
#if defined(UNIX_LIKE)
|
||||||
if (mkdir(dir, S_IRWXU | S_IRGRP|S_IXGRP | S_IROTH|S_IXOTH) < 0) {
|
if (mkdir(dir, S_IRWXU | S_IRGRP|S_IXGRP | S_IROTH|S_IXOTH) < 0) {
|
||||||
@ -721,11 +721,11 @@ Nu_CreateSubdirIFN(NuArchive* pArchive, const char* pathStart,
|
|||||||
{
|
{
|
||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
NuFileInfo fileInfo;
|
NuFileInfo fileInfo;
|
||||||
char* tmpBuf = nil;
|
char* tmpBuf = NULL;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pathStart != nil);
|
Assert(pathStart != NULL);
|
||||||
Assert(pathEnd != nil);
|
Assert(pathEnd != NULL);
|
||||||
Assert(fssep != '\0');
|
Assert(fssep != '\0');
|
||||||
|
|
||||||
/* pathStart might have whole path, but we only want up to "pathEnd" */
|
/* pathStart might have whole path, but we only want up to "pathEnd" */
|
||||||
@ -736,7 +736,7 @@ Nu_CreateSubdirIFN(NuArchive* pArchive, const char* pathStart,
|
|||||||
if (err == kNuErrFileNotFound) {
|
if (err == kNuErrFileNotFound) {
|
||||||
/* dir doesn't exist; move up a level and check parent */
|
/* dir doesn't exist; move up a level and check parent */
|
||||||
pathEnd = strrchr(tmpBuf, fssep);
|
pathEnd = strrchr(tmpBuf, fssep);
|
||||||
if (pathEnd != nil) {
|
if (pathEnd != NULL) {
|
||||||
pathEnd--;
|
pathEnd--;
|
||||||
Assert(pathEnd >= tmpBuf);
|
Assert(pathEnd >= tmpBuf);
|
||||||
err = Nu_CreateSubdirIFN(pArchive, tmpBuf, pathEnd, fssep);
|
err = Nu_CreateSubdirIFN(pArchive, tmpBuf, pathEnd, fssep);
|
||||||
@ -777,8 +777,8 @@ Nu_CreatePathIFN(NuArchive* pArchive, const char* pathname, char fssep)
|
|||||||
const char* pathStart;
|
const char* pathStart;
|
||||||
const char* pathEnd;
|
const char* pathEnd;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pathname != nil);
|
Assert(pathname != NULL);
|
||||||
Assert(fssep != '\0');
|
Assert(fssep != '\0');
|
||||||
|
|
||||||
pathStart = pathname;
|
pathStart = pathname;
|
||||||
@ -790,7 +790,7 @@ Nu_CreatePathIFN(NuArchive* pArchive, const char* pathname, char fssep)
|
|||||||
|
|
||||||
/* NOTE: not expecting names like "foo/bar/ack/", with terminating fssep */
|
/* NOTE: not expecting names like "foo/bar/ack/", with terminating fssep */
|
||||||
pathEnd = strrchr(pathStart, fssep);
|
pathEnd = strrchr(pathStart, fssep);
|
||||||
if (pathEnd == nil) {
|
if (pathEnd == NULL) {
|
||||||
/* no subdirectory components found */
|
/* no subdirectory components found */
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
@ -841,7 +841,7 @@ Nu_OpenFileForWrite(NuArchive* pArchive, const char* pathname,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
*pFp = fopen(pathname, kNuFileOpenWriteTrunc);
|
*pFp = fopen(pathname, kNuFileOpenWriteTrunc);
|
||||||
if (*pFp == nil)
|
if (*pFp == NULL)
|
||||||
return errno ? errno : -1;
|
return errno ? errno : -1;
|
||||||
return kNuErrNone;
|
return kNuErrNone;
|
||||||
}
|
}
|
||||||
@ -867,20 +867,20 @@ Nu_OpenOutputFile(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
NuErrorStatus errorStatus;
|
NuErrorStatus errorStatus;
|
||||||
NuResult result;
|
NuResult result;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pRecord != nil);
|
Assert(pRecord != NULL);
|
||||||
Assert(pThread != nil);
|
Assert(pThread != NULL);
|
||||||
Assert(newPathname != nil);
|
Assert(newPathname != NULL);
|
||||||
Assert(pFp != nil);
|
Assert(pFp != NULL);
|
||||||
|
|
||||||
/* set up some defaults, in case something goes wrong */
|
/* set up some defaults, in case something goes wrong */
|
||||||
errorStatus.operation = kNuOpExtract;
|
errorStatus.operation = kNuOpExtract;
|
||||||
errorStatus.err = kNuErrInternal;
|
errorStatus.err = kNuErrInternal;
|
||||||
errorStatus.sysErr = 0;
|
errorStatus.sysErr = 0;
|
||||||
errorStatus.message = nil;
|
errorStatus.message = NULL;
|
||||||
errorStatus.pRecord = pRecord;
|
errorStatus.pRecord = pRecord;
|
||||||
errorStatus.pathname = newPathname;
|
errorStatus.pathname = newPathname;
|
||||||
errorStatus.origPathname = nil;
|
errorStatus.origPathname = NULL;
|
||||||
errorStatus.filenameSeparator = newFssep;
|
errorStatus.filenameSeparator = newFssep;
|
||||||
/*errorStatus.origArchiveTouched = false;*/
|
/*errorStatus.origArchiveTouched = false;*/
|
||||||
errorStatus.canAbort = true;
|
errorStatus.canAbort = true;
|
||||||
@ -926,7 +926,7 @@ Nu_OpenOutputFile(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
if ((pArchive->valOnlyUpdateOlder) &&
|
if ((pArchive->valOnlyUpdateOlder) &&
|
||||||
!Nu_IsOlder(&fileInfo.modWhen, &pRecord->recModWhen))
|
!Nu_IsOlder(&fileInfo.modWhen, &pRecord->recModWhen))
|
||||||
{
|
{
|
||||||
if (pArchive->errorHandlerFunc != nil) {
|
if (pArchive->errorHandlerFunc != NULL) {
|
||||||
errorStatus.err = kNuErrNotNewer;
|
errorStatus.err = kNuErrNotNewer;
|
||||||
result = (*pArchive->errorHandlerFunc)(pArchive, &errorStatus);
|
result = (*pArchive->errorHandlerFunc)(pArchive, &errorStatus);
|
||||||
|
|
||||||
@ -962,7 +962,7 @@ Nu_OpenOutputFile(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
* and extracting to a different file.
|
* and extracting to a different file.
|
||||||
*/
|
*/
|
||||||
if (pArchive->valHandleExisting == kNuMaybeOverwrite) {
|
if (pArchive->valHandleExisting == kNuMaybeOverwrite) {
|
||||||
if (pArchive->errorHandlerFunc != nil) {
|
if (pArchive->errorHandlerFunc != NULL) {
|
||||||
errorStatus.err = kNuErrFileExists;
|
errorStatus.err = kNuErrFileExists;
|
||||||
result = (*pArchive->errorHandlerFunc)(pArchive, &errorStatus);
|
result = (*pArchive->errorHandlerFunc)(pArchive, &errorStatus);
|
||||||
|
|
||||||
@ -1005,7 +1005,7 @@ Nu_OpenOutputFile(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
*/
|
*/
|
||||||
if (pArchive->valHandleExisting == kNuMustOverwrite) {
|
if (pArchive->valHandleExisting == kNuMustOverwrite) {
|
||||||
DBUG(("+++ can't freshen nonexistent file '%s'\n", newPathname));
|
DBUG(("+++ can't freshen nonexistent file '%s'\n", newPathname));
|
||||||
if (pArchive->errorHandlerFunc != nil) {
|
if (pArchive->errorHandlerFunc != NULL) {
|
||||||
errorStatus.err = kNuErrDuplicateNotFound;
|
errorStatus.err = kNuErrDuplicateNotFound;
|
||||||
|
|
||||||
/* give them a chance to rename */
|
/* give them a chance to rename */
|
||||||
@ -1110,9 +1110,9 @@ Nu_CloseOutputFile(NuArchive* pArchive, const NuRecord* pRecord, FILE* fp,
|
|||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pRecord != nil);
|
Assert(pRecord != NULL);
|
||||||
Assert(fp != nil);
|
Assert(fp != NULL);
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
@ -1169,7 +1169,7 @@ Nu_OpenFileForRead(NuArchive* pArchive, const char* pathname,
|
|||||||
Boolean openRsrc, FILE** pFp)
|
Boolean openRsrc, FILE** pFp)
|
||||||
{
|
{
|
||||||
*pFp = fopen(pathname, kNuFileOpenReadOnly);
|
*pFp = fopen(pathname, kNuFileOpenReadOnly);
|
||||||
if (*pFp == nil)
|
if (*pFp == NULL)
|
||||||
return errno ? errno : -1;
|
return errno ? errno : -1;
|
||||||
return kNuErrNone;
|
return kNuErrNone;
|
||||||
}
|
}
|
||||||
@ -1190,9 +1190,9 @@ Nu_OpenInputFile(NuArchive* pArchive, const char* pathname,
|
|||||||
NuErrorStatus errorStatus;
|
NuErrorStatus errorStatus;
|
||||||
NuResult result;
|
NuResult result;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pathname != nil);
|
Assert(pathname != NULL);
|
||||||
Assert(pFp != nil);
|
Assert(pFp != NULL);
|
||||||
|
|
||||||
#if defined(MAC_LIKE)
|
#if defined(MAC_LIKE)
|
||||||
char path[4096];
|
char path[4096];
|
||||||
@ -1214,14 +1214,14 @@ retry:
|
|||||||
if (err == ENOENT)
|
if (err == ENOENT)
|
||||||
openErr = kNuErrFileNotFound;
|
openErr = kNuErrFileNotFound;
|
||||||
|
|
||||||
if (pArchive->errorHandlerFunc != nil) {
|
if (pArchive->errorHandlerFunc != NULL) {
|
||||||
errorStatus.operation = kNuOpAdd;
|
errorStatus.operation = kNuOpAdd;
|
||||||
errorStatus.err = openErr;
|
errorStatus.err = openErr;
|
||||||
errorStatus.sysErr = 0;
|
errorStatus.sysErr = 0;
|
||||||
errorStatus.message = nil;
|
errorStatus.message = NULL;
|
||||||
errorStatus.pRecord = nil;
|
errorStatus.pRecord = NULL;
|
||||||
errorStatus.pathname = pathname;
|
errorStatus.pathname = pathname;
|
||||||
errorStatus.origPathname = nil;
|
errorStatus.origPathname = NULL;
|
||||||
errorStatus.filenameSeparator = '\0';
|
errorStatus.filenameSeparator = '\0';
|
||||||
/*errorStatus.origArchiveTouched = false;*/
|
/*errorStatus.origArchiveTouched = false;*/
|
||||||
errorStatus.canAbort = true;
|
errorStatus.canAbort = true;
|
||||||
@ -1258,7 +1258,7 @@ retry:
|
|||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (err == kNuErrNone) {
|
if (err == kNuErrNone) {
|
||||||
Assert(*pFp != nil);
|
Assert(*pFp != NULL);
|
||||||
} else {
|
} else {
|
||||||
if (err != kNuErrSkipped && err != kNuErrRename &&
|
if (err != kNuErrSkipped && err != kNuErrRename &&
|
||||||
err != kNuErrFileExists)
|
err != kNuErrFileExists)
|
||||||
@ -1332,8 +1332,8 @@ Nu_RenameFile(const char* fromPath, const char* toPath)
|
|||||||
NuError
|
NuError
|
||||||
Nu_FTell(FILE* fp, long* pOffset)
|
Nu_FTell(FILE* fp, long* pOffset)
|
||||||
{
|
{
|
||||||
Assert(fp != nil);
|
Assert(fp != NULL);
|
||||||
Assert(pOffset != nil);
|
Assert(pOffset != NULL);
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
*pOffset = ftell(fp);
|
*pOffset = ftell(fp);
|
||||||
@ -1350,7 +1350,7 @@ Nu_FTell(FILE* fp, long* pOffset)
|
|||||||
NuError
|
NuError
|
||||||
Nu_FSeek(FILE* fp, long offset, int ptrname)
|
Nu_FSeek(FILE* fp, long offset, int ptrname)
|
||||||
{
|
{
|
||||||
Assert(fp != nil);
|
Assert(fp != NULL);
|
||||||
Assert(ptrname == SEEK_SET || ptrname == SEEK_CUR || ptrname == SEEK_END);
|
Assert(ptrname == SEEK_SET || ptrname == SEEK_CUR || ptrname == SEEK_END);
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
@ -1409,9 +1409,9 @@ Nu_CopyFileSection(NuArchive* pArchive, FILE* dstFp, FILE* srcFp, long length)
|
|||||||
NuError err;
|
NuError err;
|
||||||
long readLen;
|
long readLen;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(dstFp != nil);
|
Assert(dstFp != NULL);
|
||||||
Assert(srcFp != nil);
|
Assert(srcFp != NULL);
|
||||||
Assert(length >= 0); /* can be == 0, e.g. empty data fork from HFS */
|
Assert(length >= 0); /* can be == 0, e.g. empty data fork from HFS */
|
||||||
|
|
||||||
/* nice big buffer, for speed... could use getc/putc for simplicity */
|
/* nice big buffer, for speed... could use getc/putc for simplicity */
|
||||||
@ -1450,7 +1450,7 @@ bail:
|
|||||||
* Only useful for files < 2GB in size.
|
* Only useful for files < 2GB in size.
|
||||||
*
|
*
|
||||||
* (pArchive is only used for BailError message reporting, so it's okay
|
* (pArchive is only used for BailError message reporting, so it's okay
|
||||||
* to call here with a nil pointer if the archive isn't open yet.)
|
* to call here with a NULL pointer if the archive isn't open yet.)
|
||||||
*/
|
*/
|
||||||
NuError
|
NuError
|
||||||
Nu_GetFileLength(NuArchive* pArchive, FILE* fp, long* pLength)
|
Nu_GetFileLength(NuArchive* pArchive, FILE* fp, long* pLength)
|
||||||
@ -1458,8 +1458,8 @@ Nu_GetFileLength(NuArchive* pArchive, FILE* fp, long* pLength)
|
|||||||
NuError err;
|
NuError err;
|
||||||
long oldpos;
|
long oldpos;
|
||||||
|
|
||||||
Assert(fp != nil);
|
Assert(fp != NULL);
|
||||||
Assert(pLength != nil);
|
Assert(pLength != NULL);
|
||||||
|
|
||||||
err = Nu_FTell(fp, &oldpos);
|
err = Nu_FTell(fp, &oldpos);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
|
116
nufxlib/Funnel.c
116
nufxlib/Funnel.c
@ -28,10 +28,10 @@ Nu_ProgressDataInit_Compress(NuArchive* pArchive, NuProgressData* pProgressData,
|
|||||||
{
|
{
|
||||||
const char* cp;
|
const char* cp;
|
||||||
|
|
||||||
Assert(pProgressData != nil);
|
Assert(pProgressData != NULL);
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pRecord != nil);
|
Assert(pRecord != NULL);
|
||||||
Assert(origPathname != nil);
|
Assert(origPathname != NULL);
|
||||||
|
|
||||||
pProgressData->pRecord = pRecord;
|
pProgressData->pRecord = pRecord;
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ Nu_ProgressDataInit_Compress(NuArchive* pArchive, NuProgressData* pProgressData,
|
|||||||
pProgressData->pathname = pRecord->filename;
|
pProgressData->pathname = pRecord->filename;
|
||||||
cp = strrchr(pRecord->filename,
|
cp = strrchr(pRecord->filename,
|
||||||
NuGetSepFromSysInfo(pRecord->recFileSysInfo));
|
NuGetSepFromSysInfo(pRecord->recFileSysInfo));
|
||||||
if (cp == nil || *(cp+1) == '\0')
|
if (cp == NULL || *(cp+1) == '\0')
|
||||||
pProgressData->filename = pProgressData->pathname;
|
pProgressData->filename = pProgressData->pathname;
|
||||||
else
|
else
|
||||||
pProgressData->filename = cp+1;
|
pProgressData->filename = cp+1;
|
||||||
@ -53,7 +53,7 @@ Nu_ProgressDataInit_Compress(NuArchive* pArchive, NuProgressData* pProgressData,
|
|||||||
|
|
||||||
pProgressData->compress.threadFormat = (NuThreadFormat)-1;
|
pProgressData->compress.threadFormat = (NuThreadFormat)-1;
|
||||||
|
|
||||||
/* ya know... if this is nil, none of the above matters much */
|
/* ya know... if this is NULL, none of the above matters much */
|
||||||
pProgressData->progressFunc = pArchive->progressUpdaterFunc;
|
pProgressData->progressFunc = pArchive->progressUpdaterFunc;
|
||||||
|
|
||||||
return kNuErrNone;
|
return kNuErrNone;
|
||||||
@ -76,19 +76,19 @@ Nu_ProgressDataInit_Expand(NuArchive* pArchive, NuProgressData* pProgressData,
|
|||||||
const char* cp;
|
const char* cp;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
Assert(pProgressData != nil);
|
Assert(pProgressData != NULL);
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pRecord != nil);
|
Assert(pRecord != NULL);
|
||||||
Assert(newPathname != nil);
|
Assert(newPathname != NULL);
|
||||||
Assert(newFssep != 0);
|
Assert(newFssep != 0);
|
||||||
|
|
||||||
pProgressData->pRecord = pRecord;
|
pProgressData->pRecord = pRecord;
|
||||||
pProgressData->expand.pThread = nil;
|
pProgressData->expand.pThread = NULL;
|
||||||
|
|
||||||
pProgressData->origPathname = pRecord->filename;
|
pProgressData->origPathname = pRecord->filename;
|
||||||
pProgressData->pathname = newPathname;
|
pProgressData->pathname = newPathname;
|
||||||
cp = strrchr(newPathname, newFssep);
|
cp = strrchr(newPathname, newFssep);
|
||||||
if (cp == nil || *(cp+1) == '\0')
|
if (cp == NULL || *(cp+1) == '\0')
|
||||||
pProgressData->filename = newPathname;
|
pProgressData->filename = newPathname;
|
||||||
else
|
else
|
||||||
pProgressData->filename = cp+1;
|
pProgressData->filename = cp+1;
|
||||||
@ -116,7 +116,7 @@ Nu_ProgressDataInit_Expand(NuArchive* pArchive, NuProgressData* pProgressData,
|
|||||||
pProgressData->uncompressedLength = 0;
|
pProgressData->uncompressedLength = 0;
|
||||||
pProgressData->uncompressedProgress = 0;
|
pProgressData->uncompressedProgress = 0;
|
||||||
|
|
||||||
/* ya know... if this is nil, none of the above matters much */
|
/* ya know... if this is NULL, none of the above matters much */
|
||||||
pProgressData->progressFunc = pArchive->progressUpdaterFunc;
|
pProgressData->progressFunc = pArchive->progressUpdaterFunc;
|
||||||
|
|
||||||
return kNuErrNone;
|
return kNuErrNone;
|
||||||
@ -132,12 +132,12 @@ Nu_ProgressDataCompressPrep(NuArchive* pArchive, NuStraw* pStraw,
|
|||||||
{
|
{
|
||||||
NuProgressData* pProgressData;
|
NuProgressData* pProgressData;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pStraw != nil);
|
Assert(pStraw != NULL);
|
||||||
Assert(sourceLen < 32767*65536);
|
Assert(sourceLen < 32767*65536);
|
||||||
|
|
||||||
pProgressData = pStraw->pProgress;
|
pProgressData = pStraw->pProgress;
|
||||||
if (pProgressData == nil)
|
if (pProgressData == NULL)
|
||||||
return kNuErrNone;
|
return kNuErrNone;
|
||||||
|
|
||||||
pProgressData->uncompressedLength = sourceLen;
|
pProgressData->uncompressedLength = sourceLen;
|
||||||
@ -157,12 +157,12 @@ Nu_ProgressDataExpandPrep(NuArchive* pArchive, NuFunnel* pFunnel,
|
|||||||
{
|
{
|
||||||
NuProgressData* pProgressData;
|
NuProgressData* pProgressData;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pFunnel != nil);
|
Assert(pFunnel != NULL);
|
||||||
Assert(pThread != nil);
|
Assert(pThread != NULL);
|
||||||
|
|
||||||
pProgressData = pFunnel->pProgress;
|
pProgressData = pFunnel->pProgress;
|
||||||
if (pProgressData == nil)
|
if (pProgressData == NULL)
|
||||||
return kNuErrNone;
|
return kNuErrNone;
|
||||||
|
|
||||||
/*pProgressData->compressedLength = pThread->thCompThreadEOF;*/
|
/*pProgressData->compressedLength = pThread->thCompThreadEOF;*/
|
||||||
@ -205,10 +205,10 @@ Nu_SendInitialProgress(NuArchive* pArchive, NuProgressData* pProgress)
|
|||||||
{
|
{
|
||||||
NuResult result;
|
NuResult result;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pProgress != nil);
|
Assert(pProgress != NULL);
|
||||||
|
|
||||||
if (pProgress->progressFunc == nil)
|
if (pProgress->progressFunc == NULL)
|
||||||
return kNuErrNone;
|
return kNuErrNone;
|
||||||
|
|
||||||
pProgress->percentComplete = Nu_ComputePercent(
|
pProgress->percentComplete = Nu_ComputePercent(
|
||||||
@ -239,10 +239,10 @@ Nu_FunnelNew(NuArchive* pArchive, NuDataSink* pDataSink, NuValue convertEOL,
|
|||||||
NuValue convertEOLTo, NuProgressData* pProgress, NuFunnel** ppFunnel)
|
NuValue convertEOLTo, NuProgressData* pProgress, NuFunnel** ppFunnel)
|
||||||
{
|
{
|
||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
NuFunnel* pFunnel = nil;
|
NuFunnel* pFunnel = NULL;
|
||||||
|
|
||||||
Assert(ppFunnel != nil);
|
Assert(ppFunnel != NULL);
|
||||||
Assert(pDataSink != nil);
|
Assert(pDataSink != NULL);
|
||||||
Assert(convertEOL == kNuConvertOff ||
|
Assert(convertEOL == kNuConvertOff ||
|
||||||
convertEOL == kNuConvertOn ||
|
convertEOL == kNuConvertOn ||
|
||||||
convertEOL == kNuConvertAuto);
|
convertEOL == kNuConvertAuto);
|
||||||
@ -281,7 +281,7 @@ bail:
|
|||||||
NuError
|
NuError
|
||||||
Nu_FunnelFree(NuArchive* pArchive, NuFunnel* pFunnel)
|
Nu_FunnelFree(NuArchive* pArchive, NuFunnel* pFunnel)
|
||||||
{
|
{
|
||||||
if (pFunnel == nil)
|
if (pFunnel == NULL)
|
||||||
return kNuErrNone;
|
return kNuErrNone;
|
||||||
|
|
||||||
#ifdef DEBUG_MSGS
|
#ifdef DEBUG_MSGS
|
||||||
@ -307,7 +307,7 @@ Nu_FunnelFree(NuArchive* pArchive, NuFunnel* pFunnel)
|
|||||||
void
|
void
|
||||||
Nu_FunnelSetMaxOutput(NuFunnel* pFunnel, ulong maxBytes)
|
Nu_FunnelSetMaxOutput(NuFunnel* pFunnel, ulong maxBytes)
|
||||||
{
|
{
|
||||||
Assert(pFunnel != nil);
|
Assert(pFunnel != NULL);
|
||||||
Assert(maxBytes > 0);
|
Assert(maxBytes > 0);
|
||||||
|
|
||||||
pFunnel->outMax = maxBytes;
|
pFunnel->outMax = maxBytes;
|
||||||
@ -330,7 +330,7 @@ Nu_CheckHighASCII(const NuFunnel* pFunnel, const unsigned char* buffer,
|
|||||||
{
|
{
|
||||||
Boolean isHighASCII;
|
Boolean isHighASCII;
|
||||||
|
|
||||||
Assert(buffer != nil);
|
Assert(buffer != NULL);
|
||||||
Assert(count != 0);
|
Assert(count != 0);
|
||||||
Assert(pFunnel->checkStripHighASCII);
|
Assert(pFunnel->checkStripHighASCII);
|
||||||
|
|
||||||
@ -487,9 +487,9 @@ Nu_DetermineConversion(NuFunnel* pFunnel, const uchar* buffer, ulong count)
|
|||||||
static inline void
|
static inline void
|
||||||
Nu_FunnelPutBlock(NuFunnel* pFunnel, const uchar* buf, ulong len)
|
Nu_FunnelPutBlock(NuFunnel* pFunnel, const uchar* buf, ulong len)
|
||||||
{
|
{
|
||||||
Assert(pFunnel != nil);
|
Assert(pFunnel != NULL);
|
||||||
Assert(pFunnel->pDataSink != nil);
|
Assert(pFunnel->pDataSink != NULL);
|
||||||
Assert(buf != nil);
|
Assert(buf != NULL);
|
||||||
Assert(len > 0);
|
Assert(len > 0);
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@ -566,7 +566,7 @@ Nu_FunnelWriteConvert(NuFunnel* pFunnel, const uchar* buffer, ulong count)
|
|||||||
pFunnel->convertEOL = kNuConvertOff;
|
pFunnel->convertEOL = kNuConvertOff;
|
||||||
}
|
}
|
||||||
/* put it where the progress meter can see it */
|
/* put it where the progress meter can see it */
|
||||||
if (pFunnel->pProgress != nil)
|
if (pFunnel->pProgress != NULL)
|
||||||
pFunnel->pProgress->expand.convertEOL = pFunnel->convertEOL;
|
pFunnel->pProgress->expand.convertEOL = pFunnel->convertEOL;
|
||||||
} else if (pFunnel->convertEOL == kNuConvertOn) {
|
} else if (pFunnel->convertEOL == kNuConvertOn) {
|
||||||
if (pFunnel->checkStripHighASCII) {
|
if (pFunnel->checkStripHighASCII) {
|
||||||
@ -627,7 +627,7 @@ Nu_FunnelWriteConvert(NuFunnel* pFunnel, const uchar* buffer, ulong count)
|
|||||||
err = Nu_DataSinkGetError(pFunnel->pDataSink);
|
err = Nu_DataSinkGetError(pFunnel->pDataSink);
|
||||||
|
|
||||||
/* update progress counter with pre-LFCR count */
|
/* update progress counter with pre-LFCR count */
|
||||||
if (err == kNuErrNone && pFunnel->pProgress != nil)
|
if (err == kNuErrNone && pFunnel->pProgress != NULL)
|
||||||
pFunnel->pProgress->uncompressedProgress += progressCount;
|
pFunnel->pProgress->uncompressedProgress += progressCount;
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
@ -717,9 +717,9 @@ bail:
|
|||||||
NuError
|
NuError
|
||||||
Nu_FunnelSetProgressState(NuFunnel* pFunnel, NuProgressState state)
|
Nu_FunnelSetProgressState(NuFunnel* pFunnel, NuProgressState state)
|
||||||
{
|
{
|
||||||
Assert(pFunnel != nil);
|
Assert(pFunnel != NULL);
|
||||||
|
|
||||||
if (pFunnel->pProgress == nil)
|
if (pFunnel->pProgress == NULL)
|
||||||
return kNuErrNone;
|
return kNuErrNone;
|
||||||
|
|
||||||
pFunnel->pProgress->state = state;
|
pFunnel->pProgress->state = state;
|
||||||
@ -736,15 +736,15 @@ Nu_FunnelSendProgressUpdate(NuArchive* pArchive, NuFunnel* pFunnel)
|
|||||||
{
|
{
|
||||||
NuProgressData* pProgress;
|
NuProgressData* pProgress;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pFunnel != nil);
|
Assert(pFunnel != NULL);
|
||||||
|
|
||||||
pProgress = pFunnel->pProgress;
|
pProgress = pFunnel->pProgress;
|
||||||
if (pProgress == nil)
|
if (pProgress == NULL)
|
||||||
return kNuErrNone; /* no progress meter attached */
|
return kNuErrNone; /* no progress meter attached */
|
||||||
|
|
||||||
/* don't continue if they're not accepting progress messages */
|
/* don't continue if they're not accepting progress messages */
|
||||||
if (pProgress->progressFunc == nil)
|
if (pProgress->progressFunc == NULL)
|
||||||
return kNuErrNone;
|
return kNuErrNone;
|
||||||
|
|
||||||
/* other than the choice of arguments, it's pretty much the same story */
|
/* other than the choice of arguments, it's pretty much the same story */
|
||||||
@ -758,8 +758,8 @@ Nu_FunnelSendProgressUpdate(NuArchive* pArchive, NuFunnel* pFunnel)
|
|||||||
Boolean
|
Boolean
|
||||||
Nu_FunnelGetDoExpand(NuFunnel* pFunnel)
|
Nu_FunnelGetDoExpand(NuFunnel* pFunnel)
|
||||||
{
|
{
|
||||||
Assert(pFunnel != nil);
|
Assert(pFunnel != NULL);
|
||||||
Assert(pFunnel->pDataSink != nil);
|
Assert(pFunnel->pDataSink != NULL);
|
||||||
|
|
||||||
return Nu_DataSinkGetDoExpand(pFunnel->pDataSink);
|
return Nu_DataSinkGetDoExpand(pFunnel->pDataSink);
|
||||||
}
|
}
|
||||||
@ -779,10 +779,10 @@ Nu_StrawNew(NuArchive* pArchive, NuDataSource* pDataSource,
|
|||||||
NuProgressData* pProgress, NuStraw** ppStraw)
|
NuProgressData* pProgress, NuStraw** ppStraw)
|
||||||
{
|
{
|
||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
NuStraw* pStraw = nil;
|
NuStraw* pStraw = NULL;
|
||||||
|
|
||||||
Assert(ppStraw != nil);
|
Assert(ppStraw != NULL);
|
||||||
Assert(pDataSource != nil);
|
Assert(pDataSource != NULL);
|
||||||
|
|
||||||
pStraw = Nu_Calloc(pArchive, sizeof(*pStraw));
|
pStraw = Nu_Calloc(pArchive, sizeof(*pStraw));
|
||||||
BailAlloc(pStraw);
|
BailAlloc(pStraw);
|
||||||
@ -805,7 +805,7 @@ bail:
|
|||||||
NuError
|
NuError
|
||||||
Nu_StrawFree(NuArchive* pArchive, NuStraw* pStraw)
|
Nu_StrawFree(NuArchive* pArchive, NuStraw* pStraw)
|
||||||
{
|
{
|
||||||
if (pStraw == nil)
|
if (pStraw == NULL)
|
||||||
return kNuErrNone;
|
return kNuErrNone;
|
||||||
|
|
||||||
/* we don't own the data source or progress meter */
|
/* we don't own the data source or progress meter */
|
||||||
@ -821,8 +821,8 @@ Nu_StrawFree(NuArchive* pArchive, NuStraw* pStraw)
|
|||||||
NuError
|
NuError
|
||||||
Nu_StrawSetProgressState(NuStraw* pStraw, NuProgressState state)
|
Nu_StrawSetProgressState(NuStraw* pStraw, NuProgressState state)
|
||||||
{
|
{
|
||||||
Assert(pStraw != nil);
|
Assert(pStraw != NULL);
|
||||||
Assert(pStraw->pProgress != nil);
|
Assert(pStraw->pProgress != NULL);
|
||||||
|
|
||||||
pStraw->pProgress->state = state;
|
pStraw->pProgress->state = state;
|
||||||
|
|
||||||
@ -837,15 +837,15 @@ Nu_StrawSendProgressUpdate(NuArchive* pArchive, NuStraw* pStraw)
|
|||||||
{
|
{
|
||||||
NuProgressData* pProgress;
|
NuProgressData* pProgress;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pStraw != nil);
|
Assert(pStraw != NULL);
|
||||||
|
|
||||||
pProgress = pStraw->pProgress;
|
pProgress = pStraw->pProgress;
|
||||||
if (pProgress == nil)
|
if (pProgress == NULL)
|
||||||
return kNuErrNone; /* no progress meter attached */
|
return kNuErrNone; /* no progress meter attached */
|
||||||
|
|
||||||
/* don't continue if they're not accepting progress messages */
|
/* don't continue if they're not accepting progress messages */
|
||||||
if (pProgress->progressFunc == nil)
|
if (pProgress->progressFunc == NULL)
|
||||||
return kNuErrNone;
|
return kNuErrNone;
|
||||||
|
|
||||||
/* other than the choice of arguments, it's pretty much the same story */
|
/* other than the choice of arguments, it's pretty much the same story */
|
||||||
@ -861,9 +861,9 @@ Nu_StrawRead(NuArchive* pArchive, NuStraw* pStraw, uchar* buffer, long len)
|
|||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pStraw != nil);
|
Assert(pStraw != NULL);
|
||||||
Assert(buffer != nil);
|
Assert(buffer != NULL);
|
||||||
Assert(len > 0);
|
Assert(len > 0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -887,7 +887,7 @@ Nu_StrawRead(NuArchive* pArchive, NuStraw* pStraw, uchar* buffer, long len)
|
|||||||
* on the previous call. (This assumes that whatever they asked for
|
* on the previous call. (This assumes that whatever they asked for
|
||||||
* last time has already been fully processed.)
|
* last time has already been fully processed.)
|
||||||
*/
|
*/
|
||||||
if (pStraw->pProgress != nil) {
|
if (pStraw->pProgress != NULL) {
|
||||||
pStraw->pProgress->uncompressedProgress = pStraw->lastProgress;
|
pStraw->pProgress->uncompressedProgress = pStraw->lastProgress;
|
||||||
pStraw->lastProgress += len;
|
pStraw->lastProgress += len;
|
||||||
|
|
||||||
@ -914,8 +914,8 @@ bail:
|
|||||||
NuError
|
NuError
|
||||||
Nu_StrawRewind(NuArchive* pArchive, NuStraw* pStraw)
|
Nu_StrawRewind(NuArchive* pArchive, NuStraw* pStraw)
|
||||||
{
|
{
|
||||||
Assert(pStraw != nil);
|
Assert(pStraw != NULL);
|
||||||
Assert(pStraw->pDataSource != nil);
|
Assert(pStraw->pDataSource != NULL);
|
||||||
|
|
||||||
pStraw->lastProgress = 0;
|
pStraw->lastProgress = 0;
|
||||||
pStraw->lastDisplayed = 0;
|
pStraw->lastDisplayed = 0;
|
||||||
|
@ -587,7 +587,7 @@ Nu_LZC_compress(LZCState* pLzcState, ulong* pDstLen)
|
|||||||
register INTCODE code;
|
register INTCODE code;
|
||||||
HASH hashf[256];
|
HASH hashf[256];
|
||||||
|
|
||||||
Assert(pLzcState->outfp != nil);
|
Assert(pLzcState->outfp != NULL);
|
||||||
|
|
||||||
pLzcState->maxcode = Maxcode(pLzcState->maxbits);
|
pLzcState->maxcode = Maxcode(pLzcState->maxbits);
|
||||||
pLzcState->hashsize = Hashsize(pLzcState->maxbits);
|
pLzcState->hashsize = Hashsize(pLzcState->maxbits);
|
||||||
@ -771,7 +771,7 @@ Nu_CompressLZC(NuArchive* pArchive, NuStraw* pStraw, FILE* fp,
|
|||||||
lzcState.outfp = fp;
|
lzcState.outfp = fp;
|
||||||
lzcState.uncompRemaining = srcLen;
|
lzcState.uncompRemaining = srcLen;
|
||||||
|
|
||||||
if (pCrc == nil) {
|
if (pCrc == NULL) {
|
||||||
lzcState.doCalcCRC = false;
|
lzcState.doCalcCRC = false;
|
||||||
} else {
|
} else {
|
||||||
lzcState.doCalcCRC = true;
|
lzcState.doCalcCRC = true;
|
||||||
@ -800,7 +800,7 @@ Nu_CompressLZC(NuArchive* pArchive, NuStraw* pStraw, FILE* fp,
|
|||||||
#endif
|
#endif
|
||||||
free_array(char,lzcState.sfx, 256);
|
free_array(char,lzcState.sfx, 256);
|
||||||
|
|
||||||
if (pCrc != nil)
|
if (pCrc != NULL)
|
||||||
*pCrc = lzcState.crc;
|
*pCrc = lzcState.crc;
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
@ -911,7 +911,7 @@ Nu_LZC_decompress(LZCState* pLzcState, ulong compressedLen)
|
|||||||
/*static*/ int maxtoklen = MAXTOKLEN;
|
/*static*/ int maxtoklen = MAXTOKLEN;
|
||||||
int flags;
|
int flags;
|
||||||
|
|
||||||
Assert(pLzcState->infp != nil);
|
Assert(pLzcState->infp != NULL);
|
||||||
|
|
||||||
pLzcState->exit_stat = OK;
|
pLzcState->exit_stat = OK;
|
||||||
|
|
||||||
@ -1072,7 +1072,7 @@ Nu_ExpandLZC(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
lzcState.infp = infp;
|
lzcState.infp = infp;
|
||||||
lzcState.pFunnel = pFunnel;
|
lzcState.pFunnel = pFunnel;
|
||||||
|
|
||||||
if (pCrc == nil) {
|
if (pCrc == NULL) {
|
||||||
lzcState.doCalcCRC = false;
|
lzcState.doCalcCRC = false;
|
||||||
} else {
|
} else {
|
||||||
lzcState.doCalcCRC = true;
|
lzcState.doCalcCRC = true;
|
||||||
@ -1098,7 +1098,7 @@ Nu_ExpandLZC(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
#endif
|
#endif
|
||||||
free_array(char,lzcState.sfx, 256);
|
free_array(char,lzcState.sfx, 256);
|
||||||
|
|
||||||
if (pCrc != nil)
|
if (pCrc != NULL)
|
||||||
*pCrc = lzcState.crc;
|
*pCrc = lzcState.crc;
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -153,8 +153,8 @@ Nu_AllocLZWCompressState(NuArchive* pArchive)
|
|||||||
LZWCompressState* lzwState;
|
LZWCompressState* lzwState;
|
||||||
int ic;
|
int ic;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pArchive->lzwCompressState == nil);
|
Assert(pArchive->lzwCompressState == NULL);
|
||||||
|
|
||||||
/* allocate the general-purpose compression buffer, if needed */
|
/* allocate the general-purpose compression buffer, if needed */
|
||||||
err = Nu_AllocCompressionBufferIFN(pArchive);
|
err = Nu_AllocCompressionBufferIFN(pArchive);
|
||||||
@ -162,7 +162,7 @@ Nu_AllocLZWCompressState(NuArchive* pArchive)
|
|||||||
return err;
|
return err;
|
||||||
|
|
||||||
pArchive->lzwCompressState = Nu_Malloc(pArchive, sizeof(LZWCompressState));
|
pArchive->lzwCompressState = Nu_Malloc(pArchive, sizeof(LZWCompressState));
|
||||||
if (pArchive->lzwCompressState == nil)
|
if (pArchive->lzwCompressState == NULL)
|
||||||
return kNuErrMalloc;
|
return kNuErrMalloc;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -261,7 +261,7 @@ Nu_CompressBlockRLE(LZWCompressState* lzwState, int* pRLESize)
|
|||||||
static void
|
static void
|
||||||
Nu_ClearLZWTable(LZWCompressState* lzwState)
|
Nu_ClearLZWTable(LZWCompressState* lzwState)
|
||||||
{
|
{
|
||||||
Assert(lzwState != nil);
|
Assert(lzwState != NULL);
|
||||||
|
|
||||||
/*DBUG_LZW(("### clear table\n"));*/
|
/*DBUG_LZW(("### clear table\n"));*/
|
||||||
|
|
||||||
@ -368,8 +368,8 @@ Nu_CompressLZWBlock(LZWCompressState* lzwState, const uchar* inputBuf,
|
|||||||
uchar* pSuffix = lzwState->suffix;
|
uchar* pSuffix = lzwState->suffix;
|
||||||
uchar* outBuf = lzwState->lzwBuf;
|
uchar* outBuf = lzwState->lzwBuf;
|
||||||
|
|
||||||
Assert(lzwState != nil);
|
Assert(lzwState != NULL);
|
||||||
Assert(inputBuf != nil);
|
Assert(inputBuf != NULL);
|
||||||
Assert(inputCount > 0 && inputCount <= kNuLZWBlockSize);
|
Assert(inputCount > 0 && inputCount <= kNuLZWBlockSize);
|
||||||
/* make sure nobody has been messing with the types */
|
/* make sure nobody has been messing with the types */
|
||||||
Assert(sizeof(pHashFunc[0]) == sizeof(lzwState->hashFunc[0]));
|
Assert(sizeof(pHashFunc[0]) == sizeof(lzwState->hashFunc[0]));
|
||||||
@ -567,23 +567,23 @@ Nu_CompressLZW(NuArchive* pArchive, NuStraw* pStraw, FILE* fp,
|
|||||||
long compressedLen;
|
long compressedLen;
|
||||||
Boolean keepLzw;
|
Boolean keepLzw;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pStraw != nil);
|
Assert(pStraw != NULL);
|
||||||
Assert(fp != nil);
|
Assert(fp != NULL);
|
||||||
Assert(srcLen > 0);
|
Assert(srcLen > 0);
|
||||||
Assert(pDstLen != nil);
|
Assert(pDstLen != NULL);
|
||||||
Assert(pThreadCrc != nil);
|
Assert(pThreadCrc != NULL);
|
||||||
Assert(isType2 == true || isType2 == false);
|
Assert(isType2 == true || isType2 == false);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Do some initialization and set-up.
|
* Do some initialization and set-up.
|
||||||
*/
|
*/
|
||||||
if (pArchive->lzwCompressState == nil) {
|
if (pArchive->lzwCompressState == NULL) {
|
||||||
err = Nu_AllocLZWCompressState(pArchive);
|
err = Nu_AllocLZWCompressState(pArchive);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
}
|
}
|
||||||
Assert(pArchive->lzwCompressState != nil);
|
Assert(pArchive->lzwCompressState != NULL);
|
||||||
Assert(pArchive->compBuf != nil);
|
Assert(pArchive->compBuf != NULL);
|
||||||
|
|
||||||
lzwState = pArchive->lzwCompressState;
|
lzwState = pArchive->lzwCompressState;
|
||||||
lzwState->pArchive = pArchive;
|
lzwState->pArchive = pArchive;
|
||||||
@ -869,8 +869,8 @@ Nu_AllocLZWExpandState(NuArchive* pArchive)
|
|||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pArchive->lzwExpandState == nil);
|
Assert(pArchive->lzwExpandState == NULL);
|
||||||
|
|
||||||
/* allocate the general-purpose compression buffer, if needed */
|
/* allocate the general-purpose compression buffer, if needed */
|
||||||
err = Nu_AllocCompressionBufferIFN(pArchive);
|
err = Nu_AllocCompressionBufferIFN(pArchive);
|
||||||
@ -878,7 +878,7 @@ Nu_AllocLZWExpandState(NuArchive* pArchive)
|
|||||||
return err;
|
return err;
|
||||||
|
|
||||||
pArchive->lzwExpandState = Nu_Malloc(pArchive, sizeof(LZWExpandState));
|
pArchive->lzwExpandState = Nu_Malloc(pArchive, sizeof(LZWExpandState));
|
||||||
if (pArchive->lzwExpandState == nil)
|
if (pArchive->lzwExpandState == NULL)
|
||||||
return kNuErrMalloc;
|
return kNuErrMalloc;
|
||||||
return kNuErrNone;
|
return kNuErrNone;
|
||||||
}
|
}
|
||||||
@ -990,7 +990,7 @@ Nu_ExpandLZW1(LZWExpandState* lzwState, uint expectedLen)
|
|||||||
uchar* outbufend;
|
uchar* outbufend;
|
||||||
uchar* stackPtr;
|
uchar* stackPtr;
|
||||||
|
|
||||||
Assert(lzwState != nil);
|
Assert(lzwState != NULL);
|
||||||
Assert(expectedLen > 0 && expectedLen <= kNuLZWBlockSize);
|
Assert(expectedLen > 0 && expectedLen <= kNuLZWBlockSize);
|
||||||
|
|
||||||
inbuf = lzwState->dataPtr;
|
inbuf = lzwState->dataPtr;
|
||||||
@ -1094,7 +1094,7 @@ Nu_ExpandLZW2(LZWExpandState* lzwState, uint expectedLen,
|
|||||||
|
|
||||||
/*DBUG_LZW(("### LZW/2 block start (compIn=%d, rleOut=%d, entry=0x%04x)\n",
|
/*DBUG_LZW(("### LZW/2 block start (compIn=%d, rleOut=%d, entry=0x%04x)\n",
|
||||||
expectedInputUsed, expectedLen, lzwState->entry));*/
|
expectedInputUsed, expectedLen, lzwState->entry));*/
|
||||||
Assert(lzwState != nil);
|
Assert(lzwState != NULL);
|
||||||
Assert(expectedLen > 0 && expectedLen <= kNuLZWBlockSize);
|
Assert(expectedLen > 0 && expectedLen <= kNuLZWBlockSize);
|
||||||
|
|
||||||
inbuf = lzwState->dataPtr;
|
inbuf = lzwState->dataPtr;
|
||||||
@ -1298,7 +1298,7 @@ Nu_GetHeaderByte(LZWExpandState* lzwState)
|
|||||||
* This manages the input data buffer, passing chunks of compressed data
|
* This manages the input data buffer, passing chunks of compressed data
|
||||||
* into the appropriate expansion function.
|
* into the appropriate expansion function.
|
||||||
*
|
*
|
||||||
* Pass in nil for "pThreadCrc" if no thread CRC is desired. Otherwise,
|
* Pass in NULL for "pThreadCrc" if no thread CRC is desired. Otherwise,
|
||||||
* "*pThreadCrc" should already be set to its initial value. On exit it
|
* "*pThreadCrc" should already be set to its initial value. On exit it
|
||||||
* will contain the CRC of the uncompressed data.
|
* will contain the CRC of the uncompressed data.
|
||||||
*/
|
*/
|
||||||
@ -1311,20 +1311,20 @@ Nu_ExpandLZW(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
LZWExpandState* lzwState;
|
LZWExpandState* lzwState;
|
||||||
ulong compRemaining, uncompRemaining, minSize;
|
ulong compRemaining, uncompRemaining, minSize;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pThread != nil);
|
Assert(pThread != NULL);
|
||||||
Assert(infp != nil);
|
Assert(infp != NULL);
|
||||||
Assert(pFunnel != nil);
|
Assert(pFunnel != NULL);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Do some initialization and set-up.
|
* Do some initialization and set-up.
|
||||||
*/
|
*/
|
||||||
if (pArchive->lzwExpandState == nil) {
|
if (pArchive->lzwExpandState == NULL) {
|
||||||
err = Nu_AllocLZWExpandState(pArchive);
|
err = Nu_AllocLZWExpandState(pArchive);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
}
|
}
|
||||||
Assert(pArchive->lzwExpandState != nil);
|
Assert(pArchive->lzwExpandState != NULL);
|
||||||
Assert(pArchive->compBuf != nil);
|
Assert(pArchive->compBuf != NULL);
|
||||||
|
|
||||||
lzwState = pArchive->lzwExpandState;
|
lzwState = pArchive->lzwExpandState;
|
||||||
lzwState->pArchive = pArchive;
|
lzwState->pArchive = pArchive;
|
||||||
@ -1368,7 +1368,7 @@ Nu_ExpandLZW(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
compRemaining -= 2;
|
compRemaining -= 2;
|
||||||
|
|
||||||
lzwState->dataInBuffer = 0;
|
lzwState->dataInBuffer = 0;
|
||||||
lzwState->dataPtr = nil;
|
lzwState->dataPtr = NULL;
|
||||||
|
|
||||||
/* reset pointers */
|
/* reset pointers */
|
||||||
lzwState->entry = kNuLZWFirstCode; /* 0x0101 */
|
lzwState->entry = kNuLZWFirstCode; /* 0x0101 */
|
||||||
@ -1409,7 +1409,7 @@ Nu_ExpandLZW(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
* the buffer.
|
* the buffer.
|
||||||
*/
|
*/
|
||||||
if (lzwState->dataInBuffer) {
|
if (lzwState->dataInBuffer) {
|
||||||
Assert(lzwState->dataPtr != nil);
|
Assert(lzwState->dataPtr != NULL);
|
||||||
Assert(pArchive->compBuf != lzwState->dataPtr);
|
Assert(pArchive->compBuf != lzwState->dataPtr);
|
||||||
memmove(pArchive->compBuf, lzwState->dataPtr,
|
memmove(pArchive->compBuf, lzwState->dataPtr,
|
||||||
lzwState->dataInBuffer);
|
lzwState->dataInBuffer);
|
||||||
@ -1476,7 +1476,7 @@ Nu_ExpandLZW(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
writeLen = kNuLZWBlockSize;
|
writeLen = kNuLZWBlockSize;
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
writeBuf = nil;
|
writeBuf = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1537,7 +1537,7 @@ Nu_ExpandLZW(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
lzwState->resetFix = false;
|
lzwState->resetFix = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert(writeBuf != nil);
|
Assert(writeBuf != NULL);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Compute the CRC of the uncompressed data, and write it. For
|
* Compute the CRC of the uncompressed data, and write it. For
|
||||||
@ -1547,7 +1547,7 @@ Nu_ExpandLZW(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
* See commentary in the compression code for why we have to
|
* See commentary in the compression code for why we have to
|
||||||
* compute two CRCs for LZW/1.
|
* compute two CRCs for LZW/1.
|
||||||
*/
|
*/
|
||||||
if (pThreadCrc != nil) {
|
if (pThreadCrc != NULL) {
|
||||||
*pThreadCrc = Nu_CalcCRC16(*pThreadCrc, writeBuf, writeLen);
|
*pThreadCrc = Nu_CalcCRC16(*pThreadCrc, writeBuf, writeLen);
|
||||||
}
|
}
|
||||||
if (!isType2) {
|
if (!isType2) {
|
||||||
|
@ -42,11 +42,7 @@ int Nu_strncasecmp(const char *s1, const char *s2, size_t n);
|
|||||||
* Misc types.
|
* Misc types.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
typedef unsigned char Boolean;
|
||||||
|
|
||||||
#define nil NULL /* I can't seem to stop typing 'nil' now */
|
|
||||||
|
|
||||||
typedef uchar Boolean;
|
|
||||||
#define false (0)
|
#define false (0)
|
||||||
#define true (!false)
|
#define true (!false)
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
/*
|
/*
|
||||||
* Big fat hairy global. Unfortunately this is unavoidable.
|
* Big fat hairy global. Unfortunately this is unavoidable.
|
||||||
*/
|
*/
|
||||||
NuCallback gNuGlobalErrorMessageHandler = nil;
|
NuCallback gNuGlobalErrorMessageHandler = NULL;
|
||||||
|
|
||||||
|
|
||||||
static const char* kNufxLibName = "nufxlib";
|
static const char* kNufxLibName = "nufxlib";
|
||||||
@ -32,7 +32,7 @@ Nu_StrError(NuError err)
|
|||||||
* to return this.
|
* to return this.
|
||||||
*
|
*
|
||||||
* An easier solution, should this present a problem for someone, would
|
* An easier solution, should this present a problem for someone, would
|
||||||
* be to have the function return nil or "unknown error" when the
|
* be to have the function return NULL or "unknown error" when the
|
||||||
* error value isn't recognized. I'd recommend leaving it as-is for
|
* error value isn't recognized. I'd recommend leaving it as-is for
|
||||||
* debug builds, though, as it's helpful to know *which* error is not
|
* debug builds, though, as it's helpful to know *which* error is not
|
||||||
* recognized.
|
* recognized.
|
||||||
@ -200,11 +200,11 @@ Nu_StrError(NuError err)
|
|||||||
* Similar to perror(), but takes the error as an argument, and knows
|
* Similar to perror(), but takes the error as an argument, and knows
|
||||||
* about NufxLib errors as well as system errors.
|
* about NufxLib errors as well as system errors.
|
||||||
*
|
*
|
||||||
* Depending on the compiler, "file", "line", and "function" may be nil/zero.
|
* Depending on the compiler, "file", "line", and "function" may be NULL/zero.
|
||||||
*
|
*
|
||||||
* Calling here with "pArchive"==nil is allowed, but should only be done
|
* Calling here with "pArchive"==NULL is allowed, but should only be done
|
||||||
* if the archive is inaccessible (perhaps because it failed to open). We
|
* if the archive is inaccessible (perhaps because it failed to open). We
|
||||||
* can't invoke the error message callback if the pointer is nil.
|
* can't invoke the error message callback if the pointer is NULL.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Nu_ReportError(NuArchive* pArchive, const char* file, int line,
|
Nu_ReportError(NuArchive* pArchive, const char* file, int line,
|
||||||
@ -219,7 +219,7 @@ Nu_ReportError(NuArchive* pArchive, const char* file, int line,
|
|||||||
int cc;
|
int cc;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Assert(format != nil);
|
Assert(format != NULL);
|
||||||
|
|
||||||
|
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
@ -247,28 +247,28 @@ Nu_ReportError(NuArchive* pArchive, const char* file, int line,
|
|||||||
strcpy(buf+count, ": ");
|
strcpy(buf+count, ": ");
|
||||||
count += 2;
|
count += 2;
|
||||||
|
|
||||||
msg = nil;
|
msg = NULL;
|
||||||
if (err >= 0)
|
if (err >= 0)
|
||||||
msg = strerror(err);
|
msg = strerror(err);
|
||||||
if (msg == nil)
|
if (msg == NULL)
|
||||||
msg = Nu_StrError(err);
|
msg = Nu_StrError(err);
|
||||||
|
|
||||||
#if defined(HAVE_SNPRINTF) && defined(SNPRINTF_DECLARED)
|
#if defined(HAVE_SNPRINTF) && defined(SNPRINTF_DECLARED)
|
||||||
if (msg == nil)
|
if (msg == NULL)
|
||||||
snprintf(buf+count, sizeof(buf) - count,
|
snprintf(buf+count, sizeof(buf) - count,
|
||||||
"(unknown err=%d)", err);
|
"(unknown err=%d)", err);
|
||||||
else
|
else
|
||||||
snprintf(buf+count, sizeof(buf) - count, "%s", msg);
|
snprintf(buf+count, sizeof(buf) - count, "%s", msg);
|
||||||
#else
|
#else
|
||||||
#ifdef SPRINTF_RETURNS_INT
|
#ifdef SPRINTF_RETURNS_INT
|
||||||
if (msg == nil)
|
if (msg == NULL)
|
||||||
cc = sprintf(buf+count, "(unknown err=%d)", err);
|
cc = sprintf(buf+count, "(unknown err=%d)", err);
|
||||||
else
|
else
|
||||||
cc = sprintf(buf+count, "%s", msg);
|
cc = sprintf(buf+count, "%s", msg);
|
||||||
Assert(cc > 0);
|
Assert(cc > 0);
|
||||||
count += cc;
|
count += cc;
|
||||||
#else
|
#else
|
||||||
if (msg == nil)
|
if (msg == NULL)
|
||||||
sprintf(buf+count, "(unknown err=%d)", err);
|
sprintf(buf+count, "(unknown err=%d)", err);
|
||||||
else
|
else
|
||||||
sprintf(buf+count, "%s", msg);
|
sprintf(buf+count, "%s", msg);
|
||||||
@ -284,8 +284,8 @@ Nu_ReportError(NuArchive* pArchive, const char* file, int line,
|
|||||||
Assert(count <= kNuHeftyBufSize);
|
Assert(count <= kNuHeftyBufSize);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((pArchive != nil && pArchive->messageHandlerFunc == nil) ||
|
if ((pArchive != NULL && pArchive->messageHandlerFunc == NULL) ||
|
||||||
(pArchive == nil && gNuGlobalErrorMessageHandler == nil))
|
(pArchive == NULL && gNuGlobalErrorMessageHandler == NULL))
|
||||||
{
|
{
|
||||||
if (isDebug) {
|
if (isDebug) {
|
||||||
fprintf(stderr, "%s: [%s:%d %s] %s\n", kNufxLibName,
|
fprintf(stderr, "%s: [%s:%d %s] %s\n", kNufxLibName,
|
||||||
@ -301,7 +301,7 @@ Nu_ReportError(NuArchive* pArchive, const char* file, int line,
|
|||||||
errorMessage.line = line;
|
errorMessage.line = line;
|
||||||
errorMessage.function = function;
|
errorMessage.function = function;
|
||||||
|
|
||||||
if (pArchive == nil)
|
if (pArchive == NULL)
|
||||||
(void) (*gNuGlobalErrorMessageHandler)(pArchive, &errorMessage);
|
(void) (*gNuGlobalErrorMessageHandler)(pArchive, &errorMessage);
|
||||||
else
|
else
|
||||||
(void) (*pArchive->messageHandlerFunc)(pArchive, &errorMessage);
|
(void) (*pArchive->messageHandlerFunc)(pArchive, &errorMessage);
|
||||||
@ -329,7 +329,7 @@ Nu_Malloc(NuArchive* pArchive, size_t size)
|
|||||||
|
|
||||||
Assert(size > 0);
|
Assert(size > 0);
|
||||||
_result = malloc(size);
|
_result = malloc(size);
|
||||||
if (_result == nil) {
|
if (_result == NULL) {
|
||||||
Nu_ReportError(NU_BLOB, kNuErrMalloc, "malloc(%u) failed", (uint) size);
|
Nu_ReportError(NU_BLOB, kNuErrMalloc, "malloc(%u) failed", (uint) size);
|
||||||
DebugAbort(); /* leave a core dump if we're built for it */
|
DebugAbort(); /* leave a core dump if we're built for it */
|
||||||
}
|
}
|
||||||
@ -350,10 +350,10 @@ Nu_Realloc(NuArchive* pArchive, void* ptr, size_t size)
|
|||||||
{
|
{
|
||||||
void* _result;
|
void* _result;
|
||||||
|
|
||||||
Assert(ptr != nil); /* disallow this usage */
|
Assert(ptr != NULL); /* disallow this usage */
|
||||||
Assert(size > 0); /* disallow this usage */
|
Assert(size > 0); /* disallow this usage */
|
||||||
_result = realloc(ptr, size);
|
_result = realloc(ptr, size);
|
||||||
if (_result == nil) {
|
if (_result == NULL) {
|
||||||
Nu_ReportError(NU_BLOB, kNuErrMalloc, "realloc(%u) failed",(uint) size);
|
Nu_ReportError(NU_BLOB, kNuErrMalloc, "realloc(%u) failed",(uint) size);
|
||||||
DebugAbort(); /* leave a core dump if we're built for it */
|
DebugAbort(); /* leave a core dump if we're built for it */
|
||||||
}
|
}
|
||||||
@ -363,7 +363,7 @@ Nu_Realloc(NuArchive* pArchive, void* ptr, size_t size)
|
|||||||
void
|
void
|
||||||
Nu_Free(NuArchive* pArchive, void* ptr)
|
Nu_Free(NuArchive* pArchive, void* ptr)
|
||||||
{
|
{
|
||||||
if (ptr != nil)
|
if (ptr != NULL)
|
||||||
free(ptr);
|
free(ptr);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -376,7 +376,7 @@ NuResult
|
|||||||
Nu_InternalFreeCallback(NuArchive* pArchive, void* args)
|
Nu_InternalFreeCallback(NuArchive* pArchive, void* args)
|
||||||
{
|
{
|
||||||
DBUG(("+++ internal free callback 0x%08lx\n", (long) args));
|
DBUG(("+++ internal free callback 0x%08lx\n", (long) args));
|
||||||
Nu_Free(nil, args);
|
Nu_Free(NULL, args);
|
||||||
return kNuOK;
|
return kNuOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -676,7 +676,7 @@ typedef struct NuErrorMessage {
|
|||||||
/* these identify where the message originated if lib built w/debug set */
|
/* these identify where the message originated if lib built w/debug set */
|
||||||
const char* file; /* source file */
|
const char* file; /* source file */
|
||||||
int line; /* line number */
|
int line; /* line number */
|
||||||
const char* function; /* function name (might be nil) */
|
const char* function; /* function name (might be NULL) */
|
||||||
} NuErrorMessage;
|
} NuErrorMessage;
|
||||||
|
|
||||||
|
|
||||||
|
@ -400,7 +400,7 @@ union NuDataSink {
|
|||||||
char* pathname; /* file to open */
|
char* pathname; /* file to open */
|
||||||
char fssep;
|
char fssep;
|
||||||
|
|
||||||
/* temp storage; must be nil except when processing in library */
|
/* temp storage; must be NULL except when processing in library */
|
||||||
FILE* fp;
|
FILE* fp;
|
||||||
} toFile;
|
} toFile;
|
||||||
|
|
||||||
@ -469,13 +469,13 @@ union NuDataSink {
|
|||||||
goto bail; \
|
goto bail; \
|
||||||
}
|
}
|
||||||
#define BailNil(val) { \
|
#define BailNil(val) { \
|
||||||
if ((val) == nil) { \
|
if ((val) == NULL) { \
|
||||||
err = kNuErrUnexpectedNil; \
|
err = kNuErrUnexpectedNil; \
|
||||||
BailError(err); \
|
BailError(err); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
#define BailAlloc(val) { \
|
#define BailAlloc(val) { \
|
||||||
if ((val) == nil) { \
|
if ((val) == NULL) { \
|
||||||
err = kNuErrMalloc; \
|
err = kNuErrMalloc; \
|
||||||
BailError(err); \
|
BailError(err); \
|
||||||
} \
|
} \
|
||||||
@ -688,7 +688,7 @@ void Nu_ReportError(NuArchive* pArchive, const char* file, int line,
|
|||||||
# define Nu_Malloc(archive, size) malloc(size)
|
# define Nu_Malloc(archive, size) malloc(size)
|
||||||
# define Nu_Calloc(archive, size) calloc(1, size)
|
# define Nu_Calloc(archive, size) calloc(1, size)
|
||||||
# define Nu_Realloc(archive, ptr, size) realloc(ptr, size)
|
# define Nu_Realloc(archive, ptr, size) realloc(ptr, size)
|
||||||
# define Nu_Free(archive, ptr) (ptr != nil ? free(ptr) : (void)0)
|
# define Nu_Free(archive, ptr) (ptr != NULL ? free(ptr) : (void)0)
|
||||||
#else
|
#else
|
||||||
void* Nu_Malloc(NuArchive* pArchive, size_t size);
|
void* Nu_Malloc(NuArchive* pArchive, size_t size);
|
||||||
void* Nu_Calloc(NuArchive* pArchive, size_t size);
|
void* Nu_Calloc(NuArchive* pArchive, size_t size);
|
||||||
@ -822,7 +822,7 @@ THREAD_INLINE NuThread*
|
|||||||
Nu_GetThread(const NuRecord* pRecord, int idx)
|
Nu_GetThread(const NuRecord* pRecord, int idx)
|
||||||
{
|
{
|
||||||
if (idx >= (int)pRecord->recTotalThreads)
|
if (idx >= (int)pRecord->recTotalThreads)
|
||||||
return nil;
|
return NULL;
|
||||||
else
|
else
|
||||||
return &pRecord->pThreads[idx];
|
return &pRecord->pThreads[idx];
|
||||||
}
|
}
|
||||||
|
366
nufxlib/Record.c
366
nufxlib/Record.c
File diff suppressed because it is too large
Load Diff
@ -22,10 +22,10 @@
|
|||||||
static NuError
|
static NuError
|
||||||
Nu_DataSourceNew(NuDataSource** ppDataSource)
|
Nu_DataSourceNew(NuDataSource** ppDataSource)
|
||||||
{
|
{
|
||||||
Assert(ppDataSource != nil);
|
Assert(ppDataSource != NULL);
|
||||||
|
|
||||||
*ppDataSource = Nu_Malloc(nil, sizeof(**ppDataSource));
|
*ppDataSource = Nu_Malloc(NULL, sizeof(**ppDataSource));
|
||||||
if (*ppDataSource == nil)
|
if (*ppDataSource == NULL)
|
||||||
return kNuErrMalloc;
|
return kNuErrMalloc;
|
||||||
|
|
||||||
(*ppDataSource)->sourceType = kNuDataSourceUnknown;
|
(*ppDataSource)->sourceType = kNuDataSourceUnknown;
|
||||||
@ -47,7 +47,7 @@ Nu_DataSourceNew(NuDataSource** ppDataSource)
|
|||||||
* needed in the first place.) Buffer sources are a little scary since
|
* needed in the first place.) Buffer sources are a little scary since
|
||||||
* they include a "curOffset" value.
|
* they include a "curOffset" value.
|
||||||
*
|
*
|
||||||
* Returns nil on error.
|
* Returns NULL on error.
|
||||||
*/
|
*/
|
||||||
NuDataSource*
|
NuDataSource*
|
||||||
Nu_DataSourceCopy(NuDataSource* pDataSource)
|
Nu_DataSourceCopy(NuDataSource* pDataSource)
|
||||||
@ -59,18 +59,18 @@ Nu_DataSourceCopy(NuDataSource* pDataSource)
|
|||||||
#if 0 /* we used to copy them -- very bad idea */
|
#if 0 /* we used to copy them -- very bad idea */
|
||||||
NuDataSource* pNewDataSource;
|
NuDataSource* pNewDataSource;
|
||||||
|
|
||||||
Assert(pDataSource != nil);
|
Assert(pDataSource != NULL);
|
||||||
|
|
||||||
if (Nu_DataSourceNew(&pNewDataSource) != kNuErrNone)
|
if (Nu_DataSourceNew(&pNewDataSource) != kNuErrNone)
|
||||||
return nil;
|
return NULL;
|
||||||
Assert(pNewDataSource != nil);
|
Assert(pNewDataSource != NULL);
|
||||||
|
|
||||||
/* this gets most of it */
|
/* this gets most of it */
|
||||||
memcpy(pNewDataSource, pDataSource, sizeof(*pNewDataSource));
|
memcpy(pNewDataSource, pDataSource, sizeof(*pNewDataSource));
|
||||||
|
|
||||||
/* copy anything we're sure to free up */
|
/* copy anything we're sure to free up */
|
||||||
if (pDataSource->sourceType == kNuDataSourceFromFile) {
|
if (pDataSource->sourceType == kNuDataSourceFromFile) {
|
||||||
Assert(pDataSource->fromFile.fp == nil); /* does this matter? */
|
Assert(pDataSource->fromFile.fp == NULL); /* does this matter? */
|
||||||
pNewDataSource->fromFile.pathname =
|
pNewDataSource->fromFile.pathname =
|
||||||
strdup(pDataSource->fromFile.pathname);
|
strdup(pDataSource->fromFile.pathname);
|
||||||
}
|
}
|
||||||
@ -92,7 +92,7 @@ Nu_DataSourceCopy(NuDataSource* pDataSource)
|
|||||||
NuError
|
NuError
|
||||||
Nu_DataSourceFree(NuDataSource* pDataSource)
|
Nu_DataSourceFree(NuDataSource* pDataSource)
|
||||||
{
|
{
|
||||||
if (pDataSource == nil)
|
if (pDataSource == NULL)
|
||||||
return kNuErrNone;
|
return kNuErrNone;
|
||||||
|
|
||||||
Assert(pDataSource->common.refCount > 0);
|
Assert(pDataSource->common.refCount > 0);
|
||||||
@ -103,25 +103,25 @@ Nu_DataSourceFree(NuDataSource* pDataSource)
|
|||||||
|
|
||||||
switch (pDataSource->sourceType) {
|
switch (pDataSource->sourceType) {
|
||||||
case kNuDataSourceFromFile:
|
case kNuDataSourceFromFile:
|
||||||
Nu_Free(nil, pDataSource->fromFile.pathname);
|
Nu_Free(NULL, pDataSource->fromFile.pathname);
|
||||||
if (pDataSource->fromFile.fp != nil) {
|
if (pDataSource->fromFile.fp != NULL) {
|
||||||
fclose(pDataSource->fromFile.fp);
|
fclose(pDataSource->fromFile.fp);
|
||||||
pDataSource->fromFile.fp = nil;
|
pDataSource->fromFile.fp = NULL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case kNuDataSourceFromFP:
|
case kNuDataSourceFromFP:
|
||||||
if (pDataSource->fromFP.fcloseFunc != nil &&
|
if (pDataSource->fromFP.fcloseFunc != NULL &&
|
||||||
pDataSource->fromFP.fp != nil)
|
pDataSource->fromFP.fp != NULL)
|
||||||
{
|
{
|
||||||
(*pDataSource->fromFP.fcloseFunc)(nil, pDataSource->fromFP.fp);
|
(*pDataSource->fromFP.fcloseFunc)(NULL, pDataSource->fromFP.fp);
|
||||||
pDataSource->fromFP.fp = nil;
|
pDataSource->fromFP.fp = NULL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case kNuDataSourceFromBuffer:
|
case kNuDataSourceFromBuffer:
|
||||||
if (pDataSource->fromBuffer.freeFunc != nil) {
|
if (pDataSource->fromBuffer.freeFunc != NULL) {
|
||||||
(*pDataSource->fromBuffer.freeFunc)(nil,
|
(*pDataSource->fromBuffer.freeFunc)(NULL,
|
||||||
(void*)pDataSource->fromBuffer.buffer);
|
(void*)pDataSource->fromBuffer.buffer);
|
||||||
pDataSource->fromBuffer.buffer = nil;
|
pDataSource->fromBuffer.buffer = NULL;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case kNuDataSourceUnknown:
|
case kNuDataSourceUnknown:
|
||||||
@ -131,7 +131,7 @@ Nu_DataSourceFree(NuDataSource* pDataSource)
|
|||||||
return kNuErrInternal;
|
return kNuErrInternal;
|
||||||
}
|
}
|
||||||
|
|
||||||
Nu_Free(nil, pDataSource);
|
Nu_Free(NULL, pDataSource);
|
||||||
return kNuErrNone;
|
return kNuErrNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,9 +145,9 @@ Nu_DataSourceFile_New(NuThreadFormat threadFormat, ulong otherLen,
|
|||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
|
|
||||||
if (pathname == nil ||
|
if (pathname == NULL ||
|
||||||
!(isFromRsrcFork == true || isFromRsrcFork == false) ||
|
!(isFromRsrcFork == true || isFromRsrcFork == false) ||
|
||||||
ppDataSource == nil)
|
ppDataSource == NULL)
|
||||||
{
|
{
|
||||||
return kNuErrInvalidArg;
|
return kNuErrInvalidArg;
|
||||||
}
|
}
|
||||||
@ -164,7 +164,7 @@ Nu_DataSourceFile_New(NuThreadFormat threadFormat, ulong otherLen,
|
|||||||
|
|
||||||
(*ppDataSource)->fromFile.pathname = strdup(pathname);
|
(*ppDataSource)->fromFile.pathname = strdup(pathname);
|
||||||
(*ppDataSource)->fromFile.fromRsrcFork = isFromRsrcFork;
|
(*ppDataSource)->fromFile.fromRsrcFork = isFromRsrcFork;
|
||||||
(*ppDataSource)->fromFile.fp = nil; /* to be filled in later */
|
(*ppDataSource)->fromFile.fp = NULL; /* to be filled in later */
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
return err;
|
return err;
|
||||||
@ -182,8 +182,8 @@ Nu_DataSourceFP_New(NuThreadFormat threadFormat, ulong otherLen,
|
|||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
|
|
||||||
if (fp == nil || offset < 0 || length < 0 ||
|
if (fp == NULL || offset < 0 || length < 0 ||
|
||||||
ppDataSource == nil)
|
ppDataSource == NULL)
|
||||||
{
|
{
|
||||||
return kNuErrInvalidArg;
|
return kNuErrInvalidArg;
|
||||||
}
|
}
|
||||||
@ -216,8 +216,8 @@ bail:
|
|||||||
/*
|
/*
|
||||||
* Create a data source for a buffer.
|
* Create a data source for a buffer.
|
||||||
*
|
*
|
||||||
* We allow "buffer" to be nil so long as "offset" and "length" are also
|
* We allow "buffer" to be NULL so long as "offset" and "length" are also
|
||||||
* nil. This is useful for creating empty pre-sized buffers, such as
|
* NULL. This is useful for creating empty pre-sized buffers, such as
|
||||||
* blank comment fields.
|
* blank comment fields.
|
||||||
*/
|
*/
|
||||||
NuError
|
NuError
|
||||||
@ -227,14 +227,14 @@ Nu_DataSourceBuffer_New(NuThreadFormat threadFormat, ulong otherLen,
|
|||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
|
|
||||||
if (offset < 0 || length < 0 || ppDataSource == nil)
|
if (offset < 0 || length < 0 || ppDataSource == NULL)
|
||||||
return kNuErrInvalidArg;
|
return kNuErrInvalidArg;
|
||||||
if (buffer == nil && (offset != 0 || length != 0))
|
if (buffer == NULL && (offset != 0 || length != 0))
|
||||||
return kNuErrInvalidArg;
|
return kNuErrInvalidArg;
|
||||||
|
|
||||||
if (buffer == nil) {
|
if (buffer == NULL) {
|
||||||
DBUG(("+++ zeroing freeFunc for empty-buffer DataSource\n"));
|
DBUG(("+++ zeroing freeFunc for empty-buffer DataSource\n"));
|
||||||
freeFunc = nil;
|
freeFunc = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (otherLen && otherLen < (ulong)length) {
|
if (otherLen && otherLen < (ulong)length) {
|
||||||
@ -270,7 +270,7 @@ bail:
|
|||||||
NuDataSourceType
|
NuDataSourceType
|
||||||
Nu_DataSourceGetType(const NuDataSource* pDataSource)
|
Nu_DataSourceGetType(const NuDataSource* pDataSource)
|
||||||
{
|
{
|
||||||
Assert(pDataSource != nil);
|
Assert(pDataSource != NULL);
|
||||||
return pDataSource->sourceType;
|
return pDataSource->sourceType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,7 +280,7 @@ Nu_DataSourceGetType(const NuDataSource* pDataSource)
|
|||||||
NuThreadFormat
|
NuThreadFormat
|
||||||
Nu_DataSourceGetThreadFormat(const NuDataSource* pDataSource)
|
Nu_DataSourceGetThreadFormat(const NuDataSource* pDataSource)
|
||||||
{
|
{
|
||||||
Assert(pDataSource != nil);
|
Assert(pDataSource != NULL);
|
||||||
return pDataSource->common.threadFormat;
|
return pDataSource->common.threadFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,11 +290,11 @@ Nu_DataSourceGetThreadFormat(const NuDataSource* pDataSource)
|
|||||||
ulong
|
ulong
|
||||||
Nu_DataSourceGetDataLen(const NuDataSource* pDataSource)
|
Nu_DataSourceGetDataLen(const NuDataSource* pDataSource)
|
||||||
{
|
{
|
||||||
Assert(pDataSource != nil);
|
Assert(pDataSource != NULL);
|
||||||
|
|
||||||
if (pDataSource->sourceType == kNuDataSourceFromFile) {
|
if (pDataSource->sourceType == kNuDataSourceFromFile) {
|
||||||
/* dataLen can only be valid if file has been opened */
|
/* dataLen can only be valid if file has been opened */
|
||||||
Assert(pDataSource->fromFile.fp != nil);
|
Assert(pDataSource->fromFile.fp != NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pDataSource->common.dataLen;
|
return pDataSource->common.dataLen;
|
||||||
@ -306,7 +306,7 @@ Nu_DataSourceGetDataLen(const NuDataSource* pDataSource)
|
|||||||
ulong
|
ulong
|
||||||
Nu_DataSourceGetOtherLen(const NuDataSource* pDataSource)
|
Nu_DataSourceGetOtherLen(const NuDataSource* pDataSource)
|
||||||
{
|
{
|
||||||
Assert(pDataSource != nil);
|
Assert(pDataSource != NULL);
|
||||||
return pDataSource->common.otherLen;
|
return pDataSource->common.otherLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,7 +316,7 @@ Nu_DataSourceGetOtherLen(const NuDataSource* pDataSource)
|
|||||||
void
|
void
|
||||||
Nu_DataSourceSetOtherLen(NuDataSource* pDataSource, long otherLen)
|
Nu_DataSourceSetOtherLen(NuDataSource* pDataSource, long otherLen)
|
||||||
{
|
{
|
||||||
Assert(pDataSource != nil && otherLen > 0);
|
Assert(pDataSource != NULL && otherLen > 0);
|
||||||
pDataSource->common.otherLen = otherLen;
|
pDataSource->common.otherLen = otherLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,7 +327,7 @@ Nu_DataSourceSetOtherLen(NuDataSource* pDataSource, long otherLen)
|
|||||||
ushort
|
ushort
|
||||||
Nu_DataSourceGetRawCrc(const NuDataSource* pDataSource)
|
Nu_DataSourceGetRawCrc(const NuDataSource* pDataSource)
|
||||||
{
|
{
|
||||||
Assert(pDataSource != nil);
|
Assert(pDataSource != NULL);
|
||||||
return pDataSource->common.rawCrc;
|
return pDataSource->common.rawCrc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -338,7 +338,7 @@ Nu_DataSourceGetRawCrc(const NuDataSource* pDataSource)
|
|||||||
void
|
void
|
||||||
Nu_DataSourceSetRawCrc(NuDataSource* pDataSource, ushort crc)
|
Nu_DataSourceSetRawCrc(NuDataSource* pDataSource, ushort crc)
|
||||||
{
|
{
|
||||||
Assert(pDataSource != nil);
|
Assert(pDataSource != NULL);
|
||||||
pDataSource->common.rawCrc = crc;
|
pDataSource->common.rawCrc = crc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -350,7 +350,7 @@ NuError
|
|||||||
Nu_DataSourcePrepareInput(NuArchive* pArchive, NuDataSource* pDataSource)
|
Nu_DataSourcePrepareInput(NuArchive* pArchive, NuDataSource* pDataSource)
|
||||||
{
|
{
|
||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
FILE* fileFp = nil;
|
FILE* fileFp = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Doesn't apply to buffer sources.
|
* Doesn't apply to buffer sources.
|
||||||
@ -376,7 +376,7 @@ Nu_DataSourcePrepareInput(NuArchive* pArchive, NuDataSource* pDataSource)
|
|||||||
&fileFp);
|
&fileFp);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
|
|
||||||
Assert(fileFp != nil);
|
Assert(fileFp != NULL);
|
||||||
pDataSource->fromFile.fp = fileFp;
|
pDataSource->fromFile.fp = fileFp;
|
||||||
err = Nu_GetFileLength(pArchive, fileFp,
|
err = Nu_GetFileLength(pArchive, fileFp,
|
||||||
(long*)&pDataSource->common.dataLen);
|
(long*)&pDataSource->common.dataLen);
|
||||||
@ -409,9 +409,9 @@ Nu_DataSourceUnPrepareInput(NuArchive* pArchive, NuDataSource* pDataSource)
|
|||||||
if (Nu_DataSourceGetType(pDataSource) != kNuDataSourceFromFile)
|
if (Nu_DataSourceGetType(pDataSource) != kNuDataSourceFromFile)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (pDataSource->fromFile.fp != nil) {
|
if (pDataSource->fromFile.fp != NULL) {
|
||||||
fclose(pDataSource->fromFile.fp);
|
fclose(pDataSource->fromFile.fp);
|
||||||
pDataSource->fromFile.fp = nil;
|
pDataSource->fromFile.fp = NULL;
|
||||||
pDataSource->common.dataLen = 0;
|
pDataSource->common.dataLen = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -423,9 +423,9 @@ Nu_DataSourceUnPrepareInput(NuArchive* pArchive, NuDataSource* pDataSource)
|
|||||||
const char*
|
const char*
|
||||||
Nu_DataSourceFile_GetPathname(NuDataSource* pDataSource)
|
Nu_DataSourceFile_GetPathname(NuDataSource* pDataSource)
|
||||||
{
|
{
|
||||||
Assert(pDataSource != nil);
|
Assert(pDataSource != NULL);
|
||||||
Assert(pDataSource->sourceType == kNuDataSourceFromFile);
|
Assert(pDataSource->sourceType == kNuDataSourceFromFile);
|
||||||
Assert(pDataSource->fromFile.pathname != nil);
|
Assert(pDataSource->fromFile.pathname != NULL);
|
||||||
|
|
||||||
return pDataSource->fromFile.pathname;
|
return pDataSource->fromFile.pathname;
|
||||||
}
|
}
|
||||||
@ -439,13 +439,13 @@ Nu_DataSourceGetBlock(NuDataSource* pDataSource, uchar* buf, ulong len)
|
|||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
|
|
||||||
Assert(pDataSource != nil);
|
Assert(pDataSource != NULL);
|
||||||
Assert(buf != nil);
|
Assert(buf != NULL);
|
||||||
Assert(len > 0);
|
Assert(len > 0);
|
||||||
|
|
||||||
switch (pDataSource->sourceType) {
|
switch (pDataSource->sourceType) {
|
||||||
case kNuDataSourceFromFile:
|
case kNuDataSourceFromFile:
|
||||||
Assert(pDataSource->fromFile.fp != nil);
|
Assert(pDataSource->fromFile.fp != NULL);
|
||||||
err = Nu_FRead(pDataSource->fromFile.fp, buf, len);
|
err = Nu_FRead(pDataSource->fromFile.fp, buf, len);
|
||||||
if (feof(pDataSource->fromFile.fp))
|
if (feof(pDataSource->fromFile.fp))
|
||||||
Nu_ReportError(NU_NILBLOB, err, "EOF hit unexpectedly");
|
Nu_ReportError(NU_NILBLOB, err, "EOF hit unexpectedly");
|
||||||
@ -484,11 +484,11 @@ Nu_DataSourceRewind(NuDataSource* pDataSource)
|
|||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
|
|
||||||
Assert(pDataSource != nil);
|
Assert(pDataSource != NULL);
|
||||||
|
|
||||||
switch (pDataSource->sourceType) {
|
switch (pDataSource->sourceType) {
|
||||||
case kNuDataSourceFromFile:
|
case kNuDataSourceFromFile:
|
||||||
Assert(pDataSource->fromFile.fp != nil);
|
Assert(pDataSource->fromFile.fp != NULL);
|
||||||
err = Nu_FSeek(pDataSource->fromFile.fp, 0, SEEK_SET);
|
err = Nu_FSeek(pDataSource->fromFile.fp, 0, SEEK_SET);
|
||||||
break; /* fall through with error */
|
break; /* fall through with error */
|
||||||
case kNuDataSourceFromFP:
|
case kNuDataSourceFromFP:
|
||||||
@ -521,10 +521,10 @@ Nu_DataSourceRewind(NuDataSource* pDataSource)
|
|||||||
static NuError
|
static NuError
|
||||||
Nu_DataSinkNew(NuDataSink** ppDataSink)
|
Nu_DataSinkNew(NuDataSink** ppDataSink)
|
||||||
{
|
{
|
||||||
Assert(ppDataSink != nil);
|
Assert(ppDataSink != NULL);
|
||||||
|
|
||||||
*ppDataSink = Nu_Malloc(nil, sizeof(**ppDataSink));
|
*ppDataSink = Nu_Malloc(NULL, sizeof(**ppDataSink));
|
||||||
if (*ppDataSink == nil)
|
if (*ppDataSink == NULL)
|
||||||
return kNuErrMalloc;
|
return kNuErrMalloc;
|
||||||
|
|
||||||
(*ppDataSink)->sinkType = kNuDataSinkUnknown;
|
(*ppDataSink)->sinkType = kNuDataSinkUnknown;
|
||||||
@ -539,13 +539,13 @@ Nu_DataSinkNew(NuDataSink** ppDataSink)
|
|||||||
NuError
|
NuError
|
||||||
Nu_DataSinkFree(NuDataSink* pDataSink)
|
Nu_DataSinkFree(NuDataSink* pDataSink)
|
||||||
{
|
{
|
||||||
if (pDataSink == nil)
|
if (pDataSink == NULL)
|
||||||
return kNuErrNone;
|
return kNuErrNone;
|
||||||
|
|
||||||
switch (pDataSink->sinkType) {
|
switch (pDataSink->sinkType) {
|
||||||
case kNuDataSinkToFile:
|
case kNuDataSinkToFile:
|
||||||
Nu_DataSinkFile_Close(pDataSink);
|
Nu_DataSinkFile_Close(pDataSink);
|
||||||
Nu_Free(nil, pDataSink->toFile.pathname);
|
Nu_Free(NULL, pDataSink->toFile.pathname);
|
||||||
break;
|
break;
|
||||||
case kNuDataSinkToFP:
|
case kNuDataSinkToFP:
|
||||||
break;
|
break;
|
||||||
@ -560,7 +560,7 @@ Nu_DataSinkFree(NuDataSink* pDataSink)
|
|||||||
return kNuErrInternal;
|
return kNuErrInternal;
|
||||||
}
|
}
|
||||||
|
|
||||||
Nu_Free(nil, pDataSink);
|
Nu_Free(NULL, pDataSink);
|
||||||
return kNuErrNone;
|
return kNuErrNone;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -577,9 +577,9 @@ Nu_DataSinkFile_New(Boolean doExpand, NuValue convertEOL, const char* pathname,
|
|||||||
if ((doExpand != true && doExpand != false) ||
|
if ((doExpand != true && doExpand != false) ||
|
||||||
(convertEOL != kNuConvertOff && convertEOL != kNuConvertOn &&
|
(convertEOL != kNuConvertOff && convertEOL != kNuConvertOn &&
|
||||||
convertEOL != kNuConvertAuto) ||
|
convertEOL != kNuConvertAuto) ||
|
||||||
pathname == nil ||
|
pathname == NULL ||
|
||||||
fssep == 0 ||
|
fssep == 0 ||
|
||||||
ppDataSink == nil)
|
ppDataSink == NULL)
|
||||||
{
|
{
|
||||||
return kNuErrInvalidArg;
|
return kNuErrInvalidArg;
|
||||||
}
|
}
|
||||||
@ -597,7 +597,7 @@ Nu_DataSinkFile_New(Boolean doExpand, NuValue convertEOL, const char* pathname,
|
|||||||
(*ppDataSink)->toFile.pathname = strdup(pathname);
|
(*ppDataSink)->toFile.pathname = strdup(pathname);
|
||||||
(*ppDataSink)->toFile.fssep = fssep;
|
(*ppDataSink)->toFile.fssep = fssep;
|
||||||
|
|
||||||
(*ppDataSink)->toFile.fp = nil;
|
(*ppDataSink)->toFile.fp = NULL;
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
return err;
|
return err;
|
||||||
@ -616,8 +616,8 @@ Nu_DataSinkFP_New(Boolean doExpand, NuValue convertEOL, FILE* fp,
|
|||||||
if ((doExpand != true && doExpand != false) ||
|
if ((doExpand != true && doExpand != false) ||
|
||||||
(convertEOL != kNuConvertOff && convertEOL != kNuConvertOn &&
|
(convertEOL != kNuConvertOff && convertEOL != kNuConvertOn &&
|
||||||
convertEOL != kNuConvertAuto) ||
|
convertEOL != kNuConvertAuto) ||
|
||||||
fp == nil ||
|
fp == NULL ||
|
||||||
ppDataSink == nil)
|
ppDataSink == NULL)
|
||||||
{
|
{
|
||||||
return kNuErrInvalidArg;
|
return kNuErrInvalidArg;
|
||||||
}
|
}
|
||||||
@ -651,9 +651,9 @@ Nu_DataSinkBuffer_New(Boolean doExpand, NuValue convertEOL, uchar* buffer,
|
|||||||
if ((doExpand != true && doExpand != false) ||
|
if ((doExpand != true && doExpand != false) ||
|
||||||
(convertEOL != kNuConvertOff && convertEOL != kNuConvertOn &&
|
(convertEOL != kNuConvertOff && convertEOL != kNuConvertOn &&
|
||||||
convertEOL != kNuConvertAuto) ||
|
convertEOL != kNuConvertAuto) ||
|
||||||
buffer == nil ||
|
buffer == NULL ||
|
||||||
bufLen == 0 ||
|
bufLen == 0 ||
|
||||||
ppDataSink == nil)
|
ppDataSink == NULL)
|
||||||
{
|
{
|
||||||
return kNuErrInvalidArg;
|
return kNuErrInvalidArg;
|
||||||
}
|
}
|
||||||
@ -688,7 +688,7 @@ Nu_DataSinkVoid_New(Boolean doExpand, NuValue convertEOL,
|
|||||||
NuError err;
|
NuError err;
|
||||||
|
|
||||||
Assert(doExpand == true || doExpand == false);
|
Assert(doExpand == true || doExpand == false);
|
||||||
Assert(ppDataSink != nil);
|
Assert(ppDataSink != NULL);
|
||||||
|
|
||||||
err = Nu_DataSinkNew(ppDataSink);
|
err = Nu_DataSinkNew(ppDataSink);
|
||||||
BailErrorQuiet(err);
|
BailErrorQuiet(err);
|
||||||
@ -709,7 +709,7 @@ bail:
|
|||||||
NuDataSinkType
|
NuDataSinkType
|
||||||
Nu_DataSinkGetType(const NuDataSink* pDataSink)
|
Nu_DataSinkGetType(const NuDataSink* pDataSink)
|
||||||
{
|
{
|
||||||
Assert(pDataSink != nil);
|
Assert(pDataSink != NULL);
|
||||||
return pDataSink->sinkType;
|
return pDataSink->sinkType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -748,7 +748,7 @@ Nu_DataSinkGetOutCount(const NuDataSink* pDataSink)
|
|||||||
const char*
|
const char*
|
||||||
Nu_DataSinkFile_GetPathname(const NuDataSink* pDataSink)
|
Nu_DataSinkFile_GetPathname(const NuDataSink* pDataSink)
|
||||||
{
|
{
|
||||||
Assert(pDataSink != nil);
|
Assert(pDataSink != NULL);
|
||||||
Assert(pDataSink->sinkType == kNuDataSinkToFile);
|
Assert(pDataSink->sinkType == kNuDataSinkToFile);
|
||||||
|
|
||||||
return pDataSink->toFile.pathname;
|
return pDataSink->toFile.pathname;
|
||||||
@ -760,7 +760,7 @@ Nu_DataSinkFile_GetPathname(const NuDataSink* pDataSink)
|
|||||||
char
|
char
|
||||||
Nu_DataSinkFile_GetFssep(const NuDataSink* pDataSink)
|
Nu_DataSinkFile_GetFssep(const NuDataSink* pDataSink)
|
||||||
{
|
{
|
||||||
Assert(pDataSink != nil);
|
Assert(pDataSink != NULL);
|
||||||
Assert(pDataSink->sinkType == kNuDataSinkToFile);
|
Assert(pDataSink->sinkType == kNuDataSinkToFile);
|
||||||
|
|
||||||
return pDataSink->toFile.fssep;
|
return pDataSink->toFile.fssep;
|
||||||
@ -772,7 +772,7 @@ Nu_DataSinkFile_GetFssep(const NuDataSink* pDataSink)
|
|||||||
FILE*
|
FILE*
|
||||||
Nu_DataSinkFile_GetFP(const NuDataSink* pDataSink)
|
Nu_DataSinkFile_GetFP(const NuDataSink* pDataSink)
|
||||||
{
|
{
|
||||||
Assert(pDataSink != nil);
|
Assert(pDataSink != NULL);
|
||||||
Assert(pDataSink->sinkType == kNuDataSinkToFile);
|
Assert(pDataSink->sinkType == kNuDataSinkToFile);
|
||||||
|
|
||||||
return pDataSink->toFile.fp;
|
return pDataSink->toFile.fp;
|
||||||
@ -784,7 +784,7 @@ Nu_DataSinkFile_GetFP(const NuDataSink* pDataSink)
|
|||||||
void
|
void
|
||||||
Nu_DataSinkFile_SetFP(NuDataSink* pDataSink, FILE* fp)
|
Nu_DataSinkFile_SetFP(NuDataSink* pDataSink, FILE* fp)
|
||||||
{
|
{
|
||||||
Assert(pDataSink != nil);
|
Assert(pDataSink != NULL);
|
||||||
Assert(pDataSink->sinkType == kNuDataSinkToFile);
|
Assert(pDataSink->sinkType == kNuDataSinkToFile);
|
||||||
|
|
||||||
pDataSink->toFile.fp = fp;
|
pDataSink->toFile.fp = fp;
|
||||||
@ -796,11 +796,11 @@ Nu_DataSinkFile_SetFP(NuDataSink* pDataSink, FILE* fp)
|
|||||||
void
|
void
|
||||||
Nu_DataSinkFile_Close(NuDataSink* pDataSink)
|
Nu_DataSinkFile_Close(NuDataSink* pDataSink)
|
||||||
{
|
{
|
||||||
Assert(pDataSink != nil);
|
Assert(pDataSink != NULL);
|
||||||
|
|
||||||
if (pDataSink->toFile.fp != nil) {
|
if (pDataSink->toFile.fp != NULL) {
|
||||||
fclose(pDataSink->toFile.fp);
|
fclose(pDataSink->toFile.fp);
|
||||||
pDataSink->toFile.fp = nil;
|
pDataSink->toFile.fp = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -813,19 +813,19 @@ Nu_DataSinkPutBlock(NuDataSink* pDataSink, const uchar* buf, ulong len)
|
|||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
|
|
||||||
Assert(pDataSink != nil);
|
Assert(pDataSink != NULL);
|
||||||
Assert(buf != nil);
|
Assert(buf != NULL);
|
||||||
Assert(len > 0);
|
Assert(len > 0);
|
||||||
|
|
||||||
switch (pDataSink->sinkType) {
|
switch (pDataSink->sinkType) {
|
||||||
case kNuDataSinkToFile:
|
case kNuDataSinkToFile:
|
||||||
Assert(pDataSink->toFile.fp != nil);
|
Assert(pDataSink->toFile.fp != NULL);
|
||||||
err = Nu_FWrite(pDataSink->toFile.fp, buf, len);
|
err = Nu_FWrite(pDataSink->toFile.fp, buf, len);
|
||||||
if (err != kNuErrNone)
|
if (err != kNuErrNone)
|
||||||
return err;
|
return err;
|
||||||
break;
|
break;
|
||||||
case kNuDataSinkToFP:
|
case kNuDataSinkToFP:
|
||||||
Assert(pDataSink->toFP.fp != nil);
|
Assert(pDataSink->toFP.fp != NULL);
|
||||||
err = Nu_FWrite(pDataSink->toFP.fp, buf, len);
|
err = Nu_FWrite(pDataSink->toFP.fp, buf, len);
|
||||||
if (err != kNuErrNone)
|
if (err != kNuErrNone)
|
||||||
return err;
|
return err;
|
||||||
@ -861,7 +861,7 @@ Nu_DataSinkGetError(NuDataSink* pDataSink)
|
|||||||
{
|
{
|
||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
|
|
||||||
Assert(pDataSink != nil);
|
Assert(pDataSink != NULL);
|
||||||
|
|
||||||
switch (pDataSink->sinkType) {
|
switch (pDataSink->sinkType) {
|
||||||
case kNuDataSinkToFile:
|
case kNuDataSinkToFile:
|
||||||
|
@ -704,7 +704,7 @@ Nu_CompressHuffmanSQ(NuArchive* pArchive, NuStraw* pStraw, FILE* fp,
|
|||||||
|
|
||||||
sqState.pArchive = pArchive;
|
sqState.pArchive = pArchive;
|
||||||
sqState.crc = 0;
|
sqState.crc = 0;
|
||||||
if (pCrc == nil) {
|
if (pCrc == NULL) {
|
||||||
sqState.doCalcCRC = false;
|
sqState.doCalcCRC = false;
|
||||||
} else {
|
} else {
|
||||||
sqState.doCalcCRC = true;
|
sqState.doCalcCRC = true;
|
||||||
@ -727,7 +727,7 @@ Nu_CompressHuffmanSQ(NuArchive* pArchive, NuStraw* pStraw, FILE* fp,
|
|||||||
err = Nu_SQComputeHuffTree(&sqState);
|
err = Nu_SQComputeHuffTree(&sqState);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
|
|
||||||
if (pCrc != nil)
|
if (pCrc != NULL)
|
||||||
*pCrc = sqState.crc;
|
*pCrc = sqState.crc;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -915,7 +915,7 @@ Nu_ExpandHuffmanSQ(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
err = Nu_AllocCompressionBufferIFN(pArchive);
|
err = Nu_AllocCompressionBufferIFN(pArchive);
|
||||||
if (err != kNuErrNone)
|
if (err != kNuErrNone)
|
||||||
return err;
|
return err;
|
||||||
Assert(pArchive->compBuf != nil);
|
Assert(pArchive->compBuf != NULL);
|
||||||
|
|
||||||
usqState.dataInBuffer = 0;
|
usqState.dataInBuffer = 0;
|
||||||
usqState.dataPtr = pArchive->compBuf;
|
usqState.dataPtr = pArchive->compBuf;
|
||||||
@ -1080,7 +1080,7 @@ Nu_ExpandHuffmanSQ(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
val = 2;
|
val = 2;
|
||||||
}
|
}
|
||||||
while (--val) {
|
while (--val) {
|
||||||
if (pCrc != nil)
|
if (pCrc != NULL)
|
||||||
*pCrc = Nu_CalcCRC16(*pCrc, &lastc, 1);
|
*pCrc = Nu_CalcCRC16(*pCrc, &lastc, 1);
|
||||||
err = Nu_FunnelWrite(pArchive, pFunnel, &lastc, 1);
|
err = Nu_FunnelWrite(pArchive, pFunnel, &lastc, 1);
|
||||||
#ifdef FULL_SQ_HEADER
|
#ifdef FULL_SQ_HEADER
|
||||||
@ -1095,7 +1095,7 @@ Nu_ExpandHuffmanSQ(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
inrep = true;
|
inrep = true;
|
||||||
} else {
|
} else {
|
||||||
lastc = val;
|
lastc = val;
|
||||||
if (pCrc != nil)
|
if (pCrc != NULL)
|
||||||
*pCrc = Nu_CalcCRC16(*pCrc, &lastc, 1);
|
*pCrc = Nu_CalcCRC16(*pCrc, &lastc, 1);
|
||||||
err = Nu_FunnelWrite(pArchive, pFunnel, &lastc, 1);
|
err = Nu_FunnelWrite(pArchive, pFunnel, &lastc, 1);
|
||||||
#ifdef FULL_SQ_HEADER
|
#ifdef FULL_SQ_HEADER
|
||||||
|
150
nufxlib/Thread.c
150
nufxlib/Thread.c
@ -92,7 +92,7 @@ Nu_FindThreadByIdx(const NuRecord* pRecord, NuThreadIdx thread,
|
|||||||
|
|
||||||
for (idx = 0; idx < (int)pRecord->recTotalThreads; idx++) {
|
for (idx = 0; idx < (int)pRecord->recTotalThreads; idx++) {
|
||||||
pThread = Nu_GetThread(pRecord, idx);
|
pThread = Nu_GetThread(pRecord, idx);
|
||||||
Assert(pThread != nil);
|
Assert(pThread != NULL);
|
||||||
|
|
||||||
if (pThread->threadIdx == thread) {
|
if (pThread->threadIdx == thread) {
|
||||||
*ppThread = pThread;
|
*ppThread = pThread;
|
||||||
@ -117,7 +117,7 @@ Nu_FindThreadByID(const NuRecord* pRecord, NuThreadID threadID,
|
|||||||
|
|
||||||
for (idx = 0; idx < (int)pRecord->recTotalThreads; idx++) {
|
for (idx = 0; idx < (int)pRecord->recTotalThreads; idx++) {
|
||||||
pThread = Nu_GetThread(pRecord, idx);
|
pThread = Nu_GetThread(pRecord, idx);
|
||||||
Assert(pThread != nil);
|
Assert(pThread != NULL);
|
||||||
|
|
||||||
if (NuGetThreadID(pThread) == threadID) {
|
if (NuGetThreadID(pThread) == threadID) {
|
||||||
*ppThread = pThread;
|
*ppThread = pThread;
|
||||||
@ -135,8 +135,8 @@ Nu_FindThreadByID(const NuRecord* pRecord, NuThreadID threadID,
|
|||||||
void
|
void
|
||||||
Nu_CopyThreadContents(NuThread* pDstThread, const NuThread* pSrcThread)
|
Nu_CopyThreadContents(NuThread* pDstThread, const NuThread* pSrcThread)
|
||||||
{
|
{
|
||||||
Assert(pDstThread != nil);
|
Assert(pDstThread != NULL);
|
||||||
Assert(pSrcThread != nil);
|
Assert(pSrcThread != NULL);
|
||||||
|
|
||||||
memcpy(pDstThread, pSrcThread, sizeof(*pDstThread));
|
memcpy(pDstThread, pSrcThread, sizeof(*pDstThread));
|
||||||
}
|
}
|
||||||
@ -156,9 +156,9 @@ Nu_ReadThreadHeader(NuArchive* pArchive, NuThread* pThread, ushort* pCrc)
|
|||||||
{
|
{
|
||||||
FILE* fp;
|
FILE* fp;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pThread != nil);
|
Assert(pThread != NULL);
|
||||||
Assert(pCrc != nil);
|
Assert(pCrc != NULL);
|
||||||
|
|
||||||
fp = pArchive->archiveFp;
|
fp = pArchive->archiveFp;
|
||||||
|
|
||||||
@ -192,9 +192,9 @@ Nu_ReadThreadHeaders(NuArchive* pArchive, NuRecord* pRecord, ushort* pCrc)
|
|||||||
long count;
|
long count;
|
||||||
Boolean hasData = false;
|
Boolean hasData = false;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pRecord != nil);
|
Assert(pRecord != NULL);
|
||||||
Assert(pCrc != nil);
|
Assert(pCrc != NULL);
|
||||||
|
|
||||||
if (!pRecord->recTotalThreads) {
|
if (!pRecord->recTotalThreads) {
|
||||||
/* not sure if this is reasonable, but we can handle it */
|
/* not sure if this is reasonable, but we can handle it */
|
||||||
@ -310,10 +310,10 @@ static NuError
|
|||||||
Nu_WriteThreadHeader(NuArchive* pArchive, const NuThread* pThread, FILE* fp,
|
Nu_WriteThreadHeader(NuArchive* pArchive, const NuThread* pThread, FILE* fp,
|
||||||
ushort* pCrc)
|
ushort* pCrc)
|
||||||
{
|
{
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pThread != nil);
|
Assert(pThread != NULL);
|
||||||
Assert(fp != nil);
|
Assert(fp != NULL);
|
||||||
Assert(pCrc != nil);
|
Assert(pCrc != NULL);
|
||||||
|
|
||||||
Nu_WriteTwoC(pArchive, fp, pThread->thThreadClass, pCrc);
|
Nu_WriteTwoC(pArchive, fp, pThread->thThreadClass, pCrc);
|
||||||
Nu_WriteTwoC(pArchive, fp, (ushort)pThread->thThreadFormat, pCrc);
|
Nu_WriteTwoC(pArchive, fp, (ushort)pThread->thThreadFormat, pCrc);
|
||||||
@ -342,7 +342,7 @@ Nu_WriteThreadHeaders(NuArchive* pArchive, NuRecord* pRecord, FILE* fp,
|
|||||||
|
|
||||||
for (idx = 0; idx < (int)pRecord->recTotalThreads; idx++) {
|
for (idx = 0; idx < (int)pRecord->recTotalThreads; idx++) {
|
||||||
pThread = Nu_GetThread(pRecord, idx);
|
pThread = Nu_GetThread(pRecord, idx);
|
||||||
Assert(pThread != nil);
|
Assert(pThread != NULL);
|
||||||
|
|
||||||
err = Nu_WriteThreadHeader(pArchive, pThread, fp, pCrc);
|
err = Nu_WriteThreadHeader(pArchive, pThread, fp, pCrc);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
@ -372,8 +372,8 @@ Nu_ComputeThreadData(NuArchive* pArchive, NuRecord* pRecord)
|
|||||||
NuThread* pThread;
|
NuThread* pThread;
|
||||||
long fileOffset, count;
|
long fileOffset, count;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pRecord != nil);
|
Assert(pRecord != NULL);
|
||||||
|
|
||||||
/*pRecord->totalLength = 0;*/
|
/*pRecord->totalLength = 0;*/
|
||||||
pRecord->totalCompLength = 0;
|
pRecord->totalCompLength = 0;
|
||||||
@ -414,8 +414,8 @@ Nu_ScanThreads(NuArchive* pArchive, NuRecord* pRecord, long numThreads)
|
|||||||
NuThread* pThread;
|
NuThread* pThread;
|
||||||
FILE* fp;
|
FILE* fp;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pRecord != nil);
|
Assert(pRecord != NULL);
|
||||||
|
|
||||||
fp = pArchive->archiveFp;
|
fp = pArchive->archiveFp;
|
||||||
|
|
||||||
@ -423,7 +423,7 @@ Nu_ScanThreads(NuArchive* pArchive, NuRecord* pRecord, long numThreads)
|
|||||||
|
|
||||||
pThread = pRecord->pThreads;
|
pThread = pRecord->pThreads;
|
||||||
while (numThreads--) {
|
while (numThreads--) {
|
||||||
if (pRecord->threadFilename == nil &&
|
if (pRecord->threadFilename == NULL &&
|
||||||
NuMakeThreadID(pThread->thThreadClass, pThread->thThreadKind) ==
|
NuMakeThreadID(pThread->thThreadClass, pThread->thThreadKind) ==
|
||||||
kNuThreadIDFilename)
|
kNuThreadIDFilename)
|
||||||
{
|
{
|
||||||
@ -452,7 +452,7 @@ Nu_ScanThreads(NuArchive* pArchive, NuRecord* pRecord, long numThreads)
|
|||||||
Nu_StripHiIfAllSet(pRecord->threadFilename);
|
Nu_StripHiIfAllSet(pRecord->threadFilename);
|
||||||
|
|
||||||
/* prefer this one over the record one, but only one should exist */
|
/* prefer this one over the record one, but only one should exist */
|
||||||
if (pRecord->filename != nil) {
|
if (pRecord->filename != NULL) {
|
||||||
DBUG(("--- HEY: got record filename and thread filename\n"));
|
DBUG(("--- HEY: got record filename and thread filename\n"));
|
||||||
}
|
}
|
||||||
pRecord->filename = pRecord->threadFilename;
|
pRecord->filename = pRecord->threadFilename;
|
||||||
@ -473,7 +473,7 @@ Nu_ScanThreads(NuArchive* pArchive, NuRecord* pRecord, long numThreads)
|
|||||||
* end up with a disk image that had no name attached. This will tend
|
* 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.
|
* to confuse things, so we go ahead and give it a name.
|
||||||
*/
|
*/
|
||||||
if (pRecord->filename == nil) {
|
if (pRecord->filename == NULL) {
|
||||||
DBUG(("+++ no filename found, using default record name\n"));
|
DBUG(("+++ no filename found, using default record name\n"));
|
||||||
pRecord->filename = kNuDefaultRecordName;
|
pRecord->filename = kNuDefaultRecordName;
|
||||||
}
|
}
|
||||||
@ -527,7 +527,7 @@ Nu_ExtractThreadToDataSink(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
const NuThread* pThread, NuProgressData* pProgress, NuDataSink* pDataSink)
|
const NuThread* pThread, NuProgressData* pProgress, NuDataSink* pDataSink)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
NuFunnel* pFunnel = nil;
|
NuFunnel* pFunnel = NULL;
|
||||||
|
|
||||||
/* if it's not a stream, seek to the appropriate spot in the file */
|
/* if it's not a stream, seek to the appropriate spot in the file */
|
||||||
if (!Nu_IsStreaming(pArchive)) {
|
if (!Nu_IsStreaming(pArchive)) {
|
||||||
@ -586,18 +586,18 @@ Nu_ExtractThreadCommon(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
NuProgressData progressData;
|
NuProgressData progressData;
|
||||||
NuProgressData* pProgressData;
|
NuProgressData* pProgressData;
|
||||||
NuDataSink* pOrigDataSink;
|
NuDataSink* pOrigDataSink;
|
||||||
char* newPathStorage = nil;
|
char* newPathStorage = NULL;
|
||||||
const char* newPathname;
|
const char* newPathname;
|
||||||
NuResult result;
|
NuResult result;
|
||||||
uchar newFssep;
|
uchar newFssep;
|
||||||
Boolean doFreeSink = false;
|
Boolean doFreeSink = false;
|
||||||
|
|
||||||
Assert(pRecord != nil);
|
Assert(pRecord != NULL);
|
||||||
Assert(pThread != nil);
|
Assert(pThread != NULL);
|
||||||
Assert(pDataSink != nil);
|
Assert(pDataSink != NULL);
|
||||||
|
|
||||||
memset(&progressData, 0, sizeof(progressData));
|
memset(&progressData, 0, sizeof(progressData));
|
||||||
pProgressData = nil;
|
pProgressData = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we're just trying to verify the archive contents, create a
|
* If we're just trying to verify the archive contents, create a
|
||||||
@ -619,7 +619,7 @@ Nu_ExtractThreadCommon(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
* use by the "bulk" extract, not the per-thread extract, but it
|
* use by the "bulk" extract, not the per-thread extract, but it
|
||||||
* still applies if they so desire.
|
* still applies if they so desire.
|
||||||
*/
|
*/
|
||||||
if (pArchive->selectionFilterFunc != nil) {
|
if (pArchive->selectionFilterFunc != NULL) {
|
||||||
selProposal.pRecord = pRecord;
|
selProposal.pRecord = pRecord;
|
||||||
selProposal.pThread = pThread;
|
selProposal.pThread = pThread;
|
||||||
result = (*pArchive->selectionFilterFunc)(pArchive, &selProposal);
|
result = (*pArchive->selectionFilterFunc)(pArchive, &selProposal);
|
||||||
@ -632,7 +632,7 @@ Nu_ExtractThreadCommon(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newPathname = nil;
|
newPathname = NULL;
|
||||||
newFssep = 0;
|
newFssep = 0;
|
||||||
|
|
||||||
retry_name:
|
retry_name:
|
||||||
@ -650,16 +650,16 @@ retry_name:
|
|||||||
pDataSink = pOrigDataSink;
|
pDataSink = pOrigDataSink;
|
||||||
|
|
||||||
/* if they don't have a pathname func defined, we just use default */
|
/* if they don't have a pathname func defined, we just use default */
|
||||||
if (pArchive->outputPathnameFunc != nil) {
|
if (pArchive->outputPathnameFunc != NULL) {
|
||||||
pathProposal.pathname = pRecord->filename;
|
pathProposal.pathname = pRecord->filename;
|
||||||
pathProposal.filenameSeparator =
|
pathProposal.filenameSeparator =
|
||||||
NuGetSepFromSysInfo(pRecord->recFileSysInfo);
|
NuGetSepFromSysInfo(pRecord->recFileSysInfo);
|
||||||
pathProposal.pRecord = pRecord;
|
pathProposal.pRecord = pRecord;
|
||||||
pathProposal.pThread = pThread;
|
pathProposal.pThread = pThread;
|
||||||
pathProposal.newPathname = nil;
|
pathProposal.newPathname = NULL;
|
||||||
pathProposal.newFilenameSeparator = '\0';
|
pathProposal.newFilenameSeparator = '\0';
|
||||||
/*pathProposal.newStorage = (NuThreadID)-1;*/
|
/*pathProposal.newStorage = (NuThreadID)-1;*/
|
||||||
pathProposal.newDataSink = nil;
|
pathProposal.newDataSink = NULL;
|
||||||
|
|
||||||
result = (*pArchive->outputPathnameFunc)(pArchive, &pathProposal);
|
result = (*pArchive->outputPathnameFunc)(pArchive, &pathProposal);
|
||||||
|
|
||||||
@ -671,27 +671,27 @@ retry_name:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* we don't own this string, so make a copy */
|
/* we don't own this string, so make a copy */
|
||||||
if (pathProposal.newPathname != nil) {
|
if (pathProposal.newPathname != NULL) {
|
||||||
newPathStorage = strdup(pathProposal.newPathname);
|
newPathStorage = strdup(pathProposal.newPathname);
|
||||||
newPathname = newPathStorage;
|
newPathname = newPathStorage;
|
||||||
} else
|
} else
|
||||||
newPathname = nil;
|
newPathname = NULL;
|
||||||
if (pathProposal.newFilenameSeparator != '\0')
|
if (pathProposal.newFilenameSeparator != '\0')
|
||||||
newFssep = pathProposal.newFilenameSeparator;
|
newFssep = pathProposal.newFilenameSeparator;
|
||||||
|
|
||||||
/* if they want to send this somewhere else, let them */
|
/* if they want to send this somewhere else, let them */
|
||||||
if (pathProposal.newDataSink != nil)
|
if (pathProposal.newDataSink != NULL)
|
||||||
pDataSink = pathProposal.newDataSink;
|
pDataSink = pathProposal.newDataSink;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* at least one of these must be set */
|
/* at least one of these must be set */
|
||||||
Assert(!(newPathname == nil && pathProposal.newDataSink == nil));
|
Assert(!(newPathname == NULL && pathProposal.newDataSink == NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Prepare the progress data if this is a data thread.
|
* Prepare the progress data if this is a data thread.
|
||||||
*/
|
*/
|
||||||
if (newPathname == nil) {
|
if (newPathname == NULL) {
|
||||||
/* using a data sink; get the pathname out of the record */
|
/* using a data sink; get the pathname out of the record */
|
||||||
newPathname = pRecord->filename;
|
newPathname = pRecord->filename;
|
||||||
newFssep = NuGetSepFromSysInfo(pRecord->recFileSysInfo);
|
newFssep = NuGetSepFromSysInfo(pRecord->recFileSysInfo);
|
||||||
@ -713,23 +713,23 @@ retry_name:
|
|||||||
* We're extracting to a file. Open it, creating it if necessary and
|
* We're extracting to a file. Open it, creating it if necessary and
|
||||||
* allowed.
|
* allowed.
|
||||||
*/
|
*/
|
||||||
FILE* fileFp = nil;
|
FILE* fileFp = NULL;
|
||||||
|
|
||||||
err = Nu_OpenOutputFile(pArchive, pRecord, pThread, newPathname,
|
err = Nu_OpenOutputFile(pArchive, pRecord, pThread, newPathname,
|
||||||
newFssep, &fileFp);
|
newFssep, &fileFp);
|
||||||
if (err == kNuErrRename) {
|
if (err == kNuErrRename) {
|
||||||
/* they want to rename; the OutputPathname callback handles this */
|
/* they want to rename; the OutputPathname callback handles this */
|
||||||
Nu_Free(pArchive, newPathStorage);
|
Nu_Free(pArchive, newPathStorage);
|
||||||
newPathStorage = nil;
|
newPathStorage = NULL;
|
||||||
/* reset these just to be careful */
|
/* reset these just to be careful */
|
||||||
newPathname = nil;
|
newPathname = NULL;
|
||||||
fileFp = nil;
|
fileFp = NULL;
|
||||||
goto retry_name;
|
goto retry_name;
|
||||||
} else if (err != kNuErrNone) {
|
} else if (err != kNuErrNone) {
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
|
|
||||||
Assert(fileFp != nil);
|
Assert(fileFp != NULL);
|
||||||
(void) Nu_DataSinkFile_SetFP(pDataSink, fileFp);
|
(void) Nu_DataSinkFile_SetFP(pDataSink, fileFp);
|
||||||
|
|
||||||
DBUG(("+++ EXTRACTING 0x%08lx from '%s' at offset %0ld to '%s'\n",
|
DBUG(("+++ EXTRACTING 0x%08lx from '%s' at offset %0ld to '%s'\n",
|
||||||
@ -753,12 +753,12 @@ retry_name:
|
|||||||
*/
|
*/
|
||||||
err = Nu_CloseOutputFile(pArchive, pRecord,
|
err = Nu_CloseOutputFile(pArchive, pRecord,
|
||||||
Nu_DataSinkFile_GetFP(pDataSink), newPathname);
|
Nu_DataSinkFile_GetFP(pDataSink), newPathname);
|
||||||
Nu_DataSinkFile_SetFP(pDataSink, nil);
|
Nu_DataSinkFile_SetFP(pDataSink, NULL);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (err != kNuErrNone && pProgressData != nil) {
|
if (err != kNuErrNone && pProgressData != NULL) {
|
||||||
/* send a final progress message, indicating failure */
|
/* send a final progress message, indicating failure */
|
||||||
if (err == kNuErrSkipped)
|
if (err == kNuErrSkipped)
|
||||||
pProgressData->state = kNuProgressSkipped;
|
pProgressData->state = kNuProgressSkipped;
|
||||||
@ -790,7 +790,7 @@ Nu_ExtractThreadBulk(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
const NuThread* pThread)
|
const NuThread* pThread)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
NuDataSink* pDataSink = nil;
|
NuDataSink* pDataSink = NULL;
|
||||||
NuValue eolConv;
|
NuValue eolConv;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -814,7 +814,7 @@ Nu_ExtractThreadBulk(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
BailError(err);
|
BailError(err);
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (pDataSink != nil) {
|
if (pDataSink != NULL) {
|
||||||
NuError err2 = Nu_DataSinkFree(pDataSink);
|
NuError err2 = Nu_DataSinkFree(pDataSink);
|
||||||
if (err == kNuErrNone)
|
if (err == kNuErrNone)
|
||||||
err = err2;
|
err = err2;
|
||||||
@ -837,7 +837,7 @@ Nu_ExtractThread(NuArchive* pArchive, NuThreadIdx threadIdx,
|
|||||||
|
|
||||||
if (Nu_IsStreaming(pArchive))
|
if (Nu_IsStreaming(pArchive))
|
||||||
return kNuErrUsage;
|
return kNuErrUsage;
|
||||||
if (threadIdx == 0 || pDataSink == nil)
|
if (threadIdx == 0 || pDataSink == NULL)
|
||||||
return kNuErrInvalidArg;
|
return kNuErrInvalidArg;
|
||||||
err = Nu_GetTOCIfNeeded(pArchive);
|
err = Nu_GetTOCIfNeeded(pArchive);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
@ -846,7 +846,7 @@ Nu_ExtractThread(NuArchive* pArchive, NuThreadIdx threadIdx,
|
|||||||
err = Nu_RecordSet_FindByThreadIdx(&pArchive->origRecordSet, threadIdx,
|
err = Nu_RecordSet_FindByThreadIdx(&pArchive->origRecordSet, threadIdx,
|
||||||
&pRecord, &pThread);
|
&pRecord, &pThread);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
Assert(pRecord != nil);
|
Assert(pRecord != NULL);
|
||||||
|
|
||||||
/* extract away */
|
/* extract away */
|
||||||
err = Nu_ExtractThreadCommon(pArchive, pRecord, pThread, pDataSink);
|
err = Nu_ExtractThreadCommon(pArchive, pRecord, pThread, pDataSink);
|
||||||
@ -886,13 +886,13 @@ Nu_FindNoFutureThread(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
*/
|
*/
|
||||||
for (idx = 0; idx < (int)pRecord->recTotalThreads; idx++) {
|
for (idx = 0; idx < (int)pRecord->recTotalThreads; idx++) {
|
||||||
pThread = Nu_GetThread(pRecord, idx);
|
pThread = Nu_GetThread(pRecord, idx);
|
||||||
Assert(pThread != nil);
|
Assert(pThread != NULL);
|
||||||
|
|
||||||
if (NuGetThreadID(pThread) == threadID) {
|
if (NuGetThreadID(pThread) == threadID) {
|
||||||
/* found a match, see if it has been deleted */
|
/* found a match, see if it has been deleted */
|
||||||
pThreadMod = Nu_ThreadMod_FindByThreadIdx(pRecord,
|
pThreadMod = Nu_ThreadMod_FindByThreadIdx(pRecord,
|
||||||
pThread->threadIdx);
|
pThread->threadIdx);
|
||||||
if (pThreadMod != nil &&
|
if (pThreadMod != NULL &&
|
||||||
pThreadMod->entry.kind == kNuThreadModDelete)
|
pThreadMod->entry.kind == kNuThreadModDelete)
|
||||||
{
|
{
|
||||||
/* it's deleted, ignore it */
|
/* it's deleted, ignore it */
|
||||||
@ -908,7 +908,7 @@ Nu_FindNoFutureThread(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
* Now look for "add" threadMods with a matching threadID.
|
* Now look for "add" threadMods with a matching threadID.
|
||||||
*/
|
*/
|
||||||
pThreadMod = pRecord->pThreadMods;
|
pThreadMod = pRecord->pThreadMods;
|
||||||
while (pThreadMod != nil) {
|
while (pThreadMod != NULL) {
|
||||||
if (pThreadMod->entry.kind == kNuThreadModAdd &&
|
if (pThreadMod->entry.kind == kNuThreadModAdd &&
|
||||||
pThreadMod->entry.add.threadID == threadID)
|
pThreadMod->entry.add.threadID == threadID)
|
||||||
{
|
{
|
||||||
@ -941,13 +941,13 @@ Nu_FindNoFutureThreadClass(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
*/
|
*/
|
||||||
for (idx = 0; idx < (int)pRecord->recTotalThreads; idx++) {
|
for (idx = 0; idx < (int)pRecord->recTotalThreads; idx++) {
|
||||||
pThread = Nu_GetThread(pRecord, idx);
|
pThread = Nu_GetThread(pRecord, idx);
|
||||||
Assert(pThread != nil);
|
Assert(pThread != NULL);
|
||||||
|
|
||||||
if (pThread->thThreadClass == threadClass) {
|
if (pThread->thThreadClass == threadClass) {
|
||||||
/* found a match, see if it has been deleted */
|
/* found a match, see if it has been deleted */
|
||||||
pThreadMod = Nu_ThreadMod_FindByThreadIdx(pRecord,
|
pThreadMod = Nu_ThreadMod_FindByThreadIdx(pRecord,
|
||||||
pThread->threadIdx);
|
pThread->threadIdx);
|
||||||
if (pThreadMod != nil &&
|
if (pThreadMod != NULL &&
|
||||||
pThreadMod->entry.kind == kNuThreadModDelete)
|
pThreadMod->entry.kind == kNuThreadModDelete)
|
||||||
{
|
{
|
||||||
/* it's deleted, ignore it */
|
/* it's deleted, ignore it */
|
||||||
@ -963,7 +963,7 @@ Nu_FindNoFutureThreadClass(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
* Now look for "add" threadMods with a matching threadClass.
|
* Now look for "add" threadMods with a matching threadClass.
|
||||||
*/
|
*/
|
||||||
pThreadMod = pRecord->pThreadMods;
|
pThreadMod = pRecord->pThreadMods;
|
||||||
while (pThreadMod != nil) {
|
while (pThreadMod != NULL) {
|
||||||
if (pThreadMod->entry.kind == kNuThreadModAdd &&
|
if (pThreadMod->entry.kind == kNuThreadModAdd &&
|
||||||
NuThreadIDGetClass(pThreadMod->entry.add.threadID) == threadClass)
|
NuThreadIDGetClass(pThreadMod->entry.add.threadID) == threadClass)
|
||||||
{
|
{
|
||||||
@ -1001,7 +1001,7 @@ Nu_FindThreadForWriteByIdx(NuArchive* pArchive, NuThreadIdx threadIdx,
|
|||||||
Assert(Nu_RecordSet_GetLoaded(&pArchive->origRecordSet));
|
Assert(Nu_RecordSet_GetLoaded(&pArchive->origRecordSet));
|
||||||
err = Nu_RecordSet_FindByThreadIdx(&pArchive->origRecordSet, threadIdx,
|
err = Nu_RecordSet_FindByThreadIdx(&pArchive->origRecordSet, threadIdx,
|
||||||
ppFoundRecord, ppFoundThread);
|
ppFoundRecord, ppFoundThread);
|
||||||
*ppFoundThread = nil; /* can't delete from here, wipe ptr */
|
*ppFoundThread = NULL; /* can't delete from here, wipe ptr */
|
||||||
}
|
}
|
||||||
BailError(err);
|
BailError(err);
|
||||||
|
|
||||||
@ -1009,13 +1009,13 @@ Nu_FindThreadForWriteByIdx(NuArchive* pArchive, NuThreadIdx threadIdx,
|
|||||||
* The thread exists. If we were looking in the "orig" set, we have
|
* The thread exists. If we were looking in the "orig" set, we have
|
||||||
* to create a "copy" set, and delete it from that.
|
* to create a "copy" set, and delete it from that.
|
||||||
*/
|
*/
|
||||||
if (*ppFoundThread == nil) {
|
if (*ppFoundThread == NULL) {
|
||||||
err = Nu_RecordSet_Clone(pArchive, &pArchive->copyRecordSet,
|
err = Nu_RecordSet_Clone(pArchive, &pArchive->copyRecordSet,
|
||||||
&pArchive->origRecordSet);
|
&pArchive->origRecordSet);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
err = Nu_RecordSet_FindByThreadIdx(&pArchive->copyRecordSet, threadIdx,
|
err = Nu_RecordSet_FindByThreadIdx(&pArchive->copyRecordSet, threadIdx,
|
||||||
ppFoundRecord, ppFoundThread);
|
ppFoundRecord, ppFoundThread);
|
||||||
Assert(err == kNuErrNone && *ppFoundThread != nil); /* must succeed */
|
Assert(err == kNuErrNone && *ppFoundThread != NULL); /* must succeed */
|
||||||
BailError(err);
|
BailError(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1100,11 +1100,11 @@ Nu_AddThread(NuArchive* pArchive, NuRecordIdx recIdx, NuThreadID threadID,
|
|||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
NuRecord* pRecord;
|
NuRecord* pRecord;
|
||||||
NuThreadMod* pThreadMod = nil;
|
NuThreadMod* pThreadMod = NULL;
|
||||||
NuThreadFormat threadFormat;
|
NuThreadFormat threadFormat;
|
||||||
|
|
||||||
/* okay for pThreadIdx to be nil */
|
/* okay for pThreadIdx to be NULL */
|
||||||
if (recIdx == 0 || pDataSource == nil)
|
if (recIdx == 0 || pDataSource == NULL)
|
||||||
return kNuErrInvalidArg;
|
return kNuErrInvalidArg;
|
||||||
|
|
||||||
if (Nu_IsReadOnly(pArchive))
|
if (Nu_IsReadOnly(pArchive))
|
||||||
@ -1123,7 +1123,7 @@ Nu_AddThread(NuArchive* pArchive, NuRecordIdx recIdx, NuThreadID threadID,
|
|||||||
err = Nu_RecordSet_FindByIdx(&pArchive->newRecordSet, recIdx, &pRecord);
|
err = Nu_RecordSet_FindByIdx(&pArchive->newRecordSet, recIdx, &pRecord);
|
||||||
}
|
}
|
||||||
BailError(err);
|
BailError(err);
|
||||||
Assert(pRecord != nil);
|
Assert(pRecord != NULL);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Do some tests, looking for specific types of threads that conflict
|
* Do some tests, looking for specific types of threads that conflict
|
||||||
@ -1153,13 +1153,13 @@ Nu_AddThread(NuArchive* pArchive, NuRecordIdx recIdx, NuThreadID threadID,
|
|||||||
err = Nu_ThreadModAdd_New(pArchive, threadID, threadFormat, pDataSource,
|
err = Nu_ThreadModAdd_New(pArchive, threadID, threadFormat, pDataSource,
|
||||||
&pThreadMod);
|
&pThreadMod);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
Assert(pThreadMod != nil);
|
Assert(pThreadMod != NULL);
|
||||||
|
|
||||||
/* add the thread mod to the record */
|
/* add the thread mod to the record */
|
||||||
Nu_RecordAddThreadMod(pRecord, pThreadMod);
|
Nu_RecordAddThreadMod(pRecord, pThreadMod);
|
||||||
if (pThreadIdx != nil)
|
if (pThreadIdx != NULL)
|
||||||
*pThreadIdx = pThreadMod->entry.add.threadIdx;
|
*pThreadIdx = pThreadMod->entry.add.threadIdx;
|
||||||
pThreadMod = nil; /* successful, don't free */
|
pThreadMod = NULL; /* successful, don't free */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we've got a header filename and we're adding a filename thread,
|
* If we've got a header filename and we're adding a filename thread,
|
||||||
@ -1172,9 +1172,9 @@ Nu_AddThread(NuArchive* pArchive, NuRecordIdx recIdx, NuThreadID threadID,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (pThreadMod != nil)
|
if (pThreadMod != NULL)
|
||||||
Nu_ThreadModFree(pArchive, pThreadMod);
|
Nu_ThreadModFree(pArchive, pThreadMod);
|
||||||
if (err == kNuErrNone && pDataSource != nil) {
|
if (err == kNuErrNone && pDataSource != NULL) {
|
||||||
/* on success, we have ownership of the data source. ThreadMod
|
/* on success, we have ownership of the data source. ThreadMod
|
||||||
made its own copy, so get rid of this one */
|
made its own copy, so get rid of this one */
|
||||||
Nu_DataSourceFree(pDataSource);
|
Nu_DataSourceFree(pDataSource);
|
||||||
@ -1199,11 +1199,11 @@ Nu_UpdatePresizedThread(NuArchive* pArchive, NuThreadIdx threadIdx,
|
|||||||
NuDataSource* pDataSource, long* pMaxLen)
|
NuDataSource* pDataSource, long* pMaxLen)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
NuThreadMod* pThreadMod = nil;
|
NuThreadMod* pThreadMod = NULL;
|
||||||
NuRecord* pFoundRecord;
|
NuRecord* pFoundRecord;
|
||||||
NuThread* pFoundThread;
|
NuThread* pFoundThread;
|
||||||
|
|
||||||
if (pDataSource == nil) {
|
if (pDataSource == NULL) {
|
||||||
err = kNuErrInvalidArg;
|
err = kNuErrInvalidArg;
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
@ -1239,14 +1239,14 @@ Nu_UpdatePresizedThread(NuArchive* pArchive, NuThreadIdx threadIdx,
|
|||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pMaxLen != nil)
|
if (pMaxLen != NULL)
|
||||||
*pMaxLen = pFoundThread->thCompThreadEOF;
|
*pMaxLen = pFoundThread->thCompThreadEOF;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check to see if somebody is trying to delete this, or has already
|
* Check to see if somebody is trying to delete this, or has already
|
||||||
* updated it.
|
* updated it.
|
||||||
*/
|
*/
|
||||||
if (Nu_ThreadMod_FindByThreadIdx(pFoundRecord, threadIdx) != nil) {
|
if (Nu_ThreadMod_FindByThreadIdx(pFoundRecord, threadIdx) != NULL) {
|
||||||
DBUG(("--- Tried to modify a deleted or modified thread\n"));
|
DBUG(("--- Tried to modify a deleted or modified thread\n"));
|
||||||
err = kNuErrModThreadChange;
|
err = kNuErrModThreadChange;
|
||||||
goto bail;
|
goto bail;
|
||||||
@ -1294,7 +1294,7 @@ Nu_UpdatePresizedThread(NuArchive* pArchive, NuThreadIdx threadIdx,
|
|||||||
Assert(pFoundThread->thThreadFormat == kNuThreadFormatUncompressed);
|
Assert(pFoundThread->thThreadFormat == kNuThreadFormatUncompressed);
|
||||||
err = Nu_ThreadModUpdate_New(pArchive, threadIdx, pDataSource, &pThreadMod);
|
err = Nu_ThreadModUpdate_New(pArchive, threadIdx, pDataSource, &pThreadMod);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
Assert(pThreadMod != nil);
|
Assert(pThreadMod != NULL);
|
||||||
|
|
||||||
/* add the thread mod to the record */
|
/* add the thread mod to the record */
|
||||||
Nu_RecordAddThreadMod(pFoundRecord, pThreadMod);
|
Nu_RecordAddThreadMod(pFoundRecord, pThreadMod);
|
||||||
@ -1326,7 +1326,7 @@ NuError
|
|||||||
Nu_DeleteThread(NuArchive* pArchive, NuThreadIdx threadIdx)
|
Nu_DeleteThread(NuArchive* pArchive, NuThreadIdx threadIdx)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
NuThreadMod* pThreadMod = nil;
|
NuThreadMod* pThreadMod = NULL;
|
||||||
NuRecord* pFoundRecord;
|
NuRecord* pFoundRecord;
|
||||||
NuThread* pFoundThread;
|
NuThread* pFoundThread;
|
||||||
|
|
||||||
@ -1348,7 +1348,7 @@ Nu_DeleteThread(NuArchive* pArchive, NuThreadIdx threadIdx)
|
|||||||
* allowed. Deletion of threads from deleted records can't happen,
|
* allowed. Deletion of threads from deleted records can't happen,
|
||||||
* because deleted records are completely removed from the "copy" set.
|
* because deleted records are completely removed from the "copy" set.
|
||||||
*/
|
*/
|
||||||
if (Nu_ThreadMod_FindByThreadIdx(pFoundRecord, threadIdx) != nil) {
|
if (Nu_ThreadMod_FindByThreadIdx(pFoundRecord, threadIdx) != NULL) {
|
||||||
DBUG(("--- Tried to delete a deleted or modified thread\n"));
|
DBUG(("--- Tried to delete a deleted or modified thread\n"));
|
||||||
err = kNuErrModThreadChange;
|
err = kNuErrModThreadChange;
|
||||||
goto bail;
|
goto bail;
|
||||||
@ -1361,7 +1361,7 @@ Nu_DeleteThread(NuArchive* pArchive, NuThreadIdx threadIdx)
|
|||||||
NuGetThreadID(pFoundThread), &pThreadMod);
|
NuGetThreadID(pFoundThread), &pThreadMod);
|
||||||
BailError(err);
|
BailError(err);
|
||||||
Nu_RecordAddThreadMod(pFoundRecord, pThreadMod);
|
Nu_RecordAddThreadMod(pFoundRecord, pThreadMod);
|
||||||
pThreadMod = nil; /* successful, don't free */
|
pThreadMod = NULL; /* successful, don't free */
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
Nu_ThreadModFree(pArchive, pThreadMod);
|
Nu_ThreadModFree(pArchive, pThreadMod);
|
||||||
|
@ -19,7 +19,7 @@ Nu_GetValue(NuArchive* pArchive, NuValueID ident, NuValue* pValue)
|
|||||||
{
|
{
|
||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
|
|
||||||
if (pValue == nil)
|
if (pValue == NULL)
|
||||||
return kNuErrInvalidArg;
|
return kNuErrInvalidArg;
|
||||||
|
|
||||||
switch (ident) {
|
switch (ident) {
|
||||||
@ -229,7 +229,7 @@ NuError
|
|||||||
Nu_GetAttr(NuArchive* pArchive, NuAttrID ident, NuAttr* pAttr)
|
Nu_GetAttr(NuArchive* pArchive, NuAttrID ident, NuAttr* pAttr)
|
||||||
{
|
{
|
||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
if (pAttr == nil)
|
if (pAttr == NULL)
|
||||||
return kNuErrInvalidArg;
|
return kNuErrInvalidArg;
|
||||||
|
|
||||||
switch (ident) {
|
switch (ident) {
|
||||||
|
@ -27,15 +27,15 @@ NuError
|
|||||||
Nu_GetVersion(long* pMajorVersion, long* pMinorVersion, long* pBugVersion,
|
Nu_GetVersion(long* pMajorVersion, long* pMinorVersion, long* pBugVersion,
|
||||||
const char** ppBuildDate, const char** ppBuildFlags)
|
const char** ppBuildDate, const char** ppBuildFlags)
|
||||||
{
|
{
|
||||||
if (pMajorVersion != nil)
|
if (pMajorVersion != NULL)
|
||||||
*pMajorVersion = kNuVersionMajor;
|
*pMajorVersion = kNuVersionMajor;
|
||||||
if (pMinorVersion != nil)
|
if (pMinorVersion != NULL)
|
||||||
*pMinorVersion = kNuVersionMinor;
|
*pMinorVersion = kNuVersionMinor;
|
||||||
if (pBugVersion != nil)
|
if (pBugVersion != NULL)
|
||||||
*pBugVersion = kNuVersionBug;
|
*pBugVersion = kNuVersionBug;
|
||||||
if (ppBuildDate != nil)
|
if (ppBuildDate != NULL)
|
||||||
*ppBuildDate = gNuBuildDate;
|
*ppBuildDate = gNuBuildDate;
|
||||||
if (ppBuildFlags != nil)
|
if (ppBuildFlags != NULL)
|
||||||
*ppBuildFlags = gNuBuildFlags;
|
*ppBuildFlags = gNuBuildFlags;
|
||||||
return kNuErrNone;
|
return kNuErrNone;
|
||||||
}
|
}
|
||||||
|
@ -16,8 +16,6 @@
|
|||||||
# include "dmalloc.h"
|
# include "dmalloc.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define nil NULL /* this is seriously habit-forming */
|
|
||||||
|
|
||||||
#define NELEM(x) (sizeof(x) / sizeof((x)[0]))
|
#define NELEM(x) (sizeof(x) / sizeof((x)[0]))
|
||||||
|
|
||||||
#ifndef __cplusplus
|
#ifndef __cplusplus
|
||||||
|
@ -50,12 +50,12 @@ ExerciserState_New(void)
|
|||||||
ExerciserState* pExerState;
|
ExerciserState* pExerState;
|
||||||
|
|
||||||
pExerState = (ExerciserState*) malloc(sizeof(*pExerState));
|
pExerState = (ExerciserState*) malloc(sizeof(*pExerState));
|
||||||
if (pExerState == nil)
|
if (pExerState == NULL)
|
||||||
return nil;
|
return NULL;
|
||||||
|
|
||||||
pExerState->pArchive = nil;
|
pExerState->pArchive = NULL;
|
||||||
pExerState->archivePath = nil;
|
pExerState->archivePath = NULL;
|
||||||
pExerState->archiveFile = nil;
|
pExerState->archiveFile = NULL;
|
||||||
|
|
||||||
return pExerState;
|
return pExerState;
|
||||||
}
|
}
|
||||||
@ -63,15 +63,15 @@ ExerciserState_New(void)
|
|||||||
void
|
void
|
||||||
ExerciserState_Free(ExerciserState* pExerState)
|
ExerciserState_Free(ExerciserState* pExerState)
|
||||||
{
|
{
|
||||||
if (pExerState == nil)
|
if (pExerState == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (pExerState->pArchive != nil) {
|
if (pExerState->pArchive != NULL) {
|
||||||
printf("Exerciser: aborting open archive\n");
|
printf("Exerciser: aborting open archive\n");
|
||||||
(void) NuAbort(pExerState->pArchive);
|
(void) NuAbort(pExerState->pArchive);
|
||||||
(void) NuClose(pExerState->pArchive);
|
(void) NuClose(pExerState->pArchive);
|
||||||
}
|
}
|
||||||
if (pExerState->archivePath != nil)
|
if (pExerState->archivePath != NULL)
|
||||||
free(pExerState->archivePath);
|
free(pExerState->archivePath);
|
||||||
|
|
||||||
free(pExerState);
|
free(pExerState);
|
||||||
@ -98,19 +98,19 @@ ExerciserState_GetArchivePath(const ExerciserState* pExerState)
|
|||||||
inline void
|
inline void
|
||||||
ExerciserState_SetArchivePath(ExerciserState* pExerState, char* newPath)
|
ExerciserState_SetArchivePath(ExerciserState* pExerState, char* newPath)
|
||||||
{
|
{
|
||||||
if (pExerState->archivePath != nil)
|
if (pExerState->archivePath != NULL)
|
||||||
free(pExerState->archivePath);
|
free(pExerState->archivePath);
|
||||||
|
|
||||||
if (newPath == nil) {
|
if (newPath == NULL) {
|
||||||
pExerState->archivePath = nil;
|
pExerState->archivePath = NULL;
|
||||||
pExerState->archiveFile = nil;
|
pExerState->archiveFile = NULL;
|
||||||
} else {
|
} else {
|
||||||
pExerState->archivePath = strdup(newPath);
|
pExerState->archivePath = strdup(newPath);
|
||||||
pExerState->archiveFile = strrchr(newPath, kFssep);
|
pExerState->archiveFile = strrchr(newPath, kFssep);
|
||||||
if (pExerState->archiveFile != nil)
|
if (pExerState->archiveFile != NULL)
|
||||||
pExerState->archiveFile++;
|
pExerState->archiveFile++;
|
||||||
|
|
||||||
if (pExerState->archiveFile == nil || *pExerState->archiveFile == '\0')
|
if (pExerState->archiveFile == NULL || *pExerState->archiveFile == '\0')
|
||||||
pExerState->archiveFile = pExerState->archivePath;
|
pExerState->archiveFile = pExerState->archivePath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -118,7 +118,7 @@ ExerciserState_SetArchivePath(ExerciserState* pExerState, char* newPath)
|
|||||||
inline const char*
|
inline const char*
|
||||||
ExerciserState_GetArchiveFile(const ExerciserState* pExerState)
|
ExerciserState_GetArchiveFile(const ExerciserState* pExerState)
|
||||||
{
|
{
|
||||||
if (pExerState->archiveFile == nil)
|
if (pExerState->archiveFile == NULL)
|
||||||
return "[no archive open]";
|
return "[no archive open]";
|
||||||
else
|
else
|
||||||
return pExerState->archiveFile;
|
return pExerState->archiveFile;
|
||||||
@ -151,7 +151,7 @@ PrintEntry(NuArchive* pArchive, void* vpRecord)
|
|||||||
const char* threadLabel;
|
const char* threadLabel;
|
||||||
|
|
||||||
pThread = NuGetThread(pRecord, idx);
|
pThread = NuGetThread(pRecord, idx);
|
||||||
assert(pThread != nil);
|
assert(pThread != NULL);
|
||||||
|
|
||||||
threadID = NuGetThreadID(pThread);
|
threadID = NuGetThreadID(pThread);
|
||||||
switch (NuThreadIDGetClass(threadID)) {
|
switch (NuThreadIDGetClass(threadID)) {
|
||||||
@ -217,7 +217,7 @@ GetLine(const char* prompt, char* buffer, int bufferSize)
|
|||||||
printf("%s> ", prompt);
|
printf("%s> ", prompt);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
if (fgets(buffer, bufferSize, stdin) == nil)
|
if (fgets(buffer, bufferSize, stdin) == NULL)
|
||||||
return kNuErrGeneric;
|
return kNuErrGeneric;
|
||||||
|
|
||||||
if (buffer[strlen(buffer)-1] == '\n')
|
if (buffer[strlen(buffer)-1] == '\n')
|
||||||
@ -239,7 +239,7 @@ SelectionFilter(NuArchive* pArchive, void* vselFilt)
|
|||||||
printf("%s (N/y)? ", selProposal->pRecord->filename);
|
printf("%s (N/y)? ", selProposal->pRecord->filename);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
if (fgets(buffer, sizeof(buffer), stdin) == nil)
|
if (fgets(buffer, sizeof(buffer), stdin) == NULL)
|
||||||
return kNuAbort;
|
return kNuAbort;
|
||||||
|
|
||||||
if (tolower(buffer[0]) == 'y')
|
if (tolower(buffer[0]) == 'y')
|
||||||
@ -262,7 +262,7 @@ ErrorHandler(NuArchive* pArchive, void* vErrorStatus)
|
|||||||
printf("Exerciser: error handler op=%d err=%d sysErr=%d message='%s'\n"
|
printf("Exerciser: error handler op=%d err=%d sysErr=%d message='%s'\n"
|
||||||
"\tfilename='%s' '%c'(0x%02x)\n",
|
"\tfilename='%s' '%c'(0x%02x)\n",
|
||||||
pErrorStatus->operation, pErrorStatus->err, pErrorStatus->sysErr,
|
pErrorStatus->operation, pErrorStatus->err, pErrorStatus->sysErr,
|
||||||
pErrorStatus->message == nil ? "(nil)" : pErrorStatus->message,
|
pErrorStatus->message == NULL ? "(NULL)" : pErrorStatus->message,
|
||||||
pErrorStatus->pathname, pErrorStatus->filenameSeparator,
|
pErrorStatus->pathname, pErrorStatus->filenameSeparator,
|
||||||
pErrorStatus->filenameSeparator);
|
pErrorStatus->filenameSeparator);
|
||||||
printf("\tValid options are:");
|
printf("\tValid options are:");
|
||||||
@ -283,7 +283,7 @@ ErrorHandler(NuArchive* pArchive, void* vErrorStatus)
|
|||||||
printf("Return what (a/r/i/s/e/o)? ");
|
printf("Return what (a/r/i/s/e/o)? ");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
if (fgets(buffer, sizeof(buffer), stdin) == nil) {
|
if (fgets(buffer, sizeof(buffer), stdin) == NULL) {
|
||||||
printf("Returning kNuSkip\n");
|
printf("Returning kNuSkip\n");
|
||||||
} else switch (buffer[0]) {
|
} else switch (buffer[0]) {
|
||||||
case 'a': result = kNuAbort; break;
|
case 'a': result = kNuAbort; break;
|
||||||
@ -365,7 +365,7 @@ static NuError
|
|||||||
AbortFunc(ExerciserState* pState, int argc, char** argv)
|
AbortFunc(ExerciserState* pState, int argc, char** argv)
|
||||||
{
|
{
|
||||||
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
||||||
assert(ExerciserState_GetNuArchive(pState) != nil);
|
assert(ExerciserState_GetNuArchive(pState) != NULL);
|
||||||
assert(argc == 1);
|
assert(argc == 1);
|
||||||
|
|
||||||
return NuAbort(ExerciserState_GetNuArchive(pState));
|
return NuAbort(ExerciserState_GetNuArchive(pState));
|
||||||
@ -380,7 +380,7 @@ AddFileFunc(ExerciserState* pState, int argc, char** argv)
|
|||||||
NuFileDetails nuFileDetails;
|
NuFileDetails nuFileDetails;
|
||||||
|
|
||||||
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
||||||
assert(ExerciserState_GetNuArchive(pState) != nil);
|
assert(ExerciserState_GetNuArchive(pState) != NULL);
|
||||||
assert(argc == 2);
|
assert(argc == 2);
|
||||||
|
|
||||||
memset(&nuFileDetails, 0, sizeof(nuFileDetails));
|
memset(&nuFileDetails, 0, sizeof(nuFileDetails));
|
||||||
@ -392,7 +392,7 @@ AddFileFunc(ExerciserState* pState, int argc, char** argv)
|
|||||||
/* fileType, extraType, storageType, dates */
|
/* fileType, extraType, storageType, dates */
|
||||||
|
|
||||||
return NuAddFile(ExerciserState_GetNuArchive(pState), argv[1],
|
return NuAddFile(ExerciserState_GetNuArchive(pState), argv[1],
|
||||||
&nuFileDetails, false, nil);
|
&nuFileDetails, false, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -406,7 +406,7 @@ AddRecordFunc(ExerciserState* pState, int argc, char** argv)
|
|||||||
NuFileDetails nuFileDetails;
|
NuFileDetails nuFileDetails;
|
||||||
|
|
||||||
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
||||||
assert(ExerciserState_GetNuArchive(pState) != nil);
|
assert(ExerciserState_GetNuArchive(pState) != NULL);
|
||||||
assert(argc == 2);
|
assert(argc == 2);
|
||||||
|
|
||||||
memset(&nuFileDetails, 0, sizeof(nuFileDetails));
|
memset(&nuFileDetails, 0, sizeof(nuFileDetails));
|
||||||
@ -431,20 +431,20 @@ static NuError
|
|||||||
AddThreadFunc(ExerciserState* pState, int argc, char** argv)
|
AddThreadFunc(ExerciserState* pState, int argc, char** argv)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
NuDataSource* pDataSource = nil;
|
NuDataSource* pDataSource = NULL;
|
||||||
char* lineBuf = nil;
|
char* lineBuf = NULL;
|
||||||
long ourLen, maxLen;
|
long ourLen, maxLen;
|
||||||
NuThreadID threadID;
|
NuThreadID threadID;
|
||||||
NuThreadIdx threadIdx;
|
NuThreadIdx threadIdx;
|
||||||
|
|
||||||
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
||||||
assert(ExerciserState_GetNuArchive(pState) != nil);
|
assert(ExerciserState_GetNuArchive(pState) != NULL);
|
||||||
assert(argc == 3);
|
assert(argc == 3);
|
||||||
|
|
||||||
lineBuf = (char*)malloc(kNiceLineLen);
|
lineBuf = (char*)malloc(kNiceLineLen);
|
||||||
assert(lineBuf != nil);
|
assert(lineBuf != NULL);
|
||||||
|
|
||||||
threadID = strtol(argv[2], nil, 0);
|
threadID = strtol(argv[2], NULL, 0);
|
||||||
if (NuThreadIDGetClass(threadID) == kNuThreadClassData) {
|
if (NuThreadIDGetClass(threadID) == kNuThreadClassData) {
|
||||||
/* load data from a file on disk */
|
/* load data from a file on disk */
|
||||||
maxLen = 0;
|
maxLen = 0;
|
||||||
@ -470,7 +470,7 @@ AddThreadFunc(ExerciserState* pState, int argc, char** argv)
|
|||||||
err = GetLine("Enter max buffer size", lineBuf, kNiceLineLen);
|
err = GetLine("Enter max buffer size", lineBuf, kNiceLineLen);
|
||||||
if (err != kNuErrNone)
|
if (err != kNuErrNone)
|
||||||
goto bail;
|
goto bail;
|
||||||
maxLen = strtol(lineBuf, nil, 0);
|
maxLen = strtol(lineBuf, NULL, 0);
|
||||||
if (maxLen <= 0) {
|
if (maxLen <= 0) {
|
||||||
fprintf(stderr, "Bad length\n");
|
fprintf(stderr, "Bad length\n");
|
||||||
err = kNuErrInvalidArg;
|
err = kNuErrInvalidArg;
|
||||||
@ -494,21 +494,21 @@ AddThreadFunc(ExerciserState* pState, int argc, char** argv)
|
|||||||
"Exerciser: buffer data source create failed (err=%d)\n", err);
|
"Exerciser: buffer data source create failed (err=%d)\n", err);
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
lineBuf = nil; /* now owned by the library */
|
lineBuf = NULL; /* now owned by the library */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
err = NuAddThread(ExerciserState_GetNuArchive(pState),
|
err = NuAddThread(ExerciserState_GetNuArchive(pState),
|
||||||
strtol(argv[1], nil, 0), threadID, pDataSource, &threadIdx);
|
strtol(argv[1], NULL, 0), threadID, pDataSource, &threadIdx);
|
||||||
if (err == kNuErrNone) {
|
if (err == kNuErrNone) {
|
||||||
pDataSource = nil; /* library owns it now */
|
pDataSource = NULL; /* library owns it now */
|
||||||
printf("Exerciser: success; function returned threadIdx=%ld\n",
|
printf("Exerciser: success; function returned threadIdx=%ld\n",
|
||||||
threadIdx);
|
threadIdx);
|
||||||
}
|
}
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
NuFreeDataSource(pDataSource);
|
NuFreeDataSource(pDataSource);
|
||||||
if (lineBuf != nil)
|
if (lineBuf != NULL)
|
||||||
free(lineBuf);
|
free(lineBuf);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -522,13 +522,13 @@ CloseFunc(ExerciserState* pState, int argc, char** argv)
|
|||||||
NuError err;
|
NuError err;
|
||||||
|
|
||||||
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
||||||
assert(ExerciserState_GetNuArchive(pState) != nil);
|
assert(ExerciserState_GetNuArchive(pState) != NULL);
|
||||||
assert(argc == 1);
|
assert(argc == 1);
|
||||||
|
|
||||||
err = NuClose(ExerciserState_GetNuArchive(pState));
|
err = NuClose(ExerciserState_GetNuArchive(pState));
|
||||||
if (err == kNuErrNone) {
|
if (err == kNuErrNone) {
|
||||||
ExerciserState_SetNuArchive(pState, nil);
|
ExerciserState_SetNuArchive(pState, NULL);
|
||||||
ExerciserState_SetArchivePath(pState, nil);
|
ExerciserState_SetArchivePath(pState, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
@ -541,7 +541,7 @@ static NuError
|
|||||||
DeleteFunc(ExerciserState* pState, int argc, char** argv)
|
DeleteFunc(ExerciserState* pState, int argc, char** argv)
|
||||||
{
|
{
|
||||||
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
||||||
assert(ExerciserState_GetNuArchive(pState) != nil);
|
assert(ExerciserState_GetNuArchive(pState) != NULL);
|
||||||
assert(argc == 1);
|
assert(argc == 1);
|
||||||
|
|
||||||
NuSetSelectionFilter(ExerciserState_GetNuArchive(pState), SelectionFilter);
|
NuSetSelectionFilter(ExerciserState_GetNuArchive(pState), SelectionFilter);
|
||||||
@ -556,11 +556,11 @@ static NuError
|
|||||||
DeleteRecordFunc(ExerciserState* pState, int argc, char** argv)
|
DeleteRecordFunc(ExerciserState* pState, int argc, char** argv)
|
||||||
{
|
{
|
||||||
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
||||||
assert(ExerciserState_GetNuArchive(pState) != nil);
|
assert(ExerciserState_GetNuArchive(pState) != NULL);
|
||||||
assert(argc == 2);
|
assert(argc == 2);
|
||||||
|
|
||||||
return NuDeleteRecord(ExerciserState_GetNuArchive(pState),
|
return NuDeleteRecord(ExerciserState_GetNuArchive(pState),
|
||||||
strtol(argv[1], nil, 0));
|
strtol(argv[1], NULL, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -570,11 +570,11 @@ static NuError
|
|||||||
DeleteThreadFunc(ExerciserState* pState, int argc, char** argv)
|
DeleteThreadFunc(ExerciserState* pState, int argc, char** argv)
|
||||||
{
|
{
|
||||||
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
||||||
assert(ExerciserState_GetNuArchive(pState) != nil);
|
assert(ExerciserState_GetNuArchive(pState) != NULL);
|
||||||
assert(argc == 2);
|
assert(argc == 2);
|
||||||
|
|
||||||
return NuDeleteThread(ExerciserState_GetNuArchive(pState),
|
return NuDeleteThread(ExerciserState_GetNuArchive(pState),
|
||||||
strtol(argv[1], nil, 0));
|
strtol(argv[1], NULL, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -584,7 +584,7 @@ static NuError
|
|||||||
ExtractFunc(ExerciserState* pState, int argc, char** argv)
|
ExtractFunc(ExerciserState* pState, int argc, char** argv)
|
||||||
{
|
{
|
||||||
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
||||||
assert(ExerciserState_GetNuArchive(pState) != nil);
|
assert(ExerciserState_GetNuArchive(pState) != NULL);
|
||||||
assert(argc == 1);
|
assert(argc == 1);
|
||||||
|
|
||||||
NuSetSelectionFilter(ExerciserState_GetNuArchive(pState), SelectionFilter);
|
NuSetSelectionFilter(ExerciserState_GetNuArchive(pState), SelectionFilter);
|
||||||
@ -599,11 +599,11 @@ static NuError
|
|||||||
ExtractRecordFunc(ExerciserState* pState, int argc, char** argv)
|
ExtractRecordFunc(ExerciserState* pState, int argc, char** argv)
|
||||||
{
|
{
|
||||||
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
||||||
assert(ExerciserState_GetNuArchive(pState) != nil);
|
assert(ExerciserState_GetNuArchive(pState) != NULL);
|
||||||
assert(argc == 2);
|
assert(argc == 2);
|
||||||
|
|
||||||
return NuExtractRecord(ExerciserState_GetNuArchive(pState),
|
return NuExtractRecord(ExerciserState_GetNuArchive(pState),
|
||||||
strtol(argv[1], nil, 0));
|
strtol(argv[1], NULL, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -613,10 +613,10 @@ static NuError
|
|||||||
ExtractThreadFunc(ExerciserState* pState, int argc, char** argv)
|
ExtractThreadFunc(ExerciserState* pState, int argc, char** argv)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
NuDataSink* pDataSink = nil;
|
NuDataSink* pDataSink = NULL;
|
||||||
|
|
||||||
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
||||||
assert(ExerciserState_GetNuArchive(pState) != nil);
|
assert(ExerciserState_GetNuArchive(pState) != NULL);
|
||||||
assert(argc == 3);
|
assert(argc == 3);
|
||||||
|
|
||||||
err = NuCreateDataSinkForFile(true, kNuConvertOff, argv[2], kFssep,
|
err = NuCreateDataSinkForFile(true, kNuConvertOff, argv[2], kFssep,
|
||||||
@ -627,7 +627,7 @@ ExtractThreadFunc(ExerciserState* pState, int argc, char** argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = NuExtractThread(ExerciserState_GetNuArchive(pState),
|
err = NuExtractThread(ExerciserState_GetNuArchive(pState),
|
||||||
strtol(argv[1], nil, 0), pDataSink);
|
strtol(argv[1], NULL, 0), pDataSink);
|
||||||
/* fall through with err */
|
/* fall through with err */
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
@ -645,7 +645,7 @@ FlushFunc(ExerciserState* pState, int argc, char** argv)
|
|||||||
long flushStatus;
|
long flushStatus;
|
||||||
|
|
||||||
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
||||||
assert(ExerciserState_GetNuArchive(pState) != nil);
|
assert(ExerciserState_GetNuArchive(pState) != NULL);
|
||||||
assert(argc == 1);
|
assert(argc == 1);
|
||||||
|
|
||||||
err = NuFlush(ExerciserState_GetNuArchive(pState), &flushStatus);
|
err = NuFlush(ExerciserState_GetNuArchive(pState), &flushStatus);
|
||||||
@ -667,11 +667,11 @@ GetValueFunc(ExerciserState* pState, int argc, char** argv)
|
|||||||
NuValue value;
|
NuValue value;
|
||||||
|
|
||||||
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
||||||
assert(ExerciserState_GetNuArchive(pState) != nil);
|
assert(ExerciserState_GetNuArchive(pState) != NULL);
|
||||||
assert(argc == 2);
|
assert(argc == 2);
|
||||||
|
|
||||||
err = NuGetValue(ExerciserState_GetNuArchive(pState),
|
err = NuGetValue(ExerciserState_GetNuArchive(pState),
|
||||||
(NuValueID) strtol(argv[1], nil, 0), &value);
|
(NuValueID) strtol(argv[1], NULL, 0), &value);
|
||||||
if (err == kNuErrNone)
|
if (err == kNuErrNone)
|
||||||
printf(" --> %ld\n", value);
|
printf(" --> %ld\n", value);
|
||||||
return err;
|
return err;
|
||||||
@ -687,7 +687,7 @@ GetMasterHeaderFunc(ExerciserState* pState, int argc, char** argv)
|
|||||||
const NuMasterHeader* pMasterHeader;
|
const NuMasterHeader* pMasterHeader;
|
||||||
|
|
||||||
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
||||||
assert(ExerciserState_GetNuArchive(pState) != nil);
|
assert(ExerciserState_GetNuArchive(pState) != NULL);
|
||||||
assert(argc == 1);
|
assert(argc == 1);
|
||||||
|
|
||||||
err = NuGetMasterHeader(ExerciserState_GetNuArchive(pState),
|
err = NuGetMasterHeader(ExerciserState_GetNuArchive(pState),
|
||||||
@ -710,11 +710,11 @@ GetRecordFunc(ExerciserState* pState, int argc, char** argv)
|
|||||||
const NuRecord* pRecord;
|
const NuRecord* pRecord;
|
||||||
|
|
||||||
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
||||||
assert(ExerciserState_GetNuArchive(pState) != nil);
|
assert(ExerciserState_GetNuArchive(pState) != NULL);
|
||||||
assert(argc == 2);
|
assert(argc == 2);
|
||||||
|
|
||||||
err = NuGetRecord(ExerciserState_GetNuArchive(pState),
|
err = NuGetRecord(ExerciserState_GetNuArchive(pState),
|
||||||
strtol(argv[1], nil, 0), &pRecord);
|
strtol(argv[1], NULL, 0), &pRecord);
|
||||||
if (err == kNuErrNone) {
|
if (err == kNuErrNone) {
|
||||||
printf("Exerciser: success, call returned:\n");
|
printf("Exerciser: success, call returned:\n");
|
||||||
printf("\tfileSysID : %d\n", pRecord->recFileSysID);
|
printf("\tfileSysID : %d\n", pRecord->recFileSysID);
|
||||||
@ -740,7 +740,7 @@ GetRecordIdxByNameFunc(ExerciserState* pState, int argc, char** argv)
|
|||||||
NuRecordIdx recIdx;
|
NuRecordIdx recIdx;
|
||||||
|
|
||||||
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
||||||
assert(ExerciserState_GetNuArchive(pState) != nil);
|
assert(ExerciserState_GetNuArchive(pState) != NULL);
|
||||||
assert(argc == 2);
|
assert(argc == 2);
|
||||||
|
|
||||||
err = NuGetRecordIdxByName(ExerciserState_GetNuArchive(pState),
|
err = NuGetRecordIdxByName(ExerciserState_GetNuArchive(pState),
|
||||||
@ -760,11 +760,11 @@ GetRecordIdxByPositionFunc(ExerciserState* pState, int argc, char** argv)
|
|||||||
NuRecordIdx recIdx;
|
NuRecordIdx recIdx;
|
||||||
|
|
||||||
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
||||||
assert(ExerciserState_GetNuArchive(pState) != nil);
|
assert(ExerciserState_GetNuArchive(pState) != NULL);
|
||||||
assert(argc == 2);
|
assert(argc == 2);
|
||||||
|
|
||||||
err = NuGetRecordIdxByPosition(ExerciserState_GetNuArchive(pState),
|
err = NuGetRecordIdxByPosition(ExerciserState_GetNuArchive(pState),
|
||||||
strtol(argv[1], nil, 0), &recIdx);
|
strtol(argv[1], NULL, 0), &recIdx);
|
||||||
if (err == kNuErrNone)
|
if (err == kNuErrNone)
|
||||||
printf("Exerciser: success, returned recordIdx=%ld\n", recIdx);
|
printf("Exerciser: success, returned recordIdx=%ld\n", recIdx);
|
||||||
return err;
|
return err;
|
||||||
@ -779,7 +779,7 @@ OpenCreateReadWriteFunc(ExerciserState* pState, int argc, char** argv)
|
|||||||
NuError err;
|
NuError err;
|
||||||
NuArchive* pArchive;
|
NuArchive* pArchive;
|
||||||
|
|
||||||
assert(ExerciserState_GetNuArchive(pState) == nil);
|
assert(ExerciserState_GetNuArchive(pState) == NULL);
|
||||||
assert(argc == 2);
|
assert(argc == 2);
|
||||||
|
|
||||||
err = NuOpenRW(argv[1], kTempFile, kNuOpenCreat|kNuOpenExcl, &pArchive);
|
err = NuOpenRW(argv[1], kTempFile, kNuOpenCreat|kNuOpenExcl, &pArchive);
|
||||||
@ -800,7 +800,7 @@ OpenReadOnlyFunc(ExerciserState* pState, int argc, char** argv)
|
|||||||
NuError err;
|
NuError err;
|
||||||
NuArchive* pArchive;
|
NuArchive* pArchive;
|
||||||
|
|
||||||
assert(ExerciserState_GetNuArchive(pState) == nil);
|
assert(ExerciserState_GetNuArchive(pState) == NULL);
|
||||||
assert(argc == 2);
|
assert(argc == 2);
|
||||||
|
|
||||||
err = NuOpenRO(argv[1], &pArchive);
|
err = NuOpenRO(argv[1], &pArchive);
|
||||||
@ -820,12 +820,12 @@ OpenStreamingReadOnlyFunc(ExerciserState* pState, int argc, char** argv)
|
|||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
NuArchive* pArchive;
|
NuArchive* pArchive;
|
||||||
FILE* fp = nil;
|
FILE* fp = NULL;
|
||||||
|
|
||||||
assert(ExerciserState_GetNuArchive(pState) == nil);
|
assert(ExerciserState_GetNuArchive(pState) == NULL);
|
||||||
assert(argc == 2);
|
assert(argc == 2);
|
||||||
|
|
||||||
if ((fp = fopen(argv[1], kNuFileOpenReadOnly)) == nil) {
|
if ((fp = fopen(argv[1], kNuFileOpenReadOnly)) == NULL) {
|
||||||
err = errno ? (NuError)errno : kNuErrGeneric;
|
err = errno ? (NuError)errno : kNuErrGeneric;
|
||||||
fprintf(stderr, "Exerciser: unable to open '%s'\n", argv[1]);
|
fprintf(stderr, "Exerciser: unable to open '%s'\n", argv[1]);
|
||||||
} else {
|
} else {
|
||||||
@ -833,11 +833,11 @@ OpenStreamingReadOnlyFunc(ExerciserState* pState, int argc, char** argv)
|
|||||||
if (err == kNuErrNone) {
|
if (err == kNuErrNone) {
|
||||||
ExerciserState_SetNuArchive(pState, pArchive);
|
ExerciserState_SetNuArchive(pState, pArchive);
|
||||||
ExerciserState_SetArchivePath(pState, argv[1]);
|
ExerciserState_SetArchivePath(pState, argv[1]);
|
||||||
fp = nil;
|
fp = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fp != nil)
|
if (fp != NULL)
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
@ -852,7 +852,7 @@ OpenReadWriteFunc(ExerciserState* pState, int argc, char** argv)
|
|||||||
NuError err;
|
NuError err;
|
||||||
NuArchive* pArchive;
|
NuArchive* pArchive;
|
||||||
|
|
||||||
assert(ExerciserState_GetNuArchive(pState) == nil);
|
assert(ExerciserState_GetNuArchive(pState) == NULL);
|
||||||
assert(argc == 2);
|
assert(argc == 2);
|
||||||
|
|
||||||
err = NuOpenRW(argv[1], kTempFile, 0, &pArchive);
|
err = NuOpenRW(argv[1], kTempFile, 0, &pArchive);
|
||||||
@ -871,7 +871,7 @@ static NuError
|
|||||||
PrintFunc(ExerciserState* pState, int argc, char** argv)
|
PrintFunc(ExerciserState* pState, int argc, char** argv)
|
||||||
{
|
{
|
||||||
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
||||||
assert(ExerciserState_GetNuArchive(pState) != nil);
|
assert(ExerciserState_GetNuArchive(pState) != NULL);
|
||||||
assert(argc == 1);
|
assert(argc == 1);
|
||||||
|
|
||||||
return NuContents(ExerciserState_GetNuArchive(pState), PrintEntry);
|
return NuContents(ExerciserState_GetNuArchive(pState), PrintEntry);
|
||||||
@ -884,7 +884,7 @@ static NuError
|
|||||||
PrintDebugFunc(ExerciserState* pState, int argc, char** argv)
|
PrintDebugFunc(ExerciserState* pState, int argc, char** argv)
|
||||||
{
|
{
|
||||||
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
||||||
assert(ExerciserState_GetNuArchive(pState) != nil);
|
assert(ExerciserState_GetNuArchive(pState) != NULL);
|
||||||
assert(argc == 1);
|
assert(argc == 1);
|
||||||
|
|
||||||
return NuDebugDumpArchive(ExerciserState_GetNuArchive(pState));
|
return NuDebugDumpArchive(ExerciserState_GetNuArchive(pState));
|
||||||
@ -897,11 +897,11 @@ static NuError
|
|||||||
RenameFunc(ExerciserState* pState, int argc, char** argv)
|
RenameFunc(ExerciserState* pState, int argc, char** argv)
|
||||||
{
|
{
|
||||||
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
||||||
assert(ExerciserState_GetNuArchive(pState) != nil);
|
assert(ExerciserState_GetNuArchive(pState) != NULL);
|
||||||
assert(argc == 4);
|
assert(argc == 4);
|
||||||
|
|
||||||
return NuRename(ExerciserState_GetNuArchive(pState),
|
return NuRename(ExerciserState_GetNuArchive(pState),
|
||||||
strtol(argv[1], nil, 0), argv[2], argv[3][0]);
|
strtol(argv[1], NULL, 0), argv[2], argv[3][0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -913,7 +913,7 @@ static NuError
|
|||||||
SetErrorCallbackFunc(ExerciserState* pState, int argc, char** argv)
|
SetErrorCallbackFunc(ExerciserState* pState, int argc, char** argv)
|
||||||
{
|
{
|
||||||
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
||||||
assert(ExerciserState_GetNuArchive(pState) != nil);
|
assert(ExerciserState_GetNuArchive(pState) != NULL);
|
||||||
assert(argc == 1);
|
assert(argc == 1);
|
||||||
|
|
||||||
NuSetErrorHandler(ExerciserState_GetNuArchive(pState), ErrorHandler);
|
NuSetErrorHandler(ExerciserState_GetNuArchive(pState), ErrorHandler);
|
||||||
@ -929,11 +929,11 @@ static NuError
|
|||||||
SetValueFunc(ExerciserState* pState, int argc, char** argv)
|
SetValueFunc(ExerciserState* pState, int argc, char** argv)
|
||||||
{
|
{
|
||||||
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
||||||
assert(ExerciserState_GetNuArchive(pState) != nil);
|
assert(ExerciserState_GetNuArchive(pState) != NULL);
|
||||||
assert(argc == 3);
|
assert(argc == 3);
|
||||||
|
|
||||||
return NuSetValue(ExerciserState_GetNuArchive(pState),
|
return NuSetValue(ExerciserState_GetNuArchive(pState),
|
||||||
(NuValueID) strtol(argv[1], nil, 0), strtol(argv[2], nil, 0));
|
(NuValueID) strtol(argv[1], NULL, 0), strtol(argv[2], NULL, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -952,20 +952,20 @@ SetRecordAttrFunc(ExerciserState* pState, int argc, char** argv)
|
|||||||
NuRecordAttr recordAttr;
|
NuRecordAttr recordAttr;
|
||||||
|
|
||||||
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
||||||
assert(ExerciserState_GetNuArchive(pState) != nil);
|
assert(ExerciserState_GetNuArchive(pState) != NULL);
|
||||||
assert(argc == 4);
|
assert(argc == 4);
|
||||||
|
|
||||||
err = NuGetRecord(ExerciserState_GetNuArchive(pState),
|
err = NuGetRecord(ExerciserState_GetNuArchive(pState),
|
||||||
strtol(argv[1], nil, 0), &pRecord);
|
strtol(argv[1], NULL, 0), &pRecord);
|
||||||
if (err != kNuErrNone)
|
if (err != kNuErrNone)
|
||||||
return err;
|
return err;
|
||||||
printf("Exerciser: NuGetRecord succeeded, calling NuSetRecordAttr\n");
|
printf("Exerciser: NuGetRecord succeeded, calling NuSetRecordAttr\n");
|
||||||
NuRecordCopyAttr(&recordAttr, pRecord);
|
NuRecordCopyAttr(&recordAttr, pRecord);
|
||||||
recordAttr.fileType = strtol(argv[2], nil, 0);
|
recordAttr.fileType = strtol(argv[2], NULL, 0);
|
||||||
recordAttr.extraType = strtol(argv[3], nil, 0);
|
recordAttr.extraType = strtol(argv[3], NULL, 0);
|
||||||
/*recordAttr.fileSysInfo = ':';*/
|
/*recordAttr.fileSysInfo = ':';*/
|
||||||
return NuSetRecordAttr(ExerciserState_GetNuArchive(pState),
|
return NuSetRecordAttr(ExerciserState_GetNuArchive(pState),
|
||||||
strtol(argv[1], nil, 0), &recordAttr);
|
strtol(argv[1], NULL, 0), &recordAttr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -975,7 +975,7 @@ static NuError
|
|||||||
TestFunc(ExerciserState* pState, int argc, char** argv)
|
TestFunc(ExerciserState* pState, int argc, char** argv)
|
||||||
{
|
{
|
||||||
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
||||||
assert(ExerciserState_GetNuArchive(pState) != nil);
|
assert(ExerciserState_GetNuArchive(pState) != NULL);
|
||||||
assert(argc == 1);
|
assert(argc == 1);
|
||||||
|
|
||||||
return NuTest(ExerciserState_GetNuArchive(pState));
|
return NuTest(ExerciserState_GetNuArchive(pState));
|
||||||
@ -988,11 +988,11 @@ static NuError
|
|||||||
TestRecordFunc(ExerciserState* pState, int argc, char** argv)
|
TestRecordFunc(ExerciserState* pState, int argc, char** argv)
|
||||||
{
|
{
|
||||||
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
||||||
assert(ExerciserState_GetNuArchive(pState) != nil);
|
assert(ExerciserState_GetNuArchive(pState) != NULL);
|
||||||
assert(argc == 2);
|
assert(argc == 2);
|
||||||
|
|
||||||
return NuTestRecord(ExerciserState_GetNuArchive(pState),
|
return NuTestRecord(ExerciserState_GetNuArchive(pState),
|
||||||
strtol(argv[1], nil, 0));
|
strtol(argv[1], NULL, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1002,16 +1002,16 @@ static NuError
|
|||||||
UpdatePresizedThreadFunc(ExerciserState* pState, int argc, char** argv)
|
UpdatePresizedThreadFunc(ExerciserState* pState, int argc, char** argv)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
NuDataSource* pDataSource = nil;
|
NuDataSource* pDataSource = NULL;
|
||||||
char* lineBuf = nil;
|
char* lineBuf = NULL;
|
||||||
long ourLen, maxLen;
|
long ourLen, maxLen;
|
||||||
|
|
||||||
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
(void) pState, (void) argc, (void) argv; /* shut up, gcc */
|
||||||
assert(ExerciserState_GetNuArchive(pState) != nil);
|
assert(ExerciserState_GetNuArchive(pState) != NULL);
|
||||||
assert(argc == 2);
|
assert(argc == 2);
|
||||||
|
|
||||||
lineBuf = (char*)malloc(kNiceLineLen);
|
lineBuf = (char*)malloc(kNiceLineLen);
|
||||||
assert(lineBuf != nil);
|
assert(lineBuf != NULL);
|
||||||
err = GetLine("Enter data for thread", lineBuf, kNiceLineLen);
|
err = GetLine("Enter data for thread", lineBuf, kNiceLineLen);
|
||||||
if (err != kNuErrNone)
|
if (err != kNuErrNone)
|
||||||
goto bail;
|
goto bail;
|
||||||
@ -1027,16 +1027,16 @@ UpdatePresizedThreadFunc(ExerciserState* pState, int argc, char** argv)
|
|||||||
err);
|
err);
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
lineBuf = nil; /* now owned by the library */
|
lineBuf = NULL; /* now owned by the library */
|
||||||
|
|
||||||
err = NuUpdatePresizedThread(ExerciserState_GetNuArchive(pState),
|
err = NuUpdatePresizedThread(ExerciserState_GetNuArchive(pState),
|
||||||
strtol(argv[1], nil, 0), pDataSource, &maxLen);
|
strtol(argv[1], NULL, 0), pDataSource, &maxLen);
|
||||||
if (err == kNuErrNone)
|
if (err == kNuErrNone)
|
||||||
printf("Exerciser: success; function returned maxLen=%ld\n", maxLen);
|
printf("Exerciser: success; function returned maxLen=%ld\n", maxLen);
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
NuFreeDataSource(pDataSource);
|
NuFreeDataSource(pDataSource);
|
||||||
if (lineBuf != nil)
|
if (lineBuf != NULL)
|
||||||
free(lineBuf);
|
free(lineBuf);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -1185,22 +1185,22 @@ ParseLine(char* lineBuf, ExerciserState* pState, CommandFunc* pFunc, int* pArgc,
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
command = strtok(lineBuf, kWhitespace);
|
command = strtok(lineBuf, kWhitespace);
|
||||||
if (command == nil) {
|
if (command == NULL) {
|
||||||
/* no command; the user probably just hit "enter" on a blank line */
|
/* no command; the user probably just hit "enter" on a blank line */
|
||||||
*pFunc = NothingFunc;
|
*pFunc = NothingFunc;
|
||||||
*pArgc = 0;
|
*pArgc = 0;
|
||||||
*pArgv = nil;
|
*pArgv = NULL;
|
||||||
err = kNuErrNone;
|
err = kNuErrNone;
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* no real need to be flexible; add 1 for command and one for nil */
|
/* no real need to be flexible; add 1 for command and one for NULL */
|
||||||
*pArgv = (char**) malloc(sizeof(char*) * (kMaxArgs+2));
|
*pArgv = (char**) malloc(sizeof(char*) * (kMaxArgs+2));
|
||||||
(*pArgv)[0] = command;
|
(*pArgv)[0] = command;
|
||||||
*pArgc = 1;
|
*pArgc = 1;
|
||||||
|
|
||||||
cp = strtok(nil, kWhitespace);
|
cp = strtok(NULL, kWhitespace);
|
||||||
while (cp != nil) {
|
while (cp != NULL) {
|
||||||
if (*pArgc >= kMaxArgs+1) {
|
if (*pArgc >= kMaxArgs+1) {
|
||||||
printf("ERROR: too many arguments\n");
|
printf("ERROR: too many arguments\n");
|
||||||
goto bail;
|
goto bail;
|
||||||
@ -1208,10 +1208,10 @@ ParseLine(char* lineBuf, ExerciserState* pState, CommandFunc* pFunc, int* pArgc,
|
|||||||
(*pArgv)[*pArgc] = cp;
|
(*pArgv)[*pArgc] = cp;
|
||||||
(*pArgc)++;
|
(*pArgc)++;
|
||||||
|
|
||||||
cp = strtok(nil, kWhitespace);
|
cp = strtok(NULL, kWhitespace);
|
||||||
}
|
}
|
||||||
assert(*pArgc < kMaxArgs+2);
|
assert(*pArgc < kMaxArgs+2);
|
||||||
(*pArgv)[*pArgc] = nil;
|
(*pArgv)[*pArgc] = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Look up the command.
|
* Look up the command.
|
||||||
@ -1237,13 +1237,13 @@ ParseLine(char* lineBuf, ExerciserState* pState, CommandFunc* pFunc, int* pArgc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (gCommandTable[i].flags & kFlagArchiveReq) {
|
if (gCommandTable[i].flags & kFlagArchiveReq) {
|
||||||
if (ExerciserState_GetNuArchive(pState) == nil) {
|
if (ExerciserState_GetNuArchive(pState) == NULL) {
|
||||||
printf("ERROR: must have an archive open\n");
|
printf("ERROR: must have an archive open\n");
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (gCommandTable[i].flags & kFlagNoArchiveReq) {
|
if (gCommandTable[i].flags & kFlagNoArchiveReq) {
|
||||||
if (ExerciserState_GetNuArchive(pState) != nil) {
|
if (ExerciserState_GetNuArchive(pState) != NULL) {
|
||||||
printf("ERROR: an archive is already open\n");
|
printf("ERROR: an archive is already open\n");
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
@ -1271,29 +1271,29 @@ CommandLoop(void)
|
|||||||
CommandFunc func;
|
CommandFunc func;
|
||||||
char lineBuf[128];
|
char lineBuf[128];
|
||||||
int argc;
|
int argc;
|
||||||
char** argv = nil;
|
char** argv = NULL;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
printf("\nEnter command (%s)> ", ExerciserState_GetArchiveFile(pState));
|
printf("\nEnter command (%s)> ", ExerciserState_GetArchiveFile(pState));
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
if (fgets(lineBuf, sizeof(lineBuf), stdin) == nil) {
|
if (fgets(lineBuf, sizeof(lineBuf), stdin) == NULL) {
|
||||||
printf("\n");
|
printf("\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argv != nil) {
|
if (argv != NULL) {
|
||||||
free(argv);
|
free(argv);
|
||||||
argv = nil;
|
argv = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
func = nil; /* sanity check */
|
func = NULL; /* sanity check */
|
||||||
|
|
||||||
err = ParseLine(lineBuf, pState, &func, &argc, &argv);
|
err = ParseLine(lineBuf, pState, &func, &argc, &argv);
|
||||||
if (err != kNuErrNone)
|
if (err != kNuErrNone)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
assert(func != nil);
|
assert(func != NULL);
|
||||||
if (func == QuitFunc)
|
if (func == QuitFunc)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1304,13 +1304,13 @@ CommandLoop(void)
|
|||||||
else if (err > 0)
|
else if (err > 0)
|
||||||
printf("Exerciser: received error %d\n", err);
|
printf("Exerciser: received error %d\n", err);
|
||||||
|
|
||||||
if (argv != nil) {
|
if (argv != NULL) {
|
||||||
free(argv);
|
free(argv);
|
||||||
argv = nil;
|
argv = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ExerciserState_GetNuArchive(pState) != nil) {
|
if (ExerciserState_GetNuArchive(pState) != NULL) {
|
||||||
/* ought to query the archive before saying something like this... */
|
/* ought to query the archive before saying something like this... */
|
||||||
printf("Exerciser: aborting any un-flushed changes in archive %s\n",
|
printf("Exerciser: aborting any un-flushed changes in archive %s\n",
|
||||||
ExerciserState_GetArchivePath(pState));
|
ExerciserState_GetArchivePath(pState));
|
||||||
@ -1318,12 +1318,12 @@ CommandLoop(void)
|
|||||||
err = NuClose(ExerciserState_GetNuArchive(pState));
|
err = NuClose(ExerciserState_GetNuArchive(pState));
|
||||||
if (err != kNuErrNone)
|
if (err != kNuErrNone)
|
||||||
printf("Exerciser: got error %d closing archive\n", err);
|
printf("Exerciser: got error %d closing archive\n", err);
|
||||||
ExerciserState_SetNuArchive(pState, nil);
|
ExerciserState_SetNuArchive(pState, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pState != nil)
|
if (pState != NULL)
|
||||||
ExerciserState_Free(pState);
|
ExerciserState_Free(pState);
|
||||||
if (argv != nil)
|
if (argv != NULL)
|
||||||
free(argv);
|
free(argv);
|
||||||
return kNuErrNone;
|
return kNuErrNone;
|
||||||
}
|
}
|
||||||
@ -1371,7 +1371,7 @@ main(void)
|
|||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
char* debugSet = getenv("MALLOC_CHECK_");
|
char* debugSet = getenv("MALLOC_CHECK_");
|
||||||
if (debugSet == nil)
|
if (debugSet == NULL)
|
||||||
printf("WARNING: MALLOC_CHECK_ not enabled\n\n");
|
printf("WARNING: MALLOC_CHECK_ not enabled\n\n");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -259,7 +259,7 @@ CreateDosSource(const ImgHeader* pHeader, FILE* fp,
|
|||||||
NuDataSource** ppDataSource)
|
NuDataSource** ppDataSource)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
char* diskBuffer = nil;
|
char* diskBuffer = NULL;
|
||||||
long offset;
|
long offset;
|
||||||
|
|
||||||
if (pHeader->dataLen % 4096) {
|
if (pHeader->dataLen % 4096) {
|
||||||
@ -277,7 +277,7 @@ CreateDosSource(const ImgHeader* pHeader, FILE* fp,
|
|||||||
}
|
}
|
||||||
|
|
||||||
diskBuffer = malloc(pHeader->dataLen);
|
diskBuffer = malloc(pHeader->dataLen);
|
||||||
if (diskBuffer == nil) {
|
if (diskBuffer == NULL) {
|
||||||
fprintf(stderr, "ERROR: malloc(%ld) failed\n", pHeader->dataLen);
|
fprintf(stderr, "ERROR: malloc(%ld) failed\n", pHeader->dataLen);
|
||||||
err = kNuErrMalloc;
|
err = kNuErrMalloc;
|
||||||
goto bail;
|
goto bail;
|
||||||
@ -322,10 +322,10 @@ CreateDosSource(const ImgHeader* pHeader, FILE* fp,
|
|||||||
(const unsigned char*) diskBuffer, 0, pHeader->dataLen,
|
(const unsigned char*) diskBuffer, 0, pHeader->dataLen,
|
||||||
FreeCallback, ppDataSource);
|
FreeCallback, ppDataSource);
|
||||||
if (err == kNuErrNone)
|
if (err == kNuErrNone)
|
||||||
diskBuffer = nil;
|
diskBuffer = NULL;
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (diskBuffer != nil)
|
if (diskBuffer != NULL)
|
||||||
free(diskBuffer);
|
free(diskBuffer);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -342,14 +342,14 @@ int
|
|||||||
ConvertFromImgToShk(const char* srcName, const char* dstName)
|
ConvertFromImgToShk(const char* srcName, const char* dstName)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
NuArchive* pArchive = nil;
|
NuArchive* pArchive = NULL;
|
||||||
NuDataSource* pDataSource = nil;
|
NuDataSource* pDataSource = NULL;
|
||||||
NuRecordIdx recordIdx;
|
NuRecordIdx recordIdx;
|
||||||
NuFileDetails fileDetails;
|
NuFileDetails fileDetails;
|
||||||
ImgHeader header;
|
ImgHeader header;
|
||||||
FILE* fp = nil;
|
FILE* fp = NULL;
|
||||||
long flushStatus;
|
long flushStatus;
|
||||||
char* storageName = nil;
|
char* storageName = NULL;
|
||||||
char* cp;
|
char* cp;
|
||||||
|
|
||||||
printf("Converting 2IMG file '%s' to ShrinkIt archive '%s'\n\n",
|
printf("Converting 2IMG file '%s' to ShrinkIt archive '%s'\n\n",
|
||||||
@ -394,10 +394,10 @@ ConvertFromImgToShk(const char* srcName, const char* dstName)
|
|||||||
/* create the name that will be stored in the archive */
|
/* create the name that will be stored in the archive */
|
||||||
storageName = strdup(dstName);
|
storageName = strdup(dstName);
|
||||||
cp = strrchr(storageName, '.');
|
cp = strrchr(storageName, '.');
|
||||||
if (cp != nil)
|
if (cp != NULL)
|
||||||
*cp = '\0';
|
*cp = '\0';
|
||||||
cp = strrchr(storageName, kLocalFssep);
|
cp = strrchr(storageName, kLocalFssep);
|
||||||
if (cp != nil && *(cp+1) != '\0')
|
if (cp != NULL && *(cp+1) != '\0')
|
||||||
cp++;
|
cp++;
|
||||||
else
|
else
|
||||||
cp = storageName;
|
cp = storageName;
|
||||||
@ -433,11 +433,11 @@ ConvertFromImgToShk(const char* srcName, const char* dstName)
|
|||||||
switch (header.imageFormat) {
|
switch (header.imageFormat) {
|
||||||
case kImageFormatDOS:
|
case kImageFormatDOS:
|
||||||
err = CreateDosSource(&header, fp, &pDataSource);
|
err = CreateDosSource(&header, fp, &pDataSource);
|
||||||
fp = nil;
|
fp = NULL;
|
||||||
break;
|
break;
|
||||||
case kImageFormatProDOS:
|
case kImageFormatProDOS:
|
||||||
err = CreateProdosSource(&header, fp, &pDataSource);
|
err = CreateProdosSource(&header, fp, &pDataSource);
|
||||||
fp = nil;
|
fp = NULL;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "How the heck did I get here?");
|
fprintf(stderr, "How the heck did I get here?");
|
||||||
@ -451,12 +451,12 @@ ConvertFromImgToShk(const char* srcName, const char* dstName)
|
|||||||
|
|
||||||
/* add a disk image thread */
|
/* add a disk image thread */
|
||||||
err = NuAddThread(pArchive, recordIdx, kNuThreadIDDiskImage, pDataSource,
|
err = NuAddThread(pArchive, recordIdx, kNuThreadIDDiskImage, pDataSource,
|
||||||
nil);
|
NULL);
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
fprintf(stderr, "ERROR: unable to create thread (err=%d)\n", err);
|
fprintf(stderr, "ERROR: unable to create thread (err=%d)\n", err);
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
pDataSource = nil; /* library owns it now */
|
pDataSource = NULL; /* library owns it now */
|
||||||
|
|
||||||
/* nothing happens until we Flush */
|
/* nothing happens until we Flush */
|
||||||
err = NuFlush(pArchive, &flushStatus);
|
err = NuFlush(pArchive, &flushStatus);
|
||||||
@ -470,17 +470,17 @@ ConvertFromImgToShk(const char* srcName, const char* dstName)
|
|||||||
fprintf(stderr, "ERROR: close failed (err=%d)\n", err);
|
fprintf(stderr, "ERROR: close failed (err=%d)\n", err);
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
pArchive = nil;
|
pArchive = NULL;
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (pArchive != nil) {
|
if (pArchive != NULL) {
|
||||||
(void)NuAbort(pArchive);
|
(void)NuAbort(pArchive);
|
||||||
(void)NuClose(pArchive);
|
(void)NuClose(pArchive);
|
||||||
}
|
}
|
||||||
NuFreeDataSource(pDataSource);
|
NuFreeDataSource(pDataSource);
|
||||||
if (storageName != nil)
|
if (storageName != NULL)
|
||||||
free(storageName);
|
free(storageName);
|
||||||
if (fp != nil)
|
if (fp != NULL)
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return (err == kNuErrNone) ? 0 : -1;
|
return (err == kNuErrNone) ? 0 : -1;
|
||||||
}
|
}
|
||||||
@ -496,13 +496,13 @@ int
|
|||||||
ConvertFromShkToImg(const char* srcName, const char* dstName)
|
ConvertFromShkToImg(const char* srcName, const char* dstName)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
NuArchive* pArchive = nil;
|
NuArchive* pArchive = NULL;
|
||||||
NuDataSink* pDataSink = nil;
|
NuDataSink* pDataSink = NULL;
|
||||||
NuRecordIdx recordIdx;
|
NuRecordIdx recordIdx;
|
||||||
const NuRecord* pRecord;
|
const NuRecord* pRecord;
|
||||||
const NuThread* pThread = nil;
|
const NuThread* pThread = NULL;
|
||||||
ImgHeader header;
|
ImgHeader header;
|
||||||
FILE* fp = nil;
|
FILE* fp = NULL;
|
||||||
int idx;
|
int idx;
|
||||||
|
|
||||||
printf("Converting ShrinkIt archive '%s' to 2IMG file '%s'\n\n",
|
printf("Converting ShrinkIt archive '%s' to 2IMG file '%s'\n\n",
|
||||||
@ -592,10 +592,10 @@ ConvertFromShkToImg(const char* srcName, const char* dstName)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (pArchive != nil)
|
if (pArchive != NULL)
|
||||||
NuClose(pArchive);
|
NuClose(pArchive);
|
||||||
NuFreeDataSink(pDataSink);
|
NuFreeDataSink(pDataSink);
|
||||||
if (fp != nil)
|
if (fp != NULL)
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return (err == kNuErrNone) ? 0 : -1;
|
return (err == kNuErrNone) ? 0 : -1;
|
||||||
}
|
}
|
||||||
@ -610,7 +610,7 @@ DetermineKind(const char* filename)
|
|||||||
const char* dot;
|
const char* dot;
|
||||||
|
|
||||||
dot = strrchr(filename, '.');
|
dot = strrchr(filename, '.');
|
||||||
if (dot == nil)
|
if (dot == NULL)
|
||||||
return kKindUnknown;
|
return kKindUnknown;
|
||||||
|
|
||||||
if (strcasecmp(dot, ".shk") == 0 || strcasecmp(dot, ".sdk") == 0)
|
if (strcasecmp(dot, ".shk") == 0 || strcasecmp(dot, ".sdk") == 0)
|
||||||
|
@ -65,9 +65,9 @@ CopyThreadRecompressed(NuArchive* pInArchive, NuArchive* pOutArchive,
|
|||||||
long flags, const NuThread* pThread, long newRecordIdx)
|
long flags, const NuThread* pThread, long newRecordIdx)
|
||||||
{
|
{
|
||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
NuDataSource* pDataSource = nil;
|
NuDataSource* pDataSource = NULL;
|
||||||
NuDataSink* pDataSink = nil;
|
NuDataSink* pDataSink = NULL;
|
||||||
uchar* buffer = nil;
|
uchar* buffer = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Allocate a buffer large enough to hold all the uncompressed data, and
|
* Allocate a buffer large enough to hold all the uncompressed data, and
|
||||||
@ -77,7 +77,7 @@ CopyThreadRecompressed(NuArchive* pInArchive, NuArchive* pOutArchive,
|
|||||||
*/
|
*/
|
||||||
if (pThread->actualThreadEOF) {
|
if (pThread->actualThreadEOF) {
|
||||||
buffer = malloc(pThread->actualThreadEOF);
|
buffer = malloc(pThread->actualThreadEOF);
|
||||||
if (buffer == nil) {
|
if (buffer == NULL) {
|
||||||
err = kNuErrMalloc;
|
err = kNuErrMalloc;
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
@ -111,7 +111,7 @@ CopyThreadRecompressed(NuArchive* pInArchive, NuArchive* pOutArchive,
|
|||||||
* We always use "actualThreadEOF" because "thThreadEOF" is broken
|
* We always use "actualThreadEOF" because "thThreadEOF" is broken
|
||||||
* for disk archives created by certain versions of ShrinkIt.
|
* for disk archives created by certain versions of ShrinkIt.
|
||||||
*
|
*
|
||||||
* It's okay to pass in a nil value for "buffer", so long as the
|
* It's okay to pass in a NULL value for "buffer", so long as the
|
||||||
* amount of data in the buffer is also zero. The library will do
|
* amount of data in the buffer is also zero. The library will do
|
||||||
* the right thing.
|
* the right thing.
|
||||||
*/
|
*/
|
||||||
@ -134,25 +134,25 @@ CopyThreadRecompressed(NuArchive* pInArchive, NuArchive* pOutArchive,
|
|||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buffer = nil; /* doClose was set, so it's owned by the data source */
|
buffer = NULL; /* doClose was set, so it's owned by the data source */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Schedule the data for addition to the record.
|
* Schedule the data for addition to the record.
|
||||||
*/
|
*/
|
||||||
err = NuAddThread(pOutArchive, newRecordIdx, NuGetThreadID(pThread),
|
err = NuAddThread(pOutArchive, newRecordIdx, NuGetThreadID(pThread),
|
||||||
pDataSource, nil);
|
pDataSource, NULL);
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
fprintf(stderr, "ERROR: unable to add thread (err=%d)\n", err);
|
fprintf(stderr, "ERROR: unable to add thread (err=%d)\n", err);
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
pDataSource = nil; /* library owns it now */
|
pDataSource = NULL; /* library owns it now */
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (pDataSource != nil)
|
if (pDataSource != NULL)
|
||||||
NuFreeDataSource(pDataSource);
|
NuFreeDataSource(pDataSource);
|
||||||
if (pDataSink != nil)
|
if (pDataSink != NULL)
|
||||||
NuFreeDataSink(pDataSink);
|
NuFreeDataSink(pDataSink);
|
||||||
if (buffer != nil)
|
if (buffer != NULL)
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -179,9 +179,9 @@ CopyThreadUncompressed(NuArchive* pInArchive, NuArchive* pOutArchive,
|
|||||||
long flags, const NuThread* pThread, long newRecordIdx)
|
long flags, const NuThread* pThread, long newRecordIdx)
|
||||||
{
|
{
|
||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
NuDataSource* pDataSource = nil;
|
NuDataSource* pDataSource = NULL;
|
||||||
NuDataSink* pDataSink = nil;
|
NuDataSink* pDataSink = NULL;
|
||||||
uchar* buffer = nil;
|
uchar* buffer = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we have some data files that were left uncompressed, perhaps
|
* If we have some data files that were left uncompressed, perhaps
|
||||||
@ -207,7 +207,7 @@ CopyThreadUncompressed(NuArchive* pInArchive, NuArchive* pOutArchive,
|
|||||||
* wrap a data sink around it.
|
* wrap a data sink around it.
|
||||||
*/
|
*/
|
||||||
buffer = malloc(pThread->thCompThreadEOF);
|
buffer = malloc(pThread->thCompThreadEOF);
|
||||||
if (buffer == nil) {
|
if (buffer == NULL) {
|
||||||
err = kNuErrMalloc;
|
err = kNuErrMalloc;
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
@ -265,7 +265,7 @@ CopyThreadUncompressed(NuArchive* pInArchive, NuArchive* pOutArchive,
|
|||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buffer = nil; /* doClose was set, so it's owned by the data source */
|
buffer = NULL; /* doClose was set, so it's owned by the data source */
|
||||||
|
|
||||||
/* yes, this is a kluge... sigh */
|
/* yes, this is a kluge... sigh */
|
||||||
err = NuDataSourceSetRawCrc(pDataSource, pThread->thThreadCRC);
|
err = NuDataSourceSetRawCrc(pDataSource, pThread->thThreadCRC);
|
||||||
@ -281,19 +281,19 @@ CopyThreadUncompressed(NuArchive* pInArchive, NuArchive* pOutArchive,
|
|||||||
* "doClose" on our copy, so we are free to dispose of pDataSource.
|
* "doClose" on our copy, so we are free to dispose of pDataSource.
|
||||||
*/
|
*/
|
||||||
err = NuAddThread(pOutArchive, newRecordIdx, NuGetThreadID(pThread),
|
err = NuAddThread(pOutArchive, newRecordIdx, NuGetThreadID(pThread),
|
||||||
pDataSource, nil);
|
pDataSource, NULL);
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
fprintf(stderr, "ERROR: unable to add thread (err=%d)\n", err);
|
fprintf(stderr, "ERROR: unable to add thread (err=%d)\n", err);
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
pDataSource = nil; /* library owns it now */
|
pDataSource = NULL; /* library owns it now */
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (pDataSource != nil)
|
if (pDataSource != NULL)
|
||||||
NuFreeDataSource(pDataSource);
|
NuFreeDataSource(pDataSource);
|
||||||
if (pDataSink != nil)
|
if (pDataSink != NULL)
|
||||||
NuFreeDataSink(pDataSink);
|
NuFreeDataSink(pDataSink);
|
||||||
if (buffer != nil)
|
if (buffer != NULL)
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -393,7 +393,7 @@ CopyRecord(NuArchive* pInArchive, NuArchive* pOutArchive, long flags,
|
|||||||
if (flags & kFlagReverseThreads) {
|
if (flags & kFlagReverseThreads) {
|
||||||
for (idx = numThreads-1; idx >= 0; idx--) {
|
for (idx = numThreads-1; idx >= 0; idx--) {
|
||||||
pThread = NuGetThread(pRecord, idx);
|
pThread = NuGetThread(pRecord, idx);
|
||||||
assert(pThread != nil);
|
assert(pThread != NULL);
|
||||||
|
|
||||||
err = CopyThread(pInArchive, pOutArchive, flags, pThread,
|
err = CopyThread(pInArchive, pOutArchive, flags, pThread,
|
||||||
newRecordIdx);
|
newRecordIdx);
|
||||||
@ -403,7 +403,7 @@ CopyRecord(NuArchive* pInArchive, NuArchive* pOutArchive, long flags,
|
|||||||
} else {
|
} else {
|
||||||
for (idx = 0; idx < numThreads; idx++) {
|
for (idx = 0; idx < numThreads; idx++) {
|
||||||
pThread = NuGetThread(pRecord, idx);
|
pThread = NuGetThread(pRecord, idx);
|
||||||
assert(pThread != nil);
|
assert(pThread != NULL);
|
||||||
|
|
||||||
err = CopyThread(pInArchive, pOutArchive, flags, pThread,
|
err = CopyThread(pInArchive, pOutArchive, flags, pThread,
|
||||||
newRecordIdx);
|
newRecordIdx);
|
||||||
@ -427,8 +427,8 @@ LaunderArchive(const char* inFile, const char* outFile, NuValue compressMethod,
|
|||||||
long flags)
|
long flags)
|
||||||
{
|
{
|
||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
NuArchive* pInArchive = nil;
|
NuArchive* pInArchive = NULL;
|
||||||
NuArchive* pOutArchive = nil;
|
NuArchive* pOutArchive = NULL;
|
||||||
const NuMasterHeader* pMasterHeader;
|
const NuMasterHeader* pMasterHeader;
|
||||||
NuRecordIdx recordIdx;
|
NuRecordIdx recordIdx;
|
||||||
long idx, flushStatus;
|
long idx, flushStatus;
|
||||||
@ -541,9 +541,9 @@ LaunderArchive(const char* inFile, const char* outFile, NuValue compressMethod,
|
|||||||
}
|
}
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (pInArchive != nil)
|
if (pInArchive != NULL)
|
||||||
NuClose(pInArchive);
|
NuClose(pInArchive);
|
||||||
if (pOutArchive != nil) {
|
if (pOutArchive != NULL) {
|
||||||
if (err != kNuErrNone)
|
if (err != kNuErrNone)
|
||||||
NuAbort(pOutArchive);
|
NuAbort(pOutArchive);
|
||||||
NuClose(pOutArchive); /* flush pending changes and close */
|
NuClose(pOutArchive); /* flush pending changes and close */
|
||||||
@ -559,8 +559,8 @@ bail:
|
|||||||
* does everything we need here.
|
* does everything we need here.
|
||||||
*/
|
*/
|
||||||
int myoptind = 0;
|
int myoptind = 0;
|
||||||
char* myoptarg = nil;
|
char* myoptarg = NULL;
|
||||||
const char* curchar = nil;
|
const char* curchar = NULL;
|
||||||
int skipnext = false;
|
int skipnext = false;
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -638,7 +638,7 @@ main(int argc, char** argv)
|
|||||||
int ic;
|
int ic;
|
||||||
int cc;
|
int cc;
|
||||||
|
|
||||||
(void) NuGetVersion(&major, &minor, &bug, &pBuildDate, nil);
|
(void) NuGetVersion(&major, &minor, &bug, &pBuildDate, NULL);
|
||||||
printf("Using NuFX lib %ld.%ld.%ld built on or after %s\n",
|
printf("Using NuFX lib %ld.%ld.%ld built on or after %s\n",
|
||||||
major, minor, bug, pBuildDate);
|
major, minor, bug, pBuildDate);
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ TGetReplyChar(char defaultReply)
|
|||||||
{
|
{
|
||||||
char tmpBuf[32];
|
char tmpBuf[32];
|
||||||
|
|
||||||
if (fgets(tmpBuf, sizeof(tmpBuf), stdin) == nil)
|
if (fgets(tmpBuf, sizeof(tmpBuf), stdin) == NULL)
|
||||||
return defaultReply;
|
return defaultReply;
|
||||||
if (tmpBuf[0] == '\n' || tmpBuf[0] == '\r')
|
if (tmpBuf[0] == '\n' || tmpBuf[0] == '\r')
|
||||||
return defaultReply;
|
return defaultReply;
|
||||||
@ -80,12 +80,12 @@ ErrorMessageHandler(NuArchive* pArchive, void* vErrorMessage)
|
|||||||
|
|
||||||
if (pErrorMessage->isDebug) {
|
if (pErrorMessage->isDebug) {
|
||||||
fprintf(stderr, "%sNufxLib says: [%s:%d %s] %s\n",
|
fprintf(stderr, "%sNufxLib says: [%s:%d %s] %s\n",
|
||||||
pArchive == nil ? "GLOBAL>" : "",
|
pArchive == NULL ? "GLOBAL>" : "",
|
||||||
pErrorMessage->file, pErrorMessage->line, pErrorMessage->function,
|
pErrorMessage->file, pErrorMessage->line, pErrorMessage->function,
|
||||||
pErrorMessage->message);
|
pErrorMessage->message);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "%sNufxLib says: %s\n",
|
fprintf(stderr, "%sNufxLib says: %s\n",
|
||||||
pArchive == nil ? "GLOBAL>" : "",
|
pArchive == NULL ? "GLOBAL>" : "",
|
||||||
pErrorMessage->message);
|
pErrorMessage->message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,17 +117,17 @@ int
|
|||||||
Test_OpenFlags(void)
|
Test_OpenFlags(void)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
FILE* fp = nil;
|
FILE* fp = NULL;
|
||||||
NuArchive* pArchive = nil;
|
NuArchive* pArchive = NULL;
|
||||||
|
|
||||||
printf("... open zero-byte existing\n");
|
printf("... open zero-byte existing\n");
|
||||||
fp = fopen(kTestArchive, kNuFileOpenWriteTrunc);
|
fp = fopen(kTestArchive, kNuFileOpenWriteTrunc);
|
||||||
if (fp == nil) {
|
if (fp == NULL) {
|
||||||
perror("fopen kTestArchive");
|
perror("fopen kTestArchive");
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
fp = nil;
|
fp = NULL;
|
||||||
|
|
||||||
FAIL_OK;
|
FAIL_OK;
|
||||||
err = NuOpenRW(kTestArchive, kTestTempFile, kNuOpenCreat|kNuOpenExcl,
|
err = NuOpenRW(kTestArchive, kTestTempFile, kNuOpenCreat|kNuOpenExcl,
|
||||||
@ -149,7 +149,7 @@ Test_OpenFlags(void)
|
|||||||
fprintf(stderr, "ERROR: close failed\n");
|
fprintf(stderr, "ERROR: close failed\n");
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
pArchive = nil;
|
pArchive = NULL;
|
||||||
|
|
||||||
if (access(kTestArchive, F_OK) == 0) {
|
if (access(kTestArchive, F_OK) == 0) {
|
||||||
fprintf(stderr, "ERROR: archive should have been removed but wasn't\n");
|
fprintf(stderr, "ERROR: archive should have been removed but wasn't\n");
|
||||||
@ -159,7 +159,7 @@ Test_OpenFlags(void)
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
failed:
|
failed:
|
||||||
if (pArchive != nil) {
|
if (pArchive != NULL) {
|
||||||
NuAbort(pArchive);
|
NuAbort(pArchive);
|
||||||
NuClose(pArchive);
|
NuClose(pArchive);
|
||||||
}
|
}
|
||||||
@ -174,8 +174,8 @@ int
|
|||||||
Test_AddStuff(NuArchive* pArchive)
|
Test_AddStuff(NuArchive* pArchive)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
uchar* buf = nil;
|
uchar* buf = NULL;
|
||||||
NuDataSource* pDataSource = nil;
|
NuDataSource* pDataSource = NULL;
|
||||||
NuRecordIdx recordIdx;
|
NuRecordIdx recordIdx;
|
||||||
long status;
|
long status;
|
||||||
int i;
|
int i;
|
||||||
@ -191,14 +191,14 @@ Test_AddStuff(NuArchive* pArchive)
|
|||||||
|
|
||||||
printf("... add 'bytes' record\n");
|
printf("... add 'bytes' record\n");
|
||||||
buf = malloc(131072);
|
buf = malloc(131072);
|
||||||
if (buf == nil)
|
if (buf == NULL)
|
||||||
goto failed;
|
goto failed;
|
||||||
for (i = 0; i < 131072; i++)
|
for (i = 0; i < 131072; i++)
|
||||||
*(buf+i) = i & 0xff;
|
*(buf+i) = i & 0xff;
|
||||||
|
|
||||||
FAIL_OK;
|
FAIL_OK;
|
||||||
err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed,
|
err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed,
|
||||||
0, nil, 0, 131072, FreeCallback, &pDataSource);
|
0, NULL, 0, 131072, FreeCallback, &pDataSource);
|
||||||
FAIL_BAD;
|
FAIL_BAD;
|
||||||
if (err == kNuErrNone) {
|
if (err == kNuErrNone) {
|
||||||
fprintf(stderr, "ERROR: that should've failed!\n");
|
fprintf(stderr, "ERROR: that should've failed!\n");
|
||||||
@ -215,7 +215,7 @@ Test_AddStuff(NuArchive* pArchive)
|
|||||||
"ERROR: 'bytes' data source create failed (err=%d)\n", err);
|
"ERROR: 'bytes' data source create failed (err=%d)\n", err);
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
buf = nil; /* now owned by library */
|
buf = NULL; /* now owned by library */
|
||||||
|
|
||||||
err = AddSimpleRecord(pArchive, kTestEntryBytes, &recordIdx);
|
err = AddSimpleRecord(pArchive, kTestEntryBytes, &recordIdx);
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
@ -224,12 +224,12 @@ Test_AddStuff(NuArchive* pArchive)
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = NuAddThread(pArchive, recordIdx, kNuThreadIDDataFork, pDataSource,
|
err = NuAddThread(pArchive, recordIdx, kNuThreadIDDataFork, pDataSource,
|
||||||
nil);
|
NULL);
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
fprintf(stderr, "ERROR: 'bytes' thread add failed (err=%d)\n", err);
|
fprintf(stderr, "ERROR: 'bytes' thread add failed (err=%d)\n", err);
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
pDataSource = nil; /* now owned by library */
|
pDataSource = NULL; /* now owned by library */
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -237,7 +237,7 @@ Test_AddStuff(NuArchive* pArchive)
|
|||||||
*/
|
*/
|
||||||
printf("... add 'English' record\n");
|
printf("... add 'English' record\n");
|
||||||
err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed,
|
err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed,
|
||||||
0, (const uchar*)testMsg, 0, strlen(testMsg), nil, &pDataSource);
|
0, (const uchar*)testMsg, 0, strlen(testMsg), NULL, &pDataSource);
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"ERROR: 'English' source create failed (err=%d)\n", err);
|
"ERROR: 'English' source create failed (err=%d)\n", err);
|
||||||
@ -246,7 +246,7 @@ Test_AddStuff(NuArchive* pArchive)
|
|||||||
|
|
||||||
FAIL_OK;
|
FAIL_OK;
|
||||||
err = NuAddThread(pArchive, recordIdx, kNuThreadIDDataFork, pDataSource,
|
err = NuAddThread(pArchive, recordIdx, kNuThreadIDDataFork, pDataSource,
|
||||||
nil);
|
NULL);
|
||||||
FAIL_BAD;
|
FAIL_BAD;
|
||||||
if (err == kNuErrNone) {
|
if (err == kNuErrNone) {
|
||||||
fprintf(stderr, "ERROR: 'English' add should've conflicted!\n");
|
fprintf(stderr, "ERROR: 'English' add should've conflicted!\n");
|
||||||
@ -268,12 +268,12 @@ Test_AddStuff(NuArchive* pArchive)
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = NuAddThread(pArchive, recordIdx, kNuThreadIDDataFork, pDataSource,
|
err = NuAddThread(pArchive, recordIdx, kNuThreadIDDataFork, pDataSource,
|
||||||
nil);
|
NULL);
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
fprintf(stderr, "ERROR: 'English' thread add failed (err=%d)\n", err);
|
fprintf(stderr, "ERROR: 'English' thread add failed (err=%d)\n", err);
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
pDataSource = nil; /* now owned by library */
|
pDataSource = NULL; /* now owned by library */
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -281,7 +281,7 @@ Test_AddStuff(NuArchive* pArchive)
|
|||||||
*/
|
*/
|
||||||
printf("... add 'long' record\n");
|
printf("... add 'long' record\n");
|
||||||
err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed,
|
err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed,
|
||||||
0, nil, 0, 0, nil, &pDataSource);
|
0, NULL, 0, 0, NULL, &pDataSource);
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"ERROR: 'English' source create failed (err=%d)\n", err);
|
"ERROR: 'English' source create failed (err=%d)\n", err);
|
||||||
@ -295,12 +295,12 @@ Test_AddStuff(NuArchive* pArchive)
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = NuAddThread(pArchive, recordIdx, kNuThreadIDRsrcFork, pDataSource,
|
err = NuAddThread(pArchive, recordIdx, kNuThreadIDRsrcFork, pDataSource,
|
||||||
nil);
|
NULL);
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
fprintf(stderr, "ERROR: 'long' thread add failed (err=%d)\n", err);
|
fprintf(stderr, "ERROR: 'long' thread add failed (err=%d)\n", err);
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
pDataSource = nil; /* now owned by library */
|
pDataSource = NULL; /* now owned by library */
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -325,9 +325,9 @@ Test_AddStuff(NuArchive* pArchive)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
failed:
|
failed:
|
||||||
if (pDataSource != nil)
|
if (pDataSource != NULL)
|
||||||
NuFreeDataSource(pDataSource);
|
NuFreeDataSource(pDataSource);
|
||||||
if (buf != nil)
|
if (buf != NULL)
|
||||||
free(buf);
|
free(buf);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -390,7 +390,7 @@ Test_Contents(NuArchive* pArchive)
|
|||||||
recordIdx, err);
|
recordIdx, err);
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
assert(pRecord != nil);
|
assert(pRecord != NULL);
|
||||||
|
|
||||||
switch (posn) {
|
switch (posn) {
|
||||||
case 0:
|
case 0:
|
||||||
@ -444,10 +444,10 @@ VerifySelectionCallback(NuArchive* pArchive, void* vpProposal)
|
|||||||
const NuSelectionProposal* pProposal = vpProposal;
|
const NuSelectionProposal* pProposal = vpProposal;
|
||||||
long count;
|
long count;
|
||||||
|
|
||||||
if (pProposal->pRecord == nil || pProposal->pThread == nil ||
|
if (pProposal->pRecord == NULL || pProposal->pThread == NULL ||
|
||||||
pProposal->pRecord->filename == nil)
|
pProposal->pRecord->filename == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "ERROR: unexpected nil in proposal\n");
|
fprintf(stderr, "ERROR: unexpected NULL in proposal\n");
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -527,8 +527,8 @@ Test_Extract(NuArchive* pArchive)
|
|||||||
NuRecordIdx recordIdx;
|
NuRecordIdx recordIdx;
|
||||||
const NuRecord* pRecord;
|
const NuRecord* pRecord;
|
||||||
const NuThread* pThread;
|
const NuThread* pThread;
|
||||||
NuDataSink* pDataSink = nil;
|
NuDataSink* pDataSink = NULL;
|
||||||
uchar* buf = nil;
|
uchar* buf = NULL;
|
||||||
|
|
||||||
printf("... extracting files\n");
|
printf("... extracting files\n");
|
||||||
|
|
||||||
@ -553,11 +553,11 @@ Test_Extract(NuArchive* pArchive)
|
|||||||
recordIdx, err);
|
recordIdx, err);
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
assert(pRecord != nil);
|
assert(pRecord != NULL);
|
||||||
|
|
||||||
/* we're not using ShrinkIt compat mode, so there should not be a comment */
|
/* we're not using ShrinkIt compat mode, so there should not be a comment */
|
||||||
pThread = NuGetThread(pRecord, 1);
|
pThread = NuGetThread(pRecord, 1);
|
||||||
assert(pThread != nil);
|
assert(pThread != NULL);
|
||||||
if (NuGetThreadID(pThread) != kNuThreadIDDataFork) {
|
if (NuGetThreadID(pThread) != kNuThreadIDDataFork) {
|
||||||
fprintf(stderr, "ERROR: 'bytes' had unexpected threadID 0x%08lx\n",
|
fprintf(stderr, "ERROR: 'bytes' had unexpected threadID 0x%08lx\n",
|
||||||
NuGetThreadID(pThread));
|
NuGetThreadID(pThread));
|
||||||
@ -565,7 +565,7 @@ Test_Extract(NuArchive* pArchive)
|
|||||||
}
|
}
|
||||||
|
|
||||||
buf = malloc(pThread->actualThreadEOF);
|
buf = malloc(pThread->actualThreadEOF);
|
||||||
if (buf == nil) {
|
if (buf == NULL) {
|
||||||
fprintf(stderr, "ERROR: malloc(%ld) failed\n",pThread->actualThreadEOF);
|
fprintf(stderr, "ERROR: malloc(%ld) failed\n",pThread->actualThreadEOF);
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
@ -587,7 +587,7 @@ Test_Extract(NuArchive* pArchive)
|
|||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
NuFreeDataSink(pDataSink);
|
NuFreeDataSink(pDataSink);
|
||||||
pDataSink = nil;
|
pDataSink = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Try to extract with "on" conversion, which should fail because the
|
* Try to extract with "on" conversion, which should fail because the
|
||||||
@ -608,7 +608,7 @@ Test_Extract(NuArchive* pArchive)
|
|||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
NuFreeDataSink(pDataSink);
|
NuFreeDataSink(pDataSink);
|
||||||
pDataSink = nil;
|
pDataSink = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Try to extract with "auto" conversion, which should conclude that
|
* Try to extract with "auto" conversion, which should conclude that
|
||||||
@ -628,12 +628,12 @@ Test_Extract(NuArchive* pArchive)
|
|||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
NuFreeDataSink(pDataSink);
|
NuFreeDataSink(pDataSink);
|
||||||
pDataSink = nil;
|
pDataSink = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
buf = nil;
|
buf = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -652,11 +652,11 @@ Test_Extract(NuArchive* pArchive)
|
|||||||
recordIdx, err);
|
recordIdx, err);
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
assert(pRecord != nil);
|
assert(pRecord != NULL);
|
||||||
|
|
||||||
/* we're not using ShrinkIt compat mode, so there should not be a comment */
|
/* we're not using ShrinkIt compat mode, so there should not be a comment */
|
||||||
pThread = NuGetThread(pRecord, 1);
|
pThread = NuGetThread(pRecord, 1);
|
||||||
assert(pThread != nil);
|
assert(pThread != NULL);
|
||||||
if (NuGetThreadID(pThread) != kNuThreadIDDataFork) {
|
if (NuGetThreadID(pThread) != kNuThreadIDDataFork) {
|
||||||
fprintf(stderr, "ERROR: 'English' had unexpected threadID 0x%08lx\n",
|
fprintf(stderr, "ERROR: 'English' had unexpected threadID 0x%08lx\n",
|
||||||
NuGetThreadID(pThread));
|
NuGetThreadID(pThread));
|
||||||
@ -664,7 +664,7 @@ Test_Extract(NuArchive* pArchive)
|
|||||||
}
|
}
|
||||||
|
|
||||||
buf = malloc(pThread->actualThreadEOF);
|
buf = malloc(pThread->actualThreadEOF);
|
||||||
if (buf == nil) {
|
if (buf == NULL) {
|
||||||
fprintf(stderr, "ERROR: malloc(%ld) failed\n",pThread->actualThreadEOF);
|
fprintf(stderr, "ERROR: malloc(%ld) failed\n",pThread->actualThreadEOF);
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
@ -686,7 +686,7 @@ Test_Extract(NuArchive* pArchive)
|
|||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
NuFreeDataSink(pDataSink);
|
NuFreeDataSink(pDataSink);
|
||||||
pDataSink = nil;
|
pDataSink = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Try to extract with "auto" conversion, which should fail because the
|
* Try to extract with "auto" conversion, which should fail because the
|
||||||
@ -707,12 +707,12 @@ Test_Extract(NuArchive* pArchive)
|
|||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
NuFreeDataSink(pDataSink);
|
NuFreeDataSink(pDataSink);
|
||||||
pDataSink = nil;
|
pDataSink = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*Free(buf);*/
|
/*Free(buf);*/
|
||||||
/*buf = nil;*/
|
/*buf = NULL;*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -731,11 +731,11 @@ Test_Extract(NuArchive* pArchive)
|
|||||||
recordIdx, err);
|
recordIdx, err);
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
assert(pRecord != nil);
|
assert(pRecord != NULL);
|
||||||
|
|
||||||
/* we're not using ShrinkIt compat mode, so there should not be a comment */
|
/* we're not using ShrinkIt compat mode, so there should not be a comment */
|
||||||
pThread = NuGetThread(pRecord, 1);
|
pThread = NuGetThread(pRecord, 1);
|
||||||
assert(pThread != nil);
|
assert(pThread != NULL);
|
||||||
if (NuGetThreadID(pThread) != kNuThreadIDRsrcFork) {
|
if (NuGetThreadID(pThread) != kNuThreadIDRsrcFork) {
|
||||||
fprintf(stderr, "ERROR: 'Long' had unexpected threadID 0x%08lx\n",
|
fprintf(stderr, "ERROR: 'Long' had unexpected threadID 0x%08lx\n",
|
||||||
NuGetThreadID(pThread));
|
NuGetThreadID(pThread));
|
||||||
@ -759,20 +759,20 @@ Test_Extract(NuArchive* pArchive)
|
|||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
NuFreeDataSink(pDataSink);
|
NuFreeDataSink(pDataSink);
|
||||||
pDataSink = nil;
|
pDataSink = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
free(buf);
|
free(buf);
|
||||||
buf = nil;
|
buf = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
failed:
|
failed:
|
||||||
if (buf != nil)
|
if (buf != NULL)
|
||||||
free(buf);
|
free(buf);
|
||||||
if (pDataSink != nil)
|
if (pDataSink != NULL)
|
||||||
(void) NuFreeDataSink(pDataSink);
|
(void) NuFreeDataSink(pDataSink);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -786,7 +786,7 @@ Test_Delete(NuArchive* pArchive)
|
|||||||
NuError err;
|
NuError err;
|
||||||
NuRecordIdx recordIdx;
|
NuRecordIdx recordIdx;
|
||||||
const NuRecord* pRecord;
|
const NuRecord* pRecord;
|
||||||
const NuThread* pThread = nil;
|
const NuThread* pThread = NULL;
|
||||||
long count;
|
long count;
|
||||||
int idx;
|
int idx;
|
||||||
|
|
||||||
@ -806,12 +806,12 @@ Test_Delete(NuArchive* pArchive)
|
|||||||
recordIdx, err);
|
recordIdx, err);
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
assert(pRecord != nil);
|
assert(pRecord != NULL);
|
||||||
assert(pRecord->recTotalThreads > 0);
|
assert(pRecord->recTotalThreads > 0);
|
||||||
|
|
||||||
for (idx = 0; idx < (int)pRecord->recTotalThreads; idx++) {
|
for (idx = 0; idx < (int)pRecord->recTotalThreads; idx++) {
|
||||||
pThread = NuGetThread(pRecord, idx);
|
pThread = NuGetThread(pRecord, idx);
|
||||||
assert(pThread != nil);
|
assert(pThread != NULL);
|
||||||
|
|
||||||
err = NuDeleteThread(pArchive, pThread->threadIdx);
|
err = NuDeleteThread(pArchive, pThread->threadIdx);
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
@ -823,7 +823,7 @@ Test_Delete(NuArchive* pArchive)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* try to re-delete the same thread */
|
/* try to re-delete the same thread */
|
||||||
assert(pThread != nil);
|
assert(pThread != NULL);
|
||||||
FAIL_OK;
|
FAIL_OK;
|
||||||
err = NuDeleteThread(pArchive, pThread->threadIdx);
|
err = NuDeleteThread(pArchive, pThread->threadIdx);
|
||||||
FAIL_BAD;
|
FAIL_BAD;
|
||||||
@ -868,11 +868,11 @@ Test_Delete(NuArchive* pArchive)
|
|||||||
recordIdx, err);
|
recordIdx, err);
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
assert(pRecord != nil);
|
assert(pRecord != NULL);
|
||||||
|
|
||||||
/* grab the first thread before we whack the record */
|
/* grab the first thread before we whack the record */
|
||||||
pThread = NuGetThread(pRecord, 0);
|
pThread = NuGetThread(pRecord, 0);
|
||||||
assert(pThread != nil);
|
assert(pThread != NULL);
|
||||||
|
|
||||||
err = NuDeleteRecord(pArchive, recordIdx);
|
err = NuDeleteRecord(pArchive, recordIdx);
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
@ -936,7 +936,7 @@ int
|
|||||||
DoTests(void)
|
DoTests(void)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
NuArchive* pArchive = nil;
|
NuArchive* pArchive = NULL;
|
||||||
long status;
|
long status;
|
||||||
int cc, result = 0;
|
int cc, result = 0;
|
||||||
char answer;
|
char answer;
|
||||||
@ -1013,7 +1013,7 @@ DoTests(void)
|
|||||||
fprintf(stderr, "ERROR: mid NuClose failed (err=%d)\n", err);
|
fprintf(stderr, "ERROR: mid NuClose failed (err=%d)\n", err);
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
pArchive = nil;
|
pArchive = NULL;
|
||||||
|
|
||||||
err = NuOpenRO(kTestArchive, &pArchive);
|
err = NuOpenRO(kTestArchive, &pArchive);
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
@ -1055,7 +1055,7 @@ DoTests(void)
|
|||||||
fprintf(stderr, "ERROR: late NuClose failed (err=%d)\n", err);
|
fprintf(stderr, "ERROR: late NuClose failed (err=%d)\n", err);
|
||||||
goto failed;
|
goto failed;
|
||||||
}
|
}
|
||||||
pArchive = nil;
|
pArchive = NULL;
|
||||||
|
|
||||||
err = NuOpenRW(kTestArchive, kTestTempFile, 0, &pArchive);
|
err = NuOpenRW(kTestArchive, kTestTempFile, 0, &pArchive);
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
@ -1122,7 +1122,7 @@ DoTests(void)
|
|||||||
* That's all, folks...
|
* That's all, folks...
|
||||||
*/
|
*/
|
||||||
NuClose(pArchive);
|
NuClose(pArchive);
|
||||||
pArchive = nil;
|
pArchive = NULL;
|
||||||
|
|
||||||
printf("... removing '%s'\n", kTestArchive);
|
printf("... removing '%s'\n", kTestArchive);
|
||||||
cc = unlink(kTestArchive);
|
cc = unlink(kTestArchive);
|
||||||
@ -1133,7 +1133,7 @@ DoTests(void)
|
|||||||
|
|
||||||
|
|
||||||
leave:
|
leave:
|
||||||
if (pArchive != nil) {
|
if (pArchive != NULL) {
|
||||||
NuAbort(pArchive);
|
NuAbort(pArchive);
|
||||||
NuClose(pArchive);
|
NuClose(pArchive);
|
||||||
}
|
}
|
||||||
|
@ -53,13 +53,13 @@ typedef struct ArchiveRecord {
|
|||||||
ArchiveRecord*
|
ArchiveRecord*
|
||||||
ArchiveRecord_New(const NuRecord* pRecord)
|
ArchiveRecord_New(const NuRecord* pRecord)
|
||||||
{
|
{
|
||||||
ArchiveRecord* pArcRec = nil;
|
ArchiveRecord* pArcRec = NULL;
|
||||||
|
|
||||||
pArcRec = malloc(sizeof(*pArcRec));
|
pArcRec = malloc(sizeof(*pArcRec));
|
||||||
if (pArcRec == nil)
|
if (pArcRec == NULL)
|
||||||
return nil;
|
return NULL;
|
||||||
|
|
||||||
if (pRecord->filename == nil)
|
if (pRecord->filename == NULL)
|
||||||
pArcRec->filename = strdup("<unknown>");
|
pArcRec->filename = strdup("<unknown>");
|
||||||
else
|
else
|
||||||
pArcRec->filename = strdup((char*)pRecord->filename);
|
pArcRec->filename = strdup((char*)pRecord->filename);
|
||||||
@ -68,7 +68,7 @@ ArchiveRecord_New(const NuRecord* pRecord)
|
|||||||
pArcRec->numThreads = NuRecordGetNumThreads(pRecord);
|
pArcRec->numThreads = NuRecordGetNumThreads(pRecord);
|
||||||
(void) NuRecordCopyThreads(pRecord, &pArcRec->pThreads);
|
(void) NuRecordCopyThreads(pRecord, &pArcRec->pThreads);
|
||||||
|
|
||||||
pArcRec->pNext = nil;
|
pArcRec->pNext = NULL;
|
||||||
|
|
||||||
return pArcRec;
|
return pArcRec;
|
||||||
}
|
}
|
||||||
@ -79,12 +79,12 @@ ArchiveRecord_New(const NuRecord* pRecord)
|
|||||||
void
|
void
|
||||||
ArchiveRecord_Free(ArchiveRecord* pArcRec)
|
ArchiveRecord_Free(ArchiveRecord* pArcRec)
|
||||||
{
|
{
|
||||||
if (pArcRec == nil)
|
if (pArcRec == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (pArcRec->filename != nil)
|
if (pArcRec->filename != NULL)
|
||||||
free(pArcRec->filename);
|
free(pArcRec->filename);
|
||||||
if (pArcRec->pThreads != nil)
|
if (pArcRec->pThreads != NULL)
|
||||||
free(pArcRec->pThreads);
|
free(pArcRec->pThreads);
|
||||||
free(pArcRec);
|
free(pArcRec);
|
||||||
}
|
}
|
||||||
@ -104,7 +104,7 @@ ArchiveRecord_FindThreadByID(const ArchiveRecord* pArcRec, NuThreadID threadID)
|
|||||||
return pThread;
|
return pThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ const NuThread*
|
|||||||
ArchiveRecord_GetThread(const ArchiveRecord* pArcRec, int idx)
|
ArchiveRecord_GetThread(const ArchiveRecord* pArcRec, int idx)
|
||||||
{
|
{
|
||||||
if (idx < 0 || idx >= pArcRec->numThreads)
|
if (idx < 0 || idx >= pArcRec->numThreads)
|
||||||
return nil;
|
return NULL;
|
||||||
return NuThreadGetByIdx(pArcRec->pThreads, idx);
|
return NuThreadGetByIdx(pArcRec->pThreads, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,11 +169,11 @@ ArchiveData_New(void)
|
|||||||
ArchiveData* pArcData;
|
ArchiveData* pArcData;
|
||||||
|
|
||||||
pArcData = malloc(sizeof(*pArcData));
|
pArcData = malloc(sizeof(*pArcData));
|
||||||
if (pArcData == nil)
|
if (pArcData == NULL)
|
||||||
return nil;
|
return NULL;
|
||||||
|
|
||||||
pArcData->numRecords = 0;
|
pArcData->numRecords = 0;
|
||||||
pArcData->pRecordHead = pArcData->pRecordTail = nil;
|
pArcData->pRecordHead = pArcData->pRecordTail = NULL;
|
||||||
|
|
||||||
return pArcData;
|
return pArcData;
|
||||||
}
|
}
|
||||||
@ -183,11 +183,11 @@ ArchiveData_Free(ArchiveData* pArcData)
|
|||||||
{
|
{
|
||||||
ArchiveRecord* pNext;
|
ArchiveRecord* pNext;
|
||||||
|
|
||||||
if (pArcData == nil)
|
if (pArcData == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
printf("*** Deleting %ld records!\n", pArcData->numRecords);
|
printf("*** Deleting %ld records!\n", pArcData->numRecords);
|
||||||
while (pArcData->pRecordHead != nil) {
|
while (pArcData->pRecordHead != NULL) {
|
||||||
pNext = ArchiveRecord_GetNext(pArcData->pRecordHead);
|
pNext = ArchiveRecord_GetNext(pArcData->pRecordHead);
|
||||||
ArchiveRecord_Free(pArcData->pRecordHead);
|
ArchiveRecord_Free(pArcData->pRecordHead);
|
||||||
pArcData->pRecordHead = pNext;
|
pArcData->pRecordHead = pNext;
|
||||||
@ -208,11 +208,11 @@ ArchiveData_GetRecordHead(const ArchiveData* pArcData)
|
|||||||
void
|
void
|
||||||
ArchiveData_AddRecord(ArchiveData* pArcData, ArchiveRecord* pRecord)
|
ArchiveData_AddRecord(ArchiveData* pArcData, ArchiveRecord* pRecord)
|
||||||
{
|
{
|
||||||
assert(pRecord != nil);
|
assert(pRecord != NULL);
|
||||||
assert((pArcData->pRecordHead == nil && pArcData->pRecordTail == nil) ||
|
assert((pArcData->pRecordHead == NULL && pArcData->pRecordTail == NULL) ||
|
||||||
(pArcData->pRecordHead != nil && pArcData->pRecordTail != nil));
|
(pArcData->pRecordHead != NULL && pArcData->pRecordTail != NULL));
|
||||||
|
|
||||||
if (pArcData->pRecordHead == nil) {
|
if (pArcData->pRecordHead == NULL) {
|
||||||
/* first */
|
/* first */
|
||||||
pArcData->pRecordHead = pArcData->pRecordTail = pRecord;
|
pArcData->pRecordHead = pArcData->pRecordTail = pRecord;
|
||||||
} else {
|
} else {
|
||||||
@ -231,7 +231,7 @@ ArchiveData_DumpContents(const ArchiveData* pArcData)
|
|||||||
ArchiveRecord* pArcRec;
|
ArchiveRecord* pArcRec;
|
||||||
|
|
||||||
pArcRec = pArcData->pRecordHead;
|
pArcRec = pArcData->pRecordHead;
|
||||||
while (pArcRec != nil) {
|
while (pArcRec != NULL) {
|
||||||
const NuThread* pThread;
|
const NuThread* pThread;
|
||||||
int i, count;
|
int i, count;
|
||||||
|
|
||||||
@ -264,14 +264,14 @@ NuResult
|
|||||||
GatherContents(NuArchive* pArchive, void* vpRecord)
|
GatherContents(NuArchive* pArchive, void* vpRecord)
|
||||||
{
|
{
|
||||||
NuRecord* pRecord = (NuRecord*) vpRecord;
|
NuRecord* pRecord = (NuRecord*) vpRecord;
|
||||||
ArchiveData* pArchiveData = nil;
|
ArchiveData* pArchiveData = NULL;
|
||||||
ArchiveRecord* pArchiveRecord = ArchiveRecord_New(pRecord);
|
ArchiveRecord* pArchiveRecord = ArchiveRecord_New(pRecord);
|
||||||
|
|
||||||
NuGetExtraData(pArchive, (void**)&pArchiveData);
|
NuGetExtraData(pArchive, (void**)&pArchiveData);
|
||||||
assert(pArchiveData != nil);
|
assert(pArchiveData != NULL);
|
||||||
|
|
||||||
printf("*** Filename = '%s'\n",
|
printf("*** Filename = '%s'\n",
|
||||||
pRecord->filename == nil ? "<unknown>":(const char*)pRecord->filename);
|
pRecord->filename == NULL ? "<unknown>":(const char*)pRecord->filename);
|
||||||
|
|
||||||
ArchiveData_AddRecord(pArchiveData, pArchiveRecord);
|
ArchiveData_AddRecord(pArchiveData, pArchiveRecord);
|
||||||
|
|
||||||
@ -291,10 +291,10 @@ ReadAllFilenameThreads(NuArchive* pArchive, ArchiveData* pArchiveData,
|
|||||||
const NuThread* pThread;
|
const NuThread* pThread;
|
||||||
|
|
||||||
pArchiveRecord = ArchiveData_GetRecordHead(pArchiveData);
|
pArchiveRecord = ArchiveData_GetRecordHead(pArchiveData);
|
||||||
while (pArchiveRecord != nil) {
|
while (pArchiveRecord != NULL) {
|
||||||
pThread = ArchiveRecord_FindThreadByID(pArchiveRecord,
|
pThread = ArchiveRecord_FindThreadByID(pArchiveRecord,
|
||||||
kNuThreadIDFilename);
|
kNuThreadIDFilename);
|
||||||
if (pThread != nil) {
|
if (pThread != NULL) {
|
||||||
err = NuExtractThread(pArchive, pThread->threadIdx, pDataSink);
|
err = NuExtractThread(pArchive, pThread->threadIdx, pDataSink);
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
fprintf(stderr, "*** Extract failed (%d)\n", err);
|
fprintf(stderr, "*** Extract failed (%d)\n", err);
|
||||||
@ -314,7 +314,7 @@ NuError
|
|||||||
ExtractToFile(NuArchive* pArchive, ArchiveData* pArchiveData)
|
ExtractToFile(NuArchive* pArchive, ArchiveData* pArchiveData)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
NuDataSink* pDataSink = nil;
|
NuDataSink* pDataSink = NULL;
|
||||||
|
|
||||||
err = NuCreateDataSinkForFile(true, kNuConvertOff, "out.file", PATH_SEP,
|
err = NuCreateDataSinkForFile(true, kNuConvertOff, "out.file", PATH_SEP,
|
||||||
&pDataSink);
|
&pDataSink);
|
||||||
@ -341,10 +341,10 @@ NuError
|
|||||||
ExtractToFP(NuArchive* pArchive, ArchiveData* pArchiveData)
|
ExtractToFP(NuArchive* pArchive, ArchiveData* pArchiveData)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
FILE* fp = nil;
|
FILE* fp = NULL;
|
||||||
NuDataSink* pDataSink = nil;
|
NuDataSink* pDataSink = NULL;
|
||||||
|
|
||||||
if ((fp = fopen("out.fp", kNuFileOpenWriteTrunc)) == nil)
|
if ((fp = fopen("out.fp", kNuFileOpenWriteTrunc)) == NULL)
|
||||||
return kNuErrFileOpen;
|
return kNuErrFileOpen;
|
||||||
|
|
||||||
err = NuCreateDataSinkForFP(true, kNuConvertOff, fp, &pDataSink);
|
err = NuCreateDataSinkForFP(true, kNuConvertOff, fp, &pDataSink);
|
||||||
@ -357,7 +357,7 @@ ExtractToFP(NuArchive* pArchive, ArchiveData* pArchiveData)
|
|||||||
|
|
||||||
bail:
|
bail:
|
||||||
(void) NuFreeDataSink(pDataSink);
|
(void) NuFreeDataSink(pDataSink);
|
||||||
if (fp != nil)
|
if (fp != NULL)
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
if (err == kNuErrNone)
|
if (err == kNuErrNone)
|
||||||
printf("*** FP write complete\n");
|
printf("*** FP write complete\n");
|
||||||
@ -370,7 +370,7 @@ ExtractToBuffer(NuArchive* pArchive, ArchiveData* pArchiveData)
|
|||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
unsigned char buffer[kHappySize];
|
unsigned char buffer[kHappySize];
|
||||||
NuDataSink* pDataSink = nil;
|
NuDataSink* pDataSink = NULL;
|
||||||
unsigned long count;
|
unsigned long count;
|
||||||
|
|
||||||
err = NuCreateDataSinkForBuffer(true, kNuConvertOff, buffer, kHappySize,
|
err = NuCreateDataSinkForBuffer(true, kNuConvertOff, buffer, kHappySize,
|
||||||
@ -389,7 +389,7 @@ ExtractToBuffer(NuArchive* pArchive, ArchiveData* pArchiveData)
|
|||||||
(void) NuDataSinkGetOutCount(pDataSink, &count);
|
(void) NuDataSinkGetOutCount(pDataSink, &count);
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
FILE* fp;
|
FILE* fp;
|
||||||
if ((fp = fopen("out.buf", kNuFileOpenWriteTrunc)) != nil) {
|
if ((fp = fopen("out.buf", kNuFileOpenWriteTrunc)) != NULL) {
|
||||||
|
|
||||||
printf("*** Writing %ld bytes\n", count);
|
printf("*** Writing %ld bytes\n", count);
|
||||||
if (fwrite(buffer, count, 1, fp) != 1)
|
if (fwrite(buffer, count, 1, fp) != 1)
|
||||||
@ -413,7 +413,7 @@ int
|
|||||||
DoFileStuff(const char* filename)
|
DoFileStuff(const char* filename)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
NuArchive* pArchive = nil;
|
NuArchive* pArchive = NULL;
|
||||||
ArchiveData* pArchiveData = ArchiveData_New();
|
ArchiveData* pArchiveData = ArchiveData_New();
|
||||||
|
|
||||||
err = NuOpenRO(filename, &pArchive);
|
err = NuOpenRO(filename, &pArchive);
|
||||||
@ -444,7 +444,7 @@ bail:
|
|||||||
if (err != kNuErrNone)
|
if (err != kNuErrNone)
|
||||||
fprintf(stderr, "*** ERROR: got error %d\n", err);
|
fprintf(stderr, "*** ERROR: got error %d\n", err);
|
||||||
|
|
||||||
if (pArchive != nil) {
|
if (pArchive != NULL) {
|
||||||
NuError err2 = NuClose(pArchive);
|
NuError err2 = NuClose(pArchive);
|
||||||
if (err == kNuErrNone && err2 != kNuErrNone)
|
if (err == kNuErrNone && err2 != kNuErrNone)
|
||||||
err = err2;
|
err = err2;
|
||||||
@ -464,16 +464,16 @@ main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
long major, minor, bug;
|
long major, minor, bug;
|
||||||
const char* pBuildDate;
|
const char* pBuildDate;
|
||||||
FILE* infp = nil;
|
FILE* infp = NULL;
|
||||||
int cc;
|
int cc;
|
||||||
|
|
||||||
(void) NuGetVersion(&major, &minor, &bug, &pBuildDate, nil);
|
(void) NuGetVersion(&major, &minor, &bug, &pBuildDate, NULL);
|
||||||
printf("Using NuFX lib %ld.%ld.%ld built on or after %s\n",
|
printf("Using NuFX lib %ld.%ld.%ld built on or after %s\n",
|
||||||
major, minor, bug, pBuildDate);
|
major, minor, bug, pBuildDate);
|
||||||
|
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
infp = fopen(argv[1], kNuFileOpenReadOnly);
|
infp = fopen(argv[1], kNuFileOpenReadOnly);
|
||||||
if (infp == nil) {
|
if (infp == NULL) {
|
||||||
perror("fopen failed");
|
perror("fopen failed");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -484,7 +484,7 @@ main(int argc, char** argv)
|
|||||||
|
|
||||||
cc = DoFileStuff(argv[1]);
|
cc = DoFileStuff(argv[1]);
|
||||||
|
|
||||||
if (infp != nil)
|
if (infp != NULL)
|
||||||
fclose(infp);
|
fclose(infp);
|
||||||
|
|
||||||
exit(cc != 0);
|
exit(cc != 0);
|
||||||
|
@ -42,7 +42,7 @@ int
|
|||||||
DoStreamStuff(FILE* fp)
|
DoStreamStuff(FILE* fp)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
NuArchive* pArchive = nil;
|
NuArchive* pArchive = NULL;
|
||||||
|
|
||||||
err = NuStreamOpenRO(fp, &pArchive);
|
err = NuStreamOpenRO(fp, &pArchive);
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
@ -59,7 +59,7 @@ DoStreamStuff(FILE* fp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (pArchive != nil) {
|
if (pArchive != NULL) {
|
||||||
NuError err2 = NuClose(pArchive);
|
NuError err2 = NuClose(pArchive);
|
||||||
if (err == kNuErrNone)
|
if (err == kNuErrNone)
|
||||||
err = err2;
|
err = err2;
|
||||||
@ -77,10 +77,10 @@ main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
long major, minor, bug;
|
long major, minor, bug;
|
||||||
const char* pBuildDate;
|
const char* pBuildDate;
|
||||||
FILE* infp = nil;
|
FILE* infp = NULL;
|
||||||
int cc;
|
int cc;
|
||||||
|
|
||||||
(void) NuGetVersion(&major, &minor, &bug, &pBuildDate, nil);
|
(void) NuGetVersion(&major, &minor, &bug, &pBuildDate, NULL);
|
||||||
printf("Using NuFX lib %ld.%ld.%ld built on or after %s\n",
|
printf("Using NuFX lib %ld.%ld.%ld built on or after %s\n",
|
||||||
major, minor, bug, pBuildDate);
|
major, minor, bug, pBuildDate);
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ main(int argc, char** argv)
|
|||||||
infp = stdin;
|
infp = stdin;
|
||||||
else {
|
else {
|
||||||
infp = fopen(argv[1], kNuFileOpenReadOnly);
|
infp = fopen(argv[1], kNuFileOpenReadOnly);
|
||||||
if (infp == nil) {
|
if (infp == NULL) {
|
||||||
fprintf(stderr, "ERROR: unable to open '%s'\n", argv[1]);
|
fprintf(stderr, "ERROR: unable to open '%s'\n", argv[1]);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ DumpCRCs(const CRCList* pCRCList)
|
|||||||
void
|
void
|
||||||
FreeCRCs(CRCList* pCRCList)
|
FreeCRCs(CRCList* pCRCList)
|
||||||
{
|
{
|
||||||
if (pCRCList == nil)
|
if (pCRCList == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
free(pCRCList->entries);
|
free(pCRCList->entries);
|
||||||
@ -117,21 +117,21 @@ FreeCRCs(CRCList* pCRCList)
|
|||||||
* We assume there are at most two data threads (e.g. data fork and rsrc
|
* We assume there are at most two data threads (e.g. data fork and rsrc
|
||||||
* fork) in a record.
|
* fork) in a record.
|
||||||
*
|
*
|
||||||
* Returns the list on success, nil on failure.
|
* Returns the list on success, NULL on failure.
|
||||||
*/
|
*/
|
||||||
CRCList*
|
CRCList*
|
||||||
GatherCRCs(NuArchive* pArchive)
|
GatherCRCs(NuArchive* pArchive)
|
||||||
{
|
{
|
||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
const NuMasterHeader* pMasterHeader;
|
const NuMasterHeader* pMasterHeader;
|
||||||
CRCList* pCRCList = nil;
|
CRCList* pCRCList = NULL;
|
||||||
unsigned short* pEntries = nil;
|
unsigned short* pEntries = NULL;
|
||||||
long recCount, maxCRCs;
|
long recCount, maxCRCs;
|
||||||
long recIdx, crcIdx;
|
long recIdx, crcIdx;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
pCRCList = malloc(sizeof(*pCRCList));
|
pCRCList = malloc(sizeof(*pCRCList));
|
||||||
if (pCRCList == nil) {
|
if (pCRCList == NULL) {
|
||||||
fprintf(stderr, "ERROR: couldn't alloc CRC list\n");
|
fprintf(stderr, "ERROR: couldn't alloc CRC list\n");
|
||||||
err = kNuErrGeneric;
|
err = kNuErrGeneric;
|
||||||
goto bail;
|
goto bail;
|
||||||
@ -148,7 +148,7 @@ GatherCRCs(NuArchive* pArchive)
|
|||||||
maxCRCs = recCount * 2;
|
maxCRCs = recCount * 2;
|
||||||
|
|
||||||
pEntries = malloc(sizeof(*pEntries) * maxCRCs);
|
pEntries = malloc(sizeof(*pEntries) * maxCRCs);
|
||||||
if (pEntries == nil) {
|
if (pEntries == NULL) {
|
||||||
fprintf(stderr, "ERROR: unable to alloc CRC list (%ld entries)\n",
|
fprintf(stderr, "ERROR: unable to alloc CRC list (%ld entries)\n",
|
||||||
maxCRCs);
|
maxCRCs);
|
||||||
err = kNuErrGeneric;
|
err = kNuErrGeneric;
|
||||||
@ -211,7 +211,7 @@ GatherCRCs(NuArchive* pArchive)
|
|||||||
bail:
|
bail:
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
FreeCRCs(pCRCList);
|
FreeCRCs(pCRCList);
|
||||||
pCRCList = nil;
|
pCRCList = NULL;
|
||||||
}
|
}
|
||||||
return pCRCList;
|
return pCRCList;
|
||||||
}
|
}
|
||||||
@ -231,13 +231,13 @@ bail:
|
|||||||
int
|
int
|
||||||
CompareCRCs(NuArchive* pArchive, const CRCList* pOldCRCList)
|
CompareCRCs(NuArchive* pArchive, const CRCList* pOldCRCList)
|
||||||
{
|
{
|
||||||
CRCList* pNewCRCList = nil;
|
CRCList* pNewCRCList = NULL;
|
||||||
int result = -1;
|
int result = -1;
|
||||||
int badCrc = 0;
|
int badCrc = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
pNewCRCList = GatherCRCs(pArchive);
|
pNewCRCList = GatherCRCs(pArchive);
|
||||||
if (pNewCRCList == nil) {
|
if (pNewCRCList == NULL) {
|
||||||
fprintf(stderr, "ERROR: unable to gather new list\n");
|
fprintf(stderr, "ERROR: unable to gather new list\n");
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
@ -279,13 +279,13 @@ RecompressThread(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
const NuThread* pThread)
|
const NuThread* pThread)
|
||||||
{
|
{
|
||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
NuDataSource* pDataSource = nil;
|
NuDataSource* pDataSource = NULL;
|
||||||
NuDataSink* pDataSink = nil;
|
NuDataSink* pDataSink = NULL;
|
||||||
unsigned char* buf = nil;
|
unsigned char* buf = NULL;
|
||||||
|
|
||||||
if (pThread->actualThreadEOF == 0) {
|
if (pThread->actualThreadEOF == 0) {
|
||||||
buf = malloc(1);
|
buf = malloc(1);
|
||||||
if (buf == nil) {
|
if (buf == NULL) {
|
||||||
fprintf(stderr, "ERROR: failed allocating trivial buffer\n");
|
fprintf(stderr, "ERROR: failed allocating trivial buffer\n");
|
||||||
err = kNuErrGeneric;
|
err = kNuErrGeneric;
|
||||||
goto bail;
|
goto bail;
|
||||||
@ -295,7 +295,7 @@ RecompressThread(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
* Create a buffer and data sink to hold the data.
|
* Create a buffer and data sink to hold the data.
|
||||||
*/
|
*/
|
||||||
buf = malloc(pThread->actualThreadEOF);
|
buf = malloc(pThread->actualThreadEOF);
|
||||||
if (buf == nil) {
|
if (buf == NULL) {
|
||||||
fprintf(stderr, "ERROR: failed allocating %ld bytes\n",
|
fprintf(stderr, "ERROR: failed allocating %ld bytes\n",
|
||||||
pThread->actualThreadEOF);
|
pThread->actualThreadEOF);
|
||||||
err = kNuErrGeneric;
|
err = kNuErrGeneric;
|
||||||
@ -340,19 +340,19 @@ RecompressThread(NuArchive* pArchive, const NuRecord* pRecord,
|
|||||||
fprintf(stderr, "ERROR: unable to create data source (err=%d)\n", err);
|
fprintf(stderr, "ERROR: unable to create data source (err=%d)\n", err);
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
buf = nil;
|
buf = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create replacement thread.
|
* Create replacement thread.
|
||||||
*/
|
*/
|
||||||
err = NuAddThread(pArchive, pRecord->recordIdx, NuGetThreadID(pThread),
|
err = NuAddThread(pArchive, pRecord->recordIdx, NuGetThreadID(pThread),
|
||||||
pDataSource, nil);
|
pDataSource, NULL);
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
fprintf(stderr, "ERROR: unable to add new thread ID=0x%08lx (err=%d)\n",
|
fprintf(stderr, "ERROR: unable to add new thread ID=0x%08lx (err=%d)\n",
|
||||||
NuGetThreadID(pThread), err);
|
NuGetThreadID(pThread), err);
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
pDataSource = nil; /* now owned by NufxLib */
|
pDataSource = NULL; /* now owned by NufxLib */
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
NuFreeDataSink(pDataSink);
|
NuFreeDataSink(pDataSink);
|
||||||
@ -416,7 +416,7 @@ NuError
|
|||||||
RecompressArchive(NuArchive* pArchive, NuValue compression)
|
RecompressArchive(NuArchive* pArchive, NuValue compression)
|
||||||
{
|
{
|
||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
NuRecordIdx* pIndices = nil;
|
NuRecordIdx* pIndices = NULL;
|
||||||
NuAttr countAttr;
|
NuAttr countAttr;
|
||||||
long heldLen;
|
long heldLen;
|
||||||
long idx;
|
long idx;
|
||||||
@ -446,7 +446,7 @@ RecompressArchive(NuArchive* pArchive, NuValue compression)
|
|||||||
* record to "disappear" during processing, we will know about it.
|
* record to "disappear" during processing, we will know about it.
|
||||||
*/
|
*/
|
||||||
pIndices = malloc(countAttr * sizeof(*pIndices));
|
pIndices = malloc(countAttr * sizeof(*pIndices));
|
||||||
if (pIndices == nil) {
|
if (pIndices == NULL) {
|
||||||
fprintf(stderr, "ERROR: malloc on %ld indices failed\n", countAttr);
|
fprintf(stderr, "ERROR: malloc on %ld indices failed\n", countAttr);
|
||||||
err = kNuErrGeneric;
|
err = kNuErrGeneric;
|
||||||
goto bail;
|
goto bail;
|
||||||
@ -504,8 +504,8 @@ int
|
|||||||
TwirlArchive(const char* filename)
|
TwirlArchive(const char* filename)
|
||||||
{
|
{
|
||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
NuArchive* pArchive = nil;
|
NuArchive* pArchive = NULL;
|
||||||
CRCList* pCRCList = nil;
|
CRCList* pCRCList = NULL;
|
||||||
int compression;
|
int compression;
|
||||||
int cc;
|
int cc;
|
||||||
|
|
||||||
@ -534,7 +534,7 @@ TwirlArchive(const char* filename)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pCRCList = GatherCRCs(pArchive);
|
pCRCList = GatherCRCs(pArchive);
|
||||||
if (pCRCList == nil) {
|
if (pCRCList == NULL) {
|
||||||
fprintf(stderr, "ERROR: unable to get CRC list\n");
|
fprintf(stderr, "ERROR: unable to get CRC list\n");
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
@ -599,7 +599,7 @@ TwirlArchive(const char* filename)
|
|||||||
|
|
||||||
bail:
|
bail:
|
||||||
FreeCRCs(pCRCList);
|
FreeCRCs(pCRCList);
|
||||||
if (pArchive != nil) {
|
if (pArchive != NULL) {
|
||||||
NuAbort(pArchive);
|
NuAbort(pArchive);
|
||||||
NuClose(pArchive);
|
NuClose(pArchive);
|
||||||
}
|
}
|
||||||
@ -611,7 +611,7 @@ bail:
|
|||||||
/*
|
/*
|
||||||
* Copy from the current offset in "srcfp" to a new file called
|
* Copy from the current offset in "srcfp" to a new file called
|
||||||
* "outFileName". Returns a writable file descriptor for the new file
|
* "outFileName". Returns a writable file descriptor for the new file
|
||||||
* on success, or nil on error.
|
* on success, or NULL on error.
|
||||||
*
|
*
|
||||||
* (Note "CopyFile()" exists under Win32.)
|
* (Note "CopyFile()" exists under Win32.)
|
||||||
*/
|
*/
|
||||||
@ -623,10 +623,10 @@ MyCopyFile(const char* outFileName, FILE* srcfp)
|
|||||||
size_t count;
|
size_t count;
|
||||||
|
|
||||||
outfp = fopen(outFileName, kNuFileOpenWriteTrunc);
|
outfp = fopen(outFileName, kNuFileOpenWriteTrunc);
|
||||||
if (outfp == nil) {
|
if (outfp == NULL) {
|
||||||
fprintf(stderr, "ERROR: unable to open '%s' (err=%d)\n", outFileName,
|
fprintf(stderr, "ERROR: unable to open '%s' (err=%d)\n", outFileName,
|
||||||
errno);
|
errno);
|
||||||
return nil;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!feof(srcfp)) {
|
while (!feof(srcfp)) {
|
||||||
@ -636,14 +636,14 @@ MyCopyFile(const char* outFileName, FILE* srcfp)
|
|||||||
if (fwrite(buf, 1, count, outfp) != count) {
|
if (fwrite(buf, 1, count, outfp) != count) {
|
||||||
fprintf(stderr, "ERROR: failed writing outfp (err=%d)\n", errno);
|
fprintf(stderr, "ERROR: failed writing outfp (err=%d)\n", errno);
|
||||||
fclose(outfp);
|
fclose(outfp);
|
||||||
return nil;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ferror(srcfp)) {
|
if (ferror(srcfp)) {
|
||||||
fprintf(stderr, "ERROR: failed reading srcfp (err=%d)\n", errno);
|
fprintf(stderr, "ERROR: failed reading srcfp (err=%d)\n", errno);
|
||||||
fclose(outfp);
|
fclose(outfp);
|
||||||
return nil;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return outfp;
|
return outfp;
|
||||||
@ -657,21 +657,21 @@ main(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
long major, minor, bug;
|
long major, minor, bug;
|
||||||
const char* pBuildDate;
|
const char* pBuildDate;
|
||||||
FILE* srcfp = nil;
|
FILE* srcfp = NULL;
|
||||||
FILE* infp = nil;
|
FILE* infp = NULL;
|
||||||
int cc;
|
int cc;
|
||||||
|
|
||||||
/* don't buffer output */
|
/* don't buffer output */
|
||||||
setvbuf(stdout, nil, _IONBF, 0);
|
setvbuf(stdout, NULL, _IONBF, 0);
|
||||||
setvbuf(stderr, nil, _IONBF, 0);
|
setvbuf(stderr, NULL, _IONBF, 0);
|
||||||
|
|
||||||
(void) NuGetVersion(&major, &minor, &bug, &pBuildDate, nil);
|
(void) NuGetVersion(&major, &minor, &bug, &pBuildDate, NULL);
|
||||||
printf("Using NuFX lib %ld.%ld.%ld built on or after %s\n\n",
|
printf("Using NuFX lib %ld.%ld.%ld built on or after %s\n\n",
|
||||||
major, minor, bug, pBuildDate);
|
major, minor, bug, pBuildDate);
|
||||||
|
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
srcfp = fopen(argv[1], kNuFileOpenReadOnly);
|
srcfp = fopen(argv[1], kNuFileOpenReadOnly);
|
||||||
if (srcfp == nil) {
|
if (srcfp == NULL) {
|
||||||
perror("fopen failed");
|
perror("fopen failed");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -683,7 +683,7 @@ main(int argc, char** argv)
|
|||||||
printf("Copying '%s' to '%s'\n", argv[1], kWorkFileName);
|
printf("Copying '%s' to '%s'\n", argv[1], kWorkFileName);
|
||||||
|
|
||||||
infp = MyCopyFile(kWorkFileName, srcfp);
|
infp = MyCopyFile(kWorkFileName, srcfp);
|
||||||
if (infp == nil) {
|
if (infp == NULL) {
|
||||||
fprintf(stderr, "Copy failed, bailing.\n");
|
fprintf(stderr, "Copy failed, bailing.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
12
nulib2/Add.c
12
nulib2/Add.c
@ -18,17 +18,17 @@ NuError
|
|||||||
DoAdd(NulibState* pState)
|
DoAdd(NulibState* pState)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
NuArchive* pArchive = nil;
|
NuArchive* pArchive = NULL;
|
||||||
long flushStatus;
|
long flushStatus;
|
||||||
|
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
|
|
||||||
err = OpenArchiveReadWrite(pState);
|
err = OpenArchiveReadWrite(pState);
|
||||||
if (err != kNuErrNone)
|
if (err != kNuErrNone)
|
||||||
goto bail;
|
goto bail;
|
||||||
|
|
||||||
pArchive = NState_GetNuArchive(pState);
|
pArchive = NState_GetNuArchive(pState);
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
|
|
||||||
NState_SetMatchCount(pState, 0);
|
NState_SetMatchCount(pState, 0);
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ DoAdd(NulibState* pState)
|
|||||||
printf("%s: no records matched\n", gProgName);
|
printf("%s: no records matched\n", gProgName);
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (pArchive != nil) {
|
if (pArchive != NULL) {
|
||||||
NuError err2;
|
NuError err2;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@ -91,8 +91,8 @@ AddToArchive(NulibState* pState, NuArchive* pArchive)
|
|||||||
char* const* pSpec;
|
char* const* pSpec;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
|
|
||||||
if (!NState_GetFilespecCount(pState)) {
|
if (!NState_GetFilespecCount(pState)) {
|
||||||
err = kNuErrSyntax;
|
err = kNuErrSyntax;
|
||||||
|
@ -34,9 +34,9 @@ OutputPathnameFilter(NuArchive* pArchive, void* vproposal)
|
|||||||
char* renameToStr;
|
char* renameToStr;
|
||||||
char* resultBuf;
|
char* resultBuf;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
(void) NuGetExtraData(pArchive, (void**) &pState);
|
(void) NuGetExtraData(pArchive, (void**) &pState);
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
|
|
||||||
/* handle extract-to-pipe */
|
/* handle extract-to-pipe */
|
||||||
if (NState_GetCommand(pState) == kCommandExtractToPipe) {
|
if (NState_GetCommand(pState) == kCommandExtractToPipe) {
|
||||||
@ -51,21 +51,21 @@ OutputPathnameFilter(NuArchive* pArchive, void* vproposal)
|
|||||||
* that it's okay (and let the OS tell them if it isn't).
|
* that it's okay (and let the OS tell them if it isn't).
|
||||||
*/
|
*/
|
||||||
renameToStr = NState_GetRenameToStr(pState);
|
renameToStr = NState_GetRenameToStr(pState);
|
||||||
if (renameToStr != nil) {
|
if (renameToStr != NULL) {
|
||||||
renameFromIdx = NState_GetRenameFromIdx(pState);
|
renameFromIdx = NState_GetRenameFromIdx(pState);
|
||||||
|
|
||||||
if (renameFromIdx == pathProposal->pRecord->recordIdx) {
|
if (renameFromIdx == pathProposal->pRecord->recordIdx) {
|
||||||
/* right source file, proceed with the rename */
|
/* right source file, proceed with the rename */
|
||||||
NState_SetTempPathnameLen(pState, strlen(renameToStr) +1);
|
NState_SetTempPathnameLen(pState, strlen(renameToStr) +1);
|
||||||
resultBuf = NState_GetTempPathnameBuf(pState);
|
resultBuf = NState_GetTempPathnameBuf(pState);
|
||||||
Assert(resultBuf != nil);
|
Assert(resultBuf != NULL);
|
||||||
strcpy(resultBuf, renameToStr);
|
strcpy(resultBuf, renameToStr);
|
||||||
|
|
||||||
pathProposal->newPathname = resultBuf;
|
pathProposal->newPathname = resultBuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* free up renameToStr */
|
/* free up renameToStr */
|
||||||
NState_SetRenameToStr(pState, nil);
|
NState_SetRenameToStr(pState, NULL);
|
||||||
|
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
@ -74,7 +74,7 @@ OutputPathnameFilter(NuArchive* pArchive, void* vproposal)
|
|||||||
* Convert the pathname into something suitable for the current OS.
|
* Convert the pathname into something suitable for the current OS.
|
||||||
*/
|
*/
|
||||||
newPathname = NormalizePath(pState, pathProposal);
|
newPathname = NormalizePath(pState, pathProposal);
|
||||||
if (newPathname == nil) {
|
if (newPathname == NULL) {
|
||||||
ReportError(kNuErrNone, "unable to convert pathname");
|
ReportError(kNuErrNone, "unable to convert pathname");
|
||||||
return kNuAbort;
|
return kNuAbort;
|
||||||
}
|
}
|
||||||
@ -104,7 +104,7 @@ GetReplyChar(char defaultReply)
|
|||||||
{
|
{
|
||||||
char tmpBuf[32];
|
char tmpBuf[32];
|
||||||
|
|
||||||
if (fgets(tmpBuf, sizeof(tmpBuf), stdin) == nil)
|
if (fgets(tmpBuf, sizeof(tmpBuf), stdin) == NULL)
|
||||||
return defaultReply;
|
return defaultReply;
|
||||||
if (tmpBuf[0] == '\n' || tmpBuf[0] == '\r')
|
if (tmpBuf[0] == '\n' || tmpBuf[0] == '\r')
|
||||||
return defaultReply;
|
return defaultReply;
|
||||||
@ -130,10 +130,10 @@ GetReplyString(const char* prompt)
|
|||||||
printf("%s", prompt);
|
printf("%s", prompt);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
result = fgets(buf, sizeof(buf), stdin);
|
result = fgets(buf, sizeof(buf), stdin);
|
||||||
if (result == nil || feof(stdin) || ferror(stdin) || buf[0] == '\0' ||
|
if (result == NULL || feof(stdin) || ferror(stdin) || buf[0] == '\0' ||
|
||||||
buf[0] == '\n')
|
buf[0] == '\n')
|
||||||
{
|
{
|
||||||
return nil;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* nuke the terminating '\n', which is lots of fun in filenames */
|
/* nuke the terminating '\n', which is lots of fun in filenames */
|
||||||
@ -148,30 +148,30 @@ GetReplyString(const char* prompt)
|
|||||||
/*
|
/*
|
||||||
* Get a one-line comment from the user, of at most "maxLen" bytes.
|
* Get a one-line comment from the user, of at most "maxLen" bytes.
|
||||||
*
|
*
|
||||||
* If the user enters a blank line, return "nil".
|
* If the user enters a blank line, return "NULL".
|
||||||
*
|
*
|
||||||
* A pointer to a newly-allocated buffer is returned.
|
* A pointer to a newly-allocated buffer is returned.
|
||||||
*/
|
*/
|
||||||
char*
|
char*
|
||||||
GetSimpleComment(NulibState* pState, const char* pathname, int maxLen)
|
GetSimpleComment(NulibState* pState, const char* pathname, int maxLen)
|
||||||
{
|
{
|
||||||
char* buf = nil;
|
char* buf = NULL;
|
||||||
char* result;
|
char* result;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
buf = Malloc(maxLen);
|
buf = Malloc(maxLen);
|
||||||
if (buf == nil)
|
if (buf == NULL)
|
||||||
return nil;
|
return NULL;
|
||||||
|
|
||||||
printf("Enter one-line comment for '%s'\n: ", pathname);
|
printf("Enter one-line comment for '%s'\n: ", pathname);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
result = fgets(buf, maxLen, stdin);
|
result = fgets(buf, maxLen, stdin);
|
||||||
if (result == nil || feof(stdin) || ferror(stdin) || buf[0] == '\0' ||
|
if (result == NULL || feof(stdin) || ferror(stdin) || buf[0] == '\0' ||
|
||||||
buf[0] == '\n')
|
buf[0] == '\n')
|
||||||
{
|
{
|
||||||
Free(buf);
|
Free(buf);
|
||||||
return nil;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* nuke the terminating '\n', which we don't need */
|
/* nuke the terminating '\n', which we don't need */
|
||||||
@ -251,9 +251,9 @@ SelectionFilter(NuArchive* pArchive, void* vproposal)
|
|||||||
const NuSelectionProposal* selProposal = vproposal;
|
const NuSelectionProposal* selProposal = vproposal;
|
||||||
NulibState* pState;
|
NulibState* pState;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
(void) NuGetExtraData(pArchive, (void**) &pState);
|
(void) NuGetExtraData(pArchive, (void**) &pState);
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
|
|
||||||
if (IsSpecified(pState, selProposal->pRecord)) {
|
if (IsSpecified(pState, selProposal->pRecord)) {
|
||||||
NState_IncMatchCount(pState);
|
NState_IncMatchCount(pState);
|
||||||
@ -309,14 +309,14 @@ ProgressUpdater(NuArchive* pArchive, void* vProgress)
|
|||||||
char nameBuf[kMaxDisplayLen+1];
|
char nameBuf[kMaxDisplayLen+1];
|
||||||
Boolean showName, eolConv;
|
Boolean showName, eolConv;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
(void) NuGetExtraData(pArchive, (void**) &pState);
|
(void) NuGetExtraData(pArchive, (void**) &pState);
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
|
|
||||||
if (NState_GetSuppressOutput(pState))
|
if (NState_GetSuppressOutput(pState))
|
||||||
return kNuOK;
|
return kNuOK;
|
||||||
|
|
||||||
percStr = nil;
|
percStr = NULL;
|
||||||
showName = false;
|
showName = false;
|
||||||
eolConv = false;
|
eolConv = false;
|
||||||
|
|
||||||
@ -384,19 +384,19 @@ ProgressUpdater(NuArchive* pArchive, void* vProgress)
|
|||||||
|
|
||||||
switch (pProgress->state) {
|
switch (pProgress->state) {
|
||||||
case kNuProgressDone:
|
case kNuProgressDone:
|
||||||
actionStr = nil;
|
actionStr = NULL;
|
||||||
percStr = "DONE\n";
|
percStr = "DONE\n";
|
||||||
break;
|
break;
|
||||||
case kNuProgressSkipped:
|
case kNuProgressSkipped:
|
||||||
actionStr = nil;
|
actionStr = NULL;
|
||||||
percStr = "SKIP\n";
|
percStr = "SKIP\n";
|
||||||
break;
|
break;
|
||||||
case kNuProgressAborted: /* not currently possible in NuLib2 */
|
case kNuProgressAborted: /* not currently possible in NuLib2 */
|
||||||
actionStr = nil;
|
actionStr = NULL;
|
||||||
percStr = "CNCL\n";
|
percStr = "CNCL\n";
|
||||||
break;
|
break;
|
||||||
case kNuProgressFailed:
|
case kNuProgressFailed:
|
||||||
actionStr = nil;
|
actionStr = NULL;
|
||||||
percStr = "FAIL\n";
|
percStr = "FAIL\n";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -420,10 +420,10 @@ ProgressUpdater(NuArchive* pArchive, void* vProgress)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actionStr == nil && percStr != nil) {
|
if (actionStr == NULL && percStr != NULL) {
|
||||||
printf("\r%s", percStr);
|
printf("\r%s", percStr);
|
||||||
} else if (actionStr != nil && percStr == nil) {
|
} else if (actionStr != NULL && percStr == NULL) {
|
||||||
if (percStr == nil) {
|
if (percStr == NULL) {
|
||||||
putc('\r', stdout);
|
putc('\r', stdout);
|
||||||
PrintPercentage(pProgress->uncompressedLength,
|
PrintPercentage(pProgress->uncompressedLength,
|
||||||
pProgress->uncompressedProgress);
|
pProgress->uncompressedProgress);
|
||||||
@ -457,9 +457,9 @@ HandleReplaceExisting(NulibState* pState, NuArchive* pArchive,
|
|||||||
char* renameName;
|
char* renameName;
|
||||||
char reply;
|
char reply;
|
||||||
|
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
Assert(pErrorStatus != nil);
|
Assert(pErrorStatus != NULL);
|
||||||
Assert(pErrorStatus->pathname != nil);
|
Assert(pErrorStatus->pathname != NULL);
|
||||||
|
|
||||||
Assert(pErrorStatus->canOverwrite);
|
Assert(pErrorStatus->canOverwrite);
|
||||||
Assert(pErrorStatus->canSkip);
|
Assert(pErrorStatus->canSkip);
|
||||||
@ -506,10 +506,10 @@ HandleReplaceExisting(NulibState* pState, NuArchive* pArchive,
|
|||||||
break; /* continue in "while" loop */
|
break; /* continue in "while" loop */
|
||||||
}
|
}
|
||||||
renameName = GetReplyString("New name: ");
|
renameName = GetReplyString("New name: ");
|
||||||
if (renameName == nil)
|
if (renameName == NULL)
|
||||||
break; /* continue in "while" loop */
|
break; /* continue in "while" loop */
|
||||||
if (pErrorStatus->pRecord == nil) {
|
if (pErrorStatus->pRecord == NULL) {
|
||||||
ReportError(kNuErrNone, "Unexpected nil record");
|
ReportError(kNuErrNone, "Unexpected NULL record");
|
||||||
break; /* continue in "while" loop */
|
break; /* continue in "while" loop */
|
||||||
}
|
}
|
||||||
NState_SetRenameFromIdx(pState,
|
NState_SetRenameFromIdx(pState,
|
||||||
@ -534,7 +534,7 @@ bail:
|
|||||||
/*
|
/*
|
||||||
* Found a bad CRC... should we press onward?
|
* Found a bad CRC... should we press onward?
|
||||||
*
|
*
|
||||||
* Note pErrorStatus->pathname may be nil if the error was found in the
|
* Note pErrorStatus->pathname may be NULL if the error was found in the
|
||||||
* master header or in the record header.
|
* master header or in the record header.
|
||||||
*/
|
*/
|
||||||
static NuResult
|
static NuResult
|
||||||
@ -544,8 +544,8 @@ HandleBadCRC(NulibState* pState, NuArchive* pArchive,
|
|||||||
NuResult result = kNuOK;
|
NuResult result = kNuOK;
|
||||||
char reply;
|
char reply;
|
||||||
|
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
Assert(pErrorStatus != nil);
|
Assert(pErrorStatus != NULL);
|
||||||
|
|
||||||
if (NState_GetInputUnavailable(pState)) {
|
if (NState_GetInputUnavailable(pState)) {
|
||||||
putc('\n', stderr);
|
putc('\n', stderr);
|
||||||
@ -555,7 +555,7 @@ HandleBadCRC(NulibState* pState, NuArchive* pArchive,
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (pErrorStatus->pathname != nil)
|
if (pErrorStatus->pathname != NULL)
|
||||||
fprintf(stderr, "\n Found a bad CRC in %s\n",
|
fprintf(stderr, "\n Found a bad CRC in %s\n",
|
||||||
pErrorStatus->pathname);
|
pErrorStatus->pathname);
|
||||||
else
|
else
|
||||||
@ -604,9 +604,9 @@ HandleAddNotFound(NulibState* pState, NuArchive* pArchive,
|
|||||||
NuResult result = kNuOK;
|
NuResult result = kNuOK;
|
||||||
char reply;
|
char reply;
|
||||||
|
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
Assert(pErrorStatus != nil);
|
Assert(pErrorStatus != NULL);
|
||||||
Assert(pErrorStatus->pathname != nil);
|
Assert(pErrorStatus->pathname != NULL);
|
||||||
|
|
||||||
if (NState_GetInputUnavailable(pState)) {
|
if (NState_GetInputUnavailable(pState)) {
|
||||||
putc('\n', stdout);
|
putc('\n', stdout);
|
||||||
@ -651,9 +651,9 @@ ErrorHandler(NuArchive* pArchive, void* vErrorStatus)
|
|||||||
NulibState* pState;
|
NulibState* pState;
|
||||||
NuResult result;
|
NuResult result;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
(void) NuGetExtraData(pArchive, (void**) &pState);
|
(void) NuGetExtraData(pArchive, (void**) &pState);
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
|
|
||||||
/* default action is to abort the current operation */
|
/* default action is to abort the current operation */
|
||||||
result = kNuAbort;
|
result = kNuAbort;
|
||||||
@ -728,7 +728,7 @@ ErrorMessageHandler(NuArchive* pArchive, void* vErrorMessage)
|
|||||||
const NuErrorMessage* pErrorMessage = (const NuErrorMessage*) vErrorMessage;
|
const NuErrorMessage* pErrorMessage = (const NuErrorMessage*) vErrorMessage;
|
||||||
|
|
||||||
fprintf(stderr, "%s%d %3d %s:%d %s %s\n",
|
fprintf(stderr, "%s%d %3d %s:%d %s %s\n",
|
||||||
pArchive == nil ? "(GLOBAL)" : "",
|
pArchive == NULL ? "(GLOBAL)" : "",
|
||||||
pErrorMessage->isDebug, pErrorMessage->err, pErrorMessage->file,
|
pErrorMessage->isDebug, pErrorMessage->err, pErrorMessage->file,
|
||||||
pErrorMessage->line, pErrorMessage->function, pErrorMessage->message);
|
pErrorMessage->line, pErrorMessage->function, pErrorMessage->message);
|
||||||
return kNuOK;
|
return kNuOK;
|
||||||
@ -768,7 +768,7 @@ IsRecordReadOnly(const NuRecord* pRecord)
|
|||||||
Boolean
|
Boolean
|
||||||
IsFilenameStdin(const char* archiveName)
|
IsFilenameStdin(const char* archiveName)
|
||||||
{
|
{
|
||||||
Assert(archiveName != nil);
|
Assert(archiveName != NULL);
|
||||||
return (strcmp(archiveName, kStdinArchive) == 0);
|
return (strcmp(archiveName, kStdinArchive) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -783,9 +783,9 @@ NuError
|
|||||||
OpenArchiveReadOnly(NulibState* pState)
|
OpenArchiveReadOnly(NulibState* pState)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
NuArchive* pArchive = nil;
|
NuArchive* pArchive = NULL;
|
||||||
|
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
|
|
||||||
if (IsFilenameStdin(NState_GetArchiveFilename(pState))) {
|
if (IsFilenameStdin(NState_GetArchiveFilename(pState))) {
|
||||||
err = NuStreamOpenRO(stdin, &pArchive);
|
err = NuStreamOpenRO(stdin, &pArchive);
|
||||||
@ -881,10 +881,10 @@ OpenArchiveReadOnly(NulibState* pState)
|
|||||||
BailError(err);
|
BailError(err);
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (err != kNuErrNone && pArchive != nil) {
|
if (err != kNuErrNone && pArchive != NULL) {
|
||||||
/* clean up */
|
/* clean up */
|
||||||
(void) NuClose(pArchive);
|
(void) NuClose(pArchive);
|
||||||
NState_SetNuArchive(pState, nil);
|
NState_SetNuArchive(pState, NULL);
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -900,14 +900,14 @@ NuError
|
|||||||
OpenArchiveReadWrite(NulibState* pState)
|
OpenArchiveReadWrite(NulibState* pState)
|
||||||
{
|
{
|
||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
NuArchive* pArchive = nil;
|
NuArchive* pArchive = NULL;
|
||||||
char* tempName = nil;
|
char* tempName = NULL;
|
||||||
|
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
Assert(IsFilenameStdin(NState_GetArchiveFilename(pState)) == false);
|
Assert(IsFilenameStdin(NState_GetArchiveFilename(pState)) == false);
|
||||||
|
|
||||||
tempName = MakeTempArchiveName(pState);
|
tempName = MakeTempArchiveName(pState);
|
||||||
if (tempName == nil)
|
if (tempName == NULL)
|
||||||
goto bail;
|
goto bail;
|
||||||
DBUG(("TEMP NAME = '%s'\n", tempName));
|
DBUG(("TEMP NAME = '%s'\n", tempName));
|
||||||
|
|
||||||
@ -979,11 +979,11 @@ OpenArchiveReadWrite(NulibState* pState)
|
|||||||
|
|
||||||
bail:
|
bail:
|
||||||
Free(tempName);
|
Free(tempName);
|
||||||
if (err != kNuErrNone && pArchive != nil) {
|
if (err != kNuErrNone && pArchive != NULL) {
|
||||||
/* clean up */
|
/* clean up */
|
||||||
NuAbort(pArchive);
|
NuAbort(pArchive);
|
||||||
(void) NuClose(pArchive);
|
(void) NuClose(pArchive);
|
||||||
NState_SetNuArchive(pState, nil);
|
NState_SetNuArchive(pState, NULL);
|
||||||
}
|
}
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ OpenFileReadOnly(const char* filename, FILE** pFp)
|
|||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
|
|
||||||
*pFp = fopen(filename, kFileOpenReadOnly);
|
*pFp = fopen(filename, kFileOpenReadOnly);
|
||||||
if (*pFp == nil)
|
if (*pFp == NULL)
|
||||||
err = errno ? errno : kNuErrFileOpen;
|
err = errno ? errno : kNuErrFileOpen;
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
@ -198,7 +198,7 @@ static void
|
|||||||
BNYFree(BNYArchive* pBny)
|
BNYFree(BNYArchive* pBny)
|
||||||
{
|
{
|
||||||
/* don't need to do this on stdin, but won't really hurt */
|
/* don't need to do this on stdin, but won't really hurt */
|
||||||
if (pBny->fp != nil)
|
if (pBny->fp != NULL)
|
||||||
fclose(pBny->fp);
|
fclose(pBny->fp);
|
||||||
|
|
||||||
Free(pBny);
|
Free(pBny);
|
||||||
@ -215,9 +215,9 @@ BNYOpenReadOnly(BNYArchive* pBny)
|
|||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
NulibState* pState;
|
NulibState* pState;
|
||||||
|
|
||||||
Assert(pBny != nil);
|
Assert(pBny != NULL);
|
||||||
Assert(pBny->pState != nil);
|
Assert(pBny->pState != NULL);
|
||||||
Assert(pBny->fp == nil);
|
Assert(pBny->fp == NULL);
|
||||||
|
|
||||||
pState = pBny->pState;
|
pState = pBny->pState;
|
||||||
|
|
||||||
@ -253,10 +253,10 @@ BNYRead(BNYArchive* pBny, void* buf, size_t nbyte)
|
|||||||
{
|
{
|
||||||
size_t result;
|
size_t result;
|
||||||
|
|
||||||
Assert(pBny != nil);
|
Assert(pBny != NULL);
|
||||||
Assert(buf != nil);
|
Assert(buf != NULL);
|
||||||
Assert(nbyte > 0);
|
Assert(nbyte > 0);
|
||||||
Assert(pBny->fp != nil);
|
Assert(pBny->fp != NULL);
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
result = fread(buf, 1, nbyte, pBny->fp);
|
result = fread(buf, 1, nbyte, pBny->fp);
|
||||||
@ -273,9 +273,9 @@ BNYRead(BNYArchive* pBny, void* buf, size_t nbyte)
|
|||||||
static NuError
|
static NuError
|
||||||
BNYSeek(BNYArchive* pBny, long offset)
|
BNYSeek(BNYArchive* pBny, long offset)
|
||||||
{
|
{
|
||||||
Assert(pBny != nil);
|
Assert(pBny != NULL);
|
||||||
Assert(pBny->fp != nil);
|
Assert(pBny->fp != NULL);
|
||||||
Assert(pBny->pState != nil);
|
Assert(pBny->pState != NULL);
|
||||||
Assert(offset > 0);
|
Assert(offset > 0);
|
||||||
|
|
||||||
/*DBUG(("--- seeking forward %ld bytes\n", offset));*/
|
/*DBUG(("--- seeking forward %ld bytes\n", offset));*/
|
||||||
@ -327,8 +327,8 @@ BNYDecodeHeader(BNYArchive* pBny, BNYEntry* pEntry)
|
|||||||
uchar* raw;
|
uchar* raw;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
Assert(pBny != nil);
|
Assert(pBny != NULL);
|
||||||
Assert(pEntry != nil);
|
Assert(pEntry != NULL);
|
||||||
|
|
||||||
raw = pEntry->blockBuf;
|
raw = pEntry->blockBuf;
|
||||||
|
|
||||||
@ -422,9 +422,9 @@ BNYNormalizePath(BNYArchive* pBny, BNYEntry* pEntry)
|
|||||||
pathProposal.pRecord = &fakeRecord;
|
pathProposal.pRecord = &fakeRecord;
|
||||||
pathProposal.pThread = &fakeThread;
|
pathProposal.pThread = &fakeThread;
|
||||||
|
|
||||||
pathProposal.newPathname = nil;
|
pathProposal.newPathname = NULL;
|
||||||
pathProposal.newFilenameSeparator = '\0';
|
pathProposal.newFilenameSeparator = '\0';
|
||||||
pathProposal.newDataSink = nil;
|
pathProposal.newDataSink = NULL;
|
||||||
|
|
||||||
/* need the filetype and auxtype for -e/-ee */
|
/* need the filetype and auxtype for -e/-ee */
|
||||||
fakeRecord.recFileType = pEntry->fileType;
|
fakeRecord.recFileType = pEntry->fileType;
|
||||||
@ -464,7 +464,7 @@ BNYCopyBlocks(BNYArchive* pBny, BNYEntry* pEntry, FILE* outfp)
|
|||||||
if (toWrite > kBNYBlockSize)
|
if (toWrite > kBNYBlockSize)
|
||||||
toWrite = kBNYBlockSize;
|
toWrite = kBNYBlockSize;
|
||||||
|
|
||||||
if (outfp != nil) {
|
if (outfp != NULL) {
|
||||||
if (fwrite(pEntry->blockBuf, toWrite, 1, outfp) != 1) {
|
if (fwrite(pEntry->blockBuf, toWrite, 1, outfp) != 1) {
|
||||||
err = errno ? errno : kNuErrFileWrite;
|
err = errno ? errno : kNuErrFileWrite;
|
||||||
ReportError(err, "BNY write failed");
|
ReportError(err, "BNY write failed");
|
||||||
@ -609,11 +609,11 @@ BNYUnSqueeze(BNYArchive* pBny, BNYEntry* pEntry, FILE* outfp)
|
|||||||
#endif
|
#endif
|
||||||
short nodeCount;
|
short nodeCount;
|
||||||
int i, inrep;
|
int i, inrep;
|
||||||
uchar* tmpBuf = nil;
|
uchar* tmpBuf = NULL;
|
||||||
uchar lastc = 0;
|
uchar lastc = 0;
|
||||||
|
|
||||||
tmpBuf = Malloc(kSqBufferSize);
|
tmpBuf = Malloc(kSqBufferSize);
|
||||||
if (tmpBuf == nil) {
|
if (tmpBuf == NULL) {
|
||||||
err = kNuErrMalloc;
|
err = kNuErrMalloc;
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
@ -824,9 +824,9 @@ BNYUnSqueeze(BNYArchive* pBny, BNYEntry* pEntry, FILE* outfp)
|
|||||||
val = 2;
|
val = 2;
|
||||||
}
|
}
|
||||||
while (--val) {
|
while (--val) {
|
||||||
/*if (pCrc != nil)
|
/*if (pCrc != NULL)
|
||||||
*pCrc = Nu_CalcCRC16(*pCrc, &lastc, 1);*/
|
*pCrc = Nu_CalcCRC16(*pCrc, &lastc, 1);*/
|
||||||
if (outfp != nil)
|
if (outfp != NULL)
|
||||||
putc(lastc, outfp);
|
putc(lastc, outfp);
|
||||||
#ifdef FULL_SQ_HEADER
|
#ifdef FULL_SQ_HEADER
|
||||||
checksum += lastc;
|
checksum += lastc;
|
||||||
@ -840,9 +840,9 @@ BNYUnSqueeze(BNYArchive* pBny, BNYEntry* pEntry, FILE* outfp)
|
|||||||
inrep = true;
|
inrep = true;
|
||||||
} else {
|
} else {
|
||||||
lastc = val;
|
lastc = val;
|
||||||
/*if (pCrc != nil)
|
/*if (pCrc != NULL)
|
||||||
*pCrc = Nu_CalcCRC16(*pCrc, &lastc, 1);*/
|
*pCrc = Nu_CalcCRC16(*pCrc, &lastc, 1);*/
|
||||||
if (outfp != nil)
|
if (outfp != NULL)
|
||||||
putc(lastc, outfp);
|
putc(lastc, outfp);
|
||||||
#ifdef FULL_SQ_HEADER
|
#ifdef FULL_SQ_HEADER
|
||||||
checksum += lastc;
|
checksum += lastc;
|
||||||
@ -889,7 +889,7 @@ BNYUnSqueeze(BNYArchive* pBny, BNYEntry* pEntry, FILE* outfp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (outfp != nil)
|
if (outfp != NULL)
|
||||||
fflush(outfp);
|
fflush(outfp);
|
||||||
Free(tmpBuf);
|
Free(tmpBuf);
|
||||||
return err;
|
return err;
|
||||||
@ -913,19 +913,19 @@ static NuError
|
|||||||
BNYIterate(NulibState* pState, BNYIteratorFunc func)
|
BNYIterate(NulibState* pState, BNYIteratorFunc func)
|
||||||
{
|
{
|
||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
BNYArchive* pBny = nil;
|
BNYArchive* pBny = NULL;
|
||||||
BNYEntry entry;
|
BNYEntry entry;
|
||||||
Boolean consumed;
|
Boolean consumed;
|
||||||
int first = true;
|
int first = true;
|
||||||
int toFollow;
|
int toFollow;
|
||||||
|
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
Assert(func != nil);
|
Assert(func != NULL);
|
||||||
|
|
||||||
NState_SetMatchCount(pState, 0);
|
NState_SetMatchCount(pState, 0);
|
||||||
|
|
||||||
pBny = BNYInit(pState);
|
pBny = BNYInit(pState);
|
||||||
if (pBny == nil) {
|
if (pBny == NULL) {
|
||||||
err = kNuErrMalloc;
|
err = kNuErrMalloc;
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
@ -1012,7 +1012,7 @@ BNYIterate(NulibState* pState, BNYIteratorFunc func)
|
|||||||
printf("%s: no records match\n", gProgName);
|
printf("%s: no records match\n", gProgName);
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (pBny != nil)
|
if (pBny != NULL)
|
||||||
BNYFree(pBny);
|
BNYFree(pBny);
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
DBUG(("--- Iterator returning failure %d\n", err));
|
DBUG(("--- Iterator returning failure %d\n", err));
|
||||||
@ -1173,7 +1173,7 @@ BNYExtractDirectory(BNYArchive* pBny, BNYEntry* pEntry, ExtMode extMode)
|
|||||||
*/
|
*/
|
||||||
/*newName = BNYNormalizePath(pBny, pEntry);*/
|
/*newName = BNYNormalizePath(pBny, pEntry);*/
|
||||||
newName = pEntry->fileName;
|
newName = pEntry->fileName;
|
||||||
if (newName == nil)
|
if (newName == NULL)
|
||||||
goto bail;
|
goto bail;
|
||||||
|
|
||||||
err = TestFileExistence(newName, &isDir);
|
err = TestFileExistence(newName, &isDir);
|
||||||
@ -1216,7 +1216,7 @@ BNYExtract(BNYArchive* pBny, BNYEntry* pEntry, Boolean* pConsumedFlag)
|
|||||||
NulibState* pState;
|
NulibState* pState;
|
||||||
ExtMode extMode;
|
ExtMode extMode;
|
||||||
const char* actionStr = "HOSED";
|
const char* actionStr = "HOSED";
|
||||||
FILE* outfp = nil;
|
FILE* outfp = NULL;
|
||||||
Boolean eolConv;
|
Boolean eolConv;
|
||||||
|
|
||||||
pState = pBny->pState;
|
pState = pBny->pState;
|
||||||
@ -1275,7 +1275,7 @@ BNYExtract(BNYArchive* pBny, BNYEntry* pEntry, Boolean* pConsumedFlag)
|
|||||||
}
|
}
|
||||||
|
|
||||||
newName = BNYNormalizePath(pBny, pEntry);
|
newName = BNYNormalizePath(pBny, pEntry);
|
||||||
if (newName == nil)
|
if (newName == NULL)
|
||||||
goto bail;
|
goto bail;
|
||||||
|
|
||||||
err = TestFileExistence(newName, &isDir);
|
err = TestFileExistence(newName, &isDir);
|
||||||
@ -1303,13 +1303,13 @@ BNYExtract(BNYArchive* pBny, BNYEntry* pEntry, Boolean* pConsumedFlag)
|
|||||||
|
|
||||||
/* open it, overwriting anything present */
|
/* open it, overwriting anything present */
|
||||||
outfp = fopen(newName, "w");
|
outfp = fopen(newName, "w");
|
||||||
if (outfp == nil) {
|
if (outfp == NULL) {
|
||||||
err = kNuErrFileOpen;
|
err = kNuErrFileOpen;
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* outfp == nil means we're in test mode */
|
/* outfp == NULL means we're in test mode */
|
||||||
Assert(outfp == nil);
|
Assert(outfp == NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1358,7 +1358,7 @@ BNYExtract(BNYArchive* pBny, BNYEntry* pEntry, Boolean* pConsumedFlag)
|
|||||||
*pConsumedFlag = true;
|
*pConsumedFlag = true;
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (outfp != nil && outfp != stdout)
|
if (outfp != NULL && outfp != stdout)
|
||||||
fclose(outfp);
|
fclose(outfp);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -19,15 +19,15 @@ NuError
|
|||||||
DoDelete(NulibState* pState)
|
DoDelete(NulibState* pState)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
NuArchive* pArchive = nil;
|
NuArchive* pArchive = NULL;
|
||||||
|
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
|
|
||||||
err = OpenArchiveReadWrite(pState);
|
err = OpenArchiveReadWrite(pState);
|
||||||
if (err != kNuErrNone)
|
if (err != kNuErrNone)
|
||||||
goto bail;
|
goto bail;
|
||||||
pArchive = NState_GetNuArchive(pState);
|
pArchive = NState_GetNuArchive(pState);
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
|
|
||||||
NState_SetMatchCount(pState, 0);
|
NState_SetMatchCount(pState, 0);
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ DoDelete(NulibState* pState)
|
|||||||
printf("%s: no records matched\n", gProgName);
|
printf("%s: no records matched\n", gProgName);
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (pArchive != nil)
|
if (pArchive != NULL)
|
||||||
(void) NuClose(pArchive);
|
(void) NuClose(pArchive);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ ExtractAllRecords(NulibState* pState, NuArchive* pArchive)
|
|||||||
threadIdx++)
|
threadIdx++)
|
||||||
{
|
{
|
||||||
pThread = NuGetThread(pRecord, threadIdx);
|
pThread = NuGetThread(pRecord, threadIdx);
|
||||||
Assert(pThread != nil);
|
Assert(pThread != NULL);
|
||||||
|
|
||||||
if (NuGetThreadID(pThread) == kNuThreadIDComment &&
|
if (NuGetThreadID(pThread) == kNuThreadIDComment &&
|
||||||
pThread->actualThreadEOF > 0)
|
pThread->actualThreadEOF > 0)
|
||||||
@ -91,9 +91,9 @@ NuError
|
|||||||
DoExtract(NulibState* pState)
|
DoExtract(NulibState* pState)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
NuArchive* pArchive = nil;
|
NuArchive* pArchive = NULL;
|
||||||
|
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
|
|
||||||
if (NState_GetModBinaryII(pState))
|
if (NState_GetModBinaryII(pState))
|
||||||
return BNYDoExtract(pState);
|
return BNYDoExtract(pState);
|
||||||
@ -104,7 +104,7 @@ DoExtract(NulibState* pState)
|
|||||||
if (err != kNuErrNone)
|
if (err != kNuErrNone)
|
||||||
goto bail;
|
goto bail;
|
||||||
pArchive = NState_GetNuArchive(pState);
|
pArchive = NState_GetNuArchive(pState);
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
|
|
||||||
NState_SetMatchCount(pState, 0);
|
NState_SetMatchCount(pState, 0);
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ DoExtract(NulibState* pState)
|
|||||||
printf("%s: no records match\n", gProgName);
|
printf("%s: no records match\n", gProgName);
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (pArchive != nil)
|
if (pArchive != NULL)
|
||||||
(void) NuClose(pArchive);
|
(void) NuClose(pArchive);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -150,9 +150,9 @@ NuError
|
|||||||
DoTest(NulibState* pState)
|
DoTest(NulibState* pState)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
NuArchive* pArchive = nil;
|
NuArchive* pArchive = NULL;
|
||||||
|
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
|
|
||||||
if (NState_GetModBinaryII(pState))
|
if (NState_GetModBinaryII(pState))
|
||||||
return BNYDoTest(pState);
|
return BNYDoTest(pState);
|
||||||
@ -163,7 +163,7 @@ DoTest(NulibState* pState)
|
|||||||
if (err != kNuErrNone)
|
if (err != kNuErrNone)
|
||||||
goto bail;
|
goto bail;
|
||||||
pArchive = NState_GetNuArchive(pState);
|
pArchive = NState_GetNuArchive(pState);
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
|
|
||||||
NState_SetMatchCount(pState, 0);
|
NState_SetMatchCount(pState, 0);
|
||||||
|
|
||||||
@ -175,7 +175,7 @@ DoTest(NulibState* pState)
|
|||||||
printf("%s: no records match\n", gProgName);
|
printf("%s: no records match\n", gProgName);
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (pArchive != nil)
|
if (pArchive != NULL)
|
||||||
(void) NuClose(pArchive);
|
(void) NuClose(pArchive);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -127,15 +127,15 @@ AddPreservationString(NulibState* pState,
|
|||||||
NuThreadID threadID;
|
NuThreadID threadID;
|
||||||
char* cp;
|
char* cp;
|
||||||
|
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
Assert(pPathProposal != nil);
|
Assert(pPathProposal != NULL);
|
||||||
Assert(pathBuf != nil);
|
Assert(pathBuf != NULL);
|
||||||
Assert(NState_GetModPreserveType(pState));
|
Assert(NState_GetModPreserveType(pState));
|
||||||
|
|
||||||
pRecord = pPathProposal->pRecord;
|
pRecord = pPathProposal->pRecord;
|
||||||
pThread = pPathProposal->pThread;
|
pThread = pPathProposal->pThread;
|
||||||
Assert(pRecord != nil);
|
Assert(pRecord != NULL);
|
||||||
Assert(pThread != nil);
|
Assert(pThread != NULL);
|
||||||
|
|
||||||
cp = extBuf;
|
cp = extBuf;
|
||||||
|
|
||||||
@ -179,26 +179,26 @@ AddPreservationString(NulibState* pState,
|
|||||||
* to be ".txt", and perhaps do something clever for some others.
|
* to be ".txt", and perhaps do something clever for some others.
|
||||||
*/
|
*/
|
||||||
if (pRecord->recFileType == 0x04 || threadID == kNuThreadIDDiskImage)
|
if (pRecord->recFileType == 0x04 || threadID == kNuThreadIDDiskImage)
|
||||||
pExt = nil;
|
pExt = NULL;
|
||||||
else
|
else
|
||||||
pExt = FindExtension(pState, pathBuf);
|
pExt = FindExtension(pState, pathBuf);
|
||||||
if (pExt != nil) {
|
if (pExt != NULL) {
|
||||||
pExt++; /* skip past the '.' */
|
pExt++; /* skip past the '.' */
|
||||||
|
|
||||||
if (strlen(pExt) >= kMaxExtLen) {
|
if (strlen(pExt) >= kMaxExtLen) {
|
||||||
/* too long, forget it */
|
/* too long, forget it */
|
||||||
pExt = nil;
|
pExt = NULL;
|
||||||
} else {
|
} else {
|
||||||
/* if strictly decimal-numeric, don't use it (.1, .2, etc) */
|
/* if strictly decimal-numeric, don't use it (.1, .2, etc) */
|
||||||
(void) strtoul(pExt, &end, 10);
|
(void) strtoul(pExt, &end, 10);
|
||||||
if (*end == '\0') {
|
if (*end == '\0') {
|
||||||
pExt = nil;
|
pExt = NULL;
|
||||||
} else {
|
} else {
|
||||||
/* if '#' appears in it, don't use it -- it'll confuse us */
|
/* if '#' appears in it, don't use it -- it'll confuse us */
|
||||||
const char* ccp = pExt;
|
const char* ccp = pExt;
|
||||||
while (*ccp != '\0') {
|
while (*ccp != '\0') {
|
||||||
if (*ccp == '#') {
|
if (*ccp == '#') {
|
||||||
pExt = nil;
|
pExt = NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ccp++;
|
ccp++;
|
||||||
@ -217,11 +217,11 @@ AddPreservationString(NulibState* pState,
|
|||||||
else if (pRecord->recFileType) {
|
else if (pRecord->recFileType) {
|
||||||
pExt = GetFileTypeString(pRecord->recFileType);
|
pExt = GetFileTypeString(pRecord->recFileType);
|
||||||
if (pExt[0] == '?' || pExt[0] == '$')
|
if (pExt[0] == '?' || pExt[0] == '$')
|
||||||
pExt = nil;
|
pExt = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pExt != nil) {
|
if (pExt != NULL) {
|
||||||
*cp++ = kFilenameExtDelim;
|
*cp++ = kFilenameExtDelim;
|
||||||
strcpy(cp, pExt);
|
strcpy(cp, pExt);
|
||||||
cp += strlen(pExt);
|
cp += strlen(pExt);
|
||||||
@ -259,9 +259,9 @@ NormalizePath(NulibState* pState, NuPathnameProposal* pPathProposal)
|
|||||||
char localFssep;
|
char localFssep;
|
||||||
int newBufLen;
|
int newBufLen;
|
||||||
|
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
Assert(pPathProposal != nil);
|
Assert(pPathProposal != NULL);
|
||||||
Assert(pPathProposal->pathname != nil);
|
Assert(pPathProposal->pathname != NULL);
|
||||||
|
|
||||||
localFssep = NState_GetSystemPathSeparator(pState);
|
localFssep = NState_GetSystemPathSeparator(pState);
|
||||||
|
|
||||||
@ -273,9 +273,9 @@ NormalizePath(NulibState* pState, NuPathnameProposal* pPathProposal)
|
|||||||
newBufLen = strlen(pPathProposal->pathname)*3 + kMaxPathGrowth +1;
|
newBufLen = strlen(pPathProposal->pathname)*3 + kMaxPathGrowth +1;
|
||||||
NState_SetTempPathnameLen(pState, newBufLen);
|
NState_SetTempPathnameLen(pState, newBufLen);
|
||||||
pathBuf = NState_GetTempPathnameBuf(pState);
|
pathBuf = NState_GetTempPathnameBuf(pState);
|
||||||
Assert(pathBuf != nil);
|
Assert(pathBuf != NULL);
|
||||||
if (pathBuf == nil)
|
if (pathBuf == NULL)
|
||||||
return nil;
|
return NULL;
|
||||||
|
|
||||||
startp = pPathProposal->pathname;
|
startp = pPathProposal->pathname;
|
||||||
dstp = pathBuf;
|
dstp = pathBuf;
|
||||||
@ -285,9 +285,9 @@ NormalizePath(NulibState* pState, NuPathnameProposal* pPathProposal)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* normalize all directory components and the filename component */
|
/* normalize all directory components and the filename component */
|
||||||
while (startp != nil) {
|
while (startp != NULL) {
|
||||||
endp = strchr(startp, pPathProposal->filenameSeparator);
|
endp = strchr(startp, pPathProposal->filenameSeparator);
|
||||||
if (endp != nil) {
|
if (endp != NULL) {
|
||||||
/* normalize directory component */
|
/* normalize directory component */
|
||||||
err = NormalizeDirectoryName(pState, startp, endp - startp,
|
err = NormalizeDirectoryName(pState, startp, endp - startp,
|
||||||
pPathProposal->filenameSeparator, &dstp,
|
pPathProposal->filenameSeparator, &dstp,
|
||||||
@ -316,7 +316,7 @@ NormalizePath(NulibState* pState, NuPathnameProposal* pPathProposal)
|
|||||||
strcat(pathBuf, kResourceStr);
|
strcat(pathBuf, kResourceStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
startp = nil; /* we're done */
|
startp = NULL; /* we're done */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -332,7 +332,7 @@ NormalizePath(NulibState* pState, NuPathnameProposal* pPathProposal)
|
|||||||
if (NState_GetModJunkPaths(pState)) {
|
if (NState_GetModJunkPaths(pState)) {
|
||||||
char* lastFssep;
|
char* lastFssep;
|
||||||
lastFssep = strrchr(pathBuf, localFssep);
|
lastFssep = strrchr(pathBuf, localFssep);
|
||||||
if (lastFssep != nil) {
|
if (lastFssep != NULL) {
|
||||||
Assert(*(lastFssep+1) != '\0'); /* should already have been caught*/
|
Assert(*(lastFssep+1) != '\0'); /* should already have been caught*/
|
||||||
memmove(pathBuf, lastFssep+1, strlen(lastFssep+1)+1);
|
memmove(pathBuf, lastFssep+1, strlen(lastFssep+1)+1);
|
||||||
}
|
}
|
||||||
@ -340,7 +340,7 @@ NormalizePath(NulibState* pState, NuPathnameProposal* pPathProposal)
|
|||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (err != kNuErrNone)
|
if (err != kNuErrNone)
|
||||||
return nil;
|
return NULL;
|
||||||
return pathBuf;
|
return pathBuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -415,13 +415,13 @@ InterpretExtension(NulibState* pState, const char* pathName, ulong* pFileType,
|
|||||||
{
|
{
|
||||||
const char* pExt;
|
const char* pExt;
|
||||||
|
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
Assert(pathName != nil);
|
Assert(pathName != NULL);
|
||||||
Assert(pFileType != nil);
|
Assert(pFileType != NULL);
|
||||||
Assert(pAuxType != nil);
|
Assert(pAuxType != NULL);
|
||||||
|
|
||||||
pExt = FindExtension(pState, pathName);
|
pExt = FindExtension(pState, pathName);
|
||||||
if (pExt != nil)
|
if (pExt != NULL)
|
||||||
LookupExtension(pState, pExt+1, pFileType, pAuxType);
|
LookupExtension(pState, pExt+1, pFileType, pAuxType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -445,14 +445,14 @@ ExtractPreservationString(NulibState* pState, char* pathname, ulong* pFileType,
|
|||||||
char* cp;
|
char* cp;
|
||||||
int digitCount;
|
int digitCount;
|
||||||
|
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
Assert(pathname != nil);
|
Assert(pathname != NULL);
|
||||||
Assert(pFileType != nil);
|
Assert(pFileType != NULL);
|
||||||
Assert(pAuxType != nil);
|
Assert(pAuxType != NULL);
|
||||||
Assert(pThreadID != nil);
|
Assert(pThreadID != NULL);
|
||||||
|
|
||||||
pPreserve = strrchr(pathname, kPreserveIndic);
|
pPreserve = strrchr(pathname, kPreserveIndic);
|
||||||
if (pPreserve == nil)
|
if (pPreserve == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* count up the #of hex digits */
|
/* count up the #of hex digits */
|
||||||
@ -583,20 +583,20 @@ DenormalizePath(NulibState* pState, char* pathBuf)
|
|||||||
* Find the filename component of a local pathname. Uses the fssep defined
|
* Find the filename component of a local pathname. Uses the fssep defined
|
||||||
* in pState.
|
* in pState.
|
||||||
*
|
*
|
||||||
* Always returns a pointer to a string; never returns nil.
|
* Always returns a pointer to a string; never returns NULL.
|
||||||
*/
|
*/
|
||||||
const char*
|
const char*
|
||||||
FilenameOnly(NulibState* pState, const char* pathname)
|
FilenameOnly(NulibState* pState, const char* pathname)
|
||||||
{
|
{
|
||||||
const char* retstr;
|
const char* retstr;
|
||||||
const char* pSlash;
|
const char* pSlash;
|
||||||
char* tmpStr = nil;
|
char* tmpStr = NULL;
|
||||||
|
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
Assert(pathname != nil);
|
Assert(pathname != NULL);
|
||||||
|
|
||||||
pSlash = strrchr(pathname, NState_GetSystemPathSeparator(pState));
|
pSlash = strrchr(pathname, NState_GetSystemPathSeparator(pState));
|
||||||
if (pSlash == nil) {
|
if (pSlash == NULL) {
|
||||||
retstr = pathname; /* whole thing is the filename */
|
retstr = pathname; /* whole thing is the filename */
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
@ -614,7 +614,7 @@ FilenameOnly(NulibState* pState, const char* pathname)
|
|||||||
tmpStr[strlen(pathname)-1] = '\0';
|
tmpStr[strlen(pathname)-1] = '\0';
|
||||||
pSlash = strrchr(tmpStr, NState_GetSystemPathSeparator(pState));
|
pSlash = strrchr(tmpStr, NState_GetSystemPathSeparator(pState));
|
||||||
|
|
||||||
if (pSlash == nil) {
|
if (pSlash == NULL) {
|
||||||
retstr = pathname; /* just a filename with a '/' after it */
|
retstr = pathname; /* just a filename with a '/' after it */
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
@ -642,7 +642,7 @@ bail:
|
|||||||
* An extension is the stuff following the last '.' in the filename. If
|
* An extension is the stuff following the last '.' in the filename. If
|
||||||
* there is nothing following the last '.', then there is no extension.
|
* there is nothing following the last '.', then there is no extension.
|
||||||
*
|
*
|
||||||
* Returns a pointer to the '.' preceding the extension, or nil if no
|
* Returns a pointer to the '.' preceding the extension, or NULL if no
|
||||||
* extension was found.
|
* extension was found.
|
||||||
*/
|
*/
|
||||||
const char*
|
const char*
|
||||||
@ -656,13 +656,13 @@ FindExtension(NulibState* pState, const char* pathname)
|
|||||||
* about "/foo.bar/file".
|
* about "/foo.bar/file".
|
||||||
*/
|
*/
|
||||||
pFilename = FilenameOnly(pState, pathname);
|
pFilename = FilenameOnly(pState, pathname);
|
||||||
Assert(pFilename != nil);
|
Assert(pFilename != NULL);
|
||||||
pExt = strrchr(pFilename, kFilenameExtDelim);
|
pExt = strrchr(pFilename, kFilenameExtDelim);
|
||||||
|
|
||||||
/* also check for "/blah/foo.", which doesn't count */
|
/* also check for "/blah/foo.", which doesn't count */
|
||||||
if (pExt != nil && *(pExt+1) != '\0')
|
if (pExt != NULL && *(pExt+1) != '\0')
|
||||||
return pExt;
|
return pExt;
|
||||||
|
|
||||||
return nil;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,15 +107,15 @@ ShowContentsShort(NuArchive* pArchive, void* vpRecord)
|
|||||||
const NuRecord* pRecord = (NuRecord*) vpRecord;
|
const NuRecord* pRecord = (NuRecord*) vpRecord;
|
||||||
NulibState* pState;
|
NulibState* pState;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
(void) NuGetExtraData(pArchive, (void**) &pState);
|
(void) NuGetExtraData(pArchive, (void**) &pState);
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
|
|
||||||
if (!IsSpecified(pState, pRecord))
|
if (!IsSpecified(pState, pRecord))
|
||||||
goto bail;
|
goto bail;
|
||||||
|
|
||||||
printf("%s\n",
|
printf("%s\n",
|
||||||
pRecord->filename == nil ? "<unknown>":(const char*)pRecord->filename);
|
pRecord->filename == NULL ? "<unknown>":(const char*)pRecord->filename);
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
return kNuOK;
|
return kNuOK;
|
||||||
@ -156,7 +156,7 @@ AnalyzeRecord(const NuRecord* pRecord, enum RecordKind* pRecordKind,
|
|||||||
|
|
||||||
for (idx = 0; idx < pRecord->recTotalThreads; idx++) {
|
for (idx = 0; idx < pRecord->recTotalThreads; idx++) {
|
||||||
pThread = NuGetThread(pRecord, idx);
|
pThread = NuGetThread(pRecord, idx);
|
||||||
Assert(pThread != nil);
|
Assert(pThread != NULL);
|
||||||
|
|
||||||
if (pThread->thThreadClass == kNuThreadClassData) {
|
if (pThread->thThreadClass == kNuThreadClassData) {
|
||||||
/* replace what's there if this might be more interesting */
|
/* replace what's there if this might be more interesting */
|
||||||
@ -201,9 +201,9 @@ ShowContentsVerbose(NuArchive* pArchive, void* vpRecord)
|
|||||||
char tmpbuf[16];
|
char tmpbuf[16];
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
(void) NuGetExtraData(pArchive, (void**) &pState);
|
(void) NuGetExtraData(pArchive, (void**) &pState);
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
|
|
||||||
if (!IsSpecified(pState, pRecord))
|
if (!IsSpecified(pState, pRecord))
|
||||||
goto bail;
|
goto bail;
|
||||||
@ -270,7 +270,7 @@ ShowContentsVerbose(NuArchive* pArchive, void* vpRecord)
|
|||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
printf("(ERROR on '%s')\n", pRecord->filename == nil ?
|
printf("(ERROR on '%s')\n", pRecord->filename == NULL ?
|
||||||
"<unknown>" : (const char*)pRecord->filename);
|
"<unknown>" : (const char*)pRecord->filename);
|
||||||
}
|
}
|
||||||
return kNuOK;
|
return kNuOK;
|
||||||
@ -283,9 +283,9 @@ NuError
|
|||||||
DoListShort(NulibState* pState)
|
DoListShort(NulibState* pState)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
NuArchive* pArchive = nil;
|
NuArchive* pArchive = NULL;
|
||||||
|
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
|
|
||||||
if (NState_GetModBinaryII(pState))
|
if (NState_GetModBinaryII(pState))
|
||||||
return BNYDoListShort(pState);
|
return BNYDoListShort(pState);
|
||||||
@ -296,13 +296,13 @@ DoListShort(NulibState* pState)
|
|||||||
if (err != kNuErrNone)
|
if (err != kNuErrNone)
|
||||||
goto bail;
|
goto bail;
|
||||||
pArchive = NState_GetNuArchive(pState);
|
pArchive = NState_GetNuArchive(pState);
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
|
|
||||||
err = NuContents(pArchive, ShowContentsShort);
|
err = NuContents(pArchive, ShowContentsShort);
|
||||||
/* fall through with err */
|
/* fall through with err */
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (pArchive != nil)
|
if (pArchive != NULL)
|
||||||
(void) NuClose(pArchive);
|
(void) NuClose(pArchive);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -315,14 +315,14 @@ NuError
|
|||||||
DoListVerbose(NulibState* pState)
|
DoListVerbose(NulibState* pState)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
NuArchive* pArchive = nil;
|
NuArchive* pArchive = NULL;
|
||||||
const NuMasterHeader* pHeader;
|
const NuMasterHeader* pHeader;
|
||||||
char date1[kDateOutputLen];
|
char date1[kDateOutputLen];
|
||||||
char date2[kDateOutputLen];
|
char date2[kDateOutputLen];
|
||||||
long totalLen, totalCompLen;
|
long totalLen, totalCompLen;
|
||||||
const char* cp;
|
const char* cp;
|
||||||
|
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
|
|
||||||
if (NState_GetModBinaryII(pState))
|
if (NState_GetModBinaryII(pState))
|
||||||
return BNYDoListVerbose(pState);
|
return BNYDoListVerbose(pState);
|
||||||
@ -333,7 +333,7 @@ DoListVerbose(NulibState* pState)
|
|||||||
if (err != kNuErrNone)
|
if (err != kNuErrNone)
|
||||||
goto bail;
|
goto bail;
|
||||||
pArchive = NState_GetNuArchive(pState);
|
pArchive = NState_GetNuArchive(pState);
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Try to get just the filename.
|
* Try to get just the filename.
|
||||||
@ -384,7 +384,7 @@ DoListVerbose(NulibState* pState)
|
|||||||
/*(void) NuDebugDumpArchive(pArchive);*/
|
/*(void) NuDebugDumpArchive(pArchive);*/
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (pArchive != nil)
|
if (pArchive != NULL)
|
||||||
(void) NuClose(pArchive);
|
(void) NuClose(pArchive);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -408,9 +408,9 @@ NuError
|
|||||||
DoListDebug(NulibState* pState)
|
DoListDebug(NulibState* pState)
|
||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
NuArchive* pArchive = nil;
|
NuArchive* pArchive = NULL;
|
||||||
|
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
|
|
||||||
if (NState_GetModBinaryII(pState))
|
if (NState_GetModBinaryII(pState))
|
||||||
return BNYDoListDebug(pState);
|
return BNYDoListDebug(pState);
|
||||||
@ -421,7 +421,7 @@ DoListDebug(NulibState* pState)
|
|||||||
if (err != kNuErrNone)
|
if (err != kNuErrNone)
|
||||||
goto bail;
|
goto bail;
|
||||||
pArchive = NState_GetNuArchive(pState);
|
pArchive = NState_GetNuArchive(pState);
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
|
|
||||||
/* have to do something to force the library to scan the archive */
|
/* have to do something to force the library to scan the archive */
|
||||||
err = NuContents(pArchive, NullCallback);
|
err = NuContents(pArchive, NullCallback);
|
||||||
@ -434,7 +434,7 @@ DoListDebug(NulibState* pState)
|
|||||||
/* fall through with err */
|
/* fall through with err */
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (pArchive != nil)
|
if (pArchive != NULL)
|
||||||
(void) NuClose(pArchive);
|
(void) NuClose(pArchive);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ static const ValidCombo gValidCombos[] = {
|
|||||||
/*
|
/*
|
||||||
* Find an entry in the gValidCombos table matching the specified command.
|
* Find an entry in the gValidCombos table matching the specified command.
|
||||||
*
|
*
|
||||||
* Returns nil if not found.
|
* Returns NULL if not found.
|
||||||
*/
|
*/
|
||||||
static const ValidCombo*
|
static const ValidCombo*
|
||||||
FindValidComboEntry(Command cmd)
|
FindValidComboEntry(Command cmd)
|
||||||
@ -54,7 +54,7 @@ FindValidComboEntry(Command cmd)
|
|||||||
return &gValidCombos[i];
|
return &gValidCombos[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -67,8 +67,8 @@ IsValidModifier(Command cmd, char modifier)
|
|||||||
const ValidCombo* pvc;
|
const ValidCombo* pvc;
|
||||||
|
|
||||||
pvc = FindValidComboEntry(cmd);
|
pvc = FindValidComboEntry(cmd);
|
||||||
if (pvc != nil) {
|
if (pvc != NULL) {
|
||||||
if (strchr(pvc->modifiers, modifier) == nil)
|
if (strchr(pvc->modifiers, modifier) == NULL)
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
return true;
|
return true;
|
||||||
@ -85,7 +85,7 @@ IsValidOnPipe(Command cmd)
|
|||||||
const ValidCombo* pvc;
|
const ValidCombo* pvc;
|
||||||
|
|
||||||
pvc = FindValidComboEntry(cmd);
|
pvc = FindValidComboEntry(cmd);
|
||||||
if (pvc != nil) {
|
if (pvc != NULL) {
|
||||||
return pvc->okayForPipe;
|
return pvc->okayForPipe;
|
||||||
} else
|
} else
|
||||||
return false;
|
return false;
|
||||||
@ -100,7 +100,7 @@ IsFilespecRequired(Command cmd)
|
|||||||
const ValidCombo* pvc;
|
const ValidCombo* pvc;
|
||||||
|
|
||||||
pvc = FindValidComboEntry(cmd);
|
pvc = FindValidComboEntry(cmd);
|
||||||
if (pvc != nil) {
|
if (pvc != NULL) {
|
||||||
return pvc->filespecRequired;
|
return pvc->filespecRequired;
|
||||||
} else {
|
} else {
|
||||||
/* command not found? warn about it here... */
|
/* command not found? warn about it here... */
|
||||||
@ -124,7 +124,7 @@ GetProgName(const NulibState* pState, const char* argv0)
|
|||||||
sep = NState_GetSystemPathSeparator(pState);
|
sep = NState_GetSystemPathSeparator(pState);
|
||||||
|
|
||||||
result = strrchr(argv0, sep);
|
result = strrchr(argv0, sep);
|
||||||
if (result == nil)
|
if (result == NULL)
|
||||||
result = argv0;
|
result = argv0;
|
||||||
else
|
else
|
||||||
result++; /* advance past the separator */
|
result++; /* advance past the separator */
|
||||||
@ -273,7 +273,7 @@ DoHelp(const NulibState* pState)
|
|||||||
int j;
|
int j;
|
||||||
|
|
||||||
pvc = FindValidComboEntry(help[i].cmd);
|
pvc = FindValidComboEntry(help[i].cmd);
|
||||||
if (pvc == nil) {
|
if (pvc == NULL) {
|
||||||
fprintf(stderr, "%s: internal error: couldn't find vc for %d\n",
|
fprintf(stderr, "%s: internal error: couldn't find vc for %d\n",
|
||||||
gProgName, help[i].cmd);
|
gProgName, help[i].cmd);
|
||||||
continue;
|
continue;
|
||||||
@ -328,7 +328,7 @@ ProcessOptions(NulibState* pState, int argc, char* const* argv)
|
|||||||
if (argc == 2 && (tolower(argv[1][0]) == 'h' ||
|
if (argc == 2 && (tolower(argv[1][0]) == 'h' ||
|
||||||
(argv[1][0] == '-' && tolower(argv[1][1] == 'h')) ) )
|
(argv[1][0] == '-' && tolower(argv[1][1] == 'h')) ) )
|
||||||
{
|
{
|
||||||
DoHelp(nil);
|
DoHelp(NULL);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -486,7 +486,7 @@ ProcessOptions(NulibState* pState, int argc, char* const* argv)
|
|||||||
gProgName);
|
gProgName);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
NState_SetFilespecPointer(pState, nil);
|
NState_SetFilespecPointer(pState, NULL);
|
||||||
NState_SetFilespecCount(pState, 0);
|
NState_SetFilespecCount(pState, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -561,11 +561,11 @@ DoWork(NulibState* pState)
|
|||||||
int
|
int
|
||||||
main(int argc, char** argv)
|
main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
NulibState* pState = nil;
|
NulibState* pState = NULL;
|
||||||
long majorVersion, minorVersion, bugVersion;
|
long majorVersion, minorVersion, bugVersion;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
(void) NuGetVersion(&majorVersion, &minorVersion, &bugVersion, nil, nil);
|
(void) NuGetVersion(&majorVersion, &minorVersion, &bugVersion, NULL, NULL);
|
||||||
if (majorVersion != kNuVersionMajor || minorVersion < kNuVersionMinor) {
|
if (majorVersion != kNuVersionMajor || minorVersion < kNuVersionMinor) {
|
||||||
fprintf(stderr, "ERROR: wrong version of NufxLib --"
|
fprintf(stderr, "ERROR: wrong version of NufxLib --"
|
||||||
" wanted %d.%d.x, got %ld.%ld.%ld.\n",
|
" wanted %d.%d.x, got %ld.%ld.%ld.\n",
|
||||||
|
@ -42,11 +42,7 @@ int Nu_strncasecmp(const char *s1, const char *s2, size_t n);
|
|||||||
* Misc types.
|
* Misc types.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
typedef unsigned char Boolean;
|
||||||
|
|
||||||
#define nil NULL /* I can't seem to stop typing 'nil' now */
|
|
||||||
|
|
||||||
typedef uchar Boolean;
|
|
||||||
#define false (0)
|
#define false (0)
|
||||||
#define true (!false)
|
#define true (!false)
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
* Similar to perror(), but takes the error as an argument, and knows
|
* Similar to perror(), but takes the error as an argument, and knows
|
||||||
* about NufxLib errors as well as system errors.
|
* about NufxLib errors as well as system errors.
|
||||||
*
|
*
|
||||||
* If "format" is nil, just the error message itself is printed.
|
* If "format" is NULL, just the error message itself is printed.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
ReportError(NuError err, const char* format, ...)
|
ReportError(NuError err, const char* format, ...)
|
||||||
@ -22,12 +22,12 @@ ReportError(NuError err, const char* format, ...)
|
|||||||
const char* msg;
|
const char* msg;
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
Assert(format != nil);
|
Assert(format != NULL);
|
||||||
|
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
|
|
||||||
/* print the message, if any */
|
/* print the message, if any */
|
||||||
if (format != nil) {
|
if (format != NULL) {
|
||||||
fprintf(stderr, "%s: ERROR: ", gProgName);
|
fprintf(stderr, "%s: ERROR: ", gProgName);
|
||||||
vfprintf(stderr, format, args);
|
vfprintf(stderr, format, args);
|
||||||
}
|
}
|
||||||
@ -36,16 +36,16 @@ ReportError(NuError err, const char* format, ...)
|
|||||||
if (err == kNuErrNone)
|
if (err == kNuErrNone)
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
else {
|
else {
|
||||||
if (format != nil)
|
if (format != NULL)
|
||||||
fprintf(stderr, ": ");
|
fprintf(stderr, ": ");
|
||||||
|
|
||||||
msg = nil;
|
msg = NULL;
|
||||||
if (err >= 0)
|
if (err >= 0)
|
||||||
msg = strerror(err);
|
msg = strerror(err);
|
||||||
if (msg == nil)
|
if (msg == NULL)
|
||||||
msg = NuStrError(err);
|
msg = NuStrError(err);
|
||||||
|
|
||||||
if (msg == nil)
|
if (msg == NULL)
|
||||||
fprintf(stderr, "(unknown err=%d)\n", err);
|
fprintf(stderr, "(unknown err=%d)\n", err);
|
||||||
else
|
else
|
||||||
fprintf(stderr, "%s\n", msg);
|
fprintf(stderr, "%s\n", msg);
|
||||||
@ -69,7 +69,7 @@ Malloc(size_t size)
|
|||||||
|
|
||||||
Assert(size > 0);
|
Assert(size > 0);
|
||||||
_result = malloc(size);
|
_result = malloc(size);
|
||||||
if (_result == nil) {
|
if (_result == NULL) {
|
||||||
ReportError(kNuErrMalloc, "malloc(%u) failed", (uint) size);
|
ReportError(kNuErrMalloc, "malloc(%u) failed", (uint) size);
|
||||||
DebugAbort(); /* leave a core dump if we're built for it */
|
DebugAbort(); /* leave a core dump if we're built for it */
|
||||||
}
|
}
|
||||||
@ -90,10 +90,10 @@ Realloc(void* ptr, size_t size)
|
|||||||
{
|
{
|
||||||
void* _result;
|
void* _result;
|
||||||
|
|
||||||
Assert(ptr != nil); /* disallow this usage */
|
Assert(ptr != NULL); /* disallow this usage */
|
||||||
Assert(size > 0); /* disallow this usage */
|
Assert(size > 0); /* disallow this usage */
|
||||||
_result = realloc(ptr, size);
|
_result = realloc(ptr, size);
|
||||||
if (_result == nil) {
|
if (_result == NULL) {
|
||||||
ReportError(kNuErrMalloc, "realloc(%u) failed", (uint) size);
|
ReportError(kNuErrMalloc, "realloc(%u) failed", (uint) size);
|
||||||
DebugAbort(); /* leave a core dump if we're built for it */
|
DebugAbort(); /* leave a core dump if we're built for it */
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ Realloc(void* ptr, size_t size)
|
|||||||
void
|
void
|
||||||
Free(void* ptr)
|
Free(void* ptr)
|
||||||
{
|
{
|
||||||
if (ptr != nil)
|
if (ptr != NULL)
|
||||||
free(ptr);
|
free(ptr);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -90,7 +90,7 @@ void ReportError(NuError err, const char* format, ...)
|
|||||||
# define Malloc(size) malloc(size)
|
# define Malloc(size) malloc(size)
|
||||||
# define Calloc(size) calloc(1, size)
|
# define Calloc(size) calloc(1, size)
|
||||||
# define Realloc(ptr, size) realloc(ptr, size)
|
# define Realloc(ptr, size) realloc(ptr, size)
|
||||||
# define Free(ptr) (ptr != nil ? free(ptr) : (void)0)
|
# define Free(ptr) (ptr != NULL ? free(ptr) : (void)0)
|
||||||
#else
|
#else
|
||||||
void* Malloc(size_t size);
|
void* Malloc(size_t size);
|
||||||
void* Calloc(size_t size);
|
void* Calloc(size_t size);
|
||||||
|
@ -18,10 +18,10 @@ static const char* gProgramVersion = "2.2.2";
|
|||||||
NuError
|
NuError
|
||||||
NState_Init(NulibState** ppState)
|
NState_Init(NulibState** ppState)
|
||||||
{
|
{
|
||||||
Assert(ppState != nil);
|
Assert(ppState != NULL);
|
||||||
|
|
||||||
*ppState = Calloc(sizeof(**ppState));
|
*ppState = Calloc(sizeof(**ppState));
|
||||||
if (*ppState == nil)
|
if (*ppState == NULL)
|
||||||
return kNuErrMalloc;
|
return kNuErrMalloc;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -77,14 +77,14 @@ NState_ExtraInit(NulibState* pState)
|
|||||||
void
|
void
|
||||||
NState_Free(NulibState* pState)
|
NState_Free(NulibState* pState)
|
||||||
{
|
{
|
||||||
if (pState == nil)
|
if (pState == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Free(pState->renameToStr); /* ?? */
|
Free(pState->renameToStr); /* ?? */
|
||||||
Free(pState->tempPathnameBuf);
|
Free(pState->tempPathnameBuf);
|
||||||
if (pState->pPipeSink != nil)
|
if (pState->pPipeSink != NULL)
|
||||||
NuFreeDataSink(pState->pPipeSink);
|
NuFreeDataSink(pState->pPipeSink);
|
||||||
if (pState->pCommentSink != nil)
|
if (pState->pCommentSink != NULL)
|
||||||
NuFreeDataSink(pState->pCommentSink);
|
NuFreeDataSink(pState->pCommentSink);
|
||||||
Free(pState);
|
Free(pState);
|
||||||
}
|
}
|
||||||
@ -108,7 +108,7 @@ NState_DebugDump(const NulibState* pState)
|
|||||||
"help",
|
"help",
|
||||||
};
|
};
|
||||||
|
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
|
|
||||||
printf("NState:\n");
|
printf("NState:\n");
|
||||||
printf(" programVersion: '%s'\n", pState->programVersion);
|
printf(" programVersion: '%s'\n", pState->programVersion);
|
||||||
@ -301,14 +301,14 @@ NState_SetTempPathnameLen(NulibState* pState, long len)
|
|||||||
len++; /* add one for the '\0' */
|
len++; /* add one for the '\0' */
|
||||||
|
|
||||||
if (pState->tempPathnameAlloc < len) {
|
if (pState->tempPathnameAlloc < len) {
|
||||||
if (pState->tempPathnameBuf == nil)
|
if (pState->tempPathnameBuf == NULL)
|
||||||
newBuf = Malloc(len);
|
newBuf = Malloc(len);
|
||||||
else
|
else
|
||||||
newBuf = Realloc(pState->tempPathnameBuf, len);
|
newBuf = Realloc(pState->tempPathnameBuf, len);
|
||||||
Assert(newBuf != nil);
|
Assert(newBuf != NULL);
|
||||||
if (newBuf == nil) {
|
if (newBuf == NULL) {
|
||||||
Free(pState->tempPathnameBuf);
|
Free(pState->tempPathnameBuf);
|
||||||
pState->tempPathnameBuf = nil;
|
pState->tempPathnameBuf = NULL;
|
||||||
pState->tempPathnameAlloc = 0;
|
pState->tempPathnameAlloc = 0;
|
||||||
ReportError(kNuErrMalloc, "buf realloc failed (%ld)", len);
|
ReportError(kNuErrMalloc, "buf realloc failed (%ld)", len);
|
||||||
return;
|
return;
|
||||||
|
@ -121,10 +121,10 @@ UNIXNormalizeFileName(NulibState* pState, const char* srcp, long srcLen,
|
|||||||
* The list comes from the Linux kernel's fs/msdos/namei.c.
|
* The list comes from the Linux kernel's fs/msdos/namei.c.
|
||||||
*/
|
*/
|
||||||
static const char* fatReservedNames3[] = {
|
static const char* fatReservedNames3[] = {
|
||||||
"CON", "PRN", "NUL", "AUX", nil
|
"CON", "PRN", "NUL", "AUX", NULL
|
||||||
};
|
};
|
||||||
static const char* fatReservedNames4[] = {
|
static const char* fatReservedNames4[] = {
|
||||||
"LPT1", "LPT2", "LPT3", "LPT4", "COM1", "COM2", "COM3", "COM4", nil
|
"LPT1", "LPT2", "LPT3", "LPT4", "COM1", "COM2", "COM3", "COM4", NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -142,7 +142,7 @@ Win32NormalizeFileName(NulibState* pState, const char* srcp, long srcLen,
|
|||||||
if (srcLen >= 3) {
|
if (srcLen >= 3) {
|
||||||
const char** ppcch;
|
const char** ppcch;
|
||||||
|
|
||||||
for (ppcch = fatReservedNames3; *ppcch != nil; ppcch++) {
|
for (ppcch = fatReservedNames3; *ppcch != NULL; ppcch++) {
|
||||||
if (strncasecmp(srcp, *ppcch, 3) == 0 &&
|
if (strncasecmp(srcp, *ppcch, 3) == 0 &&
|
||||||
srcp[3] == '.' || srcLen == 3)
|
srcp[3] == '.' || srcLen == 3)
|
||||||
{
|
{
|
||||||
@ -160,7 +160,7 @@ Win32NormalizeFileName(NulibState* pState, const char* srcp, long srcLen,
|
|||||||
if (srcLen >= 4) {
|
if (srcLen >= 4) {
|
||||||
const char** ppcch;
|
const char** ppcch;
|
||||||
|
|
||||||
for (ppcch = fatReservedNames4; *ppcch != nil; ppcch++) {
|
for (ppcch = fatReservedNames4; *ppcch != NULL; ppcch++) {
|
||||||
if (strncasecmp(srcp, *ppcch, 4) == 0 &&
|
if (strncasecmp(srcp, *ppcch, 4) == 0 &&
|
||||||
srcp[4] == '.' || srcLen == 4)
|
srcp[4] == '.' || srcLen == 4)
|
||||||
{
|
{
|
||||||
@ -185,7 +185,7 @@ Win32NormalizeFileName(NulibState* pState, const char* srcp, long srcLen,
|
|||||||
if (NState_GetModPreserveType(pState))
|
if (NState_GetModPreserveType(pState))
|
||||||
*dstp++ = *srcp;
|
*dstp++ = *srcp;
|
||||||
*dstp++ = *srcp++;
|
*dstp++ = *srcp++;
|
||||||
} else if (strchr(kInvalid, *srcp) != nil) {
|
} else if (strchr(kInvalid, *srcp) != NULL) {
|
||||||
/* change invalid char to "%2f" or '_' */
|
/* change invalid char to "%2f" or '_' */
|
||||||
if (NState_GetModPreserveType(pState)) {
|
if (NState_GetModPreserveType(pState)) {
|
||||||
*dstp++ = kForeignIndic;
|
*dstp++ = kForeignIndic;
|
||||||
@ -225,11 +225,11 @@ NormalizeFileName(NulibState* pState, const char* srcp, long srcLen,
|
|||||||
{
|
{
|
||||||
NuError err;
|
NuError err;
|
||||||
|
|
||||||
Assert(srcp != nil);
|
Assert(srcp != NULL);
|
||||||
Assert(srcLen > 0);
|
Assert(srcLen > 0);
|
||||||
Assert(dstLen > srcLen);
|
Assert(dstLen > srcLen);
|
||||||
Assert(pDstp != nil);
|
Assert(pDstp != NULL);
|
||||||
Assert(*pDstp != nil);
|
Assert(*pDstp != NULL);
|
||||||
Assert(fssep > ' ' && fssep < 0x7f);
|
Assert(fssep > ' ' && fssep < 0x7f);
|
||||||
|
|
||||||
#if defined(UNIX_LIKE)
|
#if defined(UNIX_LIKE)
|
||||||
@ -271,13 +271,13 @@ MakeTempArchiveName(NulibState* pState)
|
|||||||
const char* archivePathname;
|
const char* archivePathname;
|
||||||
char fssep;
|
char fssep;
|
||||||
const char* nameStart;
|
const char* nameStart;
|
||||||
char* newName = nil;
|
char* newName = NULL;
|
||||||
char* namePtr;
|
char* namePtr;
|
||||||
char* resultName = nil;
|
char* resultName = NULL;
|
||||||
long len;
|
long len;
|
||||||
|
|
||||||
archivePathname = NState_GetArchiveFilename(pState);
|
archivePathname = NState_GetArchiveFilename(pState);
|
||||||
Assert(archivePathname != nil);
|
Assert(archivePathname != NULL);
|
||||||
fssep = NState_GetSystemPathSeparator(pState);
|
fssep = NState_GetSystemPathSeparator(pState);
|
||||||
Assert(fssep != 0);
|
Assert(fssep != 0);
|
||||||
|
|
||||||
@ -292,7 +292,7 @@ MakeTempArchiveName(NulibState* pState)
|
|||||||
|
|
||||||
/* figure out where the filename ends */
|
/* figure out where the filename ends */
|
||||||
nameStart = strrchr(archivePathname, fssep);
|
nameStart = strrchr(archivePathname, fssep);
|
||||||
if (nameStart == nil) {
|
if (nameStart == NULL) {
|
||||||
/* nothing but a filename */
|
/* nothing but a filename */
|
||||||
newName = Malloc(kTempFileNameLen +1);
|
newName = Malloc(kTempFileNameLen +1);
|
||||||
namePtr = newName;
|
namePtr = newName;
|
||||||
@ -302,7 +302,7 @@ MakeTempArchiveName(NulibState* pState)
|
|||||||
strcpy(newName, archivePathname);
|
strcpy(newName, archivePathname);
|
||||||
namePtr = newName + (nameStart - archivePathname);
|
namePtr = newName + (nameStart - archivePathname);
|
||||||
}
|
}
|
||||||
if (newName == nil)
|
if (newName == NULL)
|
||||||
goto bail;
|
goto bail;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -313,7 +313,7 @@ MakeTempArchiveName(NulibState* pState)
|
|||||||
resultName = newName;
|
resultName = newName;
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (resultName == nil)
|
if (resultName == NULL)
|
||||||
Free(newName);
|
Free(newName);
|
||||||
return resultName;
|
return resultName;
|
||||||
}
|
}
|
||||||
@ -360,10 +360,10 @@ CheckFileStatus(const char* pathname, struct stat* psb, Boolean* pExists,
|
|||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
int cc;
|
int cc;
|
||||||
|
|
||||||
Assert(pathname != nil);
|
Assert(pathname != NULL);
|
||||||
Assert(pExists != nil);
|
Assert(pExists != NULL);
|
||||||
Assert(pIsReadable != nil);
|
Assert(pIsReadable != NULL);
|
||||||
Assert(pIsDir != nil);
|
Assert(pIsDir != NULL);
|
||||||
|
|
||||||
*pExists = true;
|
*pExists = true;
|
||||||
*pIsReadable = true;
|
*pIsReadable = true;
|
||||||
@ -403,8 +403,8 @@ UNIXTimeToDateTime(const time_t* pWhen, NuDateTime *pDateTime)
|
|||||||
{
|
{
|
||||||
struct tm* ptm;
|
struct tm* ptm;
|
||||||
|
|
||||||
Assert(pWhen != nil);
|
Assert(pWhen != NULL);
|
||||||
Assert(pDateTime != nil);
|
Assert(pDateTime != NULL);
|
||||||
|
|
||||||
ptm = localtime(pWhen);
|
ptm = localtime(pWhen);
|
||||||
pDateTime->second = ptm->tm_sec;
|
pDateTime->second = ptm->tm_sec;
|
||||||
@ -450,14 +450,14 @@ GetFileDetails(NulibState* pState, const char* pathname, struct stat* psb,
|
|||||||
char slashDotDotSlash[5] = "_.._";
|
char slashDotDotSlash[5] = "_.._";
|
||||||
time_t now;
|
time_t now;
|
||||||
|
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
Assert(pathname != nil);
|
Assert(pathname != NULL);
|
||||||
Assert(pDetails != nil);
|
Assert(pDetails != NULL);
|
||||||
|
|
||||||
/* set up the pathname buffer; note pDetails->storageName is const */
|
/* set up the pathname buffer; note pDetails->storageName is const */
|
||||||
NState_SetTempPathnameLen(pState, strlen(pathname) +1);
|
NState_SetTempPathnameLen(pState, strlen(pathname) +1);
|
||||||
livePathStr = NState_GetTempPathnameBuf(pState);
|
livePathStr = NState_GetTempPathnameBuf(pState);
|
||||||
Assert(livePathStr != nil);
|
Assert(livePathStr != NULL);
|
||||||
strcpy(livePathStr, pathname);
|
strcpy(livePathStr, pathname);
|
||||||
|
|
||||||
/* under Win32, both '/' and '\' work... we want to settle on one */
|
/* under Win32, both '/' and '\' work... we want to settle on one */
|
||||||
@ -472,7 +472,7 @@ GetFileDetails(NulibState* pState, const char* pathname, struct stat* psb,
|
|||||||
memset(pDetails, 0, sizeof(*pDetails));
|
memset(pDetails, 0, sizeof(*pDetails));
|
||||||
pDetails->threadID = kNuThreadIDDataFork;
|
pDetails->threadID = kNuThreadIDDataFork;
|
||||||
pDetails->storageName = livePathStr; /* point at temp buffer */
|
pDetails->storageName = livePathStr; /* point at temp buffer */
|
||||||
pDetails->origName = nil;
|
pDetails->origName = NULL;
|
||||||
pDetails->fileSysID = kNuFileSysUnknown;
|
pDetails->fileSysID = kNuFileSysUnknown;
|
||||||
pDetails->fileSysInfo = kStorageFssep;
|
pDetails->fileSysInfo = kStorageFssep;
|
||||||
pDetails->fileType = 0;
|
pDetails->fileType = 0;
|
||||||
@ -497,7 +497,7 @@ GetFileDetails(NulibState* pState, const char* pathname, struct stat* psb,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
now = time(nil);
|
now = time(NULL);
|
||||||
UNIXTimeToDateTime(&now, &pDetails->archiveWhen);
|
UNIXTimeToDateTime(&now, &pDetails->archiveWhen);
|
||||||
UNIXTimeToDateTime(&psb->st_mtime, &pDetails->modWhen);
|
UNIXTimeToDateTime(&psb->st_mtime, &pDetails->modWhen);
|
||||||
UNIXTimeToDateTime(&psb->st_mtime, &pDetails->createWhen);
|
UNIXTimeToDateTime(&psb->st_mtime, &pDetails->createWhen);
|
||||||
@ -576,7 +576,7 @@ GetFileDetails(NulibState* pState, const char* pathname, struct stat* psb,
|
|||||||
slashDotDotSlash[0] = NState_GetSystemPathSeparator(pState);
|
slashDotDotSlash[0] = NState_GetSystemPathSeparator(pState);
|
||||||
slashDotDotSlash[3] = NState_GetSystemPathSeparator(pState);
|
slashDotDotSlash[3] = NState_GetSystemPathSeparator(pState);
|
||||||
if ((livePathStr[0] == '.' && livePathStr[1] == '.') ||
|
if ((livePathStr[0] == '.' && livePathStr[1] == '.') ||
|
||||||
(strstr(livePathStr, slashDotDotSlash) != nil))
|
(strstr(livePathStr, slashDotDotSlash) != NULL))
|
||||||
{
|
{
|
||||||
DBUG(("Found dot dot in '%s', keeping only filename\n", livePathStr));
|
DBUG(("Found dot dot in '%s', keeping only filename\n", livePathStr));
|
||||||
doJunk = true;
|
doJunk = true;
|
||||||
@ -595,7 +595,7 @@ GetFileDetails(NulibState* pState, const char* pathname, struct stat* psb,
|
|||||||
if (NState_GetModJunkPaths(pState) || doJunk) {
|
if (NState_GetModJunkPaths(pState) || doJunk) {
|
||||||
char* lastFssep;
|
char* lastFssep;
|
||||||
lastFssep = strrchr(livePathStr, NState_GetSystemPathSeparator(pState));
|
lastFssep = strrchr(livePathStr, NState_GetSystemPathSeparator(pState));
|
||||||
if (lastFssep != nil) {
|
if (lastFssep != NULL) {
|
||||||
Assert(*(lastFssep+1) != '\0'); /* should already have been caught*/
|
Assert(*(lastFssep+1) != '\0'); /* should already have been caught*/
|
||||||
memmove(livePathStr, lastFssep+1, strlen(lastFssep+1)+1);
|
memmove(livePathStr, lastFssep+1, strlen(lastFssep+1)+1);
|
||||||
}
|
}
|
||||||
@ -665,7 +665,7 @@ DoAddFile(NulibState* pState, NuArchive* pArchive, const char* pathname,
|
|||||||
DBUG(("Preparing comment for recordIdx=%ld\n", recordIdx));
|
DBUG(("Preparing comment for recordIdx=%ld\n", recordIdx));
|
||||||
Assert(recordIdx != 0);
|
Assert(recordIdx != 0);
|
||||||
comment = GetSimpleComment(pState, pathname, kDefaultCommentLen);
|
comment = GetSimpleComment(pState, pathname, kDefaultCommentLen);
|
||||||
if (comment != nil) {
|
if (comment != NULL) {
|
||||||
NuDataSource* pDataSource;
|
NuDataSource* pDataSource;
|
||||||
|
|
||||||
err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed,
|
err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed,
|
||||||
@ -676,15 +676,15 @@ DoAddFile(NulibState* pState, NuArchive* pArchive, const char* pathname,
|
|||||||
Free(comment);
|
Free(comment);
|
||||||
err = kNuErrNone; /* oh well */
|
err = kNuErrNone; /* oh well */
|
||||||
} else {
|
} else {
|
||||||
comment = nil; /* now owned by the data source */
|
comment = NULL; /* now owned by the data source */
|
||||||
err = NuAddThread(pArchive, recordIdx, kNuThreadIDComment,
|
err = NuAddThread(pArchive, recordIdx, kNuThreadIDComment,
|
||||||
pDataSource, nil);
|
pDataSource, NULL);
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
ReportError(err, "comment thread add failed");
|
ReportError(err, "comment thread add failed");
|
||||||
NuFreeDataSource(pDataSource);
|
NuFreeDataSource(pDataSource);
|
||||||
err = kNuErrNone; /* oh well */
|
err = kNuErrNone; /* oh well */
|
||||||
} else {
|
} else {
|
||||||
pDataSource = nil; /* now owned by NufxLib */
|
pDataSource = NULL; /* now owned by NufxLib */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -711,20 +711,20 @@ static NuError
|
|||||||
UNIXAddDirectory(NulibState* pState, NuArchive* pArchive, const char* dirName)
|
UNIXAddDirectory(NulibState* pState, NuArchive* pArchive, const char* dirName)
|
||||||
{
|
{
|
||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
DIR* dirp = nil;
|
DIR* dirp = NULL;
|
||||||
DIR_TYPE* entry;
|
DIR_TYPE* entry;
|
||||||
char nbuf[MAX_PATH_LEN]; /* malloc might be better; this soaks stack */
|
char nbuf[MAX_PATH_LEN]; /* malloc might be better; this soaks stack */
|
||||||
char fssep;
|
char fssep;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(dirName != nil);
|
Assert(dirName != NULL);
|
||||||
|
|
||||||
DBUG(("+++ DESCEND: '%s'\n", dirName));
|
DBUG(("+++ DESCEND: '%s'\n", dirName));
|
||||||
|
|
||||||
dirp = opendir(dirName);
|
dirp = opendir(dirName);
|
||||||
if (dirp == nil) {
|
if (dirp == NULL) {
|
||||||
if (errno == ENOTDIR)
|
if (errno == ENOTDIR)
|
||||||
err = kNuErrNotDir;
|
err = kNuErrNotDir;
|
||||||
else
|
else
|
||||||
@ -736,7 +736,7 @@ UNIXAddDirectory(NulibState* pState, NuArchive* pArchive, const char* dirName)
|
|||||||
fssep = NState_GetSystemPathSeparator(pState);
|
fssep = NState_GetSystemPathSeparator(pState);
|
||||||
|
|
||||||
/* could use readdir_r, but we don't care about reentrancy here */
|
/* could use readdir_r, but we don't care about reentrancy here */
|
||||||
while ((entry = readdir(dirp)) != nil) {
|
while ((entry = readdir(dirp)) != NULL) {
|
||||||
/* skip the dotsies */
|
/* skip the dotsies */
|
||||||
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
||||||
continue;
|
continue;
|
||||||
@ -761,7 +761,7 @@ UNIXAddDirectory(NulibState* pState, NuArchive* pArchive, const char* dirName)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (dirp != nil)
|
if (dirp != NULL)
|
||||||
(void)closedir(dirp);
|
(void)closedir(dirp);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -783,9 +783,9 @@ UNIXAddFile(NulibState* pState, NuArchive* pArchive, const char* pathname)
|
|||||||
NuFileDetails details;
|
NuFileDetails details;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pathname != nil);
|
Assert(pathname != NULL);
|
||||||
|
|
||||||
err = CheckFileStatus(pathname, &sb, &exists, &isReadable, &isDir);
|
err = CheckFileStatus(pathname, &sb, &exists, &isReadable, &isDir);
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
@ -851,14 +851,14 @@ static const char* kWildMatchAll = "*.*";
|
|||||||
static Win32dirent*
|
static Win32dirent*
|
||||||
OpenDir(const char* name)
|
OpenDir(const char* name)
|
||||||
{
|
{
|
||||||
Win32dirent* dir = nil;
|
Win32dirent* dir = NULL;
|
||||||
char* tmpStr = nil;
|
char* tmpStr = NULL;
|
||||||
char* cp;
|
char* cp;
|
||||||
WIN32_FIND_DATA fnd;
|
WIN32_FIND_DATA fnd;
|
||||||
|
|
||||||
dir = Malloc(sizeof(*dir));
|
dir = Malloc(sizeof(*dir));
|
||||||
tmpStr = Malloc(strlen(name) + (2 + sizeof(kWildMatchAll)));
|
tmpStr = Malloc(strlen(name) + (2 + sizeof(kWildMatchAll)));
|
||||||
if (dir == nil || tmpStr == nil)
|
if (dir == NULL || tmpStr == NULL)
|
||||||
goto failed;
|
goto failed;
|
||||||
|
|
||||||
strcpy(tmpStr, name);
|
strcpy(tmpStr, name);
|
||||||
@ -887,14 +887,14 @@ bail:
|
|||||||
|
|
||||||
failed:
|
failed:
|
||||||
Free(dir);
|
Free(dir);
|
||||||
dir = nil;
|
dir = NULL;
|
||||||
goto bail;
|
goto bail;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get an entry from an open directory.
|
* Get an entry from an open directory.
|
||||||
*
|
*
|
||||||
* Returns a nil pointer after the last entry has been read.
|
* Returns a NULL pointer after the last entry has been read.
|
||||||
*/
|
*/
|
||||||
static Win32dirent*
|
static Win32dirent*
|
||||||
ReadDir(Win32dirent* dir)
|
ReadDir(Win32dirent* dir)
|
||||||
@ -905,7 +905,7 @@ ReadDir(Win32dirent* dir)
|
|||||||
WIN32_FIND_DATA fnd;
|
WIN32_FIND_DATA fnd;
|
||||||
|
|
||||||
if (!FindNextFile(dir->d_hFindFile, &fnd))
|
if (!FindNextFile(dir->d_hFindFile, &fnd))
|
||||||
return nil;
|
return NULL;
|
||||||
strcpy(dir->d_name, fnd.cFileName);
|
strcpy(dir->d_name, fnd.cFileName);
|
||||||
dir->d_attr = (uchar) fnd.dwFileAttributes;
|
dir->d_attr = (uchar) fnd.dwFileAttributes;
|
||||||
}
|
}
|
||||||
@ -919,7 +919,7 @@ ReadDir(Win32dirent* dir)
|
|||||||
static void
|
static void
|
||||||
CloseDir(Win32dirent* dir)
|
CloseDir(Win32dirent* dir)
|
||||||
{
|
{
|
||||||
if (dir == nil)
|
if (dir == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FindClose(dir->d_hFindFile);
|
FindClose(dir->d_hFindFile);
|
||||||
@ -943,20 +943,20 @@ static NuError
|
|||||||
Win32AddDirectory(NulibState* pState, NuArchive* pArchive, const char* dirName)
|
Win32AddDirectory(NulibState* pState, NuArchive* pArchive, const char* dirName)
|
||||||
{
|
{
|
||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
Win32dirent* dirp = nil;
|
Win32dirent* dirp = NULL;
|
||||||
Win32dirent* entry;
|
Win32dirent* entry;
|
||||||
char nbuf[MAX_PATH_LEN]; /* malloc might be better; this soaks stack */
|
char nbuf[MAX_PATH_LEN]; /* malloc might be better; this soaks stack */
|
||||||
char fssep;
|
char fssep;
|
||||||
int len;
|
int len;
|
||||||
|
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(dirName != nil);
|
Assert(dirName != NULL);
|
||||||
|
|
||||||
DBUG(("+++ DESCEND: '%s'\n", dirName));
|
DBUG(("+++ DESCEND: '%s'\n", dirName));
|
||||||
|
|
||||||
dirp = OpenDir(dirName);
|
dirp = OpenDir(dirName);
|
||||||
if (dirp == nil) {
|
if (dirp == NULL) {
|
||||||
if (errno == ENOTDIR)
|
if (errno == ENOTDIR)
|
||||||
err = kNuErrNotDir;
|
err = kNuErrNotDir;
|
||||||
else
|
else
|
||||||
@ -968,7 +968,7 @@ Win32AddDirectory(NulibState* pState, NuArchive* pArchive, const char* dirName)
|
|||||||
fssep = NState_GetSystemPathSeparator(pState);
|
fssep = NState_GetSystemPathSeparator(pState);
|
||||||
|
|
||||||
/* could use readdir_r, but we don't care about reentrancy here */
|
/* could use readdir_r, but we don't care about reentrancy here */
|
||||||
while ((entry = ReadDir(dirp)) != nil) {
|
while ((entry = ReadDir(dirp)) != NULL) {
|
||||||
/* skip the dotsies */
|
/* skip the dotsies */
|
||||||
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0)
|
||||||
continue;
|
continue;
|
||||||
@ -993,7 +993,7 @@ Win32AddDirectory(NulibState* pState, NuArchive* pArchive, const char* dirName)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bail:
|
bail:
|
||||||
if (dirp != nil)
|
if (dirp != NULL)
|
||||||
(void)CloseDir(dirp);
|
(void)CloseDir(dirp);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@ -1013,9 +1013,9 @@ Win32AddFile(NulibState* pState, NuArchive* pArchive, const char* pathname)
|
|||||||
NuFileDetails details;
|
NuFileDetails details;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
|
||||||
Assert(pState != nil);
|
Assert(pState != NULL);
|
||||||
Assert(pArchive != nil);
|
Assert(pArchive != NULL);
|
||||||
Assert(pathname != nil);
|
Assert(pathname != NULL);
|
||||||
|
|
||||||
err = CheckFileStatus(pathname, &sb, &exists, &isReadable, &isDir);
|
err = CheckFileStatus(pathname, &sb, &exists, &isReadable, &isDir);
|
||||||
if (err != kNuErrNone) {
|
if (err != kNuErrNone) {
|
||||||
@ -1071,7 +1071,7 @@ bail_quiet:
|
|||||||
*
|
*
|
||||||
* [ I figure the GS/OS version will want to pass a copy of the file
|
* [ I figure the GS/OS version will want to pass a copy of the file
|
||||||
* info from the GSOSAddDirectory function back into GSOSAddFile, so we'd
|
* info from the GSOSAddDirectory function back into GSOSAddFile, so we'd
|
||||||
* want to call it from here with a nil pointer indicating that we
|
* want to call it from here with a NULL pointer indicating that we
|
||||||
* don't yet have the file info. That way we can get the file info
|
* don't yet have the file info. That way we can get the file info
|
||||||
* from the directory read call and won't have to check it again in
|
* from the directory read call and won't have to check it again in
|
||||||
* GSOSAddFile. ]
|
* GSOSAddFile. ]
|
||||||
@ -1099,7 +1099,7 @@ Mkdir(const char* dir)
|
|||||||
{
|
{
|
||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
|
|
||||||
Assert(dir != nil);
|
Assert(dir != NULL);
|
||||||
|
|
||||||
#if defined(UNIX_LIKE)
|
#if defined(UNIX_LIKE)
|
||||||
if (mkdir(dir, S_IRWXU | S_IRGRP|S_IXGRP | S_IROTH|S_IXOTH) < 0) {
|
if (mkdir(dir, S_IRWXU | S_IRGRP|S_IXGRP | S_IROTH|S_IXOTH) < 0) {
|
||||||
@ -1130,8 +1130,8 @@ NuError
|
|||||||
TestFileExistence(const char* fileName, Boolean* pIsDir)
|
TestFileExistence(const char* fileName, Boolean* pIsDir)
|
||||||
{
|
{
|
||||||
NuError err = kNuErrNone;
|
NuError err = kNuErrNone;
|
||||||
Assert(fileName != nil);
|
Assert(fileName != NULL);
|
||||||
Assert(pIsDir != nil);
|
Assert(pIsDir != NULL);
|
||||||
|
|
||||||
#if defined(UNIX_LIKE) || defined(WINDOWS_LIKE)
|
#if defined(UNIX_LIKE) || defined(WINDOWS_LIKE)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user