1 |
schoenebeck |
2 |
/*************************************************************************** |
2 |
|
|
* * |
3 |
schoenebeck |
933 |
* libgig - C++ cross-platform Gigasampler format file access library * |
4 |
schoenebeck |
2 |
* * |
5 |
schoenebeck |
933 |
* Copyright (C) 2003-2006 by Christian Schoenebeck * |
6 |
schoenebeck |
518 |
* <cuse@users.sourceforge.net> * |
7 |
schoenebeck |
2 |
* * |
8 |
schoenebeck |
933 |
* This program is part of libgig. * |
9 |
|
|
* * |
10 |
schoenebeck |
2 |
* This program is free software; you can redistribute it and/or modify * |
11 |
|
|
* it under the terms of the GNU General Public License as published by * |
12 |
|
|
* the Free Software Foundation; either version 2 of the License, or * |
13 |
|
|
* (at your option) any later version. * |
14 |
|
|
* * |
15 |
|
|
* This program is distributed in the hope that it will be useful, * |
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
18 |
|
|
* GNU General Public License for more details. * |
19 |
|
|
* * |
20 |
|
|
* You should have received a copy of the GNU General Public License * |
21 |
|
|
* along with this program; if not, write to the Free Software * |
22 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
23 |
|
|
* MA 02111-1307 USA * |
24 |
|
|
***************************************************************************/ |
25 |
schoenebeck |
55 |
|
26 |
schoenebeck |
2 |
#ifdef HAVE_CONFIG_H |
27 |
|
|
#include <config.h> |
28 |
|
|
#endif |
29 |
|
|
|
30 |
|
|
#include <stdio.h> |
31 |
|
|
#include <iostream> |
32 |
schoenebeck |
518 |
#include <string> |
33 |
schoenebeck |
2 |
#include <cstdlib> |
34 |
|
|
|
35 |
|
|
#include "RIFF.h" |
36 |
|
|
|
37 |
|
|
using namespace std; |
38 |
|
|
|
39 |
schoenebeck |
518 |
string Revision(); |
40 |
|
|
void PrintVersion(); |
41 |
schoenebeck |
2 |
void PrintUsage(); |
42 |
|
|
void PrintChunkList(RIFF::List* list, bool PrintSize); |
43 |
|
|
|
44 |
|
|
int main(int argc, char *argv[]) |
45 |
|
|
{ |
46 |
|
|
int FileArgIndex = 1; |
47 |
|
|
bool bPrintSize = false; |
48 |
|
|
|
49 |
|
|
if (argc <= 1) { |
50 |
|
|
PrintUsage(); |
51 |
|
|
return EXIT_FAILURE; |
52 |
|
|
} |
53 |
schoenebeck |
518 |
if (argv[1][0] == '-') { |
54 |
|
|
switch (argv[1][1]) { |
55 |
|
|
case 's': |
56 |
|
|
bPrintSize = true; |
57 |
|
|
break; |
58 |
|
|
case 'v': |
59 |
|
|
PrintVersion(); |
60 |
|
|
return EXIT_SUCCESS; |
61 |
|
|
default: |
62 |
|
|
cerr << "Unknown option -" << argv[1][1] << endl; |
63 |
|
|
cerr << endl; |
64 |
|
|
PrintUsage(); |
65 |
|
|
return EXIT_FAILURE; |
66 |
schoenebeck |
2 |
} |
67 |
schoenebeck |
518 |
FileArgIndex++; |
68 |
schoenebeck |
2 |
} |
69 |
schoenebeck |
518 |
if (FileArgIndex >= argc) { |
70 |
|
|
PrintUsage(); |
71 |
|
|
return EXIT_FAILURE; |
72 |
|
|
} |
73 |
schoenebeck |
2 |
FILE* hFile = fopen(argv[FileArgIndex], "r"); |
74 |
|
|
if (!hFile) { |
75 |
|
|
cout << "Invalid file argument!" << endl; |
76 |
|
|
return EXIT_FAILURE; |
77 |
|
|
} |
78 |
|
|
fclose(hFile); |
79 |
|
|
try { |
80 |
|
|
RIFF::File* riff = new RIFF::File(argv[FileArgIndex]); |
81 |
|
|
cout << "RIFF(" << riff->GetListTypeString() << ")->"; |
82 |
|
|
if (bPrintSize) cout << " (" << riff->GetSize() << " Bytes)"; |
83 |
|
|
cout << endl; |
84 |
|
|
PrintChunkList(riff, bPrintSize); |
85 |
|
|
delete riff; |
86 |
|
|
} |
87 |
|
|
catch (RIFF::Exception e) { |
88 |
|
|
e.PrintMessage(); |
89 |
|
|
return EXIT_FAILURE; |
90 |
|
|
} |
91 |
|
|
catch (...) { |
92 |
|
|
cout << "Unknown exception while trying to parse file." << endl; |
93 |
|
|
return EXIT_FAILURE; |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
return EXIT_SUCCESS; |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
void PrintChunkList(RIFF::List* list, bool PrintSize) { |
100 |
|
|
RIFF::Chunk* ck = list->GetFirstSubChunk(); |
101 |
|
|
while (ck != NULL) { |
102 |
|
|
RIFF::Chunk* ckParent = ck; |
103 |
|
|
while (ckParent->GetParent() != NULL) { |
104 |
|
|
cout << " "; // e.g. 'LIST(INFO)->' |
105 |
|
|
ckParent = ckParent->GetParent(); |
106 |
|
|
} |
107 |
|
|
cout << ck->GetChunkIDString(); |
108 |
|
|
switch (ck->GetChunkID()) { |
109 |
|
|
case CHUNK_ID_LIST: case CHUNK_ID_RIFF: |
110 |
|
|
{ |
111 |
|
|
RIFF::List* l = (RIFF::List*) ck; |
112 |
|
|
cout << "(" << l->GetListTypeString() << ")->"; |
113 |
|
|
if (PrintSize) cout << " (" << l->GetSize() << " Bytes)"; |
114 |
|
|
cout << endl; |
115 |
|
|
PrintChunkList(l, PrintSize); |
116 |
|
|
break; |
117 |
|
|
} |
118 |
|
|
default: |
119 |
|
|
cout << ";"; |
120 |
|
|
if (PrintSize) cout << " (" << ck->GetSize() << " Bytes)"; |
121 |
|
|
cout << endl; |
122 |
|
|
} |
123 |
|
|
ck = list->GetNextSubChunk(); |
124 |
|
|
} |
125 |
|
|
} |
126 |
|
|
|
127 |
schoenebeck |
518 |
string Revision() { |
128 |
schoenebeck |
933 |
string s = "$Revision: 1.4 $"; |
129 |
schoenebeck |
518 |
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
130 |
|
|
} |
131 |
|
|
|
132 |
|
|
void PrintVersion() { |
133 |
|
|
cout << "rifftree revision " << Revision() << endl; |
134 |
|
|
cout << "using " << RIFF::libraryName() << " " << RIFF::libraryVersion() << endl; |
135 |
|
|
} |
136 |
|
|
|
137 |
schoenebeck |
2 |
void PrintUsage() { |
138 |
|
|
cout << "rifftree - parses an arbitrary RIFF file and prints out the RIFF tree structure." << endl; |
139 |
|
|
cout << endl; |
140 |
schoenebeck |
518 |
cout << "Usage: rifftree [-s|-v] FILE" << endl; |
141 |
schoenebeck |
2 |
cout << endl; |
142 |
|
|
cout << " -s Print the size of each chunk." << endl; |
143 |
schoenebeck |
518 |
cout << " -v Print version and exit." << endl; |
144 |
schoenebeck |
2 |
cout << endl; |
145 |
|
|
} |