The kunf library attempts change this - it tries to manage configuration data on behalf of the program or script. Instead of each application implementing its own resource file parser, an application calls a set of library functions (in the case of a shell script that would be a call to a utility program) which then return the configuration data.
Each piece of configuration data has a name (actually a sort of path) which identifies it. This makes that data independent of any particular location or configuration file. Once an application requests a data item, the library looks up the value in a location transparent manner and (optionally) performs a set of translations on the value. Then the value is returned to the calling code.
This approach should have the advantage that there is a consistent way of accessing configuration data - data for different applications can be modified with the same utility and the economics of scale should make it possible to construct more sophisticated maintenance tools that would be feasible for a single application. Novice users would not need to have to learn the location of the resource files.
>From a shell script you can use the utility kunfenv to place a particular piece of configuration data into the environment. For example, the template configuration files contain an entry for the nntpserver variable which is stored as news:nntp:nntpserver. A shell script can access that information with a statement like:
#!/bin/bash # evaluate the result of a call to kunfenv eval `kunfenv news:nntp:nntpserver` # Now we have the variable as news_nntp_nntpserver echo "My nntpserver is $news_nntp_nntpserver"
A C program can access the same data with the following piece of code:
#include <kunf.h> ... char *str; kunfig_open(NULL,KUNFIG_OPEN_STANDARD); str=kunfig_findvalue(3,"news","nntp","nntpserver"); printf("My nntpserver is %s\n",str); kunfig_close();Do not forget to link the program with the directive -lkunf.
The configuration file editor can be used to modify the value of news:nntp:nntpserver entry. One simply invokes the editor by typing kunfedit, navigates down to the nntpserver entry (select the news entry ...), modifies the value (hit the escape key to move off a field) and saves it (press escape several times - it will ask you if you want to save).