/* * gr - get record attributes */ static NuError GetRecordFunc(ExerciserState* pState, int argc, char** argv) { NuError err; const NuRecord* pRecord; (void) pState, (void) argc, (void) argv; /* shut up, gcc */ assert(ExerciserState_GetNuArchive(pState) != nil); assert(argc == 2); err = NuGetRecord(ExerciserState_GetNuArchive(pState), strtol(argv[1], nil, 0), &pRecord); if (err == kNuErrNone) { printf("Exerciser: success, call returned:\n"); printf("\tfileSysID : %d\n", pRecord->recFileSysID); printf("\tfileSysInfo : 0x%04x ('%c')\n", pRecord->recFileSysInfo, NuGetSepFromSysInfo(pRecord->recFileSysInfo)); printf("\taccess : 0x%02lx\n", pRecord->recAccess); printf("\tfileType : 0x%04lx\n", pRecord->recFileType); printf("\textraType : 0x%04lx\n", pRecord->recExtraType); printf("\tcreateWhen : ...\n"); printf("\tmodWhen : ...\n"); /* too lazy */ printf("\tarchiveWhen : ...\n"); } return err; }
/* * sra - set record attributes * * Right now I'm only allowing changes to file type and aux type. This * could be adapted to do more easily, but the command handler has a * rigid notion of how many arguments each function should have, so * you'd need to list all of them every time. */ static NuError SetRecordAttrFunc(ExerciserState* pState, int argc, char** argv) { NuError err; const NuRecord* pRecord; NuRecordAttr recordAttr; (void) pState, (void) argc, (void) argv; /* shut up, gcc */ assert(ExerciserState_GetNuArchive(pState) != NULL); assert(argc == 4); err = NuGetRecord(ExerciserState_GetNuArchive(pState), strtol(argv[1], NULL, 0), &pRecord); if (err != kNuErrNone) return err; printf("Exerciser: NuGetRecord succeeded, calling NuSetRecordAttr\n"); NuRecordCopyAttr(&recordAttr, pRecord); recordAttr.fileType = strtol(argv[2], NULL, 0); recordAttr.extraType = strtol(argv[3], NULL, 0); /*recordAttr.fileSysInfo = ':';*/ return NuSetRecordAttr(ExerciserState_GetNuArchive(pState), strtol(argv[1], NULL, 0), &recordAttr); }
/* * 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; }