Added Binary II support. It's not quite seamless, but it's a lot

better than what the original NuLib offered.

Wrote first cut at verbose "help" output.
This commit is contained in:
Andy McFadden 2002-10-09 00:15:24 +00:00
parent 46c7579f57
commit a9ad3e7a3e
12 changed files with 1772 additions and 138 deletions

View File

@ -21,14 +21,14 @@ DoAdd(NulibState* pState)
NuArchive* pArchive = nil;
long flushStatus;
assert(pState != nil);
Assert(pState != nil);
err = OpenArchiveReadWrite(pState);
if (err != kNuErrNone)
goto bail;
pArchive = NState_GetNuArchive(pState);
assert(pArchive != nil);
Assert(pArchive != nil);
NState_SetMatchCount(pState, 0);
@ -66,7 +66,7 @@ bail:
}
err2 = NuClose(pArchive);
assert(err2 == kNuErrNone);
Assert(err2 == kNuErrNone);
}
return err;
}
@ -86,8 +86,8 @@ AddToArchive(NulibState* pState, NuArchive* pArchive)
ulong fileCount;
int i;
assert(pState != nil);
assert(pArchive != nil);
Assert(pState != nil);
Assert(pArchive != nil);
if (!NState_GetFilespecCount(pState)) {
err = kNuErrSyntax;

View File

@ -34,9 +34,9 @@ OutputPathnameFilter(NuArchive* pArchive, void* vproposal)
char* renameToStr;
char* resultBuf;
assert(pArchive != nil);
Assert(pArchive != nil);
(void) NuGetExtraData(pArchive, (void**) &pState);
assert(pState != nil);
Assert(pState != nil);
/* handle extract-to-pipe */
if (NState_GetCommand(pState) == kCommandExtractToPipe) {
@ -58,7 +58,7 @@ OutputPathnameFilter(NuArchive* pArchive, void* vproposal)
/* right source file, proceed with the rename */
NState_SetTempPathnameLen(pState, strlen(renameToStr) +1);
resultBuf = NState_GetTempPathnameBuf(pState);
assert(resultBuf != nil);
Assert(resultBuf != nil);
strcpy(resultBuf, renameToStr);
pathProposal->newPathname = resultBuf;
@ -210,6 +210,10 @@ SpecMatchesRecord(NulibState* pState, const char* spec, const NuRecord* pRecord)
* the file specification given on the command line.
*
* If no filespec was provided, then all records are "specified".
*
* We pass the entire NuRecord in because we may want to allow
* extraction by criteria other than name, e.g. all text files or all
* files archived before a certain date.
*/
Boolean
IsSpecified(NulibState* pState, const NuRecord* pRecord)
@ -240,9 +244,9 @@ SelectionFilter(NuArchive* pArchive, void* vproposal)
const NuSelectionProposal* selProposal = vproposal;
NulibState* pState;
assert(pArchive != nil);
Assert(pArchive != nil);
(void) NuGetExtraData(pArchive, (void**) &pState);
assert(pState != nil);
Assert(pState != nil);
if (IsSpecified(pState, selProposal->pRecord)) {
NState_IncMatchCount(pState);
@ -298,9 +302,9 @@ ProgressUpdater(NuArchive* pArchive, void* vProgress)
char nameBuf[kMaxDisplayLen+1];
Boolean showName, eolConv;
assert(pArchive != nil);
Assert(pArchive != nil);
(void) NuGetExtraData(pArchive, (void**) &pState);
assert(pState != nil);
Assert(pState != nil);
if (NState_GetSuppressOutput(pState))
return kNuOK;
@ -367,7 +371,7 @@ ProgressUpdater(NuArchive* pArchive, void* vProgress)
}
break;
default:
assert(0);
Assert(0);
actionStr = "????";
}
@ -413,12 +417,12 @@ ProgressUpdater(NuArchive* pArchive, void* vProgress)
PrintPercentage(pProgress->uncompressedLength,
pProgress->uncompressedProgress);
if (showName)
printf(" %s%s %s", actionStr, eolConv ? "+" : " ", nameBuf);
printf(" %s%c %s", actionStr, eolConv ? '+' : ' ', nameBuf);
else
printf(" %s%s", actionStr, eolConv ? "+" : " ");
printf(" %s%c", actionStr, eolConv ? '+' : ' ');
}
} else {
assert(0);
Assert(0);
printf("????\n");
}
@ -442,13 +446,13 @@ HandleReplaceExisting(NulibState* pState, NuArchive* pArchive,
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);
@ -460,7 +464,7 @@ HandleReplaceExisting(NulibState* pState, NuArchive* pArchive,
while (1) {
printf("\n Replace %s? [y]es, [n]o, [A]ll, [N]one",
pErrorStatus->pathname);
if (pErrorStatus->canRename) /* renaming records not allowed */
if (pErrorStatus->canRename) /* renaming record adds not allowed */
printf(", [r]ename: ");
else
printf(": ");
@ -529,8 +533,8 @@ HandleBadCRC(NulibState* pState, NuArchive* pArchive,
NuResult result = kNuOK;
char reply;
assert(pState != nil);
assert(pErrorStatus != nil);
Assert(pState != nil);
Assert(pErrorStatus != nil);
if (NState_GetInputUnavailable(pState)) {
putc('\n', stderr);
@ -581,9 +585,9 @@ HandleAddNotFound(NulibState* pState, NuArchive* pArchive,
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);
@ -629,9 +633,9 @@ ErrorHandler(NuArchive* pArchive, void* vErrorStatus)
NulibState* pState;
NuResult result;
assert(pArchive != nil);
Assert(pArchive != nil);
(void) NuGetExtraData(pArchive, (void**) &pState);
assert(pState != nil);
Assert(pState != nil);
/* default action is to abort the current operation */
result = kNuAbort;
@ -682,7 +686,7 @@ ErrorHandler(NuArchive* pArchive, void* vErrorStatus)
* you have to "sabotage" AddFile, or remove a file from disk
* while NuFlush is running.)
*/
assert(0);
Assert(0);
/*result = HandleAddNotFound(pState, pArchive, pErrorStatus);*/
}
} else if (pErrorStatus->operation == kNuOpTest) {
@ -752,7 +756,7 @@ IsRecordReadOnly(const NuRecord* pRecord)
Boolean
IsFilenameStdin(const char* archiveName)
{
assert(archiveName != nil);
Assert(archiveName != nil);
return (strcmp(archiveName, kStdinArchive) == 0);
}
@ -769,12 +773,14 @@ OpenArchiveReadOnly(NulibState* pState)
NuError err;
NuArchive* pArchive = nil;
assert(pState != nil);
Assert(pState != nil);
if (IsFilenameStdin(NState_GetArchiveFilename(pState))) {
err = NuStreamOpenRO(stdin, &pArchive);
if (err != kNuErrNone) {
ReportError(err, "unable to open stdin archive");
if (err == kNuErrIsBinary2)
err = kNuErrNotNuFX; /* we can't seek back, so forget BNY */
goto bail;
}
/*
@ -787,8 +793,10 @@ OpenArchiveReadOnly(NulibState* pState)
} else {
err = NuOpenRO(NState_GetArchiveFilename(pState), &pArchive);
if (err != kNuErrNone) {
ReportError(err, "unable to open '%s'",
NState_GetArchiveFilename(pState));
if (err != kNuErrIsBinary2) {
ReportError(err, "unable to open '%s'",
NState_GetArchiveFilename(pState));
}
goto bail;
}
}
@ -839,7 +847,7 @@ OpenArchiveReadOnly(NulibState* pState)
else if (strcmp(SYSTEM_DEFAULT_EOL, "\r\n") == 0)
err = NuSetValue(pArchive, kNuValueEOL, kNuEOLCRLF);
else {
assert(0);
Assert(0);
err = kNuErrInternal;
ReportError(err, "Unknown SYSTEM_DEFAULT_EOL '%s'", SYSTEM_DEFAULT_EOL);
goto bail;
@ -869,8 +877,8 @@ OpenArchiveReadWrite(NulibState* pState)
NuArchive* pArchive = nil;
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)
@ -932,7 +940,7 @@ OpenArchiveReadWrite(NulibState* pState)
else if (strcmp(SYSTEM_DEFAULT_EOL, "\r\n") == 0)
err = NuSetValue(pArchive, kNuValueEOL, kNuEOLCRLF);
else {
assert(0);
Assert(0);
err = kNuErrInternal;
ReportError(err, "Unknown SYSTEM_DEFAULT_EOL '%s'", SYSTEM_DEFAULT_EOL);
goto bail;

1361
nulib2/Binary2.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,6 @@
2002/10/08 fadden
- added Binary II support
2002/09/30 fadden
- added "-z" flag to specify zlib's "deflate" compression (the
"secret" debug dump command is now -g)

View File

@ -28,7 +28,7 @@ ExtractAllRecords(NulibState* pState, NuArchive* pArchive)
int idx, threadIdx;
DBUG(("--- doing manual extract\n"));
assert(NState_GetCommand(pState) == kCommandExtract); /* no "-p" here */
Assert(NState_GetCommand(pState) == kCommandExtract); /* no "-p" here */
err = NuGetAttr(pArchive, kNuAttrNumRecords, &numRecords);
for (idx = 0; idx < (int) numRecords; idx++) {
@ -57,7 +57,7 @@ ExtractAllRecords(NulibState* pState, NuArchive* pArchive)
threadIdx++)
{
pThread = NuGetThread(pRecord, threadIdx);
assert(pThread != nil);
Assert(pThread != nil);
if (NuGetThreadID(pThread) == kNuThreadIDComment &&
pThread->actualThreadEOF > 0)
@ -93,13 +93,18 @@ DoExtract(NulibState* pState)
NuError err;
NuArchive* pArchive = nil;
assert(pState != nil);
Assert(pState != nil);
if (NState_GetModBinaryII(pState))
return BNYDoExtract(pState);
err = OpenArchiveReadOnly(pState);
if (err == kNuErrIsBinary2)
return BNYDoExtract(pState);
if (err != kNuErrNone)
goto bail;
pArchive = NState_GetNuArchive(pState);
assert(pArchive != nil);
Assert(pArchive != nil);
NState_SetMatchCount(pState, 0);
@ -147,13 +152,18 @@ DoTest(NulibState* pState)
NuError err;
NuArchive* pArchive = nil;
assert(pState != nil);
Assert(pState != nil);
if (NState_GetModBinaryII(pState))
return BNYDoTest(pState);
err = OpenArchiveReadOnly(pState);
if (err == kNuErrIsBinary2)
return BNYDoTest(pState);
if (err != kNuErrNone)
goto bail;
pArchive = NState_GetNuArchive(pState);
assert(pArchive != nil);
Assert(pArchive != nil);
NState_SetMatchCount(pState, 0);

View File

@ -35,7 +35,6 @@ static const char* gMonths[] = {
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
#define kNuDateOutputLen 64
/*
@ -66,11 +65,11 @@ ComputePercent(ulong totalSize, ulong size)
* Convert a NuDateTime structure into something printable. This uses an
* abbreviated format, with date and time but not weekday or seconds.
*
* The buffer passed in must hold at least kNuDateOutputLen bytes.
* The buffer passed in must hold at least kDateOutputLen bytes.
*
* Returns "buffer" for the benefit of printf() calls.
*/
static char*
char*
FormatDateShort(const NuDateTime* pDateTime, char* buffer)
{
/* is it valid? */
@ -108,9 +107,9 @@ ShowContentsShort(NuArchive* pArchive, void* vpRecord)
const NuRecord* pRecord = (NuRecord*) vpRecord;
NulibState* pState;
assert(pArchive != nil);
Assert(pArchive != nil);
(void) NuGetExtraData(pArchive, (void**) &pState);
assert(pState != nil);
Assert(pState != nil);
if (!IsSpecified(pState, pRecord))
goto bail;
@ -152,7 +151,7 @@ AnalyzeRecord(const NuRecord* pRecord, enum RecordKind* pRecordKind,
for (idx = 0; idx < pRecord->recTotalThreads; idx++) {
pThread = NuGetThread(pRecord, idx);
assert(pThread != nil);
Assert(pThread != nil);
if (pThread->thThreadClass == kNuThreadClassData) {
/* replace what's there if this might be more interesting */
@ -193,13 +192,13 @@ ShowContentsVerbose(NuArchive* pArchive, void* vpRecord)
ulong totalLen, totalCompLen;
ushort format;
NulibState* pState;
char date1[kNuDateOutputLen];
char date1[kDateOutputLen];
char tmpbuf[16];
int len;
assert(pArchive != nil);
Assert(pArchive != nil);
(void) NuGetExtraData(pArchive, (void**) &pState);
assert(pState != nil);
Assert(pState != nil);
if (!IsSpecified(pState, pRecord))
goto bail;
@ -235,7 +234,7 @@ ShowContentsVerbose(NuArchive* pArchive, void* vpRecord)
pRecord->recExtraType);
break;
default:
assert(0);
Assert(0);
printf("ERROR ");
}
@ -281,13 +280,18 @@ DoListShort(NulibState* pState)
NuError err;
NuArchive* pArchive = nil;
assert(pState != nil);
Assert(pState != nil);
if (NState_GetModBinaryII(pState))
return BNYDoListShort(pState);
err = OpenArchiveReadOnly(pState);
if (err == kNuErrIsBinary2)
return BNYDoListShort(pState);
if (err != kNuErrNone)
goto bail;
pArchive = NState_GetNuArchive(pState);
assert(pArchive != nil);
Assert(pArchive != nil);
err = NuContents(pArchive, ShowContentsShort);
/* fall through with err */
@ -308,18 +312,23 @@ DoListVerbose(NulibState* pState)
NuError err;
NuArchive* pArchive = nil;
const NuMasterHeader* pHeader;
char date1[kNuDateOutputLen];
char date2[kNuDateOutputLen];
char date1[kDateOutputLen];
char date2[kDateOutputLen];
long totalLen, totalCompLen;
const char* cp;
assert(pState != nil);
Assert(pState != nil);
if (NState_GetModBinaryII(pState))
return BNYDoListVerbose(pState);
err = OpenArchiveReadOnly(pState);
if (err == kNuErrIsBinary2)
return BNYDoListVerbose(pState);
if (err != kNuErrNone)
goto bail;
pArchive = NState_GetNuArchive(pState);
assert(pArchive != nil);
Assert(pArchive != nil);
/*
* Try to get just the filename.
@ -359,10 +368,12 @@ DoListVerbose(NulibState* pState)
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));
if (!NState_GetFilespecCount(pState)) {
printf(" Overhead: %ld (%d%%)\n",
pHeader->mhMasterEOF - totalCompLen,
ComputePercent(pHeader->mhMasterEOF - totalCompLen,
pHeader->mhMasterEOF));
}
#endif
/*(void) NuDebugDumpArchive(pArchive);*/
@ -386,7 +397,7 @@ NullCallback(NuArchive* pArchive, void* vpRecord)
/*
* Print very detailed output, suitable for debugging (requires that
* debugging be enabled in nufxlib).
* debug messages be enabled in nufxlib).
*/
NuError
DoListDebug(NulibState* pState)
@ -394,13 +405,18 @@ DoListDebug(NulibState* pState)
NuError err;
NuArchive* pArchive = nil;
assert(pState != nil);
Assert(pState != nil);
if (NState_GetModBinaryII(pState))
return BNYDoListDebug(pState);
err = OpenArchiveReadOnly(pState);
if (err == kNuErrIsBinary2)
return BNYDoListDebug(pState);
if (err != kNuErrNone)
goto bail;
pArchive = NState_GetNuArchive(pState);
assert(pArchive != nil);
Assert(pArchive != nil);
/* have to do something to force the library to scan the archive */
err = NuContents(pArchive, NullCallback);

View File

@ -27,14 +27,15 @@ typedef struct ValidCombo {
} ValidCombo;
static const ValidCombo gValidCombos[] = {
{ kCommandAdd, false, true, "ufrj0zcke" },
{ kCommandAdd, false, true, "ekcz0jrfu" },
{ 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" },
{ kCommandExtract, true, false, "beslcjrfu" },
{ kCommandExtractToPipe, true, false, "blr" },
{ kCommandListShort, true, false, "br" },
{ kCommandListVerbose, true, false, "br" },
{ kCommandListDebug, true, false, "b" },
{ kCommandTest, true, false, "br" },
{ kCommandHelp, false, false, "" },
};
@ -156,24 +157,119 @@ Usage(const NulibState* pState)
" -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"
" -d delete files from archive -h extended help message\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"
#ifdef HAVE_LIBZ
" -0 don't use compression -z compress with gzip-style 'deflate'\n"
" -z use gzip 'deflate' compression "
#else
" -0 don't use compression -z use zlib [not included]\n"
" -z use zlib [not included] "
#endif
" -l auto-convert text files -ll auto-convert ALL files\n"
#ifdef HAVE_LIBBZ2
"-zz use bzip2 'BWT' compression\n"
#else
"-zz use BWT [not included]\n"
#endif
" -l auto-convert text files -ll convert CR/LF on ALL files\n"
" -s stomp existing files w/o asking -k store files as disk images\n"
" -e preserve ProDOS file types -ee preserve types and extend names\n"
" -c add one-line comments\n"
" -b force Binary II mode\n"
);
}
/*
* Handle the "-h" command.
*/
NuError
DoHelp(const NulibState* pState)
{
static const struct {
Command cmd;
char letter;
const char* shortDescr;
const char* longDescr;
} help[] = {
{ kCommandListVerbose, 'v', "verbose listing of archive contents",
" List files in the archive, blah blah blah\n"
},
{ kCommandListShort, 't', "quick dump of table of contents",
" shortList files in the archive, blah blah blah\n"
},
{ kCommandAdd, 'a', "add files, creating the archive if necessary",
" Add files to the archive, blah blah blah\n"
},
{ kCommandDelete, 'd', "delete files from archive",
" Delete files from the archive, blah blah blah\n"
},
{ kCommandExtract, 'x', "extract files from an archive",
" Extracts files, blah blah blah\n"
},
{ kCommandExtractToPipe, 'p', "extract files to pipe",
" Extracts files to stdout, blah blah blah\n"
},
{ kCommandTest, 'i', "test archive integrity",
" Tests files, blah blah blah\n"
},
{ kCommandHelp, 'h', "show extended help",
" This is the extended help text\n"
" A full manual is available from http://www.nulib.com/.\n"
},
};
int i;
printf("%s",
"\n"
"NuLib2 is free software, distributed under terms of the GNU General\n"
"Public License. NuLib2 uses NufxLib, a complete library of functions\n"
"for accessing NuFX (ShrinkIt) archives. NufxLib is also free software,\n"
"distributed under terms of the GNU Library General Public License (LGPL).\n"
"Source code for both is available from http://www.nulib.com/, and copies\n"
"of the licenses are included.\n"
"\n"
"This program is distributed in the hope that it will be useful,\n"
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
"README file for more details.\n"
);
for (i = 0; i < NELEM(help); i++) {
const ValidCombo* pvc;
int j;
pvc = FindValidComboEntry(help[i].cmd);
if (pvc == nil) {
fprintf(stderr, "%s: internal error: couldn't find vc for %d\n",
gProgName, help[i].cmd);
continue;
}
printf("\nCommand \"-%c\": %s\n", help[i].letter, help[i].shortDescr);
printf(" Valid modifiers:");
for (j = strlen(pvc->modifiers) -1; j >= 0; j--) {
char ch = pvc->modifiers[j];
/* print flags, special-casing options that can be doubled */
if (ch == 'l' || ch == 'e' || ch == 'z')
printf(" -%c -%c%c", ch, ch, ch);
else
printf(" -%c", ch);
}
putchar('\n');
printf("\n%s", help[i].longDescr);
}
putchar('\n');
return kNuErrNone;
}
/*
* Process the command-line options. The results are placed into "pState".
*/
@ -184,8 +280,16 @@ ProcessOptions(NulibState* pState, int argc, char* const* argv)
int idx;
/*
* Must have at least a command letter and an archive filename.
* Must have at least a command letter and an archive filename, unless
* the command letter is 'h'. Special-case a solitary "-h" here.
*/
if (argc == 2 && (tolower(argv[1][0]) == 'h' ||
(argv[1][0] == '-' && tolower(argv[1][1] == 'h')) ) )
{
DoHelp(nil);
return -1;
}
if (argc < 3) {
Usage(pState);
return -1;
@ -228,6 +332,7 @@ ProcessOptions(NulibState* pState, int argc, char* const* argv)
case 'g': NState_SetCommand(pState, kCommandListDebug); break;
case 'i': NState_SetCommand(pState, kCommandTest); break;
case 'd': NState_SetCommand(pState, kCommandDelete); break;
case 'h': NState_SetCommand(pState, kCommandHelp); break;
default:
fprintf(stderr, "%s: Unknown command '%c'\n", gProgName, *cp);
goto fail;
@ -243,16 +348,29 @@ ProcessOptions(NulibState* pState, int argc, char* const* argv)
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 'c': NState_SetModComments(pState, true); break;
case 'b': NState_SetModBinaryII(pState, true); break;
case 'z':
#ifdef HAVE_LIBZ
NState_SetModCompressDeflate(pState, true);
#else
fprintf(stderr, "%s: WARNING: zlib support not compiled in\n",
gProgName);
#endif
if (*(cp+1) == 'z') {
#ifdef HAVE_LIBBZ2
NState_SetModCompressBWT(pState, true);
#else
fprintf(stderr,
"%s: WARNING: libbzip2 support not compiled in\n",
gProgName);
#endif
cp++;
} else {
#ifdef HAVE_LIBZ
NState_SetModCompressDeflate(pState, true);
#else
fprintf(stderr,
"%s: WARNING: zlib support not compiled in\n",
gProgName);
#endif
}
break;
case 'e':
if (*(cp-1) == 'e') /* should never point at invalid */
@ -283,10 +401,21 @@ ProcessOptions(NulibState* pState, int argc, char* const* argv)
}
}
/*
* Can't have tea and no tea at the same time.
*/
if (NState_GetModNoCompression(pState) &&
NState_GetModCompressDeflate(pState))
{
fprintf(stderr, "%s: Can't specify both -0 and -z\n",
gProgName);
goto fail;
}
/*
* See if we have an archive name. If it's "-", see if we allow that.
*/
assert(idx < argc);
Assert(idx < argc);
NState_SetArchiveFilename(pState, argv[idx]);
if (IsFilenameStdin(argv[idx])) {
if (!IsValidOnPipe(NState_GetCommand(pState))) {
@ -307,7 +436,7 @@ ProcessOptions(NulibState* pState, int argc, char* const* argv)
NState_SetFilespecPointer(pState, &argv[idx]);
NState_SetFilespecCount(pState, argc - idx);
} else {
assert(idx == argc);
Assert(idx == argc);
if (IsFilespecRequired(NState_GetCommand(pState))) {
fprintf(stderr, "%s: This command requires a list of files\n",
gProgName);
@ -368,11 +497,14 @@ DoWork(NulibState* pState)
case kCommandDelete:
err = DoDelete(pState);
break;
case kCommandHelp:
err = DoHelp(pState);
break;
default:
fprintf(stderr, "ERROR: unexpected command %d\n",
NState_GetCommand(pState));
err = kNuErrInternal;
assert(0);
Assert(0);
break;
}

View File

@ -49,10 +49,10 @@ CFLAGS = @BUILD_FLAGS@ -I. -I$(NUFXSRCDIR) -I$(includedir) @DEFS@
# CFLAGS += -DQUANTIFY
#endif
SRCS = Add.c ArcUtils.c Delete.c Extract.c Filename.c List.c Main.c \
MiscStuff.c MiscUtils.c State.c SysUtils.c
OBJS = Add.o ArcUtils.o Delete.o Extract.o Filename.o List.o Main.o \
MiscStuff.o MiscUtils.o State.o SysUtils.o
SRCS = Add.c ArcUtils.c Binary2.c Delete.c Extract.c Filename.c \
List.c Main.c MiscStuff.c MiscUtils.c State.c SysUtils.c
OBJS = Add.o ArcUtils.o Binary2.o Delete.o Extract.o Filename.o \
List.o Main.o MiscStuff.o MiscUtils.o State.o SysUtils.o
PRODUCT = nulib2

View File

@ -23,6 +23,8 @@
/* make our one-line comments this big */
#define kDefaultCommentLen 200
/* for use with FormatDateShort() */
#define kDateOutputLen 64
/*
* Function prototypes.
@ -40,6 +42,13 @@ NuError OpenArchiveReadWrite(NulibState* pState);
const NuThread* GetThread(const NuRecord* pRecord, ulong idx);
Boolean IsRecordReadOnly(const NuRecord* pRecord);
/* Binary2.c */
NuError BNYDoExtract(NulibState* pState);
NuError BNYDoTest(NulibState* pState);
NuError BNYDoListShort(NulibState* pState);
NuError BNYDoListVerbose(NulibState* pState);
NuError BNYDoListDebug(NulibState* pState);
/* Delete.c */
NuError DoDelete(NulibState* pState);
@ -63,6 +72,7 @@ const char* FindExtension(NulibState* pState, const char* pathname);
NuError DoListShort(NulibState* pState);
NuError DoListVerbose(NulibState* pState);
NuError DoListDebug(NulibState* pState);
char* FormatDateShort(const NuDateTime* pDateTime, char* buffer);
/* Main.c */
extern const char* gProgName;
@ -93,5 +103,7 @@ NuError NormalizeDirectoryName(NulibState* pState, const char* srcp,
char* MakeTempArchiveName(NulibState* pState);
NuError AddFile(NulibState* pState, NuArchive* pArchive,
const char* pathname);
NuError Mkdir(const char* dir);
NuError TestFileExistence(const char* fileName, Boolean* pIsDir);
#endif /*__Nulib2__*/

View File

@ -18,7 +18,7 @@ static const char* gProgramVersion = "1.1.0d1";
NuError
NState_Init(NulibState** ppState)
{
assert(ppState != nil);
Assert(ppState != nil);
*ppState = Calloc(sizeof(**ppState));
if (*ppState == nil)
@ -89,7 +89,7 @@ NState_Free(NulibState* pState)
void
NState_DebugDump(const NulibState* pState)
{
/* this will break when the code changes, but it's just for debugging */
/* this table will break if the code changes, but it's just for debugging */
static const char* kCommandNames[] = {
"<unknown>",
"add",
@ -100,9 +100,10 @@ NState_DebugDump(const NulibState* pState)
"listVerbose",
"listDebug",
"test",
"help",
};
assert(pState != nil);
Assert(pState != nil);
printf("NState:\n");
printf(" programVersion: '%s'\n", pState->programVersion);
@ -127,6 +128,8 @@ NState_DebugDump(const NulibState* pState)
printf(" compressDeflate\n");
if (pState->modComments)
printf(" comments\n");
if (pState->modBinaryII)
printf(" binaryII\n");
if (pState->modConvertText)
printf(" convertText\n");
if (pState->modConvertAll)
@ -286,7 +289,7 @@ NState_SetTempPathnameLen(NulibState* pState, long len)
newBuf = Malloc(len);
else
newBuf = Realloc(pState->tempPathnameBuf, len);
assert(newBuf != nil);
Assert(newBuf != nil);
if (newBuf == nil) {
Free(pState->tempPathnameBuf);
pState->tempPathnameBuf = nil;
@ -439,6 +442,18 @@ NState_SetModComments(NulibState* pState, Boolean val)
pState->modComments = val;
}
Boolean
NState_GetModBinaryII(const NulibState* pState)
{
return pState->modBinaryII;
}
void
NState_SetModBinaryII(NulibState* pState, Boolean val)
{
pState->modBinaryII = val;
}
Boolean
NState_GetModConvertText(const NulibState* pState)
{

View File

@ -24,7 +24,8 @@ typedef enum Command {
kCommandListShort,
kCommandListVerbose,
kCommandListDebug,
kCommandTest
kCommandTest,
kCommandHelp
} Command;
@ -65,6 +66,7 @@ typedef struct NulibState {
Boolean modNoCompression;
Boolean modCompressDeflate;
Boolean modComments;
Boolean modBinaryII;
Boolean modConvertText;
Boolean modConvertAll;
Boolean modOverwriteExisting;
@ -132,6 +134,8 @@ Boolean NState_GetModCompressDeflate(const NulibState* pState);
void NState_SetModCompressDeflate(NulibState* pState, Boolean val);
Boolean NState_GetModComments(const NulibState* pState);
void NState_SetModComments(NulibState* pState, Boolean val);
Boolean NState_GetModBinaryII(const NulibState* pState);
void NState_SetModBinaryII(NulibState* pState, Boolean val);
Boolean NState_GetModConvertText(const NulibState* pState);
void NState_SetModConvertText(NulibState* pState, Boolean val);
Boolean NState_GetModConvertAll(const NulibState* pState);

View File

@ -78,7 +78,7 @@ UNIXNormalizeFileName(NulibState* pState, const char* srcp, long srcLen,
char* dstp = *pDstp;
while (srcLen--) { /* don't go until null found! */
assert(*srcp != '\0');
Assert(*srcp != '\0');
if (*srcp == '%') {
/* change '%' to "%%" */
@ -101,7 +101,7 @@ UNIXNormalizeFileName(NulibState* pState, const char* srcp, long srcLen,
}
*dstp = '\0'; /* end the string, but don't advance past the null */
assert(*pDstp - dstp <= dstLen); /* make sure we didn't overflow */
Assert(*pDstp - dstp <= dstLen); /* make sure we didn't overflow */
*pDstp = dstp;
return kNuErrNone;
@ -157,7 +157,7 @@ Win32NormalizeFileName(NulibState* pState, const char* srcp, long srcLen,
while (srcLen--) { /* don't go until null found! */
assert(*srcp != '\0');
Assert(*srcp != '\0');
if (*srcp == '%') {
/* change '%' to "%%" */
@ -180,7 +180,7 @@ Win32NormalizeFileName(NulibState* pState, const char* srcp, long srcLen,
}
*dstp = '\0'; /* end the string, but don't advance past the null */
assert(*pDstp - dstp <= dstLen); /* make sure we didn't overflow */
Assert(*pDstp - dstp <= dstLen); /* make sure we didn't overflow */
*pDstp = dstp;
return kNuErrNone;
@ -203,12 +203,12 @@ NormalizeFileName(NulibState* pState, const char* srcp, long srcLen,
{
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);
@ -255,9 +255,9 @@ MakeTempArchiveName(NulibState* pState)
long len;
archivePathname = NState_GetArchiveFilename(pState);
assert(archivePathname != nil);
Assert(archivePathname != nil);
fssep = NState_GetSystemPathSeparator(pState);
assert(fssep != 0);
Assert(fssep != 0);
/* we'll get confused if the archive pathname looks like "/foo/bar/" */
len = strlen(archivePathname);
@ -338,10 +338,10 @@ CheckFileStatus(const char* pathname, struct stat* psb, Boolean* pExists,
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;
@ -411,14 +411,14 @@ SetFileDetails(NulibState* pState, const char* pathname, struct stat* psb,
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);
Assert(livePathStr != nil);
strcpy(livePathStr, pathname);
/* init to defaults */
@ -485,7 +485,7 @@ SetFileDetails(NulibState* pState, const char* pathname, struct stat* psb,
/*
* Check for other unpleasantness, such as a leading fssep.
*/
assert(NState_GetSystemPathSeparator(pState) != '\0');
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));
@ -524,7 +524,7 @@ SetFileDetails(NulibState* pState, const char* pathname, struct stat* psb,
char* lastFssep;
lastFssep = strrchr(livePathStr, NState_GetSystemPathSeparator(pState));
if (lastFssep != nil) {
assert(*(lastFssep+1) != '\0'); /* should already have been caught*/
Assert(*(lastFssep+1) != '\0'); /* should already have been caught*/
memmove(livePathStr, lastFssep+1, strlen(lastFssep+1)+1);
}
}
@ -581,7 +581,7 @@ DoAddFile(NulibState* pState, NuArchive* pArchive, const char* pathname,
char* comment;
DBUG(("Preparing comment for recordIdx=%ld\n", recordIdx));
assert(recordIdx != 0);
Assert(recordIdx != 0);
comment = GetSimpleComment(pState, pathname, kDefaultCommentLen);
if (comment != nil) {
NuDataSource* pDataSource;
@ -616,7 +616,7 @@ bail_quiet:
}
#if defined(UNIX_LIKE)
#if defined(UNIX_LIKE) /* ---- UNIX --------------------------------------- */
static NuError UNIXAddFile(NulibState* pState, NuArchive* pArchive,
const char* pathname);
@ -635,9 +635,9 @@ UNIXAddDirectory(NulibState* pState, NuArchive* pArchive, const char* dirName)
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));
@ -701,9 +701,9 @@ UNIXAddFile(NulibState* pState, NuArchive* pArchive, const char* pathname)
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) {
@ -749,7 +749,7 @@ bail_quiet:
return err;
}
#elif defined(WINDOWS_LIKE)
#elif defined(WINDOWS_LIKE) /* ---- Windows -------------------------------- */
/*
* Directory structure and functions, based on zDIR in Info-Zip sources.
@ -867,9 +867,9 @@ Win32AddDirectory(NulibState* pState, NuArchive* pArchive, const char* dirName)
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));
@ -932,9 +932,9 @@ Win32AddFile(NulibState* pState, NuArchive* pArchive, const char* pathname)
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) {
@ -980,7 +980,7 @@ bail_quiet:
return err;
}
#else
#else /* ---- unknown ----------------------------------------------------- */
# error "Port this (AddFile/AddDirectory)"
#endif
@ -1007,3 +1007,76 @@ AddFile(NulibState* pState, NuArchive* pArchive, const char* pathname)
#endif
}
/*
* Invoke the system-dependent directory creation function.
*
* Currently only used by Binary2.c.
*/
NuError
Mkdir(const char* dir)
{
NuError err = kNuErrNone;
Assert(dir != nil);
#if defined(UNIX_LIKE)
if (mkdir(dir, S_IRWXU | S_IRGRP|S_IXGRP | S_IROTH|S_IXOTH) < 0) {
err = errno ? errno : kNuErrDirCreate;
goto bail;
}
#elif defined(WINDOWS_LIKE)
if (mkdir(dir) < 0) {
err = errno ? errno : kNuErrDirCreate;
goto bail;
}
#else
#error "Port this"
#endif
bail:
return err;
}
/*
* Test for the existence of a file.
*
* Currently only used by Binary2.c.
*/
NuError
TestFileExistence(const char* fileName, Boolean* pIsDir)
{
NuError err = kNuErrNone;
Assert(fileName != nil);
Assert(pIsDir != nil);
#if defined(UNIX_LIKE) || defined(WINDOWS_LIKE)
{
struct stat sbuf;
int cc;
cc = stat(fileName, &sbuf);
if (cc) {
if (errno == ENOENT)
err = kNuErrFileNotFound;
else
err = kNuErrFileStat;
goto bail;
}
if (S_ISDIR(sbuf.st_mode))
*pIsDir = true;
else
*pIsDir = false;
}
#else
#error "Port this"
#endif
bail:
return err;
}