This file is indexed.

/usr/include/wibble/commandline/engine.h is in libwibble-dev 1.1-1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#ifndef WIBBLE_COMMANDLINE_ENGINE_H
#define WIBBLE_COMMANDLINE_ENGINE_H

#include <wibble/commandline/options.h>
#include <string>
#include <vector>
#include <map>
#include <iosfwd>

namespace wibble {
namespace commandline {

#if 0
  -- This help is left around to be reintegrated when I found something
	 appropriate.  It documents the general behavior of functions in the form
	 ArgList::iterator parse(ArgList& list, ArgList::iterator begin);

	/**
	 * Parse the list of arguments, starting at 'begin' and removing the
	 * arguments it successfully parses.
	 *
	 * The 'begin' iterator can be invalidated by this function.
	 *
	 * @returns
	 *   An iterator to the first unparsed argument (can be list.end())
	 */
#endif

/**
 * Parse commandline options.
 *
 * Normally it parses short or long switches all starting with '-'
 *
 * If other engines are added, then looks in the commandline for a non-switch
 * command to select the operation mode.  This allow to have a custom set of
 * commandline options for every non-switch command.
 */
class Engine : public Managed
{
	MemoryManager* m_manager;
	std::string m_name;

protected:
	// Elements added to this engine
	std::vector<OptionGroup*> m_groups;
	std::vector<Option*> m_options;
	std::vector<Engine*> m_commands;

	// Parse tables for commandline options
	std::map<char, Option*> m_short;
	std::map<std::string, Option*> m_long;
	std::map<std::string, Engine*> m_aliases;

	// Command selected with the non-switch command, if any were found, else
	// NULL
	Engine* m_found_command;

	void addWithoutAna(Option* o);
	void addWithoutAna(const std::vector<Option*>& o);
	void add(const std::string& alias, Engine* o);

	// Rebuild the parse tables
	void rebuild();

	/**
	 * Handle the commandline switch at 'begin'.
	 *
	 * If the switch at 'begin' cannot be handled, the list is untouched and
	 * 'begin',false is returned.  Else, the switch is removed and the new begin is
	 * returned.
	 */
	std::pair<ArgList::iterator, bool> parseFirstIfKnown(ArgList& list, ArgList::iterator begin);

#if 0
	/// Parse a consecutive sequence of switches
	ArgList::iterator parseConsecutiveSwitches(ArgList& list, ArgList::iterator begin);
#endif

	/// Parse all known Options and leave the rest in list
	ArgList::iterator parseKnownSwitches(ArgList& list, ArgList::iterator begin);

	/**
	 * Parse the list of arguments, starting at the beginning and removing the
	 * arguments it successfully parses.
	 *
	 * @returns
	 *   An iterator to the first unparsed argument (can be list.end())
	 */
	ArgList::iterator parseList(ArgList& list) { return parse(list, list.begin()); }

	/**
	 * Parse all the switches in list, leaving only the non-switch arguments or
	 * the arguments following "--"
	 */
	ArgList::iterator parse(ArgList& list, ArgList::iterator begin);


	Engine(MemoryManager* mman = 0, const std::string& name = std::string(),
					const std::string& usage = std::string(),
					const std::string& description = std::string(),
					const std::string& longDescription = std::string())
		: m_manager(mman), m_name(name), m_found_command(0), primaryAlias(name),
			usage(usage), description(description), longDescription(longDescription), hidden(false),
			no_switches_after_first_arg(false) {}

public:
	const std::string& name() const { return m_name; }

	/// Add an Option to this engine
	Option* add(Option* o);

	/// Add an OptionGroup to this engine
	OptionGroup* add(OptionGroup* group);

	/// Add a Engine to this engine
	Engine* add(Engine* o);

	/**
	 * Create an option
	 */
	template<typename T>
	T* create(const std::string& name,
			char shortName,
			const std::string& longName,
			const std::string& usage = std::string(),
			const std::string& description = std::string())
	{
		T* item = new T(name, shortName, longName, usage, description);
		if (m_manager) m_manager->add(item);
		return item;
	}

	/**
	 * Create an option and add to this engine
	 */
	template<typename T>
	T* add(const std::string& name,
			char shortName,
			const std::string& longName,
			const std::string& usage = std::string(),
			const std::string& description = std::string())
	{
		T* res = create<T>(name, shortName, longName, usage, description);
		add(res);
		return res;
	}

	/**
	 * Create an OptionGroup
	 */
	OptionGroup* createGroup(const std::string& description)
	{
		OptionGroup* g = new OptionGroup(m_manager, description);
		if (m_manager) m_manager->add(g);
		return g;
	}

	/**
	 * Create an OptionGroup and add it to this engine
	 */
	OptionGroup* addGroup(const std::string& description)
	{
		return add(createGroup(description));
	}

	/**
	 * Create a Engine
	 */
	Engine* createEngine(const std::string& name,
					const std::string& usage = std::string(),
					const std::string& description = std::string(),
					const std::string& longDescription = std::string())
	{
		Engine* item = new Engine(m_manager, name, usage, description, longDescription);
		if (m_manager) m_manager->add(item);
		return item;
	}

	/**
	 * Create a Engine and add it to this engine as a command
	 */
	Engine* addEngine(const std::string& name,
					const std::string& usage = std::string(),
					const std::string& description = std::string(),
					const std::string& longDescription = std::string())
	{
		return add(createEngine(name, usage, description, longDescription));
	}

	/// Get the OptionGroups that have been added to this engine
	const std::vector<OptionGroup*>& groups() const { return m_groups; }

	/// Get the Options that have been added to this engine
	const std::vector<Option*>& options() const { return m_options; }

	/// Get the Engines that have been added to this engine
	const std::vector<Engine*>& commands() const { return m_commands; }

	Engine* command(const std::string& name) const
	{
		std::map<std::string, Engine*>::const_iterator i = m_aliases.find(name);
		if (i == m_aliases.end())
			return 0;
		else
			return i->second;
	}

	/// Returns true if this Engine has options to parse
	bool hasOptions() const { return !m_groups.empty() || !m_options.empty(); }

	/**
	 * Return the command that has been found in the commandline, or NULL if
	 * none have been found
	 */
	Engine* foundCommand() const { return m_found_command; }


	void dump(std::ostream& out, const std::string& prefix = std::string());

	std::string primaryAlias;
	std::vector<std::string> aliases;
	std::string usage;
	std::string description;
	std::string longDescription;
	std::string examples;

	// Set to true if the engine should not be documented
	bool hidden;

	// Set to true if no switches should be parsed after the first
	// non-switch argument, and they should be just left in the argument
	// list
	bool no_switches_after_first_arg;


	friend class Parser;
};

}
}

// vim:set ts=4 sw=4:
#endif