Minor fixes

- Drop strcasecmp / strncasecmp defines; just use the VC++ version.
- Fix LOG_WARNING vs. LOG_WARN.
- Fix crash when NiftyList data file not available.
This commit is contained in:
Andy McFadden 2014-11-18 17:10:23 -08:00
parent af429c8bb9
commit f8017fdee3
13 changed files with 28 additions and 26 deletions

View File

@ -538,7 +538,7 @@ BnyArchive::LoadContentsCallback(BnyFileEntry* pEntry)
if (isSqueezed && strlen(fileName) > 3) { if (isSqueezed && strlen(fileName) > 3) {
char* ext; char* ext;
ext = fileName + strlen(fileName) -3; ext = fileName + strlen(fileName) -3;
if (strcasecmp(ext, ".qq") == 0) if (stricmp(ext, ".qq") == 0)
*ext = '\0'; *ext = '\0';
} }

View File

@ -63,7 +63,7 @@ BASTokenLookup::Lookup(const char* str, int len, int* pFoundLen)
longestIndex = longestLen = -1; longestIndex = longestLen = -1;
for (i = 0; i < fNumTokens; i++) { for (i = 0; i < fNumTokens; i++) {
if (fTokenLen[i] <= len && fTokenLen[i] > longestLen && if (fTokenLen[i] <= len && fTokenLen[i] > longestLen &&
strncasecmp(str, fTokenPtr[i], fTokenLen[i]) == 0) strnicmp(str, fTokenPtr[i], fTokenLen[i]) == 0)
{ {
longestIndex = i; longestIndex = i;
longestLen = fTokenLen[i]; longestLen = fTokenLen[i];

View File

@ -535,7 +535,7 @@ NufxArchive::NufxErrorMsgHandler(NuArchive* /*pArchive*/, void* vErrorMessage)
{ {
const NuErrorMessage* pErrorMessage = (const NuErrorMessage*) vErrorMessage; const NuErrorMessage* pErrorMessage = (const NuErrorMessage*) vErrorMessage;
LOG_BASE(pErrorMessage->isDebug ? DebugLog::LOG_DEBUG : DebugLog::LOG_WARNING, LOG_BASE(pErrorMessage->isDebug ? DebugLog::LOG_DEBUG : DebugLog::LOG_WARN,
pErrorMessage->file, pErrorMessage->line, "<nufxlib> %hs", pErrorMessage->file, pErrorMessage->line, "<nufxlib> %hs",
pErrorMessage->message); pErrorMessage->message);
@ -627,10 +627,11 @@ NufxArchive::Open(const WCHAR* filename, bool readOnly, CString* pErrMsg)
fIsReadOnly = false; fIsReadOnly = false;
CStringA tmpnameA(tmpname); CStringA tmpnameA(tmpname);
nerr = NuOpenRW(filenameA, tmpnameA, 0, &fpArchive); nerr = NuOpenRW(filenameA, tmpnameA, 0, &fpArchive);
}
if (nerr == kNuErrFileAccessDenied || nerr == EACCES) { if (nerr == kNuErrFileAccessDenied || nerr == EACCES) {
LOGI("Read-write failed with access denied, trying read-only"); LOGI("Read-write failed with access denied, trying read-only");
readOnly = true; readOnly = true;
}
} }
if (readOnly) { if (readOnly) {
LOGI("Opening file '%ls' ro", (LPCWSTR) filename); LOGI("Opening file '%ls' ro", (LPCWSTR) filename);

View File

@ -227,7 +227,7 @@ ReformatMerlin::Examine(ReformatHolder* pHolder)
{ {
if (pHolder->GetFileType() == kTypeTXT) { if (pHolder->GetFileType() == kTypeTXT) {
bool isAsm = ReformatMerlin::IsMerlin(pHolder); bool isAsm = ReformatMerlin::IsMerlin(pHolder);
bool isDotS = strcasecmp(pHolder->GetNameExt(), ".S") == 0; bool isDotS = stricmp(pHolder->GetNameExt(), ".S") == 0;
if (isAsm && isDotS) { if (isAsm && isDotS) {
/* gotta be */ /* gotta be */

View File

@ -73,7 +73,7 @@ ReformatCPMText::Examine(ReformatHolder* pHolder)
applies = ReformatHolder::kApplicProbablyNot; applies = ReformatHolder::kApplicProbablyNot;
/* allow, but don't default to, text conversion of ".com" files */ /* allow, but don't default to, text conversion of ".com" files */
if (strcasecmp(nameExt, ".com") == 0) { if (stricmp(nameExt, ".com") == 0) {
LOGI("Not reformatting '.com' file as text"); LOGI("Not reformatting '.com' file as text");
goto done; goto done;
} }

View File

@ -768,7 +768,7 @@ ReformatDisasm65xxx::ValidateOpCodeDetails(void)
/* O(n^2) duplicate string check */ /* O(n^2) duplicate string check */
for (int i = 0; i < NELEM(kOpCodeDetails)-1; i++) { for (int i = 0; i < NELEM(kOpCodeDetails)-1; i++) {
for (int j = i+1; j < NELEM(kOpCodeDetails); j++) { for (int j = i+1; j < NELEM(kOpCodeDetails); j++) {
if (strcasecmp(kOpCodeDetails[i].mnemonic, if (stricmp(kOpCodeDetails[i].mnemonic,
kOpCodeDetails[j].mnemonic) == 0) kOpCodeDetails[j].mnemonic) == 0)
{ {
LOGI("OpCodeDetails GLITCH: entries %d and %d match (%hs)", LOGI("OpCodeDetails GLITCH: entries %d and %d match (%hs)",

View File

@ -55,7 +55,7 @@ ReformatMacPaint::Examine(ReformatHolder* pHolder)
} }
version = Get32BE(ptr); version = Get32BE(ptr);
if (strcasecmp(nameExt, ".mac") == 0 && version >= 0 && version <= 3) { if (stricmp(nameExt, ".mac") == 0 && version >= 0 && version <= 3) {
LOGI(" MP: found w/o MacBinary header"); LOGI(" MP: found w/o MacBinary header");
applies = ReformatHolder::kApplicProbably; applies = ReformatHolder::kApplicProbably;
goto done; goto done;

View File

@ -338,17 +338,17 @@ NiftyList::DumpSection(const DataSet& dataSet)
{ {
long ent; long ent;
LOGI("Dumping section (count=%ld)", dataSet.numEntries); LOGD("Dumping section (count=%ld)", dataSet.numEntries);
for (ent = 0; ent < dataSet.numEntries; ent++) { for (ent = 0; ent < dataSet.numEntries; ent++) {
LOGI("%4d: %04x '%hs'", LOGD("%4d: %04x '%hs'",
ent, dataSet.pEntries[ent].value, dataSet.pEntries[ent].name); ent, dataSet.pEntries[ent].value, dataSet.pEntries[ent].name);
} }
} }
/* /*
* Look up a value in the specified table. Returns the name, or "NULL" if * Look up a value in the specified table. Returns the name, or NULL if
* not found. * not found.
* *
* This uses a binary search, so the entries must be in sorted order. * This uses a binary search, so the entries must be in sorted order.
@ -356,6 +356,9 @@ NiftyList::DumpSection(const DataSet& dataSet)
/*static*/ const char* /*static*/ const char*
NiftyList::Lookup(const DataSet& dataSet, unsigned short key) NiftyList::Lookup(const DataSet& dataSet, unsigned short key)
{ {
if (!fDataReady) {
return NULL;
}
assert(dataSet.numEntries > 0); assert(dataSet.numEntries > 0);
int high = dataSet.numEntries-1; int high = dataSet.numEntries-1;

View File

@ -42,7 +42,7 @@ ReformatMagicWindow::Examine(ReformatHolder* pHolder)
{ {
if (pHolder->GetFileType() == kTypeBIN) { if (pHolder->GetFileType() == kTypeBIN) {
bool isMW = ReformatMagicWindow::IsFormatted(pHolder); bool isMW = ReformatMagicWindow::IsFormatted(pHolder);
bool isDotMW = strcasecmp(pHolder->GetNameExt(), ".MW") == 0; bool isDotMW = stricmp(pHolder->GetNameExt(), ".MW") == 0;
if (isMW && isDotMW) { if (isMW && isDotMW) {
/* gotta be */ /* gotta be */

View File

@ -9,7 +9,7 @@
#ifndef UTIL_FADDENSTD_H #ifndef UTIL_FADDENSTD_H
#define UTIL_FADDENSTD_H #define UTIL_FADDENSTD_H
#define NELEM(x) ((int) (sizeof(x) / sizeof(x[0]))) #define NELEM(x) (sizeof(x) / sizeof(x[0]))
/* /*
* Declare copy construction and operator=. Put this in a private section * Declare copy construction and operator=. Put this in a private section
@ -19,8 +19,4 @@
_TYPE(const _TYPE&); \ _TYPE(const _TYPE&); \
_TYPE& operator= (const _TYPE&); _TYPE& operator= (const _TYPE&);
// Windows equivalents
#define strcasecmp stricmp
#define strncasecmp strnicmp
#endif /*UTIL_FADDENSTD_H*/ #endif /*UTIL_FADDENSTD_H*/

View File

@ -79,9 +79,11 @@ void DebugLog::Log(LogSeverity severity, const char* file, int line,
time_t now = time(NULL); time_t now = time(NULL);
localtime_s(&tmbuf, &now); localtime_s(&tmbuf, &now);
// also had %05u fPid before; not sure that's useful // The pid is useful when we spawn a new instance of CiderPress
fprintf(fLogFp, "%02d:%02d:%02d %c %s\n", tmbuf.tm_hour, // to handle a disk image or NuFX archive inside an archive. The
tmbuf.tm_min, tmbuf.tm_sec, kSeverityChars[severity], // file is opened in "append" mode, so we shouldn't collide.
fprintf(fLogFp, "%02d:%02d:%02d %05u %c %s\n", tmbuf.tm_hour,
tmbuf.tm_min, tmbuf.tm_sec, fPid, kSeverityChars[severity],
textBuf); textBuf);
} }
#ifdef _DEBUG #ifdef _DEBUG

View File

@ -31,7 +31,7 @@ public:
typedef enum { typedef enum {
LOG_UNKNOWN=0, LOG_VERBOSE=1, LOG_DEBUG=2, LOG_UNKNOWN=0, LOG_VERBOSE=1, LOG_DEBUG=2,
LOG_INFO=3, LOG_WARNING=4, LOG_ERROR=5 LOG_INFO=3, LOG_WARN=4, LOG_ERROR=5
} LogSeverity; } LogSeverity;
/* /*

View File

@ -519,14 +519,14 @@ GetPascalString(const char* buf, long maxLen, CString* pStr)
*pStr = ""; *pStr = "";
if (len > maxLen) { if (len > maxLen) {
LOGI("Invalid pascal string -- len=%d, maxLen=%d", len, maxLen); LOGW("Invalid pascal string -- len=%d, maxLen=%d", len, maxLen);
return -1; return -1;
} }
while (len--) { while (len--) {
if (*buf == '\0') { if (*buf == '\0') {
/* this suggests that we're not reading a pascal string */ /* this suggests that we're not reading a pascal string */
LOGI("Found pascal string with '\\0' in it"); LOGW("Found pascal string with '\\0' in it");
return -1; return -1;
} }