File: generate2.cpp

package info (click to toggle)
newsboat 2.38-0.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,540 kB
  • sloc: cpp: 90,216; xml: 606; sh: 429; makefile: 369; ruby: 258; python: 239; ansic: 211; php: 63; awk: 59; perl: 38
file content (42 lines) | stat: -rw-r--r-- 950 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
#include <fstream>
#include <iostream>

#include "split.h"

int main(int argc, char* argv[])
{
	if (argc < 2) {
		std::cerr << "usage: " << argv[0]
			<< " <dsv-file> [<link-prefix>]\n";
		return 1;
	}

	std::ifstream input(argv[1]);
	if (!input.is_open()) {
		std::cerr << "couldn't open " << argv[1] << '\n';
		return 1;
	}

	int lineno = 0;
	for (std::string line; std::getline(input, line);) {
		++lineno;
		const std::vector<std::string> matches = split(line, "||");
		if (matches.size() == 3) {
			const std::string cmd = matches[0];
			const std::string key = matches[1];
			const std::string desc = matches[2];

			std::cout << "_" << cmd << "_ ";
			std::cout << "(default key: _" << key << "_)::\n";
			std::cout << "         " << desc << "\n\n";
		} else {
			std::cerr << "expected exactly 3 cells in " << argv[1]
				<< ":" << lineno;
			std::cerr << ", but got " << matches.size()
				<< " instead\n";
			return 1;
		}
	}

	return 0;
}