Debian Codegraph @

doc/spex.html

raw symbols SCIP
1 <?xml version="1.0" encoding="UTF-8"?>
2
3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
5 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
6
7 <head>
8 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
9 <meta http-equiv="Content-Style-Type" content="text/css" />
10 <meta name="author" content="Mikio Hirabayashi" />
11 <meta name="keywords" content="QDBM, DBM, database, hash, B+ tree" />
12 <meta name="description" content="fundamental specifications of QDBM" />
13 <link rel="contents" href="./" />
14 <link rel="alternate" href="spex-ja.html" hreflang="ja" title="the Japanese version" />
15 <link rev="made" href="mailto:[email protected]" />
16 <title>Specifications of QDBM Version 1</title>
17 <style type="text/css">html { margin: 0em 0em; padding: 0em 0em; background: #eeeeee none; }
18 body { margin: 2em 2em; padding: 0em 0em;
19 background: #eeeeee none; color: #111111;
20 font-style: normal; font-weight: normal; }
21 h1 { margin-top: 1.8em; margin-bottom: 1.3em; font-weight: bold; }
22 h2 { margin-top: 1.8em; margin-bottom: 1.1em; font-weight: bold;
23 border-left: solid 0.6em #445555; border-bottom: solid 1pt #bbbbbb;
24 padding: 0.5em 0.5em; width: 60%; }
25 h3 { margin-top: 1.8em; margin-bottom: 0.8em; font-weight: bold; }
26 hr { margin-top: 2.5em; margin-bottom: 1.5em; height: 1pt;
27 color: #999999; background-color: #999999; border: none; }
28 div.note,div.navi { text-align: right; }
29 div.logo { text-align: center; margin: 3em 0em; }
30 div.logo img { border: inset 2pt #ccccdd; }
31 p { margin: 0.8em 0em; line-height: 140%; }
32 p,dd { text-indent: 0.8em; }
33 div,pre { margin-left: 1.7em; margin-right: 1.7em; }
34 pre { background-color: #ddddee; padding: 0.2em; border: 1pt solid #bbbbcc; font-size: smaller; }
35 kbd { color: #111111; font-style: normal; font-weight: bold; }
36 a { color: #0022aa; text-decoration: none; }
37 a:hover,a:focus { color: #0033ee; text-decoration: underline; }
38 a.head { color: #111111; text-decoration: none; }
39 table { padding: 1pt 2pt 1pt 2pt; border: none; margin-left: 1.7em; border-collapse: collapse; }
40 th { padding: 1pt 4pt 1pt 4pt; border-style: none;
41 text-align: left; vertical-align: bottom; }
42 td { padding: 1pt 4pt 1pt 4pt; border: 1pt solid #333333;
43 text-align: left; vertical-align: top; }
44 ul,ol,dl { line-height: 140%; }
45 dt { margin-left: 1.2em; }
46 dd { margin-left: 2.0em; }
47 ul.lines { list-style-type: none; }
48 @media print {
49 html,body { margin: 0em 0em; background-color: #ffffff; color: #000000; }
50 h1 { padding: 8em 0em 0.5em 0em; text-align: center; }
51 h2 { page-break-before: always; }
52 div.note { text-align: center; }
53 div.navi,div.logo { display: none }
54 hr { display: none; }
55 pre { margin: 0.8em 0.8em; background-color: #ffffff;
56 border: 1pt solid #aaaaaa; font-size: smaller; }
57 a,kbd { color: #000000; text-decoration: none; }
58 h1,h2,h3 { font-family: sans-serif; }
59 p,div,li,dt,dd { font-family: serif; }
60 pre,kbd { font-family: monospace; }
61 dd { font-size: smaller; }
62 }
63 </style>
64 </head>
65
66 <body>
67
68 <h1>Fundamental Specifications of QDBM Version 1</h1>
69
70 <div class="note">Copyright (C) 2000-2007 Mikio Hirabayashi</div>
71 <div class="note">Last Update: Thu, 26 Oct 2006 15:00:20 +0900</div>
72 <div class="navi">[<a href="spex-ja.html" hreflang="ja">Japanese</a>]</div>
73
74 <hr />
75
76 <h2>Table of Contents</h2>
77
78 <ol>
79 <li><a href="#overview">Overview</a></li>
80 <li><a href="#features">Features</a></li>
81 <li><a href="#installation">Installation</a></li>
82 <li><a href="#depotapi">Depot: Basic API</a></li>
83 <li><a href="#depotcli">Commands for Depot</a></li>
84 <li><a href="#curiaapi">Curia: Extended API</a></li>
85 <li><a href="#curiacli">Commands for Curia</a></li>
86 <li><a href="#relicapi">Relic: NDBM-compatible API</a></li>
87 <li><a href="#reliccli">Commands for Relic</a></li>
88 <li><a href="#hovelapi">Hovel: GDBM-compatible API</a></li>
89 <li><a href="#hovelcli">Commands for Hovel</a></li>
90 <li><a href="#cabinapi">Cabin: Utility API</a></li>
91 <li><a href="#cabincli">Commands for Cabin</a></li>
92 <li><a href="#villaapi">Villa: Advanced API</a></li>
93 <li><a href="#villacli">Commands for Villa</a></li>
94 <li><a href="#odeumapi">Odeum: Inverted API</a></li>
95 <li><a href="#odeumcli">Commands for Odeum</a></li>
96 <li><a href="#fileformat">File Format</a></li>
97 <li><a href="#porting">Porting</a></li>
98 <li><a href="#bugs">Bugs</a></li>
99 <li><a href="#faq">Frequently Asked Questions</a></li>
100 <li><a href="#copying">Copying</a></li>
101 </ol>
102
103 <hr />
104
105 <h2><a name="overview" id="overview" class="head">Overview</a></h2>
106
107 <p>QDBM is a library of routines for managing a database. The database is a simple data file containing records, each is a pair of a key and a value. Every key and value is serial bytes with variable length. Both binary data and character string can be used as a key and a value. There is neither concept of data tables nor data types. Records are organized in hash table or B+ tree.</p>
108
109 <p>As for database of hash table, each key must be unique within a database, so it is impossible to store two or more records with a key overlaps. The following access methods are provided to the database: storing a record with a key and a value, deleting a record by a key, retrieving a record by a key. Moreover, traversal access to every key are provided, although the order is arbitrary. These access methods are similar to ones of DBM (or its followers: NDBM and GDBM) library defined in the UNIX standard. QDBM is an alternative for DBM because of its higher performance.</p>
110
111 <p>As for database of B+ tree, records whose keys are duplicated can be stored. Access methods of storing, deleting, and retrieving are provided as with the database of hash table. Records are stored in order by a comparing function assigned by a user. It is possible to access each record with the cursor in ascending or descending order. According to this mechanism, forward matching search for strings and range search for integers are realized. Moreover, transaction is available in database of B+ tree.</p>
112
113 <p>QDBM is written in C, and provided as APIs of C, C++, Java, Perl, and Ruby. QDBM is available on platforms which have API conforming to POSIX. QDBM is a free software licensed under the GNU Lesser General Public License.</p>
114
115 <hr />
116
117 <h2><a name="features" id="features" class="head">Features</a></h2>
118
119 <h3>Effective Implementation of Hash Database</h3>
120
121 <p>QDBM is developed referring to GDBM for the purpose of the following three points: higher processing speed, smaller size of a database file, and simpler API. They have been achieved. Moreover, as with GDBM, the following three restrictions of traditional DBM: a process can handle only one database, the size of a key and a value is bounded, a database file is sparse, are cleared.</p>
122
123 <p>QDBM uses hash algorithm to retrieve records. If a bucket array has sufficient number of elements, the time complexity of retrieval is `O(1)'. That is, time required for retrieving a record is constant, regardless of the scale of a database. It is also the same about storing and deleting. Collision of hash values is managed by separate chaining. Data structure of the chains is binary search tree. Even if a bucket array has unusually scarce elements, the time complexity of retrieval is `O(log n)'.</p>
124
125 <p>QDBM attains improvement in retrieval by loading RAM with the whole of a bucket array. If a bucket array is on RAM, it is possible to access a region of a target record by about one path of file operations. A bucket array saved in a file is not read into RAM with the `read' call but directly mapped to RAM with the `mmap' call. Therefore, preparation time on connecting to a database is very short, and two or more processes can share the same memory map.</p>
126
127 <p>If the number of elements of a bucket array is about half of records stored within a database, although it depends on characteristic of the input, the probability of collision of hash values is about 56.7% (36.8% if the same, 21.3% if twice, 11.5% if four times, 6.0% if eight times). In such case, it is possible to retrieve a record by two or less paths of file operations. If it is made into a performance index, in order to handle a database containing one million of records, a bucket array with half a million of elements is needed. The size of each element is 4 bytes. That is, if 2M bytes of RAM is available, a database containing one million records can be handled.</p>
128
129 <p>QDBM provides two modes to connect to a database: `reader' and `writer'. A reader can perform retrieving but neither storing nor deleting. A writer can perform all access methods. Exclusion control between processes is performed when connecting to a database by file locking. While a writer is connected to a database, neither readers nor writers can be connected. While a reader is connected to a database, other readers can be connect, but writers can not. According to this mechanism, data consistency is guaranteed with simultaneous connections in multitasking environment.</p>
130
131 <p>Traditional DBM provides two modes of the storing operations: `insert' and `replace'. In the case a key overlaps an existing record, the insert mode keeps the existing value, while the replace mode transposes it to the specified value. In addition to the two modes, QDBM provides `concatenate' mode. In the mode, the specified value is concatenated at the end of the existing value and stored. This feature is useful when adding a element to a value as an array. Moreover, although DBM has a method to fetch out a value from a database only by reading the whole of a region of a record, QDBM has a method to fetch out a part of a region of a value. When a value is treated as an array, this feature is also useful.</p>
132
133 <p>Generally speaking, while succession of updating, fragmentation of available regions occurs, and the size of a database grows rapidly. QDBM deal with this problem by coalescence of dispensable regions and reuse of them, and featuring of optimization of a database. When overwriting a record with a value whose size is greater than the existing one, it is necessary to remove the region to another position of the file. Because the time complexity of the operation depends on the size of the region of a record, extending values successively is inefficient. However, QDBM deal with this problem by alignment. If increment can be put in padding, it is not necessary to remove the region.</p>
134
135 <p>As for many file systems, it is impossible to handle a file whose size is more than 2GB. To deal with this problem, QDBM provides a directory database containing multiple database files. Due to this feature, it is possible to handle a database whose total size is up to 1TB in theory. Moreover, because database files can be deployed on multiple disks, the speed of updating operations can be improved as with RAID-0 (striping). It is also possible for the database files to deploy on multiple file servers using NFS and so on.</p>
136
137 <h3>Useful Implementation of B+ Tree Database</h3>
138
139 <p>Although B+ tree database is slower than hash database, it features ordering access to each record. The order can be assigned by users. Records of B+ tree are sorted and arranged in logical pages. Sparse index organized in B tree that is multiway balanced tree are maintained for each page. Thus, the time complexity of retrieval and so on is `O(log n)'. Cursor is provided to access each record in order. The cursor can jump to a position specified by a key and can step forward or backward from the current position. Because each page is arranged as double linked list, the time complexity of stepping cursor is `O(1)'.</p>
140
141 <p>B+ tree database is implemented, based on above hash database. Because each page of B+ tree is stored as each record of hash database, B+ tree database inherits efficiency of storage management of hash database. Because the header of each record is smaller and alignment of each page is adjusted according to the page size, in most cases, the size of database file is cut by half compared to one of hash database. Although operation of many pages are required to update B+ tree, QDBM expedites the process by caching pages and reducing file operations. In most cases, because whole of the sparse index is cached on memory, it is possible to retrieve a record by one or less path of file operations.</p>
142
143 <p>B+ tree database features transaction mechanism. It is possible to commit a series of operations between the beginning and the end of the transaction in a lump, or to abort the transaction and perform rollback to the state before the transaction. Even if the process of an application is crashed while the transaction, the database file is not broken.</p>
144
145 <p>In case that QDBM was built with ZLIB, LZO, or BZIP2 enabled, a lossless data-compression library, the content of each page of B+ tree is compressed and stored in a file. Because each record in a page has similar patterns, high efficiency of compression is expected due to the Lempel-Ziv algorithm and the like. In case handling text data, the size of a database is reduced to about 25%. If the scale of a database is large and disk I/O is the bottleneck, featuring compression makes the processing speed improved to a large extent.</p>
146
147 <h3>Simple but Various Interfaces</h3>
148
149 <p>QDBM provides very simple APIs. You can perform database I/O as usual file I/O with `FILE' pointer defined in ANSI C. In the basic API of QDBM, entity of a database is recorded as one file. In the extended API, entity of a database is recorded as several files in one directory. Because the two APIs are very similar with each other, porting an application from one to the other is easy.</p>
150
151 <p>APIs which are compatible with NDBM and GDBM are also provided. As there are a lot of applications using NDBM or GDBM, it is easy to port them onto QDBM. In most cases, it is completed only by replacement of header including (#include) and re-compiling. However, QDBM can not handle database files made by the original NDBM or GDBM.</p>
152
153 <p>In order to handle records on memory easily, the utility API is provided. It implements memory allocating functions, sorting functions, extensible datum, array list, hash map, and so on. Using them, you can handle records in C language cheaply as in such script languages as Perl or Ruby.</p>
154
155 <p>B+ tree database is used with the advanced API. The advanced API is implemented using the basic API and the utility API. Because the advanced API is also similar to the basic API and the extended API, it is easy to learn how to use it.</p>
156
157 <p>In order to handle an inverted index which is used by full-text search systems, the inverted API is provided. If it is easy to handle an inverted index of documents, an application can focus on text processing and natural language processing. Because this API does not depend on character codes nor languages, it is possible to implement a full-text search system which can respond to various requests from users.</p>
158
159 <p>Along with APIs for C, QDBM provides APIs for C++, Java, Perl, and Ruby. APIs for C are composed of seven kinds: the basic API, the extended API, the NDBM-compatible API, the GDBM-compatible API, the utility API, the advanced API, and the inverted API. Command line interfaces corresponding to each API are also provided. They are useful for prototyping, testing, debugging, and so on. The C++ API encapsulates database handling functions of the basic API, the extended API, and the advanced API with class mechanism of C++. The Java API has native methods calling the basic API, the extended API, and the advanced API with Java Native Interface. The Perl API has methods calling the basic API, the extended API, and the advanced API with XS language. The Ruby API has method calling the basic API, the extended API, and the advanced API as modules of Ruby. Moreover, CGI scripts for administration of databases, file uploading, and full-text search are provided.</p>
160
161 <h3>Wide Portability</h3>
162
163 <p>QDBM is implemented being based on syntax of ANSI C (C89) and using only APIs defined in ANSI C or POSIX. Thus, QDBM works on most UNIX and its compatible OSs. As for C API, checking operations have been done at least on the following platforms.</p>
164
165 <ul>
166 <li>Linux (2.2, 2.4, 2.6) (IA32, IA64, AMD64, PA-RISC, Alpha, PowerPC, M68000, ARM)</li>
167 <li>FreeBSD (4.9, 5.0, 5.1, 5.2, 5.3) (IA32, IA64, SPARC, Alpha)</li>
168 <li>NetBSD (1.6) (IA32)</li>
169 <li>OpenBSD (3.4) (IA32)</li>
170 <li>SunOS (5.6, 5.7, 5.8, 5.9, 5.10) (IA32, SPARC)</li>
171 <li>HP-UX (11.11, 11.23) (IA64, PA-RISC)</li>
172 <li>AIX (5.2) (POWER)</li>
173 <li>Windows (2000, XP) (IA32, IA64, AMD64) (Cygwin, MinGW, Visual C++)</li>
174 <li>Mac OS X (10.2, 10.3, 10.4) (IA32, PowerPC)</li>
175 <li>Tru64 (5.1) (Alpha)</li>
176 <li>RISC OS (5.03) (ARM)</li>
177 </ul>
178
179 <p>Although a database file created by QDBM depends on byte order of the processor, to do with it, utilities to dump data in format which is independent to byte orders are provided.</p>
180
181 <hr />
182
183 <h2><a name="installation" id="installation" class="head">Installation</a></h2>
184
185 <h3>Preparation</h3>
186
187 <p>To install QDBM from a source package, GCC of 2.8 or later version and `make' are required.</p>
188
189 <p>When an archive file of QDBM is extracted, change the current working directory to the generated directory and perform installation.</p>
190
191 <h3>Usual Steps</h3>
192
193 <p>Follow the procedures below on Linux, BSD, or SunOS.</p>
194
195 <p>Run the configuration script.</p>
196
197 <pre>./configure
198 </pre>
199
200 <p>Build programs.</p>
201
202 <pre>make
203 </pre>
204
205 <p>Perform self-diagnostic test.</p>
206
207 <pre>make check
208 </pre>
209
210 <p>Install programs. This operation must be carried out by the root user.</p>
211
212 <pre>make install
213 </pre>
214
215 <h3>Using GNU Libtool</h3>
216
217 <p>If above steps do not work, try the following steps. This way needs GNU Libtool of 1.5 or later version.</p>
218
219 <p>Run the configuration script.</p>
220
221 <pre>./configure
222 </pre>
223
224 <p>Build programs.</p>
225
226 <pre>make -f LTmakefile
227 </pre>
228
229 <p>Perform self-diagnostic test.</p>
230
231 <pre>make -f LTmakefile check
232 </pre>
233
234 <p>Install programs. This operation must be carried out by the root user.</p>
235
236 <pre>make -f LTmakefile install
237 </pre>
238
239 <h3>Result</h3>
240
241 <p>When a series of work finishes, the following files will be installed. As for the rest, manuals will be installed under `/usr/local/man/man1' and '/usr/local/man/man3', other documents will be installed under `/usr/local/share/qdbm'. A configuration file for `pkg-config' will be installed under `/usr/local/lib/pkgconfig'.</p>
242
243 <pre>/usr/local/include/depot.h
244 /usr/local/include/curia.h
245 /usr/local/include/relic.h
246 /usr/local/include/hovel.h
247 /usr/local/include/cabin.h
248 /usr/local/include/villa.h
249 /usr/local/include/vista.h
250 /usr/local/include/odeum.h
251 /usr/local/lib/libqdbm.a
252 /usr/local/lib/libqdbm.so.14.14.0
253 /usr/local/lib/libqdbm.so.14
254 /usr/local/lib/libqdbm.so
255 /usr/local/bin/dpmgr
256 /usr/local/bin/dptest
257 /usr/local/bin/dptsv
258 /usr/local/bin/crmgr
259 /usr/local/bin/crtest
260 /usr/local/bin/crtsv
261 /usr/local/bin/rlmgr
262 /usr/local/bin/rltest
263 /usr/local/bin/hvmgr
264 /usr/local/bin/hvtest
265 /usr/local/bin/cbtest
266 /usr/local/bin/cbcodec
267 /usr/local/bin/vlmgr
268 /usr/local/bin/vltest
269 /usr/local/bin/vltsv
270 /usr/local/bin/odmgr
271 /usr/local/bin/odtest
272 /usr/local/bin/odidx
273 /usr/local/bin/qmttest
274 </pre>
275
276 <p>When you run a program linked dynamically to `libqdbm.so', the library search path should include `/usr/local/lib'. You can set the library search path with the environment variable `LD_LIBRARY_PATH'.</p>
277
278 <p>To uninstall QDBM, execute the following command after `./configure'. This operation must be carried out by the root user.</p>
279
280 <pre>make uninstall
281 </pre>
282
283 <p>If an old version of QDBM is installed on your system, uninstall it before installation of a new one.</p>
284
285 <p>The other APIs except for C nor CGI scripts are not installed by default. Refer to `plus/xspex.html' to know how to install the C++ API. Refer to `java/jspex.html' to know how to install the Java API. Refer to `perl/plspex.html' to know how to install the Perl API. Refer to `ruby/rbspex.html' to know how to install the Ruby API. Refer to `cgi/cgispex.html' to know how to install the CGI script.</p>
286
287 <p>To install QDBM from such a binary package as RPM, refer to the manual of the package manager. For example, if you use RPM, execute like the following command by the root user.</p>
288
289 <pre>rpm -ivh qdbm-1.x.x-x.i386.rpm
290 </pre>
291
292 <h3>For Windows</h3>
293
294 <p>On Windows (Cygwin), you should follow the procedures below for installation.</p>
295
296 <p>Run the configuration script.</p>
297
298 <pre>./configure
299 </pre>
300
301 <p>Build programs.</p>
302
303 <pre>make win
304 </pre>
305
306 <p>Perform self-diagnostic test.</p>
307
308 <pre>make check-win
309 </pre>
310
311 <p>Install programs. As well, perform `make uninstall-win' to uninstall them.</p>
312
313 <pre>make install-win
314 </pre>
315
316 <p>On Windows, the import library `libqdbm.dll.a' is created as well as the static library `libqdbm.a', and the dynamic linking library `qdbm.dll' is created instead of such shared libraries as `libqdbm.so'. `qdbm.dll' is installed into `/usr/local/bin'.</p>
317
318 <p>In order to build QDBM using MinGW on Cygwin, you should perform `make mingw' instead of `make win'. With the UNIX emulation layer of Cygwin, generated programs depend on `cygwin1.dll' (they come under GNU GPL). This problem is solved by linking them to the Win32 native DLL with MinGW.</p>
319
320 <p>In order to build QDBM using Visual C++, you should edit `VCmakefile' and set the search paths for libraries and headers. And perform `nmake /f VCMakefile'. Applications linking to `qdbm.dll' should link to `msvcrt.dll' by `/MD' or `/MDd' option of the compiler. Refer to `VCmakefile' for detail configurations.</p>
321
322 <h3>For Mac OS X</h3>
323
324 <p>On Mac OS X (Darwin), you should follow the procedures below for installation.</p>
325
326 <p>Run the configuration script.</p>
327
328 <pre>./configure
329 </pre>
330
331 <p>Build programs.</p>
332
333 <pre>make mac
334 </pre>
335
336 <p>Perform self-diagnostic test.</p>
337
338 <pre>make check-mac
339 </pre>
340
341 <p>Install programs. As well, perform `make uninstall-mac' to uninstall them.</p>
342
343 <pre>make install-mac
344 </pre>
345
346 <p>On Mac OS X, `libqdbm.dylib' and so on are created instead of `libqdbm.so' and so on. You can set the library search path with the environment variable `DYLD_LIBRARY_PATH'.</p>
347
348 <h3>For HP-UX</h3>
349
350 <p>On HP-UX, you should follow the procedures below for installation.</p>
351
352 <p>Run the configuration script.</p>
353
354 <pre>./configure
355 </pre>
356
357 <p>Build programs.</p>
358
359 <pre>make hpux
360 </pre>
361
362 <p>Perform self-diagnostic test.</p>
363
364 <pre>make check-hpux
365 </pre>
366
367 <p>Install programs. As well, perform `make uninstall-hpux' to uninstall them.</p>
368
369 <pre>make install-hpux
370 </pre>
371
372 <p>On HP-UX, `libqdbm.sl' is created instead of `libqdbm.so' and so on. You can set the library search path with the environment variable `SHLIB_PATH'.</p>
373
374 <h3>For RISC OS</h3>
375
376 <p>On RISC OS, you should follow the procedures below for installation.</p>
377
378 <p>Build programs. As `cc' is used for compilation by default, if you want to use `gcc', add the argument `CC=gcc'.</p>
379
380 <pre>make -f RISCmakefile
381 </pre>
382
383 <p>When a series of work finishes, the library file `libqdbm' and such commands as `dpmgr' are generated. Because how to install them is not defined, copy them manually for installation. As with it, such header files as `depot.h' should be installed manually.</p>
384
385 <h3>Detail Configurations</h3>
386
387 <p>You can configure building processes by the following optional arguments of `./configure'.</p>
388
389 <ul class="lines">
390 <li><kbd>--enable-debug</kbd> : build for debugging. Enable debugging symbols, do not perform optimization, and perform static linking.</li>
391 <li><kbd>--enable-devel</kbd> : build for development. Enable debugging symbols, perform optimization, and perform dynamic linking.</li>
392 <li><kbd>--enable-stable</kbd> : build for stable release. Perform conservative optimization, and perform dynamic linking.</li>
393 <li><kbd>--enable-pthread</kbd> : feature POSIX thread and treat global variables as thread specific data.</li>
394 <li><kbd>--disable-lock</kbd> : build for environments without file locking.</li>
395 <li><kbd>--disable-mmap</kbd> : build for environments without memory mapping.</li>
396 <li><kbd>--enable-zlib</kbd> : feature ZLIB compression for B+ tree and inverted index.</li>
397 <li><kbd>--enable-lzo</kbd> : feature LZO compression for B+ tree and inverted index.</li>
398 <li><kbd>--enable-bzip</kbd> : feature BZIP2 compression for B+ tree and inverted index.</li>
399 <li><kbd>--enable-iconv</kbd> : feature ICONV utilities for conversion of character encodings.</li>
400 </ul>
401
402 <p>Usually, QDBM and its applications can be built without any dependency on non-standard libraries except for `libqdbm.*'. However, they depend on `libpthread.*' if POSIX thread is enabled, and they depend on `libz.*' if ZLIB is enabled, and they depend on `liblzo2.*' if LZO is enabled, and they depend on `libbz2.*' if BZIP2 is enabled, and they depend on `libiconv.*' if ICONV is enabled.</p>
403
404 <p>Because the license of LZO is GNU GPL, note that applications linking to `liblzo2.*' should meet commitments of GNU GPL.</p>
405
406 <hr />
407
408 <h2><a name="depotapi" id="depotapi" class="head">Depot: Basic API</a></h2>
409
410 <h3>Overview</h3>
411
412 <p>Depot is the basic API of QDBM. Almost all features for managing a database provided by QDBM are implemented by Depot. Other APIs are no more than wrappers of Depot. Depot is the fastest in all APIs of QDBM.</p>
413
414 <p>In order to use Depot, you should include `depot.h' and `stdlib.h' in the source files. Usually, the following description will be near the beginning of a source file.</p>
415
416 <dl>
417 <dt><kbd>#include &lt;depot.h&gt;</kbd></dt>
418 <dt><kbd>#include &lt;stdlib.h&gt;</kbd></dt>
419 </dl>
420
421 <p>A pointer to `DEPOT' is used as a database handle. It is like that some file I/O routines of `stdio.h' use a pointer to `FILE'. A database handle is opened with the function `dpopen' and closed with `dpclose'. You should not refer directly to any member of the handle. If a fatal error occurs in a database, any access method via the handle except `dpclose' will not work and return error status. Although a process is allowed to use multiple database handles at the same time, handles of the same database file should not be used.</p>
422
423 <h3>API</h3>
424
425 <p>The external variable `dpversion' is the string containing the version information.</p>
426
427 <dl>
428 <dt><kbd>extern const char *dpversion;</kbd></dt>
429 </dl>
430
431 <p>The external variable `dpecode' is assigned with the last happened error code. Refer to `depot.h' for details of the error codes.</p>
432
433 <dl>
434 <dt><kbd>extern int dpecode;</kbd></dt>
435 <dd>The initial value of this variable is `DP_ENOERR'. The other values are `DP_EFATAL', `DP_EMODE', `DP_EBROKEN', `DP_EKEEP', `DP_ENOITEM', `DP_EALLOC', `DP_EMAP', `DP_EOPEN', `DP_ECLOSE', `DP_ETRUNC', `DP_ESYNC', `DP_ESTAT', `DP_ESEEK', `DP_EREAD', `DP_EWRITE', `DP_ELOCK', `DP_EUNLINK', `DP_EMKDIR', `DP_ERMDIR', and `DP_EMISC'.</dd>
436 </dl>
437
438 <p>The function `dperrmsg' is used in order to get a message string corresponding to an error code.</p>
439
440 <dl>
441 <dt><kbd>const char *dperrmsg(int <var>ecode</var>);</kbd></dt>
442 <dd>`ecode' specifies an error code. The return value is the message string of the error code. The region of the return value is not writable.</dd>
443 </dl>
444
445 <p>The function `dpopen' is used in order to get a database handle.</p>
446
447 <dl>
448 <dt><kbd>DEPOT *dpopen(const char *<var>name</var>, int <var>omode</var>, int <var>bnum</var>);</kbd></dt>
449 <dd>`name' specifies the name of a database file. `omode' specifies the connection mode: `DP_OWRITER' as a writer, `DP_OREADER' as a reader. If the mode is `DP_OWRITER', the following may be added by bitwise or: `DP_OCREAT', which means it creates a new database if not exist, `DP_OTRUNC', which means it creates a new database regardless if one exists. Both of `DP_OREADER' and `DP_OWRITER' can be added to by bitwise or: `DP_ONOLCK', which means it opens a database file without file locking, or `DP_OLCKNB', which means locking is performed without blocking. `DP_OCREAT' can be added to by bitwise or: `DP_OSPARSE', which means it creates a database file as a sparse file. `bnum' specifies the number of elements of the bucket array. If it is not more than 0, the default value is specified. The size of a bucket array is determined on creating, and can not be changed except for by optimization of the database. Suggested size of a bucket array is about from 0.5 to 4 times of the number of all records to store. The return value is the database handle or `NULL' if it is not successful. While connecting as a writer, an exclusive lock is invoked to the database file. While connecting as a reader, a shared lock is invoked to the database file. The thread blocks until the lock is achieved. If `DP_ONOLCK' is used, the application is responsible for exclusion control.</dd>
450 </dl>
451
452 <p>The function `dpclose' is used in order to close a database handle.</p>
453
454 <dl>
455 <dt><kbd>int dpclose(DEPOT *<var>depot</var>);</kbd></dt>
456 <dd>`depot' specifies a database handle. If successful, the return value is true, else, it is false. Because the region of a closed handle is released, it becomes impossible to use the handle. Updating a database is assured to be written when the handle is closed. If a writer opens a database but does not close it appropriately, the database will be broken.</dd>
457 </dl>
458
459 <p>The function `dpput' is used in order to store a record.</p>
460
461 <dl>
462 <dt><kbd>int dpput(DEPOT *<var>depot</var>, const char *<var>kbuf</var>, int <var>ksiz</var>, const char *<var>vbuf</var>, int <var>vsiz</var>, int <var>dmode</var>);</kbd></dt>
463 <dd>`depot' specifies a database handle connected as a writer. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `vbuf' specifies the pointer to the region of a value. `vsiz' specifies the size of the region of the value. If it is negative, the size is assigned with `strlen(vbuf)'. `dmode' specifies behavior when the key overlaps, by the following values: `DP_DOVER', which means the specified value overwrites the existing one, `DP_DKEEP', which means the existing value is kept, `DP_DCAT', which means the specified value is concatenated at the end of the existing value. If successful, the return value is true, else, it is false.</dd>
464 </dl>
465
466 <p>The function `dpout' is used in order to delete a record.</p>
467
468 <dl>
469 <dt><kbd>int dpout(DEPOT *<var>depot</var>, const char *<var>kbuf</var>, int <var>ksiz</var>);</kbd></dt>
470 <dd>`depot' specifies a database handle connected as a writer. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. If successful, the return value is true, else, it is false. False is returned when no record corresponds to the specified key.</dd>
471 </dl>
472
473 <p>The function `dpget' is used in order to retrieve a record.</p>
474
475 <dl>
476 <dt><kbd>char *dpget(DEPOT *<var>depot</var>, const char *<var>kbuf</var>, int <var>ksiz</var>, int <var>start</var>, int <var>max</var>, int *<var>sp</var>);</kbd></dt>
477 <dd>`depot' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `start' specifies the offset address of the beginning of the region of the value to be read. `max' specifies the max size to be read. If it is negative, the size to read is unlimited. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the region of the value of the corresponding record, else, it is `NULL'. `NULL' is returned when no record corresponds to the specified key or the size of the value of the corresponding record is less than `start'. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
478 </dl>
479
480 <p>The function `dpgetwb' is used in order to retrieve a record and write the value into a buffer.</p>
481
482 <dl>
483 <dt><kbd>int dpgetwb(DEPOT *<var>depot</var>, const char *<var>kbuf</var>, int <var>ksiz</var>, int <var>start</var>, int <var>max</var>, char *<var>vbuf</var>);</kbd></dt>
484 <dd>`depot' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `start' specifies the offset address of the beginning of the region of the value to be read. `max' specifies the max size to be read. It shuld be equal to or less than the size of the writing buffer. `vbuf' specifies the pointer to a buffer into which the value of the corresponding record is written. If successful, the return value is the size of the written data, else, it is -1. -1 is returned when no record corresponds to the specified key or the size of the value of the corresponding record is less than `start'. Note that no additional zero code is appended at the end of the region of the writing buffer.</dd>
485 </dl>
486
487 <p>The function `dpvsiz' is used in order to get the size of the value of a record.</p>
488
489 <dl>
490 <dt><kbd>int dpvsiz(DEPOT *<var>depot</var>, const char *<var>kbuf</var>, int <var>ksiz</var>);</kbd></dt>
491 <dd>`depot' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. If successful, the return value is the size of the value of the corresponding record, else, it is -1. Because this function does not read the entity of a record, it is faster than `dpget'.</dd>
492 </dl>
493
494 <p>The function `dpiterinit' is used in order to initialize the iterator of a database handle.</p>
495
496 <dl>
497 <dt><kbd>int dpiterinit(DEPOT *<var>depot</var>);</kbd></dt>
498 <dd>`depot' specifies a database handle. If successful, the return value is true, else, it is false. The iterator is used in order to access the key of every record stored in a database.</dd>
499 </dl>
500
501 <p>The function `dpiternext' is used in order to get the next key of the iterator.</p>
502
503 <dl>
504 <dt><kbd>char *dpiternext(DEPOT *<var>depot</var>, int *<var>sp</var>);</kbd></dt>
505 <dd>`depot' specifies a database handle. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the region of the next key, else, it is `NULL'. `NULL' is returned when no record is to be get out of the iterator. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. It is possible to access every record by iteration of calling this function. However, it is not assured if updating the database is occurred while the iteration. Besides, the order of this traversal access method is arbitrary, so it is not assured that the order of storing matches the one of the traversal access.</dd>
506 </dl>
507
508 <p>The function `dpsetalign' is used in order to set alignment of a database handle.</p>
509
510 <dl>
511 <dt><kbd>int dpsetalign(DEPOT *<var>depot</var>, int <var>align</var>);</kbd></dt>
512 <dd>`depot' specifies a database handle connected as a writer. `align' specifies the size of alignment. If successful, the return value is true, else, it is false. If alignment is set to a database, the efficiency of overwriting values is improved. The size of alignment is suggested to be average size of the values of the records to be stored. If alignment is positive, padding whose size is multiple number of the alignment is placed. If alignment is negative, as `vsiz' is the size of a value, the size of padding is calculated with `(vsiz / pow(2, abs(align) - 1))'. Because alignment setting is not saved in a database, you should specify alignment every opening a database.</dd>
513 </dl>
514
515 <p>The function `dpsetfbpsiz' is used in order to set the size of the free block pool of a database handle.</p>
516
517 <dl>
518 <dt><kbd>int dpsetfbpsiz(DEPOT *<var>depot</var>, int <var>size</var>);</kbd></dt>
519 <dd>`depot' specifies a database handle connected as a writer. `size' specifies the size of the free block pool of a database. If successful, the return value is true, else, it is false. The default size of the free block pool is 16. If the size is greater, the space efficiency of overwriting values is improved with the time efficiency sacrificed.</dd>
520 </dl>
521
522 <p>The function `dpsync' is used in order to synchronize updating contents with the file and the device.</p>
523
524 <dl>
525 <dt><kbd>int dpsync(DEPOT *<var>depot</var>);</kbd></dt>
526 <dd>`depot' specifies a database handle connected as a writer. If successful, the return value is true, else, it is false. This function is useful when another process uses the connected database file.</dd>
527 </dl>
528
529 <p>The function `dpoptimize' is used in order to optimize a database.</p>
530
531 <dl>
532 <dt><kbd>int dpoptimize(DEPOT *<var>depot</var>, int <var>bnum</var>);</kbd></dt>
533 <dd>`depot' specifies a database handle connected as a writer. `bnum' specifies the number of the elements of the bucket array. If it is not more than 0, the default value is specified. If successful, the return value is true, else, it is false. In an alternating succession of deleting and storing with overwrite or concatenate, dispensable regions accumulate. This function is useful to do away with them.</dd>
534 </dl>
535
536 <p>The function `dpname' is used in order to get the name of a database.</p>
537
538 <dl>
539 <dt><kbd>char *dpname(DEPOT *<var>depot</var>);</kbd></dt>
540 <dd>`depot' specifies a database handle. If successful, the return value is the pointer to the region of the name of the database, else, it is `NULL'. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
541 </dl>
542
543 <p>The function `dpfsiz' is used in order to get the size of a database file.</p>
544
545 <dl>
546 <dt><kbd>int dpfsiz(DEPOT *<var>depot</var>);</kbd></dt>
547 <dd>`depot' specifies a database handle. If successful, the return value is the size of the database file, else, it is -1.</dd>
548 </dl>
549
550 <p>The function `dpbnum' is used in order to get the number of the elements of the bucket array.</p>
551
552 <dl>
553 <dt><kbd>int dpbnum(DEPOT *<var>depot</var>);</kbd></dt>
554 <dd>`depot' specifies a database handle. If successful, the return value is the number of the elements of the bucket array, else, it is -1.</dd>
555 </dl>
556
557 <p>The function `dpbusenum' is used in order to get the number of the used elements of the bucket array.</p>
558
559 <dl>
560 <dt><kbd>int dpbusenum(DEPOT *<var>depot</var>);</kbd></dt>
561 <dd>`depot' specifies a database handle. If successful, the return value is the number of the used elements of the bucket array, else, it is -1. This function is inefficient because it accesses all elements of the bucket array.</dd>
562 </dl>
563
564 <p>The function `dprnum' is used in order to get the number of the records stored in a database.</p>
565
566 <dl>
567 <dt><kbd>int dprnum(DEPOT *<var>depot</var>);</kbd></dt>
568 <dd>`depot' specifies a database handle. If successful, the return value is the number of the records stored in the database, else, it is -1.</dd>
569 </dl>
570
571 <p>The function `dpwritable' is used in order to check whether a database handle is a writer or not.</p>
572
573 <dl>
574 <dt><kbd>int dpwritable(DEPOT *<var>depot</var>);</kbd></dt>
575 <dd>`depot' specifies a database handle. The return value is true if the handle is a writer, false if not.</dd>
576 </dl>
577
578 <p>The function `dpfatalerror' is used in order to check whether a database has a fatal error or not.</p>
579
580 <dl>
581 <dt><kbd>int dpfatalerror(DEPOT *<var>depot</var>);</kbd></dt>
582 <dd>`depot' specifies a database handle. The return value is true if the database has a fatal error, false if not.</dd>
583 </dl>
584
585 <p>The function `dpinode' is used in order to get the inode number of a database file.</p>
586
587 <dl>
588 <dt><kbd>int dpinode(DEPOT *<var>depot</var>);</kbd></dt>
589 <dd>`depot' specifies a database handle. The return value is the inode number of the database file.</dd>
590 </dl>
591
592 <p>The function `dpmtime' is used in order to get the last modified time of a database.</p>
593
594 <dl>
595 <dt><kbd>time_t dpmtime(DEPOT *<var>depot</var>);</kbd></dt>
596 <dd>`depot' specifies a database handle. The return value is the last modified time of the database.</dd>
597 </dl>
598
599 <p>The function `dpfdesc' is used in order to get the file descriptor of a database file.</p>
600
601 <dl>
602 <dt><kbd>int dpfdesc(DEPOT *<var>depot</var>);</kbd></dt>
603 <dd>`depot' specifies a database handle. The return value is the file descriptor of the database file. Handling the file descriptor of a database file directly is not suggested.</dd>
604 </dl>
605
606 <p>The function `dpremove' is used in order to remove a database file.</p>
607
608 <dl>
609 <dt><kbd>int dpremove(const char *<var>name</var>);</kbd></dt>
610 <dd>`name' specifies the name of a database file. If successful, the return value is true, else, it is false.</dd>
611 </dl>
612
613 <p>The function `dprepair' is used in order to repair a broken database file.</p>
614
615 <dl>
616 <dt><kbd>int dprepair(const char *<var>name</var>);</kbd></dt>
617 <dd>`name' specifies the name of a database file. If successful, the return value is true, else, it is false. There is no guarantee that all records in a repaired database file correspond to the original or expected state.</dd>
618 </dl>
619
620 <p>The function `dpexportdb' is used in order to dump all records as endian independent data.</p>
621
622 <dl>
623 <dt><kbd>int dpexportdb(DEPOT *<var>depot</var>, const char *<var>name</var>);</kbd></dt>
624 <dd>`depot' specifies a database handle. `name' specifies the name of an output file. If successful, the return value is true, else, it is false.</dd>
625 </dl>
626
627 <p>The function `dpimportdb' is used in order to load all records from endian independent data.</p>
628
629 <dl>
630 <dt><kbd>int dpimportdb(DEPOT *<var>depot</var>, const char *<var>name</var>);</kbd></dt>
631 <dd>`depot' specifies a database handle connected as a writer. The database of the handle must be empty. `name' specifies the name of an input file. If successful, the return value is true, else, it is false.</dd>
632 </dl>
633
634 <p>The function `dpsnaffle' is used in order to retrieve a record directly from a database file.</p>
635
636 <dl>
637 <dt><kbd>char *dpsnaffle(const char *<var>name</var>, const char *<var>kbuf</var>, int <var>ksiz</var>, int *<var>sp</var>);</kbd></dt>
638 <dd>`name' specifies the name of a database file. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the region of the value of the corresponding record, else, it is `NULL'. `NULL' is returned when no record corresponds to the specified key. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. Although this function can be used even while the database file is locked by another process, it is not assured that recent updated is reflected.</dd>
639 </dl>
640
641 <p>The function `dpinnerhash' is a hash function used inside Depot.</p>
642
643 <dl>
644 <dt><kbd>int dpinnerhash(const char *<var>kbuf</var>, int <var>ksiz</var>);</kbd></dt>
645 <dd>`kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. The return value is the hash value of 31 bits length computed from the key. This function is useful when an application calculates the state of the inside bucket array.</dd>
646 </dl>
647
648 <p>The function `dpouterhash' is a hash function which is independent from the hash functions used inside Depot.</p>
649
650 <dl>
651 <dt><kbd>int dpouterhash(const char *<var>kbuf</var>, int <var>ksiz</var>);</kbd></dt>
652 <dd>`kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. The return value is the hash value of 31 bits length computed from the key. This function is useful when an application uses its own hash algorithm outside Depot.</dd>
653 </dl>
654
655 <p>The function `dpprimenum' is used in order to get a natural prime number not less than a number.</p>
656
657 <dl>
658 <dt><kbd>int dpprimenum(int <var>num</var>);</kbd></dt>
659 <dd>`num' specified a natural number. The return value is a natural prime number not less than the specified number. This function is useful when an application determines the size of a bucket array of its own hash algorithm.</dd>
660 </dl>
661
662 <h3>Examples</h3>
663
664 <p>The following example stores and retrieves a phone number, using the name as the key.</p>
665
666 <pre>#include &lt;depot.h&gt;
667 #include &lt;stdlib.h&gt;
668 #include &lt;stdio.h&gt;
669
670 #define NAME "mikio"
671 #define NUMBER "000-1234-5678"
672 #define DBNAME "book"
673
674 int main(int argc, char **argv){
675 DEPOT *depot;
676 char *val;
677
678 /* open the database */
679 if(!(depot = dpopen(DBNAME, DP_OWRITER | DP_OCREAT, -1))){
680 fprintf(stderr, "dpopen: %s\n", dperrmsg(dpecode));
681 return 1;
682 }
683
684 /* store the record */
685 if(!dpput(depot, NAME, -1, NUMBER, -1, DP_DOVER)){
686 fprintf(stderr, "dpput: %s\n", dperrmsg(dpecode));
687 }
688
689 /* retrieve the record */
690 if(!(val = dpget(depot, NAME, -1, 0, -1, NULL))){
691 fprintf(stderr, "dpget: %s\n", dperrmsg(dpecode));
692 } else {
693 printf("Name: %s\n", NAME);
694 printf("Number: %s\n", val);
695 free(val);
696 }
697
698 /* close the database */
699 if(!dpclose(depot)){
700 fprintf(stderr, "dpclose: %s\n", dperrmsg(dpecode));
701 return 1;
702 }
703
704 return 0;
705 }
706 </pre>
707
708 <p>The following example shows all records of the database.</p>
709
710 <pre>#include &lt;depot.h&gt;
711 #include &lt;stdlib.h&gt;
712 #include &lt;stdio.h&gt;
713
714 #define DBNAME "book"
715
716 int main(int argc, char **argv){
717 DEPOT *depot;
718 char *key, *val;
719
720 /* open the database */
721 if(!(depot = dpopen(DBNAME, DP_OREADER, -1))){
722 fprintf(stderr, "dpopen: %s\n", dperrmsg(dpecode));
723 return 1;
724 }
725
726 /* initialize the iterator */
727 if(!dpiterinit(depot)){
728 fprintf(stderr, "dpiterinit: %s\n", dperrmsg(dpecode));
729 }
730
731 /* scan with the iterator */
732 while((key = dpiternext(depot, NULL)) != NULL){
733 if(!(val = dpget(depot, key, -1, 0, -1, NULL))){
734 fprintf(stderr, "dpget: %s\n", dperrmsg(dpecode));
735 free(key);
736 break;
737 }
738 printf("%s: %s\n", key, val);
739 free(val);
740 free(key);
741 }
742
743 /* close the database */
744 if(!dpclose(depot)){
745 fprintf(stderr, "dpclose: %s\n", dperrmsg(dpecode));
746 return 1;
747 }
748
749 return 0;
750 }
751 </pre>
752
753 <h3>Notes</h3>
754
755 <p>For building a program using Depot, the program should be linked with a library file `libqdbm.a' or `libqdbm.so'. For example, the following command is executed to build `sample' from `sample.c'.</p>
756
757 <pre>gcc -I/usr/local/include -o sample sample.c -L/usr/local/lib -lqdbm
758 </pre>
759
760 <p>If QDBM was built with POSIX thread enabled, the global variable `dpecode' is treated as thread specific data, and functions of Depot are reentrant. In that case, they are thread-safe as long as a handle is not accessed by threads at the same time, on the assumption that `errno', `malloc', and so on are thread-safe.</p>
761
762 <hr />
763
764 <h2><a name="depotcli" id="depotcli" class="head">Commands for Depot</a></h2>
765
766 <p>Depot has the following command line interfaces.</p>
767
768 <p>The command `dpmgr' is a utility for debugging Depot and its applications. It features editing and checking of a database. It can be used for database applications with shell scripts. This command is used in the following format. `name' specifies a database name. `key' specifies the key of a record. `val' specifies the value of a record.</p>
769
770 <dl>
771 <dt><kbd>dpmgr create [-s] [-bnum <var>num</var>] <var>name</var></kbd></dt>
772 <dd>Create a database file.</dd>
773 <dt><kbd>dpmgr put [-kx|-ki] [-vx|-vi|-vf] [-keep|-cat] [-na] <var>name</var> <var>key</var> <var>val</var></kbd></dt>
774 <dd>Store a record with a key and a value.</dd>
775 <dt><kbd>dpmgr out [-kx|-ki] <var>name</var> <var>key</var></kbd></dt>
776 <dd>Delete a record with a key.</dd>
777 <dt><kbd>dpmgr get [-nl] [-kx|-ki] [-start <var>num</var>] [-max <var>num</var>] [-ox] [-n] <var>name</var> <var>key</var></kbd></dt>
778 <dd>Retrieve a record with a key and output it to the standard output.</dd>
779 <dt><kbd>dpmgr list [-nl] [-k|-v] [-ox] <var>name</var></kbd></dt>
780 <dd>List all keys and values delimited with tab and line-feed to the standard output.</dd>
781 <dt><kbd>dpmgr optimize [-bnum <var>num</var>] [-na] <var>name</var></kbd></dt>
782 <dd>Optimize a database.</dd>
783 <dt><kbd>dpmgr inform [-nl] <var>name</var></kbd></dt>
784 <dd>Output miscellaneous information to the standard output.</dd>
785 <dt><kbd>dpmgr remove <var>name</var></kbd></dt>
786 <dd>Remove a database file.</dd>
787 <dt><kbd>dpmgr repair <var>name</var></kbd></dt>
788 <dd>Repair a broken database file.</dd>
789 <dt><kbd>dpmgr exportdb <var>name</var> <var>file</var></kbd></dt>
790 <dd>Dump all records as endian independent data.</dd>
791 <dt><kbd>dpmgr importdb [-bnum <var>num</var>] <var>name</var> <var>file</var></kbd></dt>
792 <dd>Load all records from endian independent data.</dd>
793 <dt><kbd>dpmgr snaffle [-kx|-ki] [-ox] [-n] <var>name</var> <var>key</var></kbd></dt>
794 <dd>Retrieve a record from a locked database with a key and output it to the standard output.</dd>
795 <dt><kbd>dpmgr version</kbd></dt>
796 <dd>Output version information of QDBM to the standard output.</dd>
797 </dl>
798
799 <p>Options feature the following.</p>
800
801 <ul class="lines">
802 <li><kbd>-s</kbd> : make the file sparse.</li>
803 <li><kbd>-bnum <var>num</var></kbd> : specify the number of the elements of the bucket array.</li>
804 <li><kbd>-kx</kbd> : treat `key' as a binary expression of hexadecimal notation.</li>
805 <li><kbd>-ki</kbd> : treat `key' as an integer expression of decimal notation.</li>
806 <li><kbd>-vx</kbd> : treat `val' as a binary expression of hexadecimal notation.</li>
807 <li><kbd>-vi</kbd> : treat `val' as an integer expression of decimal notation.</li>
808 <li><kbd>-vf</kbd> : read the value from a file specified with `val'.</li>
809 <li><kbd>-keep</kbd> : specify the storing mode for `DP_DKEEP'.</li>
810 <li><kbd>-cat</kbd> : specify the storing mode for `DP_DCAT'.</li>
811 <li><kbd>-na</kbd> : do not set alignment.</li>
812 <li><kbd>-nl</kbd> : open the database without file locking.</li>
813 <li><kbd>-start</kbd> : specify the beginning offset of a value to fetch.</li>
814 <li><kbd>-max</kbd> : specify the max size of a value to fetch.</li>
815 <li><kbd>-ox</kbd> : treat the output as a binary expression of hexadecimal notation.</li>
816 <li><kbd>-n</kbd> : do not output the tailing newline.</li>
817 <li><kbd>-k</kbd> : output keys only.</li>
818 <li><kbd>-v</kbd> : output values only.</li>
819 </ul>
820
821 <p>This command returns 0 on success, another on failure. The environment variable `QDBMDBGFD' specifies the file descriptor to output the history of updating the variable `dpecode'.</p>
822
823 <p>The command `dptest' is a utility for facility test and performance test. Check a database generated by the command or measure the execution time of the command. This command is used in the following format. `name' specifies a database name. `rnum' specifies the number of the records. `bnum' specifies the number of the elements of the bucket array. `pnum' specifies the number of patterns of the keys. `align' specifies the basic size of alignment. `fbpsiz' specifies the size of the free block pool.</p>
824
825 <dl>
826 <dt><kbd>dptest write [-s] <var>name</var> <var>rnum</var> <var>bnum</var></kbd></dt>
827 <dd>Store records with keys of 8 bytes. They change as `00000001', `00000002'...</dd>
828 <dt><kbd>dptest read [-wb] <var>name</var></kbd></dt>
829 <dd>Retrieve all records of the database above.</dd>
830 <dt><kbd>dptest rcat [-c] <var>name</var> <var>rnum</var> <var>bnum</var> <var>pnum</var> <var>align</var> <var>fbpsiz</var></kbd></dt>
831 <dd>Store records with partway duplicated keys using concatenate mode.</dd>
832 <dt><kbd>dptest combo <var>name</var></kbd></dt>
833 <dd>Perform combination test of various operations.</dd>
834 <dt><kbd>dptest wicked [-c] <var>name</var> <var>rnum</var></kbd></dt>
835 <dd>Perform updating operations selected at random.</dd>
836 </dl>
837
838 <p>Options feature the following.</p>
839
840 <ul class="lines">
841 <li><kbd>-s</kbd> : make the file sparse.</li>
842 <li><kbd>-wb</kbd> : use the function `dpgetwb' instead of the function `dpget'.</li>
843 <li><kbd>-c</kbd> : perform comparison test with map of Cabin.</li>
844 </ul>
845
846 <p>This command returns 0 on success, another on failure. The environment variable `QDBMDBGFD' specifies the file descriptor to output the history of updating the variable `dpecode'.</p>
847
848 <p>The command `dptsv' features mutual conversion between a database of Depot and a TSV text. This command is useful when data exchange with another version of QDBM or another DBM, or when data exchange between systems which have different byte orders. This command is used in the following format. `name' specifies a database name. The subcommand `export' reads TSV data from the standard input. If a key overlaps, the latter is adopted. `-bnum' specifies the number of the elements of the bucket array. The subcommand `import' writes TSV data to the standard output.</p>
849
850 <dl>
851 <dt><kbd>dptsv import [-bnum <var>num</var>] [-bin] <var>name</var></kbd></dt>
852 <dd>Create a database from TSV.</dd>
853 <dt><kbd>dptsv export [-bin] <var>name</var></kbd></dt>
854 <dd>Write TSV data of a database.</dd>
855 </dl>
856
857 <p>Options feature the following.</p>
858
859 <ul class="lines">
860 <li><kbd>-bnum <var>num</var></kbd> : specify the number of the elements of the bucket array.</li>
861 <li><kbd>-bin</kbd> : treat records as Base64 format.</li>
862 </ul>
863
864 <p>This command returns 0 on success, another on failure.</p>
865
866 <p>Commands of Depot realize a simple database system. For example, to make a database to search `/etc/password' by a user name, perform the following command.</p>
867
868 <pre>cat /etc/passwd | tr ':' '\t' | dptsv import casket
869 </pre>
870
871 <p>Thus, to retrieve the information of a user `mikio', perform the following command.</p>
872
873 <pre>dpmgr get casket mikio
874 </pre>
875
876 <p>It is easy to implement functions upsides with these commands, using the API of Depot.</p>
877
878 <hr />
879
880 <h2><a name="curiaapi" id="curiaapi" class="head">Curia: Extended API</a></h2>
881
882 <h3>Overview</h3>
883
884 <p>Curia is the extended API of QDBM. It provides routines for managing multiple database files in a directory. Restrictions of some file systems that the size of each file is limited are escaped by dividing a database file into two or more. If the database files deploy on multiple devices, the scalability is improved.</p>
885
886 <p>Although Depot creates a database with a file name, Curia creates a database with a directory name. A database file named as `depot' is placed in the specified directory. Although it keeps the attribute of the database, it does not keep the entities of the records. Besides, sub directories are created by the number of division of the database, named with 4 digits. The database files are placed in the subdirectories. The entities of the records are stored in the database file. For example, in the case that a database directory named as `casket' and the number of division is 3, `casket/depot', `casket/0001/depot', `casket/0002/depot' and `casket/0003/depot' are created. No error occurs even if the namesake directory exists when creating a database. So, if sub directories exists and some devices are mounted on the sub directories, the database files deploy on the multiple devices.</p>
887
888 <p>Curia features managing large objects. Although usual records are stored in some database files, records of large objects are stored in individual files. Because the files of large objects are deployed in different directories named with the hash values, the access speed is part-way robust although it is slower than the speed of usual records. Large and not often accessed data should be secluded as large objects. By doing this, the access speed of usual records is improved. The directory hierarchies of large objects are placed in the directory named as `lob' in the sub directories of the database. Because the key spaces of the usual records and the large objects are different, the operations keep out of each other.</p>
889
890 <p>In order to use Curia, you should include `depot.h', `curia.h' and `stdlib.h' in the source files. Usually, the following description will be near the beginning of a source file.</p>
891
892 <dl>
893 <dt><kbd>#include &lt;depot.h&gt;</kbd></dt>
894 <dt><kbd>#include &lt;curia.h&gt;</kbd></dt>
895 <dt><kbd>#include &lt;stdlib.h&gt;</kbd></dt>
896 </dl>
897
898 <p>A pointer to `CURIA' is used as a database handle. It is like that some file I/O routines of `stdio.h' use a pointer to `FILE'. A database handle is opened with the function `cropen' and closed with `crclose'. You should not refer directly to any member of the handle. If a fatal error occurs in a database, any access method via the handle except `crclose' will not work and return error status. Although a process is allowed to use multiple database handles at the same time, handles of the same database directory should not be used.</p>
899
900 <p>Curia also assign the external variable `dpecode' with the error code. The function `dperrmsg' is used in order to get the message of the error code.</p>
901
902 <h3>API</h3>
903
904 <p>The function `cropen' is used in order to get a database handle.</p>
905
906 <dl>
907 <dt><kbd>CURIA *cropen(const char *<var>name</var>, int <var>omode</var>, int <var>bnum</var>, int <var>dnum</var>);</kbd></dt>
908 <dd>`name' specifies the name of a database directory. `omode' specifies the connection mode: `CR_OWRITER' as a writer, `CR_OREADER' as a reader. If the mode is `CR_OWRITER', the following may be added by bitwise or: `CR_OCREAT', which means it creates a new database if not exist, `CR_OTRUNC', which means it creates a new database regardless if one exists. Both of `CR_OREADER' and `CR_OWRITER' can be added to by bitwise or: `CR_ONOLCK', which means it opens a database directory without file locking, or `CR_OLCKNB', which means locking is performed without blocking. `CR_OCREAT' can be added to by bitwise or: `CR_OSPARSE', which means it creates database files as sparse files. `bnum' specifies the number of elements of each bucket array. If it is not more than 0, the default value is specified. The size of each bucket array is determined on creating, and can not be changed except for by optimization of the database. Suggested size of each bucket array is about from 0.5 to 4 times of the number of all records to store. `dnum' specifies the number of division of the database. If it is not more than 0, the default value is specified. The number of division can not be changed from the initial value. The max number of division is 512. The return value is the database handle or `NULL' if it is not successful. While connecting as a writer, an exclusive lock is invoked to the database directory. While connecting as a reader, a shared lock is invoked to the database directory. The thread blocks until the lock is achieved. If `CR_ONOLCK' is used, the application is responsible for exclusion control.</dd>
909 </dl>
910
911 <p>The function `crclose' is used in order to close a database handle.</p>
912
913 <dl>
914 <dt><kbd>int crclose(CURIA *<var>curia</var>);</kbd></dt>
915 <dd>`curia' specifies a database handle. If successful, the return value is true, else, it is false. Because the region of a closed handle is released, it becomes impossible to use the handle. Updating a database is assured to be written when the handle is closed. If a writer opens a database but does not close it appropriately, the database will be broken.</dd>
916 </dl>
917
918 <p>The function `crput' is used in order to store a record.</p>
919
920 <dl>
921 <dt><kbd>int crput(CURIA *<var>curia</var>, const char *<var>kbuf</var>, int <var>ksiz</var>, const char *<var>vbuf</var>, int <var>vsiz</var>, int <var>dmode</var>);</kbd></dt>
922 <dd>`curia' specifies a database handle connected as a writer. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `vbuf' specifies the pointer to the region of a value. `vsiz' specifies the size of the region of the value. If it is negative, the size is assigned with `strlen(vbuf)'. `dmode' specifies behavior when the key overlaps, by the following values: `CR_DOVER', which means the specified value overwrites the existing one, `CR_DKEEP', which means the existing value is kept, `CR_DCAT', which means the specified value is concatenated at the end of the existing value. If successful, the return value is true, else, it is false.</dd>
923 </dl>
924
925 <p>The function `crout' is used in order to delete a record.</p>
926
927 <dl>
928 <dt><kbd>int crout(CURIA *<var>curia</var>, const char *<var>kbuf</var>, int <var>ksiz</var>);</kbd></dt>
929 <dd>`curia' specifies a database handle connected as a writer. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. If successful, the return value is true, else, it is false. False is returned when no record corresponds to the specified key.</dd>
930 </dl>
931
932 <p>The function `crget' is used in order to retrieve a record.</p>
933
934 <dl>
935 <dt><kbd>char *crget(CURIA *<var>curia</var>, const char *<var>kbuf</var>, int <var>ksiz</var>, int <var>start</var>, int <var>max</var>, int *<var>sp</var>);</kbd></dt>
936 <dd>`curia' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `start' specifies the offset address of the beginning of the region of the value to be read. `max' specifies the max size to be read. If it is negative, the size to read is unlimited. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the region of the value of the corresponding record, else, it is `NULL'. `NULL' is returned when no record corresponds to the specified key or the size of the value of the corresponding record is less than `start'. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
937 </dl>
938
939 <p>The function `crgetwb' is used in order to retrieve a record and write the value into a buffer.</p>
940
941 <dl>
942 <dt><kbd>int crgetwb(CURIA *<var>curia</var>, const char *<var>kbuf</var>, int <var>ksiz</var>, int <var>start</var>, int <var>max</var>, char *<var>vbuf</var>);</kbd></dt>
943 <dd>`curia' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `start' specifies the offset address of the beginning of the region of the value to be read. `max' specifies the max size to be read. It shuld be equal to or less than the size of the writing buffer. `vbuf' specifies the pointer to a buffer into which the value of the corresponding record is written. If successful, the return value is the size of the written data, else, it is -1. -1 is returned when no record corresponds to the specified key or the size of the value of the corresponding record is less than `start'. Note that no additional zero code is appended at the end of the region of the writing buffer.</dd>
944 </dl>
945
946 <p>The function `crvsiz' is used in order to get the size of the value of a record.</p>
947
948 <dl>
949 <dt><kbd>int crvsiz(CURIA *<var>curia</var>, const char *<var>kbuf</var>, int <var>ksiz</var>);</kbd></dt>
950 <dd>`curia' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. If successful, the return value is the size of the value of the corresponding record, else, it is -1. Because this function does not read the entity of a record, it is faster than `crget'.</dd>
951 </dl>
952
953 <p>The function `criterinit' is used in order to initialize the iterator of a database handle.</p>
954
955 <dl>
956 <dt><kbd>int criterinit(CURIA *<var>curia</var>);</kbd></dt>
957 <dd>`curia' specifies a database handle. If successful, the return value is true, else, it is false. The iterator is used in order to access the key of every record stored in a database.</dd>
958 </dl>
959
960 <p>The function `criternext' is used in order to get the next key of the iterator.</p>
961
962 <dl>
963 <dt><kbd>char *criternext(CURIA *<var>curia</var>, int *<var>sp</var>);</kbd></dt>
964 <dd>`curia' specifies a database handle. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the region of the next key, else, it is `NULL'. `NULL' is returned when no record is to be get out of the iterator. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. It is possible to access every record by iteration of calling this function. However, it is not assured if updating the database is occurred while the iteration. Besides, the order of this traversal access method is arbitrary, so it is not assured that the order of storing matches the one of the traversal access.</dd>
965 </dl>
966
967 <p>The function `crsetalign' is used in order to set alignment of a database handle.</p>
968
969 <dl>
970 <dt><kbd>int crsetalign(CURIA *<var>curia</var>, int <var>align</var>);</kbd></dt>
971 <dd>`curia' specifies a database handle connected as a writer. `align' specifies the size of alignment. If successful, the return value is true, else, it is false. If alignment is set to a database, the efficiency of overwriting values is improved. The size of alignment is suggested to be average size of the values of the records to be stored. If alignment is positive, padding whose size is multiple number of the alignment is placed. If alignment is negative, as `vsiz' is the size of a value, the size of padding is calculated with `(vsiz / pow(2, abs(align) - 1))'. Because alignment setting is not saved in a database, you should specify alignment every opening a database.</dd>
972 </dl>
973
974 <p>The function `crsetfbpsiz' is used in order to set the size of the free block pool of a database handle.</p>
975
976 <dl>
977 <dt><kbd>int crsetfbpsiz(CURIA *<var>curia</var>, int <var>size</var>);</kbd></dt>
978 <dd>`curia' specifies a database handle connected as a writer. `size' specifies the size of the free block pool of a database. If successful, the return value is true, else, it is false. The default size of the free block pool is 16. If the size is greater, the space efficiency of overwriting values is improved with the time efficiency sacrificed.</dd>
979 </dl>
980
981 <p>The function `crsync' is used in order to synchronize updating contents with the files and the devices.</p>
982
983 <dl>
984 <dt><kbd>int crsync(CURIA *<var>curia</var>);</kbd></dt>
985 <dd>`curia' specifies a database handle connected as a writer. If successful, the return value is true, else, it is false. This function is useful when another process uses the connected database directory.</dd>
986 </dl>
987
988 <p>The function `croptimize' is used in order to optimize a database.</p>
989
990 <dl>
991 <dt><kbd>int croptimize(CURIA *<var>curia</var>, int <var>bnum</var>);</kbd></dt>
992 <dd>`curia' specifies a database handle connected as a writer. `bnum' specifies the number of the elements of each bucket array. If it is not more than 0, the default value is specified. In an alternating succession of deleting and storing with overwrite or concatenate, dispensable regions accumulate. This function is useful to do away with them.</dd>
993 </dl>
994
995 <p>The function `crname' is used in order to get the name of a database.</p>
996
997 <dl>
998 <dt><kbd>char *crname(CURIA *<var>curia</var>);</kbd></dt>
999 <dd>`curia' specifies a database handle. If successful, the return value is the pointer to the region of the name of the database, else, it is `NULL'. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
1000 </dl>
1001
1002 <p>The function `crfsiz' is used in order to get the total size of database files.</p>
1003
1004 <dl>
1005 <dt><kbd>int crfsiz(CURIA *<var>curia</var>);</kbd></dt>
1006 <dd>`curia' specifies a database handle. If successful, the return value is the total size of the database files, else, it is -1. If the total size is more than 2GB, the return value overflows.</dd>
1007 </dl>
1008
1009 <p>The function `crfsizd' is used in order to get the total size of database files as double-precision floating-point number.</p>
1010
1011 <dl>
1012 <dt><kbd>double crfsizd(CURIA *<var>curia</var>);</kbd></dt>
1013 <dd>`curia' specifies a database handle. If successful, the return value is the total size of the database files, else, it is -1.0.</dd>
1014 </dl>
1015
1016 <p>The function `crbnum' is used in order to get the total number of the elements of each bucket array.</p>
1017
1018 <dl>
1019 <dt><kbd>int crbnum(CURIA *<var>curia</var>);</kbd></dt>
1020 <dd>`curia' specifies a database handle. If successful, the return value is the total number of the elements of each bucket array, else, it is -1.</dd>
1021 </dl>
1022
1023 <p>The function `crbusenum' is used in order to get the total number of the used elements of each bucket array.</p>
1024
1025 <dl>
1026 <dt><kbd>int crbusenum(CURIA *<var>curia</var>);</kbd></dt>
1027 <dd>`curia' specifies a database handle. If successful, the return value is the total number of the used elements of each bucket array, else, it is -1. This function is inefficient because it accesses all elements of each bucket array.</dd>
1028 </dl>
1029
1030 <p>The function `crrnum' is used in order to get the number of the records stored in a database.</p>
1031
1032 <dl>
1033 <dt><kbd>int crrnum(CURIA *<var>curia</var>);</kbd></dt>
1034 <dd>`curia' specifies a database handle. If successful, the return value is the number of the records stored in the database, else, it is -1.</dd>
1035 </dl>
1036
1037 <p>The function `crwritable' is used in order to check whether a database handle is a writer or not.</p>
1038
1039 <dl>
1040 <dt><kbd>int crwritable(CURIA *<var>curia</var>);</kbd></dt>
1041 <dd>`curia' specifies a database handle. The return value is true if the handle is a writer, false if not.</dd>
1042 </dl>
1043
1044 <p>The function `crfatalerror' is used in order to check whether a database has a fatal error or not.</p>
1045
1046 <dl>
1047 <dt><kbd>int crfatalerror(CURIA *<var>curia</var>);</kbd></dt>
1048 <dd>`curia' specifies a database handle. The return value is true if the database has a fatal error, false if not.</dd>
1049 </dl>
1050
1051 <p>The function `crinode' is used in order to get the inode number of a database directory.</p>
1052
1053 <dl>
1054 <dt><kbd>int crinode(CURIA *<var>curia</var>);</kbd></dt>
1055 <dd>`curia' specifies a database handle. The return value is the inode number of the database directory.</dd>
1056 </dl>
1057
1058 <p>The function `crmtime' is used in order to get the last modified time of a database.</p>
1059
1060 <dl>
1061 <dt><kbd>time_t crmtime(CURIA *<var>curia</var>);</kbd></dt>
1062 <dd>`curia' specifies a database handle. The return value is the last modified time of the database.</dd>
1063 </dl>
1064
1065 <p>The function `crremove' is used in order to remove a database directory.</p>
1066
1067 <dl>
1068 <dt><kbd>int crremove(const char *<var>name</var>);</kbd></dt>
1069 <dd>`name' specifies the name of a database directory. If successful, the return value is true, else, it is false.</dd>
1070 </dl>
1071
1072 <p>The function `crrepair' is used in order to repair a broken database directory.</p>
1073
1074 <dl>
1075 <dt><kbd>int crrepair(const char *<var>name</var>);</kbd></dt>
1076 <dd>`name' specifies the name of a database directory. If successful, the return value is true, else, it is false. There is no guarantee that all records in a repaired database directory correspond to the original or expected state.</dd>
1077 </dl>
1078
1079 <p>The function `crexportdb' is used in order to dump all records as endian independent data.</p>
1080
1081 <dl>
1082 <dt><kbd>int crexportdb(CURIA *<var>curia</var>, const char *<var>name</var>);</kbd></dt>
1083 <dd>`curia' specifies a database handle. `name' specifies the name of an output directory. If successful, the return value is true, else, it is false. Note that large objects are ignored.</dd>
1084 </dl>
1085
1086 <p>The function `crimportdb' is used in order to load all records from endian independent data.</p>
1087
1088 <dl>
1089 <dt><kbd>int crimportdb(CURIA *<var>curia</var>, const char *<var>name</var>);</kbd></dt>
1090 <dd>`curia' specifies a database handle connected as a writer. The database of the handle must be empty. `name' specifies the name of an input directory. If successful, the return value is true, else, it is false. Note that large objects are ignored.</dd>
1091 </dl>
1092
1093 <p>The function `crsnaffle' is used in order to retrieve a record directly from a database directory.</p>
1094
1095 <dl>
1096 <dt><kbd>char *crsnaffle(const char *<var>name</var>, const char *<var>kbuf</var>, int <var>ksiz</var>, int *<var>sp</var>);</kbd></dt>
1097 <dd>`name' specifies the name of a database directory. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the region of the value of the corresponding record, else, it is `NULL'. `NULL' is returned when no record corresponds to the specified key. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. Although this function can be used even while the database directory is locked by another process, it is not assured that recent updated is reflected.</dd>
1098 </dl>
1099
1100 <p>The function `crputlob' is used in order to store a large object.</p>
1101
1102 <dl>
1103 <dt><kbd>int crputlob(CURIA *<var>curia</var>, const char *<var>kbuf</var>, int <var>ksiz</var>, const char *<var>vbuf</var>, int <var>vsiz</var>, int <var>dmode</var>);</kbd></dt>
1104 <dd>`curia' specifies a database handle connected as a writer. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `vbuf' specifies the pointer to the region of a value. `vsiz' specifies the size of the region of the value. If it is negative, the size is assigned with `strlen(vbuf)'. `dmode' specifies behavior when the key overlaps, by the following values: `CR_DOVER', which means the specified value overwrites the existing one, `CR_DKEEP', which means the existing value is kept, `CR_DCAT', which means the specified value is concatenated at the end of the existing value. If successful, the return value is true, else, it is false.</dd>
1105 </dl>
1106
1107 <p>The function `croutlob' is used in order to delete a large object.</p>
1108
1109 <dl>
1110 <dt><kbd>int croutlob(CURIA *<var>curia</var>, const char *<var>kbuf</var>, int <var>ksiz</var>);</kbd></dt>
1111 <dd>`curia' specifies a database handle connected as a writer. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. If successful, the return value is true, else, it is false. false is returned when no large object corresponds to the specified key.</dd>
1112 </dl>
1113
1114 <p>The function `crgetlob' is used in order to retrieve a large object.</p>
1115
1116 <dl>
1117 <dt><kbd>char *crgetlob(CURIA *<var>curia</var>, const char *<var>kbuf</var>, int <var>ksiz</var>, int <var>start</var>, int <var>max</var>, int *<var>sp</var>);</kbd></dt>
1118 <dd>`curia' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `start' specifies the offset address of the beginning of the region of the value to be read. `max' specifies the max size to be read. If it is negative, the size to read is unlimited. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the region of the value of the corresponding large object, else, it is `NULL'. `NULL' is returned when no large object corresponds to the specified key or the size of the value of the corresponding large object is less than `start'. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
1119 </dl>
1120
1121 <p>The function `crgetlobfd' is used in order to get the file descriptor of a large object.</p>
1122
1123 <dl>
1124 <dt><kbd>int crgetlobfd(CURIA *<var>curia</var>, const char *<var>kbuf</var>, int <var>ksiz</var>);</kbd></dt>
1125 <dd>`curia' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. If successful, the return value is the file descriptor of the corresponding large object, else, it is -1. -1 is returned when no large object corresponds to the specified key. The returned file descriptor is opened with the `open' call. If the database handle was opened as a writer, the descriptor is writable (O_RDWR), else, it is not writable (O_RDONLY). The descriptor should be closed with the `close' call if it is no longer in use.</dd>
1126 </dl>
1127
1128 <p>The function `crvsizlob' is used in order to get the size of the value of a large object.</p>
1129
1130 <dl>
1131 <dt><kbd>int crvsizlob(CURIA *<var>curia</var>, const char *<var>kbuf</var>, int <var>ksiz</var>);</kbd></dt>
1132 <dd>`curia' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. If successful, the return value is the size of the value of the corresponding large object, else, it is -1. Because this function does not read the entity of a large object, it is faster than `crgetlob'.</dd>
1133 </dl>
1134
1135 <p>The function `crrnumlob' is used in order to get the number of the large objects stored in a database.</p>
1136
1137 <dl>
1138 <dt><kbd>int crrnumlob(CURIA *<var>curia</var>);</kbd></dt>
1139 <dd>`curia' specifies a database handle. If successful, the return value is the number of the large objects stored in the database, else, it is -1.</dd>
1140 </dl>
1141
1142 <h3>Examples</h3>
1143
1144 <p>The following example stores and retrieves a phone number, using the name as the key.</p>
1145
1146 <pre>#include &lt;depot.h&gt;
1147 #include &lt;curia.h&gt;
1148 #include &lt;stdlib.h&gt;
1149 #include &lt;stdio.h&gt;
1150
1151 #define NAME "mikio"
1152 #define NUMBER "000-1234-5678"
1153 #define DBNAME "book"
1154
1155 int main(int argc, char **argv){
1156 CURIA *curia;
1157 char *val;
1158
1159 /* open the database */
1160 if(!(curia = cropen(DBNAME, CR_OWRITER | CR_OCREAT, -1, -1))){
1161 fprintf(stderr, "cropen: %s\n", dperrmsg(dpecode));
1162 return 1;
1163 }
1164
1165 /* store the record */
1166 if(!crput(curia, NAME, -1, NUMBER, -1, CR_DOVER)){
1167 fprintf(stderr, "crput: %s\n", dperrmsg(dpecode));
1168 }
1169
1170 /* retrieve the record */
1171 if(!(val = crget(curia, NAME, -1, 0, -1, NULL))){
1172 fprintf(stderr, "crget: %s\n", dperrmsg(dpecode));
1173 } else {
1174 printf("Name: %s\n", NAME);
1175 printf("Number: %s\n", val);
1176 free(val);
1177 }
1178
1179 /* close the database */
1180 if(!crclose(curia)){
1181 fprintf(stderr, "crclose: %s\n", dperrmsg(dpecode));
1182 return 1;
1183 }
1184
1185 return 0;
1186 }
1187 </pre>
1188
1189 <p>The following example shows all records of the database.</p>
1190
1191 <pre>#include &lt;depot.h&gt;
1192 #include &lt;curia.h&gt;
1193 #include &lt;stdlib.h&gt;
1194 #include &lt;stdio.h&gt;
1195
1196 #define DBNAME "book"
1197
1198 int main(int argc, char **argv){
1199 CURIA *curia;
1200 char *key, *val;
1201
1202 /* open the database */
1203 if(!(curia = cropen(DBNAME, CR_OREADER, -1, -1))){
1204 fprintf(stderr, "cropen: %s\n", dperrmsg(dpecode));
1205 return 1;
1206 }
1207
1208 /* initialize the iterator */
1209 if(!criterinit(curia)){
1210 fprintf(stderr, "criterinit: %s\n", dperrmsg(dpecode));
1211 }
1212
1213 /* scan with the iterator */
1214 while((key = criternext(curia, NULL)) != NULL){
1215 if(!(val = crget(curia, key, -1, 0, -1, NULL))){
1216 fprintf(stderr, "crget: %s\n", dperrmsg(dpecode));
1217 free(key);
1218 break;
1219 }
1220 printf("%s: %s\n", key, val);
1221 free(val);
1222 free(key);
1223 }
1224
1225 /* close the iterator */
1226 if(!crclose(curia)){
1227 fprintf(stderr, "crclose: %s\n", dperrmsg(dpecode));
1228 return 1;
1229 }
1230
1231 return 0;
1232 }
1233 </pre>
1234
1235 <h3>Notes</h3>
1236
1237 <p>How to build programs using Curia is the same as the case of Depot.</p>
1238
1239 <pre>gcc -I/usr/local/include -o sample sample.c -L/usr/local/lib -lqdbm
1240 </pre>
1241
1242 <p>If QDBM was built with POSIX thread enabled, the global variable `dpecode' is treated as thread specific data, and functions of Curia are reentrant. In that case, they are thread-safe as long as a handle is not accessed by threads at the same time, on the assumption that `errno', `malloc', and so on are thread-safe.</p>
1243
1244 <hr />
1245
1246 <h2><a name="curiacli" id="curiacli" class="head">Commands for Curia</a></h2>
1247
1248 <p>Curia has the following command line interfaces.</p>
1249
1250 <p>The command `crmgr' is a utility for debugging Curia and its applications. It features editing and checking of a database. It can be used for the database applications with shell scripts. This command is used in the following format. `name' specifies a database name. `key' specifies the key of a record. `val' specifies the value of a record.</p>
1251
1252 <dl>
1253 <dt><kbd>crmgr create [-s] [-bnum <var>num</var>] [-dnum <var>num</var>] <var>name</var></kbd></dt>
1254 <dd>Create a database file.</dd>
1255 <dt><kbd>crmgr put [-kx|-ki] [-vx|-vi|-vf] [-keep|-cat] [-lob] [-na] <var>name</var> <var>key</var> <var>val</var></kbd></dt>
1256 <dd>Store a record with a key and a value.</dd>
1257 <dt><kbd>crmgr out [-kx|-ki] [-lob] <var>name</var> <var>key</var></kbd></dt>
1258 <dd>Delete a record with a key.</dd>
1259 <dt><kbd>crmgr get [-nl] [-kx|-ki] [-start <var>num</var>] [-max <var>num</var>] [-ox] [-lob] [-n] <var>name</var> <var>key</var></kbd></dt>
1260 <dd>Retrieve a record with a key and output it to the standard output.</dd>
1261 <dt><kbd>crmgr list [-nl] [-k|-v] [-ox] <var>name</var></kbd></dt>
1262 <dd>List all keys and values delimited with tab and line-feed to the standard output.</dd>
1263 <dt><kbd>crmgr optimize [-bnum <var>num</var>] [-na] <var>name</var></kbd></dt>
1264 <dd>Optimize a database.</dd>
1265 <dt><kbd>crmgr inform [-nl] <var>name</var></kbd></dt>
1266 <dd>Output miscellaneous information to the standard output.</dd>
1267 <dt><kbd>crmgr remove <var>name</var></kbd></dt>
1268 <dd>Remove a database directory.</dd>
1269 <dt><kbd>crmgr repair <var>name</var></kbd></dt>
1270 <dd>Repair a broken database directory.</dd>
1271 <dt><kbd>crmgr exportdb <var>name</var> <var>dir</var></kbd></dt>
1272 <dd>Dump all records as endian independent data.</dd>
1273 <dt><kbd>crmgr importdb [-bnum <var>num</var>] [-dnum <var>num</var>] <var>name</var> <var>dir</var></kbd></dt>
1274 <dd>Load all records from endian independent data.</dd>
1275 <dt><kbd>crmgr snaffle [-kx|-ki] [-ox] [-n] <var>name</var> <var>key</var></kbd></dt>
1276 <dd>Retrieve a record from a locked database with a key and output it to the standard output.</dd>
1277 <dt><kbd>crmgr version</kbd></dt>
1278 <dd>Output version information of QDBM to the standard output.</dd>
1279 </dl>
1280
1281 <p>Options feature the following.</p>
1282
1283 <ul class="lines">
1284 <li><kbd>-s</kbd> : make the files sparse.</li>
1285 <li><kbd>-bnum <var>num</var></kbd> : specify the number of elements of each bucket array.</li>
1286 <li><kbd>-dnum <var>num</var></kbd> : specify the number of division of the database.</li>
1287 <li><kbd>-kx</kbd> : treat `key' as a binary expression of hexadecimal notation.</li>
1288 <li><kbd>-ki</kbd> : treat `key' as an integer expression of decimal notation.</li>
1289 <li><kbd>-vx</kbd> : treat `val' as a binary expression of hexadecimal notation.</li>
1290 <li><kbd>-vi</kbd> : treat `val' as an integer expression of decimal notation.</li>
1291 <li><kbd>-vf</kbd> : read the value from a file specified with `val'.</li>
1292 <li><kbd>-keep</kbd> : specify the storing mode for `CR_DKEEP'.</li>
1293 <li><kbd>-cat</kbd> : specify the storing mode for `CR_DCAT'.</li>
1294 <li><kbd>-na</kbd> : do not set alignment.</li>
1295 <li><kbd>-nl</kbd> : open the database without file locking.</li>
1296 <li><kbd>-start</kbd> : specify the beginning offset of a value to fetch.</li>
1297 <li><kbd>-max</kbd> : specify the max size of a value to fetch.</li>
1298 <li><kbd>-ox</kbd> : treat the output as a binary expression of hexadecimal notation.</li>
1299 <li><kbd>-lob</kbd> : handle large objects.</li>
1300 <li><kbd>-n</kbd> : do not output the tailing newline.</li>
1301 <li><kbd>-k</kbd> : output keys only.</li>
1302 <li><kbd>-v</kbd> : output values only.</li>
1303 </ul>
1304
1305 <p>This command returns 0 on success, another on failure. The environment variable `QDBMDBGFD' specifies the file descriptor to output the history of updating the variable `dpecode'.</p>
1306
1307 <p>The command `crtest' is a utility for facility test and performance test. Check a database generated by the command or measure the execution time of the command. This command is used in the following format. `name' specifies a database name. `rnum' specifies the number of records. `bnum' specifies the number of elements of a bucket array. `dnum' specifies the number of division of a database. `pnum' specifies the number of patterns of the keys. `align' specifies the basic size of alignment. `fbpsiz' specifies the size of the free block pool.</p>
1308
1309 <dl>
1310 <dt><kbd>crtest write [-s] [-lob] <var>name</var> <var>rnum</var> <var>bnum</var> <var>dnum</var></kbd></dt>
1311 <dd>Store records with keys of 8 bytes. They change as `00000001', `00000002'...</dd>
1312 <dt><kbd>crtest read [-wb] [-lob] <var>name</var></kbd></dt>
1313 <dd>Retrieve all records of the database above.</dd>
1314 <dt><kbd>crtest rcat [-c] <var>name</var> <var>rnum</var> <var>bnum</var> <var>dnum</var> <var>pnum</var> <var>align</var> <var>fbpsiz</var></kbd></dt>
1315 <dd>Store records with partway duplicated keys using concatenate mode.</dd>
1316 <dt><kbd>crtest combo <var>name</var></kbd></dt>
1317 <dd>Perform combination test of various operations.</dd>
1318 <dt><kbd>crtest wicked [-c] <var>name</var> <var>rnum</var></kbd></dt>
1319 <dd>Perform updating operations selected at random.</dd>
1320 </dl>
1321
1322 <p>Options feature the following.</p>
1323
1324 <ul class="lines">
1325 <li><kbd>-s</kbd> : make the files sparse.</li>
1326 <li><kbd>-lob</kbd> : handle large objects.</li>
1327 <li><kbd>-wb</kbd> : use the function `crgetwb' instead of the function `crget'.</li>
1328 <li><kbd>-c</kbd> : perform comparison test with map of Cabin.</li>
1329 </ul>
1330
1331 <p>This command returns 0 on success, another on failure. The environment variable `QDBMDBGFD' specifies the file descriptor to output the history of updating the variable `dpecode'.</p>
1332
1333 <p>The command `crtsv' features mutual conversion between a database of Curia and a TSV text. This command is useful when data exchange with another version of QDBM or another DBM, or when data exchange between systems which have different byte orders. This command is used in the following format. `name' specifies a database name. The subcommand `export' reads TSV data from the standard input. If a key overlaps, the latter is adopted. `-bnum' specifies the number of the elements of the bucket array. `-dnum' specifies the number of division of the database. The subcommand `import' writes TSV data to the standard output.</p>
1334
1335 <dl>
1336 <dt><kbd>crtsv import [-bnum <var>num</var>] [-dnum <var>num</var>] [-bin] <var>name</var></kbd></dt>
1337 <dd>Create a database from TSV.</dd>
1338 <dt><kbd>crtsv export [-bin] <var>name</var></kbd></dt>
1339 <dd>Write TSV data of a database.</dd>
1340 </dl>
1341
1342 <p>Options feature the following.</p>
1343
1344 <ul class="lines">
1345 <li><kbd>-bnum <var>num</var></kbd> : specify the number of the elements of the bucket array.</li>
1346 <li><kbd>-dnum <var>num</var></kbd> : specify the number of division of the database.</li>
1347 <li><kbd>-bin</kbd> : treat records as Base64 format.</li>
1348 </ul>
1349
1350 <p>This command returns 0 on success, another on failure.</p>
1351
1352 <p>Commands of Curia realize a simple database system. For example, to make a database to search `/etc/password' by a user name, perform the following command.</p>
1353
1354 <pre>cat /etc/passwd | tr ':' '\t' | crtsv import casket
1355 </pre>
1356
1357 <p>Thus, to retrieve the information of a user `mikio', perform the following command.</p>
1358
1359 <pre>crmgr get casket mikio
1360 </pre>
1361
1362 <p>It is easy to implement functions upsides with these commands, using the API of Curia.</p>
1363
1364 <hr />
1365
1366 <h2><a name="relicapi" id="relicapi" class="head">Relic: NDBM-compatible API</a></h2>
1367
1368 <h3>Overview</h3>
1369
1370 <p>Relic is the API which is compatible with NDBM. So, Relic wraps functions of Depot as API of NDBM. It is easy to port an application from NDBM to QDBM. In most cases, you should only replace the includings of `ndbm.h' with `relic.h' and replace the linking option `-lndbm' with `-lqdbm'.</p>
1371
1372 <p>The original NDBM treats a database as a pair of files. One, `a directory file', has a name with suffix `.dir' and stores a bit map of keys. The other, `a data file', has a name with suffix `.pag' and stores entities of each records. Relic creates the directory file as a mere dummy file and creates the data file as a database. Relic has no restriction about the size of each record. Relic can not handle database files made by the original NDBM.</p>
1373
1374 <p>In order to use Relic, you should include `relic.h', `stdlib.h', `sys/types.h', `sys/stat.h' and `fcntl.h' in the source files. Usually, the following description will be near the beginning of a source file.</p>
1375
1376 <dl>
1377 <dt><kbd>#include &lt;relic.h&gt;</kbd></dt>
1378 <dt><kbd>#include &lt;stdlib.h&gt;</kbd></dt>
1379 <dt><kbd>#include &lt;sys/types.h&gt;</kbd></dt>
1380 <dt><kbd>#include &lt;sys/stat.h&gt;</kbd></dt>
1381 <dt><kbd>#include &lt;fcntl.h&gt;</kbd></dt>
1382 </dl>
1383
1384 <p>A pointer to `DBM' is used as a database handle. A database handle is opened with the function `dbm_open' and closed with `dbm_close'. You should not refer directly to any member of a handle.</p>
1385
1386 <h3>API</h3>
1387
1388 <p>Structures of `datum' type is used in order to give and receive data of keys and values with functions of Relic.</p>
1389
1390 <dl>
1391 <dt><kbd>typedef struct { void *dptr; size_t dsize; } datum;</kbd></dt>
1392 <dd>`dptr' specifies the pointer to the region of a key or a value. `dsize' specifies the size of the region.</dd>
1393 </dl>
1394
1395 <p>The function `dbm_open' is used in order to get a database handle.</p>
1396
1397 <dl>
1398 <dt><kbd>DBM *dbm_open(char *<var>name</var>, int <var>flags</var>, int <var>mode</var>);</kbd></dt>
1399 <dd>`name' specifies the name of a database. The file names are concatenated with suffixes. `flags' is the same as the one of `open' call, although `O_WRONLY' is treated as `O_RDWR' and additional flags except for `O_CREAT' and `O_TRUNC' have no effect. `mode' specifies the mode of the database file as the one of `open' call does. The return value is the database handle or `NULL' if it is not successful.</dd>
1400 </dl>
1401
1402 <p>The function `dbm_close' is used in order to close a database handle.</p>
1403
1404 <dl>
1405 <dt><kbd>void dbm_close(DBM *<var>db</var>);</kbd></dt>
1406 <dd>`db' specifies a database handle. Because the region of the closed handle is released, it becomes impossible to use the handle.</dd>
1407 </dl>
1408
1409 <p>The function `dbm_store' is used in order to store a record.</p>
1410
1411 <dl>
1412 <dt><kbd>int dbm_store(DBM *<var>db</var>, datum <var>key</var>, datum <var>content</var>, int <var>flags</var>);</kbd></dt>
1413 <dd>`db' specifies a database handle. `key' specifies a structure of a key. `content' specifies a structure of a value. `flags' specifies behavior when the key overlaps, by the following values: `DBM_REPLACE', which means the specified value overwrites the existing one, `DBM_INSERT', which means the existing value is kept. The return value is 0 if it is successful, 1 if it gives up because of overlaps of the key, -1 if other error occurs.</dd>
1414 </dl>
1415
1416 <p>The function `dbm_delete' is used in order to delete a record.</p>
1417
1418 <dl>
1419 <dt><kbd>int dbm_delete(DBM *<var>db</var>, datum <var>key</var>);</kbd></dt>
1420 <dd>`db' specifies a database handle. `key' specifies a structure of a key. The return value is 0 if it is successful, -1 if some errors occur.</dd>
1421 </dl>
1422
1423 <p>The function `dbm_fetch' is used in order to retrieve a record.</p>
1424
1425 <dl>
1426 <dt><kbd>datum dbm_fetch(DBM *<var>db</var>, datum <var>key</var>);</kbd></dt>
1427 <dd>`db' specifies a database handle. `key' specifies a structure of a key. The return value is a structure of the result. If a record corresponds, the member `dptr' of the structure is the pointer to the region of the value. If no record corresponds or some errors occur, `dptr' is `NULL'. `dptr' points to the region related with the handle. The region is available until the next time of calling this function with the same handle.</dd>
1428 </dl>
1429
1430 <p>The function `dbm_firstkey' is used in order to get the first key of a database.</p>
1431
1432 <dl>
1433 <dt><kbd>datum dbm_firstkey(DBM *<var>db</var>);</kbd></dt>
1434 <dd>`db' specifies a database handle. The return value is a structure of the result. If a record corresponds, the member `dptr' of the structure is the pointer to the region of the first key. If no record corresponds or some errors occur, `dptr' is `NULL'. `dptr' points to the region related with the handle. The region is available until the next time of calling this function or the function `dbm_nextkey' with the same handle.</dd>
1435 </dl>
1436
1437 <p>The function `dbm_nextkey' is used in order to get the next key of a database.</p>
1438
1439 <dl>
1440 <dt><kbd>datum dbm_nextkey(DBM *<var>db</var>);</kbd></dt>
1441 <dd>`db' specifies a database handle. The return value is a structure of the result. If a record corresponds, the member `dptr' of the structure is the pointer to the region of the next key. If no record corresponds or some errors occur, `dptr' is `NULL'. `dptr' points to the region related with the handle. The region is available until the next time of calling this function or the function `dbm_firstkey' with the same handle.</dd>
1442 </dl>
1443
1444 <p>The function `dbm_error' is used in order to check whether a database has a fatal error or not.</p>
1445
1446 <dl>
1447 <dt><kbd>int dbm_error(DBM *<var>db</var>);</kbd></dt>
1448 <dd>`db' specifies a database handle. The return value is true if the database has a fatal error, false if not.</dd>
1449 </dl>
1450
1451 <p>The function `dbm_clearerr' has no effect.</p>
1452
1453 <dl>
1454 <dt><kbd>int dbm_clearerr(DBM *<var>db</var>);</kbd></dt>
1455 <dd>`db' specifies a database handle. The return value is 0. The function is only for compatibility.</dd>
1456 </dl>
1457
1458 <p>The function `dbm_rdonly' is used in order to check whether a handle is read-only or not.</p>
1459
1460 <dl>
1461 <dt><kbd>int dbm_rdonly(DBM *<var>db</var>);</kbd></dt>
1462 <dd>`db' specifies a database handle. The return value is true if the handle is read-only, or false if not read-only.</dd>
1463 </dl>
1464
1465 <p>The function `dbm_dirfno' is used in order to get the file descriptor of a directory file.</p>
1466
1467 <dl>
1468 <dt><kbd>int dbm_dirfno(DBM *<var>db</var>);</kbd></dt>
1469 <dd>`db' specifies a database handle. The return value is the file descriptor of the directory file.</dd>
1470 </dl>
1471
1472 <p>The function `dbm_pagfno' is used in order to get the file descriptor of a data file.</p>
1473
1474 <dl>
1475 <dt><kbd>int dbm_pagfno(DBM *<var>db</var>);</kbd></dt>
1476 <dd>`db' specifies a database handle. The return value is the file descriptor of the data file.</dd>
1477 </dl>
1478
1479 <h3>Examples</h3>
1480
1481 <p>The following example stores and retrieves a phone number, using the name as the key.</p>
1482
1483 <pre>#include &lt;relic.h&gt;
1484 #include &lt;stdlib.h&gt;
1485 #include &lt;sys/types.h&gt;
1486 #include &lt;sys/stat.h&gt;
1487 #include &lt;stdio.h&gt;
1488 #include &lt;string.h&gt;
1489
1490 #define NAME "mikio"
1491 #define NUMBER "000-1234-5678"
1492 #define DBNAME "book"
1493
1494 int main(int argc, char **argv){
1495 DBM *db;
1496 datum key, val;
1497 int i;
1498
1499 /* open the database */
1500 if(!(db = dbm_open(DBNAME, O_RDWR | O_CREAT, 00644))){
1501 perror("dbm_open");
1502 return 1;
1503 }
1504
1505 /* prepare the record */
1506 key.dptr = NAME;
1507 key.dsize = strlen(NAME);
1508 val.dptr = NUMBER;
1509 val.dsize = strlen(NUMBER);
1510
1511 /* store the record */
1512 if(dbm_store(db, key, val, DBM_REPLACE) != 0){
1513 perror("dbm_store");
1514 }
1515
1516 /* retrieve the record */
1517 val = dbm_fetch(db, key);
1518 if(val.dptr){
1519 printf("Name: %s\n", NAME);
1520 printf("Number: ");
1521 for(i = 0; i &lt; val.dsize; i++){
1522 putchar(((char *)val.dptr)[i]);
1523 }
1524 putchar('\n');
1525 } else {
1526 perror("dbm_fetch");
1527 }
1528
1529 /* close the database */
1530 dbm_close(db);
1531
1532 return 0;
1533 }
1534 </pre>
1535
1536 <h3>Notes</h3>
1537
1538 <p>How to build programs using Relic is the same as the case of Depot. Note that an option to be given to a linker is not `-lndbm', but `-lqdbm'.</p>
1539
1540 <pre>gcc -I/usr/local/include -o sample sample.c -L/usr/local/lib -lqdbm
1541 </pre>
1542
1543 <p>Functions of Relic are thread-safe as long as a handle is not accessed by threads at the same time, on the assumption that `errno', `malloc', and so on are thread-safe.</p>
1544
1545 <hr />
1546
1547 <h2><a name="reliccli" id="reliccli" class="head">Commands for Relic</a></h2>
1548
1549 <p>Relic has the following command line interfaces.</p>
1550
1551 <p>The command `rlmgr' is a utility for debugging Relic and its applications. It features editing and checking of a database. It can be used for database applications with shell scripts. This command is used in the following format. `name' specifies a database name. `key' specifies the key of a record. `val' specifies the value of a record.</p>
1552
1553 <dl>
1554 <dt><kbd>rlmgr create <var>name</var></kbd></dt>
1555 <dd>Create a database file.</dd>
1556 <dt><kbd>rlmgr store [-kx] [-vx|-vf] [-insert] <var>name</var> <var>key</var> <var>val</var></kbd></dt>
1557 <dd>Store a record with a key and a value.</dd>
1558 <dt><kbd>rlmgr delete [-kx] <var>name</var> <var>key</var></kbd></dt>
1559 <dd>Delete a record with a key.</dd>
1560 <dt><kbd>rlmgr fetch [-kx] [-ox] [-n] <var>name</var> <var>key</var></kbd></dt>
1561 <dd>Retrieve a record with a key and output to the standard output.</dd>
1562 <dt><kbd>rlmgr list [-ox] <var>name</var></kbd></dt>
1563 <dd>List all keys and values delimited with tab and line-feed to the standard output.</dd>
1564 </dl>
1565
1566 <p>Options feature the following.</p>
1567
1568 <ul class="lines">
1569 <li><kbd>-kx</kbd> : treat `key' as a binary expression of hexadecimal notation.</li>
1570 <li><kbd>-vx</kbd> : treat `val' as a binary expression of hexadecimal notation.</li>
1571 <li><kbd>-vf</kbd> : read the value from a file specified with `val'.</li>
1572 <li><kbd>-insert</kbd> : specify the storing mode for `DBM_INSERT'.</li>
1573 <li><kbd>-ox</kbd> : treat the output as a binary expression of hexadecimal notation.</li>
1574 <li><kbd>-n</kbd> : do not output the tailing newline.</li>
1575 </ul>
1576
1577 <p>This command returns 0 on success, another on failure.</p>
1578
1579 <p>The command `rltest' is a utility for facility test and performance test. Check a database generated by the command or measure the execution time of the command. This command is used in the following format. `name' specifies a database name. `rnum' specifies the number of records.</p>
1580
1581 <dl>
1582 <dt><kbd>rltest write <var>name</var> <var>rnum</var></kbd></dt>
1583 <dd>Store records with keys of 8 bytes. They change as `00000001', `00000002'...</dd>
1584 <dt><kbd>rltest read <var>name</var> <var>rnum</var></kbd></dt>
1585 <dd>Retrieve records of the database above.</dd>
1586 </dl>
1587
1588 <p>This command returns 0 on success, another on failure.</p>
1589
1590 <hr />
1591
1592 <h2><a name="hovelapi" id="hovelapi" class="head">Hovel: GDBM-compatible API</a></h2>
1593
1594 <h3>Overview</h3>
1595
1596 <p>Hovel is the API which is compatible with GDBM. So, Hovel wraps functions of Depot and Curia as API of GDBM. It is easy to port an application from GDBM to QDBM. In most cases, you should only replace the includings of `gdbm.h' with `hovel.h' and replace the linking option `-lgdbm' with `-lqdbm'. Hovel can not handle database files made by the original GDBM.</p>
1597
1598 <p>In order to use Hovel, you should include `hovel.h', `stdlib.h', `sys/types.h' and `sys/stat.h' in the source files. Usually, the following description will be near the beginning of a source file.</p>
1599
1600 <dl>
1601 <dt><kbd>#include &lt;hovel.h&gt;</kbd></dt>
1602 <dt><kbd>#include &lt;stdlib.h&gt;</kbd></dt>
1603 <dt><kbd>#include &lt;sys/types.h&gt;</kbd></dt>
1604 <dt><kbd>#include &lt;sys/stat.h&gt;</kbd></dt>
1605 </dl>
1606
1607 <p>An object of `GDBM_FILE' is used as a database handle. A database handle is opened with the function `gdbm_open' and closed with `gdbm_close'. You should not refer directly to any member of a handle. Although Hovel works as a wrapper of Depot and handles a database file usually, if you use the function `gdbm_open2' to open the handle, it is possible to make behavior of a handle as a wrapper of Curia and treat a database directory.</p>
1608
1609 <h3>API</h3>
1610
1611 <p>Structures of `datum' type is used in order to give and receive data of keys and values with functions of Hovel.</p>
1612
1613 <dl>
1614 <dt><kbd>typedef struct { char *dptr; size_t dsize; } datum;</kbd></dt>
1615 <dd>`dptr' specifies the pointer to the region of a key or a value. `dsize' specifies the size of the region.</dd>
1616 </dl>
1617
1618 <p>The external variable `gdbm_version' is the string containing the version information.</p>
1619
1620 <dl>
1621 <dt><kbd>extern char *gdbm_version;</kbd></dt>
1622 </dl>
1623
1624 <p>The external variable `gdbm_errno' is assigned with the last happened error code. Refer to `hovel.h' for details of the error codes.</p>
1625
1626 <dl>
1627 <dt><kbd>extern gdbm_error gdbm_errno;</kbd></dt>
1628 <dd>The initial value of this variable is `GDBM_NO_ERROR'. The other values are `GDBM_MALLOC_ERROR', `GDBM_BLOCK_SIZE_ERROR', `GDBM_FILE_OPEN_ERROR', `GDBM_FILE_WRITE_ERROR', `GDBM_FILE_SEEK_ERROR', `GDBM_FILE_READ_ERROR', `GDBM_BAD_MAGIC_NUMBER', `GDBM_EMPTY_DATABASE', `GDBM_CANT_BE_READER', `GDBM_CANT_BE_WRITER', `GDBM_READER_CANT_DELETE', `GDBM_READER_CANT_STORE', `GDBM_READER_CANT_REORGANIZE', `GDBM_UNKNOWN_UPDATE', `GDBM_ITEM_NOT_FOUND', `GDBM_REORGANIZE_FAILED', `GDBM_CANNOT_REPLACE', `GDBM_ILLEGAL_DATA', `GDBM_OPT_ALREADY_SET', and `GDBM_OPT_ILLEGAL'.</dd>
1629 </dl>
1630
1631 <p>The function `gdbm_strerror' is used in order to get a message string corresponding to an error code.</p>
1632
1633 <dl>
1634 <dt><kbd>char *gdbm_strerror(gdbm_error <var>gdbmerrno</var>);</kbd></dt>
1635 <dd>`gdbmerrno' specifies an error code. The return value is the message string of the error code. The region of the return value is not writable.</dd>
1636 </dl>
1637
1638 <p>The function `gdbm_open' is used in order to get a database handle after the fashion of GDBM.</p>
1639
1640 <dl>
1641 <dt><kbd>GDBM_FILE gdbm_open(char *<var>name</var>, int <var>block_size</var>, int <var>read_write</var>, int <var>mode</var>, void (*<var>fatal_func</var>)(void));</kbd></dt>
1642 <dd>`name' specifies the name of a database. `block_size' is ignored. `read_write' specifies the connection mode: `GDBM_READER' as a reader, `GDBM_WRITER', `GDBM_WRCREAT' and `GDBM_NEWDB' as a writer. `GDBM_WRCREAT' makes a database file or directory if it does not exist. `GDBM_NEWDB' makes a new database even if it exists. You can add the following to writer modes by bitwise or: `GDBM_SYNC', `GDBM_NOLOCK', `GDBM_LOCKNB', `GDBM_FAST', and `GDBM_SPARSE'. `GDBM_SYNC' means a database is synchronized after every updating method. `GDBM_NOLOCK' means a database is opened without file locking. `GDBM_LOCKNB' means file locking is performed without blocking. `GDBM_FAST' is ignored. `GDBM_SPARSE' is an original mode of QDBM and makes database a sparse file. `mode' specifies mode of a database file as the one of `open' call does. `fatal_func' is ignored. The return value is the database handle or `NULL' if it is not successful.</dd>
1643 </dl>
1644
1645 <p>The function `gdbm_open2' is used in order to get a database handle after the fashion of QDBM.</p>
1646
1647 <dl>
1648 <dt><kbd>GDBM_FILE gdbm_open2(char *<var>name</var>, int <var>read_write</var>, int <var>mode</var>, int <var>bnum</var>, int <var>dnum</var>, int <var>align</var>);</kbd></dt>
1649 <dd>`name' specifies the name of a database. `read_write' specifies the connection mode: `GDBM_READER' as a reader, `GDBM_WRITER', `GDBM_WRCREAT' and `GDBM_NEWDB' as a writer. `GDBM_WRCREAT' makes a database file or directory if it does not exist. `GDBM_NEWDB' makes a new database even if it exists. You can add the following to writer modes by bitwise or: `GDBM_SYNC', `GDBM_NOLOCK', 'GDBM_LOCKNB', `GDBM_FAST', and `GDBM_SPARSE'. `GDBM_SYNC' means a database is synchronized after every updating method. `GDBM_NOLOCK' means a database is opened without file locking. `GDBM_LOCKNB' means file locking is performed without blocking. `GDBM_FAST' is ignored. `GDBM_SPARSE' is an original mode of QDBM and makes database sparse files. `mode' specifies a mode of a database file or a database directory as the one of `open' or `mkdir' call does. `bnum' specifies the number of elements of each bucket array. If it is not more than 0, the default value is specified. `dnum' specifies the number of division of the database. If it is not more than 0, the returning handle is created as a wrapper of Depot, else, it is as a wrapper of Curia. `align' specifies the basic size of alignment. The return value is the database handle or `NULL' if it is not successful. If the database already exists, whether it is one of Depot or Curia is measured automatically.</dd>
1650 </dl>
1651
1652 <p>The function `gdbm_close' is used in order to close a database handle.</p>
1653
1654 <dl>
1655 <dt><kbd>void gdbm_close(GDBM_FILE <var>dbf</var>);</kbd></dt>
1656 <dd>`dbf' specifies a database handle. Because the region of the closed handle is released, it becomes impossible to use the handle.</dd>
1657 </dl>
1658
1659 <p>The function `gdbm_store' is used in order to store a record.</p>
1660
1661 <dl>
1662 <dt><kbd>int gdbm_store(GDBM_FILE <var>dbf</var>, datum <var>key</var>, datum <var>content</var>, int <var>flag</var>);</kbd></dt>
1663 <dd>`dbf' specifies a database handle connected as a writer. `key' specifies a structure of a key. `content' specifies a structure of a value. `flag' specifies behavior when the key overlaps, by the following values: `GDBM_REPLACE', which means the specified value overwrites the existing one, `GDBM_INSERT', which means the existing value is kept. The return value is 0 if it is successful, 1 if it gives up because of overlaps of the key, -1 if other error occurs.</dd>
1664 </dl>
1665
1666 <p>The function `gdbm_delete' is used in order to delete a record.</p>
1667
1668 <dl>
1669 <dt><kbd>int gdbm_delete(GDBM_FILE <var>dbf</var>, datum <var>key</var>);</kbd></dt>
1670 <dd>`dbf' specifies a database handle connected as a writer. `key' specifies a structure of a key. The return value is 0 if it is successful, -1 if some errors occur.</dd>
1671 </dl>
1672
1673 <p>The function `gdbm_fetch' is used in order to retrieve a record.</p>
1674
1675 <dl>
1676 <dt><kbd>datum gdbm_fetch(GDBM_FILE <var>dbf</var>, datum <var>key</var>);</kbd></dt>
1677 <dd>`dbf' specifies a database handle. `key' specifies a structure of a key. The return value is a structure of the result. If a record corresponds, the member `dptr' of the structure is the pointer to the region of the value. If no record corresponds or some errors occur, `dptr' is `NULL'. Because the region pointed to by `dptr' is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
1678 </dl>
1679
1680 <p>The function `gdbm_exists' is used in order to check whether a record exists or not.</p>
1681
1682 <dl>
1683 <dt><kbd>int gdbm_exists(GDBM_FILE <var>dbf</var>, datum <var>key</var>);</kbd></dt>
1684 <dd>`dbf' specifies a database handle. `key' specifies a structure of a key. The return value is true if a record corresponds and no error occurs, or false, else, it is false.</dd>
1685 </dl>
1686
1687 <p>The function `gdbm_firstkey' is used in order to get the first key of a database.</p>
1688
1689 <dl>
1690 <dt><kbd>datum gdbm_firstkey(GDBM_FILE <var>dbf</var>);</kbd></dt>
1691 <dd>`dbf' specifies a database handle. The return value is a structure of the result. If a record corresponds, the member `dptr' of the structure is the pointer to the region of the first key. If no record corresponds or some errors occur, `dptr' is `NULL'. Because the region pointed to by `dptr' is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
1692 </dl>
1693
1694 <p>The function `gdbm_nextkey' is used in order to get the next key of a database.</p>
1695
1696 <dl>
1697 <dt><kbd>datum gdbm_nextkey(GDBM_FILE <var>dbf</var>, datum <var>key</var>);</kbd></dt>
1698 <dd>`dbf' specifies a database handle. The return value is a structure of the result. If a record corresponds, the member `dptr' of the structure is the pointer to the region of the next key. If no record corresponds or some errors occur, `dptr' is `NULL'. Because the region pointed to by `dptr' is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
1699 </dl>
1700
1701 <p>The function `gdbm_sync' is used in order to synchronize updating contents with the file and the device.</p>
1702
1703 <dl>
1704 <dt><kbd>void gdbm_sync(GDBM_FILE <var>dbf</var>);</kbd></dt>
1705 <dd>`dbf' specifies a database handle connected as a writer.</dd>
1706 </dl>
1707
1708 <p>The function `gdbm_reorganize' is used in order to reorganize a database.</p>
1709
1710 <dl>
1711 <dt><kbd>int gdbm_reorganize(GDBM_FILE <var>dbf</var>);</kbd></dt>
1712 <dd>`dbf' specifies a database handle connected as a writer. If successful, the return value is 0, else -1.</dd>
1713 </dl>
1714
1715 <p>The function `gdbm_fdesc' is used in order to get the file descriptor of a database file.</p>
1716
1717 <dl>
1718 <dt><kbd>int gdbm_fdesc(GDBM_FILE <var>dbf</var>);</kbd></dt>
1719 <dd>`dbf' specifies a database handle connected as a writer. The return value is the file descriptor of the database file. If the database is a directory the return value is -1.</dd>
1720 </dl>
1721
1722 <p>The function `gdbm_setopt' has no effect.</p>
1723
1724 <dl>
1725 <dt><kbd>int gdbm_setopt(GDBM_FILE <var>dbf</var>, int <var>option</var>, int *<var>value</var>, int <var>size</var>);</kbd></dt>
1726 <dd>`dbf' specifies a database handle. `option' is ignored. `size' is ignored. The return value is 0. The function is only for compatibility.</dd>
1727 </dl>
1728
1729 <h3>Examples</h3>
1730
1731 <p>The following example stores and retrieves a phone number, using the name as the key.</p>
1732
1733 <pre>#include &lt;hovel.h&gt;
1734 #include &lt;stdlib.h&gt;
1735 #include &lt;sys/types.h&gt;
1736 #include &lt;sys/stat.h&gt;
1737 #include &lt;stdio.h&gt;
1738 #include &lt;string.h&gt;
1739
1740 #define NAME "mikio"
1741 #define NUMBER "000-1234-5678"
1742 #define DBNAME "book"
1743
1744 int main(int argc, char **argv){
1745 GDBM_FILE dbf;
1746 datum key, val;
1747 int i;
1748
1749 /* open the database */
1750 if(!(dbf = gdbm_open(DBNAME, 0, GDBM_WRCREAT, 00644, NULL))){
1751 fprintf(stderr, "gdbm_open: %s\n", gdbm_strerror(gdbm_errno));
1752 return 1;
1753 }
1754
1755 /* prepare the record */
1756 key.dptr = NAME;
1757 key.dsize = strlen(NAME);
1758 val.dptr = NUMBER;
1759 val.dsize = strlen(NUMBER);
1760
1761 /* store the record */
1762 if(gdbm_store(dbf, key, val, GDBM_REPLACE) != 0){
1763 fprintf(stderr, "gdbm_store: %s\n", gdbm_strerror(gdbm_errno));
1764 }
1765
1766 /* retrieve the record */
1767 val = gdbm_fetch(dbf, key);
1768 if(val.dptr){
1769 printf("Name: %s\n", NAME);
1770 printf("Number: ");
1771 for(i = 0; i &lt; val.dsize; i++){
1772 putchar(val.dptr[i]);
1773 }
1774 putchar('\n');
1775 free(val.dptr);
1776 } else {
1777 fprintf(stderr, "gdbm_fetch: %s\n", gdbm_strerror(gdbm_errno));
1778 }
1779
1780 /* close the database */
1781 gdbm_close(dbf);
1782
1783 return 0;
1784 }
1785 </pre>
1786
1787 <h3>Notes</h3>
1788
1789 <p>How to build programs using Hovel is the same as the case of Depot. Note that an option to be given to a linker is not `-lgdbm', but `-lqdbm'.</p>
1790
1791 <pre>gcc -I/usr/local/include -o sample sample.c -L/usr/local/lib -lqdbm
1792 </pre>
1793
1794 <p>If QDBM was built with POSIX thread enabled, the global variable `gdbm_errno' is treated as thread specific data, and functions of Hovel are reentrant. In that case, they are thread-safe as long as a handle is not accessed by threads at the same time, on the assumption that `errno', `malloc', and so on are thread-safe.</p>
1795
1796 <hr />
1797
1798 <h2><a name="hovelcli" id="hovelcli" class="head">Commands for Hovel</a></h2>
1799
1800 <p>Hovel has the following command line interfaces.</p>
1801
1802 <p>The command `hvmgr' is a utility for debugging Hovel and its applications. It features editing and checking of a database. It can be used for database applications with shell scripts. This command is used in the following format. `name' specifies a database name. `key' specifies the key of a record. `val' specifies the value of a record.</p>
1803
1804 <dl>
1805 <dt><kbd>hvmgr create [-qdbm bnum dnum] [-s] <var>name</var></kbd></dt>
1806 <dd>Create a database file.</dd>
1807 <dt><kbd>hvmgr store [-qdbm] [-kx] [-vx|-vf] [-insert] <var>name</var> <var>key</var> <var>val</var></kbd></dt>
1808 <dd>Store a record with a key and a value.</dd>
1809 <dt><kbd>hvmgr delete [-qdbm] [-kx] <var>name</var> <var>key</var></kbd></dt>
1810 <dd>Delete a record with a key.</dd>
1811 <dt><kbd>hvmgr fetch [-qdbm] [-kx] [-ox] [-n] <var>name</var> <var>key</var></kbd></dt>
1812 <dd>Retrieve a record with a key and output to the standard output.</dd>
1813 <dt><kbd>hvmgr list [-qdbm] [-ox] <var>name</var></kbd></dt>
1814 <dd>List all keys and values delimited with tab and line-feed to the standard output.</dd>
1815 <dt><kbd>hvmgr optimize [-qdbm] <var>name</var></kbd></dt>
1816 <dd>Optimize a database.</dd>
1817 </dl>
1818
1819 <p>Options feature the following.</p>
1820
1821 <ul class="lines">
1822 <li><kbd>-qdbm [<var>bnum</var> <var>dnum</var>]</kbd> : use `gdbm_open2' to open the database. `bnum' specifies the number of the elements of the bucket array. `dnum' specifies the number of division of the database.</li>
1823 <li><kbd>-s</kbd> : make the file sparse.</li>
1824 <li><kbd>-kx</kbd> : treat `key' as a binary expression of hexadecimal notation.</li>
1825 <li><kbd>-vx</kbd> : treat `val' as a binary expression of hexadecimal notation.</li>
1826 <li><kbd>-vf</kbd> : read the value from a file specified with `val'.</li>
1827 <li><kbd>-insert</kbd> : specify the storing mode for `GDBM_INSERT'.</li>
1828 <li><kbd>-ox</kbd> : treat the output as a binary expression of hexadecimal notation.</li>
1829 <li><kbd>-n</kbd> : do not output the trailing newline.</li>
1830 </ul>
1831
1832 <p>This command returns 0 on success, another on failure.</p>
1833
1834 <p>The command `hvtest' is a utility for facility test and performance test. Check a database generated by the command or measure the execution time of the command. This command is used in the following format. `name' specifies a database name. `rnum' specifies the number of records.</p>
1835
1836 <dl>
1837 <dt><kbd>hvtest write [-qdbm] [-s] <var>name</var> <var>rnum</var></kbd></dt>
1838 <dd>Store records with keys of 8 bytes. They changes as `00000001', `00000002'...</dd>
1839 <dt><kbd>hvtest read [-qdbm] <var>name</var> <var>rnum</var></kbd></dt>
1840 <dd>Retrieve records of the database above.</dd>
1841 </dl>
1842
1843 <p>Options feature the following.</p>
1844
1845 <ul class="lines">
1846 <li><kbd>-qdbm</kbd> : use `gdbm_open2' and open the handle as Curia.</li>
1847 <li><kbd>-s</kbd> : make the file sparse.</li>
1848 </ul>
1849
1850 <p>This command returns 0 on success, another on failure.</p>
1851
1852 <hr />
1853
1854 <h2><a name="cabinapi" id="cabinapi" class="head">Cabin: Utility API</a></h2>
1855
1856 <h3>Overview</h3>
1857
1858 <p>Cabin is the utility API which provides memory allocating functions, sorting functions, extensible datum, array list, hash map, heap array, and so on for handling records easily on memory. This API features also parsing MIME, CSV, and XML, and features various types of encoding and decoding.</p>
1859
1860 <p>In order to use Cabin, you should include `cabin.h' and `stdlib.h' in the source files. Usually, the following description will be near the beginning of a source file.</p>
1861
1862 <dl>
1863 <dt><kbd>#include &lt;cabin.h&gt;</kbd></dt>
1864 <dt><kbd>#include &lt;stdlib.h&gt;</kbd></dt>
1865 </dl>
1866
1867 <p>A pointer to `CBDATUM' is used as a handle of an extensible datum. A datum handle is opened with the function `cbdatumopen' and closed with `cbdatumclose'. A pointer to `CBLIST' is used as a handle of an array list. A list handle is opened with the function `cblistopen' and closed with `cblistclose'. A pointer to `CBMAP' is used as a handle of a hash map. A map handle is opened with the function `cbmapopen' and closed with `cbmapclose'. A pointer to `CBHEAP' is used as a handle of a heap array. A heap handle is opened with the function `cbheapopen' and closed with `cbheapclose'. You should not refer directly to any member of each handles.</p>
1868
1869 <h3>API</h3>
1870
1871 <p>The external variable `cbfatalfunc' is the pointer to call back function for handling a fatal error.</p>
1872
1873 <dl>
1874 <dt><kbd>extern void (*cbfatalfunc)(const char *);</kbd></dt>
1875 <dd>The argument specifies the error message. The initial value of this variable is `NULL'. If the value is `NULL', the default function is called when a fatal error occurs. A fatal error occurs when memory allocation is failed.</dd>
1876 </dl>
1877
1878 <p>The function `cbmalloc' is used in order to allocate a region on memory.</p>
1879
1880 <dl>
1881 <dt><kbd>void *cbmalloc(size_t <var>size</var>);</kbd></dt>
1882 <dd>`size' specifies the size of the region. The return value is the pointer to the allocated region. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
1883 </dl>
1884
1885 <p>The function `cbrealloc' is used in order to re-allocate a region on memory.</p>
1886
1887 <dl>
1888 <dt><kbd>void *cbrealloc(void *<var>ptr</var>, size_t <var>size</var>);</kbd></dt>
1889 <dd>`ptr' specifies the pointer to a region. `size' specifies the size of the region. The return value is the pointer to the re-allocated region. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
1890 </dl>
1891
1892 <p>The function `cbmemdup' is used in order to duplicate a region on memory.</p>
1893
1894 <dl>
1895 <dt><kbd>char *cbmemdup(const char *<var>ptr</var>, int <var>size</var>);</kbd></dt>
1896 <dd>`ptr' specifies the pointer to a region. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. The return value is the pointer to the allocated region of the duplicate. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
1897 </dl>
1898
1899 <p>The function `cbfree' is used in order to free a region on memory.</p>
1900
1901 <dl>
1902 <dt><kbd>void cbfree(void *<var>ptr</var>);</kbd></dt>
1903 <dd>`ptr' specifies the pointer to a region. If it is `NULL', this function has no effect. Although this function is just a wrapper of `free' call, this is useful in applications using another package of the `malloc' series.</dd>
1904 </dl>
1905
1906 <p>The function `cbglobalgc' is used in order to register the pointer or handle of an object to the global garbage collector.</p>
1907
1908 <dl>
1909 <dt><kbd>void cbglobalgc(void *<var>ptr</var>, void (*<var>func</var>)(void *));</kbd></dt>
1910 <dd>`ptr' specifies the pointer or handle of an object. `func' specifies the pointer to a function to release resources of the object. Its argument is the pointer or handle of the object to release. This function assures that resources of an object are released when the process exits normally by returning from the `main' function or calling the `exit' function.</dd>
1911 </dl>
1912
1913 <p>The function `cbggcsweep' is used in order to exercise the global garbage collector explicitly.</p>
1914
1915 <dl>
1916 <dt><kbd>void cbggcsweep(void);</kbd></dt>
1917 <dd>Note that you should not use objects registered to the global garbage collector any longer after calling this function. Because the global garbage collector is initialized and you can register new objects into it.</dd>
1918 </dl>
1919
1920 <p>The function `cbvmemavail' is used in order to check availability of allocation of the virtual memory.</p>
1921
1922 <dl>
1923 <dt><kbd>int cbvmemavail(size_t <var>size</var>);</kbd></dt>
1924 <dd>`size' specifies the size of region to be allocated newly. The return value is true if allocation should be success, or false if not.</dd>
1925 </dl>
1926
1927 <p>The function `cbisort' is used in order to sort an array using insert sort.</p>
1928
1929 <dl>
1930 <dt><kbd>void cbisort(void *<var>base</var>, int <var>nmemb</var>, int <var>size</var>, int(*<var>compar</var>)(const void *, const void *));</kbd></dt>
1931 <dd>`base' specifies the pointer to an array. `nmemb' specifies the number of elements of the array. `size' specifies the size of each element. `compar' specifies the pointer to comparing function. The two arguments specify the pointers of elements. The comparing function should returns positive if the former is big, negative if the latter is big, 0 if both are equal. Insert sort is useful only if most elements have been sorted already.</dd>
1932 </dl>
1933
1934 <p>The function `cbssort' is used in order to sort an array using shell sort.</p>
1935
1936 <dl>
1937 <dt><kbd>void cbssort(void *<var>base</var>, int <var>nmemb</var>, int <var>size</var>, int(*<var>compar</var>)(const void *, const void *));</kbd></dt>
1938 <dd>`base' specifies the pointer to an array. `nmemb' specifies the number of elements of the array. `size' specifies the size of each element. `compar' specifies the pointer to comparing function. The two arguments specify the pointers of elements. The comparing function should returns positive if the former is big, negative if the latter is big, 0 if both are equal. If most elements have been sorted, shell sort may be faster than heap sort or quick sort.</dd>
1939 </dl>
1940
1941 <p>The function `cbhsort' is used in order to sort an array using heap sort.</p>
1942
1943 <dl>
1944 <dt><kbd>void cbhsort(void *<var>base</var>, int <var>nmemb</var>, int <var>size</var>, int(*<var>compar</var>)(const void *, const void *));</kbd></dt>
1945 <dd>`base' specifies the pointer to an array. `nmemb' specifies the number of elements of the array. `size' specifies the size of each element. `compar' specifies the pointer to comparing function. The two arguments specify the pointers of elements. The comparing function should returns positive if the former is big, negative if the latter is big, 0 if both are equal. Although heap sort is robust against bias of input, quick sort is faster in most cases.</dd>
1946 </dl>
1947
1948 <p>The function `cbqsort' is used in order to sort an array using quick sort.</p>
1949
1950 <dl>
1951 <dt><kbd>void cbqsort(void *<var>base</var>, int <var>nmemb</var>, int <var>size</var>, int(*<var>compar</var>)(const void *, const void *));</kbd></dt>
1952 <dd>`base' specifies the pointer to an array. `nmemb' specifies the number of elements of the array. `size' specifies the size of each element. `compar' specifies the pointer to comparing function. The two arguments specify the pointers of elements. The comparing function should returns positive if the former is big, negative if the latter is big, 0 if both are equal. Being sensitive to bias of input, quick sort is the fastest sorting algorithm.</dd>
1953 </dl>
1954
1955 <p>The function `cbstricmp' is used in order to compare two strings with case insensitive evaluation.</p>
1956
1957 <dl>
1958 <dt><kbd>int cbstricmp(const char *<var>astr</var>, const char *<var>bstr</var>);</kbd></dt>
1959 <dd>`astr' specifies the pointer of one string. `astr' specifies the pointer of the other string. The return value is positive if the former is big, negative if the latter is big, 0 if both are equivalent. Upper cases and lower cases of alphabets in ASCII code are not distinguished.</dd>
1960 </dl>
1961
1962 <p>The function `cbstrfwmatch' is used in order to check whether a string begins with a key.</p>
1963
1964 <dl>
1965 <dt><kbd>int cbstrfwmatch(const char *<var>str</var>, const char *<var>key</var>);</kbd></dt>
1966 <dd>`str' specifies the pointer of a target string. `key' specifies the pointer of a forward matching key string. The return value is true if the target string begins with the key, else, it is false.</dd>
1967 </dl>
1968
1969 <p>The function `cbstrfwimatch' is used in order to check whether a string begins with a key, with case insensitive evaluation.</p>
1970
1971 <dl>
1972 <dt><kbd>int cbstrfwimatch(const char *<var>str</var>, const char *<var>key</var>);</kbd></dt>
1973 <dd>`str' specifies the pointer of a target string. `key' specifies the pointer of a forward matching key string. The return value is true if the target string begins with the key, else, it is false. Upper cases and lower cases of alphabets in ASCII code are not distinguished.</dd>
1974 </dl>
1975
1976 <p>The function `cbstrbwmatch' is used in order to check whether a string ends with a key.</p>
1977
1978 <dl>
1979 <dt><kbd>int cbstrbwmatch(const char *<var>str</var>, const char *<var>key</var>);</kbd></dt>
1980 <dd>`str' specifies the pointer of a target string. `key' specifies the pointer of a backward matching key string. The return value is true if the target string ends with the key, else, it is false.</dd>
1981 </dl>
1982
1983 <p>The function `cbstrbwimatch' is used in order to check whether a string ends with a key, with case insensitive evaluation.</p>
1984
1985 <dl>
1986 <dt><kbd>int cbstrbwimatch(const char *<var>str</var>, const char *<var>key</var>);</kbd></dt>
1987 <dd>`str' specifies the pointer of a target string. `key' specifies the pointer of a backward matching key string. The return value is true if the target string ends with the key, else, it is false. Upper cases and lower cases of alphabets in ASCII code are not distinguished.</dd>
1988 </dl>
1989
1990 <p>The function `cbstrstrkmp' is used in order to locate a substring in a string using KMP method.</p>
1991
1992 <dl>
1993 <dt><kbd>char *cbstrstrkmp(const char *<var>haystack</var>, const char *<var>needle</var>);</kbd></dt>
1994 <dd>`haystack' specifies the pointer of a target string. `needle' specifies the pointer of a substring to be found. The return value is the pointer to the beginning of the substring or `NULL' if the substring is not found. In most cases, `strstr' as a built-in function of the compiler is faster than this function.</dd>
1995 </dl>
1996
1997 <p>The function `cbstrstrkmp' is used in order to locate a substring in a string using BM method.</p>
1998
1999 <dl>
2000 <dt><kbd>char *cbstrstrbm(const char *<var>haystack</var>, const char *<var>needle</var>);</kbd></dt>
2001 <dd>`haystack' specifies the pointer of a target string. `needle' specifies the pointer of a substring to be found. The return value is the pointer to the beginning of the substring or `NULL' if the substring is not found. In most cases, `strstr' as a built-in function of the compiler is faster than this function.</dd>
2002 </dl>
2003
2004 <p>The function `cbstrtoupper' is used in order to convert the letters of a string to upper case.</p>
2005
2006 <dl>
2007 <dt><kbd>char *cbstrtoupper(char *<var>str</var>);</kbd></dt>
2008 <dd>`str' specifies the pointer of a string to convert. The return value is the pointer to the string.</dd>
2009 </dl>
2010
2011 <p>The function `cbstrtolower' is used in order to convert the letters of a string to lower case.</p>
2012
2013 <dl>
2014 <dt><kbd>char *cbstrtolower(char *<var>str</var>);</kbd></dt>
2015 <dd>`str' specifies the pointer of a string to convert. The return value is the pointer to the string.</dd>
2016 </dl>
2017
2018 <p>The function `cbstrtrim' is used in order to cut space characters at head or tail of a string.</p>
2019
2020 <dl>
2021 <dt><kbd>char *cbstrtrim(char *<var>str</var>);</kbd></dt>
2022 <dd>`str' specifies the pointer of a string to convert. The return value is the pointer to the string.</dd>
2023 </dl>
2024
2025 <p>The function `cbstrsqzspc' is used in order to squeeze space characters in a string and trim it.</p>
2026
2027 <dl>
2028 <dt><kbd>char *cbstrsqzspc(char *<var>str</var>);</kbd></dt>
2029 <dd>`str' specifies the pointer of a string to convert. The return value is the pointer to the string.</dd>
2030 </dl>
2031
2032 <p>The function `cbstrcountutf' is used in order to count the number of characters in a string of UTF-8.</p>
2033
2034 <dl>
2035 <dt><kbd>int cbstrcountutf(const char *<var>str</var>);</kbd></dt>
2036 <dd>`str' specifies the pointer of a string of UTF-8. The return value is the number of characters in the string.</dd>
2037 </dl>
2038
2039 <p>The function `cbstrcututf' is used in order to cut a string of UTF-8 at the specified number of characters.</p>
2040
2041 <dl>
2042 <dt><kbd>char *cbstrcututf(char *<var>str</var>, int <var>num</var>);</kbd></dt>
2043 <dd>`str' specifies the pointer of a string of UTF-8. `num' specifies the number of characters to be kept. The return value is the pointer to the string.</dd>
2044 </dl>
2045
2046 <p>The function `cbdatumopen' is used in order to get a datum handle.</p>
2047
2048 <dl>
2049 <dt><kbd>CBDATUM *cbdatumopen(const char *<var>ptr</var>, int <var>size</var>);</kbd></dt>
2050 <dd>`ptr' specifies the pointer to the region of the initial content. If it is `NULL', an empty datum is created. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. The return value is a datum handle.</dd>
2051 </dl>
2052
2053 <p>The function `cbdatumdup' is used in order to copy a datum.</p>
2054
2055 <dl>
2056 <dt><kbd>CBDATUM *cbdatumdup(const CBDATUM *<var>datum</var>);</kbd></dt>
2057 <dd>`datum' specifies a datum handle. The return value is a new datum handle.</dd>
2058 </dl>
2059
2060 <p>The function `cbdatumclose' is used in order to free a datum handle.</p>
2061
2062 <dl>
2063 <dt><kbd>void cbdatumclose(CBDATUM *<var>datum</var>);</kbd></dt>
2064 <dd>`datum' specifies a datum handle. Because the region of a closed handle is released, it becomes impossible to use the handle.</dd>
2065 </dl>
2066
2067 <p>The function `cbdatumcat' is used in order to concatenate a datum and a region.</p>
2068
2069 <dl>
2070 <dt><kbd>void cbdatumcat(CBDATUM *<var>datum</var>, const char *<var>ptr</var>, int <var>size</var>);</kbd></dt>
2071 <dd>`datum' specifies a datum handle. `ptr' specifies the pointer to the region to be appended. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'.</dd>
2072 </dl>
2073
2074 <p>The function `cbdatumptr' is used in order to get the pointer of the region of a datum.</p>
2075
2076 <dl>
2077 <dt><kbd>const char *cbdatumptr(const CBDATUM *<var>datum</var>);</kbd></dt>
2078 <dd>`datum' specifies a datum handle. The return value is the pointer of the region of a datum. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string.</dd>
2079 </dl>
2080
2081 <p>The function `cbdatumsize' is used in order to get the size of the region of a datum.</p>
2082
2083 <dl>
2084 <dt><kbd>int cbdatumsize(const CBDATUM *<var>datum</var>);</kbd></dt>
2085 <dd>`datum' specifies a datum handle. The return value is the size of the region of a datum.</dd>
2086 </dl>
2087
2088 <p>The function `cbdatumsetsize' is used in order to change the size of the region of a datum.</p>
2089
2090 <dl>
2091 <dt><kbd>void cbdatumsetsize(CBDATUM *<var>datum</var>, int <var>size</var>);</kbd></dt>
2092 <dd>`datum' specifies a datum handle. `size' specifies the new size of the region. If the new size is bigger than the one of old, the surplus region is filled with zero codes.</dd>
2093 </dl>
2094
2095 <p>The function `cbdatumprintf' is used in order to perform formatted output into a datum.</p>
2096
2097 <dl>
2098 <dt><kbd>void cbdatumprintf(CBDATUM *<var>datum</var>, const char *<var>format</var>, ...);</kbd></dt>
2099 <dd>`format' specifies a printf-like format string. The conversion character `%' can be used with such flag characters as `s', `d', `o', `u', `x', `X', `c', `e', `E', `f', `g', `G', `@', `?', `:', `%'. `@' works as with `s' but escapes meta characters of XML. `?' works as with `s' but escapes meta characters of URL. `:' works as with `s' but performs MIME encoding as UTF-8. The other conversion character work as with each original.</dd>
2100 </dl>
2101
2102 <p>The function `cbdatumtomalloc' is used in order to convert a datum to an allocated region.</p>
2103
2104 <dl>
2105 <dt><kbd>char *cbdatumtomalloc(CBDATUM *<var>datum</var>, int *<var>sp</var>);</kbd></dt>
2106 <dd>`datum' specifies a datum handle. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. The return value is the pointer to the region of the datum. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. Because the region of the original datum is released, it should not be released again.</dd>
2107 </dl>
2108
2109 <p>The function `cblistopen' is used in order to get a list handle.</p>
2110
2111 <dl>
2112 <dt><kbd>CBLIST *cblistopen(void);</kbd></dt>
2113 <dd>The return value is a list handle.</dd>
2114 </dl>
2115
2116 <p>The function `cblistdup' is used in order to copy a list.</p>
2117
2118 <dl>
2119 <dt><kbd>CBLIST *cblistdup(const CBLIST *<var>list</var>);</kbd></dt>
2120 <dd>`list' specifies a list handle. The return value is a new list handle.</dd>
2121 </dl>
2122
2123 <p>The function `cblistclose' is used in order to close a list handle.</p>
2124
2125 <dl>
2126 <dt><kbd>void cblistclose(CBLIST *<var>list</var>);</kbd></dt>
2127 <dd>`list' specifies a list handle. Because the region of a closed handle is released, it becomes impossible to use the handle.</dd>
2128 </dl>
2129
2130 <p>The function `cblistnum' is used in order to get the number of elements of a list.</p>
2131
2132 <dl>
2133 <dt><kbd>int cblistnum(const CBLIST *<var>list</var>);</kbd></dt>
2134 <dd>`list' specifies a list handle. The return value is the number of elements of the list.</dd>
2135 </dl>
2136
2137 <p>The function `cblistval' is used in order to get the pointer to the region of an element of a list.</p>
2138
2139 <dl>
2140 <dt><kbd>const char *cblistval(const CBLIST *<var>list</var>, int <var>index</var>, int *<var>sp</var>);</kbd></dt>
2141 <dd>`list' specifies a list handle. `index' specifies the index of an element. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. The return value is the pointer to the region of the element. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. If `index' is equal to or more than the number of elements, the return value is `NULL'.</dd>
2142 </dl>
2143
2144 <p>The function `cblistpush' is used in order to add an element at the end of a list.</p>
2145
2146 <dl>
2147 <dt><kbd>void cblistpush(CBLIST *<var>list</var>, const char *<var>ptr</var>, int <var>size</var>);</kbd></dt>
2148 <dd>`list' specifies a list handle. `ptr' specifies the pointer to the region of an element. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'.</dd>
2149 </dl>
2150
2151 <p>The function `cblistpop' is used in order to remove an element of the end of a list.</p>
2152
2153 <dl>
2154 <dt><kbd>char *cblistpop(CBLIST *<var>list</var>, int *<var>sp</var>);</kbd></dt>
2155 <dd>`list' specifies a list handle. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. The return value is the pointer to the region of the value. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. If the list is empty, the return value is `NULL'.</dd>
2156 </dl>
2157
2158 <p>The function `cblistunshift' is used in order to add an element at the top of a list.</p>
2159
2160 <dl>
2161 <dt><kbd>void cblistunshift(CBLIST *<var>list</var>, const char *<var>ptr</var>, int <var>size</var>);</kbd></dt>
2162 <dd>`list' specifies a list handle. `ptr' specifies the pointer to the region of an element. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'.</dd>
2163 </dl>
2164
2165 <p>The function `cblistshift' is used in order to remove an element of the top of a list.</p>
2166
2167 <dl>
2168 <dt><kbd>char *cblistshift(CBLIST *<var>list</var>, int *<var>sp</var>);</kbd></dt>
2169 <dd>`list' specifies a list handle. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. The return value is the pointer to the region of the value. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. If the list is empty, the return value is `NULL'.</dd>
2170 </dl>
2171
2172 <p>The function `cblistinsert' is used in order to add an element at the specified location of a list.</p>
2173
2174 <dl>
2175 <dt><kbd>void cblistinsert(CBLIST *<var>list</var>, int <var>index</var>, const char *<var>ptr</var>, int <var>size</var>);</kbd></dt>
2176 <dd>`list' specifies a list handle. `index' specifies the index of an element. `ptr' specifies the pointer to the region of the element. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'.</dd>
2177 </dl>
2178
2179 <p>The function `cblistremove' is used in order to remove an element at the specified location of a list.</p>
2180
2181 <dl>
2182 <dt><kbd>char *cblistremove(CBLIST *<var>list</var>, int <var>index</var>, int *<var>sp</var>);</kbd></dt>
2183 <dd>`list' specifies a list handle. `index' specifies the index of an element. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. The return value is the pointer to the region of the value. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. If `index' is equal to or more than the number of elements, no element is removed and the return value is `NULL'.</dd>
2184 </dl>
2185
2186 <p>The function `cblistover' is used in order to overwrite an element at the specified location of a list.</p>
2187
2188 <dl>
2189 <dt><kbd>void cblistover(CBLIST *<var>list</var>, int <var>index</var>, const char *<var>ptr</var>, int <var>size</var>);</kbd></dt>
2190 <dd>`list' specifies a list handle. `index' specifies the index of an element. `ptr' specifies the pointer to the region of the new content. `size' specifies the size of the new content. If it is negative, the size is assigned with `strlen(ptr)'. If `index' is equal to or more than the number of elements, this function has no effect.</dd>
2191 </dl>
2192
2193 <p>The function `cblistsort' is used in order to sort elements of a list in lexical order.</p>
2194
2195 <dl>
2196 <dt><kbd>void cblistsort(CBLIST *<var>list</var>);</kbd></dt>
2197 <dd>`list' specifies a list handle. Quick sort is used for sorting.</dd>
2198 </dl>
2199
2200 <p>The function `cblistlsearch' is used in order to search a list for an element using liner search.</p>
2201
2202 <dl>
2203 <dt><kbd>int cblistlsearch(const CBLIST *<var>list</var>, const char *<var>ptr</var>, int <var>size</var>);</kbd></dt>
2204 <dd>`list' specifies a list handle. `ptr' specifies the pointer to the region of a key. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. The return value is the index of a corresponding element or -1 if there is no corresponding element. If two or more elements corresponds, the former returns.</dd>
2205 </dl>
2206
2207 <p>The function `cblistbsearch' is used in order to search a list for an element using binary search.</p>
2208
2209 <dl>
2210 <dt><kbd>int cblistbsearch(const CBLIST *<var>list</var>, const char *<var>ptr</var>, int <var>size</var>);</kbd></dt>
2211 <dd>`list' specifies a list handle. It should be sorted in lexical order. `ptr' specifies the pointer to the region of a key. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. The return value is the index of a corresponding element or -1 if there is no corresponding element. If two or more elements corresponds, which returns is not defined.</dd>
2212 </dl>
2213
2214 <p>The function `cblistdump' is used in order to serialize a list into a byte array.</p>
2215
2216 <dl>
2217 <dt><kbd>char *cblistdump(const CBLIST *<var>list</var>, int *<var>sp</var>);</kbd></dt>
2218 <dd>`list' specifies a list handle. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. The return value is the pointer to the region of the result serial region. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
2219 </dl>
2220
2221 <p>The function `cblistload' is used in order to redintegrate a serialized list.</p>
2222
2223 <dl>
2224 <dt><kbd>CBLIST *cblistload(const char *<var>ptr</var>, int <var>size</var>);</kbd></dt>
2225 <dd>`ptr' specifies the pointer to a byte array. `size' specifies the size of the region. The return value is a new list handle.</dd>
2226 </dl>
2227
2228 <p>The function `cbmapopen' is used in order to get a map handle.</p>
2229
2230 <dl>
2231 <dt><kbd>CBMAP *cbmapopen(void);</kbd></dt>
2232 <dd>The return value is a map handle.</dd>
2233 </dl>
2234
2235 <p>The function `cbmapdup' is used in order to copy a map.</p>
2236
2237 <dl>
2238 <dt><kbd>CBMAP *cbmapdup(CBMAP *<var>map</var>);</kbd></dt>
2239 <dd>`map' specifies a map handle. The return value is a new map handle. The iterator of the source map is initialized.</dd>
2240 </dl>
2241
2242 <p>The function `cbmapclose' is used in order to close a map handle.</p>
2243
2244 <dl>
2245 <dt><kbd>void cbmapclose(CBMAP *<var>map</var>);</kbd></dt>
2246 <dd>`map' specifies a map handle. Because the region of a closed handle is released, it becomes impossible to use the handle.</dd>
2247 </dl>
2248
2249 <p>The function `cbmapput' is used in order to store a record into a map.</p>
2250
2251 <dl>
2252 <dt><kbd>int cbmapput(CBMAP *<var>map</var>, const char *<var>kbuf</var>, int <var>ksiz</var>, const char *<var>vbuf</var>, int <var>vsiz</var>, int <var>over</var>);</kbd></dt>
2253 <dd>`map' specifies a map handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `vbuf' specifies the pointer to the region of a value. `vsiz' specifies the size of the region of the value. If it is negative, the size is assigned with `strlen(vbuf)'. `over' specifies whether the value of the duplicated record is overwritten or not. If `over' is false and the key duplicated, the return value is false, else, it is true.</dd>
2254 </dl>
2255
2256 <p>The function `cbmapputcat' is used in order to concatenate a value at the end of the value of the existing record.</p>
2257
2258 <dl>
2259 <dt><kbd>void cbmapputcat(CBMAP *<var>map</var>, const char *<var>kbuf</var>, int <var>ksiz</var>, const char *<var>vbuf</var>, int <var>vsiz</var>);</kbd></dt>
2260 <dd>`map' specifies a map handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `vbuf' specifies the pointer to the region of a value. `vsiz' specifies the size of the region of the value. If it is negative, the size is assigned with `strlen(vbuf)'. If there is no corresponding record, a new record is created.</dd>
2261 </dl>
2262
2263 <p>The function `cbmapout' is used in order to delete a record of a map.</p>
2264
2265 <dl>
2266 <dt><kbd>int cbmapout(CBMAP *<var>map</var>, const char *<var>kbuf</var>, int <var>ksiz</var>);</kbd></dt>
2267 <dd>`map' specifies a map handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. If successful, the return value is true. False is returned when no record corresponds to the specified key.</dd>
2268 </dl>
2269
2270 <p>The function `cbmapget' is used in order to retrieve a record of a map.</p>
2271
2272 <dl>
2273 <dt><kbd>const char *cbmapget(const CBMAP *<var>map</var>, const char *<var>kbuf</var>, int <var>ksiz</var>, int *<var>sp</var>);</kbd></dt>
2274 <dd>`map' specifies a map handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the region of the value of the corresponding record. `NULL' is returned when no record corresponds. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string.</dd>
2275 </dl>
2276
2277 <p>The function `cbmapmove' is used in order to move a record to the edge of a map.</p>
2278
2279 <dl>
2280 <dt><kbd>int cbmapmove(CBMAP *<var>map</var>, const char *<var>kbuf</var>, int <var>ksiz</var>, int <var>head</var>);</kbd></dt>
2281 <dd>`map' specifies a map handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `head' specifies the destination which is head if it is true or tail if else. If successful, the return value is true. False is returned when no record corresponds to the specified key.</dd>
2282 </dl>
2283
2284 <p>The function `cbmapiterinit' is used in order to initialize the iterator of a map.</p>
2285
2286 <dl>
2287 <dt><kbd>void cbmapiterinit(CBMAP *<var>map</var>);</kbd></dt>
2288 <dd>`map' specifies a map handle. The iterator is used in order to access the key of every record stored in a map.</dd>
2289 </dl>
2290
2291 <p>The function `cbmapiternext' is used in order to get the next key of the iterator of a map.</p>
2292
2293 <dl>
2294 <dt><kbd>const char *cbmapiternext(CBMAP *<var>map</var>, int *<var>sp</var>);</kbd></dt>
2295 <dd>`map' specifies a map handle. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the region of the next key, else, it is `NULL'. `NULL' is returned when no record is to be get out of the iterator. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. The order of iteration is assured to be the same of the one of storing.</dd>
2296 </dl>
2297
2298 <p>The function `cbmapiterval' is used in order to get the value binded to the key fetched from the iterator of a map.</p>
2299
2300 <dl>
2301 <dt><kbd>const char *cbmapiterval(const char *<var>kbuf</var>, int *<var>sp</var>);</kbd></dt>
2302 <dd>`kbuf' specifies the pointer to the region of a iteration key. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. The return value is the pointer to the region of the value of the corresponding record. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string.</dd>
2303 </dl>
2304
2305 <p>The function `cbmaprnum' is used in order to get the number of the records stored in a map.</p>
2306
2307 <dl>
2308 <dt><kbd>int cbmaprnum(const CBMAP *<var>map</var>);</kbd></dt>
2309 <dd>`map' specifies a map handle. The return value is the number of the records stored in the map.</dd>
2310 </dl>
2311
2312 <p>The function `cbmapkeys' is used in order to get the list handle contains all keys in a map.</p>
2313
2314 <dl>
2315 <dt><kbd>CBLIST *cbmapkeys(CBMAP *<var>map</var>);</kbd></dt>
2316 <dd>`map' specifies a map handle. The return value is the list handle contains all keys in the map. Because the handle of the return value is opened with the function `cblistopen', it should be closed with the function `cblistclose' if it is no longer in use.</dd>
2317 </dl>
2318
2319 <p>The function `cbmapvals' is used in order to get the list handle contains all values in a map.</p>
2320
2321 <dl>
2322 <dt><kbd>CBLIST *cbmapvals(CBMAP *<var>map</var>);</kbd></dt>
2323 <dd>`map' specifies a map handle. The return value is the list handle contains all values in the map. Because the handle of the return value is opened with the function `cblistopen', it should be closed with the function `cblistclose' if it is no longer in use.</dd>
2324 </dl>
2325
2326 <p>The function `cbmapdump' is used in order to serialize a map into a byte array.</p>
2327
2328 <dl>
2329 <dt><kbd>char *cbmapdump(const CBMAP *<var>map</var>, int *<var>sp</var>);</kbd></dt>
2330 <dd>`map' specifies a map handle. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. The return value is the pointer to the region of the result serial region. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
2331 </dl>
2332
2333 <p>The function `cbmapload' is used in order to redintegrate a serialized map.</p>
2334
2335 <dl>
2336 <dt><kbd>CBMAP *cbmapload(const char *<var>ptr</var>, int <var>size</var>);</kbd></dt>
2337 <dd>`ptr' specifies the pointer to a byte array. `size' specifies the size of the region. The return value is a new map handle.</dd>
2338 </dl>
2339
2340 <p>The function `cbmaploadone' is used in order to extract a record from a serialized map.</p>
2341
2342 <dl>
2343 <dt><kbd>char *cbmaploadone(const char *<var>ptr</var>, int <var>size</var>, const char *<var>kbuf</var>, int <var>ksiz</var>, int *<var>sp</var>);</kbd></dt>
2344 <dd>`ptr' specifies the pointer to a byte array. `size' specifies the size of the region. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the region of the value of the corresponding record. `NULL' is returned when no record corresponds. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string.</dd>
2345 </dl>
2346
2347
2348 <p>The function `cbheapopen' is used in order to get a heap handle.</p>
2349
2350 <dl>
2351 <dt><kbd>CBHEAP *cbheapopen(int <var>size</var>, int <var>max</var>, int(*<var>compar</var>)(const void *, const void *));</kbd></dt>
2352 <dd>`size' specifies the size of each record. `max' specifies the maximum number of records in the heap. `compar' specifies the pointer to comparing function. The two arguments specify the pointers of records. The comparing function should returns positive if the former is big, negative if the latter is big, 0 if both are equal. The return value is a heap handle.</dd>
2353 </dl>
2354
2355 <p>The function `cbheapdup' is used in order to copy a heap.</p>
2356
2357 <dl>
2358 <dt><kbd>CBHEAP *cbheapdup(CBHEAP *<var>heap</var>);</kbd></dt>
2359 <dd>`heap' specifies a heap handle. The return value is a new heap handle.</dd>
2360 </dl>
2361
2362 <p>The function `cbheapclose' is used in order to close a heap handle.</p>
2363
2364 <dl>
2365 <dt><kbd>void cbheapclose(CBHEAP *<var>heap</var>);</kbd></dt>
2366 <dd>`heap' specifies a heap handle. Because the region of a closed handle is released, it becomes impossible to use the handle.</dd>
2367 </dl>
2368
2369 <p>The function `cbheapnum' is used in order to get the number of the records stored in a heap.</p>
2370
2371 <dl>
2372 <dt><kbd>int cbheapnum(CBHEAP *<var>heap</var>);</kbd></dt>
2373 <dd>`heap' specifies a heap handle. The return value is the number of the records stored in the heap.</dd>
2374 </dl>
2375
2376 <p>The function `cbheapinsert' is used in order to insert a record into a heap.</p>
2377
2378 <dl>
2379 <dt><kbd>int cbheapinsert(CBHEAP *<var>heap</var>, const void *<var>ptr</var>);</kbd></dt>
2380 <dd>`heap' specifies a heap handle. `ptr' specifies the pointer to the region of a record. The return value is true if the record is added, else false. If the new record is bigger than the biggest existing regord, the new record is not added. If the new record is added and the number of records exceeds the maximum number, the biggest existing record is removed.</dd>
2381 </dl>
2382
2383 <p>The function `cbheapval' is used in order to get the pointer to the region of a record in a heap.</p>
2384
2385 <dl>
2386 <dt><kbd>void *cbheapval(CBHEAP *<var>heap</var>, int <var>index</var>);</kbd></dt>
2387 <dd>`heap' specifies a heap handle. `index' specifies the index of a record. The return value is the pointer to the region of the record. If `index' is equal to or more than the number of records, the return value is `NULL'. Note that records are organized by the nagative order the comparing function.</dd>
2388 </dl>
2389
2390 <p>The function `cbheaptomalloc' is used in order to convert a heap to an allocated region.</p>
2391
2392 <dl>
2393 <dt><kbd>void *cbheaptomalloc(CBHEAP *<var>heap</var>, int *<var>np</var>);</kbd></dt>
2394 <dd>`heap' specifies a heap handle. `np' specifies the pointer to a variable to which the number of records of the return value is assigned. If it is `NULL', it is not used. The return value is the pointer to the region of the heap. Records are sorted. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. Because the region of the original heap is released, it should not be released again.</dd>
2395 </dl>
2396
2397 <p>The function `cbsprintf' is used in order to allocate a formatted string on memory.</p>
2398
2399 <dl>
2400 <dt><kbd>char *cbsprintf(const char *<var>format</var>, ...);</kbd></dt>
2401 <dd>`format' specifies a printf-like format string. The conversion character `%' can be used with such flag characters as `d', `o', `u', `x', `X', `e', `E', `f', `g', `G', `c', `s', and `%'. Specifiers of the field length and the precision can be put between the conversion characters and the flag characters. The specifiers consist of decimal characters, `.', `+', `-', and the space character. The other arguments are used according to the format string. The return value is the pointer to the allocated region of the result string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
2402 </dl>
2403
2404 <p>The function `cbreplace' is used in order to replace some patterns in a string.</p>
2405
2406 <dl>
2407 <dt><kbd>char *cbreplace(const char *<var>str</var>, CBMAP *<var>pairs</var>);</kbd></dt>
2408 <dd>`str' specifies the pointer to a source string. `pairs' specifies the handle of a map composed of pairs of replacement. The key of each pair specifies a pattern before replacement and its value specifies the pattern after replacement. The return value is the pointer to the allocated region of the result string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
2409 </dl>
2410
2411 <p>The function `cbsplit' is used in order to make a list by splitting a serial datum.</p>
2412
2413 <dl>
2414 <dt><kbd>CBLIST *cbsplit(const char *<var>ptr</var>, int <var>size</var>, const char *<var>delim</var>);</kbd></dt>
2415 <dd>`ptr' specifies the pointer to the region of the source content. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. `delim' specifies a string containing delimiting characters. If it is `NULL', zero code is used as a delimiter. The return value is a list handle. If two delimiters are successive, it is assumed that an empty element is between the two. Because the handle of the return value is opened with the function `cblistopen', it should be closed with the function `cblistclose'.</dd>
2416 </dl>
2417
2418 <p>The function `cbreadfile' is used in order to read whole data of a file.</p>
2419
2420 <dl>
2421 <dt><kbd>char *cbreadfile(const char *<var>name</var>, int *<var>sp</var>);</kbd></dt>
2422 <dd>`name' specifies the name of a file. If it is `NULL', the standard input is specified. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. The return value is the pointer to the allocated region of the read data. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
2423 </dl>
2424
2425 <p>The function `cbwritefile' is used in order to write a serial datum into a file.</p>
2426
2427 <dl>
2428 <dt><kbd>int cbwritefile(const char *<var>name</var>, const char *<var>ptr</var>, int <var>size</var>);</kbd></dt>
2429 <dd>`name specifies the name of a file. If it is `NULL', the standard output is specified. `ptr' specifies the pointer to the region of the source content. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. If successful, the return value is true, else, it is false. If the file exists, it is overwritten. Else, a new file is created.</dd>
2430 </dl>
2431
2432 <p>The function `cbreadlines' is used in order to read every line of a file.</p>
2433
2434 <dl>
2435 <dt><kbd>CBLIST *cbreadlines(const char *<var>name</var>);</kbd></dt>
2436 <dd>`name' specifies the name of a file. If it is `NULL', the standard input is specified. The return value is a list handle of the lines if successful, else it is NULL. Line separators are cut out. Because the handle of the return value is opened with the function `cblistopen', it should be closed with the function `cblistclose' if it is no longer in use.</dd>
2437 </dl>
2438
2439 <p>The function `cbdirlist' is used in order to read names of files in a directory.</p>
2440
2441 <dl>
2442 <dt><kbd>CBLIST *cbdirlist(const char *<var>name</var>);</kbd></dt>
2443 <dd>`name' specifies the name of a directory. The return value is a list handle of names if successful, else it is NULL. Because the handle of the return value is opened with the function `cblistopen', it should be closed with the function `cblistclose' if it is no longer in use.</dd>
2444 </dl>
2445
2446 <p>The function `cbfilestat' is used in order to get the status of a file or a directory.</p>
2447
2448 <dl>
2449 <dt><kbd>int cbfilestat(const char *<var>name</var>, int *<var>isdirp</var>, int *<var>sizep</var>, int *<var>mtimep</var>);</kbd></dt>
2450 <dd>`name' specifies the name of a file or a directory. `dirp' specifies the pointer to a variable to which whether the file is a directory is assigned. If it is `NULL', it is not used. `sizep' specifies the pointer to a variable to which the size of the file is assigned. If it is `NULL', it is not used. `mtimep' specifies the pointer to a variable to which the last modified time of the file is assigned. If it is `NULL', it is not used. If successful, the return value is true, else, false. False is returned when the file does not exist or the permission is denied.</dd>
2451 </dl>
2452
2453 <p>The function `cbremove' is used in order to remove a file or a directory and its sub ones recursively.</p>
2454
2455 <dl>
2456 <dt><kbd>int cbremove(const char *<var>name</var>);</kbd></dt>
2457 <dd>`name' specifies the name of a file or a directory. If successful, the return value is true, else, false. False is returned when the file does not exist or the permission is denied.</dd>
2458 </dl>
2459
2460 <p>The function `cburlbreak' is used in order to break up a URL into elements.</p>
2461
2462 <dl>
2463 <dt><kbd>CBMAP *cburlbreak(const char *<var>str</var>);</kbd></dt>
2464 <dd>`str' specifies the pointer to a string of URL. The return value is a map handle. Each key of the map is the name of an element. The key "self" specifies the URL itself. The key "scheme" specifies the scheme. The key "host" specifies the host of the server. The key "port" specifies the port number of the server. The key "authority" specifies the authority information. The key "path" specifies the path of the resource. The key "file" specifies the file name without the directory section. The key "query" specifies the query string. The key "fragment" specifies the fragment string. Supported schema are HTTP, HTTPS, FTP, and FILE. Absolute URL and relative URL are supported. Because the handle of the return value is opened with the function `cbmapopen', it should be closed with the function `cbmapclose' if it is no longer in use.</dd>
2465 </dl>
2466
2467 <p>The runction `cburlresolve' is used in order to resolve a relative URL with another absolute URL.</p>
2468
2469 <dl>
2470 <dt><kbd>char *cburlresolve(const char *<var>base</var>, const char *<var>target</var>);</kbd></dt>
2471 <dd>`base' specifies an absolute URL of a base location. `target' specifies a URL to be resolved. The return value is a resolved URL. If the target URL is relative, a new URL of relative location from the base location is returned. Else, a copy of the target URL is returned. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
2472 </dl>
2473
2474 <p>The function `cburlencode' is used in order to encode a serial object with URL encoding.</p>
2475
2476 <dl>
2477 <dt><kbd>char *cburlencode(const char *<var>ptr</var>, int <var>size</var>);</kbd></dt>
2478 <dd>`ptr' specifies the pointer to a region. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. The return value is the pointer to the result string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
2479 </dl>
2480
2481 <p>The function `cburldecode' is used in order to decode a string encoded with URL encoding.</p>
2482
2483 <dl>
2484 <dt><kbd>char *cburldecode(const char *<var>str</var>, int *<var>sp</var>);</kbd></dt>
2485 <dd>`str' specifies the pointer to a source string. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. The return value is the pointer to the region of the result. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
2486 </dl>
2487
2488 <p>The function `cbbaseencode' is used in order to encode a serial object with Base64 encoding.</p>
2489
2490 <dl>
2491 <dt><kbd>char *cbbaseencode(const char *<var>ptr</var>, int <var>size</var>);</kbd></dt>
2492 <dd>`ptr' specifies the pointer to a region. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. The return value is the pointer to the result string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
2493 </dl>
2494
2495 <p>The function `cbbasedecode' is used in order to decode a string encoded with Base64 encoding.</p>
2496
2497 <dl>
2498 <dt><kbd>char *cbbasedecode(const char *<var>str</var>, int *<var>sp</var>);</kbd></dt>
2499 <dd>`str' specifies the pointer to a source string. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. The return value is the pointer to the region of the result. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
2500 </dl>
2501
2502 <p>The function `cbquoteencode' is used in order to encode a serial object with quoted-printable encoding.</p>
2503
2504 <dl>
2505 <dt><kbd>char *cbquoteencode(const char *<var>ptr</var>, int <var>size</var>);</kbd></dt>
2506 <dd>`ptr' specifies the pointer to a region. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. The return value is the pointer to the result string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
2507 </dl>
2508
2509 <p>The function `cbquotedecode' is used in order to decode a string encoded with quoted-printable encoding.</p>
2510
2511 <dl>
2512 <dt><kbd>char *cbquotedecode(const char *<var>str</var>, int *<var>sp</var>);</kbd></dt>
2513 <dd>`str' specifies the pointer to a source string. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. The return value is the pointer to the region of the result. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
2514 </dl>
2515
2516
2517 <p>The function `cbmimebreak' is used in order to split a string of MIME into headers and the body.</p>
2518
2519 <dl>
2520 <dt><kbd>char *cbmimebreak(const char *<var>ptr</var>, int <var>size</var>, CBMAP *<var>attrs</var>, int *<var>sp</var>);</kbd></dt>
2521 <dd>`ptr' specifies the pointer to the region of MIME data. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. `attrs' specifies a map handle to store attributes. If it is `NULL', it is not used. Each key of the map is an attribute name uncapitalized. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. The return value is the pointer of the body data. If the content type is defined, the attribute map has the key "TYPE" specifying the type. If the character encoding is defined, the key "CHARSET" specifies the encoding name. If the boundary string of multipart is defined, the key "BOUNDARY" specifies the string. If the content disposition is defined, the key "DISPOSITION" specifies the direction. If the file name is defined, the key "FILENAME" specifies the name. If the attribute name is defined, the key "NAME" specifies the name. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
2522 </dl>
2523
2524 <p>The function `cbmimeparts' is used in order to split multipart data of MIME into its parts.</p>
2525
2526 <dl>
2527 <dt><kbd>CBLIST *cbmimeparts(const char *<var>ptr</var>, int <var>size</var>, const char *<var>boundary</var>);</kbd></dt>
2528 <dd>`ptr' specifies the pointer to the region of multipart data of MIME. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. `boundary' specifies the pointer to the region of the boundary string. The return value is a list handle. Each element of the list is the string of a part. Because the handle of the return value is opened with the function `cblistopen', it should be closed with the function `cblistclose' if it is no longer in use.</dd>
2529 </dl>
2530
2531 <p>The function `cbmimeencode' is used in order to encode a string with MIME encoding.</p>
2532
2533 <dl>
2534 <dt><kbd>char *cbmimeencode(const char *<var>str</var>, const char *<var>encname</var>, int <var>base</var>);</kbd></dt>
2535 <dd>`str' specifies the pointer to a string. `encname' specifies a string of the name of the character encoding. The return value is the pointer to the result string. `base' specifies whether to use Base64 encoding. If it is false, quoted-printable is used. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
2536 </dl>
2537
2538 <p>The function `cbmimedecode' is used in order to decode a string encoded with MIME encoding.</p>
2539
2540 <dl>
2541 <dt><kbd>char *cbmimedecode(const char *<var>str</var>, char *<var>enp</var>);</kbd></dt>
2542 <dd>`str' specifies the pointer to an encoded string. `enp' specifies the pointer to a region into which the name of encoding is written. If it is `NULL', it is not used. The size of the buffer should be equal to or more than 32 bytes. The return value is the pointer to the result string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
2543 </dl>
2544
2545 <p>The function `cbcsvrows' is used in order to split a string of CSV into rows.</p>
2546
2547 <dl>
2548 <dt><kbd>CBLIST *cbcsvrows(const char *<var>str</var>);</kbd></dt>
2549 <dd>`str' specifies the pointer to the region of an CSV string. The return value is a list handle. Each element of the list is a string of a row. Because the handle of the return value is opened with the function `cblistopen', it should be closed with the function `cblistclose' if it is no longer in use. The character encoding of the input string should be US-ASCII, UTF-8, ISO-8859-*, EUC-*, or Shift_JIS. Being compatible with MS-Excel, these functions for CSV can handle cells including such meta characters as comma, between double quotation marks.</dd>
2550 </dl>
2551
2552 <p>The function `cbcsvcells' is used in order to split the string of a row of CSV into cells.</p>
2553
2554 <dl>
2555 <dt><kbd>CBLIST *cbcsvcells(const char *<var>str</var>);</kbd></dt>
2556 <dd>`str' specifies the pointer to the region of a row of CSV. The return value is a list handle. Each element of the list is the unescaped string of a cell of the row. Because the handle of the return value is opened with the function `cblistopen', it should be closed with the function `cblistclose' if it is no longer in use.</dd>
2557 </dl>
2558
2559 <p>The function `cbcsvescape' is used in order to escape a string with the meta characters of CSV.</p>
2560
2561 <dl>
2562 <dt><kbd>char *cbcsvescape(const char *<var>str</var>);</kbd></dt>
2563 <dd>`str' specifies the pointer to the region of a string. The return value is the pointer to the escaped string sanitized of meta characters. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
2564 </dl>
2565
2566 <p>The function `cbcsvunescape' is used in order to unescape a string with the escaped meta characters of CSV.</p>
2567
2568 <dl>
2569 <dt><kbd>char *cbcsvunescape(const char *<var>str</var>);</kbd></dt>
2570 <dd>`str' specifies the pointer to the region of a string with meta characters. The return value is the pointer to the unescaped string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
2571 </dl>
2572
2573 <p>The function `cbxmlbreak' is used in order to split a string of XML into tags and text sections.</p>
2574
2575 <dl>
2576 <dt><kbd>CBLIST *cbxmlbreak(const char *<var>str</var>, int <var>cr</var>);</kbd></dt>
2577 <dd>`str' specifies the pointer to the region of an XML string. `cr' specifies whether to remove comments. The return value is a list handle. Each element of the list is the string of a tag or a text section. Because the handle of the return value is opened with the function `cblistopen', it should be closed with the function `cblistclose' if it is no longer in use. The character encoding of the input string should be US-ASCII, UTF-8, ISO-8859-*, EUC-*, or Shift_JIS. Because these functions for XML are not XML parser with validation check, it can handle also HTML and SGML.</dd>
2578 </dl>
2579
2580 <p>The function `cbxmlattrs' is used in order to get the map of attributes of an XML tag.</p>
2581
2582 <dl>
2583 <dt><kbd>CBMAP *cbxmlattrs(const char *<var>str</var>);</kbd></dt>
2584 <dd>`str' specifies the pointer to the region of a tag string. The return value is a map handle. Each key of the map is the name of an attribute. Each value is unescaped. You can get the name of the tag with the key of an empty string. Because the handle of the return value is opened with the function `cbmapopen', it should be closed with the function `cbmapclose' if it is no longer in use.</dd>
2585 </dl>
2586
2587 <p>The function `cbxmlescape' is used in order to escape a string with the meta characters of XML.</p>
2588
2589 <dl>
2590 <dt><kbd>char *cbxmlescape(const char *<var>str</var>);</kbd></dt>
2591 <dd>`str' specifies the pointer to the region of a string. The return value is the pointer to the escaped string sanitized of meta characters. This function converts only `&amp;', `&lt;', `&gt;', and `&quot;'. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
2592 </dl>
2593
2594 <p>The function `cbxmlunescape' is used in order to unescape a string with the entity references of XML.</p>
2595
2596 <dl>
2597 <dt><kbd>char *cbxmlunescape(const char *<var>str</var>);</kbd></dt>
2598 <dd>`str' specifies the pointer to the region of a string. The return value is the pointer to the unescaped string. This function restores only `&amp;amp;', `&amp;lt;', `&amp;gt;', and `&amp;quot;'. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
2599 </dl>
2600
2601 <p>The function `cbdeflate' is used in order to compress a serial object with ZLIB.</p>
2602
2603 <dl>
2604 <dt><kbd>char *cbdeflate(const char *<var>ptr</var>, int <var>size</var>, int *<var>sp</var>);</kbd></dt>
2605 <dd>`ptr' specifies the pointer to a region. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If successful, the return value is the pointer to the result object, else, it is `NULL'. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. This function is available only if QDBM was built with ZLIB enabled.</dd>
2606 </dl>
2607
2608 <p>The function `cbinflate' is used in order to decompress a serial object compressed with ZLIB.</p>
2609
2610 <dl>
2611 <dt><kbd>char *cbinflate(const char *<var>ptr</var>, int <var>size</var>, int *<var>sp</var>);</kbd></dt>
2612 <dd>`ptr' specifies the pointer to a region. `size' specifies the size of the region. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the result object, else, it is `NULL'. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. This function is available only if QDBM was built with ZLIB enabled.</dd>
2613 </dl>
2614
2615 <p>The function `cbgzencode' is used in order to compress a serial object with GZIP.</p>
2616
2617 <dl>
2618 <dt><kbd>char *cbgzencode(const char *<var>ptr</var>, int <var>size</var>, int *<var>sp</var>);</kbd></dt>
2619 <dd>`ptr' specifies the pointer to a region. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If successful, the return value is the pointer to the result object, else, it is `NULL'. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. This function is available only if QDBM was built with ZLIB enabled.</dd>
2620 </dl>
2621
2622 <p>The function `cbgzdecode' is used in order to decompress a serial object compressed with GZIP.</p>
2623
2624 <dl>
2625 <dt><kbd>char *cbgzdecode(const char *<var>ptr</var>, int <var>size</var>, int *<var>sp</var>);</kbd></dt>
2626 <dd>`ptr' specifies the pointer to a region. `size' specifies the size of the region. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the result object, else, it is `NULL'. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. This function is available only if QDBM was built with ZLIB enabled.</dd>
2627 </dl>
2628
2629 <p>The function `cbgetcrc' is used in order to get the CRC32 checksum of a serial object.</p>
2630
2631 <dl>
2632 <dt><kbd>unsigned int cbgetcrc(const char *<var>ptr</var>, int <var>size</var>);</kbd></dt>
2633 <dd>`ptr' specifies the pointer to a region. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. The return value is the CRC32 checksum of the object. This function is available only if QDBM was built with ZLIB enabled.</dd>
2634 </dl>
2635
2636 <p>The function `cblzoencode' is used in order to compress a serial object with LZO.</p>
2637
2638 <dl>
2639 <dt><kbd>char *cblzoencode(const char *<var>ptr</var>, int <var>size</var>, int *<var>sp</var>);</kbd></dt>
2640 <dd>`ptr' specifies the pointer to a region. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If successful, the return value is the pointer to the result object, else, it is `NULL'. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. This function is available only if QDBM was built with LZO enabled.</dd>
2641 </dl>
2642
2643 <p>The function `cblzodecode' is used in order to decompress a serial object compressed with LZO.</p>
2644
2645 <dl>
2646 <dt><kbd>char *cblzodecode(const char *<var>ptr</var>, int <var>size</var>, int *<var>sp</var>);</kbd></dt>
2647 <dd>`ptr' specifies the pointer to a region. `size' specifies the size of the region. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the result object, else, it is `NULL'. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. This function is available only if QDBM was built with LZO enabled.</dd>
2648 </dl>
2649
2650 <p>The function `cbbzencode' is used in order to compress a serial object with BZIP2.</p>
2651
2652 <dl>
2653 <dt><kbd>char *cbbzencode(const char *<var>ptr</var>, int <var>size</var>, int *<var>sp</var>);</kbd></dt>
2654 <dd>`ptr' specifies the pointer to a region. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If successful, the return value is the pointer to the result object, else, it is `NULL'. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. This function is available only if QDBM was built with BZIP2 enabled.</dd>
2655 </dl>
2656
2657 <p>The function `cbbzdecode' is used in order to decompress a serial object compressed with BZIP2.</p>
2658
2659 <dl>
2660 <dt><kbd>char *cbbzdecode(const char *<var>ptr</var>, int <var>size</var>, int *<var>sp</var>);</kbd></dt>
2661 <dd>`ptr' specifies the pointer to a region. `size' specifies the size of the region. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the result object, else, it is `NULL'. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. This function is available only if QDBM was built with BZIP2 enabled.</dd>
2662 </dl>
2663
2664 <p>The function `cbiconv' is used in order to convert the character encoding of a string.</p>
2665
2666 <dl>
2667 <dt><kbd>char *cbiconv(const char *<var>ptr</var>, int <var>size</var>, const char *<var>icode</var>, const char *<var>ocode</var>, int *<var>sp</var>, int *<var>mp</var>);</kbd></dt>
2668 <dd>`ptr' specifies the pointer to a region. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. `icode' specifies the name of encoding of the input string. `ocode' specifies the name of encoding of the output string. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. `mp' specifies the pointer to a variable to which the number of missing characters by failure of conversion is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the result object, else, it is `NULL'. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. This function is available only if QDBM was built with ICONV enabled.</dd>
2669 </dl>
2670
2671 <p>The function `cbencname' is used in order to detect the encoding of a string automatically.</p>
2672
2673 <dl>
2674 <dt><kbd>const char *cbencname(const char *<var>ptr</var>, int <var>size</var>);</kbd></dt>
2675 <dd>`ptr' specifies the pointer to a region. `size' specifies the size of the region. If it is negative, the size is assigned with `strlen(ptr)'. The return value is the string of the encoding name of the string. As it stands, US-ASCII, ISO-2022-JP, Shift_JIS, CP932, EUC-JP, UTF-8, UTF-16, UTF-16BE, and UTF-16LE are supported. If none of them matches, ISO-8859-1 is selected. This function is available only if QDBM was built with ICONV enabled.</dd>
2676 </dl>
2677
2678 <p>The function `cbjetlag' is used in order to get the jet lag of the local time in seconds.</p>
2679
2680 <dl>
2681 <dt><kbd>int cbjetlag(void);</kbd></dt>
2682 <dd>The return value is the jet lag of the local time in seconds.</dd>
2683 </dl>
2684
2685 <p>The function `cbcalendar' is used in order to get the Gregorian calendar of a time.</p>
2686
2687 <dl>
2688 <dt><kbd>void cbcalendar(time_t <var>t</var>, int <var>jl</var>, int *<var>yearp</var>, int *<var>monp</var>, int *<var>dayp</var>, int *<var>hourp</var>, int *<var>minp</var>, int *<var>secp</var>);</kbd></dt>
2689 <dd>`t' specifies a source time. If it is negative, the current time is specified. `jl' specifies the jet lag of a location in seconds. `yearp' specifies the pointer to a variable to which the year is assigned. If it is `NULL', it is not used. `monp' specifies the pointer to a variable to which the month is assigned. If it is `NULL', it is not used. 1 means January and 12 means December. `dayp' specifies the pointer to a variable to which the day of the month is assigned. If it is `NULL', it is not used. `hourp' specifies the pointer to a variable to which the hours is assigned. If it is `NULL', it is not used. `minp' specifies the pointer to a variable to which the minutes is assigned. If it is `NULL', it is not used. `secp' specifies the pointer to a variable to which the seconds is assigned. If it is `NULL', it is not used.</dd>
2690 </dl>
2691
2692 <p>The function `cbdayofweek' is used in order to get the day of week of a date.</p>
2693
2694 <dl>
2695 <dt><kbd>int cbdayofweek(int <var>year</var>, int <var>mon</var>, int <var>day</var>);</kbd></dt>
2696 <dd>`year' specifies the year of a date. `mon' specifies the month of the date. `day' specifies the day of the date. The return value is the day of week of the date. 0 means Sunday and 6 means Saturday.</dd>
2697 </dl>
2698
2699 <p>The function `cbdatestrwww' is used in order to get the string for a date in W3CDTF.</p>
2700
2701 <dl>
2702 <dt><kbd>char *cbdatestrwww(time_t <var>t</var>, int <var>jl</var>);</kbd></dt>
2703 <dd>`t' specifies a source time. If it is negative, the current time is specified. `jl' specifies the jet lag of a location in seconds. The return value is the string of the date in W3CDTF (YYYY-MM-DDThh:mm:ddTZD). Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
2704 </dl>
2705
2706 <p>The function `cbdatestrhttp' is used in order to get the string for a date in RFC 1123 format.</p>
2707
2708 <dl>
2709 <dt><kbd>char *cbdatestrhttp(time_t <var>t</var>, int <var>jl</var>);</kbd></dt>
2710 <dd>`t' specifies a source time. If it is negative, the current time is specified. `jl' specifies the jet lag of a location in seconds. The return value is the string of the date in RFC 1123 format (Wdy, DD-Mon-YYYY hh:mm:dd TZD). Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
2711 </dl>
2712
2713 <p>The function `cbstrmktime' is used in order to get the time value of a date string in decimal, hexadecimal, W3CDTF, or RFC 822 (1123).</p>
2714
2715 <dl>
2716 <dt><kbd>time_t cbstrmktime(const char *<var>str</var>);</kbd></dt>
2717 <dd>`str' specifies a date string in decimal, hexadecimal, W3CDTF, or RFC 822 (1123). The return value is the time value of the date or -1 if the format is invalid. Decimal can be trailed by "s" for in seconds, "m" for in minutes, "h" for in hours, and "d" for in days.</dd>
2718 </dl>
2719
2720 <p>The function `cbproctime' is used in order to get user and system processing times.</p>
2721
2722 <dl>
2723 <dt><kbd>void cbproctime(double *<var>usrp</var>, double *<var>sysp</var>);</kbd></dt>
2724 <dd>`usrp' specifies the pointer to a variable to which the user processing time is assigned. If it is `NULL', it is not used. The unit of time is seconds. `sysp' specifies the pointer to a variable to which the system processing time is assigned. If it is `NULL', it is not used. The unit of time is seconds.</dd>
2725 </dl>
2726
2727 <p>The function `cbstdiobin' is used in order to ensure that the standard I/O is binary mode.</p>
2728
2729 <dl>
2730 <dt><kbd>void cbstdiobin(void);</kbd></dt>
2731 <dd>This function is useful for applications on dosish file systems.</dd>
2732 </dl>
2733
2734 <h3>Examples</h3>
2735
2736 <p>The following example is typical use.</p>
2737
2738 <pre>#include &lt;cabin.h&gt;
2739 #include &lt;stdlib.h&gt;
2740 #include &lt;stdio.h&gt;
2741
2742 int main(int argc, char **argv){
2743 CBDATUM *datum;
2744 CBLIST *list;
2745 CBMAP *map;
2746 char *buf1, *buf2;
2747 int i;
2748
2749 /* open the datum handle */
2750 datum = cbdatumopen("123", -1);
2751 /* concatenate the data */
2752 cbdatumcat(datum, "abc", -1);
2753 /* print the datum */
2754 printf("%s\n", cbdatumptr(datum));
2755 /* close the datum handle */
2756 cbdatumclose(datum);
2757
2758 /* open the list handle */
2759 list = cblistopen();
2760 /* add elements into the list */
2761 cblistpush(list, "apple", -1);
2762 cblistpush(list, "orange", -1);
2763 /* print all elements */
2764 for(i = 0; i &lt; cblistnum(list); i++){
2765 printf("%s\n", cblistval(list, i, NULL));
2766 }
2767 /* close the list handle */
2768 cblistclose(list);
2769
2770 /* open the map handle */
2771 map = cbmapopen();
2772 /* add records into the map */
2773 cbmapput(map, "dog", -1, "bowwow", -1, 1);
2774 cbmapput(map, "cat", -1, "meow", -1, 1);
2775 /* search for values and print them */
2776 printf("%s\n", cbmapget(map, "dog", -1, NULL));
2777 printf("%s\n", cbmapget(map, "cat", -1, NULL));
2778 /* close the map */
2779 cbmapclose(map);
2780
2781 /* Base64 encoding */
2782 buf1 = cbbaseencode("I miss you.", -1);
2783 printf("%s\n", buf1);
2784 /* Base64 decoding */
2785 buf2 = cbbasedecode(buf1, NULL);
2786 printf("%s\n", buf2);
2787 /* release the resources */
2788 free(buf2);
2789 free(buf1);
2790
2791 /* register a plain pointer to the global garbage collector */
2792 buf1 = cbmemdup("Take it easy.", -1);
2793 cbglobalgc(buf1, free);
2794 /* the pointer is available but you don't have to release it */
2795 printf("%s\n", buf1);
2796
2797 /* register a list to the global garbage collector */
2798 list = cblistopen();
2799 cbglobalgc(list, (void (*)(void *))cblistclose);
2800 /* the handle is available but you don't have to close it */
2801 cblistpush(list, "Don't hesitate.", -1);
2802 for(i = 0; i &lt; cblistnum(list); i++){
2803 printf("%s\n", cblistval(list, i, NULL));
2804 }
2805
2806 return 0;
2807 }
2808 </pre>
2809
2810 <h3>Notes</h3>
2811
2812 <p>How to build programs using Cabin is the same as the case of Depot.</p>
2813
2814 <pre>gcc -I/usr/local/include -o sample sample.c -L/usr/local/lib -lqdbm
2815 </pre>
2816
2817 <p>Functions of Cabin except for `cbglobalgc' are thread-safe as long as a handle is not accessed by threads at the same time, on the assumption that `errno', `malloc', and so on are thread-safe.</p>
2818
2819 <hr />
2820
2821 <h2><a name="cabincli" id="cabincli" class="head">Commands for Cabin</a></h2>
2822
2823 <p>Cabin has the following command line interfaces.</p>
2824
2825 <p>The command `cbtest' is a utility for facility test and performance test. Measure the execution time of the command. This command is used in the following format. `rnum' specifies the number of records.</p>
2826
2827 <dl>
2828 <dt><kbd>cbtest sort [-d] <var>rnum</var></kbd></dt>
2829 <dd>Perform test of sorting algorithms.</dd>
2830 <dt><kbd>cbtest strstr [-d] <var>rnum</var></kbd></dt>
2831 <dd>Perform test of string locating algorithms.</dd>
2832 <dt><kbd>cbtest list [-d] <var>rnum</var></kbd></dt>
2833 <dd>Perform writing test of list.</dd>
2834 <dt><kbd>cbtest map [-d] <var>rnum</var></kbd></dt>
2835 <dd>Perform writing test of map.</dd>
2836 <dt><kbd>cbtest wicked <var>rnum</var></kbd></dt>
2837 <dd>Perform updating operations of list and map selected at random.</dd>
2838 <dt><kbd>cbtest misc</kbd></dt>
2839 <dd>Perform test of miscellaneous routines.</dd>
2840 </dl>
2841
2842 <p>Options feature the following.</p>
2843
2844 <ul class="lines">
2845 <li><kbd>-d</kbd> : read and show data of the result.</li>
2846 </ul>
2847
2848 <p>This command returns 0 on success, another on failure.</p>
2849
2850 <p>The command `cbcodec' is a tool to use encoding and decoding features provided by Cabin. This command is used in the following format. `file' specifies a input file. If it is omitted, the standard input is read.</p>
2851
2852 <dl>
2853 <dt><kbd>cbcodec url [-d] [-br] [-rs <var>base</var> <var>target</var>] [-l] [-e <var>expr</var>] [<var>file</var>]</kbd></dt>
2854 <dd>Perform URL encoding and its decoding.</dd>
2855 <dt><kbd>cbcodec base [-d] [-l] [-c <var>num</var>] [-e <var>expr</var>] [<var>file</var>]</kbd></dt>
2856 <dd>Perform Base64 encoding and its decoding.</dd>
2857 <dt><kbd>cbcodec quote [-d] [-l] [-c <var>num</var>] [-e <var>expr</var>] [<var>file</var>]</kbd></dt>
2858 <dd>Perform quoted-printable encoding and its decoding.</dd>
2859 <dt><kbd>cbcodec mime [-d] [-hd] [-bd] [-part <var>num</var>] [-l] [-ec <var>code</var>] [-qp] [-dc] [-e <var>expr</var>] [<var>file</var>]</kbd></dt>
2860 <dd>Perform MIME encoding and its decoding.</dd>
2861 <dt><kbd>cbcodec csv [-d] [-t] [-l] [-e <var>expr</var>] [-html] [<var>file</var>]</kbd></dt>
2862 <dd>Process CSV. By default, escape meta characters.</dd>
2863 <dt><kbd>cbcodec xml [-d] [-p] [-l] [-e <var>expr</var>] [-tsv] [<var>file</var>]</kbd></dt>
2864 <dd>Process XML. By default, escape meta characters.</dd>
2865 <dt><kbd>cbcodec zlib [-d] [-gz] [-crc] [<var>file</var>]</kbd></dt>
2866 <dd>Perform deflation and inflation with ZLIB. It is available only if QDBM was built with ZLIB enabled.</dd>
2867 <dt><kbd>cbcodec lzo [-d] [<var>file</var>]</kbd></dt>
2868 <dd>Perform compression and decompression with LZO. It is available only if QDBM was built with LZO enabled.</dd>
2869 <dt><kbd>cbcodec bzip [-d] [<var>file</var>]</kbd></dt>
2870 <dd>Perform compression and decompression with BZIP2. It is available only if QDBM was built with BZIP2 enabled.</dd>
2871 <dt><kbd>cbcodec iconv [-ic <var>code</var>] [-oc <var>code</var>] [-ol <var>ltype</var>] [-cn] [-um] [-wc] [<var>file</var>]</kbd></dt>
2872 <dd>Convert character encoding with ICONV. It is available only if QDBM was built with ICONV enabled.</dd>
2873 <dt><kbd>cbcodec date [-wf] [-rf] [-utc] [<var>str</var>]</kbd></dt>
2874 <dd>Convert a date string specified `str'. By default, UNIX time is output. If `str' is omitted, the current date is dealt.</dd>
2875 </dl>
2876
2877 <p>Options feature the following.</p>
2878
2879 <ul class="lines">
2880 <li><kbd>-d</kbd> : perform decoding (unescaping), not encoding (escaping).</li>
2881 <li><kbd>-br</kbd> : break up URL into elements.</li>
2882 <li><kbd>-rs</kbd> : resolve relative URL.</li>
2883 <li><kbd>-l</kbd> : output the tailing newline.</li>
2884 <li><kbd>-e <var>expr</var></kbd> : specify input data directly.</li>
2885 <li><kbd>-c <var>num</var></kbd> : limit the number of columns of the encoded data.</li>
2886 <li><kbd>-hd</kbd> : parse MIME and extract headers in TSV format.</li>
2887 <li><kbd>-bd</kbd> : parse MIME and extract the body.</li>
2888 <li><kbd>-part <var>num</var></kbd> : parse MIME and extract a part.</li>
2889 <li><kbd>-ec <var>code</var></kbd> : specify the input encoding, which is UTF-8 by default.</li>
2890 <li><kbd>-qp</kbd> : use quoted-printable encoding, which is Base64 by default.</li>
2891 <li><kbd>-dc</kbd> : output the encoding name instead of the result string when decoding.</li>
2892 <li><kbd>-t</kbd> : parse CSV. Convert the data into TSV. Tab and new-line in a cell are deleted.</li>
2893 <li><kbd>-html</kbd> : parse CSV. Convert the data into HTML.</li>
2894 <li><kbd>-p</kbd> : parse XML. Show tags and text sections with dividing headers.</li>
2895 <li><kbd>-tsv</kbd> : parse XML. Show the result in TSV format. Characters of tabs and new-lines are URL-encoded.</li>
2896 <li><kbd>-gz</kbd> : use GZIP format.</li>
2897 <li><kbd>-crc</kbd> : output the CRC32 checksum as hexadecimal and big endian.</li>
2898 <li><kbd>-ic <var>code</var></kbd> : specify the input encoding, which is detected automatically by default.</li>
2899 <li><kbd>-oc <var>code</var></kbd> : specify the output encoding, which is UTF-8 by default.</li>
2900 <li><kbd>-ol <var>ltype</var></kbd> : convert line feed characters, with `unix'(LF), `dos'(CRLF), and `mac'(CR).</li>
2901 <li><kbd>-cn</kbd> : detect the input encoding and show its name.</li>
2902 <li><kbd>-wc</kbd> : count the number of characters of the input string of UTF-8.</li>
2903 <li><kbd>-um</kbd> : output mappings of UCS-2 characters and C strings of UTF-16BE and UTF-8.</li>
2904 <li><kbd>-wf</kbd> : output in W3CDTF format.</li>
2905 <li><kbd>-rf</kbd> : output in RFC 1123 format.</li>
2906 <li><kbd>-utc</kbd> : output the coordinate universal time.</li>
2907 </ul>
2908
2909 <p>This command returns 0 on success, another on failure.</p>
2910
2911 <hr />
2912
2913 <h2><a name="villaapi" id="villaapi" class="head">Villa: Advanced API</a></h2>
2914
2915 <h3>Overview</h3>
2916
2917 <p>Villa is the advanced API of QDBM. It provides routines for managing a database file of B+ tree. Each record is stored being sorted in order defined by a user. As for hash databases, retrieving method is provided only as complete accord. However, with Villa, it is possible to retrieve records specified by range. Cursor is used in order to access each record in order. It is possible to store records duplicating keys in a database. Moreover, according to the transaction mechanism, you can commit or abort operations of a database in a lump.</p>
2918
2919 <p>Villa is implemented, based on Depot and Cabin. A database file of Villa is actual one of Depot. Although processing speed of retrieving and storing is slower than Depot, the size of a database is smaller.</p>
2920
2921 <p>In order to use Villa, you should include `depot.h', `cabin.h', `villa.h' and `stdlib.h' in the source files. Usually, the following description will be near the beginning of a source file.</p>
2922
2923 <dl>
2924 <dt><kbd>#include &lt;depot.h&gt;</kbd></dt>
2925 <dt><kbd>#include &lt;cabin.h&gt;</kbd></dt>
2926 <dt><kbd>#include &lt;villa.h&gt;</kbd></dt>
2927 <dt><kbd>#include &lt;stdlib.h&gt;</kbd></dt>
2928 </dl>
2929
2930 <p>A pointer to `VILLA' is used as a database handle. It is like that some file I/O routines of `stdio.h' use a pointer to `FILE'. A database handle is opened with the function `vlopen' and closed with `vlclose'. You should not refer directly to any member of the handle. If a fatal error occurs in a database, any access method via the handle except `vlclose' will not work and return error status. Although a process is allowed to use multiple database handles at the same time, handles of the same database file should not be used. Before the cursor is used, it should be initialized by one of `vlcurfirst', `vlcurlast' or `vlcurjump'. Also after storing or deleting a record with functions except for `vlcurput' and `vlcurout', the cursor should be initialized.</p>
2931
2932 <p>Villa also assign the external variable `dpecode' with the error code. The function `dperrmsg' is used in order to get the message of the error code.</p>
2933
2934 <h3>API</h3>
2935
2936 <p>You can define a comparing function to specify the order of records. The function should be the following type.</p>
2937
2938 <dl>
2939 <dt><kbd>typedef int(*VLCFUNC)(const char *<var>aptr</var>, int <var>asiz</var>, const char *<var>bptr</var>, int <var>bsiz</var>);</kbd></dt>
2940 <dd>`aptr' specifies the pointer to the region of one key. `asiz' specifies the size of the region of one key. `bptr' specifies the pointer to the region of the other key. `bsiz' specifies the size of the region of the other key. The return value is positive if the former is big, negative if the latter is big, 0 if both are equivalent.</dd>
2941 </dl>
2942
2943 <p>The function `vlopen' is used in order to get a database handle.</p>
2944
2945 <dl>
2946 <dt><kbd>VILLA *vlopen(const char *<var>name</var>, int <var>omode</var>, VLCFUNC <var>cmp</var>);</kbd></dt>
2947 <dd>`name' specifies the name of a database file. `omode' specifies the connection mode: `VL_OWRITER' as a writer, `VL_OREADER' as a reader. If the mode is `VL_OWRITER', the following may be added by bitwise or: `VL_OCREAT', which means it creates a new database if not exist, `VL_OTRUNC', which means it creates a new database regardless if one exists, `VL_OZCOMP', which means leaves in the database are compressed with ZLIB, `VL_OYCOMP', which means leaves in the database are compressed with LZO, `VL_OXCOMP', which means leaves in the database are compressed with BZIP2. Both of `VL_OREADER' and `VL_OWRITER' can be added to by bitwise or: `VL_ONOLCK', which means it opens a database file without file locking, or `VL_OLCKNB', which means locking is performed without blocking. `cmp' specifies the comparing function: `VL_CMPLEX' comparing keys in lexical order, `VL_CMPINT' comparing keys as objects of `int' in native byte order, `VL_CMPNUM' comparing keys as numbers of big endian, `VL_CMPDEC' comparing keys as decimal strings. Any function based on the declaration of the type `VLCFUNC' can be assigned to the comparing function. The comparing function should be kept same in the life of a database. The return value is the database handle or `NULL' if it is not successful. While connecting as a writer, an exclusive lock is invoked to the database file. While connecting as a reader, a shared lock is invoked to the database file. The thread blocks until the lock is achieved. `VL_OZCOMP', `VL_OYCOMP', and `VL_OXCOMP' are available only if QDBM was built each with ZLIB, LZO, and BZIP2 enabled. If `VL_ONOLCK' is used, the application is responsible for exclusion control.</dd>
2948 </dl>
2949
2950 <p>The function `vlclose' is used in order to close a database handle.</p>
2951
2952 <dl>
2953 <dt><kbd>int vlclose(VILLA *<var>villa</var>);</kbd></dt>
2954 <dd>`villa' specifies a database handle. If successful, the return value is true, else, it is false. Because the region of a closed handle is released, it becomes impossible to use the handle. Updating a database is assured to be written when the handle is closed. If a writer opens a database but does not close it appropriately, the database will be broken. If the transaction is activated and not committed, it is aborted.</dd>
2955 </dl>
2956
2957 <p>The function `vlput' is used in order to store a record.</p>
2958
2959 <dl>
2960 <dt><kbd>int vlput(VILLA *<var>villa</var>, const char *<var>kbuf</var>, int <var>ksiz</var>, const char *<var>vbuf</var>, int <var>vsiz</var>, int <var>dmode</var>);</kbd></dt>
2961 <dd>`villa' specifies a database handle connected as a writer. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `vbuf' specifies the pointer to the region of a value. `vsiz' specifies the size of the region of the value. If it is negative, the size is assigned with `strlen(vbuf)'. `dmode' specifies behavior when the key overlaps, by the following values: `VL_DOVER', which means the specified value overwrites the existing one, `VL_DKEEP', which means the existing value is kept, `VL_DCAT', which means the specified value is concatenated at the end of the existing value, `VL_DDUP', which means duplication of keys is allowed and the specified value is added as the last one, `VL_DDUPR', which means duplication of keys is allowed and the specified value is added as the first one. If successful, the return value is true, else, it is false. The cursor becomes unavailable due to updating database.</dd>
2962 </dl>
2963
2964 <p>The function `vlout' is used in order to delete a record.</p>
2965
2966 <dl>
2967 <dt><kbd>int vlout(VILLA *<var>villa</var>, const char *<var>kbuf</var>, int <var>ksiz</var>);</kbd></dt>
2968 <dd>`villa' specifies a database handle connected as a writer. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. If successful, the return value is true, else, it is false. False is returned when no record corresponds to the specified key. When the key of duplicated records is specified, the first record of the same key is deleted. The cursor becomes unavailable due to updating database.</dd>
2969 </dl>
2970
2971 <p>The function `vlget' is used in order to retrieve a record.</p>
2972
2973 <dl>
2974 <dt><kbd>char *vlget(VILLA *<var>villa</var>, const char *<var>kbuf</var>, int <var>ksiz</var>, int *<var>sp</var>);</kbd></dt>
2975 <dd>`villa' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the region of the value of the corresponding record, else, it is `NULL'. `NULL' is returned when no record corresponds to the specified key. When the key of duplicated records is specified, the value of the first record of the same key is selected. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
2976 </dl>
2977
2978 <p>The function `vlvsiz' is used in order to get the size of the value of a record.</p>
2979
2980 <dl>
2981 <dt><kbd>int vlvsiz(VILLA *<var>villa</var>, const char *<var>kbuf</var>, int <var>ksiz</var>);</kbd></dt>
2982 <dd>`villa' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. If successful, the return value is the size of the value of the corresponding record, else, it is -1. If multiple records correspond, the size of the first is returned.</dd>
2983 </dl>
2984
2985 <p>The function `vlvnum' is used in order to get the number of records corresponding a key.</p>
2986
2987 <dl>
2988 <dt><kbd>int vlvnum(VILLA *<var>villa</var>, const char *<var>kbuf</var>, int <var>ksiz</var>);</kbd></dt>
2989 <dd>`villa' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. The return value is the number of corresponding records. If no record corresponds, 0 is returned.</dd>
2990 </dl>
2991
2992 <p>The function `vlputlist' is used in order to store plural records corresponding a key.</p>
2993
2994 <dl>
2995 <dt><kbd>int vlputlist(VILLA *<var>villa</var>, const char *<var>kbuf</var>, int <var>ksiz</var>, const CBLIST *<var>vals</var>);</kbd></dt>
2996 <dd>`villa' specifies a database handle connected as a writer. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `vals' specifies a list handle of values. The list should not be empty. If successful, the return value is true, else, it is false. The cursor becomes unavailable due to updating database.</dd>
2997 </dl>
2998
2999 <p>The function `vloutlist' is used in order to delete all records corresponding a key.</p>
3000
3001 <dl>
3002 <dt><kbd>int vloutlist(VILLA *<var>villa</var>, const char *<var>kbuf</var>, int <var>ksiz</var>);</kbd></dt>
3003 <dd>`villa' specifies a database handle connected as a writer. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. If successful, the return value is true, else, it is false. False is returned when no record corresponds to the specified key. The cursor becomes unavailable due to updating database.</dd>
3004 </dl>
3005
3006 <p>The function `vlgetlist' is used in order to retrieve values of all records corresponding a key.</p>
3007
3008 <dl>
3009 <dt><kbd>CBLIST *vlgetlist(VILLA *<var>villa</var>, const char *<var>kbuf</var>, int <var>ksiz</var>);</kbd></dt>
3010 <dd>`villa' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. If successful, the return value is a list handle of the values of the corresponding records, else, it is `NULL'. `NULL' is returned when no record corresponds to the specified key. Because the handle of the return value is opened with the function `cblistopen', it should be closed with the function `cblistclose' if it is no longer in use.</dd>
3011 </dl>
3012
3013 <p>The function `vlgetcat' is used in order to retrieve concatenated values of all records corresponding a key.</p>
3014
3015 <dl>
3016 <dt><kbd>char *vlgetcat(VILLA *<var>villa</var>, const char *<var>kbuf</var>, int <var>ksiz</var>, int *<var>sp</var>);</kbd></dt>
3017 <dd>`villa' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the region of the concatenated values of the corresponding record, else, it is `NULL'. `NULL' is returned when no record corresponds to the specified key. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
3018 </dl>
3019
3020 <p>The function `vlcurfirst' is used in order to move the cursor to the first record.</p>
3021
3022 <dl>
3023 <dt><kbd>int vlcurfirst(VILLA *<var>villa</var>);</kbd></dt>
3024 <dd>`villa' specifies a database handle. If successful, the return value is true, else, it is false. False is returned if there is no record in the database.</dd>
3025 </dl>
3026
3027 <p>The function `vlcurlast' is used in order to move the cursor to the last record.</p>
3028
3029 <dl>
3030 <dt><kbd>int vlcurlast(VILLA *<var>villa</var>);</kbd></dt>
3031 <dd>`villa' specifies a database handle. If successful, the return value is true, else, it is false. False is returned if there is no record in the database.</dd>
3032 </dl>
3033
3034 <p>The function `vlcurprev' is used in order to move the cursor to the previous record.</p>
3035
3036 <dl>
3037 <dt><kbd>int vlcurprev(VILLA *<var>villa</var>);</kbd></dt>
3038 <dd>`villa' specifies a database handle. If successful, the return value is true, else, it is false. False is returned if there is no previous record.</dd>
3039 </dl>
3040
3041 <p>The function `vlcurnext' is used in order to move the cursor to the next record.</p>
3042
3043 <dl>
3044 <dt><kbd>int vlcurnext(VILLA *<var>villa</var>);</kbd></dt>
3045 <dd>`villa' specifies a database handle. If successful, the return value is true, else, it is false. False is returned if there is no next record.</dd>
3046 </dl>
3047
3048 <p>The function `vlcurjump' is used in order to move the cursor to a position around a record.</p>
3049
3050 <dl>
3051 <dt><kbd>int vlcurjump(VILLA *<var>villa</var>, const char *<var>kbuf</var>, int <var>ksiz</var>, int <var>jmode</var>);</kbd></dt>
3052 <dd>`villa' specifies a database handle. `kbuf' specifies the pointer to the region of a key. `ksiz' specifies the size of the region of the key. If it is negative, the size is assigned with `strlen(kbuf)'. `jmode' specifies detail adjustment: `VL_JFORWARD', which means that the cursor is set to the first record of the same key and that the cursor is set to the next substitute if completely matching record does not exist, `VL_JBACKWARD', which means that the cursor is set to the last record of the same key and that the cursor is set to the previous substitute if completely matching record does not exist. If successful, the return value is true, else, it is false. False is returned if there is no record corresponding the condition.</dd>
3053 </dl>
3054
3055 <p>The function `vlcurkey' is used in order to get the key of the record where the cursor is.</p>
3056
3057 <dl>
3058 <dt><kbd>char *vlcurkey(VILLA *<var>villa</var>, int *<var>sp</var>);</kbd></dt>
3059 <dd>`villa' specifies a database handle. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the region of the key of the corresponding record, else, it is `NULL'. `NULL' is returned when no record corresponds to the cursor. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
3060 </dl>
3061
3062 <p>The function `vlcurval' is used in order to get the value of the record where the cursor is.</p>
3063
3064 <dl>
3065 <dt><kbd>char *vlcurval(VILLA *<var>villa</var>, int *<var>sp</var>);</kbd></dt>
3066 <dd>`villa' specifies a database handle. `sp' specifies the pointer to a variable to which the size of the region of the return value is assigned. If it is `NULL', it is not used. If successful, the return value is the pointer to the region of the value of the corresponding record, else, it is `NULL'. `NULL' is returned when no record corresponds to the cursor. Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
3067 </dl>
3068
3069 <p>The function `vlcurput' is used in order to insert a record around the cursor.</p>
3070
3071 <dl>
3072 <dt><kbd>int vlcurput(VILLA *<var>villa</var>, const char *<var>vbuf</var>, int <var>vsiz</var>, int <var>cpmode</var>);</kbd></dt>
3073 <dd>`villa' specifies a database handle connected as a writer. `vbuf' specifies the pointer to the region of a value. `vsiz' specifies the size of the region of the value. If it is negative, the size is assigned with `strlen(vbuf)'. `cpmode' specifies detail adjustment: `VL_CPCURRENT', which means that the value of the current record is overwritten, `VL_CPBEFORE', which means that a new record is inserted before the current record, `VL_CPAFTER', which means that a new record is inserted after the current record. If successful, the return value is true, else, it is false. False is returned when no record corresponds to the cursor. After insertion, the cursor is moved to the inserted record.</dd>
3074 </dl>
3075
3076 <p>The function `vlcurout' is used in order to delete the record where the cursor is.</p>
3077
3078 <dl>
3079 <dt><kbd>int vlcurout(VILLA *<var>villa</var>);</kbd></dt>
3080 <dd>`villa' specifies a database handle connected as a writer. If successful, the return value is true, else, it is false. False is returned when no record corresponds to the cursor. After deletion, the cursor is moved to the next record if possible.</dd>
3081 </dl>
3082
3083 <p>The function `vlsettuning' is used in order to set the tuning parameters for performance.</p>
3084
3085 <dl>
3086 <dt><kbd>void vlsettuning(VILLA *<var>villa</var>, int <var>lrecmax</var>, int <var>nidxmax</var>, int <var>lcnum</var>, int <var>ncnum</var>);</kbd></dt>
3087 <dd>`villa' specifies a database handle. `lrecmax' specifies the max number of records in a leaf node of B+ tree. If it is not more than 0, the default value is specified. `nidxmax' specifies the max number of indexes in a non-leaf node of B+ tree. If it is not more than 0, the default value is specified. `lcnum' specifies the max number of caching leaf nodes. If it is not more than 0, the default value is specified. `ncnum' specifies the max number of caching non-leaf nodes. If it is not more than 0, the default value is specified. The default setting is equivalent to `vlsettuning(49, 192, 1024, 512)'. Because tuning parameters are not saved in a database, you should specify them every opening a database.</dd>
3088 </dl>
3089
3090 <p>The function `vlsetfbpsiz' is used in order to set the size of the free block pool of a database handle.</p>
3091
3092 <dl>
3093 <dt><kbd>int vlsetfbpsiz(VILLA *<var>villa</var>, int <var>size</var>);</kbd></dt>
3094 <dd>`villa' specifies a database handle connected as a writer. `size' specifies the size of the free block pool of a database. If successful, the return value is true, else, it is false. The default size of the free block pool is 256. If the size is greater, the space efficiency of overwriting values is improved with the time efficiency sacrificed.</dd>
3095 </dl>
3096
3097 <p>The function `vlsync' is used in order to synchronize updating contents with the file and the device.</p>
3098
3099 <dl>
3100 <dt><kbd>int vlsync(VILLA *<var>villa</var>);</kbd></dt>
3101 <dd>`villa' specifies a database handle connected as a writer. If successful, the return value is true, else, it is false. This function is useful when another process uses the connected database file. This function should not be used while the transaction is activated.</dd>
3102 </dl>
3103
3104 <p>The function `vloptimize' is used in order to optimize a database.</p>
3105
3106 <dl>
3107 <dt><kbd>int vloptimize(VILLA *<var>villa</var>);</kbd></dt>
3108 <dd>`villa' specifies a database handle connected as a writer. If successful, the return value is true, else, it is false. In an alternating succession of deleting and storing with overwrite or concatenate, dispensable regions accumulate. This function is useful to do away with them. This function should not be used while the transaction is activated.</dd>
3109 </dl>
3110
3111 <p>The function `vlname' is used in order to get the name of a database.</p>
3112
3113 <dl>
3114 <dt><kbd>char *vlname(VILLA *<var>villa</var>);</kbd></dt>
3115 <dd>`villa' specifies a database handle. If successful, the return value is the pointer to the region of the name of the database, else, it is `NULL'. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
3116 </dl>
3117
3118 <p>The function `vlfsiz' is used in order to get the size of a database file.</p>
3119
3120 <dl>
3121 <dt><kbd>int vlfsiz(VILLA *<var>villa</var>);</kbd></dt>
3122 <dd>`villa' specifies a database handle. If successful, the return value is the size of the database file, else, it is -1. Because of the I/O buffer, the return value may be less than the hard size.</dd>
3123 </dl>
3124
3125 <p>The function `vllnum' is used in order to get the number of the leaf nodes of B+ tree.</p>
3126
3127 <dl>
3128 <dt><kbd>int vllnum(VILLA *<var>villa</var>);</kbd></dt>
3129 <dd>`villa' specifies a database handle. If successful, the return value is the number of the leaf nodes, else, it is -1.</dd>
3130 </dl>
3131
3132 <p>The function `vlnnum' is used in order to get the number of the non-leaf nodes of B+ tree.</p>
3133
3134 <dl>
3135 <dt><kbd>int vlnnum(VILLA *<var>villa</var>);</kbd></dt>
3136 <dd>`villa' specifies a database handle. If successful, the return value is the number of the non-leaf nodes, else, it is -1.</dd>
3137 </dl>
3138
3139 <p>The function `vlrnum' is used in order to get the number of the records stored in a database.</p>
3140
3141 <dl>
3142 <dt><kbd>int vlrnum(VILLA *<var>villa</var>);</kbd></dt>
3143 <dd>`villa' specifies a database handle. If successful, the return value is the number of the records stored in the database, else, it is -1.</dd>
3144 </dl>
3145
3146 <p>The function `vlwritable' is used in order to check whether a database handle is a writer or not.</p>
3147
3148 <dl>
3149 <dt><kbd>int vlwritable(VILLA *<var>villa</var>);</kbd></dt>
3150 <dd>`villa' specifies a database handle. The return value is true if the handle is a writer, false if not.</dd>
3151 </dl>
3152
3153 <p>The function `vlfatalerror' is used in order to check whether a database has a fatal error or not.</p>
3154
3155 <dl>
3156 <dt><kbd>int vlfatalerror(VILLA *<var>villa</var>);</kbd></dt>
3157 <dd>`villa' specifies a database handle. The return value is true if the database has a fatal error, false if not.</dd>
3158 </dl>
3159
3160 <p>The function `vlinode' is used in order to get the inode number of a database file.</p>
3161
3162 <dl>
3163 <dt><kbd>int vlinode(VILLA *<var>villa</var>);</kbd></dt>
3164 <dd>`villa' specifies a database handle. The return value is the inode number of the database file.</dd>
3165 </dl>
3166
3167 <p>The function `vlmtime' is used in order to get the last modified time of a database.</p>
3168
3169 <dl>
3170 <dt><kbd>time_t vlmtime(VILLA *<var>villa</var>);</kbd></dt>
3171 <dd>`villa' specifies a database handle. The return value is the last modified time of the database.</dd>
3172 </dl>
3173
3174 <p>The function `vltranbegin' is used in order to begin the transaction.</p>
3175
3176 <dl>
3177 <dt><kbd>int vltranbegin(VILLA *<var>villa</var>);</kbd></dt>
3178 <dd>`villa' specifies a database handle connected as a writer. If successful, the return value is true, else, it is false. Because this function does not perform mutual exclusion control in multi-thread, the application is responsible for it. Only one transaction can be activated with a database handle at the same time.</dd>
3179 </dl>
3180
3181 <p>The function `vltrancommit' is used in order to commit the transaction.</p>
3182
3183 <dl>
3184 <dt><kbd>int vltrancommit(VILLA *<var>villa</var>);</kbd></dt>
3185 <dd>`villa' specifies a database handle connected as a writer. If successful, the return value is true, else, it is false. Updating a database in the transaction is fixed when it is committed successfully.</dd>
3186 </dl>
3187
3188 <p>The function `vltranabort' is used in order to abort the transaction.</p>
3189
3190 <dl>
3191 <dt><kbd>int vltranabort(VILLA *<var>villa</var>);</kbd></dt>
3192 <dd>`villa' specifies a database handle connected as a writer. If successful, the return value is true, else, it is false. Updating a database in the transaction is discarded when it is aborted. The state of the database is rollbacked to before transaction.</dd>
3193 </dl>
3194
3195 <p>The function `vlremove' is used in order to remove a database file.</p>
3196
3197 <dl>
3198 <dt><kbd>int vlremove(const char *<var>name</var>);</kbd></dt>
3199 <dd>`name' specifies the name of a database file. If successful, the return value is true, else, it is false.</dd>
3200 </dl>
3201
3202 <p>The function `vlrepair' is used in order to repair a broken database file.</p>
3203
3204 <dl>
3205 <dt><kbd>int vlrepair(const char *<var>name</var>, VLCFUNC <var>cmp</var>);</kbd></dt>
3206 <dd>`name' specifies the name of a database file. `cmp' specifies the comparing function of the database file. If successful, the return value is true, else, it is false. There is no guarantee that all records in a repaired database file correspond to the original or expected state.</dd>
3207 </dl>
3208
3209 <p>The function `vlexportdb' is used in order to dump all records as endian independent data.</p>
3210
3211 <dl>
3212 <dt><kbd>int vlexportdb(VILLA *<var>villa</var>, const char *<var>name</var>);</kbd></dt>
3213 <dd>`villa' specifies a database handle. `name' specifies the name of an output file. If successful, the return value is true, else, it is false.</dd>
3214 </dl>
3215
3216 <p>The function `vlimportdb' is used in order to load all records from endian independent data.</p>
3217
3218 <dl>
3219 <dt><kbd>int vlimportdb(VILLA *<var>villa</var>, const char *<var>name</var>);</kbd></dt>
3220 <dd>`villa' specifies a database handle connected as a writer. The database of the handle must be empty. `name' specifies the name of an input file. If successful, the return value is true, else, it is false.</dd>
3221 </dl>
3222
3223 <h3>Examples</h3>
3224
3225 <p>The following example stores and retrieves a phone number, using the name as the key.</p>
3226
3227 <pre>#include &lt;depot.h&gt;
3228 #include &lt;cabin.h&gt;
3229 #include &lt;villa.h&gt;
3230 #include &lt;stdlib.h&gt;
3231 #include &lt;stdio.h&gt;
3232
3233 #define NAME "mikio"
3234 #define NUMBER "000-1234-5678"
3235 #define DBNAME "book"
3236
3237 int main(int argc, char **argv){
3238 VILLA *villa;
3239 char *val;
3240
3241 /* open the database */
3242 if(!(villa = vlopen(DBNAME, VL_OWRITER | VL_OCREAT, VL_CMPLEX))){
3243 fprintf(stderr, "vlopen: %s\n", dperrmsg(dpecode));
3244 return 1;
3245 }
3246
3247 /* store the record */
3248 if(!vlput(villa, NAME, -1, NUMBER, -1, VL_DOVER)){
3249 fprintf(stderr, "vlput: %s\n", dperrmsg(dpecode));
3250 }
3251
3252 /* retrieve the record */
3253 if(!(val = vlget(villa, NAME, -1, NULL))){
3254 fprintf(stderr, "vlget: %s\n", dperrmsg(dpecode));
3255 } else {
3256 printf("Name: %s\n", NAME);
3257 printf("Number: %s\n", val);
3258 free(val);
3259 }
3260
3261 /* close the database */
3262 if(!vlclose(villa)){
3263 fprintf(stderr, "vlclose: %s\n", dperrmsg(dpecode));
3264 return 1;
3265 }
3266
3267 return 0;
3268 }
3269 </pre>
3270
3271 <p>The following example performs forward matching search for strings.</p>
3272
3273 <pre>#include &lt;depot.h&gt;
3274 #include &lt;cabin.h&gt;
3275 #include &lt;villa.h&gt;
3276 #include &lt;stdlib.h&gt;
3277 #include &lt;stdio.h&gt;
3278 #include &lt;string.h&gt;
3279
3280 #define DBNAME "words"
3281 #define PREFIX "apple"
3282
3283 int main(int argc, char **argv){
3284 VILLA *villa;
3285 char *key, *val;
3286
3287 /* open the database */
3288 if(!(villa = vlopen(DBNAME, VL_OWRITER | VL_OCREAT, VL_CMPLEX))){
3289 fprintf(stderr, "vlopen: %s\n", dperrmsg(dpecode));
3290 return 1;
3291 }
3292
3293 /* store records */
3294 if(!vlput(villa, "applet", -1, "little application", -1, VL_DDUP) ||
3295 !vlput(villa, "aurora", -1, "polar wonderwork", -1, VL_DDUP) ||
3296 !vlput(villa, "apple", -1, "delicious fruit", -1, VL_DDUP) ||
3297 !vlput(villa, "amigo", -1, "good friend", -1, VL_DDUP) ||
3298 !vlput(villa, "apple", -1, "big city", -1, VL_DDUP)){
3299 fprintf(stderr, "vlput: %s\n", dperrmsg(dpecode));
3300 }
3301
3302 /* set the cursor at the top of candidates */
3303 vlcurjump(villa, PREFIX, -1, VL_JFORWARD);
3304
3305 /* scan with the cursor */
3306 while((key = vlcurkey(villa, NULL)) != NULL){
3307 if(strstr(key, PREFIX) != key){
3308 free(key);
3309 break;
3310 }
3311 if(!(val = vlcurval(villa, NULL))){
3312 fprintf(stderr, "vlcurval: %s\n", dperrmsg(dpecode));
3313 free(key);
3314 break;
3315 }
3316 printf("%s: %s\n", key, val);
3317 free(val);
3318 free(key);
3319 vlcurnext(villa);
3320 }
3321
3322 /* close the database */
3323 if(!vlclose(villa)){
3324 fprintf(stderr, "vlclose: %s\n", dperrmsg(dpecode));
3325 return 1;
3326 }
3327
3328 return 0;
3329 }
3330 </pre>
3331
3332 <h3>Notes</h3>
3333
3334 <p>How to build programs using Villa is the same as the case of Depot.</p>
3335
3336 <pre>gcc -I/usr/local/include -o sample sample.c -L/usr/local/lib -lqdbm
3337 </pre>
3338
3339 <p>If QDBM was built with POSIX thread enabled, the global variable `dpecode' is treated as thread specific data, and functions of Villa are reentrant. In that case, they are thread-safe as long as a handle is not accessed by threads at the same time, on the assumption that `errno', `malloc', and so on are thread-safe.</p>
3340
3341 <h3>Vista: Extended Advanced API</h3>
3342
3343 <p>Vista is the extended API of Villa. To compensate for the defect that Villa can not handle a file whose size is more than 2GB, Vista does not use Depot but Curia for handling its internal database. While Vista provides data structure and operations of B+ tree as with Villa, its database is realized as a directory.</p>
3344
3345 <p>In order to use Vista, you should include `vista.h' instead of `villa.h'. Because Vista is implemented by overriding symbols of Villa, it can be used as with Villa. That is, Signatures of Villa and Vista is all the same. However, as its adverse effect, modules (compilation unit) using Vista can not use Villa (do not include `villa.h').</p>
3346
3347 <hr />
3348
3349 <h2><a name="villacli" id="villacli" class="head">Commands for Villa</a></h2>
3350
3351 <p>Villa has the following command line interfaces.</p>
3352
3353 <p>The command `vlmgr' is a utility for debugging Villa and its applications. It features editing and checking of a database. It can be used for database applications with shell scripts. This command is used in the following format. `name' specifies a database name. `key' specifies the key of a record. `val' specifies the value of a record.</p>
3354
3355 <dl>
3356 <dt><kbd>vlmgr create [-cz|-cy|-cx] <var>name</var></kbd></dt>
3357 <dd>Create a database file.</dd>
3358 <dt><kbd>vlmgr put [-kx|-ki] [-vx|-vi|-vf] [-keep|-cat|-dup] <var>name</var> <var>key</var> <var>val</var></kbd></dt>
3359 <dd>Store a record with a key and a value.</dd>
3360 <dt><kbd>vlmgr out [-l] [-kx|-ki] <var>name</var> <var>key</var></kbd></dt>
3361 <dd>Delete a record with a key.</dd>
3362 <dt><kbd>vlmgr get [-nl] [-l] [-kx|-ki] [-ox] [-n] <var>name</var> <var>key</var></kbd></dt>
3363 <dd>Retrieve a record with a key and output it to the standard output.</dd>
3364 <dt><kbd>vlmgr list [-nl] [-k|-v] [-kx|-ki] [-ox] [-top <var>key</var>] [-bot <var>key</var>] [-gt] [-lt] [-max <var>num</var>] [-desc] <var>name</var></kbd></dt>
3365 <dd>List all keys and values delimited with tab and line-feed to the standard output.</dd>
3366 <dt><kbd>vlmgr optimize <var>name</var></kbd></dt>
3367 <dd>Optimize a database.</dd>
3368 <dt><kbd>vlmgr inform [-nl] <var>name</var></kbd></dt>
3369 <dd>Output miscellaneous information to the standard output.</dd>
3370 <dt><kbd>vlmgr remove <var>name</var></kbd></dt>
3371 <dd>Remove a database file.</dd>
3372 <dt><kbd>vlmgr repair [-ki] <var>name</var></kbd></dt>
3373 <dd>Repair a broken database file.</dd>
3374 <dt><kbd>vlmgr exportdb [-ki] <var>name</var> <var>file</var></kbd></dt>
3375 <dd>Dump all records as endian independent data.</dd>
3376 <dt><kbd>vlmgr importdb [-ki] <var>name</var> <var>file</var></kbd></dt>
3377 <dd>Load all records from endian independent data.</dd>
3378 <dt><kbd>vlmgr version</kbd></dt>
3379 <dd>Output version information of QDBM to the standard output.</dd>
3380 </dl>
3381
3382 <p>Options feature the following.</p>
3383
3384 <ul class="lines">
3385 <li><kbd>-cz</kbd> : compress leaves in the database with ZLIB.</li>
3386 <li><kbd>-cy</kbd> : compress leaves in the database with LZO.</li>
3387 <li><kbd>-cx</kbd> : compress leaves in the database with BZIP2.</li>
3388 <li><kbd>-l</kbd> : all records corresponding the key are dealt.</li>
3389 <li><kbd>-kx</kbd> : treat `key' as a binary expression of hexadecimal notation.</li>
3390 <li><kbd>-ki</kbd> : treat `key' as an integer expression of decimal notation.</li>
3391 <li><kbd>-vx</kbd> : treat `val' as a binary expression of hexadecimal notation.</li>
3392 <li><kbd>-vi</kbd> : treat `val' as an integer expression of decimal notation.</li>
3393 <li><kbd>-vf</kbd> : read the value from a file specified with `val'.</li>
3394 <li><kbd>-keep</kbd> : specify the storing mode for `VL_DKEEP'.</li>
3395 <li><kbd>-cat</kbd> : specify the storing mode for `VL_DCAT'.</li>
3396 <li><kbd>-dup</kbd> : specify the storing mode for `VL_DDUP'.</li>
3397 <li><kbd>-nl</kbd> : open the database without file locking.</li>
3398 <li><kbd>-top <var>key</var></kbd> : specify the top key of listing.</li>
3399 <li><kbd>-bot <var>key</var></kbd> : specify the bottom key of listing.</li>
3400 <li><kbd>-gt</kbd> : do not include the top key of listing.</li>
3401 <li><kbd>-lt</kbd> : do not include the bottom key of listing.</li>
3402 <li><kbd>-max <var>num</var></kbd> : specify the max number of listing.</li>
3403 <li><kbd>-desc</kbd> : list in descending order.</li>
3404 <li><kbd>-ox</kbd> : treat the output as a binary expression of hexadecimal notation.</li>
3405 <li><kbd>-n</kbd> : do not output the tailing newline.</li>
3406 <li><kbd>-k</kbd> : output keys only.</li>
3407 <li><kbd>-v</kbd> : output values only.</li>
3408 </ul>
3409
3410 <p>This command returns 0 on success, another on failure. The environment variable `QDBMDBGFD' specifies the file descriptor to output the history of updating the variable `dpecode'.</p>
3411
3412 <p>The command `vltest' is a utility for facility test and performance test. Check a database generated by the command or measure the execution time of the command. This command is used in the following format. `name' specifies a database name. `rnum' specifies the number of the records.</p>
3413
3414 <dl>
3415 <dt><kbd>vltest write [-int] [-cz|-cy|-cx] [-tune <var>lrecmax</var> <var>nidxmax</var> <var>lcnum</var> <var>ncnum</var>] [-fbp <var>num</var>] <var>name</var> <var>rnum</var></kbd></dt>
3416 <dd>Store records with keys of 8 bytes. They change as `00000001', `00000002'...</dd>
3417 <dt><kbd>vltest read [-int] [-vc] <var>name</var></kbd></dt>
3418 <dd>Retrieve all records of the database above.</dd>
3419 <dt><kbd>vltest rdup [-int] [-cz|-cy|-cx] [-cc] [-tune <var>lrecmax</var> <var>nidxmax</var> <var>lcnum</var> <var>ncnum</var>] [-fbp <var>num</var>] <var>name</var> <var>rnum</var> <var>pnum</var></kbd></dt>
3420 <dd>Store records with partway duplicated keys using duplicate mode.</dd>
3421 <dt><kbd>vltest combo [-cz|-cy|-cx] <var>name</var></kbd></dt>
3422 <dd>Perform combination test of various operations.</dd>
3423 <dt><kbd>vltest wicked [-cz|-cy|-cx] <var>name</var> <var>rnum</var></kbd></dt>
3424 <dd>Perform updating operations selected at random.</dd>
3425 </dl>
3426
3427 <p>Options feature the following.</p>
3428
3429 <ul class="lines">
3430 <li><kbd>-int</kbd> : treat keys and values as objects of `int', and use comparing function `VL_CMPINT'.</li>
3431 <li><kbd>-cz</kbd> : compress leaves in the database with ZLIB.</li>
3432 <li><kbd>-cy</kbd> : compress leaves in the database with LZO.</li>
3433 <li><kbd>-cx</kbd> : compress leaves in the database with BZIP2.</li>
3434 <li><kbd>-vc</kbd> : refer to volatile cache.</li>
3435 <li><kbd>-cc</kbd> : select `VL_DCAT' or `VL_DDUP' at random.</li>
3436 <li><kbd>-tune <var>lrecmax</var> <var>nidxmax</var> <var>lcnum</var> <var>ncnum</var></kbd> : set tuning parameters.</li>
3437 <li><kbd>-fbp <var>num</var></kbd> : set the size of the free block pool.</li>
3438 <li><kbd>-c</kbd> : perform comparison test with map of Cabin.</li>
3439 </ul>
3440
3441 <p>This command returns 0 on success, another on failure. The environment variable `QDBMDBGFD' specifies the file descriptor to output the history of updating the variable `dpecode'.</p>
3442
3443 <p>The command `vltsv' features mutual conversion between a database of Villa and a TSV text. This command is useful when data exchange with another version of QDBM or another DBM, or when data exchange between systems which have different byte orders. This command is used in the following format. `name' specifies a database name. The subcommand `export' reads TSV data from the standard input. The subcommand `import' writes TSV data to the standard output.</p>
3444
3445 <dl>
3446 <dt><kbd>vltsv import [-bin] <var>name</var></kbd></dt>
3447 <dd>Create a database from TSV.</dd>
3448 <dt><kbd>vltsv export [-bin] <var>name</var></kbd></dt>
3449 <dd>Write TSV data of a database.</dd>
3450 </dl>
3451
3452 <p>Options feature the following.</p>
3453
3454 <ul class="lines">
3455 <li><kbd>-bin</kbd> : treat records as Base64 format.</li>
3456 </ul>
3457
3458 <p>This command returns 0 on success, another on failure.</p>
3459
3460 <p>Commands of Villa realize a simple database system. For example, to make a database to search `/etc/password' by a user name, perform the following command.</p>
3461
3462 <pre>cat /etc/passwd | tr ':' '\t' | vltsv import casket
3463 </pre>
3464
3465 <p>Thus, to retrieve the information of a user `mikio', perform the following command.</p>
3466
3467 <pre>vlmgr get casket mikio
3468 </pre>
3469
3470 <p>It is easy to implement functions upsides with these commands, using the API of Villa.</p>
3471
3472 <p>The command `qmttest' checks multi-thread safety of Depot, Curia, and Villa. This command works with multi threads only if QDBM was built with POSIX thread. This command is used in the following format. `name' specifies the prefix of each database. `rnum' specifies the number of records to be stored in each database. `tnum' specifies the number of threads.</p>
3473
3474 <dl>
3475 <dt><kbd>qmttest <var>name</var> <var>rnum</var> <var>tnum</var></kbd></dt>
3476 <dd>Check multi-thread safety.</dd>
3477 </dl>
3478
3479 <p>This command returns 0 on success, another on failure.</p>
3480
3481 <hr />
3482
3483 <h2><a name="odeumapi" id="odeumapi" class="head">Odeum: Inverted API</a></h2>
3484
3485 <h3>Overview</h3>
3486
3487 <p>Odeum is the API which handles an inverted index. An inverted index is a data structure to retrieve a list of some documents that include one of words which were extracted from a population of documents. It is easy to realize a full-text search system with an inverted index. Odeum provides an abstract data structure which consists of words and attributes of a document. It is used when an application stores a document into a database and when an application retrieves some documents from a database.</p>
3488
3489 <p>Odeum does not provide methods to extract the text from the original data of a document. It should be implemented by applications. Although Odeum provides utilities to extract words from a text, it is oriented to such languages whose words are separated with space characters as English. If an application handles such languages which need morphological analysis or N-gram analysis as Japanese, or if an application perform more such rarefied analysis of natural languages as stemming, its own analyzing method can be adopted. Result of search is expressed as an array contains elements which are structures composed of the ID number of documents and its score. In order to search with two or more words, Odeum provides utilities of set operations.</p>
3490
3491 <p>Odeum is implemented, based on Curia, Cabin, and Villa. Odeum creates a database with a directory name. Some databases of Curia and Villa are placed in the specified directory. For example, `casket/docs', `casket/index', and `casket/rdocs' are created in the case that a database directory named as `casket'. `docs' is a database directory of Curia. The key of each record is the ID number of a document, and the value is such attributes as URI. `index' is a database directory of Curia. The key of each record is the normalized form of a word, and the value is an array whose element is a pair of the ID number of a document including the word and its score. `rdocs' is a database file of Villa. The key of each record is the URI of a document, and the value is its ID number.</p>
3492
3493 <p>In order to use Odeum, you should include `depot.h', `cabin.h', `odeum.h' and `stdlib.h' in the source files. Usually, the following description will be near the beginning of a source file.</p>
3494
3495 <dl>
3496 <dt><kbd>#include &lt;depot.h&gt;</kbd></dt>
3497 <dt><kbd>#include &lt;cabin.h&gt;</kbd></dt>
3498 <dt><kbd>#include &lt;odeum.h&gt;</kbd></dt>
3499 <dt><kbd>#include &lt;stdlib.h&gt;</kbd></dt>
3500 </dl>
3501
3502 <p>A pointer to `ODEUM' is used as a database handle. A database handle is opened with the function `odopen' and closed with `odclose'. You should not refer directly to any member of the handle. If a fatal error occurs in a database, any access method via the handle except `odclose' will not work and return error status. Although a process is allowed to use multiple database handles at the same time, handles of the same database file should not be used.</p>
3503
3504 <p>A pointer to `ODDOC' is used as a document handle. A document handle is opened with the function `oddocopen' and closed with `oddocclose'. You should not refer directly to any member of the handle. A document consists of attributes and words. Each word is expressed as a pair of a normalized form and a appearance form.</p>
3505
3506 <p>Odeum also assign the external variable `dpecode' with the error code. The function `dperrmsg' is used in order to get the message of the error code.</p>
3507
3508 <h3>API</h3>
3509
3510 <p>Structures of `ODPAIR' type is used in order to handle results of search.</p>
3511
3512 <dl>
3513 <dt><kbd>typedef struct { int id; int score; } ODPAIR;</kbd></dt>
3514 <dd>`id' specifies the ID number of a document. `score' specifies the score calculated from the number of searching words in the document.</dd>
3515 </dl>
3516
3517 <p>The function `odopen' is used in order to get a database handle.</p>
3518
3519 <dl>
3520 <dt><kbd>ODEUM *odopen(const char *<var>name</var>, int <var>omode</var>);</kbd></dt>
3521 <dd>`name' specifies the name of a database directory. `omode' specifies the connection mode: `OD_OWRITER' as a writer, `OD_OREADER' as a reader. If the mode is `OD_OWRITER', the following may be added by bitwise or: `OD_OCREAT', which means it creates a new database if not exist, `OD_OTRUNC', which means it creates a new database regardless if one exists. Both of `OD_OREADER' and `OD_OWRITER' can be added to by bitwise or: `OD_ONOLCK', which means it opens a database directory without file locking, or `OD_OLCKNB', which means locking is performed without blocking. The return value is the database handle or `NULL' if it is not successful. While connecting as a writer, an exclusive lock is invoked to the database directory. While connecting as a reader, a shared lock is invoked to the database directory. The thread blocks until the lock is achieved. If `OD_ONOLCK' is used, the application is responsible for exclusion control.</dd>
3522 </dl>
3523
3524 <p>The function `odclose' is used in order to close a database handle.</p>
3525
3526 <dl>
3527 <dt><kbd>int odclose(ODEUM *<var>odeum</var>);</kbd></dt>
3528 <dd>`odeum' specifies a database handle. If successful, the return value is true, else, it is false. Because the region of a closed handle is released, it becomes impossible to use the handle. Updating a database is assured to be written when the handle is closed. If a writer opens a database but does not close it appropriately, the database will be broken.</dd>
3529 </dl>
3530
3531 <p>The function `odput' is used in order to store a document.</p>
3532
3533 <dl>
3534 <dt><kbd>int odput(ODEUM *<var>odeum</var>, const ODDOC *<var>doc</var>, int <var>wmax</var>, int <var>over</var>);</kbd></dt>
3535 <dd>`odeum' specifies a database handle connected as a writer. `doc' specifies a document handle. `wmax' specifies the max number of words to be stored in the document database. If it is negative, the number is unlimited. `over' specifies whether the data of the duplicated document is overwritten or not. If it is false and the URI of the document is duplicated, the function returns as an error. If successful, the return value is true, else, it is false.</dd>
3536 </dl>
3537
3538 <p>The function `odout' is used in order to delete a document specified by a URI.</p>
3539
3540 <dl>
3541 <dt><kbd>int odout(ODEUM *<var>odeum</var>, const char *<var>uri</var>);</kbd></dt>
3542 <dd>`odeum' specifies a database handle connected as a writer. `uri' specifies the string of the URI of a document. If successful, the return value is true, else, it is false. False is returned when no document corresponds to the specified URI.</dd>
3543 </dl>
3544
3545 <p>The function `odoutbyid' is used in order to delete a document specified by an ID number.</p>
3546
3547 <dl>
3548 <dt><kbd>int odoutbyid(ODEUM *<var>odeum</var>, int <var>id</var>);</kbd></dt>
3549 <dd>`odeum' specifies a database handle connected as a writer. `id' specifies the ID number of a document. If successful, the return value is true, else, it is false. False is returned when no document corresponds to the specified ID number.</dd>
3550 </dl>
3551
3552 <p>The function `odget' is used in order to retrieve a document specified by a URI.</p>
3553
3554 <dl>
3555 <dt><kbd>ODDOC *odget(ODEUM *<var>odeum</var>, const char *<var>uri</var>);</kbd></dt>
3556 <dd>`odeum' specifies a database handle. `uri' specifies the string of the URI of a document. If successful, the return value is the handle of the corresponding document, else, it is `NULL'. `NULL' is returned when no document corresponds to the specified URI. Because the handle of the return value is opened with the function `oddocopen', it should be closed with the function `oddocclose'.</dd>
3557 </dl>
3558
3559 <p>The function `odgetbyid' is used in order to retrieve a document by an ID number.</p>
3560
3561 <dl>
3562 <dt><kbd>ODDOC *odgetbyid(ODEUM *<var>odeum</var>, int <var>id</var>);</kbd></dt>
3563 <dd>`odeum' specifies a database handle. `id' specifies the ID number of a document. If successful, the return value is the handle of the corresponding document, else, it is `NULL'. `NULL' is returned when no document corresponds to the specified ID number. Because the handle of the return value is opened with the function `oddocopen', it should be closed with the function `oddocclose'.</dd>
3564 </dl>
3565
3566 <p>The function `odgetidbyuri' is used in order to retrieve the ID of the document specified by a URI.</p>
3567
3568 <dl>
3569 <dt><kbd>int odgetidbyuri(ODEUM *<var>odeum</var>, const char *<var>uri</var>);</kbd></dt>
3570 <dd>`odeum' specifies a database handle. `uri' specifies the string the URI of a document. If successful, the return value is the ID number of the document, else, it is -1. -1 is returned when no document corresponds to the specified URI.</dd>
3571 </dl>
3572
3573 <p>The function `odcheck' is used in order to check whether the document specified by an ID number exists.</p>
3574
3575 <dl>
3576 <dt><kbd>int odcheck(ODEUM *<var>odeum</var>, int <var>id</var>);</kbd></dt>
3577 <dd>`odeum' specifies a database handle. `id' specifies the ID number of a document. The return value is true if the document exists, else, it is false.</dd>
3578 </dl>
3579
3580 <p>The function `odsearch' is used in order to search the inverted index for documents including a particular word.</p>
3581
3582 <dl>
3583 <dt><kbd>ODPAIR *odsearch(ODEUM *<var>odeum</var>, const char *<var>word</var>, int <var>max</var>, int *<var>np</var>);</kbd></dt>
3584 <dd>`odeum' specifies a database handle. `word' specifies a searching word. `max' specifies the max number of documents to be retrieve. `np' specifies the pointer to a variable to which the number of the elements of the return value is assigned. If successful, the return value is the pointer to an array, else, it is `NULL'. Each element of the array is a pair of the ID number and the score of a document, and sorted in descending order of their scores. Even if no document corresponds to the specified word, it is not error but returns an dummy array. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. Note that each element of the array of the return value can be data of a deleted document.</dd>
3585 </dl>
3586
3587 <p>The function `odsearchnum' is used in order to get the number of documents including a word.</p>
3588
3589 <dl>
3590 <dt><kbd>int odsearchdnum(ODEUM *<var>odeum</var>, const char *<var>word</var>);</kbd></dt>
3591 <dd>`odeum' specifies a database handle. `word' specifies a searching word. If successful, the return value is the number of documents including the word, else, it is -1. Because this function does not read the entity of the inverted index, it is faster than `odsearch'.</dd>
3592 </dl>
3593
3594 <p>The function `oditerinit' is used in order to initialize the iterator of a database handle.</p>
3595
3596 <dl>
3597 <dt><kbd>int oditerinit(ODEUM *<var>odeum</var>);</kbd></dt>
3598 <dd>`odeum' specifies a database handle. If successful, the return value is true, else, it is false. The iterator is used in order to access every document stored in a database.</dd>
3599 </dl>
3600
3601 <p>The function `oditernext' is used in order to get the next key of the iterator.</p>
3602
3603 <dl>
3604 <dt><kbd>ODDOC *oditernext(ODEUM *<var>odeum</var>);</kbd></dt>
3605 <dd>`odeum' specifies a database handle. If successful, the return value is the handle of the next document, else, it is `NULL'. `NULL' is returned when no document is to be get out of the iterator. It is possible to access every document by iteration of calling this function. However, it is not assured if updating the database is occurred while the iteration. Besides, the order of this traversal access method is arbitrary, so it is not assured that the order of string matches the one of the traversal access. Because the handle of the return value is opened with the function `oddocopen', it should be closed with the function `oddocclose'.</dd>
3606 </dl>
3607
3608 <p>The function `odsync' is used in order to synchronize updating contents with the files and the devices.</p>
3609
3610 <dl>
3611 <dt><kbd>int odsync(ODEUM *<var>odeum</var>);</kbd></dt>
3612 <dd>`odeum' specifies a database handle connected as a writer. If successful, the return value is true, else, it is false. This function is useful when another process uses the connected database directory.</dd>
3613 </dl>
3614
3615 <p>The function `odoptimize' is used in order to optimize a database.</p>
3616
3617 <dl>
3618 <dt><kbd>int odoptimize(ODEUM *<var>odeum</var>);</kbd></dt>
3619 <dd>`odeum' specifies a database handle connected as a writer. If successful, the return value is true, else, it is false. Elements of the deleted documents in the inverted index are purged.</dd>
3620 </dl>
3621
3622 <p>The function `odname' is used in order to get the name of a database.</p>
3623
3624 <dl>
3625 <dt><kbd>char *odname(ODEUM *<var>odeum</var>);</kbd></dt>
3626 <dd>`odeum' specifies a database handle. If successful, the return value is the pointer to the region of the name of the database, else, it is `NULL'. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
3627 </dl>
3628
3629 <p>The function `odfsiz' is used in order to get the total size of database files.</p>
3630
3631 <dl>
3632 <dt><kbd>double odfsiz(ODEUM *<var>odeum</var>);</kbd></dt>
3633 <dd>`odeum' specifies a database handle. If successful, the return value is the total size of the database files, else, it is -1.0.</dd>
3634 </dl>
3635
3636 <p>The function `odbnum' is used in order to get the total number of the elements of the bucket arrays in the inverted index.</p>
3637
3638 <dl>
3639 <dt><kbd>int odbnum(ODEUM *<var>odeum</var>);</kbd></dt>
3640 <dd>`odeum' specifies a database handle. If successful, the return value is the total number of the elements of the bucket arrays, else, it is -1.</dd>
3641 </dl>
3642
3643 <p>The function `odbusenum' is used in order to get the total number of the used elements of the bucket arrays in the inverted index.</p>
3644
3645 <dl>
3646 <dt><kbd>int odbusenum(ODEUM *<var>odeum</var>);</kbd></dt>
3647 <dd>`odeum' specifies a database handle. If successful, the return value is the total number of the used elements of the bucket arrays, else, it is -1.</dd>
3648 </dl>
3649
3650 <p>The function `oddnum' is used in order to get the number of the documents stored in a database.</p>
3651
3652 <dl>
3653 <dt><kbd>int oddnum(ODEUM *<var>odeum</var>);</kbd></dt>
3654 <dd>`odeum' specifies a database handle. If successful, the return value is the number of the documents stored in the database, else, it is -1.</dd>
3655 </dl>
3656
3657 <p>The function `odwnum' is used in order to get the number of the words stored in a database.</p>
3658
3659 <dl>
3660 <dt><kbd>int odwnum(ODEUM *<var>odeum</var>);</kbd></dt>
3661 <dd>`odeum' specifies a database handle. If successful, the return value is the number of the words stored in the database, else, it is -1. Because of the I/O buffer, the return value may be less than the hard number.</dd>
3662 </dl>
3663
3664 <p>The function `odwritable' is used in order to check whether a database handle is a writer or not.</p>
3665
3666 <dl>
3667 <dt><kbd>int odwritable(ODEUM *<var>odeum</var>);</kbd></dt>
3668 <dd>`odeum' specifies a database handle. The return value is true if the handle is a writer, false if not.</dd>
3669 </dl>
3670
3671 <p>The function `odfatalerror' is used in order to check whether a database has a fatal error or not.</p>
3672
3673 <dl>
3674 <dt><kbd>int odfatalerror(ODEUM *<var>odeum</var>);</kbd></dt>
3675 <dd>`odeum' specifies a database handle. The return value is true if the database has a fatal error, false if not.</dd>
3676 </dl>
3677
3678 <p>The function `odinode' is used in order to get the inode number of a database directory.</p>
3679
3680 <dl>
3681 <dt><kbd>int odinode(ODEUM *<var>odeum</var>);</kbd></dt>
3682 <dd>`odeum' specifies a database handle. The return value is the inode number of the database directory.</dd>
3683 </dl>
3684
3685 <p>The function `odmtime' is used in order to get the last modified time of a database.</p>
3686
3687 <dl>
3688 <dt><kbd>time_t odmtime(ODEUM *<var>odeum</var>);</kbd></dt>
3689 <dd>`odeum' specifies a database handle. The return value is the last modified time of the database.</dd>
3690 </dl>
3691
3692 <p>The function `odmerge' is used in order to merge plural database directories.</p>
3693
3694 <dl>
3695 <dt><kbd>int odmerge(const char *<var>name</var>, const CBLIST *<var>elemnames</var>);</kbd></dt>
3696 <dd>`name' specifies the name of a database directory to create. `elemnames' specifies a list of names of element databases. If successful, the return value is true, else, it is false. If two or more documents which have the same URL come in, the first one is adopted and the others are ignored.</dd>
3697 </dl>
3698
3699 <p>The function `odremove' is used in order to remove a database directory.</p>
3700
3701 <dl>
3702 <dt><kbd>int odremove(const char *<var>name</var>);</kbd></dt>
3703 <dd>`name' specifies the name of a database directory. If successful, the return value is true, else, it is false. A database directory can contain databases of other APIs of QDBM, they are also removed by this function.</dd>
3704 </dl>
3705
3706 <p>The function `oddocopen' is used in order to get a document handle.</p>
3707
3708 <dl>
3709 <dt><kbd>ODDOC *oddocopen(const char *<var>uri</var>);</kbd></dt>
3710 <dd>`uri' specifies the URI of a document. The return value is a document handle. The ID number of a new document is not defined. It is defined when the document is stored in a database.</dd>
3711 </dl>
3712
3713 <p>The function `oddocclose' is used in order to close a document handle.</p>
3714
3715 <dl>
3716 <dt><kbd>void oddocclose(ODDOC *<var>doc</var>);</kbd></dt>
3717 <dd>`doc' specifies a document handle. Because the region of a closed handle is released, it becomes impossible to use the handle.</dd>
3718 </dl>
3719
3720 <p>The function `oddocaddattr' is used in order to add an attribute to a document.</p>
3721
3722 <dl>
3723 <dt><kbd>void oddocaddattr(ODDOC *<var>doc</var>, const char *<var>name</var>, const char *<var>value</var>);</kbd></dt>
3724 <dd>`doc' specifies a document handle. `name' specifies the string of the name of an attribute. `value' specifies the string of the value of the attribute.</dd>
3725 </dl>
3726
3727 <p>The function `oddocaddword' is used in order to add a word to a document.</p>
3728
3729 <dl>
3730 <dt><kbd>void oddocaddword(ODDOC *<var>doc</var>, const char *<var>normal</var>, const char *<var>asis</var>);</kbd></dt>
3731 <dd>`doc' specifies a document handle. `normal' specifies the string of the normalized form of a word. Normalized forms are treated as keys of the inverted index. If the normalized form of a word is an empty string, the word is not reflected in the inverted index. `asis' specifies the string of the appearance form of the word. Appearance forms are used after the document is retrieved by an application.</dd>
3732 </dl>
3733
3734 <p>The function `oddocid' is used in order to get the ID number of a document.</p>
3735
3736 <dl>
3737 <dt><kbd>int oddocid(const ODDOC *<var>doc</var>);</kbd></dt>
3738 <dd>`doc' specifies a document handle. The return value is the ID number of a document.</dd>
3739 </dl>
3740
3741 <p>The function `oddocuri' is used in order to get the URI of a document.</p>
3742
3743 <dl>
3744 <dt><kbd>const char *oddocuri(const ODDOC *<var>doc</var>);</kbd></dt>
3745 <dd>`doc' specifies a document handle. The return value is the string of the URI of a document.</dd>
3746 </dl>
3747
3748 <p>The function `oddocgetattr' is used in order to get the value of an attribute of a document.</p>
3749
3750 <dl>
3751 <dt><kbd>const char *oddocgetattr(const ODDOC *<var>doc</var>, const char *<var>name</var>);</kbd></dt>
3752 <dd>`doc' specifies a document handle. `name' specifies the string of the name of an attribute. The return value is the string of the value of the attribute, or `NULL' if no attribute corresponds.</dd>
3753 </dl>
3754
3755 <p>The function `oddocnwords' is used in order to get the list handle contains words in normalized form of a document.</p>
3756
3757 <dl>
3758 <dt><kbd>const CBLIST *oddocnwords(const ODDOC *<var>doc</var>);</kbd></dt>
3759 <dd>`doc' specifies a document handle. The return value is the list handle contains words in normalized form.</dd>
3760 </dl>
3761
3762 <p>The function `oddocawords' is used in order to get the list handle contains words in appearance form of a document.</p>
3763
3764 <dl>
3765 <dt><kbd>const CBLIST *oddocawords(const ODDOC *<var>doc</var>);</kbd></dt>
3766 <dd>`doc' specifies a document handle. The return value is the list handle contains words in appearance form.</dd>
3767 </dl>
3768
3769 <p>The function `oddocscores' is used in order to get the map handle contains keywords in normalized form and their scores.</p>
3770
3771 <dl>
3772 <dt><kbd>CBMAP *oddocscores(const ODDOC *<var>doc</var>, int <var>max</var>, ODEUM *<var>odeum</var>);</kbd></dt>
3773 <dd>`doc' specifies a document handle. `max' specifies the max number of keywords to get. `odeum' specifies a database handle with which the IDF for weighting is calculate. If it is `NULL', it is not used. The return value is the map handle contains keywords and their scores. Scores are expressed as decimal strings. Because the handle of the return value is opened with the function `cbmapopen', it should be closed with the function `cbmapclose' if it is no longer in use.</dd>
3774 </dl>
3775
3776 <p>The function `odbreaktext' is used in order to break a text into words in appearance form.</p>
3777
3778 <dl>
3779 <dt><kbd>CBLIST *odbreaktext(const char *<var>text</var>);</kbd></dt>
3780 <dd>`text' specifies the string of a text. The return value is the list handle contains words in appearance form. Words are separated with space characters and such delimiters as period, comma and so on. Because the handle of the return value is opened with the function `cblistopen', it should be closed with the function `cblistclose' if it is no longer in use.</dd>
3781 </dl>
3782
3783 <p>The function `odnormalizeword' is used in order to make the normalized form of a word.</p>
3784
3785 <dl>
3786 <dt><kbd>char *odnormalizeword(const char *<var>asis</var>);</kbd></dt>
3787 <dd>`asis' specifies the string of the appearance form of a word. The return value is is the string of the normalized form of the word. Alphabets of the ASCII code are unified into lower cases. Words composed of only delimiters are treated as empty strings. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
3788 </dl>
3789
3790 <p>The function `odpairsand' is used in order to get the common elements of two sets of documents.</p>
3791
3792 <dl>
3793 <dt><kbd>ODPAIR *odpairsand(ODPAIR *<var>apairs</var>, int <var>anum</var>, ODPAIR *<var>bpairs</var>, int <var>bnum</var>, int *<var>np</var>);</kbd></dt>
3794 <dd>`apairs' specifies the pointer to the former document array. `anum' specifies the number of the elements of the former document array. `bpairs' specifies the pointer to the latter document array. `bnum' specifies the number of the elements of the latter document array. `np' specifies the pointer to a variable to which the number of the elements of the return value is assigned. The return value is the pointer to a new document array whose elements commonly belong to the specified two sets. Elements of the array are sorted in descending order of their scores. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
3795 </dl>
3796
3797 <p>The function `odpairsor' is used in order to get the sum of elements of two sets of documents.</p>
3798
3799 <dl>
3800 <dt><kbd>ODPAIR *odpairsor(ODPAIR *<var>apairs</var>, int <var>anum</var>, ODPAIR *<var>bpairs</var>, int <var>bnum</var>, int *<var>np</var>);</kbd></dt>
3801 <dd>`apairs' specifies the pointer to the former document array. `anum' specifies the number of the elements of the former document array. `bpairs' specifies the pointer to the latter document array. `bnum' specifies the number of the elements of the latter document array. `np' specifies the pointer to a variable to which the number of the elements of the return value is assigned. The return value is the pointer to a new document array whose elements belong to both or either of the specified two sets. Elements of the array are sorted in descending order of their scores. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
3802 </dl>
3803
3804 <p>The function `odpairsnotand' is used in order to get the difference set of documents.</p>
3805
3806 <dl>
3807 <dt><kbd>ODPAIR *odpairsnotand(ODPAIR *<var>apairs</var>, int <var>anum</var>, ODPAIR *<var>bpairs</var>, int <var>bnum</var>, int *<var>np</var>);</kbd></dt>
3808 <dd>`apairs' specifies the pointer to the former document array. `anum' specifies the number of the elements of the former document array. `bpairs' specifies the pointer to the latter document array of the sum of elements. `bnum' specifies the number of the elements of the latter document array. `np' specifies the pointer to a variable to which the number of the elements of the return value is assigned. The return value is the pointer to a new document array whose elements belong to the former set but not to the latter set. Elements of the array are sorted in descending order of their scores. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use.</dd>
3809 </dl>
3810
3811 <p>The function `odpairssort' is used in order to sort a set of documents in descending order of scores.</p>
3812
3813 <dl>
3814 <dt><kbd>void odpairssort(ODPAIR *<var>pairs</var>, int <var>pnum</var>);</kbd></dt>
3815 <dd>`pairs' specifies the pointer to a document array. `pnum' specifies the number of the elements of the document array.</dd>
3816 </dl>
3817
3818 <p>The function `odlogarithm' is used in order to get the natural logarithm of a number.</p>
3819
3820 <dl>
3821 <dt><kbd>double odlogarithm(double <var>x</var>);</kbd></dt>
3822 <dd>`x' specifies a number. The return value is the natural logarithm of the number. If the number is equal to or less than 1.0, the return value is 0.0. This function is useful when an application calculates the IDF of search results.</dd>
3823 </dl>
3824
3825 <p>The function `odvectorcosine' is used in order to get the cosine of the angle of two vectors.</p>
3826
3827 <dl>
3828 <dt><kbd>double odvectorcosine(const int *<var>avec</var>, const int *<var>bvec</var>, int <var>vnum</var>);</kbd></dt>
3829 <dd>`avec' specifies the pointer to one array of numbers. `bvec' specifies the pointer to the other array of numbers. `vnum' specifies the number of elements of each array. The return value is the cosine of the angle of two vectors. This function is useful when an application calculates similarity of documents.</dd>
3830 </dl>
3831
3832 <p>The function `odsettuning' is used in order to set the global tuning parameters.</p>
3833
3834 <dl>
3835 <dt><kbd>void odsettuning(int <var>ibnum</var>, int <var>idnum</var>, int <var>cbnum</var>, int <var>csiz</var>);</kbd></dt>
3836 <dd>`ibnum' specifies the number of buckets for inverted indexes. `idnum' specifies the division number of inverted index. `cbnum' specifies the number of buckets for dirty buffers. `csiz' specifies the maximum bytes to use memory for dirty buffers. The default setting is equivalent to `odsettuning(32749, 7, 262139, 8388608)'. This function should be called before opening a handle.</dd>
3837 </dl>
3838
3839 <p>The function `odanalyzetext' is used in order to break a text into words and store appearance forms and normalized form into lists.</p>
3840
3841 <dl>
3842 <dt><kbd>void odanalyzetext(ODEUM *<var>odeum</var>, const char *<var>text</var>, CBLIST *<var>awords</var>, CBLIST *<var>nwords</var>);</kbd></dt>
3843 <dd>`odeum' specifies a database handle. `text' specifies the string of a text. `awords' specifies a list handle into which appearance form is store. `nwords' specifies a list handle into which normalized form is store. If it is `NULL', it is ignored. Words are separated with space characters and such delimiters as period, comma and so on.</dd>
3844 </dl>
3845
3846 <p>The function `odsetcharclass' is used in order to set the classes of characters used by `odanalyzetext'.</p>
3847
3848 <dl>
3849 <dt><kbd>void odsetcharclass(ODEUM *<var>odeum</var>, const char *<var>spacechars</var>, const char *<var>delimchars</var>, const char *<var>gluechars</var>);</kbd></dt>
3850 <dd>`odeum' specifies a database handle. `spacechars' spacifies a string contains space characters. `delimchars' spacifies a string contains delimiter characters. `gluechars' spacifies a string contains glue characters.</dd>
3851 </dl>
3852
3853 <p>The function `odquery' is used in order to query a database using a small boolean query language.</p>
3854
3855 <dl>
3856 <dt><kbd>ODPAIR *odquery(ODEUM *<var>odeum</var>, const char *<var>query</var>, int *<var>np</var>, CBLIST *<var>errors</var>);</kbd></dt>
3857 <dd>`odeum' specifies a database handle. 'query' specifies the text of the query. `np' specifies the pointer to a variable to which the number of the elements of the return value is assigned. `errors' specifies a list handle into which error messages are stored. If it is `NULL', it is ignored. If successful, the return value is the pointer to an array, else, it is `NULL'. Each element of the array is a pair of the ID number and the score of a document, and sorted in descending order of their scores. Even if no document corresponds to the specified condition, it is not error but returns an dummy array. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if it is no longer in use. Note that each element of the array of the return value can be data of a deleted document.</dd>
3858 </dl>
3859
3860 <h3>Examples</h3>
3861
3862 <p>The following example stores a document into the database.</p>
3863
3864 <pre>#include &lt;depot.h&gt;
3865 #include &lt;cabin.h&gt;
3866 #include &lt;odeum.h&gt;
3867 #include &lt;stdlib.h&gt;
3868 #include &lt;stdio.h&gt;
3869 #include &lt;string.h&gt;
3870
3871 #define DBNAME "index"
3872
3873 int main(int argc, char **argv){
3874 ODEUM *odeum;
3875 ODDOC *doc;
3876 CBLIST *awords;
3877 const char *asis;
3878 char *normal;
3879 int i;
3880
3881 /* open the database */
3882 if(!(odeum = odopen(DBNAME, OD_OWRITER | OD_OCREAT))){
3883 fprintf(stderr, "odopen: %s\n", dperrmsg(dpecode));
3884 return 1;
3885 }
3886
3887 /* get the document handle */
3888 doc = oddocopen("http://www.foo.bar/baz.txt");
3889
3890 /* set attributes of the document */
3891 oddocaddattr(doc, "title", "Balcony Scene");
3892 oddocaddattr(doc, "author", "Shakespeare");
3893
3894 /* break the text and get the word list */
3895 awords = odbreaktext("Parting is such sweet sorrow.");
3896
3897 /* set each word into the document handle */
3898 for(i = 0; i &lt; cblistnum(awords); i++){
3899 /* get one word of the list */
3900 asis = cblistval(awords, i, NULL);
3901 /* get the normalized form from the appearance form */
3902 normal = odnormalizeword(asis);
3903 /* add the word into the document handle */
3904 oddocaddword(doc, normal, asis);
3905 /* release the region of the normalized form */
3906 free(normal);
3907 }
3908
3909 /* store the document into the database */
3910 if(!odput(odeum, doc, -1, 1)){
3911 fprintf(stderr, "odput: %s\n", dperrmsg(dpecode));
3912 }
3913
3914 /* release the word list */
3915 cblistclose(awords);
3916
3917 /* release the document handle */
3918 oddocclose(doc);
3919
3920 /* close the database */
3921 if(!odclose(odeum)){
3922 fprintf(stderr, "odclose: %s\n", dperrmsg(dpecode));
3923 return 1;
3924 }
3925
3926 return 0;
3927 }
3928 </pre>
3929
3930 <p>The following example retrieves documents.</p>
3931
3932 <pre>#include &lt;depot.h&gt;
3933 #include &lt;cabin.h&gt;
3934 #include &lt;odeum.h&gt;
3935 #include &lt;stdlib.h&gt;
3936 #include &lt;stdio.h&gt;
3937 #include &lt;string.h&gt;
3938
3939 #define DBNAME "index"
3940
3941 int main(int argc, char **argv){
3942 ODEUM *odeum;
3943 ODPAIR *pairs;
3944 ODDOC *doc;
3945 const CBLIST *words;
3946 const char *title, *author, *asis;
3947 int i, j, pnum;
3948
3949 /* open the database */
3950 if(!(odeum = odopen(DBNAME, OD_OREADER))){
3951 fprintf(stderr, "odopen: %s\n", dperrmsg(dpecode));
3952 return 1;
3953 }
3954
3955 /* retrieve documents */
3956 if((pairs = odsearch(odeum, "sorrow", -1, &amp;pnum)) != NULL){
3957
3958 /* scan each element of the document array */
3959 for(i = 0; i &lt; pnum; i++){
3960 /* get the document handle */
3961 if(!(doc = odgetbyid(odeum, pairs[i].id))) continue;
3962 /* show the attributes */
3963 printf("URI: %s\n", oddocuri(doc));
3964 title = oddocgetattr(doc, "title");
3965 if(title) printf("TITLE: %s\n", title);
3966 author = oddocgetattr(doc, "author");
3967 if(author) printf("AUTHOR: %s\n", author);
3968 /* show words in appearance form */
3969 printf("WORDS:");
3970 words = oddocawords(doc);
3971 for(j = 0; j &lt; cblistnum(words); j++){
3972 asis = cblistval(words, j, NULL);
3973 printf(" %s", asis);
3974 }
3975 putchar('\n');
3976 /* release the document handle */
3977 oddocclose(doc);
3978 }
3979
3980 /* release the document array */
3981 free(pairs);
3982
3983 } else {
3984 fprintf(stderr, "odsearch: %s\n", dperrmsg(dpecode));
3985 }
3986
3987 /* close the database */
3988 if(!odclose(odeum)){
3989 fprintf(stderr, "odclose: %s\n", dperrmsg(dpecode));
3990 return 1;
3991 }
3992
3993 return 0;
3994 }
3995 </pre>
3996
3997 <h3>Notes</h3>
3998
3999 <p>How to build programs using Odeum is the same as the case of Depot.</p>
4000
4001 <pre>gcc -I/usr/local/include -o sample sample.c -L/usr/local/lib -lqdbm
4002 </pre>
4003
4004 <p>If QDBM was built with POSIX thread enabled, the global variable `dpecode' is treated as thread specific data, and functions of Odeum are reentrant. In that case, they are thread-safe as long as a handle is not accessed by threads at the same time, on the assumption that `errno', `malloc', and so on are thread-safe.</p>
4005
4006 <p>If QDBM was built with ZLIB enabled, records in the database for document attributes are compressed. In that case, the size of the database is reduced to 30% or less. Thus, you should enable ZLIB if you use Odeum. A database of Odeum created without ZLIB enabled is not available on environment with ZLIB enabled, and vice versa. If ZLIB was not enabled but LZO, LZO is used instead.</p>
4007
4008 <h3>Query Language</h3>
4009
4010 <p>The query language of the function `odquery' is a basic language following this grammar:</p>
4011
4012 <pre>expr ::= subexpr ( op subexpr )*
4013 subexpr ::= WORD
4014 subexpr ::= LPAREN expr RPAREN
4015 </pre>
4016
4017 <p>Operators are "&amp;" (AND), "|" (OR), and "!" (NOTAND). You can use parenthesis to group sub-expressions together in order to change order of operations. The given query is broken up using the function `odanalyzetext', so if you want to specify different text breaking rules, then make sure that you at least set "&amp;", "|", "!", "(", and ")" to be delimiter characters. Consecutive words are treated as having an implicit "&amp;" operator between them, so "zed shaw" is actually "zed &amp; shaw".</p>
4018
4019 <p>The encoding of the query text should be the same with the encoding of target documents. Moreover, each of space characters, delimiter characters, and glue characters should be single byte.</p>
4020
4021 <hr />
4022
4023 <h2><a name="odeumcli" id="odeumcli" class="head">Commands for Odeum</a></h2>
4024
4025 <p>Odeum has the following command line interfaces.</p>
4026
4027 <p>The command `odmgr' is a utility for debugging Odeum and its applications. It features editing and checking of a database. It can be used for full-text search systems with shell scripts. This command is used in the following format. `name' specifies a database name. `file' specifies a file name, `expr' specifies the URI or the ID number of a document, `words' specifies searching words. `elems' specifies element databases.</p>
4028
4029 <dl>
4030 <dt><kbd>odmgr create <var>name</var></kbd></dt>
4031 <dd>Create a database file.</dd>
4032 <dt><kbd>odmgr put [-uri <var>str</var>] [-title <var>str</var>] [-author <var>str</var>] [-date <var>str</var>] [-wmax <var>num</var>] [-keep] <var>name</var> [<var>file</var>]</kbd></dt>
4033 <dd>Add a document by reading a file. If `file' is omitted, the standard input is read and URI is needed.</dd>
4034 <dt><kbd>odmgr out [-id] <var>name</var> <var>expr</var></kbd></dt>
4035 <dd>Delete a document specified by a URI.</dd>
4036 <dt><kbd>odmgr get [-id] [-t|-h] <var>name</var> <var>expr</var></kbd></dt>
4037 <dd>Show a document specified by a URI. The output is the ID number and the URI of a document, in tab separated format.</dd>
4038 <dt><kbd>odmgr search [-max <var>num</var>] [-or] [-idf] [-t|-h|-n] <var>name</var> <var>words</var>...</kbd></dt>
4039 <dd>Retrieve documents including specified words. The first line of the output is the total number of hits and each word with its number of hits, in tab separated format. The second line and below are the ID numbers and the scores of documents, in tab separated format.</dd>
4040 <dt><kbd>odmgr list [-t|-h] <var>name</var></kbd></dt>
4041 <dd>Show all documents in a database. Each line of the output is the ID number and the score of a document, in tab separated format.</dd>
4042 <dt><kbd>odmgr optimize <var>name</var></kbd></dt>
4043 <dd>Optimize a database.</dd>
4044 <dt><kbd>odmgr inform <var>name</var></kbd></dt>
4045 <dd>Output miscellaneous information.</dd>
4046 <dt><kbd>odmgr merge <var>name</var> <var>elems</var>...</kbd></dt>
4047 <dd>Merge plural databases.</dd>
4048 <dt><kbd>odmgr remove <var>name</var></kbd></dt>
4049 <dd>Remove a database directory.</dd>
4050 <dt><kbd>odmgr break [-h|-k|-s] [<var>file</var>]</kbd></dt>
4051 <dd>Read a file and output words in the text. Each line of the output is the appearance form and the normalized form of a word, in tab separated format.</dd>
4052 <dt><kbd>odmgr version</kbd></dt>
4053 <dd>Output version information of QDBM.</dd>
4054 </dl>
4055
4056 <p>Options feature the following.</p>
4057
4058 <ul class="lines">
4059 <li><kbd>-uri <var>str</var></kbd> : specify the URI of the document explicitly.</li>
4060 <li><kbd>-title <var>str</var></kbd> : specify the title of the document.</li>
4061 <li><kbd>-author <var>str</var></kbd> : specify the author of the document.</li>
4062 <li><kbd>-date <var>str</var></kbd> : specify the modified date of the document.</li>
4063 <li><kbd>-wmax <var>num</var></kbd> : specify the max number of words to be stored.</li>
4064 <li><kbd>-keep</kbd> : the storing mode is not to be overwrite.</li>
4065 <li><kbd>-id</kbd> : specify a document not by a URI but by an ID number.</li>
4066 <li><kbd>-t</kbd> : output the details of a document in tab separated format.</li>
4067 <li><kbd>-h</kbd> : output the details of a document in human-readable format.</li>
4068 <li><kbd>-k</kbd> : output keywords of a document.</li>
4069 <li><kbd>-s</kbd> : output summary of a document.</li>
4070 <li><kbd>-max <var>num</var></kbd> : specify the max number of documents of the output.</li>
4071 <li><kbd>-or</kbd> : perform OR search, nut AND search.</li>
4072 <li><kbd>-idf</kbd> : tune scores with IDF.</li>
4073 <li><kbd>-n</kbd> : show ID numbers and scores only.</li>
4074 </ul>
4075
4076 <p>This command returns 0 on success, another on failure. The environment variable `QDBMDBGFD' specifies the file descriptor to output the history of updating the variable `dpecode'.</p>
4077
4078 <p>The command `odtest' is a utility for facility test and performance test. Check a database generated by the command or measure the execution time of the command. This command is used in the following format. `name' specifies a database name. `dnum' specifies the number of the documents. `wnum' specifies the number of words per document. `pnum' specifies the number of patterns of words.</p>
4079
4080 <dl>
4081 <dt><kbd>odtest write [-tune <var>ibnum</var> <var>idnum</var> <var>cbnum</var> <var>csiz</var>] <var>name</var> <var>dnum</var> <var>wnum</var> <var>pnum</var></kbd></dt>
4082 <dd>Store documents with random attributes and random words.</dd>
4083 <dt><kbd>odtest read <var>name</var></kbd></dt>
4084 <dd>Retrieve all documents of the database above.</dd>
4085 <dt><kbd>odtest combo <var>name</var></kbd></dt>
4086 <dd>Perform combination test of various operations.</dd>
4087 <dt><kbd>odtest wicked <var>name</var> <var>dnum</var></kbd></dt>
4088 <dd>Perform updating operations selected at random.</dd>
4089 </dl>
4090
4091 <p>Options feature the following.</p>
4092
4093 <ul class="lines">
4094 <li><kbd>-tune <var>ibnum</var> <var>idnum</var> <var>cbnum</var> <var>csiz</var></kbd> : set tuning parameters.</li>
4095 </ul>
4096
4097 <p>This command returns 0 on success, another on failure. The environment variable `QDBMDBGFD' specifies the file descriptor to output the history of updating the variable `dpecode'.</p>
4098
4099 <p>The command `odidx' is a utility for indexing files on the local file system. This command is useful for a full-text search system of a Web site. Supported file format are plain text and HTML. Supported character encoding are US-ASCII and ISO-8859-1. The URI of each document is specified with the path of its file. Attributes named as `title' and `date' are given to each documents. When a document is already existing in the database, it is registered if its last modification time is newer, or it is ignored. Modification times are stored in the sub database `_mtime' in the main database directory. Score information are stored in the sub database `_score' in the main database directory. This command is used in the following format. `name' specifies a database name. `dir' specifies a directory name.</p>
4100
4101 <dl>
4102 <dt><kbd>odidx register [-l <var>file</var>] [-wmax <var>num</var>] [-tsuf <var>sufs</var>] [-hsuf <var>sufs</var>] <var>name</var> [<var>dir</var>]</kbd></dt>
4103 <dd>Register files in the specified directory. If `dir' is omitted, the current directory is specified.</dd>
4104 <dt><kbd>odidx relate <var>name</var></kbd></dt>
4105 <dd>Add score information for relational document search to each documents in the database.</dd>
4106 <dt><kbd>odidx purge <var>name</var></kbd></dt>
4107 <dd>Purge documents which are not existing on the local files system.</dd>
4108 </dl>
4109
4110 <p>Options feature the following.</p>
4111
4112 <ul class="lines">
4113 <li><kbd>-l <var>file</var></kbd> : read a file and get list of paths of files to register. If `-' is specified, the standard input is read.</li>
4114 <li><kbd>-wmax <var>num</var></kbd> : specify the max number of words to be stored in the document database.</li>
4115 <li><kbd>-tsuf <var>sufs</var></kbd> : specify suffixes of plain text files in comma separated format. The default is `-tsuf .txt,.text'.</li>
4116 <li><kbd>-hsuf <var>sufs</var></kbd> : specify suffixes of HTML files in comma separated format. The default is `-hsuf .html,.htm'.</li>
4117 </ul>
4118
4119 <p>This command returns 0 on success, another on failure.</p>
4120
4121 <p>Commands of Odeum make it easy to realize a full-text search system. For example, to register files which are under `/home/mikio' and whose suffix are `.txt', `.c', or `.h', perform the following command.</p>
4122
4123 <pre>odidx register -tsuf ".txt,.c,.h" -hsuf "" casket /home/mikio
4124 </pre>
4125
4126 <p>Thus, to retrieve documents which include `unix' and `posix' and show the top 8 terms, perform the following command.</p>
4127
4128 <pre>odmgr search -max 8 -h casket "unix posix"
4129 </pre>
4130
4131 <p>A database generated by `odidx' is available with the CGI script which is included in QDBM for full-text search.</p>
4132
4133 <hr />
4134
4135 <h2><a name="fileformat" id="fileformat" class="head">File Format</a></h2>
4136
4137 <h3>File Format of Depot</h3>
4138
4139 <p>The contents of a database file managed by Depot is divided roughly into the following three sections: the header section, the bucket section and the record section.</p>
4140
4141 <p>The header section places at the beginning of the file and its length is constant 48 bytes. The following information are stored in the header section.</p>
4142
4143 <ol>
4144 <li>magic number: from offset 0, contains "[DEPOT]\n\f" for big endian or "[depot]\n\f" for little endian.</li>
4145 <li>version number: decimal string of the version number of the library.</li>
4146 <li>flags for wrappers: from offset 16, type of `int'.</li>
4147 <li>file size: from offset 24, type of `int'.</li>
4148 <li>number of the bucket: from offset 32, type of `int'.</li>
4149 <li>number of records: from offset 40, type of `int'.</li>
4150 </ol>
4151
4152 <p>The bucket section places after the header section and its length is determined according to the number of the bucket. Each element of the bucket stores an offset of the root node of each separate chain.</p>
4153
4154 <p>The record section places after the bucket section and occupies to the end of the file. The element of the record section contains the following information.</p>
4155
4156 <ol>
4157 <li>flags: type of `int'.</li>
4158 <li>second hash value: type of `int'.</li>
4159 <li>size of the key: type of `int'.</li>
4160 <li>size of the value: type of `int'.</li>
4161 <li>size of the padding: type of `int'.</li>
4162 <li>offset of the left child: type of `int'.</li>
4163 <li>offset of the right child: type of `int'.</li>
4164 <li>entity of the key: serial bytes with variable length.</li>
4165 <li>entity of the value: serial bytes with variable length.</li>
4166 <li>padding data: void serial bytes with variable length.</li>
4167 </ol>
4168
4169 <h3>File Format of Villa</h3>
4170
4171 <p>Every data handled by Villa is stored in a database of Depot. Storing data is divided into meta data and logical pages. Logical pages can be classified into leaf nodes and non-leaf nodes. Meta data are such managing information as the number of records. Both of its key and its value are type of `int'. Leaf nodes hold records. Non-leaf nodes hold sparse index referring to pages.</p>
4172
4173 <p>Villa uses variable length numeric format (BER compression) to handle small natural number with frugal storage. A variable length numeric object is parsed from the top of the region and parsing ends at the byte of positive value. Each byte are evaluated as absolute value and calculated as little endian number based on the radix 128.</p>
4174
4175 <p>Record is logical unit of user data. Some records overlapping keys are shaped into one physical record. A Physical record is serialized in the following format.</p>
4176
4177 <ol>
4178 <li>size of the key: type of variable length number</li>
4179 <li>entity of the key: serial bytes with variable length</li>
4180 <li>number of values: type of variable length number</li>
4181 <li>list of values: serial bytes repeating the following expressions<ol>
4182 <li>size: type of variable length number</li>
4183 <li>entity of the key: serial bytes with variable length</li>
4184 </ol></li>
4185 </ol>
4186
4187 <p>Leaf node is physical unit to store a set of records. The key of a leaf node is its ID whose type is `int'. A leaf node is stored in a database of Depot with the following values. Its records are sorted in ascending order of each key.</p>
4188
4189 <ol>
4190 <li>ID of the previous leaf: type of variable length number</li>
4191 <li>ID of the next leaf: type of variable length number</li>
4192 <li>list of records: concatenation of serialized records</li>
4193 </ol>
4194
4195 <p>Index is logical unit of a pointer to search for pages. An index is serialized int the following format.</p>
4196
4197 <ol>
4198 <li>ID of the referring page: type of variable length number</li>
4199 <li>size of the key: type of variable length number</li>
4200 <li>entity of the key: serial bytes with variable length</li>
4201 </ol>
4202
4203 <p>Non-leaf node is physical unit to store a set of indexes. The key of a non-leaf node is its ID whose type is `int'. A non-leaf node is stored in a database of Depot with the following values. Its indexes are sorted in ascending order of each key.</p>
4204
4205 <ol>
4206 <li>ID of the first child node: type of variable length number</li>
4207 <li>list of indexes: concatenation of serialized indexes</li>
4208 </ol>
4209
4210 <h3>Notes</h3>
4211
4212 <p>Because the database file is not sparse, move, copy, unlink, ftp, and so on with the file are possible. Because Depot reads and writes data without normalization of byte order, it is impossible to share the same file between the environment with different byte order.</p>
4213
4214 <p>When you distribute a database file of Depot or Villa via network, the MIME type suggested to be `application/x-qdbm'. Suffix of the file name is suggested to be `.qdb'. When you distribute a database directory of Curia, you may convert the directory tree to an archive of such type as TAR.</p>
4215
4216 <p>For the command `file' to recognize database files, append the following expressions into `magic' file.</p>
4217
4218 <pre>0 string [DEPOT]\n\f QDBM, big endian
4219 &gt;12 string x \b, version=%s
4220 &gt;19 byte ^1 \b, Hash
4221 &gt;19 byte &amp;1 \b, B+ tree
4222 &gt;19 byte &amp;2 \b (deflated:ZLIB)
4223 &gt;19 byte &amp;4 \b (deflated:LZO)
4224 &gt;19 byte &amp;8 \b (deflated:BZIP2)
4225 &gt;24 belong x \b, filesize=%d
4226 &gt;32 belong x \b, buckets=%d
4227 &gt;40 belong x \b, records=%d
4228 0 string [depot]\n\f QDBM, little endian
4229 &gt;12 string x \b, version=%s
4230 &gt;16 byte ^1 \b, Hash
4231 &gt;16 byte &amp;1 \b, B+ tree
4232 &gt;16 byte &amp;2 \b (deflated:ZLIB)
4233 &gt;16 byte &amp;4 \b (deflated:LZO)
4234 &gt;16 byte &amp;8 \b (deflated:BZIP2)
4235 &gt;24 lelong x \b, filesize=%d
4236 &gt;32 lelong x \b, buckets=%d
4237 &gt;40 lelong x \b, records=%d
4238 </pre>
4239
4240 <hr />
4241
4242 <h2><a name="porting" id="porting" class="head">Porting</a></h2>
4243
4244 <p>One of the goal of QDBM is to work on all platforms which conform to POSIX. Even if some APIs are not implemented, QDBM should work. Moreover, it should be possible to build QDBM using compilers other than GCC. Porting to various platforms is performed to add a new `Makefile' or modify some parts of source files. As for APIs of C, some of the following files should be modified. Otherwise, you can create new files based on them.</p>
4245
4246 <ul class="lines">
4247 <li><kbd>Makefile.in</kbd> : base of `Makefile', used by `./configure'.</li>
4248 <li><kbd>myconf.h</kbd> : configuration of system dependency.</li>
4249 <li><kbd>depot.h</kbd> : header of the basic API.</li>
4250 <li><kbd>curia.h</kbd> : header of the extended API.</li>
4251 <li><kbd>relic.h</kbd> : header of the NDBM-compatible API.</li>
4252 <li><kbd>hovel.h</kbd> : header of the GDBM-compatible API.</li>
4253 <li><kbd>cabin.h</kbd> : header of the utility API.</li>
4254 <li><kbd>villa.h</kbd> : header of the advanced API.</li>
4255 <li><kbd>vista.h</kbd> : header of the extended advanced API.</li>
4256 <li><kbd>odeum.h</kbd> : header of the inverted API.</li>
4257 <li><kbd>myconf.c</kbd> : implementation of system dependency.</li>
4258 <li><kbd>depot.c</kbd> : implementation of the basic API.</li>
4259 <li><kbd>curia.c</kbd> : implementation of the extended API.</li>
4260 <li><kbd>relic.c</kbd> : implementation of the NDBM-compatible API.</li>
4261 <li><kbd>hovel.c</kbd> : implementation of the GDBM-compatible API.</li>
4262 <li><kbd>cabin.c</kbd> : implementation of the utility API.</li>
4263 <li><kbd>villa.c</kbd> : implementation of the advanced API.</li>
4264 <li><kbd>vista.c</kbd> : implementation of the extended advanced API.</li>
4265 <li><kbd>odeum.c</kbd> : implementation of the inverted API.</li>
4266 </ul>
4267
4268 <p>On platforms which do not support file locking with `fcntl' call, you should append `-DMYNOLOCK' to the macro `CFLAGS' defined in `Makefile'. In that case, you should consider another exclusion control. As with it, on platforms without `mmap' call, you should append `-DMYNOMMAP' to `CFLAGS'. As for `mmap', its emulation using `malloc' and so on is provided. If other system calls are not implemented, you should define emulation by modification of `myconf.h' and `myconf.c'.</p>
4269
4270 <p>Because POSIX thread is used in C++ API, it is impossible to port C++ API to platforms without the package. Because JNI is used in Java API, you should pay attention to location of the headers and libraries. Moreover, you should consider such type definitions as `long long' or `int64'. Because APIs of Perl and Ruby use building commands provided with each language system, you should be knowledgeable about their specifications.</p>
4271
4272 <hr />
4273
4274 <h2><a name="bugs" id="bugs" class="head">Bugs</a></h2>
4275
4276 <p>Each document of QDBM should be calibrated by native English speakers.</p>
4277
4278 <p>There is no such bug which are found but not fixed, as crash by segmentation fault, unexpected data vanishing, memory leak and so on.</p>
4279
4280 <p>If you find any bug, report it to the author, with the information of the version of QDBM, the operating system and the compiler.</p>
4281
4282 <p>Databases created with QDBM version 1.7.13 or earlier are not compatible to ones of the later versions.</p>
4283
4284 <hr />
4285
4286 <h2><a name="faq" id="faq" class="head">Frequently Asked Questions</a></h2>
4287
4288 <dl>
4289 <dt>Q. : Does QDBM support SQL?</dt>
4290 <dd>A. : No, it does not. QDBM is not a RDBMS (Relational Database Management System). If you want an embedded RDBMS, use SQLite and so on.</dd>
4291 <dt>Q. : After all, how different from GDBM (NDBM, SDBM, Berkeley DB)?</dt>
4292 <dd>A. : Processing speed is higher, a database file is smaller, API is simpler. A highly important thing is that efficiency in time and space is very good when records are frequently overwritten, so, scalability in practical use is high. Moreover, even when constructing such a large database that the number of storing record is more than one million, processing speed does not slowdown deathly, filesize does not grow extremely. However, because other DBM or DBMS may be more suitable in some cases, comparing performance and functionality by yourself is suggested.</dd>
4293 <dt>Q. : Which API should I use?</dt>
4294 <dd>A. : If you search for records as complete accord, try Depot. If the scale is large, try Curia. If you access records in some order, try Villa. If the scale is large, try Vista. If you pursue the greatest number of records, build QDBM with ZLIB or LZO enabled and use Vista.</dd>
4295 <dt>Q. : What is bibliography?</dt>
4296 <dd>A. : Algorithms of QDBM are mainly based on the descriptions in `Data Structures and Algorithms' by Aho et al and `Algorithms in C' by Sedgewick.</dd>
4297 <dt>Q. : Are there good sample codes for applications?</dt>
4298 <dd>A. : Refer to the source code of commands of each API. `dptsv.c', `crtsv.c' and `vltsv.c' are simplest.</dd>
4299 <dt>Q. : My database file has been broken. Why?</dt>
4300 <dd>A. : In most cases, the reason is that your application did not close the database on exit. No matter whether it is a demon process or a CGI script, any application should close handling databases when it exits. Moreover, we should remember that a process of CGI may be killed by SIGPIPE or SIGTERM.</dd>
4301 <dt>Q. : How robust are databases of QDBM?</dt>
4302 <dd>A. : QDBM does not assure absolute robustness. A database may be broken if your operating system crashes. Although transaction of Villa can save a database from crashes of applications, it is inadequate to crashes of operating systems. So, you should consider multiplexing of a database or backup system if you use QDBM for mission critical applications.</dd>
4303 <dt>Q: How should I use alignment of Depot and Curia?</dt>
4304 <dd>A: If your application repeats writing with overwrite or concatenate mode. Alignment saves the rapid growth of the size of the database file. Because the best suited size of alignment of each application is different, you should learn it by experiment. For the meantime, about 32 is suitable.</dd>
4305 <dt>Q. : How should I tune performance parameters of Villa?</dt>
4306 <dd>A. : If you perform mainly ordering access, `lrecmax' and `nidxmax' should be larger. If you perform mainly random access, they should be less. If RAM of your system is abundant, `lcnum' and `ncnum' should be increased in order to improve performance. If ZLIB, LZO, or BZIP2 is enabled, increase `lrecmax' and compression efficiency is improved.</dd>
4307 <dt>Q. : Which is the most preferable of ZLIB, LZO or BZIP2 for Villa?</dt>
4308 <dd>A. : BZIP2 has the best compression retio. LZO has the best compression speed. ZLIB takes a mean position of them. If you don't have any special reason, using ZLIB is suggested. However, if updating of the database is frequent, LZO is more preferable. If updating of the database is very infrequently, BZIP2 is more preferable. Note that the license of LZO is the GNU LGPL.</dd>
4309 <dt>Q. : What is `sparse file'?</dt>
4310 <dd>A. : It is a file where some holes are. `Hole' means a block where any data has never written in. If a file system supports sparse file, holes are not allocated into any physical storage. As for QDBM, if a database is created with such flags as DP_OSPARSE, the bucket array is not initialized and its blocks become holes. According to that mechanism, you can use greatly huge hash tables. However, its performance is strongly depends on the setting of the file system.</dd>
4311 <dt>Q. : Why Depot and Curia do not feature transaction?</dt>
4312 <dd>A. : If an application implements its own transaction, inner transaction of database is superfluous. You can implement transaction for application easily with hash map provided by Cabin.</dd>
4313 <dt>Q. : How should I tune the system for performance?</dt>
4314 <dd>A. : Install more RAM on your machine than the size of a database. Then, enlarge I/O buffer and cut down on flushing dirty buffers. File system is also important. On Linux, although EXT2 is usually fastest, EXT3 is faster in some cases. ReiserFS is okey. The other modes of EXT3 are very slow. About other file systems, you should learn them by experiment.</dd>
4315 <dt>Q. : Can I build QDBM using `cc' instead of `gcc'?</dt>
4316 <dd>A. : Yes. Try to build QDBM with `LTmakefile'.</dd>
4317 <dt>Q. : Can I build QDBM using Visual C++?</dt>
4318 <dd>A. : Yes. Use `VCmakefile' instead of `Makefile'.</dd>
4319 <dt>Q. : Can I use QDBM in other languages?</dt>
4320 <dd>A. : As for PHP, Scheme (Gauche), and OCaml, interfaces of QDBM have been released. If you need it for another language, try to turn it out.</dd>
4321 <dt>Q. : What does `QDBM' mean?</dt>
4322 <dd>A. : `QDBM' stands for `Quick Database Manager'. It means that processing speed is high, and that you can write applications quickly.</dd>
4323 </dl>
4324
4325 <hr />
4326
4327 <h2><a name="copying" id="copying" class="head">Copying</a></h2>
4328
4329 <p>QDBM is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License or any later version.</p>
4330
4331 <p>QDBM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.</p>
4332
4333 <p>You should have received a copy of the GNU Lesser General Public License along with QDBM (See the file `COPYING'); if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.</p>
4334
4335 <p>QDBM was written by Mikio Hirabayashi. You can contact the author by e-mail to `[email protected]'.</p>
4336
4337 <hr />
4338
4339 </body>
4340
4341 </html>
4342
4343 <!-- END OF FILE -->