---
name: "Configuration"
section: "3"
platform: "linux"
package: "libmifluz0-dev"
version: "0.24.0-9"
release: "Debian 3.1 (Sarge)"
platforms: ["linux"]
url: "https://new.carta.tech/Configuration"
---

# Configuration(3)

reads the configuration file and manages it in memory.

## NAME

Configuration -

reads the configuration file and manages it in memory.

## SYNOPSIS

```
#include <Configuration.h>
Configuration config;
ConfigDefault config_defaults = {
  { "verbose", "true" },
  { 0, 0 }
};
config.Defaults(config_defaults);
config.Read("/spare2/myconfig") ;
config.Add("sync", "false");
if(config["sync"]) ...
if(config.Value("rate") < 50) ...
if(config.Boolean("sync")) ...
```

## DESCRIPTION

The primary purpose of the **Configuration** class is to parse a configuration file and allow the application to modify the internal data structure produced. All values are strings and are converted by the  appropriate accessors. For instance the **Boolean** method will  return numerical true (not zero) if the string either contains  a number that is different from zero or the string *true*

The *ConfigDefaults* type is a structure of two char pointers: the name of the configuration attribute and it's value. The end of the array is the first entry that contains a null pointer instead of the attribute name. Numerical values must be in strings. For instance:

```
ConfigDefault* config_defaults = {
  { "wordlist_compress", "true" },
  { "wordlist_page_size", "8192" },
  { 0, 0 }
};
```

The additional fields of the **ConfigDefault** are purely informative.

## FILE FORMAT

The configuration file is a plain ASCII text file. Each line in the file is either a comment or an attribute. Comment lines are blank lines or lines that start with a '#'. Attributes consist of a variable name and an associated value:

```
<name>:<whitespace><value><newline>
```

The \<name\> contains any alphanumeric character or underline (\_) The \<value\> can include any character except newline. It also cannot start with spaces or tabs since those are considered part of the whitespace after the colon. It is important to keep in mind that any trailing spaces or tabs will be included.

It is possible to split the \<value\> across several lines of the configuration file by ending each line with a backslash (. The effect on the value is that a space is added where the line split occurs.

A configuration file can include another file, by using the special \<name\>, \<tt\>include\</tt\>. The \<value\> is taken as the file name of another configuration file to be read in at this point. If the given file name is not fully qualified, it is taken relative to the directory in which the current configuration file is found. Variable expansion is permitted in the file name. Multiple include statements, and nested includes are also permitted.

```
include: common.conf
```

## METHODS

- **Configuration()**

  Constructor

- **~Configuration()**

  Destructor

- **void Add(const String& str)**

  Add configuration item **str** to the configuration. The value associated with it is undefined.

- **void Add(const String& name, const String& value)**

  Add configuration item **name** to the configuration and associate it with **value**

- **int Remove(const String& name)**

  Remove the **name** from the configuration.

- **void NameValueSeparators(const String& s)**

  Let the Configuration know how to parse name value pairs. Each character of string **s** is a valid separator between the *name* and the *value.*

- **virtual int Read(const String& filename)**

  Read name/value configuration pairs from the file **filename**

- **const String Find(const String& name) const**

  Return the value of configuration attribute **name** as a *String*

- **const String operator\[\](const String& name) const**

  Alias to the **Find** method.

- **int Value(const String& name, int default\_value = 0) const**

  Return the value associated with the configuration attribute **name** , converted to integer using the [atoi(3)](/atoi/3.md) function. If the attribute is not found in the configuration and  a **default\_value** is provided, return it.

- **double Double(const String& name, double default\_value = 0) const**

  Return the value associated with the configuration attribute **name** , converted to double using the [atof(3)](/atof/3.md) function. If the attribute is not found in the configuration and  a **default\_value** is provided, return it.

- **int Boolean(const String& name, int default\_value = 0) const**

  Return 1 if the value associated to **name** is  either **1, yes** or **true** Return 0 if the value associated to **name** is  either **0, no** or **false**

- **void Defaults(const ConfigDefaults \*array)**

  Load configuration attributes from the *name* and *value* members of the **array** argument.

## AUTHORS

Loic Dachary loic@gnu.org

The Ht://Dig group http://dev.htdig.org/

## SEE ALSO

[htdb\_dump(1)](/htdb_dump/1.md), [htdb\_stat(1)](/htdb_stat/1.md), [htdb\_load(1)](/htdb_load/1.md), [mifluzdump(1)](/mifluzdump/1.md), [mifluzload(1)](/mifluzload/1.md), [mifluzsearch(1)](/mifluzsearch/1.md), [mifluzdict(1)](/mifluzdict/1.md), [WordContext(3)](/WordContext/3.md), [WordList(3)](/WordList/3.md), [WordDict(3)](/WordDict/3.md), [WordListOne(3)](/WordListOne/3.md), [WordKey(3)](/WordKey/3.md), [WordKeyInfo(3)](/WordKeyInfo/3.md), [WordType(3)](/WordType/3.md), [WordDBInfo(3)](/WordDBInfo/3.md), [WordRecordInfo(3)](/WordRecordInfo/3.md), [WordRecord(3)](/WordRecord/3.md), [WordReference(3)](/WordReference/3.md), [WordCursor(3)](/WordCursor/3.md), [WordCursorOne(3)](/WordCursorOne/3.md), [WordMonitor(3)](/WordMonitor/3.md), [mifluz(3)](/mifluz/3.md)
