Mercurial > hg > dmlib
comparison tools/fanalyze.c @ 2396:679732e4cfed
Implement counting of matching files for each match sequence.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 10 Jan 2020 01:23:02 +0200 |
parents | 647671a9a0b8 |
children | b7cd5dd0b82e |
comparison
equal
deleted
inserted
replaced
2395:e149fc273f2b | 2396:679732e4cfed |
---|---|
50 char *filename; | 50 char *filename; |
51 Uint8 *data; | 51 Uint8 *data; |
52 size_t size; | 52 size_t size; |
53 DMStats stats; | 53 DMStats stats; |
54 BOOL analyzed; | 54 BOOL analyzed; |
55 size_t index; | |
55 } DMSourceFile; | 56 } DMSourceFile; |
56 | 57 |
57 | 58 |
58 typedef struct | 59 typedef struct |
59 { | 60 { |
526 | 527 |
527 BOOL argHandleNonOpt(char *currArg) | 528 BOOL argHandleNonOpt(char *currArg) |
528 { | 529 { |
529 if (nsrcFiles < SET_MAX_FILES) | 530 if (nsrcFiles < SET_MAX_FILES) |
530 { | 531 { |
531 DMSourceFile *file = &srcFiles[nsrcFiles++]; | 532 DMSourceFile *file = &srcFiles[nsrcFiles]; |
532 file->filename = currArg; | 533 file->filename = currArg; |
534 file->index = nsrcFiles; | |
535 nsrcFiles++; | |
533 return TRUE; | 536 return TRUE; |
534 } | 537 } |
535 else | 538 else |
536 { | 539 { |
537 dmErrorMsg("Maximum number of input files exceeded (%d).\n", | 540 dmErrorMsg("Maximum number of input files exceeded (%d).\n", |
639 | 642 |
640 | 643 |
641 int main(int argc, char *argv[]) | 644 int main(int argc, char *argv[]) |
642 { | 645 { |
643 DMCompElem *compBuf = NULL; | 646 DMCompElem *compBuf = NULL; |
644 size_t compBufSize = 0, totalSize = 0; | 647 size_t compBufSize = 0, totalSize = 0, fileFlagsSize; |
648 BOOL *fileFlags = NULL; | |
645 int res; | 649 int res; |
646 | 650 |
647 memset(&dmSequences, 0, sizeof(dmSequences)); | 651 memset(&dmSequences, 0, sizeof(dmSequences)); |
648 | 652 |
649 dmInitProg("fanalyze", "Simple tool for file format analysis", | 653 dmInitProg("fanalyze", "Simple tool for file format analysis", |
658 exit(1); | 662 exit(1); |
659 | 663 |
660 if (nsrcFiles < 1) | 664 if (nsrcFiles < 1) |
661 { | 665 { |
662 dmErrorMsg("Nothing to do. (try --help)\n"); | 666 dmErrorMsg("Nothing to do. (try --help)\n"); |
667 goto out; | |
668 } | |
669 | |
670 // Allocate file flags | |
671 fileFlagsSize = sizeof(BOOL) * nsrcFiles; | |
672 if ((fileFlags = dmMalloc(fileFlagsSize)) == NULL) | |
673 { | |
674 dmErrorMsg("Could not allocate %" DM_PRIu_SIZE_T " bytes of memory for file flag array.\n", | |
675 fileFlagsSize); | |
663 goto out; | 676 goto out; |
664 } | 677 } |
665 | 678 |
666 // Read input files | 679 // Read input files |
667 for (int nfile = 0; nfile < nsrcFiles; nfile++) | 680 for (int nfile = 0; nfile < nsrcFiles; nfile++) |
1001 qsort(&seq->places, seq->nplaces, sizeof(DMMatchPlace), | 1014 qsort(&seq->places, seq->nplaces, sizeof(DMMatchPlace), |
1002 dmCompareMatchPlaces); | 1015 dmCompareMatchPlaces); |
1003 } | 1016 } |
1004 | 1017 |
1005 // | 1018 // |
1019 // Count number of files | |
1020 // | |
1021 for (int nmatch = 0; nmatch < ndmSequences; nmatch++) | |
1022 { | |
1023 DMMatchSeq *seq = &dmSequences[nmatch]; | |
1024 memset(fileFlags, 0, fileFlagsSize); | |
1025 | |
1026 for (int nplace = 0; nplace < seq->nplaces; nplace++) | |
1027 { | |
1028 DMMatchPlace *place = &seq->places[nplace]; | |
1029 if (!fileFlags[place->file->index]) | |
1030 { | |
1031 fileFlags[place->file->index] = TRUE; | |
1032 seq->nfiles++; | |
1033 } | |
1034 } | |
1035 } | |
1036 | |
1037 // | |
1006 // Display results | 1038 // Display results |
1007 // | 1039 // |
1008 dmPrint(0, "Found %d matching sequence groups of %" DM_PRIu_SIZE_T " bytes minimum.\n", | 1040 dmPrint(0, "Found %d matching sequence groups of %" DM_PRIu_SIZE_T " bytes minimum.\n", |
1009 ndmSequences, optMinMatchLen); | 1041 ndmSequences, optMinMatchLen); |
1010 | 1042 |
1011 for (int nmatch = 0; nmatch < ndmSequences; nmatch++) | 1043 for (int nmatch = 0; nmatch < ndmSequences; nmatch++) |
1012 { | 1044 { |
1013 DMMatchSeq *seq = &dmSequences[nmatch]; | 1045 DMMatchSeq *seq = &dmSequences[nmatch]; |
1014 | 1046 |
1015 printf("\nSeq of %" DM_PRIu_SIZE_T " bytes in %d places (%d files)\n", | 1047 printf("\nSeq of %" DM_PRIu_SIZE_T " bytes in %d places (in %d files)\n", |
1016 seq->len, seq->nplaces, seq->nfiles); | 1048 seq->len, seq->nplaces, seq->nfiles); |
1017 | 1049 |
1018 if (dmVerbosity > 0) | 1050 if (dmVerbosity > 0) |
1019 { | 1051 { |
1020 int n = 0; | 1052 int n = 0; |