/* * oro - open read-only */ static NuError OpenReadOnlyFunc(ExerciserState* pState, int argc, char** argv) { NuError err; NuArchive* pArchive; assert(ExerciserState_GetNuArchive(pState) == NULL); assert(argc == 2); err = NuOpenRO(argv[1], &pArchive); if (err == kNuErrNone) { ExerciserState_SetNuArchive(pState, pArchive); ExerciserState_SetArchivePath(pState, argv[1]); } return err; }
/* * Open the archive in read-only mode. We use "file mode" for a file, or * "streaming mode" for stdin. */ NuError OpenArchiveReadOnly(NulibState* pState) { NuError err; NuArchive* pArchive = NULL; Assert(pState != NULL); 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; } /* * 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) { if (err != kNuErrIsBinary2) { ReportError(err, "unable to open '%s'", NState_GetArchiveFilename(pState)); } goto bail; } } /* introduce them */ NState_SetNuArchive(pState, pArchive); err = NuSetExtraData(pArchive, pState); NuSetSelectionFilter(pArchive, SelectionFilter); NuSetOutputPathnameFilter(pArchive, OutputPathnameFilter); NuSetProgressUpdater(pArchive, ProgressUpdater); NuSetErrorHandler(pArchive, ErrorHandler); /*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); /* if we're converting EOL, we probably ought to do this too */ err = NuSetValue(pArchive, kNuValueStripHighASCII, true); 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); } DBUG(("--- enabling ShrinkIt compatibility mode\n")); err = NuSetValue(pArchive, kNuValueMimicSHK, true); BailError(err); /* handy for some malformed archives */ err = NuSetValue(pArchive, kNuValueHandleBadMac, true); BailError(err); /* DBUG(("--- enabling 'mask dataless' mode\n")); err = NuSetValue(pArchive, kNuValueMaskDataless, 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); bail: if (err != kNuErrNone && pArchive != NULL) { /* clean up */ (void) NuClose(pArchive); NState_SetNuArchive(pState, NULL); } return err; }