RSS

 
WinEdt Macro Library  | macro previous macro  | next macro

cfgSectionReader

read entries of INI-File like [section]

Description

cfgSectionReader reads all the entries of exactly one specified section. It needs to be called by another macro.

In case of section = "[execute]", the entries are considered of being macros that are executed immediately. The other entries are treated like pairs of keys and values and are stored in Local Variables where the variable name (key) can be prefixed by a configurable string value.

It works as well with "=" as seperator:  key=value
or with whitespace(s) between key and value:  key    value

Usage

While processing the keys of a section, any leading and trailing whitespaces are discarded from the values. Local Variables are explicitly released, if the value of the corresponding key is empty. This mechanism can be used to reset already existing Local Variables (that have come alive by a former call to cfgSectionReader).

Used Named Registers (local variables)

cfgFileContent

The macro expects this named register to hold the content of the config or INI file.

cfgSection

the section name to be processed

SectionReaderPrefix

Contains a string that will be used to prefix the key name.

Important

The Local Variable SectionReaderPrefix is not automatically released after use. This has to be done explicitly. Normally, I apply the same prefix to more than one section I'm reading (eg. I often use the name of the mode I'm working with). This behavior can easily changed at the end of the macro by removing the comment in the line with

//Release('SectionReaderPrefix');

Example

Suppose you have the following configuration settings in file DocBkMode.cfg:

[paths]
DOCBOOK_HOME          V:
DOCBOOK_XSL           %$('DOCBOOK_HOME');/style/XSL/dbk1.51.0

[classpath]
saxon                 %$('DOCBOOK_XSL');/extensions/saxon651.jar
xalan                 %$('DOCBOOK_XSL');/extensions/xalan2.jar

you can access the key/value pairs with the following macro:

ReadFile("%b\Config\docbk\DocBkMode.cfg",0);
Assign("cfgFileContent","%!0");

Assign("cfgSection","paths");
Exe("%B\Macros\macro\cfgSectionReader.edt");

Assign("cfgSection","classpath");
Assign("SectionReaderPrefix","CP");
Exe("%B\Macros\macro\cfgSectionReader.edt");
which delivers the following items as Local Variables:


DOCBOOK_HOME          V:
DOCBOOK_XSL           V:/style/XSL/dbk1.51.0
CPsaxon               V:/style/XSL/dbk1.51.0/extensions/saxon651.jar
CPxalan               V:/style/XSL/dbk1.51.0/extensions/xalan2.jar

As you may notice, all Local Variables are expanded automatically and the keys "saxon" and "xalan" got their prefix "CP" .

Installation Instructions

Put the macro in the folder %B\Macros\macro\.

Download

macro/cfgSectionReader.edt

Macro contributed by Georges Schmitz <georges.schmitzheitec.de>

WinEdt Macro Library  | macro previous macro  | next macro