summaryrefslogtreecommitdiff
path: root/bsd-core/drm_drv.c
diff options
context:
space:
mode:
Diffstat (limited to 'bsd-core/drm_drv.c')
0 files changed, 0 insertions, 0 deletions
9'>49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
#include <algorithm>

#include <unistd.h>
#include <getopt.h>

#include <kms++util/opts.h>

using namespace std;

Option::Option(const string& str, function<void()> func)
	: m_void_func(func)
{
	parse(str);
}

Option::Option(const string& str, function<void(const string)> func)
	: m_func(func)
{
	parse(str);
}

void Option::parse(const string& str)
{
	auto iend = str.end();
	if (*(iend - 1) == '=') {
		iend--;
		m_has_arg = 1;
	} else if (*(iend - 1) == '?') {
		iend--;
		m_has_arg = 2;
	} else {
		m_has_arg = 0;
	}

	auto isplit = find(str.begin(), iend, '|');

	if (isplit != str.begin())
		m_short = str[0];
	else
		m_short = 0;

	if (isplit != iend)
		m_long = string(isplit + 1, iend);
}

OptionSet::OptionSet(initializer_list<Option> il)
	: m_opts(il)
{
}

void OptionSet::parse(int argc, char** argv)
{
	string shortopts = ":";
	vector<struct option> longopts;

	for (unsigned opt_idx = 0; opt_idx < m_opts.size(); ++opt_idx) {
		const Option& o = m_opts[opt_idx];