File: gen-example-config.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 (59 lines) | stat: -rw-r--r-- 1,341 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <sstream>

#include "split.h"

std::string to80Columns(std::string input)
{
	std::istringstream s(input);
	const std::string prefix = "#";
	const int limit = 80;
	std::string result;
	std::string curline = prefix;

	std::string word;
	while (s >> word) {
		if (curline.length() + 1 + word.length() < limit) {
			curline += ' ' + word;
		} else {
			result += curline + '\n';
			curline = prefix + ' ' + word;
		}
	}

	result += curline + '\n';

	return result;
}

int main()
{
	std::cout << "#\n";
	std::cout << "# Newsboat's example config\n";
	std::cout << "#\n\n";

	for (std::string line; std::getline(std::cin, line);) {
		const std::vector<std::string> matches = split(line, "||");
		if (matches.size() == 5) {
			const std::string option = matches[0];
			const std::string syntax = matches[1];
			const std::string defaultparam = matches[2];
			const std::string desc = matches[3];
			const std::string example = matches[4];

			std::cout << "####  " << option << '\n';
			std::cout << "#\n";
			std::cout << to80Columns(std::move(desc));
			std::cout << "#\n";
			std::cout << "# Syntax: " << syntax << '\n';
			std::cout << "#\n";
			std::cout << "# Default value: " << defaultparam
				<< '\n';
			std::cout << "#\n";
			std::cout << "# " << example << '\n';
			std::cout << '\n';
		}
	}

	return 0;
}