home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / elm / elm2.4 / hdrs / ndbz.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-10  |  5.0 KB  |  150 lines

  1.  
  2. /* $Id: ndbz.h,v 5.2 1992/10/11 01:46:35 syd Exp $ */
  3.  
  4. /*******************************************************************************
  5.  *  The Elm Mail System  -  $Revision: 5.2 $   $State: Exp $
  6.  *
  7.  *             Copyright (c) 1988-1992 USENET Community Trust
  8.  *             Copyright (c) 1986,1987 Dave Taylor
  9.  *******************************************************************************
  10.  * Bug reports, patches, comments, suggestions should be sent to:
  11.  *
  12.  *    Syd Weinstein, Elm Coordinator
  13.  *    elm@DSI.COM            dsinc!elm
  14.  *
  15.  *******************************************************************************
  16.  * $Log: ndbz.h,v $
  17.  * Revision 5.2  1992/10/11  01:46:35  syd
  18.  * change dbm name to dbz to avoid conflicts with partial call
  19.  * ins from shared librarys, and from mixing code with yp code.
  20.  * From: Syd via prompt from Jess Anderson
  21.  *
  22.  * Revision 5.1  1992/10/03  22:34:39  syd
  23.  * Initial checkin as of 2.4 Release at PL0
  24.  *
  25.  *
  26.  ******************************************************************************/
  27.  
  28. /**  define file for ndbz for mail system.  **/
  29.  
  30. /*
  31.  * Stdio buffer for .pag reads.  Buffering more than about 16 does not help
  32.  * significantly at the densities we try to maintain, and the much larger
  33.  * buffers that most stdios default to are much more expensive to fill.
  34.  * With small buffers, stdio is performance-competitive with raw read(),
  35.  * and it's much more portable.
  36.  */
  37. #ifndef NPAGBUF
  38. #define    NPAGBUF    16
  39. #endif
  40.  
  41. /*
  42.  * Stdio buffer for base-file reads.
  43.  */
  44. #ifndef SHISTBUF
  45. #define    SHISTBUF    512
  46. #endif
  47.  
  48. /* for dbz and ndbz */
  49. typedef struct {
  50.     char *dptr;
  51.     int dsize;
  52. } datum;
  53.  
  54. /*
  55.  * ANSI C says an offset into a file is a long, not an off_t, for some
  56.  * reason.  This actually does simplify life a bit, but it's still nice
  57.  * to have a distinctive name for it.  Beware, this is just for readability,
  58.  * don't try to change this.
  59.  */
  60. #define    of_t    long
  61. #define    SOF    (sizeof(of_t))
  62.  
  63. /*
  64.  * We read configuration info from the .dir file into this structure,
  65.  * so we can avoid wired-in assumptions for an existing database.
  66.  *
  67.  * Among the info is a record of recent peak usages, so that a new table
  68.  * size can be chosen intelligently when rebuilding.  10 is a good
  69.  * number of usages to keep, since news displays marked fluctuations
  70.  * in volume on a 7-day cycle.
  71.  */
  72. struct dbzconfig {
  73.     int olddbz;        /* .dir file empty but .pag not? */
  74.     of_t tsize;        /* table size */
  75. #    ifndef NMEMORY
  76. #    define    NMEMORY    10    /* # days of use info to remember */
  77. #    endif
  78. #    define    NUSEDS    (1+NMEMORY)
  79.     of_t used[NUSEDS];    /* entries used today, yesterday, ... */
  80.     int valuesize;        /* size of table values, == SOF */
  81.     int bytemap[SOF];    /* byte-order map */
  82.     char casemap;        /* case-mapping algorithm (see cipoint()) */
  83.     char fieldsep;        /* field separator in base file, if any */
  84.     of_t tagenb;        /* unshifted tag-enable bit */
  85.     of_t tagmask;        /* unshifted tag mask */
  86.     int tagshift;        /* shift count for tagmask and tagenb */
  87. };
  88.  
  89. /*
  90.  * Data structure for recording info about searches.
  91.  */
  92. struct searcher {
  93.     of_t place;        /* current location in file */
  94.     int tabno;        /* which table we're in */
  95.     int run;        /* how long we'll stay in this table */
  96.     long hash;        /* the key's hash code (for optimization) */
  97.     of_t tag;        /* tag we are looking for */
  98.     int seen;        /* have we examined current location? */
  99.     int aborted;        /* has i/o error aborted search? */
  100. };
  101. typedef struct dbz {
  102.     FILE *dbz_basef;        /* descriptor for base file */
  103.     char *dbz_basefname;        /* name for not-yet-opened base file */
  104.     FILE *dbz_dirf;            /* descriptor for .dir file */
  105.     int dbz_dirronly;        /* dirf open read-only? */
  106.     FILE *dbz_pagf;            /* descriptor for .pag file */
  107.     of_t dbz_pagpos;        /* posn in pagf; only search may set != -1 */
  108.     int dbz_pagronly;        /* pagf open read-only? */
  109.     of_t *dbz_corepag;        /* incore version of .pag file, if any */
  110.     FILE *dbz_bufpagf;        /* well-buffered pagf, for incore rewrite */
  111.     of_t dbz_tagbits;        /* pre-shifted tag mask */
  112.     of_t dbz_taghere;        /* pre-shifted tag-enable bit */
  113.     of_t dbz_tagboth;        /* tagbits|taghere */
  114.     struct dbzconfig dbz_conf;
  115.     int dbz_incore;
  116.     of_t dbz_pagbuf[NPAGBUF];
  117.     char dbz_basebuf[SHISTBUF];
  118.     struct searcher dbz_srch;
  119.     struct searcher *dbz_prevp;    /* &srch or FRESH */
  120.     int dbz_mybmap[SOF];        /* my byte order (see mybytemap()) */
  121.     int dbz_bytesame;        /* is database order same as mine? */
  122.     int dbz_debug;            /* controlled by dbzdebug() */
  123.     int dbz_written;        /* has a store() been done? */
  124.     } DBZ;
  125.  
  126. /* standard dbz functions */
  127. extern DBZ *dbz_open();
  128. extern datum dbz_fetch();
  129. extern int dbz_store();
  130. extern int dbz_delete();    /* not in dbz */
  131. extern datum dbz_firstkey();    /* not in dbz */
  132. extern datum dbz_nextkey();    /* not in dbz */
  133. extern int dbz_close();        /* in dbz, but not in old dbm */
  134.  
  135. /* new stuff for dbz */
  136. extern DBZ *dbz_fresh();
  137. extern DBZ *dbz_again();
  138. extern int dbz_sync();
  139. extern long dbz_size();
  140. extern int dbz_incore();
  141. extern int dbz_cancel();
  142. extern int dbz_debug();
  143.  
  144. /*
  145.  * In principle we could handle unlimited-length keys by operating a chunk
  146.  * at a time, but it's not worth it in practice.  Setting a nice large
  147.  * bound on them simplifies the code and doesn't hurt anything.
  148.  */
  149. #define DBZMAXKEY    255
  150.