File: library.html

package info (click to toggle)
lg-issue16 4-4
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,256 kB
  • ctags: 77
  • sloc: tcl: 89; makefile: 37; sh: 4
file content (126 lines) | stat: -rw-r--r-- 5,261 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!--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>
&quot;Linux Gazette...<I>making Linux just a little more fun!</I>&quot;
</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 &lt;kunf.h&gt;
  ...
  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 &copy; 1997, Marc Welz <BR> 
Published in Issue 16 of the Linux Gazette, April 1997</H5></center>

<!--===================================================================-->
<P> <hr> <P> 
<A HREF="./lg_toc16.html"><IMG ALIGN=BOTTOM SRC="../gx/indexnew.gif" 
ALT="[ TABLE OF CONTENTS ]"></A>
<A HREF="../lg_frontpage.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 ============================================================-->