diff --git a/nufxlib-0/ChangeLog.txt b/nufxlib-0/ChangeLog.txt index 1cc2017..e962f0d 100644 --- a/nufxlib-0/ChangeLog.txt +++ b/nufxlib-0/ChangeLog.txt @@ -1,159 +1,163 @@ -2000/05/22 ***** v1.0.1 shipped ***** +2002/09/20 fadden + - pulled the sources out and started fiddling with them again + - changed hard tabs to spaces -2000/05/22 fadden - - added workaround for buggy 140K DOS3.3 GSHK images +2000/05/22 ***** v1.0.1 shipped ***** -2000/05/18 ***** v1.0.0 shipped ***** +2000/05/22 fadden + - added workaround for buggy 140K DOS3.3 GSHK images -2000/05/18 fadden - - updated version information to indicate final release +2000/05/18 ***** v1.0.0 shipped ***** -2000/03/25 ***** v0.6.1 shipped ***** +2000/05/18 fadden + - updated version information to indicate final release -2000/03/25 fadden - - Sheppy says Mac OS X PPC v1.02 and v1.2 work with minor SysDefs tweak +2000/03/25 ***** v0.6.1 shipped ***** -2000/03/05 ***** v0.6.0 (beta) shipped ***** +2000/03/25 fadden + - Sheppy says Mac OS X PPC v1.02 and v1.2 work with minor SysDefs tweak -2000/03/05 fadden - - modified NuOpenRW to call mktemp or mkstemp if tmpPath looks like - a template - - removed DEBUG_MSGS from default CFLAGS - - updated version information to indicate beta release +2000/03/05 ***** v0.6.0 (beta) shipped ***** -2000/02/24 ***** v0.5.1 shipped ***** +2000/03/05 fadden + - modified NuOpenRW to call mktemp or mkstemp if tmpPath looks like + a template + - removed DEBUG_MSGS from default CFLAGS + - updated version information to indicate beta release -2000/02/20 changes from Scott Blackman - - portability fixes for DJGPP under Win95 +2000/02/24 ***** v0.5.1 shipped ***** -2000/02/17 changes from Devin Reade - - portability fixes for BSD, AIX, and others +2000/02/20 changes from Scott Blackman + - portability fixes for DJGPP under Win95 -2000/02/09 ***** v0.5.0 (alpha) shipped ***** +2000/02/17 changes from Devin Reade + - portability fixes for BSD, AIX, and others -2000/02/08 fadden - - tweaked the BeOS/PPC config around a little - - deleted some commas to make "gcc -pendantic" happy +2000/02/09 ***** v0.5.0 (alpha) shipped ***** -2000/02/06 fadden - - include @CFLAGS@ in case somebody wants to override them +2000/02/08 fadden + - tweaked the BeOS/PPC config around a little + - deleted some commas to make "gcc -pendantic" happy -2000/02/06 ***** v0.4.0b shipped ***** +2000/02/06 fadden + - include @CFLAGS@ in case somebody wants to override them -2000/02/06 fadden - - added "install-shared" make target - - portability fixes for HP/UX - - configure.in test for presence of snprintf/vsnprintf declarations +2000/02/06 ***** v0.4.0b shipped ***** -2000/02/06 ***** v0.4.0a shipped ***** +2000/02/06 fadden + - added "install-shared" make target + - portability fixes for HP/UX + - configure.in test for presence of snprintf/vsnprintf declarations -2000/02/06 fadden - - massaged configure.in for BeOS, and added some type casts for mwerks +2000/02/06 ***** v0.4.0a shipped ***** -2000/02/06 ***** v0.4.0 shipped ***** +2000/02/06 fadden + - massaged configure.in for BeOS, and added some type casts for mwerks -2000/02/06 fadden - - added value range checking to Nu_SetValue +2000/02/06 ***** v0.4.0 shipped ***** -2000/02/05 fadden - - finished "test-basic" - - added an "install" target to copy libnufx and NufxLib.h - - added "mkinstalldirs" - - fixed a memory leak in NuTest - - made several implicit typecasts explicit for Visual C++'s benefit - - renamed MiscStuff's replacement function to "Nu_function" - - use "rb" or "wb" as fopen arg in sample code for Win32 +2000/02/06 fadden + - added value range checking to Nu_SetValue -2000/02/04 fadden - - wrote a fair piece of "test-basic" - - added "stickyErr" to "toBuffer" data sink so we can catch overruns +2000/02/05 fadden + - finished "test-basic" + - added an "install" target to copy libnufx and NufxLib.h + - added "mkinstalldirs" + - fixed a memory leak in NuTest + - made several implicit typecasts explicit for Visual C++'s benefit + - renamed MiscStuff's replacement function to "Nu_function" + - use "rb" or "wb" as fopen arg in sample code for Win32 -2000/02/02 fadden - - minor changes to get it working under Win32 (Visual C++ 6.0) - - added --enable-dmalloc to configuration - - instead of constantly allocating 16K buffers, use pArchive->compBuf - - ignore DataSink convertEOL value when doExpand is false +2000/02/04 fadden + - wrote a fair piece of "test-basic" + - added "stickyErr" to "toBuffer" data sink so we can catch overruns -2000/02/01 fadden - - added system-specific PATH_SEP define for samples (imgconv, exerciser) - - set the pathname in ErrorStatus for CRC failures +2000/02/02 fadden + - minor changes to get it working under Win32 (Visual C++ 6.0) + - added --enable-dmalloc to configuration + - instead of constantly allocating 16K buffers, use pArchive->compBuf + - ignore DataSink convertEOL value when doExpand is false -2000/01/31 fadden - - fixed a typo causing zero-byte GSHK-damaged files to report CRC errors - - added support for DOS-ordered 2MG images to "imgconv" +2000/02/01 fadden + - added system-specific PATH_SEP define for samples (imgconv, exerciser) + - set the pathname in ErrorStatus for CRC failures -2000/01/29 ***** v0.3.0 shipped ***** +2000/01/31 fadden + - fixed a typo causing zero-byte GSHK-damaged files to report CRC errors + - added support for DOS-ordered 2MG images to "imgconv" -2000/01/29 fadden - - renamed "tests" to "samples" - - changed library version to x.y.z format (major, minor, bug-fix) - - added DEBUG_VERBOSE define, took some stuff out of DEBUG_MSGS +2000/01/29 ***** v0.3.0 shipped ***** -2000/01/28 fadden - - make the Skip result work when an input file can't be opened - - don't allow leading fssep chars in AddRecord - - don't treat a multi-file BNY that happens to have a ShrinkIt archive - in the first slot as a BXY - - added "-t" flag (write to temp) to "launder" - - in OpenReadWrite, treat zero-length archive files as newly-created - - added workaround for GSHK's zero-byte data fork bug +2000/01/29 fadden + - renamed "tests" to "samples" + - changed library version to x.y.z format (major, minor, bug-fix) + - added DEBUG_VERBOSE define, took some stuff out of DEBUG_MSGS -2000/01/26 fadden - - added status result flags to NuFlush - - dropped kNuAbortAll and added kNuIgnore - - implemented kNuValueIgnoreCRC - - update the storageType whenever we change the record +2000/01/28 fadden + - make the Skip result work when an input file can't be opened + - don't allow leading fssep chars in AddRecord + - don't treat a multi-file BNY that happens to have a ShrinkIt archive + in the first slot as a BXY + - added "-t" flag (write to temp) to "launder" + - in OpenReadWrite, treat zero-length archive files as newly-created + - added workaround for GSHK's zero-byte data fork bug -2000/01/25 fadden - - don't remove the temp file if the rename fails - - Nu_ReportError now optionally uses a callback instead of stderr - - pass NuArchive* and all the trimmings into Nu_ReportError so we can - do the callback thing; required adding arguments to lots of places - - clearly labeled BailError output as debug-only, then replaced most - of the BailErrorQuiet calls with BailError - - added global error message for when pArchive doesn't exist (e.g. Open) +2000/01/26 fadden + - added status result flags to NuFlush + - dropped kNuAbortAll and added kNuIgnore + - implemented kNuValueIgnoreCRC + - update the storageType whenever we change the record -2000/01/24 fadden - - added args to "launder", and made it work right with 0-length threads - - reject disk image threads that aren't a valid size - - in NuFlush, recognize when a "copy" set hasn't had any changes made - - AddThread no longer makes a copy of the DataSource +2000/01/25 fadden + - don't remove the temp file if the rename fails + - Nu_ReportError now optionally uses a callback instead of stderr + - pass NuArchive* and all the trimmings into Nu_ReportError so we can + do the callback thing; required adding arguments to lots of places + - clearly labeled BailError output as debug-only, then replaced most + of the BailErrorQuiet calls with BailError + - added global error message for when pArchive doesn't exist (e.g. Open) -2000/01/24 ***** v0.2 shipped ***** +2000/01/24 fadden + - added args to "launder", and made it work right with 0-length threads + - reject disk image threads that aren't a valid size + - in NuFlush, recognize when a "copy" set hasn't had any changes made + - AddThread no longer makes a copy of the DataSource -2000/01/23 fadden - - added "sec" (Set ErrorHandler Callback) to exerciser - - wrote "launder" test program - - made "doExpand" option on data sinks work +2000/01/24 ***** v0.2 shipped ***** -2000/01/22 fadden - - added OnlyUpdateOlder attribute and implemented for add and extract - - made HandleExisting work for AddFile/AddRecord - - AddThread's validation now blocks data and control threads in same - record - - AddFile and AddRecord now use same validation function as AddThread +2000/01/23 fadden + - added "sec" (Set ErrorHandler Callback) to exerciser + - wrote "launder" test program + - made "doExpand" option on data sinks work -2000/01/20 fadden - - added Eric Shepherd's BeOS shared lib stuff to configure.in - - restructed the progress updater, and made it work when adding files +2000/01/22 fadden + - added OnlyUpdateOlder attribute and implemented for add and extract + - made HandleExisting work for AddFile/AddRecord + - AddThread's validation now blocks data and control threads in same + record + - AddFile and AddRecord now use same validation function as AddThread -2000/01/19 fadden - - normalized SysDefs.h, changing UNIX to UNIX_LIKE and defining for BeOS - - added "shared" target to makefile - - added BeOS stuff to autoconf setup +2000/01/20 fadden + - added Eric Shepherd's BeOS shared lib stuff to configure.in + - restructed the progress updater, and made it work when adding files -2000/01/17 fadden - - fixed Makefile issue preventing "tests" from working with old GNU make - - fixed Lzw.c problem fouling up SunOS gcc v2.5.8 - - discovered "<" vs "<=" flapping in GSHK, which I can't Mimic - - fixed option list dump in debug print - - properly return from all Malloc errors; abort is now debug-only again - - lots of BeOS/Metrowerks "it's not gcc" changes from Eric Shepherd +2000/01/19 fadden + - normalized SysDefs.h, changing UNIX to UNIX_LIKE and defining for BeOS + - added "shared" target to makefile + - added BeOS stuff to autoconf setup -2000/01/17 ***** v0.1 shipped ***** +2000/01/17 fadden + - fixed Makefile issue preventing "tests" from working with old GNU make + - fixed Lzw.c problem fouling up SunOS gcc v2.5.8 + - discovered "<" vs "<=" flapping in GSHK, which I can't Mimic + - fixed option list dump in debug print + - properly return from all Malloc errors; abort is now debug-only again + - lots of BeOS/Metrowerks "it's not gcc" changes from Eric Shepherd + +2000/01/17 ***** v0.1 shipped ***** (much time passes) -mid-1998 fadden - - work begins +mid-1998 fadden + - work begins diff --git a/nufxlib-0/README.txt b/nufxlib-0/README.txt index 8cba4c8..d11b88c 100644 --- a/nufxlib-0/README.txt +++ b/nufxlib-0/README.txt @@ -69,9 +69,9 @@ DJGPP, follow the UNIX instructions. NufxLib has been tested with Microsoft Visual C++ 6.0. To build NufxLib, start up a DOS shell and run vcvars32.bat to set your environment. Run: - nmake -f makefile.msc + nmake -f makefile.msc to build with debugging info, or - nmake -f makefile.msc nodebug=1 + nmake -f makefile.msc nodebug=1 to build optimized. Once the library has been built, "cd samples" and run the same command there. @@ -81,7 +81,7 @@ When it finishes, run "test-basic.exe". Other Notes =========== -All of the source code was formatted with four-space hard tabs. +All of the source code is now formatted with spaces instead of tabs. If you want to use the library in a multithreaded application, you should define "USE_REENTRANT_CALLS" to tell it to use reentrant versions of diff --git a/nufxlib-0/samples/Common.h b/nufxlib-0/samples/Common.h index e6d1366..3d8d7fe 100644 --- a/nufxlib-0/samples/Common.h +++ b/nufxlib-0/samples/Common.h @@ -9,33 +9,33 @@ #ifndef __Common__ #define __Common__ -#include "SysDefs.h" /* might as well draft off the autoconf */ +#include "SysDefs.h" /* might as well draft off the autoconf */ #include "NufxLib.h" #ifdef USE_DMALLOC # include "dmalloc.h" #endif -#define nil NULL /* this is seriously habit-forming */ +#define nil NULL /* this is seriously habit-forming */ #define NELEM(x) (sizeof(x) / sizeof((x)[0])) #ifndef __cplusplus - #define false 0 - #define true (!false) + #define false 0 + #define true (!false) #endif #ifdef FOPEN_WANTS_B -# define kNuFileOpenReadOnly "rb" -# define kNuFileOpenReadWrite "r+b" -# define kNuFileOpenWriteTrunc "wb" -# define kNuFileOpenReadWriteCreat "w+b" +# define kNuFileOpenReadOnly "rb" +# define kNuFileOpenReadWrite "r+b" +# define kNuFileOpenWriteTrunc "wb" +# define kNuFileOpenReadWriteCreat "w+b" #else -# define kNuFileOpenReadOnly "r" -# define kNuFileOpenReadWrite "r+" -# define kNuFileOpenWriteTrunc "w" -# define kNuFileOpenReadWriteCreat "w+" +# define kNuFileOpenReadOnly "r" +# define kNuFileOpenReadWrite "r+" +# define kNuFileOpenWriteTrunc "w" +# define kNuFileOpenReadWriteCreat "w+" #endif @@ -44,23 +44,23 @@ */ #ifdef MSDOS -# define PATH_SEP '\\' +# define PATH_SEP '\\' #endif #ifdef WIN32 -# define PATH_SEP '\\' +# define PATH_SEP '\\' #endif #ifdef MACOS -# define PATH_SEP ':' +# define PATH_SEP ':' #endif #if defined(APW) || defined(__ORCAC__) -# define PATH_SEP ':' +# define PATH_SEP ':' #endif #ifndef PATH_SEP -# define PATH_SEP '/' +# define PATH_SEP '/' #endif #endif /*__Common__*/ diff --git a/nufxlib-0/samples/Exerciser.c b/nufxlib-0/samples/Exerciser.c index 4bb3bbd..c817768 100644 --- a/nufxlib-0/samples/Exerciser.c +++ b/nufxlib-0/samples/Exerciser.c @@ -20,14 +20,14 @@ static const char kFssep = PATH_SEP; /* ProDOS access permissions */ -#define kUnlocked 0xe3 +#define kUnlocked 0xe3 -#define kTempFile "exer-temp" +#define kTempFile "exer-temp" /* * =========================================================================== - * ExerciserState object + * ExerciserState object * =========================================================================== */ @@ -38,96 +38,96 @@ static const char kFssep = PATH_SEP; * then converted back to C. */ typedef struct ExerciserState { - NuArchive* pArchive; - char* archivePath; - const char* archiveFile; + NuArchive* pArchive; + char* archivePath; + const char* archiveFile; } ExerciserState; ExerciserState* ExerciserState_New(void) { - ExerciserState* pExerState; - - pExerState = (ExerciserState*) malloc(sizeof(*pExerState)); - if (pExerState == nil) - return nil; + ExerciserState* pExerState; + + pExerState = (ExerciserState*) malloc(sizeof(*pExerState)); + if (pExerState == nil) + return nil; - pExerState->pArchive = nil; - pExerState->archivePath = nil; - pExerState->archiveFile = nil; + pExerState->pArchive = nil; + pExerState->archivePath = nil; + pExerState->archiveFile = nil; - return pExerState; + return pExerState; } void ExerciserState_Free(ExerciserState* pExerState) { - if (pExerState == nil) - return; + if (pExerState == nil) + return; - if (pExerState->pArchive != nil) { - printf("Exerciser: aborting open archive\n"); - (void) NuAbort(pExerState->pArchive); - (void) NuClose(pExerState->pArchive); - } - if (pExerState->archivePath != nil) - free(pExerState->archivePath); + if (pExerState->pArchive != nil) { + printf("Exerciser: aborting open archive\n"); + (void) NuAbort(pExerState->pArchive); + (void) NuClose(pExerState->pArchive); + } + if (pExerState->archivePath != nil) + free(pExerState->archivePath); - free(pExerState); + free(pExerState); } inline NuArchive* ExerciserState_GetNuArchive(const ExerciserState* pExerState) { - return pExerState->pArchive; + return pExerState->pArchive; } inline void ExerciserState_SetNuArchive(ExerciserState* pExerState, NuArchive* newArchive) { - pExerState->pArchive = newArchive; + pExerState->pArchive = newArchive; } inline char* ExerciserState_GetArchivePath(const ExerciserState* pExerState) { - return pExerState->archivePath; + return pExerState->archivePath; } inline void ExerciserState_SetArchivePath(ExerciserState* pExerState, char* newPath) { - if (pExerState->archivePath != nil) - free(pExerState->archivePath); + if (pExerState->archivePath != nil) + free(pExerState->archivePath); - if (newPath == nil) { - pExerState->archivePath = nil; - pExerState->archiveFile = nil; - } else { - pExerState->archivePath = strdup(newPath); - pExerState->archiveFile = strrchr(newPath, kFssep); - if (pExerState->archiveFile != nil) - pExerState->archiveFile++; + if (newPath == nil) { + pExerState->archivePath = nil; + pExerState->archiveFile = nil; + } else { + pExerState->archivePath = strdup(newPath); + pExerState->archiveFile = strrchr(newPath, kFssep); + if (pExerState->archiveFile != nil) + pExerState->archiveFile++; - if (pExerState->archiveFile == nil || *pExerState->archiveFile == '\0') - pExerState->archiveFile = pExerState->archivePath; - } + if (pExerState->archiveFile == nil || *pExerState->archiveFile == '\0') + pExerState->archiveFile = pExerState->archivePath; + } } inline const char* ExerciserState_GetArchiveFile(const ExerciserState* pExerState) { - if (pExerState->archiveFile == nil) - return "[no archive open]"; - else - return pExerState->archiveFile; + if (pExerState->archiveFile == nil) + return "[no archive open]"; + else + return pExerState->archiveFile; } /* * =========================================================================== - * Utility functions + * Utility functions * =========================================================================== */ @@ -137,76 +137,76 @@ ExerciserState_GetArchiveFile(const ExerciserState* pExerState) NuResult PrintEntry(NuArchive* pArchive, void* vpRecord) { - const NuRecord* pRecord = (const NuRecord*) vpRecord; - int idx; + const NuRecord* pRecord = (const NuRecord*) vpRecord; + int idx; - (void)pArchive; /* shut up, gcc */ + (void)pArchive; /* shut up, gcc */ - printf("RecordIdx %ld: '%s'\n", - pRecord->recordIdx, pRecord->filename); + printf("RecordIdx %ld: '%s'\n", + pRecord->recordIdx, pRecord->filename); - for (idx = 0; idx < (int) pRecord->recTotalThreads; idx++) { - const NuThread* pThread; - NuThreadID threadID; - const char* threadLabel; + for (idx = 0; idx < (int) pRecord->recTotalThreads; idx++) { + const NuThread* pThread; + NuThreadID threadID; + const char* threadLabel; - pThread = NuGetThread(pRecord, idx); - assert(pThread != nil); + pThread = NuGetThread(pRecord, idx); + assert(pThread != nil); - threadID = NuGetThreadID(pThread); - switch (NuThreadIDGetClass(threadID)) { - case kNuThreadClassMessage: - threadLabel = "message class"; - break; - case kNuThreadClassControl: - threadLabel = "control class"; - break; - case kNuThreadClassData: - threadLabel = "data class"; - break; - case kNuThreadClassFilename: - threadLabel = "filename class"; - break; - default: - threadLabel = "(unknown class)"; - break; - } + threadID = NuGetThreadID(pThread); + switch (NuThreadIDGetClass(threadID)) { + case kNuThreadClassMessage: + threadLabel = "message class"; + break; + case kNuThreadClassControl: + threadLabel = "control class"; + break; + case kNuThreadClassData: + threadLabel = "data class"; + break; + case kNuThreadClassFilename: + threadLabel = "filename class"; + break; + default: + threadLabel = "(unknown class)"; + break; + } - switch (threadID) { - case kNuThreadIDComment: - threadLabel = "comment"; - break; - case kNuThreadIDIcon: - threadLabel = "icon"; - break; - case kNuThreadIDMkdir: - threadLabel = "mkdir"; - break; - case kNuThreadIDDataFork: - threadLabel = "data fork"; - break; - case kNuThreadIDDiskImage: - threadLabel = "disk image"; - break; - case kNuThreadIDRsrcFork: - threadLabel = "rsrc fork"; - break; - case kNuThreadIDFilename: - threadLabel = "filename"; - break; - default: - break; - } + switch (threadID) { + case kNuThreadIDComment: + threadLabel = "comment"; + break; + case kNuThreadIDIcon: + threadLabel = "icon"; + break; + case kNuThreadIDMkdir: + threadLabel = "mkdir"; + break; + case kNuThreadIDDataFork: + threadLabel = "data fork"; + break; + case kNuThreadIDDiskImage: + threadLabel = "disk image"; + break; + case kNuThreadIDRsrcFork: + threadLabel = "rsrc fork"; + break; + case kNuThreadIDFilename: + threadLabel = "filename"; + break; + default: + break; + } - printf(" ThreadIdx %ld - 0x%08lx (%s)\n", pThread->threadIdx, - threadID, threadLabel); - } + printf(" ThreadIdx %ld - 0x%08lx (%s)\n", pThread->threadIdx, + threadID, threadLabel); + } - return kNuOK; + return kNuOK; } -#define kNiceLineLen 256 +#define kNiceLineLen 256 /* * Get a line of input, stripping the '\n' off the end. @@ -214,16 +214,16 @@ PrintEntry(NuArchive* pArchive, void* vpRecord) static NuError GetLine(const char* prompt, char* buffer, int bufferSize) { - printf("%s> ", prompt); - fflush(stdout); + printf("%s> ", prompt); + fflush(stdout); - if (fgets(buffer, bufferSize, stdin) == nil) - return kNuErrGeneric; + if (fgets(buffer, bufferSize, stdin) == nil) + return kNuErrGeneric; - if (buffer[strlen(buffer)-1] == '\n') - buffer[strlen(buffer)-1] = '\0'; + if (buffer[strlen(buffer)-1] == '\n') + buffer[strlen(buffer)-1] = '\0'; - return kNuErrNone; + return kNuErrNone; } @@ -233,19 +233,19 @@ GetLine(const char* prompt, char* buffer, int bufferSize) NuResult SelectionFilter(NuArchive* pArchive, void* vselFilt) { - const NuSelectionProposal* selProposal = (NuSelectionProposal*) vselFilt; - char buffer[8]; + const NuSelectionProposal* selProposal = (NuSelectionProposal*) vselFilt; + char buffer[8]; - printf("%s (N/y)? ", selProposal->pRecord->filename); - fflush(stdout); + printf("%s (N/y)? ", selProposal->pRecord->filename); + fflush(stdout); - if (fgets(buffer, sizeof(buffer), stdin) == nil) - return kNuAbort; + if (fgets(buffer, sizeof(buffer), stdin) == nil) + return kNuAbort; - if (tolower(buffer[0]) == 'y') - return kNuOK; - else - return kNuSkip; + if (tolower(buffer[0]) == 'y') + return kNuOK; + else + return kNuSkip; } @@ -255,60 +255,60 @@ SelectionFilter(NuArchive* pArchive, void* vselFilt) NuResult ErrorHandler(NuArchive* pArchive, void* vErrorStatus) { - const NuErrorStatus* pErrorStatus = (const NuErrorStatus*) vErrorStatus; - char buffer[8]; - NuResult result = kNuSkip; + const NuErrorStatus* pErrorStatus = (const NuErrorStatus*) vErrorStatus; + char buffer[8]; + NuResult result = kNuSkip; - printf("Exerciser: error handler op=%d err=%d sysErr=%d message='%s'\n" - "\tfilename='%s' '%c'(0x%02x)\n", - pErrorStatus->operation, pErrorStatus->err, pErrorStatus->sysErr, - pErrorStatus->message == nil ? "(nil)" : pErrorStatus->message, - pErrorStatus->pathname, pErrorStatus->filenameSeparator, - pErrorStatus->filenameSeparator); - printf("\tValid options are:"); - if (pErrorStatus->canAbort) - printf(" a)bort"); - if (pErrorStatus->canRetry) - printf(" r)etry"); - if (pErrorStatus->canIgnore) - printf(" i)gnore"); - if (pErrorStatus->canSkip) - printf(" s)kip"); - if (pErrorStatus->canRename) - printf(" re)name"); - if (pErrorStatus->canOverwrite) - printf(" o)verwrite"); - putc('\n', stdout); + printf("Exerciser: error handler op=%d err=%d sysErr=%d message='%s'\n" + "\tfilename='%s' '%c'(0x%02x)\n", + pErrorStatus->operation, pErrorStatus->err, pErrorStatus->sysErr, + pErrorStatus->message == nil ? "(nil)" : pErrorStatus->message, + pErrorStatus->pathname, pErrorStatus->filenameSeparator, + pErrorStatus->filenameSeparator); + printf("\tValid options are:"); + if (pErrorStatus->canAbort) + printf(" a)bort"); + if (pErrorStatus->canRetry) + printf(" r)etry"); + if (pErrorStatus->canIgnore) + printf(" i)gnore"); + if (pErrorStatus->canSkip) + printf(" s)kip"); + if (pErrorStatus->canRename) + printf(" re)name"); + if (pErrorStatus->canOverwrite) + printf(" o)verwrite"); + putc('\n', stdout); - printf("Return what (a/r/i/s/e/o)? "); - fflush(stdout); + printf("Return what (a/r/i/s/e/o)? "); + fflush(stdout); - if (fgets(buffer, sizeof(buffer), stdin) == nil) { - printf("Returning kNuSkip\n"); - } else switch (buffer[0]) { - case 'a': result = kNuAbort; break; - case 'r': result = kNuRetry; break; - case 'i': result = kNuIgnore; break; - case 's': result = kNuSkip; break; - case 'e': result = kNuRename; break; - case 'o': result = kNuOverwrite; break; - default: - printf("Unknown value '%c', returning kNuSkip\n", buffer[0]); - break; - } + if (fgets(buffer, sizeof(buffer), stdin) == nil) { + printf("Returning kNuSkip\n"); + } else switch (buffer[0]) { + case 'a': result = kNuAbort; break; + case 'r': result = kNuRetry; break; + case 'i': result = kNuIgnore; break; + case 's': result = kNuSkip; break; + case 'e': result = kNuRename; break; + case 'o': result = kNuOverwrite; break; + default: + printf("Unknown value '%c', returning kNuSkip\n", buffer[0]); + break; + } - return result; + return result; } /* * =========================================================================== - * Command handlers + * Command handlers * =========================================================================== */ typedef NuError (*CommandFunc)(ExerciserState* pState, int argc, - char** argv); + char** argv); static NuError HelpFunc(ExerciserState* pState, int argc, char** argv); @@ -316,9 +316,9 @@ static NuError HelpFunc(ExerciserState* pState, int argc, char** argv); static NuError GenericFunc(ExerciserState* pState, int argc, char** argv) { - (void) pState, (void) argc, (void) argv; /* shut up, gcc */ - printf("Generic! argc=%d\n", argc); - return kNuErrNone; + (void) pState, (void) argc, (void) argv; /* shut up, gcc */ + printf("Generic! argc=%d\n", argc); + return kNuErrNone; } #endif @@ -328,8 +328,8 @@ GenericFunc(ExerciserState* pState, int argc, char** argv) static NuError NothingFunc(ExerciserState* pState, int argc, char** argv) { - (void) pState, (void) argc, (void) argv; /* shut up, gcc */ - return kNuErrNone; + (void) pState, (void) argc, (void) argv; /* shut up, gcc */ + return kNuErrNone; } /* @@ -341,9 +341,9 @@ NothingFunc(ExerciserState* pState, int argc, char** argv) static NuError QuitFunc(ExerciserState* pState, int argc, char** argv) { - (void) pState, (void) argc, (void) argv; /* shut up, gcc */ - assert(0); - return kNuErrNone; + (void) pState, (void) argc, (void) argv; /* shut up, gcc */ + assert(0); + return kNuErrNone; } @@ -354,11 +354,11 @@ QuitFunc(ExerciserState* pState, int argc, char** argv) static NuError AbortFunc(ExerciserState* pState, int argc, char** argv) { - (void) pState, (void) argc, (void) argv; /* shut up, gcc */ - assert(ExerciserState_GetNuArchive(pState) != nil); - assert(argc == 1); + (void) pState, (void) argc, (void) argv; /* shut up, gcc */ + assert(ExerciserState_GetNuArchive(pState) != nil); + assert(argc == 1); - return NuAbort(ExerciserState_GetNuArchive(pState)); + return NuAbort(ExerciserState_GetNuArchive(pState)); } /* @@ -367,22 +367,22 @@ AbortFunc(ExerciserState* pState, int argc, char** argv) static NuError AddFileFunc(ExerciserState* pState, int argc, char** argv) { - NuFileDetails nuFileDetails; + NuFileDetails nuFileDetails; - (void) pState, (void) argc, (void) argv; /* shut up, gcc */ - assert(ExerciserState_GetNuArchive(pState) != nil); - assert(argc == 2); + (void) pState, (void) argc, (void) argv; /* shut up, gcc */ + assert(ExerciserState_GetNuArchive(pState) != nil); + assert(argc == 2); - memset(&nuFileDetails, 0, sizeof(nuFileDetails)); - nuFileDetails.threadID = kNuThreadIDDataFork; - nuFileDetails.storageName = argv[1]; - nuFileDetails.fileSysID = kNuFileSysUnknown; - nuFileDetails.fileSysInfo = (short) kFssep; - nuFileDetails.access = kUnlocked; - /* fileType, extraType, storageType, dates */ + memset(&nuFileDetails, 0, sizeof(nuFileDetails)); + nuFileDetails.threadID = kNuThreadIDDataFork; + nuFileDetails.storageName = argv[1]; + nuFileDetails.fileSysID = kNuFileSysUnknown; + nuFileDetails.fileSysInfo = (short) kFssep; + nuFileDetails.access = kUnlocked; + /* fileType, extraType, storageType, dates */ - return NuAddFile(ExerciserState_GetNuArchive(pState), argv[1], - &nuFileDetails, false, nil); + return NuAddFile(ExerciserState_GetNuArchive(pState), argv[1], + &nuFileDetails, false, nil); } /* @@ -391,27 +391,27 @@ AddFileFunc(ExerciserState* pState, int argc, char** argv) static NuError AddRecordFunc(ExerciserState* pState, int argc, char** argv) { - NuError err; - NuRecordIdx recordIdx; - NuFileDetails nuFileDetails; + NuError err; + NuRecordIdx recordIdx; + NuFileDetails nuFileDetails; - (void) pState, (void) argc, (void) argv; /* shut up, gcc */ - assert(ExerciserState_GetNuArchive(pState) != nil); - assert(argc == 2); + (void) pState, (void) argc, (void) argv; /* shut up, gcc */ + assert(ExerciserState_GetNuArchive(pState) != nil); + assert(argc == 2); - memset(&nuFileDetails, 0, sizeof(nuFileDetails)); - nuFileDetails.threadID = 0; /* irrelevant */ - nuFileDetails.storageName = argv[1]; - nuFileDetails.fileSysID = kNuFileSysUnknown; - nuFileDetails.fileSysInfo = (short) kFssep; - nuFileDetails.access = kUnlocked; - /* fileType, extraType, storageType, dates */ + memset(&nuFileDetails, 0, sizeof(nuFileDetails)); + nuFileDetails.threadID = 0; /* irrelevant */ + nuFileDetails.storageName = argv[1]; + nuFileDetails.fileSysID = kNuFileSysUnknown; + nuFileDetails.fileSysInfo = (short) kFssep; + nuFileDetails.access = kUnlocked; + /* fileType, extraType, storageType, dates */ - err = NuAddRecord(ExerciserState_GetNuArchive(pState), - &nuFileDetails, &recordIdx); - if (err == kNuErrNone) - printf("Exerciser: success, new recordIdx=%ld\n", recordIdx); - return err; + err = NuAddRecord(ExerciserState_GetNuArchive(pState), + &nuFileDetails, &recordIdx); + if (err == kNuErrNone) + printf("Exerciser: success, new recordIdx=%ld\n", recordIdx); + return err; } /* @@ -420,86 +420,86 @@ AddRecordFunc(ExerciserState* pState, int argc, char** argv) static NuError AddThreadFunc(ExerciserState* pState, int argc, char** argv) { - NuError err; - NuDataSource* pDataSource = nil; - char* lineBuf = nil; - long ourLen, maxLen; - NuThreadID threadID; - NuThreadIdx threadIdx; + NuError err; + NuDataSource* pDataSource = nil; + char* lineBuf = nil; + long ourLen, maxLen; + NuThreadID threadID; + NuThreadIdx threadIdx; - (void) pState, (void) argc, (void) argv; /* shut up, gcc */ - assert(ExerciserState_GetNuArchive(pState) != nil); - assert(argc == 3); + (void) pState, (void) argc, (void) argv; /* shut up, gcc */ + assert(ExerciserState_GetNuArchive(pState) != nil); + assert(argc == 3); - lineBuf = (char*)malloc(kNiceLineLen); - assert(lineBuf != nil); + lineBuf = (char*)malloc(kNiceLineLen); + assert(lineBuf != nil); - threadID = strtol(argv[2], nil, 0); - if (NuThreadIDGetClass(threadID) == kNuThreadClassData) { - /* load data from a file on disk */ - maxLen = 0; - err = GetLine("Enter filename", lineBuf, kNiceLineLen); - if (err != kNuErrNone) - goto bail; - if (!lineBuf[0]) { - fprintf(stderr, "Invalid filename\n"); - err = kNuErrInvalidArg; - goto bail; - } + threadID = strtol(argv[2], nil, 0); + if (NuThreadIDGetClass(threadID) == kNuThreadClassData) { + /* load data from a file on disk */ + maxLen = 0; + err = GetLine("Enter filename", lineBuf, kNiceLineLen); + if (err != kNuErrNone) + goto bail; + if (!lineBuf[0]) { + fprintf(stderr, "Invalid filename\n"); + err = kNuErrInvalidArg; + goto bail; + } - err = NuCreateDataSourceForFile(kNuThreadFormatUncompressed, - true, 0, lineBuf, false, &pDataSource); - if (err != kNuErrNone) { - fprintf(stderr, - "Exerciser: file data source create failed (err=%d)\n", err); - goto bail; - } - } else { - if (threadID == kNuThreadIDFilename || threadID == kNuThreadIDComment) { - /* select the buffer pre-size */ - err = GetLine("Enter max buffer size", lineBuf, kNiceLineLen); - if (err != kNuErrNone) - goto bail; - maxLen = strtol(lineBuf, nil, 0); - if (maxLen <= 0) { - fprintf(stderr, "Bad length\n"); - err = kNuErrInvalidArg; - goto bail; - } - } else { - maxLen = 0; - } + err = NuCreateDataSourceForFile(kNuThreadFormatUncompressed, + true, 0, lineBuf, false, &pDataSource); + if (err != kNuErrNone) { + fprintf(stderr, + "Exerciser: file data source create failed (err=%d)\n", err); + goto bail; + } + } else { + if (threadID == kNuThreadIDFilename || threadID == kNuThreadIDComment) { + /* select the buffer pre-size */ + err = GetLine("Enter max buffer size", lineBuf, kNiceLineLen); + if (err != kNuErrNone) + goto bail; + maxLen = strtol(lineBuf, nil, 0); + if (maxLen <= 0) { + fprintf(stderr, "Bad length\n"); + err = kNuErrInvalidArg; + goto bail; + } + } else { + maxLen = 0; + } - err = GetLine("Enter the thread contents", lineBuf, kNiceLineLen); - if (err != kNuErrNone) - goto bail; - ourLen = strlen(lineBuf); + err = GetLine("Enter the thread contents", lineBuf, kNiceLineLen); + if (err != kNuErrNone) + goto bail; + ourLen = strlen(lineBuf); - /* create a data source from the buffer */ - err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed, - true, maxLen, (unsigned char*)lineBuf, 0, ourLen, &pDataSource); - if (err != kNuErrNone) { - fprintf(stderr, - "Exerciser: buffer data source create failed (err=%d)\n", err); - goto bail; - } - lineBuf = nil; /* now owned by the library */ - } + /* create a data source from the buffer */ + err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed, + true, maxLen, (unsigned char*)lineBuf, 0, ourLen, &pDataSource); + if (err != kNuErrNone) { + fprintf(stderr, + "Exerciser: buffer data source create failed (err=%d)\n", err); + goto bail; + } + lineBuf = nil; /* now owned by the library */ + } - err = NuAddThread(ExerciserState_GetNuArchive(pState), - strtol(argv[1], nil, 0), threadID, pDataSource, &threadIdx); - if (err == kNuErrNone) { - pDataSource = nil; /* library owns it now */ - printf("Exerciser: success; function returned threadIdx=%ld\n", - threadIdx); - } + err = NuAddThread(ExerciserState_GetNuArchive(pState), + strtol(argv[1], nil, 0), threadID, pDataSource, &threadIdx); + if (err == kNuErrNone) { + pDataSource = nil; /* library owns it now */ + printf("Exerciser: success; function returned threadIdx=%ld\n", + threadIdx); + } bail: - NuFreeDataSource(pDataSource); - if (lineBuf != nil) - free(lineBuf); - return err; + NuFreeDataSource(pDataSource); + if (lineBuf != nil) + free(lineBuf); + return err; } /* @@ -508,19 +508,19 @@ bail: static NuError CloseFunc(ExerciserState* pState, int argc, char** argv) { - NuError err; + NuError err; - (void) pState, (void) argc, (void) argv; /* shut up, gcc */ - assert(ExerciserState_GetNuArchive(pState) != nil); - assert(argc == 1); + (void) pState, (void) argc, (void) argv; /* shut up, gcc */ + assert(ExerciserState_GetNuArchive(pState) != nil); + assert(argc == 1); - err = NuClose(ExerciserState_GetNuArchive(pState)); - if (err == kNuErrNone) { - ExerciserState_SetNuArchive(pState, nil); - ExerciserState_SetArchivePath(pState, nil); - } + err = NuClose(ExerciserState_GetNuArchive(pState)); + if (err == kNuErrNone) { + ExerciserState_SetNuArchive(pState, nil); + ExerciserState_SetArchivePath(pState, nil); + } - return err; + return err; } /* @@ -529,18 +529,18 @@ CloseFunc(ExerciserState* pState, int argc, char** argv) static NuError DeleteFunc(ExerciserState* pState, int argc, char** argv) { - NuError err; + NuError err; - (void) pState, (void) argc, (void) argv; /* shut up, gcc */ - assert(ExerciserState_GetNuArchive(pState) != nil); - assert(argc == 1); + (void) pState, (void) argc, (void) argv; /* shut up, gcc */ + assert(ExerciserState_GetNuArchive(pState) != nil); + assert(argc == 1); - err = NuSetSelectionFilter(ExerciserState_GetNuArchive(pState), - SelectionFilter); - if (err != kNuErrNone) - return err; + err = NuSetSelectionFilter(ExerciserState_GetNuArchive(pState), + SelectionFilter); + if (err != kNuErrNone) + return err; - return NuDelete(ExerciserState_GetNuArchive(pState)); + return NuDelete(ExerciserState_GetNuArchive(pState)); } /* @@ -549,12 +549,12 @@ DeleteFunc(ExerciserState* pState, int argc, char** argv) static NuError DeleteRecordFunc(ExerciserState* pState, int argc, char** argv) { - (void) pState, (void) argc, (void) argv; /* shut up, gcc */ - assert(ExerciserState_GetNuArchive(pState) != nil); - assert(argc == 2); + (void) pState, (void) argc, (void) argv; /* shut up, gcc */ + assert(ExerciserState_GetNuArchive(pState) != nil); + assert(argc == 2); - return NuDeleteRecord(ExerciserState_GetNuArchive(pState), - strtol(argv[1], nil, 0)); + return NuDeleteRecord(ExerciserState_GetNuArchive(pState), + strtol(argv[1], nil, 0)); } /* @@ -563,12 +563,12 @@ DeleteRecordFunc(ExerciserState* pState, int argc, char** argv) static NuError DeleteThreadFunc(ExerciserState* pState, int argc, char** argv) { - (void) pState, (void) argc, (void) argv; /* shut up, gcc */ - assert(ExerciserState_GetNuArchive(pState) != nil); - assert(argc == 2); + (void) pState, (void) argc, (void) argv; /* shut up, gcc */ + assert(ExerciserState_GetNuArchive(pState) != nil); + assert(argc == 2); - return NuDeleteThread(ExerciserState_GetNuArchive(pState), - strtol(argv[1], nil, 0)); + return NuDeleteThread(ExerciserState_GetNuArchive(pState), + strtol(argv[1], nil, 0)); } /* @@ -577,18 +577,18 @@ DeleteThreadFunc(ExerciserState* pState, int argc, char** argv) static NuError ExtractFunc(ExerciserState* pState, int argc, char** argv) { - NuError err; + NuError err; - (void) pState, (void) argc, (void) argv; /* shut up, gcc */ - assert(ExerciserState_GetNuArchive(pState) != nil); - assert(argc == 1); + (void) pState, (void) argc, (void) argv; /* shut up, gcc */ + assert(ExerciserState_GetNuArchive(pState) != nil); + assert(argc == 1); - err = NuSetSelectionFilter(ExerciserState_GetNuArchive(pState), - SelectionFilter); - if (err != kNuErrNone) - return err; + err = NuSetSelectionFilter(ExerciserState_GetNuArchive(pState), + SelectionFilter); + if (err != kNuErrNone) + return err; - return NuExtract(ExerciserState_GetNuArchive(pState)); + return NuExtract(ExerciserState_GetNuArchive(pState)); } /* @@ -597,12 +597,12 @@ ExtractFunc(ExerciserState* pState, int argc, char** argv) static NuError ExtractRecordFunc(ExerciserState* pState, int argc, char** argv) { - (void) pState, (void) argc, (void) argv; /* shut up, gcc */ - assert(ExerciserState_GetNuArchive(pState) != nil); - assert(argc == 2); + (void) pState, (void) argc, (void) argv; /* shut up, gcc */ + assert(ExerciserState_GetNuArchive(pState) != nil); + assert(argc == 2); - return NuExtractRecord(ExerciserState_GetNuArchive(pState), - strtol(argv[1], nil, 0)); + return NuExtractRecord(ExerciserState_GetNuArchive(pState), + strtol(argv[1], nil, 0)); } /* @@ -611,27 +611,27 @@ ExtractRecordFunc(ExerciserState* pState, int argc, char** argv) static NuError ExtractThreadFunc(ExerciserState* pState, int argc, char** argv) { - NuError err; - NuDataSink* pDataSink = nil; + NuError err; + NuDataSink* pDataSink = nil; - (void) pState, (void) argc, (void) argv; /* shut up, gcc */ - assert(ExerciserState_GetNuArchive(pState) != nil); - assert(argc == 3); + (void) pState, (void) argc, (void) argv; /* shut up, gcc */ + assert(ExerciserState_GetNuArchive(pState) != nil); + assert(argc == 3); - err = NuCreateDataSinkForFile(true, kNuConvertOff, argv[2], kFssep, - &pDataSink); - if (err != kNuErrNone) { - fprintf(stderr, "Exerciser: data sink create failed\n"); - goto bail; - } + err = NuCreateDataSinkForFile(true, kNuConvertOff, argv[2], kFssep, + &pDataSink); + if (err != kNuErrNone) { + fprintf(stderr, "Exerciser: data sink create failed\n"); + goto bail; + } - err = NuExtractThread(ExerciserState_GetNuArchive(pState), - strtol(argv[1], nil, 0), pDataSink); - /* fall through with err */ + err = NuExtractThread(ExerciserState_GetNuArchive(pState), + strtol(argv[1], nil, 0), pDataSink); + /* fall through with err */ bail: - NuFreeDataSink(pDataSink); - return err; + NuFreeDataSink(pDataSink); + return err; } /* @@ -640,17 +640,17 @@ bail: static NuError FlushFunc(ExerciserState* pState, int argc, char** argv) { - NuError err; - long flushStatus; + NuError err; + long flushStatus; - (void) pState, (void) argc, (void) argv; /* shut up, gcc */ - assert(ExerciserState_GetNuArchive(pState) != nil); - assert(argc == 1); + (void) pState, (void) argc, (void) argv; /* shut up, gcc */ + assert(ExerciserState_GetNuArchive(pState) != nil); + assert(argc == 1); - err = NuFlush(ExerciserState_GetNuArchive(pState), &flushStatus); - if (err != kNuErrNone) - printf("Exerciser: flush failed, status flags=0x%04lx\n", flushStatus); - return err; + err = NuFlush(ExerciserState_GetNuArchive(pState), &flushStatus); + if (err != kNuErrNone) + printf("Exerciser: flush failed, status flags=0x%04lx\n", flushStatus); + return err; } /* @@ -662,18 +662,18 @@ FlushFunc(ExerciserState* pState, int argc, char** argv) static NuError GetValueFunc(ExerciserState* pState, int argc, char** argv) { - NuError err; - NuValue value; + NuError err; + NuValue value; - (void) pState, (void) argc, (void) argv; /* shut up, gcc */ - assert(ExerciserState_GetNuArchive(pState) != nil); - assert(argc == 2); + (void) pState, (void) argc, (void) argv; /* shut up, gcc */ + assert(ExerciserState_GetNuArchive(pState) != nil); + assert(argc == 2); - err = NuGetValue(ExerciserState_GetNuArchive(pState), - (NuValueID) strtol(argv[1], nil, 0), &value); - if (err == kNuErrNone) - printf(" --> %ld\n", value); - return err; + err = NuGetValue(ExerciserState_GetNuArchive(pState), + (NuValueID) strtol(argv[1], nil, 0), &value); + if (err == kNuErrNone) + printf(" --> %ld\n", value); + return err; } /* @@ -682,21 +682,21 @@ GetValueFunc(ExerciserState* pState, int argc, char** argv) static NuError GetMasterHeaderFunc(ExerciserState* pState, int argc, char** argv) { - NuError err; - const NuMasterHeader* pMasterHeader; + NuError err; + const NuMasterHeader* pMasterHeader; - (void) pState, (void) argc, (void) argv; /* shut up, gcc */ - assert(ExerciserState_GetNuArchive(pState) != nil); - assert(argc == 1); + (void) pState, (void) argc, (void) argv; /* shut up, gcc */ + assert(ExerciserState_GetNuArchive(pState) != nil); + assert(argc == 1); - err = NuGetMasterHeader(ExerciserState_GetNuArchive(pState), - &pMasterHeader); - if (err == kNuErrNone) { - printf("Exerciser: success (version=%u, totalRecords=%lu, EOF=%lu)\n", - pMasterHeader->mhMasterVersion, pMasterHeader->mhTotalRecords, - pMasterHeader->mhMasterEOF); - } - return err; + err = NuGetMasterHeader(ExerciserState_GetNuArchive(pState), + &pMasterHeader); + if (err == kNuErrNone) { + printf("Exerciser: success (version=%u, totalRecords=%lu, EOF=%lu)\n", + pMasterHeader->mhMasterVersion, pMasterHeader->mhTotalRecords, + pMasterHeader->mhMasterEOF); + } + return err; } /* @@ -705,28 +705,28 @@ GetMasterHeaderFunc(ExerciserState* pState, int argc, char** argv) static NuError GetRecordFunc(ExerciserState* pState, int argc, char** argv) { - NuError err; - const NuRecord* pRecord; + NuError err; + const NuRecord* pRecord; - (void) pState, (void) argc, (void) argv; /* shut up, gcc */ - assert(ExerciserState_GetNuArchive(pState) != nil); - assert(argc == 2); + (void) pState, (void) argc, (void) argv; /* shut up, gcc */ + assert(ExerciserState_GetNuArchive(pState) != nil); + assert(argc == 2); - err = NuGetRecord(ExerciserState_GetNuArchive(pState), - strtol(argv[1], nil, 0), &pRecord); - if (err == kNuErrNone) { - printf("Exerciser: success, call returned:\n"); - printf("\tfileSysID : %d\n", pRecord->recFileSysID); - printf("\tfileSysInfo : 0x%04x ('%c')\n", pRecord->recFileSysInfo, - NuGetSepFromSysInfo(pRecord->recFileSysInfo)); - printf("\taccess : 0x%02lx\n", pRecord->recAccess); - printf("\tfileType : 0x%04lx\n", pRecord->recFileType); - printf("\textraType : 0x%04lx\n", pRecord->recExtraType); - printf("\tcreateWhen : ...\n"); - printf("\tmodWhen : ...\n"); /* too lazy */ - printf("\tarchiveWhen : ...\n"); - } - return err; + err = NuGetRecord(ExerciserState_GetNuArchive(pState), + strtol(argv[1], nil, 0), &pRecord); + if (err == kNuErrNone) { + printf("Exerciser: success, call returned:\n"); + printf("\tfileSysID : %d\n", pRecord->recFileSysID); + printf("\tfileSysInfo : 0x%04x ('%c')\n", pRecord->recFileSysInfo, + NuGetSepFromSysInfo(pRecord->recFileSysInfo)); + printf("\taccess : 0x%02lx\n", pRecord->recAccess); + printf("\tfileType : 0x%04lx\n", pRecord->recFileType); + printf("\textraType : 0x%04lx\n", pRecord->recExtraType); + printf("\tcreateWhen : ...\n"); + printf("\tmodWhen : ...\n"); /* too lazy */ + printf("\tarchiveWhen : ...\n"); + } + return err; } /* @@ -735,18 +735,18 @@ GetRecordFunc(ExerciserState* pState, int argc, char** argv) static NuError GetRecordIdxByNameFunc(ExerciserState* pState, int argc, char** argv) { - NuError err; - NuRecordIdx recIdx; + NuError err; + NuRecordIdx recIdx; - (void) pState, (void) argc, (void) argv; /* shut up, gcc */ - assert(ExerciserState_GetNuArchive(pState) != nil); - assert(argc == 2); + (void) pState, (void) argc, (void) argv; /* shut up, gcc */ + assert(ExerciserState_GetNuArchive(pState) != nil); + assert(argc == 2); - err = NuGetRecordIdxByName(ExerciserState_GetNuArchive(pState), - argv[1], &recIdx); - if (err == kNuErrNone) - printf("Exerciser: success, returned recordIdx=%ld\n", recIdx); - return err; + err = NuGetRecordIdxByName(ExerciserState_GetNuArchive(pState), + argv[1], &recIdx); + if (err == kNuErrNone) + printf("Exerciser: success, returned recordIdx=%ld\n", recIdx); + return err; } /* @@ -755,18 +755,18 @@ GetRecordIdxByNameFunc(ExerciserState* pState, int argc, char** argv) static NuError GetRecordIdxByPositionFunc(ExerciserState* pState, int argc, char** argv) { - NuError err; - NuRecordIdx recIdx; + NuError err; + NuRecordIdx recIdx; - (void) pState, (void) argc, (void) argv; /* shut up, gcc */ - assert(ExerciserState_GetNuArchive(pState) != nil); - assert(argc == 2); + (void) pState, (void) argc, (void) argv; /* shut up, gcc */ + assert(ExerciserState_GetNuArchive(pState) != nil); + assert(argc == 2); - err = NuGetRecordIdxByPosition(ExerciserState_GetNuArchive(pState), - strtol(argv[1], nil, 0), &recIdx); - if (err == kNuErrNone) - printf("Exerciser: success, returned recordIdx=%ld\n", recIdx); - return err; + err = NuGetRecordIdxByPosition(ExerciserState_GetNuArchive(pState), + strtol(argv[1], nil, 0), &recIdx); + if (err == kNuErrNone) + printf("Exerciser: success, returned recordIdx=%ld\n", recIdx); + return err; } /* @@ -775,19 +775,19 @@ GetRecordIdxByPositionFunc(ExerciserState* pState, int argc, char** argv) static NuError OpenCreateReadWriteFunc(ExerciserState* pState, int argc, char** argv) { - NuError err; - NuArchive* pArchive; + NuError err; + NuArchive* pArchive; - assert(ExerciserState_GetNuArchive(pState) == nil); - assert(argc == 2); + assert(ExerciserState_GetNuArchive(pState) == nil); + assert(argc == 2); - err = NuOpenRW(argv[1], kTempFile, kNuOpenCreat|kNuOpenExcl, &pArchive); - if (err == kNuErrNone) { - ExerciserState_SetNuArchive(pState, pArchive); - ExerciserState_SetArchivePath(pState, argv[1]); - } + err = NuOpenRW(argv[1], kTempFile, kNuOpenCreat|kNuOpenExcl, &pArchive); + if (err == kNuErrNone) { + ExerciserState_SetNuArchive(pState, pArchive); + ExerciserState_SetArchivePath(pState, argv[1]); + } - return err; + return err; } /* @@ -796,19 +796,19 @@ OpenCreateReadWriteFunc(ExerciserState* pState, int argc, char** argv) static NuError OpenReadOnlyFunc(ExerciserState* pState, int argc, char** argv) { - NuError err; - NuArchive* pArchive; + NuError err; + NuArchive* pArchive; - assert(ExerciserState_GetNuArchive(pState) == nil); - assert(argc == 2); + assert(ExerciserState_GetNuArchive(pState) == nil); + assert(argc == 2); - err = NuOpenRO(argv[1], &pArchive); - if (err == kNuErrNone) { - ExerciserState_SetNuArchive(pState, pArchive); - ExerciserState_SetArchivePath(pState, argv[1]); - } + err = NuOpenRO(argv[1], &pArchive); + if (err == kNuErrNone) { + ExerciserState_SetNuArchive(pState, pArchive); + ExerciserState_SetArchivePath(pState, argv[1]); + } - return err; + return err; } /* @@ -817,29 +817,29 @@ OpenReadOnlyFunc(ExerciserState* pState, int argc, char** argv) static NuError OpenStreamingReadOnlyFunc(ExerciserState* pState, int argc, char** argv) { - NuError err; - NuArchive* pArchive; - FILE* fp = nil; + NuError err; + NuArchive* pArchive; + FILE* fp = nil; - assert(ExerciserState_GetNuArchive(pState) == nil); - assert(argc == 2); + assert(ExerciserState_GetNuArchive(pState) == nil); + assert(argc == 2); - if ((fp = fopen(argv[1], kNuFileOpenReadOnly)) == nil) { - err = errno ? (NuError)errno : kNuErrGeneric; - fprintf(stderr, "Exerciser: unable to open '%s'\n", argv[1]); - } else { - err = NuStreamOpenRO(fp, &pArchive); - if (err == kNuErrNone) { - ExerciserState_SetNuArchive(pState, pArchive); - ExerciserState_SetArchivePath(pState, argv[1]); - fp = nil; - } - } + if ((fp = fopen(argv[1], kNuFileOpenReadOnly)) == nil) { + err = errno ? (NuError)errno : kNuErrGeneric; + fprintf(stderr, "Exerciser: unable to open '%s'\n", argv[1]); + } else { + err = NuStreamOpenRO(fp, &pArchive); + if (err == kNuErrNone) { + ExerciserState_SetNuArchive(pState, pArchive); + ExerciserState_SetArchivePath(pState, argv[1]); + fp = nil; + } + } - if (fp != nil) - fclose(fp); + if (fp != nil) + fclose(fp); - return err; + return err; } /* @@ -848,19 +848,19 @@ OpenStreamingReadOnlyFunc(ExerciserState* pState, int argc, char** argv) static NuError OpenReadWriteFunc(ExerciserState* pState, int argc, char** argv) { - NuError err; - NuArchive* pArchive; + NuError err; + NuArchive* pArchive; - assert(ExerciserState_GetNuArchive(pState) == nil); - assert(argc == 2); + assert(ExerciserState_GetNuArchive(pState) == nil); + assert(argc == 2); - err = NuOpenRW(argv[1], kTempFile, 0, &pArchive); - if (err == kNuErrNone) { - ExerciserState_SetNuArchive(pState, pArchive); - ExerciserState_SetArchivePath(pState, argv[1]); - } + err = NuOpenRW(argv[1], kTempFile, 0, &pArchive); + if (err == kNuErrNone) { + ExerciserState_SetNuArchive(pState, pArchive); + ExerciserState_SetArchivePath(pState, argv[1]); + } - return err; + return err; } /* @@ -869,11 +869,11 @@ OpenReadWriteFunc(ExerciserState* pState, int argc, char** argv) static NuError PrintFunc(ExerciserState* pState, int argc, char** argv) { - (void) pState, (void) argc, (void) argv; /* shut up, gcc */ - assert(ExerciserState_GetNuArchive(pState) != nil); - assert(argc == 1); + (void) pState, (void) argc, (void) argv; /* shut up, gcc */ + assert(ExerciserState_GetNuArchive(pState) != nil); + assert(argc == 1); - return NuContents(ExerciserState_GetNuArchive(pState), PrintEntry); + return NuContents(ExerciserState_GetNuArchive(pState), PrintEntry); } /* @@ -882,11 +882,11 @@ PrintFunc(ExerciserState* pState, int argc, char** argv) static NuError PrintDebugFunc(ExerciserState* pState, int argc, char** argv) { - (void) pState, (void) argc, (void) argv; /* shut up, gcc */ - assert(ExerciserState_GetNuArchive(pState) != nil); - assert(argc == 1); + (void) pState, (void) argc, (void) argv; /* shut up, gcc */ + assert(ExerciserState_GetNuArchive(pState) != nil); + assert(argc == 1); - return NuDebugDumpArchive(ExerciserState_GetNuArchive(pState)); + return NuDebugDumpArchive(ExerciserState_GetNuArchive(pState)); } /* @@ -895,12 +895,12 @@ PrintDebugFunc(ExerciserState* pState, int argc, char** argv) static NuError RenameFunc(ExerciserState* pState, int argc, char** argv) { - (void) pState, (void) argc, (void) argv; /* shut up, gcc */ - assert(ExerciserState_GetNuArchive(pState) != nil); - assert(argc == 4); + (void) pState, (void) argc, (void) argv; /* shut up, gcc */ + assert(ExerciserState_GetNuArchive(pState) != nil); + assert(argc == 4); - return NuRename(ExerciserState_GetNuArchive(pState), - strtol(argv[1], nil, 0), argv[2], argv[3][0]); + return NuRename(ExerciserState_GetNuArchive(pState), + strtol(argv[1], nil, 0), argv[2], argv[3][0]); } /* @@ -911,11 +911,11 @@ RenameFunc(ExerciserState* pState, int argc, char** argv) static NuError SetErrorCallbackFunc(ExerciserState* pState, int argc, char** argv) { - (void) pState, (void) argc, (void) argv; /* shut up, gcc */ - assert(ExerciserState_GetNuArchive(pState) != nil); - assert(argc == 1); + (void) pState, (void) argc, (void) argv; /* shut up, gcc */ + assert(ExerciserState_GetNuArchive(pState) != nil); + assert(argc == 1); - return NuSetErrorHandler(ExerciserState_GetNuArchive(pState), ErrorHandler); + return NuSetErrorHandler(ExerciserState_GetNuArchive(pState), ErrorHandler); } /* @@ -926,12 +926,12 @@ SetErrorCallbackFunc(ExerciserState* pState, int argc, char** argv) static NuError SetValueFunc(ExerciserState* pState, int argc, char** argv) { - (void) pState, (void) argc, (void) argv; /* shut up, gcc */ - assert(ExerciserState_GetNuArchive(pState) != nil); - assert(argc == 3); + (void) pState, (void) argc, (void) argv; /* shut up, gcc */ + assert(ExerciserState_GetNuArchive(pState) != nil); + assert(argc == 3); - return NuSetValue(ExerciserState_GetNuArchive(pState), - (NuValueID) strtol(argv[1], nil, 0), strtol(argv[2], nil, 0)); + return NuSetValue(ExerciserState_GetNuArchive(pState), + (NuValueID) strtol(argv[1], nil, 0), strtol(argv[2], nil, 0)); } /* @@ -945,25 +945,25 @@ SetValueFunc(ExerciserState* pState, int argc, char** argv) static NuError SetRecordAttrFunc(ExerciserState* pState, int argc, char** argv) { - NuError err; - const NuRecord* pRecord; - NuRecordAttr recordAttr; + NuError err; + const NuRecord* pRecord; + NuRecordAttr recordAttr; - (void) pState, (void) argc, (void) argv; /* shut up, gcc */ - assert(ExerciserState_GetNuArchive(pState) != nil); - assert(argc == 4); + (void) pState, (void) argc, (void) argv; /* shut up, gcc */ + assert(ExerciserState_GetNuArchive(pState) != nil); + assert(argc == 4); - err = NuGetRecord(ExerciserState_GetNuArchive(pState), - strtol(argv[1], nil, 0), &pRecord); - if (err != kNuErrNone) - return err; - printf("Exerciser: NuGetRecord succeeded, calling NuSetRecordAttr\n"); - NuRecordCopyAttr(&recordAttr, pRecord); - recordAttr.fileType = strtol(argv[2], nil, 0); - recordAttr.extraType = strtol(argv[3], nil, 0); - /*recordAttr.fileSysInfo = ':';*/ - return NuSetRecordAttr(ExerciserState_GetNuArchive(pState), - strtol(argv[1], nil, 0), &recordAttr); + err = NuGetRecord(ExerciserState_GetNuArchive(pState), + strtol(argv[1], nil, 0), &pRecord); + if (err != kNuErrNone) + return err; + printf("Exerciser: NuGetRecord succeeded, calling NuSetRecordAttr\n"); + NuRecordCopyAttr(&recordAttr, pRecord); + recordAttr.fileType = strtol(argv[2], nil, 0); + recordAttr.extraType = strtol(argv[3], nil, 0); + /*recordAttr.fileSysInfo = ':';*/ + return NuSetRecordAttr(ExerciserState_GetNuArchive(pState), + strtol(argv[1], nil, 0), &recordAttr); } /* @@ -972,11 +972,11 @@ SetRecordAttrFunc(ExerciserState* pState, int argc, char** argv) static NuError TestFunc(ExerciserState* pState, int argc, char** argv) { - (void) pState, (void) argc, (void) argv; /* shut up, gcc */ - assert(ExerciserState_GetNuArchive(pState) != nil); - assert(argc == 1); + (void) pState, (void) argc, (void) argv; /* shut up, gcc */ + assert(ExerciserState_GetNuArchive(pState) != nil); + assert(argc == 1); - return NuTest(ExerciserState_GetNuArchive(pState)); + return NuTest(ExerciserState_GetNuArchive(pState)); } /* @@ -985,43 +985,43 @@ TestFunc(ExerciserState* pState, int argc, char** argv) static NuError UpdatePresizedThreadFunc(ExerciserState* pState, int argc, char** argv) { - NuError err; - NuDataSource* pDataSource = nil; - char* lineBuf = nil; - long ourLen, maxLen; + NuError err; + NuDataSource* pDataSource = nil; + char* lineBuf = nil; + long ourLen, maxLen; - (void) pState, (void) argc, (void) argv; /* shut up, gcc */ - assert(ExerciserState_GetNuArchive(pState) != nil); - assert(argc == 2); + (void) pState, (void) argc, (void) argv; /* shut up, gcc */ + assert(ExerciserState_GetNuArchive(pState) != nil); + assert(argc == 2); - lineBuf = (char*)malloc(kNiceLineLen); - assert(lineBuf != nil); - err = GetLine("Enter data for thread", lineBuf, kNiceLineLen); - if (err != kNuErrNone) - goto bail; + lineBuf = (char*)malloc(kNiceLineLen); + assert(lineBuf != nil); + err = GetLine("Enter data for thread", lineBuf, kNiceLineLen); + if (err != kNuErrNone) + goto bail; - ourLen = strlen(lineBuf); + ourLen = strlen(lineBuf); - /* use "ourLen" for both buffer len and data len */ - err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed, - true, ourLen, (unsigned char*)lineBuf, 0, ourLen, &pDataSource); - if (err != kNuErrNone) { - fprintf(stderr, "Exerciser: data source create failed (err=%d)\n", - err); - goto bail; - } - lineBuf = nil; /* now owned by the library */ + /* use "ourLen" for both buffer len and data len */ + err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed, + true, ourLen, (unsigned char*)lineBuf, 0, ourLen, &pDataSource); + if (err != kNuErrNone) { + fprintf(stderr, "Exerciser: data source create failed (err=%d)\n", + err); + goto bail; + } + lineBuf = nil; /* now owned by the library */ - err = NuUpdatePresizedThread(ExerciserState_GetNuArchive(pState), - strtol(argv[1], nil, 0), pDataSource, &maxLen); - if (err == kNuErrNone) - printf("Exerciser: success; function returned maxLen=%ld\n", maxLen); + err = NuUpdatePresizedThread(ExerciserState_GetNuArchive(pState), + strtol(argv[1], nil, 0), pDataSource, &maxLen); + if (err == kNuErrNone) + printf("Exerciser: success; function returned maxLen=%ld\n", maxLen); bail: - NuFreeDataSource(pDataSource); - if (lineBuf != nil) - free(lineBuf); - return err; + NuFreeDataSource(pDataSource); + if (lineBuf != nil) + free(lineBuf); + return err; } @@ -1030,91 +1030,91 @@ bail: */ /* flags for the CommandTable */ -#define kFlagArchiveReq (1L) /* must have archive open */ -#define kFlagNoArchiveReq (1L<<1) /* must NOT have archive open */ +#define kFlagArchiveReq (1L) /* must have archive open */ +#define kFlagNoArchiveReq (1L<<1) /* must NOT have archive open */ /* command set */ static const struct { - const char* commandStr; - CommandFunc func; - int expectedArgCount; - const char* argumentList; - unsigned long flags; - const char* description; + const char* commandStr; + CommandFunc func; + int expectedArgCount; + const char* argumentList; + unsigned long flags; + const char* description; } gCommandTable[] = { - { "--- exerciser commands ---", HelpFunc, 0, "", 0, - "" }, - { "?", HelpFunc, 0, "", 0, - "Show help" }, - { "h", HelpFunc, 0, "", 0, - "Show help" }, - { "q", QuitFunc, 0, "", 0, - "Quit program (will abort un-flushed changes)" }, + { "--- exerciser commands ---", HelpFunc, 0, "", 0, + "" }, + { "?", HelpFunc, 0, "", 0, + "Show help" }, + { "h", HelpFunc, 0, "", 0, + "Show help" }, + { "q", QuitFunc, 0, "", 0, + "Quit program (will abort un-flushed changes)" }, - { "--- archive commands ---", HelpFunc, 0, "", 0, - "" }, + { "--- archive commands ---", HelpFunc, 0, "", 0, + "" }, - { "ab", AbortFunc, 0, "", kFlagArchiveReq, - "Abort current changes" }, - { "af", AddFileFunc, 1, "filename", kFlagArchiveReq, - "Add file" }, - { "ar", AddRecordFunc, 1, "storageName", kFlagArchiveReq, - "Add record" }, - { "at", AddThreadFunc, 2, "recordIdx threadID", kFlagArchiveReq, - "Add thread to record" }, - { "cl", CloseFunc, 0, "", kFlagArchiveReq, - "Close archive after flushing any changes" }, - { "d", DeleteFunc, 0, "", kFlagArchiveReq, - "Delete all records" }, - { "dr", DeleteRecordFunc, 1, "recordIdx", kFlagArchiveReq, - "Delete record" }, - { "dt", DeleteThreadFunc, 1, "threadIdx", kFlagArchiveReq, - "Delete thread" }, - { "e", ExtractFunc, 0, "", kFlagArchiveReq, - "Extract all files" }, - { "er", ExtractRecordFunc, 1, "recordIdx", kFlagArchiveReq, - "Extract record" }, - { "et", ExtractThreadFunc, 2, "threadIdx filename", kFlagArchiveReq, - "Extract thread" }, - { "fl", FlushFunc, 0, "", kFlagArchiveReq, - "Flush changes" }, - { "gev", GetValueFunc, 1, "ident", kFlagArchiveReq, - "Get value" }, - { "gmh", GetMasterHeaderFunc, 0, "", kFlagArchiveReq, - "Get master header" }, - { "gr", GetRecordFunc, 1, "recordIdx", kFlagArchiveReq, - "Get record" }, - { "grin", GetRecordIdxByNameFunc, 1, "name", kFlagArchiveReq, - "Get recordIdx by name" }, - { "grip", GetRecordIdxByPositionFunc, 1, "position", kFlagArchiveReq, - "Get recordIdx by position" }, - { "ocrw", OpenCreateReadWriteFunc, 1, "filename", kFlagNoArchiveReq, - "Open/create archive read-write" }, - { "oro", OpenReadOnlyFunc, 1, "filename", kFlagNoArchiveReq, - "Open archive read-only" }, - { "ors", OpenStreamingReadOnlyFunc, 1, "filename", kFlagNoArchiveReq, - "Open archive streaming read-only" }, - { "orw", OpenReadWriteFunc, 1, "filename", kFlagNoArchiveReq, - "Open archive read-write" }, - { "p", PrintFunc, 0, "", kFlagArchiveReq, - "Print archive contents" }, - { "pd", PrintDebugFunc, 0, "", kFlagArchiveReq, - "Print debugging output (if available)" }, - { "re", RenameFunc, 3, "recordIdx name sep", kFlagArchiveReq, - "Rename record" }, - { "sec", SetErrorCallbackFunc, 0, "", kFlagArchiveReq, - "Set error callback" }, - { "sev", SetValueFunc, 2, "ident value", kFlagArchiveReq, - "Set value" }, - { "sra", SetRecordAttrFunc, 3, "recordIdx type aux", kFlagArchiveReq, - "Set record attributes" }, - { "t", TestFunc, 0, "", kFlagArchiveReq, - "Test archive" }, - { "upt", UpdatePresizedThreadFunc, 1, "threadIdx", kFlagArchiveReq, - "Update pre-sized thread" }, + { "ab", AbortFunc, 0, "", kFlagArchiveReq, + "Abort current changes" }, + { "af", AddFileFunc, 1, "filename", kFlagArchiveReq, + "Add file" }, + { "ar", AddRecordFunc, 1, "storageName", kFlagArchiveReq, + "Add record" }, + { "at", AddThreadFunc, 2, "recordIdx threadID", kFlagArchiveReq, + "Add thread to record" }, + { "cl", CloseFunc, 0, "", kFlagArchiveReq, + "Close archive after flushing any changes" }, + { "d", DeleteFunc, 0, "", kFlagArchiveReq, + "Delete all records" }, + { "dr", DeleteRecordFunc, 1, "recordIdx", kFlagArchiveReq, + "Delete record" }, + { "dt", DeleteThreadFunc, 1, "threadIdx", kFlagArchiveReq, + "Delete thread" }, + { "e", ExtractFunc, 0, "", kFlagArchiveReq, + "Extract all files" }, + { "er", ExtractRecordFunc, 1, "recordIdx", kFlagArchiveReq, + "Extract record" }, + { "et", ExtractThreadFunc, 2, "threadIdx filename", kFlagArchiveReq, + "Extract thread" }, + { "fl", FlushFunc, 0, "", kFlagArchiveReq, + "Flush changes" }, + { "gev", GetValueFunc, 1, "ident", kFlagArchiveReq, + "Get value" }, + { "gmh", GetMasterHeaderFunc, 0, "", kFlagArchiveReq, + "Get master header" }, + { "gr", GetRecordFunc, 1, "recordIdx", kFlagArchiveReq, + "Get record" }, + { "grin", GetRecordIdxByNameFunc, 1, "name", kFlagArchiveReq, + "Get recordIdx by name" }, + { "grip", GetRecordIdxByPositionFunc, 1, "position", kFlagArchiveReq, + "Get recordIdx by position" }, + { "ocrw", OpenCreateReadWriteFunc, 1, "filename", kFlagNoArchiveReq, + "Open/create archive read-write" }, + { "oro", OpenReadOnlyFunc, 1, "filename", kFlagNoArchiveReq, + "Open archive read-only" }, + { "ors", OpenStreamingReadOnlyFunc, 1, "filename", kFlagNoArchiveReq, + "Open archive streaming read-only" }, + { "orw", OpenReadWriteFunc, 1, "filename", kFlagNoArchiveReq, + "Open archive read-write" }, + { "p", PrintFunc, 0, "", kFlagArchiveReq, + "Print archive contents" }, + { "pd", PrintDebugFunc, 0, "", kFlagArchiveReq, + "Print debugging output (if available)" }, + { "re", RenameFunc, 3, "recordIdx name sep", kFlagArchiveReq, + "Rename record" }, + { "sec", SetErrorCallbackFunc, 0, "", kFlagArchiveReq, + "Set error callback" }, + { "sev", SetValueFunc, 2, "ident value", kFlagArchiveReq, + "Set value" }, + { "sra", SetRecordAttrFunc, 3, "recordIdx type aux", kFlagArchiveReq, + "Set record attributes" }, + { "t", TestFunc, 0, "", kFlagArchiveReq, + "Test archive" }, + { "upt", UpdatePresizedThreadFunc, 1, "threadIdx", kFlagArchiveReq, + "Update pre-sized thread" }, }; -#define kMaxArgs 4 +#define kMaxArgs 4 /* * Display a summary of available commands. @@ -1122,25 +1122,25 @@ static const struct { static NuError HelpFunc(ExerciserState* pState, int argc, char** argv) { - int i; + int i; - (void) pState, (void) argc, (void) argv; /* shut up, gcc */ + (void) pState, (void) argc, (void) argv; /* shut up, gcc */ - printf("\nAvailable commands:\n"); - for (i = 0; i < (int)NELEM(gCommandTable); i++) { - printf(" %-4s %-21s %s\n", - gCommandTable[i].commandStr, - gCommandTable[i].argumentList, - gCommandTable[i].description); - } + printf("\nAvailable commands:\n"); + for (i = 0; i < (int)NELEM(gCommandTable); i++) { + printf(" %-4s %-21s %s\n", + gCommandTable[i].commandStr, + gCommandTable[i].argumentList, + gCommandTable[i].description); + } - return kNuErrNone; + return kNuErrNone; } /* * =========================================================================== - * Control + * Control * =========================================================================== */ @@ -1154,89 +1154,89 @@ static const char* kWhitespace = " \t\n"; */ static NuError ParseLine(char* lineBuf, ExerciserState* pState, CommandFunc* pFunc, int* pArgc, - char*** pArgv) + char*** pArgv) { - NuError err = kNuErrSyntax; - char* command; - char* cp; - int i; + NuError err = kNuErrSyntax; + char* command; + char* cp; + int i; - /* - * Parse the strings. - */ + /* + * Parse the strings. + */ - command = strtok(lineBuf, kWhitespace); - if (command == nil) { - /* no command; the user probably just hit "enter" on a blank line */ - *pFunc = NothingFunc; - *pArgc = 0; - *pArgv = nil; - err = kNuErrNone; - goto bail; - } + command = strtok(lineBuf, kWhitespace); + if (command == nil) { + /* no command; the user probably just hit "enter" on a blank line */ + *pFunc = NothingFunc; + *pArgc = 0; + *pArgv = nil; + err = kNuErrNone; + goto bail; + } - /* no real need to be flexible; add 1 for command and one for nil */ - *pArgv = (char**) malloc(sizeof(char*) * (kMaxArgs+2)); - (*pArgv)[0] = command; - *pArgc = 1; + /* no real need to be flexible; add 1 for command and one for nil */ + *pArgv = (char**) malloc(sizeof(char*) * (kMaxArgs+2)); + (*pArgv)[0] = command; + *pArgc = 1; - cp = strtok(nil, kWhitespace); - while (cp != nil) { - if (*pArgc >= kMaxArgs+1) { - printf("ERROR: too many arguments\n"); - goto bail; - } - (*pArgv)[*pArgc] = cp; - (*pArgc)++; + cp = strtok(nil, kWhitespace); + while (cp != nil) { + if (*pArgc >= kMaxArgs+1) { + printf("ERROR: too many arguments\n"); + goto bail; + } + (*pArgv)[*pArgc] = cp; + (*pArgc)++; - cp = strtok(nil, kWhitespace); - } - assert(*pArgc < kMaxArgs+2); - (*pArgv)[*pArgc] = nil; + cp = strtok(nil, kWhitespace); + } + assert(*pArgc < kMaxArgs+2); + (*pArgv)[*pArgc] = nil; - /* - * Look up the command. - */ - for (i = 0; i < (int)NELEM(gCommandTable); i++) { - if (strcmp(command, gCommandTable[i].commandStr) == 0) - break; - } - if (i == NELEM(gCommandTable)) { - printf("ERROR: unrecognized command\n"); - goto bail; - } + /* + * Look up the command. + */ + for (i = 0; i < (int)NELEM(gCommandTable); i++) { + if (strcmp(command, gCommandTable[i].commandStr) == 0) + break; + } + if (i == NELEM(gCommandTable)) { + printf("ERROR: unrecognized command\n"); + goto bail; + } - *pFunc = gCommandTable[i].func; + *pFunc = gCommandTable[i].func; - /* - * Check arguments and flags. - */ - if (*pArgc -1 != gCommandTable[i].expectedArgCount) { - printf("ERROR: expected %d args, found %d\n", - gCommandTable[i].expectedArgCount, *pArgc -1); - goto bail; - } + /* + * Check arguments and flags. + */ + if (*pArgc -1 != gCommandTable[i].expectedArgCount) { + printf("ERROR: expected %d args, found %d\n", + gCommandTable[i].expectedArgCount, *pArgc -1); + goto bail; + } - if (gCommandTable[i].flags & kFlagArchiveReq) { - if (ExerciserState_GetNuArchive(pState) == nil) { - printf("ERROR: must have an archive open\n"); - goto bail; - } - } - if (gCommandTable[i].flags & kFlagNoArchiveReq) { - if (ExerciserState_GetNuArchive(pState) != nil) { - printf("ERROR: an archive is already open\n"); - goto bail; - } - } + if (gCommandTable[i].flags & kFlagArchiveReq) { + if (ExerciserState_GetNuArchive(pState) == nil) { + printf("ERROR: must have an archive open\n"); + goto bail; + } + } + if (gCommandTable[i].flags & kFlagNoArchiveReq) { + if (ExerciserState_GetNuArchive(pState) != nil) { + printf("ERROR: an archive is already open\n"); + goto bail; + } + } - /* - * Looks good! - */ - err = kNuErrNone; + /* + * Looks good! + */ + err = kNuErrNone; bail: - return err; + return err; } @@ -1247,66 +1247,66 @@ bail: static NuError CommandLoop(void) { - NuError err = kNuErrNone; - ExerciserState* pState = ExerciserState_New(); - CommandFunc func; - char lineBuf[128]; - int argc; - char** argv = nil; + NuError err = kNuErrNone; + ExerciserState* pState = ExerciserState_New(); + CommandFunc func; + char lineBuf[128]; + int argc; + char** argv = nil; - while (1) { - printf("\nEnter command (%s)> ", ExerciserState_GetArchiveFile(pState)); - fflush(stdout); + while (1) { + printf("\nEnter command (%s)> ", ExerciserState_GetArchiveFile(pState)); + fflush(stdout); - if (fgets(lineBuf, sizeof(lineBuf), stdin) == nil) { - printf("\n"); - break; - } + if (fgets(lineBuf, sizeof(lineBuf), stdin) == nil) { + printf("\n"); + break; + } - if (argv != nil) { - free(argv); - argv = nil; - } + if (argv != nil) { + free(argv); + argv = nil; + } - func = nil; /* sanity check */ + func = nil; /* sanity check */ - err = ParseLine(lineBuf, pState, &func, &argc, &argv); - if (err != kNuErrNone) - continue; + err = ParseLine(lineBuf, pState, &func, &argc, &argv); + if (err != kNuErrNone) + continue; - assert(func != nil); - if (func == QuitFunc) - break; + assert(func != nil); + if (func == QuitFunc) + break; - err = (*func)(pState, argc, argv); + err = (*func)(pState, argc, argv); - if (err < 0) - printf("Exerciser: received error %d (%s)\n", err, NuStrError(err)); - else if (err > 0) - printf("Exerciser: received error %d\n", err); + if (err < 0) + printf("Exerciser: received error %d (%s)\n", err, NuStrError(err)); + else if (err > 0) + printf("Exerciser: received error %d\n", err); - if (argv != nil) { - free(argv); - argv = nil; - } - } + if (argv != nil) { + free(argv); + argv = nil; + } + } - if (ExerciserState_GetNuArchive(pState) != nil) { - /* ought to query the archive before saying something like this... */ - printf("Exerciser: aborting any un-flushed changes in archive %s\n", - ExerciserState_GetArchivePath(pState)); - (void) NuAbort(ExerciserState_GetNuArchive(pState)); - err = NuClose(ExerciserState_GetNuArchive(pState)); - if (err != kNuErrNone) - printf("Exerciser: got error %d closing archive\n", err); - ExerciserState_SetNuArchive(pState, nil); - } + if (ExerciserState_GetNuArchive(pState) != nil) { + /* ought to query the archive before saying something like this... */ + printf("Exerciser: aborting any un-flushed changes in archive %s\n", + ExerciserState_GetArchivePath(pState)); + (void) NuAbort(ExerciserState_GetNuArchive(pState)); + err = NuClose(ExerciserState_GetNuArchive(pState)); + if (err != kNuErrNone) + printf("Exerciser: got error %d closing archive\n", err); + ExerciserState_SetNuArchive(pState, nil); + } - if (pState != nil) - free(pState); - if (argv != nil) - free(argv); - return kNuErrNone; + if (pState != nil) + free(pState); + if (argv != nil) + free(argv); + return kNuErrNone; } @@ -1318,43 +1318,43 @@ CommandLoop(void) int main(void) { - NuError result; - long majorVersion, minorVersion, bugVersion; - const char* nufxLibDate; - const char* nufxLibFlags; + NuError result; + long majorVersion, minorVersion, bugVersion; + const char* nufxLibDate; + const char* nufxLibFlags; - (void) NuGetVersion(&majorVersion, &minorVersion, &bugVersion, - &nufxLibDate, &nufxLibFlags); - printf("NufxLib exerciser, linked with NufxLib v%ld.%ld.%ld [%s]\n\n", - majorVersion, minorVersion, bugVersion, nufxLibFlags); + (void) NuGetVersion(&majorVersion, &minorVersion, &bugVersion, + &nufxLibDate, &nufxLibFlags); + printf("NufxLib exerciser, linked with NufxLib v%ld.%ld.%ld [%s]\n\n", + majorVersion, minorVersion, bugVersion, nufxLibFlags); - /* stuff useful when debugging lots */ - if (unlink(kTempFile) == 0) - fprintf(stderr, "NOTE: whacked exer-temp\n"); - if (unlink("new.shk") == 0) - fprintf(stderr, "NOTE: whacked new.shk\n"); + /* stuff useful when debugging lots */ + if (unlink(kTempFile) == 0) + fprintf(stderr, "NOTE: whacked exer-temp\n"); + if (unlink("new.shk") == 0) + fprintf(stderr, "NOTE: whacked new.shk\n"); #if defined(HAS_MALLOC_CHECK_) && !defined(USE_DMALLOC) - /* - * This is really nice to have on Linux and any other system that - * uses the GNU libc/malloc stuff. It slows things down, but it - * tells you when you do something dumb with malloc/realloc/free. - * (Solaris 2.7 has a similar feature that is enabled by setting the - * environment variable LD_PRELOAD to include watchmalloc.so. Other - * OSs and 3rd-party malloc packages may have similar features.) - * - * This environment variable must be set when the program is launched. - * Tweaking the environment within the program has no effect. - */ - { - char* debugSet = getenv("MALLOC_CHECK_"); - if (debugSet == nil) - printf("WARNING: MALLOC_CHECK_ not enabled\n\n"); - } + /* + * This is really nice to have on Linux and any other system that + * uses the GNU libc/malloc stuff. It slows things down, but it + * tells you when you do something dumb with malloc/realloc/free. + * (Solaris 2.7 has a similar feature that is enabled by setting the + * environment variable LD_PRELOAD to include watchmalloc.so. Other + * OSs and 3rd-party malloc packages may have similar features.) + * + * This environment variable must be set when the program is launched. + * Tweaking the environment within the program has no effect. + */ + { + char* debugSet = getenv("MALLOC_CHECK_"); + if (debugSet == nil) + printf("WARNING: MALLOC_CHECK_ not enabled\n\n"); + } #endif - result = CommandLoop(); + result = CommandLoop(); - exit(result != kNuErrNone); + exit(result != kNuErrNone); } diff --git a/nufxlib-0/samples/ImgConv.c b/nufxlib-0/samples/ImgConv.c index 24acf27..981c012 100644 --- a/nufxlib-0/samples/ImgConv.c +++ b/nufxlib-0/samples/ImgConv.c @@ -22,43 +22,43 @@ int Nu_strcasecmp(const char *s1, const char *s2); #endif -#define kTempFile "imgconv.tmp" -#define kLocalFssep PATH_SEP -#define false 0 -#define true (!false) +#define kTempFile "imgconv.tmp" +#define kLocalFssep PATH_SEP +#define false 0 +#define true (!false) /* * =========================================================================== - * 2IMG stuff + * 2IMG stuff * =========================================================================== */ -#define kImgMagic "2IMG" -#define kMyCreator "NFXL" +#define kImgMagic "2IMG" +#define kMyCreator "NFXL" -#define kImageFormatDOS 0 -#define kImageFormatProDOS 1 -#define kImageFormatNibble 2 +#define kImageFormatDOS 0 +#define kImageFormatProDOS 1 +#define kImageFormatNibble 2 /* * 2IMG header definition (http://www.magnet.ch/emutech/Tech/). */ typedef struct ImgHeader { - char magic[4]; - char creator[4]; - short headerLen; - short version; - long imageFormat; - unsigned long flags; - long numBlocks; - long dataOffset; - long dataLen; - long cmntOffset; - long cmntLen; - long creatorOffset; - long creatorLen; - long spare[4]; + char magic[4]; + char creator[4]; + short headerLen; + short version; + long imageFormat; + unsigned long flags; + long numBlocks; + long dataOffset; + long dataLen; + long cmntOffset; + long cmntLen; + long creatorOffset; + long creatorLen; + long spare[4]; } ImgHeader; /* @@ -67,8 +67,8 @@ typedef struct ImgHeader { void ReadShortLE(FILE* fp, short* pBuf) { - *pBuf = getc(fp); - *pBuf += (short) getc(fp) << 8; + *pBuf = getc(fp); + *pBuf += (short) getc(fp) << 8; } /* @@ -77,8 +77,8 @@ ReadShortLE(FILE* fp, short* pBuf) void WriteShortLE(FILE* fp, unsigned short val) { - putc(val, fp); - putc(val >> 8, fp); + putc(val, fp); + putc(val >> 8, fp); } /* @@ -87,10 +87,10 @@ WriteShortLE(FILE* fp, unsigned short val) void ReadLongLE(FILE* fp, long* pBuf) { - *pBuf = getc(fp); - *pBuf += (long) getc(fp) << 8; - *pBuf += (long) getc(fp) << 16; - *pBuf += (long) getc(fp) << 24; + *pBuf = getc(fp); + *pBuf += (long) getc(fp) << 8; + *pBuf += (long) getc(fp) << 16; + *pBuf += (long) getc(fp) << 24; } /* @@ -99,10 +99,10 @@ ReadLongLE(FILE* fp, long* pBuf) void WriteLongLE(FILE* fp, unsigned long val) { - putc(val, fp); - putc(val >> 8, fp); - putc(val >> 16, fp); - putc(val >> 24, fp); + putc(val, fp); + putc(val >> 8, fp); + putc(val >> 16, fp); + putc(val >> 24, fp); } /* @@ -111,38 +111,38 @@ WriteLongLE(FILE* fp, unsigned long val) int ReadImgHeader(FILE* fp, ImgHeader* pHeader) { - fread(pHeader->magic, 4, 1, fp); - fread(pHeader->creator, 4, 1, fp); - ReadShortLE(fp, &pHeader->headerLen); - ReadShortLE(fp, &pHeader->version); - ReadLongLE(fp, &pHeader->imageFormat); - ReadLongLE(fp, (long*)&pHeader->flags); - ReadLongLE(fp, &pHeader->numBlocks); - ReadLongLE(fp, &pHeader->dataOffset); - ReadLongLE(fp, &pHeader->dataLen); - ReadLongLE(fp, &pHeader->cmntOffset); - ReadLongLE(fp, &pHeader->cmntLen); - ReadLongLE(fp, &pHeader->creatorOffset); - ReadLongLE(fp, &pHeader->creatorLen); - ReadLongLE(fp, &pHeader->spare[0]); - ReadLongLE(fp, &pHeader->spare[1]); - ReadLongLE(fp, &pHeader->spare[2]); - ReadLongLE(fp, &pHeader->spare[3]); + fread(pHeader->magic, 4, 1, fp); + fread(pHeader->creator, 4, 1, fp); + ReadShortLE(fp, &pHeader->headerLen); + ReadShortLE(fp, &pHeader->version); + ReadLongLE(fp, &pHeader->imageFormat); + ReadLongLE(fp, (long*)&pHeader->flags); + ReadLongLE(fp, &pHeader->numBlocks); + ReadLongLE(fp, &pHeader->dataOffset); + ReadLongLE(fp, &pHeader->dataLen); + ReadLongLE(fp, &pHeader->cmntOffset); + ReadLongLE(fp, &pHeader->cmntLen); + ReadLongLE(fp, &pHeader->creatorOffset); + ReadLongLE(fp, &pHeader->creatorLen); + ReadLongLE(fp, &pHeader->spare[0]); + ReadLongLE(fp, &pHeader->spare[1]); + ReadLongLE(fp, &pHeader->spare[2]); + ReadLongLE(fp, &pHeader->spare[3]); - if (feof(fp) || ferror(fp)) - return -1; + if (feof(fp) || ferror(fp)) + return -1; - if (strncmp(pHeader->magic, kImgMagic, 4) != 0) { - fprintf(stderr, "ERROR: bad magic number on 2IMG file\n"); - return -1; - } + if (strncmp(pHeader->magic, kImgMagic, 4) != 0) { + fprintf(stderr, "ERROR: bad magic number on 2IMG file\n"); + return -1; + } - if (pHeader->version > 1) { - fprintf(stderr, "WARNING: might not be able to handle version=%d\n", - pHeader->version); - } + if (pHeader->version > 1) { + fprintf(stderr, "WARNING: might not be able to handle version=%d\n", + pHeader->version); + } - return 0; + return 0; } /* @@ -151,28 +151,28 @@ ReadImgHeader(FILE* fp, ImgHeader* pHeader) int WriteImgHeader(FILE* fp, ImgHeader* pHeader) { - fwrite(pHeader->magic, 4, 1, fp); - fwrite(pHeader->creator, 4, 1, fp); - WriteShortLE(fp, pHeader->headerLen); - WriteShortLE(fp, pHeader->version); - WriteLongLE(fp, pHeader->imageFormat); - WriteLongLE(fp, pHeader->flags); - WriteLongLE(fp, pHeader->numBlocks); - WriteLongLE(fp, pHeader->dataOffset); - WriteLongLE(fp, pHeader->dataLen); - WriteLongLE(fp, pHeader->cmntOffset); - WriteLongLE(fp, pHeader->cmntLen); - WriteLongLE(fp, pHeader->creatorOffset); - WriteLongLE(fp, pHeader->creatorLen); - WriteLongLE(fp, pHeader->spare[0]); - WriteLongLE(fp, pHeader->spare[1]); - WriteLongLE(fp, pHeader->spare[2]); - WriteLongLE(fp, pHeader->spare[3]); + fwrite(pHeader->magic, 4, 1, fp); + fwrite(pHeader->creator, 4, 1, fp); + WriteShortLE(fp, pHeader->headerLen); + WriteShortLE(fp, pHeader->version); + WriteLongLE(fp, pHeader->imageFormat); + WriteLongLE(fp, pHeader->flags); + WriteLongLE(fp, pHeader->numBlocks); + WriteLongLE(fp, pHeader->dataOffset); + WriteLongLE(fp, pHeader->dataLen); + WriteLongLE(fp, pHeader->cmntOffset); + WriteLongLE(fp, pHeader->cmntLen); + WriteLongLE(fp, pHeader->creatorOffset); + WriteLongLE(fp, pHeader->creatorLen); + WriteLongLE(fp, pHeader->spare[0]); + WriteLongLE(fp, pHeader->spare[1]); + WriteLongLE(fp, pHeader->spare[2]); + WriteLongLE(fp, pHeader->spare[3]); - if (ferror(fp)) - return -1; + if (ferror(fp)) + return -1; - return 0; + return 0; } @@ -182,27 +182,27 @@ WriteImgHeader(FILE* fp, ImgHeader* pHeader) void DumpImgHeader(ImgHeader* pHeader) { - printf("--- header contents:\n"); - printf("\tmagic = '%.4s'\n", pHeader->magic); - printf("\tcreator = '%.4s'\n", pHeader->creator); - printf("\theaderLen = %d\n", pHeader->headerLen); - printf("\tversion = %d\n", pHeader->version); - printf("\timageFormat = %ld\n", pHeader->imageFormat); - printf("\tflags = 0x%08lx\n", pHeader->flags); - printf("\tnumBlocks = %ld\n", pHeader->numBlocks); - printf("\tdataOffset = %ld\n", pHeader->dataOffset); - printf("\tdataLen = %ld\n", pHeader->dataLen); - printf("\tcmntOffset = %ld\n", pHeader->cmntOffset); - printf("\tcmntLen = %ld\n", pHeader->cmntLen); - printf("\tcreatorOffset = %ld\n", pHeader->creatorOffset); - printf("\tcreatorLen = %ld\n", pHeader->creatorLen); - printf("\n"); + printf("--- header contents:\n"); + printf("\tmagic = '%.4s'\n", pHeader->magic); + printf("\tcreator = '%.4s'\n", pHeader->creator); + printf("\theaderLen = %d\n", pHeader->headerLen); + printf("\tversion = %d\n", pHeader->version); + printf("\timageFormat = %ld\n", pHeader->imageFormat); + printf("\tflags = 0x%08lx\n", pHeader->flags); + printf("\tnumBlocks = %ld\n", pHeader->numBlocks); + printf("\tdataOffset = %ld\n", pHeader->dataOffset); + printf("\tdataLen = %ld\n", pHeader->dataLen); + printf("\tcmntOffset = %ld\n", pHeader->cmntOffset); + printf("\tcmntLen = %ld\n", pHeader->cmntLen); + printf("\tcreatorOffset = %ld\n", pHeader->creatorOffset); + printf("\tcreatorLen = %ld\n", pHeader->creatorLen); + printf("\n"); } /* * =========================================================================== - * Main functions + * Main functions * =========================================================================== */ @@ -214,10 +214,10 @@ typedef enum ArchiveKind { kKindUnknown, kKindShk, kKindImg } ArchiveKind; */ NuError CreateProdosSource(const ImgHeader* pHeader, FILE* fp, - NuDataSource** ppDataSource) + NuDataSource** ppDataSource) { - return NuCreateDataSourceForFP(kNuThreadFormatUncompressed, false, 0, fp, - pHeader->dataOffset, pHeader->dataLen, ppDataSource); + return NuCreateDataSourceForFP(kNuThreadFormatUncompressed, false, 0, fp, + pHeader->dataOffset, pHeader->dataLen, ppDataSource); } /* @@ -226,76 +226,76 @@ CreateProdosSource(const ImgHeader* pHeader, FILE* fp, */ NuError CreateDosSource(const ImgHeader* pHeader, FILE* fp, - NuDataSource** ppDataSource) + NuDataSource** ppDataSource) { - NuError err; - char* diskBuffer = nil; - long offset; + NuError err; + char* diskBuffer = nil; + long offset; - if (pHeader->dataLen % 4096) { - fprintf(stderr, - "ERROR: image size must be multiple of 4096 (%ld isn't)\n", - pHeader->dataLen); - err = kNuErrGeneric; - goto bail; - } + if (pHeader->dataLen % 4096) { + fprintf(stderr, + "ERROR: image size must be multiple of 4096 (%ld isn't)\n", + pHeader->dataLen); + err = kNuErrGeneric; + goto bail; + } - if (fseek(fp, pHeader->dataOffset, SEEK_SET) < 0) { - err = errno; - perror("fseek failed"); - goto bail; - } + if (fseek(fp, pHeader->dataOffset, SEEK_SET) < 0) { + err = errno; + perror("fseek failed"); + goto bail; + } - diskBuffer = malloc(pHeader->dataLen); - if (diskBuffer == nil) { - fprintf(stderr, "ERROR: malloc(%ld) failed\n", pHeader->dataLen); - err = kNuErrMalloc; - goto bail; - } + diskBuffer = malloc(pHeader->dataLen); + if (diskBuffer == nil) { + fprintf(stderr, "ERROR: malloc(%ld) failed\n", pHeader->dataLen); + err = kNuErrMalloc; + goto bail; + } - /* - * Run through the image, reordering each track. This is a - * reversible transformation, i.e. if you do this twice you're back - * to ProDOS ordering. - */ - for (offset = 0; offset < pHeader->dataLen; offset += 4096) { - fread(diskBuffer + offset + 0x0000, 256, 1, fp); - fread(diskBuffer + offset + 0x0e00, 256, 1, fp); - fread(diskBuffer + offset + 0x0d00, 256, 1, fp); - fread(diskBuffer + offset + 0x0c00, 256, 1, fp); - fread(diskBuffer + offset + 0x0b00, 256, 1, fp); - fread(diskBuffer + offset + 0x0a00, 256, 1, fp); - fread(diskBuffer + offset + 0x0900, 256, 1, fp); - fread(diskBuffer + offset + 0x0800, 256, 1, fp); - fread(diskBuffer + offset + 0x0700, 256, 1, fp); - fread(diskBuffer + offset + 0x0600, 256, 1, fp); - fread(diskBuffer + offset + 0x0500, 256, 1, fp); - fread(diskBuffer + offset + 0x0400, 256, 1, fp); - fread(diskBuffer + offset + 0x0300, 256, 1, fp); - fread(diskBuffer + offset + 0x0200, 256, 1, fp); - fread(diskBuffer + offset + 0x0100, 256, 1, fp); - fread(diskBuffer + offset + 0x0f00, 256, 1, fp); - } - if (feof(fp) || ferror(fp)) { - err = errno ? errno : -1; - fprintf(stderr, "ERROR: failed while reading source file\n"); - goto bail; - } + /* + * Run through the image, reordering each track. This is a + * reversible transformation, i.e. if you do this twice you're back + * to ProDOS ordering. + */ + for (offset = 0; offset < pHeader->dataLen; offset += 4096) { + fread(diskBuffer + offset + 0x0000, 256, 1, fp); + fread(diskBuffer + offset + 0x0e00, 256, 1, fp); + fread(diskBuffer + offset + 0x0d00, 256, 1, fp); + fread(diskBuffer + offset + 0x0c00, 256, 1, fp); + fread(diskBuffer + offset + 0x0b00, 256, 1, fp); + fread(diskBuffer + offset + 0x0a00, 256, 1, fp); + fread(diskBuffer + offset + 0x0900, 256, 1, fp); + fread(diskBuffer + offset + 0x0800, 256, 1, fp); + fread(diskBuffer + offset + 0x0700, 256, 1, fp); + fread(diskBuffer + offset + 0x0600, 256, 1, fp); + fread(diskBuffer + offset + 0x0500, 256, 1, fp); + fread(diskBuffer + offset + 0x0400, 256, 1, fp); + fread(diskBuffer + offset + 0x0300, 256, 1, fp); + fread(diskBuffer + offset + 0x0200, 256, 1, fp); + fread(diskBuffer + offset + 0x0100, 256, 1, fp); + fread(diskBuffer + offset + 0x0f00, 256, 1, fp); + } + if (feof(fp) || ferror(fp)) { + err = errno ? errno : -1; + fprintf(stderr, "ERROR: failed while reading source file\n"); + goto bail; + } - /* - * Create a data source for the buffer. We set the "doClose" flag to - * "true", so NufxLib will free the buffer for us. - */ - err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed, true, 0, - (const unsigned char*) diskBuffer, 0, pHeader->dataLen, - ppDataSource); - if (err == kNuErrNone) - diskBuffer = nil; + /* + * Create a data source for the buffer. We set the "doClose" flag to + * "true", so NufxLib will free the buffer for us. + */ + err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed, true, 0, + (const unsigned char*) diskBuffer, 0, pHeader->dataLen, + ppDataSource); + if (err == kNuErrNone) + diskBuffer = nil; bail: - if (diskBuffer != nil) - free(diskBuffer); - return err; + if (diskBuffer != nil) + free(diskBuffer); + return err; } @@ -309,146 +309,146 @@ bail: int ConvertFromImgToShk(const char* srcName, const char* dstName) { - NuError err; - NuArchive* pArchive = nil; - NuDataSource* pDataSource = nil; - NuRecordIdx recordIdx; - NuFileDetails fileDetails; - ImgHeader header; - FILE* fp = nil; - long flushStatus; - char* storageName = nil; - char* cp; + NuError err; + NuArchive* pArchive = nil; + NuDataSource* pDataSource = nil; + NuRecordIdx recordIdx; + NuFileDetails fileDetails; + ImgHeader header; + FILE* fp = nil; + long flushStatus; + char* storageName = nil; + char* cp; - printf("Converting 2IMG file '%s' to ShrinkIt archive '%s'\n\n", - srcName, dstName); + printf("Converting 2IMG file '%s' to ShrinkIt archive '%s'\n\n", + srcName, dstName); - err = kNuErrGeneric; + err = kNuErrGeneric; - fp = fopen(srcName, kNuFileOpenReadOnly); - if (fp == NULL) { - perror("fopen failed"); - goto bail; - } + fp = fopen(srcName, kNuFileOpenReadOnly); + if (fp == NULL) { + perror("fopen failed"); + goto bail; + } - if (ReadImgHeader(fp, &header) < 0) { - fprintf(stderr, "ERROR: header read failed\n"); - goto bail; - } + if (ReadImgHeader(fp, &header) < 0) { + fprintf(stderr, "ERROR: header read failed\n"); + goto bail; + } - DumpImgHeader(&header); + DumpImgHeader(&header); - if (header.imageFormat != kImageFormatDOS && - header.imageFormat != kImageFormatProDOS) - { - fprintf(stderr, "ERROR: can only handle DOS and ProDOS images\n"); - goto bail; - } + if (header.imageFormat != kImageFormatDOS && + header.imageFormat != kImageFormatProDOS) + { + fprintf(stderr, "ERROR: can only handle DOS and ProDOS images\n"); + goto bail; + } - if (header.numBlocks > 1600) - printf("WARNING: that's a big honking image!\n"); + if (header.numBlocks > 1600) + printf("WARNING: that's a big honking image!\n"); - /* - * Open a new archive read-write. This refuses to overwrite an - * existing file. - */ - (void) unlink(kTempFile); - err = NuOpenRW(dstName, kTempFile, kNuOpenCreat|kNuOpenExcl, &pArchive); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: unable to create archive (err=%d)\n", err); - goto bail; - } + /* + * Open a new archive read-write. This refuses to overwrite an + * existing file. + */ + (void) unlink(kTempFile); + err = NuOpenRW(dstName, kTempFile, kNuOpenCreat|kNuOpenExcl, &pArchive); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: unable to create archive (err=%d)\n", err); + goto bail; + } - /* create the name that will be stored in the archive */ - storageName = strdup(dstName); - cp = strrchr(storageName, '.'); - if (cp != nil) - *cp = '\0'; - cp = strrchr(storageName, kLocalFssep); - if (cp != nil && *(cp+1) != '\0') - cp++; - else - cp = storageName; + /* create the name that will be stored in the archive */ + storageName = strdup(dstName); + cp = strrchr(storageName, '.'); + if (cp != nil) + *cp = '\0'; + cp = strrchr(storageName, kLocalFssep); + if (cp != nil && *(cp+1) != '\0') + cp++; + else + cp = storageName; - /* - * We can't say "add file", because NufxLib doesn't know what a 2MG - * archive is. However, we can point a DataSource at the data in - * the file, and construct the record manually. - */ + /* + * We can't say "add file", because NufxLib doesn't know what a 2MG + * archive is. However, we can point a DataSource at the data in + * the file, and construct the record manually. + */ - /* set up the contents of the NuFX Record */ - memset(&fileDetails, 0, sizeof(fileDetails)); - fileDetails.storageName = cp; - fileDetails.fileSysID = kNuFileSysUnknown; /* DOS? ProDOS? */ - fileDetails.fileSysInfo = kLocalFssep; - fileDetails.access = kNuAccessUnlocked; - fileDetails.extraType = header.numBlocks; - fileDetails.storageType = 512; - /* FIX - ought to set the file dates */ + /* set up the contents of the NuFX Record */ + memset(&fileDetails, 0, sizeof(fileDetails)); + fileDetails.storageName = cp; + fileDetails.fileSysID = kNuFileSysUnknown; /* DOS? ProDOS? */ + fileDetails.fileSysInfo = kLocalFssep; + fileDetails.access = kNuAccessUnlocked; + fileDetails.extraType = header.numBlocks; + fileDetails.storageType = 512; + /* FIX - ought to set the file dates */ - /* add a new record */ - err = NuAddRecord(pArchive, &fileDetails, &recordIdx); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: unable to create record (err=%d)\n", err); - goto bail; - } + /* add a new record */ + err = NuAddRecord(pArchive, &fileDetails, &recordIdx); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: unable to create record (err=%d)\n", err); + goto bail; + } - /* - * Create a data source for the 2IMG file. We do this differently - * for DOS and ProDOS, because we have to rearrange the sector - * ordering for DOS-ordered images (ShrinkIt always uses ProDOS order). - */ - switch (header.imageFormat) { - case kImageFormatDOS: - err = CreateDosSource(&header, fp, &pDataSource); - break; - case kImageFormatProDOS: - err = CreateProdosSource(&header, fp, &pDataSource); - break; - default: - fprintf(stderr, "How the heck did I get here?"); - err = kNuErrInternal; - goto bail; - } - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: unable to create data source (err=%d)\n", err); - goto bail; - } + /* + * Create a data source for the 2IMG file. We do this differently + * for DOS and ProDOS, because we have to rearrange the sector + * ordering for DOS-ordered images (ShrinkIt always uses ProDOS order). + */ + switch (header.imageFormat) { + case kImageFormatDOS: + err = CreateDosSource(&header, fp, &pDataSource); + break; + case kImageFormatProDOS: + err = CreateProdosSource(&header, fp, &pDataSource); + break; + default: + fprintf(stderr, "How the heck did I get here?"); + err = kNuErrInternal; + goto bail; + } + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: unable to create data source (err=%d)\n", err); + goto bail; + } - /* add a disk image thread */ - err = NuAddThread(pArchive, recordIdx, kNuThreadIDDiskImage, pDataSource, - nil); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: unable to create thread (err=%d)\n", err); - goto bail; - } - pDataSource = nil; /* library owns it now */ + /* add a disk image thread */ + err = NuAddThread(pArchive, recordIdx, kNuThreadIDDiskImage, pDataSource, + nil); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: unable to create thread (err=%d)\n", err); + goto bail; + } + pDataSource = nil; /* library owns it now */ - /* nothing happens until we Flush */ - err = NuFlush(pArchive, &flushStatus); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: flush failed (err=%d, status=0x%04lx)\n", - err, flushStatus); - goto bail; - } - err = NuClose(pArchive); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: close failed (err=%d)\n", err); - goto bail; - } - pArchive = nil; + /* nothing happens until we Flush */ + err = NuFlush(pArchive, &flushStatus); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: flush failed (err=%d, status=0x%04lx)\n", + err, flushStatus); + goto bail; + } + err = NuClose(pArchive); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: close failed (err=%d)\n", err); + goto bail; + } + pArchive = nil; bail: - if (pArchive != nil) { - (void)NuAbort(pArchive); - (void)NuClose(pArchive); - } - NuFreeDataSource(pDataSource); - if (storageName != nil) - free(storageName); - if (fp != nil) - fclose(fp); - return (err == kNuErrNone) ? 0 : -1; + if (pArchive != nil) { + (void)NuAbort(pArchive); + (void)NuClose(pArchive); + } + NuFreeDataSource(pDataSource); + if (storageName != nil) + free(storageName); + if (fp != nil) + fclose(fp); + return (err == kNuErrNone) ? 0 : -1; } @@ -461,109 +461,109 @@ bail: int ConvertFromShkToImg(const char* srcName, const char* dstName) { - NuError err; - NuArchive* pArchive = nil; - NuDataSink* pDataSink = nil; - NuRecordIdx recordIdx; - const NuRecord* pRecord; - const NuThread* pThread = nil; - ImgHeader header; - FILE* fp = nil; - int idx; + NuError err; + NuArchive* pArchive = nil; + NuDataSink* pDataSink = nil; + NuRecordIdx recordIdx; + const NuRecord* pRecord; + const NuThread* pThread = nil; + ImgHeader header; + FILE* fp = nil; + int idx; - printf("Converting ShrinkIt archive '%s' to 2IMG file '%s'\n\n", - srcName, dstName); + printf("Converting ShrinkIt archive '%s' to 2IMG file '%s'\n\n", + srcName, dstName); - /* - * Open the archive. - */ - err = NuOpenRO(srcName, &pArchive); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: unable to open archive (err=%d)\n", err); - goto bail; - } + /* + * Open the archive. + */ + err = NuOpenRO(srcName, &pArchive); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: unable to open archive (err=%d)\n", err); + goto bail; + } - /* get the first record */ - err = NuGetRecordIdxByPosition(pArchive, 0, &recordIdx); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: unable to get first recordIdx (err=%d)\n", err); - goto bail; - } - err = NuGetRecord(pArchive, recordIdx, &pRecord); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: unable to get first record (err=%d)\n", err); - goto bail; - } + /* get the first record */ + err = NuGetRecordIdxByPosition(pArchive, 0, &recordIdx); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: unable to get first recordIdx (err=%d)\n", err); + goto bail; + } + err = NuGetRecord(pArchive, recordIdx, &pRecord); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: unable to get first record (err=%d)\n", err); + goto bail; + } - /* find a disk image thread */ - for (idx = 0; idx < (int)NuRecordGetNumThreads(pRecord); idx++) { - pThread = NuGetThread(pRecord, idx); + /* find a disk image thread */ + for (idx = 0; idx < (int)NuRecordGetNumThreads(pRecord); idx++) { + pThread = NuGetThread(pRecord, idx); - if (NuGetThreadID(pThread) == kNuThreadIDDiskImage) - break; - } - if (idx == (int)NuRecordGetNumThreads(pRecord)) { - fprintf(stderr, "ERROR: no disk image found in first record\n"); - err = -1; - goto bail; - } + if (NuGetThreadID(pThread) == kNuThreadIDDiskImage) + break; + } + if (idx == (int)NuRecordGetNumThreads(pRecord)) { + fprintf(stderr, "ERROR: no disk image found in first record\n"); + err = -1; + goto bail; + } - /* - * Looks good. Open the 2IMG file, and create the header. - */ - if (access(dstName, F_OK) == 0) { - fprintf(stderr, "ERROR: output file already exists\n"); - err = -1; - goto bail; - } + /* + * Looks good. Open the 2IMG file, and create the header. + */ + if (access(dstName, F_OK) == 0) { + fprintf(stderr, "ERROR: output file already exists\n"); + err = -1; + goto bail; + } - fp = fopen(dstName, kNuFileOpenWriteTrunc); - if (fp == NULL) { - perror("fopen failed"); - goto bail; - } + fp = fopen(dstName, kNuFileOpenWriteTrunc); + if (fp == NULL) { + perror("fopen failed"); + goto bail; + } - /* set up the 2MG header, based on the NuFX Record */ - memset(&header, 0, sizeof(header)); - memcpy(header.magic, kImgMagic, sizeof(header.magic)); - memcpy(header.creator, kMyCreator, sizeof(header.creator)); - header.headerLen = 64; - header.version = 1; - header.imageFormat = kImageFormatProDOS; /* always ProDOS-order */ - header.numBlocks = pRecord->recExtraType; - header.dataOffset = 64; - /* old versions of ShrinkIt blew the threadEOF, so use NufxLib's "actual" */ - header.dataLen = pThread->actualThreadEOF; - DumpImgHeader(&header); - if (WriteImgHeader(fp, &header) < 0) { - fprintf(stderr, "ERROR: header write failed\n"); - err = -1; - goto bail; - } + /* set up the 2MG header, based on the NuFX Record */ + memset(&header, 0, sizeof(header)); + memcpy(header.magic, kImgMagic, sizeof(header.magic)); + memcpy(header.creator, kMyCreator, sizeof(header.creator)); + header.headerLen = 64; + header.version = 1; + header.imageFormat = kImageFormatProDOS; /* always ProDOS-order */ + header.numBlocks = pRecord->recExtraType; + header.dataOffset = 64; + /* old versions of ShrinkIt blew the threadEOF, so use NufxLib's "actual" */ + header.dataLen = pThread->actualThreadEOF; + DumpImgHeader(&header); + if (WriteImgHeader(fp, &header) < 0) { + fprintf(stderr, "ERROR: header write failed\n"); + err = -1; + goto bail; + } - /* - * We want to expand the disk image thread into "fp" at the current - * offset. - */ - err = NuCreateDataSinkForFP(true, kNuConvertOff, fp, &pDataSink); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: unable to create data sink (err=%d)\n", err); - goto bail; - } + /* + * We want to expand the disk image thread into "fp" at the current + * offset. + */ + err = NuCreateDataSinkForFP(true, kNuConvertOff, fp, &pDataSink); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: unable to create data sink (err=%d)\n", err); + goto bail; + } - err = NuExtractThread(pArchive, pThread->threadIdx, pDataSink); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: unable to extract thread (err=%d)\n", err); - goto bail; - } + err = NuExtractThread(pArchive, pThread->threadIdx, pDataSink); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: unable to extract thread (err=%d)\n", err); + goto bail; + } bail: - if (pArchive != nil) - NuClose(pArchive); - NuFreeDataSink(pDataSink); - if (fp != nil) - fclose(fp); - return (err == kNuErrNone) ? 0 : -1; + if (pArchive != nil) + NuClose(pArchive); + NuFreeDataSink(pDataSink); + if (fp != nil) + fclose(fp); + return (err == kNuErrNone) ? 0 : -1; } @@ -573,18 +573,18 @@ bail: ArchiveKind DetermineKind(const char* filename) { - const char* dot; + const char* dot; - dot = strrchr(filename, '.'); - if (dot == nil) - return kKindUnknown; + dot = strrchr(filename, '.'); + if (dot == nil) + return kKindUnknown; - if (strcasecmp(dot, ".shk") == 0 || strcasecmp(dot, ".sdk") == 0) - return kKindShk; - else if (strcasecmp(dot, ".2mg") == 0) - return kKindImg; + if (strcasecmp(dot, ".shk") == 0 || strcasecmp(dot, ".sdk") == 0) + return kKindShk; + else if (strcasecmp(dot, ".2mg") == 0) + return kKindImg; - return kKindUnknown; + return kKindUnknown; } @@ -595,30 +595,30 @@ DetermineKind(const char* filename) int main(int argc, char** argv) { - ArchiveKind kind; - int cc; + ArchiveKind kind; + int cc; - if (argc != 3) { - fprintf(stderr, "Usage: %s (input.2mg|input.shk) output\n", argv[0]); - exit(2); - } + if (argc != 3) { + fprintf(stderr, "Usage: %s (input.2mg|input.shk) output\n", argv[0]); + exit(2); + } - kind = DetermineKind(argv[1]); - if (kind == kKindUnknown) { - fprintf(stderr, "ERROR: input name must end in '.shk' or '.2mg'\n"); - exit(2); - } + kind = DetermineKind(argv[1]); + if (kind == kKindUnknown) { + fprintf(stderr, "ERROR: input name must end in '.shk' or '.2mg'\n"); + exit(2); + } - if (kind == kKindShk) - cc = ConvertFromShkToImg(argv[1], argv[2]); - else - cc = ConvertFromImgToShk(argv[1], argv[2]); + if (kind == kKindShk) + cc = ConvertFromShkToImg(argv[1], argv[2]); + else + cc = ConvertFromImgToShk(argv[1], argv[2]); - if (cc) - fprintf(stderr, "Failed\n"); - else - printf("Done!\n"); + if (cc) + fprintf(stderr, "Failed\n"); + else + printf("Done!\n"); - exit(cc != 0); + exit(cc != 0); } diff --git a/nufxlib-0/samples/Launder.c b/nufxlib-0/samples/Launder.c index 32c6a99..3510c92 100644 --- a/nufxlib-0/samples/Launder.c +++ b/nufxlib-0/samples/Launder.c @@ -29,13 +29,13 @@ #include "Common.h" -#define kTempFile "tmp-laundry" +#define kTempFile "tmp-laundry" -#define kFlagCopyOnly (1) -#define kFlagReverseThreads (1 << 1) -#define kFlagFrequentFlush (1 << 2) -#define kFlagFrequentAbort (1 << 3) /* implies FrequentFlush */ -#define kFlagUseTmp (1 << 4) +#define kFlagCopyOnly (1) +#define kFlagReverseThreads (1 << 1) +#define kFlagFrequentFlush (1 << 2) +#define kFlagFrequentAbort (1 << 3) /* implies FrequentFlush */ +#define kFlagUseTmp (1 << 4) /* @@ -53,99 +53,99 @@ char gSentRecordWarning = false; */ NuError CopyThreadRecompressed(NuArchive* pInArchive, NuArchive* pOutArchive, - long flags, const NuThread* pThread, long newRecordIdx) + long flags, const NuThread* pThread, long newRecordIdx) { - NuError err = kNuErrNone; - NuDataSource* pDataSource = nil; - NuDataSink* pDataSink = nil; - uchar* buffer = nil; + NuError err = kNuErrNone; + NuDataSource* pDataSource = nil; + NuDataSink* pDataSink = nil; + uchar* buffer = nil; - /* - * Allocate a buffer large enough to hold all the uncompressed data, and - * wrap a data sink around it. - * - * If the thread is zero bytes long, we can skip this part. - */ - if (pThread->actualThreadEOF) { - buffer = malloc(pThread->actualThreadEOF); - if (buffer == nil) { - err = kNuErrMalloc; - goto bail; - } - err = NuCreateDataSinkForBuffer(true, kNuConvertOff, buffer, - pThread->actualThreadEOF, &pDataSink); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: unable to create data sink (err=%d)\n", - err); - goto bail; - } + /* + * Allocate a buffer large enough to hold all the uncompressed data, and + * wrap a data sink around it. + * + * If the thread is zero bytes long, we can skip this part. + */ + if (pThread->actualThreadEOF) { + buffer = malloc(pThread->actualThreadEOF); + if (buffer == nil) { + err = kNuErrMalloc; + goto bail; + } + err = NuCreateDataSinkForBuffer(true, kNuConvertOff, buffer, + pThread->actualThreadEOF, &pDataSink); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: unable to create data sink (err=%d)\n", + err); + goto bail; + } - /* - * Expand the data. For a pre-sized thread, this grabs only the - * interesting part of the buffer. - */ - err = NuExtractThread(pInArchive, pThread->threadIdx, pDataSink); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: unable to extract thread %ld (err=%d)\n", - pThread->threadIdx, err); - goto bail; - } - } + /* + * Expand the data. For a pre-sized thread, this grabs only the + * interesting part of the buffer. + */ + err = NuExtractThread(pInArchive, pThread->threadIdx, pDataSink); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: unable to extract thread %ld (err=%d)\n", + pThread->threadIdx, err); + goto bail; + } + } - /* - * The expanded data is in the buffer, now create a data source that - * describes it. - * - * This is complicated by the existence of pre-sized threads, which - * require us to set "otherLen". - * - * We always use "actualThreadEOF" because "thThreadEOF" is broken - * for disk archives created by certain versions of ShrinkIt. - * - * It's okay to pass in a nil value for "buffer", so long as the - * amount of data in the buffer is also zero. The library will do - * the right thing. - */ - if (NuIsPresizedThreadID(NuGetThreadID(pThread))) { - err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed, true, - pThread->thCompThreadEOF, buffer, 0, - pThread->actualThreadEOF, &pDataSource); - if (err != kNuErrNone) { - fprintf(stderr, - "ERROR: unable to create pre-sized data source (err=%d)\n",err); - goto bail; - } - } else { - err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed, true, - 0, buffer, 0, - pThread->actualThreadEOF, &pDataSource); - if (err != kNuErrNone) { - fprintf(stderr, - "ERROR: unable to create data source (err=%d)\n", err); - goto bail; - } - } - buffer = nil; /* doClose was set, so it's owned by the data source */ + /* + * The expanded data is in the buffer, now create a data source that + * describes it. + * + * This is complicated by the existence of pre-sized threads, which + * require us to set "otherLen". + * + * We always use "actualThreadEOF" because "thThreadEOF" is broken + * for disk archives created by certain versions of ShrinkIt. + * + * It's okay to pass in a nil value for "buffer", so long as the + * amount of data in the buffer is also zero. The library will do + * the right thing. + */ + if (NuIsPresizedThreadID(NuGetThreadID(pThread))) { + err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed, true, + pThread->thCompThreadEOF, buffer, 0, + pThread->actualThreadEOF, &pDataSource); + if (err != kNuErrNone) { + fprintf(stderr, + "ERROR: unable to create pre-sized data source (err=%d)\n",err); + goto bail; + } + } else { + err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed, true, + 0, buffer, 0, + pThread->actualThreadEOF, &pDataSource); + if (err != kNuErrNone) { + fprintf(stderr, + "ERROR: unable to create data source (err=%d)\n", err); + goto bail; + } + } + buffer = nil; /* doClose was set, so it's owned by the data source */ - /* - * Schedule the data for addition to the record. - */ - err = NuAddThread(pOutArchive, newRecordIdx, NuGetThreadID(pThread), - pDataSource, nil); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: unable to add thread (err=%d)\n", err); - goto bail; - } - pDataSource = nil; /* library owns it now */ + /* + * Schedule the data for addition to the record. + */ + err = NuAddThread(pOutArchive, newRecordIdx, NuGetThreadID(pThread), + pDataSource, nil); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: unable to add thread (err=%d)\n", err); + goto bail; + } + pDataSource = nil; /* library owns it now */ bail: - if (pDataSource != nil) - NuFreeDataSource(pDataSource); - if (pDataSink != nil) - NuFreeDataSink(pDataSink); - if (buffer != nil) - free(buffer); - return err; + if (pDataSource != nil) + NuFreeDataSource(pDataSource); + if (pDataSink != nil) + NuFreeDataSink(pDataSink); + if (buffer != nil) + free(buffer); + return err; } /* @@ -167,122 +167,122 @@ bail: */ NuError CopyThreadUncompressed(NuArchive* pInArchive, NuArchive* pOutArchive, - long flags, const NuThread* pThread, long newRecordIdx) + long flags, const NuThread* pThread, long newRecordIdx) { - NuError err = kNuErrNone; - NuDataSource* pDataSource = nil; - NuDataSink* pDataSink = nil; - uchar* buffer = nil; + NuError err = kNuErrNone; + NuDataSource* pDataSource = nil; + NuDataSink* pDataSink = nil; + uchar* buffer = nil; - /* - * If we have some data files that were left uncompressed, perhaps - * because of GSHK's "don't compress anything smaller than 512 bytes" - * rule, NufxLib will try to compress them. We disable this - * behavior by disabling compression. That way, stuff that is - * already compressed will remain that way, and stuff that isn't - * compressed won't be. (We really only need to do this once, at - * the start of the program, but it's illustrative to do it here.) - */ - err = NuSetValue(pOutArchive, kNuValueDataCompression, kNuCompressNone); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: unable to set compression (err=%d)\n", err); - goto bail; - } + /* + * If we have some data files that were left uncompressed, perhaps + * because of GSHK's "don't compress anything smaller than 512 bytes" + * rule, NufxLib will try to compress them. We disable this + * behavior by disabling compression. That way, stuff that is + * already compressed will remain that way, and stuff that isn't + * compressed won't be. (We really only need to do this once, at + * the start of the program, but it's illustrative to do it here.) + */ + err = NuSetValue(pOutArchive, kNuValueDataCompression, kNuCompressNone); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: unable to set compression (err=%d)\n", err); + goto bail; + } - /* - * Allocate a buffer large enough to hold all the compressed data, and - * wrap a data sink around it. - */ - buffer = malloc(pThread->thCompThreadEOF); - if (buffer == nil) { - err = kNuErrMalloc; - goto bail; - } - err = NuCreateDataSinkForBuffer(false, kNuConvertOff, buffer, - pThread->thCompThreadEOF, &pDataSink); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: unable to create data sink (err=%d)\n", - err); - goto bail; - } + /* + * Allocate a buffer large enough to hold all the compressed data, and + * wrap a data sink around it. + */ + buffer = malloc(pThread->thCompThreadEOF); + if (buffer == nil) { + err = kNuErrMalloc; + goto bail; + } + err = NuCreateDataSinkForBuffer(false, kNuConvertOff, buffer, + pThread->thCompThreadEOF, &pDataSink); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: unable to create data sink (err=%d)\n", + err); + goto bail; + } - /* - * Get the compressed data. For a pre-sized thread, this grabs the - * entire contents of the buffer, including the padding. - */ - err = NuExtractThread(pInArchive, pThread->threadIdx, pDataSink); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: unable to extract thread %ld (err=%d)\n", - pThread->threadIdx, err); - goto bail; - } + /* + * Get the compressed data. For a pre-sized thread, this grabs the + * entire contents of the buffer, including the padding. + */ + err = NuExtractThread(pInArchive, pThread->threadIdx, pDataSink); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: unable to extract thread %ld (err=%d)\n", + pThread->threadIdx, err); + goto bail; + } - /* - * The (perhaps compressed) data is in the buffer, now create a data - * source that describes it. - * - * This is complicated by the existence of pre-sized threads. There - * are two possibilities: - * 1. We have a certain amount of non-pre-sized data (thCompThreadEOF) - * that will expand out to a certain length (actualThreadEOF). - * 2. We have a certain amount of pre-sized data (actualThreadEOF) - * that will fit within a buffer (thCompThreadEOF). - * As you can see, the arguments need to be reversed for pre-sized - * threads. - * - * We always use "actualThreadEOF" because "thThreadEOF" is broken - * for disk archives created by certain versions of ShrinkIt. - */ - if (NuIsPresizedThreadID(NuGetThreadID(pThread))) { - err = NuCreateDataSourceForBuffer(pThread->thThreadFormat, true, - pThread->thCompThreadEOF, buffer, 0, - pThread->actualThreadEOF, &pDataSource); - if (err != kNuErrNone) { - fprintf(stderr, - "ERROR: unable to create pre-sized data source (err=%d)\n",err); - goto bail; - } - } else { - err = NuCreateDataSourceForBuffer(pThread->thThreadFormat, true, - pThread->actualThreadEOF, buffer, 0, - pThread->thCompThreadEOF, &pDataSource); - if (err != kNuErrNone) { - fprintf(stderr, - "ERROR: unable to create data source (err=%d)\n", err); - goto bail; - } - } - buffer = nil; /* doClose was set, so it's owned by the data source */ + /* + * The (perhaps compressed) data is in the buffer, now create a data + * source that describes it. + * + * This is complicated by the existence of pre-sized threads. There + * are two possibilities: + * 1. We have a certain amount of non-pre-sized data (thCompThreadEOF) + * that will expand out to a certain length (actualThreadEOF). + * 2. We have a certain amount of pre-sized data (actualThreadEOF) + * that will fit within a buffer (thCompThreadEOF). + * As you can see, the arguments need to be reversed for pre-sized + * threads. + * + * We always use "actualThreadEOF" because "thThreadEOF" is broken + * for disk archives created by certain versions of ShrinkIt. + */ + if (NuIsPresizedThreadID(NuGetThreadID(pThread))) { + err = NuCreateDataSourceForBuffer(pThread->thThreadFormat, true, + pThread->thCompThreadEOF, buffer, 0, + pThread->actualThreadEOF, &pDataSource); + if (err != kNuErrNone) { + fprintf(stderr, + "ERROR: unable to create pre-sized data source (err=%d)\n",err); + goto bail; + } + } else { + err = NuCreateDataSourceForBuffer(pThread->thThreadFormat, true, + pThread->actualThreadEOF, buffer, 0, + pThread->thCompThreadEOF, &pDataSource); + if (err != kNuErrNone) { + fprintf(stderr, + "ERROR: unable to create data source (err=%d)\n", err); + goto bail; + } + } + buffer = nil; /* doClose was set, so it's owned by the data source */ - /* yes, this is a kluge... sigh */ - err = NuDataSourceSetRawCrc(pDataSource, pThread->thThreadCRC); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: can't set source CRC (err=%d)\n", err); - goto bail; - } + /* yes, this is a kluge... sigh */ + err = NuDataSourceSetRawCrc(pDataSource, pThread->thThreadCRC); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: can't set source CRC (err=%d)\n", err); + goto bail; + } - /* - * Schedule the data for addition to the record. - * - * Note that NuAddThread makes a copy of the data source, and clears - * "doClose" on our copy, so we are free to dispose of pDataSource. - */ - err = NuAddThread(pOutArchive, newRecordIdx, NuGetThreadID(pThread), - pDataSource, nil); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: unable to add thread (err=%d)\n", err); - goto bail; - } - pDataSource = nil; /* library owns it now */ + /* + * Schedule the data for addition to the record. + * + * Note that NuAddThread makes a copy of the data source, and clears + * "doClose" on our copy, so we are free to dispose of pDataSource. + */ + err = NuAddThread(pOutArchive, newRecordIdx, NuGetThreadID(pThread), + pDataSource, nil); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: unable to add thread (err=%d)\n", err); + goto bail; + } + pDataSource = nil; /* library owns it now */ bail: - if (pDataSource != nil) - NuFreeDataSource(pDataSource); - if (pDataSink != nil) - NuFreeDataSink(pDataSink); - if (buffer != nil) - free(buffer); - return err; + if (pDataSource != nil) + NuFreeDataSource(pDataSource); + if (pDataSink != nil) + NuFreeDataSink(pDataSink); + if (buffer != nil) + free(buffer); + return err; } @@ -294,15 +294,15 @@ bail: */ NuError CopyThread(NuArchive* pInArchive, NuArchive* pOutArchive, long flags, - const NuThread* pThread, long newRecordIdx) + const NuThread* pThread, long newRecordIdx) { - if (flags & kFlagCopyOnly) { - return CopyThreadUncompressed(pInArchive, pOutArchive, flags, pThread, - newRecordIdx); - } else { - return CopyThreadRecompressed(pInArchive, pOutArchive, flags, pThread, - newRecordIdx); - } + if (flags & kFlagCopyOnly) { + return CopyThreadUncompressed(pInArchive, pOutArchive, flags, pThread, + newRecordIdx); + } else { + return CopyThreadRecompressed(pInArchive, pOutArchive, flags, pThread, + newRecordIdx); + } } @@ -316,91 +316,91 @@ CopyThread(NuArchive* pInArchive, NuArchive* pOutArchive, long flags, */ NuError CopyRecord(NuArchive* pInArchive, NuArchive* pOutArchive, long flags, - NuRecordIdx recordIdx) + NuRecordIdx recordIdx) { - NuError err = kNuErrNone; - const NuRecord* pRecord; - const NuThread* pThread; - NuFileDetails fileDetails; - NuRecordIdx newRecordIdx; - long numThreads; - int idx; + NuError err = kNuErrNone; + const NuRecord* pRecord; + const NuThread* pThread; + NuFileDetails fileDetails; + NuRecordIdx newRecordIdx; + long numThreads; + int idx; - /* - * Grab the original record and see how many threads it has. - */ - err = NuGetRecord(pInArchive, recordIdx, &pRecord); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: unable to get recordIdx %ld\n", recordIdx); - goto bail; - } + /* + * Grab the original record and see how many threads it has. + */ + err = NuGetRecord(pInArchive, recordIdx, &pRecord); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: unable to get recordIdx %ld\n", recordIdx); + goto bail; + } - /* - * Pre-v3 records didn't put CRCs in the thread headers. If we just - * copy the thread over without reprocessing the data, we won't compute - * a CRC for the thread, and we will get CRC failures. - */ - if (!gSentRecordWarning && (flags & kFlagCopyOnly) && - pRecord->recVersionNumber < 3) - { - printf("WARNING: pre-v3 records that aren't recompressed may exhibit CRC failures\n"); - gSentRecordWarning = true; - } + /* + * Pre-v3 records didn't put CRCs in the thread headers. If we just + * copy the thread over without reprocessing the data, we won't compute + * a CRC for the thread, and we will get CRC failures. + */ + if (!gSentRecordWarning && (flags & kFlagCopyOnly) && + pRecord->recVersionNumber < 3) + { + printf("WARNING: pre-v3 records that aren't recompressed may exhibit CRC failures\n"); + gSentRecordWarning = true; + } - numThreads = NuRecordGetNumThreads(pRecord); - if (!numThreads) { - fprintf(stderr, "WARNING: recordIdx=%ld was empty\n", recordIdx); - goto bail; - } + numThreads = NuRecordGetNumThreads(pRecord); + if (!numThreads) { + fprintf(stderr, "WARNING: recordIdx=%ld was empty\n", recordIdx); + goto bail; + } - /* - * Create a new record that looks just like the original. - */ - memset(&fileDetails, 0, sizeof(fileDetails)); - fileDetails.storageName = pRecord->filename; - fileDetails.fileSysID = pRecord->recFileSysID; - fileDetails.fileSysInfo = pRecord->recFileSysInfo; - fileDetails.access = pRecord->recAccess; - fileDetails.fileType = pRecord->recFileType; - fileDetails.extraType = pRecord->recExtraType; - fileDetails.storageType = pRecord->recStorageType; - fileDetails.createWhen = pRecord->recCreateWhen; - fileDetails.modWhen = pRecord->recModWhen; - fileDetails.archiveWhen = pRecord->recArchiveWhen; + /* + * Create a new record that looks just like the original. + */ + memset(&fileDetails, 0, sizeof(fileDetails)); + fileDetails.storageName = pRecord->filename; + fileDetails.fileSysID = pRecord->recFileSysID; + fileDetails.fileSysInfo = pRecord->recFileSysInfo; + fileDetails.access = pRecord->recAccess; + fileDetails.fileType = pRecord->recFileType; + fileDetails.extraType = pRecord->recExtraType; + fileDetails.storageType = pRecord->recStorageType; + fileDetails.createWhen = pRecord->recCreateWhen; + fileDetails.modWhen = pRecord->recModWhen; + fileDetails.archiveWhen = pRecord->recArchiveWhen; - err = NuAddRecord(pOutArchive, &fileDetails, &newRecordIdx); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: NuAddRecord failed (err=%d)\n", err); - goto bail; - } + err = NuAddRecord(pOutArchive, &fileDetails, &newRecordIdx); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: NuAddRecord failed (err=%d)\n", err); + goto bail; + } - /* - * Copy the threads. - */ - if (flags & kFlagReverseThreads) { - for (idx = numThreads-1; idx >= 0; idx--) { - pThread = NuGetThread(pRecord, idx); - assert(pThread != nil); + /* + * Copy the threads. + */ + if (flags & kFlagReverseThreads) { + for (idx = numThreads-1; idx >= 0; idx--) { + pThread = NuGetThread(pRecord, idx); + assert(pThread != nil); - err = CopyThread(pInArchive, pOutArchive, flags, pThread, - newRecordIdx); - if (err != kNuErrNone) - goto bail; - } - } else { - for (idx = 0; idx < numThreads; idx++) { - pThread = NuGetThread(pRecord, idx); - assert(pThread != nil); + err = CopyThread(pInArchive, pOutArchive, flags, pThread, + newRecordIdx); + if (err != kNuErrNone) + goto bail; + } + } else { + for (idx = 0; idx < numThreads; idx++) { + pThread = NuGetThread(pRecord, idx); + assert(pThread != nil); - err = CopyThread(pInArchive, pOutArchive, flags, pThread, - newRecordIdx); - if (err != kNuErrNone) - goto bail; - } - } + err = CopyThread(pInArchive, pOutArchive, flags, pThread, + newRecordIdx); + if (err != kNuErrNone) + goto bail; + } + } bail: - return err; + return err; } @@ -412,113 +412,113 @@ bail: int LaunderArchive(const char* inFile, const char* outFile, long flags) { - NuError err = kNuErrNone; - NuArchive* pInArchive = nil; - NuArchive* pOutArchive = nil; - const NuMasterHeader* pMasterHeader; - NuRecordIdx recordIdx; - long idx, flushStatus; + NuError err = kNuErrNone; + NuArchive* pInArchive = nil; + NuArchive* pOutArchive = nil; + const NuMasterHeader* pMasterHeader; + NuRecordIdx recordIdx; + long idx, flushStatus; - err = NuOpenRO(inFile, &pInArchive); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't open input archive '%s' (err=%d)\n", - inFile, err); - goto bail; - } - err = NuOpenRW(outFile, kTempFile, kNuOpenCreat|kNuOpenExcl, &pOutArchive); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't open output archive '%s' (err=%d)\n", - outFile, err); - goto bail; - } + err = NuOpenRO(inFile, &pInArchive); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't open input archive '%s' (err=%d)\n", + inFile, err); + goto bail; + } + err = NuOpenRW(outFile, kTempFile, kNuOpenCreat|kNuOpenExcl, &pOutArchive); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't open output archive '%s' (err=%d)\n", + outFile, err); + goto bail; + } - /* allow duplicates, in case the original archive has them */ - err = NuSetValue(pOutArchive, kNuValueAllowDuplicates, true); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't allow duplicates (err=%d)\n", err); - goto bail; - } + /* allow duplicates, in case the original archive has them */ + err = NuSetValue(pOutArchive, kNuValueAllowDuplicates, true); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't allow duplicates (err=%d)\n", err); + goto bail; + } - if (flags & kFlagUseTmp) { - err = NuSetValue(pOutArchive, kNuValueModifyOrig, false); - if (err != kNuErrNone) { - fprintf(stderr, - "ERROR: couldn't disable modify orig (err=%d)\n", err); - goto bail; - } - } + if (flags & kFlagUseTmp) { + err = NuSetValue(pOutArchive, kNuValueModifyOrig, false); + if (err != kNuErrNone) { + fprintf(stderr, + "ERROR: couldn't disable modify orig (err=%d)\n", err); + goto bail; + } + } - err = NuGetMasterHeader(pInArchive, &pMasterHeader); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't get master header (err=%d)\n", err); - goto bail; - } + err = NuGetMasterHeader(pInArchive, &pMasterHeader); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't get master header (err=%d)\n", err); + goto bail; + } - /* - * Iterate through the set of records. - */ - for (idx = 0; idx < (int)pMasterHeader->mhTotalRecords; idx++) { - err = NuGetRecordIdxByPosition(pInArchive, idx, &recordIdx); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't get record #%ld (err=%d)\n", - idx, err); - goto bail; - } + /* + * Iterate through the set of records. + */ + for (idx = 0; idx < (int)pMasterHeader->mhTotalRecords; idx++) { + err = NuGetRecordIdxByPosition(pInArchive, idx, &recordIdx); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't get record #%ld (err=%d)\n", + idx, err); + goto bail; + } - err = CopyRecord(pInArchive, pOutArchive, flags, recordIdx); - if (err != kNuErrNone) - goto bail; + err = CopyRecord(pInArchive, pOutArchive, flags, recordIdx); + if (err != kNuErrNone) + goto bail; - /* - * If "frequent abort" is set, abort what we just did and redo it. - */ - if (flags & kFlagFrequentAbort) { - printf("(abort)\n"); - err = NuAbort(pOutArchive); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: abort failed (err=%d)\n", err); - goto bail; - } + /* + * If "frequent abort" is set, abort what we just did and redo it. + */ + if (flags & kFlagFrequentAbort) { + printf("(abort)\n"); + err = NuAbort(pOutArchive); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: abort failed (err=%d)\n", err); + goto bail; + } - err = CopyRecord(pInArchive, pOutArchive, flags, recordIdx); - if (err != kNuErrNone) - goto bail; + err = CopyRecord(pInArchive, pOutArchive, flags, recordIdx); + if (err != kNuErrNone) + goto bail; - } + } - /* - * If "frequent abort" or "frequent flush" is set, flush after - * each record is copied. - */ - if ((flags & kFlagFrequentAbort) || (flags & kFlagFrequentFlush)) { - printf("(flush)\n"); - err = NuFlush(pOutArchive, &flushStatus); - if (err != kNuErrNone) { - fprintf(stderr, - "ERROR: flush failed (err=%d, status=0x%04lx)\n", - err, flushStatus); - goto bail; - } - } - } + /* + * If "frequent abort" or "frequent flush" is set, flush after + * each record is copied. + */ + if ((flags & kFlagFrequentAbort) || (flags & kFlagFrequentFlush)) { + printf("(flush)\n"); + err = NuFlush(pOutArchive, &flushStatus); + if (err != kNuErrNone) { + fprintf(stderr, + "ERROR: flush failed (err=%d, status=0x%04lx)\n", + err, flushStatus); + goto bail; + } + } + } - /* first and only flush if frequent-flushing wasn't enabled */ - err = NuFlush(pOutArchive, &flushStatus); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: flush failed (err=%d, status=0x%04lx)\n", - err, flushStatus); - goto bail; - } + /* first and only flush if frequent-flushing wasn't enabled */ + err = NuFlush(pOutArchive, &flushStatus); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: flush failed (err=%d, status=0x%04lx)\n", + err, flushStatus); + goto bail; + } bail: - if (pInArchive != nil) - NuClose(pInArchive); - if (pOutArchive != nil) { - if (err != kNuErrNone) - NuAbort(pOutArchive); - NuClose(pOutArchive); /* flush pending changes and close */ - } - return (err != kNuErrNone); + if (pInArchive != nil) + NuClose(pInArchive); + if (pOutArchive != nil) { + if (err != kNuErrNone) + NuAbort(pOutArchive); + NuClose(pOutArchive); /* flush pending changes and close */ + } + return (err != kNuErrNone); } @@ -528,7 +528,7 @@ bail: void Usage(const char* argv0) { - fprintf(stderr, "Usage: %s [-crfat] infile.shk outfile.shk\n", argv0); + fprintf(stderr, "Usage: %s [-crfat] infile.shk outfile.shk\n", argv0); } /* @@ -537,51 +537,51 @@ Usage(const char* argv0) int main(int argc, char** argv) { - long major, minor, bug; - const char* pBuildDate; - long flags = 0; - char* cp = nil; - int cc; + long major, minor, bug; + const char* pBuildDate; + long flags = 0; + char* cp = nil; + int cc; - (void) NuGetVersion(&major, &minor, &bug, &pBuildDate, nil); - printf("Using NuFX lib %ld.%ld.%ld built on or after %s\n", - major, minor, bug, pBuildDate); + (void) NuGetVersion(&major, &minor, &bug, &pBuildDate, nil); + printf("Using NuFX lib %ld.%ld.%ld built on or after %s\n", + major, minor, bug, pBuildDate); - if (argc < 3 || argc > 4) { - Usage(argv[0]); - exit(2); - } + if (argc < 3 || argc > 4) { + Usage(argv[0]); + exit(2); + } - if (argc == 4) { - cp = argv[1]; - if (*cp++ != '-') { - Usage(argv[0]); - exit(2); - } + if (argc == 4) { + cp = argv[1]; + if (*cp++ != '-') { + Usage(argv[0]); + exit(2); + } - while (*cp != '\0') { - switch (*cp) { - case 'c': flags |= kFlagCopyOnly; break; - case 'r': flags |= kFlagReverseThreads; break; - case 'f': flags |= kFlagFrequentFlush; break; - case 'a': flags |= kFlagFrequentAbort; break; - case 't': flags |= kFlagUseTmp; break; - default: - Usage(argv[0]); - exit(2); - } - cp++; - } + while (*cp != '\0') { + switch (*cp) { + case 'c': flags |= kFlagCopyOnly; break; + case 'r': flags |= kFlagReverseThreads; break; + case 'f': flags |= kFlagFrequentFlush; break; + case 'a': flags |= kFlagFrequentAbort; break; + case 't': flags |= kFlagUseTmp; break; + default: + Usage(argv[0]); + exit(2); + } + cp++; + } - argv++; - } + argv++; + } - cc = LaunderArchive(argv[1], argv[2], flags); + cc = LaunderArchive(argv[1], argv[2], flags); - if (cc == 0) - printf("Success!\n"); - else - printf("Failed.\n"); - exit(cc != 0); + if (cc == 0) + printf("Success!\n"); + else + printf("Failed.\n"); + exit(cc != 0); } diff --git a/nufxlib-0/samples/TestBasic.c b/nufxlib-0/samples/TestBasic.c index 72a278b..d1b4d4c 100644 --- a/nufxlib-0/samples/TestBasic.c +++ b/nufxlib-0/samples/TestBasic.c @@ -11,27 +11,27 @@ #include "NufxLib.h" #include "Common.h" -#define kTestArchive "nlbt.shk" -#define kTestTempFile "nlbt.tmp" +#define kTestArchive "nlbt.shk" +#define kTestTempFile "nlbt.tmp" -#define kNumEntries 3 /* how many records are we going to add? */ -#define kTestEntryBytes "bytes" -#define kTestEntryEnglish "English" -#define kTestEntryLong "three|is a fairly long filename, complete with" \ - "punctuation and other nifty/bad stuff" -#define kLocalFssep '|' +#define kNumEntries 3 /* how many records are we going to add? */ +#define kTestEntryBytes "bytes" +#define kTestEntryEnglish "English" +#define kTestEntryLong "three|is a fairly long filename, complete with" \ + "punctuation and other nifty/bad stuff" +#define kLocalFssep '|' /* * Globals. */ char gSuppressError = false; -#define FAIL_OK gSuppressError = true; -#define FAIL_BAD gSuppressError = false; +#define FAIL_OK gSuppressError = true; +#define FAIL_BAD gSuppressError = false; /* * =========================================================================== - * Helper functions + * Helper functions * =========================================================================== */ @@ -41,28 +41,28 @@ char gSuppressError = false; static char TGetReplyChar(char defaultReply) { - char tmpBuf[32]; + char tmpBuf[32]; - if (fgets(tmpBuf, sizeof(tmpBuf), stdin) == nil) - return defaultReply; - if (tmpBuf[0] == '\n' || tmpBuf[0] == '\r') - return defaultReply; + if (fgets(tmpBuf, sizeof(tmpBuf), stdin) == nil) + return defaultReply; + if (tmpBuf[0] == '\n' || tmpBuf[0] == '\r') + return defaultReply; - return tmpBuf[0]; + return tmpBuf[0]; } NuError AddSimpleRecord(NuArchive* pArchive, const char* filename, - NuRecordIdx* pRecordIdx) + NuRecordIdx* pRecordIdx) { - NuFileDetails fileDetails; + NuFileDetails fileDetails; - memset(&fileDetails, 0, sizeof(fileDetails)); - fileDetails.storageName = filename; - fileDetails.fileSysInfo = kLocalFssep; - fileDetails.access = kNuAccessUnlocked; + memset(&fileDetails, 0, sizeof(fileDetails)); + fileDetails.storageName = filename; + fileDetails.fileSysInfo = kLocalFssep; + fileDetails.access = kNuAccessUnlocked; - return NuAddRecord(pArchive, &fileDetails, pRecordIdx); + return NuAddRecord(pArchive, &fileDetails, pRecordIdx); } @@ -72,26 +72,26 @@ AddSimpleRecord(NuArchive* pArchive, const char* filename, NuResult ErrorMessageHandler(NuArchive* pArchive, void* vErrorMessage) { - const NuErrorMessage* pErrorMessage = (const NuErrorMessage*) vErrorMessage; + const NuErrorMessage* pErrorMessage = (const NuErrorMessage*) vErrorMessage; - if (gSuppressError) - return kNuOK; + if (gSuppressError) + return kNuOK; - if (pErrorMessage->isDebug) { - fprintf(stderr, "NufxLib says: [%s:%d %s] %s\n", - pErrorMessage->file, pErrorMessage->line, pErrorMessage->function, - pErrorMessage->message); - } else { - fprintf(stderr, "NufxLib says: %s\n", pErrorMessage->message); - } + if (pErrorMessage->isDebug) { + fprintf(stderr, "NufxLib says: [%s:%d %s] %s\n", + pErrorMessage->file, pErrorMessage->line, pErrorMessage->function, + pErrorMessage->message); + } else { + fprintf(stderr, "NufxLib says: %s\n", pErrorMessage->message); + } - return kNuOK; + return kNuOK; } /* * =========================================================================== - * Tests + * Tests * =========================================================================== */ @@ -102,54 +102,54 @@ ErrorMessageHandler(NuArchive* pArchive, void* vErrorMessage) int Test_OpenFlags(void) { - NuError err; - FILE* fp = nil; - NuArchive* pArchive = nil; + NuError err; + FILE* fp = nil; + NuArchive* pArchive = nil; - printf("... open zero-byte existing\n"); - fp = fopen(kTestArchive, kNuFileOpenWriteTrunc); - if (fp == nil) { - perror("fopen kTestArchive"); - goto failed; - } - fclose(fp); - fp = nil; + printf("... open zero-byte existing\n"); + fp = fopen(kTestArchive, kNuFileOpenWriteTrunc); + if (fp == nil) { + perror("fopen kTestArchive"); + goto failed; + } + fclose(fp); + fp = nil; - FAIL_OK; - err = NuOpenRW(kTestArchive, kTestTempFile, kNuOpenCreat|kNuOpenExcl, - &pArchive); - FAIL_BAD; - if (err == kNuErrNone) { - fprintf(stderr, "ERROR: file opened when it shouldn't have\n"); - goto failed; - } + FAIL_OK; + err = NuOpenRW(kTestArchive, kTestTempFile, kNuOpenCreat|kNuOpenExcl, + &pArchive); + FAIL_BAD; + if (err == kNuErrNone) { + fprintf(stderr, "ERROR: file opened when it shouldn't have\n"); + goto failed; + } - err = NuOpenRW(kTestArchive, kTestTempFile, kNuOpenCreat, &pArchive); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: file didn't open when it should have\n"); - goto failed; - } + err = NuOpenRW(kTestArchive, kTestTempFile, kNuOpenCreat, &pArchive); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: file didn't open when it should have\n"); + goto failed; + } - err = NuClose(pArchive); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: close faileded\n"); - goto failed; - } - pArchive = nil; + err = NuClose(pArchive); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: close faileded\n"); + goto failed; + } + pArchive = nil; - if (access(kTestArchive, F_OK) == 0) { - fprintf(stderr, "ERROR: archive should have been removed but wasn't\n"); - goto failed; - } + if (access(kTestArchive, F_OK) == 0) { + fprintf(stderr, "ERROR: archive should have been removed but wasn't\n"); + goto failed; + } - return 0; + return 0; failed: - if (pArchive != nil) { - NuAbort(pArchive); - NuClose(pArchive); - } - return -1; + if (pArchive != nil) { + NuAbort(pArchive); + NuClose(pArchive); + } + return -1; } @@ -159,163 +159,163 @@ failed: int Test_AddStuff(NuArchive* pArchive) { - NuError err; - uchar* buf = nil; - NuDataSource* pDataSource = nil; - NuRecordIdx recordIdx; - long status; - int i; - static const char* testMsg = - "This is a nice test message that has linefeeds in it so we can\n" - "see if the line conversion stuff is actually doing anything at\n" - "all. It's certainly nice to know that everything works the way\n" - "it's supposed to, which I suppose is why we have this nifty test\n" - "program available. It sure would be nice if everybody tested\n" - "there code, but where would Microsoft be without endless upgrades\n" - "and service packs? Bugs are what America was built on, and\n" - "anybody who says otherwise is a pinko commie lowlife. Verily.\n"; + NuError err; + uchar* buf = nil; + NuDataSource* pDataSource = nil; + NuRecordIdx recordIdx; + long status; + int i; + static const char* testMsg = + "This is a nice test message that has linefeeds in it so we can\n" + "see if the line conversion stuff is actually doing anything at\n" + "all. It's certainly nice to know that everything works the way\n" + "it's supposed to, which I suppose is why we have this nifty test\n" + "program available. It sure would be nice if everybody tested\n" + "there code, but where would Microsoft be without endless upgrades\n" + "and service packs? Bugs are what America was built on, and\n" + "anybody who says otherwise is a pinko commie lowlife. Verily.\n"; - printf("... add 'bytes' record\n"); - buf = malloc(131072); - if (buf == nil) - goto failed; - for (i = 0; i < 131072; i++) - *(buf+i) = i & 0xff; + printf("... add 'bytes' record\n"); + buf = malloc(131072); + if (buf == nil) + goto failed; + for (i = 0; i < 131072; i++) + *(buf+i) = i & 0xff; - FAIL_OK; - err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed, true, - 0, nil, 0, 131072, &pDataSource); - FAIL_BAD; - if (err == kNuErrNone) { - fprintf(stderr, "ERROR: that should've faileded!\n"); - goto failed; - } + FAIL_OK; + err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed, true, + 0, nil, 0, 131072, &pDataSource); + FAIL_BAD; + if (err == kNuErrNone) { + fprintf(stderr, "ERROR: that should've faileded!\n"); + goto failed; + } - /* - * Create a data source for the big batch of bytes. - */ - err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed, true, - 0, buf, 0, 131072, &pDataSource); - if (err != kNuErrNone) { - fprintf(stderr, - "ERROR: 'bytes' data source create faileded (err=%d)\n", err); - goto failed; - } - buf = nil; /* now owned by library */ + /* + * Create a data source for the big batch of bytes. + */ + err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed, true, + 0, buf, 0, 131072, &pDataSource); + if (err != kNuErrNone) { + fprintf(stderr, + "ERROR: 'bytes' data source create faileded (err=%d)\n", err); + goto failed; + } + buf = nil; /* now owned by library */ - err = AddSimpleRecord(pArchive, kTestEntryBytes, &recordIdx); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: 'bytes' record faileded (err=%d)\n", err); - goto failed; - } + err = AddSimpleRecord(pArchive, kTestEntryBytes, &recordIdx); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: 'bytes' record faileded (err=%d)\n", err); + goto failed; + } - err = NuAddThread(pArchive, recordIdx, kNuThreadIDDataFork, pDataSource, - nil); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: 'bytes' thread add faileded (err=%d)\n", err); - goto failed; - } - pDataSource = nil; /* now owned by library */ + err = NuAddThread(pArchive, recordIdx, kNuThreadIDDataFork, pDataSource, + nil); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: 'bytes' thread add faileded (err=%d)\n", err); + goto failed; + } + pDataSource = nil; /* now owned by library */ - /* - * Create a data source for our lovely text message. - */ - printf("... add 'English' record\n"); - err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed, false, - 0, (const uchar*)testMsg, 0, strlen(testMsg), &pDataSource); - if (err != kNuErrNone) { - fprintf(stderr, - "ERROR: 'English' source create faileded (err=%d)\n", err); - goto failed; - } + /* + * Create a data source for our lovely text message. + */ + printf("... add 'English' record\n"); + err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed, false, + 0, (const uchar*)testMsg, 0, strlen(testMsg), &pDataSource); + if (err != kNuErrNone) { + fprintf(stderr, + "ERROR: 'English' source create faileded (err=%d)\n", err); + goto failed; + } - FAIL_OK; - err = NuAddThread(pArchive, recordIdx, kNuThreadIDDataFork, pDataSource, - nil); - FAIL_BAD; - if (err == kNuErrNone) { - fprintf(stderr, "ERROR: 'English' add should've conflicted!\n"); - goto failed; - } + FAIL_OK; + err = NuAddThread(pArchive, recordIdx, kNuThreadIDDataFork, pDataSource, + nil); + FAIL_BAD; + if (err == kNuErrNone) { + fprintf(stderr, "ERROR: 'English' add should've conflicted!\n"); + goto failed; + } - FAIL_OK; - err = AddSimpleRecord(pArchive, kTestEntryBytes, &recordIdx); - FAIL_BAD; - if (err == kNuErrNone) { - fprintf(stderr, "ERROR: duplicates not allowed, should've faileded\n"); - goto failed; - } + FAIL_OK; + err = AddSimpleRecord(pArchive, kTestEntryBytes, &recordIdx); + FAIL_BAD; + if (err == kNuErrNone) { + fprintf(stderr, "ERROR: duplicates not allowed, should've faileded\n"); + goto failed; + } - err = AddSimpleRecord(pArchive, kTestEntryEnglish, &recordIdx); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: 'English' record faileded (err=%d)\n", err); - goto failed; - } + err = AddSimpleRecord(pArchive, kTestEntryEnglish, &recordIdx); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: 'English' record faileded (err=%d)\n", err); + goto failed; + } - err = NuAddThread(pArchive, recordIdx, kNuThreadIDDataFork, pDataSource, - nil); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: 'English' thread add faileded (err=%d)\n", err); - goto failed; - } - pDataSource = nil; /* now owned by library */ + err = NuAddThread(pArchive, recordIdx, kNuThreadIDDataFork, pDataSource, + nil); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: 'English' thread add faileded (err=%d)\n", err); + goto failed; + } + pDataSource = nil; /* now owned by library */ - /* - * Create an empty file with a rather non-empty name. - */ - printf("... add 'long' record\n"); - err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed, false, - 0, nil, 0, 0, &pDataSource); - if (err != kNuErrNone) { - fprintf(stderr, - "ERROR: 'English' source create faileded (err=%d)\n", err); - goto failed; - } + /* + * Create an empty file with a rather non-empty name. + */ + printf("... add 'long' record\n"); + err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed, false, + 0, nil, 0, 0, &pDataSource); + if (err != kNuErrNone) { + fprintf(stderr, + "ERROR: 'English' source create faileded (err=%d)\n", err); + goto failed; + } - err = AddSimpleRecord(pArchive, kTestEntryLong, &recordIdx); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: 'long' record faileded (err=%d)\n", err); - goto failed; - } + err = AddSimpleRecord(pArchive, kTestEntryLong, &recordIdx); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: 'long' record faileded (err=%d)\n", err); + goto failed; + } - err = NuAddThread(pArchive, recordIdx, kNuThreadIDRsrcFork, pDataSource, - nil); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: 'long' thread add faileded (err=%d)\n", err); - goto failed; - } - pDataSource = nil; /* now owned by library */ + err = NuAddThread(pArchive, recordIdx, kNuThreadIDRsrcFork, pDataSource, + nil); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: 'long' thread add faileded (err=%d)\n", err); + goto failed; + } + pDataSource = nil; /* now owned by library */ - /* - * Flush changes. - */ - err = NuFlush(pArchive, &status); - if (err != kNuErrNone) { - fprintf(stderr,"ERROR: couldn't flush after add (err=%d, status=%ld)\n", - err, status); - goto failed; - } + /* + * Flush changes. + */ + err = NuFlush(pArchive, &status); + if (err != kNuErrNone) { + fprintf(stderr,"ERROR: couldn't flush after add (err=%d, status=%ld)\n", + err, status); + goto failed; + } - /* - * Flush again; should succeed since it doesn't have to do anything. - */ - err = NuFlush(pArchive, &status); - if (err != kNuErrNone) { - fprintf(stderr,"ERROR: second add flush failed (err=%d, status=%ld)\n", - err, status); - goto failed; - } + /* + * Flush again; should succeed since it doesn't have to do anything. + */ + err = NuFlush(pArchive, &status); + if (err != kNuErrNone) { + fprintf(stderr,"ERROR: second add flush failed (err=%d, status=%ld)\n", + err, status); + goto failed; + } - return 0; + return 0; failed: - if (pDataSource != nil) - NuFreeDataSource(pDataSource); - if (buf != nil) - free(buf); - return -1; + if (pDataSource != nil) + NuFreeDataSource(pDataSource); + if (buf != nil) + free(buf); + return -1; } @@ -325,17 +325,17 @@ failed: NuResult TestContentsCallback(NuArchive* pArchive, void* vpRecord) { - const NuRecord* pRecord = (NuRecord*) vpRecord; + const NuRecord* pRecord = (NuRecord*) vpRecord; - if (strcmp(pRecord->filename, kTestEntryBytes) == 0 || - strcmp(pRecord->filename, kTestEntryEnglish) == 0 || - strcmp(pRecord->filename, kTestEntryLong) == 0) - { - return kNuOK; - } + if (strcmp(pRecord->filename, kTestEntryBytes) == 0 || + strcmp(pRecord->filename, kTestEntryEnglish) == 0 || + strcmp(pRecord->filename, kTestEntryLong) == 0) + { + return kNuOK; + } - fprintf(stderr, "ERROR: found mystery entry '%s'\n", pRecord->filename); - return kNuAbort; + fprintf(stderr, "ERROR: found mystery entry '%s'\n", pRecord->filename); + return kNuAbort; } @@ -345,78 +345,78 @@ TestContentsCallback(NuArchive* pArchive, void* vpRecord) int Test_Contents(NuArchive* pArchive) { - NuError err; - long posn; - NuRecordIdx recordIdx; - const NuRecord* pRecord; - int cc; + NuError err; + long posn; + NuRecordIdx recordIdx; + const NuRecord* pRecord; + int cc; - /* - * First, do it with a callback. - */ - err = NuContents(pArchive, TestContentsCallback); - if (err != kNuErrNone) - goto failed; + /* + * First, do it with a callback. + */ + err = NuContents(pArchive, TestContentsCallback); + if (err != kNuErrNone) + goto failed; - /* - * Now step through the records with get-by-position and verify that - * they're in the expected order. - */ - for (posn = 0; posn < kNumEntries; posn++) { - err = NuGetRecordIdxByPosition(pArchive, posn, &recordIdx); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't get record #%ld (err=%d)\n", - posn, err); - goto failed; - } + /* + * Now step through the records with get-by-position and verify that + * they're in the expected order. + */ + for (posn = 0; posn < kNumEntries; posn++) { + err = NuGetRecordIdxByPosition(pArchive, posn, &recordIdx); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't get record #%ld (err=%d)\n", + posn, err); + goto failed; + } - err = NuGetRecord(pArchive, recordIdx, &pRecord); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't get record index %ld (err=%d)\n", - recordIdx, err); - goto failed; - } - assert(pRecord != nil); + err = NuGetRecord(pArchive, recordIdx, &pRecord); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't get record index %ld (err=%d)\n", + recordIdx, err); + goto failed; + } + assert(pRecord != nil); - switch (posn) { - case 0: - cc = strcmp(pRecord->filename, kTestEntryBytes); - break; - case 1: - cc = strcmp(pRecord->filename, kTestEntryEnglish); - break; - case 2: - cc = strcmp(pRecord->filename, kTestEntryLong); - if (!cc) - cc = !(pRecord->recStorageType == kNuStorageExtended); - break; - default: - fprintf(stderr, "ERROR: somebody forgot to put a case here (%ld)\n", - posn); - cc = -1; - } + switch (posn) { + case 0: + cc = strcmp(pRecord->filename, kTestEntryBytes); + break; + case 1: + cc = strcmp(pRecord->filename, kTestEntryEnglish); + break; + case 2: + cc = strcmp(pRecord->filename, kTestEntryLong); + if (!cc) + cc = !(pRecord->recStorageType == kNuStorageExtended); + break; + default: + fprintf(stderr, "ERROR: somebody forgot to put a case here (%ld)\n", + posn); + cc = -1; + } - if (cc) { - fprintf(stderr, "ERROR: got '%s' for %ld (%ld), not expected\n", - pRecord->filename, posn, recordIdx); - goto failed; - } - } + if (cc) { + fprintf(stderr, "ERROR: got '%s' for %ld (%ld), not expected\n", + pRecord->filename, posn, recordIdx); + goto failed; + } + } - /* - * Read one more past the end, should fail. - */ - FAIL_OK; - err = NuGetRecordIdxByPosition(pArchive, posn, &recordIdx); - FAIL_BAD; - if (err == kNuErrNone) { - fprintf(stderr, "ERROR: too many records (%ld was ok)\n", posn); - goto failed; - } + /* + * Read one more past the end, should fail. + */ + FAIL_OK; + err = NuGetRecordIdxByPosition(pArchive, posn, &recordIdx); + FAIL_BAD; + if (err == kNuErrNone) { + fprintf(stderr, "ERROR: too many records (%ld was ok)\n", posn); + goto failed; + } - return 0; + return 0; failed: - return -1; + return -1; } @@ -426,34 +426,34 @@ failed: NuResult VerifySelectionCallback(NuArchive* pArchive, void* vpProposal) { - NuError err; - const NuSelectionProposal* pProposal = vpProposal; - long count; + NuError err; + const NuSelectionProposal* pProposal = vpProposal; + long count; - if (pProposal->pRecord == nil || pProposal->pThread == nil || - pProposal->pRecord->filename == nil) - { - fprintf(stderr, "ERROR: unexpected nil in proposal\n"); - goto failed; - } + if (pProposal->pRecord == nil || pProposal->pThread == nil || + pProposal->pRecord->filename == nil) + { + fprintf(stderr, "ERROR: unexpected nil in proposal\n"); + goto failed; + } - err = NuGetExtraData(pArchive, (void**) &count); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: unable to get extra data (err=%d)\n", err); - goto failed; - } + err = NuGetExtraData(pArchive, (void**) &count); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: unable to get extra data (err=%d)\n", err); + goto failed; + } - count++; + count++; - err = NuSetExtraData(pArchive, (void*) count); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: unable to inc extra data (err=%d)\n", err); - goto failed; - } + err = NuSetExtraData(pArchive, (void*) count); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: unable to inc extra data (err=%d)\n", err); + goto failed; + } - return kNuOK; + return kNuOK; failed: - return kNuAbort; + return kNuAbort; } /* @@ -462,44 +462,44 @@ failed: int Test_Verify(NuArchive* pArchive) { - NuError err; - long count; + NuError err; + long count; - printf("... verifying CRCs\n"); + printf("... verifying CRCs\n"); - err = NuSetSelectionFilter(pArchive, VerifySelectionCallback); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: unable to set selection filter (err=%d)\n",err); - goto failed; - } + err = NuSetSelectionFilter(pArchive, VerifySelectionCallback); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: unable to set selection filter (err=%d)\n",err); + goto failed; + } - err = NuSetExtraData(pArchive, (void*) 0); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: unable to set extra data (err=%d)\n", err); - goto failed; - } + err = NuSetExtraData(pArchive, (void*) 0); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: unable to set extra data (err=%d)\n", err); + goto failed; + } - err = NuTest(pArchive); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: verify failed (err=%d)\n", err); - goto failed; - } + err = NuTest(pArchive); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: verify failed (err=%d)\n", err); + goto failed; + } - err = NuGetExtraData(pArchive, (void**) &count); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: last extra data get failed (err=%d)\n", err); - goto failed; - } + err = NuGetExtraData(pArchive, (void**) &count); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: last extra data get failed (err=%d)\n", err); + goto failed; + } - if (count != kNumEntries) { - fprintf(stderr, "ERROR: verified %ld when expecting %d\n", count, - kNumEntries); - goto failed; - } + if (count != kNumEntries) { + fprintf(stderr, "ERROR: verified %ld when expecting %d\n", count, + kNumEntries); + goto failed; + } - return 0; + return 0; failed: - return -1; + return -1; } /* @@ -508,258 +508,258 @@ failed: int Test_Extract(NuArchive* pArchive) { - NuError err; - NuRecordIdx recordIdx; - const NuRecord* pRecord; - const NuThread* pThread; - NuDataSink* pDataSink = nil; - uchar* buf = nil; + NuError err; + NuRecordIdx recordIdx; + const NuRecord* pRecord; + const NuThread* pThread; + NuDataSink* pDataSink = nil; + uchar* buf = nil; - printf("... extracting files\n"); + printf("... extracting files\n"); - /* - * Tell it the current system uses CRLF, so it'll bloat up when we do - * a text conversion. - */ - err = NuSetValue(pArchive, kNuValueEOL, kNuEOLCRLF); + /* + * Tell it the current system uses CRLF, so it'll bloat up when we do + * a text conversion. + */ + err = NuSetValue(pArchive, kNuValueEOL, kNuEOLCRLF); - /* - * Extract "bytes". - */ - err = NuGetRecordIdxByName(pArchive, kTestEntryBytes, &recordIdx); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't find '%s' (err=%d)\n", kTestEntryBytes, - err); - goto failed; - } - err = NuGetRecord(pArchive, recordIdx, &pRecord); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't get record index %ld (err=%d)\n", - recordIdx, err); - goto failed; - } - assert(pRecord != nil); + /* + * Extract "bytes". + */ + err = NuGetRecordIdxByName(pArchive, kTestEntryBytes, &recordIdx); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't find '%s' (err=%d)\n", kTestEntryBytes, + err); + goto failed; + } + err = NuGetRecord(pArchive, recordIdx, &pRecord); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't get record index %ld (err=%d)\n", + recordIdx, err); + goto failed; + } + assert(pRecord != nil); - /* we're not using ShrinkIt compat mode, so there should not be a comment */ - pThread = NuGetThread(pRecord, 1); - assert(pThread != nil); - if (NuGetThreadID(pThread) != kNuThreadIDDataFork) { - fprintf(stderr, "ERROR: 'bytes' had unexpected threadID 0x%08lx\n", - NuGetThreadID(pThread)); - goto failed; - } + /* we're not using ShrinkIt compat mode, so there should not be a comment */ + pThread = NuGetThread(pRecord, 1); + assert(pThread != nil); + if (NuGetThreadID(pThread) != kNuThreadIDDataFork) { + fprintf(stderr, "ERROR: 'bytes' had unexpected threadID 0x%08lx\n", + NuGetThreadID(pThread)); + goto failed; + } - buf = malloc(pThread->actualThreadEOF); - if (buf == nil) { - fprintf(stderr, "ERROR: malloc(%ld) failed\n",pThread->actualThreadEOF); - goto failed; - } + buf = malloc(pThread->actualThreadEOF); + if (buf == nil) { + fprintf(stderr, "ERROR: malloc(%ld) failed\n",pThread->actualThreadEOF); + goto failed; + } - /* - * Try to extract it with text conversion off. - */ - err = NuCreateDataSinkForBuffer(true, kNuConvertOff, buf, - pThread->actualThreadEOF, &pDataSink); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't create data sink (err=%d)\n", err); - goto failed; - } + /* + * Try to extract it with text conversion off. + */ + err = NuCreateDataSinkForBuffer(true, kNuConvertOff, buf, + pThread->actualThreadEOF, &pDataSink); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't create data sink (err=%d)\n", err); + goto failed; + } - err = NuExtractThread(pArchive, pThread->threadIdx, pDataSink); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't extract 'bytes' (off) (err=%d)\n", - err); - goto failed; - } - NuFreeDataSink(pDataSink); - pDataSink = nil; + err = NuExtractThread(pArchive, pThread->threadIdx, pDataSink); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't extract 'bytes' (off) (err=%d)\n", + err); + goto failed; + } + NuFreeDataSink(pDataSink); + pDataSink = nil; - /* - * Try to extract with "on" conversion, which should fail because the - * buffer is too small. - */ - err = NuCreateDataSinkForBuffer(true, kNuConvertOn, buf, - pThread->actualThreadEOF, &pDataSink); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't create data sink (err=%d)\n", err); - goto failed; - } + /* + * Try to extract with "on" conversion, which should fail because the + * buffer is too small. + */ + err = NuCreateDataSinkForBuffer(true, kNuConvertOn, buf, + pThread->actualThreadEOF, &pDataSink); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't create data sink (err=%d)\n", err); + goto failed; + } - FAIL_OK; - err = NuExtractThread(pArchive, pThread->threadIdx, pDataSink); - FAIL_BAD; - if (err == kNuErrNone) { - fprintf(stderr, "ERROR: managed to extract bloated 'bytes'?\n"); - goto failed; - } - NuFreeDataSink(pDataSink); - pDataSink = nil; + FAIL_OK; + err = NuExtractThread(pArchive, pThread->threadIdx, pDataSink); + FAIL_BAD; + if (err == kNuErrNone) { + fprintf(stderr, "ERROR: managed to extract bloated 'bytes'?\n"); + goto failed; + } + NuFreeDataSink(pDataSink); + pDataSink = nil; - /* - * Try to extract with "auto" conversion, which should conclude that - * the input is text and not try to convert. - */ - err = NuCreateDataSinkForBuffer(true, kNuConvertAuto, buf, - pThread->actualThreadEOF, &pDataSink); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't create data sink (err=%d)\n", err); - goto failed; - } + /* + * Try to extract with "auto" conversion, which should conclude that + * the input is text and not try to convert. + */ + err = NuCreateDataSinkForBuffer(true, kNuConvertAuto, buf, + pThread->actualThreadEOF, &pDataSink); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't create data sink (err=%d)\n", err); + goto failed; + } - err = NuExtractThread(pArchive, pThread->threadIdx, pDataSink); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't extract 'bytes' (auto) (err=%d)\n", - err); - goto failed; - } - NuFreeDataSink(pDataSink); - pDataSink = nil; + err = NuExtractThread(pArchive, pThread->threadIdx, pDataSink); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't extract 'bytes' (auto) (err=%d)\n", + err); + goto failed; + } + NuFreeDataSink(pDataSink); + pDataSink = nil; - free(buf); - buf = nil; + free(buf); + buf = nil; - /* - * Extract "English". - */ - err = NuGetRecordIdxByName(pArchive, kTestEntryEnglish, &recordIdx); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't find '%s' (err=%d)\n", - kTestEntryEnglish, err); - goto failed; - } - err = NuGetRecord(pArchive, recordIdx, &pRecord); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't get record index %ld (err=%d)\n", - recordIdx, err); - goto failed; - } - assert(pRecord != nil); + /* + * Extract "English". + */ + err = NuGetRecordIdxByName(pArchive, kTestEntryEnglish, &recordIdx); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't find '%s' (err=%d)\n", + kTestEntryEnglish, err); + goto failed; + } + err = NuGetRecord(pArchive, recordIdx, &pRecord); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't get record index %ld (err=%d)\n", + recordIdx, err); + goto failed; + } + assert(pRecord != nil); - /* we're not using ShrinkIt compat mode, so there should not be a comment */ - pThread = NuGetThread(pRecord, 1); - assert(pThread != nil); - if (NuGetThreadID(pThread) != kNuThreadIDDataFork) { - fprintf(stderr, "ERROR: 'English' had unexpected threadID 0x%08lx\n", - NuGetThreadID(pThread)); - goto failed; - } + /* we're not using ShrinkIt compat mode, so there should not be a comment */ + pThread = NuGetThread(pRecord, 1); + assert(pThread != nil); + if (NuGetThreadID(pThread) != kNuThreadIDDataFork) { + fprintf(stderr, "ERROR: 'English' had unexpected threadID 0x%08lx\n", + NuGetThreadID(pThread)); + goto failed; + } - buf = malloc(pThread->actualThreadEOF); - if (buf == nil) { - fprintf(stderr, "ERROR: malloc(%ld) failed\n",pThread->actualThreadEOF); - goto failed; - } + buf = malloc(pThread->actualThreadEOF); + if (buf == nil) { + fprintf(stderr, "ERROR: malloc(%ld) failed\n",pThread->actualThreadEOF); + goto failed; + } - /* - * Try to extract it with text conversion off. - */ - err = NuCreateDataSinkForBuffer(true, kNuConvertOff, buf, - pThread->actualThreadEOF, &pDataSink); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't create data sink (err=%d)\n", err); - goto failed; - } + /* + * Try to extract it with text conversion off. + */ + err = NuCreateDataSinkForBuffer(true, kNuConvertOff, buf, + pThread->actualThreadEOF, &pDataSink); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't create data sink (err=%d)\n", err); + goto failed; + } - err = NuExtractThread(pArchive, pThread->threadIdx, pDataSink); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't extract 'bytes' (off) (err=%d)\n", - err); - goto failed; - } - NuFreeDataSink(pDataSink); - pDataSink = nil; + err = NuExtractThread(pArchive, pThread->threadIdx, pDataSink); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't extract 'bytes' (off) (err=%d)\n", + err); + goto failed; + } + NuFreeDataSink(pDataSink); + pDataSink = nil; - /* - * Try to extract with "auto" conversion, which should fail because the - * buffer is too small, and the input looks like text. - */ - err = NuCreateDataSinkForBuffer(true, kNuConvertAuto, buf, - pThread->actualThreadEOF, &pDataSink); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't create data sink (err=%d)\n", err); - goto failed; - } + /* + * Try to extract with "auto" conversion, which should fail because the + * buffer is too small, and the input looks like text. + */ + err = NuCreateDataSinkForBuffer(true, kNuConvertAuto, buf, + pThread->actualThreadEOF, &pDataSink); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't create data sink (err=%d)\n", err); + goto failed; + } - FAIL_OK; - err = NuExtractThread(pArchive, pThread->threadIdx, pDataSink); - FAIL_BAD; - if (err == kNuErrNone) { - fprintf(stderr, "ERROR: managed to extract bloated 'English'?\n"); - goto failed; - } - NuFreeDataSink(pDataSink); - pDataSink = nil; + FAIL_OK; + err = NuExtractThread(pArchive, pThread->threadIdx, pDataSink); + FAIL_BAD; + if (err == kNuErrNone) { + fprintf(stderr, "ERROR: managed to extract bloated 'English'?\n"); + goto failed; + } + NuFreeDataSink(pDataSink); + pDataSink = nil; - /*Free(buf);*/ - /*buf = nil;*/ + /*Free(buf);*/ + /*buf = nil;*/ - /* - * Extract "long" (which is zero bytes). - */ - err = NuGetRecordIdxByName(pArchive, kTestEntryLong, &recordIdx); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't find '%s' (err=%d)\n", - kTestEntryLong, err); - goto failed; - } - err = NuGetRecord(pArchive, recordIdx, &pRecord); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't get record index %ld (err=%d)\n", - recordIdx, err); - goto failed; - } - assert(pRecord != nil); + /* + * Extract "long" (which is zero bytes). + */ + err = NuGetRecordIdxByName(pArchive, kTestEntryLong, &recordIdx); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't find '%s' (err=%d)\n", + kTestEntryLong, err); + goto failed; + } + err = NuGetRecord(pArchive, recordIdx, &pRecord); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't get record index %ld (err=%d)\n", + recordIdx, err); + goto failed; + } + assert(pRecord != nil); - /* we're not using ShrinkIt compat mode, so there should not be a comment */ - pThread = NuGetThread(pRecord, 1); - assert(pThread != nil); - if (NuGetThreadID(pThread) != kNuThreadIDRsrcFork) { - fprintf(stderr, "ERROR: 'Long' had unexpected threadID 0x%08lx\n", - NuGetThreadID(pThread)); - goto failed; - } + /* we're not using ShrinkIt compat mode, so there should not be a comment */ + pThread = NuGetThread(pRecord, 1); + assert(pThread != nil); + if (NuGetThreadID(pThread) != kNuThreadIDRsrcFork) { + fprintf(stderr, "ERROR: 'Long' had unexpected threadID 0x%08lx\n", + NuGetThreadID(pThread)); + goto failed; + } - /* - * Try it with text conversion on; shouldn't matter. - */ - err = NuCreateDataSinkForBuffer(true, kNuConvertOn, buf, - 1, &pDataSink); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't create data sink (err=%d)\n", err); - goto failed; - } + /* + * Try it with text conversion on; shouldn't matter. + */ + err = NuCreateDataSinkForBuffer(true, kNuConvertOn, buf, + 1, &pDataSink); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't create data sink (err=%d)\n", err); + goto failed; + } - err = NuExtractThread(pArchive, pThread->threadIdx, pDataSink); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't extract 'Long' (off) (err=%d)\n", - err); - goto failed; - } - NuFreeDataSink(pDataSink); - pDataSink = nil; + err = NuExtractThread(pArchive, pThread->threadIdx, pDataSink); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't extract 'Long' (off) (err=%d)\n", + err); + goto failed; + } + NuFreeDataSink(pDataSink); + pDataSink = nil; - free(buf); - buf = nil; + free(buf); + buf = nil; - return 0; + return 0; failed: - if (buf != nil) - free(buf); - if (pDataSink != nil) - (void) NuFreeDataSink(pDataSink); - return -1; + if (buf != nil) + free(buf); + if (pDataSink != nil) + (void) NuFreeDataSink(pDataSink); + return -1; } /* @@ -768,118 +768,118 @@ failed: int Test_Delete(NuArchive* pArchive) { - NuError err; - NuRecordIdx recordIdx; - const NuRecord* pRecord; - const NuThread* pThread = nil; - long count; - int idx; + NuError err; + NuRecordIdx recordIdx; + const NuRecord* pRecord; + const NuThread* pThread = nil; + long count; + int idx; - printf("... deleting first and last\n"); + printf("... deleting first and last\n"); - /* - * Delete all threads from the first record ("bytes"). - */ - err = NuGetRecordIdxByPosition(pArchive, 0, &recordIdx); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't find #%d (err=%d)\n", 0, err); - goto failed; - } - err = NuGetRecord(pArchive, recordIdx, &pRecord); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't get record index %ld (err=%d)\n", - recordIdx, err); - goto failed; - } - assert(pRecord != nil); - assert(pRecord->recTotalThreads > 0); + /* + * Delete all threads from the first record ("bytes"). + */ + err = NuGetRecordIdxByPosition(pArchive, 0, &recordIdx); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't find #%d (err=%d)\n", 0, err); + goto failed; + } + err = NuGetRecord(pArchive, recordIdx, &pRecord); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't get record index %ld (err=%d)\n", + recordIdx, err); + goto failed; + } + assert(pRecord != nil); + assert(pRecord->recTotalThreads > 0); - for (idx = 0; idx < (int)pRecord->recTotalThreads; idx++) { - pThread = NuGetThread(pRecord, idx); - assert(pThread != nil); + for (idx = 0; idx < (int)pRecord->recTotalThreads; idx++) { + pThread = NuGetThread(pRecord, idx); + assert(pThread != nil); - err = NuDeleteThread(pArchive, pThread->threadIdx); - if (err != kNuErrNone) { - fprintf(stderr, - "ERROR: couldn't delete thread #%d (%ld) (err=%d)\n", - idx, recordIdx, err); - goto failed; - } - } + err = NuDeleteThread(pArchive, pThread->threadIdx); + if (err != kNuErrNone) { + fprintf(stderr, + "ERROR: couldn't delete thread #%d (%ld) (err=%d)\n", + idx, recordIdx, err); + goto failed; + } + } - /* try to re-delete the same thread */ - assert(pThread != nil); - FAIL_OK; - err = NuDeleteThread(pArchive, pThread->threadIdx); - FAIL_BAD; - if (err == kNuErrNone) { - fprintf(stderr, "ERROR: allowed to re-delete thread (%ld) (err=%d)\n", - recordIdx, err); - goto failed; - } + /* try to re-delete the same thread */ + assert(pThread != nil); + FAIL_OK; + err = NuDeleteThread(pArchive, pThread->threadIdx); + FAIL_BAD; + if (err == kNuErrNone) { + fprintf(stderr, "ERROR: allowed to re-delete thread (%ld) (err=%d)\n", + recordIdx, err); + goto failed; + } - /* try to delete the modified record */ - FAIL_OK; - err = NuDeleteRecord(pArchive, recordIdx); - FAIL_BAD; - if (err == kNuErrNone) { - fprintf(stderr, - "ERROR: able to delete modified record (%ld) (err=%d)\n", - recordIdx, err); - goto failed; - } + /* try to delete the modified record */ + FAIL_OK; + err = NuDeleteRecord(pArchive, recordIdx); + FAIL_BAD; + if (err == kNuErrNone) { + fprintf(stderr, + "ERROR: able to delete modified record (%ld) (err=%d)\n", + recordIdx, err); + goto failed; + } - /* - * Make sure the attr hasn't been updated yet. - */ - err = NuGetAttr(pArchive, kNuAttrNumRecords, (unsigned long*) &count); - if (count != kNumEntries) { - fprintf(stderr, "ERROR: kNuAttrNumRecords %ld vs %d\n", - count, kNumEntries); - goto failed; - } + /* + * Make sure the attr hasn't been updated yet. + */ + err = NuGetAttr(pArchive, kNuAttrNumRecords, (unsigned long*) &count); + if (count != kNumEntries) { + fprintf(stderr, "ERROR: kNuAttrNumRecords %ld vs %d\n", + count, kNumEntries); + goto failed; + } - /* - * Delete the last record ("long"). - */ - err = NuGetRecordIdxByPosition(pArchive, kNumEntries-1, &recordIdx); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't find #%d (err=%d)\n", 0, err); - goto failed; - } - err = NuGetRecord(pArchive, recordIdx, &pRecord); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't get record index %ld (err=%d)\n", - recordIdx, err); - goto failed; - } - assert(pRecord != nil); + /* + * Delete the last record ("long"). + */ + err = NuGetRecordIdxByPosition(pArchive, kNumEntries-1, &recordIdx); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't find #%d (err=%d)\n", 0, err); + goto failed; + } + err = NuGetRecord(pArchive, recordIdx, &pRecord); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't get record index %ld (err=%d)\n", + recordIdx, err); + goto failed; + } + assert(pRecord != nil); - /* grab the first thread before we whack the record */ - pThread = NuGetThread(pRecord, 0); - assert(pThread != nil); + /* grab the first thread before we whack the record */ + pThread = NuGetThread(pRecord, 0); + assert(pThread != nil); - err = NuDeleteRecord(pArchive, recordIdx); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: unable to delete record #%d (%ld) (err=%d)\n", - kNumEntries-1, recordIdx, err); - goto failed; - } + err = NuDeleteRecord(pArchive, recordIdx); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: unable to delete record #%d (%ld) (err=%d)\n", + kNumEntries-1, recordIdx, err); + goto failed; + } - /* try to delete a thread from the deleted record */ - FAIL_OK; - err = NuDeleteThread(pArchive, pThread->threadIdx); - FAIL_BAD; - if (err == kNuErrNone) { - fprintf(stderr, - "ERROR: allowed to delete from deleted (%ld) (err=%d)\n", - pThread->threadIdx, err); - goto failed; - } + /* try to delete a thread from the deleted record */ + FAIL_OK; + err = NuDeleteThread(pArchive, pThread->threadIdx); + FAIL_BAD; + if (err == kNuErrNone) { + fprintf(stderr, + "ERROR: allowed to delete from deleted (%ld) (err=%d)\n", + pThread->threadIdx, err); + goto failed; + } - return 0; + return 0; failed: - return -1; + return -1; } @@ -889,26 +889,26 @@ failed: int Test_MasterCount(NuArchive* pArchive, long expected) { - NuError err; - const NuMasterHeader* pMasterHeader; + NuError err; + const NuMasterHeader* pMasterHeader; - printf("... checking master count\n"); + printf("... checking master count\n"); - err = NuGetMasterHeader(pArchive, &pMasterHeader); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't get master header (err=%d)\n", err); - goto failed; - } + err = NuGetMasterHeader(pArchive, &pMasterHeader); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't get master header (err=%d)\n", err); + goto failed; + } - if (pMasterHeader->mhTotalRecords != (ulong)expected) { - fprintf(stderr, "ERROR: unexpected MH count (%ld vs %ld)\n", - pMasterHeader->mhTotalRecords, expected); - goto failed; - } + if (pMasterHeader->mhTotalRecords != (ulong)expected) { + fprintf(stderr, "ERROR: unexpected MH count (%ld vs %ld)\n", + pMasterHeader->mhTotalRecords, expected); + goto failed; + } - return 0; + return 0; failed: - return -1; + return -1; } @@ -920,210 +920,210 @@ failed: int DoTests(void) { - NuError err; - NuArchive* pArchive = nil; - long status; - int cc, result = 0; - char answer; + NuError err; + NuArchive* pArchive = nil; + long status; + int cc, result = 0; + char answer; - /* - * Make sure we're starting with a clean slate. - */ - if (access(kTestArchive, F_OK) == 0) { - printf("Test archive '%s' exists, remove (y/n)? ", kTestArchive); - fflush(stdout); - answer = TGetReplyChar('n'); - if (tolower(answer) != 'y') - goto failed; - cc = unlink(kTestArchive); - if (cc < 0) { - perror("unlink kTestArchive"); - goto failed; - } - } - if (access(kTestTempFile, F_OK) == 0) { - printf("Test temp file '%s' exists, remove (y/n)? ", kTestTempFile); - fflush(stdout); - answer = TGetReplyChar('n'); - if (tolower(answer) != 'y') - goto failed; - cc = unlink(kTestTempFile); - if (cc < 0) { - perror("unlink kTestTempFile"); - goto failed; - } - } + /* + * Make sure we're starting with a clean slate. + */ + if (access(kTestArchive, F_OK) == 0) { + printf("Test archive '%s' exists, remove (y/n)? ", kTestArchive); + fflush(stdout); + answer = TGetReplyChar('n'); + if (tolower(answer) != 'y') + goto failed; + cc = unlink(kTestArchive); + if (cc < 0) { + perror("unlink kTestArchive"); + goto failed; + } + } + if (access(kTestTempFile, F_OK) == 0) { + printf("Test temp file '%s' exists, remove (y/n)? ", kTestTempFile); + fflush(stdout); + answer = TGetReplyChar('n'); + if (tolower(answer) != 'y') + goto failed; + cc = unlink(kTestTempFile); + if (cc < 0) { + perror("unlink kTestTempFile"); + goto failed; + } + } - /* - * Test some of the open flags. - */ - if (Test_OpenFlags() != 0) - goto failed; + /* + * Test some of the open flags. + */ + if (Test_OpenFlags() != 0) + goto failed; - /* - * Create a new archive to play with. - */ - err = NuOpenRW(kTestArchive, kTestTempFile, kNuOpenCreat|kNuOpenExcl, - &pArchive); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: NuOpenRW faileded (err=%d)\n", err); - goto failed; - } - err = NuSetErrorMessageHandler(pArchive, ErrorMessageHandler); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't set message handler (err=%d)\n", err); - goto failed; - } + /* + * Create a new archive to play with. + */ + err = NuOpenRW(kTestArchive, kTestTempFile, kNuOpenCreat|kNuOpenExcl, + &pArchive); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: NuOpenRW faileded (err=%d)\n", err); + goto failed; + } + err = NuSetErrorMessageHandler(pArchive, ErrorMessageHandler); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't set message handler (err=%d)\n", err); + goto failed; + } - /* - * Add some test entries. - */ - if (Test_AddStuff(pArchive) != 0) - goto failed; + /* + * Add some test entries. + */ + if (Test_AddStuff(pArchive) != 0) + goto failed; - /* - * Check the archive contents. - */ - printf("... checking contents\n"); - if (Test_Contents(pArchive) != 0) - goto failed; + /* + * Check the archive contents. + */ + printf("... checking contents\n"); + if (Test_Contents(pArchive) != 0) + goto failed; - /* - * Reopen it read-only. - */ - printf("... reopening archive read-only\n"); - err = NuClose(pArchive); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: mid NuClose failed (err=%d)\n", err); - goto failed; - } - pArchive = nil; + /* + * Reopen it read-only. + */ + printf("... reopening archive read-only\n"); + err = NuClose(pArchive); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: mid NuClose failed (err=%d)\n", err); + goto failed; + } + pArchive = nil; - err = NuOpenRO(kTestArchive, &pArchive); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: NuOpenRO failed (err=%d)\n", err); - goto failed; - } - err = NuSetErrorMessageHandler(pArchive, ErrorMessageHandler); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't set message handler (err=%d)\n", err); - goto failed; - } + err = NuOpenRO(kTestArchive, &pArchive); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: NuOpenRO failed (err=%d)\n", err); + goto failed; + } + err = NuSetErrorMessageHandler(pArchive, ErrorMessageHandler); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't set message handler (err=%d)\n", err); + goto failed; + } - /* - * Make sure the contents are still what we expect. - */ - printf("... checking contents\n"); - if (Test_Contents(pArchive) != 0) - goto failed; + /* + * Make sure the contents are still what we expect. + */ + printf("... checking contents\n"); + if (Test_Contents(pArchive) != 0) + goto failed; - /* - * Verify the archive contents. - */ - if (Test_Verify(pArchive) != 0) - goto failed; + /* + * Verify the archive contents. + */ + if (Test_Verify(pArchive) != 0) + goto failed; - /* - * Extract the files. - */ - if (Test_Extract(pArchive) != 0) - goto failed; + /* + * Extract the files. + */ + if (Test_Extract(pArchive) != 0) + goto failed; - /* - * Reopen it read-write. - */ - printf("... reopening archive read-write\n"); - err = NuClose(pArchive); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: late NuClose failed (err=%d)\n", err); - goto failed; - } - pArchive = nil; + /* + * Reopen it read-write. + */ + printf("... reopening archive read-write\n"); + err = NuClose(pArchive); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: late NuClose failed (err=%d)\n", err); + goto failed; + } + pArchive = nil; - err = NuOpenRW(kTestArchive, kTestTempFile, 0, &pArchive); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: re-NuOpenRW failed (err=%d)\n", err); - goto failed; - } - err = NuSetErrorMessageHandler(pArchive, ErrorMessageHandler); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't set message handler (err=%d)\n", err); - goto failed; - } + err = NuOpenRW(kTestArchive, kTestTempFile, 0, &pArchive); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: re-NuOpenRW failed (err=%d)\n", err); + goto failed; + } + err = NuSetErrorMessageHandler(pArchive, ErrorMessageHandler); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't set message handler (err=%d)\n", err); + goto failed; + } - /* - * Contents shouldn't have changed. - */ - printf("... checking contents\n"); - if (Test_Contents(pArchive) != 0) - goto failed; + /* + * Contents shouldn't have changed. + */ + printf("... checking contents\n"); + if (Test_Contents(pArchive) != 0) + goto failed; - /* - * Test deletion. - */ - if (Test_Delete(pArchive) != 0) - goto failed; + /* + * Test deletion. + */ + if (Test_Delete(pArchive) != 0) + goto failed; - /* - * Abort the changes and verify that nothing has changed. - */ - printf("... aborting changes\n"); - err = NuAbort(pArchive); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: abort failed (err=%d)\n", err); - goto failed; - } + /* + * Abort the changes and verify that nothing has changed. + */ + printf("... aborting changes\n"); + err = NuAbort(pArchive); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: abort failed (err=%d)\n", err); + goto failed; + } - printf("... checking contents\n"); - if (Test_Contents(pArchive) != 0) - goto failed; + printf("... checking contents\n"); + if (Test_Contents(pArchive) != 0) + goto failed; - /* - * Delete them again. - */ - if (Test_Delete(pArchive) != 0) - goto failed; + /* + * Delete them again. + */ + if (Test_Delete(pArchive) != 0) + goto failed; - /* - * Flush the deletions. This should remove the first and last records. - */ - err = NuFlush(pArchive, &status); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: flush failed (err=%d, status=%ld)\n", - err, status); - goto failed; - } + /* + * Flush the deletions. This should remove the first and last records. + */ + err = NuFlush(pArchive, &status); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: flush failed (err=%d, status=%ld)\n", + err, status); + goto failed; + } - /* - * Check count in master header. - */ - if (Test_MasterCount(pArchive, kNumEntries-2) != 0) - goto failed; + /* + * Check count in master header. + */ + if (Test_MasterCount(pArchive, kNumEntries-2) != 0) + goto failed; - /* - * That's all, folks... - */ - NuClose(pArchive); - pArchive = nil; + /* + * That's all, folks... + */ + NuClose(pArchive); + pArchive = nil; - printf("... removing '%s'\n", kTestArchive); - cc = unlink(kTestArchive); - if (cc < 0) { - perror("unlink kTestArchive"); - goto failed; - } + printf("... removing '%s'\n", kTestArchive); + cc = unlink(kTestArchive); + if (cc < 0) { + perror("unlink kTestArchive"); + goto failed; + } leave: - if (pArchive != nil) { - NuAbort(pArchive); - NuClose(pArchive); - } - return result; + if (pArchive != nil) { + NuAbort(pArchive); + NuClose(pArchive); + } + return result; failed: - result = -1; - goto leave; + result = -1; + goto leave; } @@ -1133,26 +1133,26 @@ failed: int main(void) { - long major, minor, bug; - const char* pBuildDate; - const char* pBuildFlags; - int cc; + long major, minor, bug; + const char* pBuildDate; + const char* pBuildFlags; + int cc; - (void) NuGetVersion(&major, &minor, &bug, &pBuildDate, &pBuildFlags); - printf("Using NuFX library v%ld.%ld.%ld, built on or after\n" - "%s with [%s]\n\n", - major, minor, bug, pBuildDate, pBuildFlags); + (void) NuGetVersion(&major, &minor, &bug, &pBuildDate, &pBuildFlags); + printf("Using NuFX library v%ld.%ld.%ld, built on or after\n" + "%s with [%s]\n\n", + major, minor, bug, pBuildDate, pBuildFlags); - if (NuSetGlobalErrorMessageHandler(ErrorMessageHandler) != kNuErrNone) { - fprintf(stderr, "ERROR: can't set the global message handler"); - exit(1); - } + if (NuSetGlobalErrorMessageHandler(ErrorMessageHandler) != kNuErrNone) { + fprintf(stderr, "ERROR: can't set the global message handler"); + exit(1); + } - printf("... starting tests\n"); + printf("... starting tests\n"); - cc = DoTests(); + cc = DoTests(); - printf("... tests ended, %s\n", cc == 0 ? "SUCCESS" : "FAILURE"); - exit(cc != 0); + printf("... tests ended, %s\n", cc == 0 ? "SUCCESS" : "FAILURE"); + exit(cc != 0); } diff --git a/nufxlib-0/samples/TestExtract.c b/nufxlib-0/samples/TestExtract.c index 4688b0e..b6ee336 100644 --- a/nufxlib-0/samples/TestExtract.c +++ b/nufxlib-0/samples/TestExtract.c @@ -21,15 +21,15 @@ #include "Common.h" -#define false 0 -#define true (!false) +#define false 0 +#define true (!false) -#define kHappySize 2408 +#define kHappySize 2408 /* * =========================================================================== - * ArchiveRecord + * ArchiveRecord * =========================================================================== */ @@ -37,13 +37,13 @@ * Track an archive record. */ typedef struct ArchiveRecord { - char* filename; - NuRecordIdx recordIdx; + char* filename; + NuRecordIdx recordIdx; - long numThreads; - NuThread* pThreads; + long numThreads; + NuThread* pThreads; - struct ArchiveRecord* pNext; + struct ArchiveRecord* pNext; } ArchiveRecord; @@ -53,24 +53,24 @@ typedef struct ArchiveRecord { ArchiveRecord* ArchiveRecord_New(const NuRecord* pRecord) { - ArchiveRecord* pArcRec = nil; + ArchiveRecord* pArcRec = nil; - pArcRec = malloc(sizeof(*pArcRec)); - if (pArcRec == nil) - return nil; + pArcRec = malloc(sizeof(*pArcRec)); + if (pArcRec == nil) + return nil; - if (pRecord->filename == nil) - pArcRec->filename = strdup(""); - else - pArcRec->filename = strdup((char*)pRecord->filename); + if (pRecord->filename == nil) + pArcRec->filename = strdup(""); + else + pArcRec->filename = strdup((char*)pRecord->filename); - pArcRec->recordIdx = pRecord->recordIdx; - pArcRec->numThreads = NuRecordGetNumThreads(pRecord); - (void) NuRecordCopyThreads(pRecord, &pArcRec->pThreads); + pArcRec->recordIdx = pRecord->recordIdx; + pArcRec->numThreads = NuRecordGetNumThreads(pRecord); + (void) NuRecordCopyThreads(pRecord, &pArcRec->pThreads); - pArcRec->pNext = nil; + pArcRec->pNext = nil; - return pArcRec; + return pArcRec; } /* @@ -79,14 +79,14 @@ ArchiveRecord_New(const NuRecord* pRecord) void ArchiveRecord_Free(ArchiveRecord* pArcRec) { - if (pArcRec == nil) - return; + if (pArcRec == nil) + return; - if (pArcRec->filename != nil) - free(pArcRec->filename); - if (pArcRec->pThreads != nil) - free(pArcRec->pThreads); - free(pArcRec); + if (pArcRec->filename != nil) + free(pArcRec->filename); + if (pArcRec->pThreads != nil) + free(pArcRec->pThreads); + free(pArcRec); } /* @@ -95,61 +95,61 @@ ArchiveRecord_Free(ArchiveRecord* pArcRec) const NuThread* ArchiveRecord_FindThreadByID(const ArchiveRecord* pArcRec, NuThreadID threadID) { - const NuThread* pThread; - int i; + const NuThread* pThread; + int i; - for (i = 0; i < pArcRec->numThreads; i++) { - pThread = NuThreadGetByIdx(pArcRec->pThreads, i); - if (NuGetThreadID(pThread) == threadID) - return pThread; - } + for (i = 0; i < pArcRec->numThreads; i++) { + pThread = NuThreadGetByIdx(pArcRec->pThreads, i); + if (NuGetThreadID(pThread) == threadID) + return pThread; + } - return nil; + return nil; } const char* ArchiveRecord_GetFilename(const ArchiveRecord* pArcRec) { - return pArcRec->filename; + return pArcRec->filename; } NuRecordIdx ArchiveRecord_GetRecordIdx(const ArchiveRecord* pArcRec) { - return pArcRec->recordIdx; + return pArcRec->recordIdx; } long ArchiveRecord_GetNumThreads(const ArchiveRecord* pArcRec) { - return pArcRec->numThreads; + return pArcRec->numThreads; } const NuThread* ArchiveRecord_GetThread(const ArchiveRecord* pArcRec, int idx) { - if (idx < 0 || idx >= pArcRec->numThreads) - return nil; - return NuThreadGetByIdx(pArcRec->pThreads, idx); + if (idx < 0 || idx >= pArcRec->numThreads) + return nil; + return NuThreadGetByIdx(pArcRec->pThreads, idx); } void ArchiveRecord_SetNext(ArchiveRecord* pArcRec, ArchiveRecord* pNextRec) { - pArcRec->pNext = pNextRec; + pArcRec->pNext = pNextRec; } ArchiveRecord* ArchiveRecord_GetNext(const ArchiveRecord* pArcRec) { - return pArcRec->pNext; + return pArcRec->pNext; } /* * =========================================================================== - * ArchiveData + * ArchiveData * =========================================================================== */ @@ -157,50 +157,50 @@ ArchiveRecord_GetNext(const ArchiveRecord* pArcRec) * A collection of records. */ typedef struct ArchiveData { - long numRecords; - ArchiveRecord* pRecordHead; - ArchiveRecord* pRecordTail; + long numRecords; + ArchiveRecord* pRecordHead; + ArchiveRecord* pRecordTail; } ArchiveData; ArchiveData* ArchiveData_New(void) { - ArchiveData* pArcData; + ArchiveData* pArcData; - pArcData = malloc(sizeof(*pArcData)); - if (pArcData == nil) - return nil; + pArcData = malloc(sizeof(*pArcData)); + if (pArcData == nil) + return nil; - pArcData->numRecords = 0; - pArcData->pRecordHead = pArcData->pRecordTail = nil; + pArcData->numRecords = 0; + pArcData->pRecordHead = pArcData->pRecordTail = nil; - return pArcData; + return pArcData; } void ArchiveData_Free(ArchiveData* pArcData) { - ArchiveRecord* pNext; + ArchiveRecord* pNext; - if (pArcData == nil) - return; + if (pArcData == nil) + return; - printf("*** Deleting %ld records!\n", pArcData->numRecords); - while (pArcData->pRecordHead != nil) { - pNext = ArchiveRecord_GetNext(pArcData->pRecordHead); - ArchiveRecord_Free(pArcData->pRecordHead); - pArcData->pRecordHead = pNext; - } + printf("*** Deleting %ld records!\n", pArcData->numRecords); + while (pArcData->pRecordHead != nil) { + pNext = ArchiveRecord_GetNext(pArcData->pRecordHead); + ArchiveRecord_Free(pArcData->pRecordHead); + pArcData->pRecordHead = pNext; + } - free(pArcData); + free(pArcData); } ArchiveRecord* ArchiveData_GetRecordHead(const ArchiveData* pArcData) { - return pArcData->pRecordHead; + return pArcData->pRecordHead; } @@ -208,52 +208,52 @@ ArchiveData_GetRecordHead(const ArchiveData* pArcData) void ArchiveData_AddRecord(ArchiveData* pArcData, ArchiveRecord* pRecord) { - assert(pRecord != nil); - assert((pArcData->pRecordHead == nil && pArcData->pRecordTail == nil) || - (pArcData->pRecordHead != nil && pArcData->pRecordTail != nil)); + assert(pRecord != nil); + assert((pArcData->pRecordHead == nil && pArcData->pRecordTail == nil) || + (pArcData->pRecordHead != nil && pArcData->pRecordTail != nil)); - if (pArcData->pRecordHead == nil) { - /* first */ - pArcData->pRecordHead = pArcData->pRecordTail = pRecord; - } else { - /* not first, add to end */ - ArchiveRecord_SetNext(pArcData->pRecordTail, pRecord); - pArcData->pRecordTail = pRecord; - } + if (pArcData->pRecordHead == nil) { + /* first */ + pArcData->pRecordHead = pArcData->pRecordTail = pRecord; + } else { + /* not first, add to end */ + ArchiveRecord_SetNext(pArcData->pRecordTail, pRecord); + pArcData->pRecordTail = pRecord; + } - pArcData->numRecords++; + pArcData->numRecords++; } /* dump the contents of the ArchiveData to stdout */ void ArchiveData_DumpContents(const ArchiveData* pArcData) { - ArchiveRecord* pArcRec; + ArchiveRecord* pArcRec; - pArcRec = pArcData->pRecordHead; - while (pArcRec != nil) { - const NuThread* pThread; - int i, count; + pArcRec = pArcData->pRecordHead; + while (pArcRec != nil) { + const NuThread* pThread; + int i, count; - printf("%5ld '%s'\n", - ArchiveRecord_GetRecordIdx(pArcRec), - ArchiveRecord_GetFilename(pArcRec)); + printf("%5ld '%s'\n", + ArchiveRecord_GetRecordIdx(pArcRec), + ArchiveRecord_GetFilename(pArcRec)); - count = ArchiveRecord_GetNumThreads(pArcRec); - for (i = 0; i < count; i++) { - pThread = ArchiveRecord_GetThread(pArcRec, i); - printf(" %5ld 0x%04x 0x%04x\n", pThread->threadIdx, - pThread->thThreadClass, pThread->thThreadKind); - } + count = ArchiveRecord_GetNumThreads(pArcRec); + for (i = 0; i < count; i++) { + pThread = ArchiveRecord_GetThread(pArcRec, i); + printf(" %5ld 0x%04x 0x%04x\n", pThread->threadIdx, + pThread->thThreadClass, pThread->thThreadKind); + } - pArcRec = ArchiveRecord_GetNext(pArcRec); - } + pArcRec = ArchiveRecord_GetNext(pArcRec); + } } /* * =========================================================================== - * Main stuff + * Main stuff * =========================================================================== */ @@ -263,19 +263,19 @@ ArchiveData_DumpContents(const ArchiveData* pArcData) NuResult GatherContents(NuArchive* pArchive, void* vpRecord) { - NuRecord* pRecord = (NuRecord*) vpRecord; - ArchiveData* pArchiveData = nil; - ArchiveRecord* pArchiveRecord = ArchiveRecord_New(pRecord); + NuRecord* pRecord = (NuRecord*) vpRecord; + ArchiveData* pArchiveData = nil; + ArchiveRecord* pArchiveRecord = ArchiveRecord_New(pRecord); - NuGetExtraData(pArchive, (void**)&pArchiveData); - assert(pArchiveData != nil); + NuGetExtraData(pArchive, (void**)&pArchiveData); + assert(pArchiveData != nil); - printf("*** Filename = '%s'\n", - pRecord->filename == nil ? "":(const char*)pRecord->filename); + printf("*** Filename = '%s'\n", + pRecord->filename == nil ? "":(const char*)pRecord->filename); - ArchiveData_AddRecord(pArchiveData, pArchiveRecord); + ArchiveData_AddRecord(pArchiveData, pArchiveRecord); - return kNuOK; + return kNuOK; } @@ -284,28 +284,28 @@ GatherContents(NuArchive* pArchive, void* vpRecord) */ NuError ReadAllFilenameThreads(NuArchive* pArchive, ArchiveData* pArchiveData, - NuDataSink* pDataSink) + NuDataSink* pDataSink) { - NuError err = kNuErrNone; - ArchiveRecord* pArchiveRecord; - const NuThread* pThread; + NuError err = kNuErrNone; + ArchiveRecord* pArchiveRecord; + const NuThread* pThread; - pArchiveRecord = ArchiveData_GetRecordHead(pArchiveData); - while (pArchiveRecord != nil) { - pThread = ArchiveRecord_FindThreadByID(pArchiveRecord, - kNuThreadIDFilename); - if (pThread != nil) { - err = NuExtractThread(pArchive, pThread->threadIdx, pDataSink); - if (err != kNuErrNone) { - fprintf(stderr, "*** Extract failed (%d)\n", err); - goto bail; - } - } - pArchiveRecord = ArchiveRecord_GetNext(pArchiveRecord); - } + pArchiveRecord = ArchiveData_GetRecordHead(pArchiveData); + while (pArchiveRecord != nil) { + pThread = ArchiveRecord_FindThreadByID(pArchiveRecord, + kNuThreadIDFilename); + if (pThread != nil) { + err = NuExtractThread(pArchive, pThread->threadIdx, pDataSink); + if (err != kNuErrNone) { + fprintf(stderr, "*** Extract failed (%d)\n", err); + goto bail; + } + } + pArchiveRecord = ArchiveRecord_GetNext(pArchiveRecord); + } bail: - return err; + return err; } @@ -313,96 +313,96 @@ bail: NuError ExtractToFile(NuArchive* pArchive, ArchiveData* pArchiveData) { - NuError err; - NuDataSink* pDataSink = nil; + NuError err; + NuDataSink* pDataSink = nil; - err = NuCreateDataSinkForFile(true, kNuConvertOff, "out.file", PATH_SEP, - &pDataSink); - if (err != kNuErrNone) - goto bail; + err = NuCreateDataSinkForFile(true, kNuConvertOff, "out.file", PATH_SEP, + &pDataSink); + if (err != kNuErrNone) + goto bail; - err = NuSetValue(pArchive, kNuValueHandleExisting, kNuAlwaysOverwrite); - if (err != kNuErrNone) - goto bail; + err = NuSetValue(pArchive, kNuValueHandleExisting, kNuAlwaysOverwrite); + if (err != kNuErrNone) + goto bail; - err = ReadAllFilenameThreads(pArchive, pArchiveData, pDataSink); - if (err != kNuErrNone) - goto bail; + err = ReadAllFilenameThreads(pArchive, pArchiveData, pDataSink); + if (err != kNuErrNone) + goto bail; bail: - (void) NuFreeDataSink(pDataSink); - if (err == kNuErrNone) - printf("*** File write complete\n"); - return err; + (void) NuFreeDataSink(pDataSink); + if (err == kNuErrNone) + printf("*** File write complete\n"); + return err; } /* extract every filename thread into a FILE*, appending */ NuError ExtractToFP(NuArchive* pArchive, ArchiveData* pArchiveData) { - NuError err; - FILE* fp = nil; - NuDataSink* pDataSink = nil; + NuError err; + FILE* fp = nil; + NuDataSink* pDataSink = nil; - if ((fp = fopen("out.fp", kNuFileOpenWriteTrunc)) == nil) - return kNuErrFileOpen; + if ((fp = fopen("out.fp", kNuFileOpenWriteTrunc)) == nil) + return kNuErrFileOpen; - err = NuCreateDataSinkForFP(true, kNuConvertOff, fp, &pDataSink); - if (err != kNuErrNone) - goto bail; + err = NuCreateDataSinkForFP(true, kNuConvertOff, fp, &pDataSink); + if (err != kNuErrNone) + goto bail; - err = ReadAllFilenameThreads(pArchive, pArchiveData, pDataSink); - if (err != kNuErrNone) - goto bail; + err = ReadAllFilenameThreads(pArchive, pArchiveData, pDataSink); + if (err != kNuErrNone) + goto bail; bail: - (void) NuFreeDataSink(pDataSink); - if (fp != nil) - fclose(fp); - if (err == kNuErrNone) - printf("*** FP write complete\n"); - return err; + (void) NuFreeDataSink(pDataSink); + if (fp != nil) + fclose(fp); + if (err == kNuErrNone) + printf("*** FP write complete\n"); + return err; } /* extract every filename thread into a buffer, advancing as we go */ NuError ExtractToBuffer(NuArchive* pArchive, ArchiveData* pArchiveData) { - NuError err; - unsigned char buffer[kHappySize]; - NuDataSink* pDataSink = nil; - unsigned long count; + NuError err; + unsigned char buffer[kHappySize]; + NuDataSink* pDataSink = nil; + unsigned long count; - err = NuCreateDataSinkForBuffer(true, kNuConvertOff, buffer, kHappySize, - &pDataSink); - if (err != kNuErrNone) - goto bail; + err = NuCreateDataSinkForBuffer(true, kNuConvertOff, buffer, kHappySize, + &pDataSink); + if (err != kNuErrNone) + goto bail; - err = ReadAllFilenameThreads(pArchive, pArchiveData, pDataSink); - if (err != kNuErrNone) { - if (err == kNuErrBufferOverrun) - fprintf(stderr, "*** Hey, buffer wasn't big enough!\n"); - goto bail; - } + err = ReadAllFilenameThreads(pArchive, pArchiveData, pDataSink); + if (err != kNuErrNone) { + if (err == kNuErrBufferOverrun) + fprintf(stderr, "*** Hey, buffer wasn't big enough!\n"); + goto bail; + } - /* write the buffer to a file */ - (void) NuDataSinkGetOutCount(pDataSink, &count); - if (count > 0) { - FILE* fp; - if ((fp = fopen("out.buf", kNuFileOpenWriteTrunc)) != nil) { + /* write the buffer to a file */ + (void) NuDataSinkGetOutCount(pDataSink, &count); + if (count > 0) { + FILE* fp; + if ((fp = fopen("out.buf", kNuFileOpenWriteTrunc)) != nil) { - printf("*** Writing %ld bytes\n", count); - if (fwrite(buffer, count, 1, fp) != 1) - err = kNuErrFileWrite; - fclose(fp); - } - } else { - printf("*** No data found!\n"); - } + printf("*** Writing %ld bytes\n", count); + if (fwrite(buffer, count, 1, fp) != 1) + err = kNuErrFileWrite; + fclose(fp); + } + } else { + printf("*** No data found!\n"); + } bail: - (void) NuFreeDataSink(pDataSink); - return err; + (void) NuFreeDataSink(pDataSink); + return err; } @@ -412,52 +412,52 @@ bail: int DoFileStuff(const char* filename) { - NuError err; - NuArchive* pArchive = nil; - NuMasterHeader* pMasterHeader = nil; - ArchiveData* pArchiveData = ArchiveData_New(); + NuError err; + NuArchive* pArchive = nil; + NuMasterHeader* pMasterHeader = nil; + ArchiveData* pArchiveData = ArchiveData_New(); - err = NuOpenRO(filename, &pArchive); - if (err != kNuErrNone) - goto bail; + err = NuOpenRO(filename, &pArchive); + if (err != kNuErrNone) + goto bail; - NuSetExtraData(pArchive, pArchiveData); + NuSetExtraData(pArchive, pArchiveData); - printf("*** Gathering contents!\n"); - err = NuContents(pArchive, GatherContents); - if (err != kNuErrNone) - goto bail; + printf("*** Gathering contents!\n"); + err = NuContents(pArchive, GatherContents); + if (err != kNuErrNone) + goto bail; - printf("*** Dumping contents!\n"); - ArchiveData_DumpContents(pArchiveData); + printf("*** Dumping contents!\n"); + ArchiveData_DumpContents(pArchiveData); - err = ExtractToFile(pArchive, pArchiveData); - if (err != kNuErrNone) - goto bail; - err = ExtractToFP(pArchive, pArchiveData); - if (err != kNuErrNone) - goto bail; - err = ExtractToBuffer(pArchive, pArchiveData); - if (err != kNuErrNone) - goto bail; + err = ExtractToFile(pArchive, pArchiveData); + if (err != kNuErrNone) + goto bail; + err = ExtractToFP(pArchive, pArchiveData); + if (err != kNuErrNone) + goto bail; + err = ExtractToBuffer(pArchive, pArchiveData); + if (err != kNuErrNone) + goto bail; bail: - if (err != kNuErrNone) - fprintf(stderr, "*** ERROR: got error %d\n", err); + if (err != kNuErrNone) + fprintf(stderr, "*** ERROR: got error %d\n", err); - if (pArchive != nil) { - NuError err2 = NuClose(pArchive); - if (err == kNuErrNone && err2 != kNuErrNone) - err = err2; - } + if (pArchive != nil) { + NuError err2 = NuClose(pArchive); + if (err == kNuErrNone && err2 != kNuErrNone) + err = err2; + } - if (pMasterHeader != nil) - free(pMasterHeader); + if (pMasterHeader != nil) + free(pMasterHeader); - if (pArchiveData != nil) - free(pArchiveData); + if (pArchiveData != nil) + free(pArchiveData); - return err; + return err; } @@ -467,28 +467,28 @@ bail: int main(int argc, char** argv) { - long major, minor, bug; - const char* pBuildDate; - FILE* infp; - int cc; + long major, minor, bug; + const char* pBuildDate; + FILE* infp; + int cc; - (void) NuGetVersion(&major, &minor, &bug, &pBuildDate, nil); - printf("Using NuFX lib %ld.%ld.%ld built on or after %s\n", - major, minor, bug, pBuildDate); + (void) NuGetVersion(&major, &minor, &bug, &pBuildDate, nil); + printf("Using NuFX lib %ld.%ld.%ld built on or after %s\n", + major, minor, bug, pBuildDate); - if (argc == 2) { - infp = fopen(argv[1], kNuFileOpenReadOnly); - if (infp == nil) { - perror("fopen failed"); - exit(1); - } - } else { - fprintf(stderr, "ERROR: you have to specify a filename\n"); - exit(2); - } + if (argc == 2) { + infp = fopen(argv[1], kNuFileOpenReadOnly); + if (infp == nil) { + perror("fopen failed"); + exit(1); + } + } else { + fprintf(stderr, "ERROR: you have to specify a filename\n"); + exit(2); + } - cc = DoFileStuff(argv[1]); + cc = DoFileStuff(argv[1]); - exit(cc != 0); + exit(cc != 0); } diff --git a/nufxlib-0/samples/TestSimple.c b/nufxlib-0/samples/TestSimple.c index c0355e5..cb00289 100644 --- a/nufxlib-0/samples/TestSimple.c +++ b/nufxlib-0/samples/TestSimple.c @@ -24,11 +24,11 @@ NuResult ShowContents(NuArchive* pArchive, void* vpRecord) { - const NuRecord* pRecord = (NuRecord*) vpRecord; + const NuRecord* pRecord = (NuRecord*) vpRecord; - printf("*** Filename = '%s'\n", pRecord->filename); + printf("*** Filename = '%s'\n", pRecord->filename); - return kNuOK; + return kNuOK; } @@ -41,31 +41,31 @@ ShowContents(NuArchive* pArchive, void* vpRecord) int DoStreamStuff(FILE* fp) { - NuError err; - NuArchive* pArchive = nil; + NuError err; + NuArchive* pArchive = nil; - err = NuStreamOpenRO(fp, &pArchive); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: unable to open stream archive (err=%d)\n", err); - goto bail; - } + err = NuStreamOpenRO(fp, &pArchive); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: unable to open stream archive (err=%d)\n", err); + goto bail; + } - printf("*** Streaming contents!\n"); + printf("*** Streaming contents!\n"); - err = NuContents(pArchive, ShowContents); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: NuContents failed (err=%d)\n", err); - goto bail; - } + err = NuContents(pArchive, ShowContents); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: NuContents failed (err=%d)\n", err); + goto bail; + } bail: - if (pArchive != nil) { - NuError err2 = NuClose(pArchive); - if (err == kNuErrNone) - err = err2; - } + if (pArchive != nil) { + NuError err2 = NuClose(pArchive); + if (err == kNuErrNone) + err = err2; + } - return err; + return err; } @@ -75,31 +75,31 @@ bail: int main(int argc, char** argv) { - long major, minor, bug; - const char* pBuildDate; - FILE* infp = nil; - int cc; + long major, minor, bug; + const char* pBuildDate; + FILE* infp = nil; + int cc; - (void) NuGetVersion(&major, &minor, &bug, &pBuildDate, nil); - printf("Using NuFX lib %ld.%ld.%ld built on or after %s\n", - major, minor, bug, pBuildDate); + (void) NuGetVersion(&major, &minor, &bug, &pBuildDate, nil); + printf("Using NuFX lib %ld.%ld.%ld built on or after %s\n", + major, minor, bug, pBuildDate); - if (argc != 2) { - fprintf(stderr, "Usage: %s (archive-name|-)\n", argv[0]); - exit(2); - } + if (argc != 2) { + fprintf(stderr, "Usage: %s (archive-name|-)\n", argv[0]); + exit(2); + } - if (strcmp(argv[1], "-") == 0) - infp = stdin; - else { - infp = fopen(argv[1], kNuFileOpenReadOnly); - if (infp == nil) { - fprintf(stderr, "ERROR: unable to open '%s'\n", argv[1]); - exit(1); - } - } + if (strcmp(argv[1], "-") == 0) + infp = stdin; + else { + infp = fopen(argv[1], kNuFileOpenReadOnly); + if (infp == nil) { + fprintf(stderr, "ERROR: unable to open '%s'\n", argv[1]); + exit(1); + } + } - cc = DoStreamStuff(infp); - exit(cc != 0); + cc = DoStreamStuff(infp); + exit(cc != 0); } diff --git a/nulib2/Add.c b/nulib2/Add.c index fc3246d..c027199 100644 --- a/nulib2/Add.c +++ b/nulib2/Add.c @@ -17,58 +17,58 @@ static NuError AddToArchive(NulibState* pState, NuArchive* pArchive); NuError DoAdd(NulibState* pState) { - NuError err; - NuArchive* pArchive = nil; - long flushStatus; + NuError err; + NuArchive* pArchive = nil; + long flushStatus; - assert(pState != nil); + assert(pState != nil); - err = OpenArchiveReadWrite(pState); - if (err != kNuErrNone) - goto bail; + err = OpenArchiveReadWrite(pState); + if (err != kNuErrNone) + goto bail; - pArchive = NState_GetNuArchive(pState); - assert(pArchive != nil); + pArchive = NState_GetNuArchive(pState); + assert(pArchive != nil); - NState_SetMatchCount(pState, 0); + NState_SetMatchCount(pState, 0); - /* tell them about the list of files */ - err = AddToArchive(pState, pArchive); - if (err != kNuErrNone) - goto bail; + /* tell them about the list of files */ + err = AddToArchive(pState, pArchive); + if (err != kNuErrNone) + goto bail; - /*(void)NuDebugDumpArchive(pArchive);*/ + /*(void)NuDebugDumpArchive(pArchive);*/ - if (!NState_GetMatchCount(pState)) - printf("%s: no records matched\n", gProgName); + if (!NState_GetMatchCount(pState)) + printf("%s: no records matched\n", gProgName); bail: - if (pArchive != nil) { - NuError err2; + if (pArchive != nil) { + NuError err2; - #if 0 - if (err != kNuErrNone) { - printf("Attempting to flush changes in spite of errors...\n"); - err = kNuErrNone; - } - #endif + #if 0 + if (err != kNuErrNone) { + printf("Attempting to flush changes in spite of errors...\n"); + err = kNuErrNone; + } + #endif - if (err == kNuErrNone) { - err = NuFlush(pArchive, &flushStatus); - if (err != kNuErrNone && err == kNuErrNone) { - ReportError(err, - "Unable to flush archive changes (status=0x%04lx)", - flushStatus); - NuAbort(pArchive); - } - } else { - NuAbort(pArchive); - } + if (err == kNuErrNone) { + err = NuFlush(pArchive, &flushStatus); + if (err != kNuErrNone && err == kNuErrNone) { + ReportError(err, + "Unable to flush archive changes (status=0x%04lx)", + flushStatus); + NuAbort(pArchive); + } + } else { + NuAbort(pArchive); + } - err2 = NuClose(pArchive); - assert(err2 == kNuErrNone); - } - return err; + err2 = NuClose(pArchive); + assert(err2 == kNuErrNone); + } + return err; } @@ -81,29 +81,29 @@ bail: static NuError AddToArchive(NulibState* pState, NuArchive* pArchive) { - NuError err = kNuErrNone; - char* const* pSpec; - ulong fileCount; - int i; + NuError err = kNuErrNone; + char* const* pSpec; + ulong fileCount; + int i; - assert(pState != nil); - assert(pArchive != nil); + assert(pState != nil); + assert(pArchive != nil); - if (!NState_GetFilespecCount(pState)) { - err = kNuErrSyntax; - ReportError(err, "no files were specified"); - } + if (!NState_GetFilespecCount(pState)) { + err = kNuErrSyntax; + ReportError(err, "no files were specified"); + } - fileCount = 0; + fileCount = 0; - pSpec = NState_GetFilespecPointer(pState); - for (i = NState_GetFilespecCount(pState); i > 0; i--, pSpec++) { - err = AddFile(pState, pArchive, *pSpec); - if (err != kNuErrNone) - goto bail; - } + pSpec = NState_GetFilespecPointer(pState); + for (i = NState_GetFilespecCount(pState); i > 0; i--, pSpec++) { + err = AddFile(pState, pArchive, *pSpec); + if (err != kNuErrNone) + goto bail; + } bail: - return err; + return err; } diff --git a/nulib2/ArcUtils.c b/nulib2/ArcUtils.c index 16a6261..f21d41e 100644 --- a/nulib2/ArcUtils.c +++ b/nulib2/ArcUtils.c @@ -11,7 +11,7 @@ /* * =========================================================================== - * Output pathnames + * Output pathnames * =========================================================================== */ @@ -27,68 +27,68 @@ static NuResult OutputPathnameFilter(NuArchive* pArchive, void* vproposal) { - NuPathnameProposal* pathProposal = vproposal; - NulibState* pState; - const char* newPathname; - NuRecordIdx renameFromIdx; - char* renameToStr; - char* resultBuf; + NuPathnameProposal* pathProposal = vproposal; + NulibState* pState; + const char* newPathname; + NuRecordIdx renameFromIdx; + char* renameToStr; + char* resultBuf; - assert(pArchive != nil); - (void) NuGetExtraData(pArchive, (void**) &pState); - assert(pState != nil); + assert(pArchive != nil); + (void) NuGetExtraData(pArchive, (void**) &pState); + assert(pState != nil); - /* handle extract-to-pipe */ - if (NState_GetCommand(pState) == kCommandExtractToPipe) { - pathProposal->newDataSink = NState_GetPipeSink(pState); - NState_SetSuppressOutput(pState, true); - return kNuOK; - } + /* handle extract-to-pipe */ + if (NState_GetCommand(pState) == kCommandExtractToPipe) { + pathProposal->newDataSink = NState_GetPipeSink(pState); + NState_SetSuppressOutput(pState, true); + return kNuOK; + } - /* - * If they're trying to rename this file, do so now. We don't run - * the output through the normalizer; if the user typed it, assume - * that it's okay (and let the OS tell them if it isn't). - */ - renameToStr = NState_GetRenameToStr(pState); - if (renameToStr != nil) { - renameFromIdx = NState_GetRenameFromIdx(pState); + /* + * If they're trying to rename this file, do so now. We don't run + * the output through the normalizer; if the user typed it, assume + * that it's okay (and let the OS tell them if it isn't). + */ + renameToStr = NState_GetRenameToStr(pState); + if (renameToStr != nil) { + renameFromIdx = NState_GetRenameFromIdx(pState); - if (renameFromIdx == pathProposal->pRecord->recordIdx) { - /* right source file, proceed with the rename */ - NState_SetTempPathnameLen(pState, strlen(renameToStr) +1); - resultBuf = NState_GetTempPathnameBuf(pState); - assert(resultBuf != nil); - strcpy(resultBuf, renameToStr); + if (renameFromIdx == pathProposal->pRecord->recordIdx) { + /* right source file, proceed with the rename */ + NState_SetTempPathnameLen(pState, strlen(renameToStr) +1); + resultBuf = NState_GetTempPathnameBuf(pState); + assert(resultBuf != nil); + strcpy(resultBuf, renameToStr); - pathProposal->newPathname = resultBuf; - } + pathProposal->newPathname = resultBuf; + } - /* free up renameToStr */ - NState_SetRenameToStr(pState, nil); + /* free up renameToStr */ + NState_SetRenameToStr(pState, nil); - goto bail; - } + goto bail; + } - /* - * Convert the pathname into something suitable for the current OS. - */ - newPathname = NormalizePath(pState, pathProposal); - if (newPathname == nil) { - ReportError(kNuErrNone, "unable to convert pathname"); - return kNuAbort; - } + /* + * Convert the pathname into something suitable for the current OS. + */ + newPathname = NormalizePath(pState, pathProposal); + if (newPathname == nil) { + ReportError(kNuErrNone, "unable to convert pathname"); + return kNuAbort; + } - pathProposal->newPathname = newPathname; + pathProposal->newPathname = newPathname; bail: - return kNuOK; + return kNuOK; } /* * =========================================================================== - * User input + * User input * =========================================================================== */ @@ -102,18 +102,18 @@ bail: static char GetReplyChar(char defaultReply) { - char tmpBuf[32]; + char tmpBuf[32]; - if (fgets(tmpBuf, sizeof(tmpBuf), stdin) == nil) - return defaultReply; - if (tmpBuf[0] == '\n' || tmpBuf[0] == '\r') - return defaultReply; + if (fgets(tmpBuf, sizeof(tmpBuf), stdin) == nil) + return defaultReply; + if (tmpBuf[0] == '\n' || tmpBuf[0] == '\r') + return defaultReply; - return tmpBuf[0]; + return tmpBuf[0]; } -#define kMaxInputLen 128 +#define kMaxInputLen 128 /* * Get a string back from the user. @@ -123,25 +123,25 @@ GetReplyChar(char defaultReply) static char* GetReplyString(const char* prompt) { - char buf[kMaxInputLen]; - char* result; - int len; + char buf[kMaxInputLen]; + char* result; + int len; - printf("%s", prompt); - fflush(stdout); - result = fgets(buf, sizeof(buf), stdin); - if (result == nil || feof(stdin) || ferror(stdin) || buf[0] == '\0' || - buf[0] == '\n') - { - return nil; - } + printf("%s", prompt); + fflush(stdout); + result = fgets(buf, sizeof(buf), stdin); + if (result == nil || feof(stdin) || ferror(stdin) || buf[0] == '\0' || + buf[0] == '\n') + { + return nil; + } - /* nuke the terminating '\n', which is lots of fun in filenames */ - len = strlen(buf); - if (buf[len-1] == '\n') - buf[len-1] = '\0'; + /* nuke the terminating '\n', which is lots of fun in filenames */ + len = strlen(buf); + if (buf[len-1] == '\n') + buf[len-1] = '\0'; - return strdup(buf); + return strdup(buf); } @@ -155,41 +155,41 @@ GetReplyString(const char* prompt) char* GetSimpleComment(NulibState* pState, const char* pathname, int maxLen) { - char* buf = nil; - char* result; - int len; + char* buf = nil; + char* result; + int len; - buf = Malloc(maxLen); - if (buf == nil) - return nil; + buf = Malloc(maxLen); + if (buf == nil) + return nil; - printf("Enter one-line comment for '%s'\n: ", pathname); - fflush(stdout); + printf("Enter one-line comment for '%s'\n: ", pathname); + fflush(stdout); - result = fgets(buf, maxLen, stdin); - if (result == nil || feof(stdin) || ferror(stdin) || buf[0] == '\0' || - buf[0] == '\n') - { - Free(buf); - return nil; - } + result = fgets(buf, maxLen, stdin); + if (result == nil || feof(stdin) || ferror(stdin) || buf[0] == '\0' || + buf[0] == '\n') + { + Free(buf); + return nil; + } - /* nuke the terminating '\n', which we don't need */ - len = strlen(buf); - if (buf[len-1] == '\n') - buf[len-1] = '\0'; + /* nuke the terminating '\n', which we don't need */ + len = strlen(buf); + if (buf[len-1] == '\n') + buf[len-1] = '\0'; - return buf; + return buf; } /* * =========================================================================== - * Callbacks (progress updates, error handling, record selection) + * Callbacks (progress updates, error handling, record selection) * =========================================================================== */ -#define kMaxDisplayLen 60 +#define kMaxDisplayLen 60 /* * Returns "true" if the filespec in "spec" matches what's in "pRecord". @@ -199,10 +199,10 @@ GetSimpleComment(NulibState* pState, const char* pathname, int maxLen) static Boolean SpecMatchesRecord(NulibState* pState, const char* spec, const NuRecord* pRecord) { - if (NState_GetModRecurse(pState)) - return (strncmp(spec, pRecord->filename, strlen(spec)) == 0); - else - return (strcmp(spec, pRecord->filename) == 0); + if (NState_GetModRecurse(pState)) + return (strncmp(spec, pRecord->filename, strlen(spec)) == 0); + else + return (strcmp(spec, pRecord->filename) == 0); } /* @@ -214,19 +214,19 @@ SpecMatchesRecord(NulibState* pState, const char* spec, const NuRecord* pRecord) Boolean IsSpecified(NulibState* pState, const NuRecord* pRecord) { - char* const* pSpec; - int i; + char* const* pSpec; + int i; - if (!NState_GetFilespecCount(pState)) - return true; + if (!NState_GetFilespecCount(pState)) + return true; - pSpec = NState_GetFilespecPointer(pState); - for (i = NState_GetFilespecCount(pState); i > 0; i--, pSpec++) { - if (SpecMatchesRecord(pState, *pSpec, pRecord)) - return true; - } + pSpec = NState_GetFilespecPointer(pState); + for (i = NState_GetFilespecCount(pState); i > 0; i--, pSpec++) { + if (SpecMatchesRecord(pState, *pSpec, pRecord)) + return true; + } - return false; + return false; } @@ -237,23 +237,23 @@ IsSpecified(NulibState* pState, const NuRecord* pRecord) NuResult SelectionFilter(NuArchive* pArchive, void* vproposal) { - const NuSelectionProposal* selProposal = vproposal; - NulibState* pState; + const NuSelectionProposal* selProposal = vproposal; + NulibState* pState; - assert(pArchive != nil); - (void) NuGetExtraData(pArchive, (void**) &pState); - assert(pState != nil); + assert(pArchive != nil); + (void) NuGetExtraData(pArchive, (void**) &pState); + assert(pState != nil); - if (IsSpecified(pState, selProposal->pRecord)) { - NState_IncMatchCount(pState); + if (IsSpecified(pState, selProposal->pRecord)) { + NState_IncMatchCount(pState); - /* we don't get progress notifications for delete, so do it here */ - if (NState_GetCommand(pState) == kCommandDelete) - printf("Deleting %s\n", selProposal->pRecord->filename); + /* we don't get progress notifications for delete, so do it here */ + if (NState_GetCommand(pState) == kCommandDelete) + printf("Deleting %s\n", selProposal->pRecord->filename); - return kNuOK; - } else - return kNuSkip; + return kNuOK; + } else + return kNuSkip; } @@ -263,25 +263,25 @@ SelectionFilter(NuArchive* pArchive, void* vproposal) void PrintPercentage(ulong total, ulong progress) { - ulong perc; + ulong perc; - if (!total) { - /*printf(" %%");*/ - printf(" "); - return; - } + if (!total) { + /*printf(" %%");*/ + printf(" "); + return; + } - if (total < 21474836) { - perc = (progress * 100 + 50) / total; - if (perc > 100) - perc = 100; - } else { - perc = progress / (total / 100); - if (perc > 100) - perc = 100; - } + if (total < 21474836) { + perc = (progress * 100 + 50) / total; + if (perc > 100) + perc = 100; + } else { + perc = progress / (total / 100); + if (perc > 100) + perc = 100; + } - printf("%3ld%%", perc); + printf("%3ld%%", perc); } /* @@ -291,139 +291,139 @@ PrintPercentage(ulong total, ulong progress) NuResult ProgressUpdater(NuArchive* pArchive, void* vProgress) { - const NuProgressData* pProgress = vProgress; - NulibState* pState; - const char* percStr; - const char* actionStr; - char nameBuf[kMaxDisplayLen+1]; - Boolean showName, eolConv; + const NuProgressData* pProgress = vProgress; + NulibState* pState; + const char* percStr; + const char* actionStr; + char nameBuf[kMaxDisplayLen+1]; + Boolean showName, eolConv; - assert(pArchive != nil); - (void) NuGetExtraData(pArchive, (void**) &pState); - assert(pState != nil); + assert(pArchive != nil); + (void) NuGetExtraData(pArchive, (void**) &pState); + assert(pState != nil); - if (NState_GetSuppressOutput(pState)) - return kNuOK; + if (NState_GetSuppressOutput(pState)) + return kNuOK; - percStr = nil; - showName = false; - eolConv = false; + percStr = nil; + showName = false; + eolConv = false; - switch (pProgress->operation) { - case kNuOpAdd: - switch (pProgress->state) { - case kNuProgressPreparing: - case kNuProgressOpening: - actionStr = "adding "; - showName = true; - break; - case kNuProgressCompressing: - actionStr = "compressing"; - break; - case kNuProgressStoring: - actionStr = "storing "; - break; - default: - actionStr = "?????? "; - break; - } - break; - case kNuOpExtract: - switch (pProgress->state) { - case kNuProgressPreparing: - case kNuProgressOpening: - actionStr = "extracting"; - showName = true; - break; - case kNuProgressExpanding: - actionStr = "expanding "; - break; - case kNuProgressCopying: - actionStr = "extracting"; - break; - default: - actionStr = "?????? "; - break; - } - if (pProgress->expand.convertEOL == kNuConvertOn) - eolConv = true; - break; - case kNuOpTest: - switch (pProgress->state) { - case kNuProgressPreparing: - case kNuProgressOpening: - showName = true; - /* no break */ - case kNuProgressExpanding: - case kNuProgressCopying: - actionStr = "verifying"; - break; - default: - actionStr = "?????? "; - break; - } - break; - default: - assert(0); - actionStr = "????"; - } + switch (pProgress->operation) { + case kNuOpAdd: + switch (pProgress->state) { + case kNuProgressPreparing: + case kNuProgressOpening: + actionStr = "adding "; + showName = true; + break; + case kNuProgressCompressing: + actionStr = "compressing"; + break; + case kNuProgressStoring: + actionStr = "storing "; + break; + default: + actionStr = "?????? "; + break; + } + break; + case kNuOpExtract: + switch (pProgress->state) { + case kNuProgressPreparing: + case kNuProgressOpening: + actionStr = "extracting"; + showName = true; + break; + case kNuProgressExpanding: + actionStr = "expanding "; + break; + case kNuProgressCopying: + actionStr = "extracting"; + break; + default: + actionStr = "?????? "; + break; + } + if (pProgress->expand.convertEOL == kNuConvertOn) + eolConv = true; + break; + case kNuOpTest: + switch (pProgress->state) { + case kNuProgressPreparing: + case kNuProgressOpening: + showName = true; + /* no break */ + case kNuProgressExpanding: + case kNuProgressCopying: + actionStr = "verifying"; + break; + default: + actionStr = "?????? "; + break; + } + break; + default: + assert(0); + actionStr = "????"; + } - switch (pProgress->state) { - case kNuProgressDone: - actionStr = nil; - percStr = "DONE\n"; - break; - case kNuProgressSkipped: - actionStr = nil; - percStr = "SKIP\n"; - break; - case kNuProgressFailed: - actionStr = nil; - percStr = "FAIL\n"; - break; - default: - break; - } + switch (pProgress->state) { + case kNuProgressDone: + actionStr = nil; + percStr = "DONE\n"; + break; + case kNuProgressSkipped: + actionStr = nil; + percStr = "SKIP\n"; + break; + case kNuProgressFailed: + actionStr = nil; + percStr = "FAIL\n"; + break; + default: + break; + } - if (showName) { - /* - * Use "pathname" (whole thing) rather than "filename" (file part). - * Could also use "origPathname", but I like to show what they're - * getting instead of what they're giving. - */ - int len = strlen(pProgress->pathname); - if (len < sizeof(nameBuf)) { - strcpy(nameBuf, pProgress->pathname); - } else { - nameBuf[0] = nameBuf[1] = '.'; - strncpy(nameBuf+2, pProgress->pathname + len - (sizeof(nameBuf)-3), - sizeof(nameBuf)-3); - nameBuf[sizeof(nameBuf)-1] = '\0'; - } - } + if (showName) { + /* + * Use "pathname" (whole thing) rather than "filename" (file part). + * Could also use "origPathname", but I like to show what they're + * getting instead of what they're giving. + */ + int len = strlen(pProgress->pathname); + if (len < sizeof(nameBuf)) { + strcpy(nameBuf, pProgress->pathname); + } else { + nameBuf[0] = nameBuf[1] = '.'; + strncpy(nameBuf+2, pProgress->pathname + len - (sizeof(nameBuf)-3), + sizeof(nameBuf)-3); + nameBuf[sizeof(nameBuf)-1] = '\0'; + } + } - if (actionStr == nil && percStr != nil) { - printf("\r%s", percStr); - } else if (actionStr != nil && percStr == nil) { - if (percStr == nil) { - putc('\r', stdout); - PrintPercentage(pProgress->uncompressedLength, - pProgress->uncompressedProgress); - if (showName) - printf(" %s%s %s", actionStr, eolConv ? "+" : " ", nameBuf); - else - printf(" %s%s", actionStr, eolConv ? "+" : " "); - } - } else { - assert(0); - printf("????\n"); - } + if (actionStr == nil && percStr != nil) { + printf("\r%s", percStr); + } else if (actionStr != nil && percStr == nil) { + if (percStr == nil) { + putc('\r', stdout); + PrintPercentage(pProgress->uncompressedLength, + pProgress->uncompressedProgress); + if (showName) + printf(" %s%s %s", actionStr, eolConv ? "+" : " ", nameBuf); + else + printf(" %s%s", actionStr, eolConv ? "+" : " "); + } + } else { + assert(0); + printf("????\n"); + } - fflush(stdout); - /*printf(" %ld \n", pProgress->uncompressedProgress);*/ - /*usleep(250000);*/ + fflush(stdout); + /*printf(" %ld \n", pProgress->uncompressedProgress);*/ + /*usleep(250000);*/ - return kNuOK; + return kNuOK; } @@ -433,84 +433,84 @@ ProgressUpdater(NuArchive* pArchive, void* vProgress) */ static NuResult HandleReplaceExisting(NulibState* pState, NuArchive* pArchive, - const NuErrorStatus* pErrorStatus) + const NuErrorStatus* pErrorStatus) { - NuResult result = kNuOK; - char* renameName; - char reply; + NuResult result = kNuOK; + char* renameName; + char reply; - assert(pState != nil); - assert(pErrorStatus != nil); - assert(pErrorStatus->pathname != nil); + assert(pState != nil); + assert(pErrorStatus != nil); + assert(pErrorStatus->pathname != nil); - assert(pErrorStatus->canOverwrite); - assert(pErrorStatus->canSkip); - assert(pErrorStatus->canAbort); + assert(pErrorStatus->canOverwrite); + assert(pErrorStatus->canSkip); + assert(pErrorStatus->canAbort); - if (NState_GetInputUnavailable(pState)) { - putc('\n', stdout); - ReportError(pErrorStatus->err, "Giving up"); - result = kNuAbort; - goto bail; - } + if (NState_GetInputUnavailable(pState)) { + putc('\n', stdout); + ReportError(pErrorStatus->err, "Giving up"); + result = kNuAbort; + goto bail; + } - while (1) { - printf("\n Replace %s? [y]es, [n]o, [A]ll, [N]one", - pErrorStatus->pathname); - if (pErrorStatus->canRename) /* renaming records not allowed */ - printf(", [r]ename: "); - else - printf(": "); - fflush(stdout); + while (1) { + printf("\n Replace %s? [y]es, [n]o, [A]ll, [N]one", + pErrorStatus->pathname); + if (pErrorStatus->canRename) /* renaming records not allowed */ + printf(", [r]ename: "); + else + printf(": "); + fflush(stdout); - reply = GetReplyChar('n'); + reply = GetReplyChar('n'); - switch (reply) { - case 'y': - result = kNuOverwrite; - goto bail; - case 'n': - result = kNuSkip; - goto bail; - case 'A': - (void) NuSetValue(pArchive, kNuValueHandleExisting, - kNuAlwaysOverwrite); - result = kNuOverwrite; - goto bail; - case 'N': - (void) NuSetValue(pArchive, kNuValueHandleExisting, - kNuNeverOverwrite); - result = kNuSkip; - goto bail; - case 'r': - if (!pErrorStatus->canRename) { - printf("Response not acceptable\n"); - break; /* continue in "while" loop */ - } - renameName = GetReplyString("New name: "); - if (renameName == nil) - break; /* continue in "while" loop */ - if (pErrorStatus->pRecord == nil) { - ReportError(kNuErrNone, "Unexpected nil record"); - break; /* continue in "while" loop */ - } - NState_SetRenameFromIdx(pState, - pErrorStatus->pRecord->recordIdx); - NState_SetRenameToStr(pState, renameName); - result = kNuRename; - goto bail; - case 'q': /* stealth option to quit */ - case 'Q': - result = kNuAbort; - goto bail; - default: - printf("Response not understood -- please use y/n/A/N/r\n"); - break; /* continue in "while" loop */ - } - } + switch (reply) { + case 'y': + result = kNuOverwrite; + goto bail; + case 'n': + result = kNuSkip; + goto bail; + case 'A': + (void) NuSetValue(pArchive, kNuValueHandleExisting, + kNuAlwaysOverwrite); + result = kNuOverwrite; + goto bail; + case 'N': + (void) NuSetValue(pArchive, kNuValueHandleExisting, + kNuNeverOverwrite); + result = kNuSkip; + goto bail; + case 'r': + if (!pErrorStatus->canRename) { + printf("Response not acceptable\n"); + break; /* continue in "while" loop */ + } + renameName = GetReplyString("New name: "); + if (renameName == nil) + break; /* continue in "while" loop */ + if (pErrorStatus->pRecord == nil) { + ReportError(kNuErrNone, "Unexpected nil record"); + break; /* continue in "while" loop */ + } + NState_SetRenameFromIdx(pState, + pErrorStatus->pRecord->recordIdx); + NState_SetRenameToStr(pState, renameName); + result = kNuRename; + goto bail; + case 'q': /* stealth option to quit */ + case 'Q': + result = kNuAbort; + goto bail; + default: + printf("Response not understood -- please use y/n/A/N/r\n"); + break; /* continue in "while" loop */ + } + } bail: - return result; + return result; } /* @@ -521,50 +521,50 @@ bail: */ static NuResult HandleBadCRC(NulibState* pState, NuArchive* pArchive, - const NuErrorStatus* pErrorStatus) + const NuErrorStatus* pErrorStatus) { - NuResult result = kNuOK; - char reply; + NuResult result = kNuOK; + char reply; - assert(pState != nil); - assert(pErrorStatus != nil); + assert(pState != nil); + assert(pErrorStatus != nil); - if (NState_GetInputUnavailable(pState)) { - putc('\n', stderr); - ReportError(pErrorStatus->err, "Giving up"); - result = kNuAbort; - goto bail; - } + if (NState_GetInputUnavailable(pState)) { + putc('\n', stderr); + ReportError(pErrorStatus->err, "Giving up"); + result = kNuAbort; + goto bail; + } - while (1) { - if (pErrorStatus->pathname != nil) - fprintf(stderr, "\n Found a bad CRC in %s\n", - pErrorStatus->pathname); - else - fprintf(stderr, "\n Found a bad CRC in the archive\n"); + while (1) { + if (pErrorStatus->pathname != nil) + fprintf(stderr, "\n Found a bad CRC in %s\n", + pErrorStatus->pathname); + else + fprintf(stderr, "\n Found a bad CRC in the archive\n"); - fprintf(stderr, - " Archive may be damaged, continue anyway? [y]es, [n]o: "); - fflush(stderr); + fprintf(stderr, + " Archive may be damaged, continue anyway? [y]es, [n]o: "); + fflush(stderr); - reply = GetReplyChar('n'); + reply = GetReplyChar('n'); - switch (reply) { - case 'y': - result = kNuIgnore; - goto bail; - case 'n': - case 'N': - result = kNuAbort; - goto bail; - default: - fprintf(stderr, "Response not understood -- please use y/n\n"); - break; /* continue in "while" loop */ - } - } + switch (reply) { + case 'y': + result = kNuIgnore; + goto bail; + case 'n': + case 'N': + result = kNuAbort; + goto bail; + default: + fprintf(stderr, "Response not understood -- please use y/n\n"); + break; /* continue in "while" loop */ + } + } bail: - return result; + return result; } #if 0 @@ -573,45 +573,45 @@ bail: */ static NuResult HandleAddNotFound(NulibState* pState, NuArchive* pArchive, - const NuErrorStatus* pErrorStatus) + const NuErrorStatus* pErrorStatus) { - NuResult result = kNuOK; - char reply; + NuResult result = kNuOK; + char reply; - assert(pState != nil); - assert(pErrorStatus != nil); - assert(pErrorStatus->pathname != nil); + assert(pState != nil); + assert(pErrorStatus != nil); + assert(pErrorStatus->pathname != nil); - if (NState_GetInputUnavailable(pState)) { - putc('\n', stdout); - ReportError(pErrorStatus->err, "Giving up"); - result = kNuAbort; - goto bail; - } + if (NState_GetInputUnavailable(pState)) { + putc('\n', stdout); + ReportError(pErrorStatus->err, "Giving up"); + result = kNuAbort; + goto bail; + } - while (1) { - fprintf("\n Couldn't find %s, continue? [y]es, [n]o: ", - pErrorStatus->pathname); - fflush(stderr); + while (1) { + fprintf("\n Couldn't find %s, continue? [y]es, [n]o: ", + pErrorStatus->pathname); + fflush(stderr); - reply = GetReplyChar('n'); + reply = GetReplyChar('n'); - switch (reply) { - case 'y': - result = kNuSkip; - goto bail; - case 'n': - case 'N': - result = kNuAbort; - goto bail; - default: - fprintf(stderr, "Response not understood -- please use y/n\n"); - break; /* continue in "while" loop */ - } - } + switch (reply) { + case 'y': + result = kNuSkip; + goto bail; + case 'n': + case 'N': + result = kNuAbort; + goto bail; + default: + fprintf(stderr, "Response not understood -- please use y/n\n"); + break; /* continue in "while" loop */ + } + } bail: - return result; + return result; } #endif @@ -622,77 +622,77 @@ bail: NuResult ErrorHandler(NuArchive* pArchive, void* vErrorStatus) { - const NuErrorStatus* pErrorStatus = vErrorStatus; - NulibState* pState; - NuResult result; + const NuErrorStatus* pErrorStatus = vErrorStatus; + NulibState* pState; + NuResult result; - assert(pArchive != nil); - (void) NuGetExtraData(pArchive, (void**) &pState); - assert(pState != nil); + assert(pArchive != nil); + (void) NuGetExtraData(pArchive, (void**) &pState); + assert(pState != nil); - /* default action is to abort the current operation */ - result = kNuAbort; + /* default action is to abort the current operation */ + result = kNuAbort; - /* - * When extracting, the error handler callback gets invoked for several - * different problems because we might want to rename the file. Also, - * because extractions are done with "bulk" calls, returning an - * individual error message would be meaningless. - * - * When adding files, the NuAddFile and NuAddRecord calls can return - * immediate, specific results for a single add. The only reasons for - * calling here are to decide if an existing record should be replaced - * or not (without even an option to rename), or to decide what to do - * when the NuFlush call runs into a problem while adding a file. - */ - if (pErrorStatus->operation == kNuOpExtract) { - if (pErrorStatus->err == kNuErrFileExists) { - result = HandleReplaceExisting(pState, pArchive, pErrorStatus); - } else if (pErrorStatus->err == kNuErrNotNewer) { - /* if we were expecting this, it's okay */ - if (NState_GetModFreshen(pState) || NState_GetModUpdate(pState)) { - printf("\rSKIP\n"); - result = kNuSkip; - } else { - DBUG(("WEIRD one\n")); - } - } else if (pErrorStatus->err == kNuErrDuplicateNotFound) { - /* if we were expecting this, it's okay */ - if (NState_GetModFreshen(pState)) { - printf("\rSKIP\n"); - result = kNuSkip; - } else { - DBUG(("WEIRD two\n")); - } - } - } else if (pErrorStatus->operation == kNuOpAdd) { - if (pErrorStatus->err == kNuErrRecordExists) { - /* if they want to update or freshen, don't hassle them */ - if (NState_GetModFreshen(pState) || NState_GetModUpdate(pState)) - result = kNuOverwrite; - else - result = HandleReplaceExisting(pState, pArchive, pErrorStatus); - } else if (pErrorStatus->err == kNuErrFileNotFound) { - /* - * This should never happen, because NuLib2 verifies the - * presence of the files. (If you want to test this out, - * you have to "sabotage" AddFile, or remove a file from disk - * while NuFlush is running.) - */ - assert(0); - /*result = HandleAddNotFound(pState, pArchive, pErrorStatus);*/ - } - } else if (pErrorStatus->operation == kNuOpTest) { - if (pErrorStatus->err == kNuErrBadMHCRC || - pErrorStatus->err == kNuErrBadRHCRC || - pErrorStatus->err == kNuErrBadThreadCRC || - pErrorStatus->err == kNuErrBadDataCRC) - { - result = HandleBadCRC(pState, pArchive, pErrorStatus); - } - } + /* + * When extracting, the error handler callback gets invoked for several + * different problems because we might want to rename the file. Also, + * because extractions are done with "bulk" calls, returning an + * individual error message would be meaningless. + * + * When adding files, the NuAddFile and NuAddRecord calls can return + * immediate, specific results for a single add. The only reasons for + * calling here are to decide if an existing record should be replaced + * or not (without even an option to rename), or to decide what to do + * when the NuFlush call runs into a problem while adding a file. + */ + if (pErrorStatus->operation == kNuOpExtract) { + if (pErrorStatus->err == kNuErrFileExists) { + result = HandleReplaceExisting(pState, pArchive, pErrorStatus); + } else if (pErrorStatus->err == kNuErrNotNewer) { + /* if we were expecting this, it's okay */ + if (NState_GetModFreshen(pState) || NState_GetModUpdate(pState)) { + printf("\rSKIP\n"); + result = kNuSkip; + } else { + DBUG(("WEIRD one\n")); + } + } else if (pErrorStatus->err == kNuErrDuplicateNotFound) { + /* if we were expecting this, it's okay */ + if (NState_GetModFreshen(pState)) { + printf("\rSKIP\n"); + result = kNuSkip; + } else { + DBUG(("WEIRD two\n")); + } + } + } else if (pErrorStatus->operation == kNuOpAdd) { + if (pErrorStatus->err == kNuErrRecordExists) { + /* if they want to update or freshen, don't hassle them */ + if (NState_GetModFreshen(pState) || NState_GetModUpdate(pState)) + result = kNuOverwrite; + else + result = HandleReplaceExisting(pState, pArchive, pErrorStatus); + } else if (pErrorStatus->err == kNuErrFileNotFound) { + /* + * This should never happen, because NuLib2 verifies the + * presence of the files. (If you want to test this out, + * you have to "sabotage" AddFile, or remove a file from disk + * while NuFlush is running.) + */ + assert(0); + /*result = HandleAddNotFound(pState, pArchive, pErrorStatus);*/ + } + } else if (pErrorStatus->operation == kNuOpTest) { + if (pErrorStatus->err == kNuErrBadMHCRC || + pErrorStatus->err == kNuErrBadRHCRC || + pErrorStatus->err == kNuErrBadThreadCRC || + pErrorStatus->err == kNuErrBadDataCRC) + { + result = HandleBadCRC(pState, pArchive, pErrorStatus); + } + } - return result; + return result; } @@ -706,20 +706,20 @@ ErrorHandler(NuArchive* pArchive, void* vErrorStatus) NuResult 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", - pArchive == nil ? "(GLOBAL)" : "", - pErrorMessage->isDebug, pErrorMessage->err, pErrorMessage->file, - pErrorMessage->line, pErrorMessage->function, pErrorMessage->message); - return kNuOK; + fprintf(stderr, "%s%d %3d %s:%d %s %s\n", + pArchive == nil ? "(GLOBAL)" : "", + pErrorMessage->isDebug, pErrorMessage->err, pErrorMessage->file, + pErrorMessage->line, pErrorMessage->function, pErrorMessage->message); + return kNuOK; } #endif /* * =========================================================================== - * Open an archive + * Open an archive * =========================================================================== */ @@ -736,10 +736,10 @@ static const char* kStdinArchive = "-"; Boolean IsRecordReadOnly(const NuRecord* pRecord) { - if (pRecord->recAccess == 0x21L || pRecord->recAccess == 0x01L) - return true; - else - return false; + if (pRecord->recAccess == 0x21L || pRecord->recAccess == 0x01L) + return true; + else + return false; } @@ -749,8 +749,8 @@ IsRecordReadOnly(const NuRecord* pRecord) Boolean IsFilenameStdin(const char* archiveName) { - assert(archiveName != nil); - return (strcmp(archiveName, kStdinArchive) == 0); + assert(archiveName != nil); + return (strcmp(archiveName, kStdinArchive) == 0); } @@ -763,88 +763,88 @@ IsFilenameStdin(const char* archiveName) NuError OpenArchiveReadOnly(NulibState* pState) { - NuError err; - NuArchive* pArchive; + NuError err; + NuArchive* pArchive; - assert(pState != nil); + assert(pState != nil); - if (IsFilenameStdin(NState_GetArchiveFilename(pState))) { - err = NuStreamOpenRO(stdin, &pArchive); - if (err != kNuErrNone) { - ReportError(err, "unable to open create stdin archive"); - goto bail; - } - /* - * Since the archive is on stdin, we can't ask the user questions. - * On a UNIX system we could open /dev/tty, but that's not portable, - * and I don't think archives on stdin are going to be popular - * enough to make this worth doing. - */ - NState_SetInputUnavailable(pState, true); - } else { - err = NuOpenRO(NState_GetArchiveFilename(pState), &pArchive); - if (err != kNuErrNone) { - ReportError(err, "unable to open '%s'", - NState_GetArchiveFilename(pState)); - goto bail; - } - } + if (IsFilenameStdin(NState_GetArchiveFilename(pState))) { + err = NuStreamOpenRO(stdin, &pArchive); + if (err != kNuErrNone) { + ReportError(err, "unable to open create stdin archive"); + goto bail; + } + /* + * Since the archive is on stdin, we can't ask the user questions. + * On a UNIX system we could open /dev/tty, but that's not portable, + * and I don't think archives on stdin are going to be popular + * enough to make this worth doing. + */ + NState_SetInputUnavailable(pState, true); + } else { + err = NuOpenRO(NState_GetArchiveFilename(pState), &pArchive); + if (err != kNuErrNone) { + ReportError(err, "unable to open '%s'", + NState_GetArchiveFilename(pState)); + goto bail; + } + } - /* introduce them */ - NState_SetNuArchive(pState, pArchive); - err = NuSetExtraData(pArchive, pState); + /* introduce them */ + NState_SetNuArchive(pState, pArchive); + err = NuSetExtraData(pArchive, pState); - err = NuSetSelectionFilter(pArchive, SelectionFilter); - err = NuSetOutputPathnameFilter(pArchive, OutputPathnameFilter); - err = NuSetProgressUpdater(pArchive, ProgressUpdater); - err = NuSetErrorHandler(pArchive, ErrorHandler); - /*err = NuSetErrorMessageHandler(pArchive, ErrorMessageHandler);*/ + err = NuSetSelectionFilter(pArchive, SelectionFilter); + err = NuSetOutputPathnameFilter(pArchive, OutputPathnameFilter); + err = NuSetProgressUpdater(pArchive, ProgressUpdater); + err = NuSetErrorHandler(pArchive, ErrorHandler); + /*err = NuSetErrorMessageHandler(pArchive, ErrorMessageHandler);*/ - /* set the EOL conversion */ - if (NState_GetModConvertAll(pState)) - err = NuSetValue(pArchive, kNuValueConvertExtractedEOL, kNuConvertOn); - else if (NState_GetModConvertText(pState)) - err = NuSetValue(pArchive, kNuValueConvertExtractedEOL, kNuConvertAuto); - else - err = NuSetValue(pArchive, kNuValueConvertExtractedEOL, kNuConvertOff); - BailError(err); + /* set the EOL conversion */ + if (NState_GetModConvertAll(pState)) + err = NuSetValue(pArchive, kNuValueConvertExtractedEOL, kNuConvertOn); + else if (NState_GetModConvertText(pState)) + err = NuSetValue(pArchive, kNuValueConvertExtractedEOL, kNuConvertAuto); + else + err = NuSetValue(pArchive, kNuValueConvertExtractedEOL, kNuConvertOff); + BailError(err); - /* handle "-s" flag */ - if (NState_GetModOverwriteExisting(pState)) { - err = NuSetValue(pArchive, kNuValueHandleExisting, kNuAlwaysOverwrite); - BailError(err); - } + /* handle "-s" flag */ + if (NState_GetModOverwriteExisting(pState)) { + err = NuSetValue(pArchive, kNuValueHandleExisting, kNuAlwaysOverwrite); + BailError(err); + } - /* handle "-f" and "-u" flags (this overrides "-s" during extraction) */ - if (NState_GetModFreshen(pState) || NState_GetModUpdate(pState)) { - err = NuSetValue(pArchive, kNuValueOnlyUpdateOlder, true); - BailError(err); - } - if (NState_GetModFreshen(pState)) { - err = NuSetValue(pArchive, kNuValueHandleExisting, kNuMustOverwrite); - BailError(err); - } + /* handle "-f" and "-u" flags (this overrides "-s" during extraction) */ + if (NState_GetModFreshen(pState) || NState_GetModUpdate(pState)) { + err = NuSetValue(pArchive, kNuValueOnlyUpdateOlder, true); + BailError(err); + } + if (NState_GetModFreshen(pState)) { + err = NuSetValue(pArchive, kNuValueHandleExisting, kNuMustOverwrite); + BailError(err); + } - DBUG(("--- enabling ShrinkIt compatibility mode\n")); - err = NuSetValue(pArchive, kNuValueMimicSHK, true); - BailError(err); + DBUG(("--- enabling ShrinkIt compatibility mode\n")); + err = NuSetValue(pArchive, kNuValueMimicSHK, true); + BailError(err); - if (strcmp(SYSTEM_DEFAULT_EOL, "\r") == 0) - err = NuSetValue(pArchive, kNuValueEOL, kNuEOLCR); - else if (strcmp(SYSTEM_DEFAULT_EOL, "\n") == 0) - err = NuSetValue(pArchive, kNuValueEOL, kNuEOLLF); - else if (strcmp(SYSTEM_DEFAULT_EOL, "\r\n") == 0) - err = NuSetValue(pArchive, kNuValueEOL, kNuEOLCRLF); - else { - assert(0); - err = kNuErrInternal; - ReportError(err, "Unknown SYSTEM_DEFAULT_EOL '%s'", SYSTEM_DEFAULT_EOL); - goto bail; - } - BailError(err); + if (strcmp(SYSTEM_DEFAULT_EOL, "\r") == 0) + err = NuSetValue(pArchive, kNuValueEOL, kNuEOLCR); + else if (strcmp(SYSTEM_DEFAULT_EOL, "\n") == 0) + err = NuSetValue(pArchive, kNuValueEOL, kNuEOLLF); + else if (strcmp(SYSTEM_DEFAULT_EOL, "\r\n") == 0) + err = NuSetValue(pArchive, kNuValueEOL, kNuEOLCRLF); + else { + assert(0); + err = kNuErrInternal; + ReportError(err, "Unknown SYSTEM_DEFAULT_EOL '%s'", SYSTEM_DEFAULT_EOL); + goto bail; + } + BailError(err); bail: - return err; + return err; } @@ -857,79 +857,79 @@ bail: NuError OpenArchiveReadWrite(NulibState* pState) { - NuError err = kNuErrNone; - NuArchive* pArchive; - char* tempName = nil; + NuError err = kNuErrNone; + NuArchive* pArchive; + char* tempName = nil; - assert(pState != nil); - assert(IsFilenameStdin(NState_GetArchiveFilename(pState)) == false); + assert(pState != nil); + assert(IsFilenameStdin(NState_GetArchiveFilename(pState)) == false); - tempName = MakeTempArchiveName(pState); - if (tempName == nil) - goto bail; - DBUG(("TEMP NAME = '%s'\n", tempName)); + tempName = MakeTempArchiveName(pState); + if (tempName == nil) + goto bail; + DBUG(("TEMP NAME = '%s'\n", tempName)); - err = NuOpenRW(NState_GetArchiveFilename(pState), tempName, - kNuOpenCreat, &pArchive); - if (err != kNuErrNone) { - ReportError(err, "unable to open '%s'", - NState_GetArchiveFilename(pState)); - goto bail; - } + err = NuOpenRW(NState_GetArchiveFilename(pState), tempName, + kNuOpenCreat, &pArchive); + if (err != kNuErrNone) { + ReportError(err, "unable to open '%s'", + NState_GetArchiveFilename(pState)); + goto bail; + } - /* introduce them */ - NState_SetNuArchive(pState, pArchive); - err = NuSetExtraData(pArchive, pState); - BailError(err); + /* introduce them */ + NState_SetNuArchive(pState, pArchive); + err = NuSetExtraData(pArchive, pState); + BailError(err); - err = NuSetSelectionFilter(pArchive, SelectionFilter); - BailError(err) - err = NuSetProgressUpdater(pArchive, ProgressUpdater); - BailError(err) - err = NuSetErrorHandler(pArchive, ErrorHandler); - BailError(err) - /*err = NuSetErrorMessageHandler(pArchive, ErrorMessageHandler);*/ + err = NuSetSelectionFilter(pArchive, SelectionFilter); + BailError(err) + err = NuSetProgressUpdater(pArchive, ProgressUpdater); + BailError(err) + err = NuSetErrorHandler(pArchive, ErrorHandler); + BailError(err) + /*err = NuSetErrorMessageHandler(pArchive, ErrorMessageHandler);*/ - /* handle "-0" flag */ - if (NState_GetModNoCompression(pState)) { - err = NuSetValue(pArchive, kNuValueDataCompression, kNuCompressNone); - BailError(err); - } + /* handle "-0" flag */ + if (NState_GetModNoCompression(pState)) { + err = NuSetValue(pArchive, kNuValueDataCompression, kNuCompressNone); + BailError(err); + } - /* handle "-f" and "-u" flags */ - /* (BUG: if "-f" is set, creating a new archive is impossible) */ - if (NState_GetModFreshen(pState) || NState_GetModUpdate(pState)) { - err = NuSetValue(pArchive, kNuValueOnlyUpdateOlder, true); - BailError(err); - } - if (NState_GetModFreshen(pState)) { - err = NuSetValue(pArchive, kNuValueHandleExisting, kNuMustOverwrite); - BailError(err); - } + /* handle "-f" and "-u" flags */ + /* (BUG: if "-f" is set, creating a new archive is impossible) */ + if (NState_GetModFreshen(pState) || NState_GetModUpdate(pState)) { + err = NuSetValue(pArchive, kNuValueOnlyUpdateOlder, true); + BailError(err); + } + if (NState_GetModFreshen(pState)) { + err = NuSetValue(pArchive, kNuValueHandleExisting, kNuMustOverwrite); + BailError(err); + } - DBUG(("--- enabling ShrinkIt compatibility mode\n")); - err = NuSetValue(pArchive, kNuValueMimicSHK, true); - BailError(err); + DBUG(("--- enabling ShrinkIt compatibility mode\n")); + err = NuSetValue(pArchive, kNuValueMimicSHK, true); + BailError(err); - /* this probably isn't needed here, but set it anyway */ - if (strcmp(SYSTEM_DEFAULT_EOL, "\r") == 0) - err = NuSetValue(pArchive, kNuValueEOL, kNuEOLCR); - else if (strcmp(SYSTEM_DEFAULT_EOL, "\n") == 0) - err = NuSetValue(pArchive, kNuValueEOL, kNuEOLLF); - else if (strcmp(SYSTEM_DEFAULT_EOL, "\r\n") == 0) - err = NuSetValue(pArchive, kNuValueEOL, kNuEOLCRLF); - else { - assert(0); - err = kNuErrInternal; - ReportError(err, "Unknown SYSTEM_DEFAULT_EOL '%s'", SYSTEM_DEFAULT_EOL); - goto bail; - } - BailError(err); + /* this probably isn't needed here, but set it anyway */ + if (strcmp(SYSTEM_DEFAULT_EOL, "\r") == 0) + err = NuSetValue(pArchive, kNuValueEOL, kNuEOLCR); + else if (strcmp(SYSTEM_DEFAULT_EOL, "\n") == 0) + err = NuSetValue(pArchive, kNuValueEOL, kNuEOLLF); + else if (strcmp(SYSTEM_DEFAULT_EOL, "\r\n") == 0) + err = NuSetValue(pArchive, kNuValueEOL, kNuEOLCRLF); + else { + assert(0); + err = kNuErrInternal; + ReportError(err, "Unknown SYSTEM_DEFAULT_EOL '%s'", SYSTEM_DEFAULT_EOL); + goto bail; + } + BailError(err); - /*(void) NuSetValue(pArchive, kNuValueAllowDuplicates, true);*/ + /*(void) NuSetValue(pArchive, kNuValueAllowDuplicates, true);*/ bail: - Free(tempName); - return err; + Free(tempName); + return err; } diff --git a/nulib2/ChangeLog.txt b/nulib2/ChangeLog.txt index 52b1288..81f0249 100644 --- a/nulib2/ChangeLog.txt +++ b/nulib2/ChangeLog.txt @@ -1,125 +1,129 @@ -2000/05/22 ***** v1.0.1 shipped (no changes - version follows nufxlib) ***** +2002/09/20 fadden + - pulled the sources out and started fiddling with them again + - changed hard tabs to spaces -2000/05/18 ***** v1.0.0 shipped ***** +2000/05/22 ***** v1.0.1 shipped (no changes - version follows nufxlib) ***** -2000/05/18 fadden - - added nulib2 to set of things stripped by "distbin" - - updated version information to indicate final release +2000/05/18 ***** v1.0.0 shipped ***** -2000/03/25 ***** v0.6.1 shipped ***** +2000/05/18 fadden + - added nulib2 to set of things stripped by "distbin" + - updated version information to indicate final release + +2000/03/25 ***** v0.6.1 shipped ***** 2000/03/25 fadden - - Sheppy says Mac OS X PPC v1.02 and v1.2 work with minor SysDefs tweak + - Sheppy says Mac OS X PPC v1.02 and v1.2 work with minor SysDefs tweak -2000/03/05 ***** v0.6.0 (beta) shipped ***** +2000/03/05 ***** v0.6.0 (beta) shipped ***** -2000/03/05 fadden - - don't call mktemp(), just pass template into NuOpenRW - - removed DEBUG_MSGS from default CFLAGS - - updated version information to indicate beta release +2000/03/05 fadden + - don't call mktemp(), just pass template into NuOpenRW + - removed DEBUG_MSGS from default CFLAGS + - updated version information to indicate beta release -2000/02/24 ***** v0.5.1 shipped ***** +2000/02/24 ***** v0.5.1 shipped ***** -2000/02/20 changes from Scott Blackman - - portability fixes for DJGPP under Win95 +2000/02/20 changes from Scott Blackman + - portability fixes for DJGPP under Win95 -2000/02/17 changes from Devin Reade - - portability fixes for BSD, AIX, and others - - added "distbin" target +2000/02/17 changes from Devin Reade + - portability fixes for BSD, AIX, and others + - added "distbin" target -2000/02/09 ***** v0.5.0 (alpha) shipped ***** +2000/02/09 ***** v0.5.0 (alpha) shipped ***** -2000/02/09 fadden - - changed the comparison used when extracting/deleting a list of files - from strcasecmp to strcmp, since NufxLib does case-sensitive compares. - - fixed the percentage for files and archives larger than 21MB +2000/02/09 fadden + - changed the comparison used when extracting/deleting a list of files + from strcasecmp to strcmp, since NufxLib does case-sensitive compares. + - fixed the percentage for files and archives larger than 21MB -2000/02/08 fadden - - tweaked the BeOS/PPC config around a little - - deleted some commas to make "gcc -pedantic" happy - - changed version to x.y.z format here too - - generalized the "aux" handling to include all MS-DOS device names +2000/02/08 fadden + - tweaked the BeOS/PPC config around a little + - deleted some commas to make "gcc -pedantic" happy + - changed version to x.y.z format here too + - generalized the "aux" handling to include all MS-DOS device names -2000/02/06 fadden - - include @CFLAGS@ in case somebody wants to override them +2000/02/06 fadden + - include @CFLAGS@ in case somebody wants to override them -2000/02/06 ***** v0.4b shipped ***** +2000/02/06 ***** v0.4b shipped ***** -2000/02/06 fadden - - added "install-shared" make target - - portability fixes for HP/UX +2000/02/06 fadden + - added "install-shared" make target + - portability fixes for HP/UX -2000/02/06 ***** v0.4a shipped ***** +2000/02/06 ***** v0.4a shipped ***** -2000/02/06 fadden - - massaged configure.in for BeOS, and added some type casts for mwerks +2000/02/06 fadden + - massaged configure.in for BeOS, and added some type casts for mwerks -2000/02/06 ***** v0.4 shipped ***** +2000/02/06 ***** v0.4 shipped ***** -2000/02/05 fadden - - added "mkinstalldirs" to install target - - added Win32 makefile - - made a few implicit typecasts explicit for Visual C++'s benefit - - change "aux" to "_aux", because FAT filesystems choke on it +2000/02/05 fadden + - added "mkinstalldirs" to install target + - added Win32 makefile + - made a few implicit typecasts explicit for Visual C++'s benefit + - change "aux" to "_aux", because FAT filesystems choke on it -2000/02/04 fadden - - added Win32 recursive directory descent +2000/02/04 fadden + - added Win32 recursive directory descent -2000/02/02 fadden - - minor changes to get it working under Win32 (Visual C++ 6.0) - - added --enable-dmalloc to configuration +2000/02/02 fadden + - minor changes to get it working under Win32 (Visual C++ 6.0) + - added --enable-dmalloc to configuration -2000/02/01 fadden - - screen out leading "./", and junk the path if ".." shows up in path - - don't try to add comments to records we're skipping - - set kNuValueEOL appropriately for the current system +2000/02/01 fadden + - screen out leading "./", and junk the path if ".." shows up in path + - don't try to add comments to records we're skipping + - set kNuValueEOL appropriately for the current system -2000/01/29 ***** v0.3 shipped ***** +2000/01/29 ***** v0.3 shipped ***** -2000/01/29 fadden - - added "make install" target, with the standard autoconf defines - - added some examples to the man page +2000/01/29 fadden + - added "make install" target, with the standard autoconf defines + - added some examples to the man page -2000/01/28 fadden - - merged "Kind" and "Type" columns in "v" output - - display a '+' when doing EOL conversions on an extracted file +2000/01/28 fadden + - merged "Kind" and "Type" columns in "v" output + - display a '+' when doing EOL conversions on an extracted file -2000/01/26 fadden - - added UI for allowing the user to ignore bad CRCs - - implemented "-j" (junk paths) for add and extract - - implemented "-c" (comments) for add and extract - - added totals to bottom of "v" output +2000/01/26 fadden + - added UI for allowing the user to ignore bad CRCs + - implemented "-j" (junk paths) for add and extract + - implemented "-c" (comments) for add and extract + - added totals to bottom of "v" output -2000/01/25 fadden - - when extracting without type preservation, append "_rsrc_" to - resource forks +2000/01/25 fadden + - when extracting without type preservation, append "_rsrc_" to + resource forks -2000/01/24 fadden - - added support for "-k" (add as disk image) flag +2000/01/24 fadden + - added support for "-k" (add as disk image) flag -2000/01/24 ***** v0.2 shipped ***** +2000/01/24 ***** v0.2 shipped ***** -2000/01/22 fadden - - added support for "-u" (update) and "-f" (freshen) flags - - set file dates in AddFile call +2000/01/22 fadden + - added support for "-u" (update) and "-f" (freshen) flags + - set file dates in AddFile call -2000/01/20 fadden - - restructed the progress updater +2000/01/20 fadden + - restructed the progress updater -2000/01/19 fadden - - normalized SysDefs.h, changing UNIX to UNIX_LIKE and defining for BeOS - - added "shared" target to makefile - - added BeOS stuff to autoconf setup +2000/01/19 fadden + - normalized SysDefs.h, changing UNIX to UNIX_LIKE and defining for BeOS + - added "shared" target to makefile + - added BeOS stuff to autoconf setup -2000/01/17 fadden - - started recording locked/unlocked status - - some BeOS/Metrowerks "it's not gcc" changes from Eric Shepherd - - implemented "-s" (stomp existing) and "-0" (no compression) modifiers +2000/01/17 fadden + - started recording locked/unlocked status + - some BeOS/Metrowerks "it's not gcc" changes from Eric Shepherd + - implemented "-s" (stomp existing) and "-0" (no compression) modifiers -2000/01/17 ***** v0.1 shipped ***** +2000/01/17 ***** v0.1 shipped ***** (much time passes) -mid-1998 fadden - - work begins +mid-1998 fadden + - work begins diff --git a/nulib2/Delete.c b/nulib2/Delete.c index 1dfa9c1..06675e5 100644 --- a/nulib2/Delete.c +++ b/nulib2/Delete.c @@ -18,29 +18,29 @@ NuError DoDelete(NulibState* pState) { - NuError err; - NuArchive* pArchive = nil; + NuError err; + NuArchive* pArchive = nil; - assert(pState != nil); + assert(pState != nil); - err = OpenArchiveReadWrite(pState); - if (err != kNuErrNone) - goto bail; - pArchive = NState_GetNuArchive(pState); - assert(pArchive != nil); + err = OpenArchiveReadWrite(pState); + if (err != kNuErrNone) + goto bail; + pArchive = NState_GetNuArchive(pState); + assert(pArchive != nil); - NState_SetMatchCount(pState, 0); + NState_SetMatchCount(pState, 0); - err = NuDelete(pArchive); - if (err != kNuErrNone) - goto bail; + err = NuDelete(pArchive); + if (err != kNuErrNone) + goto bail; - if (!NState_GetMatchCount(pState)) - printf("%s: no records matched\n", gProgName); + if (!NState_GetMatchCount(pState)) + printf("%s: no records matched\n", gProgName); bail: - if (pArchive != nil) - (void) NuClose(pArchive); - return err; + if (pArchive != nil) + (void) NuClose(pArchive); + return err; } diff --git a/nulib2/Extract.c b/nulib2/Extract.c index 7fdfbc8..d14103f 100644 --- a/nulib2/Extract.c +++ b/nulib2/Extract.c @@ -20,67 +20,67 @@ static NuError ExtractAllRecords(NulibState* pState, NuArchive* pArchive) { - NuError err; - const NuRecord* pRecord; - const NuThread* pThread; - NuRecordIdx recordIdx; - NuAttr numRecords; - int idx, threadIdx; + NuError err; + const NuRecord* pRecord; + const NuThread* pThread; + NuRecordIdx recordIdx; + NuAttr numRecords; + int idx, threadIdx; - DBUG(("--- doing manual extract\n")); - assert(NState_GetCommand(pState) == kCommandExtract); /* no "-p" here */ + DBUG(("--- doing manual extract\n")); + assert(NState_GetCommand(pState) == kCommandExtract); /* no "-p" here */ - err = NuGetAttr(pArchive, kNuAttrNumRecords, &numRecords); - for (idx = 0; idx < (int) numRecords; idx++) { - err = NuGetRecordIdxByPosition(pArchive, idx, &recordIdx); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: couldn't get record #%d (err=%d)\n", - idx, err); - goto bail; - } + err = NuGetAttr(pArchive, kNuAttrNumRecords, &numRecords); + for (idx = 0; idx < (int) numRecords; idx++) { + err = NuGetRecordIdxByPosition(pArchive, idx, &recordIdx); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: couldn't get record #%d (err=%d)\n", + idx, err); + goto bail; + } - err = NuGetRecord(pArchive, recordIdx, &pRecord); - if (err != kNuErrNone) { - fprintf(stderr, "ERROR: unable to get recordIdx %ld\n", recordIdx); - goto bail; - } + err = NuGetRecord(pArchive, recordIdx, &pRecord); + if (err != kNuErrNone) { + fprintf(stderr, "ERROR: unable to get recordIdx %ld\n", recordIdx); + goto bail; + } - /* do we want to extract this record? */ - if (!IsSpecified(pState, pRecord)) - continue; - NState_IncMatchCount(pState); + /* do we want to extract this record? */ + if (!IsSpecified(pState, pRecord)) + continue; + NState_IncMatchCount(pState); - /* - * Look for a comment thread. - */ - for (threadIdx = 0; (ulong)threadIdx < pRecord->recTotalThreads; - threadIdx++) - { - pThread = NuGetThread(pRecord, threadIdx); - assert(pThread != nil); + /* + * Look for a comment thread. + */ + for (threadIdx = 0; (ulong)threadIdx < pRecord->recTotalThreads; + threadIdx++) + { + pThread = NuGetThread(pRecord, threadIdx); + assert(pThread != nil); - if (NuGetThreadID(pThread) == kNuThreadIDComment && - pThread->actualThreadEOF > 0) - { - printf("----- '%s':\n", pRecord->filename); - err = NuExtractThread(pArchive, pThread->threadIdx, - NState_GetCommentSink(pState)); - if (err != kNuErrNone) { - printf("[comment extraction failed, continuing\n"); - } else { - printf("\n-----\n"); - } - } - } + if (NuGetThreadID(pThread) == kNuThreadIDComment && + pThread->actualThreadEOF > 0) + { + printf("----- '%s':\n", pRecord->filename); + err = NuExtractThread(pArchive, pThread->threadIdx, + NState_GetCommentSink(pState)); + if (err != kNuErrNone) { + printf("[comment extraction failed, continuing\n"); + } else { + printf("\n-----\n"); + } + } + } - /* extract the record, using the usual mechanisms */ - err = NuExtractRecord(pArchive, recordIdx); - if (err != kNuErrNone) - goto bail; - } + /* extract the record, using the usual mechanisms */ + err = NuExtractRecord(pArchive, recordIdx); + if (err != kNuErrNone) + goto bail; + } bail: - return err; + return err; } @@ -90,40 +90,40 @@ bail: NuError DoExtract(NulibState* pState) { - NuError err; - NuArchive* pArchive = nil; + NuError err; + NuArchive* pArchive = nil; - assert(pState != nil); + assert(pState != nil); - err = OpenArchiveReadOnly(pState); - if (err != kNuErrNone) - goto bail; - pArchive = NState_GetNuArchive(pState); - assert(pArchive != nil); + err = OpenArchiveReadOnly(pState); + if (err != kNuErrNone) + goto bail; + pArchive = NState_GetNuArchive(pState); + assert(pArchive != nil); - NState_SetMatchCount(pState, 0); + NState_SetMatchCount(pState, 0); - /* - * If we're not interested in comments, just use the "bulk" extract - * call. If we want comments, we need to do this one at a time. - */ - if (!NState_GetModComments(pState)) { - err = NuExtract(pArchive); - if (err != kNuErrNone) - goto bail; - } else { - err = ExtractAllRecords(pState, pArchive); - if (err != kNuErrNone) - goto bail; - } + /* + * If we're not interested in comments, just use the "bulk" extract + * call. If we want comments, we need to do this one at a time. + */ + if (!NState_GetModComments(pState)) { + err = NuExtract(pArchive); + if (err != kNuErrNone) + goto bail; + } else { + err = ExtractAllRecords(pState, pArchive); + if (err != kNuErrNone) + goto bail; + } - if (!NState_GetMatchCount(pState)) - printf("%s: no records match\n", gProgName); + if (!NState_GetMatchCount(pState)) + printf("%s: no records match\n", gProgName); bail: - if (pArchive != nil) - (void) NuClose(pArchive); - return err; + if (pArchive != nil) + (void) NuClose(pArchive); + return err; } @@ -133,8 +133,8 @@ bail: NuError DoExtractToPipe(NulibState* pState) { - /* we handle the "to pipe" part farther down */ - return DoExtract(pState); + /* we handle the "to pipe" part farther down */ + return DoExtract(pState); } @@ -144,29 +144,29 @@ DoExtractToPipe(NulibState* pState) NuError DoTest(NulibState* pState) { - NuError err; - NuArchive* pArchive = nil; + NuError err; + NuArchive* pArchive = nil; - assert(pState != nil); + assert(pState != nil); - err = OpenArchiveReadOnly(pState); - if (err != kNuErrNone) - goto bail; - pArchive = NState_GetNuArchive(pState); - assert(pArchive != nil); + err = OpenArchiveReadOnly(pState); + if (err != kNuErrNone) + goto bail; + pArchive = NState_GetNuArchive(pState); + assert(pArchive != nil); - NState_SetMatchCount(pState, 0); + NState_SetMatchCount(pState, 0); - err = NuTest(pArchive); - if (err != kNuErrNone) - goto bail; + err = NuTest(pArchive); + if (err != kNuErrNone) + goto bail; - if (!NState_GetMatchCount(pState)) - printf("%s: no records match\n", gProgName); + if (!NState_GetMatchCount(pState)) + printf("%s: no records match\n", gProgName); bail: - if (pArchive != nil) - (void) NuClose(pArchive); - return err; + if (pArchive != nil) + (void) NuClose(pArchive); + return err; } diff --git a/nulib2/Filename.c b/nulib2/Filename.c index d623e5a..5faf42c 100644 --- a/nulib2/Filename.c +++ b/nulib2/Filename.c @@ -12,55 +12,55 @@ /* * =========================================================================== - * Common definitions + * Common definitions * =========================================================================== */ -#define kPreserveIndic '#' /* use # rather than $ for hex indication */ -#define kFilenameExtDelim '.' /* separates extension from filename */ -#define kResourceFlag 'r' -#define kDiskImageFlag 'i' -#define kMaxExtLen 4 /* ".1234" */ -#define kResourceStr "_rsrc_" +#define kPreserveIndic '#' /* use # rather than $ for hex indication */ +#define kFilenameExtDelim '.' /* separates extension from filename */ +#define kResourceFlag 'r' +#define kDiskImageFlag 'i' +#define kMaxExtLen 4 /* ".1234" */ +#define kResourceStr "_rsrc_" /* must be longer then strlen(kResourceStr)... no problem there */ -#define kMaxPathGrowth (sizeof("#XXXXXXXXYYYYYYYYZ")-1 + kMaxExtLen+1) +#define kMaxPathGrowth (sizeof("#XXXXXXXXYYYYYYYYZ")-1 + kMaxExtLen+1) /* ProDOS file type names; must be entirely in upper case */ static const char gFileTypeNames[256][4] = { - "NON", "BAD", "PCD", "PTX", "TXT", "PDA", "BIN", "FNT", - "FOT", "BA3", "DA3", "WPF", "SOS", "$0D", "$0E", "DIR", - "RPD", "RPI", "AFD", "AFM", "AFR", "SCL", "PFS", "$17", - "$18", "ADB", "AWP", "ASP", "$1C", "$1D", "$1E", "$1F", - "TDM", "$21", "$22", "$23", "$24", "$25", "$26", "$27", - "$28", "$29", "8SC", "8OB", "8IC", "8LD", "P8C", "$2F", - "$30", "$31", "$32", "$33", "$34", "$35", "$36", "$37", - "$38", "$39", "$3A", "$3B", "$3C", "$3D", "$3E", "$3F", - "DIC", "OCR", "FTD", "$43", "$44", "$45", "$46", "$47", - "$48", "$49", "$4A", "$4B", "$4C", "$4D", "$4E", "$4F", - "GWP", "GSS", "GDB", "DRW", "GDP", "HMD", "EDU", "STN", - "HLP", "COM", "CFG", "ANM", "MUM", "ENT", "DVU", "FIN", - "$60", "$61", "$62", "$63", "$64", "$65", "$66", "$67", - "$68", "$69", "$6A", "BIO", "$6C", "TDR", "PRE", "HDV", - "$70", "$71", "$72", "$73", "$74", "$75", "$76", "$77", - "$78", "$79", "$7A", "$7B", "$7C", "$7D", "$7E", "$7F", - "$80", "$81", "$82", "$83", "$84", "$85", "$86", "$87", - "$88", "$89", "$8A", "$8B", "$8C", "$8D", "$8E", "$8F", - "$90", "$91", "$92", "$93", "$94", "$95", "$96", "$97", - "$98", "$99", "$9A", "$9B", "$9C", "$9D", "$9E", "$9F", - "WP ", "$A1", "$A2", "$A3", "$A4", "$A5", "$A6", "$A7", - "$A8", "$A9", "$AA", "GSB", "TDF", "BDF", "$AE", "$AF", - "SRC", "OBJ", "LIB", "S16", "RTL", "EXE", "PIF", "TIF", - "NDA", "CDA", "TOL", "DVR", "LDF", "FST", "$BE", "DOC", - "PNT", "PIC", "ANI", "PAL", "$C4", "OOG", "SCR", "CDV", - "FON", "FND", "ICN", "$CB", "$CC", "$CD", "$CE", "$CF", - "$D0", "$D1", "$D2", "$D3", "$D4", "MUS", "INS", "MDI", - "SND", "$D9", "$DA", "DBM", "$DC", "DDD", "$DE", "$DF", - "LBR", "$E1", "ATK", "$E3", "$E4", "$E5", "$E6", "$E7", - "$E8", "$E9", "$EA", "$EB", "$EC", "$ED", "R16", "PAS", - "CMD", "$F1", "$F2", "$F3", "$F4", "$F5", "$F6", "$F7", - "$F8", "OS ", "INT", "IVR", "BAS", "VAR", "REL", "SYS" + "NON", "BAD", "PCD", "PTX", "TXT", "PDA", "BIN", "FNT", + "FOT", "BA3", "DA3", "WPF", "SOS", "$0D", "$0E", "DIR", + "RPD", "RPI", "AFD", "AFM", "AFR", "SCL", "PFS", "$17", + "$18", "ADB", "AWP", "ASP", "$1C", "$1D", "$1E", "$1F", + "TDM", "$21", "$22", "$23", "$24", "$25", "$26", "$27", + "$28", "$29", "8SC", "8OB", "8IC", "8LD", "P8C", "$2F", + "$30", "$31", "$32", "$33", "$34", "$35", "$36", "$37", + "$38", "$39", "$3A", "$3B", "$3C", "$3D", "$3E", "$3F", + "DIC", "OCR", "FTD", "$43", "$44", "$45", "$46", "$47", + "$48", "$49", "$4A", "$4B", "$4C", "$4D", "$4E", "$4F", + "GWP", "GSS", "GDB", "DRW", "GDP", "HMD", "EDU", "STN", + "HLP", "COM", "CFG", "ANM", "MUM", "ENT", "DVU", "FIN", + "$60", "$61", "$62", "$63", "$64", "$65", "$66", "$67", + "$68", "$69", "$6A", "BIO", "$6C", "TDR", "PRE", "HDV", + "$70", "$71", "$72", "$73", "$74", "$75", "$76", "$77", + "$78", "$79", "$7A", "$7B", "$7C", "$7D", "$7E", "$7F", + "$80", "$81", "$82", "$83", "$84", "$85", "$86", "$87", + "$88", "$89", "$8A", "$8B", "$8C", "$8D", "$8E", "$8F", + "$90", "$91", "$92", "$93", "$94", "$95", "$96", "$97", + "$98", "$99", "$9A", "$9B", "$9C", "$9D", "$9E", "$9F", + "WP ", "$A1", "$A2", "$A3", "$A4", "$A5", "$A6", "$A7", + "$A8", "$A9", "$AA", "GSB", "TDF", "BDF", "$AE", "$AF", + "SRC", "OBJ", "LIB", "S16", "RTL", "EXE", "PIF", "TIF", + "NDA", "CDA", "TOL", "DVR", "LDF", "FST", "$BE", "DOC", + "PNT", "PIC", "ANI", "PAL", "$C4", "OOG", "SCR", "CDV", + "FON", "FND", "ICN", "$CB", "$CC", "$CD", "$CE", "$CF", + "$D0", "$D1", "$D2", "$D3", "$D4", "MUS", "INS", "MDI", + "SND", "$D9", "$DA", "DBM", "$DC", "DDD", "$DE", "$DF", + "LBR", "$E1", "ATK", "$E3", "$E4", "$E5", "$E6", "$E7", + "$E8", "$E9", "$EA", "$EB", "$EC", "$ED", "R16", "PAS", + "CMD", "$F1", "$F2", "$F3", "$F4", "$F5", "$F6", "$F7", + "$F8", "OS ", "INT", "IVR", "BAS", "VAR", "REL", "SYS" }; /* @@ -72,23 +72,23 @@ static const char gFileTypeNames[256][4] = { * file rather than a hard-coded table. Ought to fix that someday. */ static const struct { - const char* label; - ushort fileType; - ulong auxType; - uchar flags; + const char* label; + ushort fileType; + ulong auxType; + uchar flags; } gRecognizedExtensions[] = { - { "ASM", 0xb0, 0x0003, 0 }, /* APW assembly source */ - { "C", 0xb0, 0x000a, 0 }, /* APW C source */ - { "H", 0xb0, 0x000a, 0 }, /* APW C header */ - { "BNY", 0xe0, 0x8000, 0 }, /* Binary II lib */ - { "BQY", 0xe0, 0x8000, 0 }, /* Binary II lib, w/ compress */ - { "BXY", 0xe0, 0x8000, 0 }, /* Binary II wrap around SHK */ - { "BSE", 0xe0, 0x8000, 0 }, /* Binary II wrap around SEA */ - { "SEA", 0xb3, 0xdb07, 0 }, /* GSHK SEA */ - { "GIF", 0xc0, 0x8006, 0 }, /* GIF image */ - { "JPG", 0x06, 0x0000, 0 }, /* JPEG (nicer than 'NON') */ - { "JPEG", 0x06, 0x0000, 0 }, /* JPEG (nicer than 'NON') */ - { "SHK", 0xe0, 0x8002, 0 }, /* ShrinkIt archive */ + { "ASM", 0xb0, 0x0003, 0 }, /* APW assembly source */ + { "C", 0xb0, 0x000a, 0 }, /* APW C source */ + { "H", 0xb0, 0x000a, 0 }, /* APW C header */ + { "BNY", 0xe0, 0x8000, 0 }, /* Binary II lib */ + { "BQY", 0xe0, 0x8000, 0 }, /* Binary II lib, w/ compress */ + { "BXY", 0xe0, 0x8000, 0 }, /* Binary II wrap around SHK */ + { "BSE", 0xe0, 0x8000, 0 }, /* Binary II wrap around SEA */ + { "SEA", 0xb3, 0xdb07, 0 }, /* GSHK SEA */ + { "GIF", 0xc0, 0x8006, 0 }, /* GIF image */ + { "JPG", 0x06, 0x0000, 0 }, /* JPEG (nicer than 'NON') */ + { "JPEG", 0x06, 0x0000, 0 }, /* JPEG (nicer than 'NON') */ + { "SHK", 0xe0, 0x8002, 0 }, /* ShrinkIt archive */ }; @@ -98,16 +98,16 @@ static const struct { const char* GetFileTypeString(ulong fileType) { - if (fileType < NELEM(gFileTypeNames)) - return gFileTypeNames[fileType]; - else - return "???"; + if (fileType < NELEM(gFileTypeNames)) + return gFileTypeNames[fileType]; + else + return "???"; } /* * =========================================================================== - * File type preservation + * File type preservation * =========================================================================== */ @@ -119,113 +119,113 @@ GetFileTypeString(ulong fileType) */ static void AddPreservationString(NulibState* pState, - const NuPathnameProposal* pPathProposal, char* pathBuf) + const NuPathnameProposal* pPathProposal, char* pathBuf) { - char extBuf[kMaxPathGrowth +1]; - const NuRecord* pRecord; - const NuThread* pThread; - NuThreadID threadID; - char* cp; + char extBuf[kMaxPathGrowth +1]; + const NuRecord* pRecord; + const NuThread* pThread; + NuThreadID threadID; + char* cp; - assert(pState != nil); - assert(pPathProposal != nil); - assert(pathBuf != nil); - assert(NState_GetModPreserveType(pState)); + assert(pState != nil); + assert(pPathProposal != nil); + assert(pathBuf != nil); + assert(NState_GetModPreserveType(pState)); - pRecord = pPathProposal->pRecord; - pThread = pPathProposal->pThread; - assert(pRecord != nil); - assert(pThread != nil); + pRecord = pPathProposal->pRecord; + pThread = pPathProposal->pThread; + assert(pRecord != nil); + assert(pThread != nil); - cp = extBuf; + cp = extBuf; - /* - * Cons up a preservation string. On some platforms "sprintf" doesn't - * return the #of characters written, so we add it up manually. - */ - if (pRecord->recFileType < 0x100 && pRecord->recExtraType < 0x10000) { - sprintf(cp, "%c%02lx%04lx", kPreserveIndic, pRecord->recFileType, - pRecord->recExtraType); - cp += 7; - } else { - sprintf(cp, "%c%08lx%08lx", kPreserveIndic, pRecord->recFileType, - pRecord->recExtraType); - cp += 17; - } + /* + * Cons up a preservation string. On some platforms "sprintf" doesn't + * return the #of characters written, so we add it up manually. + */ + if (pRecord->recFileType < 0x100 && pRecord->recExtraType < 0x10000) { + sprintf(cp, "%c%02lx%04lx", kPreserveIndic, pRecord->recFileType, + pRecord->recExtraType); + cp += 7; + } else { + sprintf(cp, "%c%08lx%08lx", kPreserveIndic, pRecord->recFileType, + pRecord->recExtraType); + cp += 17; + } - threadID = NuMakeThreadID(pThread->thThreadClass, pThread->thThreadKind); - if (threadID == kNuThreadIDRsrcFork) - *cp++ = kResourceFlag; - else if (threadID == kNuThreadIDDiskImage) - *cp++ = kDiskImageFlag; + threadID = NuMakeThreadID(pThread->thThreadClass, pThread->thThreadKind); + if (threadID == kNuThreadIDRsrcFork) + *cp++ = kResourceFlag; + else if (threadID == kNuThreadIDDiskImage) + *cp++ = kDiskImageFlag; - /* - * If they've asked for "extended" type preservation, then we need - * to retain either the existing extension or append an extension - * based on the ProDOS file type. - */ - if (NState_GetModPreserveTypeExtended(pState)) { - const char* pExt; - char* end; + /* + * If they've asked for "extended" type preservation, then we need + * to retain either the existing extension or append an extension + * based on the ProDOS file type. + */ + if (NState_GetModPreserveTypeExtended(pState)) { + const char* pExt; + char* end; - /* - * Find extension. Note FindExtension guarantees there's at least - * one char after '.'. - * - * It's hard to know when this is right and when it isn't. It's - * fairly likely that a text file really ought to end in ".txt", - * and it's fairly unlikely that a BIN file should be ".bin", but - * where do the rest fall in? We might want to force TXT files - * to be ".txt", and perhaps do something clever for some others. - */ - if (pRecord->recFileType == 0x04) - pExt = nil; - else - pExt = FindExtension(pState, pathBuf); - if (pExt != nil && strlen(pExt+1) <= kMaxExtLen) { - pExt++; /* skip past the '.' */ + /* + * Find extension. Note FindExtension guarantees there's at least + * one char after '.'. + * + * It's hard to know when this is right and when it isn't. It's + * fairly likely that a text file really ought to end in ".txt", + * and it's fairly unlikely that a BIN file should be ".bin", but + * where do the rest fall in? We might want to force TXT files + * to be ".txt", and perhaps do something clever for some others. + */ + if (pRecord->recFileType == 0x04) + pExt = nil; + else + pExt = FindExtension(pState, pathBuf); + if (pExt != nil && strlen(pExt+1) <= kMaxExtLen) { + pExt++; /* skip past the '.' */ - /* if it's strictly decimal-numeric, don't use it (.1, .2, etc) */ - (void) strtoul(pExt, &end, 10); - if (*end == '\0') { - pExt = nil; - } else { - /* if '#' appears in it, don't use it -- it'll confuse us */ - const char* ccp = pExt; - while (*ccp != '\0') { - if (*ccp == '#') { - pExt = nil; - break; - } - ccp++; - } - } + /* if it's strictly decimal-numeric, don't use it (.1, .2, etc) */ + (void) strtoul(pExt, &end, 10); + if (*end == '\0') { + pExt = nil; + } else { + /* if '#' appears in it, don't use it -- it'll confuse us */ + const char* ccp = pExt; + while (*ccp != '\0') { + if (*ccp == '#') { + pExt = nil; + break; + } + ccp++; + } + } - } else { - /* - * There's no extension on the filename. Use the standard - * ProDOS type, if one exists for this entry. We don't use - * the table if it's "NON" or a hex value. - */ - if (pRecord->recFileType) { - pExt = GetFileTypeString(pRecord->recFileType); - if (pExt[0] == '?' || pExt[0] == '$') - pExt = nil; - } - } + } else { + /* + * There's no extension on the filename. Use the standard + * ProDOS type, if one exists for this entry. We don't use + * the table if it's "NON" or a hex value. + */ + if (pRecord->recFileType) { + pExt = GetFileTypeString(pRecord->recFileType); + if (pExt[0] == '?' || pExt[0] == '$') + pExt = nil; + } + } - if (pExt != nil) { - *cp++ = kFilenameExtDelim; - strcpy(cp, pExt); - cp += strlen(pExt); - } - } + if (pExt != nil) { + *cp++ = kFilenameExtDelim; + strcpy(cp, pExt); + cp += strlen(pExt); + } + } - /* make sure it's terminated */ - *cp = '\0'; + /* make sure it's terminated */ + *cp = '\0'; - assert(cp - extBuf <= kMaxPathGrowth); - strcat(pathBuf, extBuf); + assert(cp - extBuf <= kMaxPathGrowth); + strcat(pathBuf, extBuf); } /* @@ -244,103 +244,103 @@ AddPreservationString(NulibState* pState, const char* NormalizePath(NulibState* pState, NuPathnameProposal* pPathProposal) { - NuError err = kNuErrNone; - char* pathBuf; - const char* startp; - const char* endp; - char* dstp; - char localFssep; + NuError err = kNuErrNone; + char* pathBuf; + const char* startp; + const char* endp; + char* dstp; + char localFssep; - assert(pState != nil); - assert(pPathProposal != nil); - assert(pPathProposal->pathname != nil); + assert(pState != nil); + assert(pPathProposal != nil); + assert(pPathProposal->pathname != nil); - localFssep = NState_GetSystemPathSeparator(pState); + localFssep = NState_GetSystemPathSeparator(pState); - /* - * Set up temporary buffer space. The maximum possible expansion - * requires converting all chars to '%' codes and adding the longest - * possible preservation string. - */ - NState_SetTempPathnameLen(pState, - strlen(pPathProposal->pathname)*3 + kMaxPathGrowth +1); - pathBuf = NState_GetTempPathnameBuf(pState); - assert(pathBuf != nil); - if (pathBuf == nil) - return nil; + /* + * Set up temporary buffer space. The maximum possible expansion + * requires converting all chars to '%' codes and adding the longest + * possible preservation string. + */ + NState_SetTempPathnameLen(pState, + strlen(pPathProposal->pathname)*3 + kMaxPathGrowth +1); + pathBuf = NState_GetTempPathnameBuf(pState); + assert(pathBuf != nil); + if (pathBuf == nil) + return nil; - startp = pPathProposal->pathname; - dstp = pathBuf; - while (*startp == pPathProposal->filenameSeparator) { - /* ignore leading path sep; always extract to current dir */ - startp++; - } + startp = pPathProposal->pathname; + dstp = pathBuf; + while (*startp == pPathProposal->filenameSeparator) { + /* ignore leading path sep; always extract to current dir */ + startp++; + } - /* normalize all directory components and the filename component */ - while (startp != nil) { - endp = strchr(startp, pPathProposal->filenameSeparator); - if (endp != nil) { - /* normalize directory component */ - err = NormalizeDirectoryName(pState, startp, endp - startp, - pPathProposal->filenameSeparator, &dstp, - NState_GetTempPathnameLen(pState)); - if (err != kNuErrNone) - goto bail; + /* normalize all directory components and the filename component */ + while (startp != nil) { + endp = strchr(startp, pPathProposal->filenameSeparator); + if (endp != nil) { + /* normalize directory component */ + err = NormalizeDirectoryName(pState, startp, endp - startp, + pPathProposal->filenameSeparator, &dstp, + NState_GetTempPathnameLen(pState)); + if (err != kNuErrNone) + goto bail; - *dstp++ = localFssep; + *dstp++ = localFssep; - startp = endp +1; - } else { - /* normalize filename */ - err = NormalizeFileName(pState, startp, strlen(startp), - pPathProposal->filenameSeparator, &dstp, - NState_GetTempPathnameLen(pState)); - if (err != kNuErrNone) - goto bail; + startp = endp +1; + } else { + /* normalize filename */ + err = NormalizeFileName(pState, startp, strlen(startp), + pPathProposal->filenameSeparator, &dstp, + NState_GetTempPathnameLen(pState)); + if (err != kNuErrNone) + goto bail; - /* add/replace extension if necessary */ - *dstp++ = '\0'; - if (NState_GetModPreserveType(pState)) { - AddPreservationString(pState, pPathProposal, pathBuf); - } else if (NuGetThreadID(pPathProposal->pThread) == kNuThreadIDRsrcFork) - { - /* add this in lieu of the preservation extension */ - strcat(pathBuf, kResourceStr); - } + /* add/replace extension if necessary */ + *dstp++ = '\0'; + if (NState_GetModPreserveType(pState)) { + AddPreservationString(pState, pPathProposal, pathBuf); + } else if (NuGetThreadID(pPathProposal->pThread) == kNuThreadIDRsrcFork) + { + /* add this in lieu of the preservation extension */ + strcat(pathBuf, kResourceStr); + } - startp = nil; /* we're done */ - } - } + startp = nil; /* we're done */ + } + } - pPathProposal->newPathname = pathBuf; - pPathProposal->newFilenameSeparator = localFssep; + pPathProposal->newPathname = pathBuf; + pPathProposal->newFilenameSeparator = localFssep; - /* check for overflow */ - assert(dstp - pathBuf <= - (int)(strlen(pPathProposal->pathname) + kMaxPathGrowth)); + /* check for overflow */ + assert(dstp - pathBuf <= + (int)(strlen(pPathProposal->pathname) + kMaxPathGrowth)); - /* - * If "junk paths" is set, drop everything but the last component. - */ - if (NState_GetModJunkPaths(pState)) { - char* lastFssep; - lastFssep = strrchr(pathBuf, localFssep); - if (lastFssep != nil) { - assert(*(lastFssep+1) != '\0'); /* should already have been caught*/ - memmove(pathBuf, lastFssep+1, strlen(lastFssep+1)+1); - } - } + /* + * If "junk paths" is set, drop everything but the last component. + */ + if (NState_GetModJunkPaths(pState)) { + char* lastFssep; + lastFssep = strrchr(pathBuf, localFssep); + if (lastFssep != nil) { + assert(*(lastFssep+1) != '\0'); /* should already have been caught*/ + memmove(pathBuf, lastFssep+1, strlen(lastFssep+1)+1); + } + } bail: - if (err != kNuErrNone) - return nil; - return pathBuf; + if (err != kNuErrNone) + return nil; + return pathBuf; } /* * =========================================================================== - * File type restoration + * File type restoration * =========================================================================== */ @@ -352,51 +352,51 @@ bail: */ static void LookupExtension(NulibState* pState, const char* ext, ulong* pFileType, - ulong* pAuxType) + ulong* pAuxType) { - char uext3[4]; - int i, extLen; + char uext3[4]; + int i, extLen; - extLen = strlen(ext); - assert(extLen > 0); + extLen = strlen(ext); + assert(extLen > 0); - /* - * First step is to try to find it in the recognized types list. - */ - for (i = 0; i < NELEM(gRecognizedExtensions); i++) { - if (strcasecmp(ext, gRecognizedExtensions[i].label) == 0) { - *pFileType = gRecognizedExtensions[i].fileType; - *pAuxType = gRecognizedExtensions[i].auxType; - goto bail; - } - } + /* + * First step is to try to find it in the recognized types list. + */ + for (i = 0; i < NELEM(gRecognizedExtensions); i++) { + if (strcasecmp(ext, gRecognizedExtensions[i].label) == 0) { + *pFileType = gRecognizedExtensions[i].fileType; + *pAuxType = gRecognizedExtensions[i].auxType; + goto bail; + } + } - /* - * Second step is to try to find it in the ProDOS types list. - * - * The extension is converted to upper case and padded with spaces. - * - * [do we want to obstruct matching on things like '$f7' here?] - */ - if (extLen <= 3) { - for (i = 2; i >= extLen; i--) - uext3[i] = ' '; - for ( ; i >= 0; i--) - uext3[i] = toupper(ext[i]); - uext3[3] = '\0'; + /* + * Second step is to try to find it in the ProDOS types list. + * + * The extension is converted to upper case and padded with spaces. + * + * [do we want to obstruct matching on things like '$f7' here?] + */ + if (extLen <= 3) { + for (i = 2; i >= extLen; i--) + uext3[i] = ' '; + for ( ; i >= 0; i--) + uext3[i] = toupper(ext[i]); + uext3[3] = '\0'; - /*printf("### converted '%s' to '%s'\n", ext, uext3);*/ + /*printf("### converted '%s' to '%s'\n", ext, uext3);*/ - for (i = 0; i < NELEM(gFileTypeNames); i++) { - if (strcmp(uext3, gFileTypeNames[i]) == 0) { - *pFileType = i; - goto bail; - } - } - } + for (i = 0; i < NELEM(gFileTypeNames); i++) { + if (strcmp(uext3, gFileTypeNames[i]) == 0) { + *pFileType = i; + goto bail; + } + } + } bail: - return; + return; } /* @@ -404,18 +404,18 @@ bail: */ void InterpretExtension(NulibState* pState, const char* pathName, ulong* pFileType, - ulong* pAuxType) + ulong* pAuxType) { - const char* pExt; + const char* pExt; - assert(pState != nil); - assert(pathName != nil); - assert(pFileType != nil); - assert(pAuxType != nil); + assert(pState != nil); + assert(pathName != nil); + assert(pFileType != nil); + assert(pAuxType != nil); - pExt = FindExtension(pState, pathName); - if (pExt != nil) - LookupExtension(pState, pExt+1, pFileType, pAuxType); + pExt = FindExtension(pState, pathName); + if (pExt != nil) + LookupExtension(pState, pExt+1, pFileType, pAuxType); } @@ -429,89 +429,89 @@ InterpretExtension(NulibState* pState, const char* pathName, ulong* pFileType, */ Boolean ExtractPreservationString(NulibState* pState, char* pathname, ulong* pFileType, - ulong* pAuxType, NuThreadID* pThreadID) + ulong* pAuxType, NuThreadID* pThreadID) { - char numBuf[9]; - ulong fileType, auxType; - NuThreadID threadID; - char* pPreserve; - char* cp; - int digitCount; + char numBuf[9]; + ulong fileType, auxType; + NuThreadID threadID; + char* pPreserve; + char* cp; + int digitCount; - assert(pState != nil); - assert(pathname != nil); - assert(pFileType != nil); - assert(pAuxType != nil); - assert(pThreadID != nil); + assert(pState != nil); + assert(pathname != nil); + assert(pFileType != nil); + assert(pAuxType != nil); + assert(pThreadID != nil); - pPreserve = strrchr(pathname, kPreserveIndic); - if (pPreserve == nil) - return false; + pPreserve = strrchr(pathname, kPreserveIndic); + if (pPreserve == nil) + return false; - /* count up the #of hex digits */ - digitCount = 0; - for (cp = pPreserve+1; *cp != '\0' && isxdigit((int)*cp); cp++) - digitCount++; + /* count up the #of hex digits */ + digitCount = 0; + for (cp = pPreserve+1; *cp != '\0' && isxdigit((int)*cp); cp++) + digitCount++; - /* extract the file and aux type */ - switch (digitCount) { - case 6: - /* ProDOS 1-byte type and 2-byte aux */ - memcpy(numBuf, pPreserve+1, 2); - numBuf[2] = 0; - fileType = strtoul(numBuf, &cp, 16); - assert(cp == numBuf + 2); + /* extract the file and aux type */ + switch (digitCount) { + case 6: + /* ProDOS 1-byte type and 2-byte aux */ + memcpy(numBuf, pPreserve+1, 2); + numBuf[2] = 0; + fileType = strtoul(numBuf, &cp, 16); + assert(cp == numBuf + 2); - auxType = strtoul(pPreserve+3, &cp, 16); - assert(cp == pPreserve + 7); - break; - case 16: - /* HFS 4-byte type and 4-byte creator */ - memcpy(numBuf, pPreserve+1, 8); - numBuf[8] = 0; - fileType = strtoul(numBuf, &cp, 16); - assert(cp == numBuf + 8); + auxType = strtoul(pPreserve+3, &cp, 16); + assert(cp == pPreserve + 7); + break; + case 16: + /* HFS 4-byte type and 4-byte creator */ + memcpy(numBuf, pPreserve+1, 8); + numBuf[8] = 0; + fileType = strtoul(numBuf, &cp, 16); + assert(cp == numBuf + 8); - auxType = strtoul(pPreserve+9, &cp, 16); - assert(cp == pPreserve + 17); - break; - default: - /* not valid */ - return false; - } + auxType = strtoul(pPreserve+9, &cp, 16); + assert(cp == pPreserve + 17); + break; + default: + /* not valid */ + return false; + } - /* check for a threadID specifier */ - threadID = kNuThreadIDDataFork; - switch (*cp) { - case kResourceFlag: - threadID = kNuThreadIDRsrcFork; - cp++; - break; - case kDiskImageFlag: - threadID = kNuThreadIDDiskImage; - cp++; - break; - default: - /* do nothing... yet */ - break; - } + /* check for a threadID specifier */ + threadID = kNuThreadIDDataFork; + switch (*cp) { + case kResourceFlag: + threadID = kNuThreadIDRsrcFork; + cp++; + break; + case kDiskImageFlag: + threadID = kNuThreadIDDiskImage; + cp++; + break; + default: + /* do nothing... yet */ + break; + } - /* make sure we were the very last component */ - switch (*cp) { - case kFilenameExtDelim: /* redundant "-ee" extension */ - case '\0': /* end of string! */ - break; - default: - return false; - } + /* make sure we were the very last component */ + switch (*cp) { + case kFilenameExtDelim: /* redundant "-ee" extension */ + case '\0': /* end of string! */ + break; + default: + return false; + } - /* truncate the original string, and return what we got */ - *pPreserve = '\0'; - *pFileType = fileType; - *pAuxType = auxType; - *pThreadID = threadID; + /* truncate the original string, and return what we got */ + *pPreserve = '\0'; + *pFileType = fileType; + *pAuxType = auxType; + *pThreadID = threadID; - return true; + return true; } @@ -524,50 +524,50 @@ ExtractPreservationString(NulibState* pState, char* pathname, ulong* pFileType, void DenormalizePath(NulibState* pState, char* pathBuf) { - const char* srcp; - char* dstp; - char ch; + const char* srcp; + char* dstp; + char ch; - srcp = pathBuf; - dstp = pathBuf; + srcp = pathBuf; + dstp = pathBuf; - while (*srcp != '\0') { - if (*srcp == kForeignIndic) { - srcp++; - if (*srcp == kForeignIndic) { - *dstp++ = kForeignIndic; - srcp++; - } else if (isxdigit((int)*srcp)) { - ch = HexDigit(*srcp) << 4; - srcp++; - if (isxdigit((int)*srcp)) { - /* valid, output char */ - ch += HexDigit(*srcp); - *dstp++ = ch; - srcp++; - } else { - /* bogus '%' with trailing hex digit found! */ - *dstp++ = kForeignIndic; - *dstp++ = *(srcp-1); - } - } else { - /* bogus lone '%s' found! */ - *dstp++ = kForeignIndic; - } + while (*srcp != '\0') { + if (*srcp == kForeignIndic) { + srcp++; + if (*srcp == kForeignIndic) { + *dstp++ = kForeignIndic; + srcp++; + } else if (isxdigit((int)*srcp)) { + ch = HexDigit(*srcp) << 4; + srcp++; + if (isxdigit((int)*srcp)) { + /* valid, output char */ + ch += HexDigit(*srcp); + *dstp++ = ch; + srcp++; + } else { + /* bogus '%' with trailing hex digit found! */ + *dstp++ = kForeignIndic; + *dstp++ = *(srcp-1); + } + } else { + /* bogus lone '%s' found! */ + *dstp++ = kForeignIndic; + } - } else { - *dstp++ = *srcp++; - } - } + } else { + *dstp++ = *srcp++; + } + } - *dstp = '\0'; - assert(dstp <= srcp); + *dstp = '\0'; + assert(dstp <= srcp); } /* * =========================================================================== - * Misc utils + * Misc utils * =========================================================================== */ @@ -580,52 +580,52 @@ DenormalizePath(NulibState* pState, char* pathBuf) const char* FilenameOnly(NulibState* pState, const char* pathname) { - const char* retstr; - const char* pSlash; - char* tmpStr = nil; + const char* retstr; + const char* pSlash; + char* tmpStr = nil; - assert(pState != nil); - assert(pathname != nil); + assert(pState != nil); + assert(pathname != nil); - pSlash = strrchr(pathname, NState_GetSystemPathSeparator(pState)); - if (pSlash == nil) { - retstr = pathname; /* whole thing is the filename */ - goto bail; - } + pSlash = strrchr(pathname, NState_GetSystemPathSeparator(pState)); + if (pSlash == nil) { + retstr = pathname; /* whole thing is the filename */ + goto bail; + } - pSlash++; - if (*pSlash == '\0') { - if (strlen(pathname) < 2) { - retstr = pathname; /* the pathname is just "/"? Whatever */ - goto bail; - } + pSlash++; + if (*pSlash == '\0') { + if (strlen(pathname) < 2) { + retstr = pathname; /* the pathname is just "/"? Whatever */ + goto bail; + } - /* some bonehead put an fssep on the very end; back up before it */ - /* (not efficient, but this should be rare, and I'm feeling lazy) */ - tmpStr = strdup(pathname); - tmpStr[strlen(pathname)-1] = '\0'; - pSlash = strrchr(tmpStr, NState_GetSystemPathSeparator(pState)); + /* some bonehead put an fssep on the very end; back up before it */ + /* (not efficient, but this should be rare, and I'm feeling lazy) */ + tmpStr = strdup(pathname); + tmpStr[strlen(pathname)-1] = '\0'; + pSlash = strrchr(tmpStr, NState_GetSystemPathSeparator(pState)); - if (pSlash == nil) { - retstr = pathname; /* just a filename with a '/' after it */ - goto bail; - } + if (pSlash == nil) { + retstr = pathname; /* just a filename with a '/' after it */ + goto bail; + } - pSlash++; - if (*pSlash == '\0') { - retstr = pathname; /* I give up! */ - goto bail; - } + pSlash++; + if (*pSlash == '\0') { + retstr = pathname; /* I give up! */ + goto bail; + } - retstr = pathname + (pSlash - tmpStr); + retstr = pathname + (pSlash - tmpStr); - } else { - retstr = pSlash; - } + } else { + retstr = pSlash; + } bail: - Free(tmpStr); - return retstr; + Free(tmpStr); + return retstr; } /* @@ -640,21 +640,21 @@ bail: const char* FindExtension(NulibState* pState, const char* pathname) { - const char* pFilename; - const char* pExt; + const char* pFilename; + const char* pExt; - /* - * We have to isolate the filename so that we don't get excited - * about "/foo.bar/file". - */ - pFilename = FilenameOnly(pState, pathname); - assert(pFilename != nil); - pExt = strrchr(pFilename, kFilenameExtDelim); + /* + * We have to isolate the filename so that we don't get excited + * about "/foo.bar/file". + */ + pFilename = FilenameOnly(pState, pathname); + assert(pFilename != nil); + pExt = strrchr(pFilename, kFilenameExtDelim); - /* also check for "/blah/foo.", which doesn't count */ - if (pExt != nil && *(pExt+1) != '\0') - return pExt; + /* also check for "/blah/foo.", which doesn't count */ + if (pExt != nil && *(pExt+1) != '\0') + return pExt; - return nil; + return nil; } diff --git a/nulib2/List.c b/nulib2/List.c index 619afe8..fb2af5e 100644 --- a/nulib2/List.c +++ b/nulib2/List.c @@ -11,31 +11,31 @@ /* kinds of records */ enum RecordKind { - kRecordKindUnknown = 0, - kRecordKindDisk, - kRecordKindFile, - kRecordKindForkedFile + kRecordKindUnknown = 0, + kRecordKindDisk, + kRecordKindFile, + kRecordKindForkedFile }; static const char* gShortFormatNames[] = { - "unc", "squ", "lz1", "lz2", "u12", "u16" + "unc", "squ", "lz1", "lz2", "u12", "u16" }; #if 0 /* days of the week */ static const char* gDayNames[] = { - "[ null ]", - "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" + "[ null ]", + "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; #endif /* months of the year */ static const char* gMonths[] = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; -#define kNuDateOutputLen 64 +#define kNuDateOutputLen 64 /* @@ -44,21 +44,21 @@ static const char* gMonths[] = { int ComputePercent(ulong totalSize, ulong size) { - int perc; + int perc; - if (!totalSize && !size) - return 100; /* file is zero bytes long */ + if (!totalSize && !size) + return 100; /* file is zero bytes long */ - if (totalSize < 21474836) - perc = (totalSize * 100) / size; - else - perc = totalSize / (size/100); + if (totalSize < 21474836) + perc = (totalSize * 100) / size; + else + perc = totalSize / (size/100); - /* don't say "0%" if it's not actually zero... it looks dumb */ - if (!perc && size) - perc = 1; + /* don't say "0%" if it's not actually zero... it looks dumb */ + if (!perc && size) + perc = 1; - return perc; + return perc; } @@ -73,29 +73,29 @@ ComputePercent(ulong totalSize, ulong size) static char* FormatDateShort(const NuDateTime* pDateTime, char* buffer) { - /* is it valid? */ - if (pDateTime->day > 30 || pDateTime->month > 11 || pDateTime->hour > 24 || - pDateTime->minute > 59) - { - strcpy(buffer, " "); - goto bail; - } + /* is it valid? */ + if (pDateTime->day > 30 || pDateTime->month > 11 || pDateTime->hour > 24 || + pDateTime->minute > 59) + { + strcpy(buffer, " "); + goto bail; + } - /* is it empty? */ - if ((pDateTime->second | pDateTime->minute | pDateTime->hour | - pDateTime->year | pDateTime->day | pDateTime->month | - pDateTime->extra | pDateTime->weekDay) == 0) - { - strcpy(buffer, " [No Date] "); - goto bail; - } + /* is it empty? */ + if ((pDateTime->second | pDateTime->minute | pDateTime->hour | + pDateTime->year | pDateTime->day | pDateTime->month | + pDateTime->extra | pDateTime->weekDay) == 0) + { + strcpy(buffer, " [No Date] "); + goto bail; + } - sprintf(buffer, "%02d-%s-%02d %02d:%02d", - pDateTime->day+1, gMonths[pDateTime->month], pDateTime->year % 100, - pDateTime->hour, pDateTime->minute); + sprintf(buffer, "%02d-%s-%02d %02d:%02d", + pDateTime->day+1, gMonths[pDateTime->month], pDateTime->year % 100, + pDateTime->hour, pDateTime->minute); bail: - return buffer; + return buffer; } @@ -105,21 +105,21 @@ bail: static NuResult ShowContentsShort(NuArchive* pArchive, void* vpRecord) { - const NuRecord* pRecord = (NuRecord*) vpRecord; - NulibState* pState; + const NuRecord* pRecord = (NuRecord*) vpRecord; + NulibState* pState; - assert(pArchive != nil); - (void) NuGetExtraData(pArchive, (void**) &pState); - assert(pState != nil); + assert(pArchive != nil); + (void) NuGetExtraData(pArchive, (void**) &pState); + assert(pState != nil); - if (!IsSpecified(pState, pRecord)) - goto bail; + if (!IsSpecified(pState, pRecord)) + goto bail; - printf("%s\n", - pRecord->filename == nil ? "":(const char*)pRecord->filename); + printf("%s\n", + pRecord->filename == nil ? "":(const char*)pRecord->filename); bail: - return kNuOK; + return kNuOK; } @@ -140,42 +140,42 @@ bail: */ static NuError AnalyzeRecord(const NuRecord* pRecord, enum RecordKind* pRecordKind, - ushort* pFormat, ulong* pTotalLen, ulong* pTotalCompLen) + ushort* pFormat, ulong* pTotalLen, ulong* pTotalCompLen) { - const NuThread* pThread; - NuThreadID threadID; - ulong idx; + const NuThread* pThread; + NuThreadID threadID; + ulong idx; - *pRecordKind = kRecordKindUnknown; - *pTotalLen = *pTotalCompLen = 0; - *pFormat = kNuThreadFormatUncompressed; + *pRecordKind = kRecordKindUnknown; + *pTotalLen = *pTotalCompLen = 0; + *pFormat = kNuThreadFormatUncompressed; - for (idx = 0; idx < pRecord->recTotalThreads; idx++) { - pThread = NuGetThread(pRecord, idx); - assert(pThread != nil); + for (idx = 0; idx < pRecord->recTotalThreads; idx++) { + pThread = NuGetThread(pRecord, idx); + assert(pThread != nil); - if (pThread->thThreadClass == kNuThreadClassData) { - /* replace what's there if this might be more interesting */ - if (*pFormat == kNuThreadFormatUncompressed) - *pFormat = pThread->thThreadFormat; + if (pThread->thThreadClass == kNuThreadClassData) { + /* replace what's there if this might be more interesting */ + if (*pFormat == kNuThreadFormatUncompressed) + *pFormat = pThread->thThreadFormat; - threadID = NuMakeThreadID(pThread->thThreadClass, - pThread->thThreadKind); - if (threadID == kNuThreadIDRsrcFork) - *pRecordKind = kRecordKindForkedFile; - else if (threadID == kNuThreadIDDiskImage) - *pRecordKind = kRecordKindDisk; - else if (threadID == kNuThreadIDDataFork && - *pRecordKind == kRecordKindUnknown) - *pRecordKind = kRecordKindFile; + threadID = NuMakeThreadID(pThread->thThreadClass, + pThread->thThreadKind); + if (threadID == kNuThreadIDRsrcFork) + *pRecordKind = kRecordKindForkedFile; + else if (threadID == kNuThreadIDDiskImage) + *pRecordKind = kRecordKindDisk; + else if (threadID == kNuThreadIDDataFork && + *pRecordKind == kRecordKindUnknown) + *pRecordKind = kRecordKindFile; - /* sum up, so we get both forks of forked files */ - *pTotalLen += pThread->actualThreadEOF; - *pTotalCompLen += pThread->thCompThreadEOF; - } - } + /* sum up, so we get both forks of forked files */ + *pTotalLen += pThread->actualThreadEOF; + *pTotalCompLen += pThread->thCompThreadEOF; + } + } - return kNuErrNone; + return kNuErrNone; } /* @@ -187,89 +187,89 @@ AnalyzeRecord(const NuRecord* pRecord, enum RecordKind* pRecordKind, static NuResult ShowContentsVerbose(NuArchive* pArchive, void* vpRecord) { - NuError err = kNuErrNone; - const NuRecord* pRecord = (NuRecord*) vpRecord; - enum RecordKind recordKind; - ulong totalLen, totalCompLen; - ushort format; - NulibState* pState; - char date1[kNuDateOutputLen]; - char tmpbuf[16]; - int len; + NuError err = kNuErrNone; + const NuRecord* pRecord = (NuRecord*) vpRecord; + enum RecordKind recordKind; + ulong totalLen, totalCompLen; + ushort format; + NulibState* pState; + char date1[kNuDateOutputLen]; + char tmpbuf[16]; + int len; - assert(pArchive != nil); - (void) NuGetExtraData(pArchive, (void**) &pState); - assert(pState != nil); + assert(pArchive != nil); + (void) NuGetExtraData(pArchive, (void**) &pState); + assert(pState != nil); - if (!IsSpecified(pState, pRecord)) - goto bail; + if (!IsSpecified(pState, pRecord)) + goto bail; - err = AnalyzeRecord(pRecord, &recordKind, &format, &totalLen, - &totalCompLen); - if (err != kNuErrNone) - goto bail; + err = AnalyzeRecord(pRecord, &recordKind, &format, &totalLen, + &totalCompLen); + if (err != kNuErrNone) + goto bail; - len = strlen(pRecord->filename); - if (len <= 27) { - printf("%c%-27.27s ", IsRecordReadOnly(pRecord) ? '+' : ' ', - pRecord->filename); - } else { - printf("%c..%-25.25s ", IsRecordReadOnly(pRecord) ? '+' : ' ', - pRecord->filename + len - 25); - } - switch (recordKind) { - case kRecordKindUnknown: - printf("??? $%04lX ", - /*GetFileTypeString(pRecord->recFileType),*/ - pRecord->recExtraType); - break; - case kRecordKindDisk: - sprintf(tmpbuf, "%ldk", totalLen / 1024); - printf("Disk %-6s ", tmpbuf); - break; - case kRecordKindFile: - case kRecordKindForkedFile: - printf("%s%c $%04lX ", - GetFileTypeString(pRecord->recFileType), - recordKind == kRecordKindForkedFile ? '+' : ' ', - pRecord->recExtraType); - break; - default: - assert(0); - printf("ERROR "); - } + len = strlen(pRecord->filename); + if (len <= 27) { + printf("%c%-27.27s ", IsRecordReadOnly(pRecord) ? '+' : ' ', + pRecord->filename); + } else { + printf("%c..%-25.25s ", IsRecordReadOnly(pRecord) ? '+' : ' ', + pRecord->filename + len - 25); + } + switch (recordKind) { + case kRecordKindUnknown: + printf("??? $%04lX ", + /*GetFileTypeString(pRecord->recFileType),*/ + pRecord->recExtraType); + break; + case kRecordKindDisk: + sprintf(tmpbuf, "%ldk", totalLen / 1024); + printf("Disk %-6s ", tmpbuf); + break; + case kRecordKindFile: + case kRecordKindForkedFile: + printf("%s%c $%04lX ", + GetFileTypeString(pRecord->recFileType), + recordKind == kRecordKindForkedFile ? '+' : ' ', + pRecord->recExtraType); + break; + default: + assert(0); + printf("ERROR "); + } - printf("%s ", FormatDateShort(&pRecord->recArchiveWhen, date1)); - if (format >= NELEM(gShortFormatNames)) - printf("??? "); - else - printf("%s ", gShortFormatNames[format]); + printf("%s ", FormatDateShort(&pRecord->recArchiveWhen, date1)); + if (format >= NELEM(gShortFormatNames)) + printf("??? "); + else + printf("%s ", gShortFormatNames[format]); - /* compute the percent size */ - if ((!totalLen && totalCompLen) || (totalLen && !totalCompLen)) - printf("--- "); /* weird */ - else if (totalLen < totalCompLen) - printf(">100%% "); /* compression failed? */ - else { - sprintf(tmpbuf, "%02d%%", ComputePercent(totalCompLen, totalLen)); - printf("%4s ", tmpbuf); - } + /* compute the percent size */ + if ((!totalLen && totalCompLen) || (totalLen && !totalCompLen)) + printf("--- "); /* weird */ + else if (totalLen < totalCompLen) + printf(">100%% "); /* compression failed? */ + else { + sprintf(tmpbuf, "%02d%%", ComputePercent(totalCompLen, totalLen)); + printf("%4s ", tmpbuf); + } - if (!totalLen && totalCompLen) - printf(" ????"); /* weird */ - else - printf("%8ld", totalLen); + if (!totalLen && totalCompLen) + printf(" ????"); /* weird */ + else + printf("%8ld", totalLen); - printf("\n"); + printf("\n"); - NState_AddToTotals(pState, totalLen, totalCompLen); + NState_AddToTotals(pState, totalLen, totalCompLen); bail: - if (err != kNuErrNone) { - printf("(ERROR on '%s')\n", pRecord->filename == nil ? - "" : (const char*)pRecord->filename); - } - return kNuOK; + if (err != kNuErrNone) { + printf("(ERROR on '%s')\n", pRecord->filename == nil ? + "" : (const char*)pRecord->filename); + } + return kNuOK; } /* @@ -278,24 +278,24 @@ bail: NuError DoListShort(NulibState* pState) { - NuError err; - NuArchive* pArchive = nil; + NuError err; + NuArchive* pArchive = nil; - assert(pState != nil); + assert(pState != nil); - err = OpenArchiveReadOnly(pState); - if (err != kNuErrNone) - goto bail; - pArchive = NState_GetNuArchive(pState); - assert(pArchive != nil); + err = OpenArchiveReadOnly(pState); + if (err != kNuErrNone) + goto bail; + pArchive = NState_GetNuArchive(pState); + assert(pArchive != nil); - err = NuContents(pArchive, ShowContentsShort); - /* fall through with err */ + err = NuContents(pArchive, ShowContentsShort); + /* fall through with err */ bail: - if (pArchive != nil) - (void) NuClose(pArchive); - return err; + if (pArchive != nil) + (void) NuClose(pArchive); + return err; } @@ -305,72 +305,72 @@ bail: NuError DoListVerbose(NulibState* pState) { - NuError err; - NuArchive* pArchive = nil; - const NuMasterHeader* pHeader; - char date1[kNuDateOutputLen]; - char date2[kNuDateOutputLen]; - long totalLen, totalCompLen; - const char* cp; + NuError err; + NuArchive* pArchive = nil; + const NuMasterHeader* pHeader; + char date1[kNuDateOutputLen]; + char date2[kNuDateOutputLen]; + long totalLen, totalCompLen; + const char* cp; - assert(pState != nil); + assert(pState != nil); - err = OpenArchiveReadOnly(pState); - if (err != kNuErrNone) - goto bail; - pArchive = NState_GetNuArchive(pState); - assert(pArchive != nil); + err = OpenArchiveReadOnly(pState); + if (err != kNuErrNone) + goto bail; + pArchive = NState_GetNuArchive(pState); + assert(pArchive != nil); - /* - * Try to get just the filename. - */ - if (IsFilenameStdin(NState_GetArchiveFilename(pState))) - cp = ""; - else - cp = FilenameOnly(pState, NState_GetArchiveFilename(pState)); + /* + * Try to get just the filename. + */ + if (IsFilenameStdin(NState_GetArchiveFilename(pState))) + cp = ""; + else + cp = FilenameOnly(pState, NState_GetArchiveFilename(pState)); - /* grab the master header block */ - err = NuGetMasterHeader(pArchive, &pHeader); - if (err != kNuErrNone) - goto bail; + /* grab the master header block */ + err = NuGetMasterHeader(pArchive, &pHeader); + if (err != kNuErrNone) + goto bail; - printf(" %-15.15s Created:%s Mod:%s Recs:%5lu\n\n", - cp, - FormatDateShort(&pHeader->mhArchiveCreateWhen, date1), - FormatDateShort(&pHeader->mhArchiveModWhen, date2), - pHeader->mhTotalRecords); - printf(" Name Type Auxtyp Archived" - " Fmat Size Un-Length\n"); - printf("-------------------------------------------------" - "----------------------------\n"); + printf(" %-15.15s Created:%s Mod:%s Recs:%5lu\n\n", + cp, + FormatDateShort(&pHeader->mhArchiveCreateWhen, date1), + FormatDateShort(&pHeader->mhArchiveModWhen, date2), + pHeader->mhTotalRecords); + printf(" Name Type Auxtyp Archived" + " Fmat Size Un-Length\n"); + printf("-------------------------------------------------" + "----------------------------\n"); - err = NuContents(pArchive, ShowContentsVerbose); - if (err != kNuErrNone) - goto bail; + err = NuContents(pArchive, ShowContentsVerbose); + if (err != kNuErrNone) + goto bail; - /* - * Show the totals. NuFX overhead can be as much as 25% for archives - * with lots of small files. - */ - NState_GetTotals(pState, &totalLen, &totalCompLen); - printf("-------------------------------------------------" - "----------------------------\n"); - printf(" Uncomp: %ld Comp: %ld %%of orig: %d%%\n", - totalLen, totalCompLen, - totalLen == 0 ? 0 : ComputePercent(totalCompLen, totalLen)); - #ifdef DEBUG_VERBOSE - printf(" Overhead: %ld (%d%%)\n", - pHeader->mhMasterEOF - totalCompLen, - ComputePercent(pHeader->mhMasterEOF - totalCompLen, - pHeader->mhMasterEOF)); - #endif + /* + * Show the totals. NuFX overhead can be as much as 25% for archives + * with lots of small files. + */ + NState_GetTotals(pState, &totalLen, &totalCompLen); + printf("-------------------------------------------------" + "----------------------------\n"); + printf(" Uncomp: %ld Comp: %ld %%of orig: %d%%\n", + totalLen, totalCompLen, + totalLen == 0 ? 0 : ComputePercent(totalCompLen, totalLen)); + #ifdef DEBUG_VERBOSE + printf(" Overhead: %ld (%d%%)\n", + pHeader->mhMasterEOF - totalCompLen, + ComputePercent(pHeader->mhMasterEOF - totalCompLen, + pHeader->mhMasterEOF)); + #endif - /*(void) NuDebugDumpArchive(pArchive);*/ + /*(void) NuDebugDumpArchive(pArchive);*/ bail: - if (pArchive != nil) - (void) NuClose(pArchive); - return err; + if (pArchive != nil) + (void) NuClose(pArchive); + return err; } @@ -381,7 +381,7 @@ bail: static NuResult NullCallback(NuArchive* pArchive, void* vpRecord) { - return kNuOK; + return kNuOK; } /* @@ -391,30 +391,30 @@ NullCallback(NuArchive* pArchive, void* vpRecord) NuError DoListDebug(NulibState* pState) { - NuError err; - NuArchive* pArchive = nil; + NuError err; + NuArchive* pArchive = nil; - assert(pState != nil); + assert(pState != nil); - err = OpenArchiveReadOnly(pState); - if (err != kNuErrNone) - goto bail; - pArchive = NState_GetNuArchive(pState); - assert(pArchive != nil); + err = OpenArchiveReadOnly(pState); + if (err != kNuErrNone) + goto bail; + pArchive = NState_GetNuArchive(pState); + assert(pArchive != nil); - /* have to do something to force the library to scan the archive */ - err = NuContents(pArchive, NullCallback); - if (err != kNuErrNone) - goto bail; + /* have to do something to force the library to scan the archive */ + err = NuContents(pArchive, NullCallback); + if (err != kNuErrNone) + goto bail; - err = NuDebugDumpArchive(pArchive); - if (err != kNuErrNone) - fprintf(stderr, "ERROR: debugging not enabled in nufxlib\n"); - /* fall through with err */ + err = NuDebugDumpArchive(pArchive); + if (err != kNuErrNone) + fprintf(stderr, "ERROR: debugging not enabled in nufxlib\n"); + /* fall through with err */ bail: - if (pArchive != nil) - (void) NuClose(pArchive); - return err; + if (pArchive != nil) + (void) NuClose(pArchive); + return err; } diff --git a/nulib2/Main.c b/nulib2/Main.c index 189ac93..11e3c41 100644 --- a/nulib2/Main.c +++ b/nulib2/Main.c @@ -20,21 +20,21 @@ const char* gProgName = "Nulib2"; * Which modifiers are valid with which commands? */ typedef struct ValidCombo { - Command cmd; - Boolean okayForPipe; - Boolean filespecRequired; - const char* modifiers; + Command cmd; + Boolean okayForPipe; + Boolean filespecRequired; + const char* modifiers; } ValidCombo; static const ValidCombo gValidCombos[] = { - { kCommandAdd, false, true, "ufrj0cke" }, - { kCommandDelete, false, true, "r" }, - { kCommandExtract, true, false, "ufrjclse" }, - { kCommandExtractToPipe, true, false, "rl" }, - { kCommandListShort, true, false, "" }, - { kCommandListVerbose, true, false, "" }, - { kCommandListDebug, true, false, "" }, - { kCommandTest, true, false, "r" }, + { kCommandAdd, false, true, "ufrj0cke" }, + { kCommandDelete, false, true, "r" }, + { kCommandExtract, true, false, "ufrjclse" }, + { kCommandExtractToPipe, true, false, "rl" }, + { kCommandListShort, true, false, "" }, + { kCommandListVerbose, true, false, "" }, + { kCommandListDebug, true, false, "" }, + { kCommandTest, true, false, "r" }, }; @@ -46,14 +46,14 @@ static const ValidCombo gValidCombos[] = { static const ValidCombo* FindValidComboEntry(Command cmd) { - int i; + int i; - for (i = 0; i < NELEM(gValidCombos); i++) { - if (gValidCombos[i].cmd == cmd) - return &gValidCombos[i]; - } + for (i = 0; i < NELEM(gValidCombos); i++) { + if (gValidCombos[i].cmd == cmd) + return &gValidCombos[i]; + } - return nil; + return nil; } /* @@ -63,16 +63,16 @@ FindValidComboEntry(Command cmd) static Boolean IsValidModifier(Command cmd, char modifier) { - const ValidCombo* pvc; + const ValidCombo* pvc; - pvc = FindValidComboEntry(cmd); - if (pvc != nil) { - if (strchr(pvc->modifiers, modifier) == nil) - return false; - else - return true; - } else - return false; + pvc = FindValidComboEntry(cmd); + if (pvc != nil) { + if (strchr(pvc->modifiers, modifier) == nil) + return false; + else + return true; + } else + return false; } /* @@ -81,13 +81,13 @@ IsValidModifier(Command cmd, char modifier) static Boolean IsValidOnPipe(Command cmd) { - const ValidCombo* pvc; + const ValidCombo* pvc; - pvc = FindValidComboEntry(cmd); - if (pvc != nil) { - return pvc->okayForPipe; - } else - return false; + pvc = FindValidComboEntry(cmd); + if (pvc != nil) { + return pvc->okayForPipe; + } else + return false; } /* @@ -96,17 +96,17 @@ IsValidOnPipe(Command cmd) static Boolean IsFilespecRequired(Command cmd) { - const ValidCombo* pvc; + const ValidCombo* pvc; - pvc = FindValidComboEntry(cmd); - if (pvc != nil) { - return pvc->filespecRequired; - } else { - /* command not found? warn about it here... */ - fprintf(stderr, "%s: Command %d not found in gValidCombos table\n", - gProgName, cmd); - return false; - } + pvc = FindValidComboEntry(cmd); + if (pvc != nil) { + return pvc->filespecRequired; + } else { + /* command not found? warn about it here... */ + fprintf(stderr, "%s: Command %d not found in gValidCombos table\n", + gProgName, cmd); + return false; + } } @@ -116,19 +116,19 @@ IsFilespecRequired(Command cmd) static const char* GetProgName(const NulibState* pState, const char* argv0) { - const char* result; - char sep; + const char* result; + char sep; - /* use the appropriate system pathname separator */ - sep = NState_GetSystemPathSeparator(pState); + /* use the appropriate system pathname separator */ + sep = NState_GetSystemPathSeparator(pState); - result = strrchr(argv0, sep); - if (result == nil) - result = argv0; - else - result++; /* advance past the separator */ - - return result; + result = strrchr(argv0, sep); + if (result == nil) + result = argv0; + else + result++; /* advance past the separator */ + + return result; } @@ -138,34 +138,34 @@ GetProgName(const NulibState* pState, const char* argv0) static void Usage(const NulibState* pState) { - long majorVersion, minorVersion, bugVersion; - const char* nufxLibDate; - const char* nufxLibFlags; + long majorVersion, minorVersion, bugVersion; + const char* nufxLibDate; + const char* nufxLibFlags; - (void) NuGetVersion(&majorVersion, &minorVersion, &bugVersion, - &nufxLibDate, &nufxLibFlags); + (void) NuGetVersion(&majorVersion, &minorVersion, &bugVersion, + &nufxLibDate, &nufxLibFlags); - printf("\nNulib2 v%s, linked with NufxLib v%ld.%ld.%ld [%s]\n", - NState_GetProgramVersion(pState), - majorVersion, minorVersion, bugVersion, nufxLibFlags); - printf("This software is distributed under terms of the GNU General Public License.\n"); - printf("Written by Andy McFadden, http://www.nulib.com/.\n\n"); - printf("Usage: %s -command[modifiers] archive [filename-list]\n\n", - gProgName); - printf( - " -a add files, create arc if needed -x extract files\n" - " -t list files (short) -v list files (verbose)\n" - " -p extract files to pipe, no msgs -i test archive integrity\n" - " -d delete files from archive\n" - "\n" - " modifiers:\n" - " -u update files (add + keep newest) -f freshen (update, no add)\n" - " -r recurse into subdirs -j junk (don't record) directory names\n" - " -0 don't use compression -c add one-line comments\n" - " -l auto-convert text files -ll auto-convert ALL files\n" - " -s stomp existing files w/o asking -k store files as disk images\n" - " -e preserve ProDOS file types -ee extend preserved names\n" - ); + printf("\nNulib2 v%s, linked with NufxLib v%ld.%ld.%ld [%s]\n", + NState_GetProgramVersion(pState), + majorVersion, minorVersion, bugVersion, nufxLibFlags); + printf("This software is distributed under terms of the GNU General Public License.\n"); + printf("Written by Andy McFadden, http://www.nulib.com/.\n\n"); + printf("Usage: %s -command[modifiers] archive [filename-list]\n\n", + gProgName); + printf( + " -a add files, create arc if needed -x extract files\n" + " -t list files (short) -v list files (verbose)\n" + " -p extract files to pipe, no msgs -i test archive integrity\n" + " -d delete files from archive\n" + "\n" + " modifiers:\n" + " -u update files (add + keep newest) -f freshen (update, no add)\n" + " -r recurse into subdirs -j junk (don't record) directory names\n" + " -0 don't use compression -c add one-line comments\n" + " -l auto-convert text files -ll auto-convert ALL files\n" + " -s stomp existing files w/o asking -k store files as disk images\n" + " -e preserve ProDOS file types -ee extend preserved names\n" + ); } @@ -175,147 +175,147 @@ Usage(const NulibState* pState) static int ProcessOptions(NulibState* pState, int argc, char* const* argv) { - const char* cp; - int idx; + const char* cp; + int idx; - /* - * Must have at least a command letter and an archive filename. - */ - if (argc < 3) { - Usage(pState); - return -1; - } + /* + * Must have at least a command letter and an archive filename. + */ + if (argc < 3) { + Usage(pState); + return -1; + } - /* - * Argv[1] and any subsequent entries that have a leading hyphen - * are options. Anything after that is a filename. Parse until we - * think we've hit the filename. - * - * By UNIX convention, however, stdin is specified as a file called "-". - */ - for (idx = 1; idx < argc; idx++) { - cp = argv[idx]; + /* + * Argv[1] and any subsequent entries that have a leading hyphen + * are options. Anything after that is a filename. Parse until we + * think we've hit the filename. + * + * By UNIX convention, however, stdin is specified as a file called "-". + */ + for (idx = 1; idx < argc; idx++) { + cp = argv[idx]; - if (idx > 1 && *cp != '-') - break; + if (idx > 1 && *cp != '-') + break; - if (*cp == '-') - cp++; - if (*cp == '\0') { - if (idx == 1) { - fprintf(stderr, - "%s: You must specify a command after the '-'\n", - gProgName); - goto fail; - } else { - /* they're using '-' for the filename */ - break; - } - } + if (*cp == '-') + cp++; + if (*cp == '\0') { + if (idx == 1) { + fprintf(stderr, + "%s: You must specify a command after the '-'\n", + gProgName); + goto fail; + } else { + /* they're using '-' for the filename */ + break; + } + } - if (idx == 1) { - switch (tolower(*cp)) { - case 'a': NState_SetCommand(pState, kCommandAdd); break; - case 'x': NState_SetCommand(pState, kCommandExtract); break; - case 'p': NState_SetCommand(pState, kCommandExtractToPipe); break; - case 't': NState_SetCommand(pState, kCommandListShort); break; - case 'v': NState_SetCommand(pState, kCommandListVerbose); break; - case 'z': NState_SetCommand(pState, kCommandListDebug); break; - case 'i': NState_SetCommand(pState, kCommandTest); break; - case 'd': NState_SetCommand(pState, kCommandDelete); break; - default: - fprintf(stderr, "%s: Unknown command '%c'\n", gProgName, *cp); - goto fail; - } + if (idx == 1) { + switch (tolower(*cp)) { + case 'a': NState_SetCommand(pState, kCommandAdd); break; + case 'x': NState_SetCommand(pState, kCommandExtract); break; + case 'p': NState_SetCommand(pState, kCommandExtractToPipe); break; + case 't': NState_SetCommand(pState, kCommandListShort); break; + case 'v': NState_SetCommand(pState, kCommandListVerbose); break; + case 'z': NState_SetCommand(pState, kCommandListDebug); break; + case 'i': NState_SetCommand(pState, kCommandTest); break; + case 'd': NState_SetCommand(pState, kCommandDelete); break; + default: + fprintf(stderr, "%s: Unknown command '%c'\n", gProgName, *cp); + goto fail; + } - cp++; - } + cp++; + } - while (*cp != '\0') { - switch (tolower(*cp)) { - case 'u': NState_SetModUpdate(pState, true); break; - case 'f': NState_SetModFreshen(pState, true); break; - case 'r': NState_SetModRecurse(pState, true); break; - case 'j': NState_SetModJunkPaths(pState, true); break; - case '0': NState_SetModNoCompression(pState, true); break; - case 'c': NState_SetModComments(pState, true); break; - case 's': NState_SetModOverwriteExisting(pState, true); break; - case 'k': NState_SetModAddAsDisk(pState, true); break; - case 'e': - if (*(cp-1) == 'e') /* should never point at invalid */ - NState_SetModPreserveTypeExtended(pState, true); - else - NState_SetModPreserveType(pState, true); - break; - case 'l': - if (*(cp-1) == 'l') /* should never point at invalid */ - NState_SetModConvertAll(pState, true); - else - NState_SetModConvertText(pState, true); - break; - default: - fprintf(stderr, "%s: Unknown modifier '%c'\n", gProgName, *cp); - goto fail; - } + while (*cp != '\0') { + switch (tolower(*cp)) { + case 'u': NState_SetModUpdate(pState, true); break; + case 'f': NState_SetModFreshen(pState, true); break; + case 'r': NState_SetModRecurse(pState, true); break; + case 'j': NState_SetModJunkPaths(pState, true); break; + case '0': NState_SetModNoCompression(pState, true); break; + case 'c': NState_SetModComments(pState, true); break; + case 's': NState_SetModOverwriteExisting(pState, true); break; + case 'k': NState_SetModAddAsDisk(pState, true); break; + case 'e': + if (*(cp-1) == 'e') /* should never point at invalid */ + NState_SetModPreserveTypeExtended(pState, true); + else + NState_SetModPreserveType(pState, true); + break; + case 'l': + if (*(cp-1) == 'l') /* should never point at invalid */ + NState_SetModConvertAll(pState, true); + else + NState_SetModConvertText(pState, true); + break; + default: + fprintf(stderr, "%s: Unknown modifier '%c'\n", gProgName, *cp); + goto fail; + } - if (!IsValidModifier(NState_GetCommand(pState), (char)tolower(*cp))) - { - fprintf(stderr, - "%s: The '%c' modifier doesn't make sense here\n", - gProgName, tolower(*cp)); - goto fail; - } + if (!IsValidModifier(NState_GetCommand(pState), (char)tolower(*cp))) + { + fprintf(stderr, + "%s: The '%c' modifier doesn't make sense here\n", + gProgName, tolower(*cp)); + goto fail; + } - cp++; - } - } + cp++; + } + } - /* - * See if we have an archive name. If it's "-", see if we allow that. - */ - assert(idx < argc); - NState_SetArchiveFilename(pState, argv[idx]); - if (IsFilenameStdin(argv[idx])) { - if (!IsValidOnPipe(NState_GetCommand(pState))) { - fprintf(stderr, "%s: You can't do that with a pipe\n", - gProgName); - goto fail; - } - } - idx++; + /* + * See if we have an archive name. If it's "-", see if we allow that. + */ + assert(idx < argc); + NState_SetArchiveFilename(pState, argv[idx]); + if (IsFilenameStdin(argv[idx])) { + if (!IsValidOnPipe(NState_GetCommand(pState))) { + fprintf(stderr, "%s: You can't do that with a pipe\n", + gProgName); + goto fail; + } + } + idx++; - /* - * See if we have a file specification. Some of the commands require - * a filespec; others just perform the requested operation on all of - * the records in the archive if none is provided. - */ - if (idx < argc) { - /* got one or more */ - NState_SetFilespecPointer(pState, &argv[idx]); - NState_SetFilespecCount(pState, argc - idx); - } else { - assert(idx == argc); - if (IsFilespecRequired(NState_GetCommand(pState))) { - fprintf(stderr, "%s: This command requires a list of files\n", - gProgName); - goto fail; - } - NState_SetFilespecPointer(pState, nil); - NState_SetFilespecCount(pState, 0); - } + /* + * See if we have a file specification. Some of the commands require + * a filespec; others just perform the requested operation on all of + * the records in the archive if none is provided. + */ + if (idx < argc) { + /* got one or more */ + NState_SetFilespecPointer(pState, &argv[idx]); + NState_SetFilespecCount(pState, argc - idx); + } else { + assert(idx == argc); + if (IsFilespecRequired(NState_GetCommand(pState))) { + fprintf(stderr, "%s: This command requires a list of files\n", + gProgName); + goto fail; + } + NState_SetFilespecPointer(pState, nil); + NState_SetFilespecCount(pState, 0); + } #ifdef DEBUG_VERBOSE - NState_DebugDump(pState); + NState_DebugDump(pState); #endif - return 0; + return 0; fail: - fprintf(stderr, - "%s: (invoke without arguments to see usage information)\n", - gProgName); - return -1; + fprintf(stderr, + "%s: (invoke without arguments to see usage information)\n", + gProgName); + return -1; } @@ -328,42 +328,42 @@ fail: int DoWork(NulibState* pState) { - NuError err; + NuError err; - switch (NState_GetCommand(pState)) { - case kCommandAdd: - err = DoAdd(pState); - break; - case kCommandExtract: - err = DoExtract(pState); - break; - case kCommandExtractToPipe: - err = DoExtractToPipe(pState); - break; - case kCommandTest: - err = DoTest(pState); - break; - case kCommandListShort: - err = DoListShort(pState); - break; - case kCommandListVerbose: - err = DoListVerbose(pState); - break; - case kCommandListDebug: - err = DoListDebug(pState); - break; - case kCommandDelete: - err = DoDelete(pState); - break; - default: - fprintf(stderr, "ERROR: unexpected command %d\n", - NState_GetCommand(pState)); - err = kNuErrInternal; - assert(0); - break; - } + switch (NState_GetCommand(pState)) { + case kCommandAdd: + err = DoAdd(pState); + break; + case kCommandExtract: + err = DoExtract(pState); + break; + case kCommandExtractToPipe: + err = DoExtractToPipe(pState); + break; + case kCommandTest: + err = DoTest(pState); + break; + case kCommandListShort: + err = DoListShort(pState); + break; + case kCommandListVerbose: + err = DoListVerbose(pState); + break; + case kCommandListDebug: + err = DoListDebug(pState); + break; + case kCommandDelete: + err = DoDelete(pState); + break; + default: + fprintf(stderr, "ERROR: unexpected command %d\n", + NState_GetCommand(pState)); + err = kNuErrInternal; + assert(0); + break; + } - return (err != kNuErrNone); + return (err != kNuErrNone); } /* @@ -372,38 +372,38 @@ DoWork(NulibState* pState) int main(int argc, char** argv) { - NulibState* pState = nil; - int result = 0; + NulibState* pState = nil; + int result = 0; - #if 0 - extern NuResult ErrorMessageHandler(NuArchive* pArchive, - void* vErrorMessage); - NuSetGlobalErrorMessageHandler(ErrorMessageHandler); - #endif + #if 0 + extern NuResult ErrorMessageHandler(NuArchive* pArchive, + void* vErrorMessage); + NuSetGlobalErrorMessageHandler(ErrorMessageHandler); + #endif - if (NState_Init(&pState) != kNuErrNone) { - fprintf(stderr, "ERROR: unable to initialize globals\n"); - exit(1); - } + if (NState_Init(&pState) != kNuErrNone) { + fprintf(stderr, "ERROR: unable to initialize globals\n"); + exit(1); + } - gProgName = GetProgName(pState, argv[0]); + gProgName = GetProgName(pState, argv[0]); - if (ProcessOptions(pState, argc, argv) < 0) { - result = 2; - goto bail; - } + if (ProcessOptions(pState, argc, argv) < 0) { + result = 2; + goto bail; + } - if (NState_ExtraInit(pState) != kNuErrNone) { - fprintf(stderr, "ERROR: additional initialization failed\n"); - exit(1); - } + if (NState_ExtraInit(pState) != kNuErrNone) { + fprintf(stderr, "ERROR: additional initialization failed\n"); + exit(1); + } - result = DoWork(pState); - if (result) - printf("Failed.\n"); + result = DoWork(pState); + if (result) + printf("Failed.\n"); bail: - NState_Free(pState); - exit(result); + NState_Free(pState); + exit(result); } diff --git a/nulib2/MiscStuff.c b/nulib2/MiscStuff.c index a14af3f..ce94151 100644 --- a/nulib2/MiscStuff.c +++ b/nulib2/MiscStuff.c @@ -19,13 +19,13 @@ const char* Nu_strerror(int errnum) { - extern int sys_nerr; - extern char *sys_errlist[]; + extern int sys_nerr; + extern char *sys_errlist[]; - if (errnum < 0 || errnum > sys_nerr) - return NULL; + if (errnum < 0 || errnum > sys_nerr) + return NULL; - return sys_errlist[errnum]; + return sys_errlist[errnum]; } #endif @@ -41,13 +41,13 @@ Nu_strerror(int errnum) void* Nu_memmove(void* dst, const void* src, size_t n) { - void* retval = dst; - char* srcp = (char*)src; - char* dstp = (char*)dst; + void* retval = dst; + char* srcp = (char*)src; + char* dstp = (char*)dst; - /* you can normally get away with this if n==0 */ - assert(dst != NULL); - assert(src != NULL); + /* you can normally get away with this if n==0 */ + assert(dst != NULL); + assert(src != NULL); if (dstp == srcp || !n) { /* nothing to do */ @@ -63,7 +63,7 @@ Nu_memmove(void* dst, const void* src, size_t n) *dstp++ = *srcp++; } - return retval; + return retval; } #endif @@ -83,7 +83,7 @@ Nu_memmove(void* dst, const void* src, size_t n) unsigned long Nu_strtoul(const char *nptr, char **endptr, int base) { - return strtol(nptr, endptr, base); + return strtol(nptr, endptr, base); } #endif @@ -94,9 +94,9 @@ Nu_strtoul(const char *nptr, char **endptr, int base) int Nu_strcasecmp(const char *str1, const char *str2) { - while (*str1 && *str2 && toupper(*str1) == toupper(*str2)) - str1++, str2++; - return (toupper(*str1) - toupper(*str2)); + while (*str1 && *str2 && toupper(*str1) == toupper(*str2)) + str1++, str2++; + return (toupper(*str1) - toupper(*str2)); } #endif @@ -108,13 +108,13 @@ Nu_strcasecmp(const char *str1, const char *str2) int Nu_strncasecmp(const char *str1, const char *str2, size_t n) { - while (n && *str1 && *str2 && toupper(*str1) == toupper(*str2)) - str1++, str2++, n--; + while (n && *str1 && *str2 && toupper(*str1) == toupper(*str2)) + str1++, str2++, n--; - if (n) - return (toupper(*str1) - toupper(*str2)); - else - return 0; /* no mismatch in first n chars */ + if (n) + return (toupper(*str1) - toupper(*str2)); + else + return 0; /* no mismatch in first n chars */ } #endif diff --git a/nulib2/MiscStuff.h b/nulib2/MiscStuff.h index 1f35ea0..5455fad 100644 --- a/nulib2/MiscStuff.h +++ b/nulib2/MiscStuff.h @@ -42,11 +42,11 @@ int Nu_strncasecmp(const char *s1, const char *s2, size_t n); #include -#define nil NULL /* I can't seem to stop typing 'nil' now */ +#define nil NULL /* I can't seem to stop typing 'nil' now */ -typedef uchar Boolean; -#define false (0) -#define true (!false) +typedef uchar Boolean; +#define false (0) +#define true (!false) /* @@ -54,15 +54,15 @@ typedef uchar Boolean; */ /* compute #of elements in a static array */ -#define NELEM(x) (sizeof(x) / sizeof((x)[0])) +#define NELEM(x) (sizeof(x) / sizeof((x)[0])) /* convert single hex digit char to number */ #define HexDigit(x) ( !isxdigit((int)(x)) ? -1 : \ - (x) <= '9' ? (x) - '0' : toupper(x) +10 - 'A' ) + (x) <= '9' ? (x) - '0' : toupper(x) +10 - 'A' ) /* convert number from 0-15 to hex digit */ -#define HexConv(x) ( ((uint)(x)) <= 15 ? \ - ( (x) <= 9 ? (x) + '0' : (x) -10 + 'A') : -1 ) +#define HexConv(x) ( ((uint)(x)) <= 15 ? \ + ( (x) <= 9 ? (x) + '0' : (x) -10 + 'A') : -1 ) /* @@ -80,29 +80,29 @@ typedef uchar Boolean; #if defined(DEBUG_VERBOSE) /* quick debug printf macro */ - #define DBUG(args) printf args + #define DBUG(args) printf args #else - #define DBUG(args) ((void)0) + #define DBUG(args) ((void)0) #endif #if defined(NDEBUG) - #define DebugFill(addr, len) ((void)0) + #define DebugFill(addr, len) ((void)0) - #define DebugAbort() ((void)0) + #define DebugAbort() ((void)0) #else /* when debugging, fill Malloc blocks with junk, unless we're using Purify */ #if !defined(PURIFY) - #define DebugFill(addr, len) memset(addr, 0xa3, len) + #define DebugFill(addr, len) memset(addr, 0xa3, len) #else - #define DebugFill(addr, len) ((void)0) + #define DebugFill(addr, len) ((void)0) #endif - #define DebugAbort() abort() + #define DebugAbort() abort() #endif -#define kInvalidFill (0xa3) -#define kInvalidPtr ((void*)0xa3a3a3a3) +#define kInvalidFill (0xa3) +#define kInvalidPtr ((void*)0xa3a3a3a3) #endif /*__MiscStuff__*/ diff --git a/nulib2/MiscUtils.c b/nulib2/MiscUtils.c index 73dfb4f..d709d87 100644 --- a/nulib2/MiscUtils.c +++ b/nulib2/MiscUtils.c @@ -19,39 +19,39 @@ void ReportError(NuError err, const char* format, ...) { - const char* msg; - va_list args; + const char* msg; + va_list args; - assert(format != nil); + assert(format != nil); - va_start(args, format); + va_start(args, format); - /* print the message, if any */ - if (format != nil) { - fprintf(stderr, "%s: ERROR: ", gProgName); - vfprintf(stderr, format, args); - } + /* print the message, if any */ + if (format != nil) { + fprintf(stderr, "%s: ERROR: ", gProgName); + vfprintf(stderr, format, args); + } - /* print the error code data, if any */ - if (err == kNuErrNone) - fprintf(stderr, "\n"); - else { - if (format != nil) - fprintf(stderr, ": "); + /* print the error code data, if any */ + if (err == kNuErrNone) + fprintf(stderr, "\n"); + else { + if (format != nil) + fprintf(stderr, ": "); - msg = nil; - if (err >= 0) - msg = strerror(err); - if (msg == nil) - msg = NuStrError(err); + msg = nil; + if (err >= 0) + msg = strerror(err); + if (msg == nil) + msg = NuStrError(err); - if (msg == nil) - fprintf(stderr, "(unknown err=%d)\n", err); - else - fprintf(stderr, "%s\n", msg); - } + if (msg == nil) + fprintf(stderr, "(unknown err=%d)\n", err); + else + fprintf(stderr, "%s\n", msg); + } - va_end(args); + va_end(args); } @@ -65,46 +65,46 @@ ReportError(NuError err, const char* format, ...) void* Malloc(size_t size) { - void* _result; + void* _result; - Assert(size > 0); - _result = malloc(size); - if (_result == nil) { - ReportError(kNuErrMalloc, "malloc(%u) failed", (uint) size); - DebugAbort(); /* leave a core dump if we're built for it */ - } - DebugFill(_result, size); - return _result; + Assert(size > 0); + _result = malloc(size); + if (_result == nil) { + ReportError(kNuErrMalloc, "malloc(%u) failed", (uint) size); + DebugAbort(); /* leave a core dump if we're built for it */ + } + DebugFill(_result, size); + return _result; } void* Calloc(size_t size) { - void* _cresult = Malloc(size); - memset(_cresult, 0, size); - return _cresult; + void* _cresult = Malloc(size); + memset(_cresult, 0, size); + return _cresult; } void* Realloc(void* ptr, size_t size) { - void* _result; + void* _result; - Assert(ptr != nil); /* disallow this usage */ - Assert(size > 0); /* disallow this usage */ - _result = realloc(ptr, size); - if (_result == nil) { - ReportError(kNuErrMalloc, "realloc(%u) failed", (uint) size); - DebugAbort(); /* leave a core dump if we're built for it */ - } - return _result; + Assert(ptr != nil); /* disallow this usage */ + Assert(size > 0); /* disallow this usage */ + _result = realloc(ptr, size); + if (_result == nil) { + ReportError(kNuErrMalloc, "realloc(%u) failed", (uint) size); + DebugAbort(); /* leave a core dump if we're built for it */ + } + return _result; } void Free(void* ptr) { - if (ptr != nil) - free(ptr); + if (ptr != nil) + free(ptr); } #endif diff --git a/nulib2/Nulib2.h b/nulib2/Nulib2.h index 899ebde..6271496 100644 --- a/nulib2/Nulib2.h +++ b/nulib2/Nulib2.h @@ -7,7 +7,7 @@ #ifndef __Nulib2__ #define __Nulib2__ -#include "SysDefs.h" /* system-dependent defs; must come first */ +#include "SysDefs.h" /* system-dependent defs; must come first */ #include #include "State.h" #include "MiscStuff.h" @@ -18,10 +18,10 @@ #endif /* replace unsupported chars with '%xx' */ -#define kForeignIndic '%' +#define kForeignIndic '%' /* make our one-line comments this big */ -#define kDefaultCommentLen 200 +#define kDefaultCommentLen 200 /* @@ -52,9 +52,9 @@ NuError DoTest(NulibState* pState); const char* GetFileTypeString(ulong fileType); const char* NormalizePath(NulibState* pState, NuPathnameProposal* pathProposal); void InterpretExtension(NulibState* pState, const char* pathName, - ulong* pFileType, ulong* pAuxType); + ulong* pFileType, ulong* pAuxType); Boolean ExtractPreservationString(NulibState* pState, char* pathname, - ulong* pFileType, ulong* pAuxType, NuThreadID* pThreadID); + ulong* pFileType, ulong* pAuxType, NuThreadID* pThreadID); void DenormalizePath(NulibState* pState, char* pathBuf); const char* FilenameOnly(NulibState* pState, const char* pathname); const char* FindExtension(NulibState* pState, const char* pathname); @@ -73,7 +73,7 @@ void ReportError(NuError err, const char* format, ...) __attribute__ ((format(printf, 2, 3))) #endif ; -#ifdef USE_DMALLOC /* want file and line numbers for calls */ +#ifdef USE_DMALLOC /* want file and line numbers for calls */ # define Malloc(size) malloc(size) # define Calloc(size) calloc(1, size) # define Realloc(ptr, size) realloc(ptr, size) @@ -87,11 +87,11 @@ void Free(void* ptr); /* SysUtils.c */ NuError NormalizeFileName(NulibState* pState, const char* srcp, long srcLen, - char fssep, char** pDstp, long dstLen); + char fssep, char** pDstp, long dstLen); NuError NormalizeDirectoryName(NulibState* pState, const char* srcp, - long srcLen, char fssep, char** pDstp, long dstLen); + long srcLen, char fssep, char** pDstp, long dstLen); char* MakeTempArchiveName(NulibState* pState); NuError AddFile(NulibState* pState, NuArchive* pArchive, - const char* pathname); + const char* pathname); #endif /*__Nulib2__*/ diff --git a/nulib2/README.txt b/nulib2/README.txt index 2c5f7ef..9e7aced 100644 --- a/nulib2/README.txt +++ b/nulib2/README.txt @@ -59,16 +59,16 @@ DJGPP, follow the UNIX instructions. NuLib2 has been tested with Microsoft Visual C++ 6.0. To build NuLib2, start up a DOS shell and run vcvars32.bat to set your environment. Run: - nmake -f makefile.msc + nmake -f makefile.msc to build with debugging info, or - nmake -f makefile.msc nodebug=1 + nmake -f makefile.msc nodebug=1 to build optimized. Other Notes =========== -All of the source code was formatted with four-space hard tabs. +All of the source code is now formatted with spaces instead of tabs. Fun benchmark of the day: diff --git a/nulib2/State.c b/nulib2/State.c index 3942cc7..432775c 100644 --- a/nulib2/State.c +++ b/nulib2/State.c @@ -18,19 +18,19 @@ static const char* gProgramVersion = "1.0.1"; NuError NState_Init(NulibState** ppState) { - assert(ppState != nil); + assert(ppState != nil); - *ppState = Calloc(sizeof(**ppState)); - if (*ppState == nil) - return kNuErrMalloc; + *ppState = Calloc(sizeof(**ppState)); + if (*ppState == nil) + return kNuErrMalloc; - /* - * Initialize the contents to default values. - */ - (*ppState)->systemPathSeparator = PATH_SEP; - (*ppState)->programVersion = gProgramVersion; + /* + * Initialize the contents to default values. + */ + (*ppState)->systemPathSeparator = PATH_SEP; + (*ppState)->programVersion = gProgramVersion; - return kNuErrNone; + return kNuErrNone; } /* @@ -39,30 +39,30 @@ NState_Init(NulibState** ppState) NuError NState_ExtraInit(NulibState* pState) { - NuError err; - NuValue convertEOL; + NuError err; + NuValue convertEOL; - /* - * Create a data sink for "stdout", in case we use the "-p" command. - * Set the EOL conversion according to the "-l" modifier. - */ - convertEOL = kNuConvertOff; - if (pState->modConvertText) - convertEOL = kNuConvertAuto; - if (pState->modConvertAll) - convertEOL = kNuConvertOn; + /* + * Create a data sink for "stdout", in case we use the "-p" command. + * Set the EOL conversion according to the "-l" modifier. + */ + convertEOL = kNuConvertOff; + if (pState->modConvertText) + convertEOL = kNuConvertAuto; + if (pState->modConvertAll) + convertEOL = kNuConvertOn; - err = NuCreateDataSinkForFP(true, convertEOL, stdout, &pState->pPipeSink); - if (err != kNuErrNone) - return err; + err = NuCreateDataSinkForFP(true, convertEOL, stdout, &pState->pPipeSink); + if (err != kNuErrNone) + return err; - /* - * Create a data sink for "stdout", in case we use the "-c" modifier. - * The EOL conversion is always on. - */ - err = NuCreateDataSinkForFP(true, kNuConvertOn, stdout, - &pState->pCommentSink); - return err; + /* + * Create a data sink for "stdout", in case we use the "-c" modifier. + * The EOL conversion is always on. + */ + err = NuCreateDataSinkForFP(true, kNuConvertOn, stdout, + &pState->pCommentSink); + return err; } @@ -72,16 +72,16 @@ NState_ExtraInit(NulibState* pState) void NState_Free(NulibState* pState) { - if (pState == nil) - return; + if (pState == nil) + return; - Free(pState->renameToStr); /* ?? */ - Free(pState->tempPathnameBuf); - if (pState->pPipeSink != nil) - NuFreeDataSink(pState->pPipeSink); - if (pState->pCommentSink != nil) - NuFreeDataSink(pState->pCommentSink); - Free(pState); + Free(pState->renameToStr); /* ?? */ + Free(pState->tempPathnameBuf); + if (pState->pPipeSink != nil) + NuFreeDataSink(pState->pPipeSink); + if (pState->pCommentSink != nil) + NuFreeDataSink(pState->pCommentSink); + Free(pState); } @@ -89,411 +89,411 @@ NState_Free(NulibState* pState) void NState_DebugDump(const NulibState* pState) { - /* this will break when the code changes, but it's just for debugging */ - static const char* kCommandNames[] = { - "", - "add", - "delete", - "extract", - "extractToPipe", - "listShort", - "listVerbose", - "listDebug", - "test", - }; + /* this will break when the code changes, but it's just for debugging */ + static const char* kCommandNames[] = { + "", + "add", + "delete", + "extract", + "extractToPipe", + "listShort", + "listVerbose", + "listDebug", + "test", + }; - assert(pState != nil); + assert(pState != nil); - printf("NState:\n"); - printf(" programVersion: '%s'\n", pState->programVersion); - printf(" systemPathSeparator: '%c'\n", pState->systemPathSeparator); - printf(" archiveFilename: '%s'\n", pState->archiveFilename); - printf(" filespec: %ld (%s ...)\n", pState->filespecCount, - !pState->filespecCount ? "" : *pState->filespecPointer); + printf("NState:\n"); + printf(" programVersion: '%s'\n", pState->programVersion); + printf(" systemPathSeparator: '%c'\n", pState->systemPathSeparator); + printf(" archiveFilename: '%s'\n", pState->archiveFilename); + printf(" filespec: %ld (%s ...)\n", pState->filespecCount, + !pState->filespecCount ? "" : *pState->filespecPointer); - printf(" command: %d (%s); modifiers:\n", pState->command, - kCommandNames[pState->command]); - if (pState->modUpdate) - printf(" update\n"); - if (pState->modFreshen) - printf(" freshen\n"); - if (pState->modRecurse) - printf(" recurse\n"); - if (pState->modJunkPaths) - printf(" junkPaths\n"); - if (pState->modNoCompression) - printf(" noCompression\n"); - if (pState->modComments) - printf(" comments\n"); - if (pState->modConvertText) - printf(" convertText\n"); - if (pState->modConvertAll) - printf(" convertAll\n"); - if (pState->modOverwriteExisting) - printf(" overwriteExisting\n"); - if (pState->modPreserveType) - printf(" preserveType\n"); - if (pState->modPreserveTypeExtended) - printf(" preserveTypeExtended\n"); + printf(" command: %d (%s); modifiers:\n", pState->command, + kCommandNames[pState->command]); + if (pState->modUpdate) + printf(" update\n"); + if (pState->modFreshen) + printf(" freshen\n"); + if (pState->modRecurse) + printf(" recurse\n"); + if (pState->modJunkPaths) + printf(" junkPaths\n"); + if (pState->modNoCompression) + printf(" noCompression\n"); + if (pState->modComments) + printf(" comments\n"); + if (pState->modConvertText) + printf(" convertText\n"); + if (pState->modConvertAll) + printf(" convertAll\n"); + if (pState->modOverwriteExisting) + printf(" overwriteExisting\n"); + if (pState->modPreserveType) + printf(" preserveType\n"); + if (pState->modPreserveTypeExtended) + printf(" preserveTypeExtended\n"); - printf("\n"); + printf("\n"); } #endif /* * =========================================================================== - * Simple set/get functions + * Simple set/get functions * =========================================================================== */ char NState_GetSystemPathSeparator(const NulibState* pState) { - return pState->systemPathSeparator; + return pState->systemPathSeparator; } const char* NState_GetProgramVersion(const NulibState* pState) { - return pState->programVersion; + return pState->programVersion; } NuArchive* NState_GetNuArchive(const NulibState* pState) { - return pState->pArchive; + return pState->pArchive; } void NState_SetNuArchive(NulibState* pState, NuArchive* pArchive) { - pState->pArchive = pArchive; + pState->pArchive = pArchive; } Boolean NState_GetSuppressOutput(const NulibState* pState) { - return pState->suppressOutput; + return pState->suppressOutput; } void NState_SetSuppressOutput(NulibState* pState, Boolean doSuppress) { - pState->suppressOutput = doSuppress; + pState->suppressOutput = doSuppress; } Boolean NState_GetInputUnavailable(const NulibState* pState) { - return pState->inputUnavailable; + return pState->inputUnavailable; } void NState_SetInputUnavailable(NulibState* pState, Boolean isUnavailable) { - pState->inputUnavailable = isUnavailable; + pState->inputUnavailable = isUnavailable; } NuRecordIdx NState_GetRenameFromIdx(const NulibState* pState) { - return pState->renameFromIdx; + return pState->renameFromIdx; } void NState_SetRenameFromIdx(NulibState* pState, NuRecordIdx recordIdx) { - pState->renameFromIdx = recordIdx; + pState->renameFromIdx = recordIdx; } char* NState_GetRenameToStr(const NulibState* pState) { - return pState->renameToStr; + return pState->renameToStr; } void NState_SetRenameToStr(NulibState* pState, char* str) { - Free(pState->renameToStr); - pState->renameToStr = str; + Free(pState->renameToStr); + pState->renameToStr = str; } NuDataSink* NState_GetPipeSink(const NulibState* pState) { - return pState->pPipeSink; + return pState->pPipeSink; } NuDataSink* NState_GetCommentSink(const NulibState* pState) { - return pState->pCommentSink; + return pState->pCommentSink; } long NState_GetMatchCount(const NulibState* pState) { - return pState->matchCount; + return pState->matchCount; } void NState_SetMatchCount(NulibState* pState, long count) { - pState->matchCount = count; + pState->matchCount = count; } void NState_IncMatchCount(NulibState* pState) { - pState->matchCount++; + pState->matchCount++; } void NState_AddToTotals(NulibState* pState, long len, long compLen) { - pState->totalLen += len; - pState->totalCompLen += compLen; + pState->totalLen += len; + pState->totalCompLen += compLen; } void NState_GetTotals(NulibState* pState, long* pTotalLen, long* pTotalCompLen) { - *pTotalLen = pState->totalLen; - *pTotalCompLen = pState->totalCompLen; + *pTotalLen = pState->totalLen; + *pTotalCompLen = pState->totalCompLen; } long NState_GetTempPathnameLen(NulibState* pState) { - return pState->tempPathnameAlloc; + return pState->tempPathnameAlloc; } void NState_SetTempPathnameLen(NulibState* pState, long len) { - char* newBuf; + char* newBuf; - len++; /* add one for the '\0' */ + len++; /* add one for the '\0' */ - if (pState->tempPathnameAlloc < len) { - if (pState->tempPathnameBuf == nil) - newBuf = Malloc(len); - else - newBuf = Realloc(pState->tempPathnameBuf, len); - assert(newBuf != nil); - if (newBuf == nil) { - Free(pState->tempPathnameBuf); - pState->tempPathnameBuf = nil; - pState->tempPathnameAlloc = 0; - ReportError(kNuErrMalloc, "buf realloc failed (%ld)", len); - return; - } + if (pState->tempPathnameAlloc < len) { + if (pState->tempPathnameBuf == nil) + newBuf = Malloc(len); + else + newBuf = Realloc(pState->tempPathnameBuf, len); + assert(newBuf != nil); + if (newBuf == nil) { + Free(pState->tempPathnameBuf); + pState->tempPathnameBuf = nil; + pState->tempPathnameAlloc = 0; + ReportError(kNuErrMalloc, "buf realloc failed (%ld)", len); + return; + } - pState->tempPathnameBuf = newBuf; - pState->tempPathnameAlloc = len; - } + pState->tempPathnameBuf = newBuf; + pState->tempPathnameAlloc = len; + } } char* NState_GetTempPathnameBuf(NulibState* pState) { - return pState->tempPathnameBuf; + return pState->tempPathnameBuf; } Command NState_GetCommand(const NulibState* pState) { - return pState->command; + return pState->command; } void NState_SetCommand(NulibState* pState, Command cmd) { - pState->command = cmd; + pState->command = cmd; } const char* NState_GetArchiveFilename(const NulibState* pState) { - return pState->archiveFilename; + return pState->archiveFilename; } void NState_SetArchiveFilename(NulibState* pState, const char* archiveFilename) { - pState->archiveFilename = archiveFilename; + pState->archiveFilename = archiveFilename; } char* const* NState_GetFilespecPointer(const NulibState* pState) { - return pState->filespecPointer; + return pState->filespecPointer; } void NState_SetFilespecPointer(NulibState* pState, char* const* filespecPointer) { - pState->filespecPointer = filespecPointer; + pState->filespecPointer = filespecPointer; } long NState_GetFilespecCount(const NulibState* pState) { - return pState->filespecCount; + return pState->filespecCount; } void NState_SetFilespecCount(NulibState* pState, long filespecCount) { - pState->filespecCount = filespecCount; + pState->filespecCount = filespecCount; } Boolean NState_GetModUpdate(const NulibState* pState) { - return pState->modUpdate; + return pState->modUpdate; } void NState_SetModUpdate(NulibState* pState, Boolean val) { - pState->modUpdate = val; + pState->modUpdate = val; } Boolean NState_GetModFreshen(const NulibState* pState) { - return pState->modFreshen; + return pState->modFreshen; } void NState_SetModFreshen(NulibState* pState, Boolean val) { - pState->modFreshen = val; + pState->modFreshen = val; } Boolean NState_GetModRecurse(const NulibState* pState) { - return pState->modRecurse; + return pState->modRecurse; } void NState_SetModRecurse(NulibState* pState, Boolean val) { - pState->modRecurse = val; + pState->modRecurse = val; } Boolean NState_GetModJunkPaths(const NulibState* pState) { - return pState->modJunkPaths; + return pState->modJunkPaths; } void NState_SetModJunkPaths(NulibState* pState, Boolean val) { - pState->modJunkPaths = val; + pState->modJunkPaths = val; } Boolean NState_GetModNoCompression(const NulibState* pState) { - return pState->modNoCompression; + return pState->modNoCompression; } void NState_SetModNoCompression(NulibState* pState, Boolean val) { - pState->modNoCompression = val; + pState->modNoCompression = val; } Boolean NState_GetModComments(const NulibState* pState) { - return pState->modComments; + return pState->modComments; } void NState_SetModComments(NulibState* pState, Boolean val) { - pState->modComments = val; + pState->modComments = val; } Boolean NState_GetModConvertText(const NulibState* pState) { - return pState->modConvertText; + return pState->modConvertText; } void NState_SetModConvertText(NulibState* pState, Boolean val) { - pState->modConvertText = val; + pState->modConvertText = val; } Boolean NState_GetModConvertAll(const NulibState* pState) { - return pState->modConvertAll; + return pState->modConvertAll; } void NState_SetModConvertAll(NulibState* pState, Boolean val) { - pState->modConvertAll = val; + pState->modConvertAll = val; } Boolean NState_GetModOverwriteExisting(const NulibState* pState) { - return pState->modOverwriteExisting; + return pState->modOverwriteExisting; } void NState_SetModOverwriteExisting(NulibState* pState, Boolean val) { - pState->modOverwriteExisting = val; + pState->modOverwriteExisting = val; } Boolean NState_GetModAddAsDisk(const NulibState* pState) { - return pState->modAddAsDisk; + return pState->modAddAsDisk; } void NState_SetModAddAsDisk(NulibState* pState, Boolean val) { - pState->modAddAsDisk = val; + pState->modAddAsDisk = val; } Boolean NState_GetModPreserveType(const NulibState* pState) { - return pState->modPreserveType; + return pState->modPreserveType; } void NState_SetModPreserveType(NulibState* pState, Boolean val) { - pState->modPreserveType = val; + pState->modPreserveType = val; } Boolean NState_GetModPreserveTypeExtended(const NulibState* pState) { - return pState->modPreserveTypeExtended; + return pState->modPreserveTypeExtended; } void NState_SetModPreserveTypeExtended(NulibState* pState, Boolean val) { - pState->modPreserveTypeExtended = val; + pState->modPreserveTypeExtended = val; } diff --git a/nulib2/State.h b/nulib2/State.h index 94d15f9..91250de 100644 --- a/nulib2/State.h +++ b/nulib2/State.h @@ -16,15 +16,15 @@ * (Some debug code in NState_DebugDump() is sensitive to the order here.) */ typedef enum Command { - kCommandUnknown = 0, - kCommandAdd, - kCommandDelete, - kCommandExtract, - kCommandExtractToPipe, - kCommandListShort, - kCommandListVerbose, - kCommandListDebug, - kCommandTest + kCommandUnknown = 0, + kCommandAdd, + kCommandDelete, + kCommandExtract, + kCommandExtractToPipe, + kCommandListShort, + kCommandListVerbose, + kCommandListDebug, + kCommandTest } Command; @@ -32,48 +32,48 @@ typedef enum Command { * Program-wide state. */ typedef struct NulibState { - /* global goodness */ - const char* programVersion; + /* global goodness */ + const char* programVersion; - /* system-specific values */ - char systemPathSeparator; + /* system-specific values */ + char systemPathSeparator; - /* pointer to archive we're working with */ - NuArchive* pArchive; + /* pointer to archive we're working with */ + NuArchive* pArchive; - /* misc state */ - Boolean suppressOutput; - Boolean inputUnavailable; - NuRecordIdx renameFromIdx; - char* renameToStr; - NuDataSink* pPipeSink; - NuDataSink* pCommentSink; - long matchCount; - long totalLen; - long totalCompLen; + /* misc state */ + Boolean suppressOutput; + Boolean inputUnavailable; + NuRecordIdx renameFromIdx; + char* renameToStr; + NuDataSink* pPipeSink; + NuDataSink* pCommentSink; + long matchCount; + long totalLen; + long totalCompLen; - /* temp storage */ - long tempPathnameAlloc; - char* tempPathnameBuf; + /* temp storage */ + long tempPathnameAlloc; + char* tempPathnameBuf; - /* command-line options */ - Command command; - Boolean modUpdate; - Boolean modFreshen; - Boolean modRecurse; - Boolean modJunkPaths; - Boolean modNoCompression; - Boolean modComments; - Boolean modConvertText; - Boolean modConvertAll; - Boolean modOverwriteExisting; - Boolean modAddAsDisk; - Boolean modPreserveType; - Boolean modPreserveTypeExtended; + /* command-line options */ + Command command; + Boolean modUpdate; + Boolean modFreshen; + Boolean modRecurse; + Boolean modJunkPaths; + Boolean modNoCompression; + Boolean modComments; + Boolean modConvertText; + Boolean modConvertAll; + Boolean modOverwriteExisting; + Boolean modAddAsDisk; + Boolean modPreserveType; + Boolean modPreserveTypeExtended; - const char* archiveFilename; - char* const* filespecPointer; - long filespecCount; + const char* archiveFilename; + char* const* filespecPointer; + long filespecCount; } NulibState; NuError NState_Init(NulibState** ppState); diff --git a/nulib2/SunOS4.h b/nulib2/SunOS4.h index 76161ea..22467d1 100644 --- a/nulib2/SunOS4.h +++ b/nulib2/SunOS4.h @@ -13,35 +13,35 @@ #define __SunOS4__ #ifdef __GNUC__ -extern int _flsbuf(int, FILE*); -extern int _filbuf(FILE*); +extern int _flsbuf(int, FILE*); +extern int _filbuf(FILE*); #endif -extern void bcopy(char*, char*, int); -extern int fclose(FILE*); -extern int fflush(FILE*); -extern int fprintf(FILE*, const char*, ...); -extern int fread(char*, int, int, FILE *); -extern int fseek(FILE*, long, int); -extern int ftruncate(int, off_t); -extern int fwrite(const char*, int, int, FILE*); -extern char* mktemp(char *template); -extern time_t mktime(struct tm*); -extern int perror(const char*); -extern int printf(const char*, ...); -extern int remove(const char*); -extern int rename(const char*, const char*); -extern int tolower(int); -extern int setvbuf(FILE*, char*, int, int); -extern int sscanf(char*, const char*, ...); -extern int strcasecmp(const char*, const char*); -extern int strncasecmp(const char*, const char*, size_t); -extern long strtol(const char *, char **, int); -extern int system(const char*); -extern time_t timelocal(struct tm*); -extern time_t time(time_t*); -extern int toupper(int); -extern int vfprintf(FILE*, const char *, va_list); -extern char* vsprintf(char *str, const char *format, va_list ap); +extern void bcopy(char*, char*, int); +extern int fclose(FILE*); +extern int fflush(FILE*); +extern int fprintf(FILE*, const char*, ...); +extern int fread(char*, int, int, FILE *); +extern int fseek(FILE*, long, int); +extern int ftruncate(int, off_t); +extern int fwrite(const char*, int, int, FILE*); +extern char* mktemp(char *template); +extern time_t mktime(struct tm*); +extern int perror(const char*); +extern int printf(const char*, ...); +extern int remove(const char*); +extern int rename(const char*, const char*); +extern int tolower(int); +extern int setvbuf(FILE*, char*, int, int); +extern int sscanf(char*, const char*, ...); +extern int strcasecmp(const char*, const char*); +extern int strncasecmp(const char*, const char*, size_t); +extern long strtol(const char *, char **, int); +extern int system(const char*); +extern time_t timelocal(struct tm*); +extern time_t time(time_t*); +extern int toupper(int); +extern int vfprintf(FILE*, const char *, va_list); +extern char* vsprintf(char *str, const char *format, va_list ap); #endif /*__SunOS4__*/ diff --git a/nulib2/SysDefs.h b/nulib2/SysDefs.h index 7228bd7..de166a1 100644 --- a/nulib2/SysDefs.h +++ b/nulib2/SysDefs.h @@ -93,16 +93,16 @@ #if defined(WINDOWS_LIKE) # ifndef F_OK -# define F_OK 02 +# define F_OK 02 # endif # ifndef R_OK -# define R_OK 04 +# define R_OK 04 # endif #endif #if defined(__unix__) || defined(__unix) || defined(__BEOS__) || \ - defined(__hpux) || defined(_AIX) || defined(__APPLE__) + defined(__hpux) || defined(_AIX) || defined(__APPLE__) # define UNIX_LIKE #endif @@ -190,7 +190,7 @@ # endif #endif -#ifdef __GNUC__ /* this was missing from BeOS __MWERKS__, and probably others */ +#ifdef __GNUC__ /* this was missing from BeOS __MWERKS__, and probably others */ # define HAS__FUNCTION__ #endif @@ -207,7 +207,7 @@ # define SYSTEM_DEFAULT_EOL "\n" #endif #ifndef MAX_PATH_LEN -# define MAX_PATH_LEN 1024 +# define MAX_PATH_LEN 1024 #endif #endif /*__SysDefs__*/ diff --git a/nulib2/SysUtils.c b/nulib2/SysUtils.c index 0381056..e5f6754 100644 --- a/nulib2/SysUtils.c +++ b/nulib2/SysUtils.c @@ -16,15 +16,15 @@ #if defined(UNIX_LIKE) # if defined(HAVE_DIRENT_H) # include -# define DIR_NAME_LEN(dirent) ((int)strlen((dirent)->d_name)) +# define DIR_NAME_LEN(dirent) ((int)strlen((dirent)->d_name)) typedef struct dirent DIR_TYPE; # elif defined(HAVE_SYS_DIR_H) # include -# define DIR_NAME_LEN(direct) ((direct)->d_namlen) +# define DIR_NAME_LEN(direct) ((direct)->d_namlen) typedef struct direct DIR_TYPE; # elif defined(HAVE_NDIR_H) # include -# define DIR_NAME_LEN(direct) ((direct)->d_namlen) +# define DIR_NAME_LEN(direct) ((direct)->d_namlen) typedef struct direct DIR_TYPE; # else # error "Port this?" @@ -35,32 +35,32 @@ * For systems (e.g. Visual C++ 6.0) that don't have these standard values. */ #ifndef S_IRUSR -# define S_IRUSR 0400 -# define S_IWUSR 0200 -# define S_IXUSR 0100 -# define S_IRWXU (S_IRUSR|S_IWUSR|S_IXUSR) -# define S_IRGRP (S_IRUSR >> 3) -# define S_IWGRP (S_IWUSR >> 3) -# define S_IXGRP (S_IXUSR >> 3) -# define S_IRWXG (S_IRWXU >> 3) -# define S_IROTH (S_IRGRP >> 3) -# define S_IWOTH (S_IWGRP >> 3) -# define S_IXOTH (S_IXGRP >> 3) -# define S_IRWXO (S_IRWXG >> 3) +# define S_IRUSR 0400 +# define S_IWUSR 0200 +# define S_IXUSR 0100 +# define S_IRWXU (S_IRUSR|S_IWUSR|S_IXUSR) +# define S_IRGRP (S_IRUSR >> 3) +# define S_IWGRP (S_IWUSR >> 3) +# define S_IXGRP (S_IXUSR >> 3) +# define S_IRWXG (S_IRWXU >> 3) +# define S_IROTH (S_IRGRP >> 3) +# define S_IWOTH (S_IWGRP >> 3) +# define S_IXOTH (S_IXGRP >> 3) +# define S_IRWXO (S_IRWXG >> 3) #endif #ifndef S_ISREG -# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) -# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +# define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +# define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) #endif /* * =========================================================================== - * System-specific filename stuff + * System-specific filename stuff * =========================================================================== */ -#define kTempFileNameLen 20 +#define kTempFileNameLen 20 #if defined(UNIX_LIKE) @@ -73,38 +73,38 @@ */ static NuError UNIXNormalizeFileName(NulibState* pState, const char* srcp, long srcLen, - char fssep, char** pDstp, long dstLen) + char fssep, char** pDstp, long dstLen) { - char* dstp = *pDstp; + char* dstp = *pDstp; - while (srcLen--) { /* don't go until null found! */ - assert(*srcp != '\0'); + while (srcLen--) { /* don't go until null found! */ + assert(*srcp != '\0'); - if (*srcp == '%') { - /* change '%' to "%%" */ - *dstp++ = *srcp; - *dstp++ = *srcp++; - } else if (*srcp == '/') { - /* change '/' to "%2f" */ - if (NState_GetModPreserveType(pState)) { - *dstp++ = kForeignIndic; - *dstp++ = HexConv(*srcp >> 4 & 0x0f); - *dstp++ = HexConv(*srcp & 0x0f); - } else { - *dstp++ = '_'; - } - srcp++; - } else { - /* no need to fiddle with it */ - *dstp++ = *srcp++; - } - } + if (*srcp == '%') { + /* change '%' to "%%" */ + *dstp++ = *srcp; + *dstp++ = *srcp++; + } else if (*srcp == '/') { + /* change '/' to "%2f" */ + if (NState_GetModPreserveType(pState)) { + *dstp++ = kForeignIndic; + *dstp++ = HexConv(*srcp >> 4 & 0x0f); + *dstp++ = HexConv(*srcp & 0x0f); + } else { + *dstp++ = '_'; + } + srcp++; + } else { + /* no need to fiddle with it */ + *dstp++ = *srcp++; + } + } - *dstp = '\0'; /* end the string, but don't advance past the null */ - assert(*pDstp - dstp <= dstLen); /* make sure we didn't overflow */ - *pDstp = dstp; + *dstp = '\0'; /* end the string, but don't advance past the null */ + assert(*pDstp - dstp <= dstLen); /* make sure we didn't overflow */ + *pDstp = dstp; - return kNuErrNone; + return kNuErrNone; } #elif defined(WINDOWS_LIKE) @@ -115,10 +115,10 @@ UNIXNormalizeFileName(NulibState* pState, const char* srcp, long srcLen, * The list comes from the Linux kernel's fs/msdos/namei.c. */ static const char* fatReservedNames3[] = { - "CON", "PRN", "NUL", "AUX", nil + "CON", "PRN", "NUL", "AUX", nil }; static const char* fatReservedNames4[] = { - "LPT1", "LPT2", "LPT3", "LPT4", "COM1", "COM2", "COM3", "COM4", nil + "LPT1", "LPT2", "LPT3", "LPT4", "COM1", "COM2", "COM3", "COM4", nil }; /* @@ -126,64 +126,64 @@ static const char* fatReservedNames4[] = { */ static NuError Win32NormalizeFileName(NulibState* pState, const char* srcp, long srcLen, - char fssep, char** pDstp, long dstLen) + char fssep, char** pDstp, long dstLen) { - char* dstp = *pDstp; - const char* startp = srcp; - static const char* kInvalid = "\\/:*?\"<>|"; + char* dstp = *pDstp; + const char* startp = srcp; + static const char* kInvalid = "\\/:*?\"<>|"; - /* look for an exact match */ - if (srcLen == 3) { - const char** ppcch; + /* look for an exact match */ + if (srcLen == 3) { + const char** ppcch; - for (ppcch = fatReservedNames3; *ppcch != nil; ppcch++) { - if (strncasecmp(srcp, *ppcch, srcLen) == 0) { - DBUG(("--- fixing '%s'\n", *ppcch)); - *dstp++ = '_'; - break; - } - } - } else if (srcLen == 4) { - const char** ppcch; + for (ppcch = fatReservedNames3; *ppcch != nil; ppcch++) { + if (strncasecmp(srcp, *ppcch, srcLen) == 0) { + DBUG(("--- fixing '%s'\n", *ppcch)); + *dstp++ = '_'; + break; + } + } + } else if (srcLen == 4) { + const char** ppcch; - for (ppcch = fatReservedNames4; *ppcch != nil; ppcch++) { - if (strncasecmp(srcp, *ppcch, srcLen) == 0) { - DBUG(("--- fixing '%s'\n", *ppcch)); - *dstp++ = '_'; - break; - } - } - } + for (ppcch = fatReservedNames4; *ppcch != nil; ppcch++) { + if (strncasecmp(srcp, *ppcch, srcLen) == 0) { + DBUG(("--- fixing '%s'\n", *ppcch)); + *dstp++ = '_'; + break; + } + } + } - while (srcLen--) { /* don't go until null found! */ - assert(*srcp != '\0'); + while (srcLen--) { /* don't go until null found! */ + assert(*srcp != '\0'); - if (*srcp == '%') { - /* change '%' to "%%" */ - *dstp++ = *srcp; - *dstp++ = *srcp++; - } else if (strchr(kInvalid, *srcp) != nil) { - /* change invalid char to "%2f" or '_' */ - if (NState_GetModPreserveType(pState)) { - *dstp++ = kForeignIndic; - *dstp++ = HexConv(*srcp >> 4 & 0x0f); - *dstp++ = HexConv(*srcp & 0x0f); - } else { - *dstp++ = '_'; - } - srcp++; - } else { - /* no need to fiddle with it */ - *dstp++ = *srcp++; - } - } + if (*srcp == '%') { + /* change '%' to "%%" */ + *dstp++ = *srcp; + *dstp++ = *srcp++; + } else if (strchr(kInvalid, *srcp) != nil) { + /* change invalid char to "%2f" or '_' */ + if (NState_GetModPreserveType(pState)) { + *dstp++ = kForeignIndic; + *dstp++ = HexConv(*srcp >> 4 & 0x0f); + *dstp++ = HexConv(*srcp & 0x0f); + } else { + *dstp++ = '_'; + } + srcp++; + } else { + /* no need to fiddle with it */ + *dstp++ = *srcp++; + } + } - *dstp = '\0'; /* end the string, but don't advance past the null */ - assert(*pDstp - dstp <= dstLen); /* make sure we didn't overflow */ - *pDstp = dstp; + *dstp = '\0'; /* end the string, but don't advance past the null */ + assert(*pDstp - dstp <= dstLen); /* make sure we didn't overflow */ + *pDstp = dstp; - return kNuErrNone; + return kNuErrNone; } #endif @@ -199,26 +199,26 @@ Win32NormalizeFileName(NulibState* pState, const char* srcp, long srcLen, */ NuError NormalizeFileName(NulibState* pState, const char* srcp, long srcLen, - char fssep, char** pDstp, long dstLen) + char fssep, char** pDstp, long dstLen) { - NuError err; + NuError err; - assert(srcp != nil); - assert(srcLen > 0); - assert(dstLen > srcLen); - assert(pDstp != nil); - assert(*pDstp != nil); - assert(fssep > ' ' && fssep < 0x7f); + assert(srcp != nil); + assert(srcLen > 0); + assert(dstLen > srcLen); + assert(pDstp != nil); + assert(*pDstp != nil); + assert(fssep > ' ' && fssep < 0x7f); #if defined(UNIX_LIKE) - err = UNIXNormalizeFileName(pState, srcp, srcLen, fssep, pDstp, dstLen); + err = UNIXNormalizeFileName(pState, srcp, srcLen, fssep, pDstp, dstLen); #elif defined(WINDOWS_LIKE) - err = Win32NormalizeFileName(pState, srcp, srcLen, fssep, pDstp, dstLen); + err = Win32NormalizeFileName(pState, srcp, srcLen, fssep, pDstp, dstLen); #else - #error "port this" + #error "port this" #endif - return err; + return err; } @@ -227,10 +227,10 @@ NormalizeFileName(NulibState* pState, const char* srcp, long srcLen, */ NuError NormalizeDirectoryName(NulibState* pState, const char* srcp, long srcLen, - char fssep, char** pDstp, long dstLen) + char fssep, char** pDstp, long dstLen) { - /* in general, directories and filenames are the same */ - return NormalizeFileName(pState, srcp, srcLen, fssep, pDstp, dstLen); + /* in general, directories and filenames are the same */ + return NormalizeFileName(pState, srcp, srcLen, fssep, pDstp, dstLen); } @@ -246,60 +246,60 @@ NormalizeDirectoryName(NulibState* pState, const char* srcp, long srcLen, char* MakeTempArchiveName(NulibState* pState) { - const char* archivePathname; - char fssep; - const char* nameStart; - char* newName = nil; - char* namePtr; - char* resultName = nil; - long len; + const char* archivePathname; + char fssep; + const char* nameStart; + char* newName = nil; + char* namePtr; + char* resultName = nil; + long len; - archivePathname = NState_GetArchiveFilename(pState); - assert(archivePathname != nil); - fssep = NState_GetSystemPathSeparator(pState); - assert(fssep != 0); + archivePathname = NState_GetArchiveFilename(pState); + assert(archivePathname != nil); + fssep = NState_GetSystemPathSeparator(pState); + assert(fssep != 0); - /* we'll get confused if the archive pathname looks like "/foo/bar/" */ - len = strlen(archivePathname); - if (len < 1) - goto bail; - if (archivePathname[len-1] == fssep) { - ReportError(kNuErrNone, "archive pathname can't end in '%c'", fssep); - goto bail; - } + /* we'll get confused if the archive pathname looks like "/foo/bar/" */ + len = strlen(archivePathname); + if (len < 1) + goto bail; + if (archivePathname[len-1] == fssep) { + ReportError(kNuErrNone, "archive pathname can't end in '%c'", fssep); + goto bail; + } - /* figure out where the filename ends */ - nameStart = strrchr(archivePathname, fssep); - if (nameStart == nil) { - /* nothing but a filename */ - newName = Malloc(kTempFileNameLen +1); - namePtr = newName; - } else { - nameStart++; /* advance past the fssep */ - newName = Malloc((nameStart - archivePathname) + kTempFileNameLen +1); - strcpy(newName, archivePathname); - namePtr = newName + (nameStart - archivePathname); - } - if (newName == nil) - goto bail; + /* figure out where the filename ends */ + nameStart = strrchr(archivePathname, fssep); + if (nameStart == nil) { + /* nothing but a filename */ + newName = Malloc(kTempFileNameLen +1); + namePtr = newName; + } else { + nameStart++; /* advance past the fssep */ + newName = Malloc((nameStart - archivePathname) + kTempFileNameLen +1); + strcpy(newName, archivePathname); + namePtr = newName + (nameStart - archivePathname); + } + if (newName == nil) + goto bail; - /* - * Create a new name with a mktemp-style template. - */ - strcpy(namePtr, "nulibtmpXXXXXX"); + /* + * Create a new name with a mktemp-style template. + */ + strcpy(namePtr, "nulibtmpXXXXXX"); - resultName = newName; + resultName = newName; bail: - if (resultName == nil) - Free(newName); - return resultName; + if (resultName == nil) + Free(newName); + return resultName; } /* * =========================================================================== - * Add a set of files + * Add a set of files * =========================================================================== */ @@ -333,42 +333,42 @@ bail: */ NuError CheckFileStatus(const char* pathname, struct stat* psb, Boolean* pExists, - Boolean* pIsReadable, Boolean* pIsDir) + Boolean* pIsReadable, Boolean* pIsDir) { - NuError err = kNuErrNone; - int cc; + NuError err = kNuErrNone; + int cc; - assert(pathname != nil); - assert(pExists != nil); - assert(pIsReadable != nil); - assert(pIsDir != nil); + assert(pathname != nil); + assert(pExists != nil); + assert(pIsReadable != nil); + assert(pIsDir != nil); - *pExists = true; - *pIsReadable = true; - *pIsDir = false; + *pExists = true; + *pIsReadable = true; + *pIsDir = false; - cc = stat(pathname, psb); - if (cc) { - if (errno == ENOENT) - *pExists = false; - else - err = kNuErrFileStat; - goto bail; - } + cc = stat(pathname, psb); + if (cc) { + if (errno == ENOENT) + *pExists = false; + else + err = kNuErrFileStat; + goto bail; + } - if (S_ISDIR(psb->st_mode)) - *pIsDir = true; + if (S_ISDIR(psb->st_mode)) + *pIsDir = true; - /* - * Test if we can read this file. How do we do that? The easy but slow - * way is to call access(2), the harder way is to figure out - * what user/group we are and compare the appropriate file mode. - */ - if (access(pathname, R_OK) < 0) - *pIsReadable = false; + /* + * Test if we can read this file. How do we do that? The easy but slow + * way is to call access(2), the harder way is to figure out + * what user/group we are and compare the appropriate file mode. + */ + if (access(pathname, R_OK) < 0) + *pIsReadable = false; bail: - return err; + return err; } #endif @@ -379,20 +379,20 @@ bail: static void UNIXTimeToDateTime(const time_t* pWhen, NuDateTime *pDateTime) { - struct tm* ptm; + struct tm* ptm; - Assert(pWhen != nil); - Assert(pDateTime != nil); + Assert(pWhen != nil); + Assert(pDateTime != nil); - ptm = localtime(pWhen); - pDateTime->second = ptm->tm_sec; - pDateTime->minute = ptm->tm_min; - pDateTime->hour = ptm->tm_hour; - pDateTime->day = ptm->tm_mday -1; - pDateTime->month = ptm->tm_mon; - pDateTime->year = ptm->tm_year; - pDateTime->extra = 0; - pDateTime->weekDay = ptm->tm_wday +1; + ptm = localtime(pWhen); + pDateTime->second = ptm->tm_sec; + pDateTime->minute = ptm->tm_min; + pDateTime->hour = ptm->tm_hour; + pDateTime->day = ptm->tm_mday -1; + pDateTime->month = ptm->tm_mon; + pDateTime->year = ptm->tm_year; + pDateTime->extra = 0; + pDateTime->weekDay = ptm->tm_wday +1; } #endif @@ -403,134 +403,134 @@ UNIXTimeToDateTime(const time_t* pWhen, NuDateTime *pDateTime) */ static NuError SetFileDetails(NulibState* pState, const char* pathname, struct stat* psb, - NuFileDetails* pDetails) + NuFileDetails* pDetails) { - Boolean wasPreserved; - Boolean doJunk = false; - char* livePathStr; - char slashDotDotSlash[5] = "_.._"; - time_t now; + Boolean wasPreserved; + Boolean doJunk = false; + char* livePathStr; + char slashDotDotSlash[5] = "_.._"; + time_t now; - assert(pState != nil); - assert(pathname != nil); - assert(pDetails != nil); + assert(pState != nil); + assert(pathname != nil); + assert(pDetails != nil); - /* set up the pathname buffer; note pDetails->storageName is const */ - NState_SetTempPathnameLen(pState, strlen(pathname) +1); - livePathStr = NState_GetTempPathnameBuf(pState); - assert(livePathStr != nil); - strcpy(livePathStr, pathname); + /* set up the pathname buffer; note pDetails->storageName is const */ + NState_SetTempPathnameLen(pState, strlen(pathname) +1); + livePathStr = NState_GetTempPathnameBuf(pState); + assert(livePathStr != nil); + strcpy(livePathStr, pathname); - /* init to defaults */ - memset(pDetails, 0, sizeof(*pDetails)); - pDetails->threadID = kNuThreadIDDataFork; - pDetails->storageName = livePathStr; /* point at temp buffer */ - pDetails->fileSysID = kNuFileSysUnknown; - pDetails->fileSysInfo = NState_GetSystemPathSeparator(pState); - pDetails->fileType = 0; - pDetails->extraType = 0; - pDetails->storageType = kNuStorageUnknown; /* let NufxLib worry about it */ - if (psb->st_mode & S_IWUSR) - pDetails->access = kNuAccessUnlocked; - else - pDetails->access = kNuAccessLocked; + /* init to defaults */ + memset(pDetails, 0, sizeof(*pDetails)); + pDetails->threadID = kNuThreadIDDataFork; + pDetails->storageName = livePathStr; /* point at temp buffer */ + pDetails->fileSysID = kNuFileSysUnknown; + pDetails->fileSysInfo = NState_GetSystemPathSeparator(pState); + pDetails->fileType = 0; + pDetails->extraType = 0; + pDetails->storageType = kNuStorageUnknown; /* let NufxLib worry about it */ + if (psb->st_mode & S_IWUSR) + pDetails->access = kNuAccessUnlocked; + else + pDetails->access = kNuAccessLocked; - /* if this is a disk image, fill in disk-specific fields */ - if (NState_GetModAddAsDisk(pState)) { - if ((psb->st_size & 0x1ff) != 0) { - /* reject anything whose size isn't a multiple of 512 bytes */ - printf("NOT storing odd-sized (%ld) file as disk image: %s\n", - (long)psb->st_size, livePathStr); - } else { - /* set fields; note the "preserve" stuff will override this */ - pDetails->threadID = kNuThreadIDDiskImage; - pDetails->storageType = 512; - pDetails->extraType = psb->st_size / 512; - } - } + /* if this is a disk image, fill in disk-specific fields */ + if (NState_GetModAddAsDisk(pState)) { + if ((psb->st_size & 0x1ff) != 0) { + /* reject anything whose size isn't a multiple of 512 bytes */ + printf("NOT storing odd-sized (%ld) file as disk image: %s\n", + (long)psb->st_size, livePathStr); + } else { + /* set fields; note the "preserve" stuff will override this */ + pDetails->threadID = kNuThreadIDDiskImage; + pDetails->storageType = 512; + pDetails->extraType = psb->st_size / 512; + } + } - now = time(nil); - UNIXTimeToDateTime(&now, &pDetails->archiveWhen); - UNIXTimeToDateTime(&psb->st_mtime, &pDetails->modWhen); - UNIXTimeToDateTime(&psb->st_mtime, &pDetails->createWhen); + now = time(nil); + UNIXTimeToDateTime(&now, &pDetails->archiveWhen); + UNIXTimeToDateTime(&psb->st_mtime, &pDetails->modWhen); + UNIXTimeToDateTime(&psb->st_mtime, &pDetails->createWhen); - /* - * Check for file type preservation info in the filename. If present, - * set the file type values and truncate the filename. - */ - wasPreserved = false; - if (NState_GetModPreserveType(pState)) { - wasPreserved = ExtractPreservationString(pState, livePathStr, - &pDetails->fileType, &pDetails->extraType, - &pDetails->threadID); - } + /* + * Check for file type preservation info in the filename. If present, + * set the file type values and truncate the filename. + */ + wasPreserved = false; + if (NState_GetModPreserveType(pState)) { + wasPreserved = ExtractPreservationString(pState, livePathStr, + &pDetails->fileType, &pDetails->extraType, + &pDetails->threadID); + } - /* - * Do a "denormalization" pass, where we convert invalid chars (such - * as '/') from percent-codes back to 8-bit characters. The filename - * will always be the same size or smaller, so we can do it in place. - */ - if (wasPreserved) - DenormalizePath(pState, livePathStr); + /* + * Do a "denormalization" pass, where we convert invalid chars (such + * as '/') from percent-codes back to 8-bit characters. The filename + * will always be the same size or smaller, so we can do it in place. + */ + if (wasPreserved) + DenormalizePath(pState, livePathStr); - /* - * If we're in "extended" mode, and the file wasn't preserved, take a - * guess at what the file type should be based on the file extension. - */ - if (!wasPreserved && NState_GetModPreserveTypeExtended(pState)) { - InterpretExtension(pState, livePathStr, &pDetails->fileType, - &pDetails->extraType); - } + /* + * If we're in "extended" mode, and the file wasn't preserved, take a + * guess at what the file type should be based on the file extension. + */ + if (!wasPreserved && NState_GetModPreserveTypeExtended(pState)) { + InterpretExtension(pState, livePathStr, &pDetails->fileType, + &pDetails->extraType); + } - /* - * Check for other unpleasantness, such as a leading fssep. - */ - assert(NState_GetSystemPathSeparator(pState) != '\0'); - while (livePathStr[0] == NState_GetSystemPathSeparator(pState)) { - /* slide it down, len is strlen +1 (for null) -1 (dropping first char)*/ - memmove(livePathStr, livePathStr+1, strlen(livePathStr)); - } + /* + * Check for other unpleasantness, such as a leading fssep. + */ + assert(NState_GetSystemPathSeparator(pState) != '\0'); + while (livePathStr[0] == NState_GetSystemPathSeparator(pState)) { + /* slide it down, len is strlen +1 (for null) -1 (dropping first char)*/ + memmove(livePathStr, livePathStr+1, strlen(livePathStr)); + } - /* - * Remove leading "./". - */ - while (livePathStr[0] == '.' && - livePathStr[1] == NState_GetSystemPathSeparator(pState)) - { - /* slide it down, len is strlen +1 (for null) -2 (dropping two chars) */ - memmove(livePathStr, livePathStr+2, strlen(livePathStr)-1); - } + /* + * Remove leading "./". + */ + while (livePathStr[0] == '.' && + livePathStr[1] == NState_GetSystemPathSeparator(pState)) + { + /* slide it down, len is strlen +1 (for null) -2 (dropping two chars) */ + memmove(livePathStr, livePathStr+2, strlen(livePathStr)-1); + } - /* - * If there's a "/../" present anywhere in the name, junk everything - * but the filename. - * - * This won't catch "foo/bar/..", but that should've been caught as - * a directory anyway. - */ - slashDotDotSlash[0] = NState_GetSystemPathSeparator(pState); - slashDotDotSlash[3] = NState_GetSystemPathSeparator(pState); - if ((livePathStr[0] == '.' && livePathStr[1] == '.') || - (strstr(livePathStr, slashDotDotSlash) != nil)) - { - DBUG(("Found dot dot in '%s', keeping only filename\n", livePathStr)); - doJunk = true; - } + /* + * If there's a "/../" present anywhere in the name, junk everything + * but the filename. + * + * This won't catch "foo/bar/..", but that should've been caught as + * a directory anyway. + */ + slashDotDotSlash[0] = NState_GetSystemPathSeparator(pState); + slashDotDotSlash[3] = NState_GetSystemPathSeparator(pState); + if ((livePathStr[0] == '.' && livePathStr[1] == '.') || + (strstr(livePathStr, slashDotDotSlash) != nil)) + { + DBUG(("Found dot dot in '%s', keeping only filename\n", livePathStr)); + doJunk = true; + } - /* - * If "junk paths" is set, drop everything before the last fssep char. - */ - if (NState_GetModJunkPaths(pState) || doJunk) { - char* lastFssep; - lastFssep = strrchr(livePathStr, NState_GetSystemPathSeparator(pState)); - if (lastFssep != nil) { - assert(*(lastFssep+1) != '\0'); /* should already have been caught*/ - memmove(livePathStr, lastFssep+1, strlen(lastFssep+1)+1); - } - } + /* + * If "junk paths" is set, drop everything before the last fssep char. + */ + if (NState_GetModJunkPaths(pState) || doJunk) { + char* lastFssep; + lastFssep = strrchr(livePathStr, NState_GetSystemPathSeparator(pState)); + if (lastFssep != nil) { + assert(*(lastFssep+1) != '\0'); /* should already have been caught*/ + memmove(livePathStr, lastFssep+1, strlen(lastFssep+1)+1); + } + } /*bail:*/ - return kNuErrNone; + return kNuErrNone; } #endif @@ -541,84 +541,84 @@ SetFileDetails(NulibState* pState, const char* pathname, struct stat* psb, */ NuError DoAddFile(NulibState* pState, NuArchive* pArchive, const char* pathname, - const NuFileDetails* pDetails) + const NuFileDetails* pDetails) { - NuError err; - NuRecordIdx recordIdx = 0; + NuError err; + NuRecordIdx recordIdx = 0; - err = NuAddFile(pArchive, pathname, pDetails, false, &recordIdx); + err = NuAddFile(pArchive, pathname, pDetails, false, &recordIdx); - if (err == kNuErrNone) { - NState_IncMatchCount(pState); - } else if (err == kNuErrSkipped) { - /* "maybe overwrite" UI causes this if user declines */ - err = kNuErrNone; - goto bail; - } else if (err == kNuErrNotNewer) { - /* if we were expecting this, it's okay */ - if (NState_GetModFreshen(pState) || NState_GetModUpdate(pState)) { - printf("SKIP older file: %s\n", pathname); - err = kNuErrNone; - goto bail; - } - } else if (err == kNuErrDuplicateNotFound) { - /* if we were expecting this, it's okay */ - if (NState_GetModFreshen(pState)) { - printf("SKIP file not in archive: %s\n", pathname); - err = kNuErrNone; - goto bail; - } - } else if (err == kNuErrRecordExists) { - printf("FAIL same filename added twice: '%s'\n", - NState_GetTempPathnameBuf(pState)); - goto bail_quiet; - } - if (err != kNuErrNone) - goto bail; + if (err == kNuErrNone) { + NState_IncMatchCount(pState); + } else if (err == kNuErrSkipped) { + /* "maybe overwrite" UI causes this if user declines */ + err = kNuErrNone; + goto bail; + } else if (err == kNuErrNotNewer) { + /* if we were expecting this, it's okay */ + if (NState_GetModFreshen(pState) || NState_GetModUpdate(pState)) { + printf("SKIP older file: %s\n", pathname); + err = kNuErrNone; + goto bail; + } + } else if (err == kNuErrDuplicateNotFound) { + /* if we were expecting this, it's okay */ + if (NState_GetModFreshen(pState)) { + printf("SKIP file not in archive: %s\n", pathname); + err = kNuErrNone; + goto bail; + } + } else if (err == kNuErrRecordExists) { + printf("FAIL same filename added twice: '%s'\n", + NState_GetTempPathnameBuf(pState)); + goto bail_quiet; + } + if (err != kNuErrNone) + goto bail; - /* add a one-line comment if requested */ - if (NState_GetModComments(pState)) { - char* comment; + /* add a one-line comment if requested */ + if (NState_GetModComments(pState)) { + char* comment; - DBUG(("Preparing comment for recordIdx=%ld\n", recordIdx)); - assert(recordIdx != 0); - comment = GetSimpleComment(pState, pathname, kDefaultCommentLen); - if (comment != nil) { - NuDataSource* pDataSource; + DBUG(("Preparing comment for recordIdx=%ld\n", recordIdx)); + assert(recordIdx != 0); + comment = GetSimpleComment(pState, pathname, kDefaultCommentLen); + if (comment != nil) { + NuDataSource* pDataSource; - err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed, - true, kDefaultCommentLen, (unsigned char*)comment, 0, - strlen(comment), &pDataSource); - if (err != kNuErrNone) { - ReportError(err, "comment buffer create failed"); - Free(comment); - err = kNuErrNone; /* oh well */ - } else { - comment = nil; /* now owned by the data source */ - err = NuAddThread(pArchive, recordIdx, kNuThreadIDComment, - pDataSource, nil); - if (err != kNuErrNone) { - ReportError(err, "comment thread add failed"); - NuFreeDataSource(pDataSource); - err = kNuErrNone; /* oh well */ - } else { - pDataSource = nil; /* now owned by NufxLib */ - } - } - } - } + err = NuCreateDataSourceForBuffer(kNuThreadFormatUncompressed, + true, kDefaultCommentLen, (unsigned char*)comment, 0, + strlen(comment), &pDataSource); + if (err != kNuErrNone) { + ReportError(err, "comment buffer create failed"); + Free(comment); + err = kNuErrNone; /* oh well */ + } else { + comment = nil; /* now owned by the data source */ + err = NuAddThread(pArchive, recordIdx, kNuThreadIDComment, + pDataSource, nil); + if (err != kNuErrNone) { + ReportError(err, "comment thread add failed"); + NuFreeDataSource(pDataSource); + err = kNuErrNone; /* oh well */ + } else { + pDataSource = nil; /* now owned by NufxLib */ + } + } + } + } bail: - if (err != kNuErrNone) - ReportError(err, "Unable to add file"); + if (err != kNuErrNone) + ReportError(err, "Unable to add file"); bail_quiet: - return err; + return err; } #if defined(UNIX_LIKE) static NuError UNIXAddFile(NulibState* pState, NuArchive* pArchive, - const char* pathname); + const char* pathname); /* * UNIX-style recursive directory descent. Scan the contents of a directory. @@ -628,60 +628,60 @@ static NuError UNIXAddFile(NulibState* pState, NuArchive* pArchive, static NuError UNIXAddDirectory(NulibState* pState, NuArchive* pArchive, const char* dirName) { - NuError err = kNuErrNone; - DIR* dirp = nil; - DIR_TYPE* entry; - char nbuf[MAX_PATH_LEN]; /* malloc might be better; this soaks stack */ - char fssep; - int len; + NuError err = kNuErrNone; + DIR* dirp = nil; + DIR_TYPE* entry; + char nbuf[MAX_PATH_LEN]; /* malloc might be better; this soaks stack */ + char fssep; + int len; - assert(pState != nil); - assert(pArchive != nil); - assert(dirName != nil); + assert(pState != nil); + assert(pArchive != nil); + assert(dirName != nil); - DBUG(("+++ DESCEND: '%s'\n", dirName)); + DBUG(("+++ DESCEND: '%s'\n", dirName)); - dirp = opendir(dirName); - if (dirp == nil) { - if (errno == ENOTDIR) - err = kNuErrNotDir; - else - err = errno ? errno : kNuErrOpenDir; - ReportError(err, "failed on '%s'", dirName); - goto bail; - } + dirp = opendir(dirName); + if (dirp == nil) { + if (errno == ENOTDIR) + err = kNuErrNotDir; + else + err = errno ? errno : kNuErrOpenDir; + ReportError(err, "failed on '%s'", dirName); + goto bail; + } - fssep = NState_GetSystemPathSeparator(pState); + fssep = NState_GetSystemPathSeparator(pState); - /* could use readdir_r, but we don't care about reentrancy here */ - while ((entry = readdir(dirp)) != nil) { - /* skip the dotsies */ - if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) - continue; + /* could use readdir_r, but we don't care about reentrancy here */ + while ((entry = readdir(dirp)) != nil) { + /* skip the dotsies */ + if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) + continue; - len = strlen(dirName); - if (len + DIR_NAME_LEN(entry) +2 > MAX_PATH_LEN) { - err = kNuErrInternal; - ReportError(err, "Filename exceeds %d bytes: %s%c%s", - MAX_PATH_LEN, dirName, fssep, entry->d_name); - goto bail; - } + len = strlen(dirName); + if (len + DIR_NAME_LEN(entry) +2 > MAX_PATH_LEN) { + err = kNuErrInternal; + ReportError(err, "Filename exceeds %d bytes: %s%c%s", + MAX_PATH_LEN, dirName, fssep, entry->d_name); + goto bail; + } - /* form the new name, inserting an fssep if needed */ - strcpy(nbuf, dirName); - if (dirName[len-1] != fssep) - nbuf[len++] = fssep; - strcpy(nbuf+len, entry->d_name); + /* form the new name, inserting an fssep if needed */ + strcpy(nbuf, dirName); + if (dirName[len-1] != fssep) + nbuf[len++] = fssep; + strcpy(nbuf+len, entry->d_name); - err = UNIXAddFile(pState, pArchive, nbuf); - if (err != kNuErrNone) - goto bail; - } + err = UNIXAddFile(pState, pArchive, nbuf); + if (err != kNuErrNone) + goto bail; + } bail: - if (dirp != nil) - (void)closedir(dirp); - return err; + if (dirp != nil) + (void)closedir(dirp); + return err; } /* @@ -696,57 +696,57 @@ bail: static NuError UNIXAddFile(NulibState* pState, NuArchive* pArchive, const char* pathname) { - NuError err = kNuErrNone; - Boolean exists, isDir, isReadable; - NuFileDetails details; - struct stat sb; + NuError err = kNuErrNone; + Boolean exists, isDir, isReadable; + NuFileDetails details; + struct stat sb; - assert(pState != nil); - assert(pArchive != nil); - assert(pathname != nil); + assert(pState != nil); + assert(pArchive != nil); + assert(pathname != nil); - err = CheckFileStatus(pathname, &sb, &exists, &isReadable, &isDir); - if (err != kNuErrNone) { - ReportError(err, "unexpected error while examining '%s'", pathname); - goto bail; - } + err = CheckFileStatus(pathname, &sb, &exists, &isReadable, &isDir); + if (err != kNuErrNone) { + ReportError(err, "unexpected error while examining '%s'", pathname); + goto bail; + } - if (!exists) { - err = kNuErrFileNotFound; - ReportError(err, "couldn't find '%s'", pathname); - goto bail; - } - if (!isReadable) { - ReportError(kNuErrNone, "file '%s' isn't readable", pathname); - err = kNuErrFileNotReadable; - goto bail; - } - if (isDir) { - if (NState_GetModRecurse(pState)) - err = UNIXAddDirectory(pState, pArchive, pathname); - goto bail_quiet; - } + if (!exists) { + err = kNuErrFileNotFound; + ReportError(err, "couldn't find '%s'", pathname); + goto bail; + } + if (!isReadable) { + ReportError(kNuErrNone, "file '%s' isn't readable", pathname); + err = kNuErrFileNotReadable; + goto bail; + } + if (isDir) { + if (NState_GetModRecurse(pState)) + err = UNIXAddDirectory(pState, pArchive, pathname); + goto bail_quiet; + } - /* - * We've found a file that we want to add. We need to decide what - * filetype and auxtype it has, and whether or not it's actually the - * resource fork of another file. - */ - DBUG(("+++ ADD '%s'\n", pathname)); + /* + * We've found a file that we want to add. We need to decide what + * filetype and auxtype it has, and whether or not it's actually the + * resource fork of another file. + */ + DBUG(("+++ ADD '%s'\n", pathname)); - err = SetFileDetails(pState, pathname, &sb, &details); - if (err != kNuErrNone) - goto bail; + err = SetFileDetails(pState, pathname, &sb, &details); + if (err != kNuErrNone) + goto bail; - err = DoAddFile(pState, pArchive, pathname, &details); - if (err != kNuErrNone) - goto bail_quiet; + err = DoAddFile(pState, pArchive, pathname, &details); + if (err != kNuErrNone) + goto bail_quiet; bail: - if (err != kNuErrNone) - ReportError(err, "Unable to add file"); + if (err != kNuErrNone) + ReportError(err, "Unable to add file"); bail_quiet: - return err; + return err; } #elif defined(WINDOWS_LIKE) @@ -755,10 +755,10 @@ bail_quiet: * Directory structure and functions, based on zDIR in Info-Zip sources. */ typedef struct Win32dirent { - char d_attr; - char d_name[MAX_PATH_LEN]; - int d_first; - HANDLE d_hFindFile; + char d_attr; + char d_name[MAX_PATH_LEN]; + int d_first; + HANDLE d_hFindFile; } Win32dirent; static const char* kWildMatchAll = "*.*"; @@ -769,44 +769,44 @@ static const char* kWildMatchAll = "*.*"; static Win32dirent* OpenDir(const char* name) { - Win32dirent* dir = nil; - char* tmpStr = nil; - char* cp; - WIN32_FIND_DATA fnd; + Win32dirent* dir = nil; + char* tmpStr = nil; + char* cp; + WIN32_FIND_DATA fnd; - dir = Malloc(sizeof(*dir)); - tmpStr = Malloc(strlen(name) + (2 + sizeof(kWildMatchAll))); - if (dir == nil || tmpStr == nil) - goto failed; + dir = Malloc(sizeof(*dir)); + tmpStr = Malloc(strlen(name) + (2 + sizeof(kWildMatchAll))); + if (dir == nil || tmpStr == nil) + goto failed; - strcpy(tmpStr, name); - cp = tmpStr + strlen(tmpStr); + strcpy(tmpStr, name); + cp = tmpStr + strlen(tmpStr); - /* don't end in a colon (e.g. "C:") */ - if ((cp - tmpStr) > 0 && strrchr(tmpStr, ':') == (cp - 1)) - *cp++ = '.'; - /* must end in a slash */ - if ((cp - tmpStr) > 0 && strrchr(tmpStr, PATH_SEP) != (cp - 1)) - *cp++ = PATH_SEP; + /* don't end in a colon (e.g. "C:") */ + if ((cp - tmpStr) > 0 && strrchr(tmpStr, ':') == (cp - 1)) + *cp++ = '.'; + /* must end in a slash */ + if ((cp - tmpStr) > 0 && strrchr(tmpStr, PATH_SEP) != (cp - 1)) + *cp++ = PATH_SEP; - strcpy(cp, kWildMatchAll); + strcpy(cp, kWildMatchAll); - dir->d_hFindFile = FindFirstFile(tmpStr, &fnd); - if (dir->d_hFindFile == INVALID_HANDLE_VALUE) - goto failed; + dir->d_hFindFile = FindFirstFile(tmpStr, &fnd); + if (dir->d_hFindFile == INVALID_HANDLE_VALUE) + goto failed; - strcpy(dir->d_name, fnd.cFileName); - dir->d_attr = (uchar) fnd.dwFileAttributes; - dir->d_first = 1; + strcpy(dir->d_name, fnd.cFileName); + dir->d_attr = (uchar) fnd.dwFileAttributes; + dir->d_first = 1; bail: - Free(tmpStr); - return dir; + Free(tmpStr); + return dir; failed: - Free(dir); - dir = nil; - goto bail; + Free(dir); + dir = nil; + goto bail; } /* @@ -817,18 +817,18 @@ failed: static Win32dirent* ReadDir(Win32dirent* dir) { - if (dir->d_first) - dir->d_first = 0; - else { - WIN32_FIND_DATA fnd; + if (dir->d_first) + dir->d_first = 0; + else { + WIN32_FIND_DATA fnd; - if (!FindNextFile(dir->d_hFindFile, &fnd)) - return nil; - strcpy(dir->d_name, fnd.cFileName); - dir->d_attr = (uchar) fnd.dwFileAttributes; - } + if (!FindNextFile(dir->d_hFindFile, &fnd)) + return nil; + strcpy(dir->d_name, fnd.cFileName); + dir->d_attr = (uchar) fnd.dwFileAttributes; + } - return dir; + return dir; } /* @@ -837,19 +837,19 @@ ReadDir(Win32dirent* dir) static void CloseDir(Win32dirent* dir) { - if (dir == nil) - return; + if (dir == nil) + return; - FindClose(dir->d_hFindFile); - Free(dir); + FindClose(dir->d_hFindFile); + Free(dir); } /* might as well blend in with the UNIX version */ -#define DIR_NAME_LEN(dirent) ((int)strlen((dirent)->d_name)) +#define DIR_NAME_LEN(dirent) ((int)strlen((dirent)->d_name)) static NuError Win32AddFile(NulibState* pState, NuArchive* pArchive, - const char* pathname); + const char* pathname); /* @@ -860,60 +860,60 @@ static NuError Win32AddFile(NulibState* pState, NuArchive* pArchive, static NuError Win32AddDirectory(NulibState* pState, NuArchive* pArchive, const char* dirName) { - NuError err = kNuErrNone; - Win32dirent* dirp = nil; - Win32dirent* entry; - char nbuf[MAX_PATH_LEN]; /* malloc might be better; this soaks stack */ - char fssep; - int len; + NuError err = kNuErrNone; + Win32dirent* dirp = nil; + Win32dirent* entry; + char nbuf[MAX_PATH_LEN]; /* malloc might be better; this soaks stack */ + char fssep; + int len; - assert(pState != nil); - assert(pArchive != nil); - assert(dirName != nil); + assert(pState != nil); + assert(pArchive != nil); + assert(dirName != nil); - DBUG(("+++ DESCEND: '%s'\n", dirName)); + DBUG(("+++ DESCEND: '%s'\n", dirName)); - dirp = OpenDir(dirName); - if (dirp == nil) { - if (errno == ENOTDIR) - err = kNuErrNotDir; - else - err = errno ? errno : kNuErrOpenDir; - ReportError(err, "failed on '%s'", dirName); - goto bail; - } + dirp = OpenDir(dirName); + if (dirp == nil) { + if (errno == ENOTDIR) + err = kNuErrNotDir; + else + err = errno ? errno : kNuErrOpenDir; + ReportError(err, "failed on '%s'", dirName); + goto bail; + } - fssep = NState_GetSystemPathSeparator(pState); + fssep = NState_GetSystemPathSeparator(pState); - /* could use readdir_r, but we don't care about reentrancy here */ - while ((entry = ReadDir(dirp)) != nil) { - /* skip the dotsies */ - if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) - continue; + /* could use readdir_r, but we don't care about reentrancy here */ + while ((entry = ReadDir(dirp)) != nil) { + /* skip the dotsies */ + if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) + continue; - len = strlen(dirName); - if (len + DIR_NAME_LEN(entry) +2 > MAX_PATH_LEN) { - err = kNuErrInternal; - ReportError(err, "Filename exceeds %d bytes: %s%c%s", - MAX_PATH_LEN, dirName, fssep, entry->d_name); - goto bail; - } + len = strlen(dirName); + if (len + DIR_NAME_LEN(entry) +2 > MAX_PATH_LEN) { + err = kNuErrInternal; + ReportError(err, "Filename exceeds %d bytes: %s%c%s", + MAX_PATH_LEN, dirName, fssep, entry->d_name); + goto bail; + } - /* form the new name, inserting an fssep if needed */ - strcpy(nbuf, dirName); - if (dirName[len-1] != fssep) - nbuf[len++] = fssep; - strcpy(nbuf+len, entry->d_name); + /* form the new name, inserting an fssep if needed */ + strcpy(nbuf, dirName); + if (dirName[len-1] != fssep) + nbuf[len++] = fssep; + strcpy(nbuf+len, entry->d_name); - err = Win32AddFile(pState, pArchive, nbuf); - if (err != kNuErrNone) - goto bail; - } + err = Win32AddFile(pState, pArchive, nbuf); + if (err != kNuErrNone) + goto bail; + } bail: - if (dirp != nil) - (void)CloseDir(dirp); - return err; + if (dirp != nil) + (void)CloseDir(dirp); + return err; } /* @@ -927,57 +927,57 @@ bail: static NuError Win32AddFile(NulibState* pState, NuArchive* pArchive, const char* pathname) { - NuError err = kNuErrNone; - Boolean exists, isDir, isReadable; - NuFileDetails details; - struct stat sb; + NuError err = kNuErrNone; + Boolean exists, isDir, isReadable; + NuFileDetails details; + struct stat sb; - assert(pState != nil); - assert(pArchive != nil); - assert(pathname != nil); + assert(pState != nil); + assert(pArchive != nil); + assert(pathname != nil); - err = CheckFileStatus(pathname, &sb, &exists, &isReadable, &isDir); - if (err != kNuErrNone) { - ReportError(err, "unexpected error while examining '%s'", pathname); - goto bail; - } + err = CheckFileStatus(pathname, &sb, &exists, &isReadable, &isDir); + if (err != kNuErrNone) { + ReportError(err, "unexpected error while examining '%s'", pathname); + goto bail; + } - if (!exists) { - err = kNuErrFileNotFound; - ReportError(err, "couldn't find '%s'", pathname); - goto bail; - } - if (!isReadable) { - ReportError(kNuErrNone, "file '%s' isn't readable", pathname); - err = kNuErrFileNotReadable; - goto bail; - } - if (isDir) { - if (NState_GetModRecurse(pState)) - err = Win32AddDirectory(pState, pArchive, pathname); - goto bail_quiet; - } + if (!exists) { + err = kNuErrFileNotFound; + ReportError(err, "couldn't find '%s'", pathname); + goto bail; + } + if (!isReadable) { + ReportError(kNuErrNone, "file '%s' isn't readable", pathname); + err = kNuErrFileNotReadable; + goto bail; + } + if (isDir) { + if (NState_GetModRecurse(pState)) + err = Win32AddDirectory(pState, pArchive, pathname); + goto bail_quiet; + } - /* - * We've found a file that we want to add. We need to decide what - * filetype and auxtype it has, and whether or not it's actually the - * resource fork of another file. - */ - DBUG(("+++ ADD '%s'\n", pathname)); + /* + * We've found a file that we want to add. We need to decide what + * filetype and auxtype it has, and whether or not it's actually the + * resource fork of another file. + */ + DBUG(("+++ ADD '%s'\n", pathname)); - err = SetFileDetails(pState, pathname, &sb, &details); - if (err != kNuErrNone) - goto bail; + err = SetFileDetails(pState, pathname, &sb, &details); + if (err != kNuErrNone) + goto bail; - err = DoAddFile(pState, pArchive, pathname, &details); - if (err != kNuErrNone) - goto bail_quiet; + err = DoAddFile(pState, pArchive, pathname, &details); + if (err != kNuErrNone) + goto bail_quiet; bail: - if (err != kNuErrNone) - ReportError(err, "Unable to add file"); + if (err != kNuErrNone) + ReportError(err, "Unable to add file"); bail_quiet: - return err; + return err; } #else @@ -999,11 +999,11 @@ NuError AddFile(NulibState* pState, NuArchive* pArchive, const char* pathname) { #if defined(UNIX_LIKE) - return UNIXAddFile(pState, pArchive, pathname); + return UNIXAddFile(pState, pArchive, pathname); #elif defined(WINDOWS_LIKE) - return Win32AddFile(pState, pArchive, pathname); + return Win32AddFile(pState, pArchive, pathname); #else - #error "Port this" + #error "Port this" #endif } diff --git a/nulib2/configure.in b/nulib2/configure.in index 0c077fb..37973f3 100644 --- a/nulib2/configure.in +++ b/nulib2/configure.in @@ -15,7 +15,7 @@ dnl Checks for header files. AC_HEADER_DIRENT AC_HEADER_STDC AC_CHECK_HEADERS(fcntl.h limits.h malloc.h stdlib.h strings.h sys/stat.h \ - sys/time.h sys/types.h unistd.h) + sys/time.h sys/types.h unistd.h) dnl Checks for typedefs, structures, and compiler characteristics. AC_C_CONST @@ -37,50 +37,50 @@ dnl BeOS doesn't like /usr/local/include, and gets feisty about it. If libdir dnl and includedir are set to defaults, replace them with BeOS values. This dnl might be going a little too far... if test "$host_os" = "beos"; then - if test "$prefix" = "NONE" -a \ - "$includedir" = '${prefix}/include' -a \ - "$libdir" = '${exec_prefix}/lib' -a \ - "$bindir" = '${exec_prefix}/bin' -a \ - "$mandir" = '${prefix}/man' - then - echo replacing install locations with BeOS values - prefix=/boot - includedir='${prefix}/develop/headers' - libdir='${exec_prefix}/home/config/lib' - bindir='${exec_prefix}/home/config/bin' - mandir='/tmp' - AC_SUBST(prefix) - AC_SUBST(includedir) - AC_SUBST(libdir) - AC_SUBST(bindir) - AC_SUBST(mandir) - fi + if test "$prefix" = "NONE" -a \ + "$includedir" = '${prefix}/include' -a \ + "$libdir" = '${exec_prefix}/lib' -a \ + "$bindir" = '${exec_prefix}/bin' -a \ + "$mandir" = '${prefix}/man' + then + echo replacing install locations with BeOS values + prefix=/boot + includedir='${prefix}/develop/headers' + libdir='${exec_prefix}/home/config/lib' + bindir='${exec_prefix}/home/config/bin' + mandir='/tmp' + AC_SUBST(prefix) + AC_SUBST(includedir) + AC_SUBST(libdir) + AC_SUBST(bindir) + AC_SUBST(mandir) + fi fi dnl Figure out what the build and link flags should be if test "$host_cpu" = "powerpc" -a "$host_os" = "beos"; then - dnl BeOS/PPC with Metrowerks compiler - CC=cc - GCC= - CFLAGS='-proc 603 -opt full' - echo "forcing CC to \"$CC\" and CFLAGS to \"$CFLAGS\"" + dnl BeOS/PPC with Metrowerks compiler + CC=cc + GCC= + CFLAGS='-proc 603 -opt full' + echo "forcing CC to \"$CC\" and CFLAGS to \"$CFLAGS\"" fi dnl if we're using gcc, include gcc-specific warning flags dnl ( if test -z "$GCC"; then - BUILD_FLAGS='$(OPT)' + BUILD_FLAGS='$(OPT)' else - BUILD_FLAGS='$(OPT) $(GCC_FLAGS)' + BUILD_FLAGS='$(OPT) $(GCC_FLAGS)' fi AC_SUBST(BUILD_FLAGS) DMALLOC= AC_ARG_ENABLE(dmalloc, [ --enable-dmalloc: do dmalloc stuff], \ - [ echo "--- enabling dmalloc"; - DMALLOC="-L/usr/local/lib -ldmalloc"; AC_DEFINE(USE_DMALLOC) ]) + [ echo "--- enabling dmalloc"; + DMALLOC="-L/usr/local/lib -ldmalloc"; AC_DEFINE(USE_DMALLOC) ]) AC_SUBST(DMALLOC) AC_OUTPUT(Makefile)