nicer formatting, etc.

This commit is contained in:
David Rose 2004-10-25 23:04:10 +00:00
parent 073f6bf261
commit b937aef183
5 changed files with 70 additions and 47 deletions

View File

@ -28,8 +28,10 @@ ConfigVariableBase(const string &name,
ConfigVariableBase::ValueType value_type) : ConfigVariableBase::ValueType value_type) :
_core(ConfigVariableManager::get_global_ptr()->make_variable(name)) _core(ConfigVariableManager::get_global_ptr()->make_variable(name))
{ {
if (value_type != VT_undefined) {
_core->set_value_type(value_type); _core->set_value_type(value_type);
} }
}
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: ConfigVariableBase::Destructor // Function: ConfigVariableBase::Destructor

View File

@ -30,7 +30,9 @@ ConfigVariableBase(const string &name,
const string &description, int flags) : const string &description, int flags) :
_core(ConfigVariableManager::get_global_ptr()->make_variable(name)) _core(ConfigVariableManager::get_global_ptr()->make_variable(name))
{ {
if (value_type != VT_undefined) {
_core->set_value_type(value_type); _core->set_value_type(value_type);
}
if (flags != 0) { if (flags != 0) {
_core->set_flags(flags); _core->set_flags(flags);
} }

View File

@ -340,6 +340,10 @@ write(ostream &out) const {
out << " " << *(*di) out << " " << *(*di)
<< " (from " << (*di)->get_page()->get_name() << ", untrusted)\n"; << " (from " << (*di)->get_page()->get_name() << ", untrusted)\n";
} }
if (!_description.empty()) {
out << "\n" << _description << "\n";
}
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////

View File

@ -117,20 +117,14 @@ output(ostream &out) const {
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void ConfigVariableManager:: void ConfigVariableManager::
write(ostream &out) const { write(ostream &out) const {
out << "ConfigVariableManager, " << _variables.size() << " variables:\n";
VariablesByName::const_iterator ni; VariablesByName::const_iterator ni;
for (ni = _variables_by_name.begin(); for (ni = _variables_by_name.begin();
ni != _variables_by_name.end(); ni != _variables_by_name.end();
++ni) { ++ni) {
ConfigVariableCore *variable = (*ni).second; ConfigVariableCore *variable = (*ni).second;
if (!variable->is_dynamic()) { if (variable->get_num_trusted_references() != 0 ||
out << " " << variable->get_name(); variable->has_local_value()) {
if (!variable->is_used()) { list_variable(variable, false);
out << " (not used)";
} else {
out << " " << variable->get_declaration(0)->get_string_value();
}
out << "\n";
} }
} }
} }
@ -175,7 +169,7 @@ list_variables() const {
++ni) { ++ni) {
const ConfigVariableCore *variable = (*ni).second; const ConfigVariableCore *variable = (*ni).second;
if (variable->is_used() && !variable->is_dynamic()) { if (variable->is_used() && !variable->is_dynamic()) {
list_variable(variable); list_variable(variable, true);
} }
} }
} }
@ -197,7 +191,7 @@ list_dynamic_variables() const {
++ni) { ++ni) {
const ConfigVariableCore *variable = (*ni).second; const ConfigVariableCore *variable = (*ni).second;
if (variable->is_used() && variable->is_dynamic()) { if (variable->is_used() && variable->is_dynamic()) {
list_variable(variable); list_variable(variable, false);
} }
} }
} }
@ -221,13 +215,30 @@ get_global_ptr() {
// Description: Lists a single variable and its value. // Description: Lists a single variable and its value.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void ConfigVariableManager:: void ConfigVariableManager::
list_variable(const ConfigVariableCore *variable) const { list_variable(const ConfigVariableCore *variable,
bool include_descriptions) const {
if (!variable->is_used()) {
// If the variable is unused, just show its name.
nout << variable->get_name() << " not used";
if (variable->get_num_references() > 0) {
nout << " (referenced in "
<< variable->get_reference(0)->get_page()->get_name()
<< ")";
}
nout << "\n";
} else {
// If the variable is used--it's been defined somewhere--show its
// name, its type, its current and default values, and if
// available, its description.
nout << variable->get_name() << " " nout << variable->get_name() << " "
<< variable->get_value_type() << "\n"; << variable->get_value_type() << "\n";
const ConfigDeclaration *decl; const ConfigDeclaration *decl;
if (variable->get_value_type() == ConfigVariableCore::VT_list) { if (variable->get_value_type() == ConfigVariableCore::VT_list ||
variable->get_value_type() == ConfigVariableCore::VT_search_path) {
// We treat a "list" variable as a special case: list all of // We treat a "list" variable as a special case: list all of
// its values. // its values.
nout << " current value =\n"; nout << " current value =\n";
@ -258,7 +269,10 @@ list_variable(const ConfigVariableCore *variable) const {
} }
} }
if (!variable->get_description().empty()) { if (!variable->get_description().empty() && include_descriptions) {
nout << " " << variable->get_description() << "\n"; nout << " " << variable->get_description() << "\n";
} }
} }
nout << "\n";
}

View File

@ -55,7 +55,8 @@ PUBLISHED:
static ConfigVariableManager *get_global_ptr(); static ConfigVariableManager *get_global_ptr();
private: private:
void list_variable(const ConfigVariableCore *variable) const; void list_variable(const ConfigVariableCore *variable,
bool include_descriptions) const;
typedef pvector<ConfigVariableCore *> Variables; typedef pvector<ConfigVariableCore *> Variables;
Variables _variables; Variables _variables;