Pattern - ini file

Contents

Pattern .ini file

The .ini file probably first appeared in Microsoft Windows, but it is quite common in Unix applications, such as here, in the configuration file /etc/yum from a Linux distribution:

[main]
cachedir=/var/cache/yum
keepcache=1
debuglevel=2
logfile=/var/log/yum.log
pkgpolicy=newest
distroverpkg=redhat-release
tolerant=1
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
metadata_expire=1800

[repositories]
#repository specific content goes here

Features

  • Text files
  • name=value assignments, one to a line
  • Possibly split into sections, using [section-name] syntax.

Advantages

  • Purely declarative
  • Easy to parse without needing to write complex parsers or link to complex libraries
  • Easy to write
  • Readable by people

Disadvantages

  • Weak Unicode support -it usually depends upon the character set of the specific machine hosting the file.
  • No uniform handling of escaped characters
  • Hierarchy limited to a depth of 1
  • No uniform rules for comments. Some variants use #, others ;, some (Samba smb.conf files) both. Some have no comment support at all.
  • No uniform rules for space handling. Should it be name="value here"?
  • No uniform rules for splitting values across multiple lines.

SmartFrog support

Generating text files is something the TextFile component can do; it can generate .ini files dynamically, and so configure other applications. There is no specific component just to generate .ini files, although this could be done, taking a list of [name,value] tuples and generating .ini file entries. The problem here is that there is no consistent format to generate, no standard rule for escaping characters outside the target character set or to insert a newline into the file.

If someone wanted to contribute/write an .ini file package, it would be best to have some general purpose component into which you could plug in a different generator component, a component that knew the specific rules (and validity options) of different target components, such as yum and samba.

Get SmartFrog at SourceForge.net. Fast, secure and Free Open Source software downloads