home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume26 / db-1.6 / part05 < prev    next >
Encoding:
Text File  |  1993-07-05  |  84.3 KB  |  2,810 lines

  1. Newsgroups: comp.sources.unix
  2. From: bostic@cs.berkeley.edu (Keith Bostic)
  3. Subject: v26i284: db-1.6 - A New Hashing Package for UNIX(tm) (updates dbm/ndbm), Part05/09
  4. Sender: unix-sources-moderator@gw.home.vix.com
  5. Approved: vixie@gw.home.vix.com
  6.  
  7. Submitted-By: bostic@cs.berkeley.edu (Keith Bostic)
  8. Posting-Number: Volume 26, Issue 284
  9. Archive-Name: db-1.6/part05
  10.  
  11. #! /bin/sh
  12. # This is a shell archive.  Remove anything before this line, then unpack
  13. # it by saving it into a file and typing "sh file".  To overwrite existing
  14. # files, type "sh file -c".  You can also feed this as standard input via
  15. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  16. # will see the following message at the end:
  17. #        "End of archive 5 (of 9)."
  18. # Contents:  btree/btree.h doc/mpool.3.ps doc/recno.3.ps man/dbopen.3
  19. #   test/dbtest.c test/run.test
  20. # Wrapped by vixie@gw.home.vix.com on Mon Jul  5 15:27:26 1993
  21. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  22. if test -f 'btree/btree.h' -a "${1}" != "-c" ; then 
  23.   echo shar: Will not clobber existing file \"'btree/btree.h'\"
  24. else
  25. echo shar: Extracting \"'btree/btree.h'\" \(12888 characters\)
  26. sed "s/^X//" >'btree/btree.h' <<'END_OF_FILE'
  27. X/*-
  28. X * Copyright (c) 1991, 1993
  29. X *    The Regents of the University of California.  All rights reserved.
  30. X *
  31. X * This code is derived from software contributed to Berkeley by
  32. X * Mike Olson.
  33. X *
  34. X * Redistribution and use in source and binary forms, with or without
  35. X * modification, are permitted provided that the following conditions
  36. X * are met:
  37. X * 1. Redistributions of source code must retain the above copyright
  38. X *    notice, this list of conditions and the following disclaimer.
  39. X * 2. Redistributions in binary form must reproduce the above copyright
  40. X *    notice, this list of conditions and the following disclaimer in the
  41. X *    documentation and/or other materials provided with the distribution.
  42. X * 3. All advertising materials mentioning features or use of this software
  43. X *    must display the following acknowledgement:
  44. X *    This product includes software developed by the University of
  45. X *    California, Berkeley and its contributors.
  46. X * 4. Neither the name of the University nor the names of its contributors
  47. X *    may be used to endorse or promote products derived from this software
  48. X *    without specific prior written permission.
  49. X *
  50. X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  51. X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  52. X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  53. X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  54. X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  55. X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  56. X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  57. X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  58. X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  59. X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  60. X * SUCH DAMAGE.
  61. X *
  62. X *    @(#)btree.h    8.1 (Berkeley) 6/4/93
  63. X */
  64. X
  65. X#include <mpool.h>
  66. X
  67. X#define    DEFMINKEYPAGE    (2)        /* Minimum keys per page */
  68. X#define    MINCACHE    (5)        /* Minimum cached pages */
  69. X#define    MINPSIZE    (512)        /* Minimum page size */
  70. X
  71. X/*
  72. X * Page 0 of a btree file contains a copy of the meta-data.  This page is also
  73. X * used as an out-of-band page, i.e. page pointers that point to nowhere point
  74. X * to page 0.  Page 1 is the root of the btree.
  75. X */
  76. X#define    P_INVALID     0        /* Invalid tree page number. */
  77. X#define    P_META         0        /* Tree metadata page number. */
  78. X#define    P_ROOT         1        /* Tree root page number. */
  79. X
  80. X/*
  81. X * There are five page layouts in the btree: btree internal pages (BINTERNAL),
  82. X * btree leaf pages (BLEAF), recno internal pages (RINTERNAL), recno leaf pages
  83. X * (RLEAF) and overflow pages.  All five page types have a page header (PAGE).
  84. X * This implementation requires that longs within structures are NOT padded.
  85. X * (ANSI C permits random padding.)  If your compiler pads randomly you'll have
  86. X * to do some work to get this package to run.
  87. X */
  88. Xtypedef struct PAGE {
  89. X    pgno_t    pgno;            /* this page's page number */
  90. X    pgno_t    prevpg;            /* left sibling */
  91. X    pgno_t    nextpg;            /* right sibling */
  92. X
  93. X#define    P_BINTERNAL    0x01        /* btree internal page */
  94. X#define    P_BLEAF        0x02        /* leaf page */
  95. X#define    P_OVERFLOW    0x04        /* overflow page */
  96. X#define    P_RINTERNAL    0x08        /* recno internal page */
  97. X#define    P_RLEAF        0x10        /* leaf page */
  98. X#define P_TYPE        0x1f        /* type mask */
  99. X
  100. X#define    P_PRESERVE    0x20        /* never delete this chain of pages */
  101. X    u_long    flags;
  102. X
  103. X    indx_t    lower;            /* lower bound of free space on page */
  104. X    indx_t    upper;            /* upper bound of free space on page */
  105. X    indx_t    linp[1];        /* long-aligned VARIABLE LENGTH DATA */
  106. X} PAGE;
  107. X
  108. X/* First and next index. */
  109. X#define    BTDATAOFF    (sizeof(pgno_t) + sizeof(pgno_t) + sizeof(pgno_t) + \
  110. X                sizeof(u_long) + sizeof(indx_t) + sizeof(indx_t))
  111. X#define    NEXTINDEX(p)    (((p)->lower - BTDATAOFF) / sizeof(indx_t))
  112. X
  113. X/*
  114. X * For pages other than overflow pages, there is an array of offsets into the
  115. X * rest of the page immediately following the page header.  Each offset is to
  116. X * an item which is unique to the type of page.  The h_lower offset is just
  117. X * past the last filled-in index.  The h_upper offset is the first item on the
  118. X * page.  Offsets are from the beginning of the page.
  119. X *
  120. X * If an item is too big to store on a single page, a flag is set and the item
  121. X * is a { page, size } pair such that the page is the first page of an overflow
  122. X * chain with size bytes of item.  Overflow pages are simply bytes without any
  123. X * external structure.
  124. X *
  125. X * The size and page number fields in the items are long aligned so they can be
  126. X * manipulated without copying.
  127. X */
  128. X#define    LALIGN(n)    (((n) + sizeof(u_long) - 1) & ~(sizeof(u_long) - 1))
  129. X#define    NOVFLSIZE    (sizeof(pgno_t) + sizeof(size_t))
  130. X
  131. X/*
  132. X * For the btree internal pages, the item is a key.  BINTERNALs are {key, pgno}
  133. X * pairs, such that the key compares less than or equal to all of the records
  134. X * on that page.  For a tree without duplicate keys, an internal page with two
  135. X * consecutive keys, a and b, will have all records greater than or equal to a
  136. X * and less than b stored on the page associated with a.  Duplicate keys are
  137. X * somewhat special and can cause duplicate internal and leaf page records and
  138. X * some minor modifications of the above rule.
  139. X */
  140. Xtypedef struct BINTERNAL {
  141. X    size_t    ksize;            /* key size */
  142. X    pgno_t    pgno;            /* page number stored on */
  143. X#define    P_BIGDATA    0x01        /* overflow data */
  144. X#define    P_BIGKEY    0x02        /* overflow key */
  145. X    u_char    flags;
  146. X    char    bytes[1];        /* data */
  147. X} BINTERNAL;
  148. X
  149. X/* Get the page's BINTERNAL structure at index indx. */
  150. X#define    GETBINTERNAL(pg, indx) \
  151. X    ((BINTERNAL *)((char *)(pg) + (pg)->linp[indx]))
  152. X
  153. X/* Get the number of bytes in the entry. */
  154. X#define NBINTERNAL(len) \
  155. X    LALIGN(sizeof(size_t) + sizeof(pgno_t) + sizeof(u_char) + (len))
  156. X
  157. X/* Copy a BINTERNAL entry to the page. */
  158. X#define    WR_BINTERNAL(p, size, pgno, flags) { \
  159. X    *(size_t *)p = size; \
  160. X    p += sizeof(size_t); \
  161. X    *(pgno_t *)p = pgno; \
  162. X    p += sizeof(pgno_t); \
  163. X    *(u_char *)p = flags; \
  164. X    p += sizeof(u_char); \
  165. X}
  166. X
  167. X/*
  168. X * For the recno internal pages, the item is a page number with the number of
  169. X * keys found on that page and below.
  170. X */
  171. Xtypedef struct RINTERNAL {
  172. X    recno_t    nrecs;            /* number of records */
  173. X    pgno_t    pgno;            /* page number stored below */
  174. X} RINTERNAL;
  175. X
  176. X/* Get the page's RINTERNAL structure at index indx. */
  177. X#define    GETRINTERNAL(pg, indx) \
  178. X    ((RINTERNAL *)((char *)(pg) + (pg)->linp[indx]))
  179. X
  180. X/* Get the number of bytes in the entry. */
  181. X#define NRINTERNAL \
  182. X    LALIGN(sizeof(recno_t) + sizeof(pgno_t))
  183. X
  184. X/* Copy a RINTERAL entry to the page. */
  185. X#define    WR_RINTERNAL(p, nrecs, pgno) { \
  186. X    *(recno_t *)p = nrecs; \
  187. X    p += sizeof(recno_t); \
  188. X    *(pgno_t *)p = pgno; \
  189. X}
  190. X
  191. X/* For the btree leaf pages, the item is a key and data pair. */
  192. Xtypedef struct BLEAF {
  193. X    size_t    ksize;            /* size of key */
  194. X    size_t    dsize;            /* size of data */
  195. X    u_char    flags;            /* P_BIGDATA, P_BIGKEY */
  196. X    char    bytes[1];        /* data */
  197. X} BLEAF;
  198. X
  199. X/* Get the page's BLEAF structure at index indx. */
  200. X#define    GETBLEAF(pg, indx) \
  201. X    ((BLEAF *)((char *)(pg) + (pg)->linp[indx]))
  202. X
  203. X/* Get the number of bytes in the entry. */
  204. X#define NBLEAF(p)    NBLEAFDBT((p)->ksize, (p)->dsize)
  205. X
  206. X/* Get the number of bytes in the user's key/data pair. */
  207. X#define NBLEAFDBT(ksize, dsize) \
  208. X    LALIGN(sizeof(size_t) + sizeof(size_t) + sizeof(u_char) + \
  209. X        (ksize) + (dsize))
  210. X
  211. X/* Copy a BLEAF entry to the page. */
  212. X#define    WR_BLEAF(p, key, data, flags) { \
  213. X    *(size_t *)p = key->size; \
  214. X    p += sizeof(size_t); \
  215. X    *(size_t *)p = data->size; \
  216. X    p += sizeof(size_t); \
  217. X    *(u_char *)p = flags; \
  218. X    p += sizeof(u_char); \
  219. X    memmove(p, key->data, key->size); \
  220. X    p += key->size; \
  221. X    memmove(p, data->data, data->size); \
  222. X}
  223. X
  224. X/* For the recno leaf pages, the item is a data entry. */
  225. Xtypedef struct RLEAF {
  226. X    size_t    dsize;            /* size of data */
  227. X    u_char    flags;            /* P_BIGDATA */
  228. X    char    bytes[1];
  229. X} RLEAF;
  230. X
  231. X/* Get the page's RLEAF structure at index indx. */
  232. X#define    GETRLEAF(pg, indx) \
  233. X    ((RLEAF *)((char *)(pg) + (pg)->linp[indx]))
  234. X
  235. X/* Get the number of bytes in the entry. */
  236. X#define NRLEAF(p)    NRLEAFDBT((p)->dsize)
  237. X
  238. X/* Get the number of bytes from the user's data. */
  239. X#define    NRLEAFDBT(dsize) \
  240. X    LALIGN(sizeof(size_t) + sizeof(u_char) + (dsize))
  241. X
  242. X/* Copy a RLEAF entry to the page. */
  243. X#define    WR_RLEAF(p, data, flags) { \
  244. X    *(size_t *)p = data->size; \
  245. X    p += sizeof(size_t); \
  246. X    *(u_char *)p = flags; \
  247. X    p += sizeof(u_char); \
  248. X    memmove(p, data->data, data->size); \
  249. X}
  250. X
  251. X/*
  252. X * A record in the tree is either a pointer to a page and an index in the page
  253. X * or a page number and an index.  These structures are used as a cursor, stack
  254. X * entry and search returns as well as to pass records to other routines.
  255. X *
  256. X * One comment about searches.  Internal page searches must find the largest
  257. X * record less than key in the tree so that descents work.  Leaf page searches
  258. X * must find the smallest record greater than key so that the returned index
  259. X * is the record's correct position for insertion.
  260. X *
  261. X * One comment about cursors.  The cursor key is never removed from the tree,
  262. X * even if deleted.  This is because it is quite difficult to decide where the
  263. X * cursor should be when other keys have been inserted/deleted in the tree;
  264. X * duplicate keys make it impossible.  This scheme does require extra work
  265. X * though, to make sure that we don't perform an operation on a deleted key.
  266. X */
  267. Xtypedef struct EPGNO {
  268. X    pgno_t    pgno;            /* the page number */
  269. X    indx_t    index;            /* the index on the page */
  270. X} EPGNO;
  271. X
  272. Xtypedef struct EPG {
  273. X    PAGE    *page;            /* the (pinned) page */
  274. X    indx_t     index;            /* the index on the page */
  275. X} EPG;
  276. X
  277. X/*
  278. X * The metadata of the tree.  The m_nrecs field is used only by the RECNO code.
  279. X * This is because the btree doesn't really need it and it requires that every
  280. X * put or delete call modify the metadata.
  281. X */
  282. Xtypedef struct BTMETA {
  283. X    u_long    m_magic;        /* magic number */
  284. X    u_long    m_version;        /* version */
  285. X    u_long    m_psize;        /* page size */
  286. X    u_long    m_free;            /* page number of first free page */
  287. X    u_long    m_nrecs;        /* R: number of records */
  288. X#define    SAVEMETA    (B_NODUPS | R_RECNO)
  289. X    u_long    m_flags;        /* bt_flags & SAVEMETA */
  290. X    u_long    m_unused;        /* unused */
  291. X} BTMETA;
  292. X
  293. X/* The in-memory btree/recno data structure. */
  294. Xtypedef struct BTREE {
  295. X    MPOOL    *bt_mp;            /* memory pool cookie */
  296. X
  297. X    DB    *bt_dbp;        /* pointer to enclosing DB */
  298. X
  299. X    EPGNO    bt_bcursor;        /* B: btree cursor */
  300. X    recno_t    bt_rcursor;        /* R: recno cursor (1-based) */
  301. X
  302. X#define    BT_POP(t)    (t->bt_sp ? t->bt_stack + --t->bt_sp : NULL)
  303. X#define    BT_CLR(t)    (t->bt_sp = 0)
  304. X    EPGNO    *bt_stack;        /* stack of parent pages */
  305. X    u_int    bt_sp;            /* current stack pointer */
  306. X    u_int    bt_maxstack;        /* largest stack */
  307. X
  308. X    char    *bt_kbuf;        /* key buffer */
  309. X    size_t    bt_kbufsz;        /* key buffer size */
  310. X    char    *bt_dbuf;        /* data buffer */
  311. X    size_t    bt_dbufsz;        /* data buffer size */
  312. X
  313. X    int    bt_fd;            /* tree file descriptor */
  314. X
  315. X    pgno_t    bt_free;        /* next free page */
  316. X    u_long    bt_psize;        /* page size */
  317. X    indx_t    bt_ovflsize;        /* cut-off for key/data overflow */
  318. X    int    bt_lorder;        /* byte order */
  319. X                    /* sorted order */
  320. X    enum { NOT, BACK, FORWARD, } bt_order;
  321. X    EPGNO    bt_last;        /* last insert */
  322. X
  323. X                    /* B: key comparison function */
  324. X    int    (*bt_cmp) __P((const DBT *, const DBT *));
  325. X                    /* B: prefix comparison function */
  326. X    int    (*bt_pfx) __P((const DBT *, const DBT *));
  327. X                    /* R: recno input function */
  328. X    int    (*bt_irec) __P((struct BTREE *, recno_t));
  329. X
  330. X    FILE    *bt_rfp;        /* R: record FILE pointer */
  331. X    int    bt_rfd;            /* R: record file descriptor */
  332. X
  333. X    caddr_t    bt_cmap;        /* R: current point in mapped space */
  334. X    caddr_t    bt_smap;        /* R: start of mapped space */
  335. X    caddr_t bt_emap;        /* R: end of mapped space */
  336. X    size_t    bt_msize;        /* R: size of mapped region. */
  337. X
  338. X    recno_t    bt_nrecs;        /* R: number of records */
  339. X    size_t    bt_reclen;        /* R: fixed record length */
  340. X    u_char    bt_bval;        /* R: delimiting byte/pad character */
  341. X
  342. X/*
  343. X * NB:
  344. X * B_NODUPS and R_RECNO are stored on disk, and may not be changed.
  345. X */
  346. X#define    B_DELCRSR    0x00001        /* cursor has been deleted */
  347. X#define    B_INMEM        0x00002        /* in-memory tree */
  348. X#define    B_METADIRTY    0x00004        /* need to write metadata */
  349. X#define    B_MODIFIED    0x00008        /* tree modified */
  350. X#define    B_NEEDSWAP    0x00010        /* if byte order requires swapping */
  351. X#define    B_NODUPS    0x00020        /* no duplicate keys permitted */
  352. X#define    B_RDONLY    0x00040        /* read-only tree */
  353. X#define    B_SEQINIT    0x00100        /* sequential scan initialized */
  354. X
  355. X#define    R_CLOSEFP    0x00200        /* opened a file pointer */
  356. X#define    R_EOF        0x00400        /* end of input file reached. */
  357. X#define    R_FIXLEN    0x00800        /* fixed length records */
  358. X#define    R_MEMMAPPED    0x01000        /* memory mapped file. */
  359. X#define    R_RECNO        0x00080        /* record oriented tree */
  360. X#define    R_INMEM        0x02000        /* in-memory file */
  361. X#define    R_MODIFIED    0x04000        /* modified file */
  362. X#define    R_RDONLY    0x08000        /* read-only file */
  363. X
  364. X    u_long        bt_flags;    /* btree state */
  365. X} BTREE;
  366. X
  367. X#define    SET(t, f)    ((t)->bt_flags |= (f))
  368. X#define    CLR(t, f)    ((t)->bt_flags &= ~(f))
  369. X#define    ISSET(t, f)    ((t)->bt_flags & (f))
  370. X
  371. X#include "extern.h"
  372. END_OF_FILE
  373. if test 12888 -ne `wc -c <'btree/btree.h'`; then
  374.     echo shar: \"'btree/btree.h'\" unpacked with wrong size!
  375. fi
  376. # end of 'btree/btree.h'
  377. fi
  378. if test -f 'doc/mpool.3.ps' -a "${1}" != "-c" ; then 
  379.   echo shar: Will not clobber existing file \"'doc/mpool.3.ps'\"
  380. else
  381. echo shar: Extracting \"'doc/mpool.3.ps'\" \(13311 characters\)
  382. sed "s/^X//" >'doc/mpool.3.ps' <<'END_OF_FILE'
  383. X%!PS-Adobe-3.0
  384. X%%Creator: groff version 1.08
  385. X%%DocumentNeededResources: font Times-Roman
  386. X%%+ font Times-Bold
  387. X%%+ font Times-Italic
  388. X%%DocumentSuppliedResources: procset grops 1.08 0
  389. X%%Pages: 2
  390. X%%PageOrder: Ascend
  391. X%%Orientation: Portrait
  392. X%%EndComments
  393. X%%BeginProlog
  394. X%%BeginResource: procset grops 1.08 0
  395. X/setpacking where{
  396. Xpop
  397. Xcurrentpacking
  398. Xtrue setpacking
  399. X}if
  400. X/grops 120 dict dup begin
  401. X/SC 32 def
  402. X/A/show load def
  403. X/B{0 SC 3 -1 roll widthshow}bind def
  404. X/C{0 exch ashow}bind def
  405. X/D{0 exch 0 SC 5 2 roll awidthshow}bind def
  406. X/E{0 rmoveto show}bind def
  407. X/F{0 rmoveto 0 SC 3 -1 roll widthshow}bind def
  408. X/G{0 rmoveto 0 exch ashow}bind def
  409. X/H{0 rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def
  410. X/I{0 exch rmoveto show}bind def
  411. X/J{0 exch rmoveto 0 SC 3 -1 roll widthshow}bind def
  412. X/K{0 exch rmoveto 0 exch ashow}bind def
  413. X/L{0 exch rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def
  414. X/M{rmoveto show}bind def
  415. X/N{rmoveto 0 SC 3 -1 roll widthshow}bind def
  416. X/O{rmoveto 0 exch ashow}bind def
  417. X/P{rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def
  418. X/Q{moveto show}bind def
  419. X/R{moveto 0 SC 3 -1 roll widthshow}bind def
  420. X/S{moveto 0 exch ashow}bind def
  421. X/T{moveto 0 exch 0 SC 5 2 roll awidthshow}bind def
  422. X/SF{
  423. Xfindfont exch
  424. X[exch dup 0 exch 0 exch neg 0 0]makefont
  425. Xdup setfont
  426. X[exch/setfont cvx]cvx bind def
  427. X}bind def
  428. X/MF{
  429. Xfindfont
  430. X[5 2 roll
  431. X0 3 1 roll 
  432. Xneg 0 0]makefont
  433. Xdup setfont
  434. X[exch/setfont cvx]cvx bind def
  435. X}bind def
  436. X/level0 0 def
  437. X/RES 0 def
  438. X/PL 0 def
  439. X/LS 0 def
  440. X/PLG{
  441. Xgsave newpath clippath pathbbox grestore
  442. Xexch pop add exch pop
  443. X}bind def
  444. X/BP{
  445. X/level0 save def
  446. X1 setlinecap
  447. X1 setlinejoin
  448. X72 RES div dup scale
  449. XLS{
  450. X90 rotate
  451. X}{
  452. X0 PL translate
  453. X}ifelse
  454. X1 -1 scale
  455. X}bind def
  456. X/EP{
  457. Xlevel0 restore
  458. Xshowpage
  459. X}bind def
  460. X/DA{
  461. Xnewpath arcn stroke
  462. X}bind def
  463. X/SN{
  464. Xtransform
  465. X.25 sub exch .25 sub exch
  466. Xround .25 add exch round .25 add exch
  467. Xitransform
  468. X}bind def
  469. X/DL{
  470. XSN
  471. Xmoveto
  472. XSN
  473. Xlineto stroke
  474. X}bind def
  475. X/DC{
  476. Xnewpath 0 360 arc closepath
  477. X}bind def
  478. X/TM matrix def
  479. X/DE{
  480. XTM currentmatrix pop
  481. Xtranslate scale newpath 0 0 .5 0 360 arc closepath
  482. XTM setmatrix
  483. X}bind def
  484. X/RC/rcurveto load def
  485. X/RL/rlineto load def
  486. X/ST/stroke load def
  487. X/MT/moveto load def
  488. X/CL/closepath load def
  489. X/FL{
  490. Xcurrentgray exch setgray fill setgray
  491. X}bind def
  492. X/BL/fill load def
  493. X/LW/setlinewidth load def
  494. X/RE{
  495. Xfindfont
  496. Xdup maxlength 1 index/FontName known not{1 add}if dict begin
  497. X{
  498. X1 index/FID ne{def}{pop pop}ifelse
  499. X}forall
  500. X/Encoding exch def
  501. Xdup/FontName exch def
  502. Xcurrentdict end definefont pop
  503. X}bind def
  504. X/DEFS 0 def
  505. X/EBEGIN{
  506. Xmoveto
  507. XDEFS begin
  508. X}bind def
  509. X/EEND/end load def
  510. X/CNT 0 def
  511. X/level1 0 def
  512. X/PBEGIN{
  513. X/level1 save def
  514. Xtranslate
  515. Xdiv 3 1 roll div exch scale
  516. Xneg exch neg exch translate
  517. X0 setgray
  518. X0 setlinecap
  519. X1 setlinewidth
  520. X0 setlinejoin
  521. X10 setmiterlimit
  522. X[]0 setdash
  523. X/setstrokeadjust where{
  524. Xpop
  525. Xfalse setstrokeadjust
  526. X}if
  527. X/setoverprint where{
  528. Xpop
  529. Xfalse setoverprint
  530. X}if
  531. Xnewpath
  532. X/CNT countdictstack def
  533. Xuserdict begin
  534. X/showpage{}def
  535. X}bind def
  536. X/PEND{
  537. Xclear
  538. Xcountdictstack CNT sub{end}repeat
  539. Xlevel1 restore
  540. X}bind def
  541. Xend def
  542. X/setpacking where{
  543. Xpop
  544. Xsetpacking
  545. X}if
  546. X%%EndResource
  547. X%%IncludeResource: font Times-Roman
  548. X%%IncludeResource: font Times-Bold
  549. X%%IncludeResource: font Times-Italic
  550. Xgrops begin/DEFS 1 dict def DEFS begin/u{.001 mul}bind def end/RES 72 def/PL
  551. X792 def/LS false def/ENC0[/asciicircum/asciitilde/Scaron/Zcaron/scaron/zcaron
  552. X/Ydieresis/trademark/quotesingle/.notdef/.notdef/.notdef/.notdef/.notdef
  553. X/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
  554. X/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/space
  555. X/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright/parenleft
  556. X/parenright/asterisk/plus/comma/hyphen/period/slash/zero/one/two/three/four
  557. X/five/six/seven/eight/nine/colon/semicolon/less/equal/greater/question/at/A/B/C
  558. X/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash
  559. X/bracketright/circumflex/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q
  560. X/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/tilde/.notdef/quotesinglbase
  561. X/guillemotleft/guillemotright/bullet/florin/fraction/perthousand/dagger
  562. X/daggerdbl/endash/emdash/ff/fi/fl/ffi/ffl/dotlessi/dotlessj/grave/hungarumlaut
  563. X/dotaccent/breve/caron/ring/ogonek/quotedblleft/quotedblright/oe/lslash
  564. X/quotedblbase/OE/Lslash/.notdef/exclamdown/cent/sterling/currency/yen/brokenbar
  565. X/section/dieresis/copyright/ordfeminine/guilsinglleft/logicalnot/minus
  566. X/registered/macron/degree/plusminus/twosuperior/threesuperior/acute/mu
  567. X/paragraph/periodcentered/cedilla/onesuperior/ordmasculine/guilsinglright
  568. X/onequarter/onehalf/threequarters/questiondown/Agrave/Aacute/Acircumflex/Atilde
  569. X/Adieresis/Aring/AE/Ccedilla/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute
  570. X/Icircumflex/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis
  571. X/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute/Thorn/germandbls
  572. X/agrave/aacute/acircumflex/atilde/adieresis/aring/ae/ccedilla/egrave/eacute
  573. X/ecircumflex/edieresis/igrave/iacute/icircumflex/idieresis/eth/ntilde/ograve
  574. X/oacute/ocircumflex/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex
  575. X/udieresis/yacute/thorn/ydieresis]def/Times-Italic@0 ENC0/Times-Italic RE
  576. X/Times-Bold@0 ENC0/Times-Bold RE/Times-Roman@0 ENC0/Times-Roman RE
  577. X%%EndProlog
  578. X%%Page: 1 1
  579. X%%BeginPageSetup
  580. XBP
  581. X%%EndPageSetup
  582. X/F0 10/Times-Roman@0 SF 174.84(MPOOL\(3\) 1991 MPOOL\(3\))72 48 R/F1 9
  583. X/Times-Bold@0 SF -.18(NA)72 84 S(ME).18 E F0(mpool \255 shared memory b)108 96
  584. XQ(uf)-.2 E(fer pool)-.25 E F1(SYNOPSIS)72 112.8 Q/F2 10/Times-Bold@0 SF
  585. X(#include <db)108 124.8 Q(.h>)-.4 E(#include <mpool.h>)108 136.8 Q(MPOOL *)108
  586. X160.8 Q(mpool_open \(DBT *k)108 172.8 Q(ey)-.1 E 2.5(,i)-.55 G
  587. X(nt fd, pgno_t pagesize, pgno_t maxcache\);)216.25 172.8 Q -.1(vo)108 196.8 S
  588. X(id).1 E(mpool_\214lter \(MPOOL *mp, v)108 208.8 Q(oid \(*pgin\)\(v)-.1 E
  589. X(oid *, pgno_t, v)-.1 E(oid *\),)-.1 E -.1(vo)158 220.8 S(id \(*pgout\)\(v).1 E
  590. X(oid *, pgno_t, v)-.1 E(oid *\), v)-.1 E(oid *pgcookie\);)-.1 E -.1(vo)108
  591. X244.8 S(id *).1 E(mpool_new \(MPOOL *mp, pgno_t *pgnoaddr\);)108 256.8 Q -.1
  592. X(vo)108 280.8 S(id *).1 E(mpool_get \(MPOOL *mp, pgno_t pgno, u_int \215ags\);)
  593. X108 292.8 Q(int)108 316.8 Q(mpool_put \(MPOOL *mp, v)108 328.8 Q(oid *pgaddr)
  594. X-.1 E 2.5(,u)-.92 G(_int \215ags\);)290.62 328.8 Q(int)108 352.8 Q
  595. X(mpool_sync \(MPOOL *mp\);)108 364.8 Q(int)108 388.8 Q
  596. X(mpool_close \(MPOOL *mp\);)108 400.8 Q F1(DESCRIPTION)72 417.6 Q/F3 10
  597. X/Times-Italic@0 SF(Mpool)108 429.6 Q F0 1.013(is the library interf)3.513 F
  598. X1.013(ace intended to pro)-.1 F 1.013(vide page oriented b)-.15 F(uf)-.2 E
  599. X1.012(fer management of \214les.)-.25 F 1.012(The b)6.012 F(uf)-.2 E(fers)-.25
  600. XE(may be shared between processes.)108 441.6 Q .416(The function)108 458.4 R F3
  601. X(mpool_open)2.916 E F0 .417(initializes a memory pool.)2.917 F(The)5.417 E F3
  602. X-.1(ke)2.917 G(y)-.2 E F0(ar)2.917 E .417(gument is the byte string used to ne)
  603. X-.18 F(gotiate)-.15 E .697(between multiple processes wishing to share b)108
  604. X470.4 R(uf)-.2 E 3.196(fers. If)-.25 F .696(the \214le b)3.196 F(uf)-.2 E .696
  605. X(fers are mapped in shared memory)-.25 F 3.196(,a)-.65 G(ll)534.44 470.4 Q .894
  606. X(processes using the same k)108 482.4 R 1.194 -.15(ey w)-.1 H .894
  607. X(ill share the b).15 F(uf)-.2 E 3.394(fers. If)-.25 F F3 -.1(ke)3.394 G(y)-.2 E
  608. XF0 .895(is NULL, the b)3.395 F(uf)-.2 E .895(fers are mapped into pri)-.25 F
  609. X-.25(va)-.25 G(te).25 E(memory)108 494.4 Q 5.116(.T)-.65 G(he)154.406 494.4 Q
  610. XF3(fd)2.616 E F0(ar)2.616 E .115(gument is a \214le descriptor for the underly\
  611. Xing \214le, which must be seekable.)-.18 F(If)5.115 E F3 -.1(ke)2.615 G(y)-.2 E
  612. XF0 .115(is non-)2.615 F(NULL and matches a \214le already being mapped, the)108
  613. X506.4 Q F3(fd)2.5 E F0(ar)2.5 E(gument is ignored.)-.18 E(The)108 523.2 Q F3
  614. X(pa)3.328 E -.1(ge)-.1 G(size).1 E F0(ar)3.329 E .829
  615. X(gument is the size, in bytes, of the pages into which the \214le is brok)-.18
  616. XF .829(en up.)-.1 F(The)5.829 E F3(maxcac)3.329 E(he)-.15 E F0(ar)108 535.2 Q
  617. X.153(gument is the maximum number of pages from the underlying \214le to cache\
  618. X at an)-.18 F 2.653(yo)-.15 G .153(ne time.)451.308 535.2 R .153(This v)5.153 F
  619. X.153(alue is)-.25 F .099(not relati)108 547.2 R .399 -.15(ve t)-.25 H 2.599(ot)
  620. X.15 G .099(he number of processes which share a \214le')168.727 547.2 R 2.6(sb)
  621. X-.55 G(uf)350.39 547.2 Q .1(fers, b)-.25 F .1(ut will be the lar)-.2 F .1
  622. X(gest v)-.18 F .1(alue speci\214ed by)-.25 F(an)108 559.2 Q 2.5(yo)-.15 G 2.5
  623. X(ft)129.79 559.2 S(he processes sharing the \214le.)138.4 559.2 Q(The)108 576 Q
  624. XF3(mpool_\214lter)3.254 E F0 .754(function is intended to mak)3.254 F 3.254(et)
  625. X-.1 G .754(ransparent input and output processing of the pages possi-)301.778
  626. X576 R 3.095(ble. If)108 588 R(the)3.095 E F3(pgin)3.095 E F0 .596
  627. X(function is speci\214ed, it is called each time a b)3.095 F(uf)-.2 E .596
  628. X(fer is read into the memory pool from the)-.25 F .125(backing \214le.)108 600
  629. XR .125(If the)5.125 F F3(pgout)2.625 E F0 .125
  630. X(function is speci\214ed, it is called each time a b)2.625 F(uf)-.2 E .125
  631. X(fer is written into the backing \214le.)-.25 F .276
  632. X(Both functions are are called with the)108 612 R F3(pgcookie)2.777 E F0
  633. X(pointer)2.777 E 2.777(,t)-.4 G .277
  634. X(he page number and a pointer to the page to being)337.27 612 R
  635. X(read or written.)108 624 Q .124(The function)108 640.8 R F3(mpool_ne)2.624 E
  636. X(w)-.15 E F0(tak)2.624 E .123(es an MPOOL pointer and an address as ar)-.1 F
  637. X2.623(guments. If)-.18 F 2.623(an)2.623 G .623 -.25(ew p)457.568 640.8 T .123
  638. X(age can be allo-).25 F .944(cated, a pointer to the page is returned and the \
  639. Xpage number is stored into the)108 652.8 R F3(pgnoaddr)3.445 E F0 3.445
  640. X(address. Other)3.445 F(-)-.2 E(wise, NULL is returned and errno is set.)108
  641. X664.8 Q 1.167(The function)108 681.6 R F3(mpool_g)3.667 E(et)-.1 E F0(tak)3.667
  642. XE 1.167(es a MPOOL pointer and a page number as ar)-.1 F 3.666(guments. If)-.18
  643. XF 1.166(the page e)3.666 F 1.166(xists, a)-.15 F .686
  644. X(pointer to the page is returned.)108 693.6 R .687
  645. X(Otherwise, NULL is returned and errno is set.)5.686 F .687
  646. X(The \215ags parameter is not)5.687 F(currently used.)108 705.6 Q 1.463
  647. X(The function)108 722.4 R F3(mpool_put)3.963 E F0 1.462
  648. X(unpins the page referenced by)3.962 F F3(pgaddr)3.962 E F0(.).73 E F3(Pgaddr)
  649. X6.462 E F0 1.462(must be an address pre)3.962 F(viously)-.25 E 197.615
  650. X(12, September)72 768 R(1)535 768 Q EP
  651. X%%Page: 2 2
  652. X%%BeginPageSetup
  653. XBP
  654. X%%EndPageSetup
  655. X/F0 10/Times-Roman@0 SF 174.84(MPOOL\(3\) 1991 MPOOL\(3\))72 48 R(returned by)
  656. X108 84 Q/F1 10/Times-Italic@0 SF(mpool_g)2.5 E(et)-.1 E F0(or)2.5 E F1
  657. X(mpool_ne)2.5 E(w)-.15 E F0 5(.T).31 G(he \215ag v)271.65 84 Q
  658. X(alue is speci\214ed by)-.25 E F1(or)2.5 E F0('ing an).73 E 2.5(yo)-.15 G 2.5
  659. X(ft)434.74 84 S(he follo)443.35 84 Q(wing v)-.25 E(alues:)-.25 E(MPOOL_DIR)108
  660. X100.8 Q(TY)-.6 E
  661. X(The page has been modi\214ed and needs to be written to the backing \214le.)
  662. X144 112.8 Q F1(Mpool_put)108 129.6 Q F0
  663. X(returns 0 on success and -1 if an error occurs.)2.5 E .247(The function)108
  664. X146.4 R F1(mpool_sync)2.747 E F0 .247(writes all modi\214ed pages associated w\
  665. Xith the MPOOL pointer to the backing \214le.)2.747 F F1(Mpool_sync)108 158.4 Q
  666. XF0(returns 0 on success and -1 if an error occurs.)2.5 E(The)108 175.2 Q F1
  667. X(mpool_close)2.698 E F0 .198(function free')2.698 F 2.698(su)-.55 G 2.698(pa)
  668. X245.432 175.2 S .498 -.15(ny a)257.57 175.2 T .198
  669. X(llocated memory associated with the memory pool cookie.).15 F(Modi-)5.197 E
  670. X(\214ed pages are)108 187.2 Q/F2 10/Times-Bold@0 SF(not)2.5 E F0
  671. X(written to the backing \214le.)2.5 E F1(Mpool_close)5 E F0
  672. X(returns 0 on success and -1 if an error occurs.)2.5 E/F3 9/Times-Bold@0 SF
  673. X(ERR)72 204 Q(ORS)-.27 E F0(The)108 216 Q F1(mpool_open)2.938 E F0 .438
  674. X(function may f)2.938 F .438(ail and set)-.1 F F1(errno)2.938 E F0 .438(for an)
  675. X2.938 F 2.938(yo)-.15 G 2.938(ft)344.87 216 S .439
  676. X(he errors speci\214ed for the library routine)353.918 216 R F1(mal-)2.939 E
  677. X(loc)108 228 Q F0(\(3\).).31 E(The)108 244.8 Q F1(mpool_g)2.5 E(et)-.1 E F0
  678. X(function may f)2.5 E(ail and set)-.1 E F1(errno)2.5 E F0(for the follo)2.5 E
  679. X(wing:)-.25 E([EINV)108 261.6 Q 29.98(AL] The)-1.35 F(requested record doesn')
  680. X2.5 E 2.5(te)-.18 G(xist.)305.96 261.6 Q(The)108 278.4 Q F1(mpool_ne)4.073 E(w)
  681. X-.15 E F0(and)4.073 E F1(mpool_g)4.073 E(et)-.1 E F0 1.573(functions may f)
  682. X4.073 F 1.573(ail and set)-.1 F F1(errno)4.073 E F0 1.573(for an)4.073 F 4.073
  683. X(yo)-.15 G 4.073(ft)421.336 278.4 S 1.573(he errors speci\214ed for the)431.519
  684. X278.4 R(library routines)108 290.4 Q F1 -.37(re)2.5 G(ad).37 E F0(\(2\)).77 E
  685. XF1 2.5(,w).54 G(rite)214.48 290.4 Q F0(\(2\)).18 E F1(,).54 E F0(and)2.5 E F1
  686. X(malloc)2.5 E F0(\(3\).).31 E(The)108 307.2 Q F1(mpool_sync)4.287 E F0 1.787
  687. X(function may f)4.287 F 1.787(ail and set)-.1 F F1(errno)4.288 E F0 1.788
  688. X(for an)4.288 F 4.288(yo)-.15 G 4.288(ft)356.694 307.2 S 1.788
  689. X(he errors speci\214ed for the library routine)367.092 307.2 R F1(write)108
  690. X319.2 Q F0(\(2\).).18 E(The)108 336 Q F1(mpool_close)4.125 E F0 1.624
  691. X(function may f)4.125 F 1.624(ail and set)-.1 F F1(errno)4.124 E F0 1.624
  692. X(for an)4.124 F 4.124(yo)-.15 G 4.124(ft)357.842 336 S 1.624
  693. X(he errors speci\214ed for the library routine)368.076 336 R F1(fr)108 348 Q
  694. X(ee)-.37 E F0(\(3\).).18 E F3(SEE ALSO)72 364.8 Q F1(dbopen)108 376.8 Q F0
  695. X(\(3\),).24 E F1(btr)2.5 E(ee)-.37 E F0(\(3\),).18 E F1(hash)2.5 E F0(\(3\),)
  696. X.28 E F1 -.37(re)2.5 G(cno).37 E F0(\(3\)).18 E 197.615(12, September)72 768 R
  697. X(2)535 768 Q EP
  698. X%%Trailer
  699. Xend
  700. X%%EOF
  701. END_OF_FILE
  702. if test 13311 -ne `wc -c <'doc/mpool.3.ps'`; then
  703.     echo shar: \"'doc/mpool.3.ps'\" unpacked with wrong size!
  704. fi
  705. # end of 'doc/mpool.3.ps'
  706. fi
  707. if test -f 'doc/recno.3.ps' -a "${1}" != "-c" ; then 
  708.   echo shar: Will not clobber existing file \"'doc/recno.3.ps'\"
  709. else
  710. echo shar: Extracting \"'doc/recno.3.ps'\" \(12881 characters\)
  711. sed "s/^X//" >'doc/recno.3.ps' <<'END_OF_FILE'
  712. X%!PS-Adobe-3.0
  713. X%%Creator: groff version 1.08
  714. X%%DocumentNeededResources: font Times-Roman
  715. X%%+ font Times-Bold
  716. X%%+ font Times-Italic
  717. X%%DocumentSuppliedResources: procset grops 1.08 0
  718. X%%Pages: 2
  719. X%%PageOrder: Ascend
  720. X%%Orientation: Portrait
  721. X%%EndComments
  722. X%%BeginProlog
  723. X%%BeginResource: procset grops 1.08 0
  724. X/setpacking where{
  725. Xpop
  726. Xcurrentpacking
  727. Xtrue setpacking
  728. X}if
  729. X/grops 120 dict dup begin
  730. X/SC 32 def
  731. X/A/show load def
  732. X/B{0 SC 3 -1 roll widthshow}bind def
  733. X/C{0 exch ashow}bind def
  734. X/D{0 exch 0 SC 5 2 roll awidthshow}bind def
  735. X/E{0 rmoveto show}bind def
  736. X/F{0 rmoveto 0 SC 3 -1 roll widthshow}bind def
  737. X/G{0 rmoveto 0 exch ashow}bind def
  738. X/H{0 rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def
  739. X/I{0 exch rmoveto show}bind def
  740. X/J{0 exch rmoveto 0 SC 3 -1 roll widthshow}bind def
  741. X/K{0 exch rmoveto 0 exch ashow}bind def
  742. X/L{0 exch rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def
  743. X/M{rmoveto show}bind def
  744. X/N{rmoveto 0 SC 3 -1 roll widthshow}bind def
  745. X/O{rmoveto 0 exch ashow}bind def
  746. X/P{rmoveto 0 exch 0 SC 5 2 roll awidthshow}bind def
  747. X/Q{moveto show}bind def
  748. X/R{moveto 0 SC 3 -1 roll widthshow}bind def
  749. X/S{moveto 0 exch ashow}bind def
  750. X/T{moveto 0 exch 0 SC 5 2 roll awidthshow}bind def
  751. X/SF{
  752. Xfindfont exch
  753. X[exch dup 0 exch 0 exch neg 0 0]makefont
  754. Xdup setfont
  755. X[exch/setfont cvx]cvx bind def
  756. X}bind def
  757. X/MF{
  758. Xfindfont
  759. X[5 2 roll
  760. X0 3 1 roll 
  761. Xneg 0 0]makefont
  762. Xdup setfont
  763. X[exch/setfont cvx]cvx bind def
  764. X}bind def
  765. X/level0 0 def
  766. X/RES 0 def
  767. X/PL 0 def
  768. X/LS 0 def
  769. X/PLG{
  770. Xgsave newpath clippath pathbbox grestore
  771. Xexch pop add exch pop
  772. X}bind def
  773. X/BP{
  774. X/level0 save def
  775. X1 setlinecap
  776. X1 setlinejoin
  777. X72 RES div dup scale
  778. XLS{
  779. X90 rotate
  780. X}{
  781. X0 PL translate
  782. X}ifelse
  783. X1 -1 scale
  784. X}bind def
  785. X/EP{
  786. Xlevel0 restore
  787. Xshowpage
  788. X}bind def
  789. X/DA{
  790. Xnewpath arcn stroke
  791. X}bind def
  792. X/SN{
  793. Xtransform
  794. X.25 sub exch .25 sub exch
  795. Xround .25 add exch round .25 add exch
  796. Xitransform
  797. X}bind def
  798. X/DL{
  799. XSN
  800. Xmoveto
  801. XSN
  802. Xlineto stroke
  803. X}bind def
  804. X/DC{
  805. Xnewpath 0 360 arc closepath
  806. X}bind def
  807. X/TM matrix def
  808. X/DE{
  809. XTM currentmatrix pop
  810. Xtranslate scale newpath 0 0 .5 0 360 arc closepath
  811. XTM setmatrix
  812. X}bind def
  813. X/RC/rcurveto load def
  814. X/RL/rlineto load def
  815. X/ST/stroke load def
  816. X/MT/moveto load def
  817. X/CL/closepath load def
  818. X/FL{
  819. Xcurrentgray exch setgray fill setgray
  820. X}bind def
  821. X/BL/fill load def
  822. X/LW/setlinewidth load def
  823. X/RE{
  824. Xfindfont
  825. Xdup maxlength 1 index/FontName known not{1 add}if dict begin
  826. X{
  827. X1 index/FID ne{def}{pop pop}ifelse
  828. X}forall
  829. X/Encoding exch def
  830. Xdup/FontName exch def
  831. Xcurrentdict end definefont pop
  832. X}bind def
  833. X/DEFS 0 def
  834. X/EBEGIN{
  835. Xmoveto
  836. XDEFS begin
  837. X}bind def
  838. X/EEND/end load def
  839. X/CNT 0 def
  840. X/level1 0 def
  841. X/PBEGIN{
  842. X/level1 save def
  843. Xtranslate
  844. Xdiv 3 1 roll div exch scale
  845. Xneg exch neg exch translate
  846. X0 setgray
  847. X0 setlinecap
  848. X1 setlinewidth
  849. X0 setlinejoin
  850. X10 setmiterlimit
  851. X[]0 setdash
  852. X/setstrokeadjust where{
  853. Xpop
  854. Xfalse setstrokeadjust
  855. X}if
  856. X/setoverprint where{
  857. Xpop
  858. Xfalse setoverprint
  859. X}if
  860. Xnewpath
  861. X/CNT countdictstack def
  862. Xuserdict begin
  863. X/showpage{}def
  864. X}bind def
  865. X/PEND{
  866. Xclear
  867. Xcountdictstack CNT sub{end}repeat
  868. Xlevel1 restore
  869. X}bind def
  870. Xend def
  871. X/setpacking where{
  872. Xpop
  873. Xsetpacking
  874. X}if
  875. X%%EndResource
  876. X%%IncludeResource: font Times-Roman
  877. X%%IncludeResource: font Times-Bold
  878. X%%IncludeResource: font Times-Italic
  879. Xgrops begin/DEFS 1 dict def DEFS begin/u{.001 mul}bind def end/RES 72 def/PL
  880. X792 def/LS false def/ENC0[/asciicircum/asciitilde/Scaron/Zcaron/scaron/zcaron
  881. X/Ydieresis/trademark/quotesingle/.notdef/.notdef/.notdef/.notdef/.notdef
  882. X/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef
  883. X/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/.notdef/space
  884. X/exclam/quotedbl/numbersign/dollar/percent/ampersand/quoteright/parenleft
  885. X/parenright/asterisk/plus/comma/hyphen/period/slash/zero/one/two/three/four
  886. X/five/six/seven/eight/nine/colon/semicolon/less/equal/greater/question/at/A/B/C
  887. X/D/E/F/G/H/I/J/K/L/M/N/O/P/Q/R/S/T/U/V/W/X/Y/Z/bracketleft/backslash
  888. X/bracketright/circumflex/underscore/quoteleft/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q
  889. X/r/s/t/u/v/w/x/y/z/braceleft/bar/braceright/tilde/.notdef/quotesinglbase
  890. X/guillemotleft/guillemotright/bullet/florin/fraction/perthousand/dagger
  891. X/daggerdbl/endash/emdash/ff/fi/fl/ffi/ffl/dotlessi/dotlessj/grave/hungarumlaut
  892. X/dotaccent/breve/caron/ring/ogonek/quotedblleft/quotedblright/oe/lslash
  893. X/quotedblbase/OE/Lslash/.notdef/exclamdown/cent/sterling/currency/yen/brokenbar
  894. X/section/dieresis/copyright/ordfeminine/guilsinglleft/logicalnot/minus
  895. X/registered/macron/degree/plusminus/twosuperior/threesuperior/acute/mu
  896. X/paragraph/periodcentered/cedilla/onesuperior/ordmasculine/guilsinglright
  897. X/onequarter/onehalf/threequarters/questiondown/Agrave/Aacute/Acircumflex/Atilde
  898. X/Adieresis/Aring/AE/Ccedilla/Egrave/Eacute/Ecircumflex/Edieresis/Igrave/Iacute
  899. X/Icircumflex/Idieresis/Eth/Ntilde/Ograve/Oacute/Ocircumflex/Otilde/Odieresis
  900. X/multiply/Oslash/Ugrave/Uacute/Ucircumflex/Udieresis/Yacute/Thorn/germandbls
  901. X/agrave/aacute/acircumflex/atilde/adieresis/aring/ae/ccedilla/egrave/eacute
  902. X/ecircumflex/edieresis/igrave/iacute/icircumflex/idieresis/eth/ntilde/ograve
  903. X/oacute/ocircumflex/otilde/odieresis/divide/oslash/ugrave/uacute/ucircumflex
  904. X/udieresis/yacute/thorn/ydieresis]def/Times-Italic@0 ENC0/Times-Italic RE
  905. X/Times-Bold@0 ENC0/Times-Bold RE/Times-Roman@0 ENC0/Times-Roman RE
  906. X%%EndProlog
  907. X%%Page: 1 1
  908. X%%BeginPageSetup
  909. XBP
  910. X%%EndPageSetup
  911. X/F0 10/Times-Roman@0 SF 175.95(RECNO\(3\) 1993 RECNO\(3\))72 48 R/F1 9
  912. X/Times-Bold@0 SF -.18(NA)72 84 S(ME).18 E F0
  913. X(recno \255 record number database access method)108 96 Q F1(SYNOPSIS)72 112.8
  914. XQ/F2 10/Times-Bold@0 SF(#include <sys/types.h>)108 124.8 Q(#include <db)108
  915. X136.8 Q(.h>)-.4 E F1(DESCRIPTION)72 153.6 Q F0 1.158(The routine)108 165.6 R/F3
  916. X10/Times-Italic@0 SF(dbopen)3.658 E F0 1.158(is the library interf)3.658 F
  917. X1.158(ace to database \214les.)-.1 F 1.157
  918. X(One of the supported \214le formats is record)6.158 F 1.159(number \214les.)
  919. X108 177.6 R 1.159(The general description of the database access methods is in)
  920. X6.159 F F3(dbopen)3.66 E F0 1.16(\(3\), this manual page).24 F
  921. X(describes only the recno speci\214c information.)108 189.6 Q 1.944
  922. X(The record number data structure is either v)108 206.4 R 1.944
  923. X(ariable or \214x)-.25 F 1.944
  924. X(ed-length records stored in a \215at-\214le format,)-.15 F 2.04
  925. X(accessed by the logical record number)108 218.4 R 7.04(.T)-.55 G 2.04(he e)
  926. X286.31 218.4 R 2.04(xistence of record number \214v)-.15 F 4.54(ei)-.15 G 2.04
  927. X(mplies the e)442.1 218.4 R 2.04(xistence of)-.15 F .876
  928. X(records one through four)108 230.4 R 3.376(,a)-.4 G .875
  929. X(nd the deletion of record number one causes record number \214v)219.684 230.4
  930. XR 3.375(et)-.15 G 3.375(ob)489.93 230.4 S 3.375(er)503.305 230.4 S(enum-)514.45
  931. X230.4 Q .282(bered to record number four)108 242.4 R 2.782(,a)-.4 G 2.782(sw)
  932. X231.19 242.4 S .283(ell as the cursor)245.082 242.4 R 2.783(,i)-.4 G 2.783(fp)
  933. X316.633 242.4 S .283(ositioned after record number one, to shift do)327.746
  934. X242.4 R .283(wn one)-.25 F(record.)108 254.4 Q .373
  935. X(The recno access method speci\214c data structure pro)108 271.2 R .373
  936. X(vided to)-.15 F F3(dbopen)2.873 E F0 .373(is de\214ned in the <db)2.873 F .373
  937. X(.h> include \214le as)-.4 F(follo)108 283.2 Q(ws:)-.25 E(typedef struct {)108
  938. X300 Q(u_char b)144 312 Q -.25(va)-.15 G(l;).25 E(u_int cachesize;)144 324 Q
  939. X(inde)144 336 Q(x_t psize;)-.15 E(u_long \215ags;)144 348 Q(int lorder;)144 360
  940. XQ(size_t reclen;)144 372 Q(char *bfname;)144 384 Q 2.5(}R)108 396 S(ECNOINFO;)
  941. X121.97 396 Q(The elements of this structure are de\214ned as follo)108 412.8 Q
  942. X(ws:)-.25 E -.15(bv)108 429.6 S 16.68(al The)-.1 F .182
  943. X(delimiting byte to be used to mark the end of a record for v)2.682 F .183
  944. X(ariable-length records, and the pad)-.25 F .809(character for \214x)144 441.6
  945. XR .809(ed-length records.)-.15 F .809(If no v)5.809 F .809
  946. X(alue is speci\214ed, ne)-.25 F .809(wlines \(`)-.25 F(`\\n')-.74 E .808
  947. X('\) are used to mark the)-.74 F(end of v)144 453.6 Q
  948. X(ariable-length records and \214x)-.25 E
  949. X(ed-length records are padded with spaces.)-.15 E(cachesize)108 470.4 Q 3.159
  950. X(As)144 482.4 S .659(uggested maximum size, in bytes, of the memory cache.)
  951. X158.269 482.4 R .66(This v)5.659 F .66(alue is)-.25 F F2(only)3.16 E F0
  952. X(advisory)3.16 E 3.16(,a)-.65 G .66(nd the)514.62 482.4 R
  953. X(access method will allocate more memory rather than f)144 494.4 Q(ail.)-.1 E
  954. X12.95(psize The)108 511.2 R .715
  955. X(recno access method stores the in-memory copies of its records in a btree.)
  956. X3.216 F .715(This v)5.715 F .715(alue is the)-.25 F
  957. X(size \(in bytes\) of the pages used for nodes in that tree.)144 523.2 Q(See)5
  958. XE F3(btr)2.5 E(ee)-.37 E F0(\(3\) for more information.).18 E 3.51(bfname The)
  959. X108 540 R .505
  960. X(recno access method stores the in-memory copies of its records in a btree.)
  961. X3.005 F .506(If bfname is non-)5.506 F .065(NULL, it speci\214es the name of t\
  962. Xhe btree \214le, as if speci\214ed as the \214le name for a dbopen of a btree)
  963. X144 552 R(\214le.)144 564 Q 14.61(\215ags The)108 580.8 R(\215ag v)2.5 E
  964. X(alue is speci\214ed by)-.25 E F3(or)2.5 E F0('ing an).73 E 2.5(yo)-.15 G 2.5
  965. X(ft)313.2 580.8 S(he follo)321.81 580.8 Q(wing v)-.25 E(alues:)-.25 E
  966. X(R_FIXEDLEN)144 597.6 Q .962(The records are \214x)180 609.6 R .963
  967. X(ed-length, not byte delimited.)-.15 F .963(The structure element)5.963 F F3
  968. X-.37(re)3.463 G(clen).37 E F0(speci\214es)3.463 E
  969. X(the length of the record, and the structure element)180 621.6 Q F3(bval)2.5 E
  970. XF0(is used as the pad character)2.5 E(.)-.55 E(R_NOKEY)144 638.4 Q 2.34
  971. X(In the interf)180 650.4 R 2.34(ace speci\214ed by)-.1 F F3(dbopen)4.84 E F0
  972. X4.84(,t).24 G 2.34(he sequential record retrie)344.98 650.4 R -.25(va)-.25 G
  973. X4.84<6c8c>.25 G 2.34(lls in both the)478.25 650.4 R(caller')180 662.4 Q 3.556
  974. X(sk)-.55 G 1.357 -.15(ey a)217.336 662.4 T 1.057(nd data structures.).15 F
  975. X1.057(If the R_NOKEY \215ag is speci\214ed, the)6.057 F F3(cur)3.557 E(sor)-.1
  976. XE F0(routines)3.557 E .029(are not required to \214ll in the k)180 674.4 R .329
  977. X-.15(ey s)-.1 H 2.529(tructure. This).15 F .028(permits applications to retrie)
  978. X2.529 F .328 -.15(ve r)-.25 H .028(ecords at).15 F
  979. X(the end of \214les without reading all of the interv)180 686.4 Q
  980. X(ening records.)-.15 E(R_SN)144 703.2 Q(APSHO)-.35 E(T)-.4 E .964
  981. X(This \215ag requires that a snapshot of the \214le be tak)180 715.2 R .965
  982. X(en when)-.1 F F3(dbopen)3.465 E F0 .965(is called, instead of)3.465 F
  983. X(permitting an)180 727.2 Q 2.5(yu)-.15 G
  984. X(nmodi\214ed records to be read from the original \214le.)245.96 727.2 Q
  985. X209.835(16, May)72 768 R(1)535 768 Q EP
  986. X%%Page: 2 2
  987. X%%BeginPageSetup
  988. XBP
  989. X%%EndPageSetup
  990. X/F0 10/Times-Roman@0 SF 175.95(RECNO\(3\) 1993 RECNO\(3\))72 48 R 9.62
  991. X(lorder The)108 84 R 1.597(byte order for inte)4.097 F 1.596
  992. X(gers in the stored database metadata.)-.15 F 1.596
  993. X(The number should represent the)6.596 F .688(order as an inte)144 96 R .689
  994. X(ger; for e)-.15 F .689(xample, big endian order w)-.15 F .689
  995. X(ould be the number 4,321.)-.1 F(If)5.689 E/F1 10/Times-Italic@0 SF(lor)3.189 E
  996. X(der)-.37 E F0 .689(is 0 \(no)3.189 F
  997. X(order is speci\214ed\) the current host order is used.)144 108 Q 9.07
  998. X(reclen The)108 124.8 R(length of a \214x)2.5 E(ed-length record.)-.15 E .972
  999. X(The data part of the k)108 141.6 R -.15(ey)-.1 G .971(/data pair used by the \
  1000. Xrecno access method is the same as other access methods.).15 F .198(The k)108
  1001. X153.6 R .498 -.15(ey i)-.1 H 2.698(sd).15 G(if)157.504 153.6 Q 2.698
  1002. X(ferent. The)-.25 F F1(data)2.698 E F0 .198(\214eld of the k)2.698 F .499 -.15
  1003. X(ey s)-.1 H .199(hould be a pointer to a memory location of type).15 F F1 -.37
  1004. X(re)2.699 G(cno_t).37 E F0 2.699(,a).68 G(s)536.11 153.6 Q .506
  1005. X(de\214ned in the <db)108 165.6 R .506(.h> include \214le.)-.4 F .506
  1006. X(This type is normally the lar)5.506 F .506(gest unsigned inte)-.18 F .506
  1007. X(gral type a)-.15 F -.25(va)-.2 G .505(ilable to the).25 F 2.5
  1008. X(implementation. The)108 177.6 R F1(size)2.5 E F0(\214eld of the k)2.5 E .3
  1009. X-.15(ey s)-.1 H(hould be the size of that type.).15 E .064(In the interf)108
  1010. X194.4 R .064(ace speci\214ed by)-.1 F F1(dbopen)2.564 E F0 2.564(,u).24 G .064
  1011. X(sing the)261.544 194.4 R F1(put)2.564 E F0(interf)2.564 E .064
  1012. X(ace to create a ne)-.1 F 2.564(wr)-.25 G .065
  1013. X(ecord will cause the creation of)414.436 194.4 R .755(multiple, empty records\
  1014. X if the record number is more than one greater than the lar)108 206.4 R .754
  1015. X(gest record currently in)-.18 F(the database.)108 218.4 Q/F2 9/Times-Bold@0 SF
  1016. X(SEE ALSO)72 235.2 Q F1(dbopen)108 247.2 Q F0(\(3\),).24 E F1(hash)2.5 E F0
  1017. X(\(3\),).28 E F1(mpool)2.5 E F0(\(3\),).51 E F1 -.37(re)2.5 G(cno).37 E F0
  1018. X(\(3\)).18 E F1 2.754(Document Pr)108 271.2 R 2.754
  1019. X(ocessing in a Relational Database System)-.45 F F0 5.255(,M).32 G 2.755
  1020. X(ichael Stonebrak)362.13 271.2 R(er)-.1 E 5.255(,H)-.4 G 2.755(eidi Stettner)
  1021. X454.06 271.2 R 5.255(,J)-.4 G(oseph)516.67 271.2 Q
  1022. X(Kalash, Antonin Guttman, Nadene L)108 283.2 Q
  1023. X(ynn, Memorandum No. UCB/ERL M82/32, May 1982.)-.55 E F2 -.09(BU)72 300 S(GS)
  1024. X.09 E F0(Only big and little endian byte order is supported.)108 312 Q 209.835
  1025. X(16, May)72 768 R(2)535 768 Q EP
  1026. X%%Trailer
  1027. Xend
  1028. X%%EOF
  1029. END_OF_FILE
  1030. if test 12881 -ne `wc -c <'doc/recno.3.ps'`; then
  1031.     echo shar: \"'doc/recno.3.ps'\" unpacked with wrong size!
  1032. fi
  1033. # end of 'doc/recno.3.ps'
  1034. fi
  1035. if test -f 'man/dbopen.3' -a "${1}" != "-c" ; then 
  1036.   echo shar: Will not clobber existing file \"'man/dbopen.3'\"
  1037. else
  1038. echo shar: Extracting \"'man/dbopen.3'\" \(12751 characters\)
  1039. sed "s/^X//" >'man/dbopen.3' <<'END_OF_FILE'
  1040. X.\" Copyright (c) 1990, 1993
  1041. X.\"    The Regents of the University of California.  All rights reserved.
  1042. X.\"
  1043. X.\" Redistribution and use in source and binary forms, with or without
  1044. X.\" modification, are permitted provided that the following conditions
  1045. X.\" are met:
  1046. X.\" 1. Redistributions of source code must retain the above copyright
  1047. X.\"    notice, this list of conditions and the following disclaimer.
  1048. X.\" 2. Redistributions in binary form must reproduce the above copyright
  1049. X.\"    notice, this list of conditions and the following disclaimer in the
  1050. X.\"    documentation and/or other materials provided with the distribution.
  1051. X.\" 3. All advertising materials mentioning features or use of this software
  1052. X.\"    must display the following acknowledgement:
  1053. X.\"    This product includes software developed by the University of
  1054. X.\"    California, Berkeley and its contributors.
  1055. X.\" 4. Neither the name of the University nor the names of its contributors
  1056. X.\"    may be used to endorse or promote products derived from this software
  1057. X.\"    without specific prior written permission.
  1058. X.\"
  1059. X.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  1060. X.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  1061. X.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  1062. X.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  1063. X.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  1064. X.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  1065. X.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  1066. X.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  1067. X.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  1068. X.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  1069. X.\" SUCH DAMAGE.
  1070. X.\"
  1071. X.\"    @(#)dbopen.3    8.1 (Berkeley) 6/4/93
  1072. X.\"
  1073. X.TH DBOPEN 3 "June 4, 1993"
  1074. X.UC 7
  1075. X.SH NAME
  1076. Xdbopen \- database access methods
  1077. X.SH SYNOPSIS
  1078. X.nf
  1079. X.ft B
  1080. X#include <sys/types.h>
  1081. X#include <limits.h>
  1082. X#include <db.h>
  1083. X
  1084. XDB *
  1085. Xdbopen(const char *file, int flags, int mode, DBTYPE type,
  1086. X.ti +5
  1087. Xconst void *openinfo);
  1088. X.ft R
  1089. X.fi
  1090. X.SH DESCRIPTION
  1091. X.IR Dbopen
  1092. Xis the library interface to database files.
  1093. XThe supported file formats are btree, hashed and UNIX file oriented.
  1094. XThe btree format is a representation of a sorted, balanced tree structure.
  1095. XThe hashed format is an extensible, dynamic hashing scheme.
  1096. XThe flat-file format is a byte stream file with fixed or variable length
  1097. Xrecords.
  1098. XThe formats and file format specific information are described in detail
  1099. Xin their respective manual pages
  1100. X.IR btree (3),
  1101. X.IR hash (3)
  1102. Xand
  1103. X.IR recno (3).
  1104. X.PP
  1105. XDbopen opens
  1106. X.I file
  1107. Xfor reading and/or writing.
  1108. XFiles never intended to be preserved on disk may be created by setting
  1109. Xthe file parameter to NULL.
  1110. X.PP
  1111. XThe
  1112. X.I flags
  1113. Xand
  1114. X.I mode arguments
  1115. Xare as specified to the
  1116. X.IR open (2)
  1117. Xroutine, however, only the O_CREAT, O_EXCL, O_EXLOCK, O_RDONLY, O_RDWR,
  1118. XO_SHLOCK and O_TRUNC flags are meaningful.
  1119. X(Note, opening a database file O_WRONLY is not possible.)
  1120. X.PP
  1121. XThe
  1122. X.I type
  1123. Xargument is of type DBTYPE (as defined in the <db.h> include file) and
  1124. Xmay be set to DB_BTREE, DB_HASH or DB_RECNO.
  1125. X.PP
  1126. XThe
  1127. X.I openinfo
  1128. Xargument is a pointer to an access method specific structure described
  1129. Xin the access method's manual page.
  1130. XIf
  1131. X.I openinfo
  1132. Xis NULL, each access method will use defaults appropriate for the system
  1133. Xand the access method.
  1134. X.PP
  1135. X.I Dbopen
  1136. Xreturns a pointer to a DB structure on success and NULL on error.
  1137. XThe DB structure is defined in the <db.h> include file, and contains at
  1138. Xleast the following fields:
  1139. X.sp
  1140. X.nf
  1141. Xtypedef struct {
  1142. X.RS
  1143. XDBTYPE type;
  1144. Xint (*close)(const DB *db);
  1145. Xint (*del)(const DB *db, const DBT *key, u_int flags);
  1146. Xint (*fd)(const DB *db);
  1147. Xint (*get)(const DB *db, DBT *key, DBT *data, u_int flags);
  1148. Xint (*put)(const DB *db, DBT *key, const DBT *data,
  1149. X.ti +5
  1150. Xu_int flags);
  1151. Xint (*sync)(const DB *db, u_int flags);
  1152. Xint (*seq)(const DB *db, DBT *key, DBT *data, u_int flags);
  1153. X.RE
  1154. X} DB;
  1155. X.fi
  1156. X.PP
  1157. XThese elements describe a database type and a set of functions performing
  1158. Xvarious actions.
  1159. XThese functions take a pointer to a structure as returned by
  1160. X.IR dbopen ,
  1161. Xand sometimes one or more pointers to key/data structures and a flag value.
  1162. X.TP
  1163. Xtype
  1164. XThe type of the underlying access method (and file format).
  1165. X.TP
  1166. Xclose
  1167. XA pointer to a routine to flush any cached information to disk, free any
  1168. Xallocated resources, and close the underlying file(s).
  1169. XSince key/data pairs may be cached in memory, failing to sync the file
  1170. Xwith a
  1171. X.I close
  1172. Xor
  1173. X.I sync
  1174. Xfunction may result in inconsistent or lost information.
  1175. X.I Close
  1176. Xroutines return -1 on error (setting
  1177. X.IR errno )
  1178. Xand 0 on success.
  1179. X.TP
  1180. Xdel
  1181. XA pointer to a routine to remove key/data pairs from the database.
  1182. X.IP
  1183. XThe parameter
  1184. X.I flag
  1185. Xmay be set to the following value:
  1186. X.RS
  1187. X.TP
  1188. XR_CURSOR
  1189. XDelete the record referenced by the cursor.
  1190. XThe cursor must have previously been initialized.
  1191. X.RE
  1192. X.IP
  1193. X.I Delete
  1194. Xroutines return -1 on error (setting
  1195. X.IR errno ),
  1196. X0 on success, and 1 if the specified
  1197. X.I key
  1198. Xwas not in the file.
  1199. X.TP
  1200. Xfd
  1201. XA pointer to a routine which returns a file descriptor representative
  1202. Xof the underlying database.
  1203. XA file descriptor referencing the same file will be returned to all
  1204. Xprocesses which call
  1205. X.I dbopen
  1206. Xwith the same
  1207. X.I file
  1208. Xname.
  1209. XThis file descriptor may be safely used as a argument to the
  1210. X.IR fcntl (2)
  1211. Xand
  1212. X.IR flock (2)
  1213. Xlocking functions.
  1214. XThe file descriptor is not necessarily associated with any of the
  1215. Xunderlying files used by the access method.
  1216. XNo file descriptor is available for in memory databases.
  1217. X.I Fd
  1218. Xroutines return -1 on error (setting
  1219. X.IR errno ),
  1220. Xand the file descriptor on success.
  1221. X.TP
  1222. Xget
  1223. XA pointer to a routine which is the interface for keyed retrieval from
  1224. Xthe database.
  1225. XThe address and length of the data associated with the specified
  1226. X.I key
  1227. Xare returned in the structure referenced by
  1228. X.IR data .
  1229. X.I Get
  1230. Xroutines return -1 on error (setting
  1231. X.IR errno ),
  1232. X0 on success, and 1 if the
  1233. X.I key
  1234. Xwas not in the file.
  1235. X.TP
  1236. Xput
  1237. XA pointer to a routine to store key/data pairs in the database.
  1238. X.IP
  1239. XThe parameter
  1240. X.I flag
  1241. Xmay be set to one of the following values:
  1242. X.RS
  1243. X.TP
  1244. XR_CURSOR
  1245. XReplace the key/data pair referenced by the cursor.
  1246. XThe cursor must have previously been initialized.
  1247. X.TP
  1248. XR_IAFTER
  1249. XAppend the data immediately after the data referenced by
  1250. X.IR key ,
  1251. Xcreating a new key/data pair.
  1252. XThe record number of the appended key/data pair is returned in the
  1253. X.I key
  1254. Xstructure.
  1255. X(Applicable only to the DB_RECNO access method.)
  1256. X.TP
  1257. XR_IBEFORE
  1258. XInsert the data immediately before the data referenced by
  1259. X.IR key ,
  1260. Xcreating a new key/data pair.
  1261. XThe record number of the inserted key/data pair is returned in the
  1262. X.I key
  1263. Xstructure.
  1264. X(Applicable only to the DB_RECNO access method.)
  1265. X.TP
  1266. XR_NOOVERWRITE
  1267. XEnter the new key/data pair only if the key does not previously exist.
  1268. X.TP
  1269. XR_SETCURSOR
  1270. XStore the key/data pair, setting or initializing the position of the
  1271. Xcursor to reference it.
  1272. X(Applicable only to the DB_BTREE and DB_RECNO access methods.)
  1273. X.RE
  1274. X.IP
  1275. XR_SETCURSOR is available only for the DB_BTREE and DB_RECNO access
  1276. Xmethods because it implies that the keys have an inherent order
  1277. Xwhich does not change.
  1278. X.IP
  1279. XR_IAFTER and R_IBEFORE are available only for the DB_RECNO
  1280. Xaccess method because they each imply that the access method is able to
  1281. Xcreate new keys.
  1282. XThis is only true if the keys are ordered and independent, record numbers
  1283. Xfor example.
  1284. X.IP
  1285. XThe default behavior of the
  1286. X.I put
  1287. Xroutines is to enter the new key/data pair, replacing any previously
  1288. Xexisting key.
  1289. X.IP
  1290. X.I Put
  1291. Xroutines return -1 on error (setting
  1292. X.IR errno ),
  1293. X0 on success, and 1 if the R_NOOVERWRITE
  1294. X.I flag
  1295. Xwas set and the key already exists in the file.
  1296. X.TP
  1297. Xseq
  1298. XA pointer to a routine which is the interface for sequential
  1299. Xretrieval from the database.
  1300. XThe address and length of the key are returned in the structure
  1301. Xreferenced by
  1302. X.IR key ,
  1303. Xand the address and length of the data are returned in the
  1304. Xstructure referenced
  1305. Xby
  1306. X.IR data .
  1307. X.IP
  1308. XSequential key/data pair retrieval may begin at any time, and the
  1309. Xposition of the ``cursor'' is not affected by calls to the
  1310. X.IR del ,
  1311. X.IR get ,
  1312. X.IR put ,
  1313. Xor
  1314. X.I sync
  1315. Xroutines.
  1316. XModifications to the database during a sequential scan will be reflected
  1317. Xin the scan, i.e. records inserted behind the cursor will not be returned
  1318. Xwhile records inserted in front of the cursor will be returned.
  1319. X.IP
  1320. XThe flag value
  1321. X.B must
  1322. Xbe set to one of the following values:
  1323. X.RS
  1324. X.TP
  1325. XR_CURSOR
  1326. XThe data associated with the specified key is returned.
  1327. XThis differs from the
  1328. X.I get
  1329. Xroutines in that it sets or initializes the cursor to the location of
  1330. Xthe key as well.
  1331. X(Note, for the DB_BTREE access method, the returned key is not necessarily an
  1332. Xexact match for the specified key.
  1333. XThe returned key is the smallest key greater than or equal to the specified
  1334. Xkey, permitting partial key matches and range searches.)
  1335. X.TP
  1336. XR_FIRST
  1337. XThe first key/data pair of the database is returned, and the cursor
  1338. Xis set or initialized to reference it.
  1339. X.TP
  1340. XR_LAST
  1341. XThe last key/data pair of the database is returned, and the cursor
  1342. Xis set or initialized to reference it.
  1343. X(Applicable only to the DB_BTREE and DB_RECNO access methods.)
  1344. X.TP
  1345. XR_NEXT
  1346. XRetrieve the key/data pair immediately after the cursor.
  1347. XIf the cursor is not yet set, this is the same as the R_FIRST flag.
  1348. X.TP
  1349. XR_PREV
  1350. XRetrieve the key/data pair immediately before the cursor.
  1351. XIf the cursor is not yet set, this is the same as the R_LAST flag.
  1352. X(Applicable only to the DB_BTREE and DB_RECNO access methods.)
  1353. X.RE
  1354. X.IP
  1355. XR_LAST and R_PREV are available only for the DB_BTREE and DB_RECNO
  1356. Xaccess methods because they each imply that the keys have an inherent
  1357. Xorder which does not change.
  1358. X.IP
  1359. X.I Seq
  1360. Xroutines return -1 on error (setting
  1361. X.IR errno ),
  1362. X0 on success and 1 if there are no key/data pairs less than or greater
  1363. Xthan the specified or current key.
  1364. XIf the DB_RECNO access method is being used, and if the database file
  1365. Xis a character special file and no complete key/data pairs are currently
  1366. Xavailable, the
  1367. X.I seq
  1368. Xroutines return 2.
  1369. X.TP
  1370. Xsync
  1371. XA pointer to a routine to flush any cached information to disk.
  1372. XIf the database is in memory only, the
  1373. X.I sync
  1374. Xroutine has no effect and will always succeed.
  1375. X.IP
  1376. XThe flag value may be set to the following value:
  1377. X.RS
  1378. X.TP
  1379. XR_RECNOSYNC
  1380. XIf the DB_RECNO access method is being used, this flag causes
  1381. Xthe sync routine to apply to the btree file which underlies the
  1382. Xrecno file, not the recno file itself.
  1383. X(See the
  1384. X.I bfname
  1385. Xfield of the
  1386. X.IR recno (3)
  1387. Xmanual page for more information.)
  1388. X.RE
  1389. X.IP
  1390. X.I Sync
  1391. Xroutines return -1 on error (setting
  1392. X.IR errno )
  1393. Xand 0 on success.
  1394. X.SH "KEY/DATA PAIRS"
  1395. XAccess to all file types is based on key/data pairs.
  1396. XBoth keys and data are represented by the following data structure:
  1397. X.PP
  1398. Xtypedef struct {
  1399. X.RS
  1400. Xvoid *data;
  1401. X.br
  1402. Xsize_t size;
  1403. X.RE
  1404. X} DBT;
  1405. X.PP
  1406. XThe elements of the DBT structure are defined as follows:
  1407. X.TP
  1408. Xdata
  1409. XA pointer to a byte string.
  1410. X.TP
  1411. Xsize
  1412. XThe length of the byte string.
  1413. X.PP
  1414. XKey and data byte strings may reference strings of essentially unlimited
  1415. Xlength although any two of them must fit into available memory at the same
  1416. Xtime.
  1417. XIt should be noted that the access methods provide no guarantees about
  1418. Xbyte string alignment.
  1419. X.SH ERRORS
  1420. XThe
  1421. X.I dbopen
  1422. Xroutine may fail and set
  1423. X.I errno
  1424. Xfor any of the errors specified for the library routines
  1425. X.IR open (2)
  1426. Xand
  1427. X.IR malloc (3)
  1428. Xor the following:
  1429. X.TP
  1430. X[EFTYPE]
  1431. XA file is incorrectly formatted.
  1432. X.TP
  1433. X[EINVAL]
  1434. XA parameter has been specified (hash function, pad byte etc.) that is
  1435. Xincompatible with the current file specification or which is not
  1436. Xmeaningful for the function (for example, use of the cursor without
  1437. Xprior initialization) or there is a mismatch between the version
  1438. Xnumber of file and the software.
  1439. X.PP
  1440. XThe
  1441. X.I close
  1442. Xroutines may fail and set
  1443. X.I errno
  1444. Xfor any of the errors specified for the library routines
  1445. X.IR close (2),
  1446. X.IR read (2),
  1447. X.IR write (2),
  1448. X.IR free (3),
  1449. Xor
  1450. X.IR fsync (2).
  1451. X.PP
  1452. XThe
  1453. X.IR del ,
  1454. X.IR get ,
  1455. X.I put
  1456. Xand
  1457. X.I seq
  1458. Xroutines may fail and set
  1459. X.I errno
  1460. Xfor any of the errors specified for the library routines
  1461. X.IR read (2),
  1462. X.IR write (2),
  1463. X.IR free (3)
  1464. Xor
  1465. X.IR malloc (3).
  1466. X.PP
  1467. XThe
  1468. X.I fd
  1469. Xroutines will fail and set
  1470. X.I errno
  1471. Xto ENOENT for in memory databases.
  1472. X.PP
  1473. XThe
  1474. X.I sync
  1475. Xroutines may fail and set
  1476. X.I errno
  1477. Xfor any of the errors specified for the library routine
  1478. X.IR fsync (2).
  1479. X.SH "SEE ALSO"
  1480. X.IR btree (3),
  1481. X.IR hash (3),
  1482. X.IR mpool (3),
  1483. X.IR recno (3)
  1484. X.SH BUGS
  1485. XThe typedef DBT is a mnemonic for ``data base thang'', and was used
  1486. Xbecause noone could think of a reasonable name that wasn't already used.
  1487. X.PP
  1488. XThe file descriptor interface is a kluge and will be deleted in a
  1489. Xfuture version of the interface.
  1490. X.PP
  1491. XNone of the access methods provide any form of concurrent access,
  1492. Xlocking, or transactions.
  1493. END_OF_FILE
  1494. if test 12751 -ne `wc -c <'man/dbopen.3'`; then
  1495.     echo shar: \"'man/dbopen.3'\" unpacked with wrong size!
  1496. fi
  1497. # end of 'man/dbopen.3'
  1498. fi
  1499. if test -f 'test/dbtest.c' -a "${1}" != "-c" ; then 
  1500.   echo shar: Will not clobber existing file \"'test/dbtest.c'\"
  1501. else
  1502. echo shar: Extracting \"'test/dbtest.c'\" \(14197 characters\)
  1503. sed "s/^X//" >'test/dbtest.c' <<'END_OF_FILE'
  1504. X/*-
  1505. X * Copyright (c) 1992, 1993
  1506. X *    The Regents of the University of California.  All rights reserved.
  1507. X *
  1508. X * Redistribution and use in source and binary forms, with or without
  1509. X * modification, are permitted provided that the following conditions
  1510. X * are met:
  1511. X * 1. Redistributions of source code must retain the above copyright
  1512. X *    notice, this list of conditions and the following disclaimer.
  1513. X * 2. Redistributions in binary form must reproduce the above copyright
  1514. X *    notice, this list of conditions and the following disclaimer in the
  1515. X *    documentation and/or other materials provided with the distribution.
  1516. X * 3. All advertising materials mentioning features or use of this software
  1517. X *    must display the following acknowledgement:
  1518. X *    This product includes software developed by the University of
  1519. X *    California, Berkeley and its contributors.
  1520. X * 4. Neither the name of the University nor the names of its contributors
  1521. X *    may be used to endorse or promote products derived from this software
  1522. X *    without specific prior written permission.
  1523. X *
  1524. X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  1525. X * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  1526. X * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  1527. X * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  1528. X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  1529. X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  1530. X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  1531. X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  1532. X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  1533. X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  1534. X * SUCH DAMAGE.
  1535. X */
  1536. X
  1537. X#ifndef lint
  1538. Xstatic char copyright[] =
  1539. X"@(#) Copyright (c) 1992, 1993\n\
  1540. X    The Regents of the University of California.  All rights reserved.\n";
  1541. X#endif /* not lint */
  1542. X
  1543. X#ifndef lint
  1544. Xstatic char sccsid[] = "@(#)dbtest.c    8.1 (Berkeley) 6/4/93";
  1545. X#endif /* not lint */
  1546. X
  1547. X#include <sys/param.h>
  1548. X#include <sys/stat.h>
  1549. X
  1550. X#include <ctype.h>
  1551. X#include <errno.h>
  1552. X#include <fcntl.h>
  1553. X#include <limits.h>
  1554. X#include <stdio.h>
  1555. X#include <stdlib.h>
  1556. X#include <string.h>
  1557. X#include <unistd.h>
  1558. X
  1559. X#include <db.h>
  1560. X
  1561. Xenum S { COMMAND, COMPARE, GET, PUT, REMOVE, SEQ, SEQFLAG, KEY, DATA };
  1562. X
  1563. Xvoid     compare __P((DBT *, DBT *));
  1564. XDBTYPE     dbtype __P((char *));
  1565. Xvoid     dump __P((DB *, int));
  1566. Xvoid     err __P((const char *, ...));
  1567. Xvoid     get __P((DB *, DBT *));
  1568. Xvoid     getdata __P((DB *, DBT *, DBT *));
  1569. Xvoid     put __P((DB *, DBT *, DBT *));
  1570. Xvoid     rem __P((DB *, DBT *));
  1571. Xvoid    *rfile __P((char *, size_t *));
  1572. Xvoid     seq __P((DB *, DBT *));
  1573. Xu_int     setflags __P((char *));
  1574. Xvoid    *setinfo __P((DBTYPE, char *));
  1575. Xvoid     usage __P((void));
  1576. Xvoid    *xmalloc __P((char *, size_t));
  1577. X
  1578. XDBTYPE type;
  1579. Xvoid *infop;
  1580. Xu_long lineno;
  1581. Xu_int flags;
  1582. Xint ofd = STDOUT_FILENO;
  1583. X
  1584. XDB *XXdbp;                /* Global for gdb. */
  1585. X
  1586. Xint
  1587. Xmain(argc, argv)
  1588. X    int argc;
  1589. X    char *argv[];
  1590. X{
  1591. X    extern int optind;
  1592. X    extern char *optarg;
  1593. X    enum S command, state;
  1594. X    DB *dbp;
  1595. X    DBT data, key, keydata;
  1596. X    size_t len;
  1597. X    int ch;
  1598. X    char *fname, *infoarg, *p, buf[8 * 1024];
  1599. X
  1600. X    infoarg = NULL;
  1601. X    fname = NULL;
  1602. X    while ((ch = getopt(argc, argv, "f:i:o:")) != EOF)
  1603. X        switch(ch) {
  1604. X        case 'f':
  1605. X            fname = optarg;
  1606. X            break;
  1607. X        case 'i':
  1608. X            infoarg = optarg;
  1609. X            break;
  1610. X        case 'o':
  1611. X            if ((ofd = open(optarg,
  1612. X                O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0)
  1613. X                err("%s: %s", optarg, strerror(errno));
  1614. X            break;
  1615. X        case '?':
  1616. X        default:
  1617. X            usage();
  1618. X        }
  1619. X    argc -= optind;
  1620. X    argv += optind;
  1621. X
  1622. X    if (argc != 2)
  1623. X        usage();
  1624. X
  1625. X    /* Set the type. */
  1626. X    type = dbtype(*argv++);
  1627. X
  1628. X    /* Open the descriptor file. */
  1629. X    if (freopen(*argv, "r", stdin) == NULL)
  1630. X        err("%s: %s", *argv, strerror(errno));
  1631. X
  1632. X    /* Set up the db structure as necessary. */
  1633. X    if (infoarg == NULL)
  1634. X        infop = NULL;
  1635. X    else
  1636. X        for (p = strtok(infoarg, ",\t "); p != NULL;
  1637. X            p = strtok(0, ",\t "))
  1638. X            if (*p != '\0')
  1639. X                infop = setinfo(type, p);
  1640. X
  1641. X    /* Open the DB. */
  1642. X    if (fname == NULL) {
  1643. X        p = getenv("TMPDIR");
  1644. X        if (p == NULL)
  1645. X            p = "/var/tmp";
  1646. X        (void)sprintf(buf, "%s/__dbtest", p);
  1647. X        fname = buf;
  1648. X        (void)unlink(buf);
  1649. X    }
  1650. X    if ((dbp = dbopen(fname,
  1651. X        O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, type, infop)) == NULL)
  1652. X        err("dbopen: %s", strerror(errno));
  1653. X    XXdbp = dbp;
  1654. X
  1655. X    state = COMMAND;
  1656. X    for (lineno = 1;
  1657. X        (p = fgets(buf, sizeof(buf), stdin)) != NULL; ++lineno) {
  1658. X        len = strlen(buf);
  1659. X        switch(*p) {
  1660. X        case 'c':            /* compare */
  1661. X            if (state != COMMAND)
  1662. X                err("line %lu: not expecting command", lineno);
  1663. X            state = KEY;
  1664. X            command = COMPARE;
  1665. X            break;
  1666. X        case 'e':            /* echo */
  1667. X            if (state != COMMAND)
  1668. X                err("line %lu: not expecting command", lineno);
  1669. X            /* Don't display the newline, if CR at EOL. */
  1670. X            if (p[len - 2] == '\r')
  1671. X                --len;
  1672. X            if (write(ofd, p + 1, len - 1) != len - 1)
  1673. X                err("write: %s", strerror(errno));
  1674. X            break;
  1675. X        case 'g':            /* get */
  1676. X            if (state != COMMAND)
  1677. X                err("line %lu: not expecting command", lineno);
  1678. X            state = KEY;
  1679. X            command = GET;
  1680. X            break;
  1681. X        case 'p':            /* put */
  1682. X            if (state != COMMAND)
  1683. X                err("line %lu: not expecting command", lineno);
  1684. X            state = KEY;
  1685. X            command = PUT;
  1686. X            break;
  1687. X        case 'r':            /* remove */
  1688. X            if (state != COMMAND)
  1689. X                err("line %lu: not expecting command", lineno);
  1690. X            state = KEY;
  1691. X            command = REMOVE;
  1692. X            break;
  1693. X        case 's':            /* seq */
  1694. X            if (state != COMMAND)
  1695. X                err("line %lu: not expecting command", lineno);
  1696. X            if (flags == R_CURSOR) {
  1697. X                state = KEY;
  1698. X                command = SEQ;
  1699. X            } else
  1700. X                seq(dbp, &key);
  1701. X            break;
  1702. X        case 'f':
  1703. X            flags = setflags(p + 1);
  1704. X            break;
  1705. X        case 'D':            /* data file */
  1706. X            if (state != DATA)
  1707. X                err("line %lu: not expecting data", lineno);
  1708. X            data.data = rfile(p + 1, &data.size);
  1709. X            goto ldata;
  1710. X        case 'd':            /* data */
  1711. X            if (state != DATA)
  1712. X                err("line %lu: not expecting data", lineno);
  1713. X            data.data = xmalloc(p + 1, len - 1);
  1714. X            data.size = len - 1;
  1715. Xldata:            switch(command) {
  1716. X            case COMPARE:
  1717. X                compare(&keydata, &data);
  1718. X                break;
  1719. X            case PUT:
  1720. X                put(dbp, &key, &data);
  1721. X                break;
  1722. X            default:
  1723. X                err("line %lu: command doesn't take data",
  1724. X                    lineno);
  1725. X            }
  1726. X            if (type != DB_RECNO)
  1727. X                free(key.data);
  1728. X            free(data.data);
  1729. X            state = COMMAND;
  1730. X            break;
  1731. X        case 'K':            /* key file */
  1732. X            if (state != KEY)
  1733. X                err("line %lu: not expecting a key", lineno);
  1734. X            if (type == DB_RECNO)
  1735. X                err("line %lu: 'K' not available for recno",
  1736. X                    lineno);
  1737. X            key.data = rfile(p + 1, &key.size);
  1738. X            goto lkey;
  1739. X        case 'k':            /* key */
  1740. X            if (state != KEY)
  1741. X                err("line %lu: not expecting a key", lineno);
  1742. X            if (type == DB_RECNO) {
  1743. X                static recno_t recno;
  1744. X                recno = strtol(p + 1, NULL, 0);
  1745. X                key.data = &recno;
  1746. X                key.size = sizeof(recno);
  1747. X            } else {
  1748. X                key.data = xmalloc(p + 1, len - 1);
  1749. X                key.size = len - 1;
  1750. X            }
  1751. Xlkey:            switch(command) {
  1752. X            case COMPARE:
  1753. X                getdata(dbp, &key, &keydata);
  1754. X                state = DATA;
  1755. X                break;
  1756. X            case GET:
  1757. X                get(dbp, &key);
  1758. X                if (type != DB_RECNO)
  1759. X                    free(key.data);
  1760. X                state = COMMAND;
  1761. X                break;
  1762. X            case PUT:
  1763. X                state = DATA;
  1764. X                break;
  1765. X            case REMOVE:
  1766. X                rem(dbp, &key);
  1767. X                if (type != DB_RECNO)
  1768. X                    free(key.data);
  1769. X                state = COMMAND;
  1770. X                break;
  1771. X            case SEQ:
  1772. X                seq(dbp, &key);
  1773. X                if (type != DB_RECNO)
  1774. X                    free(key.data);
  1775. X                state = COMMAND;
  1776. X                break;
  1777. X            default:
  1778. X                err("line %lu: command doesn't take a key",
  1779. X                    lineno);
  1780. X            }
  1781. X            break;
  1782. X        case 'o':
  1783. X            dump(dbp, p[1] == 'r');
  1784. X            break;
  1785. X        default:
  1786. X            err("line %lu: %s: unknown command character",
  1787. X                p, lineno);
  1788. X        }
  1789. X    }
  1790. X    if (dbp->close(dbp))
  1791. X        err("db->close: %s", strerror(errno));
  1792. X    (void)close(ofd);
  1793. X    exit(0);
  1794. X}
  1795. X
  1796. X#define    NOOVERWRITE    "put failed, would overwrite key\n"
  1797. X#define    NOSUCHKEY    "get failed, no such key\n"
  1798. X
  1799. Xvoid
  1800. Xcompare(db1, db2)
  1801. X    DBT *db1, *db2;
  1802. X{
  1803. X    register size_t len;
  1804. X    register u_char *p1, *p2;
  1805. X
  1806. X    if (db1->size != db2->size)
  1807. X        printf("compare failed: key->data len %lu != data len %lu\n",
  1808. X            db1->size, db2->size);
  1809. X
  1810. X    len = MIN(db1->size, db2->size);
  1811. X    for (p1 = db1->data, p2 = db2->data; len--;)
  1812. X        if (*p1++ != *p2++) {
  1813. X            printf("compare failed at offset %d\n",
  1814. X                p1 - (u_char *)db1->data);
  1815. X            break;
  1816. X        }
  1817. X}
  1818. X
  1819. Xvoid
  1820. Xget(dbp, kp)
  1821. X    DB *dbp;
  1822. X    DBT *kp;
  1823. X{
  1824. X    DBT data;
  1825. X
  1826. X    switch(dbp->get(dbp, kp, &data, flags)) {
  1827. X    case 0:
  1828. X        (void)write(ofd, data.data, data.size);
  1829. X        break;
  1830. X    case -1:
  1831. X        err("line %lu: get: %s", lineno, strerror(errno));
  1832. X        /* NOTREACHED */
  1833. X    case 1:
  1834. X        (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1);
  1835. X        (void)fprintf(stderr, "%d: %.*s: %s\n", 
  1836. X            lineno, kp->size, kp->data, NOSUCHKEY);
  1837. X        break;
  1838. X    }
  1839. X}
  1840. X
  1841. Xvoid
  1842. Xgetdata(dbp, kp, dp)
  1843. X    DB *dbp;
  1844. X    DBT *kp, *dp;
  1845. X{
  1846. X    switch(dbp->get(dbp, kp, dp, flags)) {
  1847. X    case 0:
  1848. X        return;
  1849. X    case -1:
  1850. X        err("line %lu: getdata: %s", lineno, strerror(errno));
  1851. X        /* NOTREACHED */
  1852. X    case 1:
  1853. X        err("line %lu: get failed, no such key", lineno);
  1854. X        /* NOTREACHED */
  1855. X    }
  1856. X}
  1857. X
  1858. Xvoid
  1859. Xput(dbp, kp, dp)
  1860. X    DB *dbp;
  1861. X    DBT *kp, *dp;
  1862. X{
  1863. X    switch(dbp->put(dbp, kp, dp, flags)) {
  1864. X    case 0:
  1865. X        break;
  1866. X    case -1:
  1867. X        err("line %lu: put: %s", lineno, strerror(errno));
  1868. X        /* NOTREACHED */
  1869. X    case 1:
  1870. X        (void)write(ofd, NOOVERWRITE, sizeof(NOOVERWRITE) - 1);
  1871. X        break;
  1872. X    }
  1873. X}
  1874. X
  1875. Xvoid
  1876. Xrem(dbp, kp)
  1877. X    DB *dbp;
  1878. X    DBT *kp;
  1879. X{
  1880. X    switch(dbp->del(dbp, kp, flags)) {
  1881. X    case 0:
  1882. X        break;
  1883. X    case -1:
  1884. X        err("line %lu: get: %s", lineno, strerror(errno));
  1885. X        /* NOTREACHED */
  1886. X    case 1:
  1887. X        (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1);
  1888. X        break;
  1889. X    }
  1890. X}
  1891. X
  1892. Xvoid
  1893. Xseq(dbp, kp)
  1894. X    DB *dbp;
  1895. X    DBT *kp;
  1896. X{
  1897. X    DBT data;
  1898. X
  1899. X    switch(dbp->seq(dbp, kp, &data, flags)) {
  1900. X    case 0:
  1901. X        (void)write(ofd, data.data, data.size);
  1902. X        break;
  1903. X    case -1:
  1904. X        err("line %lu: seq: %s", lineno, strerror(errno));
  1905. X        /* NOTREACHED */
  1906. X    case 1:
  1907. X        (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1);
  1908. X        break;
  1909. X    }
  1910. X}
  1911. X
  1912. Xvoid
  1913. Xdump(dbp, rev)
  1914. X    DB *dbp;
  1915. X    int rev;
  1916. X{
  1917. X    DBT key, data;
  1918. X    int flags, nflags;
  1919. X
  1920. X    if (rev) {
  1921. X        flags = R_LAST;
  1922. X        nflags = R_PREV;
  1923. X    } else {
  1924. X        flags = R_FIRST;
  1925. X        nflags = R_NEXT;
  1926. X    }
  1927. X    for (;; flags = nflags)
  1928. X        switch(dbp->seq(dbp, &key, &data, flags)) {
  1929. X        case 0:
  1930. X            (void)write(ofd, data.data, data.size);
  1931. X            break;
  1932. X        case 1:
  1933. X            goto done;
  1934. X        case -1:
  1935. X            err("line %lu: (dump) seq: %s",
  1936. X                lineno, strerror(errno));
  1937. X            /* NOTREACHED */
  1938. X        }
  1939. Xdone:    return;
  1940. X}
  1941. X    
  1942. Xu_int
  1943. Xsetflags(s)
  1944. X    char *s;
  1945. X{
  1946. X    char *p;
  1947. X
  1948. X    for (; isspace(*s); ++s);
  1949. X    if (*s == '\n')
  1950. X        return (0);
  1951. X    if ((p = index(s, '\n')) != NULL)
  1952. X        *p = '\0';
  1953. X    if (!strcmp(s, "R_CURSOR"))
  1954. X        return (R_CURSOR);
  1955. X    if (!strcmp(s, "R_FIRST"))
  1956. X        return (R_FIRST);
  1957. X    if (!strcmp(s, "R_IAFTER"))
  1958. X        return (R_IAFTER);
  1959. X    if (!strcmp(s, "R_IBEFORE"))
  1960. X        return (R_IBEFORE);
  1961. X    if (!strcmp(s, "R_LAST"))
  1962. X        return (R_LAST);
  1963. X    if (!strcmp(s, "R_NEXT"))
  1964. X        return (R_NEXT);
  1965. X    if (!strcmp(s, "R_NOOVERWRITE"))
  1966. X        return (R_NOOVERWRITE);
  1967. X    if (!strcmp(s, "R_PREV"))
  1968. X        return (R_PREV);
  1969. X    if (!strcmp(s, "R_SETCURSOR"))
  1970. X        return (R_SETCURSOR);
  1971. X    err("line %lu: %s: unknown flag", lineno, s);
  1972. X    /* NOTREACHED */
  1973. X}
  1974. X    
  1975. XDBTYPE
  1976. Xdbtype(s)
  1977. X    char *s;
  1978. X{
  1979. X    if (!strcmp(s, "btree"))
  1980. X        return (DB_BTREE);
  1981. X    if (!strcmp(s, "hash"))
  1982. X        return (DB_HASH);
  1983. X    if (!strcmp(s, "recno"))
  1984. X        return (DB_RECNO);
  1985. X    err("%s: unknown type (use btree, hash or recno)", s);
  1986. X    /* NOTREACHED */
  1987. X}
  1988. X
  1989. Xvoid *
  1990. Xsetinfo(type, s)
  1991. X    DBTYPE type;
  1992. X    char *s;
  1993. X{
  1994. X    static BTREEINFO ib;
  1995. X    static HASHINFO ih;
  1996. X    static RECNOINFO rh;
  1997. X    char *eq;
  1998. X
  1999. X    if ((eq = index(s, '=')) == NULL)
  2000. X        err("%s: illegal structure set statement", s);
  2001. X    *eq++ = '\0';
  2002. X    if (!isdigit(*eq))
  2003. X        err("%s: structure set statement must be a number", s);
  2004. X        
  2005. X    switch(type) {
  2006. X    case DB_BTREE:
  2007. X        if (!strcmp("flags", s)) {
  2008. X            ib.flags = strtoul(eq, NULL, 0);
  2009. X            return (&ib);
  2010. X        }
  2011. X        if (!strcmp("cachesize", s)) {
  2012. X            ib.cachesize = strtoul(eq, NULL, 0);
  2013. X            return (&ib);
  2014. X        }
  2015. X        if (!strcmp("maxkeypage", s)) {
  2016. X            ib.maxkeypage = strtoul(eq, NULL, 0);
  2017. X            return (&ib);
  2018. X        }
  2019. X        if (!strcmp("minkeypage", s)) {
  2020. X            ib.minkeypage = strtoul(eq, NULL, 0);
  2021. X            return (&ib);
  2022. X        }
  2023. X        if (!strcmp("lorder", s)) {
  2024. X            ib.lorder = strtoul(eq, NULL, 0);
  2025. X            return (&ib);
  2026. X        }
  2027. X        if (!strcmp("psize", s)) {
  2028. X            ib.psize = strtoul(eq, NULL, 0);
  2029. X            return (&ib);
  2030. X        }
  2031. X        break;
  2032. X    case DB_HASH:
  2033. X        if (!strcmp("bsize", s)) {
  2034. X            ih.bsize = strtoul(eq, NULL, 0);
  2035. X            return (&ih);
  2036. X        }
  2037. X        if (!strcmp("ffactor", s)) {
  2038. X            ih.ffactor = strtoul(eq, NULL, 0);
  2039. X            return (&ih);
  2040. X        }
  2041. X        if (!strcmp("nelem", s)) {
  2042. X            ih.nelem = strtoul(eq, NULL, 0);
  2043. X            return (&ih);
  2044. X        }
  2045. X        if (!strcmp("cachesize", s)) {
  2046. X            ih.cachesize = strtoul(eq, NULL, 0);
  2047. X            return (&ih);
  2048. X        }
  2049. X        if (!strcmp("lorder", s)) {
  2050. X            ih.lorder = strtoul(eq, NULL, 0);
  2051. X            return (&ih);
  2052. X        }
  2053. X        break;
  2054. X    case DB_RECNO:
  2055. X        if (!strcmp("flags", s)) {
  2056. X            rh.flags = strtoul(eq, NULL, 0);
  2057. X            return (&rh);
  2058. X        }
  2059. X        if (!strcmp("cachesize", s)) {
  2060. X            rh.cachesize = strtoul(eq, NULL, 0);
  2061. X            return (&rh);
  2062. X        }
  2063. X        if (!strcmp("lorder", s)) {
  2064. X            rh.lorder = strtoul(eq, NULL, 0);
  2065. X            return (&rh);
  2066. X        }
  2067. X        if (!strcmp("reclen", s)) {
  2068. X            rh.reclen = strtoul(eq, NULL, 0);
  2069. X            return (&rh);
  2070. X        }
  2071. X        if (!strcmp("bval", s)) {
  2072. X            rh.bval = strtoul(eq, NULL, 0);
  2073. X            return (&rh);
  2074. X        }
  2075. X        if (!strcmp("psize", s)) {
  2076. X            rh.psize = strtoul(eq, NULL, 0);
  2077. X            return (&rh);
  2078. X        }
  2079. X        break;
  2080. X    }
  2081. X    err("%s: unknown structure value", s);
  2082. X    /* NOTREACHED */
  2083. X}
  2084. X
  2085. Xvoid *
  2086. Xrfile(name, lenp)
  2087. X    char *name;
  2088. X    size_t *lenp;
  2089. X{
  2090. X    struct stat sb;
  2091. X    void *p;
  2092. X    int fd;
  2093. X    char *np;
  2094. X
  2095. X    for (; isspace(*name); ++name);
  2096. X    if ((np = index(name, '\n')) != NULL)
  2097. X        *np = '\0';
  2098. X    if ((fd = open(name, O_RDONLY, 0)) < 0 ||
  2099. X        fstat(fd, &sb))
  2100. X        err("%s: %s\n", name, strerror(errno));
  2101. X    if (sb.st_size > (off_t)SIZE_T_MAX)
  2102. X        err("%s: %s\n", name, strerror(E2BIG));
  2103. X    if ((p = malloc((u_int)sb.st_size)) == NULL)
  2104. X        err("%s", strerror(errno));
  2105. X    (void)read(fd, p, (int)sb.st_size);
  2106. X    *lenp = sb.st_size;
  2107. X    (void)close(fd);
  2108. X    return (p);
  2109. X}
  2110. X
  2111. Xvoid *
  2112. Xxmalloc(text, len)
  2113. X    char *text;
  2114. X    size_t len;
  2115. X{
  2116. X    void *p;
  2117. X
  2118. X    if ((p = malloc(len)) == NULL)
  2119. X        err("%s", strerror(errno));
  2120. X    memmove(p, text, len);
  2121. X    return (p);
  2122. X}
  2123. X
  2124. Xvoid
  2125. Xusage()
  2126. X{
  2127. X    (void)fprintf(stderr,
  2128. X        "usage: dbtest [-f file] [-i info] [-o file] type script\n");
  2129. X    exit(1);
  2130. X}
  2131. X
  2132. X#if __STDC__
  2133. X#include <stdarg.h>
  2134. X#else
  2135. X#include <varargs.h>
  2136. X#endif
  2137. X
  2138. Xvoid
  2139. X#if __STDC__
  2140. Xerr(const char *fmt, ...)
  2141. X#else
  2142. Xerr(fmt, va_alist)
  2143. X    char *fmt;
  2144. X        va_dcl
  2145. X#endif
  2146. X{
  2147. X    va_list ap;
  2148. X#if __STDC__
  2149. X    va_start(ap, fmt);
  2150. X#else
  2151. X    va_start(ap);
  2152. X#endif
  2153. X    (void)fprintf(stderr, "dbtest: ");
  2154. X    (void)vfprintf(stderr, fmt, ap);
  2155. X    va_end(ap);
  2156. X    (void)fprintf(stderr, "\n");
  2157. X    exit(1);
  2158. X    /* NOTREACHED */
  2159. X}
  2160. END_OF_FILE
  2161. if test 14197 -ne `wc -c <'test/dbtest.c'`; then
  2162.     echo shar: \"'test/dbtest.c'\" unpacked with wrong size!
  2163. fi
  2164. # end of 'test/dbtest.c'
  2165. fi
  2166. if test -f 'test/run.test' -a "${1}" != "-c" ; then 
  2167.   echo shar: Will not clobber existing file \"'test/run.test'\"
  2168. else
  2169. echo shar: Extracting \"'test/run.test'\" \(13894 characters\)
  2170. sed "s/^X//" >'test/run.test' <<'END_OF_FILE'
  2171. X#!/bin/sh -
  2172. X#
  2173. X#    @(#)run.test    8.1 (Berkeley) 6/4/93
  2174. X#
  2175. X
  2176. X# db regression tests
  2177. X
  2178. Xmain()
  2179. X{
  2180. X    DICT=/usr/share/dict/words
  2181. X    PROG=obj/dbtest
  2182. X    TMP1=t1
  2183. X    TMP2=t2
  2184. X    TMP3=t3
  2185. X
  2186. X    test1
  2187. X    test2
  2188. X    test3
  2189. X    test4
  2190. X    test5
  2191. X    test6
  2192. X    test7
  2193. X    test8
  2194. X    test9
  2195. X    test10
  2196. X    test11
  2197. X    test12
  2198. X    test13
  2199. X    test20
  2200. X    rm -f $TMP1 $TMP2 $TMP3
  2201. X    exit 0
  2202. X}
  2203. X
  2204. X# Take the first hundred entries in the dictionary, and make them
  2205. X# be key/data pairs.
  2206. Xtest1()
  2207. X{
  2208. X    printf "Test 1: btree, hash: small key, small data pairs\n"
  2209. X    sed 200q $DICT > $TMP1
  2210. X    for type in btree hash; do
  2211. X        rm -f $TMP2 $TMP3
  2212. X        for i in `sed 200q $DICT`; do
  2213. X            printf "p\nk%s\nd%s\ng\nk%s\n" $i $i $i
  2214. X        done > $TMP2
  2215. X        $PROG -o $TMP3 $type $TMP2
  2216. X        if (cmp -s $TMP1 $TMP3) ; then :
  2217. X        else
  2218. X            printf "test1: type %s: failed\n" $type
  2219. X            exit 1
  2220. X        fi
  2221. X    done
  2222. X    printf "Test 1: recno: small key, small data pairs\n"
  2223. X    rm -f $TMP2 $TMP3
  2224. X    sed 200q $DICT |
  2225. X    awk '{ 
  2226. X        ++i;
  2227. X        printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
  2228. X    }' > $TMP2
  2229. X    $PROG -o $TMP3 recno $TMP2
  2230. X    if (cmp -s $TMP1 $TMP3) ; then :
  2231. X    else
  2232. X        printf "test1: type recno: failed\n"
  2233. X        exit 1
  2234. X    fi
  2235. X}
  2236. X
  2237. X# Take the first 200 entries in the dictionary, and give them
  2238. X# each a medium size data entry.
  2239. Xtest2()
  2240. X{
  2241. X    printf "Test 2: btree, hash: small key, medium data pairs\n"
  2242. X    mdata=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
  2243. X    echo $mdata |
  2244. X    awk '{ for (i = 1; i < 201; ++i) print $0 }' > $TMP1
  2245. X    for type in hash btree; do
  2246. X        rm -f $TMP2 $TMP3
  2247. X        for i in `sed 200q $DICT`; do
  2248. X            printf "p\nk%s\nd%s\ng\nk%s\n" $i $mdata $i
  2249. X        done > $TMP2
  2250. X        $PROG -o $TMP3 $type $TMP2
  2251. X        if (cmp -s $TMP1 $TMP3) ; then :
  2252. X        else
  2253. X            printf "test2: type %s: failed\n" $type
  2254. X            exit 1
  2255. X        fi
  2256. X    done
  2257. X    printf "Test 2: recno: small key, medium data pairs\n"
  2258. X    rm -f $TMP2 $TMP3
  2259. X    echo $mdata | 
  2260. X    awk '{  for (i = 1; i < 201; ++i)
  2261. X        printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
  2262. X    }' > $TMP2
  2263. X    $PROG -o $TMP3 recno $TMP2
  2264. X    if (cmp -s $TMP1 $TMP3) ; then :
  2265. X    else
  2266. X        printf "test2: type recno: failed\n"
  2267. X        exit 1
  2268. X    fi
  2269. X}
  2270. X
  2271. X# Insert the programs in /bin with their paths as their keys.
  2272. Xtest3()
  2273. X{
  2274. X    printf "Test 3: hash: small key, big data pairs\n"
  2275. X    rm -f $TMP1
  2276. X    (find /bin -type f -print | xargs cat) > $TMP1
  2277. X    for type in hash; do
  2278. X        rm -f $TMP2 $TMP3
  2279. X        for i in `find /bin -type f -print`; do
  2280. X            printf "p\nk%s\nD%s\ng\nk%s\n" $i $i $i
  2281. X        done > $TMP2
  2282. X        $PROG -o $TMP3 $type $TMP2
  2283. X        if (cmp -s $TMP1 $TMP3) ; then :
  2284. X        else
  2285. X            printf "test3: %s: page size %d: failed\n" \
  2286. X                $type $psize
  2287. X            exit 1
  2288. X        fi
  2289. X    done
  2290. X    printf "Test 3: btree: small key, big data pairs\n"
  2291. X    for psize in 512 16384 65536; do
  2292. X        printf "\tpage size %d\n" $psize
  2293. X        for type in btree; do
  2294. X            rm -f $TMP2 $TMP3
  2295. X            for i in `find /bin -type f -print`; do
  2296. X                printf "p\nk%s\nD%s\ng\nk%s\n" $i $i $i
  2297. X            done > $TMP2
  2298. X            $PROG -i psize=$psize -o $TMP3 $type $TMP2
  2299. X            if (cmp -s $TMP1 $TMP3) ; then :
  2300. X            else
  2301. X                printf "test3: %s: page size %d: failed\n" \
  2302. X                    $type $psize
  2303. X                exit 1
  2304. X            fi
  2305. X        done
  2306. X    done
  2307. X    printf "Test 3: recno: big data pairs\n"
  2308. X    rm -f $TMP2 $TMP3
  2309. X    find /bin -type f -print | 
  2310. X    awk '{
  2311. X        ++i;
  2312. X        printf("p\nk%d\nD%s\ng\nk%d\n", i, $0, i);
  2313. X    }' > $TMP2
  2314. X    for psize in 512 16384 65536; do
  2315. X        printf "\tpage size %d\n" $psize
  2316. X        $PROG -i psize=$psize -o $TMP3 recno $TMP2
  2317. X        if (cmp -s $TMP1 $TMP3) ; then :
  2318. X        else
  2319. X            printf "test3: recno: page size %d: failed\n" $psize
  2320. X            exit 1
  2321. X        fi
  2322. X    done
  2323. X}
  2324. X
  2325. X# Do random recno entries.
  2326. Xtest4()
  2327. X{
  2328. X    printf "Test 4: recno: random entries\n"
  2329. X    echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
  2330. X    awk '{
  2331. X        for (i = 37; i <= 37 + 88 * 17; i += 17)
  2332. X            printf("input key %d: %.*s\n", i, i % 41, $0);
  2333. X        for (i = 1; i <= 15; ++i)
  2334. X            printf("input key %d: %.*s\n", i, i % 41, $0);
  2335. X        for (i = 19234; i <= 19234 + 61 * 27; i += 27)
  2336. X            printf("input key %d: %.*s\n", i, i % 41, $0);
  2337. X        exit
  2338. X    }' > $TMP1
  2339. X    rm -f TMP2 $TMP3
  2340. X    cat $TMP1 |
  2341. X    awk 'BEGIN {
  2342. X            i = 37;
  2343. X            incr = 17;
  2344. X        }
  2345. X        {
  2346. X            printf("p\nk%d\nd%s\n", i, $0);
  2347. X            if (i == 19234 + 61 * 27)
  2348. X                exit;
  2349. X            if (i == 37 + 88 * 17) {
  2350. X                i = 1;
  2351. X                incr = 1;
  2352. X            } else if (i == 15) {
  2353. X                i = 19234;
  2354. X                incr = 27;
  2355. X            } else
  2356. X                i += incr;
  2357. X        }
  2358. X        END {
  2359. X            for (i = 37; i <= 37 + 88 * 17; i += 17)
  2360. X                printf("g\nk%d\n", i);
  2361. X            for (i = 1; i <= 15; ++i)
  2362. X                printf("g\nk%d\n", i);
  2363. X            for (i = 19234; i <= 19234 + 61 * 27; i += 27)
  2364. X                printf("g\nk%d\n", i);
  2365. X        }' > $TMP2
  2366. X    $PROG -o $TMP3 recno $TMP2
  2367. X    if (cmp -s $TMP1 $TMP3) ; then :
  2368. X    else
  2369. X        printf "test4: type recno: failed\n"
  2370. X        exit 1
  2371. X    fi
  2372. X}
  2373. X
  2374. X# Do reverse order recno entries.
  2375. Xtest5()
  2376. X{
  2377. X    printf "Test 5: recno: reverse order entries\n"
  2378. X    echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
  2379. X    awk ' {
  2380. X        for (i = 1500; i; --i)
  2381. X            printf("input key %d: %.*s\n", i, i % 34, $0);
  2382. X        exit;
  2383. X    }' > $TMP1
  2384. X    rm -f TMP2 $TMP3
  2385. X    cat $TMP1 |
  2386. X    awk 'BEGIN {
  2387. X            i = 1500;
  2388. X        }
  2389. X        {
  2390. X            printf("p\nk%d\nd%s\n", i, $0);
  2391. X            --i;
  2392. X        }
  2393. X        END {
  2394. X            for (i = 1500; i; --i) 
  2395. X                printf("g\nk%d\n", i);
  2396. X        }' > $TMP2
  2397. X    $PROG -o $TMP3 recno $TMP2
  2398. X    if (cmp -s $TMP1 $TMP3) ; then :
  2399. X    else
  2400. X        printf "test5: type recno: failed\n"
  2401. X        exit 1
  2402. X    fi
  2403. X}
  2404. X        
  2405. X# Do alternating order recno entries.
  2406. Xtest6()
  2407. X{
  2408. X    printf "Test 6: recno: alternating order entries\n"
  2409. X    echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
  2410. X    awk ' {
  2411. X        for (i = 1; i < 1200; i += 2)
  2412. X            printf("input key %d: %.*s\n", i, i % 34, $0);
  2413. X        for (i = 2; i < 1200; i += 2)
  2414. X            printf("input key %d: %.*s\n", i, i % 34, $0);
  2415. X        exit;
  2416. X    }' > $TMP1
  2417. X    rm -f TMP2 $TMP3
  2418. X    cat $TMP1 |
  2419. X    awk 'BEGIN {
  2420. X            i = 1;
  2421. X            even = 0;
  2422. X        }
  2423. X        {
  2424. X            printf("p\nk%d\nd%s\n", i, $0);
  2425. X            i += 2;
  2426. X            if (i >= 1200) {
  2427. X                if (even == 1)
  2428. X                    exit;
  2429. X                even = 1;
  2430. X                i = 2;
  2431. X            }
  2432. X        }
  2433. X        END {
  2434. X            for (i = 1; i < 1200; ++i) 
  2435. X                printf("g\nk%d\n", i);
  2436. X        }' > $TMP2
  2437. X    $PROG -o $TMP3 recno $TMP2
  2438. X    sort -o $TMP1 $TMP1
  2439. X    sort -o $TMP3 $TMP3
  2440. X    if (cmp -s $TMP1 $TMP3) ; then :
  2441. X    else
  2442. X        printf "test6: type recno: failed\n"
  2443. X        exit 1
  2444. X    fi
  2445. X}
  2446. X
  2447. X# Delete cursor record
  2448. Xtest7()
  2449. X{
  2450. X    printf "Test 7: btree, recno: delete cursor record\n"
  2451. X    echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
  2452. X    awk '{
  2453. X        for (i = 1; i <= 120; ++i)
  2454. X            printf("%05d: input key %d: %s\n", i, i, $0);
  2455. X        printf("%05d: input key %d: %s\n", 120, 120, $0);
  2456. X        printf("get failed, no such key\n");
  2457. X        printf("%05d: input key %d: %s\n", 1, 1, $0);
  2458. X        printf("%05d: input key %d: %s\n", 2, 2, $0);
  2459. X        exit;
  2460. X    }' > $TMP1
  2461. X    rm -f TMP2 $TMP3
  2462. X
  2463. X    for type in btree recno; do
  2464. X        cat $TMP1 |
  2465. X        awk '{
  2466. X            if (i == 120)
  2467. X                exit;
  2468. X            printf("p\nk%d\nd%s\n", ++i, $0);
  2469. X        }
  2470. X        END {
  2471. X            printf("fR_NEXT\n");
  2472. X            for (i = 1; i <= 120; ++i)
  2473. X                printf("s\n");
  2474. X            printf("fR_CURSOR\ns\nk120\n");
  2475. X            printf("r\nk120\n");
  2476. X            printf("fR_NEXT\ns\n");
  2477. X            printf("fR_CURSOR\ns\nk1\n");
  2478. X            printf("r\nk1\n");
  2479. X            printf("fR_FIRST\ns\n");
  2480. X        }' > $TMP2
  2481. X        $PROG -o $TMP3 recno $TMP2
  2482. X        if (cmp -s $TMP1 $TMP3) ; then :
  2483. X        else
  2484. X            printf "test7: type $type: failed\n"
  2485. X            exit 1
  2486. X        fi
  2487. X    done
  2488. X}
  2489. X
  2490. X# Make sure that overflow pages are reused.
  2491. Xtest8()
  2492. X{
  2493. X    printf "Test 8: btree, hash: repeated small key, big data pairs\n"
  2494. X    rm -f $TMP1
  2495. X    awk 'BEGIN {
  2496. X        for (i = 1; i <= 10; ++i) {
  2497. X            printf("p\nkkey1\nD/bin/sh\n");
  2498. X            printf("p\nkkey2\nD/bin/csh\n");
  2499. X            if (i % 8 == 0) {
  2500. X                printf("c\nkkey2\nD/bin/csh\n");
  2501. X                printf("c\nkkey1\nD/bin/sh\n");
  2502. X                printf("e\t%d of 10 (comparison)\r\n", i);
  2503. X            } else
  2504. X                printf("e\t%d of 10             \r\n", i);
  2505. X            printf("r\nkkey1\nr\nkkey2\n");
  2506. X        }
  2507. X        printf("e\n");
  2508. X        printf("eend of test8 run\n");
  2509. X    }' > $TMP1
  2510. X    $PROG btree $TMP1
  2511. X    $PROG hash $TMP1
  2512. X    # No explicit test for success.
  2513. X}
  2514. X
  2515. X# Test btree duplicate keys
  2516. Xtest9()
  2517. X{
  2518. X    printf "Test 9: btree: duplicate keys\n"
  2519. X    echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
  2520. X    awk '{
  2521. X        for (i = 1; i <= 543; ++i)
  2522. X            printf("%05d: input key %d: %s\n", i, i, $0);
  2523. X        exit;
  2524. X    }' > $TMP1
  2525. X    rm -f TMP2 $TMP3
  2526. X
  2527. X    for type in btree; do
  2528. X        cat $TMP1 | 
  2529. X        awk '{
  2530. X            if (i++ % 2)
  2531. X                printf("p\nkduplicatekey\nd%s\n", $0);
  2532. X            else
  2533. X                printf("p\nkunique%dkey\nd%s\n", i, $0);
  2534. X        }
  2535. X        END {
  2536. X                printf("o\n");
  2537. X        }' > $TMP2
  2538. X        $PROG -iflags=1 -o $TMP3 $type $TMP2
  2539. X        sort -o $TMP3 $TMP3
  2540. X        if (cmp -s $TMP1 $TMP3) ; then :
  2541. X        else
  2542. X            printf "test9: type $type: failed\n"
  2543. X            exit 1
  2544. X        fi
  2545. X    done
  2546. X}
  2547. X
  2548. X# Test use of cursor flags without initialization
  2549. Xtest10()
  2550. X{
  2551. X    printf "Test 10: btree, recno: test cursor flag use\n"
  2552. X    echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
  2553. X    awk '{
  2554. X        for (i = 1; i <= 20; ++i)
  2555. X            printf("%05d: input key %d: %s\n", i, i, $0);
  2556. X        exit;
  2557. X    }' > $TMP1
  2558. X    rm -f TMP2 $TMP3
  2559. X
  2560. X    # Test that R_CURSOR doesn't succeed before cursor initialized
  2561. X    for type in btree recno; do
  2562. X        cat $TMP1 |
  2563. X        awk '{
  2564. X            if (i == 10)
  2565. X                exit;
  2566. X            printf("p\nk%d\nd%s\n", ++i, $0);
  2567. X        }
  2568. X        END {
  2569. X            printf("fR_CURSOR\nr\nk1\n");
  2570. X            printf("eR_CURSOR SHOULD HAVE FAILED\n");
  2571. X        }' > $TMP2
  2572. X        $PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1
  2573. X        if [ -s $TMP3 ] ; then
  2574. X            printf "Test 10: delete: R_CURSOR SHOULD HAVE FAILED\n"
  2575. X            exit 1
  2576. X        fi
  2577. X    done
  2578. X    for type in btree recno; do
  2579. X        cat $TMP1 |
  2580. X        awk '{
  2581. X            if (i == 10)
  2582. X                exit;
  2583. X            printf("p\nk%d\nd%s\n", ++i, $0);
  2584. X        }
  2585. X        END {
  2586. X            printf("fR_CURSOR\np\nk1\ndsome data\n");
  2587. X            printf("eR_CURSOR SHOULD HAVE FAILED\n");
  2588. X        }' > $TMP2
  2589. X        $PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1
  2590. X        if [ -s $TMP3 ] ; then
  2591. X            printf "Test 10: put: R_CURSOR SHOULD HAVE FAILED\n"
  2592. X            exit 1
  2593. X        fi
  2594. X    done
  2595. X}
  2596. X
  2597. X# Test insert in reverse order.
  2598. Xtest11()
  2599. X{
  2600. X    printf "Test 11: recno: reverse order insert\n"
  2601. X    echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
  2602. X    awk '{
  2603. X        for (i = 1; i <= 779; ++i)
  2604. X            printf("%05d: input key %d: %s\n", i, i, $0);
  2605. X        exit;
  2606. X    }' > $TMP1
  2607. X    rm -f TMP2 $TMP3
  2608. X
  2609. X    for type in recno; do
  2610. X        cat $TMP1 |
  2611. X        awk '{
  2612. X            if (i == 0) {
  2613. X                i = 1;
  2614. X                printf("p\nk1\nd%s\n", $0);
  2615. X                printf("%s\n", "fR_IBEFORE");
  2616. X            } else
  2617. X                printf("p\nk1\nd%s\n", $0);
  2618. X        }
  2619. X        END {
  2620. X                printf("or\n");
  2621. X        }' > $TMP2
  2622. X        $PROG -o $TMP3 $type $TMP2
  2623. X        if (cmp -s $TMP1 $TMP3) ; then :
  2624. X        else
  2625. X            printf "test11: type $type: failed\n"
  2626. X            exit 1
  2627. X        fi
  2628. X    done
  2629. X}
  2630. X
  2631. X# Take the first 20000 entries in the dictionary, reverse them, and give
  2632. X# them each a small size data entry.  Use a small page size to make sure
  2633. X# the btree split code gets hammered.
  2634. Xtest12()
  2635. X{
  2636. X    printf "Test 12: btree: lots of keys, small page size\n"
  2637. X    mdata=abcdefghijklmnopqrstuvwxy
  2638. X    echo $mdata |
  2639. X    awk '{ for (i = 1; i < 20001; ++i) print $0 }' > $TMP1
  2640. X    for type in btree; do
  2641. X        rm -f $TMP2 $TMP3
  2642. X        for i in `sed 20000q $DICT | rev`; do
  2643. X            printf "p\nk%s\nd%s\ng\nk%s\n" $i $mdata $i
  2644. X        done > $TMP2
  2645. X        $PROG -i psize=512 -o $TMP3 $type $TMP2
  2646. X        if (cmp -s $TMP1 $TMP3) ; then :
  2647. X        else
  2648. X            printf "test12: type %s: failed\n" $type
  2649. X            exit 1
  2650. X        fi
  2651. X    done
  2652. X}
  2653. X
  2654. X# Test different byte orders.
  2655. Xtest13()
  2656. X{
  2657. X    printf "Test 13: btree, hash: differing byte orders\n"
  2658. X    sed 50q $DICT > $TMP1
  2659. X    for order in 1234 4321; do
  2660. X        for type in btree hash; do
  2661. X            rm -f byte.file $TMP2 $TMP3
  2662. X            for i in `sed 50q $DICT`; do
  2663. X                printf "p\nk%s\nd%s\ng\nk%s\n" $i $i $i
  2664. X            done > $TMP2
  2665. X            $PROG -ilorder=$order -f byte.file -o $TMP3 $type $TMP2
  2666. X            if (cmp -s $TMP1 $TMP3) ; then :
  2667. X            else
  2668. X                printf "test13: %s/%s put failed\n" $type $order
  2669. X                exit 1
  2670. X            fi
  2671. X            for i in `sed 50q $DICT`; do
  2672. X                printf "g\nk%s\n" $i
  2673. X            done > $TMP2
  2674. X            $PROG -ilorder=$order -f byte.file -o $TMP3 $type $TMP2
  2675. X            if (cmp -s $TMP1 $TMP3) ; then :
  2676. X            else
  2677. X                printf "test13: %s/%s get failed\n" $type $order
  2678. X                exit 1
  2679. X            fi
  2680. X        done
  2681. X    done
  2682. X    rm -f byte.file
  2683. X}
  2684. X
  2685. X# Try a variety of bucketsizes and fill factors for hashing
  2686. Xtest20()
  2687. X{
  2688. X    printf\
  2689. X    "Test 20: hash: bucketsize, fill factor; nelem 25000 cachesize 65536\n"
  2690. X    awk 'BEGIN {
  2691. X        for (i = 1; i <= 10000; ++i)
  2692. X            printf("%.*s\n", i % 34,
  2693. X            "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg");
  2694. X    }' > $TMP1
  2695. X    sed 10000q $DICT |
  2696. X    awk '{
  2697. X        ++i;
  2698. X        printf("p\nk%s\nd%.*s\n", $0, i % 34,
  2699. X            "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg");
  2700. X    }' > $TMP2
  2701. X    sed 10000q $DICT |
  2702. X    awk '{
  2703. X        ++i;
  2704. X        printf("g\nk%s\n", $0);
  2705. X    }' >> $TMP2
  2706. X    bsize=256
  2707. X    for ffactor in 11 14 21; do
  2708. X        printf "\tbucketsize %d, fill factor %d\n" $bsize $ffactor
  2709. X        $PROG -o$TMP3 \
  2710. X            -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
  2711. X            hash $TMP2
  2712. X        if (cmp -s $TMP1 $TMP3) ; then :
  2713. X        else
  2714. X            printf "test20: type hash:\
  2715. Xbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
  2716. X            exit 1
  2717. X        fi
  2718. X    done
  2719. X    bsize=512
  2720. X    for ffactor in 21 28 43; do
  2721. X        printf "\tbucketsize %d, fill factor %d\n" $bsize $ffactor
  2722. X        $PROG -o$TMP3 \
  2723. X            -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
  2724. X            hash $TMP2
  2725. X        if (cmp -s $TMP1 $TMP3) ; then :
  2726. X        else
  2727. X            printf "test20: type hash:\
  2728. Xbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
  2729. X            exit 1
  2730. X        fi
  2731. X    done
  2732. X    bsize=1024
  2733. X    for ffactor in 43 57 85; do
  2734. X        printf "\tbucketsize %d, fill factor %d\n" $bsize $ffactor
  2735. X        $PROG -o$TMP3 \
  2736. X            -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
  2737. X            hash $TMP2
  2738. X        if (cmp -s $TMP1 $TMP3) ; then :
  2739. X        else
  2740. X            printf "test20: type hash:\
  2741. Xbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
  2742. X            exit 1
  2743. X        fi
  2744. X    done
  2745. X    bsize=2048
  2746. X    for ffactor in 85 114 171; do
  2747. X        printf "\tbucketsize %d, fill factor %d\n" $bsize $ffactor
  2748. X        $PROG -o$TMP3 \
  2749. X            -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
  2750. X            hash $TMP2
  2751. X        if (cmp -s $TMP1 $TMP3) ; then :
  2752. X        else
  2753. X            printf "test20: type hash:\
  2754. Xbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
  2755. X            exit 1
  2756. X        fi
  2757. X    done
  2758. X    bsize=4096
  2759. X    for ffactor in 171 228 341; do
  2760. X        printf "\tbucketsize %d, fill factor %d\n" $bsize $ffactor
  2761. X        $PROG -o$TMP3 \
  2762. X            -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
  2763. X            hash $TMP2
  2764. X        if (cmp -s $TMP1 $TMP3) ; then :
  2765. X        else
  2766. X            printf "test20: type hash:\
  2767. Xbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
  2768. X            exit 1
  2769. X        fi
  2770. X    done
  2771. X    bsize=8192
  2772. X    for ffactor in 341 455 683; do
  2773. X        printf "\tbucketsize %d, fill factor %d\n" $bsize $ffactor
  2774. X        $PROG -o$TMP3 \
  2775. X            -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
  2776. X            hash $TMP2
  2777. X        if (cmp -s $TMP1 $TMP3) ; then :
  2778. X        else
  2779. X            printf "test20: type hash:\
  2780. Xbsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
  2781. X            exit 1
  2782. X        fi
  2783. X    done
  2784. X}
  2785. X
  2786. Xmain
  2787. END_OF_FILE
  2788. if test 13894 -ne `wc -c <'test/run.test'`; then
  2789.     echo shar: \"'test/run.test'\" unpacked with wrong size!
  2790. fi
  2791. # end of 'test/run.test'
  2792. fi
  2793. echo shar: End of archive 5 \(of 9\).
  2794. cp /dev/null ark5isdone
  2795. MISSING=""
  2796. for I in 1 2 3 4 5 6 7 8 9 ; do
  2797.     if test ! -f ark${I}isdone ; then
  2798.     MISSING="${MISSING} ${I}"
  2799.     fi
  2800. done
  2801. if test "${MISSING}" = "" ; then
  2802.     echo You have unpacked all 9 archives.
  2803.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2804. else
  2805.     echo You still need to unpack the following archives:
  2806.     echo "        " ${MISSING}
  2807. fi
  2808. ##  End of shell archive.
  2809. exit 0
  2810.