summaryrefslogtreecommitdiff
path: root/libkms/kms-symbol-check
blob: 658b269265676de252708a03e90eb517eb2213ac (plain)
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
#!/bin/bash

# The following symbols (past the first five) are taken from the public headers.
# A list of the latter should be available Makefile.sources/LIBKMS_H_FILES

FUNCS=$(nm -D --format=bsd --defined-only ${1-.libs/libkms.so} | awk '{print $3}'| while read func; do
( grep -q "^$func$" || echo $func )  <<EOF
__bss_start
_edata
_end
_fini
_init
kms_bo_create
kms_bo_destroy
kms_bo_get_prop
kms_bo_map
kms_bo_unmap
kms_create
kms_destroy
kms_get_prop
EOF
done)

test ! -n "$FUNCS" || echo $FUNCS
test ! -n "$FUNCS"
a> 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
#pragma once

#include <cstdio>
#include <string>
#include <vector>
#include <map>

using namespace std;

#define NO_PARAM(h) (CmdOption(false, h))
#define HAS_PARAM(h) (CmdOption(true, h))

class CmdOption
{
public:
	CmdOption(bool has_param, string help) :
	        m_has_param(has_param), m_help(help), m_is_set(false) { }
        bool has_param() const { return m_has_param; }
	const string& help() const { return m_help; }

	void oset() { m_is_set = true; }
	void pset(const string& p) { m_param = p; oset(); }
        bool is_set() const { return m_is_set; }
        const string& param() const { return m_param; }
private:
	bool m_has_param;
	string m_help;

	bool m_is_set;
	string m_param;
};

class CmdOptions
{
public:
	CmdOptions(int argc, char **argv, map<string, CmdOption>& opts) :
		m_opts(opts), m_cmd(argv[0]) {
		for (int i = 1; i < argc; i++) {
			if (argv[i][0] == '-') {
				auto ii = m_opts.find(&argv[i][1]);
				if (ii == m_opts.end()) {
					m_error += m_cmd + ": " +
						string(argv[i]) +
						": unknown option\n";
					continue;
				}
				if ((*ii).second.has_param()) {
					if (++i == argc) {
						m_error += m_cmd + ": -" +
							(*ii).first +
							": parameter missing\n";
						continue;
					}
					(*ii).second.pset(argv[i]);
				} else {
					(*ii).second.oset();
				}
			} else {
				m_params.push_back(argv[i]);
			}
		}
	}
	const string& error() const { return m_error; }
	const string& cmd() const { return m_cmd; }

	bool is_set(const string& name) const {
		return m_opts.at(name).is_set();
	}
	const string& opt_param(const string& name) const {
		return m_opts.at(name).param();
	}
	const vector<string>& params() const { return m_params; }
	CmdOption& get_option(const string& name) { return m_opts.at(name); }

	int num_options() const {
		int ret(0);
		for (const auto& p : m_opts)
			if (p.second.is_set())
				ret++;
		return ret;
	}

	const string usage() const {
		string ret("usage:\n");
		for (const auto& p : m_opts)
			ret += "-" + p.first +
				(p.second.has_param() ? " <>: " : ": ") +
				p.second.help() + "\n";
		return ret;
	}

private:
	map<string, CmdOption>& m_opts;
	string m_cmd;
	vector<string> m_params;
	string m_error;
};