31 #define OLD_HEADER_SIZE 12 32 #define NEW_HEADER_SIZE 100 33 #define MIN_RECORD_SIZE 3 // type+0-length+FF 37 int main(
int argc,
char** argv) {
38 fprintf(stderr,
"\"%s\", version 2021-05-20. Copyright (c) 2021 Live Networks, Inc. All rights reserved.\n", argv[0]);
39 fprintf(stderr,
"For the latest version of this program (and more information), visit http://djilogs.live555.com\n");
43 fprintf(stderr,
"Usage: %s <txtFileName>\n", argv[0]);
46 char const* fileName = argv[fileNamePos];
48 FILE* fid = fopen(fileName,
"rb");
50 fprintf(stderr,
"Failed to open \"%s\"\n", fileName);
57 if (stat(fileName, &sb) == 0) {
58 fileSize = sb.st_size;
60 fprintf(stderr,
"Failed to get file size\n");
66 fprintf(stderr,
"Bad file size: %llu bytes\n", fileSize);
71 u_int8_t*
const mappedFile
72 = (u_int8_t*)mmap(0, fileSize, PROT_READ, MAP_SHARED, fileno(fid), 0);
73 if (mappedFile == MAP_FAILED) {
75 fprintf(stderr,
"mmap() call failed: %s\n", strerror(errno));
80 u_int64_t recordsAreaStart, recordsAreaEnd;
81 u_int64_t detailsAreaStart, detailsAreaEnd;
84 u_int8_t
const* ptr = mappedFile;
109 u_int64_t computedFileSize;
112 recordsAreaStart = headerSize + detailsAreaSize;
113 detailsAreaStart = headerSize;
114 detailsAreaEnd = detailsAreaStart + detailsAreaSize;
116 computedFileSize = recordsAreaEnd;
119 recordsAreaStart = headerSize;
120 detailsAreaStart = recordsAreaEnd;
121 detailsAreaEnd = detailsAreaStart + detailsAreaSize;
123 computedFileSize = detailsAreaEnd;
128 if (computedFileSize < minFileSize || computedFileSize > fileSize) {
129 fprintf(stderr,
"Bad 'recordsAreaEnd' %llu (0x%llx) and/or 'detailsAreaSize' %u (0x%x); file size is %llu\n",
130 recordsAreaEnd, recordsAreaEnd,
131 detailsAreaSize, detailsAreaSize,
140 ptr = &mappedFile[detailsAreaStart];
144 ptr = &mappedFile[recordsAreaStart];
145 u_int8_t*
const recordsAreaEndPtr = &mappedFile[recordsAreaEnd];
147 while (ptr < recordsAreaEndPtr) {
148 #ifdef DEBUG_RECORD_PARSING 149 u_int64_t curFilePosition = ptr - mappedFile;
150 fprintf(stderr,
"@0x%08llx: ", curFilePosition);
152 if (!parser->
parseRecord(ptr, recordsAreaEndPtr, isScrambled))
break;
154 if (ptr < recordsAreaEndPtr) {
155 u_int64_t curFilePosition = ptr - mappedFile;
156 fprintf(stderr,
"Premature end of record parsing at file position %llu (0x%08llx)\n", curFilePosition, curFilePosition);
163 fprintf(stderr,
"Done writing CSV.\n");
static DJITxtParser * createNew()
u_int64_t getWord64LE(u_int8_t const *&ptr, u_int8_t const *limit)
virtual void summarizeRecordParsing()=0
int main(int argc, char **argv)
virtual void outputOneRow(int outputColumnLabels=0)=0
u_int8_t fileVersionNumber
virtual void parseDetailsArea(u_int8_t const *&ptr, u_int8_t const *limit)=0
u_int16_t get2BytesLE(u_int8_t const *&ptr, u_int8_t const *limit)
virtual int parseRecord(u_int8_t const *&ptr, u_int8_t const *limit, int isScrambled)=0