root/libutil/dbop.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


   1 /*
   2  * Copyright (c) 1997, 1998, 1999, 2000, 2001, 2006, 2009, 2010
   3  *      Tama Communications Corporation
   4  *
   5  * This file is part of GNU GLOBAL.
   6  *
   7  * This program is free software: you can redistribute it and/or modify
   8  * it under the terms of the GNU General Public License as published by
   9  * the Free Software Foundation, either version 3 of the License, or
  10  * (at your option) any later version.
  11  * 
  12  * This program is distributed in the hope that it will be useful,
  13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15  * GNU General Public License for more details.
  16  * 
  17  * You should have received a copy of the GNU General Public License
  18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19  */
  20 
  21 #ifndef _DBOP_H_
  22 #define _DBOP_H_
  23 
  24 #include "gparam.h"
  25 #ifdef USE_DB185_COMPAT
  26 #include <db_185.h>
  27 #else
  28 #include "db.h"
  29 #endif
  30 #include "regex.h"
  31 #include "strbuf.h"
  32 
  33 #if defined(_WIN32) && !defined(__CYGWIN__)
  34 typedef void* HANDLE;
  35 #endif
  36 
  37 #define DBOP_PAGESIZE   8192
  38 #define VERSIONKEY      " __.VERSION"
  39 
  40 typedef struct {
  41         /**
  42          * @name (1) COMMON PART
  43          */
  44         /** @{ */
  45         int mode;                       /**< 0:read, 1:create, 2:modify */
  46         int openflags;                  /**< flags of @NAME{xxxx_open()} */
  47         int ioflags;                    /**< flags of @NAME{xxxx_first()} */
  48         char *lastdat;                  /**< the data of last located record */
  49         int lastsize;                   /**< the size of the lastdat */
  50         char *lastkey;                  /**< the key of last located record */
  51         int lastkeysize;                /**< the size of the key */
  52         regex_t *preg;                  /**< compiled regular expression */
  53         int unread;                     /**< leave record to read again */
  54         const char *put_errmsg;         /**< error message for @NAME{put_xxx()} */
  55         /** @} */
  56 
  57         /**
  58          * @name (2) DB185 PART
  59          */
  60         /** @{ */
  61         DB *db;                         /**< descripter of DB */
  62         char dbname[MAXPATHLEN];        /**< dbname */
  63         char key[MAXKEYLEN];            /**< key */
  64         int keylen;                     /**< key length */
  65         char prev[MAXKEYLEN];           /**< previous key value */
  66         int perm;                       /**< file permission */
  67         /** @} */
  68 
  69         /**
  70          * @name (3) sorted write
  71          */
  72         /** @{ */
  73         FILE *sortout;                  /**< write to sort command */
  74         FILE *sortin;                   /**< read from sort command */
  75 #if defined(_WIN32) && !defined(__CYGWIN__)
  76         HANDLE pid;
  77 #else
  78         int pid;                        /**< sort process id */
  79 #endif
  80         /** @} */
  81 } DBOP;
  82 
  83 /**
  84  * @name openflags
  85  */
  86 /** @{ */
  87                 /** allow duplicate records     */
  88 #define DBOP_DUP        1
  89 /** @} */
  90 
  91 /**
  92  * @name ioflags
  93  */
  94 /** @{ */
  95                         /** read key part */
  96 #define DBOP_KEY                1
  97                         /** prefixed read */
  98 #define DBOP_PREFIX             2
  99                         /** raw read */
 100 #define DBOP_RAW                4
 101                         /** sorted write */
 102 #define DBOP_SORTED_WRITE       8
 103 /** @} */
 104 
 105 DBOP *dbop_open(const char *, int, int, int);
 106 const char *dbop_get(DBOP *, const char *);
 107 void dbop_put(DBOP *, const char *, const char *);
 108 void dbop_put_withlen(DBOP *, const char *, const char *, int);
 109 void dbop_delete(DBOP *, const char *);
 110 void dbop_update(DBOP *, const char *, const char *);
 111 const char *dbop_first(DBOP *, const char *, regex_t *, int);
 112 const char *dbop_next(DBOP *);
 113 void dbop_unread(DBOP *);
 114 const char *dbop_lastdat(DBOP *, int *);
 115 const char *dbop_getflag(DBOP *);
 116 const char *dbop_getoption(DBOP *, const char *);
 117 void dbop_putoption(DBOP *, const char *, const char *);
 118 int dbop_getversion(DBOP *);
 119 void dbop_putversion(DBOP *, int);
 120 void dbop_close(DBOP *);
 121 
 122 #endif /* _DBOP_H_ */

/* [previous][next][first][last][top][bottom][index][help] */