turbonss/deps/cmph/cxxmph/cxxmph.cc

75 lines
1.8 KiB
C++
Raw Normal View History

// Copyright 2010 Google Inc. All Rights Reserved.
// Author: davi@google.com (Davi Reis)
#include <getopt.h>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
2011-05-16 02:47:42 +03:00
#include "mph_map.h"
#include "config.h"
using std::cerr;
using std::cout;
using std::endl;
using std::getline;
using std::ifstream;
using std::string;
using std::vector;
2011-05-16 02:47:42 +03:00
using cxxmph::mph_map;
void usage(const char* prg) {
2011-05-16 02:47:42 +03:00
cerr << "usage: " << prg << " [-v] [-h] [-V] <keys.txt>" << endl;
}
void usage_long(const char* prg) {
usage(prg);
cerr << " -h\t print this help message" << endl;
cerr << " -V\t print version number and exit" << endl;
cerr << " -v\t increase verbosity (may be used multiple times)" << endl;
}
int main(int argc, char** argv) {
int verbosity = 0;
while (1) {
2012-06-08 17:37:40 +03:00
char ch = (char)getopt(argc, argv, "hvV");
if (ch == -1) break;
switch (ch) {
case 'h':
usage_long(argv[0]);
return 0;
case 'V':
std::cout << VERSION << std::endl;
return 0;
case 'v':
++verbosity;
break;
}
}
if (optind != argc - 1) {
usage(argv[0]);
return 1;
}
vector<string> keys;
ifstream f(argv[optind]);
2012-06-08 17:37:40 +03:00
if (!f.is_open()) {
std::cerr << "Failed to open " << argv[optind] << std::endl;
exit(-1);
}
string buffer;
while (!getline(f, buffer).eof()) keys.push_back(buffer);
2012-04-15 06:03:00 +03:00
for (uint32_t i = 0; i < keys.size(); ++i) string s = keys[i];
2011-05-16 02:47:42 +03:00
mph_map<string, string> table;
2010-11-08 22:19:44 +02:00
2012-04-15 06:03:00 +03:00
for (uint32_t i = 0; i < keys.size(); ++i) table[keys[i]] = keys[i];
2011-05-16 02:47:42 +03:00
mph_map<string, string>::const_iterator it = table.begin();
mph_map<string, string>::const_iterator end = table.end();
for (int i = 0; it != end; ++it, ++i) {
cout << i << ": " << it->first
<<" -> " << it->second << endl;
}
}