1 /************
2 *
3 *   This file is part of a tool for reading 3D content in the PRC format.
4 *   Copyright (C) 2008 Orest Shardt <shardtor (at) gmail dot com>
5 *
6 *   This program is free software: you can redistribute it and/or modify
7 *   it under the terms of the GNU Lesser General Public License as published by
8 *   the Free Software Foundation, either version 3 of the License, or
9 *   (at your option) any later version.
10 *
11 *   This program is distributed in the hope that it will be useful,
12 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 *   GNU Lesser General Public License for more details.
15 *
16 *   You should have received a copy of the GNU Lesser General Public License
17 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 *
19 *************/
20 
21 #include <iostream>
22 #include <fstream>
23 #include <iomanip>
24 #include "bitData.h"
25 
26 using namespace std;
27 
main(int argc,char * argv[])28 int main(int argc, char *argv[])
29 {
30   if(argc < 2)
31   {
32     cerr << "Error: Input file not specified." << endl;
33     return 1;
34   }
35   ifstream inFile(argv[1]);
36   if(!inFile)
37   {
38     cerr << "Error: Cannot open input file." << endl;
39     return 1;
40   }
41   inFile.seekg(0,ios::end);
42   unsigned int length = inFile.tellg();
43   inFile.seekg(0,ios::beg);
44 
45   char *buf = new char[length];
46 
47   inFile.read(buf,length);
48   BitByBitData bbbd(buf,length);
49 
50   unsigned int uisf;
51   cout << "Unsigned int to search for: "; cin >> uisf;
52   BitPosition currP;
53   for(currP.byteIndex = 0; currP.byteIndex < length; ++currP.byteIndex)
54     for(currP.bitIndex = 0; currP.bitIndex < 8; ++currP.bitIndex)
55     {
56       bbbd.setPosition(currP);
57       if(bbbd.readUnsignedInt() == uisf)
58       {
59         cout << "Found " << uisf << " at " << currP.byteIndex << ':'
60             << currP.bitIndex << endl;
61       }
62     }
63   delete[] buf;
64   return 0;
65 }
66