/[svn]/libgig/trunk/src/rifftree.cpp
ViewVC logotype

Contents of /libgig/trunk/src/rifftree.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations) (download)
Sat Oct 25 20:15:04 2003 UTC (20 years, 6 months ago) by schoenebeck
File size: 4422 byte(s)
Initial revision

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

  ViewVC Help
Powered by ViewVC