/* tsoscan - IFF statistical webpage generator tsoscan.c - Copyright (c) 2012 Niotso Project Author(s): Ahmed El-Mahdawy Fatbag Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include #include #include #include "tsoscan.h" static void print_usage(){ printf("Usage: tsoscan [-f] [-o outfile] indir1 [indir2 [...]]\n" "Generate a statistical HTML page based on a number of IFF files.\n" "Use -f to force overwriting without confirmation.\n" "If outfile is unspecified, the output HTML page will be written to stats.html.\n" "\n" "Report bugs to .\n" "tsoscan is maintained by the Niotso project.\n" "Home page: \n"); } int main(int argc, char *argv[]){ CommandLineArgs *CmdArgs; unsigned i, version, FileCount = 0; char **Files = NULL; IFFStats Stats; FILE *OutFile; if(!stats_create(&Stats)){ fprintf(stderr, "%sUnable to allocate enough memory.\n", TSOSCAN_ERROR); return -1; } if(argc == 1 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")){ print_usage(); return 0; } CmdArgs = cmd_parse_args(argc, argv); if(CmdArgs == NULL || CmdArgs->InDirCount == 0){ print_usage(); return -1; } if(CmdArgs->OutFile == NULL){ CmdArgs->OutFile = "stats.html"; } /**** ** List selected input directories */ for(i=0; iInDirCount; i++){ DIR *dir = opendir(CmdArgs->InDirs[i]); struct dirent *entry; unsigned DirStartIndex; if(dir == NULL){ fprintf(stderr, "%sUnable to open the specified directory '%s'. Skipping.\n", TSOSCAN_WARNING, CmdArgs->InDirs[i]); continue; } DirStartIndex = FileCount; while((entry = readdir(dir)) != NULL){ if(strcmp(entry->d_name, ".") && strcmp(entry->d_name, "..")) FileCount++; } rewinddir(dir); Files = realloc(Files, FileCount*sizeof(char**)); if(Files == NULL){ fprintf(stderr, "%sUnable to allocate enough memory.\n", TSOSCAN_ERROR); return -1; } for(; DirStartIndexd_name, ".") && strcmp(entry->d_name, "..")){ int dirlen = strlen(CmdArgs->InDirs[i]); int pathlen = strlen(entry->d_name); Files[DirStartIndex] = malloc(dirlen+pathlen+2); if(Files[DirStartIndex] == NULL){ fprintf(stderr, "%sUnable to allocate enough memory.\n", TSOSCAN_ERROR); return -1; } memcpy(Files[DirStartIndex], CmdArgs->InDirs[i], dirlen); Files[DirStartIndex][dirlen] = PATH_SEP; memcpy(Files[DirStartIndex]+dirlen+1, entry->d_name, pathlen); Files[DirStartIndex][dirlen+pathlen+1] = '\0'; DirStartIndex++; } } closedir(dir); } /**** ** Load and parse IFF files */ for(i=0; iType, ChunkData->Data); if(!stats_version_increment(&Stats, ChunkData->Type, version)){ fprintf(stderr, "%sUnable to allocate enough memory.\n", TSOSCAN_ERROR); return -1; } } iff_delete(&iff); } /**** ** Write output file */ if(!CmdArgs->ForceWrite){ OutFile = fopen(CmdArgs->OutFile, "rb"); if(OutFile != NULL){ char c; fclose(OutFile); printf("File \"%s\" exists. Continue anyway? (y/n) ", CmdArgs->OutFile); c = getchar(); if(c != 'y' && c != 'Y') return -1; } } OutFile = fopen(CmdArgs->OutFile, "wb"); if(OutFile == NULL){ fprintf(stderr, "%sThe output file '%s' could not be opened for writing.", TSOSCAN_ERROR, CmdArgs->OutFile); return -1; } fprintf(OutFile, "\n"); fprintf(OutFile, "\n"); fprintf(OutFile, "\n"); fprintf(OutFile, "\n"); fprintf(OutFile, "\n"); fprintf(OutFile, "\n"); fprintf(OutFile, "\n"); fprintf(OutFile, "\n"); fprintf(OutFile, "IFF Chunk Statistics (tsostats)\n"); fprintf(OutFile, "\n"); fprintf(OutFile, "\n"); fprintf(OutFile, "\n"); fprintf(OutFile, "

IFF Chunk Statistics (tsostats)

\n"); fprintf(OutFile, "
\n"); fprintf(OutFile, "\n"); fprintf(OutFile, "\n", Stats.FileCount); fprintf(OutFile, "\n", Stats.AverageChunkCount); fprintf(OutFile, "
Number of IFF files:%u
Average chunk count:%.1f
\n"); fprintf(OutFile, "
\n"); fprintf(OutFile, "
Contents – %u chunk types
\n", Stats.ChunkTypeCount); fprintf(OutFile, "
    \n"); for(i=0; i%u %s\n", i, i+1, Stats.ChunkTypes[i].Type); fprintf(OutFile, "
\n"); fprintf(OutFile, "
\n"); fprintf(OutFile, "\n"); for(i=0; i%u %s (Jump)\n", i, i+1, Stats.ChunkTypes[i].Type, i); fprintf(OutFile, "
\n"); fprintf(OutFile, "\n"); fprintf(OutFile, "\n", chunk->ChunkCount); if(chunk->VersionCount == 1 && chunk->Versions[0].Version == (unsigned)-1) fprintf(OutFile, "\n"); else fprintf(OutFile, "\n", chunk->VersionCount); fprintf(OutFile, "
Number of occurrences:%u
Number of versions:N/A
Number of versions:%u
\n"); if(chunk->VersionCount > 1 || (chunk->VersionCount == 1 && chunk->Versions[0].Version != (unsigned)-1)){ fprintf(OutFile, "\n"); fprintf(OutFile, "\n"); for(version=0; versionVersionCount; version++){ VersionInfo *verinfo = chunk->Versions+version; float percentage = (float)verinfo->Count / chunk->ChunkCount * 100; fprintf(OutFile, "\n", version+1, verinfo->Version, verinfo->Version, verinfo->Count, percentage); } fprintf(OutFile, "
VersionCount
%u%u (0x%x)%u (%.1f%%)
\n"); } fprintf(OutFile, "
\n\n"); } fprintf(OutFile, "
This page was generated by the use of tsostats.
\n"); fprintf(OutFile, "\n"); fprintf(OutFile, ""); fclose(OutFile); printf("Generated statistics based on %u IFF files.\n", Stats.FileCount); cmd_delete(CmdArgs); stats_delete(&Stats); return 0; }