/* * NuContents callback function. Print the contents of an individual record. */ NuResult PrintEntry(NuArchive* pArchive, void* vpRecord) { const NuRecord* pRecord = (const NuRecord*) vpRecord; int idx; (void)pArchive; /* shut up, gcc */ printf("RecordIdx %ld: '%s'\n", pRecord->recordIdx, pRecord->filename); for (idx = 0; idx < (int) pRecord->recTotalThreads; idx++) { const NuThread* pThread; NuThreadID threadID; const char* threadLabel; pThread = NuGetThread(pRecord, idx); assert(pThread != nil); threadID = NuGetThreadID(pThread); switch (NuThreadIDGetClass(threadID)) { case kNuThreadClassMessage: threadLabel = "message class"; break; case kNuThreadClassControl: threadLabel = "control class"; break; case kNuThreadClassData: threadLabel = "data class"; break; case kNuThreadClassFilename: threadLabel = "filename class"; break; default: threadLabel = "(unknown class)"; break; } switch (threadID) { case kNuThreadIDComment: threadLabel = "comment"; break; case kNuThreadIDIcon: threadLabel = "icon"; break; case kNuThreadIDMkdir: threadLabel = "mkdir"; break; case kNuThreadIDDataFork: threadLabel = "data fork"; break; case kNuThreadIDDiskImage: threadLabel = "disk image"; break; case kNuThreadIDRsrcFork: threadLabel = "rsrc fork"; break; case kNuThreadIDFilename: threadLabel = "filename"; break; default: break; } printf(" ThreadIdx %ld - 0x%08lx (%s)\n", pThread->threadIdx, threadID, threadLabel); } return kNuOK; }
/* * Extract all of the records from the archive, pulling out and displaying * comment threads. * * The "bulk extract" call doesn't deal with comments. Since we want to * show them while we're extracting the files, we have to manually find * and extract them. */ static NuError ExtractAllRecords(NulibState* pState, NuArchive* pArchive) { NuError err; const NuRecord* pRecord; const NuThread* pThread; NuRecordIdx recordIdx; NuAttr numRecords; int idx, threadIdx; DBUG(("--- doing manual extract\n")); Assert(NState_GetCommand(pState) == kCommandExtract); /* no "-p" here */ err = NuGetAttr(pArchive, kNuAttrNumRecords, &numRecords); for (idx = 0; idx < (int) numRecords; idx++) { err = NuGetRecordIdxByPosition(pArchive, idx, &recordIdx); if (err != kNuErrNone) { fprintf(stderr, "ERROR: couldn't get record #%d (err=%d)\n", idx, err); goto bail; } err = NuGetRecord(pArchive, recordIdx, &pRecord); if (err != kNuErrNone) { fprintf(stderr, "ERROR: unable to get recordIdx %u\n", recordIdx); goto bail; } /* do we want to extract this record? */ if (!IsSpecified(pState, pRecord)) continue; NState_IncMatchCount(pState); /* * Look for a comment thread. */ for (threadIdx = 0; (uint32_t)threadIdx < pRecord->recTotalThreads; threadIdx++) { pThread = NuGetThread(pRecord, threadIdx); Assert(pThread != NULL); if (NuGetThreadID(pThread) == kNuThreadIDComment && pThread->actualThreadEOF > 0) { UNICHAR* filenameUNI = CopyMORToUNI(pRecord->filenameMOR); printf("----- '%s':\n", filenameUNI); free(filenameUNI); err = NuExtractThread(pArchive, pThread->threadIdx, NState_GetCommentSink(pState)); if (err != kNuErrNone) { printf("[comment extraction failed, continuing\n"); } else { printf("\n-----\n"); } } } /* extract the record, using the usual mechanisms */ err = NuExtractRecord(pArchive, recordIdx); if (err != kNuErrNone) goto bail; } bail: return err; }