127 lines
5.1 KiB
HTML
127 lines
5.1 KiB
HTML
<!--startcut ==========================================================-->
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
|
<HTML>
|
|
<HEAD>
|
|
<title>Library Issue 16</title>
|
|
</HEAD>
|
|
<BODY BGCOLOR="#EEE1CC" TEXT="#000000" LINK="#0000FF" VLINK="#0020F0"
|
|
ALINK="#FF0000" >
|
|
<!--endcut ============================================================-->
|
|
|
|
<H4>
|
|
"Linux Gazette...<I>making Linux just a little more fun!</I>"
|
|
</H4>
|
|
|
|
<P> <HR> <P>
|
|
<!--===================================================================-->
|
|
|
|
<center>
|
|
|
|
<h3>A Brief Introduction to the <b>kunf</b> Library</h3>
|
|
<H4>By Marc Welz,
|
|
<a href="mailto:mwelz@sar8.ee.uct.ac.za">mwelz@sar8.ee.uct.ac.za</a></H4>
|
|
</center>
|
|
|
|
<h4>Why ?</h4>
|
|
The kunf library is an attempt to set up a uniform way of accessing
|
|
configuration data. Currently most large applications have their own
|
|
configuration files - these files are likely to have a varying syntax
|
|
and have no well-specified location. On the other hand small programs
|
|
and scripts have no configuration files at all - they have values hard-coded
|
|
into them which sometimes can be overridden from the command line
|
|
or through environment variables. This entire setup seems somewhat
|
|
suboptimal - it can be quite daunting to the novice user.
|
|
<p>
|
|
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.
|
|
<p>
|
|
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.
|
|
<p>
|
|
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.
|
|
<p>
|
|
<hr>
|
|
<h4>How ?</h4>
|
|
Once you have <a href="http://sar8.ee.uct.ac.za/linux/kunf/download.html">
|
|
downloaded</a>, extracted (<tt>tar -xzvf filename</tt>) and installed (a
|
|
<tt>make ; make install</tt> should suffice) the library, you should be
|
|
able to make use of the shell and C interface without too much difficulty:
|
|
<p>
|
|
>From a shell script you can use the utility <tt>kunfenv</tt> 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 <tt>news:nntp:nntpserver</tt>. A shell script
|
|
can access that information with a statement like:
|
|
<pre>
|
|
|
|
#!/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"
|
|
|
|
</pre>
|
|
<p>
|
|
A C program can access the same data with the following piece of
|
|
code:
|
|
<pre>
|
|
|
|
#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();
|
|
|
|
</pre>
|
|
Do not forget to link the program with the directive <tt>-lkunf</tt>.
|
|
<p>
|
|
The configuration file editor can be used to modify the value of
|
|
<tt>news:nntp:nntpserver</tt> entry. One simply invokes the editor
|
|
by typing <tt>kunfedit</tt>, navigates down to the nntpserver entry
|
|
(select the <b>news</b> 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).
|
|
<p>
|
|
<hr>
|
|
<h4>More ?</h4>
|
|
There exists a <a href="http://sar8.ee.uct.ac.za/linux/kunf/">web page</a>
|
|
which contains more information on this library. You can also
|
|
<a href="ftp://sar8.ee.uct.ac.za/linux/kunf/">ftp</a> the entire
|
|
package directly. The library is released under the GNU Copyleft.
|
|
You can contact the author at his <a href="http://sar8.ee.uct.ac.za/linux/kunf/address.gif">difficult-to-spam-address</a>.
|
|
|
|
<!--===================================================================-->
|
|
<P> <hr> <P>
|
|
<center><H5>Copyright © 1997, Marc Welz <BR>
|
|
Published in Issue 16 of the Linux Gazette, April 1997</H5></center>
|
|
|
|
<!--===================================================================-->
|
|
<P> <hr> <P>
|
|
<A HREF="./index.html"><IMG ALIGN=BOTTOM SRC="../gx/indexnew.gif"
|
|
ALT="[ TABLE OF CONTENTS ]"></A>
|
|
<A HREF="../index.html"><IMG ALIGN=BOTTOM SRC="../gx/homenew.gif"
|
|
ALT="[ FRONT PAGE ]"></A>
|
|
<A HREF="./answer.html"><IMG SRC="../gx/back2.gif"
|
|
ALT=" Back "></A>
|
|
<A HREF="./clueless.html"><IMG SRC="../gx/fwd.gif" ALT=" Next "></A>
|
|
<P> <hr> <P>
|
|
<!--startcut ==========================================================-->
|
|
</BODY>
|
|
</HTML>
|
|
<!--endcut ============================================================-->
|