cd2b21c6290f3097cf51038595366a83a580dab1
[SXSI/TextCollection.git] / incbwt / utils / convert_patterns.cpp
1 #include <fstream>
2 #include <iostream>
3 #include <vector>
4
5 #include "../misc/definitions.h"
6 #include "../misc/utils.h"
7
8
9 using namespace CSA;
10
11
12 int
13 main(int argc, char** argv)
14 {
15   std::cout << "Converting lines into a patterns file in Pizza & Chili format" << std::endl;
16   if(argc < 3)
17   {
18     std::cout << "Usage: convert_patterns input output" << std::endl;
19     return 1;
20   }
21
22   std::cout << "Input file: " << argv[1] << std::endl;
23   std::ifstream input_file(argv[1], std::ios_base::binary);
24   if(!input_file)
25   {
26     std::cerr << "Error opening input file!" << std::endl;
27     return 2;
28   }
29
30   std::cout << "Output file: " << argv[2] << std::endl;
31   std::ofstream output_file(argv[2], std::ios_base::binary);
32   if(!output_file)
33   {
34     std::cerr << "Error creating output file!" << std::endl;
35     return 3;
36   }
37   std::cout << std::endl;
38
39   std::vector<std::string> rows;
40   readRows(input_file, rows, true);
41
42   usint patterns = rows.size();
43   usint pattern_length = (*(rows.begin())).length();
44   std::cout << "Number of patterns: " << patterns << std::endl;
45   std::cout << "Pattern length:     " << pattern_length << std::endl;
46   std::cout << std::endl;
47
48   output_file << "# number=" << patterns << " length=" << pattern_length << " file=foo forbidden=" << std::endl;
49   for(std::vector<std::string>::iterator iter = rows.begin(); iter != rows.end(); iter++)
50   {
51     output_file.write((*iter).c_str(), pattern_length);
52   }
53
54   output_file.close();
55   input_file.close();
56   return 0;
57 }