2000-05-23 01:55:31 +00:00
|
|
|
/*
|
|
|
|
* NuFX archive manipulation library
|
|
|
|
* Copyright (C) 2000 by Andy McFadden, All Rights Reserved.
|
|
|
|
* This is free software; you can redistribute it and/or modify it under the
|
|
|
|
* terms of the GNU Library General Public License, see the file COPYING.LIB.
|
|
|
|
*
|
|
|
|
* Get/set certain values and attributes.
|
|
|
|
*/
|
|
|
|
#include "NufxLibPriv.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a configurable parameter.
|
|
|
|
*/
|
|
|
|
NuError
|
|
|
|
Nu_GetValue(NuArchive* pArchive, NuValueID ident, NuValue* pValue)
|
|
|
|
{
|
2002-09-21 00:49:42 +00:00
|
|
|
NuError err = kNuErrNone;
|
|
|
|
|
|
|
|
if (pValue == nil)
|
|
|
|
return kNuErrInvalidArg;
|
|
|
|
|
|
|
|
switch (ident) {
|
|
|
|
case kNuValueAllowDuplicates:
|
|
|
|
*pValue = pArchive->valAllowDuplicates;
|
|
|
|
break;
|
|
|
|
case kNuValueConvertExtractedEOL:
|
|
|
|
*pValue = pArchive->valConvertExtractedEOL;
|
|
|
|
break;
|
|
|
|
case kNuValueDataCompression:
|
|
|
|
*pValue = pArchive->valDataCompression;
|
|
|
|
break;
|
|
|
|
case kNuValueDiscardWrapper:
|
|
|
|
*pValue = pArchive->valDiscardWrapper;
|
|
|
|
break;
|
|
|
|
case kNuValueEOL:
|
|
|
|
*pValue = pArchive->valEOL;
|
|
|
|
break;
|
|
|
|
case kNuValueHandleExisting:
|
|
|
|
*pValue = pArchive->valHandleExisting;
|
|
|
|
break;
|
|
|
|
case kNuValueIgnoreCRC:
|
|
|
|
*pValue = pArchive->valIgnoreCRC;
|
|
|
|
break;
|
|
|
|
case kNuValueMimicSHK:
|
|
|
|
*pValue = pArchive->valMimicSHK;
|
|
|
|
break;
|
|
|
|
case kNuValueModifyOrig:
|
|
|
|
*pValue = pArchive->valModifyOrig;
|
|
|
|
break;
|
|
|
|
case kNuValueOnlyUpdateOlder:
|
|
|
|
*pValue = pArchive->valOnlyUpdateOlder;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err = kNuErrInvalidArg;
|
|
|
|
Nu_ReportError(NU_BLOB, err, "Unknown ValueID %d requested", ident);
|
|
|
|
goto bail;
|
|
|
|
}
|
2000-05-23 01:55:31 +00:00
|
|
|
|
|
|
|
bail:
|
2002-09-21 00:49:42 +00:00
|
|
|
return err;
|
2000-05-23 01:55:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set a configurable parameter.
|
|
|
|
*/
|
|
|
|
NuError
|
|
|
|
Nu_SetValue(NuArchive* pArchive, NuValueID ident, NuValue value)
|
|
|
|
{
|
2002-09-21 00:49:42 +00:00
|
|
|
NuError err = kNuErrInvalidArg;
|
|
|
|
|
|
|
|
switch (ident) {
|
|
|
|
case kNuValueAllowDuplicates:
|
|
|
|
if (value != true && value != false) {
|
|
|
|
Nu_ReportError(NU_BLOB, err,
|
2002-10-09 23:12:06 +00:00
|
|
|
"Invalid kNuValueAllowDuplicates value %ld", value);
|
2002-09-21 00:49:42 +00:00
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
pArchive->valAllowDuplicates = value;
|
|
|
|
break;
|
|
|
|
case kNuValueConvertExtractedEOL:
|
|
|
|
if (value < kNuConvertOff || value > kNuConvertAuto) {
|
|
|
|
Nu_ReportError(NU_BLOB, err,
|
2002-10-09 23:12:06 +00:00
|
|
|
"Invalid kNuValueConvertExtractedEOL value %ld", value);
|
2002-09-21 00:49:42 +00:00
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
pArchive->valConvertExtractedEOL = value;
|
|
|
|
break;
|
|
|
|
case kNuValueDataCompression:
|
2002-10-09 23:12:06 +00:00
|
|
|
if (value < kNuCompressNone || value > kNuCompressBzip2) {
|
2002-09-21 00:49:42 +00:00
|
|
|
Nu_ReportError(NU_BLOB, err,
|
2002-10-09 23:12:06 +00:00
|
|
|
"Invalid kNuValueDataCompression value %ld", value);
|
2002-09-21 00:49:42 +00:00
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
pArchive->valDataCompression = value;
|
|
|
|
break;
|
|
|
|
case kNuValueDiscardWrapper:
|
|
|
|
if (value != true && value != false) {
|
|
|
|
Nu_ReportError(NU_BLOB, err,
|
2002-10-09 23:12:06 +00:00
|
|
|
"Invalid kNuValueDiscardWrapper value %ld", value);
|
2002-09-21 00:49:42 +00:00
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
pArchive->valDiscardWrapper = value;
|
|
|
|
break;
|
|
|
|
case kNuValueEOL:
|
|
|
|
if (value < kNuEOLUnknown || value > kNuEOLCRLF) {
|
|
|
|
Nu_ReportError(NU_BLOB, err,
|
2002-10-09 23:12:06 +00:00
|
|
|
"Invalid kNuValueEOL value %ld", value);
|
2002-09-21 00:49:42 +00:00
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
pArchive->valEOL = value;
|
|
|
|
break;
|
|
|
|
case kNuValueHandleExisting:
|
|
|
|
if (value < kNuMaybeOverwrite || value > kNuMustOverwrite) {
|
|
|
|
Nu_ReportError(NU_BLOB, err,
|
2002-10-09 23:12:06 +00:00
|
|
|
"Invalid kNuValueHandleExisting value %ld", value);
|
2002-09-21 00:49:42 +00:00
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
pArchive->valHandleExisting = value;
|
|
|
|
break;
|
|
|
|
case kNuValueIgnoreCRC:
|
|
|
|
if (value != true && value != false) {
|
|
|
|
Nu_ReportError(NU_BLOB, err,
|
2002-10-09 23:12:06 +00:00
|
|
|
"Invalid kNuValueIgnoreCRC value %ld", value);
|
2002-09-21 00:49:42 +00:00
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
pArchive->valIgnoreCRC = value;
|
|
|
|
break;
|
|
|
|
case kNuValueMimicSHK:
|
|
|
|
if (value != true && value != false) {
|
|
|
|
Nu_ReportError(NU_BLOB, err,
|
2002-10-09 23:12:06 +00:00
|
|
|
"Invalid kNuValueMimicSHK value %ld", value);
|
2002-09-21 00:49:42 +00:00
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
pArchive->valMimicSHK = value;
|
|
|
|
break;
|
|
|
|
case kNuValueModifyOrig:
|
|
|
|
if (value != true && value != false) {
|
|
|
|
Nu_ReportError(NU_BLOB, err,
|
2002-10-09 23:12:06 +00:00
|
|
|
"Invalid kNuValueModifyOrig value %ld", value);
|
2002-09-21 00:49:42 +00:00
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
pArchive->valModifyOrig = value;
|
|
|
|
break;
|
|
|
|
case kNuValueOnlyUpdateOlder:
|
|
|
|
if (value != true && value != false) {
|
|
|
|
Nu_ReportError(NU_BLOB, err,
|
2002-10-09 23:12:06 +00:00
|
|
|
"Invalid kNuValueOnlyUpdateOlder value %ld", value);
|
2002-09-21 00:49:42 +00:00
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
pArchive->valOnlyUpdateOlder = value;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Nu_ReportError(NU_BLOB, err, "Unknown ValueID %d requested", ident);
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = kNuErrNone;
|
2000-05-23 01:55:31 +00:00
|
|
|
|
|
|
|
bail:
|
2002-09-21 00:49:42 +00:00
|
|
|
return err;
|
2000-05-23 01:55:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get an archive attribute. These are things that you would have to
|
|
|
|
* pry into pArchive to get at (like the archive type) or get the master
|
|
|
|
* header (like the number of records).
|
|
|
|
*/
|
|
|
|
NuError
|
|
|
|
Nu_GetAttr(NuArchive* pArchive, NuAttrID ident, NuAttr* pAttr)
|
|
|
|
{
|
2002-09-21 00:49:42 +00:00
|
|
|
NuError err = kNuErrNone;
|
|
|
|
if (pAttr == nil)
|
|
|
|
return kNuErrInvalidArg;
|
|
|
|
|
|
|
|
switch (ident) {
|
|
|
|
case kNuAttrArchiveType:
|
|
|
|
*pAttr = pArchive->archiveType;
|
|
|
|
break;
|
|
|
|
case kNuAttrNumRecords:
|
|
|
|
*pAttr = pArchive->masterHeader.mhTotalRecords;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err = kNuErrInvalidArg;
|
|
|
|
Nu_ReportError(NU_BLOB, err, "Unknown AttrID %d requested", ident);
|
|
|
|
goto bail;
|
|
|
|
}
|
2000-05-23 01:55:31 +00:00
|
|
|
|
|
|
|
bail:
|
2002-09-21 00:49:42 +00:00
|
|
|
return err;
|
2000-05-23 01:55:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert a NuValue compression type to a "phyiscal" ThreadFormat.
|
|
|
|
*
|
|
|
|
* Unsupported compression types cause a warning to be flagged.
|
|
|
|
*/
|
|
|
|
NuThreadFormat
|
|
|
|
Nu_ConvertCompressValToFormat(NuArchive* pArchive, NuValue compValue)
|
|
|
|
{
|
2002-09-21 00:49:42 +00:00
|
|
|
NuThreadFormat threadFormat;
|
|
|
|
Boolean unsup = false;
|
|
|
|
|
|
|
|
switch (compValue) {
|
|
|
|
case kNuCompressNone: threadFormat = kNuThreadFormatUncompressed; break;
|
2002-10-09 23:12:06 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_SQ
|
|
|
|
case kNuCompressSQ: threadFormat = kNuThreadFormatHuffmanSQ; break;
|
|
|
|
#else
|
|
|
|
case kNuCompressSQ: threadFormat = kNuThreadFormatHuffmanSQ;
|
|
|
|
unsup = true; break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENABLE_LZW
|
2002-09-21 00:49:42 +00:00
|
|
|
case kNuCompressLZW1: threadFormat = kNuThreadFormatLZW1; break;
|
|
|
|
case kNuCompressLZW2: threadFormat = kNuThreadFormatLZW2; break;
|
2002-10-09 23:12:06 +00:00
|
|
|
#else
|
|
|
|
case kNuCompressLZW1: threadFormat = kNuThreadFormatLZW1;
|
|
|
|
unsup = true; break;
|
|
|
|
case kNuCompressLZW2: threadFormat = kNuThreadFormatLZW2;
|
|
|
|
unsup = true; break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENABLE_LZC
|
2002-09-28 01:02:03 +00:00
|
|
|
case kNuCompressLZC12: threadFormat = kNuThreadFormatLZC12; break;
|
|
|
|
case kNuCompressLZC16: threadFormat = kNuThreadFormatLZC16; break;
|
2002-10-09 23:12:06 +00:00
|
|
|
#else
|
|
|
|
case kNuCompressLZC12: threadFormat = kNuThreadFormatLZC12;
|
|
|
|
unsup = true; break;
|
|
|
|
case kNuCompressLZC16: threadFormat = kNuThreadFormatLZC16;
|
|
|
|
unsup = true; break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef ENABLE_DEFLATE
|
2002-10-01 01:05:42 +00:00
|
|
|
case kNuCompressDeflate: threadFormat = kNuThreadFormatDeflate; break;
|
|
|
|
#else
|
|
|
|
case kNuCompressDeflate: threadFormat = kNuThreadFormatDeflate;
|
|
|
|
unsup = true; break;
|
|
|
|
#endif
|
2002-10-09 23:12:06 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_BZIP2
|
|
|
|
case kNuCompressBzip2: threadFormat = kNuThreadFormatBzip2; break;
|
|
|
|
#else
|
|
|
|
case kNuCompressBzip2: threadFormat = kNuThreadFormatBzip2;
|
|
|
|
unsup = true; break;
|
|
|
|
#endif
|
|
|
|
|
2002-09-21 00:49:42 +00:00
|
|
|
default:
|
|
|
|
Nu_ReportError(NU_BLOB, kNuErrInvalidArg,
|
|
|
|
"Unknown compress value %ld", compValue);
|
2002-10-09 23:12:06 +00:00
|
|
|
Assert(false);
|
2002-09-21 00:49:42 +00:00
|
|
|
return kNuThreadFormatUncompressed;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unsup) {
|
|
|
|
Nu_ReportError(NU_BLOB, kNuErrNone,
|
2002-10-09 23:12:06 +00:00
|
|
|
"Unsupported compression type 0x%04x requested (%ld), not compressing",
|
2002-09-21 00:49:42 +00:00
|
|
|
threadFormat, compValue);
|
|
|
|
return kNuThreadFormatUncompressed;
|
|
|
|
}
|
|
|
|
|
|
|
|
return threadFormat;
|
2000-05-23 01:55:31 +00:00
|
|
|
}
|
|
|
|
|