00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifdef HAVE_CONFIG_H
00027 #include <config.h>
00028 #endif
00029
00030 #include <stdio.h>
00031 #include <iostream>
00032 #include <string>
00033 #include <cstdlib>
00034
00035 #include "RIFF.h"
00036
00037 using namespace std;
00038
00039 string Revision();
00040 void PrintVersion();
00041 void PrintUsage();
00042 void PrintChunkList(RIFF::List* list, bool PrintSize);
00043
00044 int main(int argc, char *argv[])
00045 {
00046 int FileArgIndex = 1;
00047 bool bPrintSize = false;
00048
00049 if (argc <= 1) {
00050 PrintUsage();
00051 return EXIT_FAILURE;
00052 }
00053 if (argv[1][0] == '-') {
00054 switch (argv[1][1]) {
00055 case 's':
00056 bPrintSize = true;
00057 break;
00058 case 'v':
00059 PrintVersion();
00060 return EXIT_SUCCESS;
00061 default:
00062 cerr << "Unknown option -" << argv[1][1] << endl;
00063 cerr << endl;
00064 PrintUsage();
00065 return EXIT_FAILURE;
00066 }
00067 FileArgIndex++;
00068 }
00069 if (FileArgIndex >= argc) {
00070 PrintUsage();
00071 return EXIT_FAILURE;
00072 }
00073 FILE* hFile = fopen(argv[FileArgIndex], "r");
00074 if (!hFile) {
00075 cout << "Invalid file argument!" << endl;
00076 return EXIT_FAILURE;
00077 }
00078 fclose(hFile);
00079 try {
00080 RIFF::File* riff = new RIFF::File(argv[FileArgIndex]);
00081 cout << "RIFF(" << riff->GetListTypeString() << ")->";
00082 if (bPrintSize) cout << " (" << riff->GetSize() << " Bytes)";
00083 cout << endl;
00084 PrintChunkList(riff, bPrintSize);
00085 delete riff;
00086 }
00087 catch (RIFF::Exception e) {
00088 e.PrintMessage();
00089 return EXIT_FAILURE;
00090 }
00091 catch (...) {
00092 cout << "Unknown exception while trying to parse file." << endl;
00093 return EXIT_FAILURE;
00094 }
00095
00096 return EXIT_SUCCESS;
00097 }
00098
00099 void PrintChunkList(RIFF::List* list, bool PrintSize) {
00100 RIFF::Chunk* ck = list->GetFirstSubChunk();
00101 while (ck != NULL) {
00102 RIFF::Chunk* ckParent = ck;
00103 while (ckParent->GetParent() != NULL) {
00104 cout << " ";
00105 ckParent = ckParent->GetParent();
00106 }
00107 cout << ck->GetChunkIDString();
00108 switch (ck->GetChunkID()) {
00109 case CHUNK_ID_LIST: case CHUNK_ID_RIFF:
00110 {
00111 RIFF::List* l = (RIFF::List*) ck;
00112 cout << "(" << l->GetListTypeString() << ")->";
00113 if (PrintSize) cout << " (" << l->GetSize() << " Bytes)";
00114 cout << endl;
00115 PrintChunkList(l, PrintSize);
00116 break;
00117 }
00118 default:
00119 cout << ";";
00120 if (PrintSize) cout << " (" << ck->GetSize() << " Bytes)";
00121 cout << endl;
00122 }
00123 ck = list->GetNextSubChunk();
00124 }
00125 }
00126
00127 string Revision() {
00128 string s = "$Revision: 1.4 $";
00129 return s.substr(11, s.size() - 13);
00130 }
00131
00132 void PrintVersion() {
00133 cout << "rifftree revision " << Revision() << endl;
00134 cout << "using " << RIFF::libraryName() << " " << RIFF::libraryVersion() << endl;
00135 }
00136
00137 void PrintUsage() {
00138 cout << "rifftree - parses an arbitrary RIFF file and prints out the RIFF tree structure." << endl;
00139 cout << endl;
00140 cout << "Usage: rifftree [-s|-v] FILE" << endl;
00141 cout << endl;
00142 cout << " -s Print the size of each chunk." << endl;
00143 cout << " -v Print version and exit." << endl;
00144 cout << endl;
00145 }