From 1286c3518ef22fca456fdc644c5c2c2c9f3234a3 Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Sat, 3 Jan 2015 11:24:12 -0800 Subject: [PATCH] Minor Mac fixes Eliminated the two inline functions. Support for function inlining in plain C is a bit uneven. The CRC calculation is now a macro, and the thread get-by-index is a plain function. --- nufxlib/ChangeLog.txt | 3 +++ nufxlib/Crc16.c | 1 - nufxlib/Entry.c | 1 - nufxlib/NufxLibPriv.h | 39 +++++++++------------------------------ nufxlib/README.txt | 10 +++------- nufxlib/Thread.c | 12 +++++++++++- nulib2/ChangeLog.txt | 3 +++ nulib2/State.c | 2 +- 8 files changed, 30 insertions(+), 41 deletions(-) diff --git a/nufxlib/ChangeLog.txt b/nufxlib/ChangeLog.txt index 7115fb1..1aa8d61 100644 --- a/nufxlib/ChangeLog.txt +++ b/nufxlib/ChangeLog.txt @@ -1,3 +1,6 @@ +2015/01/02 fadden + - Distinguish Unicode and Mac OS Roman strings. + 2014/12/22 fadden - Source code cleanup. diff --git a/nufxlib/Crc16.c b/nufxlib/Crc16.c index fd49b90..1f92397 100644 --- a/nufxlib/Crc16.c +++ b/nufxlib/Crc16.c @@ -7,7 +7,6 @@ * Compute 16-bit CRCs. Depending on the hardware, the table version * might be slower than the loop computation. */ -#define COMPILE_CRC16_C 1 #include "NufxLibPriv.h" #define CRC_TAB diff --git a/nufxlib/Entry.c b/nufxlib/Entry.c index 12a805c..e9f0fd3 100644 --- a/nufxlib/Entry.c +++ b/nufxlib/Entry.c @@ -48,7 +48,6 @@ static NuError Nu_PartiallyValidateNuArchive(const NuArchive* pArchive) if (pArchive == NULL) return kNuErrInvalidArg; - pArchive = pArchive; if (pArchive->structMagic != kNuArchiveStructMagic) return kNuErrBadStruct; diff --git a/nufxlib/NufxLibPriv.h b/nufxlib/NufxLibPriv.h index d1e449a..dd3df95 100644 --- a/nufxlib/NufxLibPriv.h +++ b/nufxlib/NufxLibPriv.h @@ -563,20 +563,15 @@ NuError Nu_CopyPresizedToArchive(NuArchive* pArchive, /* Crc16.c */ extern const uint16_t gNuCrc16Table[256]; uint16_t Nu_CalcCRC16(uint16_t seed, const uint8_t* ptr, int count); -#ifdef COMPILE_CRC16_C /* just doing "static inline" warns def-but-not-used */ - #define CRC_INLINE /**/ -#else - #define CRC_INLINE extern inline -#endif -#if defined(inline) && !defined(COMPILE_CRC16_C) /* somebody ovrd inline def? */ -uint16_t Nu_UpdateCRC16(uint8_t val, uint16_t crc); -#else -CRC_INLINE uint16_t -Nu_UpdateCRC16(uint8_t val, uint16_t crc) -{ - return (gNuCrc16Table[((crc >> 8) & 0xFF) ^ val] ^ (crc << 8)) & 0xFFFF; -} -#endif +/* + * Update the CRC-16. + * + * _val (uint8_t) is the byte to add to the CRC. It's evaluated once. + * _crc (uint16_t) is the previous CRC. It's evaluated twice. + * Returns the updated CRC as a uint16_t. + */ +#define Nu_UpdateCRC16(_val, _crc) \ + (gNuCrc16Table[(((_crc) >> 8) & 0xff) ^ (_val)] ^ ((_crc) << 8)) /* Debug.c */ #if defined(DEBUG_MSGS) || !defined(NDEBUG) @@ -822,23 +817,7 @@ NuError Nu_ExpandHuffmanSQ(NuArchive* pArchive, const NuRecord* pRecord, const NuThread* pThread, FILE* infp, NuFunnel* pFunnel, uint16_t* pCrc); /* Thread.c */ -#ifdef COMPILE_THREAD_C - #define THREAD_INLINE /**/ -#else - #define THREAD_INLINE extern inline -#endif -#if defined(inline) && !defined(COMPILE_THREAD_C) /*somebody ovrd inline def?*/ NuThread* Nu_GetThread(const NuRecord* pRecord, int idx); -#else -THREAD_INLINE NuThread* -Nu_GetThread(const NuRecord* pRecord, int idx) -{ - if (idx >= (int)pRecord->recTotalThreads) - return NULL; - else - return &pRecord->pThreads[idx]; -} -#endif void Nu_StripHiIfAllSet(char* str); Boolean Nu_IsPresizedThreadID(NuThreadID threadID); Boolean Nu_IsCompressibleThreadID(NuThreadID threadID); diff --git a/nufxlib/README.txt b/nufxlib/README.txt index 0b54194..3e246ee 100644 --- a/nufxlib/README.txt +++ b/nufxlib/README.txt @@ -64,14 +64,10 @@ If you're using BeOS/PPC, it will also do: Mac OS X ======== -This works just like the UNIX version, with the exception that when you link -against nufxlib, your project must also link against the Carbon framework. -This can be done in ProjectBuilder by using the Add Framework option in the -Project menu, or by adding "-framework Carbon" to the gcc command line. +This works just like the UNIX version, but includes support for resource +forks and Finder file/aux types. -You'll see some warnings due to some namespace collisions between nufxlib and -Carbon, but everything will work fine. Carbon is used to provide support for -file types and resource forks. +Tested with Xcode v5.1.1 and Mac OS 10.8.5. Win32 diff --git a/nufxlib/Thread.c b/nufxlib/Thread.c index efad155..d8e2683 100644 --- a/nufxlib/Thread.c +++ b/nufxlib/Thread.c @@ -6,7 +6,6 @@ * * Thread-level operations. */ -#define COMPILE_THREAD_C 1 #include "NufxLibPriv.h" @@ -16,6 +15,17 @@ * =========================================================================== */ +/* + * Returns thread N, or NULL if the index is invalid. + */ +NuThread* Nu_GetThread(const NuRecord* pRecord, int idx) +{ + if (idx >= (int)pRecord->recTotalThreads) + return NULL; + else + return &pRecord->pThreads[idx]; +} + /* * ShrinkIt v3.0.0 had a bug where the filename thread would get created * with the high bits set. We want to undo that without stomping on diff --git a/nulib2/ChangeLog.txt b/nulib2/ChangeLog.txt index 3248905..bd559cc 100644 --- a/nulib2/ChangeLog.txt +++ b/nulib2/ChangeLog.txt @@ -1,3 +1,6 @@ +2015/01/02 fadden + - Distinguish Unicode and Mac OS Roman strings. + 2014/12/22 fadden - Source code cleanup. diff --git a/nulib2/State.c b/nulib2/State.c index a64bf2f..ab5379c 100644 --- a/nulib2/State.c +++ b/nulib2/State.c @@ -9,7 +9,7 @@ #include "NuLib2.h" -static const char* gProgramVersion = "3.0.0"; +static const char* gProgramVersion = "3.0.0d2"; /*