findDoxytag.cpp 1.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <boost/algorithm/string.hpp>

int main(int argc, char *argv[]) {
	if (argc < 2) {
		std::cerr << "### no argument given to find the tag for..." << std::endl;
		return 1;
	}
	
	std::string memberName(argv[1]);
	std::ifstream inFile("xerus.tags");
	std::string line;
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
	std::size_t jumpSize = 100;
	// seek rough position
	auto lastPos = inFile.tellg();
	while (!inFile.eof()) {
		lastPos = inFile.tellg();
		for (size_t i=0; i<jumpSize; ++i) {
			std::getline(inFile, line);
		}
		std::vector<std::string> parts;
		boost::split(parts, line, boost::is_any_of("\t"));
		if (parts[0] == memberName) {
			std::cout << parts[1] << std::endl;
			return 0;
		}
		if (parts[0] > memberName) {
			inFile.seekg(lastPos);
			jumpSize /= 10;
			if (jumpSize == 1) {
				break;
			}
		}
	}
	if (inFile.eof()) {
		inFile.clear();
		inFile.seekg(lastPos);
	}
	
43 44 45 46 47 48 49 50 51 52 53 54
	while (std::getline(inFile, line)) {
		std::vector<std::string> parts;
		boost::split(parts, line, boost::is_any_of("\t"));
		if (parts[0] == memberName) {
			std::cout << parts[1] << std::endl;
			return 0;
		}
	}
	
	std::cerr << "### '" << memberName << "' not found in xerus.tags" << std::endl;
	return 2;
}